AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Ardk / DR / mardr2.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mardr2.c
6  *
7  * Platform specific settings for DR DDR2 L1 system
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 L1 */
47
48
49 #include "AGESA.h"
50 #include "mport.h"
51 #include "ma.h"
52 #include "OptionMemory.h"
53 #include "PlatformMemoryConfiguration.h"
54 #include "mu.h"
55 #include "Ids.h"
56 #include "cpuFamRegisters.h"
57 #include "Filecode.h"
58 CODE_GROUP (G2_PEI)
59 RDATA_GROUP (G2_PEI)
60
61 #define FILECODE PROC_MEM_ARDK_DR_MARDR2_FILECODE
62 /*----------------------------------------------------------------------------
63  *                          DEFINITIONS AND MACROS
64  *
65  *----------------------------------------------------------------------------
66  */
67
68 /*----------------------------------------------------------------------------
69  *                           TYPEDEFS AND STRUCTURES
70  *
71  *----------------------------------------------------------------------------
72  */
73
74 /*----------------------------------------------------------------------------
75  *                        PROTOTYPES OF LOCAL FUNCTIONS
76  *
77  *----------------------------------------------------------------------------
78  */
79
80 /*
81  *-----------------------------------------------------------------------------
82  *                                EXPORTED FUNCTIONS
83  *
84  *-----------------------------------------------------------------------------
85  */
86
87 STATIC CONST UINT8 ROMDATA DrRDdr2CLKDis[] = {0x00, 0x00, 0xC0, 0x30, 0x0C, 0x03, 0x00, 0x00};
88
89 // Chip select 0, 1, 4, 5 maps to M[B,A]_CKE[0]
90 // Chip select 2, 3, 6, 7 maps to M[B,A]_CKE[1]
91 STATIC CONST UINT8 ROMDATA DrRDdr2CKETri[] = {0x33, 0xCC};
92
93 // 2 dimms per channel
94 // Dimm 0: BP_MEMODTx[2,0]
95 // Dimm 1: BP_MEMODTx[3,1]
96 STATIC CONST UINT8 ROMDATA DrRDdr2ODTTri2D[] = {0x03, 0x0C, 0x32, 0xC8};
97 // 3 dimms per channel
98 // Dimm 0: BP_MEMODTx[0]
99 // Dimm 1: BP_MEMODTx[3,1]
100 // Dimm 2: BP_MEMODTx[2]
101 STATIC CONST UINT8 ROMDATA DrRDdr2ODTTri3D[] = {0x03, 0x0C, 0x30, 0xC8};
102 // 4 dimms per channel
103 // Dimm 0: BP_MEMODTx[0]
104 // Dimm 1: BP_MEMODTx[1]
105 // Dimm 2: BP_MEMODTx[2]
106 // Dimm 3: BP_MEMODTx[3]
107 STATIC CONST UINT8 ROMDATA DrRDdr2ODTTri4D[] = {0x03, 0x0C, 0x30, 0xC0};
108
109 // BIOS must not tri-state chip select pin corresponding to the second chip
110 // select of a single rank registered dimm
111 STATIC CONST UINT8 ROMDATA DrRDdr2CSTri[] = {0x01, 0x03, 0x04, 0x0C, 0x10, 0x30, 0x40, 0xC0};
112
113 /* -----------------------------------------------------------------------------*/
114 /**
115  *
116  *     This is function sets the platform specific settings for DR DDR2 L1 system
117  *
118  *     @param[in,out]   *MemData           Pointer to MEM_DATA_STRUCTURE
119  *     @param[in]       SocketID          Socket number
120  *     @param[in,out]   *CurrentChannel       Pointer to CH_DEF_STRUCT
121  *
122  *     @return          AGESA_SUCCESS
123  *     @return          CurrentChannel->MemClkDisMap     Points this pointer to RB MemClkDis table
124  *     @return          CurrentChannel->ChipSelTriMap    Points this pointer to RB CS table
125  *     @return          CurrentChannel->CKETriMap        Points this pointer to RB ODT table
126  *     @return          CurrentChannel->ODTTriMap        Points this pointer to RB CKE table
127  *     @return          CurrentChannel->DctEccDQSLike      Indicates the bytes that should be averaged for ECC
128  *     @return          CurrentChannel->DctEccDQSScale     Indicates the scale that should be used for Averaging ECC byte
129  *     @return          CurrentChannel->DctAddrTmg        Address Command Timing Settings for specified channel
130  *     @return          CurrentChannel->DctOdcCtl         Drive Strength settings for specified channel
131  *     @return          CurrentChannel->SlowMode             Slow Mode
132  *
133  */
134
135 AGESA_STATUS
136 MemAGetPsCfgRDr2 (
137   IN OUT   MEM_DATA_STRUCT *MemData,
138   IN       UINT8 SocketID,
139   IN OUT   CH_DEF_STRUCT *CurrentChannel
140   )
141 {
142   STATIC CONST ADV_PSCFG_ENTRY PSCfg4D[] = {
143     {ANY_, ANY_, 0x00000000, 0x00111222, 1},
144     {ANY_, ANY_, 0x00370000, 0x00111222, 2}
145   };
146
147   STATIC CONST ADV_PSCFG_ENTRY PSCfg8D[] = {
148     {ANY_, ANY_, 0x00000000, 0x00111222, 1},
149     {ANY_, ANY_, 0x00370000, 0x00111222, 2},
150     {ANY_, ANY_, 0x002F0000, 0x00111222, ANY_}
151   };
152
153   CONST ADV_PSCFG_ENTRY *PSCfgPtr;
154   UINT16 i;
155   UINT8  MaxDimmPerCH;
156   UINT16 TabSize;
157   UINT8 Loads;
158   UINT8 Dimms;
159   UINT16 Speed;
160   UINT32 AddrTmgCTL;
161   UINT32 DctOdcCtl;
162   UINT16 QRPresent;
163   UINT16 DRx4Present;
164   BOOLEAN SlowMode;
165   UINT8 *DimmsPerChPtr;
166
167   ASSERT (MemData != 0);
168   ASSERT (CurrentChannel != 0);
169
170   if ((CurrentChannel->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_RB) == 0) {
171     return AGESA_UNSUPPORTED;
172   }
173   if (CurrentChannel->TechType != DDR2_TECHNOLOGY) {
174     return AGESA_UNSUPPORTED;
175   }
176   if (CurrentChannel->RegDimmPresent != CurrentChannel->ChDimmValid) {
177     return AGESA_UNSUPPORTED;
178   }
179
180   // Prepare inputs
181   Loads = CurrentChannel->Loads;
182   Dimms = CurrentChannel->Dimms;
183   Speed = CurrentChannel->DCTPtr->Timings.Speed;
184   DimmsPerChPtr = FindPSOverrideEntry (MemData->ParameterListPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, SocketID, CurrentChannel->ChannelID, 0, NULL, NULL);
185   if (DimmsPerChPtr != NULL) {
186     MaxDimmPerCH = *DimmsPerChPtr;
187   } else {
188     MaxDimmPerCH = 2;
189   }
190   QRPresent = CurrentChannel->DimmQrPresent;
191   DRx4Present = CurrentChannel->DimmDrPresent & CurrentChannel->Dimmx4Present;
192   if (QRPresent) {
193     Dimms = (Dimms + 1) / 2;
194   }
195
196   // Table look up
197   if (MaxDimmPerCH <= 2) {
198     PSCfgPtr = PSCfg4D;
199     TabSize = GET_SIZE_OF (PSCfg4D);
200   } else {
201     PSCfgPtr = PSCfg8D;
202     TabSize = GET_SIZE_OF (PSCfg8D);
203   }
204   DctOdcCtl = 0;
205   AddrTmgCTL = 0;
206   for (i = 0; i < TabSize; i++) {
207     if ((PSCfgPtr[i].Dimms == ANY_) || (PSCfgPtr[i].Dimms == Dimms)) {
208       if ((PSCfgPtr[i].Speed == ANY_) || (PSCfgPtr[i].Speed == Speed)) {
209         if ((PSCfgPtr[i].Loads == ANY_) || (PSCfgPtr[i].Loads >= Loads)) {
210           AddrTmgCTL = PSCfgPtr[i].AddrTmg;
211           DctOdcCtl = PSCfgPtr[i].Odc;
212           break;
213         }
214       }
215     }
216   }
217   ASSERT (i == TabSize);
218   SlowMode = FALSE;  // 1T
219
220   //
221   // Overrides and/or exceptions
222   //
223
224   if (QRPresent == 0x55) {
225     // QR for 4DIMM case only
226     AddrTmgCTL = 0x002F0000;
227     if (Speed >= DDR667_FREQUENCY) {
228       DctOdcCtl = 0x00331222;
229     }
230   }
231
232   if (Speed >= DDR667_FREQUENCY) {
233     if ((QRPresent != 0) || (DRx4Present != 0)) {
234       AddrTmgCTL |= 0x00002F00;
235     }
236     if (Dimms >= 3) {
237       AddrTmgCTL |= 0x0000002F;
238     }
239     if (Dimms == 3 || Dimms == 4) {
240       DctOdcCtl = 0x00331222;
241     }
242   }
243
244   // Adjust Processor ODT
245   if (Dimms == 1) {
246     DctOdcCtl |= 0x20000000;        // 75ohms
247   } else {
248     DctOdcCtl |= 0x10000000;        // 150ohms
249   }
250
251   CurrentChannel->MemClkDisMap = (UINT8 *) DrRDdr2CLKDis;
252   CurrentChannel->CKETriMap = (UINT8 *) DrRDdr2CKETri;
253   CurrentChannel->ChipSelTriMap = (UINT8 *) DrRDdr2CSTri;
254
255   switch (MaxDimmPerCH) {
256   case 3:
257     CurrentChannel->ODTTriMap = (UINT8 *) DrRDdr2ODTTri3D;
258     break;
259   case 4:
260     CurrentChannel->ODTTriMap = (UINT8 *) DrRDdr2ODTTri4D;
261     break;
262   default:
263     CurrentChannel->ODTTriMap = (UINT8 *) DrRDdr2ODTTri2D;
264   }
265
266   CurrentChannel->DctEccDqsLike = 0x0504;
267   CurrentChannel->DctEccDqsScale = 0;
268   CurrentChannel->DctAddrTmg = AddrTmgCTL;
269   CurrentChannel->DctOdcCtl = DctOdcCtl;
270   CurrentChannel->SlowMode = SlowMode;
271
272   return AGESA_SUCCESS;
273 }