Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/38700 )
Change subject: drivers/intel/fsp2_0: Add weak reservation for FSP-M memory
......................................................................
drivers/intel/fsp2_0: Add weak reservation for FSP-M memory
The function fsp_memory_init() is capable of executing in place or
as non-XIP. For devices starting with DRAM enabled, this option
increases performance but requires the memory to be reserved later.
Add a weak function so the soc may save the base and size of the
memory consumed by FSP-M.
Signed-off-by: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Change-Id: I04b2fff4074b720d1910ff21e1a1f841cfea8efb
---
M src/drivers/intel/fsp2_0/include/fsp/api.h
M src/drivers/intel/fsp2_0/memory_init.c
2 files changed, 10 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/00/38700/1
diff --git a/src/drivers/intel/fsp2_0/include/fsp/api.h b/src/drivers/intel/fsp2_0/include/fsp/api.h
index 60adb98..a0366f6 100644
--- a/src/drivers/intel/fsp2_0/include/fsp/api.h
+++ b/src/drivers/intel/fsp2_0/include/fsp/api.h
@@ -50,6 +50,12 @@
void fsp_temp_ram_exit(void);
/*
+ * When fsp_memory_init() runs non-XIP, and if it affects any DRAM, allow
+ * the soc to note the memory to be reserved.
+ */
+void fsp_reserve_fspm_mem(uintptr_t base, size_t size);
+
+/*
* Load FSP-S from stage cache or CBFS. This allows SoCs to load FSPS-S
* separately from calling silicon init. It might be required in cases where
* stage cache is no longer available by the point SoC calls into silicon init.
diff --git a/src/drivers/intel/fsp2_0/memory_init.c b/src/drivers/intel/fsp2_0/memory_init.c
index 455dfa5..3e9da8e 100644
--- a/src/drivers/intel/fsp2_0/memory_init.c
+++ b/src/drivers/intel/fsp2_0/memory_init.c
@@ -42,6 +42,8 @@
CONFIG(VBOOT_STARTS_IN_BOOTBLOCK),
"for TPM MRC hash functionality, vboot must start in bootblock");
+__weak void fsp_reserve_fspm_mem(uintptr_t base, size_t size) {}
+
static void save_memory_training_data(bool s3wake, uint32_t fsp_version)
{
size_t mrc_data_size;
@@ -356,6 +358,8 @@
if (rdev_readat(rdev, (void *)fspm_begin, 0, fspm_end - fspm_begin) < 0)
return CB_ERR;
+ fsp_reserve_fspm_mem(fspm_begin, fspm_end - fspm_begin);
+
return CB_SUCCESS;
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/38700
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I04b2fff4074b720d1910ff21e1a1f841cfea8efb
Gerrit-Change-Number: 38700
Gerrit-PatchSet: 1
Gerrit-Owner: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Gerrit-Reviewer: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Gerrit-Reviewer: Patrick Rudolph <siro(a)das-labor.org>
Gerrit-MessageType: newchange
Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/38729 )
Change subject: arch/x86: Set/get DRAM consumed by early non-XIP stages
......................................................................
arch/x86: Set/get DRAM consumed by early non-XIP stages
Save DRAM consumed by bootblock, verstage, and romstage when those
stages do not execute in place (and also not from CAR). Gather
each program's region as they are prepared to be run. Store the
information in a new earlymem region then move to cbmem when
it comes online. Override the weak bootmem_platform_add_ranges()
to reserve the regions in ramstage.
Signed-off-by: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Change-Id: Ieaf2885cb23ea42520c086f2ba06d7013becae07
---
M src/arch/x86/Makefile.inc
M src/arch/x86/early_ram.ld
M src/arch/x86/include/arch/stages.h
A src/arch/x86/nonxip_rsvd.c
M src/commonlib/include/commonlib/cbmem_id.h
M src/cpu/x86/mtrr/nonxip_cache.c
M src/include/memlayout.h
M src/include/symbols.h
8 files changed, 117 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/29/38729/1
diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index 534f2ce..1e52a32 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -100,6 +100,7 @@
all-y += memset.c
all-y += cpu_common.c
all-y += post.c
+all-$(CONFIG_RESET_VECTOR_IN_RAM) += nonxip_rsvd.c
endif
diff --git a/src/arch/x86/early_ram.ld b/src/arch/x86/early_ram.ld
index af576ca..c8afe2a 100644
--- a/src/arch/x86/early_ram.ld
+++ b/src/arch/x86/early_ram.ld
@@ -17,6 +17,7 @@
* regions by placing them near the top of bootblock's program region.
* The stack area is reused although not shared across stages.
*/
+_EARLYSTAGES_RSVD_SIZE = 0x40;
_STACK_SIZE = CONFIG_EARLYRAM_BSP_STACK_SIZE;
_CONSOLE_SIZE = CONFIG_PRERAM_CBMEM_CONSOLE_SIZE;
_TIMESTAMPS_SIZE = 0x200;
@@ -30,8 +31,9 @@
_bogus1 = ASSERT(_STACK_SIZE > 0x0, "Early BSP stack size not configured");
/* Place the following regions in predictable locations */
-. = CONFIG_X86_RESET_VECTOR - _STACK_SIZE - _CONSOLE_SIZE - _TIMESTAMPS_SIZE - _FMAP_SIZE - _PAD_FOR_ALIGNS;
+. = CONFIG_X86_RESET_VECTOR - _EARLYSTAGES_RSVD_SIZE - _STACK_SIZE - _CONSOLE_SIZE - _TIMESTAMPS_SIZE - _FMAP_SIZE - _PAD_FOR_ALIGNS;
.earlyram.data . (NOLOAD) : {
+ EARLYSTAGES_RSVD_MEM(., _EARLYSTAGES_RSVD_SIZE)
EARLYRAM_STACK(., _STACK_SIZE)
PRERAM_CBMEM_CONSOLE(., _CONSOLE_SIZE)
TIMESTAMP(., _TIMESTAMPS_SIZE)
diff --git a/src/arch/x86/include/arch/stages.h b/src/arch/x86/include/arch/stages.h
index 0726cac..c598faf 100644
--- a/src/arch/x86/include/arch/stages.h
+++ b/src/arch/x86/include/arch/stages.h
@@ -14,4 +14,9 @@
#ifndef __ARCH_STAGES_H
#define __ARCH_STAGES_H
+#include <program_loading.h>
+
+/* Reserve DRAM used by an early stage not executing as XIP or from CAR */
+void reserve_non_xip_prog(struct prog *prog);
+
#endif
diff --git a/src/arch/x86/nonxip_rsvd.c b/src/arch/x86/nonxip_rsvd.c
new file mode 100644
index 0000000..1d231ec
--- /dev/null
+++ b/src/arch/x86/nonxip_rsvd.c
@@ -0,0 +1,91 @@
+/*
+ * 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 <arch/stages.h>
+#include <bootmem.h>
+#include <cbmem.h>
+#include <commonlib/helpers.h>
+#include <commonlib/region.h>
+#include <console/console.h>
+#include <program_loading.h>
+#include <string.h>
+#include <symbols.h>
+
+struct stages_rsvd_dram {
+ struct region bootblock;
+ struct region verstage;
+ struct region romstage;
+};
+
+
+void reserve_non_xip_prog(struct prog *prog)
+{
+ struct stages_rsvd_dram *p;
+
+ p = (struct stages_rsvd_dram *)_earlystages_rsvd_mem;
+
+ if (ENV_BOOTBLOCK) {
+ /* bootblock inits the region and reserves self */
+ memset(p, _eearlystages_rsvd_mem - _earlystages_rsvd_mem, 0);
+ p->bootblock.offset = (uintptr_t)_bootblock;
+ p->bootblock.size = ALIGN_UP(_ebootblock - _bootblock, 4 * KiB);
+ }
+
+ switch (prog->type) {
+ case PROG_VERSTAGE:
+ p->verstage.offset = region_device_offset(&prog->rdev);
+ p->verstage.size = ALIGN_UP(region_device_sz(&prog->rdev), 4 * KiB);
+ break;
+ case PROG_ROMSTAGE:
+ p->romstage.offset = region_device_offset(&prog->rdev);
+ p->romstage.size = ALIGN_UP(region_device_sz(&prog->rdev), 4 * KiB);
+ break;
+ default:
+ printk(BIOS_ERR, "BUG: Unexpected PROG_LOAD for type %d\n", prog->type);
+ }
+}
+
+void bootmem_platform_add_ranges(void)
+{
+ const struct cbmem_entry *rsvd_mem;
+ struct stages_rsvd_dram *p;
+
+ rsvd_mem = cbmem_entry_find(CBMEM_ID_NONXIP_RSVD);
+ if (!rsvd_mem) {
+ printk(BIOS_ERR, "Error: Unable to find reserved regions in cbmem: %s()\n",
+ __func__);
+ return;
+ }
+ p = cbmem_entry_start(rsvd_mem);
+
+ bootmem_add_range(p->bootblock.offset, p->bootblock.size, BM_MEM_RESERVED);
+ bootmem_add_range(p->verstage.offset, p->verstage.size, BM_MEM_RESERVED);
+ bootmem_add_range(p->romstage.offset, p->romstage.size, BM_MEM_RESERVED);
+}
+
+static void alloc_reservations_in_cbmem(int unused)
+{
+ struct stages_rsvd_dram *c, *p;
+
+ c = cbmem_add(CBMEM_ID_NONXIP_RSVD, sizeof(struct stages_rsvd_dram));
+ if (!c) {
+ printk(BIOS_ERR, "Error: Unable to add reserved regions to cbmem: %s()\n",
+ __func__);
+ return;
+ }
+
+ p = (struct stages_rsvd_dram *)_earlystages_rsvd_mem;
+ memcpy(c, p, sizeof(*p));
+}
+
+ROMSTAGE_CBMEM_INIT_HOOK(alloc_reservations_in_cbmem)
diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h
index b063cd1..3a4f563 100644
--- a/src/commonlib/include/commonlib/cbmem_id.h
+++ b/src/commonlib/include/commonlib/cbmem_id.h
@@ -56,6 +56,7 @@
#define CBMEM_ID_ROMSTAGE_RAM_STACK 0x90357ac4
#define CBMEM_ID_ROOT 0xff4007ff
#define CBMEM_ID_SMBIOS 0x534d4254
+#define CBMEM_ID_NONXIP_RSVD 0x4e584950
#define CBMEM_ID_BERT_RAW_DATA 0x42455254
#define CBMEM_ID_SMM_TSEG_SPACE 0x54534547
#define CBMEM_ID_SMM_SAVE_SPACE 0x07e9acee
@@ -122,6 +123,7 @@
{ CBMEM_ID_ROMSTAGE_RAM_STACK, "ROMSTG STCK" }, \
{ CBMEM_ID_ROOT, "CBMEM ROOT " }, \
{ CBMEM_ID_SMBIOS, "SMBIOS " }, \
+ { CBMEM_ID_NONXIP_RSVD, "NONXIP RSVD" }, \
{ CBMEM_ID_BERT_RAW_DATA, "BERT DATA " }, \
{ CBMEM_ID_SMM_TSEG_SPACE, "TSEG " }, \
{ CBMEM_ID_SMM_SAVE_SPACE, "SMM BACKUP " }, \
diff --git a/src/cpu/x86/mtrr/nonxip_cache.c b/src/cpu/x86/mtrr/nonxip_cache.c
index 334e829..6309b48 100644
--- a/src/cpu/x86/mtrr/nonxip_cache.c
+++ b/src/cpu/x86/mtrr/nonxip_cache.c
@@ -12,11 +12,14 @@
*/
#include <stdint.h>
+#include <arch/stages.h>
#include <cpu/x86/mtrr.h>
#include <console/console.h>
#include <program_loading.h>
-
-void reserve_non_xip_prog(struct prog *prog); // move me
+#include <string.h>
+#include <commonlib/region.h>
+#include <cbmem.h>
+#include <symbols.h>
/* Set a variable MTRR to WB for the program about to run.
* It is up to the designer to ensure ranges are chosen carefully to avoid
@@ -33,6 +36,11 @@
uint32_t mtrr_base;
uint32_t mtrr_size = 4 * KiB;
+ if (!ENV_ROMSTAGE_OR_BEFORE)
+ return;
+
+ reserve_non_xip_prog(prog);
+
mtrr_num = get_free_var_mtrr();
if (mtrr_num == -1) {
printk(BIOS_NOTICE,
diff --git a/src/include/memlayout.h b/src/include/memlayout.h
index 3c8e02b..0afc551 100644
--- a/src/include/memlayout.h
+++ b/src/include/memlayout.h
@@ -74,6 +74,10 @@
ALIGN_COUNTER(16) \
REGION(earlyram_stack, addr, size, 16)
+#define EARLYSTAGES_RSVD_MEM(addr, size) \
+ ALIGN_COUNTER(4) \
+ REGION(earlystages_rsvd_mem, addr, size, 4)
+
/* Use either CBFS_CACHE (unified) or both (PRERAM|POSTRAM)_CBFS_CACHE */
#define CBFS_CACHE(addr, size) \
REGION(cbfs_cache, addr, size, 4) \
diff --git a/src/include/symbols.h b/src/include/symbols.h
index eec4701..649accc 100644
--- a/src/include/symbols.h
+++ b/src/include/symbols.h
@@ -35,6 +35,7 @@
DECLARE_REGION(postram_cbfs_cache)
DECLARE_REGION(cbfs_cache)
DECLARE_REGION(fmap_cache)
+DECLARE_REGION(earlystages_rsvd_mem)
DECLARE_REGION(payload)
/* "program" always refers to the current execution unit. */
--
To view, visit https://review.coreboot.org/c/coreboot/+/38729
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ieaf2885cb23ea42520c086f2ba06d7013becae07
Gerrit-Change-Number: 38729
Gerrit-PatchSet: 1
Gerrit-Owner: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Gerrit-Reviewer: Julius Werner <jwerner(a)chromium.org>
Gerrit-Reviewer: Marshall Dawson <marshalldawson3rd(a)gmail.com>
Gerrit-Reviewer: Martin Roth <martinroth(a)google.com>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-MessageType: newchange