[Skiboot] [PATCH 4/4] pci: Use a macro for accessing PCI BDF Function Number
Jordan Niethe
jniethe5 at gmail.com
Fri Aug 9 14:12:20 AEST 2019
Currently when the Function Number bits of a BDF are needed the bit
operations to get it are free coded. There are many places where the
Function 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.c | 6 +++---
hw/npu2.c | 6 +++---
hw/npu3-nvlink.c | 8 ++++----
hw/phb3.c | 2 +-
include/npu2.h | 2 +-
include/pci.h | 8 ++++----
include/skiboot.h | 1 +
platforms/astbmc/vesnin.c | 2 +-
8 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/core/pci.c b/core/pci.c
index c9b262f38b93..cd6b9f3f000c 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -1470,7 +1470,7 @@ static void pci_add_loc_code(struct dt_node *np, struct pci_device *pd)
}
lcode[pos++] = '-';
lcode[pos++] = 'T';
- lcode[pos++] = (char)(pd->bdfn & 0x7) + '1';
+ lcode[pos++] = (char)PCI_FUNC(pd->bdfn) + '1';
lcode[pos++] = '\0';
dt_add_property_string(np, "ibm,loc-code", lcode);
free(lcode);
@@ -1574,9 +1574,9 @@ static void __noinline pci_add_one_device_node(struct phb *phb,
rev_class = (rev_class & 0xff) | 0x6040000;
cname = pci_class_name(rev_class >> 8);
- if (pd->bdfn & 0x7)
+ if (PCI_FUNC(pd->bdfn))
snprintf(name, MAX_NAME - 1, "%s@%x,%x",
- cname, PCI_DEV(pd->bdfn), pd->bdfn & 0x7);
+ cname, PCI_DEV(pd->bdfn), PCI_FUNC(pd->bdfn));
else
snprintf(name, MAX_NAME - 1, "%s@%x",
cname, PCI_DEV(pd->bdfn));
diff --git a/hw/npu2.c b/hw/npu2.c
index f561386f5865..06eaf4d0481c 100644
--- a/hw/npu2.c
+++ b/hw/npu2.c
@@ -584,10 +584,10 @@ static int npu2_assign_gmb(struct npu2_dev *ndev)
* the highest bdfn (fn = 6) and count back until we find a
* npu2_dev. */
for (bdfn = (ndev->bdfn & ~0x7) | NPU2_LINKS_PER_CHIP;
- (bdfn & 0x7) != 0x7; bdfn = (bdfn & ~0x7) | ((bdfn & 0x7) - 1))
+ PCI_FUNC(bdfn) != 0x7; bdfn = (bdfn & ~0x7) | (PCI_FUNC(bdfn) - 1))
if (npu2_bdf_to_dev(p, bdfn))
break;
- peers = bdfn & 0x7;
+ peers = PCI_FUNC(bdfn);
npu2_get_gpu_base(ndev, &base, &size);
@@ -625,7 +625,7 @@ static int npu2_assign_gmb(struct npu2_dev *ndev)
assert(0);
}
- mode += ndev->bdfn & 0x7;
+ mode += PCI_FUNC(ndev->bdfn);
val = SETFIELD(NPU2_MEM_BAR_MODE, val, mode);
gmb = NPU2_GPU0_MEM_BAR;
diff --git a/hw/npu3-nvlink.c b/hw/npu3-nvlink.c
index c61e1b7b5ba1..3939f2c489b1 100644
--- a/hw/npu3-nvlink.c
+++ b/hw/npu3-nvlink.c
@@ -30,7 +30,7 @@
(dev)->npu->nvlink.phb.opal_id, \
PCI_BUS_NUM((dev)->nvlink.pvd->bdfn), \
PCI_DEV((dev)->nvlink.pvd->bdfn), \
- (dev)->nvlink.pvd->bdfn & 0x7, ##a)
+ PCI_FUNC((dev)->nvlink.pvd->bdfn), ##a)
#define NPU3DEVDBG(dev, fmt, a...) NPU3DEVLOG(PR_DEBUG, dev, fmt, ##a)
#define NPU3DEVINF(dev, fmt, a...) NPU3DEVLOG(PR_INFO, dev, fmt, ##a)
#define NPU3DEVERR(dev, fmt, a...) NPU3DEVLOG(PR_ERR, dev, fmt, ##a)
@@ -614,7 +614,7 @@ static void npu3_dev_assign_gmb(struct npu3_dev *dev, uint64_t addr,
assert(0);
}
- mode += dev->nvlink.pvd->bdfn & 0x7;
+ mode += PCI_FUNC(dev->nvlink.pvd->bdfn);
val = NPU3_GPU_MEM_BAR_ENABLE |
NPU3_GPU_MEM_BAR_POISON;
@@ -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), PCI_DEV(bdf), bdf & 0x7);
+ lparshort, PCI_BUS_NUM(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
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), PCI_DEV(bdf), bdf & 0x7);
+ PCI_BUS_NUM(bdf), PCI_DEV(bdf), PCI_FUNC(bdf));
rc = OPAL_PARAMETER;
goto out;
}
diff --git a/hw/phb3.c b/hw/phb3.c
index 8d02eda1478f..e75ef677cacf 100644
--- a/hw/phb3.c
+++ b/hw/phb3.c
@@ -2146,7 +2146,7 @@ static int64_t phb3_set_pe(struct phb *phb,
all = (all << 1) | 0x1;
else {
mask |= 0x7;
- val |= (bdfn & 0x7);
+ val |= PCI_FUNC(bdfn);
}
/* Map or unmap the RTT range */
diff --git a/include/npu2.h b/include/npu2.h
index 282ee8b065c5..aac7e7a58e23 100644
--- a/include/npu2.h
+++ b/include/npu2.h
@@ -20,7 +20,7 @@
(p)->npu->phb_nvlink.opal_id, \
PCI_BUS_NUM((p)->bdfn), \
PCI_DEV((p)->bdfn), \
- (p)->bdfn & 0x7, ##a)
+ PCI_FUNC((p)->bdfn), ##a)
#define NPU2DEVDBG(p, fmt, a...) NPU2DEVLOG(PR_DEBUG, p, fmt, ##a)
#define NPU2DEVINF(p, fmt, a...) NPU2DEVLOG(PR_INFO, p, fmt, ##a)
#define NPU2DEVERR(p, fmt, a...) NPU2DEVLOG(PR_ERR, p, fmt, ##a)
diff --git a/include/pci.h b/include/pci.h
index f837e0f3fe67..220d6b187f5f 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), \
- PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), PCI_FUNC(_bdfn), ## a)
#define PCIDBG(_p, _bdfn, fmt, a...) \
prlog(PR_DEBUG, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), PCI_FUNC(_bdfn), ## a)
#define PCINOTICE(_p, _bdfn, fmt, a...) \
prlog(PR_NOTICE, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), PCI_FUNC(_bdfn), ## a)
#define PCIERR(_p, _bdfn, fmt, a...) \
prlog(PR_ERR, "PHB#%04x:%02x:%02x.%x " fmt, \
(_p)->opal_id, \
PCI_BUS_NUM(_bdfn), \
- PCI_DEV(_bdfn), (_bdfn) & 0x7, ## a)
+ PCI_DEV(_bdfn), PCI_FUNC(_bdfn), ## a)
struct pci_device;
struct pci_cfg_reg_filter;
diff --git a/include/skiboot.h b/include/skiboot.h
index 22aa58c323d8..d64aa67993e8 100644
--- a/include/skiboot.h
+++ b/include/skiboot.h
@@ -140,6 +140,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)
+#define PCI_FUNC(bdfn) ((bdfn) & 0x07)
/* 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 3204bc5a6382..bd412aa8d0a1 100644
--- a/platforms/astbmc/vesnin.c
+++ b/platforms/astbmc/vesnin.c
@@ -269,7 +269,7 @@ static int pciinv_walk(struct phb *phb, struct pci_device *pd, void *data)
pack->device.domain_num = cpu_to_be16(phb->opal_id & 0xffff);
pack->device.bus_num = PCI_BUS_NUM(pd->bdfn);
pack->device.device_num = PCI_DEV(pd->bdfn);
- pack->device.func_num = pd->bdfn & 0x7;
+ pack->device.func_num = PCI_FUNC(pd->bdfn);
pack->device.vendor_id = cpu_to_be16(PCI_VENDOR_ID(pd->vdid));
pack->device.device_id = cpu_to_be16(PCI_DEVICE_ID(pd->vdid));
pack->device.class_code = cpu_to_be32(pd->class & 0xffffff);
--
2.20.1
More information about the Skiboot
mailing list