Stefan Reinauer (stefan.reinauer@coreboot.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14618
-gerrit
commit 517511d511252c6c307509fdea22ebcbc922b79c Author: Stefan Reinauer stefan.reinauer@coreboot.org Date: Wed May 4 17:04:37 2016 -0700
amd/amdmct: Rewrite mct_ResetDataStruct_D()
The function was doing some nasty pointer arithmetics to erase a whole struct except three fields in that struct (and the two others that are manually preserved)
Clean up the code by using offsetof() and memset() to achieve the same thing.
Change-Id: I99c430aa6d3309e39ac0837717cd448b1a5eb0ab Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org --- src/northbridge/amd/amdmct/mct/mct_d.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/src/northbridge/amd/amdmct/mct/mct_d.c b/src/northbridge/amd/amdmct/mct/mct_d.c index 0e59e1d..2e5033f 100644 --- a/src/northbridge/amd/amdmct/mct/mct_d.c +++ b/src/northbridge/amd/amdmct/mct/mct_d.c @@ -3609,35 +3609,21 @@ static void mct_ResetDataStruct_D(struct MCTStatStruc *pMCTstat, struct DCTStatStruc *pDCTstatA) { u8 Node; - u32 i; - struct DCTStatStruc *pDCTstat; - u32 start, stop; - u8 *p; - u16 host_serv1, host_serv2;
/* Initialize Data structures by clearing all entries to 0 */ - p = (u8 *) pMCTstat; - for (i = 0; i < sizeof(struct MCTStatStruc); i++) { - p[i] = 0; - } + memset(pMCTstat, 0, sizeof(struct MCTStatStruc));
for (Node = 0; Node < 8; Node++) { + struct DCTStatStruc *pDCTstat; + u16 host_serv1, host_serv2; pDCTstat = pDCTstatA + Node; host_serv1 = pDCTstat->HostBiosSrvc1; host_serv2 = pDCTstat->HostBiosSrvc2;
- p = (u8 *) pDCTstat; - start = 0; - stop = (u32)(&((struct DCTStatStruc *)0)->CH_MaxRdLat[2]); - for (i = start; i < stop ; i++) { - p[i] = 0; - } + /* Do not erase CH_D_DIR_B_DQS, CH_D_B_RCVRDLY, CH_D_BC_RCVRDLY */ + memset((void *)pDCTstat, 0, offsetof(struct DCTStatStruc, CH_D_DIR_B_DQS)); + memset((void *)pDCTstat + offsetof(struct DCTStatStruc, DIMMValidDCT), 0, sizeof(struct DCTStatStruc) - offsetof(struct DCTStatStruc, DIMMValidDCT));
- start = (u32)(&((struct DCTStatStruc *)0)->CH_D_BC_RCVRDLY[2][4]); - stop = sizeof(struct DCTStatStruc); - for (i = start; i < stop; i++) { - p[i] = 0; - } pDCTstat->HostBiosSrvc1 = host_serv1; pDCTstat->HostBiosSrvc2 = host_serv2; }