e1000 的工作原理
可以很清晰的看到,这个地址就是 os 告知的,通过写 PCI 设备的配置空间的 bar 空间的位置的:
// 检测这个 memory region 是如何被加入的, 这个时候的大小是确定的
#0 martins3 () at ../softmmu/memory.c:1188
#1 0x0000555555b8eeb5 in memory_region_init (mr=0x5555579fa5c0, owner=0x5555579f7ca0, name=<optimized out>, size=131072) at ../softmmu/memory.c:1198
#2 0x0000555555b8ef5c in memory_region_init_io (mr=mr@entry=0x5555579fa5c0, owner=owner@entry=0x5555579f7ca0, ops=ops@entry=0x5555562d9520 <e1000_mmio_ops>, opaque=opa que@entry=0x5555579f7ca0, name=name@entry=0x555555dc1976 "e1000-mmio", size=size@entry=131072) at ../softmmu/memory.c:1532
#3 0x000055555590a682 in e1000_mmio_setup (d=0x5555579f7ca0) at ../hw/net/e1000.c:1640
#4 pci_e1000_realize (pci_dev=0x5555579f7ca0, errp=<optimized out>) at ../hw/net/e1000.c:1698
#5 0x000055555596eb91 in pci_qdev_realize (qdev=0x5555579f7ca0, errp=<optimized out>) at ../hw/pci/pci.c:2117
#6 0x0000555555cadec7 in device_set_realized (obj=<optimized out>, value=true, errp=0x7fffffffd300) at ../hw/core/qdev.c:761
#7 0x0000555555c9b21a in property_set_bool (obj=0x5555579f7ca0, v=<optimized out>, name=<optimized out>, opaque=0x5555565d1db0, errp=0x7fffffffd300) at ../qom/object.c :2257
#8 0x0000555555c9d72c in object_property_set (obj=obj@entry=0x5555579f7ca0, name=name@entry=0x555555ed7f96 "realized", v=v@entry=0x555556dbfe10, errp=errp@entry=0x5555 564e2e30 <error_fatal>) at ../qom/object.c:1402
#9 0x0000555555c9fa64 in object_property_set_qobject (obj=obj@entry=0x5555579f7ca0, name=name@entry=0x555555ed7f96 "realized", value=value@entry=0x555556d9d790, errp=e rrp@entry=0x5555564e2e30 <error_fatal>) at ../qom/qom-qobject.c:28
#10 0x0000555555c9d979 in object_property_set_bool (obj=0x5555579f7ca0, name=0x555555ed7f96 "realized", value=<optimized out>, errp=0x5555564e2e30 <error_fatal>) at ../ qom/object.c:1472
#11 0x0000555555cacd93 in qdev_realize_and_unref (dev=dev@entry=0x5555579f7ca0, bus=bus@entry=0x555556e0f800, errp=<optimized out>) at ../hw/core/qdev.c:396
#12 0x000055555596d209 in pci_realize_and_unref (dev=dev@entry=0x5555579f7ca0, bus=bus@entry=0x555556e0f800, errp=<optimized out>) at ../hw/pci/pci.c:2182
#13 0x000055555596d437 in pci_nic_init_nofail (nd=nd@entry=0x5555564c4300 <nd_table>, rootbus=rootbus@entry=0x555556e0f800, default_model=default_model@entry=0x555555d7 227c "e1000", default_devaddr=default_devaddr@entry=0x0) at ../hw/pci/pci.c:1957
#14 0x0000555555a62b20 in pc_nic_init (pcmc=pcmc@entry=0x5555567978b0, isa_bus=0x5555568b4980, pci_bus=pci_bus@entry=0x555556e0f800) at ../hw/i386/pc.c:1189
#15 0x0000555555a65bed in pc_init1 (machine=0x5555566c0000, pci_type=0x555555dbe5ad "i440FX", host_type=0x555555d80e54 "i440FX-pcihost") at ../hw/i386/pc_piix.c:244
#16 0x00005555558ff1ae in machine_run_board_init (machine=machine@entry=0x5555566c0000) at ../hw/core/machine.c:1232
#17 0x0000555555bae25e in qemu_init_board () at ../softmmu/vl.c:2514
#18 qmp_x_exit_preconfig (errp=<optimized out>) at ../softmmu/vl.c:2588
#19 0x0000555555bb1ea2 in qemu_init (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../softmmu/vl.c:3611
#20 0x000055555582b4bd in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../softmmu/main.c:49
// 检测 mmio 的地址是确定的,果然如此
#0 martins3 () at ../softmmu/memory.c:1188
#1 0x0000555555b928fa in memory_region_add_subregion_common (subregion=0x5555579fcf80, offset=4273733632, mr=0x55555681a700) at ../softmmu/memory.c:2478
#2 memory_region_add_subregion_overlap (mr=0x55555681a700, offset=4273733632, subregion=0x5555579fcf80, priority=<optimized out>) at ../softmmu/memory.c:2500
#3 0x000055555596b5a2 in pci_update_mappings (d=d@entry=0x5555579fa660) at ../hw/pci/pci.c:1371
#4 0x000055555596bd1c in pci_default_write_config (d=d@entry=0x5555579fa660, addr=addr@entry=4, val_in=val_in@entry=259, l=l@entry=2) at ../hw/pci/pci.c:1431
#5 0x0000555555909d68 in e1000_write_config (pci_dev=0x5555579fa660, address=4, val=259, len=2) at ../hw/net/e1000.c:1674
#6 0x0000555555877f1b in pci_host_config_write_common (pci_dev=0x5555579fa660, addr=4, limit=<optimized out>, val=259, len=2) at ../hw/pci/pci_host.c:83
#7 0x0000555555b8d7c0 in memory_region_write_accessor (mr=0x5555569dbd90, addr=0, value=<optimized out>, size=2, shift=<optimized out>, mask=<optimized out>, attrs=...
) at ../softmmu/memory.c:491
#8 0x0000555555b8c0ee in access_with_adjusted_size (addr=0, value=0x7fffd9ff90a8, size=2, access_size_min=<optimized out>, access_size_max=<optimized out>, access_fn=0
x555555b8d730 <memory_region_write_accessor>, mr=0x5555569dbd90, attrs=...) at ../softmmu/memory.c:552
#9 0x0000555555b8fce7 in memory_region_dispatch_write (mr=mr@entry=0x5555569dbd90, addr=0, data=<optimized out>, op=<optimized out>, attrs=attrs@entry=...) at ../softm
mu/memory.c:1533
#10 0x0000555555bd7190 in flatview_write_continue (fv=fv@entry=0x7ffdcc1490a0, addr=addr@entry=3324, attrs=..., ptr=ptr@entry=0x7fffeb121000, len=len@entry=2, addr1=<op
timized out>, l=<optimized out>, mr=0x5555569dbd90) at /home/maritns3/core/kvmqemu/include/qemu/host-utils.h:164
#11 0x0000555555bd73a6 in flatview_write (fv=0x7ffdcc1490a0, addr=addr@entry=3324, attrs=attrs@entry=..., buf=buf@entry=0x7fffeb121000, len=len@entry=2) at ../softmmu/p
hysmem.c:2786
#12 0x0000555555bda066 in address_space_write (as=0x5555564e0ba0 <address_space_io>, addr=addr@entry=3324, attrs=..., buf=0x7fffeb121000, len=len@entry=2) at ../softmmu
/physmem.c:2878
#13 0x0000555555bda0fe in address_space_rw (as=<optimized out>, addr=addr@entry=3324, attrs=..., attrs@entry=..., buf=<optimized out>, len=len@entry=2, is_write=is_writ
e@entry=true) at ../softmmu/physmem.c:2888
#14 0x0000555555bb8939 in kvm_handle_io (count=1, size=2, direction=<optimized out>, data=<optimized out>, attrs=..., port=3324) at ../accel/kvm/kvm-all.c:2256
#15 kvm_cpu_exec (cpu=cpu@entry=0x5555569b9530) at ../accel/kvm/kvm-all.c:2507
#16 0x0000555555b77185 in kvm_vcpu_thread_fn (arg=arg@entry=0x5555569b9530) at ../accel/kvm/kvm-accel-ops.c:49
#17 0x0000555555d24983 in qemu_thread_start (args=<optimized out>) at ../util/qemu-thread-posix.c:521
#18 0x00007ffff6235609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#19 0x00007ffff615a293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
- 内核中间是怎么初始化 e1000 的 bar 地址的 ?
- 不知道为什么 memory_region_add_subregion_common 在 e1000 的地址上
神奇的 acpi,会添加很多设备:
[0] from 0xffffffff8167c890 in device_add+0 at drivers/base/core.c:3199
[1] from 0xffffffff8146a90a in acpi_device_add+442 at drivers/acpi/scan.c:723
[2] from 0xffffffff8146b8b7 in acpi_add_single_object+615 at drivers/acpi/scan.c:1711
[3] from 0xffffffff8146bd05 in acpi_bus_check_add+261 at drivers/acpi/scan.c:1951
[4] from 0xffffffff8148c805 in acpi_ns_walk_namespace+217 at drivers/acpi/acpica/nswalk.c:229
[5] from 0xffffffff8148cdce in acpi_walk_namespace+68 at drivers/acpi/acpica/nsxfeval.c:606
[6] from 0xffffffff8148cdce in acpi_walk_namespace+148 at drivers/acpi/acpica/nsxfeval.c:554
[7] from 0xffffffff8146bf85 in acpi_bus_scan+181 at drivers/acpi/scan.c:2160
[8] from 0xffffffff82b699a2 in acpi_scan_init+277 at drivers/acpi/scan.c:2342
[9] from 0xffffffff82b696d3 in acpi_init+1010 at drivers/acpi/bus.c:1341
acpi 会将 pci 添加进去, 首先从 host bridge 加入开始:
[0] from 0xffffffff8167c890 in device_add+0 at drivers/base/core.c:3199
[1] from 0xffffffff8167d182 in device_register+18 at drivers/base/core.c:3401
[2] from 0xffffffff81430ed3 in pci_register_host_bridge+499 at drivers/pci/probe.c:940
[3] from 0xffffffff81431014 in pci_create_root_bus+132 at drivers/pci/probe.c:2979
[4] from 0xffffffff8147151e in acpi_pci_root_create+318 at drivers/acpi/pci_root.c:895
[5] from 0xffffffff81b179cd in pci_acpi_scan_root+365 at arch/x86/pci/acpi.c:368
[6] from 0xffffffff81b3542c in acpi_pci_root_add+7094956 at drivers/acpi/pci_root.c:597
[7] from 0xffffffff8146a1c3 in acpi_scan_attach_handler+48 at drivers/acpi/scan.c:2038
[8] from 0xffffffff8146a1c3 in acpi_bus_attach+323 at drivers/acpi/scan.c:2086
[9] from 0xffffffff8146a110 in acpi_bus_attach+144 at drivers/acpi/scan.c:2107
然后 pci 将普通的 device 一个个的加入:
#0 device_add (dev=dev@entry=0xffff8881002d90c0) at drivers/base/core.c:3199
#1 0xffffffff814301d3 in pci_device_add (dev=dev@entry=0xffff8881002d9000, bus=bus@entry=0xffff888100259c00) at drivers/pci/probe.c:2498
#2 0xffffffff814305ff in pci_scan_single_device (devfn=0, bus=0xffff888100259c00) at drivers/pci/probe.c:2516
#3 pci_scan_single_device (bus=0xffff888100259c00, devfn=0) at drivers/pci/probe.c:2502
#4 0xffffffff8143066d in pci_scan_slot (bus=bus@entry=0xffff888100259c00, devfn=devfn@entry=0) at drivers/pci/probe.c:2591
#5 0xffffffff81431790 in pci_scan_child_bus_extend (bus=bus@entry=0xffff888100259c00, available_buses=available_buses@entry=0) at drivers/pci/probe.c:2808
#6 0xffffffff81431977 in pci_scan_child_bus (bus=bus@entry=0xffff888100259c00) at drivers/pci/probe.c:2938
#7 0xffffffff814715e1 in acpi_pci_root_create (root=root@entry=0xffff88810021fa00, ops=ops@entry=0xffffffff8263f580 <acpi_pci_root_ops>, info=info@entry=0xffff88810022
c960, sysdata=sysdata@entry=0xffff88810022c998) at drivers/acpi/pci_root.c:925
#8 0xffffffff81b179cd in pci_acpi_scan_root (root=root@entry=0xffff88810021fa00) at arch/x86/pci/acpi.c:368
#9 0xffffffff81b3542c in acpi_pci_root_add (device=0xffff888100217000, not_used=<optimized out>) at drivers/acpi/pci_root.c:597
#10 0xffffffff8146a1c3 in acpi_scan_attach_handler (device=0xffff888100217000) at drivers/acpi/scan.c:2038
#11 acpi_bus_attach (device=device@entry=0xffff888100217000, first_pass=first_pass@entry=true) at drivers/acpi/scan.c:2086
#12 0xffffffff8146a110 in acpi_bus_attach (device=device@entry=0xffff888100216800, first_pass=first_pass@entry=true) at drivers/acpi/scan.c:2107
#13 0xffffffff8146a110 in acpi_bus_attach (device=0xffff888100216000, first_pass=first_pass@entry=true) at drivers/acpi/scan.c:2107
#14 0xffffffff8146bf1f in acpi_bus_scan (handle=handle@entry=0xffffffffffffffff) at drivers/acpi/scan.c:2167
#15 0xffffffff82b699a2 in acpi_scan_init () at drivers/acpi/scan.c:2342
#16 0xffffffff82b696d3 in acpi_init () at drivers/acpi/bus.c:1341
#17 0xffffffff81000def in do_one_initcall (fn=0xffffffff82b692e1 <acpi_init>) at init/main.c:1249
#18 0xffffffff82b3726b in do_initcall_level (command_line=0xffff888100122400 "root", level=4) at ./include/linux/compiler.h:234
device_add 似乎不仅仅添加硬件的,软件也是会添加的
本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。