AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Ps / C32 / mprc32_3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mprc32_3.c
6  *
7  * Platform specific settings for C32 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
47 #include "AGESA.h"
48 #include "AdvancedApi.h"
49 #include "mport.h"
50 #include "ma.h"
51 #include "Ids.h"
52 #include "cpuFamRegisters.h"
53 #include "mm.h"
54 #include "mn.h"
55 #include "mp.h"
56 #include "mu.h"
57 #include "OptionMemory.h"
58 #include "PlatformMemoryConfiguration.h"
59 #include "GeneralServices.h"
60 #include "Filecode.h"
61 CODE_GROUP (G2_PEI)
62 RDATA_GROUP (G2_PEI)
63 #define FILECODE PROC_MEM_PS_C32_MPRC32_3_FILECODE
64 /*----------------------------------------------------------------------------
65  *                          DEFINITIONS AND MACROS
66  *
67  *----------------------------------------------------------------------------
68  */
69 #define AMD_FAMILY_10_C32    AMD_FAMILY_10_HY
70
71 /*----------------------------------------------------------------------------
72  *                           TYPEDEFS AND STRUCTURES
73  *
74  *----------------------------------------------------------------------------
75  */
76
77 /*----------------------------------------------------------------------------
78  *                        PROTOTYPES OF LOCAL FUNCTIONS
79  *
80  *----------------------------------------------------------------------------
81  */
82 BOOLEAN
83 STATIC
84 MemPDoPsRC32_3 (
85   IN OUT   MEM_NB_BLOCK *NBPtr
86   );
87
88 VOID
89 STATIC
90 MemPGetPORFreqLimitRC32_3 (
91   IN OUT   MEM_NB_BLOCK *NBPtr
92   );
93 /*
94  *-----------------------------------------------------------------------------
95  *                                EXPORTED FUNCTIONS
96  *
97  *-----------------------------------------------------------------------------
98  */
99
100 /*
101  * ODT Settings for 1 or 2 Dimms Per Channel
102  *
103  * Speeds Supported, # of Dimms, # of QRDimms, DramTerm, QR DramTerm, Dynamic DramTerm
104  */
105 STATIC CONST DRAM_TERM_ENTRY C32RDdr3DramTerm2D[] = {
106   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, ONE_DIMM, NO_DIMM, 1, 0, 0},
107   {DDR667 + DDR800 + DDR1066, TWO_DIMM, NO_DIMM, 3, 0, 2},
108   {DDR1333, TWO_DIMM, NO_DIMM, 5, 0, 2},
109   {DDR1600, TWO_DIMM, NO_DIMM, 5, 0, 1},
110   {DDR667 + DDR800 + DDR1066 + DDR1333, ONE_DIMM, ONE_DIMM, 0, 1, 2},
111   {DDR1600, ONE_DIMM, ONE_DIMM, 0, 1, 1},
112   {DDR667 + DDR800, TWO_DIMM, ONE_DIMM, 5, 1, 2},
113   {DDR1066 + DDR1333 + DDR1600, TWO_DIMM, ONE_DIMM, 5, 1, 1},
114   {DDR667 + DDR800, TWO_DIMM, TWO_DIMM, 0, 1, 2},
115   {DDR1066 + DDR1333 + DDR1600, TWO_DIMM, TWO_DIMM, 0, 1, 1}
116 };
117 /*
118  * ODT Settings for 3 Dimms Per Channel
119  *
120  * Speeds Supported, # of Dimms, # of QRDimms, DramTerm, QR DramTerm, Dynamic DramTerm
121  */
122 STATIC CONST DRAM_TERM_ENTRY C32RDdr3DramTerm3D[] = {
123   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, ONE_DIMM, NO_DIMM, 1, 0, 0},
124   {DDR667 + DDR800 + DDR1066, TWO_DIMM, NO_DIMM, 3, 0, 2},
125   {DDR1333 + DDR1600, TWO_DIMM, NO_DIMM, 5, 0, 2},
126   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, THREE_DIMM, NO_DIMM, 3, 0, 2},
127   {DDR667 + DDR800 + DDR1066 + DDR1333, ONE_DIMM, ONE_DIMM, 0, 1, 2},
128   {DDR667 + DDR800, TWO_DIMM, ONE_DIMM, 5, 1, 2},
129   {DDR1066 + DDR1333 + DDR1600, TWO_DIMM, ONE_DIMM, 5, 1, 1},
130   {DDR667 + DDR800 + DDR1066 + DDR1333 + DDR1600, THREE_DIMM, ONE_DIMM, 3, 1, 2}
131 };
132 /*
133  * POR Max Frequency supported for specific Dimm configurations for 1 Dimm Per Channel
134  *
135  * Dimm Config, # of Dimms, Max Freq @ 1.5V, Max Freq @ 1.35V, Max Freq @ 1.25
136  */
137 STATIC CONST POR_SPEED_LIMIT C32RDdr3PSPorFreqLimit1D[] = {
138   {SR_DIMM0 + DR_DIMM0, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
139   {QR_DIMM0, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0}
140 };
141 /*
142  * POR Max Frequency supported for specific Dimm configurations for 2 Dimms Per Channel
143  *
144  * Dimm Config, # of Dimms, Max Freq @ 1.5V, Max Freq @ 1.35V, Max Freq @ 1.25
145  */
146 STATIC CONST POR_SPEED_LIMIT C32RDdr3PSPorFreqLimit2D[] = {
147   {SR_DIMM1 + DR_DIMM1, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
148   {QR_DIMM1, 1, DDR1333_FREQUENCY, DDR1066_FREQUENCY, 0},
149   {SR_DIMM0 + SR_DIMM1, 2, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
150   {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1, 2, DDR1066_FREQUENCY, DDR1066_FREQUENCY, 0},
151   {QR_DIMM0 + ANY_DIMM1, 2, DDR800_FREQUENCY, DDR667_FREQUENCY, 0},
152   {ANY_DIMM0 + QR_DIMM1, 2, DDR800_FREQUENCY, DDR667_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 C32RDdr3PSPorFreqLimit3D[] = {
160   {SR_DIMM2 + DR_DIMM2, 1, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
161   {SR_DIMM0 + SR_DIMM2, 2, DDR1333_FREQUENCY, DDR1333_FREQUENCY, 0},
162   {SR_DIMM0 + DR_DIMM0 + SR_DIMM2 + DR_DIMM2, 2, DDR1066_FREQUENCY, DDR1066_FREQUENCY, 0},
163   {QR_DIMM1, 1, DDR800_FREQUENCY, DDR800_FREQUENCY, 0},
164   {QR_DIMM1 + SR_DIMM2 + DR_DIMM2, 2, DDR800_FREQUENCY, DDR667_FREQUENCY, 0},
165   {SR_DIMM0 + SR_DIMM1 + SR_DIMM2, 3, DDR1066_FREQUENCY, DDR800_FREQUENCY, 0},
166   {SR_DIMM0 + DR_DIMM0 + SR_DIMM1 + DR_DIMM1 + SR_DIMM2 + DR_DIMM2, 3, DDR800_FREQUENCY, DDR800_FREQUENCY, 0},
167   {SR_DIMM0 + DR_DIMM0 + QR_DIMM1 + SR_DIMM2 + DR_DIMM2, 3, DDR667_FREQUENCY, DDR667_FREQUENCY, 0}
168
169 };
170 /* -----------------------------------------------------------------------------*/
171 /**
172  *
173  *     This function is the constructor platform specific settings for R DIMM-DDR3 C32 DDR3
174  *
175  *     @param[in,out]   *MemPtr           Pointer to MEM_DATA_STRUCTURE
176  *     @param[in,out]   *ChannelPtr       Pointer to CH_DEF_STRUCT
177  *     @param[in,out]   *PsPtr       Pointer to MEM_PS_BLOCK
178  *
179  *     @return          AGESA_SUCCESS
180  *
181  */
182
183 AGESA_STATUS
184 MemPConstructPsRC32_3 (
185   IN OUT   MEM_DATA_STRUCT *MemPtr,
186   IN OUT   CH_DEF_STRUCT *ChannelPtr,
187   IN OUT   MEM_PS_BLOCK *PsPtr
188   )
189 {
190   ASSERT (MemPtr != 0);
191   ASSERT (ChannelPtr != 0);
192
193   if ((ChannelPtr->MCTPtr->LogicalCpuid.Family & AMD_FAMILY_10_C32) == 0) {
194     return AGESA_UNSUPPORTED;
195   }
196   if (ChannelPtr->TechType != DDR3_TECHNOLOGY) {
197     return AGESA_UNSUPPORTED;
198   }
199   if (ChannelPtr->RegDimmPresent != ChannelPtr->ChDimmValid) {
200     return AGESA_UNSUPPORTED;
201   }
202   PsPtr->MemPDoPs = MemPDoPsRC32_3;
203   PsPtr->MemPGetPORFreqLimit = MemPGetPORFreqLimitRC32_3;
204   return AGESA_SUCCESS;
205 }
206
207 /* -----------------------------------------------------------------------------*/
208 /**
209  *
210  *     This is function sets the platform specific settings for R-DDR3 C32 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 MemPDoPsRC32_3 (
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 (C32RDdr3DramTerm2D);
241     DramTermPtr = C32RDdr3DramTerm2D;
242   } else if (MaxDimmsPerChannel == 3) {
243     DramTermSize = GET_SIZE_OF (C32RDdr3DramTerm3D);
244     DramTermPtr = C32RDdr3DramTerm3D;
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   // SR-SR-SR 1.5v @1066 (Currently only 3DPCH config at 1066)
256   if ((MaxDimmsPerChannel == 3) && (NBPtr->ChannelPtr->Dimms == 3) &&
257       (NBPtr->DCTPtr->Timings.Speed == DDR1066_FREQUENCY)) {
258     NBPtr->PsPtr->DramTerm = 5; //30 Ohms
259   }
260
261   return TRUE;
262 }
263
264 /* -----------------------------------------------------------------------------*/
265 /**
266  *
267  *     This is function gets the POR speed limit for R-DDR3 C32 DDR3
268  *
269  *     @param[in,out]   *NBPtr           Pointer to MEM_NB_BLOCK
270  *
271  *
272  */
273 VOID
274 STATIC
275 MemPGetPORFreqLimitRC32_3 (
276   IN OUT   MEM_NB_BLOCK *NBPtr
277   )
278 {
279   UINT8 *DimmsPerChPtr;
280   UINT8 MaxDimmPerCH;
281   UINT8 FreqLimitSize;
282   UINT16 SpeedLimit;
283   CONST POR_SPEED_LIMIT *FreqLimitPtr;
284   DCT_STRUCT *DCTPtr;
285
286   DCTPtr = NBPtr->DCTPtr;
287   DimmsPerChPtr = FindPSOverrideEntry (NBPtr->RefPtr->PlatformMemoryConfiguration, PSO_MAX_DIMMS, NBPtr->MCTPtr->SocketId, NBPtr->ChannelPtr->ChannelID, 0, NULL, NULL);
288   if (DimmsPerChPtr != NULL) {
289     MaxDimmPerCH = *DimmsPerChPtr;
290   } else {
291     MaxDimmPerCH = 2;
292   }
293
294   if (MaxDimmPerCH == 4) {
295     DCTPtr->Timings.DimmExclude |= DCTPtr->Timings.DctDimmValid;
296     PutEventLog (AGESA_CRITICAL, MEM_ERROR_UNSUPPORTED_DIMM_CONFIG, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
297     SetMemError (AGESA_CRITICAL, NBPtr->MCTPtr);
298     // Change target speed to highest value so it won't affect other channels when leveling frequency across the node.
299     NBPtr->DCTPtr->Timings.TargetSpeed = UNSUPPORTED_DDR_FREQUENCY;
300     return;
301   } else if (MaxDimmPerCH == 3) {
302     FreqLimitPtr = C32RDdr3PSPorFreqLimit3D;
303     FreqLimitSize = GET_SIZE_OF (C32RDdr3PSPorFreqLimit3D);
304   } else if (MaxDimmPerCH == 2) {
305     FreqLimitPtr = C32RDdr3PSPorFreqLimit2D;
306     FreqLimitSize = GET_SIZE_OF (C32RDdr3PSPorFreqLimit2D);
307   } else {
308     FreqLimitPtr = C32RDdr3PSPorFreqLimit1D;
309     FreqLimitSize = GET_SIZE_OF (C32RDdr3PSPorFreqLimit1D);
310   }
311
312   SpeedLimit = MemPGetPorFreqLimit (NBPtr, FreqLimitSize, FreqLimitPtr);
313
314   if (SpeedLimit != 0) {
315     if (DCTPtr->Timings.TargetSpeed > SpeedLimit) {
316       DCTPtr->Timings.TargetSpeed = SpeedLimit;
317     }
318   } else {
319     DCTPtr->Timings.DimmExclude |= DCTPtr->Timings.DctDimmValid;
320     PutEventLog (AGESA_CRITICAL, MEM_ERROR_UNSUPPORTED_DIMM_CONFIG, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader);
321     SetMemError (AGESA_CRITICAL, NBPtr->MCTPtr);
322     // Change target speed to highest value so it won't affect other channels when leveling frequency across the node.
323     NBPtr->DCTPtr->Timings.TargetSpeed = UNSUPPORTED_DDR_FREQUENCY;
324   }
325 }