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: Add pci_rebar_get_max_size()

Add pci_rebar_get_max_size() to allow simplifying code that wants to know
the maximum possible size for a Resizable BAR.

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-9-ilpo.jarvinen@linux.intel.com

authored by

Ilpo Järvinen and committed by
Bjorn Helgaas
1c680f2a 2987a64d

+24
+23
drivers/pci/rebar.c
··· 5 5 6 6 #include <linux/bits.h> 7 7 #include <linux/bitfield.h> 8 + #include <linux/bitops.h> 8 9 #include <linux/errno.h> 9 10 #include <linux/export.h> 10 11 #include <linux/ioport.h> ··· 142 141 return BIT(size) & sizes; 143 142 } 144 143 EXPORT_SYMBOL_GPL(pci_rebar_size_supported); 144 + 145 + /** 146 + * pci_rebar_get_max_size - get the maximum supported size of a BAR 147 + * @pdev: PCI device 148 + * @bar: BAR to query 149 + * 150 + * Get the largest supported size of a resizable BAR as a size. 151 + * 152 + * Return: the encoded maximum BAR size as defined in the PCIe spec 153 + * (0=1MB, 31=128TB), or %-NOENT on error. 154 + */ 155 + int pci_rebar_get_max_size(struct pci_dev *pdev, int bar) 156 + { 157 + u32 sizes; 158 + 159 + sizes = pci_rebar_get_possible_sizes(pdev, bar); 160 + if (!sizes) 161 + return -ENOENT; 162 + 163 + return __fls(sizes); 164 + } 165 + EXPORT_SYMBOL_GPL(pci_rebar_get_max_size); 145 166 146 167 /** 147 168 * pci_rebar_get_current_size - get the current size of a Resizable BAR
+1
include/linux/pci.h
··· 1425 1425 resource_size_t pci_rebar_size_to_bytes(int size); 1426 1426 u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); 1427 1427 bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size); 1428 + int pci_rebar_get_max_size(struct pci_dev *pdev, int bar); 1428 1429 int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size, 1429 1430 int exclude_bars); 1430 1431