]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: Add pci_resource_is_bridge_win()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 19 Dec 2025 17:40:23 +0000 (19:40 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 27 Jan 2026 22:36:52 +0000 (16:36 -0600)
Add pci_resource_is_bridge_win() helper to simplify checking if the
resource is a bridge window.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20251219174036.16738-11-ilpo.jarvinen@linux.intel.com
drivers/pci/pci-sysfs.c
drivers/pci/pci.h
drivers/pci/setup-bus.c
drivers/pci/setup-res.c

index c2df915ad2d29835ad0404f7636c31ec2847f04c..363187ba4f56c57ba766e978caa531fceb5b4ba9 100644 (file)
@@ -181,7 +181,7 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
                struct resource zerores = {};
 
                /* For backwards compatibility */
-               if (i >= PCI_BRIDGE_RESOURCES && i <= PCI_BRIDGE_RESOURCE_END &&
+               if (pci_resource_is_bridge_win(i) &&
                    res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
                        res = &zerores;
 
index 0e67014aa0013a7086c3a45d576d4b1ca2bb159f..c27144af550f9a9b9247bdb565646a3d8c9f46a0 100644 (file)
@@ -452,6 +452,11 @@ void pci_walk_bus_locked(struct pci_bus *top,
 
 const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
 bool pci_resource_is_optional(const struct pci_dev *dev, int resno);
+static inline bool pci_resource_is_bridge_win(int resno)
+{
+       return resno >= PCI_BRIDGE_RESOURCES &&
+              resno <= PCI_BRIDGE_RESOURCE_END;
+}
 
 /**
  * pci_resource_num - Reverse lookup resource number from device resources
index 41417084ddf844566abffe6217fb0c3dc40ecda6..403139d8c86acea9fff6886a7cea5805120dfc9c 100644 (file)
@@ -303,8 +303,7 @@ static bool pdev_resource_assignable(struct pci_dev *dev, struct resource *res)
        if (!res->flags)
                return false;
 
-       if (idx >= PCI_BRIDGE_RESOURCES && idx <= PCI_BRIDGE_RESOURCE_END &&
-           res->flags & IORESOURCE_DISABLED)
+       if (pci_resource_is_bridge_win(idx) && res->flags & IORESOURCE_DISABLED)
                return false;
 
        return true;
@@ -389,7 +388,7 @@ static inline void reset_resource(struct pci_dev *dev, struct resource *res)
 {
        int idx = pci_resource_num(dev, res);
 
-       if (idx >= PCI_BRIDGE_RESOURCES && idx <= PCI_BRIDGE_RESOURCE_END) {
+       if (pci_resource_is_bridge_win(idx)) {
                res->flags |= IORESOURCE_UNSET;
                return;
        }
@@ -985,7 +984,7 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
 {
        int ret = -EINVAL;
 
-       if (i < PCI_BRIDGE_RESOURCES || i > PCI_BRIDGE_RESOURCE_END)
+       if (!pci_resource_is_bridge_win(i))
                return 0;
 
        if (pci_claim_resource(bridge, i) == 0)
index e5fcadfc58b0180305c1514a251ee46e1051ae89..bb2aef373d6fc0e9da123ee016de3bb5ed434dc8 100644 (file)
@@ -359,7 +359,7 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
 
        res->flags &= ~IORESOURCE_UNSET;
        res->flags &= ~IORESOURCE_STARTALIGN;
-       if (resno >= PCI_BRIDGE_RESOURCES && resno <= PCI_BRIDGE_RESOURCE_END)
+       if (pci_resource_is_bridge_win(resno))
                res->flags &= ~IORESOURCE_DISABLED;
 
        pci_info(dev, "%s %pR: assigned\n", res_name, res);