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
28 #include "virtio-net.h"
32 #include "device-assignment.h"
39 pci_set_irq_fn set_irq
;
40 pci_map_irq_fn map_irq
;
41 uint32_t config_reg
; /* XXX: suppress */
43 SetIRQFunc
*low_set_irq
;
45 PCIDevice
*devices
[256];
46 PCIDevice
*parent_dev
;
48 /* The bus IRQ state is the logical OR of the connected devices.
49 Keep a count of the number of devices with raised IRQs. */
54 static void pci_update_mappings(PCIDevice
*d
);
55 static void pci_set_irq(void *opaque
, int irq_num
, int level
);
57 target_phys_addr_t pci_mem_base
;
58 static uint16_t pci_default_sub_vendor_id
= PCI_SUBVENDOR_ID_REDHAT_QUMRANET
;
59 static uint16_t pci_default_sub_device_id
= PCI_SUBDEVICE_ID_QEMU
;
60 static int pci_irq_index
;
61 static PCIBus
*first_bus
;
63 static void pcibus_save(QEMUFile
*f
, void *opaque
)
65 PCIBus
*bus
= (PCIBus
*)opaque
;
68 qemu_put_be32(f
, bus
->nirq
);
69 for (i
= 0; i
< bus
->nirq
; i
++)
70 qemu_put_be32(f
, bus
->irq_count
[i
]);
73 static int pcibus_load(QEMUFile
*f
, void *opaque
, int version_id
)
75 PCIBus
*bus
= (PCIBus
*)opaque
;
81 nirq
= qemu_get_be32(f
);
82 if (bus
->nirq
!= nirq
) {
83 fprintf(stderr
, "pcibus_load: nirq mismatch: src=%d dst=%d\n",
88 for (i
= 0; i
< nirq
; i
++)
89 bus
->irq_count
[i
] = qemu_get_be32(f
);
94 PCIBus
*pci_register_bus(pci_set_irq_fn set_irq
, pci_map_irq_fn map_irq
,
95 qemu_irq
*pic
, int devfn_min
, int nirq
)
100 bus
= qemu_mallocz(sizeof(PCIBus
) + (nirq
* sizeof(int)));
101 bus
->set_irq
= set_irq
;
102 bus
->map_irq
= map_irq
;
103 bus
->irq_opaque
= pic
;
104 bus
->devfn_min
= devfn_min
;
107 register_savevm("PCIBUS", nbus
++, 1, pcibus_save
, pcibus_load
, bus
);
111 static PCIBus
*pci_register_secondary_bus(PCIDevice
*dev
, pci_map_irq_fn map_irq
)
114 bus
= qemu_mallocz(sizeof(PCIBus
));
115 bus
->map_irq
= map_irq
;
116 bus
->parent_dev
= dev
;
117 bus
->next
= dev
->bus
->next
;
118 dev
->bus
->next
= bus
;
122 int pci_bus_num(PCIBus
*s
)
127 void pci_device_save(PCIDevice
*s
, QEMUFile
*f
)
131 qemu_put_be32(f
, 2); /* PCI device version */
132 qemu_put_buffer(f
, s
->config
, 256);
133 for (i
= 0; i
< 4; i
++)
134 qemu_put_be32(f
, s
->irq_state
[i
]);
137 int pci_device_load(PCIDevice
*s
, QEMUFile
*f
)
142 version_id
= qemu_get_be32(f
);
145 qemu_get_buffer(f
, s
->config
, 256);
146 pci_update_mappings(s
);
149 for (i
= 0; i
< 4; i
++)
150 s
->irq_state
[i
] = qemu_get_be32(f
);
155 static int pci_set_default_subsystem_id(PCIDevice
*pci_dev
)
159 id
= (void*)(&pci_dev
->config
[PCI_SUBVENDOR_ID
]);
160 id
[0] = cpu_to_le16(pci_default_sub_vendor_id
);
161 id
[1] = cpu_to_le16(pci_default_sub_device_id
);
166 * Parse pci address in qemu command
167 * Parse [[<domain>:]<bus>:]<slot>, return -1 on error
169 static int pci_parse_devaddr(const char *addr
, int *domp
, int *busp
, unsigned *slotp
)
174 unsigned long dom
= 0, bus
= 0;
178 val
= strtoul(p
, &e
, 16);
184 val
= strtoul(p
, &e
, 16);
191 val
= strtoul(p
, &e
, 16);
197 if (dom
> 0xffff || bus
> 0xff || val
> 0x1f)
205 /* Note: QEMU doesn't implement domains other than 0 */
206 if (dom
!= 0 || pci_find_bus(bus
) == NULL
)
216 * Parse device bdf in device assignment command:
218 * -pcidevice host=bus:dev.func
220 * Parse <bus>:<slot>.<func> return -1 on error
222 int pci_parse_host_devaddr(const char *addr
, int *busp
,
223 int *slotp
, int *funcp
)
228 int bus
= 0, slot
= 0, func
= 0;
231 val
= strtoul(p
, &e
, 16);
237 val
= strtoul(p
, &e
, 16);
243 val
= strtoul(p
, &e
, 16);
252 if (bus
> 0xff || slot
> 0x1f || func
> 0x7)
264 int pci_read_devaddr(const char *addr
, int *domp
, int *busp
, unsigned *slotp
)
268 if (!get_param_value(devaddr
, sizeof(devaddr
), "pci_addr", addr
))
271 return pci_parse_devaddr(devaddr
, domp
, busp
, slotp
);
274 int pci_assign_devaddr(const char *addr
, int *domp
, int *busp
, unsigned *slotp
)
278 if (!get_param_value(devaddr
, sizeof(devaddr
), "pci_addr", addr
))
281 if (!strcmp(devaddr
, "auto")) {
284 /* want to support dom/bus auto-assign at some point */
288 return pci_parse_devaddr(devaddr
, domp
, busp
, slotp
);
291 /* -1 for devfn means auto assign */
292 PCIDevice
*pci_register_device(PCIBus
*bus
, const char *name
,
293 int instance_size
, int devfn
,
294 PCIConfigReadFunc
*config_read
,
295 PCIConfigWriteFunc
*config_write
)
299 if (pci_irq_index
>= PCI_DEVICES_MAX
)
303 for(devfn
= bus
->devfn_min
; devfn
< 256; devfn
+= 8) {
304 if (!bus
->devices
[devfn
])
310 pci_dev
= qemu_mallocz(instance_size
);
312 pci_dev
->devfn
= devfn
;
313 pstrcpy(pci_dev
->name
, sizeof(pci_dev
->name
), name
);
314 memset(pci_dev
->irq_state
, 0, sizeof(pci_dev
->irq_state
));
315 pci_set_default_subsystem_id(pci_dev
);
318 config_read
= pci_default_read_config
;
320 config_write
= pci_default_write_config
;
321 pci_dev
->config_read
= config_read
;
322 pci_dev
->config_write
= config_write
;
323 pci_dev
->irq_index
= pci_irq_index
++;
324 bus
->devices
[devfn
] = pci_dev
;
325 pci_dev
->irq
= qemu_allocate_irqs(pci_set_irq
, pci_dev
, 4);
329 static target_phys_addr_t
pci_to_cpu_addr(target_phys_addr_t addr
)
331 return addr
+ pci_mem_base
;
334 static void pci_unregister_io_regions(PCIDevice
*pci_dev
)
339 for(i
= 0; i
< PCI_NUM_REGIONS
; i
++) {
340 r
= &pci_dev
->io_regions
[i
];
341 if (!r
->size
|| r
->addr
== -1)
343 if (r
->type
== PCI_ADDRESS_SPACE_IO
) {
344 isa_unassign_ioport(r
->addr
, r
->size
);
346 cpu_register_physical_memory(pci_to_cpu_addr(r
->addr
),
353 int pci_unregister_device(PCIDevice
*pci_dev
)
357 if (pci_dev
->unregister
)
358 ret
= pci_dev
->unregister(pci_dev
);
362 pci_unregister_io_regions(pci_dev
);
364 qemu_free_irqs(pci_dev
->irq
);
366 pci_dev
->bus
->devices
[pci_dev
->devfn
] = NULL
;
371 void pci_register_io_region(PCIDevice
*pci_dev
, int region_num
,
372 uint32_t size
, int type
,
373 PCIMapIORegionFunc
*map_func
)
378 if ((unsigned int)region_num
>= PCI_NUM_REGIONS
)
381 if (size
& (size
-1)) {
382 fprintf(stderr
, "ERROR: PCI region size must be pow2 "
383 "type=0x%x, size=0x%x\n", type
, size
);
387 r
= &pci_dev
->io_regions
[region_num
];
391 r
->map_func
= map_func
;
392 if (region_num
== PCI_ROM_SLOT
) {
395 addr
= 0x10 + region_num
* 4;
397 *(uint32_t *)(pci_dev
->config
+ addr
) = cpu_to_le32(type
);
400 static void pci_update_mappings(PCIDevice
*d
)
404 uint32_t last_addr
, new_addr
, config_ofs
;
406 cmd
= le16_to_cpu(*(uint16_t *)(d
->config
+ PCI_COMMAND
));
407 for(i
= 0; i
< PCI_NUM_REGIONS
; i
++) {
408 r
= &d
->io_regions
[i
];
409 if (i
== PCI_ROM_SLOT
) {
412 config_ofs
= 0x10 + i
* 4;
415 if (r
->type
& PCI_ADDRESS_SPACE_IO
) {
416 if (cmd
& PCI_COMMAND_IO
) {
417 new_addr
= le32_to_cpu(*(uint32_t *)(d
->config
+
419 new_addr
= new_addr
& ~(r
->size
- 1);
420 last_addr
= new_addr
+ r
->size
- 1;
421 /* NOTE: we have only 64K ioports on PC */
422 if (last_addr
<= new_addr
|| new_addr
== 0 ||
423 last_addr
>= 0x10000) {
430 if (cmd
& PCI_COMMAND_MEMORY
) {
431 new_addr
= le32_to_cpu(*(uint32_t *)(d
->config
+
433 /* the ROM slot has a specific enable bit */
434 if (i
== PCI_ROM_SLOT
&& !(new_addr
& 1))
436 new_addr
= new_addr
& ~(r
->size
- 1);
437 last_addr
= new_addr
+ r
->size
- 1;
438 /* NOTE: we do not support wrapping */
439 /* XXX: as we cannot support really dynamic
440 mappings, we handle specific values as invalid
442 if (last_addr
<= new_addr
|| new_addr
== 0 ||
451 /* now do the real mapping */
452 if (new_addr
!= r
->addr
) {
454 if (r
->type
& PCI_ADDRESS_SPACE_IO
) {
456 /* NOTE: specific hack for IDE in PC case:
457 only one byte must be mapped. */
458 class = d
->config
[0x0a] | (d
->config
[0x0b] << 8);
459 if (class == 0x0101 && r
->size
== 4) {
460 isa_unassign_ioport(r
->addr
+ 2, 1);
462 isa_unassign_ioport(r
->addr
, r
->size
);
465 cpu_register_physical_memory(pci_to_cpu_addr(r
->addr
),
468 qemu_unregister_coalesced_mmio(r
->addr
, r
->size
);
473 r
->map_func(d
, i
, r
->addr
, r
->size
, r
->type
);
480 static uint32_t pci_read_config(PCIDevice
*d
,
481 uint32_t address
, int len
)
488 if (address
<= 0xfc) {
489 val
= le32_to_cpu(*(uint32_t *)(d
->config
+ address
));
494 if (address
<= 0xfe) {
495 val
= le16_to_cpu(*(uint16_t *)(d
->config
+ address
));
500 val
= d
->config
[address
];
506 static void pci_write_config(PCIDevice
*pci_dev
,
507 uint32_t address
, uint32_t val
, int len
)
510 for (i
= 0; i
< len
; i
++) {
511 pci_dev
->config
[address
+ i
] = val
& 0xff;
516 int pci_access_cap_config(PCIDevice
*pci_dev
, uint32_t address
, int len
)
518 if (pci_dev
->cap
.supported
&& address
>= pci_dev
->cap
.start
&&
519 (address
+ len
) < pci_dev
->cap
.start
+ pci_dev
->cap
.length
)
524 uint32_t pci_default_cap_read_config(PCIDevice
*pci_dev
,
525 uint32_t address
, int len
)
527 return pci_read_config(pci_dev
, address
, len
);
530 void pci_default_cap_write_config(PCIDevice
*pci_dev
,
531 uint32_t address
, uint32_t val
, int len
)
533 pci_write_config(pci_dev
, address
, val
, len
);
536 uint32_t pci_default_read_config(PCIDevice
*d
,
537 uint32_t address
, int len
)
539 if (pci_access_cap_config(d
, address
, len
))
540 return d
->cap
.config_read(d
, address
, len
);
542 return pci_read_config(d
, address
, len
);
545 void pci_default_write_config(PCIDevice
*d
,
546 uint32_t address
, uint32_t val
, int len
)
551 if (len
== 4 && ((address
>= 0x10 && address
< 0x10 + 4 * 6) ||
552 (address
>= 0x30 && address
< 0x34))) {
556 if ( address
>= 0x30 ) {
559 reg
= (address
- 0x10) >> 2;
561 r
= &d
->io_regions
[reg
];
564 /* compute the stored value */
565 if (reg
== PCI_ROM_SLOT
) {
566 /* keep ROM enable bit */
567 val
&= (~(r
->size
- 1)) | 1;
569 val
&= ~(r
->size
- 1);
572 *(uint32_t *)(d
->config
+ address
) = cpu_to_le32(val
);
573 pci_update_mappings(d
);
577 if (pci_access_cap_config(d
, address
, len
)) {
578 d
->cap
.config_write(d
, address
, val
, len
);
582 /* not efficient, but simple */
584 for(i
= 0; i
< len
; i
++) {
585 /* default read/write accesses */
586 switch(d
->config
[0x0e]) {
599 case 0x10 ... 0x27: /* base */
600 case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */
601 case 0x30 ... 0x33: /* rom */
622 case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */
623 case 0x38 ... 0x3b: /* rom */
634 /* Mask out writes to reserved bits in registers */
637 val
&= ~PCI_COMMAND_RESERVED_MASK_HI
;
640 val
&= ~PCI_STATUS_RESERVED_MASK_LO
;
643 val
&= ~PCI_STATUS_RESERVED_MASK_HI
;
646 d
->config
[addr
] = val
;
653 #ifdef USE_KVM_DEVICE_ASSIGNMENT
654 if (kvm_enabled() && qemu_kvm_irqchip_in_kernel() &&
655 address
>= PIIX_CONFIG_IRQ_ROUTE
&&
656 address
< PIIX_CONFIG_IRQ_ROUTE
+ 4)
657 assigned_dev_update_irqs();
658 #endif /* USE_KVM_DEVICE_ASSIGNMENT */
661 if (end
> PCI_COMMAND
&& address
< (PCI_COMMAND
+ 2)) {
662 /* if the command register is modified, we must modify the mappings */
663 pci_update_mappings(d
);
667 void pci_data_write(void *opaque
, uint32_t addr
, uint32_t val
, int len
)
671 int config_addr
, bus_num
;
673 #if defined(DEBUG_PCI) && 0
674 printf("pci_data_write: addr=%08x val=%08x len=%d\n",
677 bus_num
= (addr
>> 16) & 0xff;
678 while (s
&& s
->bus_num
!= bus_num
)
682 pci_dev
= s
->devices
[(addr
>> 8) & 0xff];
685 config_addr
= addr
& 0xff;
686 #if defined(DEBUG_PCI)
687 printf("pci_config_write: %s: addr=%02x val=%08x len=%d\n",
688 pci_dev
->name
, config_addr
, val
, len
);
690 pci_dev
->config_write(pci_dev
, config_addr
, val
, len
);
693 uint32_t pci_data_read(void *opaque
, uint32_t addr
, int len
)
697 int config_addr
, bus_num
;
700 bus_num
= (addr
>> 16) & 0xff;
701 while (s
&& s
->bus_num
!= bus_num
)
705 pci_dev
= s
->devices
[(addr
>> 8) & 0xff];
722 config_addr
= addr
& 0xff;
723 val
= pci_dev
->config_read(pci_dev
, config_addr
, len
);
724 #if defined(DEBUG_PCI)
725 printf("pci_config_read: %s: addr=%02x val=%08x len=%d\n",
726 pci_dev
->name
, config_addr
, val
, len
);
729 #if defined(DEBUG_PCI) && 0
730 printf("pci_data_read: addr=%08x val=%08x len=%d\n",
736 /***********************************************************/
737 /* generic PCI irq support */
739 /* 0 <= irq_num <= 3. level must be 0 or 1 */
740 static void pci_set_irq(void *opaque
, int irq_num
, int level
)
742 PCIDevice
*pci_dev
= (PCIDevice
*)opaque
;
746 change
= level
- pci_dev
->irq_state
[irq_num
];
750 pci_dev
->irq_state
[irq_num
] = level
;
752 #if defined(TARGET_IA64)
753 ioapic_set_irq(pci_dev
, irq_num
, level
);
758 irq_num
= bus
->map_irq(pci_dev
, irq_num
);
761 pci_dev
= bus
->parent_dev
;
763 bus
->irq_count
[irq_num
] += change
;
764 bus
->set_irq(bus
->irq_opaque
, irq_num
, bus
->irq_count
[irq_num
] != 0);
767 int pci_map_irq(PCIDevice
*pci_dev
, int pin
)
769 return pci_dev
->bus
->map_irq(pci_dev
, pin
);
772 /***********************************************************/
773 /* monitor info on PCI */
780 static const pci_class_desc pci_class_descriptions
[] =
782 { 0x0100, "SCSI controller"},
783 { 0x0101, "IDE controller"},
784 { 0x0102, "Floppy controller"},
785 { 0x0103, "IPI controller"},
786 { 0x0104, "RAID controller"},
787 { 0x0106, "SATA controller"},
788 { 0x0107, "SAS controller"},
789 { 0x0180, "Storage controller"},
790 { 0x0200, "Ethernet controller"},
791 { 0x0201, "Token Ring controller"},
792 { 0x0202, "FDDI controller"},
793 { 0x0203, "ATM controller"},
794 { 0x0280, "Network controller"},
795 { 0x0300, "VGA controller"},
796 { 0x0301, "XGA controller"},
797 { 0x0302, "3D controller"},
798 { 0x0380, "Display controller"},
799 { 0x0400, "Video controller"},
800 { 0x0401, "Audio controller"},
802 { 0x0480, "Multimedia controller"},
803 { 0x0500, "RAM controller"},
804 { 0x0501, "Flash controller"},
805 { 0x0580, "Memory controller"},
806 { 0x0600, "Host bridge"},
807 { 0x0601, "ISA bridge"},
808 { 0x0602, "EISA bridge"},
809 { 0x0603, "MC bridge"},
810 { 0x0604, "PCI bridge"},
811 { 0x0605, "PCMCIA bridge"},
812 { 0x0606, "NUBUS bridge"},
813 { 0x0607, "CARDBUS bridge"},
814 { 0x0608, "RACEWAY bridge"},
816 { 0x0c03, "USB controller"},
820 static void pci_info_device(PCIDevice
*d
)
822 Monitor
*mon
= cur_mon
;
825 const pci_class_desc
*desc
;
827 monitor_printf(mon
, " Bus %2d, device %3d, function %d:\n",
828 d
->bus
->bus_num
, d
->devfn
>> 3, d
->devfn
& 7);
829 class = le16_to_cpu(*((uint16_t *)(d
->config
+ PCI_CLASS_DEVICE
)));
830 monitor_printf(mon
, " ");
831 desc
= pci_class_descriptions
;
832 while (desc
->desc
&& class != desc
->class)
835 monitor_printf(mon
, "%s", desc
->desc
);
837 monitor_printf(mon
, "Class %04x", class);
839 monitor_printf(mon
, ": PCI device %04x:%04x\n",
840 le16_to_cpu(*((uint16_t *)(d
->config
+ PCI_VENDOR_ID
))),
841 le16_to_cpu(*((uint16_t *)(d
->config
+ PCI_DEVICE_ID
))));
843 if (d
->config
[PCI_INTERRUPT_PIN
] != 0) {
844 monitor_printf(mon
, " IRQ %d.\n",
845 d
->config
[PCI_INTERRUPT_LINE
]);
847 if (class == 0x0604) {
848 monitor_printf(mon
, " BUS %d.\n", d
->config
[0x19]);
850 for(i
= 0;i
< PCI_NUM_REGIONS
; i
++) {
851 r
= &d
->io_regions
[i
];
853 monitor_printf(mon
, " BAR%d: ", i
);
854 if (r
->type
& PCI_ADDRESS_SPACE_IO
) {
855 monitor_printf(mon
, "I/O at 0x%04x [0x%04x].\n",
856 r
->addr
, r
->addr
+ r
->size
- 1);
858 monitor_printf(mon
, "32 bit memory at 0x%08x [0x%08x].\n",
859 r
->addr
, r
->addr
+ r
->size
- 1);
863 if (class == 0x0604 && d
->config
[0x19] != 0) {
864 pci_for_each_device(d
->config
[0x19], pci_info_device
);
868 void pci_for_each_device(int bus_num
, void (*fn
)(PCIDevice
*d
))
870 PCIBus
*bus
= first_bus
;
874 while (bus
&& bus
->bus_num
!= bus_num
)
877 for(devfn
= 0; devfn
< 256; devfn
++) {
878 d
= bus
->devices
[devfn
];
885 void pci_info(Monitor
*mon
)
887 pci_for_each_device(0, pci_info_device
);
890 static const char * const pci_nic_models
[] = {
902 typedef PCIDevice
*(*PCINICInitFn
)(PCIBus
*, NICInfo
*, int);
904 static PCINICInitFn pci_nic_init_fns
[] = {
916 /* Initialize a PCI NIC. */
917 PCIDevice
*pci_nic_init(PCIBus
*bus
, NICInfo
*nd
, int devfn
,
918 const char *default_model
)
923 qemu_check_nic_model_list(nd
, pci_nic_models
, default_model
);
925 for (i
= 0; pci_nic_models
[i
]; i
++)
926 if (strcmp(nd
->model
, pci_nic_models
[i
]) == 0) {
927 pci_dev
= pci_nic_init_fns
[i
](bus
, nd
, devfn
);
929 nd
->private = pci_dev
;
941 static void pci_bridge_write_config(PCIDevice
*d
,
942 uint32_t address
, uint32_t val
, int len
)
944 PCIBridge
*s
= (PCIBridge
*)d
;
946 if (address
== 0x19 || (address
== 0x18 && len
> 1)) {
948 s
->bus
->bus_num
= val
& 0xff;
950 s
->bus
->bus_num
= (val
>> 8) & 0xff;
951 #if defined(DEBUG_PCI)
952 printf ("pci-bridge: %s: Assigned bus %d\n", d
->name
, s
->bus
->bus_num
);
955 pci_default_write_config(d
, address
, val
, len
);
958 PCIBus
*pci_find_bus(int bus_num
)
960 PCIBus
*bus
= first_bus
;
962 while (bus
&& bus
->bus_num
!= bus_num
)
968 PCIDevice
*pci_find_device(int bus_num
, int slot
, int function
)
970 PCIBus
*bus
= pci_find_bus(bus_num
);
975 return bus
->devices
[PCI_DEVFN(slot
, function
)];
978 PCIBus
*pci_bridge_init(PCIBus
*bus
, int devfn
, uint16_t vid
, uint16_t did
,
979 pci_map_irq_fn map_irq
, const char *name
)
982 s
= (PCIBridge
*)pci_register_device(bus
, name
, sizeof(PCIBridge
),
983 devfn
, NULL
, pci_bridge_write_config
);
985 pci_config_set_vendor_id(s
->dev
.config
, vid
);
986 pci_config_set_device_id(s
->dev
.config
, did
);
988 s
->dev
.config
[0x04] = 0x06; // command = bus master, pci mem
989 s
->dev
.config
[0x05] = 0x00;
990 s
->dev
.config
[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
991 s
->dev
.config
[0x07] = 0x00; // status = fast devsel
992 s
->dev
.config
[0x08] = 0x00; // revision
993 s
->dev
.config
[0x09] = 0x00; // programming i/f
994 pci_config_set_class(s
->dev
.config
, PCI_CLASS_BRIDGE_PCI
);
995 s
->dev
.config
[0x0D] = 0x10; // latency_timer
996 s
->dev
.config
[0x0E] = 0x81; // header_type
997 s
->dev
.config
[0x1E] = 0xa0; // secondary status
999 s
->bus
= pci_register_secondary_bus(&s
->dev
, map_irq
);
1003 int pci_enable_capability_support(PCIDevice
*pci_dev
,
1004 uint32_t config_start
,
1005 PCICapConfigReadFunc
*config_read
,
1006 PCICapConfigWriteFunc
*config_write
,
1007 PCICapConfigInitFunc
*config_init
)
1012 pci_dev
->config
[0x06] |= 0x10; // status = capabilities
1014 if (config_start
== 0)
1015 pci_dev
->cap
.start
= PCI_CAPABILITY_CONFIG_DEFAULT_START_ADDR
;
1016 else if (config_start
>= 0x40 && config_start
< 0xff)
1017 pci_dev
->cap
.start
= config_start
;
1022 pci_dev
->cap
.config_read
= config_read
;
1024 pci_dev
->cap
.config_read
= pci_default_cap_read_config
;
1026 pci_dev
->cap
.config_write
= config_write
;
1028 pci_dev
->cap
.config_write
= pci_default_cap_write_config
;
1029 pci_dev
->cap
.supported
= 1;
1030 pci_dev
->config
[PCI_CAPABILITY_LIST
] = pci_dev
->cap
.start
;
1031 return config_init(pci_dev
);