Skip to content

Commit

Permalink
core/pci: Allow associating parameter with capability
Browse files Browse the repository at this point in the history
When we start to support SRIOV capability in subsequent patches,
a data struct will be instantiated and associated with the SRIOV
capability. This extends the current implementation for that.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
Gavin Shan authored and stewartsmith committed Feb 16, 2017
1 parent 6f05217 commit b200ee0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void pci_init_pcie_cap(struct phb *phb, struct pci_device *pd)
return;
}

pci_set_cap(pd, PCI_CFG_CAP_ID_EXP, ecap, false);
pci_set_cap(pd, PCI_CFG_CAP_ID_EXP, ecap, NULL, false);

/*
* XXX We observe a problem on some PLX switches where one
Expand Down Expand Up @@ -197,7 +197,7 @@ static void pci_init_aer_cap(struct phb *phb, struct pci_device *pd)

pos = pci_find_ecap(phb, pd->bdfn, PCIECAP_ID_AER, NULL);
if (pos > 0)
pci_set_cap(pd, PCIECAP_ID_AER, pos, true);
pci_set_cap(pd, PCIECAP_ID_AER, pos, NULL, true);
}

void pci_init_capabilities(struct phb *phb, struct pci_device *pd)
Expand Down
27 changes: 20 additions & 7 deletions include/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ struct pci_device {
uint32_t sub_vdid;
uint32_t class;
uint64_t cap_list;
uint32_t cap[64];
struct {
uint32_t pos;
void *data;
} cap[64];
uint32_t mps; /* Max payload size capability */

uint32_t pcrf_start;
Expand All @@ -88,15 +91,17 @@ struct pci_device {
struct list_node link;
};

static inline void pci_set_cap(struct pci_device *pd,
int id, int pos, bool ext)
static inline void pci_set_cap(struct pci_device *pd, int id,
int pos, void *data, bool ext)
{
if (!ext) {
pd->cap_list |= (0x1ul << id);
pd->cap[id] = pos;
pd->cap[id].pos = pos;
pd->cap[id].data = data;
} else {
pd->cap_list |= (0x1ul << (id + 32));
pd->cap[id + 32] = pos;
pd->cap[id + 32].pos = pos;
pd->cap[id + 32].data = data;
}
}

Expand All @@ -113,9 +118,17 @@ static inline int pci_cap(struct pci_device *pd,
int id, bool ext)
{
if (!ext)
return pd->cap[id];
return pd->cap[id].pos;
else
return pd->cap[id + 32];
return pd->cap[id + 32].pos;
}

static inline void *pci_cap_data(struct pci_device *pd, int id, bool ext)
{
if (!ext)
return pd->cap[id].data;
else
return pd->cap[id + 32].data;
}

/*
Expand Down

0 comments on commit b200ee0

Please sign in to comment.