Skip to content

Commit 1c680f2

Browse files
ij-intelbjorn-helgaas
authored andcommitted
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
1 parent 2987a64 commit 1c680f2

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

drivers/pci/rebar.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/bits.h>
77
#include <linux/bitfield.h>
8+
#include <linux/bitops.h>
89
#include <linux/errno.h>
910
#include <linux/export.h>
1011
#include <linux/ioport.h>
@@ -142,6 +143,28 @@ bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
142143
}
143144
EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
144145

146+
/**
147+
* pci_rebar_get_max_size - get the maximum supported size of a BAR
148+
* @pdev: PCI device
149+
* @bar: BAR to query
150+
*
151+
* Get the largest supported size of a resizable BAR as a size.
152+
*
153+
* Return: the encoded maximum BAR size as defined in the PCIe spec
154+
* (0=1MB, 31=128TB), or %-NOENT on error.
155+
*/
156+
int pci_rebar_get_max_size(struct pci_dev *pdev, int bar)
157+
{
158+
u32 sizes;
159+
160+
sizes = pci_rebar_get_possible_sizes(pdev, bar);
161+
if (!sizes)
162+
return -ENOENT;
163+
164+
return __fls(sizes);
165+
}
166+
EXPORT_SYMBOL_GPL(pci_rebar_get_max_size);
167+
145168
/**
146169
* pci_rebar_get_current_size - get the current size of a Resizable BAR
147170
* @pdev: PCI device

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,7 @@ int pci_rebar_bytes_to_size(u64 bytes);
14251425
resource_size_t pci_rebar_size_to_bytes(int size);
14261426
u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar);
14271427
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);
14281429
int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size,
14291430
int exclude_bars);
14301431

0 commit comments

Comments
 (0)