AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Ps / HY / mprhy3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mprhy3.c
6  *
7  * Platform specific settings for HY DDR3 R-DIMM system
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Ps)
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 "AdvancedApi.h"
51 #include "mport.h"
52 #include "ma.h"
53 #include "Ids.h"
54 #include "cpuFamRegisters.h"
55 #include "mm.h"
56 #include "mn.h"
57 #include "mp.h"
58 #include "mu.h"
59 #include "GeneralServices.h"
60 #include "OptionMemory.h"
61 #include "PlatformMemoryConfiguration.h"
62 #include "Filecode.h"
63 CODE_GROUP (G2_PEI)
64 RDATA_GROUP (G2_PEI)
65 #define FILECODE PROC_MEM_PS_HY_MPRHY3_FILECODE
66 /*----------------------------------------------------------------------------
67  *                          DEFINITIONS AND MACROS
68  *
69  *----------------------------------------------------------------------------
70  */
71
72 /*----------------------------------------------------------------------------
73  *                           TYPEDEFS AND STRUCTURES
74  *
75  *----------------------------------------------------------------------------
76  */
77
78 /*----------------------------------------------------------------------------
79  *                        PROTOTYPES OF LOCAL FUNCTIONS
80  *
81  *----------------------------------------------------------------------------
82  */
83 BOOLEAN
84 STATIC
85 MemPDoPsRHy3 (
86   IN OUT   MEM_NB_BLOCK *NBPtr
87   );
88
89 VOID
90 STATIC
91 MemPGetPORFreqLimitRHy3 (
92   IN OUT   MEM_NB_BLOCK *NBPtr
93   );
94 /*
95  *-----------------------------------------------------------------------------
96  *                                EXPORTED FUNCTIONS
97  *
98  *-----------------------------------------------------------------------------
99  */
100
101 /*
102  * ODT Settings for 1 Dimm or 2 Dimms Per Channel
103  *
104  * Speeds Supported, # of Dimms, # of QRDimms, DramTerm, QR DramTerm, Dynamic DramTerm
105  */
106 STATIC CONST DRAM_TERM_ENTRY HyRDdr3DramTerm2D[] = {
107   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, ONE_DIMM, NO_DIMM, 1, 0, 0},
108   {DDR667 + DDR800 + DDR1066, TWO_DIMM, NO_DIMM, 3, 0, 2},
109   {DDR1333, TWO_DIMM, NO_DIMM, 5, 0, 2},
110   {DDR1600, TWO_DIMM, NO_DIMM, 5, 0, 1},
111   {DDR667 + DDR800 + DDR1066 + DDR1333, ONE_DIMM, ONE_DIMM, 0, 1, 2},
112   {DDR1600, ONE_DIMM, ONE_DIMM, 0, 1, 1},
113   {DDR667 + DDR800, TWO_DIMM, ONE_DIMM, 5, 1, 2},
114   {DDR1066 + DDR1333 + DDR1600, TWO_DIMM, ONE_DIMM, 5, 1, 1},
115   {DDR667 + DDR800, TWO_DIMM, TWO_DIMM, 0, 1, 2},
116   {DDR1066 + DDR1333 + DDR1600, TWO_DIMM, TWO_DIMM, 0, 1, 1}
117 };
118 /*
119  * ODT Settings for 3 Dimms Per Channel
120  *
121  * Speeds Supported, # of Dimms, # of QRDimms, DramTerm, QR DramTerm, Dynamic DramTerm
122  */
123 STATIC CONST DRAM_TERM_ENTRY HyRDdr3DramTerm3D[] = {
124   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, ONE_DIMM, NO_DIMM, 1, 0, 0},
125   {DDR667 + DDR800 + DDR1066, TWO_DIMM, NO_DIMM, 3, 0, 2},
126   {DDR1333 + DDR1600, TWO_DIMM, NO_DIMM, 5, 0, 2},
127   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, THREE_DIMM, NO_DIMM, 3, 0, 2},
128   {DDR667 + DDR800 + DDR1066 + DDR1333, ONE_DIMM, ONE_DIMM, 0, 1, 2},
129   {DDR667 + DDR800, TWO_DIMM, ONE_DIMM, 5, 1, 2},
130   {DDR1066 + DDR1333 + DDR1600, TWO_DIMM, ONE_DIMM, 5, 1, 1},
131   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, THREE_DIMM, ONE_DIMM, 3, 1, 2}
132 };
133 /*
134  * POR Max Frequency supported for specific Dimm configurations for 1 Dimm Per Channel
135  *
136  * Dimm Config, # of Dimms, Max Freq @ 1.5V, Max Freq @ 1.35V, Max Freq @ 1.25
137  */
138 STATIC CONST POR_SPEED_LIMIT HyRDdr3PSPorFreqLimit1D[] = {
139   {SR_DIMM0 + DR_DIMM0, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
140   {QR_DIMM0, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0}
141 };
142 /*
143  * POR Max Frequency supported for specific Dimm configurations for 2 Dimms Per Channel
144  *
145  * Dimm Config, # of Dimms, Max Freq @ 1.5V, Max Freq @ 1.35V, Max Freq @ 1.25
146  */
147 STATIC CONST POR_SPEED_LIMIT HyRDdr3PSPorFreqLimit2D[] = {
148   {SR_DIMM1 + DR_DIMM1, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
149   {QR_DIMM1, 1, DDR1333_FREQUENCY, DDR1066_FREQUENCY, 0},
150   {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, 2, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
151   {QR_DIMM0 + ANY_DIMM1, 2, DDR1066_FREQUENCY, DDR800_FREQUENCY, 0},
152   {ANY_DIMM0 + QR_DIMM1, 2, DDR1066_FREQUENCY, DDR800_FREQUENCY, 0}
153 };
154 /*
155  * POR Max Frequency supported for specific Dimm configurations for 3 Dimms Per Channel
156  *
157  * Dimm Config, # of Dimms, Max Freq @ 1.5V, Max Freq @ 1.35V, Max Freq @ 1.25
158  */
159 STATIC CONST POR_SPEED_LIMIT HyRDdr3PSPorFreqLimit3D[] = {
160   {SR_DIMM2 + DR_DIMM2, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
161   {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, 2, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
162   {QR_DIMM1, 1, DDR1066_FREQUENCY, DDR1066_FREQUENCY, 0},
163   {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, 2, DDR800_FREQUENCY, DDR800_FREQUENCY, 0},
164   {SR_DIMM0 + SR_DIMM1 + SR_DIMM2, 3, DDR1066_FREQUENCY, DDR1066_FREQUENCY, 0},
165   {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, 3, DDR1066_FREQUENCY, DDR800_FREQUENCY, 0},
166   {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, 3, DDR800_FREQUENCY, DDR667_FREQUENCY, 0}
167 };
168
169 /* -----------------------------------------------------------------------------*/
170 /**
171  *
172  *     This function is the constructor platform specific settings for R DIMM-DDR3 HY DDR3
173  *
174  *     @param[in,out]   *MemPtr           Pointer to MEM_DATA_STRUCTURE
175  *     @param[in,out]   *ChannelPtr       Pointer to CH_DEF_STRUCT
176  *     @param[in,out]   *PsPtr       Pointer to MEM_PS_BLOCK
177  *
178  *     @return          AGESA_SUCCESS
179  *
180  */
181
182 AGESA_STATUS
183 MemPConstructPsRHy3 (
184   IN OUT   MEM_DATA_STRUCT *MemPtr,
185   IN OUT   CH_DEF_STRUCT *ChannelPtr,
186   IN OUT   MEM_PS_BLOCK *PsPtr
187   )
188 {
189   ASSERT (MemPtr != 0);
190   ASSERT (ChannelPtr != 0);
191
192   if ((ChannelPtr->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_HY) == 0) {
193     return AGESA_UNSUPPORTED;
194   }
195   if (ChannelPtr->TechType != DDR3_TECHNOLOGY) {
196     return AGESA_UNSUPPORTED;
197   }
198   if (ChannelPtr->RegDimmPresent != ChannelPtr->ChDimmValid) {
199     return AGESA_UNSUPPORTED;
200   }
201   PsPtr->MemPDoPs = MemPDoPsRHy3;
202   PsPtr->MemPGetPORFreqLimit = MemPGetPORFreqLimitRHy3;
203
204   return AGESA_SUCCESS;
205 }
206
207 /* -----------------------------------------------------------------------------*/
208 /**
209  *
210  *     This is function sets the platform specific settings for R-DDR3 HY DDR3
211  *
212  *     @param[in,out]   *NBPtr           Pointer to MEM_NB_BLOCK
213  *
214  *     @return          TRUE - Find settings for corresponding platform and dimm population.
215  *     @return          FALSE - Fail to find settings for corresponding platform and dimm population.
216  *
217  */
218
219 BOOLEAN
220 STATIC
221 MemPDoPsRHy3 (
222   IN OUT   MEM_NB_BLOCK *NBPtr
223   )
224 {
225   CONST DRAM_TERM_ENTRY *DramTermPtr;
226   UINT8 MaxDimmsPerChannel;
227   UINT8 *DimmsPerChPtr;
228   UINT8 DramTermSize;
229
230   DramTermSize = 0;
231   DramTermPtr = NULL;
232   DimmsPerChPtr = FindPSOverrideEntry (NBPtr->RefPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, NBPtr->MCTPtr->SocketId, NBPtr->ChannelPtr->ChannelID, 0, NULL, NULL);
233   if (DimmsPerChPtr != NULL) {
234     MaxDimmsPerChannel = *DimmsPerChPtr;
235   } else {
236     MaxDimmsPerChannel = 2;
237   }
238
239   if ((MaxDimmsPerChannel == 1) || (MaxDimmsPerChannel == 2)) {
240     DramTermSize = GET_SIZE_OF (HyRDdr3DramTerm2D);
241     DramTermPtr = HyRDdr3DramTerm2D;
242   } else if (MaxDimmsPerChannel == 3) {
243     DramTermSize = GET_SIZE_OF (HyRDdr3DramTerm3D);
244     DramTermPtr = HyRDdr3DramTerm3D;
245   } else {
246     IDS_ERROR_TRAP;
247   }
248
249   if (!MemPGetDramTerm (NBPtr, DramTermSize, DramTermPtr)) {
250     return FALSE;
251   }
252   //
253   // Special Cases for certain configs not covered by the table
254   //
255   // 3DPCH Fully populated.
256   if ((MaxDimmsPerChannel == 3) && (NBPtr->ChannelPtr->Dimms == 3)) {
257     NBPtr->PsPtr->DramTerm = 5; //30 Ohms
258     NBPtr->PsPtr->QR_DramTerm = 1; // 60 Ohms
259   }
260   return TRUE;
261 }
262
263 /* -----------------------------------------------------------------------------*/
264 /**
265  *
266  *     This is function gets the POR speed limit for R-DDR3 HY
267  *
268  *     @param[in,out]   *NBPtr           Pointer to MEM_NB_BLOCK
269  *
270  *
271  */
272 VOID
273 STATIC
274 MemPGetPORFreqLimitRHy3 (
275   IN OUT   MEM_NB_BLOCK *NBPtr
276   )
277 {
278   UINT8 *DimmsPerChPtr;
279   UINT8 MaxDimmPerCH;
280   UINT8 FreqLimitSize;
281   UINT16 SpeedLimit;
282   CONST POR_SPEED_LIMIT *FreqLimitPtr;
283   DCT_STRUCT *DCTPtr;
284
285   DCTPtr = NBPtr->DCTPtr;
286   DimmsPerChPtr = FindPSOverrideEntry (NBPtr->RefPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, NBPtr->MCTPtr->SocketId, NBPtr->ChannelPtr->ChannelID, 0, NULL, NULL);
287   if (DimmsPerChPtr != NULL) {
288     MaxDimmPerCH = *DimmsPerChPtr;
289   } else {
290     MaxDimmPerCH = 2;
291   }
292
293   if (MaxDimmPerCH == 4) {
294     DCTPtr->Timings.DimmExclude |= DCTPtr->Timings.DctDimmValid;
295     PutEventLog (AGESA_CRITICAL, MEM_ERROR_UNSUPPORTED_DIMM_CONFIG, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
296     SetMemError (AGESA_CRITICAL, NBPtr->MCTPtr);
297     // Change target speed to highest value so it won't affect other channels when leveling frequency across the node.
298     NBPtr->DCTPtr->Timings.TargetSpeed = UNSUPPORTED_DDR_FREQUENCY;
299     return;
300   } else if (MaxDimmPerCH == 3) {
301     FreqLimitPtr = HyRDdr3PSPorFreqLimit3D;
302     FreqLimitSize = GET_SIZE_OF (HyRDdr3PSPorFreqLimit3D);
303   } else if (MaxDimmPerCH == 2) {
304     FreqLimitPtr = HyRDdr3PSPorFreqLimit2D;
305     FreqLimitSize = GET_SIZE_OF (HyRDdr3PSPorFreqLimit2D);
306   } else {
307     FreqLimitPtr = HyRDdr3PSPorFreqLimit1D;
308     FreqLimitSize = GET_SIZE_OF (HyRDdr3PSPorFreqLimit1D);
309   }
310
311   SpeedLimit = MemPGetPorFreqLimit (NBPtr, FreqLimitSize, FreqLimitPtr);
312
313   if (SpeedLimit != 0) {
314     if (DCTPtr->Timings.TargetSpeed > SpeedLimit) {
315       DCTPtr->Timings.TargetSpeed = SpeedLimit;
316     }
317   } else {
318     DCTPtr->Timings.DimmExclude |= DCTPtr->Timings.DctDimmValid;
319     PutEventLog (AGESA_CRITICAL, MEM_ERROR_UNSUPPORTED_DIMM_CONFIG, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
320     SetMemError (AGESA_CRITICAL, NBPtr->MCTPtr);
321     // Change target speed to highest value so it won't affect other channels when leveling frequency across the node.
322     NBPtr->DCTPtr->Timings.TargetSpeed = UNSUPPORTED_DDR_FREQUENCY;
323   }
324 }