Skip to content

Commit

Permalink
pci: Use a macro for accessing PCI BDF Device Number
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
iamjpn authored and oohal committed Aug 16, 2019
1 parent df15dcf commit f68639c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/pci-dt-slot.c
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions core/pci.c
Expand Up @@ -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);

/*
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hw/npu2.c
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions hw/npu3-nvlink.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion include/npu2.h
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions include/pci.h
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/skiboot.h
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion platforms/astbmc/vesnin.c
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion platforms/ibm-fsp/lxvpd.c
Expand Up @@ -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;

Expand Down

0 comments on commit f68639c

Please sign in to comment.