PCI: Add pci_resource_is_iov() to identify IOV resources
authorMichał Winiarski <michal.winiarski@intel.com>
Mon, 16 Dec 2024 17:56:15 +0000 (19:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 18 Feb 2025 21:40:52 +0000 (15:40 -0600)
There are multiple places where special handling is required for IOV
resources.

Extract the identification of IOV resources to pci_resource_is_iov() and
drop a few ifdefs.

Link: https://lore.kernel.org/r/20241216175632.4175-9-ilpo.jarvinen@linux.intel.com
Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Tested-by: Xiaochun Lee <lixc17@lenovo.com>
drivers/pci/pci.h
drivers/pci/setup-bus.c
drivers/pci/setup-res.c

index 01e51db8d285af54673db3ea526ceda073c94ec9..89599e63f60ce98935f83b33053fdd27ec25b079 100644 (file)
@@ -632,6 +632,10 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
 resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
 void pci_restore_iov_state(struct pci_dev *dev);
 int pci_iov_bus_range(struct pci_bus *bus);
+static inline bool pci_resource_is_iov(int resno)
+{
+       return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END;
+}
 extern const struct attribute_group sriov_pf_dev_attr_group;
 extern const struct attribute_group sriov_vf_dev_attr_group;
 #else
@@ -641,12 +645,21 @@ static inline int pci_iov_init(struct pci_dev *dev)
 }
 static inline void pci_iov_release(struct pci_dev *dev) { }
 static inline void pci_iov_remove(struct pci_dev *dev) { }
+static inline void pci_iov_update_resource(struct pci_dev *dev, int resno) { }
+static inline resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev,
+                                                          int resno)
+{
+       return 0;
+}
 static inline void pci_restore_iov_state(struct pci_dev *dev) { }
 static inline int pci_iov_bus_range(struct pci_bus *bus)
 {
        return 0;
 }
-
+static inline bool pci_resource_is_iov(int resno)
+{
+       return false;
+}
 #endif /* CONFIG_PCI_IOV */
 
 #ifdef CONFIG_PCIE_TPH
@@ -680,12 +693,10 @@ unsigned long pci_cardbus_resource_alignment(struct resource *);
 static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
                                                     struct resource *res)
 {
-#ifdef CONFIG_PCI_IOV
        int resno = res - dev->resource;
 
-       if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
+       if (pci_resource_is_iov(resno))
                return pci_sriov_resource_alignment(dev, resno);
-#endif
        if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
                return pci_cardbus_resource_alignment(res);
        return resource_alignment(res);
index d273b50420179cbab4b50d97e23d98568d621b1a..5f3215e0904d878fbb300102d157bcc6f5a29ea6 100644 (file)
@@ -1093,17 +1093,16 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
                             (r->flags & mask) != type3))
                                continue;
                        r_size = resource_size(r);
-#ifdef CONFIG_PCI_IOV
+
                        /* Put SRIOV requested res to the optional list */
-                       if (realloc_head && i >= PCI_IOV_RESOURCES &&
-                                       i <= PCI_IOV_RESOURCE_END) {
+                       if (realloc_head && pci_resource_is_iov(i)) {
                                add_align = max(pci_resource_alignment(dev, r), add_align);
                                resource_set_size(r, 0);
                                add_to_list(realloc_head, dev, r, r_size, 0 /* Don't care */);
                                children_add_size += r_size;
                                continue;
                        }
-#endif
+
                        /*
                         * aligns[0] is for 1MB (since bridge memory
                         * windows are always at least 1MB aligned), so
index ad64360071486c4c4b08a78b563af2ce876bc7c5..83ffff7cc0a372899e7a618f468d1f7afe4e7549 100644 (file)
@@ -127,10 +127,8 @@ void pci_update_resource(struct pci_dev *dev, int resno)
 {
        if (resno <= PCI_ROM_RESOURCE)
                pci_std_update_resource(dev, resno);
-#ifdef CONFIG_PCI_IOV
-       else if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
+       else if (pci_resource_is_iov(resno))
                pci_iov_update_resource(dev, resno);
-#endif
 }
 
 int pci_claim_resource(struct pci_dev *dev, int resource)