[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251219174036.16738-7-ilpo.jarvinen@linux.intel.com>
Date: Fri, 19 Dec 2025 19:40:19 +0200
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: linux-pci@...r.kernel.org,
Bjorn Helgaas <bhelgaas@...gle.com>,
Dominik Brodowski <linux@...inikbrodowski.net>,
linux-kernel@...r.kernel.org
Cc: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
Subject: [PATCH 06/23] PCI: Push realloc check into pbus_size_mem()
pbus_size_mem() and calculate_memsize() input both min_size and
add_size. They are given the same value if realloc_head is NULL and
min_size is 0 otherwise. Both are used in calculate_memsize() to
enforce a lower bound to the size.
The interface between __pci_bus_size_bridges() and the forementioned
functions can be simplied by pushing the realloc check into
pbus_size_mem().
There are only two possible cases:
1) when calculating size0, add_size parameter given to
calculate_memsize() is always 0 which implies only min_size
matters.
2) when calculating size1, realloc_head is not NULL which implies
min_size=0 so only add_size matters.
Drop min_size parameter from pbus_size_mem() and check realloc_head
when calling calculate_memsize(). Drop add_size from
calculate_memsize() and use only min_size within max() to enforce the
lower bound.
calculate_iosize() is a bit more complicated than calculate_memsize()
and is therefore left as is, but pbus_size_io() can still input only
min_size similar to pbus_size_mem().
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
---
drivers/pci/setup-bus.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 8660449f59bd..f85ae20dc894 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1069,14 +1069,10 @@ static resource_size_t calculate_iosize(resource_size_t size,
static resource_size_t calculate_memsize(resource_size_t size,
resource_size_t min_size,
- resource_size_t add_size,
resource_size_t children_add_size,
resource_size_t align)
{
- if (size < min_size)
- size = min_size;
-
- size = max(size, add_size) + children_add_size;
+ size = max(size, min_size) + children_add_size;
return ALIGN(size, align);
}
@@ -1115,8 +1111,7 @@ static resource_size_t window_alignment(struct pci_bus *bus, unsigned long type)
* pbus_size_io() - Size the I/O window of a given bus
*
* @bus: The bus
- * @min_size: The minimum I/O window that must be allocated
- * @add_size: Additional optional I/O window
+ * @add_size: Additional I/O window
* @realloc_head: Track the additional I/O window on this list
*
* Sizing the I/O windows of the PCI-PCI bridge is trivial, since these
@@ -1124,8 +1119,7 @@ static resource_size_t window_alignment(struct pci_bus *bus, unsigned long type)
* devices are limited to 256 bytes. We must be careful with the ISA
* aliasing though.
*/
-static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
- resource_size_t add_size,
+static void pbus_size_io(struct pci_bus *bus, resource_size_t add_size,
struct list_head *realloc_head)
{
struct pci_dev *dev;
@@ -1170,7 +1164,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
}
}
- size0 = calculate_iosize(size, min_size, size1, 0, 0,
+ size0 = calculate_iosize(size, realloc_head ? 0 : add_size, size1, 0, 0,
resource_size(b_res), min_align);
if (size0)
@@ -1178,7 +1172,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
size1 = size0;
if (realloc_head && (add_size > 0 || children_add_size > 0)) {
- size1 = calculate_iosize(size, min_size, size1, add_size,
+ size1 = calculate_iosize(size, 0, size1, add_size,
children_add_size, resource_size(b_res),
min_align);
}
@@ -1269,8 +1263,7 @@ static resource_size_t calculate_head_align(resource_size_t *aligns,
*
* @bus: The bus
* @type: The type of bridge resource
- * @min_size: The minimum memory window that must be allocated
- * @add_size: Additional optional memory window
+ * @add_size: Additional memory window
* @realloc_head: Track the additional memory window on this list
*
* Calculate the size of the bus resource for @type and minimal alignment
@@ -1283,7 +1276,6 @@ static resource_size_t calculate_head_align(resource_size_t *aligns,
* supplied.
*/
static void pbus_size_mem(struct pci_bus *bus, unsigned long type,
- resource_size_t min_size,
resource_size_t add_size,
struct list_head *realloc_head)
{
@@ -1363,7 +1355,8 @@ static void pbus_size_mem(struct pci_bus *bus, unsigned long type,
win_align = window_alignment(bus, b_res->flags);
min_align = calculate_head_align(aligns, max_order);
min_align = max(min_align, win_align);
- size0 = calculate_memsize(size, min_size, 0, 0, win_align);
+ size0 = calculate_memsize(size, realloc_head ? 0 : add_size,
+ 0, win_align);
if (size0) {
resource_set_range(b_res, min_align, size0);
@@ -1372,7 +1365,7 @@ static void pbus_size_mem(struct pci_bus *bus, unsigned long type,
if (realloc_head && (add_size > 0 || children_add_size > 0)) {
add_align = max(min_align, add_align);
- size1 = calculate_memsize(size, min_size, add_size, children_add_size,
+ size1 = calculate_memsize(size, add_size, children_add_size,
win_align);
}
@@ -1550,20 +1543,17 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
}
fallthrough;
default:
- pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
- additional_io_size, realloc_head);
+ pbus_size_io(bus, additional_io_size, realloc_head);
if (pref && (pref->flags & IORESOURCE_PREFETCH)) {
pbus_size_mem(bus,
IORESOURCE_MEM | IORESOURCE_PREFETCH |
(pref->flags & IORESOURCE_MEM_64),
- realloc_head ? 0 : additional_mmio_pref_size,
additional_mmio_pref_size, realloc_head);
}
- pbus_size_mem(bus, IORESOURCE_MEM,
- realloc_head ? 0 : additional_mmio_size,
- additional_mmio_size, realloc_head);
+ pbus_size_mem(bus, IORESOURCE_MEM, additional_mmio_size,
+ realloc_head);
break;
}
}
--
2.39.5
Powered by blists - more mailing lists