Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/37212 )
Change subject: arch/x86/exit_car.S: Make sure _cbmem_top_ptr hits dram
......................................................................
arch/x86/exit_car.S: Make sure _cbmem_top_ptr hits dram
INVD is called below so if postcar is running in a cached environment
it needs to happen.
NOTE: postcar cannot execute in a cached environment if clflush is not
supported!
Change-Id: I37681ee1f1d2ae5f9dd824b5baf7b23b2883b1dc
Signed-off-by: Arthur Heymans <arthur(a)aheymans.xyz>
---
M src/arch/x86/exit_car.S
1 file changed, 7 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/12/37212/1
diff --git a/src/arch/x86/exit_car.S b/src/arch/x86/exit_car.S
index 8c28784..ceb0321 100644
--- a/src/arch/x86/exit_car.S
+++ b/src/arch/x86/exit_car.S
@@ -38,7 +38,14 @@
movl 4(%esp), %eax
movl %eax, _cbmem_top_ptr
#endif
+ /* Make sure _cbmem_top_ptr hits dram before invd */
+ movl $1, %eax
+ cpuid
+ btl $19, %edx
+ jz skip_clflush
+ clflush _cbmem_top_ptr
+skip_clflush:
/* chipset_teardown_car() is expected to disable cache-as-ram. */
call chipset_teardown_car
--
To view, visit https://review.coreboot.org/c/coreboot/+/37212
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I37681ee1f1d2ae5f9dd824b5baf7b23b2883b1dc
Gerrit-Change-Number: 37212
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-MessageType: newchange
Arthur Heymans has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/37199 )
Change subject: cpu/x86/mtrr: Add helper function to cache cbmem in romstage
......................................................................
cpu/x86/mtrr: Add helper function to cache cbmem in romstage
Romstage has some operations on cbmem and external stage cache.
In most circumstances this memory is set up as UC, so to speed
up these operations like decompressing postcar, this has to be
set up as WB.
Note: This should only be attempted on platforms where some form
of non eviction mode is used to guarantee not blowing up CAR.
Change-Id: Ic0bc487a11cd0f5c489383364c729547031beccc
Signed-off-by: Arthur Heymans <arthur(a)aheymans.xyz>
---
M src/cpu/x86/mtrr/Makefile.inc
A src/cpu/x86/mtrr/cbmem_cache.c
M src/include/cpu/x86/mtrr.h
3 files changed, 79 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/99/37199/1
diff --git a/src/cpu/x86/mtrr/Makefile.inc b/src/cpu/x86/mtrr/Makefile.inc
index 129d05d..2658388 100644
--- a/src/cpu/x86/mtrr/Makefile.inc
+++ b/src/cpu/x86/mtrr/Makefile.inc
@@ -11,3 +11,5 @@
bootblock-$(CONFIG_SETUP_XIP_CACHE) += xip_cache.c
verstage-$(CONFIG_SETUP_XIP_CACHE) += xip_cache.c
+
+romstage-y += cbmem_cache.c
\ No newline at end of file
diff --git a/src/cpu/x86/mtrr/cbmem_cache.c b/src/cpu/x86/mtrr/cbmem_cache.c
new file mode 100644
index 0000000..8753e9e
--- /dev/null
+++ b/src/cpu/x86/mtrr/cbmem_cache.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <cbmem.h>
+#include <stage_cache.h>
+#include <cpu/x86/cache.h>
+#include <arch/cpu.h>
+#include <program_loading.h>
+#include <commonlib/region.h>
+#include <console/console.h>
+#include <cpu/x86/mtrr.h>
+
+void setup_romstage_wb_cbmem_cache(void)
+{
+ int mtrr_num = get_free_var_mtrr();
+ uintptr_t top_of_ram = (uintptr_t)cbmem_top();
+ uintptr_t stage_cache_base, stage_cache_end;
+ size_t stage_cache_size;
+ size_t stage_cache_mtrr_size = 4 * KiB;
+
+ printk(BIOS_DEBUG, "Setting MTRR's for cbmem and stage cache\n");
+
+ /* postcar will do invd so we need a way to make sure things are in memory
+ which is only possible if clflush is supported. */
+ if (!clflush_supported()) {
+ printk(BIOS_WARNING, "CLFLUSH not supported, not caching cbmem!\n");
+ if (CONFIG(COMPRESS_POSTCAR))
+ printk(BIOS_WARNING, "Decompressing POSTCAR will be slow!\n");
+
+ return;
+ }
+ if (mtrr_num < 0) {
+ printk(BIOS_DEBUG, "No MTRR free to cache cbmem\n!");
+ return;
+ }
+ /* Often cbmem_top is chosen to be aligned already to optimize MTRR
+ usage in the postcar frame so this should not be too worrisome. */
+ top_of_ram = ALIGN_DOWN(top_of_ram, 4 * MiB);
+ set_var_mtrr(mtrr_num, top_of_ram - 4 * MiB, 4 * MiB, MTRR_TYPE_WRBACK);
+
+ if (!CONFIG(TSEG_STAGE_CACHE))
+ return;
+ mtrr_num = get_free_var_mtrr();
+ if (mtrr_num < 0) {
+ printk(BIOS_DEBUG, "No MTRR free to cache TSEG stage cache\n!");
+ return;
+ }
+ stage_cache_external_region((void **)&stage_cache_base, &stage_cache_size);
+ stage_cache_end = stage_cache_base + stage_cache_size;
+
+ /* Find MTRR to cover TSEG stage cache */
+ while (1) {
+ /* Do some sanity check before it gets absurdly. */
+ if (stage_cache_mtrr_size > 64 * MiB) {
+ printk(BIOS_WARNING, "Not caching stage cache, too large\n");
+ return;
+ }
+ if (ALIGN_DOWN(stage_cache_base, stage_cache_mtrr_size)
+ + stage_cache_mtrr_size > stage_cache_end)
+ break;
+ stage_cache_mtrr_size *= 2;
+ }
+ set_var_mtrr(mtrr_num, ALIGN_DOWN(stage_cache_base, stage_cache_mtrr_size),
+ stage_cache_mtrr_size, MTRR_TYPE_WRBACK);
+}
diff --git a/src/include/cpu/x86/mtrr.h b/src/include/cpu/x86/mtrr.h
index 29256c8..abdecfe 100644
--- a/src/include/cpu/x86/mtrr.h
+++ b/src/include/cpu/x86/mtrr.h
@@ -95,6 +95,8 @@
void x86_setup_fixed_mtrrs_no_enable(void);
void x86_mtrr_check(void);
+void setup_romstage_wb_cbmem_cache(void);
+
/* Insert a temporary MTRR range for the duration of coreboot's runtime.
* This function needs to be called after the first MTRR solution is derived. */
void mtrr_use_temp_range(uintptr_t begin, size_t size, int type);
--
To view, visit https://review.coreboot.org/c/coreboot/+/37199
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ic0bc487a11cd0f5c489383364c729547031beccc
Gerrit-Change-Number: 37199
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: Martin Roth <martinroth(a)google.com>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-MessageType: newchange