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>
This commit is contained in:
Kyösti Mälkki 2018-06-28 16:58:52 +03:00 committed by Patrick Georgi
parent 03180212b7
commit 7f8a57e96a
2 changed files with 70 additions and 100 deletions

View File

@ -65,41 +65,60 @@ AGESA_STATUS amd_late_run_ap_task(AP_EXE_PARAMS *ApExeParams)
return module_dispatch(AMD_LATE_RUN_AP_TASK, StdHeader); 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; AMD_CONFIG_PARAMS *StdHeader;
AGESA_STATUS status;
/* Should clone entire StdHeader here. */ /* Should clone entire StdHeader here. */
interface_struct->StdHeader.CalloutPtr = &GetBiosCallout; memset(aip, 0, sizeof(*aip));
aip->StdHeader.CalloutPtr = &GetBiosCallout;
AGESA_STATUS status = AmdCreateStruct(interface_struct); /* 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;
}
aip->AgesaFunctionName = func;
status = module_dispatch(AMD_CREATE_STRUCT, &aip->StdHeader);
if (status != AGESA_SUCCESS) { if (status != AGESA_SUCCESS) {
printk(BIOS_ERR, "Error: AmdCreateStruct() for 0x%x returned 0x%x. " printk(BIOS_ERR, "Error: AmdCreateStruct() for 0x%x returned 0x%x. "
"Proper system initialization may not be possible.\n", "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"); die("No AGESA structure created");
StdHeader = interface_struct->NewStructPtr; StdHeader = aip->NewStructPtr;
StdHeader->Func = interface_struct->AgesaFunctionName; StdHeader->Func = aip->AgesaFunctionName;
return StdHeader; 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) static AGESA_STATUS amd_init_reset(void)
{ {
AGESA_STATUS status; AGESA_STATUS status;
AMD_RESET_PARAMS _ResetParams; AMD_RESET_PARAMS _ResetParams;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_RESET,
.AllocationMethod = ByHost,
.NewStructSize = sizeof(AMD_RESET_PARAMS),
.NewStructPtr = &_ResetParams,
};
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); SetFchResetParams(&ResetParams->FchInterface);
@ -107,19 +126,17 @@ static AGESA_STATUS amd_init_reset(void)
status = amd_dispatch(ResetParams); status = amd_dispatch(ResetParams);
timestamp_add_now(TS_AGESA_INIT_RESET_DONE); timestamp_add_now(TS_AGESA_INIT_RESET_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return status; return status;
} }
static AGESA_STATUS amd_init_early(void) static AGESA_STATUS amd_init_early(void)
{ {
AGESA_STATUS status; AGESA_STATUS status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_EARLY,
.AllocationMethod = PreMemHeap,
};
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); soc_customize_init_early(EarlyParams);
OemCustomizeInitEarly(EarlyParams); OemCustomizeInitEarly(EarlyParams);
@ -128,7 +145,7 @@ static AGESA_STATUS amd_init_early(void)
status = amd_dispatch(EarlyParams); status = amd_dispatch(EarlyParams);
timestamp_add_now(TS_AGESA_INIT_EARLY_DONE); timestamp_add_now(TS_AGESA_INIT_EARLY_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return status; return status;
} }
@ -169,12 +186,10 @@ static void print_init_post_settings(AMD_POST_PARAMS *parms)
static AGESA_STATUS amd_init_post(void) static AGESA_STATUS amd_init_post(void)
{ {
AGESA_STATUS status; AGESA_STATUS status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_POST,
.AllocationMethod = PreMemHeap,
};
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.UmaMode = CONFIG(GFXUMA) ? UMA_AUTO : UMA_NONE;
PostParams->MemConfig.UmaSize = 0; PostParams->MemConfig.UmaSize = 0;
@ -214,7 +229,7 @@ static AGESA_STATUS amd_init_post(void)
print_init_post_settings(PostParams); print_init_post_settings(PostParams);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return status; return status;
} }
@ -222,12 +237,10 @@ static AGESA_STATUS amd_init_post(void)
static AGESA_STATUS amd_init_env(void) static AGESA_STATUS amd_init_env(void)
{ {
AGESA_STATUS status; AGESA_STATUS status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_ENV,
.AllocationMethod = PostMemDram,
};
AMD_ENV_PARAMS *EnvParams = create_struct(&AmdParamStruct); AMD_ENV_PARAMS *EnvParams = amd_create_struct(&AmdParamStruct,
AMD_INIT_ENV, NULL, 0);
SetFchEnvParams(&EnvParams->FchInterface); SetFchEnvParams(&EnvParams->FchInterface);
SetNbEnvParams(&EnvParams->GnbEnvConfiguration); SetNbEnvParams(&EnvParams->GnbEnvConfiguration);
@ -236,7 +249,7 @@ static AGESA_STATUS amd_init_env(void)
status = amd_dispatch(EnvParams); status = amd_dispatch(EnvParams);
timestamp_add_now(TS_AGESA_INIT_ENV_DONE); timestamp_add_now(TS_AGESA_INIT_ENV_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return status; return status;
} }
@ -270,15 +283,13 @@ void *agesawrapper_getlateinitptr(int pick)
static AGESA_STATUS amd_init_mid(void) static AGESA_STATUS amd_init_mid(void)
{ {
AGESA_STATUS status; AGESA_STATUS status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_MID,
.AllocationMethod = PostMemDram,
};
/* Enable MMIO on AMD CPU Address Map Controller */ /* Enable MMIO on AMD CPU Address Map Controller */
amd_initcpuio(); 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); SetFchMidParams(&MidParams->FchInterface);
SetNbMidParams(&MidParams->GnbMidConfiguration); SetNbMidParams(&MidParams->GnbMidConfiguration);
@ -287,7 +298,7 @@ static AGESA_STATUS amd_init_mid(void)
status = amd_dispatch(MidParams); status = amd_dispatch(MidParams);
timestamp_add_now(TS_AGESA_INIT_MID_DONE); timestamp_add_now(TS_AGESA_INIT_MID_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return status; return status;
} }
@ -295,16 +306,14 @@ static AGESA_STATUS amd_init_mid(void)
static AGESA_STATUS amd_init_late(void) static AGESA_STATUS amd_init_late(void)
{ {
AGESA_STATUS Status; AGESA_STATUS Status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_LATE,
.AllocationMethod = PostMemDram,
};
/* /*
* NOTE: if not call amdcreatestruct, the initializer * NOTE: if not call amdcreatestruct, the initializer
* (AmdInitLateInitializer) would not be called. * (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); const struct device *dev = pcidev_path_on_root(IOMMU_DEVFN);
if (dev && dev->enabled) { if (dev && dev->enabled) {
@ -333,19 +342,17 @@ static AGESA_STATUS amd_init_late(void)
AcpiSlit, AcpiWheaMce, AcpiWheaCmc, AcpiSlit, AcpiWheaMce, AcpiWheaCmc,
AcpiAlib, AcpiIvrs, __func__); AcpiAlib, AcpiIvrs, __func__);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return Status; return Status;
} }
static AGESA_STATUS amd_init_rtb(void) static AGESA_STATUS amd_init_rtb(void)
{ {
AGESA_STATUS Status; AGESA_STATUS Status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_RTB,
.AllocationMethod = PostMemDram,
};
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); timestamp_add_now(TS_AGESA_INIT_RTB_START);
Status = amd_dispatch(RtbParams); Status = amd_dispatch(RtbParams);
@ -357,7 +364,7 @@ static AGESA_STATUS amd_init_rtb(void)
RtbParams->S3DataBlock.VolatileStorageSize)) RtbParams->S3DataBlock.VolatileStorageSize))
printk(BIOS_ERR, "S3 data not saved, resuming impossible\n"); printk(BIOS_ERR, "S3 data not saved, resuming impossible\n");
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return Status; return Status;
} }
@ -365,13 +372,11 @@ static AGESA_STATUS amd_init_rtb(void)
static AGESA_STATUS amd_init_resume(void) static AGESA_STATUS amd_init_resume(void)
{ {
AGESA_STATUS status; AGESA_STATUS status;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_INIT_RESUME,
.AllocationMethod = PreMemHeap,
};
size_t nv_size; 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); get_s3nv_info(&InitResumeParams->S3DataBlock.NvStorage, &nv_size);
InitResumeParams->S3DataBlock.NvStorageSize = nv_size; InitResumeParams->S3DataBlock.NvStorageSize = nv_size;
@ -380,7 +385,7 @@ static AGESA_STATUS amd_init_resume(void)
status = amd_dispatch(InitResumeParams); status = amd_dispatch(InitResumeParams);
timestamp_add_now(TS_AGESA_INIT_RESUME_DONE); timestamp_add_now(TS_AGESA_INIT_RESUME_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return status; return status;
} }
@ -389,17 +394,13 @@ static AGESA_STATUS amd_s3late_restore(void)
{ {
AGESA_STATUS Status; AGESA_STATUS Status;
AMD_S3LATE_PARAMS _S3LateParams; AMD_S3LATE_PARAMS _S3LateParams;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_S3LATE_RESTORE,
.AllocationMethod = ByHost,
.NewStructSize = sizeof(AMD_S3LATE_PARAMS),
.NewStructPtr = &_S3LateParams,
};
size_t vol_size; size_t vol_size;
amd_initcpuio(); 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); get_s3vol_info(&S3LateParams->S3DataBlock.VolatileStorage, &vol_size);
S3LateParams->S3DataBlock.VolatileStorageSize = vol_size; S3LateParams->S3DataBlock.VolatileStorageSize = vol_size;
@ -408,7 +409,7 @@ static AGESA_STATUS amd_s3late_restore(void)
Status = amd_dispatch(S3LateParams); Status = amd_dispatch(S3LateParams);
timestamp_add_now(TS_AGESA_S3_LATE_DONE); timestamp_add_now(TS_AGESA_S3_LATE_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return Status; return Status;
} }
@ -417,15 +418,11 @@ static AGESA_STATUS amd_s3final_restore(void)
{ {
AGESA_STATUS Status; AGESA_STATUS Status;
AMD_S3FINAL_PARAMS _S3FinalParams; AMD_S3FINAL_PARAMS _S3FinalParams;
AMD_INTERFACE_PARAMS AmdParamStruct = { AMD_INTERFACE_PARAMS AmdParamStruct;
.AgesaFunctionName = AMD_S3FINAL_RESTORE,
.AllocationMethod = ByHost,
.NewStructSize = sizeof(AMD_S3FINAL_PARAMS),
.NewStructPtr = &_S3FinalParams,
};
size_t vol_size; 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); get_s3vol_info(&S3FinalParams->S3DataBlock.VolatileStorage, &vol_size);
S3FinalParams->S3DataBlock.VolatileStorageSize = vol_size; S3FinalParams->S3DataBlock.VolatileStorageSize = vol_size;
@ -434,7 +431,7 @@ static AGESA_STATUS amd_s3final_restore(void)
Status = amd_dispatch(S3FinalParams); Status = amd_dispatch(S3FinalParams);
timestamp_add_now(TS_AGESA_S3_FINAL_DONE); timestamp_add_now(TS_AGESA_S3_FINAL_DONE);
AmdReleaseStruct(&AmdParamStruct); amd_release_struct(&AmdParamStruct);
return Status; return Status;
} }

View File

@ -45,30 +45,3 @@ CONST UINT32 ImageSignature = IMAGE_SIGNATURE;
CONST UINT32 ModuleSignature = MODULE_SIGNATURE; CONST UINT32 ModuleSignature = MODULE_SIGNATURE;
CONST CHAR8 ModuleIdentifier[8] = AGESA_ID; CONST CHAR8 ModuleIdentifier[8] = AGESA_ID;
/**********************************************************************
* Interface call: AmdCreateStruct
**********************************************************************/
AGESA_STATUS
AmdCreateStruct (
IN OUT AMD_INTERFACE_PARAMS *InterfaceParams
)
{
MODULE_ENTRY Dispatcher = agesa_get_dispatcher();
InterfaceParams->StdHeader.Func = AMD_CREATE_STRUCT;
if (!Dispatcher) return AGESA_UNSUPPORTED;
return Dispatcher(InterfaceParams);
}
/**********************************************************************
* Interface call: AmdReleaseStruct
**********************************************************************/
AGESA_STATUS
AmdReleaseStruct (
IN OUT AMD_INTERFACE_PARAMS *InterfaceParams
)
{
MODULE_ENTRY Dispatcher = agesa_get_dispatcher();
InterfaceParams->StdHeader.Func = AMD_RELEASE_STRUCT;
if (!Dispatcher) return AGESA_UNSUPPORTED;
return Dispatcher(InterfaceParams);
}