pci: Make PCI API consistent wrt using struct pci_dev
Complete conversion of PCI API so all functions
that imply the underlying device does exist would
use struct pci_dev as a handle, not pcidevaddr_t.
Cc: Thomas Huth <thuth@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
diff --git a/lib/pci-host-generic.c b/lib/pci-host-generic.c
index 8b505b4..818150d 100644
--- a/lib/pci-host-generic.c
+++ b/lib/pci-host-generic.c
@@ -192,7 +192,7 @@
if (i >= host->nr_addr_spaces) {
printf("%s: warning: can't satisfy request for ", __func__);
- pci_dev_print_id(dev->bdf);
+ pci_dev_print_id(dev);
printf(" ");
pci_bar_print(dev, bar_num);
printf("\n");
diff --git a/lib/pci.c b/lib/pci.c
index fc18b25..daf3981 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -265,11 +265,13 @@
printf("]");
}
-void pci_dev_print_id(pcidevaddr_t dev)
+void pci_dev_print_id(struct pci_dev *dev)
{
- printf("00.%02x.%1x %04x:%04x", dev / 8, dev % 8,
- pci_config_readw(dev, PCI_VENDOR_ID),
- pci_config_readw(dev, PCI_DEVICE_ID));
+ pcidevaddr_t bdf = dev->bdf;
+
+ printf("00.%02x.%1x %04x:%04x", bdf / 8, bdf % 8,
+ pci_config_readw(bdf, PCI_VENDOR_ID),
+ pci_config_readw(bdf, PCI_DEVICE_ID));
}
static void pci_cap_print(struct pci_dev *dev, int cap_offset, int cap_id)
@@ -287,44 +289,45 @@
printf("at offset 0x%02x\n", cap_offset);
}
-void pci_dev_print(pcidevaddr_t dev)
+void pci_dev_print(struct pci_dev *dev)
{
- uint8_t header = pci_config_readb(dev, PCI_HEADER_TYPE);
- uint8_t progif = pci_config_readb(dev, PCI_CLASS_PROG);
- uint8_t subclass = pci_config_readb(dev, PCI_CLASS_DEVICE);
- uint8_t class = pci_config_readb(dev, PCI_CLASS_DEVICE + 1);
- struct pci_dev pci_dev;
+ pcidevaddr_t bdf = dev->bdf;
+ uint8_t header = pci_config_readb(bdf, PCI_HEADER_TYPE);
+ uint8_t progif = pci_config_readb(bdf, PCI_CLASS_PROG);
+ uint8_t subclass = pci_config_readb(bdf, PCI_CLASS_DEVICE);
+ uint8_t class = pci_config_readb(bdf, PCI_CLASS_DEVICE + 1);
int i;
- pci_dev_init(&pci_dev, dev);
-
pci_dev_print_id(dev);
printf(" type %02x progif %02x class %02x subclass %02x\n",
header, progif, class, subclass);
- pci_cap_walk(&pci_dev, pci_cap_print);
+ pci_cap_walk(dev, pci_cap_print);
if ((header & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL)
return;
for (i = 0; i < PCI_BAR_NUM; i++) {
- if (pci_bar_is_valid(&pci_dev, i)) {
+ if (pci_bar_is_valid(dev, i)) {
printf("\t");
- pci_bar_print(&pci_dev, i);
+ pci_bar_print(dev, i);
printf("\n");
}
- if (pci_bar_is64(&pci_dev, i))
+ if (pci_bar_is64(dev, i))
i++;
}
}
void pci_print(void)
{
- pcidevaddr_t dev;
+ pcidevaddr_t devfn;
+ struct pci_dev pci_dev;
- for (dev = 0; dev < PCI_DEVFN_MAX; ++dev) {
- if (pci_dev_exists(dev))
- pci_dev_print(dev);
+ for (devfn = 0; devfn < PCI_DEVFN_MAX; ++devfn) {
+ if (pci_dev_exists(devfn)) {
+ pci_dev_init(&pci_dev, devfn);
+ pci_dev_print(&pci_dev);
+ }
}
}
diff --git a/lib/pci.h b/lib/pci.h
index fefd9a8..03cc0a7 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -63,8 +63,8 @@
extern bool pci_bar_is_memory(struct pci_dev *dev, int bar_num);
extern bool pci_bar_is_valid(struct pci_dev *dev, int bar_num);
extern void pci_bar_print(struct pci_dev *dev, int bar_num);
-extern void pci_dev_print_id(pcidevaddr_t dev);
-extern void pci_dev_print(pcidevaddr_t dev);
+extern void pci_dev_print_id(struct pci_dev *dev);
+extern void pci_dev_print(struct pci_dev *dev);
extern uint8_t pci_intx_line(struct pci_dev *dev);
void pci_msi_set_enable(struct pci_dev *dev, bool enabled);