]> xenbits.xensource.com Git - xen.git/commitdiff
pci: switch pci_conf_read8 to use pci_sbdf_t
authorRoger Pau Monné <roger.pau@citrix.com>
Tue, 23 Jul 2019 14:53:24 +0000 (16:53 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 23 Jul 2019 14:53:24 +0000 (16:53 +0200)
This reduces the number of parameters of the function to two, and
simplifies some of the calling sites.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Brian Woods <brian.woods@amd.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
14 files changed:
xen/arch/x86/cpu/amd.c
xen/arch/x86/msi.c
xen/arch/x86/x86_64/pci.c
xen/drivers/char/ehci-dbgp.c
xen/drivers/char/ns16550.c
xen/drivers/passthrough/amd/iommu_init.c
xen/drivers/passthrough/pci.c
xen/drivers/passthrough/vtd/dmar.c
xen/drivers/passthrough/vtd/quirks.c
xen/drivers/pci/pci.c
xen/drivers/video/vga.c
xen/drivers/vpci/header.c
xen/drivers/vpci/vpci.c
xen/include/xen/pci.h

index 839f19292d5efe62a10018abc5a7c5b1044d4b32..c6c74e75f5e649227c497161129520fe4a49c90e 100644 (file)
@@ -420,7 +420,7 @@ static void disable_c1_ramping(void)
        nr_nodes = ((pci_conf_read32(0, 0, 0x18, 0x0, 0x60)>>4)&0x07)+1;
        for (node = 0; node < nr_nodes; node++) {
                /* PMM7: bus=0, dev=0x18+node, function=0x3, register=0x87. */
-               pmm7 = pci_conf_read8(0, 0, 0x18+node, 0x3, 0x87);
+               pmm7 = pci_conf_read8(PCI_SBDF(0, 0, 0x18 + node, 3), 0x87);
                /* Invalid read means we've updated every Northbridge. */
                if (pmm7 == 0xFF)
                        break;
index 89e61160e994b606d5aec9427f95f25b72201812..ed8b89cc0fc9cdd675588bd33a846f73b07f8156 100644 (file)
@@ -800,7 +800,7 @@ static u64 read_pci_mem_bar(u16 seg, u8 bus, u8 slot, u8 func, u8 bir, int vf)
         disp = vf * pdev->vf_rlen[bir];
         limit = PCI_SRIOV_NUM_BARS;
     }
-    else switch ( pci_conf_read8(seg, bus, slot, func,
+    else switch ( pci_conf_read8(PCI_SBDF(seg, bus, slot, func),
                                  PCI_HEADER_TYPE) & 0x7f )
     {
     case PCI_HEADER_TYPE_NORMAL:
index 6e3f5cf203eebb59226d1a49ca66b32aae966b9e..b70383fb030113980f7550eda0bdfab4124cd4ec 100644 (file)
@@ -8,27 +8,26 @@
 #include <xen/pci.h>
 #include <asm/io.h>
 
-#define PCI_CONF_ADDRESS(bus, dev, func, reg) \
-    (0x80000000 | (bus << 16) | (dev << 11) | (func << 8) | (reg & ~3))
+#define PCI_CONF_ADDRESS(sbdf, reg) \
+    (0x80000000 | ((sbdf).bdf << 8) | ((reg) & ~3))
 
-uint8_t pci_conf_read8(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg)
+uint8_t pci_conf_read8(pci_sbdf_t sbdf, unsigned int reg)
 {
-    u32 value;
+    uint32_t value;
 
-    if ( seg || reg > 255 )
+    if ( sbdf.seg || reg > 255 )
     {
-        pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, 1, &value);
+        pci_mmcfg_read(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 1, &value);
         return value;
     }
-    else
-    {
-        BUG_ON((bus > 255) || (dev > 31) || (func > 7));
-        return pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 3, 1);
-    }
+
+    return pci_conf_read(PCI_CONF_ADDRESS(sbdf, reg), reg & 3, 1);
 }
 
+#undef PCI_CONF_ADDRESS
+#define PCI_CONF_ADDRESS(bus, dev, func, reg) \
+    (0x80000000 | (bus << 16) | (dev << 11) | (func << 8) | (reg & ~3))
+
 uint16_t pci_conf_read16(
     unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
     unsigned int reg)
index 475dc417679fb9ab84d028a8f528f951457da7a9..71f0aaa6ac3cf81c782d7903b1bce5a5b8b3b494 100644 (file)
@@ -713,7 +713,7 @@ static unsigned int __init find_dbgp(struct ehci_dbgp *dbgp,
                 cap = __find_dbgp(bus, slot, func);
                 if ( !cap || ehci_num-- )
                 {
-                    if ( !func && !(pci_conf_read8(0, bus, slot, func,
+                    if ( !func && !(pci_conf_read8(PCI_SBDF(0, bus, slot, func),
                                                    PCI_HEADER_TYPE) & 0x80) )
                         break;
                     continue;
@@ -1312,7 +1312,8 @@ static void __init ehci_dbgp_init_preirq(struct serial_port *port)
     offset = (debug_port >> 16) & 0xfff;
 
     /* double check if the mem space is enabled */
-    dbgp->pci_cr = pci_conf_read8(0, dbgp->bus, dbgp->slot, dbgp->func,
+    dbgp->pci_cr = pci_conf_read8(PCI_SBDF(0, dbgp->bus, dbgp->slot,
+                                           dbgp->func),
                                   PCI_COMMAND);
     if ( !(dbgp->pci_cr & PCI_COMMAND_MEMORY) )
     {
index 189e121b7e4d0c8ff25d192d488f405f39a061e3..547270d0e12505260149b9678c0c3cc2af7ba351 100644 (file)
@@ -1188,8 +1188,10 @@ pci_uart_config(struct ns16550 *uart, bool_t skip_amt, unsigned int idx)
                 uart->bar64 = bar_64;
                 uart->io_size = max(8U << param->reg_shift,
                                     param->uart_offset);
-                uart->irq = pci_conf_read8(0, b, d, f, PCI_INTERRUPT_PIN) ?
-                    pci_conf_read8(0, b, d, f, PCI_INTERRUPT_LINE) : 0;
+                uart->irq = pci_conf_read8(PCI_SBDF(0, b, d, f),
+                                           PCI_INTERRUPT_PIN) ?
+                            pci_conf_read8(PCI_SBDF(0, b, d, f),
+                                           PCI_INTERRUPT_LINE) : 0;
 
                 return 0;
             }
index a4480858cfa574c779656d7919372e4c5672c714..16f9af3a2f8081359d6acc9d7e20c35517098bb9 100644 (file)
@@ -1243,7 +1243,7 @@ static bool_t __init amd_sp5100_erratum28(void)
         if (vendor_id != 0x1002 || dev_id != 0x4385)
             continue;
 
-        byte = pci_conf_read8(0, bus, 0x14, 0, 0xad);
+        byte = pci_conf_read8(PCI_SBDF(0, bus, 0x14, 0), 0xad);
         if ( (byte >> 3) & 1 )
         {
             printk(XENLOG_WARNING "AMD-Vi: SP5100 erratum 28 detected, disabling IOMMU.\n"
index e88689425d0fc0accba3a038fe098c7594258cb4..340e957954fe07dc3fd100f2ecad2324ea8e3f81 100644 (file)
@@ -260,7 +260,7 @@ static void check_pdev(const struct pci_dev *pdev)
         }
     }
 
-    switch ( pci_conf_read8(seg, bus, dev, func, PCI_HEADER_TYPE) & 0x7f )
+    switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f )
     {
     case PCI_HEADER_TYPE_BRIDGE:
         if ( !bridge_ctl_mask )
@@ -370,10 +370,8 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
 
         case DEV_TYPE_PCIe2PCI_BRIDGE:
         case DEV_TYPE_LEGACY_PCI_BRIDGE:
-            sec_bus = pci_conf_read8(pseg->nr, bus, PCI_SLOT(devfn),
-                                     PCI_FUNC(devfn), PCI_SECONDARY_BUS);
-            sub_bus = pci_conf_read8(pseg->nr, bus, PCI_SLOT(devfn),
-                                     PCI_FUNC(devfn), PCI_SUBORDINATE_BUS);
+            sec_bus = pci_conf_read8(pdev->sbdf, PCI_SECONDARY_BUS);
+            sub_bus = pci_conf_read8(pdev->sbdf, PCI_SUBORDINATE_BUS);
 
             spin_lock(&pseg->bus2bridge_lock);
             for ( ; sec_bus <= sub_bus; sec_bus++ )
@@ -436,16 +434,12 @@ static void free_pdev(struct pci_seg *pseg, struct pci_dev *pdev)
     /* update bus2bridge */
     switch ( pdev->type )
     {
-        u8 dev, func, sec_bus, sub_bus;
+        uint8_t sec_bus, sub_bus;
 
         case DEV_TYPE_PCIe2PCI_BRIDGE:
         case DEV_TYPE_LEGACY_PCI_BRIDGE:
-            dev = PCI_SLOT(pdev->devfn);
-            func = PCI_FUNC(pdev->devfn);
-            sec_bus = pci_conf_read8(pseg->nr, pdev->bus, dev, func,
-                                     PCI_SECONDARY_BUS);
-            sub_bus = pci_conf_read8(pseg->nr, pdev->bus, dev, func,
-                                     PCI_SUBORDINATE_BUS);
+            sec_bus = pci_conf_read8(pdev->sbdf, PCI_SECONDARY_BUS);
+            sub_bus = pci_conf_read8(pdev->sbdf, PCI_SUBORDINATE_BUS);
 
             spin_lock(&pseg->bus2bridge_lock);
             for ( ; sec_bus <= sub_bus; sec_bus++ )
@@ -1082,7 +1076,8 @@ static int __init _scan_pci_devices(struct pci_seg *pseg, void *arg)
                     return -ENOMEM;
                 }
 
-                if ( !func && !(pci_conf_read8(pseg->nr, bus, dev, func,
+                if ( !func && !(pci_conf_read8(PCI_SBDF(pseg->nr, bus, dev,
+                                                        func),
                                                PCI_HEADER_TYPE) & 0x80) )
                     break;
             }
index b858fe7c805884eb3d0f4fc1f5611c4402f15cb3..9c94deac0be599b7bc3a33d2940c0aea81c8799b 100644 (file)
@@ -348,7 +348,7 @@ static int __init acpi_parse_dev_scope(
 
         while ( --depth > 0 )
         {
-            bus = pci_conf_read8(seg, bus, path->dev, path->fn,
+            bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
                                  PCI_SECONDARY_BUS);
             path++;
         }
@@ -356,9 +356,9 @@ static int __init acpi_parse_dev_scope(
         switch ( acpi_scope->entry_type )
         {
         case ACPI_DMAR_SCOPE_TYPE_BRIDGE:
-            sec_bus = pci_conf_read8(seg, bus, path->dev, path->fn,
+            sec_bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
                                      PCI_SECONDARY_BUS);
-            sub_bus = pci_conf_read8(seg, bus, path->dev, path->fn,
+            sub_bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
                                      PCI_SUBORDINATE_BUS);
             if ( iommu_verbose )
                 printk(VTDPREFIX
index d6db8626786a6991a1d267d8951a04d36dcf0c87..ff73b0e7f49825b2b6f9ad1cdf4e2cedb1e4420a 100644 (file)
@@ -92,8 +92,8 @@ static void __init cantiga_b3_errata_init(void)
     if ( vid != 0x8086 )
         return;
 
-    did_hi = pci_conf_read8(0, 0, IGD_DEV, 0, 3);
-    rid = pci_conf_read8(0, 0, IGD_DEV, 0, 8);
+    did_hi = pci_conf_read8(PCI_SBDF(0, 0, IGD_DEV, 0), 3);
+    rid = pci_conf_read8(PCI_SBDF(0, 0, IGD_DEV, 0), 8);
 
     if ( (did_hi == 0x2A) && (rid == 0x7) )
         is_cantiga_b3 = 1;
@@ -281,7 +281,7 @@ static void __init tylersburg_intremap_quirk(void)
     {
         /* Match on System Management Registers on Device 20 Function 0 */
         device = pci_conf_read32(0, bus, 20, 0, PCI_VENDOR_ID);
-        rev = pci_conf_read8(0, bus, 20, 0, PCI_REVISION_ID);
+        rev = pci_conf_read8(PCI_SBDF(0, bus, 20, 0), PCI_REVISION_ID);
 
         if ( rev == 0x13 && device == 0x342e8086 )
         {
index 1c808d6632034fa3dbcdcc935a3ba53a500b977d..e3f883fc5cc0e87da7376f5343eb3fb8bafb4121 100644 (file)
@@ -21,12 +21,12 @@ int pci_find_cap_offset(u16 seg, u8 bus, u8 dev, u8 func, u8 cap)
 
     while ( max_cap-- )
     {
-        pos = pci_conf_read8(seg, bus, dev, func, pos);
+        pos = pci_conf_read8(PCI_SBDF(seg, bus, dev, func), pos);
         if ( pos < 0x40 )
             break;
 
         pos &= ~3;
-        id = pci_conf_read8(seg, bus, dev, func, pos + PCI_CAP_LIST_ID);
+        id = pci_conf_read8(PCI_SBDF(seg, bus, dev, func), pos + PCI_CAP_LIST_ID);
 
         if ( id == 0xff )
             break;
@@ -46,13 +46,12 @@ int pci_find_next_cap(u16 seg, u8 bus, unsigned int devfn, u8 pos, int cap)
 
     while ( ttl-- )
     {
-        pos = pci_conf_read8(seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), pos);
+        pos = pci_conf_read8(PCI_SBDF3(seg, bus, devfn), pos);
         if ( pos < 0x40 )
             break;
 
         pos &= ~3;
-        id = pci_conf_read8(seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
-                            pos + PCI_CAP_LIST_ID);
+        id = pci_conf_read8(PCI_SBDF3(seg, bus, devfn), pos + PCI_CAP_LIST_ID);
 
         if ( id == 0xff )
             break;
index 6a64fd90135ab01acfcf855cb8b44ac7e2984112..78533ad0b1744282f9b59cb6e8980f2caa03f345 100644 (file)
@@ -136,8 +136,7 @@ void __init video_endboot(void)
                         b = 0;
                         break;
                     case 1:
-                        switch ( pci_conf_read8(0, b, PCI_SLOT(df),
-                                                PCI_FUNC(df),
+                        switch ( pci_conf_read8(PCI_SBDF3(0, b, df),
                                                 PCI_HEADER_TYPE) )
                         {
                         case PCI_HEADER_TYPE_BRIDGE:
index 258b91deed0913e5a78fe2e45dde6c561a400dfc..564c7b6a7d42b7b17355b5c98fd33a2be79b0820 100644 (file)
@@ -463,8 +463,7 @@ static int init_bars(struct pci_dev *pdev)
     struct vpci_bar *bars = header->bars;
     int rc;
 
-    switch ( pci_conf_read8(pdev->seg, pdev->bus, slot, func, PCI_HEADER_TYPE)
-             & 0x7f )
+    switch ( pci_conf_read8(pdev->sbdf, PCI_HEADER_TYPE) & 0x7f )
     {
     case PCI_HEADER_TYPE_NORMAL:
         num_bars = PCI_HEADER_NORMAL_NR_BARS;
index ca598675eabc0046963ec84ed5c47944946ca9f2..c4030333a57c1ad472ef4e81c96d9839227ab8f8 100644 (file)
@@ -222,8 +222,7 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg,
          */
         if ( reg & 1 )
         {
-            data = pci_conf_read8(sbdf.seg, sbdf.bus, sbdf.dev, sbdf.fn,
-                                  reg);
+            data = pci_conf_read8(sbdf, reg);
             data |= pci_conf_read16(sbdf.seg, sbdf.bus, sbdf.dev, sbdf.fn,
                                     reg + 1) << 8;
         }
@@ -231,8 +230,7 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg,
         {
             data = pci_conf_read16(sbdf.seg, sbdf.bus, sbdf.dev, sbdf.fn,
                                    reg);
-            data |= pci_conf_read8(sbdf.seg, sbdf.bus, sbdf.dev, sbdf.fn,
-                                   reg + 2) << 16;
+            data |= pci_conf_read8(sbdf, reg + 2) << 16;
         }
         break;
 
@@ -241,7 +239,7 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int reg,
         break;
 
     case 1:
-        data = pci_conf_read8(sbdf.seg, sbdf.bus, sbdf.dev, sbdf.fn, reg);
+        data = pci_conf_read8(sbdf, reg);
         break;
 
     default:
index 04a9f46cc32ffc56452efa022b03ea19d6e0f06a..408cd1cb674fcb11ad3f0e73bdeb6bb540c1ea98 100644 (file)
@@ -172,9 +172,7 @@ struct pci_dev *pci_get_pdev_by_domain(const struct domain *, int seg,
                                        int bus, int devfn);
 void pci_check_disable_device(u16 seg, u8 bus, u8 devfn);
 
-uint8_t pci_conf_read8(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg);
+uint8_t pci_conf_read8(pci_sbdf_t sbdf, unsigned int reg);
 uint16_t pci_conf_read16(
     unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
     unsigned int reg);