Arthur Heymans has submitted this change. ( https://review.coreboot.org/c/coreboot/+/63555 )
Change subject: cpu/x86/mtrr: Allow for multiple TEMP MTRR ranges ......................................................................
cpu/x86/mtrr: Allow for multiple TEMP MTRR ranges
Temporary MTRR setup usually covers the memory mapped flash. On recent Intel hardware the mapping is not coherent. It uses an external window for parts of the BIOS region that exceed 16M.
This now allows up to 10 temporary memory ranges.
TESTED: Qemu with multiple MTRR temporary MTRR ranges sets up a valid and optimized temporary MTRR solution.
Change-Id: I23442bd2ab7602e4c5cbd37d187a31413cf27ecc Signed-off-by: Arthur Heymans arthur@aheymans.xyz Reviewed-on: https://review.coreboot.org/c/coreboot/+/63555 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Lean Sheng Tan sheng.tan@9elements.com Reviewed-by: Tim Wawrzynczak twawrzynczak@chromium.org Reviewed-by: Subrata Banik subratabanik@google.com --- M src/cpu/x86/mtrr/mtrr.c 1 file changed, 28 insertions(+), 1 deletion(-)
Approvals: build bot (Jenkins): Verified Lean Sheng Tan: Looks good to me, approved Tim Wawrzynczak: Looks good to me, approved Subrata Banik: Looks good to me, approved
diff --git a/src/cpu/x86/mtrr/mtrr.c b/src/cpu/x86/mtrr/mtrr.c index d8903b8..d1098d9 100644 --- a/src/cpu/x86/mtrr/mtrr.c +++ b/src/cpu/x86/mtrr/mtrr.c @@ -9,6 +9,7 @@ */
#include <stddef.h> +#include <stdint.h> #include <string.h> #include <bootstate.h> #include <commonlib/helpers.h> @@ -873,6 +874,28 @@ struct memranges addr_space; const int above4gb = 1; /* Cover above 4GiB by default. */ int address_bits; + static struct temp_range { + uintptr_t begin; + size_t size; + int type; + } temp_ranges[10]; + + if (size == 0) + return; + + int i; + for (i = 0; i < ARRAY_SIZE(temp_ranges); i++) { + if (temp_ranges[i].size == 0) { + temp_ranges[i].begin = begin; + temp_ranges[i].size = size; + temp_ranges[i].type = type; + break; + } + } + if (i == ARRAY_SIZE(temp_ranges)) { + printk(BIOS_ERR, "Out of temporary ranges for MTRR use\n"); + return; + }
/* Make a copy of the original address space and tweak it with the * provided range. */ @@ -891,7 +914,11 @@ }
/* Place new range into the address space. */ - memranges_insert(&addr_space, begin, size, type); + for (i = 0; i < ARRAY_SIZE(temp_ranges); i++) { + if (temp_ranges[i].size != 0) + memranges_insert(&addr_space, temp_ranges[i].begin, + temp_ranges[i].size, temp_ranges[i].type); + }
print_physical_address_space(&addr_space, "TEMPORARY");