Kyösti Mälkki (kyosti.malkki@gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14418
-gerrit
commit fb03f923138efb65b5aea256b1f6871433479546 Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Tue Apr 19 15:51:24 2016 +0300
AGESA: Rewrite agesawrapper [NOTFORMERGE]
Change-Id: Ic111291a2c0f1f171d2330c9ddaf6061a648bc86 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- src/northbridge/amd/agesa/agesawrapper.c | 254 ++++++++++++------------------- 1 file changed, 94 insertions(+), 160 deletions(-)
diff --git a/src/northbridge/amd/agesa/agesawrapper.c b/src/northbridge/amd/agesa/agesawrapper.c index a72e239..19b7e33 100644 --- a/src/northbridge/amd/agesa/agesawrapper.c +++ b/src/northbridge/amd/agesa/agesawrapper.c @@ -25,60 +25,74 @@
static const struct OEM_HOOK *OemHook = &OemCustomize;
+ +static void prepare_AmdParams(AMD_INTERFACE_PARAMS *p, int f) +{ + memset(p, 0, sizeof(AMD_INTERFACE_PARAMS)); + p->StdHeader.CalloutPtr = GetBiosCallout; + p->AgesaFunctionName = f; + + p->AllocationMethod = 0; /* Only byHost makes difference. */ +} + +static void * empty_AmdParams(AMD_INTERFACE_PARAMS *p, int f) +{ + prepare_AmdParams(p, f); + + AmdCreateStruct(p); + return (void *) p->NewStructPtr; +} + +static void free_AmdParams(AMD_INTERFACE_PARAMS *p) +{ + AmdReleaseStruct(p); +} + #if defined(__PRE_RAM__)
+static void * local_AmdParams(AMD_INTERFACE_PARAMS *p, int f, void *buf, size_t len) +{ + prepare_AmdParams(p, f); + + memset(buf, 0, len); + p->NewStructPtr = buf; + p->NewStructSize = len; + p->AllocationMethod = ByHost; + + AmdCreateStruct(p); + return (void *) p->NewStructPtr; +} + AGESA_STATUS agesawrapper_amdinitreset(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; - AMD_RESET_PARAMS AmdResetParams; - - memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); - memset(&AmdResetParams, 0, sizeof(AMD_RESET_PARAMS)); - - AmdParamStruct.AgesaFunctionName = AMD_INIT_RESET; - AmdParamStruct.AllocationMethod = ByHost; - AmdParamStruct.NewStructSize = sizeof(AMD_RESET_PARAMS); - AmdParamStruct.NewStructPtr = &AmdResetParams; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - - AmdCreateStruct(&AmdParamStruct); - AmdResetParams.HtConfig.Depth = 0; - - status = AmdInitReset((AMD_RESET_PARAMS *) AmdParamStruct.NewStructPtr); - AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader); - AmdReleaseStruct(&AmdParamStruct); + AMD_INTERFACE_PARAMS aip; + AMD_RESET_PARAMS tmp; + + AMD_RESET_PARAMS *AmdResetParams = local_AmdParams(&aip, + AMD_INIT_RESET, &tmp, sizeof(tmp)); + + AmdResetParams->HtConfig.Depth = 0; + + status = AmdInitReset(AmdResetParams); + AGESA_EVENTLOG(status, &aip.StdHeader); return status; }
AGESA_STATUS agesawrapper_amdinitearly(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; - AMD_EARLY_PARAMS *AmdEarlyParamsPtr; - - memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); - - AmdParamStruct.AgesaFunctionName = AMD_INIT_EARLY; - AmdParamStruct.AllocationMethod = PreMemHeap; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - AmdCreateStruct(&AmdParamStruct); + AMD_INTERFACE_PARAMS aip;
/* OEM Should Customize the defaults through this hook. */ - AmdEarlyParamsPtr = (AMD_EARLY_PARAMS *) AmdParamStruct.NewStructPtr; + AMD_EARLY_PARAMS *AmdEarlyParams = empty_AmdParams(&aip, AMD_INIT_EARLY); if (OemHook->InitEarly) - OemHook->InitEarly(AmdEarlyParamsPtr); + OemHook->InitEarly(AmdEarlyParams);
- status = AmdInitEarly(AmdEarlyParamsPtr); - AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader); + status = AmdInitEarly(AmdEarlyParams); + AGESA_EVENTLOG(status, &aip.StdHeader);
- AmdReleaseStruct(&AmdParamStruct); + free_AmdParams(&aip);
return status; } @@ -86,29 +100,17 @@ AGESA_STATUS agesawrapper_amdinitearly(void) AGESA_STATUS agesawrapper_amdinitpost(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; - AMD_POST_PARAMS *PostParams; - - memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); - - AmdParamStruct.AgesaFunctionName = AMD_INIT_POST; - AmdParamStruct.AllocationMethod = PreMemHeap; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - - AmdCreateStruct(&AmdParamStruct); + AMD_INTERFACE_PARAMS aip;
/* OEM Should Customize the defaults through this hook. */ - PostParams = (AMD_POST_PARAMS *) AmdParamStruct.NewStructPtr; + AMD_POST_PARAMS *PostParams = empty_AmdParams(&aip, AMD_INIT_POST); if (OemHook->InitPost) OemHook->InitPost(PostParams);
status = AmdInitPost(PostParams); AGESA_EVENTLOG(status, &PostParams->StdHeader);
- AmdReleaseStruct(&AmdParamStruct); + free_AmdParams(&aip);
/* Initialize heap space */ EmptyHeap(); @@ -119,29 +121,18 @@ AGESA_STATUS agesawrapper_amdinitpost(void) AGESA_STATUS agesawrapper_amdinitresume(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; - AMD_RESUME_PARAMS *AmdResumeParamsPtr; - - memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); - - AmdParamStruct.AgesaFunctionName = AMD_INIT_RESUME; - AmdParamStruct.AllocationMethod = PreMemHeap; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - AmdCreateStruct(&AmdParamStruct); + AMD_INTERFACE_PARAMS aip;
- AmdResumeParamsPtr = (AMD_RESUME_PARAMS *) AmdParamStruct.NewStructPtr; + AMD_RESUME_PARAMS *AmdResumeParams = empty_AmdParams(&aip, AMD_INIT_RESUME);
- AmdResumeParamsPtr->S3DataBlock.NvStorageSize = 0; - AmdResumeParamsPtr->S3DataBlock.VolatileStorageSize = 0; - OemInitResume(AmdResumeParamsPtr); + AmdResumeParams->S3DataBlock.NvStorageSize = 0; + AmdResumeParams->S3DataBlock.VolatileStorageSize = 0; + OemInitResume(AmdResumeParams);
- status = AmdInitResume(AmdResumeParamsPtr); + status = AmdInitResume(AmdResumeParams); + AGESA_EVENTLOG(status, &aip.StdHeader);
- AGESA_EVENTLOG(status, &AmdParamStruct.StdHeader); - AmdReleaseStruct(&AmdParamStruct); + free_AmdParams(&aip);
return status; } @@ -149,55 +140,34 @@ AGESA_STATUS agesawrapper_amdinitresume(void) AGESA_STATUS agesawrapper_amdinitenv(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; - AMD_ENV_PARAMS *EnvParam; + AMD_INTERFACE_PARAMS aip;
- memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); - - AmdParamStruct.AgesaFunctionName = AMD_INIT_ENV; - AmdParamStruct.AllocationMethod = PostMemDram; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - AmdCreateStruct(&AmdParamStruct); - EnvParam = (AMD_ENV_PARAMS *) AmdParamStruct.NewStructPtr; + AMD_ENV_PARAMS *EnvParam = empty_AmdParams(&aip, AMD_INIT_ENV);
status = AmdInitEnv(EnvParam); AGESA_EVENTLOG(status, &EnvParam->StdHeader);
- AmdReleaseStruct(&AmdParamStruct); + free_AmdParams(&aip); return status; }
AGESA_STATUS agesawrapper_amds3laterestore(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdInterfaceParams; - AMD_S3LATE_PARAMS AmdS3LateParams; - AMD_S3LATE_PARAMS *AmdS3LateParamsPtr; - - memset(&AmdS3LateParams, 0, sizeof(AMD_S3LATE_PARAMS)); - - AmdInterfaceParams.StdHeader.ImageBasePtr = 0; - AmdInterfaceParams.AllocationMethod = ByHost; - AmdInterfaceParams.AgesaFunctionName = AMD_S3LATE_RESTORE; - AmdInterfaceParams.NewStructPtr = &AmdS3LateParams; - AmdInterfaceParams.StdHeader.CalloutPtr = &GetBiosCallout; - AmdS3LateParamsPtr = &AmdS3LateParams; - AmdInterfaceParams.NewStructSize = sizeof(AMD_S3LATE_PARAMS); + AMD_INTERFACE_PARAMS aip; + AMD_S3LATE_PARAMS tmp;
- AmdCreateStruct(&AmdInterfaceParams); + AMD_S3LATE_PARAMS *AmdS3LateParams = local_AmdParams(&aip, + AMD_S3LATE_RESTORE, &tmp, sizeof(tmp));
-#if 0 - /* TODO: What to do with NvStorage here? */ - AmdS3LateParamsPtr->S3DataBlock.NvStorageSize = 0; +#if 0 /* TODO: What to do with NvStorage here? */ + AmdS3LateParams->S3DataBlock.NvStorageSize = 0; #endif - AmdS3LateParamsPtr->S3DataBlock.VolatileStorageSize = 0; - OemS3LateRestore(AmdS3LateParamsPtr); + AmdS3LateParams->S3DataBlock.VolatileStorageSize = 0; + OemS3LateRestore(AmdS3LateParams);
- status = AmdS3LateRestore(AmdS3LateParamsPtr); - AGESA_EVENTLOG(status, &AmdInterfaceParams.StdHeader); + status = AmdS3LateRestore(AmdS3LateParams); + AGESA_EVENTLOG(status, &aip.StdHeader); ASSERT(status == AGESA_SUCCESS);
return status; @@ -208,28 +178,20 @@ AGESA_STATUS agesawrapper_amds3laterestore(void) AGESA_STATUS agesawrapper_amdinitmid(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; - AMD_MID_PARAMS *MidParam; - - memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); - - AmdParamStruct.AgesaFunctionName = AMD_INIT_MID; - AmdParamStruct.AllocationMethod = PostMemDram; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - - AmdCreateStruct(&AmdParamStruct); + AMD_INTERFACE_PARAMS aip;
/* OEM Should Customize the defaults through this hook. */ - MidParam = (AMD_MID_PARAMS *) AmdParamStruct.NewStructPtr; + AMD_MID_PARAMS *MidParam = empty_AmdParams(&aip, AMD_INIT_MID); if (OemHook->InitMid) OemHook->InitMid(MidParam);
status = AmdInitMid(MidParam); AGESA_EVENTLOG(status, &MidParam->StdHeader); - AmdReleaseStruct(&AmdParamStruct); +#if 0 /* TODO: Why not? */ + ASSERT(status == AGESA_SUCCESS); +#endif + + free_AmdParams(&aip);
return status; } @@ -237,30 +199,19 @@ AGESA_STATUS agesawrapper_amdinitmid(void) AGESA_STATUS agesawrapper_amdS3Save(void) { AGESA_STATUS status; - AMD_S3SAVE_PARAMS *AmdS3SaveParamsPtr; - AMD_INTERFACE_PARAMS AmdInterfaceParams; - - memset(&AmdInterfaceParams, 0, sizeof(AMD_INTERFACE_PARAMS)); + AMD_INTERFACE_PARAMS aip;
- AmdInterfaceParams.StdHeader.ImageBasePtr = 0; - AmdInterfaceParams.StdHeader.HeapStatus = HEAP_SYSTEM_MEM; - AmdInterfaceParams.StdHeader.CalloutPtr = &GetBiosCallout; - AmdInterfaceParams.AllocationMethod = PostMemDram; - AmdInterfaceParams.AgesaFunctionName = AMD_S3_SAVE; - AmdInterfaceParams.StdHeader.AltImageBasePtr = 0; - AmdInterfaceParams.StdHeader.Func = 0; - AmdCreateStruct(&AmdInterfaceParams); + AMD_S3SAVE_PARAMS *AmdS3SaveParams = empty_AmdParams(&aip, AMD_S3_SAVE);
- AmdS3SaveParamsPtr = (AMD_S3SAVE_PARAMS *) AmdInterfaceParams.NewStructPtr; - AmdS3SaveParamsPtr->StdHeader = AmdInterfaceParams.StdHeader; + AmdS3SaveParams->StdHeader = aip.StdHeader;
- status = AmdS3Save(AmdS3SaveParamsPtr); - AGESA_EVENTLOG(status, &AmdInterfaceParams.StdHeader); + status = AmdS3Save(AmdS3SaveParams); + AGESA_EVENTLOG(status, &aip.StdHeader); ASSERT(status == AGESA_SUCCESS);
- OemS3Save(AmdS3SaveParamsPtr); + OemS3Save(AmdS3SaveParams);
- AmdReleaseStruct(&AmdInterfaceParams); + free_AmdParams(&aip);
return status; } @@ -271,29 +222,15 @@ static AMD_LATE_PARAMS *AmdLateParams = NULL; AGESA_STATUS agesawrapper_amdinitlate(void) { AGESA_STATUS status; - AMD_INTERFACE_PARAMS AmdParamStruct; + AMD_INTERFACE_PARAMS aip;
- memset(&AmdParamStruct, 0, sizeof(AMD_INTERFACE_PARAMS)); + AmdLateParams = empty_AmdParams(&aip, AMD_INIT_LATE);
- AmdParamStruct.AgesaFunctionName = AMD_INIT_LATE; - AmdParamStruct.AllocationMethod = PostMemDram; - AmdParamStruct.StdHeader.AltImageBasePtr = 0; - AmdParamStruct.StdHeader.CalloutPtr = &GetBiosCallout; - AmdParamStruct.StdHeader.Func = 0; - AmdParamStruct.StdHeader.ImageBasePtr = 0; - -#if IS_ENABLED(CONFIG_CPU_AMD_AGESA_FAMILY15_TN) || IS_ENABLED(CONFIG_CPU_AMD_AGESA_FAMILY15_RL) || \ - IS_ENABLED(CONFIG_CPU_AMD_AGESA_FAMILY16_KB) - AmdParamStruct.StdHeader.HeapStatus = HEAP_SYSTEM_MEM; -#endif - - AmdCreateStruct(&AmdParamStruct); - AmdLateParams = (AMD_LATE_PARAMS *) AmdParamStruct.NewStructPtr; status = AmdInitLate(AmdLateParams); AGESA_EVENTLOG(status, &AmdLateParams->StdHeader); ASSERT(status == AGESA_SUCCESS);
- /* No AmdReleaseStruct(&AmdParamStruct), we need AmdLateParams later. */ + /* No free_AmdParams(&aip), we need AmdLateParams later. */ return status; }
@@ -336,11 +273,8 @@ AGESA_STATUS agesawrapper_amdlaterunaptask(UINT32 Func, UINT32 Data, VOID * Conf AP_EXE_PARAMS ApExeParams;
memset(&ApExeParams, 0, sizeof(AP_EXE_PARAMS)); - - ApExeParams.StdHeader.AltImageBasePtr = 0; ApExeParams.StdHeader.CalloutPtr = &GetBiosCallout; - ApExeParams.StdHeader.Func = 0; - ApExeParams.StdHeader.ImageBasePtr = 0; + ApExeParams.FunctionNumber = Func; ApExeParams.RelatedDataBlock = ConfigPtr;