From 4ed22601369d074425a43d2077ff84ab4b328d51 Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Mon, 11 Apr 2022 18:58:09 +0200 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/63555 Tested-by: build bot (Jenkins) Reviewed-by: Lean Sheng Tan Reviewed-by: Tim Wawrzynczak Reviewed-by: Subrata Banik --- src/cpu/x86/mtrr/mtrr.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/cpu/x86/mtrr/mtrr.c b/src/cpu/x86/mtrr/mtrr.c index d8903b89e0af..d1098d988f29 100644 --- a/src/cpu/x86/mtrr/mtrr.c +++ b/src/cpu/x86/mtrr/mtrr.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -873,6 +874,28 @@ void mtrr_use_temp_range(uintptr_t begin, size_t size, int type) 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 @@ void mtrr_use_temp_range(uintptr_t begin, size_t size, int type) } /* 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"); -- cgit v1.2.3