7 * Memory Controller, registered dimms
9 * @xrefitem bom "File Content Label" "Release Content"
11 * @e sub-project: (Mem/Ardk)
12 * @e \$Revision: 52286 $ @e \$Date: 2011-05-04 03:48:21 -0600 (Wed, 04 May 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 * ***************************************************************************
46 /* This file contains routine that add platform specific support AM3 */
51 #include "OptionMemory.h"
52 #include "PlatformMemoryConfiguration.h"
55 #include "cpuFamRegisters.h"
60 #define FILECODE PROC_MEM_ARDK_DR_MARDR3_FILECODE
61 /*----------------------------------------------------------------------------
62 * DEFINITIONS AND MACROS
64 *----------------------------------------------------------------------------
67 /*----------------------------------------------------------------------------
68 * TYPEDEFS AND STRUCTURES
70 *----------------------------------------------------------------------------
73 /*----------------------------------------------------------------------------
74 * PROTOTYPES OF LOCAL FUNCTIONS
76 *----------------------------------------------------------------------------
80 *-----------------------------------------------------------------------------
83 *-----------------------------------------------------------------------------
86 STATIC CONST UINT8 ROMDATA DrRDdr3CLKDis[] = {0x00, 0x00, 0xC0, 0x30, 0x0C, 0x03, 0x00, 0x00};
88 // Even chip select maps to M[B,A]_CKE[0]
89 // Odd chip select maps to M[B,A]_CKE[1]
90 STATIC CONST UINT8 ROMDATA DrRDdr3CKETri[] = {0x55, 0xAA};
92 // 2 dimms per channel
93 // Dimm 0: BP_MEMODTx[2,0]
94 // Dimm 1: BP_MEMODTx[3,1]
95 STATIC CONST UINT8 ROMDATA DrRDdr3ODTTri2D[] = {0x03, 0x0C, 0x32, 0xC8};
96 // 3 dimms per channel
97 // Dimm 0: BP_MEMODTx[0]
98 // Dimm 1: BP_MEMODTx[3,1]
99 // Dimm 2: BP_MEMODTx[2]
100 STATIC CONST UINT8 ROMDATA DrRDdr3ODTTri3D[] = {0x03, 0x0C, 0x30, 0xC8};
101 // 4 dimms per channel
102 // Dimm 0: BP_MEMODTx[0]
103 // Dimm 1: BP_MEMODTx[1]
104 // Dimm 2: BP_MEMODTx[2]
105 // Dimm 3: BP_MEMODTx[3]
106 STATIC CONST UINT8 ROMDATA DrRDdr3ODTTri4D[] = {0x03, 0x0C, 0x30, 0xC0};
108 // BIOS must not tri-state chip select pin corresponding to the second chip
109 // select of a single rank registered dimm
110 STATIC CONST UINT8 ROMDATA DrRDdr3CSTri[] = {0x01, 0x03, 0x04, 0x0C, 0x10, 0x30, 0x40, 0xC0};
112 /* -----------------------------------------------------------------------------*/
115 * This is function sets the platform specific settings for DR DDR3 L1 system
117 * @param[in,out] *MemData Pointer to MEM_DATA_STRUCTURE
118 * @param[in] SocketID Socket number
119 * @param[in,out] *CurrentChannel Pointer to CH_DEF_STRUCT
121 * @return AGESA_SUCCESS
122 * @return CurrentChannel->MemClkDisMap Points this pointer to RB MemClkDis table
123 * @return CurrentChannel->ChipSelTriMap Points this pointer to RB CS table
124 * @return CurrentChannel->CKETriMap Points this pointer to RB ODT table
125 * @return CurrentChannel->ODTTriMap Points this pointer to RB CKE table
126 * @return CurrentChannel->DctEccDQSLike Indicates the bytes that should be averaged for ECC
127 * @return CurrentChannel->DctEccDQSScale Indicates the scale that should be used for Averaging ECC byte
128 * @return CurrentChannel->DctAddrTmg Address Command Timing Settings for specified channel
129 * @return CurrentChannel->DctOdcCtl Drive Strength settings for specified channel
130 * @return CurrentChannel->SlowMode Slow Mode
137 IN OUT MEM_DATA_STRUCT *MemData,
139 IN OUT CH_DEF_STRUCT *CurrentChannel
142 STATIC CONST ADV_R_PSCFG_ENTRY PSCfg2DIMMs[] = {
143 {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
144 0x00000000, 0x0000, 1},
145 {DDR800_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
146 0x00000000, 0x0040, 1},
147 {DDR800_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
148 0x00000000, 0x4004, 2},
149 {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
150 0x003C3C3C, 0x0000,1},
151 {DDR1066_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
152 0x003C3C3C, 0x0040, 1},
153 {DDR1066_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
154 0x003A3C3A, 0x4004, 2},
155 {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
156 0x003A3A3A, 0x0000, 1},
157 {DDR1333_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
158 0x003A3A3A, 0x0040, 1},
159 {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
160 0x00383A38, 0x4040, 2},
161 {DDR1333_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
162 0x00383A38, 0x4004, 2},
163 {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
164 0x00373937, 0x0000, 1},
165 {DDR1600_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
166 0x00373937, 0x0040, 1},
167 {DDR1600_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
168 0x00353935, 0x4004, 2}
171 STATIC CONST ADV_R_PSCFG_ENTRY PSCfg3DIMMs[] = {
172 {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
173 0x00000000, 0x0000, 1},
174 {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
175 0x00000000, 0x4040, 2},
176 {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
177 0x00380038, 0x4004, 3},
178 {DDR800_FREQUENCY, QR_DIMM1, \
179 0x00000000, 0x0040, 1},
180 {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
181 0x00000000, 0x4004, 2},
182 {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
183 0x003C3C3C, 0x0000, 1},
184 {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
185 0x003A3C3A, 0x4040, 2},
186 {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
187 0x00373C37, 0x4040, 3},
188 {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
189 0x00373C37, 0x4004, 3},
190 {DDR1066_FREQUENCY, QR_DIMM1, \
191 0x003C3C3C, 0x0040, 1},
192 {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
193 0x003A3C3A, 0x4004, 2},
194 {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
195 0x003A3A3A, 0x0000, 1},
196 {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
197 0x00383A38, 0x4040, 2},
198 {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
199 0x00343A34, 0x4004, 3},
200 {DDR1333_FREQUENCY, QR_DIMM1, \
201 0x003A3A3A, 0x0040, 1},
202 {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
203 0x00383A38, 0x4004, 2},
204 {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
205 0x00393939, 0x0000, 1},
206 {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
207 0x00363936, 0x4040, 2},
208 {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
209 0x00303930, 0x4004, 3},
210 {DDR1600_FREQUENCY, QR_DIMM1, \
211 0x00393939, 0x0040, 1},
212 {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
213 0x00363936, 0x4004, 2}
216 STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg2DIMMsWlODT[] = {
217 {SR_DIMM0, {0x01, 0x00, 0x00, 0x00}, 1},
218 {DR_DIMM0, {0x04, 0x00, 0x00, 0x00}, 1},
219 {SR_DIMM1, {0x00, 0x02, 0x00, 0x00}, 1},
220 {DR_DIMM1, {0x00, 0x08, 0x00, 0x00}, 1},
221 {QR_DIMM1, {0x00, 0x0A, 0x00, 0x00}, 1},
222 {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, {0x03, 0x03, 0x00, 0x00}, 2},
223 {SR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
224 {DR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
225 {QR_DIMM0 + SR_DIMM1, {0x03, 0x07, 0x06, 0x00}, 2},
226 {QR_DIMM0 + DR_DIMM1, {0x03, 0x07, 0x06, 0x00}, 2},
227 {QR_DIMM0 + QR_DIMM1, {0x0B, 0x07, 0x0E, 0x0D}, 2}
230 STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg3DIMMsWlODT[] = {
231 {SR_DIMM2 + DR_DIMM2, {0x00, 0x00, 0x04, 0x00}, 1},
232 {SR_DIMM0 + DR_DIMM0, {0x01, 0x02, 0x00, 0x00}, 1},
233 {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, {0x05, 0x00, 0x05, 0x00}, 2},
234 {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x07, 0x07, 0x07, 0x00}, 3},
235 {QR_DIMM1, {0x00, 0x0A, 0x00, 0x0A}, 1},
236 {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x00, 0x06, 0x0E, 0x0C}, 2},
237 {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
238 {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x0F, 0x07, 0x0F, 0x0D}, 3}
241 STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg4DIMMsWlODT[] = {
242 {ANY_DIMM3, {0x00, 0x00, 0x00, 0x08}, 1},
243 {ANY_DIMM2 + ANY_DIMM3, {0x00, 0x00, 0x0C, 0x0C}, 2},
244 {ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, {0x00, 0x0E, 0x0E, 0x0E}, 3},
245 {ANY_DIMM0 + ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, {0x0F, 0x0F, 0x0F, 0x0F}, 4}
253 UINT16 _DIMMRankType;
260 UINT8 PSCfgWlODTSize;
262 CONST ADV_R_PSCFG_ENTRY *PSCfgPtr;
263 CONST ADV_R_PSCFG_WL_ODT_ENTRY *PSCfgWlODTPtr;
264 UINT8 *DimmsPerChPtr;
270 ASSERT (MemData != NULL);
275 if ((CurrentChannel->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_RB) == 0) {
276 return AGESA_UNSUPPORTED;
278 if (CurrentChannel->TechType != DDR3_TECHNOLOGY) {
279 return AGESA_UNSUPPORTED;
281 if (CurrentChannel->RegDimmPresent != CurrentChannel->ChDimmValid) {
282 return AGESA_UNSUPPORTED;
285 Dimms = CurrentChannel->Dimms;
286 Speed = CurrentChannel->DCTPtr->Timings.Speed;
288 DimmsPerChPtr = FindPSOverrideEntry (MemData->ParameterListPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, SocketID, CurrentChannel->ChannelID, 0, NULL, NULL);
289 if (DimmsPerChPtr != NULL) {
290 MaxDimmPerCH = *DimmsPerChPtr;
295 DIMMRankType = MemAGetPsRankType (CurrentChannel);
297 if (MaxDimmPerCH == 4) {
300 PSCfgWlODTPtr = PSCfg4DIMMsWlODT;
301 PSCfgWlODTSize = sizeof (PSCfg4DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
302 } else if (MaxDimmPerCH == 3) {
303 PSCfgPtr = PSCfg3DIMMs;
304 PSCfgSize = sizeof (PSCfg3DIMMs) / sizeof (ADV_R_PSCFG_ENTRY);
305 PSCfgWlODTPtr = PSCfg3DIMMsWlODT;
306 PSCfgWlODTSize = sizeof (PSCfg3DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
308 PSCfgPtr = PSCfg2DIMMs;
309 PSCfgSize = sizeof (PSCfg2DIMMs) / sizeof (ADV_R_PSCFG_ENTRY);
310 PSCfgWlODTPtr = PSCfg2DIMMsWlODT;
311 PSCfgWlODTSize = sizeof (PSCfg2DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
314 // AddrTmgCTL and DctOdcCtl
315 if (MaxDimmPerCH != 4) {
316 for (i = 0; i < PSCfgSize; i++, PSCfgPtr++) {
317 if ((Speed != PSCfgPtr->Speed) || (Dimms != PSCfgPtr->Dimms)) {
321 _DIMMRankType = DIMMRankType & PSCfgPtr->DIMMRankType;
322 for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
323 if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
327 if (DimmTpMatch == PSCfgPtr->Dimms) {
328 AddrTmgCTL = PSCfgPtr->AddrTmg;
329 DctOdcCtl = 0x00223222;
330 RC2RC8 = PSCfgPtr->RC2RC8;
337 // Overrides and/or exceptions
340 for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
341 if ((DIMMRankType & (UINT16) 0x03 << (j << 2)) != 0) {
345 if (MaxDimmPerCH == 4) {
346 if (DimmTpMatch > 0) {
347 DctOdcCtl = 0x00223222;
348 if ((Speed == DDR800_FREQUENCY) && (DimmTpMatch == 1)) {
349 DctOdcCtl = 0x00113222;
352 if (DimmTpMatch >= 3) {
353 AddrTmgCTL |= 0x002F0000;
355 if (DimmTpMatch >= 2) {
359 if ((Dimms == 1) && (DimmTpMatch == 1)) {
360 DctOdcCtl = 0x00113222;
365 for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
366 // CtrlWrd02(s) will contain the info. of SPD byte 63 after MemTDIMMPresence3 execution.
367 if (CurrentChannel->CtrlWrd02[j] > 0) {
368 if (CurrentChannel->CtrlWrd02[j] == 1) {
369 // Store real RC2 and RC8 value (High byte) into CtrlWrd02(s) and CtrlWrd08(s).
370 CurrentChannel->CtrlWrd02[j] = (UINT8) (RC2RC8 >> 12) & 0x000F;
371 CurrentChannel->CtrlWrd08[j] = (UINT8) (RC2RC8 >> 8) & 0x000F;
373 // Store real RC2 and RC8 value (low byte) into CtrlWrd02(s) and CtrlWrd08(s).
374 CurrentChannel->CtrlWrd02[j] = (UINT8) (RC2RC8 >> 4) & 0x000F;
375 CurrentChannel->CtrlWrd08[j] = (UINT8) RC2RC8 & 0x000F;
382 for (i = 0; i < PSCfgWlODTSize; i++, PSCfgWlODTPtr++) {
383 if (Dimms != PSCfgWlODTPtr->Dimms) {
387 _DIMMRankType = DIMMRankType & PSCfgWlODTPtr->DIMMRankType;
388 for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
389 if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
393 if (DimmTpMatch == PSCfgWlODTPtr->Dimms) {
394 PhyWLODT[0] = PSCfgWlODTPtr->PhyWrLvOdt[0];
395 PhyWLODT[1] = PSCfgWlODTPtr->PhyWrLvOdt[1];
396 PhyWLODT[2] = PSCfgWlODTPtr->PhyWrLvOdt[2];
397 PhyWLODT[3] = PSCfgWlODTPtr->PhyWrLvOdt[3];
403 DctOdcCtl |= 0x20000000;
405 CurrentChannel->MemClkDisMap = (UINT8 *) DrRDdr3CLKDis;
406 CurrentChannel->CKETriMap = (UINT8 *) DrRDdr3CKETri;
407 CurrentChannel->ChipSelTriMap = (UINT8 *) DrRDdr3CSTri;
409 switch (MaxDimmPerCH) {
411 CurrentChannel->ODTTriMap = (UINT8 *) DrRDdr3ODTTri3D;
414 CurrentChannel->ODTTriMap = (UINT8 *) DrRDdr3ODTTri4D;
417 CurrentChannel->ODTTriMap = (UINT8 *) DrRDdr3ODTTri2D;
420 CurrentChannel->DctAddrTmg = AddrTmgCTL;
421 CurrentChannel->DctOdcCtl = DctOdcCtl;
422 for (i = 0; i < sizeof (CurrentChannel->PhyWLODT); i++) {
423 CurrentChannel->PhyWLODT[i] = PhyWLODT[i];
425 CurrentChannel->SlowMode = SlowMode;
427 return AGESA_SUCCESS;