mirror of
https://github.com/torvalds/linux.git
synced 2026-06-03 12:03:54 +02:00
PCI: Add pci_resource_num() helper
A few places in PCI code, mainly in setup-bus.c, need to reverse lookup the index of a resource in pci_dev's resource array. Create pci_resource_num() helper to avoid repeating the pointer arithmetic trick used to calculate the index. Link: https://lore.kernel.org/r/20241216175632.4175-11-ilpo.jarvinen@linux.intel.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Tested-by: Xiaochun Lee <lixc17@lenovo.com>
This commit is contained in:
parent
2bd0c72117
commit
e4728eed24
|
|
@ -334,6 +334,28 @@ void pci_walk_bus_locked(struct pci_bus *top,
|
|||
|
||||
const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
|
||||
|
||||
/**
|
||||
* pci_resource_num - Reverse lookup resource number from device resources
|
||||
* @dev: PCI device
|
||||
* @res: Resource to lookup index for (MUST be a @dev's resource)
|
||||
*
|
||||
* Perform reverse lookup to determine the resource number for @res within
|
||||
* @dev resource array. NOTE: The caller is responsible for ensuring @res is
|
||||
* among @dev's resources!
|
||||
*
|
||||
* Returns: resource number.
|
||||
*/
|
||||
static inline int pci_resource_num(const struct pci_dev *dev,
|
||||
const struct resource *res)
|
||||
{
|
||||
int resno = res - &dev->resource[0];
|
||||
|
||||
/* Passing a resource that is not among dev's resources? */
|
||||
WARN_ON_ONCE(resno >= PCI_NUM_RESOURCES);
|
||||
|
||||
return resno;
|
||||
}
|
||||
|
||||
void pci_reassigndev_resource_alignment(struct pci_dev *dev);
|
||||
void pci_disable_bridge_window(struct pci_dev *dev);
|
||||
struct pci_bus *pci_bus_get(struct pci_bus *bus);
|
||||
|
|
@ -693,7 +715,7 @@ unsigned long pci_cardbus_resource_alignment(struct resource *);
|
|||
static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
|
||||
struct resource *res)
|
||||
{
|
||||
int resno = res - dev->resource;
|
||||
int resno = pci_resource_num(dev, res);
|
||||
|
||||
if (pci_resource_is_iov(resno))
|
||||
return pci_sriov_resource_alignment(dev, resno);
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
|
|||
if (!found_match) /* Just skip */
|
||||
continue;
|
||||
|
||||
idx = res - &add_res->dev->resource[0];
|
||||
idx = pci_resource_num(add_res->dev, res);
|
||||
res_name = pci_resource_name(add_res->dev, idx);
|
||||
add_size = add_res->add_size;
|
||||
align = add_res->min_align;
|
||||
|
|
@ -284,7 +284,7 @@ static void assign_requested_resources_sorted(struct list_head *head,
|
|||
|
||||
list_for_each_entry(dev_res, head, list) {
|
||||
res = dev_res->res;
|
||||
idx = res - &dev_res->dev->resource[0];
|
||||
idx = pci_resource_num(dev_res->dev, res);
|
||||
|
||||
if (!resource_size(res))
|
||||
continue;
|
||||
|
|
@ -2210,7 +2210,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
|
|||
res->flags = fail_res->flags;
|
||||
|
||||
if (pci_is_bridge(fail_res->dev)) {
|
||||
idx = res - &fail_res->dev->resource[0];
|
||||
idx = pci_resource_num(fail_res->dev, res);
|
||||
if (idx >= PCI_BRIDGE_RESOURCES &&
|
||||
idx <= PCI_BRIDGE_RESOURCE_END)
|
||||
res->flags = 0;
|
||||
|
|
@ -2294,7 +2294,7 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
|
|||
res->flags = fail_res->flags;
|
||||
|
||||
if (pci_is_bridge(fail_res->dev)) {
|
||||
idx = res - &fail_res->dev->resource[0];
|
||||
idx = pci_resource_num(fail_res->dev, res);
|
||||
if (idx >= PCI_BRIDGE_RESOURCES &&
|
||||
idx <= PCI_BRIDGE_RESOURCE_END)
|
||||
res->flags = 0;
|
||||
|
|
@ -2401,7 +2401,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
|
|||
struct resource *res = dev_res->res;
|
||||
|
||||
bridge = dev_res->dev;
|
||||
i = res - bridge->resource;
|
||||
i = pci_resource_num(bridge, res);
|
||||
|
||||
res->start = dev_res->start;
|
||||
res->end = dev_res->end;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user