Arthur Heymans has uploaded this change for review.

View Change

[UNTESTED]drivers/amd/agesa: Don't save regular boot MTRR to flash

Save the regular boot MTRR's that are restored on the S3 path during
the CPU init with cbmem instead of storing them to the SPI flash.

Change-Id: Ia58e7cd1afb785ba0c379ba75ef6090b56cb9dc6
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
---
M src/commonlib/include/commonlib/cbmem_id.h
M src/drivers/amd/agesa/oem_s3.c
M src/drivers/amd/agesa/s3_mtrr.c
M src/northbridge/amd/agesa/agesa_helper.h
4 files changed, 21 insertions(+), 52 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/94/44294/1
diff --git a/src/commonlib/include/commonlib/cbmem_id.h b/src/commonlib/include/commonlib/cbmem_id.h
index ac271a0..058a9d4 100644
--- a/src/commonlib/include/commonlib/cbmem_id.h
+++ b/src/commonlib/include/commonlib/cbmem_id.h
@@ -8,6 +8,7 @@
#define CBMEM_ID_ACPI_UCSI 0x55435349
#define CBMEM_ID_AFTER_CAR 0xc4787a93
#define CBMEM_ID_AGESA_RUNTIME 0x41474553
+#define CBMEM_ID_AGESA_MTRR 0xf08b4b9d
#define CBMEM_ID_AMDMCT_MEMINFO 0x494D454E
#define CBMEM_ID_CAR_GLOBALS 0xcac4e6a3
#define CBMEM_ID_CBTABLE 0x43425442
@@ -74,6 +75,7 @@
{ CBMEM_ID_ACPI_GNVS, "ACPI GNVS " }, \
{ CBMEM_ID_ACPI_UCSI, "ACPI UCSI " }, \
{ CBMEM_ID_AGESA_RUNTIME, "AGESA RSVD " }, \
+ { CBMEM_ID_AGESA_MTRR, "AGESA MTRR " }, \
{ CBMEM_ID_AFTER_CAR, "AFTER CAR " }, \
{ CBMEM_ID_AMDMCT_MEMINFO, "AMDMEM INFO" }, \
{ CBMEM_ID_CAR_GLOBALS, "CAR GLOBALS" }, \
diff --git a/src/drivers/amd/agesa/oem_s3.c b/src/drivers/amd/agesa/oem_s3.c
index e47daf3..0b37d3e 100644
--- a/src/drivers/amd/agesa/oem_s3.c
+++ b/src/drivers/amd/agesa/oem_s3.c
@@ -9,45 +9,24 @@
#include <AGESA.h>
#include <northbridge/amd/agesa/agesa_helper.h>

-typedef enum {
- S3DataTypeNonVolatile = 0, ///< NonVolatile Data Type
- S3DataTypeMTRR ///< MTRR storage
-} S3_DATA_TYPE;
-
/* The size needs to be 4k aligned, which is the sector size of most flashes. */
-#define S3_DATA_MTRR_SIZE 0x1000
#define S3_DATA_NONVOLATILE_SIZE 0x1000

-#if CONFIG(HAVE_ACPI_RESUME) && \
- (S3_DATA_MTRR_SIZE + S3_DATA_NONVOLATILE_SIZE) > CONFIG_S3_DATA_SIZE
+#if CONFIG(HAVE_ACPI_RESUME) && S3_DATA_NONVOLATILE_SIZE > CONFIG_S3_DATA_SIZE
#error "Please increase the value of S3_DATA_SIZE"
#endif

-static void get_s3nv_data(S3_DATA_TYPE S3DataType, uintptr_t *pos, uintptr_t *len)
+static void get_s3nv_data(uintptr_t *pos, uintptr_t *len)
{
/* FIXME: Find file from CBFS. */
- u32 s3_data = CONFIG_S3_DATA_POS;
-
- switch (S3DataType) {
- case S3DataTypeMTRR:
- *pos = s3_data;
- *len = S3_DATA_MTRR_SIZE;
- break;
- case S3DataTypeNonVolatile:
- *pos = s3_data + S3_DATA_MTRR_SIZE;
- *len = S3_DATA_NONVOLATILE_SIZE;
- break;
- default:
- *pos = 0;
- *len = 0;
- break;
- }
+ *pos = CONFIG_S3_DATA_POS;
+ *len= S3_DATA_NONVOLATILE_SIZE;
}

AGESA_STATUS OemInitResume(AMD_S3_PARAMS *dataBlock)
{
uintptr_t pos, size;
- get_s3nv_data(S3DataTypeNonVolatile, &pos, &size);
+ get_s3nv_data(&pos, &size);

u32 len = *(u32*)pos;

@@ -101,15 +80,12 @@
#endif
}

-static u8 MTRRStorage[S3_DATA_MTRR_SIZE];
-
AGESA_STATUS OemS3Save(AMD_S3_PARAMS *dataBlock)
{
- u32 MTRRStorageSize = 0;
uintptr_t pos, size;

/* To be consumed in AmdInitResume. */
- get_s3nv_data(S3DataTypeNonVolatile, &pos, &size);
+ get_s3nv_data(&pos, &size);
if (size && dataBlock->NvStorageSize)
spi_SaveS3info(pos, size, dataBlock->NvStorage,
dataBlock->NvStorageSize);
@@ -127,24 +103,9 @@
}

/* Collect MTRR setup. */
- backup_mtrr(MTRRStorage, &MTRRStorageSize);
-
- /* To be consumed in restore_mtrr, CPU enumeration in ramstage. */
- get_s3nv_data(S3DataTypeMTRR, &pos, &size);
- if (size && MTRRStorageSize)
- spi_SaveS3info(pos, size, MTRRStorage, MTRRStorageSize);
+ backup_mtrr();

return AGESA_SUCCESS;
}

#endif /* ENV_RAMSTAGE */
-
-const void *OemS3Saved_MTRR_Storage(void)
-{
- uintptr_t pos, size;
- get_s3nv_data(S3DataTypeMTRR, &pos, &size);
- if (!size)
- return NULL;
-
- return (void *)(pos + sizeof(UINT32));
-}
diff --git a/src/drivers/amd/agesa/s3_mtrr.c b/src/drivers/amd/agesa/s3_mtrr.c
index 672eb20..be38327 100644
--- a/src/drivers/amd/agesa/s3_mtrr.c
+++ b/src/drivers/amd/agesa/s3_mtrr.c
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */

#include <stdint.h>
+#include <cbmem.h>
#include <cpu/x86/msr.h>
#include <cpu/x86/mtrr.h>
#include <cpu/amd/mtrr.h>
@@ -20,12 +21,16 @@
msr_t top_mem2;
};

-void backup_mtrr(void *mtrr_store, u32 *mtrr_store_size)
+void backup_mtrr(void)
{
msr_t syscfg_msr;
- struct mtrr_backup *mtrr_save = (struct mtrr_backup *)mtrr_store;
+ struct mtrr_backup *mtrr_save;
uint32_t i;

+ mtrr_save = cbmem_add(CBMEM_ID_AGESA_MTRR, sizeof(struct mtrr_backup));
+ if (!mtrr_save)
+ return;
+
/* Enable access to AMD RdDram and WrDram extension bits */
syscfg_msr = rdmsr(SYSCFG_MSR);
syscfg_msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
@@ -51,16 +56,17 @@
mtrr_save->syscfg = rdmsr(SYSCFG_MSR);
mtrr_save->top_mem = rdmsr(TOP_MEM);
mtrr_save->top_mem2 = rdmsr(TOP_MEM2);
-
- *mtrr_store_size = sizeof(struct mtrr_backup);
}

void restore_mtrr(void)
{
msr_t syscfg_msr;
- struct mtrr_backup *mtrr_save = (struct mtrr_backup *)OemS3Saved_MTRR_Storage();
+ struct mtrr_backup *mtrr_save = cbmem_find(CBMEM_ID_AGESA_MTRR);
uint32_t i;

+ if (!mtrr_save)
+ return;
+
/* Enable access to AMD RdDram and WrDram extension bits */
syscfg_msr = rdmsr(SYSCFG_MSR);
syscfg_msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
diff --git a/src/northbridge/amd/agesa/agesa_helper.h b/src/northbridge/amd/agesa/agesa_helper.h
index 120e74a..ef6085f 100644
--- a/src/northbridge/amd/agesa/agesa_helper.h
+++ b/src/northbridge/amd/agesa/agesa_helper.h
@@ -39,7 +39,7 @@
void recover_postcar_frame(struct postcar_frame *pcf, int s3resume);

void restore_mtrr(void);
-void backup_mtrr(void *mtrr_store, u32 *mtrr_store_size);
+void backup_mtrr(void);
const void *OemS3Saved_MTRR_Storage(void);

#endif /* _AGESA_HELPER_H_ */

To view, visit change 44294. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ia58e7cd1afb785ba0c379ba75ef6090b56cb9dc6
Gerrit-Change-Number: 44294
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-MessageType: newchange