4 * Copyright (c) 2004 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 # define PCI_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
34 # define PCI_DPRINTF(format, ...) do { } while (0)
40 pci_set_irq_fn set_irq
;
41 pci_map_irq_fn map_irq
;
42 pci_hotplug_fn hotplug
;
43 uint32_t config_reg
; /* XXX: suppress */
45 PCIDevice
*devices
[256];
46 PCIDevice
*parent_dev
;
48 QLIST_HEAD(, PCIBus
) child
; /* this will be replaced by qdev later */
49 QLIST_ENTRY(PCIBus
) sibling
;/* this will be replaced by qdev later */
51 /* The bus IRQ state is the logical OR of the connected devices.
52 Keep a count of the number of devices with raised IRQs. */
57 static void pcibus_dev_print(Monitor
*mon
, DeviceState
*dev
, int indent
);
59 static struct BusInfo pci_bus_info
= {
61 .size
= sizeof(PCIBus
),
62 .print_dev
= pcibus_dev_print
,
63 .props
= (Property
[]) {
64 DEFINE_PROP_PCI_DEVFN("addr", PCIDevice
, devfn
, -1),
65 DEFINE_PROP_END_OF_LIST()
69 static void pci_update_mappings(PCIDevice
*d
);
70 static void pci_set_irq(void *opaque
, int irq_num
, int level
);
72 target_phys_addr_t pci_mem_base
;
73 static uint16_t pci_default_sub_vendor_id
= PCI_SUBVENDOR_ID_REDHAT_QUMRANET
;
74 static uint16_t pci_default_sub_device_id
= PCI_SUBDEVICE_ID_QEMU
;
79 QLIST_ENTRY(PCIHostBus
) next
;
81 static QLIST_HEAD(, PCIHostBus
) host_buses
;
83 static const VMStateDescription vmstate_pcibus
= {
86 .minimum_version_id
= 1,
87 .minimum_version_id_old
= 1,
88 .fields
= (VMStateField
[]) {
89 VMSTATE_INT32_EQUAL(nirq
, PCIBus
),
90 VMSTATE_VARRAY_INT32(irq_count
, PCIBus
, nirq
, 0, vmstate_info_int32
, int32_t),
95 static int pci_bar(PCIDevice
*d
, int reg
)
99 if (reg
!= PCI_ROM_SLOT
)
100 return PCI_BASE_ADDRESS_0
+ reg
* 4;
102 type
= d
->config
[PCI_HEADER_TYPE
] & ~PCI_HEADER_TYPE_MULTI_FUNCTION
;
103 return type
== PCI_HEADER_TYPE_BRIDGE
? PCI_ROM_ADDRESS1
: PCI_ROM_ADDRESS
;
106 static void pci_device_reset(PCIDevice
*dev
)
110 memset(dev
->irq_state
, 0, sizeof dev
->irq_state
);
111 dev
->config
[PCI_COMMAND
] &= ~(PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
113 dev
->config
[PCI_CACHE_LINE_SIZE
] = 0x0;
114 dev
->config
[PCI_INTERRUPT_LINE
] = 0x0;
115 for (r
= 0; r
< PCI_NUM_REGIONS
; ++r
) {
116 if (!dev
->io_regions
[r
].size
) {
119 pci_set_long(dev
->config
+ pci_bar(dev
, r
), dev
->io_regions
[r
].type
);
121 pci_update_mappings(dev
);
124 static void pci_bus_reset(void *opaque
)
126 PCIBus
*bus
= opaque
;
129 for (i
= 0; i
< bus
->nirq
; i
++) {
130 bus
->irq_count
[i
] = 0;
132 for (i
= 0; i
< ARRAY_SIZE(bus
->devices
); ++i
) {
133 if (bus
->devices
[i
]) {
134 pci_device_reset(bus
->devices
[i
]);
139 static void pci_host_bus_register(int domain
, PCIBus
*bus
)
141 struct PCIHostBus
*host
;
142 host
= qemu_mallocz(sizeof(*host
));
143 host
->domain
= domain
;
145 QLIST_INSERT_HEAD(&host_buses
, host
, next
);
148 PCIBus
*pci_find_root_bus(int domain
)
150 struct PCIHostBus
*host
;
152 QLIST_FOREACH(host
, &host_buses
, next
) {
153 if (host
->domain
== domain
) {
161 void pci_bus_new_inplace(PCIBus
*bus
, DeviceState
*parent
,
162 const char *name
, int devfn_min
)
164 qbus_create_inplace(&bus
->qbus
, &pci_bus_info
, parent
, name
);
165 bus
->devfn_min
= devfn_min
;
168 QLIST_INIT(&bus
->child
);
169 pci_host_bus_register(0, bus
); /* for now only pci domain 0 is supported */
171 vmstate_register(-1, &vmstate_pcibus
, bus
);
172 qemu_register_reset(pci_bus_reset
, bus
);
175 PCIBus
*pci_bus_new(DeviceState
*parent
, const char *name
, int devfn_min
)
179 bus
= qemu_mallocz(sizeof(*bus
));
180 bus
->qbus
.qdev_allocated
= 1;
181 pci_bus_new_inplace(bus
, parent
, name
, devfn_min
);
185 void pci_bus_irqs(PCIBus
*bus
, pci_set_irq_fn set_irq
, pci_map_irq_fn map_irq
,
186 void *irq_opaque
, int nirq
)
188 bus
->set_irq
= set_irq
;
189 bus
->map_irq
= map_irq
;
190 bus
->irq_opaque
= irq_opaque
;
192 bus
->irq_count
= qemu_mallocz(nirq
* sizeof(bus
->irq_count
[0]));
195 void pci_bus_hotplug(PCIBus
*bus
, pci_hotplug_fn hotplug
)
197 bus
->qbus
.allow_hotplug
= 1;
198 bus
->hotplug
= hotplug
;
201 PCIBus
*pci_register_bus(DeviceState
*parent
, const char *name
,
202 pci_set_irq_fn set_irq
, pci_map_irq_fn map_irq
,
203 void *irq_opaque
, int devfn_min
, int nirq
)
207 bus
= pci_bus_new(parent
, name
, devfn_min
);
208 pci_bus_irqs(bus
, set_irq
, map_irq
, irq_opaque
, nirq
);
212 static void pci_register_secondary_bus(PCIBus
*parent
,
215 pci_map_irq_fn map_irq
,
218 qbus_create_inplace(&bus
->qbus
, &pci_bus_info
, &dev
->qdev
, name
);
219 bus
->map_irq
= map_irq
;
220 bus
->parent_dev
= dev
;
222 QLIST_INIT(&bus
->child
);
223 QLIST_INSERT_HEAD(&parent
->child
, bus
, sibling
);
226 static void pci_unregister_secondary_bus(PCIBus
*bus
)
228 assert(QLIST_EMPTY(&bus
->child
));
229 QLIST_REMOVE(bus
, sibling
);
232 int pci_bus_num(PCIBus
*s
)
235 return 0; /* pci host bridge */
236 return s
->parent_dev
->config
[PCI_SECONDARY_BUS
];
239 static int get_pci_config_device(QEMUFile
*f
, void *pv
, size_t size
)
241 PCIDevice
*s
= container_of(pv
, PCIDevice
, config
);
245 assert(size
== pci_config_size(s
));
246 config
= qemu_malloc(size
);
248 qemu_get_buffer(f
, config
, size
);
249 for (i
= 0; i
< size
; ++i
) {
250 if ((config
[i
] ^ s
->config
[i
]) & s
->cmask
[i
] & ~s
->wmask
[i
]) {
255 memcpy(s
->config
, config
, size
);
257 pci_update_mappings(s
);
263 /* just put buffer */
264 static void put_pci_config_device(QEMUFile
*f
, void *pv
, size_t size
)
266 const uint8_t **v
= pv
;
267 assert(size
== pci_config_size(container_of(pv
, PCIDevice
, config
)));
268 qemu_put_buffer(f
, *v
, size
);
271 static VMStateInfo vmstate_info_pci_config
= {
272 .name
= "pci config",
273 .get
= get_pci_config_device
,
274 .put
= put_pci_config_device
,
277 const VMStateDescription vmstate_pci_device
= {
280 .minimum_version_id
= 1,
281 .minimum_version_id_old
= 1,
282 .fields
= (VMStateField
[]) {
283 VMSTATE_INT32_LE(version_id
, PCIDevice
),
284 VMSTATE_BUFFER_UNSAFE_INFO(config
, PCIDevice
, 0,
285 vmstate_info_pci_config
,
286 PCI_CONFIG_SPACE_SIZE
),
287 VMSTATE_INT32_ARRAY_V(irq_state
, PCIDevice
, PCI_NUM_PINS
, 2),
288 VMSTATE_END_OF_LIST()
292 const VMStateDescription vmstate_pcie_device
= {
295 .minimum_version_id
= 1,
296 .minimum_version_id_old
= 1,
297 .fields
= (VMStateField
[]) {
298 VMSTATE_INT32_LE(version_id
, PCIDevice
),
299 VMSTATE_BUFFER_UNSAFE_INFO(config
, PCIDevice
, 0,
300 vmstate_info_pci_config
,
301 PCIE_CONFIG_SPACE_SIZE
),
302 VMSTATE_INT32_ARRAY_V(irq_state
, PCIDevice
, PCI_NUM_PINS
, 2),
303 VMSTATE_END_OF_LIST()
307 static inline const VMStateDescription
*pci_get_vmstate(PCIDevice
*s
)
309 return pci_is_express(s
) ? &vmstate_pcie_device
: &vmstate_pci_device
;
312 void pci_device_save(PCIDevice
*s
, QEMUFile
*f
)
314 vmstate_save_state(f
, pci_get_vmstate(s
), s
);
317 int pci_device_load(PCIDevice
*s
, QEMUFile
*f
)
319 return vmstate_load_state(f
, pci_get_vmstate(s
), s
, s
->version_id
);
322 static int pci_set_default_subsystem_id(PCIDevice
*pci_dev
)
326 id
= (void*)(&pci_dev
->config
[PCI_SUBVENDOR_ID
]);
327 id
[0] = cpu_to_le16(pci_default_sub_vendor_id
);
328 id
[1] = cpu_to_le16(pci_default_sub_device_id
);
333 * Parse [[<domain>:]<bus>:]<slot>, return -1 on error
335 static int pci_parse_devaddr(const char *addr
, int *domp
, int *busp
, unsigned *slotp
)
340 unsigned long dom
= 0, bus
= 0;
344 val
= strtoul(p
, &e
, 16);
350 val
= strtoul(p
, &e
, 16);
357 val
= strtoul(p
, &e
, 16);
363 if (dom
> 0xffff || bus
> 0xff || val
> 0x1f)
371 /* Note: QEMU doesn't implement domains other than 0 */
372 if (!pci_find_bus(pci_find_root_bus(dom
), bus
))
381 int pci_read_devaddr(Monitor
*mon
, const char *addr
, int *domp
, int *busp
,
384 /* strip legacy tag */
385 if (!strncmp(addr
, "pci_addr=", 9)) {
388 if (pci_parse_devaddr(addr
, domp
, busp
, slotp
)) {
389 monitor_printf(mon
, "Invalid pci address\n");
395 PCIBus
*pci_get_bus_devfn(int *devfnp
, const char *devaddr
)
402 return pci_find_bus(pci_find_root_bus(0), 0);
405 if (pci_parse_devaddr(devaddr
, &dom
, &bus
, &slot
) < 0) {
410 return pci_find_bus(pci_find_root_bus(0), bus
);
413 static void pci_init_cmask(PCIDevice
*dev
)
415 pci_set_word(dev
->cmask
+ PCI_VENDOR_ID
, 0xffff);
416 pci_set_word(dev
->cmask
+ PCI_DEVICE_ID
, 0xffff);
417 dev
->cmask
[PCI_STATUS
] = PCI_STATUS_CAP_LIST
;
418 dev
->cmask
[PCI_REVISION_ID
] = 0xff;
419 dev
->cmask
[PCI_CLASS_PROG
] = 0xff;
420 pci_set_word(dev
->cmask
+ PCI_CLASS_DEVICE
, 0xffff);
421 dev
->cmask
[PCI_HEADER_TYPE
] = 0xff;
422 dev
->cmask
[PCI_CAPABILITY_LIST
] = 0xff;
425 static void pci_init_wmask(PCIDevice
*dev
)
427 int config_size
= pci_config_size(dev
);
429 dev
->wmask
[PCI_CACHE_LINE_SIZE
] = 0xff;
430 dev
->wmask
[PCI_INTERRUPT_LINE
] = 0xff;
431 pci_set_word(dev
->wmask
+ PCI_COMMAND
,
432 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
);
434 memset(dev
->wmask
+ PCI_CONFIG_HEADER_SIZE
, 0xff,
435 config_size
- PCI_CONFIG_HEADER_SIZE
);
438 static void pci_init_wmask_bridge(PCIDevice
*d
)
440 /* PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS and
441 PCI_SEC_LETENCY_TIMER */
442 memset(d
->wmask
+ PCI_PRIMARY_BUS
, 0xff, 4);
445 d
->wmask
[PCI_IO_BASE
] = PCI_IO_RANGE_MASK
& 0xff;
446 d
->wmask
[PCI_IO_LIMIT
] = PCI_IO_RANGE_MASK
& 0xff;
447 pci_set_word(d
->wmask
+ PCI_MEMORY_BASE
,
448 PCI_MEMORY_RANGE_MASK
& 0xffff);
449 pci_set_word(d
->wmask
+ PCI_MEMORY_LIMIT
,
450 PCI_MEMORY_RANGE_MASK
& 0xffff);
451 pci_set_word(d
->wmask
+ PCI_PREF_MEMORY_BASE
,
452 PCI_PREF_RANGE_MASK
& 0xffff);
453 pci_set_word(d
->wmask
+ PCI_PREF_MEMORY_LIMIT
,
454 PCI_PREF_RANGE_MASK
& 0xffff);
456 /* PCI_PREF_BASE_UPPER32 and PCI_PREF_LIMIT_UPPER32 */
457 memset(d
->wmask
+ PCI_PREF_BASE_UPPER32
, 0xff, 8);
459 pci_set_word(d
->wmask
+ PCI_BRIDGE_CONTROL
, 0xffff);
462 static void pci_config_alloc(PCIDevice
*pci_dev
)
464 int config_size
= pci_config_size(pci_dev
);
466 pci_dev
->config
= qemu_mallocz(config_size
);
467 pci_dev
->cmask
= qemu_mallocz(config_size
);
468 pci_dev
->wmask
= qemu_mallocz(config_size
);
469 pci_dev
->used
= qemu_mallocz(config_size
);
472 static void pci_config_free(PCIDevice
*pci_dev
)
474 qemu_free(pci_dev
->config
);
475 qemu_free(pci_dev
->cmask
);
476 qemu_free(pci_dev
->wmask
);
477 qemu_free(pci_dev
->used
);
480 /* -1 for devfn means auto assign */
481 static PCIDevice
*do_pci_register_device(PCIDevice
*pci_dev
, PCIBus
*bus
,
482 const char *name
, int devfn
,
483 PCIConfigReadFunc
*config_read
,
484 PCIConfigWriteFunc
*config_write
,
488 for(devfn
= bus
->devfn_min
; devfn
< ARRAY_SIZE(bus
->devices
);
490 if (!bus
->devices
[devfn
])
493 hw_error("PCI: no devfn available for %s, all in use\n", name
);
495 } else if (bus
->devices
[devfn
]) {
496 hw_error("PCI: devfn %d not available for %s, in use by %s\n", devfn
,
497 name
, bus
->devices
[devfn
]->name
);
500 pci_dev
->devfn
= devfn
;
501 pstrcpy(pci_dev
->name
, sizeof(pci_dev
->name
), name
);
502 memset(pci_dev
->irq_state
, 0, sizeof(pci_dev
->irq_state
));
503 pci_config_alloc(pci_dev
);
505 header_type
&= ~PCI_HEADER_TYPE_MULTI_FUNCTION
;
506 if (header_type
== PCI_HEADER_TYPE_NORMAL
) {
507 pci_set_default_subsystem_id(pci_dev
);
509 pci_init_cmask(pci_dev
);
510 pci_init_wmask(pci_dev
);
511 if (header_type
== PCI_HEADER_TYPE_BRIDGE
) {
512 pci_init_wmask_bridge(pci_dev
);
516 config_read
= pci_default_read_config
;
518 config_write
= pci_default_write_config
;
519 pci_dev
->config_read
= config_read
;
520 pci_dev
->config_write
= config_write
;
521 bus
->devices
[devfn
] = pci_dev
;
522 pci_dev
->irq
= qemu_allocate_irqs(pci_set_irq
, pci_dev
, PCI_NUM_PINS
);
523 pci_dev
->version_id
= 2; /* Current pci device vmstate version */
527 PCIDevice
*pci_register_device(PCIBus
*bus
, const char *name
,
528 int instance_size
, int devfn
,
529 PCIConfigReadFunc
*config_read
,
530 PCIConfigWriteFunc
*config_write
)
534 pci_dev
= qemu_mallocz(instance_size
);
535 pci_dev
= do_pci_register_device(pci_dev
, bus
, name
, devfn
,
536 config_read
, config_write
,
537 PCI_HEADER_TYPE_NORMAL
);
540 static target_phys_addr_t
pci_to_cpu_addr(target_phys_addr_t addr
)
542 return addr
+ pci_mem_base
;
545 static void pci_unregister_io_regions(PCIDevice
*pci_dev
)
550 for(i
= 0; i
< PCI_NUM_REGIONS
; i
++) {
551 r
= &pci_dev
->io_regions
[i
];
552 if (!r
->size
|| r
->addr
== PCI_BAR_UNMAPPED
)
554 if (r
->type
== PCI_BASE_ADDRESS_SPACE_IO
) {
555 isa_unassign_ioport(r
->addr
, r
->filtered_size
);
557 cpu_register_physical_memory(pci_to_cpu_addr(r
->addr
),
564 static int pci_unregister_device(DeviceState
*dev
)
566 PCIDevice
*pci_dev
= DO_UPCAST(PCIDevice
, qdev
, dev
);
567 PCIDeviceInfo
*info
= DO_UPCAST(PCIDeviceInfo
, qdev
, dev
->info
);
571 ret
= info
->exit(pci_dev
);
575 pci_unregister_io_regions(pci_dev
);
577 qemu_free_irqs(pci_dev
->irq
);
578 pci_dev
->bus
->devices
[pci_dev
->devfn
] = NULL
;
579 pci_config_free(pci_dev
);
583 void pci_register_bar(PCIDevice
*pci_dev
, int region_num
,
584 pcibus_t size
, int type
,
585 PCIMapIORegionFunc
*map_func
)
591 if ((unsigned int)region_num
>= PCI_NUM_REGIONS
)
594 if (size
& (size
-1)) {
595 fprintf(stderr
, "ERROR: PCI region size must be pow2 "
596 "type=0x%x, size=0x%"FMT_PCIBUS
"\n", type
, size
);
600 r
= &pci_dev
->io_regions
[region_num
];
601 r
->addr
= PCI_BAR_UNMAPPED
;
603 r
->filtered_size
= size
;
605 r
->map_func
= map_func
;
608 addr
= pci_bar(pci_dev
, region_num
);
609 if (region_num
== PCI_ROM_SLOT
) {
610 /* ROM enable bit is writeable */
611 wmask
|= PCI_ROM_ADDRESS_ENABLE
;
613 pci_set_long(pci_dev
->config
+ addr
, type
);
614 if (!(r
->type
& PCI_BASE_ADDRESS_SPACE_IO
) &&
615 r
->type
& PCI_BASE_ADDRESS_MEM_TYPE_64
) {
616 pci_set_quad(pci_dev
->wmask
+ addr
, wmask
);
617 pci_set_quad(pci_dev
->cmask
+ addr
, ~0ULL);
619 pci_set_long(pci_dev
->wmask
+ addr
, wmask
& 0xffffffff);
620 pci_set_long(pci_dev
->cmask
+ addr
, 0xffffffff);
624 static uint32_t pci_config_get_io_base(PCIDevice
*d
,
625 uint32_t base
, uint32_t base_upper16
)
629 val
= ((uint32_t)d
->config
[base
] & PCI_IO_RANGE_MASK
) << 8;
630 if (d
->config
[base
] & PCI_IO_RANGE_TYPE_32
) {
631 val
|= (uint32_t)pci_get_word(d
->config
+ base_upper16
) << 16;
636 static pcibus_t
pci_config_get_memory_base(PCIDevice
*d
, uint32_t base
)
638 return ((pcibus_t
)pci_get_word(d
->config
+ base
) & PCI_MEMORY_RANGE_MASK
)
642 static pcibus_t
pci_config_get_pref_base(PCIDevice
*d
,
643 uint32_t base
, uint32_t upper
)
648 tmp
= (pcibus_t
)pci_get_word(d
->config
+ base
);
649 val
= (tmp
& PCI_PREF_RANGE_MASK
) << 16;
650 if (tmp
& PCI_PREF_RANGE_TYPE_64
) {
651 val
|= (pcibus_t
)pci_get_long(d
->config
+ upper
) << 32;
656 static pcibus_t
pci_bridge_get_base(PCIDevice
*bridge
, uint8_t type
)
659 if (type
& PCI_BASE_ADDRESS_SPACE_IO
) {
660 base
= pci_config_get_io_base(bridge
,
661 PCI_IO_BASE
, PCI_IO_BASE_UPPER16
);
663 if (type
& PCI_BASE_ADDRESS_MEM_PREFETCH
) {
664 base
= pci_config_get_pref_base(
665 bridge
, PCI_PREF_MEMORY_BASE
, PCI_PREF_BASE_UPPER32
);
667 base
= pci_config_get_memory_base(bridge
, PCI_MEMORY_BASE
);
674 static pcibus_t
pci_bridge_get_limit(PCIDevice
*bridge
, uint8_t type
)
677 if (type
& PCI_BASE_ADDRESS_SPACE_IO
) {
678 limit
= pci_config_get_io_base(bridge
,
679 PCI_IO_LIMIT
, PCI_IO_LIMIT_UPPER16
);
680 limit
|= 0xfff; /* PCI bridge spec 3.2.5.6. */
682 if (type
& PCI_BASE_ADDRESS_MEM_PREFETCH
) {
683 limit
= pci_config_get_pref_base(
684 bridge
, PCI_PREF_MEMORY_LIMIT
, PCI_PREF_LIMIT_UPPER32
);
686 limit
= pci_config_get_memory_base(bridge
, PCI_MEMORY_LIMIT
);
688 limit
|= 0xfffff; /* PCI bridge spec 3.2.5.{1, 8}. */
693 static void pci_bridge_filter(PCIDevice
*d
, pcibus_t
*addr
, pcibus_t
*size
,
696 pcibus_t base
= *addr
;
697 pcibus_t limit
= *addr
+ *size
- 1;
700 for (br
= d
->bus
->parent_dev
; br
; br
= br
->bus
->parent_dev
) {
701 uint16_t cmd
= pci_get_word(d
->config
+ PCI_COMMAND
);
703 if (type
& PCI_BASE_ADDRESS_SPACE_IO
) {
704 if (!(cmd
& PCI_COMMAND_IO
)) {
708 if (!(cmd
& PCI_COMMAND_MEMORY
)) {
713 base
= MAX(base
, pci_bridge_get_base(br
, type
));
714 limit
= MIN(limit
, pci_bridge_get_limit(br
, type
));
721 *size
= limit
- base
+ 1;
724 *addr
= PCI_BAR_UNMAPPED
;
728 static pcibus_t
pci_bar_address(PCIDevice
*d
,
729 int reg
, uint8_t type
, pcibus_t size
)
731 pcibus_t new_addr
, last_addr
;
732 int bar
= pci_bar(d
, reg
);
733 uint16_t cmd
= pci_get_word(d
->config
+ PCI_COMMAND
);
735 if (type
& PCI_BASE_ADDRESS_SPACE_IO
) {
736 if (!(cmd
& PCI_COMMAND_IO
)) {
737 return PCI_BAR_UNMAPPED
;
739 new_addr
= pci_get_long(d
->config
+ bar
) & ~(size
- 1);
740 last_addr
= new_addr
+ size
- 1;
741 /* NOTE: we have only 64K ioports on PC */
742 if (last_addr
<= new_addr
|| new_addr
== 0 || last_addr
> UINT16_MAX
) {
743 return PCI_BAR_UNMAPPED
;
748 if (!(cmd
& PCI_COMMAND_MEMORY
)) {
749 return PCI_BAR_UNMAPPED
;
751 if (type
& PCI_BASE_ADDRESS_MEM_TYPE_64
) {
752 new_addr
= pci_get_quad(d
->config
+ bar
);
754 new_addr
= pci_get_long(d
->config
+ bar
);
756 /* the ROM slot has a specific enable bit */
757 if (reg
== PCI_ROM_SLOT
&& !(new_addr
& PCI_ROM_ADDRESS_ENABLE
)) {
758 return PCI_BAR_UNMAPPED
;
760 new_addr
&= ~(size
- 1);
761 last_addr
= new_addr
+ size
- 1;
762 /* NOTE: we do not support wrapping */
763 /* XXX: as we cannot support really dynamic
764 mappings, we handle specific values as invalid
766 if (last_addr
<= new_addr
|| new_addr
== 0 ||
767 last_addr
== PCI_BAR_UNMAPPED
) {
768 return PCI_BAR_UNMAPPED
;
771 /* Now pcibus_t is 64bit.
772 * Check if 32 bit BAR wraps around explicitly.
773 * Without this, PC ide doesn't work well.
774 * TODO: remove this work around.
776 if (!(type
& PCI_BASE_ADDRESS_MEM_TYPE_64
) && last_addr
>= UINT32_MAX
) {
777 return PCI_BAR_UNMAPPED
;
781 * OS is allowed to set BAR beyond its addressable
782 * bits. For example, 32 bit OS can set 64bit bar
783 * to >4G. Check it. TODO: we might need to support
784 * it in the future for e.g. PAE.
786 if (last_addr
>= TARGET_PHYS_ADDR_MAX
) {
787 return PCI_BAR_UNMAPPED
;
793 static void pci_update_mappings(PCIDevice
*d
)
797 pcibus_t new_addr
, filtered_size
;
799 for(i
= 0; i
< PCI_NUM_REGIONS
; i
++) {
800 r
= &d
->io_regions
[i
];
802 /* this region isn't registered */
806 new_addr
= pci_bar_address(d
, i
, r
->type
, r
->size
);
808 /* bridge filtering */
809 filtered_size
= r
->size
;
810 if (new_addr
!= PCI_BAR_UNMAPPED
) {
811 pci_bridge_filter(d
, &new_addr
, &filtered_size
, r
->type
);
814 /* This bar isn't changed */
815 if (new_addr
== r
->addr
&& filtered_size
== r
->filtered_size
)
818 /* now do the real mapping */
819 if (r
->addr
!= PCI_BAR_UNMAPPED
) {
820 if (r
->type
& PCI_BASE_ADDRESS_SPACE_IO
) {
822 /* NOTE: specific hack for IDE in PC case:
823 only one byte must be mapped. */
824 class = pci_get_word(d
->config
+ PCI_CLASS_DEVICE
);
825 if (class == 0x0101 && r
->size
== 4) {
826 isa_unassign_ioport(r
->addr
+ 2, 1);
828 isa_unassign_ioport(r
->addr
, r
->filtered_size
);
831 cpu_register_physical_memory(pci_to_cpu_addr(r
->addr
),
834 qemu_unregister_coalesced_mmio(r
->addr
, r
->filtered_size
);
838 r
->filtered_size
= filtered_size
;
839 if (r
->addr
!= PCI_BAR_UNMAPPED
) {
841 * TODO: currently almost all the map funcions assumes
842 * filtered_size == size and addr & ~(size - 1) == addr.
843 * However with bridge filtering, they aren't always true.
844 * Teach them such cases, such that filtered_size < size and
845 * addr & (size - 1) != 0.
847 r
->map_func(d
, i
, r
->addr
, r
->filtered_size
, r
->type
);
852 uint32_t pci_default_read_config(PCIDevice
*d
,
853 uint32_t address
, int len
)
856 assert(len
== 1 || len
== 2 || len
== 4);
857 len
= MIN(len
, pci_config_size(d
) - address
);
858 memcpy(&val
, d
->config
+ address
, len
);
859 return le32_to_cpu(val
);
862 void pci_default_write_config(PCIDevice
*d
, uint32_t addr
, uint32_t val
, int l
)
865 uint32_t config_size
= pci_config_size(d
);
867 for (i
= 0; i
< l
&& addr
+ i
< config_size
; val
>>= 8, ++i
) {
868 uint8_t wmask
= d
->wmask
[addr
+ i
];
869 d
->config
[addr
+ i
] = (d
->config
[addr
+ i
] & ~wmask
) | (val
& wmask
);
871 if (ranges_overlap(addr
, l
, PCI_BASE_ADDRESS_0
, 24) ||
872 ranges_overlap(addr
, l
, PCI_ROM_ADDRESS
, 4) ||
873 ranges_overlap(addr
, l
, PCI_ROM_ADDRESS1
, 4) ||
874 range_covers_byte(addr
, l
, PCI_COMMAND
))
875 pci_update_mappings(d
);
878 /***********************************************************/
879 /* generic PCI irq support */
881 /* 0 <= irq_num <= 3. level must be 0 or 1 */
882 static void pci_set_irq(void *opaque
, int irq_num
, int level
)
884 PCIDevice
*pci_dev
= opaque
;
888 change
= level
- pci_dev
->irq_state
[irq_num
];
892 pci_dev
->irq_state
[irq_num
] = level
;
895 irq_num
= bus
->map_irq(pci_dev
, irq_num
);
898 pci_dev
= bus
->parent_dev
;
900 bus
->irq_count
[irq_num
] += change
;
901 bus
->set_irq(bus
->irq_opaque
, irq_num
, bus
->irq_count
[irq_num
] != 0);
904 /***********************************************************/
905 /* monitor info on PCI */
912 static const pci_class_desc pci_class_descriptions
[] =
914 { 0x0100, "SCSI controller"},
915 { 0x0101, "IDE controller"},
916 { 0x0102, "Floppy controller"},
917 { 0x0103, "IPI controller"},
918 { 0x0104, "RAID controller"},
919 { 0x0106, "SATA controller"},
920 { 0x0107, "SAS controller"},
921 { 0x0180, "Storage controller"},
922 { 0x0200, "Ethernet controller"},
923 { 0x0201, "Token Ring controller"},
924 { 0x0202, "FDDI controller"},
925 { 0x0203, "ATM controller"},
926 { 0x0280, "Network controller"},
927 { 0x0300, "VGA controller"},
928 { 0x0301, "XGA controller"},
929 { 0x0302, "3D controller"},
930 { 0x0380, "Display controller"},
931 { 0x0400, "Video controller"},
932 { 0x0401, "Audio controller"},
934 { 0x0480, "Multimedia controller"},
935 { 0x0500, "RAM controller"},
936 { 0x0501, "Flash controller"},
937 { 0x0580, "Memory controller"},
938 { 0x0600, "Host bridge"},
939 { 0x0601, "ISA bridge"},
940 { 0x0602, "EISA bridge"},
941 { 0x0603, "MC bridge"},
942 { 0x0604, "PCI bridge"},
943 { 0x0605, "PCMCIA bridge"},
944 { 0x0606, "NUBUS bridge"},
945 { 0x0607, "CARDBUS bridge"},
946 { 0x0608, "RACEWAY bridge"},
948 { 0x0c03, "USB controller"},
952 static void pci_info_device(PCIBus
*bus
, PCIDevice
*d
)
954 Monitor
*mon
= cur_mon
;
957 const pci_class_desc
*desc
;
959 monitor_printf(mon
, " Bus %2d, device %3d, function %d:\n",
961 PCI_SLOT(d
->devfn
), PCI_FUNC(d
->devfn
));
962 class = pci_get_word(d
->config
+ PCI_CLASS_DEVICE
);
963 monitor_printf(mon
, " ");
964 desc
= pci_class_descriptions
;
965 while (desc
->desc
&& class != desc
->class)
968 monitor_printf(mon
, "%s", desc
->desc
);
970 monitor_printf(mon
, "Class %04x", class);
972 monitor_printf(mon
, ": PCI device %04x:%04x\n",
973 pci_get_word(d
->config
+ PCI_VENDOR_ID
),
974 pci_get_word(d
->config
+ PCI_DEVICE_ID
));
976 if (d
->config
[PCI_INTERRUPT_PIN
] != 0) {
977 monitor_printf(mon
, " IRQ %d.\n",
978 d
->config
[PCI_INTERRUPT_LINE
]);
980 if (class == 0x0604) {
984 monitor_printf(mon
, " BUS %d.\n", d
->config
[0x19]);
985 monitor_printf(mon
, " secondary bus %d.\n",
986 d
->config
[PCI_SECONDARY_BUS
]);
987 monitor_printf(mon
, " subordinate bus %d.\n",
988 d
->config
[PCI_SUBORDINATE_BUS
]);
990 base
= pci_bridge_get_base(d
, PCI_BASE_ADDRESS_SPACE_IO
);
991 limit
= pci_bridge_get_limit(d
, PCI_BASE_ADDRESS_SPACE_IO
);
992 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
995 base
= pci_bridge_get_base(d
, PCI_BASE_ADDRESS_SPACE_MEMORY
);
996 limit
= pci_bridge_get_limit(d
, PCI_BASE_ADDRESS_SPACE_MEMORY
);
998 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
1001 base
= pci_bridge_get_base(d
, PCI_BASE_ADDRESS_SPACE_MEMORY
|
1002 PCI_BASE_ADDRESS_MEM_PREFETCH
);
1003 limit
= pci_bridge_get_limit(d
, PCI_BASE_ADDRESS_SPACE_MEMORY
|
1004 PCI_BASE_ADDRESS_MEM_PREFETCH
);
1005 monitor_printf(mon
, " prefetchable memory range "
1006 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n", base
, limit
);
1008 for(i
= 0;i
< PCI_NUM_REGIONS
; i
++) {
1009 r
= &d
->io_regions
[i
];
1011 monitor_printf(mon
, " BAR%d: ", i
);
1012 if (r
->type
& PCI_BASE_ADDRESS_SPACE_IO
) {
1013 monitor_printf(mon
, "I/O at 0x%04"FMT_PCIBUS
1014 " [0x%04"FMT_PCIBUS
"].\n",
1015 r
->addr
, r
->addr
+ r
->size
- 1);
1017 const char *type
= r
->type
& PCI_BASE_ADDRESS_MEM_TYPE_64
?
1018 "64 bit" : "32 bit";
1019 const char *prefetch
=
1020 r
->type
& PCI_BASE_ADDRESS_MEM_PREFETCH
?
1021 " prefetchable" : "";
1023 monitor_printf(mon
, "%s%s memory at 0x%08"FMT_PCIBUS
1024 " [0x%08"FMT_PCIBUS
"].\n",
1026 r
->addr
, r
->addr
+ r
->size
- 1);
1030 monitor_printf(mon
, " id \"%s\"\n", d
->qdev
.id
? d
->qdev
.id
: "");
1031 if (class == 0x0604 && d
->config
[0x19] != 0) {
1032 pci_for_each_device(bus
, d
->config
[0x19], pci_info_device
);
1036 static void pci_for_each_device_under_bus(PCIBus
*bus
,
1037 void (*fn
)(PCIBus
*b
, PCIDevice
*d
))
1042 for(devfn
= 0; devfn
< ARRAY_SIZE(bus
->devices
); devfn
++) {
1043 d
= bus
->devices
[devfn
];
1049 void pci_for_each_device(PCIBus
*bus
, int bus_num
,
1050 void (*fn
)(PCIBus
*b
, PCIDevice
*d
))
1052 bus
= pci_find_bus(bus
, bus_num
);
1055 pci_for_each_device_under_bus(bus
, fn
);
1059 void pci_info(Monitor
*mon
)
1061 struct PCIHostBus
*host
;
1062 QLIST_FOREACH(host
, &host_buses
, next
) {
1063 pci_for_each_device(host
->bus
, 0, pci_info_device
);
1067 static const char * const pci_nic_models
[] = {
1079 static const char * const pci_nic_names
[] = {
1091 /* Initialize a PCI NIC. */
1092 /* FIXME callers should check for failure, but don't */
1093 PCIDevice
*pci_nic_init(NICInfo
*nd
, const char *default_model
,
1094 const char *default_devaddr
)
1096 const char *devaddr
= nd
->devaddr
? nd
->devaddr
: default_devaddr
;
1103 i
= qemu_find_nic_model(nd
, pci_nic_models
, default_model
);
1107 bus
= pci_get_bus_devfn(&devfn
, devaddr
);
1109 qemu_error("Invalid PCI device address %s for device %s\n",
1110 devaddr
, pci_nic_names
[i
]);
1114 pci_dev
= pci_create(bus
, devfn
, pci_nic_names
[i
]);
1115 dev
= &pci_dev
->qdev
;
1117 dev
->id
= qemu_strdup(nd
->name
);
1118 qdev_set_nic_properties(dev
, nd
);
1119 if (qdev_init(dev
) < 0)
1124 PCIDevice
*pci_nic_init_nofail(NICInfo
*nd
, const char *default_model
,
1125 const char *default_devaddr
)
1129 if (qemu_show_nic_models(nd
->model
, pci_nic_models
))
1132 res
= pci_nic_init(nd
, default_model
, default_devaddr
);
1146 static void pci_bridge_update_mappings_fn(PCIBus
*b
, PCIDevice
*d
)
1148 pci_update_mappings(d
);
1151 static void pci_bridge_update_mappings(PCIBus
*b
)
1155 pci_for_each_device_under_bus(b
, pci_bridge_update_mappings_fn
);
1157 QLIST_FOREACH(child
, &b
->child
, sibling
) {
1158 pci_bridge_update_mappings(child
);
1162 static void pci_bridge_write_config(PCIDevice
*d
,
1163 uint32_t address
, uint32_t val
, int len
)
1165 pci_default_write_config(d
, address
, val
, len
);
1167 if (/* io base/limit */
1168 ranges_overlap(address
, len
, PCI_IO_BASE
, 2) ||
1170 /* memory base/limit, prefetchable base/limit and
1171 io base/limit upper 16 */
1172 ranges_overlap(address
, len
, PCI_MEMORY_BASE
, 20)) {
1173 pci_bridge_update_mappings(d
->bus
);
1177 PCIBus
*pci_find_bus(PCIBus
*bus
, int bus_num
)
1184 if (pci_bus_num(bus
) == bus_num
) {
1189 QLIST_FOREACH(sec
, &bus
->child
, sibling
) {
1191 if (!bus
->parent_dev
/* pci host bridge */
1192 || (pci_bus_num(sec
) <= bus_num
&&
1193 bus
->parent_dev
->config
[PCI_SUBORDINATE_BUS
])) {
1194 return pci_find_bus(sec
, bus_num
);
1201 PCIDevice
*pci_find_device(PCIBus
*bus
, int bus_num
, int slot
, int function
)
1203 bus
= pci_find_bus(bus
, bus_num
);
1208 return bus
->devices
[PCI_DEVFN(slot
, function
)];
1211 static int pci_bridge_initfn(PCIDevice
*dev
)
1213 PCIBridge
*s
= DO_UPCAST(PCIBridge
, dev
, dev
);
1215 pci_config_set_vendor_id(s
->dev
.config
, s
->vid
);
1216 pci_config_set_device_id(s
->dev
.config
, s
->did
);
1218 pci_set_word(dev
->config
+ PCI_STATUS
,
1219 PCI_STATUS_66MHZ
| PCI_STATUS_FAST_BACK
);
1220 pci_config_set_class(dev
->config
, PCI_CLASS_BRIDGE_PCI
);
1221 dev
->config
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_BRIDGE
;
1222 pci_set_word(dev
->config
+ PCI_SEC_STATUS
,
1223 PCI_STATUS_66MHZ
| PCI_STATUS_FAST_BACK
);
1227 static int pci_bridge_exitfn(PCIDevice
*pci_dev
)
1229 PCIBridge
*s
= DO_UPCAST(PCIBridge
, dev
, pci_dev
);
1230 PCIBus
*bus
= &s
->bus
;
1231 pci_unregister_secondary_bus(bus
);
1235 PCIBus
*pci_bridge_init(PCIBus
*bus
, int devfn
, uint16_t vid
, uint16_t did
,
1236 pci_map_irq_fn map_irq
, const char *name
)
1241 dev
= pci_create(bus
, devfn
, "pci-bridge");
1242 qdev_prop_set_uint32(&dev
->qdev
, "vendorid", vid
);
1243 qdev_prop_set_uint32(&dev
->qdev
, "deviceid", did
);
1244 qdev_init_nofail(&dev
->qdev
);
1246 s
= DO_UPCAST(PCIBridge
, dev
, dev
);
1247 pci_register_secondary_bus(bus
, &s
->bus
, &s
->dev
, map_irq
, name
);
1251 PCIDevice
*pci_bridge_get_device(PCIBus
*bus
)
1253 return bus
->parent_dev
;
1256 static int pci_qdev_init(DeviceState
*qdev
, DeviceInfo
*base
)
1258 PCIDevice
*pci_dev
= (PCIDevice
*)qdev
;
1259 PCIDeviceInfo
*info
= container_of(base
, PCIDeviceInfo
, qdev
);
1263 /* initialize cap_present for pci_is_express() and pci_config_size() */
1264 if (info
->is_express
) {
1265 pci_dev
->cap_present
|= QEMU_PCI_CAP_EXPRESS
;
1268 bus
= FROM_QBUS(PCIBus
, qdev_get_parent_bus(qdev
));
1269 devfn
= pci_dev
->devfn
;
1270 pci_dev
= do_pci_register_device(pci_dev
, bus
, base
->name
, devfn
,
1271 info
->config_read
, info
->config_write
,
1273 rc
= info
->init(pci_dev
);
1276 if (qdev
->hotplugged
)
1277 bus
->hotplug(pci_dev
, 1);
1281 static int pci_unplug_device(DeviceState
*qdev
)
1283 PCIDevice
*dev
= DO_UPCAST(PCIDevice
, qdev
, qdev
);
1285 dev
->bus
->hotplug(dev
, 0);
1289 void pci_qdev_register(PCIDeviceInfo
*info
)
1291 info
->qdev
.init
= pci_qdev_init
;
1292 info
->qdev
.unplug
= pci_unplug_device
;
1293 info
->qdev
.exit
= pci_unregister_device
;
1294 info
->qdev
.bus_info
= &pci_bus_info
;
1295 qdev_register(&info
->qdev
);
1298 void pci_qdev_register_many(PCIDeviceInfo
*info
)
1300 while (info
->qdev
.name
) {
1301 pci_qdev_register(info
);
1306 PCIDevice
*pci_create(PCIBus
*bus
, int devfn
, const char *name
)
1310 dev
= qdev_create(&bus
->qbus
, name
);
1311 qdev_prop_set_uint32(dev
, "addr", devfn
);
1312 return DO_UPCAST(PCIDevice
, qdev
, dev
);
1315 PCIDevice
*pci_create_simple(PCIBus
*bus
, int devfn
, const char *name
)
1317 PCIDevice
*dev
= pci_create(bus
, devfn
, name
);
1318 qdev_init_nofail(&dev
->qdev
);
1322 static int pci_find_space(PCIDevice
*pdev
, uint8_t size
)
1324 int config_size
= pci_config_size(pdev
);
1325 int offset
= PCI_CONFIG_HEADER_SIZE
;
1327 for (i
= PCI_CONFIG_HEADER_SIZE
; i
< config_size
; ++i
)
1330 else if (i
- offset
+ 1 == size
)
1335 static uint8_t pci_find_capability_list(PCIDevice
*pdev
, uint8_t cap_id
,
1340 if (!(pdev
->config
[PCI_STATUS
] & PCI_STATUS_CAP_LIST
))
1343 for (prev
= PCI_CAPABILITY_LIST
; (next
= pdev
->config
[prev
]);
1344 prev
= next
+ PCI_CAP_LIST_NEXT
)
1345 if (pdev
->config
[next
+ PCI_CAP_LIST_ID
] == cap_id
)
1353 /* Reserve space and add capability to the linked list in pci config space */
1354 int pci_add_capability(PCIDevice
*pdev
, uint8_t cap_id
, uint8_t size
)
1356 uint8_t offset
= pci_find_space(pdev
, size
);
1357 uint8_t *config
= pdev
->config
+ offset
;
1360 config
[PCI_CAP_LIST_ID
] = cap_id
;
1361 config
[PCI_CAP_LIST_NEXT
] = pdev
->config
[PCI_CAPABILITY_LIST
];
1362 pdev
->config
[PCI_CAPABILITY_LIST
] = offset
;
1363 pdev
->config
[PCI_STATUS
] |= PCI_STATUS_CAP_LIST
;
1364 memset(pdev
->used
+ offset
, 0xFF, size
);
1365 /* Make capability read-only by default */
1366 memset(pdev
->wmask
+ offset
, 0, size
);
1367 /* Check capability by default */
1368 memset(pdev
->cmask
+ offset
, 0xFF, size
);
1372 /* Unlink capability from the pci config space. */
1373 void pci_del_capability(PCIDevice
*pdev
, uint8_t cap_id
, uint8_t size
)
1375 uint8_t prev
, offset
= pci_find_capability_list(pdev
, cap_id
, &prev
);
1378 pdev
->config
[prev
] = pdev
->config
[offset
+ PCI_CAP_LIST_NEXT
];
1379 /* Make capability writeable again */
1380 memset(pdev
->wmask
+ offset
, 0xff, size
);
1381 /* Clear cmask as device-specific registers can't be checked */
1382 memset(pdev
->cmask
+ offset
, 0, size
);
1383 memset(pdev
->used
+ offset
, 0, size
);
1385 if (!pdev
->config
[PCI_CAPABILITY_LIST
])
1386 pdev
->config
[PCI_STATUS
] &= ~PCI_STATUS_CAP_LIST
;
1389 /* Reserve space for capability at a known offset (to call after load). */
1390 void pci_reserve_capability(PCIDevice
*pdev
, uint8_t offset
, uint8_t size
)
1392 memset(pdev
->used
+ offset
, 0xff, size
);
1395 uint8_t pci_find_capability(PCIDevice
*pdev
, uint8_t cap_id
)
1397 return pci_find_capability_list(pdev
, cap_id
, NULL
);
1400 static void pcibus_dev_print(Monitor
*mon
, DeviceState
*dev
, int indent
)
1402 PCIDevice
*d
= (PCIDevice
*)dev
;
1403 const pci_class_desc
*desc
;
1408 class = pci_get_word(d
->config
+ PCI_CLASS_DEVICE
);
1409 desc
= pci_class_descriptions
;
1410 while (desc
->desc
&& class != desc
->class)
1413 snprintf(ctxt
, sizeof(ctxt
), "%s", desc
->desc
);
1415 snprintf(ctxt
, sizeof(ctxt
), "Class %04x", class);
1418 monitor_printf(mon
, "%*sclass %s, addr %02x:%02x.%x, "
1419 "pci id %04x:%04x (sub %04x:%04x)\n",
1421 d
->config
[PCI_SECONDARY_BUS
],
1422 PCI_SLOT(d
->devfn
), PCI_FUNC(d
->devfn
),
1423 pci_get_word(d
->config
+ PCI_VENDOR_ID
),
1424 pci_get_word(d
->config
+ PCI_DEVICE_ID
),
1425 pci_get_word(d
->config
+ PCI_SUBSYSTEM_VENDOR_ID
),
1426 pci_get_word(d
->config
+ PCI_SUBSYSTEM_ID
));
1427 for (i
= 0; i
< PCI_NUM_REGIONS
; i
++) {
1428 r
= &d
->io_regions
[i
];
1431 monitor_printf(mon
, "%*sbar %d: %s at 0x%"FMT_PCIBUS
1432 " [0x%"FMT_PCIBUS
"]\n",
1434 i
, r
->type
& PCI_BASE_ADDRESS_SPACE_IO
? "i/o" : "mem",
1435 r
->addr
, r
->addr
+ r
->size
- 1);
1439 static PCIDeviceInfo bridge_info
= {
1440 .qdev
.name
= "pci-bridge",
1441 .qdev
.size
= sizeof(PCIBridge
),
1442 .init
= pci_bridge_initfn
,
1443 .exit
= pci_bridge_exitfn
,
1444 .config_write
= pci_bridge_write_config
,
1445 .qdev
.props
= (Property
[]) {
1446 DEFINE_PROP_HEX32("vendorid", PCIBridge
, vid
, 0),
1447 DEFINE_PROP_HEX32("deviceid", PCIBridge
, did
, 0),
1448 DEFINE_PROP_END_OF_LIST(),
1452 static void pci_register_devices(void)
1454 pci_qdev_register(&bridge_info
);
1457 device_init(pci_register_devices
)