aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Niethe <jniethe5@gmail.com>2019-08-09 14:12:19 +1000
committerOliver O'Halloran <oohall@gmail.com>2019-08-16 15:51:55 +1000
commitf68639c6fcdf9261290a4601eda1ae6a406ba95a (patch)
tree5badd225d6b18b5b3595e1181f1697e99c8b388b
parentdf15dcfc8acc83591889fa3b33100734a6b6bdb7 (diff)
downloadskiboot-f68639c6fcdf9261290a4601eda1ae6a406ba95a.zip
skiboot-f68639c6fcdf9261290a4601eda1ae6a406ba95a.tar.gz
skiboot-f68639c6fcdf9261290a4601eda1ae6a406ba95a.tar.bz2
pci: Use a macro for accessing PCI BDF Device Number
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@gmail.com> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
-rw-r--r--core/pci-dt-slot.c2
-rw-r--r--core/pci.c6
-rw-r--r--hw/npu2.c2
-rw-r--r--hw/npu3-nvlink.c6
-rw-r--r--include/npu2.h2
-rw-r--r--include/pci.h8
-rw-r--r--include/skiboot.h1
-rw-r--r--platforms/astbmc/vesnin.c2
-rw-r--r--platforms/ibm-fsp/lxvpd.c2
9 files changed, 16 insertions, 15 deletions
diff --git a/core/pci-dt-slot.c b/core/pci-dt-slot.c
index f0d22c3..034422c 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 1f81c65..c9b262f 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 29c998f..f561386 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 3297125..c61e1b7 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 372d1be..282ee8b 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 cb33063..f837e0f 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 4db265f..7ea17bf 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 d138cdc..3204bc5 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 39c1cbf..bdebc44 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;