Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

PCI: Move pci_rebar_bytes_to_size() and clean it up

Move pci_rebar_bytes_to_size() from include/linux/pci.h to rebar.c as it
does not look very trivial and is not expected to be performance critical.

Convert literals to use a newly added PCI_REBAR_MIN_SIZE define.

Also add kernel doc for the function as the function is exported.

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>
Reviewed-by: Michael J. Ruhl <mjruhl@habana.ai>
Link: https://patch.msgid.link/20251113180053.27944-3-ilpo.jarvinen@linux.intel.com

authored by

Ilpo Järvinen and committed by
Bjorn Helgaas
876e1594 9f71938c

+26 -7
+23
drivers/pci/rebar.c
··· 7 7 #include <linux/errno.h> 8 8 #include <linux/export.h> 9 9 #include <linux/ioport.h> 10 + #include <linux/log2.h> 10 11 #include <linux/pci.h> 12 + #include <linux/sizes.h> 11 13 #include <linux/types.h> 12 14 13 15 #include "pci.h" 16 + 17 + #define PCI_REBAR_MIN_SIZE ((resource_size_t)SZ_1M) 18 + 19 + /** 20 + * pci_rebar_bytes_to_size - Convert size in bytes to PCI BAR Size 21 + * @bytes: size in bytes 22 + * 23 + * Convert size in bytes to encoded BAR Size in Resizable BAR Capability 24 + * (PCIe r6.2, sec. 7.8.6.3). 25 + * 26 + * Return: encoded BAR Size as defined in the PCIe spec (0=1MB, 31=128TB) 27 + */ 28 + int pci_rebar_bytes_to_size(u64 bytes) 29 + { 30 + int rebar_minsize = ilog2(PCI_REBAR_MIN_SIZE); 31 + 32 + bytes = roundup_pow_of_two(bytes); 33 + 34 + return max(ilog2(bytes), rebar_minsize) - rebar_minsize; 35 + } 36 + EXPORT_SYMBOL_GPL(pci_rebar_bytes_to_size); 14 37 15 38 void pci_rebar_init(struct pci_dev *pdev) 16 39 {
+3 -7
include/linux/pci.h
··· 1419 1419 void pci_update_resource(struct pci_dev *dev, int resno); 1420 1420 int __must_check pci_assign_resource(struct pci_dev *dev, int i); 1421 1421 int pci_release_resource(struct pci_dev *dev, int resno); 1422 - static inline int pci_rebar_bytes_to_size(u64 bytes) 1423 - { 1424 - bytes = roundup_pow_of_two(bytes); 1425 1422 1426 - /* Return BAR size as defined in the resizable BAR specification */ 1427 - return max(ilog2(bytes), 20) - 20; 1428 - } 1429 - 1423 + /* Resizable BAR related routines */ 1424 + int pci_rebar_bytes_to_size(u64 bytes); 1430 1425 u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); 1431 1426 int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size, 1432 1427 int exclude_bars); 1428 + 1433 1429 int pci_select_bars(struct pci_dev *dev, unsigned long flags); 1434 1430 bool pci_device_is_present(struct pci_dev *pdev); 1435 1431 void pci_ignore_hotplug(struct pci_dev *dev);