]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
pci: use function generation macros for pci_config_{write,read}<size>
authorRoger Pau Monne <roger.pau@citrix.com>
Mon, 20 May 2019 10:24:10 +0000 (12:24 +0200)
committerRoger Pau Monne <roger.pau@citrix.com>
Mon, 20 May 2019 10:24:10 +0000 (12:24 +0200)
This avoids code duplication between the helpers.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
xen/arch/x86/x86_64/pci.c

index 6e3f5cf203eebb59226d1a49ca66b32aae966b9e..4f77beb1193a3b8847224c8428e4a5573c68a5ff 100644 (file)
 #define PCI_CONF_ADDRESS(bus, dev, func, reg) \
     (0x80000000 | (bus << 16) | (dev << 11) | (func << 8) | (reg & ~3))
 
-uint8_t pci_conf_read8(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg)
-{
-    u32 value;
-
-    if ( seg || reg > 255 )
-    {
-        pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), 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);
+#define GEN_PCI_CONF_READ(s)                                                   \
+    uint ## s ## _t pci_conf_read ## s (unsigned int seg, unsigned int bus,    \
+                                        unsigned int dev, unsigned int func,   \
+                                        unsigned int reg)                      \
+    {                                                                          \
+        uint32_t value;                                                        \
+                                                                               \
+        BUILD_BUG_ON(s != 8 && s != 16 && s != 32);                            \
+        if ( seg || reg > 255 )                                                \
+            pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, s / 8, &value);\
+        else                                                                   \
+        {                                                                      \
+            BUG_ON((bus > 255) || (dev > 31) || (func > 7));                   \
+            value = pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg),       \
+                                  reg & (4 - s / 8), s / 8);                   \
+        }                                                                      \
+                                                                               \
+        return value;                                                          \
     }
-}
 
-uint16_t pci_conf_read16(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg)
-{
-    u32 value;
+/* Grep fodder */
+#define pci_conf_read8
+#define pci_conf_read16
+#define pci_conf_read32
 
-    if ( seg || reg > 255 )
-    {
-        pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, 2, &value);
-        return value;
-    }
-    else
-    {
-        BUG_ON((bus > 255) || (dev > 31) || (func > 7));
-        return pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 2, 2);
-    }
-}
+#undef pci_conf_read8
+#undef pci_conf_read16
+#undef pci_conf_read32
 
-uint32_t pci_conf_read32(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg)
-{
-    u32 value;
+GEN_PCI_CONF_READ(8)
+GEN_PCI_CONF_READ(16)
+GEN_PCI_CONF_READ(32)
 
-    if ( seg || reg > 255 )
-    {
-        pci_mmcfg_read(seg, bus, PCI_DEVFN(dev, func), reg, 4, &value);
-        return value;
-    }
-    else
-    {
-        BUG_ON((bus > 255) || (dev > 31) || (func > 7));
-        return pci_conf_read(PCI_CONF_ADDRESS(bus, dev, func, reg), 0, 4);
-    }
-}
+#undef GEN_PCI_CONF_READ
 
-void pci_conf_write8(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg, uint8_t data)
-{
-    if ( seg || reg > 255 )
-        pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, 1, data);
-    else
-    {
-        BUG_ON((bus > 255) || (dev > 31) || (func > 7));
-        pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 3, 1, data);
+#define GEN_PCI_CONF_WRITE(s)                                                  \
+    void pci_conf_write ## s (unsigned int seg, unsigned int bus,              \
+                              unsigned int dev, unsigned int func,             \
+                              unsigned int reg, uint ## s ## _t data)          \
+    {                                                                          \
+        BUILD_BUG_ON(s != 8 && s != 16 && s != 32);                            \
+        if ( seg || reg > 255 )                                                \
+            pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, s / 8, data); \
+        else                                                                   \
+        {                                                                      \
+            BUG_ON((bus > 255) || (dev > 31) || (func > 7));                   \
+            pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg),              \
+                           reg & (4 - s / 8), s / 8, data);                    \
+        }                                                                      \
     }
-}
 
-void pci_conf_write16(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg, uint16_t data)
-{
-    if ( seg || reg > 255 )
-        pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, 2, data);
-    else
-    {
-        BUG_ON((bus > 255) || (dev > 31) || (func > 7));
-        pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), reg & 2, 2, data);
-    }
-}
+/* Grep fodder */
+#define pci_conf_write8
+#define pci_conf_write16
+#define pci_conf_write32
+
+#undef pci_conf_write8
+#undef pci_conf_write16
+#undef pci_conf_write32
+
+GEN_PCI_CONF_WRITE(8)
+GEN_PCI_CONF_WRITE(16)
+GEN_PCI_CONF_WRITE(32)
+
+#undef GEN_PCI_CONF_WRITE
 
-void pci_conf_write32(
-    unsigned int seg, unsigned int bus, unsigned int dev, unsigned int func,
-    unsigned int reg, uint32_t data)
-{
-    if ( seg || reg > 255 )
-        pci_mmcfg_write(seg, bus, PCI_DEVFN(dev, func), reg, 4, data);
-    else
-    {
-        BUG_ON((bus > 255) || (dev > 31) || (func > 7));
-        pci_conf_write(PCI_CONF_ADDRESS(bus, dev, func, reg), 0, 4, data);
-    }
-}