Some additional PCI code cleanup - most notable is the first patch which adds a '%pP' modifier to the 'printf' code for outputting 'struct pci_device' pointers.
This series is on top of the previous series; it is also at:
https://github.com/KevinOConnor/seabios/tree/testing
-Kevin
Kevin O'Connor (4): pci: Implement '%pP' printf handler for 'struct pci_device' pointers pci: Move code in pci.c that is specific to pciinit.c to pciinit.c pci: Split low-level pci code from higher-level 'struct pci_device' code scsi: Always use MAXDESCSIZE when building drive description
Makefile | 2 +- src/boot.c | 1 + src/fw/acpi.c | 2 +- src/fw/coreboot.c | 2 +- src/fw/csm.c | 3 +- src/fw/mptable.c | 5 +- src/fw/mtrr.c | 1 - src/fw/paravirt.c | 3 +- src/fw/pciinit.c | 63 ++++++++--- src/fw/smm.c | 1 + src/hw/ahci.c | 8 +- src/hw/ata.c | 3 +- src/hw/esp-scsi.c | 10 +- src/hw/floppy.c | 2 +- src/hw/lsi-scsi.c | 10 +- src/hw/megasas.c | 12 +-- src/hw/pci.c | 241 +----------------------------------------- src/hw/pci.h | 104 ++---------------- src/hw/{pci.c => pcidevice.c} | 137 +----------------------- src/hw/{pci.h => pcidevice.h} | 71 ++----------- src/hw/pvscsi.c | 10 +- src/hw/sdcard.c | 2 +- src/hw/usb-ehci.c | 6 +- src/hw/usb-ohci.c | 6 +- src/hw/usb-uhci.c | 7 +- src/hw/usb-xhci.c | 9 +- src/hw/virtio-blk.c | 41 +++---- src/hw/virtio-pci.c | 12 +-- src/hw/virtio-scsi.c | 15 +-- src/optionroms.c | 22 ++-- src/output.c | 19 ++++ src/pcibios.c | 1 + src/util.h | 2 + src/vgahooks.c | 3 +- 34 files changed, 173 insertions(+), 663 deletions(-) copy src/hw/{pci.c => pcidevice.c} (64%) copy src/hw/{pci.h => pcidevice.h} (59%)
Handle '%pP' format descriptions as a pointer to a 'struct pci_device' and display it in bus:device.function (%02x:%02x.%x) format.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/fw/pciinit.c | 25 +++++++++---------------- src/hw/ahci.c | 5 ++--- src/hw/esp-scsi.c | 8 ++------ src/hw/lsi-scsi.c | 8 ++------ src/hw/megasas.c | 8 ++------ src/hw/pci.c | 6 ++---- src/hw/pvscsi.c | 8 ++------ src/hw/usb-ehci.c | 4 +--- src/hw/usb-ohci.c | 4 +--- src/hw/usb-uhci.c | 4 +--- src/hw/usb-xhci.c | 7 +++---- src/hw/virtio-blk.c | 39 ++++++++++++++------------------------- src/hw/virtio-pci.c | 11 ++++------- src/hw/virtio-scsi.c | 13 ++++--------- src/optionroms.c | 19 +++++++------------ src/output.c | 18 ++++++++++++++++++ 16 files changed, 74 insertions(+), 113 deletions(-)
diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 6b1c902..8e6716d 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -306,12 +306,11 @@ void pci_resume(void)
static void pci_bios_init_device(struct pci_device *pci) { - u16 bdf = pci->bdf; - dprintf(1, "PCI: init bdf=%02x:%02x.%x id=%04x:%04x\n" - , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf) - , pci->vendor, pci->device); + dprintf(1, "PCI: init bdf=%pP id=%04x:%04x\n" + , pci, pci->vendor, pci->device);
/* map the interrupt */ + u16 bdf = pci->bdf; int pin = pci_config_readb(bdf, PCI_INTERRUPT_PIN); if (pin != 0) pci_config_writeb(bdf, PCI_INTERRUPT_LINE, pci_slot_get_irq(pci, pin)); @@ -341,9 +340,7 @@ static void pci_enable_default_vga(void)
foreachpci(pci) { if (is_pci_vga(pci)) { - dprintf(1, "PCI: Using %02x:%02x.%x for primary VGA\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf)); + dprintf(1, "PCI: Using %pP for primary VGA\n", pci); return; } } @@ -354,9 +351,7 @@ static void pci_enable_default_vga(void) return; }
- dprintf(1, "PCI: Enabling %02x:%02x.%x for primary VGA\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf)); + dprintf(1, "PCI: Enabling %pP for primary VGA\n", pci);
pci_config_maskw(pci->bdf, PCI_COMMAND, 0, PCI_COMMAND_IO | PCI_COMMAND_MEMORY); @@ -364,9 +359,7 @@ static void pci_enable_default_vga(void) while (pci->parent) { pci = pci->parent;
- dprintf(1, "PCI: Setting VGA enable on bridge %02x:%02x.%x\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf)); + dprintf(1, "PCI: Setting VGA enable on bridge %pP\n", pci);
pci_config_maskw(pci->bdf, PCI_BRIDGE_CONTROL, 0, PCI_BRIDGE_CTL_VGA); pci_config_maskw(pci->bdf, PCI_COMMAND, 0, @@ -821,17 +814,17 @@ static int pci_bios_init_root_regions_mem(struct pci_bus *bus) static void pci_region_map_one_entry(struct pci_region_entry *entry, u64 addr) { - u16 bdf = entry->dev->bdf; if (entry->bar >= 0) { - dprintf(1, "PCI: map device bdf=%02x:%02x.%x" + dprintf(1, "PCI: map device bdf=%pP" " bar %d, addr %08llx, size %08llx [%s]\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf), + entry->dev, entry->bar, addr, entry->size, region_type_name[entry->type]);
pci_set_io_region_addr(entry->dev, entry->bar, addr, entry->is64); return; }
+ u16 bdf = entry->dev->bdf; u64 limit = addr + entry->size - 1; if (entry->type == PCI_REGION_TYPE_IO) { pci_config_writeb(bdf, PCI_IO_BASE, addr >> PCI_IO_SHIFT); diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 5401cca..bd21bf6 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -584,9 +584,8 @@ ahci_controller_setup(struct pci_device *pci) ctrl->pci_tmp = pci; ctrl->iobase = iobase; ctrl->irq = pci_config_readb(pci->bdf, PCI_INTERRUPT_LINE); - dprintf(1, "AHCI controller at %02x:%02x.%x, iobase %p, irq %d\n" - , pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf) - , pci_bdf_to_fn(pci->bdf), ctrl->iobase, ctrl->irq); + dprintf(1, "AHCI controller at %pP, iobase %p, irq %d\n" + , pci, ctrl->iobase, ctrl->irq);
pci_enable_busmaster(pci);
diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index cf2cc11..9abc361 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -168,9 +168,7 @@ esp_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) llun->lun = lun; llun->iobase = iobase;
- char *name = znprintf(16, "esp %02x:%02x.%x %d:%d", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), target, lun); + char *name = znprintf(16, "esp %pP %d:%d", pci, target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); int ret = scsi_drive_setup(&llun->drive, name, prio); free(name); @@ -197,9 +195,7 @@ init_esp_scsi(struct pci_device *pci) return; pci_enable_busmaster(pci);
- dprintf(1, "found esp at %02x:%02x.%x, io @ %x\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), iobase); + dprintf(1, "found esp at %pP, io @ %x\n", pci, iobase);
// reset outb(ESP_CMD_RESET, iobase + ESP_CMD); diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 2629b5f..5d872a2 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -147,9 +147,7 @@ lsi_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) llun->lun = lun; llun->iobase = iobase;
- char *name = znprintf(16, "lsi %02x:%02x.%x %d:%d", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), target, lun); + char *name = znprintf(16, "lsi %pP %d:%d", pci, target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); int ret = scsi_drive_setup(&llun->drive, name, prio); free(name); @@ -177,9 +175,7 @@ init_lsi_scsi(struct pci_device *pci) return; pci_enable_busmaster(pci);
- dprintf(1, "found lsi53c895a at %02x:%02x.%x, io @ %x\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), iobase); + dprintf(1, "found lsi53c895a at %pP, io @ %x\n", pci, iobase);
// reset outb(LSI_ISTAT0_SRST, iobase + LSI_REG_ISTAT0); diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 31426e7..71af3c3 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -224,9 +224,7 @@ megasas_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) free(mlun); return -1; } - name = znprintf(36, "MegaRAID SAS (PCI %02x:%02x.%x) LD %d:%d", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), target, lun); + name = znprintf(36, "MegaRAID SAS (PCI %pP) LD %d:%d", pci, target, lun); prio = bootprio_find_scsi_device(pci, target, lun); ret = scsi_drive_setup(&mlun->drive, name, prio); free(name); @@ -367,9 +365,7 @@ init_megasas(struct pci_device *pci) return; pci_enable_busmaster(pci);
- dprintf(1, "found MegaRAID SAS at %02x:%02x.%x, io @ %x\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), iobase); + dprintf(1, "found MegaRAID SAS at %pP, io @ %x\n", pci, iobase);
// reset if (megasas_transition_to_ready(pci, iobase) == 0) diff --git a/src/hw/pci.c b/src/hw/pci.c index 76c293c..1576787 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -162,10 +162,8 @@ pci_probe_devices(void) if (secbus > MaxPCIBus) MaxPCIBus = secbus; } - dprintf(4, "PCI device %02x:%02x.%x (vd=%04x:%04x c=%04x)\n" - , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf) - , pci_bdf_to_fn(bdf) - , dev->vendor, dev->device, dev->class); + dprintf(4, "PCI device %pP (vd=%04x:%04x c=%04x)\n" + , dev, dev->vendor, dev->device, dev->class); } } dprintf(1, "Found %d PCI devices (max PCI bus is %02x)\n", count, MaxPCIBus); diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index 101a9c5..b1dd03f 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -272,9 +272,7 @@ pvscsi_add_lun(struct pci_device *pci, void *iobase, plun->iobase = iobase; plun->ring_dsc = ring_dsc;
- char *name = znprintf(16, "pvscsi %02x:%02x.%x %d:%d", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), target, lun); + char *name = znprintf(16, "pvscsi %pP %d:%d", pci, target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); int ret = scsi_drive_setup(&plun->drive, name, prio); free(name); @@ -303,9 +301,7 @@ init_pvscsi(struct pci_device *pci) return; pci_enable_busmaster(pci);
- dprintf(1, "found pvscsi at %02x:%02x.%x, io @ %p\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - pci_bdf_to_fn(pci->bdf), iobase); + dprintf(1, "found pvscsi at %pP, io @ %p\n", pci, iobase);
pvscsi_write_cmd_desc(iobase, PVSCSI_CMD_ADAPTER_RESET, NULL, 0);
diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 57ce5a8..1d1eb57 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -315,9 +315,7 @@ ehci_controller_setup(struct pci_device *pci) cntl->regs->ctrldssegment = 0; PendingEHCI++;
- dprintf(1, "EHCI init on dev %02x:%02x.%x (regs=%p)\n" - , pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf) - , pci_bdf_to_fn(pci->bdf), cntl->regs); + dprintf(1, "EHCI init on dev %pP (regs=%p)\n", pci, cntl->regs);
pci_enable_busmaster(pci);
diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index 3d55d48..b586575 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -282,9 +282,7 @@ ohci_controller_setup(struct pci_device *pci) cntl->usb.type = USB_TYPE_OHCI; cntl->regs = regs;
- dprintf(1, "OHCI init on dev %02x:%02x.%x (regs=%p)\n" - , pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf) - , pci_bdf_to_fn(pci->bdf), cntl->regs); + dprintf(1, "OHCI init on dev %pP (regs=%p)\n", pci, cntl->regs);
pci_enable_busmaster(pci);
diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index 3b949e4..ed7c39a 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -258,9 +258,7 @@ uhci_controller_setup(struct pci_device *pci) cntl->usb.type = USB_TYPE_UHCI; cntl->iobase = iobase;
- dprintf(1, "UHCI init on dev %02x:%02x.%x (io=%x)\n" - , pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf) - , pci_bdf_to_fn(pci->bdf), cntl->iobase); + dprintf(1, "UHCI init on dev %pP (io=%x)\n", pci, cntl->iobase);
pci_enable_busmaster(pci);
diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index af09592..6c1720d 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -552,11 +552,10 @@ xhci_controller_setup(struct pci_device *pci) xhci->usb.pci = pci; xhci->usb.type = USB_TYPE_XHCI;
- dprintf(1, "XHCI init on dev %02x:%02x.%x: regs @ %p, %d ports, %d slots" + dprintf(1, "XHCI init on dev %pP: regs @ %p, %d ports, %d slots" ", %d byte contexts\n" - , pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf) - , pci_bdf_to_fn(pci->bdf), xhci->caps - , xhci->ports, xhci->slots, xhci->context64 ? 64 : 32); + , pci, xhci->caps, xhci->ports, xhci->slots + , xhci->context64 ? 64 : 32);
if (xhci->xcap) { u32 off; diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 20a79eb..cd0cbe9 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -95,10 +95,8 @@ virtio_blk_process_op(struct disk_op_s *op) static void init_virtio_blk(struct pci_device *pci) { - u16 bdf = pci->bdf; u8 status = VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; - dprintf(1, "found virtio-blk at %x:%x\n", pci_bdf_to_bus(bdf), - pci_bdf_to_dev(bdf)); + dprintf(1, "found virtio-blk at %pP\n", pci); struct virtiodrive_s *vdrive = malloc_fseg(sizeof(*vdrive)); if (!vdrive) { warn_noalloc(); @@ -106,12 +104,11 @@ init_virtio_blk(struct pci_device *pci) } memset(vdrive, 0, sizeof(*vdrive)); vdrive->drive.type = DTYPE_VIRTIO_BLK; - vdrive->drive.cntl_id = bdf; + vdrive->drive.cntl_id = pci->bdf;
vp_init_simple(&vdrive->vp, pci); if (vp_find_vq(&vdrive->vp, 0, &vdrive->vq) < 0 ) { - dprintf(1, "fail to find vq for virtio-blk %x:%x\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); + dprintf(1, "fail to find vq for virtio-blk %pP\n", pci); goto fail; }
@@ -121,8 +118,7 @@ init_virtio_blk(struct pci_device *pci) u64 version1 = 1ull << VIRTIO_F_VERSION_1; u64 blk_size = 1ull << VIRTIO_BLK_F_BLK_SIZE; if (!(features & version1)) { - dprintf(1, "modern device without virtio_1 feature bit: %x:%x\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); + dprintf(1, "modern device without virtio_1 feature bit: %pP\n", pci); goto fail; }
@@ -131,8 +127,7 @@ init_virtio_blk(struct pci_device *pci) status |= VIRTIO_CONFIG_S_FEATURES_OK; vp_set_status(vp, status); if (!(vp_get_status(vp) & VIRTIO_CONFIG_S_FEATURES_OK)) { - dprintf(1, "device didn't accept features: %x:%x\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); + dprintf(1, "device didn't accept features: %pP\n", pci); goto fail; }
@@ -145,14 +140,12 @@ init_virtio_blk(struct pci_device *pci) vdrive->drive.blksize = DISK_SECTOR_SIZE; } if (vdrive->drive.blksize != DISK_SECTOR_SIZE) { - dprintf(1, "virtio-blk %x:%x block size %d is unsupported\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), - vdrive->drive.blksize); + dprintf(1, "virtio-blk %pP block size %d is unsupported\n", + pci, vdrive->drive.blksize); goto fail; } - dprintf(3, "virtio-blk %x:%x blksize=%d sectors=%u\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), - vdrive->drive.blksize, (u32)vdrive->drive.sectors); + dprintf(3, "virtio-blk %pP blksize=%d sectors=%u\n", + pci, vdrive->drive.blksize, (u32)vdrive->drive.sectors);
vdrive->drive.pchs.cylinder = vp_read(&vp->device, struct virtio_blk_config, cylinders); @@ -169,14 +162,12 @@ init_virtio_blk(struct pci_device *pci) cfg.blk_size : DISK_SECTOR_SIZE;
vdrive->drive.sectors = cfg.capacity; - dprintf(3, "virtio-blk %x:%x blksize=%d sectors=%u\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), - vdrive->drive.blksize, (u32)vdrive->drive.sectors); + dprintf(3, "virtio-blk %pP blksize=%d sectors=%u\n", + pci, vdrive->drive.blksize, (u32)vdrive->drive.sectors);
if (vdrive->drive.blksize != DISK_SECTOR_SIZE) { - dprintf(1, "virtio-blk %x:%x block size %d is unsupported\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), - vdrive->drive.blksize); + dprintf(1, "virtio-blk %pP block size %d is unsupported\n", + pci, vdrive->drive.blksize); goto fail; } vdrive->drive.pchs.cylinder = cfg.cylinders; @@ -184,9 +175,7 @@ init_virtio_blk(struct pci_device *pci) vdrive->drive.pchs.sector = cfg.sectors; }
- char *desc = znprintf(MAXDESCSIZE, "Virtio disk PCI:%x:%x", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); - + char *desc = znprintf(MAXDESCSIZE, "Virtio disk PCI:%pP", pci); boot_add_hd(&vdrive->drive, desc, bootprio_find_pci_device(pci));
status |= VIRTIO_CONFIG_S_DRIVER_OK; diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index f1e30a2..378d901 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -252,10 +252,9 @@ void vp_init_simple(struct vp_device *vp, struct pci_device *pci) return; vp_cap->memaddr = addr + offset; } - dprintf(3, "pci dev %x:%x virtio cap at 0x%x type %d " + dprintf(3, "pci dev %pP virtio cap at 0x%x type %d " "bar %d at 0x%08x off +0x%04x [%s]\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf), - vp_cap->cap, type, vp_cap->bar, vp_cap->ioaddr, offset, + pci, vp_cap->cap, type, vp_cap->bar, vp_cap->ioaddr, offset, vp_cap->is_io ? "io" : "mmio"); }
@@ -263,12 +262,10 @@ void vp_init_simple(struct vp_device *vp, struct pci_device *pci) }
if (vp->common.cap && vp->notify.cap && vp->isr.cap && vp->device.cap) { - dprintf(1, "pci dev %x:%x using modern (1.0) virtio mode\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf)); + dprintf(1, "pci dev %pP using modern (1.0) virtio mode\n", pci); vp->use_modern = 1; } else { - dprintf(1, "pci dev %x:%x using legacy (0.9.5) virtio mode\n", - pci_bdf_to_bus(pci->bdf), pci_bdf_to_dev(pci->bdf)); + dprintf(1, "pci dev %pP using legacy (0.9.5) virtio mode\n", pci); vp->legacy.bar = 0; vp->legacy.ioaddr = pci_enable_iobar(pci, PCI_BASE_ADDRESS_0); if (!vp->legacy.ioaddr) diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 80afd04..f7f01cd 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -134,9 +134,7 @@ virtio_scsi_scan_target(struct pci_device *pci, struct vp_device *vp, static void init_virtio_scsi(struct pci_device *pci) { - u16 bdf = pci->bdf; - dprintf(1, "found virtio-scsi at %x:%x\n", pci_bdf_to_bus(bdf), - pci_bdf_to_dev(bdf)); + dprintf(1, "found virtio-scsi at %pP\n", pci); struct vring_virtqueue *vq = NULL; struct vp_device *vp = malloc_high(sizeof(*vp)); if (!vp) { @@ -150,8 +148,7 @@ init_virtio_scsi(struct pci_device *pci) u64 features = vp_get_features(vp); u64 version1 = 1ull << VIRTIO_F_VERSION_1; if (!(features & version1)) { - dprintf(1, "modern device without virtio_1 feature bit: %x:%x\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); + dprintf(1, "modern device without virtio_1 feature bit: %pP\n", pci); goto fail; }
@@ -159,15 +156,13 @@ init_virtio_scsi(struct pci_device *pci) status |= VIRTIO_CONFIG_S_FEATURES_OK; vp_set_status(vp, status); if (!(vp_get_status(vp) & VIRTIO_CONFIG_S_FEATURES_OK)) { - dprintf(1, "device didn't accept features: %x:%x\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); + dprintf(1, "device didn't accept features: %pP\n", pci); goto fail; } }
if (vp_find_vq(vp, 2, &vq) < 0 ) { - dprintf(1, "fail to find vq for virtio-scsi %x:%x\n", - pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf)); + dprintf(1, "fail to find vq for virtio-scsi %pP\n", pci); goto fail; }
diff --git a/src/optionroms.c b/src/optionroms.c index c81eff2..a389dd9 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -243,9 +243,7 @@ copy_rom(struct rom_header *rom) static struct rom_header * map_pcirom(struct pci_device *pci) { - u16 bdf = pci->bdf; - dprintf(6, "Attempting to map option rom on dev %02x:%02x.%x\n" - , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf)); + dprintf(6, "Attempting to map option rom on dev %pP\n", pci);
if ((pci->header_type & 0x7f) != PCI_HEADER_TYPE_NORMAL) { dprintf(6, "Skipping non-normal pci device (type=%x)\n" @@ -253,6 +251,7 @@ map_pcirom(struct pci_device *pci) return NULL; }
+ u16 bdf = pci->bdf; u32 orig = pci_config_readl(bdf, PCI_ROM_ADDRESS); pci_config_writel(bdf, PCI_ROM_ADDRESS, ~PCI_ROM_ADDRESS_ENABLE); u32 sz = pci_config_readl(bdf, PCI_ROM_ADDRESS); @@ -274,10 +273,8 @@ map_pcirom(struct pci_device *pci)
struct rom_header *rom = (void*)orig; for (;;) { - dprintf(5, "Inspecting possible rom at %p (vd=%04x:%04x" - " bdf=%02x:%02x.%x)\n" - , rom, pci->vendor, pci->device - , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf)); + dprintf(5, "Inspecting possible rom at %p (vd=%04x:%04x bdf=%pP)\n" + , rom, pci->vendor, pci->device, pci); if (rom->signature != OPTION_ROM_SIGNATURE) { dprintf(6, "No option rom signature (got %x)\n", rom->signature); goto fail; @@ -314,10 +311,8 @@ fail: static void init_pcirom(struct pci_device *pci, int isvga, u64 *sources) { - u16 bdf = pci->bdf; - dprintf(4, "Attempting to init PCI bdf %02x:%02x.%x (vd %04x:%04x)\n" - , pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf) - , pci->vendor, pci->device); + dprintf(4, "Attempting to init PCI bdf %pP (vd %04x:%04x)\n" + , pci, pci->vendor, pci->device);
char fname[17]; snprintf(fname, sizeof(fname), "pci%04x,%04x.rom" @@ -332,7 +327,7 @@ init_pcirom(struct pci_device *pci, int isvga, u64 *sources) // No ROM present. return; setRomSource(sources, rom, RS_PCIROM | (u32)pci); - init_optionrom(rom, bdf, isvga); + init_optionrom(rom, pci->bdf, isvga); }
diff --git a/src/output.c b/src/output.c index 8a88388..9a8a130 100644 --- a/src/output.c +++ b/src/output.c @@ -10,6 +10,7 @@ #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL +#include "hw/pci.h" // pci_bdf_to_bus #include "hw/serialio.h" // serial_debug_putc #include "malloc.h" // malloc_tmp #include "output.h" // dprintf @@ -194,6 +195,17 @@ putprettyhex(struct putcinfo *action, u32 val, int width, char padchar) puthex(action, val, count); }
+// Output 'struct pci_device' BDF as %02x:%02x.%x +static void +put_pci_device(struct putcinfo *action, struct pci_device *pci) +{ + puthex(action, pci_bdf_to_bus(pci->bdf), 2); + putc(action, ':'); + puthex(action, pci_bdf_to_dev(pci->bdf), 2); + putc(action, '.'); + puthex(action, pci_bdf_to_fn(pci->bdf), 1); +} + static inline int isdigit(u8 c) { @@ -260,6 +272,12 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) break; case 'p': val = va_arg(args, s32); + if (!MODESEGMENT && GET_GLOBAL(*(u8*)(n+1)) == 'P') { + // %pP is 'struct pci_device' printer + put_pci_device(action, (void*)val); + n++; + break; + } putc(action, '0'); putc(action, 'x'); puthex(action, val, 8);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/fw/mtrr.c | 1 - src/fw/pciinit.c | 37 +++++++++++++++++++++++++++++++++++++ src/hw/pci.c | 26 -------------------------- src/hw/pci.h | 15 --------------- src/util.h | 2 ++ 5 files changed, 39 insertions(+), 42 deletions(-)
diff --git a/src/fw/mtrr.c b/src/fw/mtrr.c index 913580e..3e799ce 100644 --- a/src/fw/mtrr.c +++ b/src/fw/mtrr.c @@ -5,7 +5,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "config.h" // CONFIG_* -#include "hw/pci.h" // pcimem_start #include "output.h" // dprintf #include "paravirt.h" // RamSize #include "util.h" // mtrr_setup diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 8e6716d..ead2c1a 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -27,6 +27,17 @@ #define PCI_BRIDGE_MEM_MIN (1<<21) // 2M == hugepage size #define PCI_BRIDGE_IO_MIN 0x1000 // mandated by pci bridge spec
+#define PCI_ROM_SLOT 6 +#define PCI_NUM_REGIONS 7 +#define PCI_BRIDGE_NUM_REGIONS 2 + +enum pci_region_type { + PCI_REGION_TYPE_IO, + PCI_REGION_TYPE_MEM, + PCI_REGION_TYPE_PREFMEM, + PCI_REGION_TYPE_COUNT, +}; + static const char *region_type_name[] = { [ PCI_REGION_TYPE_IO ] = "io", [ PCI_REGION_TYPE_MEM ] = "mem", @@ -667,6 +678,32 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap) return !!shpc_cap; }
+/* Test whether bridge support forwarding of transactions + * of a specific type. + * Note: disables bridge's window registers as a side effect. + */ +static int pci_bridge_has_region(struct pci_device *pci, + enum pci_region_type region_type) +{ + u8 base; + + switch (region_type) { + case PCI_REGION_TYPE_IO: + base = PCI_IO_BASE; + break; + case PCI_REGION_TYPE_PREFMEM: + base = PCI_PREF_MEMORY_BASE; + break; + default: + /* Regular memory support is mandatory */ + return 1; + } + + pci_config_writeb(pci->bdf, base, 0xFF); + + return pci_config_readb(pci->bdf, base) != 0; +} + static int pci_bios_check_devices(struct pci_bus *busses) { dprintf(1, "PCI: check devices\n"); diff --git a/src/hw/pci.c b/src/hw/pci.c index 1576787..dcf240c 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -244,32 +244,6 @@ u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap) return 0; }
-/* Test whether bridge support forwarding of transactions - * of a specific type. - * Note: disables bridge's window registers as a side effect. - */ -int pci_bridge_has_region(struct pci_device *pci, - enum pci_region_type region_type) -{ - u8 base; - - switch (region_type) { - case PCI_REGION_TYPE_IO: - base = PCI_IO_BASE; - break; - case PCI_REGION_TYPE_PREFMEM: - base = PCI_PREF_MEMORY_BASE; - break; - default: - /* Regular memory support is mandatory */ - return 1; - } - - pci_config_writeb(pci->bdf, base, 0xFF); - - return pci_config_readb(pci->bdf, base) != 0; -} - // Enable PCI bus-mastering (ie, DMA) support on a pci device void pci_enable_busmaster(struct pci_device *pci) diff --git a/src/hw/pci.h b/src/hw/pci.h index 8e39753..61eb1f3 100644 --- a/src/hw/pci.h +++ b/src/hw/pci.h @@ -8,17 +8,6 @@ #define PORT_PCI_REBOOT 0x0cf9 #define PORT_PCI_DATA 0x0cfc
-#define PCI_ROM_SLOT 6 -#define PCI_NUM_REGIONS 7 -#define PCI_BRIDGE_NUM_REGIONS 2 - -enum pci_region_type { - PCI_REGION_TYPE_IO, - PCI_REGION_TYPE_MEM, - PCI_REGION_TYPE_PREFMEM, - PCI_REGION_TYPE_COUNT, -}; - static inline u8 pci_bdf_to_bus(u16 bdf) { return bdf >> 8; } @@ -68,8 +57,6 @@ struct pci_device { // Local information on device. int have_driver; }; -extern u64 pcimem_start, pcimem_end; -extern u64 pcimem64_start, pcimem64_end; extern struct hlist_head PCIDevices; extern int MaxPCIBus; int pci_probe_host(void); @@ -124,8 +111,6 @@ int pci_init_device(const struct pci_device_id *ids struct pci_device *pci_find_init_device(const struct pci_device_id *ids , void *arg); u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap); -int pci_bridge_has_region(struct pci_device *pci, - enum pci_region_type region_type); void pci_enable_busmaster(struct pci_device *pci); u16 pci_enable_iobar(struct pci_device *pci, u32 addr); void *pci_enable_membar(struct pci_device *pci, u32 addr); diff --git a/src/util.h b/src/util.h index 43f2199..7b41207 100644 --- a/src/util.h +++ b/src/util.h @@ -110,6 +110,8 @@ void mtrr_setup(void); void multiboot_init(void);
// fw/pciinit.c +extern u64 pcimem_start, pcimem_end; +extern u64 pcimem64_start, pcimem64_end; extern const u8 pci_irqs[4]; void pci_setup(void); void pci_resume(void);
Split pci.c into pci.c and pcidevice.c. The low-level code that interacts directly with the PCI devices remains in pci.c, while functions dealing with the higher level pci_device cache move to pcidevice.c. Only pci.c is needed in 16bit mode.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 2 +- src/boot.c | 1 + src/fw/acpi.c | 2 +- src/fw/coreboot.c | 2 +- src/fw/csm.c | 3 +- src/fw/mptable.c | 5 +- src/fw/paravirt.c | 3 +- src/fw/pciinit.c | 1 + src/fw/smm.c | 1 + src/hw/ahci.c | 3 +- src/hw/ata.c | 3 +- src/hw/esp-scsi.c | 2 +- src/hw/floppy.c | 2 +- src/hw/lsi-scsi.c | 2 +- src/hw/megasas.c | 3 +- src/hw/pci.c | 213 +----------------------------------------- src/hw/pci.h | 89 ++---------------- src/hw/{pci.c => pcidevice.c} | 105 +-------------------- src/hw/{pci.h => pcidevice.h} | 56 ++--------- src/hw/pvscsi.c | 2 +- src/hw/sdcard.c | 2 +- src/hw/usb-ehci.c | 2 +- src/hw/usb-ohci.c | 2 +- src/hw/usb-uhci.c | 3 +- src/hw/usb-xhci.c | 2 +- src/hw/virtio-blk.c | 2 +- src/hw/virtio-pci.c | 1 + src/hw/virtio-scsi.c | 2 +- src/optionroms.c | 3 +- src/output.c | 1 + src/pcibios.c | 1 + src/vgahooks.c | 3 +- 32 files changed, 59 insertions(+), 465 deletions(-) copy src/hw/{pci.c => pcidevice.c} (72%) copy src/hw/{pci.h => pcidevice.h} (65%)
diff --git a/Makefile b/Makefile index cbe9454..b0eb239 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ SRCBOTH=misc.c stacks.c output.c string.c block.c cdrom.c disk.c mouse.c kbd.c \ SRC16=$(SRCBOTH) SRC32FLAT=$(SRCBOTH) post.c e820map.c malloc.c romfile.c x86.c optionroms.c \ pmm.c font.c boot.c bootsplash.c jpeg.c bmp.c tcgbios.c sha1.c \ - hw/ahci.c hw/pvscsi.c hw/usb-xhci.c hw/usb-hub.c hw/sdcard.c \ + hw/pcidevice.c hw/ahci.c hw/pvscsi.c hw/usb-xhci.c hw/usb-hub.c hw/sdcard.c \ fw/coreboot.c fw/lzmadecode.c fw/multiboot.c fw/csm.c fw/biostables.c \ fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/smp.c fw/mtrr.c fw/xen.c \ fw/acpi.c fw/mptable.c fw/pirtable.c fw/smbios.c fw/romfile_loader.c \ diff --git a/src/boot.c b/src/boot.c index a045a8e..706b7df 100644 --- a/src/boot.c +++ b/src/boot.c @@ -10,6 +10,7 @@ #include "config.h" // CONFIG_* #include "fw/paravirt.h" // qemu_cfg_show_boot_menu #include "hw/pci.h" // pci_bdf_to_* +#include "hw/pcidevice.h" // struct pci_device #include "hw/rtc.h" // rtc_read #include "hw/usb.h" // struct usbdevice_s #include "list.h" // hlist_node diff --git a/src/fw/acpi.c b/src/fw/acpi.c index b805b44..8bc2ca6 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -10,7 +10,7 @@ #include "config.h" // CONFIG_* #include "dev-q35.h" #include "dev-piix.h" -#include "hw/pci.h" // pci_find_init_device +#include "hw/pcidevice.h" // pci_find_init_device #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_INTERRUPT_LINE #include "malloc.h" // free diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 4fe1292..4957b80 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -8,7 +8,7 @@ #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_* #include "e820map.h" // e820_add -#include "hw/pci.h" // pci_probe_devices +#include "hw/pcidevice.h" // pci_probe_devices #include "lzmadecode.h" // LzmaDecode #include "malloc.h" // free #include "output.h" // dprintf diff --git a/src/fw/csm.c b/src/fw/csm.c index b01f181..03b4bb8 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -8,7 +8,8 @@ #include "config.h" // CONFIG_* #include "e820map.h" // e820_add #include "farptr.h" // MAKE_FLATPTR -#include "hw/pci.h" // pci_probe_devices +#include "hw/pci.h" // pci_to_bdf +#include "hw/pcidevice.h" // pci_probe_devices #include "hw/pic.h" // pic_irqmask_read #include "malloc.h" // malloc_csm_preinit #include "memmap.h" // SYMBOL diff --git a/src/fw/mptable.c b/src/fw/mptable.c index 8e01e00..47385cc 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -7,8 +7,9 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "config.h" // CONFIG_* -#include "hw/pci.h" -#include "hw/pci_regs.h" +#include "hw/pci.h" // pci_bdf_to_bus +#include "hw/pcidevice.h" // foreachpci +#include "hw/pci_regs.h" // PCI_INTERRUPT_PIN #include "malloc.h" // free #include "output.h" // dprintf #include "romfile.h" // romfile_loadint diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 3fae13a..8ed4380 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -11,7 +11,8 @@ #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_QEMU #include "e820map.h" // e820_add -#include "hw/pci.h" // create_pirtable +#include "hw/pci.h" // pci_config_readw +#include "hw/pcidevice.h" // pci_probe_devices #include "hw/pci_regs.h" // PCI_DEVICE_ID #include "hw/rtc.h" // CMOS_* #include "malloc.h" // malloc_tmp diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index ead2c1a..0ed5dfb 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -12,6 +12,7 @@ #include "e820map.h" // e820_add #include "hw/ata.h" // PORT_ATA1_CMD_BASE #include "hw/pci.h" // pci_config_readl +#include "hw/pcidevice.h" // pci_probe_devices #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_COMMAND #include "list.h" // struct hlist_node diff --git a/src/fw/smm.c b/src/fw/smm.c index 8f042ee..95f6ba7 100644 --- a/src/fw/smm.c +++ b/src/fw/smm.c @@ -9,6 +9,7 @@ #include "dev-q35.h" #include "dev-piix.h" #include "hw/pci.h" // pci_config_writel +#include "hw/pcidevice.h" // pci_find_device #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_DEVICE_ID #include "output.h" // dprintf diff --git a/src/hw/ahci.c b/src/hw/ahci.c index bd21bf6..9310850 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -10,7 +10,8 @@ #include "blockcmd.h" // CDB_CMD_READ_10 #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pci.h" // pci_config_readb +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE #include "stacks.h" // yield diff --git a/src/hw/ata.c b/src/hw/ata.c index 12dab96..9a4b435 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -12,7 +12,8 @@ #include "byteorder.h" // be16_to_cpu #include "malloc.h" // malloc_fseg #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pci.h" // pci_config_readb +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE #include "pic.h" // enable_hwirq diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 9abc361..086a032 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -17,7 +17,7 @@ #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID #include "pci_regs.h" // PCI_VENDOR_ID #include "std/disk.h" // DISK_RET_SUCCESS diff --git a/src/hw/floppy.c b/src/hw/floppy.c index a14f7e0..98ed9bb 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -11,7 +11,7 @@ #include "config.h" // CONFIG_FLOPPY #include "malloc.h" // malloc_fseg #include "output.h" // dprintf -#include "pci.h" // pci_to_bdf +#include "pcidevice.h" // pci_find_class #include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA #include "pic.h" // pic_eoi1 #include "romfile.h" // romfile_loadint diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 5d872a2..564c9f1 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -17,7 +17,7 @@ #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID #include "std/disk.h" // DISK_RET_SUCCESS diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 71af3c3..2ee457b 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -16,7 +16,8 @@ #include "config.h" // CONFIG_* #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pci.h" // pci_config_readl +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_XXX #include "pci_regs.h" // PCI_VENDOR_ID #include "stacks.h" // yield diff --git a/src/hw/pci.c b/src/hw/pci.c index dcf240c..506ee56 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -5,16 +5,16 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "malloc.h" // malloc_tmp #include "output.h" // dprintf #include "pci.h" // pci_config_writel #include "pci_regs.h" // PCI_VENDOR_ID -#include "romfile.h" // romfile_loadint -#include "stacks.h" // wait_preempt -#include "string.h" // memset #include "util.h" // udelay #include "x86.h" // outl
+#define PORT_PCI_CMD 0x0cf8 +#define PORT_PCI_REBOOT 0x0cf9 +#define PORT_PCI_DATA 0x0cfc + void pci_config_writel(u16 bdf, u32 addr, u32 val) { outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); @@ -87,9 +87,6 @@ pci_next(int bdf, int bus) } }
-struct hlist_head PCIDevices VARVERIFY32INIT; -int MaxPCIBus VARFSEG; - // Check if PCI is available at all int pci_probe_host(void) @@ -102,208 +99,6 @@ pci_probe_host(void) return 0; }
-// Find all PCI devices and populate PCIDevices linked list. -void -pci_probe_devices(void) -{ - dprintf(3, "PCI probe\n"); - struct pci_device *busdevs[256]; - memset(busdevs, 0, sizeof(busdevs)); - struct hlist_node **pprev = &PCIDevices.first; - int extraroots = romfile_loadint("etc/extra-pci-roots", 0); - int bus = -1, lastbus = 0, rootbuses = 0, count=0; - while (bus < 0xff && (bus < MaxPCIBus || rootbuses < extraroots)) { - bus++; - int bdf; - foreachbdf(bdf, bus) { - // Create new pci_device struct and add to list. - struct pci_device *dev = malloc_tmp(sizeof(*dev)); - if (!dev) { - warn_noalloc(); - return; - } - memset(dev, 0, sizeof(*dev)); - hlist_add(&dev->node, pprev); - pprev = &dev->node.next; - count++; - - // Find parent device. - int rootbus; - struct pci_device *parent = busdevs[bus]; - if (!parent) { - if (bus != lastbus) - rootbuses++; - lastbus = bus; - rootbus = rootbuses; - if (bus > MaxPCIBus) - MaxPCIBus = bus; - } else { - rootbus = parent->rootbus; - } - - // Populate pci_device info. - dev->bdf = bdf; - dev->parent = parent; - dev->rootbus = rootbus; - u32 vendev = pci_config_readl(bdf, PCI_VENDOR_ID); - dev->vendor = vendev & 0xffff; - dev->device = vendev >> 16; - u32 classrev = pci_config_readl(bdf, PCI_CLASS_REVISION); - dev->class = classrev >> 16; - dev->prog_if = classrev >> 8; - dev->revision = classrev & 0xff; - dev->header_type = pci_config_readb(bdf, PCI_HEADER_TYPE); - u8 v = dev->header_type & 0x7f; - if (v == PCI_HEADER_TYPE_BRIDGE || v == PCI_HEADER_TYPE_CARDBUS) { - u8 secbus = pci_config_readb(bdf, PCI_SECONDARY_BUS); - dev->secondary_bus = secbus; - if (secbus > bus && !busdevs[secbus]) - busdevs[secbus] = dev; - if (secbus > MaxPCIBus) - MaxPCIBus = secbus; - } - dprintf(4, "PCI device %pP (vd=%04x:%04x c=%04x)\n" - , dev, dev->vendor, dev->device, dev->class); - } - } - dprintf(1, "Found %d PCI devices (max PCI bus is %02x)\n", count, MaxPCIBus); -} - -// Search for a device with the specified vendor and device ids. -struct pci_device * -pci_find_device(u16 vendid, u16 devid) -{ - struct pci_device *pci; - foreachpci(pci) { - if (pci->vendor == vendid && pci->device == devid) - return pci; - } - return NULL; -} - -// Search for a device with the specified class id. -struct pci_device * -pci_find_class(u16 classid) -{ - struct pci_device *pci; - foreachpci(pci) { - if (pci->class == classid) - return pci; - } - return NULL; -} - -int pci_init_device(const struct pci_device_id *ids - , struct pci_device *pci, void *arg) -{ - while (ids->vendid || ids->class_mask) { - if ((ids->vendid == PCI_ANY_ID || ids->vendid == pci->vendor) && - (ids->devid == PCI_ANY_ID || ids->devid == pci->device) && - !((ids->class ^ pci->class) & ids->class_mask)) { - if (ids->func) - ids->func(pci, arg); - return 0; - } - ids++; - } - return -1; -} - -struct pci_device * -pci_find_init_device(const struct pci_device_id *ids, void *arg) -{ - struct pci_device *pci; - foreachpci(pci) { - if (pci_init_device(ids, pci, arg) == 0) - return pci; - } - return NULL; -} - -u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap) -{ - int i; - u16 status = pci_config_readw(pci->bdf, PCI_STATUS); - - if (!(status & PCI_STATUS_CAP_LIST)) - return 0; - - if (cap == 0) { - /* find first */ - cap = pci_config_readb(pci->bdf, PCI_CAPABILITY_LIST); - } else { - /* find next */ - cap = pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_NEXT); - } - for (i = 0; cap && i <= 0xff; i++) { - if (pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_ID) == cap_id) - return cap; - cap = pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_NEXT); - } - - return 0; -} - -// Enable PCI bus-mastering (ie, DMA) support on a pci device -void -pci_enable_busmaster(struct pci_device *pci) -{ - ASSERT32FLAT(); - wait_preempt(); - pci_config_maskw(pci->bdf, PCI_COMMAND, 0, PCI_COMMAND_MASTER); - pci->have_driver = 1; -} - -// Verify an IO bar and return it to the caller -u16 -pci_enable_iobar(struct pci_device *pci, u32 addr) -{ - ASSERT32FLAT(); - wait_preempt(); - u32 bar = pci_config_readl(pci->bdf, addr); - if (!(bar & PCI_BASE_ADDRESS_SPACE_IO)) { - warn_internalerror(); - return 0; - } - bar &= PCI_BASE_ADDRESS_IO_MASK; - if (bar == 0 || bar > 0xffff) { - warn_internalerror(); - return 0; - } - pci_config_maskw(pci->bdf, PCI_COMMAND, 0, PCI_COMMAND_IO); - pci->have_driver = 1; - return bar; -} - -// Verify a memory bar and return it to the caller -void * -pci_enable_membar(struct pci_device *pci, u32 addr) -{ - ASSERT32FLAT(); - wait_preempt(); - u32 bar = pci_config_readl(pci->bdf, addr); - if (bar & PCI_BASE_ADDRESS_SPACE_IO) { - warn_internalerror(); - return NULL; - } - if (bar & PCI_BASE_ADDRESS_MEM_TYPE_64) { - u32 high = pci_config_readl(pci->bdf, addr+4); - if (high) { - dprintf(1, "Can not map memory bar over 4Gig\n"); - return NULL; - } - } - bar &= PCI_BASE_ADDRESS_MEM_MASK; - if (bar + 4*1024*1024 < 20*1024*1024) { - // Bar doesn't look valid (it is in last 4M or first 16M) - warn_internalerror(); - return NULL; - } - pci_config_maskw(pci->bdf, PCI_COMMAND, 0, PCI_COMMAND_MEMORY); - pci->have_driver = 1; - return (void*)bar; -} - void pci_reboot(void) { diff --git a/src/hw/pci.h b/src/hw/pci.h index 61eb1f3..bf50430 100644 --- a/src/hw/pci.h +++ b/src/hw/pci.h @@ -2,11 +2,6 @@ #define __PCI_H
#include "types.h" // u32 -#include "list.h" // hlist_node - -#define PORT_PCI_CMD 0x0cf8 -#define PORT_PCI_REBOOT 0x0cf9 -#define PORT_PCI_DATA 0x0cfc
static inline u8 pci_bdf_to_bus(u16 bdf) { return bdf >> 8; @@ -30,6 +25,11 @@ static inline u16 pci_bus_devfn_to_bdf(int bus, u16 devfn) { return (bus << 8) | devfn; }
+#define foreachbdf(BDF, BUS) \ + for (BDF=pci_next(pci_bus_devfn_to_bdf((BUS), 0)-1, (BUS)) \ + ; BDF >= 0 \ + ; BDF=pci_next(BDF, (BUS))) + void pci_config_writel(u16 bdf, u32 addr, u32 val); void pci_config_writew(u16 bdf, u32 addr, u16 val); void pci_config_writeb(u16 bdf, u32 addr, u8 val); @@ -37,83 +37,8 @@ u32 pci_config_readl(u16 bdf, u32 addr); u16 pci_config_readw(u16 bdf, u32 addr); u8 pci_config_readb(u16 bdf, u32 addr); void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on); - -struct pci_device *pci_find_device(u16 vendid, u16 devid); -struct pci_device *pci_find_class(u16 classid); - -struct pci_device { - u16 bdf; - u8 rootbus; - struct hlist_node node; - struct pci_device *parent; - - // Configuration space device information - u16 vendor, device; - u16 class; - u8 prog_if, revision; - u8 header_type; - u8 secondary_bus; - - // Local information on device. - int have_driver; -}; -extern struct hlist_head PCIDevices; -extern int MaxPCIBus; -int pci_probe_host(void); -void pci_probe_devices(void); -static inline u32 pci_classprog(struct pci_device *pci) { - return (pci->class << 8) | pci->prog_if; -} - -#define foreachpci(PCI) \ - hlist_for_each_entry(PCI, &PCIDevices, node) - int pci_next(int bdf, int bus); -#define foreachbdf(BDF, BUS) \ - for (BDF=pci_next(pci_bus_devfn_to_bdf((BUS), 0)-1, (BUS)) \ - ; BDF >= 0 \ - ; BDF=pci_next(BDF, (BUS))) - -#define PCI_ANY_ID (~0) -struct pci_device_id { - u32 vendid; - u32 devid; - u32 class; - u32 class_mask; - void (*func)(struct pci_device *pci, void *arg); -}; - -#define PCI_DEVICE(vendor_id, device_id, init_func) \ - { \ - .vendid = (vendor_id), \ - .devid = (device_id), \ - .class = PCI_ANY_ID, \ - .class_mask = 0, \ - .func = (init_func) \ - } - -#define PCI_DEVICE_CLASS(vendor_id, device_id, class_code, init_func) \ - { \ - .vendid = (vendor_id), \ - .devid = (device_id), \ - .class = (class_code), \ - .class_mask = ~0, \ - .func = (init_func) \ - } - -#define PCI_DEVICE_END \ - { \ - .vendid = 0, \ - } - -int pci_init_device(const struct pci_device_id *ids - , struct pci_device *pci, void *arg); -struct pci_device *pci_find_init_device(const struct pci_device_id *ids - , void *arg); -u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap); -void pci_enable_busmaster(struct pci_device *pci); -u16 pci_enable_iobar(struct pci_device *pci, u32 addr); -void *pci_enable_membar(struct pci_device *pci, u32 addr); +int pci_probe_host(void); void pci_reboot(void);
-#endif +#endif // pci.h diff --git a/src/hw/pci.c b/src/hw/pcidevice.c similarity index 72% copy from src/hw/pci.c copy to src/hw/pcidevice.c index dcf240c..cfebf66 100644 --- a/src/hw/pci.c +++ b/src/hw/pcidevice.c @@ -1,107 +1,21 @@ -// PCI config space access functions. +// Code to maintain and access the pci_device cache // -// Copyright (C) 2008 Kevin O'Connor kevin@koconnor.net -// Copyright (C) 2002 MandrakeSoft S.A. +// Copyright (C) 2008-2016 Kevin O'Connor kevin@koconnor.net // // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "malloc.h" // malloc_tmp #include "output.h" // dprintf #include "pci.h" // pci_config_writel +#include "pcidevice.h" // pci_probe_devices #include "pci_regs.h" // PCI_VENDOR_ID #include "romfile.h" // romfile_loadint #include "stacks.h" // wait_preempt #include "string.h" // memset -#include "util.h" // udelay -#include "x86.h" // outl - -void pci_config_writel(u16 bdf, u32 addr, u32 val) -{ - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); - outl(val, PORT_PCI_DATA); -} - -void pci_config_writew(u16 bdf, u32 addr, u16 val) -{ - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); - outw(val, PORT_PCI_DATA + (addr & 2)); -} - -void pci_config_writeb(u16 bdf, u32 addr, u8 val) -{ - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); - outb(val, PORT_PCI_DATA + (addr & 3)); -} - -u32 pci_config_readl(u16 bdf, u32 addr) -{ - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); - return inl(PORT_PCI_DATA); -} - -u16 pci_config_readw(u16 bdf, u32 addr) -{ - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); - return inw(PORT_PCI_DATA + (addr & 2)); -} - -u8 pci_config_readb(u16 bdf, u32 addr) -{ - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); - return inb(PORT_PCI_DATA + (addr & 3)); -} - -void -pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on) -{ - u16 val = pci_config_readw(bdf, addr); - val = (val & ~off) | on; - pci_config_writew(bdf, addr, val); -} - -// Helper function for foreachbdf() macro - return next device -int -pci_next(int bdf, int bus) -{ - if (pci_bdf_to_fn(bdf) == 0 - && (pci_config_readb(bdf, PCI_HEADER_TYPE) & 0x80) == 0) - // Last found device wasn't a multi-function device - skip to - // the next device. - bdf += 8; - else - bdf += 1; - - for (;;) { - if (pci_bdf_to_bus(bdf) != bus) - return -1; - - u16 v = pci_config_readw(bdf, PCI_VENDOR_ID); - if (v != 0x0000 && v != 0xffff) - // Device is present. - return bdf; - - if (pci_bdf_to_fn(bdf) == 0) - bdf += 8; - else - bdf += 1; - } -}
struct hlist_head PCIDevices VARVERIFY32INIT; int MaxPCIBus VARFSEG;
-// Check if PCI is available at all -int -pci_probe_host(void) -{ - outl(0x80000000, PORT_PCI_CMD); - if (inl(PORT_PCI_CMD) != 0x80000000) { - dprintf(1, "Detected non-PCI system\n"); - return -1; - } - return 0; -} - // Find all PCI devices and populate PCIDevices linked list. void pci_probe_devices(void) @@ -248,7 +162,6 @@ u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap) void pci_enable_busmaster(struct pci_device *pci) { - ASSERT32FLAT(); wait_preempt(); pci_config_maskw(pci->bdf, PCI_COMMAND, 0, PCI_COMMAND_MASTER); pci->have_driver = 1; @@ -258,7 +171,6 @@ pci_enable_busmaster(struct pci_device *pci) u16 pci_enable_iobar(struct pci_device *pci, u32 addr) { - ASSERT32FLAT(); wait_preempt(); u32 bar = pci_config_readl(pci->bdf, addr); if (!(bar & PCI_BASE_ADDRESS_SPACE_IO)) { @@ -279,7 +191,6 @@ pci_enable_iobar(struct pci_device *pci, u32 addr) void * pci_enable_membar(struct pci_device *pci, u32 addr) { - ASSERT32FLAT(); wait_preempt(); u32 bar = pci_config_readl(pci->bdf, addr); if (bar & PCI_BASE_ADDRESS_SPACE_IO) { @@ -303,13 +214,3 @@ pci_enable_membar(struct pci_device *pci, u32 addr) pci->have_driver = 1; return (void*)bar; } - -void -pci_reboot(void) -{ - u8 v = inb(PORT_PCI_REBOOT) & ~6; - outb(v|2, PORT_PCI_REBOOT); /* Request hard reset */ - udelay(50); - outb(v|6, PORT_PCI_REBOOT); /* Actually do the reset */ - udelay(50); -} diff --git a/src/hw/pci.h b/src/hw/pcidevice.h similarity index 65% copy from src/hw/pci.h copy to src/hw/pcidevice.h index 61eb1f3..354b549 100644 --- a/src/hw/pci.h +++ b/src/hw/pcidevice.h @@ -1,46 +1,9 @@ -#ifndef __PCI_H -#define __PCI_H +#ifndef __PCIDEVICE_H +#define __PCIDEVICE_H
#include "types.h" // u32 #include "list.h" // hlist_node
-#define PORT_PCI_CMD 0x0cf8 -#define PORT_PCI_REBOOT 0x0cf9 -#define PORT_PCI_DATA 0x0cfc - -static inline u8 pci_bdf_to_bus(u16 bdf) { - return bdf >> 8; -} -static inline u8 pci_bdf_to_devfn(u16 bdf) { - return bdf & 0xff; -} -static inline u16 pci_bdf_to_busdev(u16 bdf) { - return bdf & ~0x07; -} -static inline u8 pci_bdf_to_dev(u16 bdf) { - return (bdf >> 3) & 0x1f; -} -static inline u8 pci_bdf_to_fn(u16 bdf) { - return bdf & 0x07; -} -static inline u16 pci_to_bdf(int bus, int dev, int fn) { - return (bus<<8) | (dev<<3) | fn; -} -static inline u16 pci_bus_devfn_to_bdf(int bus, u16 devfn) { - return (bus << 8) | devfn; -} - -void pci_config_writel(u16 bdf, u32 addr, u32 val); -void pci_config_writew(u16 bdf, u32 addr, u16 val); -void pci_config_writeb(u16 bdf, u32 addr, u8 val); -u32 pci_config_readl(u16 bdf, u32 addr); -u16 pci_config_readw(u16 bdf, u32 addr); -u8 pci_config_readb(u16 bdf, u32 addr); -void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on); - -struct pci_device *pci_find_device(u16 vendid, u16 devid); -struct pci_device *pci_find_class(u16 classid); - struct pci_device { u16 bdf; u8 rootbus; @@ -59,8 +22,7 @@ struct pci_device { }; extern struct hlist_head PCIDevices; extern int MaxPCIBus; -int pci_probe_host(void); -void pci_probe_devices(void); + static inline u32 pci_classprog(struct pci_device *pci) { return (pci->class << 8) | pci->prog_if; } @@ -68,12 +30,6 @@ static inline u32 pci_classprog(struct pci_device *pci) { #define foreachpci(PCI) \ hlist_for_each_entry(PCI, &PCIDevices, node)
-int pci_next(int bdf, int bus); -#define foreachbdf(BDF, BUS) \ - for (BDF=pci_next(pci_bus_devfn_to_bdf((BUS), 0)-1, (BUS)) \ - ; BDF >= 0 \ - ; BDF=pci_next(BDF, (BUS))) - #define PCI_ANY_ID (~0) struct pci_device_id { u32 vendid; @@ -106,6 +62,9 @@ struct pci_device_id { .vendid = 0, \ }
+void pci_probe_devices(void); +struct pci_device *pci_find_device(u16 vendid, u16 devid); +struct pci_device *pci_find_class(u16 classid); int pci_init_device(const struct pci_device_id *ids , struct pci_device *pci, void *arg); struct pci_device *pci_find_init_device(const struct pci_device_id *ids @@ -114,6 +73,5 @@ u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap); void pci_enable_busmaster(struct pci_device *pci); u16 pci_enable_iobar(struct pci_device *pci, u32 addr); void *pci_enable_membar(struct pci_device *pci, u32 addr); -void pci_reboot(void);
-#endif +#endif // pcidevice.h diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index b1dd03f..e1685b3 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -13,7 +13,7 @@ #include "malloc.h" // free #include "memmap.h" // PAGE_SHIFT, virt_to_phys #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VMWARE_PVSCSI #include "pci_regs.h" // PCI_VENDOR_ID #include "pvscsi.h" // pvscsi_setup diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 1524b51..7e0875f 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -7,7 +7,7 @@ #include "block.h" // struct drive_s #include "malloc.h" // malloc_fseg #include "output.h" // znprintf -#include "pci.h" // foreachpci +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_SYSTEM_SDHCI #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "romfile.h" // romfile_findprefix diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 1d1eb57..7eca55b 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -9,7 +9,7 @@ #include "output.h" // dprintf #include "malloc.h" // free #include "memmap.h" // PAGE_SIZE -#include "pci.h" // pci_bdf_to_bus +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index b586575..90f60e6 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -9,7 +9,7 @@ #include "malloc.h" // free #include "memmap.h" // PAGE_SIZE #include "output.h" // dprintf -#include "pci.h" // pci_bdf_to_bus +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_OHCI #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index ed7c39a..075ed02 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -8,7 +8,8 @@ #include "config.h" // CONFIG_* #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // pci_bdf_to_bus +#include "pci.h" // pci_config_writew +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI #include "pci_regs.h" // PCI_BASE_ADDRESS_4 #include "string.h" // memset diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index 6c1720d..5e2f071 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -9,7 +9,7 @@ #include "malloc.h" // memalign_low #include "memmap.h" // PAGE_SIZE #include "output.h" // dprintf -#include "pci.h" // pci_bdf_to_bus +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_XHCI #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memcpy diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index cd0cbe9..2dfd0c3 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -12,7 +12,7 @@ #include "block.h" // struct drive_s #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID #include "std/disk.h" // DISK_RET_SUCCESS diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index 378d901..ce15672 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -19,6 +19,7 @@ #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // pci_config_readl +#include "pcidevice.h" // pci_find_capability #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset #include "virtio-pci.h" diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index f7f01cd..322d469 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -13,7 +13,7 @@ #include "config.h" // CONFIG_* #include "malloc.h" // free #include "output.h" // dprintf -#include "pci.h" // foreachpci +#include "pcidevice.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID #include "std/disk.h" // DISK_RET_SUCCESS diff --git a/src/optionroms.c b/src/optionroms.c index a389dd9..9897753 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -8,7 +8,8 @@ #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "farptr.h" // FLATPTR_TO_SEG -#include "hw/pci.h" // foreachpci +#include "hw/pci.h" // pci_config_readl +#include "hw/pcidevice.h" // foreachpci #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "hw/pci_regs.h" // PCI_ROM_ADDRESS #include "malloc.h" // rom_confirm diff --git a/src/output.c b/src/output.c index 9a8a130..ec51f5e 100644 --- a/src/output.c +++ b/src/output.c @@ -11,6 +11,7 @@ #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL #include "hw/pci.h" // pci_bdf_to_bus +#include "hw/pcidevice.h" // pci_device #include "hw/serialio.h" // serial_debug_putc #include "malloc.h" // malloc_tmp #include "output.h" // dprintf diff --git a/src/pcibios.c b/src/pcibios.c index 7e5d972..81735e3 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -8,6 +8,7 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "hw/pci.h" // pci_config_readl +#include "hw/pcidevice.h" // MaxPCIBus #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "output.h" // dprintf #include "std/pirtable.h" // struct pir_header diff --git a/src/vgahooks.c b/src/vgahooks.c index 48efb08..1f14953 100644 --- a/src/vgahooks.c +++ b/src/vgahooks.c @@ -7,7 +7,8 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // set_code_invalid #include "config.h" // CONFIG_* -#include "hw/pci.h" // pci_find_device +#include "hw/pci.h" // pci_config_readb +#include "hw/pcidevice.h" // pci_find_device #include "hw/pci_ids.h" // PCI_VENDOR_ID_VIA #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "output.h" // dprintf
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/esp-scsi.c | 2 +- src/hw/lsi-scsi.c | 2 +- src/hw/megasas.c | 3 ++- src/hw/pvscsi.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 086a032..c98989c 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -168,7 +168,7 @@ esp_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) llun->lun = lun; llun->iobase = iobase;
- char *name = znprintf(16, "esp %pP %d:%d", pci, target, lun); + char *name = znprintf(MAXDESCSIZE, "esp %pP %d:%d", pci, target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); int ret = scsi_drive_setup(&llun->drive, name, prio); free(name); diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 564c9f1..fd695fa 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -147,7 +147,7 @@ lsi_scsi_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) llun->lun = lun; llun->iobase = iobase;
- char *name = znprintf(16, "lsi %pP %d:%d", pci, target, lun); + char *name = znprintf(MAXDESCSIZE, "lsi %pP %d:%d", pci, target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); int ret = scsi_drive_setup(&llun->drive, name, prio); free(name); diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 2ee457b..7514164 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -225,7 +225,8 @@ megasas_add_lun(struct pci_device *pci, u32 iobase, u8 target, u8 lun) free(mlun); return -1; } - name = znprintf(36, "MegaRAID SAS (PCI %pP) LD %d:%d", pci, target, lun); + name = znprintf(MAXDESCSIZE, "MegaRAID SAS (PCI %pP) LD %d:%d" + , pci, target, lun); prio = bootprio_find_scsi_device(pci, target, lun); ret = scsi_drive_setup(&mlun->drive, name, prio); free(name); diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c index e1685b3..a9d118b 100644 --- a/src/hw/pvscsi.c +++ b/src/hw/pvscsi.c @@ -272,7 +272,7 @@ pvscsi_add_lun(struct pci_device *pci, void *iobase, plun->iobase = iobase; plun->ring_dsc = ring_dsc;
- char *name = znprintf(16, "pvscsi %pP %d:%d", pci, target, lun); + char *name = znprintf(MAXDESCSIZE, "pvscsi %pP %d:%d", pci, target, lun); int prio = bootprio_find_scsi_device(pci, target, lun); int ret = scsi_drive_setup(&plun->drive, name, prio); free(name);
On Wed, Feb 03, 2016 at 10:51:50AM -0500, Kevin O'Connor wrote:
Some additional PCI code cleanup - most notable is the first patch which adds a '%pP' modifier to the 'printf' code for outputting 'struct pci_device' pointers.
FYI, I committed this series.
-Kevin