Skip to content

Commit

Permalink
pci: Make handling of config filters generic
Browse files Browse the repository at this point in the history
Move phb3_pcicfg_filter() to pci.c, rename it to pci_handle_cfg_filters()

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
ozbenh authored and stewartsmith committed Jun 6, 2017
1 parent 94920c4 commit 5bbbb39
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
24 changes: 23 additions & 1 deletion core/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,11 +1768,33 @@ struct pci_cfg_reg_filter *pci_find_cfg_reg_filter(struct pci_device *pd,
return NULL;
}

bool pci_device_has_cfg_reg_filters(struct phb *phb, uint16_t bdfn)
static bool pci_device_has_cfg_reg_filters(struct phb *phb, uint16_t bdfn)
{
return bitmap_tst_bit(*phb->filter_map, bdfn);
}

int64_t pci_handle_cfg_filters(struct phb *phb, uint32_t bdfn,
uint32_t offset, uint32_t len,
uint32_t *data, bool write)
{
struct pci_device *pd;
struct pci_cfg_reg_filter *pcrf;
uint32_t flags;

if (!pci_device_has_cfg_reg_filters(phb, bdfn))
return OPAL_PARTIAL;
pd = pci_find_dev(phb, bdfn);
pcrf = pd ? pci_find_cfg_reg_filter(pd, offset, len) : NULL;
if (!pcrf || !pcrf->func)
return OPAL_PARTIAL;

flags = write ? PCI_REG_FLAG_WRITE : PCI_REG_FLAG_READ;
if ((pcrf->flags & flags) != flags)
return OPAL_PARTIAL;

return pcrf->func(pd, pcrf, offset, len, data, write);
}

struct pci_cfg_reg_filter *pci_add_cfg_reg_filter(struct pci_device *pd,
uint32_t start, uint32_t len,
uint32_t flags,
Expand Down
30 changes: 4 additions & 26 deletions hw/phb3.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,6 @@ static int64_t phb3_pcicfg_rc_link_speed(void *dev,
return OPAL_PARTIAL;
}

static int64_t phb3_pcicfg_filter(struct phb *phb, uint32_t bdfn,
uint32_t offset, uint32_t len,
uint32_t *data, bool write)
{
struct pci_device *pd;
struct pci_cfg_reg_filter *pcrf;
uint32_t flags;

if (!pci_device_has_cfg_reg_filters(phb, bdfn))
return OPAL_PARTIAL;
pd = pci_find_dev(phb, bdfn);
pcrf = pd ? pci_find_cfg_reg_filter(pd, offset, len) : NULL;
if (!pcrf || !pcrf->func)
return OPAL_PARTIAL;

flags = write ? PCI_REG_FLAG_WRITE : PCI_REG_FLAG_READ;
if ((pcrf->flags & flags) != flags)
return OPAL_PARTIAL;

return pcrf->func(pd, pcrf, offset, len, data, write);
}

#define PHB3_PCI_CFG_READ(size, type) \
static int64_t phb3_pcicfg_read##size(struct phb *phb, uint32_t bdfn, \
uint32_t offset, type *data) \
Expand All @@ -285,8 +263,8 @@ static int64_t phb3_pcicfg_read##size(struct phb *phb, uint32_t bdfn, \
return OPAL_HARDWARE; \
} \
\
rc = phb3_pcicfg_filter(phb, bdfn, offset, sizeof(type), \
(uint32_t *)data, false); \
rc = pci_handle_cfg_filters(phb, bdfn, offset, sizeof(type), \
(uint32_t *)data, false); \
if (rc != OPAL_PARTIAL) \
return rc; \
\
Expand Down Expand Up @@ -330,8 +308,8 @@ static int64_t phb3_pcicfg_write##size(struct phb *phb, uint32_t bdfn, \
return OPAL_HARDWARE; \
} \
\
rc = phb3_pcicfg_filter(phb, bdfn, offset, sizeof(type), \
(uint32_t *)&data, true); \
rc = pci_handle_cfg_filters(phb, bdfn, offset, sizeof(type), \
(uint32_t *)&data, true); \
if (rc != OPAL_PARTIAL) \
return rc; \
\
Expand Down
4 changes: 3 additions & 1 deletion include/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,11 @@ extern struct pci_device *pci_walk_dev(struct phb *phb,
void *userdata);
extern struct pci_device *pci_find_dev(struct phb *phb, uint16_t bdfn);
extern void pci_restore_bridge_buses(struct phb *phb, struct pci_device *pd);
extern bool pci_device_has_cfg_reg_filters(struct phb *phb, uint16_t bdfn);
extern struct pci_cfg_reg_filter *pci_find_cfg_reg_filter(struct pci_device *pd,
uint32_t start, uint32_t len);
extern int64_t pci_handle_cfg_filters(struct phb *phb, uint32_t bdfn,
uint32_t offset, uint32_t len,
uint32_t *data, bool write);
extern struct pci_cfg_reg_filter *pci_add_cfg_reg_filter(struct pci_device *pd,
uint32_t start, uint32_t len,
uint32_t flags, pci_cfg_reg_func func);
Expand Down

0 comments on commit 5bbbb39

Please sign in to comment.