AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Ardk / C32 / marc32_3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * marc32_3.c
6  *
7  * Memory Controller, registered dimms
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Ardk)
12  * @e \$Revision: 52286 $ @e \$Date: 2011-05-04 03:48:21 -0600 (Wed, 04 May 2011) $
13  *
14  **/
15 /*****************************************************************************
16   *
17  * Copyright (C) 2012 Advanced Micro Devices, Inc.
18  * All rights reserved.
19  *
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.
30  *
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.
41   *
42   * ***************************************************************************
43   *
44  */
45
46 /* This file contains routine that add platform specific support AM3 */
47
48
49 #include "AGESA.h"
50 #include "ma.h"
51 #include "OptionMemory.h"
52 #include "PlatformMemoryConfiguration.h"
53 #include "mu.h"
54 #include "Ids.h"
55 #include "cpuFamRegisters.h"
56 #include "Filecode.h"
57 CODE_GROUP (G2_PEI)
58 RDATA_GROUP (G2_PEI)
59
60 #define FILECODE PROC_MEM_ARDK_C32_MARC32_3_FILECODE
61 /*----------------------------------------------------------------------------
62  *                          DEFINITIONS AND MACROS
63  *
64  *----------------------------------------------------------------------------
65  */
66
67 /*----------------------------------------------------------------------------
68  *                           TYPEDEFS AND STRUCTURES
69  *
70  *----------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------
74  *                        PROTOTYPES OF LOCAL FUNCTIONS
75  *
76  *----------------------------------------------------------------------------
77  */
78
79 /*
80  *-----------------------------------------------------------------------------
81  *                                EXPORTED FUNCTIONS
82  *
83  *-----------------------------------------------------------------------------
84  */
85
86 STATIC CONST UINT8 ROMDATA C32RDdr3CLKDis[] = {0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
87
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 C32RDdr3CKETri[] = {0x55, 0xAA};
91
92 // 2 dimms per channel
93 // Dimm 0: BP_MEMODTx[2,0]
94 // Dimm 1: BP_MEMODTx[3,1]
95 STATIC CONST UINT8 ROMDATA C32RDdr3ODTTri2D[] = {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 C32RDdr3ODTTri3D[] = {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 C32RDdr3ODTTri4D[] = {0x03, 0x0C, 0x30, 0xC0};
107
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 C32RDdr3CSTri[] = {0x01, 0x03, 0x04, 0x0C, 0x10, 0x30, 0x40, 0xC0};
111
112 /* -----------------------------------------------------------------------------*/
113 /**
114  *
115  *         This is function sets the platform specific settings for C32 DDR3 L1 system
116  *
117  *     @param[in,out]   *MemData           Pointer to MEM_DATA_STRUCTURE
118  *     @param[in]       SocketID        Socket number
119  *     @param[in]       *CurrentChannel       Pointer to CH_DEF_STRUCT
120  *
121  *     @return          AGESA_SUCCESS
122  *     @return          CurrentChannel->MemClkDisMap     Points this pointer to C32 MemClkDis table
123  *     @return          CurrentChannel->ChipSelTriMap    Points this pointer to C32 CS table
124  *     @return          CurrentChannel->CKETriMap        Points this pointer to C32 ODT table
125  *     @return          CurrentChannel->ODTTriMap        Points this pointer to C32 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
131  *
132  */
133
134 AGESA_STATUS
135 MemAGetPsCfgRC32_3 (
136   IN OUT   MEM_DATA_STRUCT *MemData,
137   IN       UINT8 SocketID,
138   IN OUT   CH_DEF_STRUCT *CurrentChannel
139   )
140 {
141   //
142   // Address Timings and Drive Strengths for 1 DIMM per channel or 2 Dimms per Channel
143   //
144   // Code searches table for matching speed, then matches the current dimm
145   // population and # of dimms to current config and programs the Addr Timing and RC2/RC2
146   //
147   // RC2/RC8 Value - This field id dependent upon the number of Registers on the Dimm, as indicated
148   //                 in SPD Byte 63.
149   //                 Bits 15-12       RC2 if One register
150   //                 Bits 11-8        RC8 if One register
151   //                 Bits 7-4         RC2 for more than one register
152   //                 Bits 3-0         RC8 for more than one register
153   //
154   // Frequency, Dimm Config ,
155   // Address Timing Value(F2x[1, 0]9C_x04), RC2/RC8 Value, # Dimms to match
156   //
157   STATIC CONST ADV_R_PSCFG_ENTRY PSCfg2DIMMs[] = {
158      {DDR667_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
159        0x00000000, 0x4004, 2},
160      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
161        0x00000000, 0x0000, 1},
162      {DDR800_FREQUENCY, QR_DIMM1, \
163        0x00000000, 0x0040, 1},
164      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
165        0x00000000, 0x4004, 2},
166      {DDR800_FREQUENCY, QR_DIMM0 + ANY_DIMM1, \
167        0x00000000, 0x4004, 2},
168      {DDR800_FREQUENCY, ANY_DIMM0 + QR_DIMM1, \
169        0x00000000, 0x4004, 2},
170      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
171        0x003C3C3C, 0x0000,1},
172      {DDR1066_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
173        0x003C3C3C, 0x0040, 1},
174      {DDR1066_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
175        0x003A3C3A, 0x4004, 2},
176      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
177        0x003A3A3A, 0x0000, 1},
178      {DDR1333_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
179        0x003A3A3A, 0x0040, 1},
180      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
181        0x00383A38, 0x4040, 2},
182   };
183   //
184   // Address Timings and Drive Strengths for 3 DIMMs per channel
185   //
186   // Code searches table for matching speed, then matches the current dimm
187   // population and # of dimms to current config and programs the Addr Timing and RC2/RC2
188   //
189   // RC2/RC8 Value - This field id dependent upon the number of Registers on the Dimm, as indicated
190   //                 in SPD Byte 63.
191   //                 Bits 15-12       RC2 if One register
192   //                 Bits 11-8        RC8 if One register
193   //                 Bits 7-4         RC2 for more than one register
194   //                 Bits 3-0         RC8 for more than one register
195   //
196   // Frequency, Dimm Config ,
197   // Address Timing Value(F2x[1, 0]9C_x04), RC2/RC8 Value, # Dimms to match
198   //
199   STATIC CONST ADV_R_PSCFG_ENTRY PSCfg3DIMMs[] = {
200      {DDR667_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
201        0x00000000, 0x0000, 1},
202      {DDR667_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
203        0x00000000, 0x4040, 2},
204      {DDR667_FREQUENCY, QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
205        0x00000000, 0x4004, 2},
206      {DDR667_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
207        0x00380038, 0x4004, 3},
208      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
209        0x00000000, 0x0000, 1},
210      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, \
211        0x00000000, 0x4040, 2},
212      {DDR800_FREQUENCY, QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
213        0x00000000, 0x4004, 2},
214      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
215        0x00380038, 0x4004, 3},
216      {DDR800_FREQUENCY, QR_DIMM1, \
217        0x00000000, 0x0040, 1},
218      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
219        0x003C3C3C, 0x0000, 1},
220      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, \
221        0x003A3C3A, 0x4040, 2},
222      {DDR1066_FREQUENCY, SR_DIMM0 + SR_DIMM1 + SR_DIMM2, \
223        0x00373C37, 0x4040, 3},
224      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
225        0x003A3A3A, 0x0000, 1},
226      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, \
227        0x00383A38, 0x4040, 2},
228   };
229
230   //
231   // DIMM ODT Pattern (1 or 2 DIMMs per channel)
232   //
233   // Dimm Config ,
234   // Fn2_9C 180, Fn2_9C 181, Fn2_9C 182, Fn2_9C 183, # Dimms to match
235   //
236   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfg2DIMMsODT[] = {
237     {SR_DIMM0, \
238       0x00000000, 0x00000000, 0x00000001, 0x00000000, 1},
239     {DR_DIMM0, \
240       0x00000000, 0x00000000, 0x00000104, 0x00000000, 1},
241     {QR_DIMM0, \
242       0x00000000, 0x00000000, 0x00000505, 0x00000505, 1},
243     {SR_DIMM1, \
244       0x00000000, 0x00000000, 0x00020000, 0x00000000, 1},
245     {DR_DIMM1, \
246       0x00000000, 0x00000000, 0x02080000, 0x00000000, 1},
247     {QR_DIMM1, \
248       0x00000000, 0x00000000, 0x0A0A0000, 0x0A0A0000, 1},
249     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
250       0x01010202, 0x00000000, 0x09030603, 0x00000000, 2},
251     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, \
252       0x01010A0A, 0x01010000, 0x01030E0B, 0x01090000, 2},
253     {QR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
254       0x05050202, 0x00000202, 0x0D070203, 0x00000206, 2},
255     {QR_DIMM0 + QR_DIMM1, \
256       0x05050A0A, 0x05050A0A, 0x05070A0B, 0x050D0A0E, 2}
257   };
258   // DIMM ODT Pattern (3 DIMMs per channel)
259   //
260   // Dimm Config ,
261   // Fn2_9C 180, Fn2_9C 181, Fn2_9C 182, Fn2_9C 183, # Dimms to match
262   //
263   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfg3DIMMsODT[] = {
264     {SR_DIMM2 + DR_DIMM2, \
265       0x00000000, 0x00000000, 0x00000000, 0x00000404, 1},
266     {SR_DIMM0 + DR_DIMM0, \
267       0x00000000, 0x00000000, 0x00000101, 0x00000000, 1},
268     {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, \
269       0x00000404, 0x00000101, 0x00000405, 0x00000105, 2},
270     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
271       0x05050606, 0x00000303, 0x0D070607, 0x00000307, 3},
272     {QR_DIMM1, \
273       0x00000000, 0x00000000, 0x080A0000, 0x020A0000, 1},
274     {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
275       0x04040000, 0x04040A0A, 0x04060000, 0x040C0A0E, 2},
276     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, \
277       0x01010A0A, 0x01010000, 0x01030A0B, 0x01090000, 2},
278     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
279       0x05050E0E, 0x05050B0B, 0x05070E0F, 0x050D0B0F, 3}
280   };
281   //
282   // DIMM ODT Pattern (4 DIMMs per channel)
283   //
284   // Dimm Config ,
285   // Fn2_9C 180, Fn2_9C 181, Fn2_9C 182, Fn2_9C 183, # Dimms to match
286   //
287   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfg4DIMMsODT[] = {
288     {ANY_DIMM3, \
289       0x00000000, 0x00000000, 0x00000000, 0x08080000, 1},
290     {ANY_DIMM2 + ANY_DIMM3, \
291       0x00000000, 0x04040808, 0x00000000, 0x0C0C0C0C, 2},
292     {ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, \
293       0x0C0C0000, 0x06060A0A, 0x0E0E0000, 0x0E0E0E0E, 3},
294     {ANY_DIMM0 + ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, \
295       0x0D0D0E0E, 0x07070B0B, 0x0F0F0F0F, 0x0F0F0F0F, 4}
296   };
297   //
298   // DIMM Write Leveling ODT Pattern 1 or 2 Dimms Per Channel
299   //
300   // Dimm Config, WrLvOdt (Fn2_9C_0x08[11:8]) Value for each Dimm, # Dimms to match
301   //
302   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg2DIMMsWlODT[] = {
303     {SR_DIMM0,            {0x01, 0x00, 0x00, 0x00}, 1},
304     {DR_DIMM0,            {0x04, 0x00, 0x00, 0x00}, 1},
305     {QR_DIMM0,            {0x05, 0x00, 0x00, 0x00}, 1},
306     {SR_DIMM1,            {0x00, 0x02, 0x00, 0x00}, 1},
307     {DR_DIMM1,            {0x00, 0x08, 0x00, 0x00}, 1},
308     {QR_DIMM1,            {0x00, 0x0A, 0x00, 0x00}, 1},
309     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, {0x03, 0x03, 0x00, 0x00}, 2},
310     {SR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
311     {DR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
312     {QR_DIMM0 + SR_DIMM1, {0x03, 0x07, 0x06, 0x00}, 2},
313     {QR_DIMM0 + DR_DIMM1, {0x03, 0x07, 0x06, 0x00}, 2},
314     {QR_DIMM0 + QR_DIMM1, {0x0B, 0x07, 0x0E, 0x0D}, 2}
315   };
316   //
317   // DIMM Write Leveling ODT Pattern 3 Dimms Per Channel
318   //
319   // Dimm Config, WrLvOdt (Fn2_9C_0x08[11:8]) Value for each Dimm, # Dimms to match
320   //
321   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg3DIMMsWlODT[] = {
322     {SR_DIMM2 + DR_DIMM2, {0x00, 0x00, 0x04, 0x00}, 1},
323     {SR_DIMM0 + DR_DIMM0, {0x01, 0x02, 0x00, 0x00}, 1},
324     {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, {0x05, 0x00, 0x05, 0x00}, 2},
325     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x07, 0x07, 0x07, 0x00}, 3},
326     {QR_DIMM1, {0x00, 0x0A, 0x00, 0x0A}, 1},
327     {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x00, 0x06, 0x0E, 0x0C}, 2},
328     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
329     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x0F, 0x07, 0x0F, 0x0D}, 3}
330   };
331   //
332   // DIMM Write Leveling ODT Pattern 4 Dimms Per Channel
333   //
334   // Dimm Config, WrLvOdt (Fn2_9C_0x08[11:8]) Value for each Dimm, # Dimms to match
335   //
336   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg4DIMMsWlODT[] = {
337     {ANY_DIMM3, {0x00, 0x00, 0x00, 0x08}, 1},
338     {ANY_DIMM2 + ANY_DIMM3, {0x00, 0x00, 0x0C, 0x0C}, 2},
339     {ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, {0x00, 0x0E, 0x0E, 0x0E}, 3},
340     {ANY_DIMM0 + ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, {0x0F, 0x0F, 0x0F, 0x0F}, 4}
341   };
342
343
344   UINT16 i;
345   UINT16 j;
346   UINT8  MaxDimmPerCH;
347   UINT8 Dimms;
348   UINT16 Speed;
349   UINT16 DIMMRankType;
350   UINT16 _DIMMRankType;
351   UINT8 DimmTpMatch;
352   UINT32 AddrTmgCTL;
353   UINT32 DctOdcCtl;
354   UINT16 RC2RC8;
355   UINT32 PhyRODTCSLow;
356   UINT32 PhyRODTCSHigh;
357   UINT32 PhyWODTCSLow;
358   UINT32 PhyWODTCSHigh;
359   BOOLEAN SlowMode;
360   UINT8 PSCfgSize;
361   UINT8 PSCfgODTSize;
362   UINT8 PSCfgWlODTSize;
363   UINT8 PhyWLODT[4];
364
365   CONST ADV_R_PSCFG_ENTRY *PSCfgPtr;
366   CONST ADV_PSCFG_ODT_ENTRY *PSCfgODTPtr;
367   CONST ADV_R_PSCFG_WL_ODT_ENTRY *PSCfgWlODTPtr;
368   UINT8 *DimmsPerChPtr;
369
370   ASSERT (MemData != NULL);
371   ASSERT (CurrentChannel != NULL);
372
373   AddrTmgCTL = 0;
374   DctOdcCtl = 0;
375   RC2RC8 = 0;
376   PhyRODTCSLow = 0;
377   PhyRODTCSHigh = 0;
378   PhyWODTCSLow = 0;
379   PhyWODTCSHigh = 0;
380   SlowMode = FALSE;
381   PhyWLODT[0] = 0x0F;
382   PhyWLODT[1] = 0x0F;
383   PhyWLODT[2] = 0x0F;
384   PhyWLODT[3] = 0x0F;
385
386   if ((CurrentChannel->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_C32) == 0) {
387     return AGESA_UNSUPPORTED;
388   }
389   if (CurrentChannel->TechType != DDR3_TECHNOLOGY) {
390     return AGESA_UNSUPPORTED;
391   }
392   if (CurrentChannel->RegDimmPresent == 0) {
393     return AGESA_UNSUPPORTED;
394   }
395
396   // Prepare inputs
397   Dimms = CurrentChannel->Dimms;
398   Speed = CurrentChannel->DCTPtr->Timings.Speed;
399
400   DimmsPerChPtr = FindPSOverrideEntry (MemData->ParameterListPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, SocketID, CurrentChannel->ChannelID, 0, NULL, NULL);
401   if (DimmsPerChPtr != NULL) {
402     MaxDimmPerCH = *DimmsPerChPtr;
403   } else {
404     MaxDimmPerCH = 2;
405   }
406
407   DIMMRankType = MemAGetPsRankType (CurrentChannel);
408
409   if (MaxDimmPerCH == 4) {
410     PSCfgPtr = NULL;
411     PSCfgSize = 0;
412     PSCfgODTPtr = PSCfg4DIMMsODT;
413     PSCfgWlODTPtr = PSCfg4DIMMsWlODT;
414     PSCfgODTSize = sizeof (PSCfg4DIMMsODT) / sizeof (ADV_PSCFG_ODT_ENTRY);
415     PSCfgWlODTSize = sizeof (PSCfg4DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
416   } else if (MaxDimmPerCH == 3) {
417     PSCfgPtr = PSCfg3DIMMs;
418     PSCfgSize = sizeof (PSCfg3DIMMs) / sizeof (ADV_R_PSCFG_ENTRY);
419     PSCfgODTPtr = PSCfg3DIMMsODT;
420     PSCfgWlODTPtr = PSCfg3DIMMsWlODT;
421     PSCfgODTSize = sizeof (PSCfg3DIMMsODT) / sizeof (ADV_PSCFG_ODT_ENTRY);
422     PSCfgWlODTSize = sizeof (PSCfg3DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
423   } else {
424     PSCfgPtr = PSCfg2DIMMs;
425     PSCfgSize = sizeof (PSCfg2DIMMs) / sizeof (ADV_R_PSCFG_ENTRY);
426     PSCfgODTPtr = PSCfg2DIMMsODT;
427     PSCfgWlODTPtr = PSCfg2DIMMsWlODT;
428     PSCfgODTSize = sizeof (PSCfg2DIMMsODT) / sizeof (ADV_PSCFG_ODT_ENTRY);
429     PSCfgWlODTSize = sizeof (PSCfg2DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
430   }
431
432   // AddrTmgCTL and DctOdcCtl
433   if (MaxDimmPerCH != 4) {
434     for (i = 0; i < PSCfgSize; i++, PSCfgPtr++) {
435       if ((Speed != PSCfgPtr->Speed) || (Dimms != PSCfgPtr->Dimms)) {
436         continue;
437       }
438       DimmTpMatch = 0;
439       _DIMMRankType = DIMMRankType & PSCfgPtr->DIMMRankType;
440       for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
441         if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
442           DimmTpMatch++;
443         }
444       }
445       if (DimmTpMatch == PSCfgPtr->Dimms) {
446         AddrTmgCTL = PSCfgPtr->AddrTmg;
447         DctOdcCtl = 0x00223222;
448         RC2RC8 = PSCfgPtr->RC2RC8;
449         break;
450       }
451     }
452   }
453
454   //
455   // Overrides and/or exceptions
456   //
457   //
458   // Count slots with SR/DR poulated.
459   //
460   DimmTpMatch = 0;
461   for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
462     if ((DIMMRankType & (UINT16) 0x03 << (j << 2)) != 0) {
463       DimmTpMatch++;
464     }
465   }
466   //
467   // DimmTpMatch is equal to the count of  slot that have either an SR or DR
468   // installed.
469   //
470   if (MaxDimmPerCH == 4) {
471     //
472     // Any SR/DR in 4 DPCH
473     //
474     if (DimmTpMatch > 0) {
475       DctOdcCtl = 0x00223222;
476       if ((Speed == DDR800_FREQUENCY) && (DimmTpMatch == 1)) {
477         DctOdcCtl = 0x00113222;
478       }
479     }
480     //
481     // At Least 3 SR/DR in 4 DPCH
482     //
483     if (DimmTpMatch >= 3) {
484       AddrTmgCTL |= 0x002F0000;
485     }
486     // At Least 2 SR/DR in 4 DPCH
487     if (DimmTpMatch >= 2) {
488       RC2RC8 = 0x4040;
489     }
490   } else {
491     //
492     // Less than 4 DPCH
493     //
494     //
495     // Only 1 Dimm Populated and its a SR or DR OR
496     //   3 Dimms Populated and Frequency is 800 MHz
497     //
498     if (((Dimms == 1) && (DimmTpMatch == 1)) ||
499       ((Dimms == 3) && ((Speed == DDR800_FREQUENCY) ||
500        (Speed == DDR1066_FREQUENCY)))) {
501         DctOdcCtl = 0x00113222;
502     }
503   }
504
505   //RC2 and RC8
506   for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
507     // CtrlWrd02(s) will contain the info. of SPD byte 63 after MemTDIMMPresence3 execution.
508     if (CurrentChannel->CtrlWrd02[j] > 0) {
509       if (CurrentChannel->CtrlWrd02[j] == 1) {
510         // Store real RC2 and RC8 value (High byte) into CtrlWrd02(s) and CtrlWrd08(s).
511         CurrentChannel->CtrlWrd02[j] = (UINT8) (RC2RC8 >> 12) & 0x000F;
512         CurrentChannel->CtrlWrd08[j] = (UINT8) (RC2RC8 >> 8) & 0x000F;
513       } else {
514         // Store real RC2 and RC8 value (low byte) into CtrlWrd02(s) and CtrlWrd08(s).
515         CurrentChannel->CtrlWrd02[j] = (UINT8) (RC2RC8 >> 4) & 0x000F;
516         CurrentChannel->CtrlWrd08[j] = (UINT8) RC2RC8 & 0x000F;
517       }
518     }
519   }
520
521   //Programmable ODT
522   for (i = 0; i  < PSCfgODTSize; i++, PSCfgODTPtr++) {
523     if (Dimms != PSCfgODTPtr->Dimms) {
524       continue;
525     }
526     DimmTpMatch = 0;
527     _DIMMRankType = DIMMRankType & PSCfgODTPtr->DIMMRankType;
528     for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
529       if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
530         DimmTpMatch++;
531       }
532     }
533     if (DimmTpMatch == PSCfgODTPtr->Dimms) {
534       PhyRODTCSLow = PSCfgODTPtr->PhyRODTCSLow;
535       PhyRODTCSHigh = PSCfgODTPtr->PhyRODTCSHigh;
536       PhyWODTCSLow = PSCfgODTPtr->PhyWODTCSLow;
537       PhyWODTCSHigh = PSCfgODTPtr->PhyWODTCSHigh;
538       break;
539     }
540   }
541
542   //WLODT
543   for (i = 0; i  < PSCfgWlODTSize; i++, PSCfgWlODTPtr++) {
544     if (Dimms != PSCfgWlODTPtr->Dimms) {
545       continue;
546     }
547     DimmTpMatch = 0;
548     _DIMMRankType = DIMMRankType & PSCfgWlODTPtr->DIMMRankType;
549     for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
550       if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
551         DimmTpMatch++;
552       }
553     }
554     if (DimmTpMatch == PSCfgWlODTPtr->Dimms) {
555       PhyWLODT[0] = PSCfgWlODTPtr->PhyWrLvOdt[0];
556       PhyWLODT[1] = PSCfgWlODTPtr->PhyWrLvOdt[1];
557       PhyWLODT[2] = PSCfgWlODTPtr->PhyWrLvOdt[2];
558       PhyWLODT[3] = PSCfgWlODTPtr->PhyWrLvOdt[3];
559       break;
560     }
561   }
562
563   // Set ProcODT
564   DctOdcCtl |= 0x20000000;
565
566   CurrentChannel->MemClkDisMap = (UINT8 *) C32RDdr3CLKDis;
567   CurrentChannel->CKETriMap = (UINT8 *) C32RDdr3CKETri;
568   CurrentChannel->ChipSelTriMap = (UINT8 *) C32RDdr3CSTri;
569
570   switch (MaxDimmPerCH) {
571   case 3:
572     CurrentChannel->ODTTriMap = (UINT8 *) C32RDdr3ODTTri3D;
573     break;
574   case 4:
575     CurrentChannel->ODTTriMap = (UINT8 *) C32RDdr3ODTTri4D;
576     break;
577   default:
578     CurrentChannel->ODTTriMap = (UINT8 *) C32RDdr3ODTTri2D;  // Most conservative
579   }
580
581   CurrentChannel->DctAddrTmg = AddrTmgCTL;
582   CurrentChannel->DctOdcCtl = DctOdcCtl;
583   CurrentChannel->PhyRODTCSLow  = PhyRODTCSLow;
584   CurrentChannel->PhyRODTCSHigh = PhyRODTCSHigh;
585   CurrentChannel->PhyWODTCSLow  = PhyWODTCSLow;
586   CurrentChannel->PhyWODTCSHigh = PhyWODTCSHigh;
587   for (i = 0; i < sizeof (CurrentChannel->PhyWLODT); i++) {
588     CurrentChannel->PhyWLODT[i] = PhyWLODT[i];
589   }
590   CurrentChannel->SlowMode = SlowMode;
591
592   return AGESA_SUCCESS;
593 }