* [PATCH 00/11] PCI: Resizable BAR improvements
@ 2025-09-11 7:55 Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 01/11] PCI: Move Resizable BAR code into rebar.c Ilpo Järvinen
` (11 more replies)
0 siblings, 12 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:55 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=
Cc: linux-kernel, linux-doc, Ilpo Järvinen
pci.c has been used as catch everything that doesn't fits elsewhere
within PCI core and thus resizable BAR code has been placed there as
well. Move Resizable BAR related code to a newly introduced rebar.c to
reduce size of pci.c. After move, there are no pci_rebar_*() calls from
pci.c indicating this is indeed well-defined subset of PCI core.
Endpoint drivers perform Resizable BAR related operations which could
well be performed by PCI core to simplify driver-side code. This
series adds a few new API functions to that effect and converts the
drivers to use the new APIs (in separate patches).
While at it, also convert BAR sizes bitmask to u64 as PCIe spec already
specifies more sizes than what will fit u32 to make the API typing more
future-proof. The extra sizes beyond 128TB are not added at this point.
These are based on pci/main, there are two minor conflicts with the
work in pci/resource but I'm hesitant to base this on top of it as this
is otherwise entirely independent. If we end up having to pull the
bridge window select changes, there should be no reason why this does
have to become collateral damage (so my suggestion, if this is good to
go in this cycle, to take this into a separate branch than pci/resource
and deal with those small conflicts while merging into pci/next).
I've tested sysfs resize, i915, and xe BAR resizing functionality. In
the case of xe, I did small hack patch as its resize is anyway broken
as is because BAR0 pins the bridge window so resizing BAR2 fails. My
hack caused other problems further down the road (likely because BAR0
is in use by the driver so releasing it messed assumptions xe driver
has) but the BAR resize itself was working which was all I was
interested to know. I'm not planning to pursue fixing the pinning
problem within xe driver because the core changes to consider maximum
size of the resizable BARs should take care of the main problem by
different means.
Some parts of this are to be used by the resizable BAR changes into the
resource fitting/assingment logic but these seem to stand on their own
so sending these out now to reduce the size of the other patch series.
Ilpo Järvinen (11):
PCI: Move Resizable BAR code into rebar.c
PCI: Cleanup pci_rebar_bytes_to_size() and move into rebar.c
PCI: Move pci_rebar_size_to_bytes() and export it
PCI: Improve Resizable BAR functions kernel doc
PCI: Add pci_rebar_size_supported() helper
drm/i915/gt: Use pci_rebar_size_supported()
drm/xe/vram: Use PCI rebar helpers in resize_vram_bar()
PCI: Add pci_rebar_get_max_size()
drm/xe/vram: Use pci_rebar_get_max_size()
drm/amdgpu: Use pci_rebar_get_max_size()
PCI: Convert BAR sizes bitmasks to u64
Documentation/driver-api/pci/pci.rst | 3 +
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 +-
drivers/gpu/drm/i915/gt/intel_region_lmem.c | 10 +-
drivers/gpu/drm/xe/xe_vram.c | 32 +-
drivers/pci/Makefile | 2 +-
drivers/pci/iov.c | 9 +-
drivers/pci/pci-sysfs.c | 2 +-
drivers/pci/pci.c | 145 ---------
drivers/pci/pci.h | 5 +-
drivers/pci/rebar.c | 318 ++++++++++++++++++++
drivers/pci/setup-res.c | 78 -----
include/linux/pci.h | 15 +-
12 files changed, 354 insertions(+), 273 deletions(-)
create mode 100644 drivers/pci/rebar.c
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
--
2.39.5
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 01/11] PCI: Move Resizable BAR code into rebar.c
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
@ 2025-09-11 7:55 ` Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move " Ilpo Järvinen
` (10 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:55 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
Jonathan Corbet, linux-doc, linux-kernel
Cc: Ilpo Järvinen
In the lack of better place to put it, Resizable BAR code has been
placed inside pci.c and setup-res.c that do not use it for anything.
Upcoming changes are going to add more Resizable BAR related API
functions to PCI core increasing the Resizable BAR code size from the
current.
As pci.c is huge file as is, extract the Resizable BAR related code out
of it into rebar.c and move the actual BAR resize code from setup-res.c
as well.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
Documentation/driver-api/pci/pci.rst | 3 +
drivers/pci/Makefile | 2 +-
drivers/pci/pci.c | 145 ----------------
drivers/pci/pci.h | 1 +
drivers/pci/rebar.c | 236 +++++++++++++++++++++++++++
drivers/pci/setup-res.c | 78 ---------
6 files changed, 241 insertions(+), 224 deletions(-)
create mode 100644 drivers/pci/rebar.c
diff --git a/Documentation/driver-api/pci/pci.rst b/Documentation/driver-api/pci/pci.rst
index 59d86e827198..99a1bbaaec5d 100644
--- a/Documentation/driver-api/pci/pci.rst
+++ b/Documentation/driver-api/pci/pci.rst
@@ -37,6 +37,9 @@ PCI Support Library
.. kernel-doc:: drivers/pci/slot.c
:export:
+.. kernel-doc:: drivers/pci/rebar.c
+ :export:
+
.. kernel-doc:: drivers/pci/rom.c
:export:
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 67647f1880fb..f3c81c892786 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -4,7 +4,7 @@
obj-$(CONFIG_PCI) += access.o bus.o probe.o host-bridge.o \
remove.o pci.o pci-driver.o search.o \
- rom.o setup-res.o irq.o vpd.o \
+ rebar.o rom.o setup-res.o irq.o vpd.o \
setup-bus.o vc.o mmap.o devres.o
obj-$(CONFIG_PCI) += msi/
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b0f4d98036cd..da3a48bf2799 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1874,32 +1874,6 @@ static void pci_restore_config_space(struct pci_dev *pdev)
}
}
-static void pci_restore_rebar_state(struct pci_dev *pdev)
-{
- unsigned int pos, nbars, i;
- u32 ctrl;
-
- pos = pdev->rebar_cap;
- if (!pos)
- return;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
- nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
-
- for (i = 0; i < nbars; i++, pos += 8) {
- struct resource *res;
- int bar_idx, size;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
- bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX;
- res = pci_resource_n(pdev, bar_idx);
- size = pci_rebar_bytes_to_size(resource_size(res));
- ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
- ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
- pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl);
- }
-}
-
/**
* pci_restore_state - Restore the saved state of a PCI device
* @dev: PCI device that we're dealing with
@@ -3738,125 +3712,6 @@ void pci_acs_init(struct pci_dev *dev)
pci_enable_acs(dev);
}
-void pci_rebar_init(struct pci_dev *pdev)
-{
- pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
-}
-
-/**
- * pci_rebar_find_pos - find position of resize ctrl reg for BAR
- * @pdev: PCI device
- * @bar: BAR to find
- *
- * Helper to find the position of the ctrl register for a BAR.
- * Returns -ENOTSUPP if resizable BARs are not supported at all.
- * Returns -ENOENT if no ctrl register for the BAR could be found.
- */
-static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
-{
- unsigned int pos, nbars, i;
- u32 ctrl;
-
- if (pci_resource_is_iov(bar)) {
- pos = pci_iov_vf_rebar_cap(pdev);
- bar = pci_resource_num_to_vf_bar(bar);
- } else {
- pos = pdev->rebar_cap;
- }
-
- if (!pos)
- return -ENOTSUPP;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
- nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
-
- for (i = 0; i < nbars; i++, pos += 8) {
- int bar_idx;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
- bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
- if (bar_idx == bar)
- return pos;
- }
-
- return -ENOENT;
-}
-
-/**
- * pci_rebar_get_possible_sizes - get possible sizes for BAR
- * @pdev: PCI device
- * @bar: BAR to query
- *
- * Get the possible sizes of a resizable BAR as bitmask defined in the spec
- * (bit 0=1MB, bit 31=128TB). Returns 0 if BAR isn't resizable.
- */
-u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
-{
- int pos;
- u32 cap;
-
- pos = pci_rebar_find_pos(pdev, bar);
- if (pos < 0)
- return 0;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap);
- cap = FIELD_GET(PCI_REBAR_CAP_SIZES, cap);
-
- /* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */
- if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f &&
- bar == 0 && cap == 0x700)
- return 0x3f00;
-
- return cap;
-}
-EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
-
-/**
- * pci_rebar_get_current_size - get the current size of a BAR
- * @pdev: PCI device
- * @bar: BAR to set size to
- *
- * Read the size of a BAR from the resizable BAR config.
- * Returns size if found or negative error code.
- */
-int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
-{
- int pos;
- u32 ctrl;
-
- pos = pci_rebar_find_pos(pdev, bar);
- if (pos < 0)
- return pos;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
- return FIELD_GET(PCI_REBAR_CTRL_BAR_SIZE, ctrl);
-}
-
-/**
- * pci_rebar_set_size - set a new size for a BAR
- * @pdev: PCI device
- * @bar: BAR to set size to
- * @size: new size as defined in the spec (0=1MB, 31=128TB)
- *
- * Set the new size of a BAR as defined in the spec.
- * Returns zero if resizing was successful, error code otherwise.
- */
-int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
-{
- int pos;
- u32 ctrl;
-
- pos = pci_rebar_find_pos(pdev, bar);
- if (pos < 0)
- return pos;
-
- pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
- ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
- ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
- pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl);
- return 0;
-}
-
/**
* pci_enable_atomic_ops_to_root - enable AtomicOp requests to root port
* @dev: the PCI device
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 34f65d69662e..f1b30414b2f1 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -926,6 +926,7 @@ static inline int acpi_get_rc_resources(struct device *dev, const char *hid,
#endif
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)
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
new file mode 100644
index 000000000000..b87cfa6fb3ef
--- /dev/null
+++ b/drivers/pci/rebar.c
@@ -0,0 +1,236 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PCI Resizable BAR Extended Capability handling.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/ioport.h>
+#include <linux/pci.h>
+#include <linux/types.h>
+
+#include "pci.h"
+
+void pci_rebar_init(struct pci_dev *pdev)
+{
+ pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
+}
+
+/**
+ * pci_rebar_find_pos - find position of resize ctrl reg for BAR
+ * @pdev: PCI device
+ * @bar: BAR to find
+ *
+ * Helper to find the position of the ctrl register for a BAR.
+ * Returns -ENOTSUPP if resizable BARs are not supported at all.
+ * Returns -ENOENT if no ctrl register for the BAR could be found.
+ */
+static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
+{
+ unsigned int pos, nbars, i;
+ u32 ctrl;
+
+ if (pci_resource_is_iov(bar)) {
+ pos = pci_iov_vf_rebar_cap(pdev);
+ bar = pci_resource_num_to_vf_bar(bar);
+ } else {
+ pos = pdev->rebar_cap;
+ }
+
+ if (!pos)
+ return -ENOTSUPP;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
+ nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
+
+ for (i = 0; i < nbars; i++, pos += 8) {
+ int bar_idx;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
+ bar_idx = FIELD_GET(PCI_REBAR_CTRL_BAR_IDX, ctrl);
+ if (bar_idx == bar)
+ return pos;
+ }
+
+ return -ENOENT;
+}
+
+/**
+ * pci_rebar_get_possible_sizes - get possible sizes for BAR
+ * @pdev: PCI device
+ * @bar: BAR to query
+ *
+ * Get the possible sizes of a resizable BAR as bitmask defined in the spec
+ * (bit 0=1MB, bit 31=128TB). Returns 0 if BAR isn't resizable.
+ */
+u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
+{
+ int pos;
+ u32 cap;
+
+ pos = pci_rebar_find_pos(pdev, bar);
+ if (pos < 0)
+ return 0;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CAP, &cap);
+ cap = FIELD_GET(PCI_REBAR_CAP_SIZES, cap);
+
+ /* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */
+ if (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x731f &&
+ bar == 0 && cap == 0x700)
+ return 0x3f00;
+
+ return cap;
+}
+EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
+
+/**
+ * pci_rebar_get_current_size - get the current size of a BAR
+ * @pdev: PCI device
+ * @bar: BAR to set size to
+ *
+ * Read the size of a BAR from the resizable BAR config.
+ * Returns size if found or negative error code.
+ */
+int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
+{
+ int pos;
+ u32 ctrl;
+
+ pos = pci_rebar_find_pos(pdev, bar);
+ if (pos < 0)
+ return pos;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
+ return FIELD_GET(PCI_REBAR_CTRL_BAR_SIZE, ctrl);
+}
+
+/**
+ * pci_rebar_set_size - set a new size for a BAR
+ * @pdev: PCI device
+ * @bar: BAR to set size to
+ * @size: new size as defined in the spec (0=1MB, 31=128TB)
+ *
+ * Set the new size of a BAR as defined in the spec.
+ * Returns zero if resizing was successful, error code otherwise.
+ */
+int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
+{
+ int pos;
+ u32 ctrl;
+
+ pos = pci_rebar_find_pos(pdev, bar);
+ if (pos < 0)
+ return pos;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
+ ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
+ ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
+ pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl);
+ return 0;
+}
+
+void pci_restore_rebar_state(struct pci_dev *pdev)
+{
+ unsigned int pos, nbars, i;
+ u32 ctrl;
+
+ pos = pdev->rebar_cap;
+ if (!pos)
+ return;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
+ nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl);
+
+ for (i = 0; i < nbars; i++, pos += 8) {
+ struct resource *res;
+ int bar_idx, size;
+
+ pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
+ bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX;
+ res = pci_resource_n(pdev, bar_idx);
+ size = pci_rebar_bytes_to_size(resource_size(res));
+ ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
+ ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
+ pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl);
+ }
+}
+
+static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev,
+ int resno)
+{
+ u16 cmd;
+
+ if (pci_resource_is_iov(resno))
+ return pci_iov_is_memory_decoding_enabled(dev);
+
+ pci_read_config_word(dev, PCI_COMMAND, &cmd);
+
+ return cmd & PCI_COMMAND_MEMORY;
+}
+
+static void pci_resize_resource_set_size(struct pci_dev *dev, int resno,
+ int size)
+{
+ resource_size_t res_size = pci_rebar_size_to_bytes(size);
+ struct resource *res = pci_resource_n(dev, resno);
+
+ if (!pci_resource_is_iov(resno)) {
+ resource_set_size(res, res_size);
+ } else {
+ resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));
+ pci_iov_resource_set_size(dev, resno, res_size);
+ }
+}
+
+int pci_resize_resource(struct pci_dev *dev, int resno, int size)
+{
+ struct resource *res = pci_resource_n(dev, resno);
+ struct pci_host_bridge *host;
+ int old, ret;
+ u32 sizes;
+
+ /* Check if we must preserve the firmware's resource assignment */
+ host = pci_find_host_bridge(dev->bus);
+ if (host->preserve_config)
+ return -ENOTSUPP;
+
+ /* Make sure the resource isn't assigned before resizing it. */
+ if (!(res->flags & IORESOURCE_UNSET))
+ return -EBUSY;
+
+ if (pci_resize_is_memory_decoding_enabled(dev, resno))
+ return -EBUSY;
+
+ sizes = pci_rebar_get_possible_sizes(dev, resno);
+ if (!sizes)
+ return -ENOTSUPP;
+
+ if (!(sizes & BIT(size)))
+ return -EINVAL;
+
+ old = pci_rebar_get_current_size(dev, resno);
+ if (old < 0)
+ return old;
+
+ ret = pci_rebar_set_size(dev, resno, size);
+ if (ret)
+ return ret;
+
+ pci_resize_resource_set_size(dev, resno, size);
+
+ /* Check if the new config works by trying to assign everything. */
+ if (dev->bus->self) {
+ ret = pci_reassign_bridge_resources(dev->bus->self, res->flags);
+ if (ret)
+ goto error_resize;
+ }
+ return 0;
+
+error_resize:
+ pci_rebar_set_size(dev, resno, old);
+ pci_resize_resource_set_size(dev, resno, old);
+ return ret;
+}
+EXPORT_SYMBOL(pci_resize_resource);
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index d2b3ed51e880..20b02b74e90b 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -423,84 +423,6 @@ void pci_release_resource(struct pci_dev *dev, int resno)
}
EXPORT_SYMBOL(pci_release_resource);
-static bool pci_resize_is_memory_decoding_enabled(struct pci_dev *dev,
- int resno)
-{
- u16 cmd;
-
- if (pci_resource_is_iov(resno))
- return pci_iov_is_memory_decoding_enabled(dev);
-
- pci_read_config_word(dev, PCI_COMMAND, &cmd);
-
- return cmd & PCI_COMMAND_MEMORY;
-}
-
-static void pci_resize_resource_set_size(struct pci_dev *dev, int resno,
- int size)
-{
- resource_size_t res_size = pci_rebar_size_to_bytes(size);
- struct resource *res = pci_resource_n(dev, resno);
-
- if (!pci_resource_is_iov(resno)) {
- resource_set_size(res, res_size);
- } else {
- resource_set_size(res, res_size * pci_sriov_get_totalvfs(dev));
- pci_iov_resource_set_size(dev, resno, res_size);
- }
-}
-
-int pci_resize_resource(struct pci_dev *dev, int resno, int size)
-{
- struct resource *res = pci_resource_n(dev, resno);
- struct pci_host_bridge *host;
- int old, ret;
- u32 sizes;
-
- /* Check if we must preserve the firmware's resource assignment */
- host = pci_find_host_bridge(dev->bus);
- if (host->preserve_config)
- return -ENOTSUPP;
-
- /* Make sure the resource isn't assigned before resizing it. */
- if (!(res->flags & IORESOURCE_UNSET))
- return -EBUSY;
-
- if (pci_resize_is_memory_decoding_enabled(dev, resno))
- return -EBUSY;
-
- sizes = pci_rebar_get_possible_sizes(dev, resno);
- if (!sizes)
- return -ENOTSUPP;
-
- if (!(sizes & BIT(size)))
- return -EINVAL;
-
- old = pci_rebar_get_current_size(dev, resno);
- if (old < 0)
- return old;
-
- ret = pci_rebar_set_size(dev, resno, size);
- if (ret)
- return ret;
-
- pci_resize_resource_set_size(dev, resno, size);
-
- /* Check if the new config works by trying to assign everything. */
- if (dev->bus->self) {
- ret = pci_reassign_bridge_resources(dev->bus->self, res->flags);
- if (ret)
- goto error_resize;
- }
- return 0;
-
-error_resize:
- pci_rebar_set_size(dev, resno, old);
- pci_resize_resource_set_size(dev, resno, old);
- return ret;
-}
-EXPORT_SYMBOL(pci_resize_resource);
-
int pci_enable_resources(struct pci_dev *dev, int mask)
{
u16 cmd, old_cmd;
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move into rebar.c
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 01/11] PCI: Move Resizable BAR code into rebar.c Ilpo Järvinen
@ 2025-09-11 7:55 ` Ilpo Järvinen
2025-09-11 17:25 ` Ruhl, Michael J
2025-09-11 7:55 ` [PATCH 03/11] PCI: Move pci_rebar_size_to_bytes() and export it Ilpo Järvinen
` (9 subsequent siblings)
11 siblings, 1 reply; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:55 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
Move pci_rebar_bytes_to_size() from include/linux/pci.h into 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>
---
drivers/pci/rebar.c | 23 +++++++++++++++++++++++
include/linux/pci.h | 10 +++-------
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index b87cfa6fb3ef..961bd43be02b 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -7,11 +7,34 @@
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/ioport.h>
+#include <linux/log2.h>
#include <linux/pci.h>
+#include <linux/sizes.h>
#include <linux/types.h>
#include "pci.h"
+#define PCI_REBAR_MIN_SIZE ((resource_size_t)SZ_1M)
+
+/**
+ * pci_rebar_bytes_to_size - Convert size in bytes to PCI BAR Size
+ * @bytes: size in bytes
+ *
+ * Convert bytes to BAR Size in Resizable BAR Capability (PCIe r6.2,
+ * sec. 7.8.6.3).
+ *
+ * Return: BAR Size as defined in the PCIe spec (0=1MB, bit 31=128TB).
+ */
+int pci_rebar_bytes_to_size(u64 bytes)
+{
+ int rebar_minsize = ilog2(PCI_REBAR_MIN_SIZE);
+
+ bytes = roundup_pow_of_two(bytes);
+
+ return max(ilog2(bytes), rebar_minsize) - rebar_minsize;
+}
+EXPORT_SYMBOL_GPL(pci_rebar_bytes_to_size);
+
void pci_rebar_init(struct pci_dev *pdev)
{
pdev->rebar_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 59876de13860..894e9020b07d 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1418,16 +1418,12 @@ void pcibios_reset_secondary_bus(struct pci_dev *dev);
void pci_update_resource(struct pci_dev *dev, int resno);
int __must_check pci_assign_resource(struct pci_dev *dev, int i);
void pci_release_resource(struct pci_dev *dev, int resno);
-static inline int pci_rebar_bytes_to_size(u64 bytes)
-{
- bytes = roundup_pow_of_two(bytes);
-
- /* Return BAR size as defined in the resizable BAR specification */
- return max(ilog2(bytes), 20) - 20;
-}
+/* Resizable BAR related routines */
+int pci_rebar_bytes_to_size(u64 bytes);
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 pci_select_bars(struct pci_dev *dev, unsigned long flags);
bool pci_device_is_present(struct pci_dev *pdev);
void pci_ignore_hotplug(struct pci_dev *dev);
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 03/11] PCI: Move pci_rebar_size_to_bytes() and export it
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 01/11] PCI: Move Resizable BAR code into rebar.c Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move " Ilpo Järvinen
@ 2025-09-11 7:55 ` Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc Ilpo Järvinen
` (8 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:55 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
pci_rebar_size_to_bytes() is in drivers/pci/pci.h but would be useful
for endpoint drivers as well.
Move the function into 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>
---
drivers/pci/pci.h | 4 ----
drivers/pci/rebar.c | 12 ++++++++++++
include/linux/pci.h | 1 +
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index f1b30414b2f1..3d5068d6e195 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -929,10 +929,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;
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index 961bd43be02b..020ed7a1b3aa 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -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 BAR Size to bytes
+ * @size: BAR Size as defined in the PCIe spec (0=1MB, bit 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);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 894e9020b07d..6f0c31290675 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1421,6 +1421,7 @@ void 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);
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (2 preceding siblings ...)
2025-09-11 7:55 ` [PATCH 03/11] PCI: Move pci_rebar_size_to_bytes() and export it Ilpo Järvinen
@ 2025-09-11 7:55 ` Ilpo Järvinen
2025-09-11 8:24 ` Christian König
2025-09-11 20:58 ` Randy Dunlap
2025-09-11 7:55 ` [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper Ilpo Järvinen
` (7 subsequent siblings)
11 siblings, 2 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:55 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
Fix the copy-pasted errors in the Resizable BAR handling functions
kernel doc and generally improve wording choices.
Fix the formatting errors of the Return: line.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/rebar.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index 020ed7a1b3aa..64315dd8b6bb 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -58,8 +58,9 @@ void pci_rebar_init(struct pci_dev *pdev)
* @bar: BAR to find
*
* Helper to find the position of the ctrl register for a BAR.
- * Returns -ENOTSUPP if resizable BARs are not supported at all.
- * Returns -ENOENT if no ctrl register for the BAR could be found.
+ *
+ * Return: %-ENOTSUPP if resizable BARs are not supported at all,
+ * %-ENOENT if no ctrl register for the BAR could be found.
*/
static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
{
@@ -92,12 +93,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
}
/**
- * pci_rebar_get_possible_sizes - get possible sizes for BAR
+ * pci_rebar_get_possible_sizes - get possible sizes for Resizable BAR
* @pdev: PCI device
* @bar: BAR to query
*
* Get the possible sizes of a resizable BAR as bitmask defined in the spec
- * (bit 0=1MB, bit 31=128TB). Returns 0 if BAR isn't resizable.
+ * (bit 0=1MB, bit 31=128TB).
+ *
+ * Return: A bitmask of possible sizes (0=1MB, 31=128TB), or %0 if BAR isn't
+ * resizable.
*/
u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
{
@@ -121,12 +125,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
/**
- * pci_rebar_get_current_size - get the current size of a BAR
+ * pci_rebar_get_current_size - get the current size of a Resizable BAR
* @pdev: PCI device
- * @bar: BAR to set size to
+ * @bar: BAR to get the size from
*
- * Read the size of a BAR from the resizable BAR config.
- * Returns size if found or negative error code.
+ * Reads the current size of a BAR from the Resizable BAR config.
+ *
+ * Return: BAR Size if @bar is resizable (bit 0=1MB, bit 31=128TB), or
+ * negative on error.
*/
int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
{
@@ -142,13 +148,14 @@ int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
}
/**
- * pci_rebar_set_size - set a new size for a BAR
+ * pci_rebar_set_size - set a new size for a Resizable BAR
* @pdev: PCI device
* @bar: BAR to set size to
- * @size: new size as defined in the spec (0=1MB, 31=128TB)
+ * @size: new size as defined in the PCIe spec (0=1MB, 31=128TB)
*
* Set the new size of a BAR as defined in the spec.
- * Returns zero if resizing was successful, error code otherwise.
+ *
+ * Return: %0 if resizing was successful, or negative on error.
*/
int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
{
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (3 preceding siblings ...)
2025-09-11 7:55 ` [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc Ilpo Järvinen
@ 2025-09-11 7:55 ` Ilpo Järvinen
2025-09-11 8:27 ` Christian König
2025-09-11 7:56 ` [PATCH 06/11] drm/i915/gt: Use pci_rebar_size_supported() Ilpo Järvinen
` (6 subsequent siblings)
11 siblings, 1 reply; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:55 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
Many callers of pci_rebar_get_possible_sizes() are interested in
finding out if a particular BAR Size (PCIe r6.2 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>
---
drivers/pci/iov.c | 7 +------
drivers/pci/rebar.c | 29 +++++++++++++++++++++++------
include/linux/pci.h | 1 +
3 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index ac4375954c94..51844a9176a0 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -1334,7 +1334,6 @@ EXPORT_SYMBOL_GPL(pci_sriov_configure_simple);
*/
int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
{
- u32 sizes;
int ret;
if (!pci_resource_is_iov(resno))
@@ -1343,11 +1342,7 @@ int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
if (pci_iov_is_memory_decoding_enabled(dev))
return -EBUSY;
- sizes = pci_rebar_get_possible_sizes(dev, resno);
- if (!sizes)
- return -ENOTSUPP;
-
- if (!(sizes & BIT(size)))
+ if (!pci_rebar_size_supported(dev, resno, size))
return -EINVAL;
ret = pci_rebar_set_size(dev, resno, size);
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index 64315dd8b6bb..735d9afd6ab1 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -3,6 +3,7 @@
* PCI Resizable BAR Extended Capability handling.
*/
+#include <linux/bits.h>
#include <linux/bitfield.h>
#include <linux/errno.h>
#include <linux/export.h>
@@ -124,6 +125,27 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
}
EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
+/**
+ * pci_rebar_size_supported - check if size is supported for BAR
+ * @pdev: PCI device
+ * @bar: BAR to check
+ * @size: size as defined in the PCIe spec (0=1MB, 31=128TB)
+ *
+ * Return: %true if @bar is resizable and @size is a supported, otherwise
+ * %false.
+ */
+bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
+{
+ u64 sizes;
+
+ sizes = pci_rebar_get_possible_sizes(pdev, bar);
+ if (!sizes)
+ return false;
+
+ return BIT(size) & sizes;
+}
+EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
+
/**
* pci_rebar_get_current_size - get the current size of a Resizable BAR
* @pdev: PCI device
@@ -231,7 +253,6 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
struct resource *res = pci_resource_n(dev, resno);
struct pci_host_bridge *host;
int old, ret;
- u32 sizes;
/* Check if we must preserve the firmware's resource assignment */
host = pci_find_host_bridge(dev->bus);
@@ -245,11 +266,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
if (pci_resize_is_memory_decoding_enabled(dev, resno))
return -EBUSY;
- sizes = pci_rebar_get_possible_sizes(dev, resno);
- if (!sizes)
- return -ENOTSUPP;
-
- if (!(sizes & BIT(size)))
+ if (!pci_rebar_size_supported(dev, resno, size))
return -EINVAL;
old = pci_rebar_get_current_size(dev, resno);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 6f0c31290675..917c3b897739 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1423,6 +1423,7 @@ void pci_release_resource(struct pci_dev *dev, int resno);
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);
+bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size);
int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size);
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 06/11] drm/i915/gt: Use pci_rebar_size_supported()
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (4 preceding siblings ...)
2025-09-11 7:55 ` [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper Ilpo Järvinen
@ 2025-09-11 7:56 ` Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 07/11] drm/xe/vram: Use PCI rebar helpers in resize_vram_bar() Ilpo Järvinen
` (5 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:56 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
PCI core provides pci_rebar_size_supported() that helps in checking if
a BAR Size is supported for the BAR or not. Use it in
i915_resize_lmem_bar() to simplify code.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/gpu/drm/i915/gt/intel_region_lmem.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/i915/gt/intel_region_lmem.c b/drivers/gpu/drm/i915/gt/intel_region_lmem.c
index 51bb27e10a4f..69c65fc8a72d 100644
--- a/drivers/gpu/drm/i915/gt/intel_region_lmem.c
+++ b/drivers/gpu/drm/i915/gt/intel_region_lmem.c
@@ -61,16 +61,12 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_t
current_size = roundup_pow_of_two(pci_resource_len(pdev, GEN12_LMEM_BAR));
if (i915->params.lmem_bar_size) {
- u32 bar_sizes;
-
- rebar_size = i915->params.lmem_bar_size *
- (resource_size_t)SZ_1M;
- bar_sizes = pci_rebar_get_possible_sizes(pdev, GEN12_LMEM_BAR);
-
+ rebar_size = i915->params.lmem_bar_size * (resource_size_t)SZ_1M;
if (rebar_size == current_size)
return;
- if (!(bar_sizes & BIT(pci_rebar_bytes_to_size(rebar_size))) ||
+ if (!pci_rebar_size_supported(pdev, GEN12_LMEM_BAR,
+ pci_rebar_bytes_to_size(rebar_size)) ||
rebar_size >= roundup_pow_of_two(lmem_size)) {
rebar_size = lmem_size;
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 07/11] drm/xe/vram: Use PCI rebar helpers in resize_vram_bar()
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (5 preceding siblings ...)
2025-09-11 7:56 ` [PATCH 06/11] drm/i915/gt: Use pci_rebar_size_supported() Ilpo Järvinen
@ 2025-09-11 7:56 ` Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 08/11] PCI: Add pci_rebar_get_max_size() Ilpo Järvinen
` (4 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:56 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
PCI core provides pci_rebar_size_supported(), use it in
resize_vram_bar() to simplify code.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/gpu/drm/xe/xe_vram.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_vram.c b/drivers/gpu/drm/xe/xe_vram.c
index e421a74fb87c..08a9abebfee7 100644
--- a/drivers/gpu/drm/xe/xe_vram.c
+++ b/drivers/gpu/drm/xe/xe_vram.c
@@ -21,8 +21,6 @@
#include "xe_sriov.h"
#include "xe_vram.h"
-#define BAR_SIZE_SHIFT 20
-
static void
_resize_bar(struct xe_device *xe, int resno, resource_size_t size)
{
@@ -71,25 +69,22 @@ static void resize_vram_bar(struct xe_device *xe)
/* set to a specific size? */
if (force_vram_bar_size) {
- u32 bar_size_bit;
-
- rebar_size = force_vram_bar_size * (resource_size_t)SZ_1M;
+ rebar_size = pci_rebar_bytes_to_size(force_vram_bar_size *
+ (resource_size_t)SZ_1M);
- bar_size_bit = bar_size_mask & BIT(pci_rebar_bytes_to_size(rebar_size));
-
- if (!bar_size_bit) {
+ if (!pci_rebar_size_supported(pdev, LMEM_BAR, rebar_size)) {
drm_info(&xe->drm,
"Requested size: %lluMiB is not supported by rebar sizes: 0x%x. Leaving default: %lluMiB\n",
- (u64)rebar_size >> 20, bar_size_mask, (u64)current_size >> 20);
+ (u64)pci_rebar_size_to_bytes(rebar_size) >> 20,
+ bar_size_mask, (u64)current_size >> 20);
return;
}
- rebar_size = 1ULL << (__fls(bar_size_bit) + BAR_SIZE_SHIFT);
-
+ rebar_size = pci_rebar_size_to_bytes(rebar_size);
if (rebar_size == current_size)
return;
} else {
- rebar_size = 1ULL << (__fls(bar_size_mask) + BAR_SIZE_SHIFT);
+ rebar_size = pci_rebar_size_to_bytes(__fls(bar_size_mask));
/* only resize if larger than current */
if (rebar_size <= current_size)
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 08/11] PCI: Add pci_rebar_get_max_size()
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (6 preceding siblings ...)
2025-09-11 7:56 ` [PATCH 07/11] drm/xe/vram: Use PCI rebar helpers in resize_vram_bar() Ilpo Järvinen
@ 2025-09-11 7:56 ` Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 09/11] drm/xe/vram: Use pci_rebar_get_max_size() Ilpo Järvinen
` (3 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:56 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
Add pci_rebar_get_max_size() into PCI core 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>
---
drivers/pci/rebar.c | 23 +++++++++++++++++++++++
include/linux/pci.h | 1 +
2 files changed, 24 insertions(+)
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index 735d9afd6ab1..76572c7a6e6e 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -5,6 +5,7 @@
#include <linux/bits.h>
#include <linux/bitfield.h>
+#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/ioport.h>
@@ -146,6 +147,28 @@ bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
}
EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
+/**
+ * pci_rebar_get_max_size - get the maximum supported size of a BAR
+ * @pdev: PCI device
+ * @bar: BAR to query
+ *
+ * Get the largest supported size of a resizable BAR as a size.
+ *
+ * Returns: the maximum BAR size as defined in the PCIe spec (0=1MB, 31=128TB),
+ * or %-NOENT on error.
+ */
+int pci_rebar_get_max_size(struct pci_dev *pdev, int bar)
+{
+ u32 sizes;
+
+ sizes = pci_rebar_get_possible_sizes(pdev, bar);
+ if (!sizes)
+ return -ENOENT;
+
+ return __fls(sizes);
+}
+EXPORT_SYMBOL_GPL(pci_rebar_get_max_size);
+
/**
* pci_rebar_get_current_size - get the current size of a Resizable BAR
* @pdev: PCI device
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 917c3b897739..a4236aafad24 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1424,6 +1424,7 @@ 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);
bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size);
+int pci_rebar_get_max_size(struct pci_dev *pdev, int bar);
int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size);
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 09/11] drm/xe/vram: Use pci_rebar_get_max_size()
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (7 preceding siblings ...)
2025-09-11 7:56 ` [PATCH 08/11] PCI: Add pci_rebar_get_max_size() Ilpo Järvinen
@ 2025-09-11 7:56 ` Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 10/11] drm/amdgpu: " Ilpo Järvinen
` (2 subsequent siblings)
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:56 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
Use pci_rebar_get_max_size() from PCI core in resize_vram_bar() to
simplify code.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/gpu/drm/xe/xe_vram.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_vram.c b/drivers/gpu/drm/xe/xe_vram.c
index 08a9abebfee7..b063c072df1e 100644
--- a/drivers/gpu/drm/xe/xe_vram.c
+++ b/drivers/gpu/drm/xe/xe_vram.c
@@ -53,16 +53,11 @@ static void resize_vram_bar(struct xe_device *xe)
resource_size_t current_size;
resource_size_t rebar_size;
struct resource *root_res;
- u32 bar_size_mask;
+ int max_size, i;
u32 pci_cmd;
- int i;
/* gather some relevant info */
current_size = pci_resource_len(pdev, LMEM_BAR);
- bar_size_mask = pci_rebar_get_possible_sizes(pdev, LMEM_BAR);
-
- if (!bar_size_mask)
- return;
if (force_vram_bar_size < 0)
return;
@@ -76,7 +71,8 @@ static void resize_vram_bar(struct xe_device *xe)
drm_info(&xe->drm,
"Requested size: %lluMiB is not supported by rebar sizes: 0x%x. Leaving default: %lluMiB\n",
(u64)pci_rebar_size_to_bytes(rebar_size) >> 20,
- bar_size_mask, (u64)current_size >> 20);
+ pci_rebar_get_possible_sizes(pdev, LMEM_BAR),
+ (u64)current_size >> 20);
return;
}
@@ -84,7 +80,10 @@ static void resize_vram_bar(struct xe_device *xe)
if (rebar_size == current_size)
return;
} else {
- rebar_size = pci_rebar_size_to_bytes(__fls(bar_size_mask));
+ max_size = pci_rebar_get_max_size(pdev, LMEM_BAR);
+ if (max_size < 0)
+ return;
+ rebar_size = pci_rebar_size_to_bytes(max_size);
/* only resize if larger than current */
if (rebar_size <= current_size)
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 10/11] drm/amdgpu: Use pci_rebar_get_max_size()
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (8 preceding siblings ...)
2025-09-11 7:56 ` [PATCH 09/11] drm/xe/vram: Use pci_rebar_get_max_size() Ilpo Järvinen
@ 2025-09-11 7:56 ` Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 11/11] PCI: Convert BAR sizes bitmasks to u64 Ilpo Järvinen
2025-09-11 8:35 ` [PATCH 00/11] PCI: Resizable BAR improvements Christian König
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:56 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
Use pci_rebar_get_max_size() from PCI core to simplify code in
amdgpu_device_resize_fb_bar().
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 01d234cf8156..c4ab503fb5d0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1670,9 +1670,9 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
int rbar_size = pci_rebar_bytes_to_size(adev->gmc.real_vram_size);
struct pci_bus *root;
struct resource *res;
+ int max_size, r;
unsigned int i;
u16 cmd;
- int r;
if (!IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
return 0;
@@ -1718,8 +1718,10 @@ int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
return 0;
/* Limit the BAR size to what is available */
- rbar_size = min(fls(pci_rebar_get_possible_sizes(adev->pdev, 0)) - 1,
- rbar_size);
+ max_size = pci_rebar_get_max_size(adev->pdev, 0);
+ if (max_size < 0)
+ return 0;
+ rbar_size = min(max_size, rbar_size);
/* Disable memory decoding while we change the BAR addresses and size */
pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd);
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 11/11] PCI: Convert BAR sizes bitmasks to u64
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (9 preceding siblings ...)
2025-09-11 7:56 ` [PATCH 10/11] drm/amdgpu: " Ilpo Järvinen
@ 2025-09-11 7:56 ` Ilpo Järvinen
2025-09-11 8:35 ` [PATCH 00/11] PCI: Resizable BAR improvements Christian König
11 siblings, 0 replies; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 7:56 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Christian König, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc, Ilpo Järvinen
PCIe r6.2 section 7.8.6 defines resizable BAR sizes beyond the
currently supported maximum of 128TB which will require more than u32
to store the entire bitmask.
Convert Resizable BAR related functions to use u64 bitmask for BAR
sizes to make the typing more future-proof.
The support for the larger BAR sizes themselves is not added at this
point.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/gpu/drm/xe/xe_vram.c | 2 +-
drivers/pci/iov.c | 2 +-
drivers/pci/pci-sysfs.c | 2 +-
drivers/pci/rebar.c | 4 ++--
include/linux/pci.h | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_vram.c b/drivers/gpu/drm/xe/xe_vram.c
index b063c072df1e..196b75fa0c57 100644
--- a/drivers/gpu/drm/xe/xe_vram.c
+++ b/drivers/gpu/drm/xe/xe_vram.c
@@ -69,7 +69,7 @@ static void resize_vram_bar(struct xe_device *xe)
if (!pci_rebar_size_supported(pdev, LMEM_BAR, rebar_size)) {
drm_info(&xe->drm,
- "Requested size: %lluMiB is not supported by rebar sizes: 0x%x. Leaving default: %lluMiB\n",
+ "Requested size: %lluMiB is not supported by rebar sizes: 0x%llx. Leaving default: %lluMiB\n",
(u64)pci_rebar_size_to_bytes(rebar_size) >> 20,
pci_rebar_get_possible_sizes(pdev, LMEM_BAR),
(u64)current_size >> 20);
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 51844a9176a0..d2741c4f3315 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -1370,7 +1370,7 @@ EXPORT_SYMBOL_GPL(pci_iov_vf_bar_set_size);
u32 pci_iov_vf_bar_get_sizes(struct pci_dev *dev, int resno, int num_vfs)
{
u64 vf_len = pci_resource_len(dev, resno);
- u32 sizes;
+ u64 sizes;
if (!num_vfs)
return 0;
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5eea14c1f7f5..b6920114d538 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1544,7 +1544,7 @@ static ssize_t __resource_resize_show(struct device *dev, int n, char *buf)
pci_config_pm_runtime_get(pdev);
ret = sysfs_emit(buf, "%016llx\n",
- (u64)pci_rebar_get_possible_sizes(pdev, n));
+ pci_rebar_get_possible_sizes(pdev, n));
pci_config_pm_runtime_put(pdev);
diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
index 76572c7a6e6e..b42bda80fabf 100644
--- a/drivers/pci/rebar.c
+++ b/drivers/pci/rebar.c
@@ -105,7 +105,7 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
* Return: A bitmask of possible sizes (0=1MB, 31=128TB), or %0 if BAR isn't
* resizable.
*/
-u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
+u64 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
{
int pos;
u32 cap;
@@ -159,7 +159,7 @@ EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
*/
int pci_rebar_get_max_size(struct pci_dev *pdev, int bar)
{
- u32 sizes;
+ u64 sizes;
sizes = pci_rebar_get_possible_sizes(pdev, bar);
if (!sizes)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a4236aafad24..bb10c7eb49e2 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1422,7 +1422,7 @@ void 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);
+u64 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar);
bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size);
int pci_rebar_get_max_size(struct pci_dev *pdev, int bar);
int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size);
--
2.39.5
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc
2025-09-11 7:55 ` [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc Ilpo Järvinen
@ 2025-09-11 8:24 ` Christian König
2025-09-11 8:59 ` Ilpo Järvinen
2025-09-11 20:58 ` Randy Dunlap
1 sibling, 1 reply; 19+ messages in thread
From: Christian König @ 2025-09-11 8:24 UTC (permalink / raw)
To: Ilpo Järvinen, linux-pci, Bjorn Helgaas,
Krzysztof Wilczyński, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc
On 11.09.25 09:55, Ilpo Järvinen wrote:
> Fix the copy-pasted errors in the Resizable BAR handling functions
> kernel doc and generally improve wording choices.
>
> Fix the formatting errors of the Return: line.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
> drivers/pci/rebar.c | 29 ++++++++++++++++++-----------
> 1 file changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
> index 020ed7a1b3aa..64315dd8b6bb 100644
> --- a/drivers/pci/rebar.c
> +++ b/drivers/pci/rebar.c
> @@ -58,8 +58,9 @@ void pci_rebar_init(struct pci_dev *pdev)
> * @bar: BAR to find
> *
> * Helper to find the position of the ctrl register for a BAR.
> - * Returns -ENOTSUPP if resizable BARs are not supported at all.
> - * Returns -ENOENT if no ctrl register for the BAR could be found.
> + *
> + * Return: %-ENOTSUPP if resizable BARs are not supported at all,
> + * %-ENOENT if no ctrl register for the BAR could be found.
> */
> static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> {
> @@ -92,12 +93,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> }
>
> /**
> - * pci_rebar_get_possible_sizes - get possible sizes for BAR
> + * pci_rebar_get_possible_sizes - get possible sizes for Resizable BAR
> * @pdev: PCI device
> * @bar: BAR to query
> *
> * Get the possible sizes of a resizable BAR as bitmask defined in the spec
> - * (bit 0=1MB, bit 31=128TB). Returns 0 if BAR isn't resizable.
> + * (bit 0=1MB, bit 31=128TB).
> + *
> + * Return: A bitmask of possible sizes (0=1MB, 31=128TB), or %0 if BAR isn't
> + * resizable.
> */
> u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
> {
> @@ -121,12 +125,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
> EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
>
> /**
> - * pci_rebar_get_current_size - get the current size of a BAR
> + * pci_rebar_get_current_size - get the current size of a Resizable BAR
> * @pdev: PCI device
> - * @bar: BAR to set size to
> + * @bar: BAR to get the size from
> *
> - * Read the size of a BAR from the resizable BAR config.
> - * Returns size if found or negative error code.
> + * Reads the current size of a BAR from the Resizable BAR config.
> + *
> + * Return: BAR Size if @bar is resizable (bit 0=1MB, bit 31=128TB), or
This is a bit misleading since there is no mask returned but rather the order or in other words which bit of the mask was used.
Regards,
Christian.
> + * negative on error.
> */
> int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
> {
> @@ -142,13 +148,14 @@ int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
> }
>
> /**
> - * pci_rebar_set_size - set a new size for a BAR
> + * pci_rebar_set_size - set a new size for a Resizable BAR
> * @pdev: PCI device
> * @bar: BAR to set size to
> - * @size: new size as defined in the spec (0=1MB, 31=128TB)
> + * @size: new size as defined in the PCIe spec (0=1MB, 31=128TB)
> *
> * Set the new size of a BAR as defined in the spec.
> - * Returns zero if resizing was successful, error code otherwise.
> + *
> + * Return: %0 if resizing was successful, or negative on error.
> */
> int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
> {
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper
2025-09-11 7:55 ` [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper Ilpo Järvinen
@ 2025-09-11 8:27 ` Christian König
0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2025-09-11 8:27 UTC (permalink / raw)
To: Ilpo Järvinen, linux-pci, Bjorn Helgaas,
Krzysztof Wilczyński, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel
Cc: linux-doc
On 11.09.25 09:55, Ilpo Järvinen wrote:
> Many callers of pci_rebar_get_possible_sizes() are interested in
> finding out if a particular BAR Size (PCIe r6.2 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>
> ---
> drivers/pci/iov.c | 7 +------
> drivers/pci/rebar.c | 29 +++++++++++++++++++++++------
> include/linux/pci.h | 1 +
> 3 files changed, 25 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index ac4375954c94..51844a9176a0 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -1334,7 +1334,6 @@ EXPORT_SYMBOL_GPL(pci_sriov_configure_simple);
> */
> int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
> {
> - u32 sizes;
> int ret;
>
> if (!pci_resource_is_iov(resno))
> @@ -1343,11 +1342,7 @@ int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size)
> if (pci_iov_is_memory_decoding_enabled(dev))
> return -EBUSY;
>
> - sizes = pci_rebar_get_possible_sizes(dev, resno);
> - if (!sizes)
> - return -ENOTSUPP;
> -
> - if (!(sizes & BIT(size)))
> + if (!pci_rebar_size_supported(dev, resno, size))
> return -EINVAL;
>
> ret = pci_rebar_set_size(dev, resno, size);
> diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
> index 64315dd8b6bb..735d9afd6ab1 100644
> --- a/drivers/pci/rebar.c
> +++ b/drivers/pci/rebar.c
> @@ -3,6 +3,7 @@
> * PCI Resizable BAR Extended Capability handling.
> */
>
> +#include <linux/bits.h>
> #include <linux/bitfield.h>
> #include <linux/errno.h>
> #include <linux/export.h>
> @@ -124,6 +125,27 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
> }
> EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
>
> +/**
> + * pci_rebar_size_supported - check if size is supported for BAR
> + * @pdev: PCI device
> + * @bar: BAR to check
> + * @size: size as defined in the PCIe spec (0=1MB, 31=128TB)
> + *
> + * Return: %true if @bar is resizable and @size is a supported, otherwise
> + * %false.
> + */
> +bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size)
> +{
> + u64 sizes;
> +
> + sizes = pci_rebar_get_possible_sizes(pdev, bar);
> + if (!sizes)
> + return false;
> +
> + return BIT(size) & sizes;
Checking size for zero first looks superfluous.
Regards,
Christian.
> +}
> +EXPORT_SYMBOL_GPL(pci_rebar_size_supported);
> +
> /**
> * pci_rebar_get_current_size - get the current size of a Resizable BAR
> * @pdev: PCI device
> @@ -231,7 +253,6 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
> struct resource *res = pci_resource_n(dev, resno);
> struct pci_host_bridge *host;
> int old, ret;
> - u32 sizes;
>
> /* Check if we must preserve the firmware's resource assignment */
> host = pci_find_host_bridge(dev->bus);
> @@ -245,11 +266,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
> if (pci_resize_is_memory_decoding_enabled(dev, resno))
> return -EBUSY;
>
> - sizes = pci_rebar_get_possible_sizes(dev, resno);
> - if (!sizes)
> - return -ENOTSUPP;
> -
> - if (!(sizes & BIT(size)))
> + if (!pci_rebar_size_supported(dev, resno, size))
> return -EINVAL;
>
> old = pci_rebar_get_current_size(dev, resno);
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 6f0c31290675..917c3b897739 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1423,6 +1423,7 @@ void pci_release_resource(struct pci_dev *dev, int resno);
> 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);
> +bool pci_rebar_size_supported(struct pci_dev *pdev, int bar, int size);
> int __must_check pci_resize_resource(struct pci_dev *dev, int i, int size);
>
> int pci_select_bars(struct pci_dev *dev, unsigned long flags);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 00/11] PCI: Resizable BAR improvements
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
` (10 preceding siblings ...)
2025-09-11 7:56 ` [PATCH 11/11] PCI: Convert BAR sizes bitmasks to u64 Ilpo Järvinen
@ 2025-09-11 8:35 ` Christian König
11 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2025-09-11 8:35 UTC (permalink / raw)
To: Ilpo Järvinen, linux-pci, Bjorn Helgaas,
Krzysztof Wilczyński, Michał Winiarski, Alex Deucher,
amd-gfx, David Airlie, dri-devel, intel-gfx, intel-xe,
Jani Nikula, Joonas Lahtinen, Lucas De Marchi, Rodrigo Vivi,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=
Cc: linux-kernel, linux-doc
On 11.09.25 09:55, Ilpo Järvinen wrote:
> pci.c has been used as catch everything that doesn't fits elsewhere
> within PCI core and thus resizable BAR code has been placed there as
> well. Move Resizable BAR related code to a newly introduced rebar.c to
> reduce size of pci.c. After move, there are no pci_rebar_*() calls from
> pci.c indicating this is indeed well-defined subset of PCI core.
>
> Endpoint drivers perform Resizable BAR related operations which could
> well be performed by PCI core to simplify driver-side code. This
> series adds a few new API functions to that effect and converts the
> drivers to use the new APIs (in separate patches).
>
> While at it, also convert BAR sizes bitmask to u64 as PCIe spec already
> specifies more sizes than what will fit u32 to make the API typing more
> future-proof. The extra sizes beyond 128TB are not added at this point.
>
> These are based on pci/main, there are two minor conflicts with the
> work in pci/resource but I'm hesitant to base this on top of it as this
> is otherwise entirely independent. If we end up having to pull the
> bridge window select changes, there should be no reason why this does
> have to become collateral damage (so my suggestion, if this is good to
> go in this cycle, to take this into a separate branch than pci/resource
> and deal with those small conflicts while merging into pci/next).
>
> I've tested sysfs resize, i915, and xe BAR resizing functionality. In
> the case of xe, I did small hack patch as its resize is anyway broken
> as is because BAR0 pins the bridge window so resizing BAR2 fails. My
> hack caused other problems further down the road (likely because BAR0
> is in use by the driver so releasing it messed assumptions xe driver
> has) but the BAR resize itself was working which was all I was
> interested to know. I'm not planning to pursue fixing the pinning
> problem within xe driver because the core changes to consider maximum
> size of the resizable BARs should take care of the main problem by
> different means.
>
> Some parts of this are to be used by the resizable BAR changes into the
> resource fitting/assingment logic but these seem to stand on their own
> so sending these out now to reduce the size of the other patch series.
Yeah, sounds like a good idea to me.
Before I answer each mail individually:
Patches #1-#3, #8, #10 and #11 are Reviewed-by: Christian König <christian.koenig@amd.com>.
Patches #6, #7 and #9 are Acked-by: Christian König <christian.koenig@amd.com>.
Nit pick comments on patches #4 and #5, feel free to add my rb to them as well when those are fixed.
Regards,
Christian.
>
>
> Ilpo Järvinen (11):
> PCI: Move Resizable BAR code into rebar.c
> PCI: Cleanup pci_rebar_bytes_to_size() and move into rebar.c
> PCI: Move pci_rebar_size_to_bytes() and export it
> PCI: Improve Resizable BAR functions kernel doc
> PCI: Add pci_rebar_size_supported() helper
> drm/i915/gt: Use pci_rebar_size_supported()
> drm/xe/vram: Use PCI rebar helpers in resize_vram_bar()
> PCI: Add pci_rebar_get_max_size()
> drm/xe/vram: Use pci_rebar_get_max_size()
> drm/amdgpu: Use pci_rebar_get_max_size()
> PCI: Convert BAR sizes bitmasks to u64
>
> Documentation/driver-api/pci/pci.rst | 3 +
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 +-
> drivers/gpu/drm/i915/gt/intel_region_lmem.c | 10 +-
> drivers/gpu/drm/xe/xe_vram.c | 32 +-
> drivers/pci/Makefile | 2 +-
> drivers/pci/iov.c | 9 +-
> drivers/pci/pci-sysfs.c | 2 +-
> drivers/pci/pci.c | 145 ---------
> drivers/pci/pci.h | 5 +-
> drivers/pci/rebar.c | 318 ++++++++++++++++++++
> drivers/pci/setup-res.c | 78 -----
> include/linux/pci.h | 15 +-
> 12 files changed, 354 insertions(+), 273 deletions(-)
> create mode 100644 drivers/pci/rebar.c
>
>
> base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc
2025-09-11 8:24 ` Christian König
@ 2025-09-11 8:59 ` Ilpo Järvinen
2025-09-11 9:08 ` Christian König
0 siblings, 1 reply; 19+ messages in thread
From: Ilpo Järvinen @ 2025-09-11 8:59 UTC (permalink / raw)
To: Christian König
Cc: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Michał Winiarski, Alex Deucher, amd-gfx, David Airlie,
dri-devel, intel-gfx, intel-xe, Jani Nikula, Joonas Lahtinen,
Lucas De Marchi, Rodrigo Vivi, Simona Vetter, Tvrtko Ursulin,
?UTF-8?q?Thomas=20Hellstr=C3=B6m?=, LKML, linux-doc
[-- Attachment #1: Type: text/plain, Size: 3711 bytes --]
On Thu, 11 Sep 2025, Christian König wrote:
> On 11.09.25 09:55, Ilpo Järvinen wrote:
> > Fix the copy-pasted errors in the Resizable BAR handling functions
> > kernel doc and generally improve wording choices.
> >
> > Fix the formatting errors of the Return: line.
> >
> > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > ---
> > drivers/pci/rebar.c | 29 ++++++++++++++++++-----------
> > 1 file changed, 18 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
> > index 020ed7a1b3aa..64315dd8b6bb 100644
> > --- a/drivers/pci/rebar.c
> > +++ b/drivers/pci/rebar.c
> > @@ -58,8 +58,9 @@ void pci_rebar_init(struct pci_dev *pdev)
> > * @bar: BAR to find
> > *
> > * Helper to find the position of the ctrl register for a BAR.
> > - * Returns -ENOTSUPP if resizable BARs are not supported at all.
> > - * Returns -ENOENT if no ctrl register for the BAR could be found.
> > + *
> > + * Return: %-ENOTSUPP if resizable BARs are not supported at all,
> > + * %-ENOENT if no ctrl register for the BAR could be found.
> > */
> > static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> > {
> > @@ -92,12 +93,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> > }
> >
> > /**
> > - * pci_rebar_get_possible_sizes - get possible sizes for BAR
> > + * pci_rebar_get_possible_sizes - get possible sizes for Resizable BAR
> > * @pdev: PCI device
> > * @bar: BAR to query
> > *
> > * Get the possible sizes of a resizable BAR as bitmask defined in the spec
> > - * (bit 0=1MB, bit 31=128TB). Returns 0 if BAR isn't resizable.
> > + * (bit 0=1MB, bit 31=128TB).
> > + *
> > + * Return: A bitmask of possible sizes (0=1MB, 31=128TB), or %0 if BAR isn't
> > + * resizable.
> > */
> > u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
> > {
> > @@ -121,12 +125,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
> > EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
> >
> > /**
> > - * pci_rebar_get_current_size - get the current size of a BAR
> > + * pci_rebar_get_current_size - get the current size of a Resizable BAR
> > * @pdev: PCI device
> > - * @bar: BAR to set size to
> > + * @bar: BAR to get the size from
> > *
> > - * Read the size of a BAR from the resizable BAR config.
> > - * Returns size if found or negative error code.
> > + * Reads the current size of a BAR from the Resizable BAR config.
> > + *
> > + * Return: BAR Size if @bar is resizable (bit 0=1MB, bit 31=128TB), or
>
> This is a bit misleading since there is no mask returned but rather the
> order or in other words which bit of the mask was used.
Thanks for noticing this. I'll removed "bit" x2 from it, does that fully
address your concern?
--
i.
> > + * negative on error.
> > */
> > int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
> > {
> > @@ -142,13 +148,14 @@ int pci_rebar_get_current_size(struct pci_dev *pdev, int bar)
> > }
> >
> > /**
> > - * pci_rebar_set_size - set a new size for a BAR
> > + * pci_rebar_set_size - set a new size for a Resizable BAR
> > * @pdev: PCI device
> > * @bar: BAR to set size to
> > - * @size: new size as defined in the spec (0=1MB, 31=128TB)
> > + * @size: new size as defined in the PCIe spec (0=1MB, 31=128TB)
> > *
> > * Set the new size of a BAR as defined in the spec.
> > - * Returns zero if resizing was successful, error code otherwise.
> > + *
> > + * Return: %0 if resizing was successful, or negative on error.
> > */
> > int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size)
> > {
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc
2025-09-11 8:59 ` Ilpo Järvinen
@ 2025-09-11 9:08 ` Christian König
0 siblings, 0 replies; 19+ messages in thread
From: Christian König @ 2025-09-11 9:08 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Krzysztof Wilczyński,
Michał Winiarski, Alex Deucher, amd-gfx, David Airlie,
dri-devel, intel-gfx, intel-xe, Jani Nikula, Joonas Lahtinen,
Lucas De Marchi, Rodrigo Vivi, Simona Vetter, Tvrtko Ursulin,
?UTF-8?q?Thomas=20Hellstr=C3=B6m?=, LKML, linux-doc
On 11.09.25 10:59, Ilpo Järvinen wrote:
> On Thu, 11 Sep 2025, Christian König wrote:
>
>> On 11.09.25 09:55, Ilpo Järvinen wrote:
>>> Fix the copy-pasted errors in the Resizable BAR handling functions
>>> kernel doc and generally improve wording choices.
>>>
>>> Fix the formatting errors of the Return: line.
>>>
>>> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>>> ---
>>> drivers/pci/rebar.c | 29 ++++++++++++++++++-----------
>>> 1 file changed, 18 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
>>> index 020ed7a1b3aa..64315dd8b6bb 100644
>>> --- a/drivers/pci/rebar.c
>>> +++ b/drivers/pci/rebar.c
>>> @@ -58,8 +58,9 @@ void pci_rebar_init(struct pci_dev *pdev)
>>> * @bar: BAR to find
>>> *
>>> * Helper to find the position of the ctrl register for a BAR.
>>> - * Returns -ENOTSUPP if resizable BARs are not supported at all.
>>> - * Returns -ENOENT if no ctrl register for the BAR could be found.
>>> + *
>>> + * Return: %-ENOTSUPP if resizable BARs are not supported at all,
>>> + * %-ENOENT if no ctrl register for the BAR could be found.
>>> */
>>> static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
>>> {
>>> @@ -92,12 +93,15 @@ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
>>> }
>>>
>>> /**
>>> - * pci_rebar_get_possible_sizes - get possible sizes for BAR
>>> + * pci_rebar_get_possible_sizes - get possible sizes for Resizable BAR
>>> * @pdev: PCI device
>>> * @bar: BAR to query
>>> *
>>> * Get the possible sizes of a resizable BAR as bitmask defined in the spec
>>> - * (bit 0=1MB, bit 31=128TB). Returns 0 if BAR isn't resizable.
>>> + * (bit 0=1MB, bit 31=128TB).
>>> + *
>>> + * Return: A bitmask of possible sizes (0=1MB, 31=128TB), or %0 if BAR isn't
>>> + * resizable.
>>> */
>>> u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
>>> {
>>> @@ -121,12 +125,14 @@ u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar)
>>> EXPORT_SYMBOL(pci_rebar_get_possible_sizes);
>>>
>>> /**
>>> - * pci_rebar_get_current_size - get the current size of a BAR
>>> + * pci_rebar_get_current_size - get the current size of a Resizable BAR
>>> * @pdev: PCI device
>>> - * @bar: BAR to set size to
>>> + * @bar: BAR to get the size from
>>> *
>>> - * Read the size of a BAR from the resizable BAR config.
>>> - * Returns size if found or negative error code.
>>> + * Reads the current size of a BAR from the Resizable BAR config.
>>> + *
>>> + * Return: BAR Size if @bar is resizable (bit 0=1MB, bit 31=128TB), or
>>
>> This is a bit misleading since there is no mask returned but rather the
>> order or in other words which bit of the mask was used.
>
> Thanks for noticing this. I'll removed "bit" x2 from it, does that fully
> address your concern?
That works for me, yes.
Regards,
Christian.
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* RE: [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move into rebar.c
2025-09-11 7:55 ` [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move " Ilpo Järvinen
@ 2025-09-11 17:25 ` Ruhl, Michael J
0 siblings, 0 replies; 19+ messages in thread
From: Ruhl, Michael J @ 2025-09-11 17:25 UTC (permalink / raw)
To: Ilpo Järvinen, linux-pci@vger.kernel.org, Bjorn Helgaas,
Krzysztof Wilczyński, Christian König,
Winiarski, Michal, Alex Deucher, amd-gfx@lists.freedesktop.org,
David Airlie, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
Jani Nikula, Joonas Lahtinen, De Marchi, Lucas, Vivi, Rodrigo,
Simona Vetter, Tvrtko Ursulin, ?UTF-8?q?Thomas=20Hellstr=C3=B6m?=,
linux-kernel@vger.kernel.org
Cc: linux-doc@vger.kernel.org
>-----Original Message-----
>From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of Ilpo
>Järvinen
>Sent: Thursday, September 11, 2025 3:56 AM
>To: linux-pci@vger.kernel.org; Bjorn Helgaas <bhelgaas@google.com>;
>Krzysztof Wilczyński <kw@linux.com>; Christian König
><christian.koenig@amd.com>; Winiarski, Michal <michal.winiarski@intel.com>;
>Alex Deucher <alexander.deucher@amd.com>; amd-gfx@lists.freedesktop.org;
>David Airlie <airlied@gmail.com>; dri-devel@lists.freedesktop.org; intel-
>gfx@lists.freedesktop.org; intel-xe@lists.freedesktop.org; Jani Nikula
><jani.nikula@linux.intel.com>; Joonas Lahtinen
><joonas.lahtinen@linux.intel.com>; De Marchi, Lucas
><lucas.demarchi@intel.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>; Simona
>Vetter <simona@ffwll.ch>; Tvrtko Ursulin <tursulin@ursulin.net>; ?UTF-
>8?q?Thomas=20Hellstr=C3=B6m?= <thomas.hellstrom@linux.intel.com>; linux-
>kernel@vger.kernel.org
>Cc: linux-doc@vger.kernel.org; Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>Subject: [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move into
>rebar.c
>
>Move pci_rebar_bytes_to_size() from include/linux/pci.h into 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>
>---
> drivers/pci/rebar.c | 23 +++++++++++++++++++++++
> include/linux/pci.h | 10 +++-------
> 2 files changed, 26 insertions(+), 7 deletions(-)
>
>diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
>index b87cfa6fb3ef..961bd43be02b 100644
>--- a/drivers/pci/rebar.c
>+++ b/drivers/pci/rebar.c
>@@ -7,11 +7,34 @@
> #include <linux/errno.h>
> #include <linux/export.h>
> #include <linux/ioport.h>
>+#include <linux/log2.h>
> #include <linux/pci.h>
>+#include <linux/sizes.h>
> #include <linux/types.h>
>
> #include "pci.h"
>
>+#define PCI_REBAR_MIN_SIZE ((resource_size_t)SZ_1M)
>+
>+/**
>+ * pci_rebar_bytes_to_size - Convert size in bytes to PCI BAR Size
>+ * @bytes: size in bytes
>+ *
>+ * Convert bytes to BAR Size in Resizable BAR Capability (PCIe r6.2,
>+ * sec. 7.8.6.3).
>+ *
>+ * Return: BAR Size as defined in the PCIe spec (0=1MB, bit 31=128TB).
Thank you for this helper and documentation. I wasted a lot of time to trying to understand
this usage a few years ago.
Regardless of the rest of the patch set, this update should be used.
Reviewed-by: Michael J. Ruhl <mjruhl@habana.ai
Mike
>+ */
>+int pci_rebar_bytes_to_size(u64 bytes)
>+{
>+ int rebar_minsize = ilog2(PCI_REBAR_MIN_SIZE);
>+
>+ bytes = roundup_pow_of_two(bytes);
>+
>+ return max(ilog2(bytes), rebar_minsize) - rebar_minsize;
>+}
>+EXPORT_SYMBOL_GPL(pci_rebar_bytes_to_size);
>+
> void pci_rebar_init(struct pci_dev *pdev)
> {
> pdev->rebar_cap = pci_find_ext_capability(pdev,
>PCI_EXT_CAP_ID_REBAR);
>diff --git a/include/linux/pci.h b/include/linux/pci.h
>index 59876de13860..894e9020b07d 100644
>--- a/include/linux/pci.h
>+++ b/include/linux/pci.h
>@@ -1418,16 +1418,12 @@ void pcibios_reset_secondary_bus(struct pci_dev
>*dev);
> void pci_update_resource(struct pci_dev *dev, int resno);
> int __must_check pci_assign_resource(struct pci_dev *dev, int i);
> void pci_release_resource(struct pci_dev *dev, int resno);
>-static inline int pci_rebar_bytes_to_size(u64 bytes)
>-{
>- bytes = roundup_pow_of_two(bytes);
>-
>- /* Return BAR size as defined in the resizable BAR specification */
>- return max(ilog2(bytes), 20) - 20;
>-}
>
>+/* Resizable BAR related routines */
>+int pci_rebar_bytes_to_size(u64 bytes);
> 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 pci_select_bars(struct pci_dev *dev, unsigned long flags);
> bool pci_device_is_present(struct pci_dev *pdev);
> void pci_ignore_hotplug(struct pci_dev *dev);
>--
>2.39.5
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc
2025-09-11 7:55 ` [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc Ilpo Järvinen
2025-09-11 8:24 ` Christian König
@ 2025-09-11 20:58 ` Randy Dunlap
1 sibling, 0 replies; 19+ messages in thread
From: Randy Dunlap @ 2025-09-11 20:58 UTC (permalink / raw)
To: Ilpo Järvinen, linux-pci, Bjorn Helgaas,
Krzysztof Wilczyński, Christian König,
Michał Winiarski, Alex Deucher, amd-gfx, David Airlie,
dri-devel, intel-gfx, intel-xe, Jani Nikula, Joonas Lahtinen,
Lucas De Marchi, Rodrigo Vivi, Simona Vetter, Tvrtko Ursulin,
?UTF-8?q?Thomas=20Hellstr=C3=B6m?=, linux-kernel
Cc: linux-doc
Hi,
On 9/11/25 12:55 AM, Ilpo Järvinen wrote:
> Fix the copy-pasted errors in the Resizable BAR handling functions
> kernel doc and generally improve wording choices.
>
> Fix the formatting errors of the Return: line.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
> drivers/pci/rebar.c | 29 ++++++++++++++++++-----------
> 1 file changed, 18 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/pci/rebar.c b/drivers/pci/rebar.c
> index 020ed7a1b3aa..64315dd8b6bb 100644
> --- a/drivers/pci/rebar.c
> +++ b/drivers/pci/rebar.c
> @@ -58,8 +58,9 @@ void pci_rebar_init(struct pci_dev *pdev)
> * @bar: BAR to find
> *
> * Helper to find the position of the ctrl register for a BAR.
> - * Returns -ENOTSUPP if resizable BARs are not supported at all.
> - * Returns -ENOENT if no ctrl register for the BAR could be found.
> + *
> + * Return: %-ENOTSUPP if resizable BARs are not supported at all,
> + * %-ENOENT if no ctrl register for the BAR could be found.
These 2 lines will run together in the (html) output. They could be
made "prettier" (IMO) into a 2-item list if you choose:
* Return:
* * %-ENOTSUPP if resizable BARs are not supported at all
* * %-ENOENT if no ctrl register for the BAR could be found
> */
> static int pci_rebar_find_pos(struct pci_dev *pdev, int bar)
> {
--
~Randy
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2025-09-11 20:58 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-11 7:55 [PATCH 00/11] PCI: Resizable BAR improvements Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 01/11] PCI: Move Resizable BAR code into rebar.c Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 02/11] PCI: Cleanup pci_rebar_bytes_to_size() and move " Ilpo Järvinen
2025-09-11 17:25 ` Ruhl, Michael J
2025-09-11 7:55 ` [PATCH 03/11] PCI: Move pci_rebar_size_to_bytes() and export it Ilpo Järvinen
2025-09-11 7:55 ` [PATCH 04/11] PCI: Improve Resizable BAR functions kernel doc Ilpo Järvinen
2025-09-11 8:24 ` Christian König
2025-09-11 8:59 ` Ilpo Järvinen
2025-09-11 9:08 ` Christian König
2025-09-11 20:58 ` Randy Dunlap
2025-09-11 7:55 ` [PATCH 05/11] PCI: Add pci_rebar_size_supported() helper Ilpo Järvinen
2025-09-11 8:27 ` Christian König
2025-09-11 7:56 ` [PATCH 06/11] drm/i915/gt: Use pci_rebar_size_supported() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 07/11] drm/xe/vram: Use PCI rebar helpers in resize_vram_bar() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 08/11] PCI: Add pci_rebar_get_max_size() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 09/11] drm/xe/vram: Use pci_rebar_get_max_size() Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 10/11] drm/amdgpu: " Ilpo Järvinen
2025-09-11 7:56 ` [PATCH 11/11] PCI: Convert BAR sizes bitmasks to u64 Ilpo Järvinen
2025-09-11 8:35 ` [PATCH 00/11] PCI: Resizable BAR improvements Christian König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox