Commit 02992064 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Bjorn Helgaas

PCI: Make pci_bus_for_each_resource() index optional

Refactor pci_bus_for_each_resource() in the same way as
pci_dev_for_each_resource(). This allows the index to be hidden inside the
implementation so the caller can omit it when it's not used otherwise.

No functional changes intended.

Link: https://lore.kernel.org/r/20230330162434.35055-6-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Reviewed-by: default avatarKrzysztof Wilczyński <kw@linux.com>
Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@linaro.org>
parent ceb928be
...@@ -161,13 +161,13 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, ...@@ -161,13 +161,13 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
void *alignf_data, void *alignf_data,
struct pci_bus_region *region) struct pci_bus_region *region)
{ {
int i, ret;
struct resource *r, avail; struct resource *r, avail;
resource_size_t max; resource_size_t max;
int ret;
type_mask |= IORESOURCE_TYPE_BITS; type_mask |= IORESOURCE_TYPE_BITS;
pci_bus_for_each_resource(bus, r, i) { pci_bus_for_each_resource(bus, r) {
resource_size_t min_used = min; resource_size_t min_used = min;
if (!r) if (!r)
...@@ -268,9 +268,8 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx) ...@@ -268,9 +268,8 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
struct resource *res = &dev->resource[idx]; struct resource *res = &dev->resource[idx];
struct resource orig_res = *res; struct resource orig_res = *res;
struct resource *r; struct resource *r;
int i;
pci_bus_for_each_resource(bus, r, i) { pci_bus_for_each_resource(bus, r) {
resource_size_t start, end; resource_size_t start, end;
if (!r) if (!r)
......
...@@ -24,16 +24,16 @@ ...@@ -24,16 +24,16 @@
static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct pci_dev *pdev; struct pci_dev *pdev;
int index, busnr;
struct resource *res; struct resource *res;
struct pci_bus *bus; struct pci_bus *bus;
size_t len = 0; size_t len = 0;
int busnr;
pdev = to_pci_dev(dev); pdev = to_pci_dev(dev);
bus = pdev->subordinate; bus = pdev->subordinate;
len += sysfs_emit_at(buf, len, "Free resources: memory\n"); len += sysfs_emit_at(buf, len, "Free resources: memory\n");
pci_bus_for_each_resource(bus, res, index) { pci_bus_for_each_resource(bus, res) {
if (res && (res->flags & IORESOURCE_MEM) && if (res && (res->flags & IORESOURCE_MEM) &&
!(res->flags & IORESOURCE_PREFETCH)) { !(res->flags & IORESOURCE_PREFETCH)) {
len += sysfs_emit_at(buf, len, len += sysfs_emit_at(buf, len,
...@@ -43,7 +43,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char ...@@ -43,7 +43,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char
} }
} }
len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n"); len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
pci_bus_for_each_resource(bus, res, index) { pci_bus_for_each_resource(bus, res) {
if (res && (res->flags & IORESOURCE_MEM) && if (res && (res->flags & IORESOURCE_MEM) &&
(res->flags & IORESOURCE_PREFETCH)) { (res->flags & IORESOURCE_PREFETCH)) {
len += sysfs_emit_at(buf, len, len += sysfs_emit_at(buf, len,
...@@ -53,7 +53,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char ...@@ -53,7 +53,7 @@ static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char
} }
} }
len += sysfs_emit_at(buf, len, "Free resources: IO\n"); len += sysfs_emit_at(buf, len, "Free resources: IO\n");
pci_bus_for_each_resource(bus, res, index) { pci_bus_for_each_resource(bus, res) {
if (res && (res->flags & IORESOURCE_IO)) { if (res && (res->flags & IORESOURCE_IO)) {
len += sysfs_emit_at(buf, len, len += sysfs_emit_at(buf, len,
"start = %8.8llx, length = %8.8llx\n", "start = %8.8llx, length = %8.8llx\n",
......
...@@ -779,9 +779,8 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev, ...@@ -779,9 +779,8 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,
{ {
const struct pci_bus *bus = dev->bus; const struct pci_bus *bus = dev->bus;
struct resource *r; struct resource *r;
int i;
pci_bus_for_each_resource(bus, r, i) { pci_bus_for_each_resource(bus, r) {
if (!r) if (!r)
continue; continue;
if (resource_contains(r, res)) { if (resource_contains(r, res)) {
......
...@@ -533,7 +533,7 @@ void pci_read_bridge_bases(struct pci_bus *child) ...@@ -533,7 +533,7 @@ void pci_read_bridge_bases(struct pci_bus *child)
pci_read_bridge_mmio_pref(child); pci_read_bridge_mmio_pref(child);
if (dev->transparent) { if (dev->transparent) {
pci_bus_for_each_resource(child->parent, res, i) { pci_bus_for_each_resource(child->parent, res) {
if (res && res->flags) { if (res && res->flags) {
pci_bus_add_resource(child, res, pci_bus_add_resource(child, res,
PCI_SUBTRACTIVE_DECODE); PCI_SUBTRACTIVE_DECODE);
......
...@@ -770,9 +770,8 @@ static struct resource *find_bus_resource_of_type(struct pci_bus *bus, ...@@ -770,9 +770,8 @@ static struct resource *find_bus_resource_of_type(struct pci_bus *bus,
unsigned long type) unsigned long type)
{ {
struct resource *r, *r_assigned = NULL; struct resource *r, *r_assigned = NULL;
int i;
pci_bus_for_each_resource(bus, r, i) { pci_bus_for_each_resource(bus, r) {
if (r == &ioport_resource || r == &iomem_resource) if (r == &ioport_resource || r == &iomem_resource)
continue; continue;
if (r && (r->flags & type_mask) == type && !r->parent) if (r && (r->flags & type_mask) == type && !r->parent)
...@@ -1204,7 +1203,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) ...@@ -1204,7 +1203,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
additional_mmio_pref_size = 0; additional_mmio_pref_size = 0;
struct resource *pref; struct resource *pref;
struct pci_host_bridge *host; struct pci_host_bridge *host;
int hdr_type, i, ret; int hdr_type, ret;
list_for_each_entry(dev, &bus->devices, bus_list) { list_for_each_entry(dev, &bus->devices, bus_list) {
struct pci_bus *b = dev->subordinate; struct pci_bus *b = dev->subordinate;
...@@ -1228,7 +1227,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) ...@@ -1228,7 +1227,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
host = to_pci_host_bridge(bus->bridge); host = to_pci_host_bridge(bus->bridge);
if (!host->size_windows) if (!host->size_windows)
return; return;
pci_bus_for_each_resource(bus, pref, i) pci_bus_for_each_resource(bus, pref)
if (pref && (pref->flags & IORESOURCE_PREFETCH)) if (pref && (pref->flags & IORESOURCE_PREFETCH))
break; break;
hdr_type = -1; /* Intentionally invalid - not a PCI device. */ hdr_type = -1; /* Intentionally invalid - not a PCI device. */
...@@ -1333,12 +1332,11 @@ EXPORT_SYMBOL(pci_bus_size_bridges); ...@@ -1333,12 +1332,11 @@ EXPORT_SYMBOL(pci_bus_size_bridges);
static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r)
{ {
int i;
struct resource *parent_r; struct resource *parent_r;
unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM | unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM |
IORESOURCE_PREFETCH; IORESOURCE_PREFETCH;
pci_bus_for_each_resource(b, parent_r, i) { pci_bus_for_each_resource(b, parent_r) {
if (!parent_r) if (!parent_r)
continue; continue;
......
...@@ -1444,11 +1444,21 @@ int devm_request_pci_bus_resources(struct device *dev, ...@@ -1444,11 +1444,21 @@ int devm_request_pci_bus_resources(struct device *dev,
/* Temporary until new and working PCI SBR API in place */ /* Temporary until new and working PCI SBR API in place */
int pci_bridge_secondary_bus_reset(struct pci_dev *dev); int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
#define __pci_bus_for_each_res0(bus, res, ...) \
for (unsigned int __b = 0; \
(res = pci_bus_resource_n(bus, __b)) || __b < PCI_BRIDGE_RESOURCE_NUM; \
__b++)
#define __pci_bus_for_each_res1(bus, res, __b) \
for (__b = 0; \
(res = pci_bus_resource_n(bus, __b)) || __b < PCI_BRIDGE_RESOURCE_NUM; \
__b++)
/** /**
* pci_bus_for_each_resource - iterate over PCI bus resources * pci_bus_for_each_resource - iterate over PCI bus resources
* @bus: the PCI bus * @bus: the PCI bus
* @res: pointer to the current resource * @res: pointer to the current resource
* @i: index of the current resource * @...: optional index of the current resource
* *
* Iterate over PCI bus resources. The first part is to go over PCI bus * Iterate over PCI bus resources. The first part is to go over PCI bus
* resource array, which has at most the %PCI_BRIDGE_RESOURCE_NUM entries. * resource array, which has at most the %PCI_BRIDGE_RESOURCE_NUM entries.
...@@ -1461,13 +1471,17 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev); ...@@ -1461,13 +1471,17 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
* struct resource *res; * struct resource *res;
* unsigned int i; * unsigned int i;
* *
* // With optional index
* pci_bus_for_each_resource(bus, res, i) * pci_bus_for_each_resource(bus, res, i)
* pr_info("PCI bus resource[%u]: %pR\n", i, res); * pr_info("PCI bus resource[%u]: %pR\n", i, res);
*
* // Without index
* pci_bus_for_each_resource(bus, res)
* _do_something_(res);
*/ */
#define pci_bus_for_each_resource(bus, res, i) \ #define pci_bus_for_each_resource(bus, res, ...) \
for (i = 0; \ CONCATENATE(__pci_bus_for_each_res, COUNT_ARGS(__VA_ARGS__)) \
(res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \ (bus, res, __VA_ARGS__)
i++)
int __must_check pci_bus_alloc_resource(struct pci_bus *bus, int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
struct resource *res, resource_size_t size, struct resource *res, resource_size_t size,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment