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_size_supported() helper

Many callers of pci_rebar_get_possible_sizes() are interested in finding
out if a particular encoded BAR Size (PCIe r7.0, sec 7.8.6.3) is supported
by the particular BAR.

Add pci_rebar_size_supported() into PCI core to make it easy for the
drivers to determine if the BAR size is supported or not.

Use the new function in pci_resize_resource() and in
pci_iov_vf_bar_set_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>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patch.msgid.link/20251113180053.27944-6-ilpo.jarvinen@linux.intel.com

authored by

Ilpo Järvinen and committed by
Bjorn Helgaas
bb1fabd0 ce04b2f9

+21 -13
+1 -7
drivers/pci/iov.c
··· 1339 1339 */ 1340 1340 int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size) 1341 1341 { 1342 - u32 sizes; 1343 - 1344 1342 if (!pci_resource_is_iov(resno)) 1345 1343 return -EINVAL; 1346 1344 1347 1345 if (pci_iov_is_memory_decoding_enabled(dev)) 1348 1346 return -EBUSY; 1349 1347 1350 - sizes = pci_rebar_get_possible_sizes(dev, resno); 1351 - if (!sizes) 1352 - return -ENOTSUPP; 1353 - 1354 - if (!(sizes & BIT(size))) 1348 + if (!pci_rebar_size_supported(dev, resno, size)) 1355 1349 return -EINVAL; 1356 1350 1357 1351 return pci_rebar_set_size(dev, resno, size);
+19 -6
drivers/pci/rebar.c
··· 3 3 * PCI Resizable BAR Extended Capability handling. 4 4 */ 5 5 6 + #include <linux/bits.h> 6 7 #include <linux/bitfield.h> 7 8 #include <linux/errno.h> 8 9 #include <linux/export.h> ··· 124 123 return cap; 125 124 } 126 125 EXPORT_SYMBOL(pci_rebar_get_possible_sizes); 126 + 127 + /** 128 + * pci_rebar_size_supported - check if size is supported for BAR 129 + * @pdev: PCI device 130 + * @bar: BAR to check 131 + * @size: encoded size as defined in the PCIe spec (0=1MB, 31=128TB) 132 + * 133 + * Return: %true if @bar is resizable and @size is supported, otherwise 134 + * %false. 135 + */ 136 + bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size) 137 + { 138 + u64 sizes = pci_rebar_get_possible_sizes(pdev, bar); 139 + 140 + return BIT(size) & sizes; 141 + } 142 + EXPORT_SYMBOL_GPL(pci_rebar_size_supported); 127 143 128 144 /** 129 145 * pci_rebar_get_current_size - get the current size of a Resizable BAR ··· 270 252 { 271 253 struct pci_host_bridge *host; 272 254 int old, ret; 273 - u32 sizes; 274 255 275 256 /* Check if we must preserve the firmware's resource assignment */ 276 257 host = pci_find_host_bridge(dev->bus); ··· 279 262 if (pci_resize_is_memory_decoding_enabled(dev, resno)) 280 263 return -EBUSY; 281 264 282 - sizes = pci_rebar_get_possible_sizes(dev, resno); 283 - if (!sizes) 284 - return -ENOTSUPP; 285 - 286 - if (!(sizes & BIT(size))) 265 + if (!pci_rebar_size_supported(dev, resno, size)) 287 266 return -EINVAL; 288 267 289 268 old = pci_rebar_get_current_size(dev, resno);
+1
include/linux/pci.h
··· 1424 1424 int pci_rebar_bytes_to_size(u64 bytes); 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 + bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size); 1427 1428 int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size, 1428 1429 int exclude_bars); 1429 1430