AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Ardk / HY / marhy3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * marhy3.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_HY_MARHY3_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 HyRDdr3CLKDis[] = {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 HyRDdr3CKETri[] = {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 HyRDdr3ODTTri2D[] = {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 HyRDdr3ODTTri3D[] = {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 HyRDdr3ODTTri4D[] = {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 HyRDdr3CSTri[] = {0x01, 0x03, 0x04, 0x0C, 0x10, 0x30, 0x40, 0xC0};
111
112 /* -----------------------------------------------------------------------------*/
113 /**
114  *
115  *         This is function sets the platform specific settings for HY 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 HY MemClkDis table
123  *     @return          CurrentChannel->ChipSelTriMap    Points this pointer to HY CS table
124  *     @return          CurrentChannel->CKETriMap        Points this pointer to HY ODT table
125  *     @return          CurrentChannel->ODTTriMap        Points this pointer to HY 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 MemAGetPsCfgRHy3 (
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   // Frequency, Dimm Config ,
148   // Address Timing Value(F2x[1, 0]9C_x04), RC2/RC8 Value, # Dimms to match
149   //
150   STATIC CONST ADV_R_PSCFG_ENTRY PSCfg2DIMMs[] = {
151      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
152        0x00000000, 0x0000, 1},
153      {DDR800_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
154        0x00000000, 0x0040, 1},
155      {DDR800_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
156        0x00000000, 0x4004, 2},
157      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
158        0x003C3C3C, 0x0000,1},
159      {DDR1066_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
160        0x003C3C3C, 0x0040, 1},
161      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
162        0x003A3C3A, 0x4004, 2},
163      {DDR1066_FREQUENCY, QR_DIMM0 + ANY_DIMM1, \
164        0x003A3C3A, 0x4004, 2},
165      {DDR1066_FREQUENCY, ANY_DIMM0 + QR_DIMM1, \
166        0x003A3C3A, 0x4004, 2},
167      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
168        0x003A3A3A, 0x0000, 1},
169      {DDR1333_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
170        0x003A3A3A, 0x0040, 1},
171      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
172        0x00383A38, 0x4040, 2},
173      {DDR1333_FREQUENCY, QR_DIMM0 + ANY_DIMM1, \
174        0x00383A38, 0x4004, 2},
175      {DDR1333_FREQUENCY, ANY_DIMM0 + QR_DIMM1, \
176        0x00383A38, 0x4004, 2},
177      {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
178        0x00373937, 0x0000, 1},
179      {DDR1600_FREQUENCY, QR_DIMM0 + QR_DIMM1, \
180        0x00373937, 0x0040, 1},
181      {DDR1600_FREQUENCY, ANY_DIMM0 + ANY_DIMM1, \
182        0x00353935, 0x4004, 2}
183   };
184   //
185   // Address Timings and Drive Strengths for 3 DIMMs per channel
186   //
187   // Code searches table for matching speed, then matches the current dimm
188   // population and # of dimms to current config and programs the Addr Timing and RC2/RC2
189   //
190   // Frequency, Dimm Config ,
191   // Address Timing Value(F2x[1, 0]9C_x04), RC2/RC8 Value, # Dimms to match
192   //
193   STATIC CONST ADV_R_PSCFG_ENTRY PSCfg3DIMMs[] = {
194      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
195        0x00000000, 0x0000, 1},
196      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
197        0x00000000, 0x4040, 2},
198      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
199        0x00380038, 0x4004, 3},
200      {DDR800_FREQUENCY, QR_DIMM1, \
201        0x00000000, 0x0040, 1},
202      {DDR800_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
203        0x00000000, 0x4004, 2},
204      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
205        0x003C3C3C, 0x0000, 1},
206      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
207        0x003A3C3A, 0x4040, 2},
208      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
209        0x00373C37, 0x4040, 3},
210      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
211        0x00373C37, 0x4004, 3},
212      {DDR1066_FREQUENCY, QR_DIMM1, \
213        0x003C3C3C, 0x0040, 1},
214      {DDR1066_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
215        0x003A3C3A, 0x4004, 2},
216      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
217        0x003A3A3A, 0x0000, 1},
218      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
219        0x00383A38, 0x4040, 2},
220      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
221        0x00343A34, 0x4004, 3},
222      {DDR1333_FREQUENCY, QR_DIMM1, \
223        0x003A3A3A, 0x0040, 1},
224      {DDR1333_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
225        0x00383A38, 0x4004, 2},
226      {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
227        0x00393939, 0x0000, 1},
228      {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
229        0x00363936, 0x4040, 2},
230      {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + ANY_DIMM1 + SR_DIMM2 + DR_DIMM2, \
231        0x00303930, 0x4004, 3},
232      {DDR1600_FREQUENCY, QR_DIMM1, \
233        0x00393939, 0x0040, 1},
234      {DDR1600_FREQUENCY, SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
235        0x00363936, 0x4004, 2}
236   };
237   //
238   // DIMM ODT Pattern (1 or 2 DIMMs per channel)
239   //
240   // Dimm Config ,
241   // Fn2_9C 180, Fn2_9C 181, Fn2_9C 182, Fn2_9C 183, # Dimms to match
242   //
243   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfg2DIMMsODT[] = {
244     {SR_DIMM0, \
245       0x00000000, 0x00000000, 0x00000001, 0x00000000, 1},
246     {DR_DIMM0, \
247       0x00000000, 0x00000000, 0x00000104, 0x00000000, 1},
248     {QR_DIMM0, \
249       0x00000000, 0x00000000, 0x00000505, 0x00000505, 1},
250     {SR_DIMM1, \
251       0x00000000, 0x00000000, 0x00020000, 0x00000000, 1},
252     {DR_DIMM1, \
253       0x00000000, 0x00000000, 0x02080000, 0x00000000, 1},
254     {QR_DIMM1, \
255       0x00000000, 0x00000000, 0x0A0A0000, 0x0A0A0000, 1},
256     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
257       0x01010202, 0x00000000, 0x09030603, 0x00000000, 2},
258     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, \
259       0x01010A0A, 0x01010000, 0x01030E0B, 0x01090000, 2},
260     {QR_DIMM0 + SR_DIMM1 + DR_DIMM1, \
261       0x05050202, 0x00000202, 0x0D070203, 0x00000206, 2},
262     {QR_DIMM0 + QR_DIMM1, \
263       0x05050A0A, 0x05050A0A, 0x05070A0B, 0x050D0A0E, 2}
264   };
265   // DIMM ODT Pattern (3 DIMMs per channel)
266   //
267   // Dimm Config ,
268   // Fn2_9C 180, Fn2_9C 181, Fn2_9C 182, Fn2_9C 183, # Dimms to match
269   //
270   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfg3DIMMsODT[] = {
271     {SR_DIMM2 + DR_DIMM2, \
272       0x00000000, 0x00000000, 0x00000000, 0x00000404, 1},
273     {SR_DIMM0 + DR_DIMM0, \
274       0x00000000, 0x00000000, 0x00000101, 0x00000000, 1},
275     {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, \
276       0x00000404, 0x00000101, 0x00000405, 0x00000105, 2},
277     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
278       0x05050606, 0x00000303, 0x0D070607, 0x00000307, 3},
279     {QR_DIMM1, \
280       0x00000000, 0x00000000, 0x080A0000, 0x020A0000, 1},
281     {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
282       0x04040000, 0x04040A0A, 0x04060000, 0x040C0A0E, 2},
283     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, \
284       0x01010A0A, 0x01010000, 0x01030A0B, 0x01090000, 2},
285     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, \
286       0x05050E0E, 0x05050B0B, 0x05070E0F, 0x050D0B0F, 3}
287   };
288   //
289   // DIMM ODT Pattern (4 DIMMs per channel)
290   //
291   // Dimm Config ,
292   // Fn2_9C 180, Fn2_9C 181, Fn2_9C 182, Fn2_9C 183, # Dimms to match
293   //
294   STATIC CONST ADV_PSCFG_ODT_ENTRY PSCfg4DIMMsODT[] = {
295     {ANY_DIMM3, \
296       0x00000000, 0x00000000, 0x00000000, 0x08080000, 1},
297     {ANY_DIMM2 + ANY_DIMM3, \
298       0x00000000, 0x04040808, 0x00000000, 0x0C0C0C0C, 2},
299     {ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, \
300       0x0C0C0000, 0x06060A0A, 0x0E0E0000, 0x0E0E0E0E, 3},
301     {ANY_DIMM0 + ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, \
302       0x0D0D0E0E, 0x07070B0B, 0x0F0F0F0F, 0x0F0F0F0F, 4}
303   };
304   //
305   // DIMM Write Leveling ODT Pattern for 1 or 2 Dimms Per Channel
306   //
307   // Dimm Config, WrLvOdt (Fn2_9C_0x08[11:8]) Value for each Dimm, # Dimms to match
308   //
309   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg2DIMMsWlODT[] = {
310     {SR_DIMM0,            {0x01, 0x00, 0x00, 0x00}, 1},
311     {DR_DIMM0,            {0x04, 0x00, 0x00, 0x00}, 1},
312     {QR_DIMM0,            {0x05, 0x00, 0x00, 0x00}, 1},
313     {SR_DIMM1,            {0x00, 0x02, 0x00, 0x00}, 1},
314     {DR_DIMM1,            {0x00, 0x08, 0x00, 0x00}, 1},
315     {QR_DIMM1,            {0x00, 0x0A, 0x00, 0x00}, 1},
316     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, {0x03, 0x03, 0x00, 0x00}, 2},
317     {SR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
318     {DR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
319     {QR_DIMM0 + SR_DIMM1, {0x03, 0x07, 0x06, 0x00}, 2},
320     {QR_DIMM0 + DR_DIMM1, {0x03, 0x07, 0x06, 0x00}, 2},
321     {QR_DIMM0 + QR_DIMM1, {0x0B, 0x07, 0x0E, 0x0D}, 2}
322   };
323   //
324   // DIMM Write Leveling ODT Pattern 3 Dimms Per Channel
325   //
326   // Dimm Config, WrLvOdt (Fn2_9C_0x08[11:8]) Value for each Dimm, # Dimms to match
327   //
328   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg3DIMMsWlODT[] = {
329     {SR_DIMM2 + DR_DIMM2, {0x00, 0x00, 0x04, 0x00}, 1},
330     {SR_DIMM0 + DR_DIMM0, {0x01, 0x02, 0x00, 0x00}, 1},
331     {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, {0x05, 0x00, 0x05, 0x00}, 2},
332     {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x07, 0x07, 0x07, 0x00}, 3},
333     {QR_DIMM1, {0x00, 0x0A, 0x00, 0x0A}, 1},
334     {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x00, 0x06, 0x0E, 0x0C}, 2},
335     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1, {0x0B, 0x03, 0x00, 0x09}, 2},
336     {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, {0x0F, 0x07, 0x0F, 0x0D}, 3}
337   };
338   //
339   // DIMM Write Leveling ODT Pattern 4 Dimms Per Channel
340   //
341   // Dimm Config, WrLvOdt (Fn2_9C_0x08[11:8]) Value for each Dimm, # Dimms to match
342   //
343   STATIC CONST ADV_R_PSCFG_WL_ODT_ENTRY PSCfg4DIMMsWlODT[] = {
344     {ANY_DIMM3, {0x00, 0x00, 0x00, 0x08}, 1},
345     {ANY_DIMM2 + ANY_DIMM3, {0x00, 0x00, 0x0C, 0x0C}, 2},
346     {ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, {0x00, 0x0E, 0x0E, 0x0E}, 3},
347     {ANY_DIMM0 + ANY_DIMM1 + ANY_DIMM2 + ANY_DIMM3, {0x0F, 0x0F, 0x0F, 0x0F}, 4}
348   };
349
350   UINT16 i;
351   UINT16 j;
352   UINT8  MaxDimmPerCH;
353   UINT8 Dimms;
354   UINT16 Speed;
355   UINT16 DIMMRankType;
356   UINT16 _DIMMRankType;
357   UINT8 DimmTpMatch;
358   UINT32 AddrTmgCTL;
359   UINT32 DctOdcCtl;
360   UINT16 RC2RC8;
361   UINT32 PhyRODTCSLow;
362   UINT32 PhyRODTCSHigh;
363   UINT32 PhyWODTCSLow;
364   UINT32 PhyWODTCSHigh;
365   BOOLEAN SlowMode;
366   UINT8 PSCfgSize;
367   UINT8 PSCfgODTSize;
368   UINT8 PSCfgWlODTSize;
369   UINT8 PhyWLODT[4];
370
371   CONST ADV_R_PSCFG_ENTRY *PSCfgPtr;
372   CONST ADV_PSCFG_ODT_ENTRY *PSCfgODTPtr;
373   CONST ADV_R_PSCFG_WL_ODT_ENTRY *PSCfgWlODTPtr;
374   UINT8 *DimmsPerChPtr;
375
376   ASSERT (MemData != NULL);
377   ASSERT (CurrentChannel != NULL);
378
379   AddrTmgCTL = 0;
380   DctOdcCtl = 0;
381   RC2RC8 = 0;
382   PhyRODTCSLow = 0;
383   PhyRODTCSHigh = 0;
384   PhyWODTCSLow = 0;
385   PhyWODTCSHigh = 0;
386   SlowMode = FALSE;
387   PhyWLODT[0] = 0x0F;
388   PhyWLODT[1] = 0x0F;
389   PhyWLODT[2] = 0x0F;
390   PhyWLODT[3] = 0x0F;
391
392   if ((CurrentChannel->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_HY) == 0) {
393     return AGESA_UNSUPPORTED;
394   }
395   if (CurrentChannel->TechType != DDR3_TECHNOLOGY) {
396     return AGESA_UNSUPPORTED;
397   }
398   if (CurrentChannel->RegDimmPresent == 0) {
399     return AGESA_UNSUPPORTED;
400   }
401
402   // Prepare inputs
403   Dimms = CurrentChannel->Dimms;
404   Speed = CurrentChannel->DCTPtr->Timings.Speed;
405   DimmsPerChPtr = FindPSOverrideEntry (MemData->ParameterListPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, SocketID, CurrentChannel->ChannelID, 0, NULL, NULL);
406   if (DimmsPerChPtr != NULL) {
407     MaxDimmPerCH = *DimmsPerChPtr;
408   } else {
409     MaxDimmPerCH = 2;
410   }
411
412   DIMMRankType = MemAGetPsRankType (CurrentChannel);
413
414   if (MaxDimmPerCH == 4) {
415     PSCfgPtr = NULL;
416     PSCfgSize = 0;
417     PSCfgODTPtr = PSCfg4DIMMsODT;
418     PSCfgWlODTPtr = PSCfg4DIMMsWlODT;
419     PSCfgODTSize = sizeof (PSCfg4DIMMsODT) / sizeof (ADV_PSCFG_ODT_ENTRY);
420     PSCfgWlODTSize = sizeof (PSCfg4DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
421   } else if (MaxDimmPerCH == 3) {
422     PSCfgPtr = PSCfg3DIMMs;
423     PSCfgSize = sizeof (PSCfg3DIMMs) / sizeof (ADV_R_PSCFG_ENTRY);
424     PSCfgODTPtr = PSCfg3DIMMsODT;
425     PSCfgWlODTPtr = PSCfg3DIMMsWlODT;
426     PSCfgODTSize = sizeof (PSCfg3DIMMsODT) / sizeof (ADV_PSCFG_ODT_ENTRY);
427     PSCfgWlODTSize = sizeof (PSCfg3DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
428   } else {
429     PSCfgPtr = PSCfg2DIMMs;
430     PSCfgSize = sizeof (PSCfg2DIMMs) / sizeof (ADV_R_PSCFG_ENTRY);
431     PSCfgODTPtr = PSCfg2DIMMsODT;
432     PSCfgWlODTPtr = PSCfg2DIMMsWlODT;
433     PSCfgODTSize = sizeof (PSCfg2DIMMsODT) / sizeof (ADV_PSCFG_ODT_ENTRY);
434     PSCfgWlODTSize = sizeof (PSCfg2DIMMsWlODT) / sizeof (ADV_R_PSCFG_WL_ODT_ENTRY);
435   }
436
437   // AddrTmgCTL and DctOdcCtl
438   if (MaxDimmPerCH != 4) {
439     for (i = 0; i < PSCfgSize; i++, PSCfgPtr++) {
440       if ((Speed != PSCfgPtr->Speed) || (Dimms != PSCfgPtr->Dimms)) {
441         continue;
442       }
443       DimmTpMatch = 0;
444       _DIMMRankType = DIMMRankType & PSCfgPtr->DIMMRankType;
445       for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
446         if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
447           DimmTpMatch++;
448         }
449       }
450       if (DimmTpMatch == PSCfgPtr->Dimms) {
451         AddrTmgCTL = PSCfgPtr->AddrTmg;
452         DctOdcCtl = 0x00223222;
453         RC2RC8 = PSCfgPtr->RC2RC8;
454         break;
455       }
456     }
457   }
458
459   //
460   // Overrides and/or exceptions
461   //
462   DimmTpMatch = 0;
463   for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
464     if ((DIMMRankType & (UINT16) 0x03 << (j << 2)) != 0) {
465       DimmTpMatch++;
466     }
467   }
468   if (MaxDimmPerCH == 4) {
469     if (DimmTpMatch > 0) {
470       DctOdcCtl = 0x00223222;
471       if ((Speed == DDR800_FREQUENCY) && (DimmTpMatch == 1)) {
472         DctOdcCtl = 0x00113222;
473       }
474     }
475     if (DimmTpMatch >= 3) {
476       AddrTmgCTL |= 0x002F0000;
477     }
478     if (DimmTpMatch >= 2) {
479       RC2RC8 = 0x4040;
480     }
481   } else if ((MaxDimmPerCH == 3) && (CurrentChannel->Dimms == 3)) {
482     DctOdcCtl = 0x00113222;
483   } else {
484     if ((Dimms == 1) && (DimmTpMatch == 1)) {
485       DctOdcCtl = 0x00113222;
486     }
487   }
488
489   //RC2 and RC8
490   for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
491     // CtrlWrd02(s) will contain the info. of SPD byte 63 after MemTDIMMPresence3 execution.
492     if (CurrentChannel->CtrlWrd02[j] > 0) {
493       if (CurrentChannel->CtrlWrd02[j] == 1) {
494         // Store real RC2 and RC8 value (High byte) into CtrlWrd02(s) and CtrlWrd08(s).
495         CurrentChannel->CtrlWrd02[j] = (UINT8) (RC2RC8 >> 12) & 0x000F;
496         CurrentChannel->CtrlWrd08[j] = (UINT8) (RC2RC8 >> 8) & 0x000F;
497       } else {
498         // Store real RC2 and RC8 value (low byte) into CtrlWrd02(s) and CtrlWrd08(s).
499         CurrentChannel->CtrlWrd02[j] = (UINT8) (RC2RC8 >> 4) & 0x000F;
500         CurrentChannel->CtrlWrd08[j] = (UINT8) RC2RC8 & 0x000F;
501       }
502     }
503   }
504
505   //Programmable ODT
506   for (i = 0; i  < PSCfgODTSize; i++, PSCfgODTPtr++) {
507     if (Dimms != PSCfgODTPtr->Dimms) {
508       continue;
509     }
510     DimmTpMatch = 0;
511     _DIMMRankType = DIMMRankType & PSCfgODTPtr->DIMMRankType;
512     for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
513       if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
514         DimmTpMatch++;
515       }
516     }
517     if (DimmTpMatch == PSCfgODTPtr->Dimms) {
518       PhyRODTCSLow = PSCfgODTPtr->PhyRODTCSLow;
519       PhyRODTCSHigh = PSCfgODTPtr->PhyRODTCSHigh;
520       PhyWODTCSLow = PSCfgODTPtr->PhyWODTCSLow;
521       PhyWODTCSHigh = PSCfgODTPtr->PhyWODTCSHigh;
522       break;
523     }
524   }
525
526   //WLODT
527   for (i = 0; i  < PSCfgWlODTSize; i++, PSCfgWlODTPtr++) {
528     if (Dimms != PSCfgWlODTPtr->Dimms) {
529       continue;
530     }
531     DimmTpMatch = 0;
532     _DIMMRankType = DIMMRankType & PSCfgWlODTPtr->DIMMRankType;
533     for (j = 0; j < MAX_DIMMS_PER_CHANNEL; j++) {
534       if ((_DIMMRankType & (UINT16) 0x0F << (j << 2)) != 0) {
535         DimmTpMatch++;
536       }
537     }
538     if (DimmTpMatch == PSCfgWlODTPtr->Dimms) {
539       PhyWLODT[0] = PSCfgWlODTPtr->PhyWrLvOdt[0];
540       PhyWLODT[1] = PSCfgWlODTPtr->PhyWrLvOdt[1];
541       PhyWLODT[2] = PSCfgWlODTPtr->PhyWrLvOdt[2];
542       PhyWLODT[3] = PSCfgWlODTPtr->PhyWrLvOdt[3];
543       break;
544     }
545   }
546
547   // Set ProcODT
548   DctOdcCtl |= 0x20000000;
549
550   CurrentChannel->MemClkDisMap = (UINT8 *) HyRDdr3CLKDis;
551   CurrentChannel->CKETriMap = (UINT8 *) HyRDdr3CKETri;
552   CurrentChannel->ChipSelTriMap = (UINT8 *) HyRDdr3CSTri;
553
554   switch (MaxDimmPerCH) {
555   case 3:
556     CurrentChannel->ODTTriMap = (UINT8 *) HyRDdr3ODTTri3D;
557     break;
558   case 4:
559     CurrentChannel->ODTTriMap = (UINT8 *) HyRDdr3ODTTri4D;
560     break;
561   default:
562     CurrentChannel->ODTTriMap = (UINT8 *) HyRDdr3ODTTri2D;  // Most conservative
563   }
564
565   CurrentChannel->DctAddrTmg = AddrTmgCTL;
566   CurrentChannel->DctOdcCtl = DctOdcCtl;
567   CurrentChannel->PhyRODTCSLow  = PhyRODTCSLow;
568   CurrentChannel->PhyRODTCSHigh = PhyRODTCSHigh;
569   CurrentChannel->PhyWODTCSLow  = PhyWODTCSLow;
570   CurrentChannel->PhyWODTCSHigh = PhyWODTCSHigh;
571   for (i = 0; i < sizeof (CurrentChannel->PhyWLODT); i++) {
572     CurrentChannel->PhyWLODT[i] = PhyWLODT[i];
573   }
574   CurrentChannel->SlowMode = SlowMode;
575
576   return AGESA_SUCCESS;
577 }