[Skiboot] [PATCH 3/4] pci: Use a macro for accessing PCI BDF Device Number
Jordan Niethe
jniethe5 at gmail.com
Fri Aug 9 14:12:19 AEST 2019
Currently when the Device Number bits of a BDF are needed the bit
operations to get it are free coded. There are many places where the
Device Number is used, so make a macro to use instead of free coding it
everytime.
Signed-off-by: Jordan Niethe <jniethe5 at gmail.com>
---
core/pci-dt-slot.c | 2 +-
core/pci.c | 6 +++---
hw/npu2.c | 2 +-
hw/npu3-nvlink.c | 6 +++---
include/npu2.h | 2 +-
include/pci.h | 8 ++++----
include/skiboot.h | 1 +
platforms/astbmc/vesnin.c | 2 +-
platforms/ibm-fsp/lxvpd.c | 2 +-
9 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/core/pci-dt-slot.c b/core/pci-dt-slot.c
index f0d22c3738e7..034422c2a848 100644
--- a/core/pci-dt-slot.c
+++ b/core/pci-dt-slot.c
@@ -53,7 +53,7 @@ static struct dt_node *map_phb_to_slot(struct phb *phb)
static struct dt_node *find_devfn(struct dt_node *bus, uint32_t bdfn)
{
- uint32_t port_dev_id = (bdfn >> 3) & 0x1f;
+ uint32_t port_dev_id = PCI_DEV(bdfn);
struct dt_node *child;
dt_for_each_child(bus, child)
diff --git a/core/pci.c b/core/pci.c
index 1f81c65e4933..c9b262f38b93 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -1576,10 +1576,10 @@ static void __noinline pci_add_one_device_node(struct phb *phb,
if (pd->bdfn & 0x7)
snprintf(name, MAX_NAME - 1, "%s@%x,%x",
- cname, (pd->bdfn >> 3) & 0x1f, pd->bdfn & 0x7);
+ cname, PCI_DEV(pd->bdfn), pd->bdfn & 0x7);
else
snprintf(name, MAX_NAME - 1, "%s@%x",
- cname, (pd->bdfn >> 3) & 0x1f);
+ cname, PCI_DEV(pd->bdfn));
pd->dn = np = dt_new(parent_node, name);
/*
@@ -1657,7 +1657,7 @@ static void __noinline pci_add_one_device_node(struct phb *phb,
/* Update the current interrupt swizzling level based on our own
* device number
*/
- swizzle = (swizzle + ((pd->bdfn >> 3) & 0x1f)) & 3;
+ swizzle = (swizzle + PCI_DEV(pd->bdfn)) & 3;
/* We generate a standard-swizzling interrupt map. This is pretty
* big, we *could* try to be smarter for things that aren't hotplug
diff --git a/hw/npu2.c b/hw/npu2.c
index 29c998f60ae1..f561386f5865 100644
--- a/hw/npu2.c
+++ b/hw/npu2.c
@@ -548,7 +548,7 @@ static void npu2_get_gpu_base(struct npu2_dev *ndev, uint64_t *addr, uint64_t *s
struct npu2 *p = ndev->npu;
int group;
- group = (ndev->bdfn >> 3) & 0x1f;
+ group = PCI_DEV(ndev->bdfn);
phys_map_get(ndev->npu->chip_id, p->gpu_map_type, group, addr, size);
}
diff --git a/hw/npu3-nvlink.c b/hw/npu3-nvlink.c
index 3297125e4b25..c61e1b7b5ba1 100644
--- a/hw/npu3-nvlink.c
+++ b/hw/npu3-nvlink.c
@@ -29,7 +29,7 @@
prlog(l, "NPU#%04x:%02x:%02x.%x " fmt, \
(dev)->npu->nvlink.phb.opal_id, \
PCI_BUS_NUM((dev)->nvlink.pvd->bdfn), \
- (dev)->nvlink.pvd->bdfn >> 3 & 0x1f, \
+ PCI_DEV((dev)->nvlink.pvd->bdfn), \
(dev)->nvlink.pvd->bdfn & 0x7, ##a)
#define NPU3DEVDBG(dev, fmt, a...) NPU3DEVLOG(PR_DEBUG, dev, fmt, ##a)
#define NPU3DEVINF(dev, fmt, a...) NPU3DEVLOG(PR_INFO, dev, fmt, ##a)
@@ -1594,7 +1594,7 @@ int64_t npu3_init_context(struct phb *phb, uint64_t msr, uint64_t bdf)
lparshort = GETFIELD(NPU3_XTS_BDF_MAP_LPARSHORT, map);
NPU3DBG(npu, "Found LPARSHORT 0x%x for bdf %02llx:%02llx.%llx\n",
- lparshort, PCI_BUS_NUM(bdf), bdf >> 3 & 0x1f, bdf & 0x7);
+ lparshort, PCI_BUS_NUM(bdf), PCI_DEV(bdf), bdf & 0x7);
rc = npu3_init_context_pid(npu, lparshort, msr);
if (rc)
@@ -1711,7 +1711,7 @@ int64_t npu3_map_lpar(struct phb *phb, uint64_t bdf, uint64_t lparid,
if (!dev || dev->nvlink.gpu->bdfn != bdf) {
NPU3ERR(npu, "Can't find a link for bdf %02llx:%02llx.%llx\n",
- PCI_BUS_NUM(bdf), bdf >> 3 & 0x1f, bdf & 0x7);
+ PCI_BUS_NUM(bdf), PCI_DEV(bdf), bdf & 0x7);
rc = OPAL_PARAMETER;
goto out;
}
diff --git a/include/npu2.h b/include/npu2.h
index 372d1bed2ac2..282ee8b065c5 100644
--- a/include/npu2.h
+++ b/include/npu2.h
@@ -19,7 +19,7 @@
#define NPU2DEVLOG(l, p, fmt, a...) prlog(l, "NPU%d:%d:%d.%d " fmt, \
(p)->npu->phb_nvlink.opal_id, \
PCI_BUS_NUM((p)->bdfn), \
- ((p)->bdfn >> 3) & 0x1f, \
+ PCI_DEV((p)->bdfn), \
(p)->bdfn & 0x7, ##a)
#define NPU2DEVDBG(p, fmt, a...) NPU2DEVLOG(PR_DEBUG, p, fmt, ##a)
#define NPU2DEVINF(p, fmt, a...) NPU2DEVLOG(PR_INFO, p, fmt, ##a)
diff --git a/include/pci.h b/include/pci.h
index cb330634a587..f837e0f3fe67 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -14,22 +14,22 @@
prlog(PR_TRACE, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- ((_bdfn) >> 3) & 0x1f, (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
#define PCIDBG(_p, _bdfn, fmt, a...) \
prlog(PR_DEBUG, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- ((_bdfn) >> 3) & 0x1f, (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
#define PCINOTICE(_p, _bdfn, fmt, a...) \
prlog(PR_NOTICE, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- ((_bdfn) >> 3) & 0x1f, (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
#define PCIERR(_p, _bdfn, fmt, a...) \
prlog(PR_ERR, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- ((_bdfn) >> 3) & 0x1f, (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
struct pci_device;
struct pci_cfg_reg_filter;
diff --git a/include/skiboot.h b/include/skiboot.h
index 1dc690c7aea4..22aa58c323d8 100644
--- a/include/skiboot.h
+++ b/include/skiboot.h
@@ -139,6 +139,7 @@ static inline bool is_pow2(unsigned long val)
/* PCI Geographical Addressing */
#define PCI_BUS_NUM(bdfn) (((bdfn) >> 8) & 0xff)
+#define PCI_DEV(bdfn) (((bdfn) >> 3) & 0x1f)
/* Clean the stray high bit which the FSP inserts: we only have 52 bits real */
static inline u64 cleanup_addr(u64 addr)
diff --git a/platforms/astbmc/vesnin.c b/platforms/astbmc/vesnin.c
index d138cdc3c11c..3204bc5a6382 100644
--- a/platforms/astbmc/vesnin.c
+++ b/platforms/astbmc/vesnin.c
@@ -268,7 +268,7 @@ static int pciinv_walk(struct phb *phb, struct pci_device *pd, void *data)
/* Fill the PCI device inventory description */
pack->device.domain_num = cpu_to_be16(phb->opal_id & 0xffff);
pack->device.bus_num = PCI_BUS_NUM(pd->bdfn);
- pack->device.device_num = (pd->bdfn >> 3) & 0x1f;
+ pack->device.device_num = PCI_DEV(pd->bdfn);
pack->device.func_num = pd->bdfn & 0x7;
pack->device.vendor_id = cpu_to_be16(PCI_VENDOR_ID(pd->vdid));
pack->device.device_id = cpu_to_be16(PCI_DEVICE_ID(pd->vdid));
diff --git a/platforms/ibm-fsp/lxvpd.c b/platforms/ibm-fsp/lxvpd.c
index 39c1cbfd5b72..bdebc44a7893 100644
--- a/platforms/ibm-fsp/lxvpd.c
+++ b/platforms/ibm-fsp/lxvpd.c
@@ -66,7 +66,7 @@ void *lxvpd_get_slot(struct pci_slot *slot)
struct pci_device *pd = slot->pd;
struct lxvpd_pci_slot_data *sdata = phb->platform_data;
struct lxvpd_pci_slot *s = NULL;
- uint8_t slot_num = pd ? ((pd->bdfn >> 3) & 0x1f) : 0xff;
+ uint8_t slot_num = pd ? PCI_DEV(pd->bdfn) : 0xff;
bool is_phb = (pd && pd->parent) ? false : true;
uint8_t index;
--
2.20.1
More information about the Skiboot
mailing list