1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/ioport.h>
4 #include <asm/e820/api.h>
6 static void resource_clip(struct resource *res, resource_size_t start,
9 resource_size_t low = 0, high = 0;
11 if (res->end < start || res->start > end)
12 return; /* no conflict */
14 if (res->start < start)
15 low = start - res->start;
18 high = res->end - end;
20 /* Keep the area above or below the conflict, whichever is larger */
28 * Some BIOS-es contain a bug where they add addresses which map to
29 * system RAM in the PCI host bridge window returned by the ACPI _CRS
30 * method, see commit 4dc2287c1805 ("x86: avoid E820 regions when
31 * allocating address space"). To avoid this Linux by default excludes
32 * E820 reservations when allocating addresses since 2010.
33 * In 2019 some systems have shown-up with E820 reservations which cover
34 * the entire _CRS returned PCI host bridge window, causing all attempts
35 * to assign memory to PCI BARs to fail if Linux uses E820 reservations.
37 * Ideally Linux would fully stop using E820 reservations, but then
38 * the old systems this was added for will regress.
39 * Instead keep the old behavior for old systems, while ignoring the
40 * E820 reservations for any systems from now on.
42 static void remove_e820_regions(struct resource *avail)
44 int i, year = dmi_get_bios_year();
45 struct e820_entry *entry;
50 pr_info_once("PCI: Removing E820 reservations from host bridge windows\n");
52 for (i = 0; i < e820_table->nr_entries; i++) {
53 entry = &e820_table->entries[i];
55 resource_clip(avail, entry->addr,
56 entry->addr + entry->size - 1);
60 void arch_remove_reservations(struct resource *avail)
63 * Trim out BIOS area (high 2MB) and E820 regions. We do not remove
64 * the low 1MB unconditionally, as this area is needed for some ISA
65 * cards requiring a memory range, e.g. the i82365 PCMCIA controller.
67 if (avail->flags & IORESOURCE_MEM) {
68 resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END);
70 remove_e820_regions(avail);