aboutsummaryrefslogtreecommitdiff
path: root/src/northbridge
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2014-12-16 19:50:47 +0200
committerKyösti Mälkki <kyosti.malkki@gmail.com>2015-05-26 19:14:52 +0200
commit300caced970febaa84357e60cee872553a872af5 (patch)
tree0dc14e0a7e623d603f764d0e72f9e5dd26db2a93 /src/northbridge
parent90a54b087419faf15bef27f5dbd57e79de667f99 (diff)
AGESA: Refactor OEM S3 storage
Use function prototypes that match more closely with the structure of other OEM hooks in agesawrappers. Change-Id: Id241fdce78a21a5138ef60ac2f841b694da92241 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/8606 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan <edward.ocallaghan@koparo.com>
Diffstat (limited to 'src/northbridge')
-rw-r--r--src/northbridge/amd/agesa/agesawrapper.c37
-rw-r--r--src/northbridge/amd/agesa/agesawrapper.h5
-rw-r--r--src/northbridge/amd/agesa/oem_s3.c90
3 files changed, 101 insertions, 31 deletions
diff --git a/src/northbridge/amd/agesa/agesawrapper.c b/src/northbridge/amd/agesa/agesawrapper.c
index 82088ac363..8ad36c7df2 100644
--- a/src/northbridge/amd/agesa/agesawrapper.c
+++ b/src/northbridge/amd/agesa/agesawrapper.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <string.h>
-#include <cpu/amd/agesa/s3_resume.h>
#include <northbridge/amd/agesa/agesawrapper.h>
#include <northbridge/amd/agesa/BiosCallOuts.h>
#include "amdlib.h"
@@ -125,7 +124,6 @@ AGESA_STATUS agesawrapper_amdinitresume(void)
AGESA_STATUS status;
AMD_INTERFACE_PARAMS AmdParamStruct;
AMD_RESUME_PARAMS *AmdResumeParamsPtr;
- S3_DATA_TYPE S3DataType;
memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS));
@@ -141,13 +139,9 @@ AGESA_STATUS agesawrapper_amdinitresume(void)
AmdResumeParamsPtr->S3DataBlock.NvStorageSize = 0;
AmdResumeParamsPtr->S3DataBlock.VolatileStorageSize = 0;
- S3DataType = S3DataTypeNonVolatile;
+ OemInitResume(AmdResumeParamsPtr);
- OemAgesaGetS3Info(S3DataType,
- (u32 *) & AmdResumeParamsPtr->S3DataBlock.NvStorageSize,
- (void **)&AmdResumeParamsPtr->S3DataBlock.NvStorage);
-
- status = AmdInitResume((AMD_RESUME_PARAMS *) AmdParamStruct.NewStructPtr);
+ status = AmdInitResume(AmdResumeParamsPtr);
AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader);
AmdReleaseStruct(&AmdParamStruct);
@@ -185,7 +179,6 @@ AGESA_STATUS agesawrapper_amds3laterestore(void)
AMD_INTERFACE_PARAMS AmdInterfaceParams;
AMD_S3LATE_PARAMS AmdS3LateParams;
AMD_S3LATE_PARAMS *AmdS3LateParamsPtr;
- S3_DATA_TYPE S3DataType;
memset(&AmdS3LateParams, 0, sizeof(AMD_S3LATE_PARAMS));
@@ -199,12 +192,12 @@ AGESA_STATUS agesawrapper_amds3laterestore(void)
AmdCreateStruct(&AmdInterfaceParams);
+#if 0
+ /* TODO: What to do with NvStorage here? */
+ AmdS3LateParamsPtr->S3DataBlock.NvStorageSize = 0;
+#endif
AmdS3LateParamsPtr->S3DataBlock.VolatileStorageSize = 0;
- S3DataType = S3DataTypeVolatile;
-
- OemAgesaGetS3Info(S3DataType,
- (u32 *) & AmdS3LateParamsPtr->S3DataBlock.VolatileStorageSize,
- (void **)&AmdS3LateParamsPtr->S3DataBlock.VolatileStorage);
+ OemS3LateRestore(AmdS3LateParamsPtr);
status = AmdS3LateRestore(AmdS3LateParamsPtr);
AGESA_EVENTLOG(status, &AmdInterfaceParams.StdHeader);
@@ -249,7 +242,6 @@ AGESA_STATUS agesawrapper_amdS3Save(void)
AGESA_STATUS status;
AMD_S3SAVE_PARAMS *AmdS3SaveParamsPtr;
AMD_INTERFACE_PARAMS AmdInterfaceParams;
- S3_DATA_TYPE S3DataType;
memset(&AmdInterfaceParams, 0, sizeof(AMD_INTERFACE_PARAMS));
@@ -269,21 +261,8 @@ AGESA_STATUS agesawrapper_amdS3Save(void)
AGESA_EVENTLOG(status, &AmdInterfaceParams.StdHeader);
ASSERT(status == AGESA_SUCCESS);
- S3DataType = S3DataTypeNonVolatile;
-
- status = OemAgesaSaveS3Info(S3DataType,
- AmdS3SaveParamsPtr->S3DataBlock.NvStorageSize,
- AmdS3SaveParamsPtr->S3DataBlock.NvStorage);
-
- if (AmdS3SaveParamsPtr->S3DataBlock.VolatileStorageSize != 0) {
- S3DataType = S3DataTypeVolatile;
-
- status = OemAgesaSaveS3Info(S3DataType,
- AmdS3SaveParamsPtr->S3DataBlock.VolatileStorageSize,
- AmdS3SaveParamsPtr->S3DataBlock.VolatileStorage);
- }
+ OemS3Save(AmdS3SaveParamsPtr);
- OemAgesaSaveMtrr();
AmdReleaseStruct(&AmdInterfaceParams);
return status;
diff --git a/src/northbridge/amd/agesa/agesawrapper.h b/src/northbridge/amd/agesa/agesawrapper.h
index 9ec6b75fe5..eb1a59cda5 100644
--- a/src/northbridge/amd/agesa/agesawrapper.h
+++ b/src/northbridge/amd/agesa/agesawrapper.h
@@ -71,4 +71,9 @@ struct OEM_HOOK
extern const struct OEM_HOOK OemCustomize;
+/* For suspend-to-ram support. */
+AGESA_STATUS OemInitResume(AMD_RESUME_PARAMS *ResumeParams);
+AGESA_STATUS OemS3LateRestore(AMD_S3LATE_PARAMS *S3LateParams);
+AGESA_STATUS OemS3Save(AMD_S3SAVE_PARAMS *S3SaveParams);
+
#endif /* _AGESAWRAPPER_H_ */
diff --git a/src/northbridge/amd/agesa/oem_s3.c b/src/northbridge/amd/agesa/oem_s3.c
index c196be2abd..08f68e58b4 100644
--- a/src/northbridge/amd/agesa/oem_s3.c
+++ b/src/northbridge/amd/agesa/oem_s3.c
@@ -21,6 +21,15 @@
#include <spi_flash.h>
#include <string.h>
#include <cpu/amd/agesa/s3_resume.h>
+#include <northbridge/amd/agesa/BiosCallOuts.h>
+#include <northbridge/amd/agesa/agesawrapper.h>
+#include <AGESA.h>
+
+typedef enum {
+ S3DataTypeNonVolatile=0, ///< NonVolatile Data Type
+ S3DataTypeVolatile, ///< Volatile 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_VOLATILE_SIZE 0x6000
@@ -32,7 +41,7 @@
#error "Please increase the value of S3_DATA_SIZE"
#endif
-void get_s3nv_data(S3_DATA_TYPE S3DataType, u32 *pos, u32 *len)
+static void get_s3nv_data(S3_DATA_TYPE S3DataType, u32 *pos, u32 *len)
{
/* FIXME: Find file from CBFS. */
u32 s3_data = CONFIG_S3_DATA_POS;
@@ -57,7 +66,42 @@ void get_s3nv_data(S3_DATA_TYPE S3DataType, u32 *pos, u32 *len)
}
}
-int spi_SaveS3info(u32 pos, u32 size, u8 *buf, u32 len)
+#if defined(__PRE_RAM__)
+
+AGESA_STATUS OemInitResume(AMD_RESUME_PARAMS *ResumeParams)
+{
+ AMD_S3_PARAMS *dataBlock = &ResumeParams->S3DataBlock;
+ u32 pos, size;
+
+ get_s3nv_data(S3DataTypeNonVolatile, &pos, &size);
+
+ /* TODO: Our NvStorage is really const. */
+ dataBlock->NvStorageSize = *(UINT32 *) pos;
+ dataBlock->NvStorage = (void *) (pos + sizeof(UINT32));
+ return AGESA_SUCCESS;
+}
+
+AGESA_STATUS OemS3LateRestore(AMD_S3LATE_PARAMS *S3LateParams)
+{
+ AMD_S3_PARAMS *dataBlock = &S3LateParams->S3DataBlock;
+ AMD_CONFIG_PARAMS StdHeader;
+ u32 pos, size;
+
+ get_s3nv_data(S3DataTypeVolatile, &pos, &size);
+
+ u32 len = *(UINT32 *) pos;
+ void *src = (void *) (pos + sizeof(UINT32));
+ void *dst = (void *) GetHeapBase(&StdHeader);
+
+ memcpy(dst, src, len);
+ dataBlock->VolatileStorageSize = len;
+ dataBlock->VolatileStorage = dst;
+ return AGESA_SUCCESS;
+}
+
+#else
+
+static int spi_SaveS3info(u32 pos, u32 size, u8 *buf, u32 len)
{
#if IS_ENABLED(CONFIG_SPI_FLASH)
struct spi_flash *flash;
@@ -81,3 +125,45 @@ int spi_SaveS3info(u32 pos, u32 size, u8 *buf, u32 len)
return -1;
#endif
}
+
+AGESA_STATUS OemS3Save(AMD_S3SAVE_PARAMS *S3SaveParams)
+{
+ AMD_S3_PARAMS *dataBlock = &S3SaveParams->S3DataBlock;
+ u8 MTRRStorage[S3_DATA_MTRR_SIZE];
+ u32 MTRRStorageSize = 0;
+ u32 pos, size;
+
+ /* To be consumed in AmdInitResume. */
+ get_s3nv_data(S3DataTypeNonVolatile, &pos, &size);
+ if (size && dataBlock->NvStorageSize)
+ spi_SaveS3info(pos, size, dataBlock->NvStorage,
+ dataBlock->NvStorageSize);
+
+ /* To be consumed in AmdS3LateRestore. */
+ get_s3nv_data(S3DataTypeVolatile, &pos, &size);
+ if (size && dataBlock->VolatileStorageSize)
+ spi_SaveS3info(pos, size, dataBlock->VolatileStorage,
+ dataBlock->VolatileStorageSize);
+
+ /* 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);
+
+ return AGESA_SUCCESS;
+}
+
+const void *OemS3Saved_MTRR_Storage(void)
+{
+ u32 pos, size;
+ get_s3nv_data(S3DataTypeMTRR, &pos, &size);
+ if (!size)
+ return NULL;
+
+ return (void*)(pos + sizeof(UINT32));
+}
+
+#endif