summaryrefslogtreecommitdiff
path: root/src/soc/amd/common
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2018-06-28 16:58:52 +0300
committerPatrick Georgi <pgeorgi@google.com>2019-05-21 09:26:21 +0000
commit7f8a57e96ae8a0ad41bc6024c9fa5a0c14282f15 (patch)
treec058796d8a125a9e3d8420a977c48fbc6c6d4441 /src/soc/amd/common
parent03180212b7295d288bd79c5756d9355c55bd2193 (diff)
downloadcoreboot-7f8a57e96ae8a0ad41bc6024c9fa5a0c14282f15.tar.xz
soc/amd/common: Refactor AmdCreateStruct() use
AmdCreateStruct() and AmdReleaseStruct() are equally bad when it comes to lack of correct function declarations for definitions found in vendorcode binaryPI/AGESA.c. Replace these with calls that go through the common module_dispatch() functions. Change-Id: I611bcbe2a71fb65c8eb759a9dc74cbd9cb74136e Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/31486 Reviewed-by: Richard Spiegel <richard.spiegel@silverbackltd.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/soc/amd/common')
-rw-r--r--src/soc/amd/common/block/pi/agesawrapper.c143
1 files changed, 70 insertions, 73 deletions
diff --git a/src/soc/amd/common/block/pi/agesawrapper.c b/src/soc/amd/common/block/pi/agesawrapper.c
index 5f58346625..da6de00568 100644
--- a/src/soc/amd/common/block/pi/agesawrapper.c
+++ b/src/soc/amd/common/block/pi/agesawrapper.c
@@ -65,41 +65,60 @@ AGESA_STATUS amd_late_run_ap_task(AP_EXE_PARAMS *ApExeParams)
return module_dispatch(AMD_LATE_RUN_AP_TASK, StdHeader);
}
-static void *create_struct(AMD_INTERFACE_PARAMS *interface_struct)
+static void *amd_create_struct(AMD_INTERFACE_PARAMS *aip,
+ AGESA_STRUCT_NAME func, void *buf, size_t len)
{
AMD_CONFIG_PARAMS *StdHeader;
+ AGESA_STATUS status;
/* Should clone entire StdHeader here. */
- interface_struct->StdHeader.CalloutPtr = &GetBiosCallout;
+ memset(aip, 0, sizeof(*aip));
+ aip->StdHeader.CalloutPtr = &GetBiosCallout;
+
+ /* If we provide the buffer, API expects it to have
+ StdHeader already filled. */
+ if (buf != NULL && len >= sizeof(*StdHeader)) {
+ memcpy(buf, &aip->StdHeader, sizeof(*StdHeader));
+ aip->AllocationMethod = ByHost;
+ aip->NewStructPtr = buf;
+ aip->NewStructSize = len;
+ } else {
+ if (ENV_ROMSTAGE)
+ aip->AllocationMethod = PreMemHeap;
+ if (ENV_RAMSTAGE)
+ aip->AllocationMethod = PostMemDram;
+ }
- AGESA_STATUS status = AmdCreateStruct(interface_struct);
+ aip->AgesaFunctionName = func;
+ status = module_dispatch(AMD_CREATE_STRUCT, &aip->StdHeader);
if (status != AGESA_SUCCESS) {
printk(BIOS_ERR, "Error: AmdCreateStruct() for 0x%x returned 0x%x. "
"Proper system initialization may not be possible.\n",
- interface_struct->AgesaFunctionName, status);
+ aip->AgesaFunctionName, status);
}
- if (!interface_struct->NewStructPtr) /* Avoid NULL pointer usage */
+ if (!aip->NewStructPtr)
die("No AGESA structure created");
- StdHeader = interface_struct->NewStructPtr;
- StdHeader->Func = interface_struct->AgesaFunctionName;
+ StdHeader = aip->NewStructPtr;
+ StdHeader->Func = aip->AgesaFunctionName;
return StdHeader;
}
+static AGESA_STATUS amd_release_struct(AMD_INTERFACE_PARAMS *aip)
+{
+ return module_dispatch(AMD_RELEASE_STRUCT, &aip->StdHeader);
+}
+
static AGESA_STATUS amd_init_reset(void)
{
AGESA_STATUS status;
AMD_RESET_PARAMS _ResetParams;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_RESET,
- .AllocationMethod = ByHost,
- .NewStructSize = sizeof(AMD_RESET_PARAMS),
- .NewStructPtr = &_ResetParams,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
- AMD_RESET_PARAMS *ResetParams = create_struct(&AmdParamStruct);
+ AMD_RESET_PARAMS *ResetParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_RESET, &_ResetParams, sizeof(AMD_RESET_PARAMS));
SetFchResetParams(&ResetParams->FchInterface);
@@ -107,19 +126,17 @@ static AGESA_STATUS amd_init_reset(void)
status = amd_dispatch(ResetParams);
timestamp_add_now(TS_AGESA_INIT_RESET_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return status;
}
static AGESA_STATUS amd_init_early(void)
{
AGESA_STATUS status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_EARLY,
- .AllocationMethod = PreMemHeap,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
- AMD_EARLY_PARAMS *EarlyParams = create_struct(&AmdParamStruct);
+ AMD_EARLY_PARAMS *EarlyParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_EARLY, NULL, 0);
soc_customize_init_early(EarlyParams);
OemCustomizeInitEarly(EarlyParams);
@@ -128,7 +145,7 @@ static AGESA_STATUS amd_init_early(void)
status = amd_dispatch(EarlyParams);
timestamp_add_now(TS_AGESA_INIT_EARLY_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return status;
}
@@ -169,12 +186,10 @@ static void print_init_post_settings(AMD_POST_PARAMS *parms)
static AGESA_STATUS amd_init_post(void)
{
AGESA_STATUS status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_POST,
- .AllocationMethod = PreMemHeap,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
- AMD_POST_PARAMS *PostParams = create_struct(&AmdParamStruct);
+ AMD_POST_PARAMS *PostParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_POST, NULL, 0);
PostParams->MemConfig.UmaMode = CONFIG(GFXUMA) ? UMA_AUTO : UMA_NONE;
PostParams->MemConfig.UmaSize = 0;
@@ -214,7 +229,7 @@ static AGESA_STATUS amd_init_post(void)
print_init_post_settings(PostParams);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return status;
}
@@ -222,12 +237,10 @@ static AGESA_STATUS amd_init_post(void)
static AGESA_STATUS amd_init_env(void)
{
AGESA_STATUS status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_ENV,
- .AllocationMethod = PostMemDram,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
- AMD_ENV_PARAMS *EnvParams = create_struct(&AmdParamStruct);
+ AMD_ENV_PARAMS *EnvParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_ENV, NULL, 0);
SetFchEnvParams(&EnvParams->FchInterface);
SetNbEnvParams(&EnvParams->GnbEnvConfiguration);
@@ -236,7 +249,7 @@ static AGESA_STATUS amd_init_env(void)
status = amd_dispatch(EnvParams);
timestamp_add_now(TS_AGESA_INIT_ENV_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return status;
}
@@ -270,15 +283,13 @@ void *agesawrapper_getlateinitptr(int pick)
static AGESA_STATUS amd_init_mid(void)
{
AGESA_STATUS status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_MID,
- .AllocationMethod = PostMemDram,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
/* Enable MMIO on AMD CPU Address Map Controller */
amd_initcpuio();
- AMD_MID_PARAMS *MidParams = create_struct(&AmdParamStruct);
+ AMD_MID_PARAMS *MidParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_MID, NULL, 0);
SetFchMidParams(&MidParams->FchInterface);
SetNbMidParams(&MidParams->GnbMidConfiguration);
@@ -287,7 +298,7 @@ static AGESA_STATUS amd_init_mid(void)
status = amd_dispatch(MidParams);
timestamp_add_now(TS_AGESA_INIT_MID_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return status;
}
@@ -295,16 +306,14 @@ static AGESA_STATUS amd_init_mid(void)
static AGESA_STATUS amd_init_late(void)
{
AGESA_STATUS Status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_LATE,
- .AllocationMethod = PostMemDram,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
/*
* NOTE: if not call amdcreatestruct, the initializer
* (AmdInitLateInitializer) would not be called.
*/
- AMD_LATE_PARAMS *LateParams = create_struct(&AmdParamStruct);
+ AMD_LATE_PARAMS *LateParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_LATE, NULL, 0);
const struct device *dev = pcidev_path_on_root(IOMMU_DEVFN);
if (dev && dev->enabled) {
@@ -333,19 +342,17 @@ static AGESA_STATUS amd_init_late(void)
AcpiSlit, AcpiWheaMce, AcpiWheaCmc,
AcpiAlib, AcpiIvrs, __func__);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return Status;
}
static AGESA_STATUS amd_init_rtb(void)
{
AGESA_STATUS Status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_RTB,
- .AllocationMethod = PostMemDram,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
- AMD_RTB_PARAMS *RtbParams = create_struct(&AmdParamStruct);
+ AMD_RTB_PARAMS *RtbParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_RTB, NULL, 0);
timestamp_add_now(TS_AGESA_INIT_RTB_START);
Status = amd_dispatch(RtbParams);
@@ -357,7 +364,7 @@ static AGESA_STATUS amd_init_rtb(void)
RtbParams->S3DataBlock.VolatileStorageSize))
printk(BIOS_ERR, "S3 data not saved, resuming impossible\n");
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return Status;
}
@@ -365,13 +372,11 @@ static AGESA_STATUS amd_init_rtb(void)
static AGESA_STATUS amd_init_resume(void)
{
AGESA_STATUS status;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_INIT_RESUME,
- .AllocationMethod = PreMemHeap,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
size_t nv_size;
- AMD_RESUME_PARAMS *InitResumeParams = create_struct(&AmdParamStruct);
+ AMD_RESUME_PARAMS *InitResumeParams = amd_create_struct(&AmdParamStruct,
+ AMD_INIT_RESUME, NULL, 0);
get_s3nv_info(&InitResumeParams->S3DataBlock.NvStorage, &nv_size);
InitResumeParams->S3DataBlock.NvStorageSize = nv_size;
@@ -380,7 +385,7 @@ static AGESA_STATUS amd_init_resume(void)
status = amd_dispatch(InitResumeParams);
timestamp_add_now(TS_AGESA_INIT_RESUME_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return status;
}
@@ -389,17 +394,13 @@ static AGESA_STATUS amd_s3late_restore(void)
{
AGESA_STATUS Status;
AMD_S3LATE_PARAMS _S3LateParams;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_S3LATE_RESTORE,
- .AllocationMethod = ByHost,
- .NewStructSize = sizeof(AMD_S3LATE_PARAMS),
- .NewStructPtr = &_S3LateParams,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
size_t vol_size;
amd_initcpuio();
- AMD_S3LATE_PARAMS *S3LateParams = create_struct(&AmdParamStruct);
+ AMD_S3LATE_PARAMS *S3LateParams = amd_create_struct(&AmdParamStruct,
+ AMD_S3LATE_RESTORE, &_S3LateParams, sizeof(AMD_S3LATE_PARAMS));
get_s3vol_info(&S3LateParams->S3DataBlock.VolatileStorage, &vol_size);
S3LateParams->S3DataBlock.VolatileStorageSize = vol_size;
@@ -408,7 +409,7 @@ static AGESA_STATUS amd_s3late_restore(void)
Status = amd_dispatch(S3LateParams);
timestamp_add_now(TS_AGESA_S3_LATE_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return Status;
}
@@ -417,15 +418,11 @@ static AGESA_STATUS amd_s3final_restore(void)
{
AGESA_STATUS Status;
AMD_S3FINAL_PARAMS _S3FinalParams;
- AMD_INTERFACE_PARAMS AmdParamStruct = {
- .AgesaFunctionName = AMD_S3FINAL_RESTORE,
- .AllocationMethod = ByHost,
- .NewStructSize = sizeof(AMD_S3FINAL_PARAMS),
- .NewStructPtr = &_S3FinalParams,
- };
+ AMD_INTERFACE_PARAMS AmdParamStruct;
size_t vol_size;
- AMD_S3FINAL_PARAMS *S3FinalParams = create_struct(&AmdParamStruct);
+ AMD_S3FINAL_PARAMS *S3FinalParams = amd_create_struct(&AmdParamStruct,
+ AMD_S3FINAL_RESTORE, &_S3FinalParams, sizeof(AMD_S3FINAL_PARAMS));
get_s3vol_info(&S3FinalParams->S3DataBlock.VolatileStorage, &vol_size);
S3FinalParams->S3DataBlock.VolatileStorageSize = vol_size;
@@ -434,7 +431,7 @@ static AGESA_STATUS amd_s3final_restore(void)
Status = amd_dispatch(S3FinalParams);
timestamp_add_now(TS_AGESA_S3_FINAL_DONE);
- AmdReleaseStruct(&AmdParamStruct);
+ amd_release_struct(&AmdParamStruct);
return Status;
}