]> Gentwo Git Trees - linux/.git/commitdiff
PCI: Move pci_rebar_size_to_bytes() and export it
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 13 Nov 2025 18:00:45 +0000 (20:00 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 14 Nov 2025 18:34:21 +0000 (12:34 -0600)
pci_rebar_size_to_bytes() is in drivers/pci/pci.h but would be useful for
endpoint drivers as well.

Move the function to rebar.c and export it.

In addition, convert the literal to where the number comes from
(PCI_REBAR_MIN_SIZE).

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patch.msgid.link/20251113180053.27944-4-ilpo.jarvinen@linux.intel.com
drivers/pci/pci.h
drivers/pci/rebar.c
include/linux/pci.h

index 41df35920632509a1ba556c4ea624e3834548c0d..a1e7dbeb0f2cc582da703cc59ce918ccfb4a8b5a 100644 (file)
@@ -1024,10 +1024,6 @@ void pci_rebar_init(struct pci_dev *pdev);
 void pci_restore_rebar_state(struct pci_dev *pdev);
 int pci_rebar_get_current_size(struct pci_dev *pdev, int bar);
 int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size);
-static inline u64 pci_rebar_size_to_bytes(int size)
-{
-       return 1ULL << (size + 20);
-}
 
 struct device_node;
 
index f29810fe0a5841b9ea341cd3e5073d5b66f20431..a81cb3fcddefd61d00690e416a6b0905f10e7f31 100644 (file)
@@ -35,6 +35,18 @@ int pci_rebar_bytes_to_size(u64 bytes)
 }
 EXPORT_SYMBOL_GPL(pci_rebar_bytes_to_size);
 
+/**
+ * pci_rebar_size_to_bytes - Convert encoded BAR Size to size in bytes
+ * @size: encoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB)
+ *
+ * Return: BAR size in bytes
+ */
+resource_size_t pci_rebar_size_to_bytes(int size)
+{
+       return 1ULL << (size + ilog2(PCI_REBAR_MIN_SIZE));
+}
+EXPORT_SYMBOL_GPL(pci_rebar_size_to_bytes);
+
 void pci_rebar_init(struct pci_dev *pdev)
 {
        pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
index 628dda63b9e09d38aa7eeeae67e98a6f6ef98a9e..33b27e0c4f3e7b93abfa8e34b62c84fb3abea7dc 100644 (file)
@@ -1422,6 +1422,7 @@ int pci_release_resource(struct pci_dev *dev, int resno);
 
 /* Resizable BAR related routines */
 int pci_rebar_bytes_to_size(u64 bytes);
+resource_size_t pci_rebar_size_to_bytes(int size);
 u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar);
 int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size,
                                     int exclude_bars);