]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
PCI: Align head space better
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 24 Mar 2026 16:56:32 +0000 (18:56 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 27 Mar 2026 15:19:08 +0000 (10:19 -0500)
commit9036bd0efcb6162a77f3bf9bacbafba7686c7275
tree3703add19570c960793e308699e7b7da4c40d470
parent8bbe8cec891f88dd3de8cae44812a884e10f1446
PCI: Align head space better

When a bridge window contains big and small resource(s), the small
resource(s) may not amount to the half of the size of the big resource
which would allow calculate_head_align() to shrink the head alignment.
This results in always placing the small resource(s) after the big
resource.

In general, it would be good to be able to place the small resource(s)
before the big resource to achieve better utilization of the address space.
In the cases where the large resource can only fit at the end of the
window, it is even required.

However, carrying the information over from pbus_size_mem() and
calculate_head_align() to __pci_assign_resource() and
pcibios_align_resource() is not easy with the current data structures.

A somewhat hacky way to move the non-aligning tail part to the head is
possible within pcibios_align_resource(). The free space between the start
of the free space span and the aligned start address can be compared with
the non-aligning remainder of the size. If the free space is larger than
the remainder, placing the remainder before the start address is possible.
This relocation should generally work, because PCI resources consist only
power-of-2 atoms.

Various arch requirements may still need to override the relocation, so the
relocation is only applied selectively in such cases.

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=221205
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Xifer <xiferdev@gmail.com>
Link: https://patch.msgid.link/20260324165633.4583-10-ilpo.jarvinen@linux.intel.com
12 files changed:
arch/arm/kernel/bios32.c
arch/m68k/kernel/pcibios.c
arch/mips/pci/pci-generic.c
arch/mips/pci/pci-legacy.c
arch/parisc/kernel/pci.c
arch/powerpc/kernel/pci-common.c
arch/sh/drivers/pci/pci.c
arch/x86/pci/i386.c
arch/xtensa/kernel/pci.c
drivers/pci/setup-res.c
include/linux/pci.h
kernel/resource.c