7 * Feature ECC initialization functions
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: (Mem/Feat/ECC)
12 * @e \$Revision: 54543 $ @e \$Date: 2011-06-08 23:19:25 -0600 (Wed, 08 Jun 2011) $
15 /*****************************************************************************
17 * Copyright (C) 2012 Advanced Micro Devices, Inc.
18 * All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
22 * * Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * * Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
28 * its contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 * ***************************************************************************
54 #include "GeneralServices.h"
58 #define FILECODE PROC_MEM_FEAT_ECC_MFECC_FILECODE
59 /*----------------------------------------------------------------------------
60 * DEFINITIONS AND MACROS
62 *----------------------------------------------------------------------------
65 /*----------------------------------------------------------------------------
66 * TYPEDEFS AND STRUCTURES
68 *----------------------------------------------------------------------------
71 /*----------------------------------------------------------------------------
72 * PROTOTYPES OF LOCAL FUNCTIONS
74 *----------------------------------------------------------------------------
79 InitECCOverriedeStruct (
80 IN OUT MEM_NB_BLOCK *NBPtr,
81 IN OUT ECC_OVERRIDE_STRUCT *pecc_override_struct
86 IN OUT MEM_NB_BLOCK *NBPtr
90 *-----------------------------------------------------------------------------
93 *-----------------------------------------------------------------------------
96 extern BUILD_OPT_CFG UserOptions;
98 /* -----------------------------------------------------------------------------*/
102 * This function checks to see if ECC can be enabled on all nodes
104 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
106 * @return TRUE - This feature is enabled.
107 * @return FALSE - This feature is not enabled.
112 IN OUT MEM_NB_BLOCK *NBPtr
116 MEM_SHARED_DATA *SharedPtr;
117 BOOLEAN ErrorRecovery;
119 ASSERT (NBPtr != NULL);
121 MCTPtr = NBPtr->MCTPtr;
122 SharedPtr = NBPtr->SharedPtr;
124 ErrorRecovery = TRUE;
125 IDS_OPTION_HOOK (IDS_MEM_ERROR_RECOVERY, &ErrorRecovery, &NBPtr->MemPtr->StdHeader);
127 if (MCTPtr->NodeMemSize != 0) {
128 if (SharedPtr->AllECC && MCTPtr->Status[SbEccDimms] && (ErrorRecovery || (MCTPtr->ErrCode < AGESA_ERROR))) {
129 // Clear all MCA reports before using scrubber
130 // to initialize ECC check bits
132 NBPtr->McaNbCtlReg = NBPtr->GetBitField (NBPtr, BFMcaNbCtlReg);
133 NBPtr->SetBitField (NBPtr, BFMcaNbCtlReg, 0);
134 NBPtr->SetBitField (NBPtr, BFSyncOnUcEccEn, 0);
135 // In unganged mode, set DctDctIntlv
136 if (!NBPtr->Ganged) {
137 NBPtr->SetBitField (NBPtr, BFDctDatIntLv, 1);
140 // Set Ecc Symbol Size
142 NBPtr->SetEccSymbolSize (NBPtr);
143 // If ECC can be enabled on this node,
144 // set the master ECCen bit (according to setup)
146 NBPtr->SetBitField (NBPtr, BFDramEccEn, 1);
147 // Do mem clear on current node
148 MemFMctMemClr_Init (NBPtr);
151 if (SharedPtr->AllECC) {
152 SharedPtr->AllECC = FALSE;
154 // ECC requested but cannot be enabled
155 MCTPtr->Status[SbEccDimms] = FALSE;
156 MCTPtr->ErrStatus[EsbDramECCDis] = TRUE;
157 PutEventLog (AGESA_WARNING, MEM_WARNING_ECC_DIS, NBPtr->Node, 0, 0, 0, &NBPtr->MemPtr->StdHeader);
158 SetMemError (AGESA_WARNING, MCTPtr);
164 /* -----------------------------------------------------------------------------*/
168 * This function initializes the ECC on all nodes
170 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
172 * @return TRUE - This feature is enabled.
173 * @return FALSE - This feature is not enabled.
178 IN OUT MEM_NB_BLOCK *NBPtr
182 UINT32 ScrubAddrRJ16;
184 MEM_SHARED_DATA *SharedPtr;
185 ECC_OVERRIDE_STRUCT ecc_override_struct;
188 InitECCOverriedeStruct (NBPtr, &ecc_override_struct);
189 IDS_OPTION_HOOK (IDS_ECC, &ecc_override_struct, &(NBPtr->MemPtr->StdHeader));
191 ASSERT (NBPtr != NULL);
193 MCTPtr = NBPtr->MCTPtr;
194 Node = MCTPtr->NodeId;
195 SharedPtr = NBPtr->SharedPtr;
198 NBPtr->FamilySpecificHook[ScrubberErratum] (NBPtr, (VOID *) &Flag);
200 if ((MCTPtr->Status[SbEccDimms]) && (SharedPtr->AllECC)) {
201 // Check if the input dram scrub rate is supported or not
202 ASSERT (ecc_override_struct.CfgScrubDramRate <= 0x16);
203 if (ecc_override_struct.CfgScrubDramRate != 0) {
204 // Program scrub address,
205 // let the scrub Addr be the Base of this Node
206 // Only enable Dram scrubber when there is memory on current node
208 NBPtr->SetBitField (NBPtr, BFScrubReDirEn, 0);
209 ScrubAddrRJ16 = (NBPtr->GetBitField (NBPtr, BFDramBaseReg0 + Node) & 0xFFFF0000) >> 8;
210 ScrubAddrRJ16 |= NBPtr->GetBitField (NBPtr, BFDramBaseHiReg0 + Node) << 24;
211 NBPtr->SetBitField (NBPtr, BFScrubAddrLoReg, ScrubAddrRJ16 << 16);
212 NBPtr->SetBitField (NBPtr, BFScrubAddrHiReg, ScrubAddrRJ16 >> 16);
213 NBPtr->SetBitField (NBPtr, BFDramScrub, ecc_override_struct.CfgScrubDramRate);
216 // Scrub CTL for Dcache, L2, L3
217 // Check if the input L2 scrub rate is supported or not
218 ASSERT (ecc_override_struct.CfgScrubL2Rate <= 0x16);
219 NBPtr->SetBitField (NBPtr, BFL2Scrub, ecc_override_struct.CfgScrubL2Rate);
220 // Check if the input Dcache scrub rate is supported or not
221 ASSERT (ecc_override_struct.CfgScrubDcRate <= 0x16);
222 NBPtr->SetBitField (NBPtr, BFDcacheScrub, ecc_override_struct.CfgScrubDcRate);
223 // Do not enable L3 Scrub if F3xE8[L3Capable] is 0 or F3x188[BFReserved00B] is 1
224 if ((NBPtr->GetBitField (NBPtr, BFL3Capable) == 1) && (NBPtr->GetBitField (NBPtr, BFReserved00B) == 0)) {
225 // Check if input L3 scrub rate is supported or not
226 ASSERT (ecc_override_struct.CfgScrubL3Rate <= 0x16);
227 NBPtr->SetBitField (NBPtr, BFL3Scrub, ecc_override_struct.CfgScrubL3Rate);
230 // Check if Dcache scrubber or L2 scrubber is enabled
231 if ((ecc_override_struct.CfgScrubL2Rate != 0) || (ecc_override_struct.CfgScrubDcRate!= 0)) {
232 // If ClkDivisor is deeper than divide-by-16
233 if (NBPtr->GetBitField (NBPtr, BFC1ClkDivisor) > 4) {
234 // Set it to divide-by-16
235 NBPtr->SetBitField (NBPtr, BFC1ClkDivisor, 4);
239 NBPtr->SetBitField (NBPtr, BFScrubReDirEn, ecc_override_struct.CfgEccRedirection);
240 NBPtr->SetBitField (NBPtr, BFSyncOnUcEccEn, ecc_override_struct.CfgEccSyncFlood);
241 // Restore MCA reports after scrubber is done
242 // with initializing ECC check bits
243 NBPtr->SetBitField (NBPtr, BFMcaNbCtlReg, NBPtr->McaNbCtlReg);
246 NBPtr->FamilySpecificHook[ScrubberErratum] (NBPtr, (VOID *) &Flag);
253 InitECCOverriedeStruct (
254 IN OUT MEM_NB_BLOCK *NBPtr,
255 IN OUT ECC_OVERRIDE_STRUCT *pecc_override_struct
259 // If (D18F3x44[DramEccEn]==1) THEN 1 ELSE 0 ENDIF
261 if (NBPtr->GetBitField (NBPtr, BFDramEccEn) == 1) {
262 pecc_override_struct->CfgEccRedirection = 1;
264 pecc_override_struct->CfgEccRedirection = 0;
267 pecc_override_struct->CfgEccSyncFlood = UserOptions.CfgEccSyncFlood;
268 pecc_override_struct->CfgScrubDcRate = UserOptions.CfgScrubDcRate;
270 if (UserOptions.CfgScrubDramRate != 0xFF) {
271 pecc_override_struct->CfgScrubDramRate = UserOptions.CfgScrubDramRate;
273 if (NBPtr->MCTPtr->NodeMemSize <= 0x4000) {
274 pecc_override_struct->CfgScrubDramRate = 0x12; // 1 ~ 1 GB
275 } else if (NBPtr->MCTPtr->NodeMemSize <= 0x8000) {
276 pecc_override_struct->CfgScrubDramRate = 0x11; // 1 GB + 1 ~ 2 GB
277 } else if (NBPtr->MCTPtr->NodeMemSize <= 0x10000) {
278 pecc_override_struct->CfgScrubDramRate = 0x10; // 2 GB + 1 ~ 4 GB
279 } else if (NBPtr->MCTPtr->NodeMemSize <= 0x20000) {
280 pecc_override_struct->CfgScrubDramRate = 0x0F; // 4 GB + 1 ~ 8 GB
281 } else if (NBPtr->MCTPtr->NodeMemSize <= 0x40000) {
282 pecc_override_struct->CfgScrubDramRate = 0x0E; // 8 GB + 1 ~ 16 GB
284 pecc_override_struct->CfgScrubDramRate = 0x0D; //16 GB + 1 above
288 pecc_override_struct->CfgScrubL2Rate = UserOptions.CfgScrubL2Rate;
289 pecc_override_struct->CfgScrubL3Rate = UserOptions.CfgScrubL3Rate;