AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Recovery / Mem / Ps / mrp.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mrp.c
6  *
7  * Common platform specific configuration.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Proc/Recovery/Mem/Ps)
12  * @e \$Revision: 44324 $ @e \$Date: 2010-12-22 02:16:51 -0700 (Wed, 22 Dec 2010) $
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  *                                MODULES USED
48  *
49  *----------------------------------------------------------------------------
50  */
51
52
53
54 #include "AGESA.h"
55 #include "AdvancedApi.h"
56 #include "amdlib.h"
57 #include "Ids.h"
58 #include "cpuFamRegisters.h"
59 #include "cpuRegisters.h"
60 #include "OptionMemory.h"
61 #include "ma.h"
62 #include "mp.h"
63 #include "Filecode.h"
64 CODE_GROUP (G2_PEI)
65 RDATA_GROUP (G2_PEI)
66
67 #define FILECODE PROC_RECOVERY_MEM_PS_MRP_FILECODE
68
69
70 /*----------------------------------------------------------------------------
71  *                          DEFINITIONS AND MACROS
72  *
73  *----------------------------------------------------------------------------
74  */
75
76 /*----------------------------------------------------------------------------
77  *                           TYPEDEFS AND STRUCTURES
78  *
79  *----------------------------------------------------------------------------
80  */
81 /*----------------------------------------------------------------------------
82  *                        PROTOTYPES OF LOCAL FUNCTIONS
83  *
84  *----------------------------------------------------------------------------
85  */
86 /*----------------------------------------------------------------------------
87  *                            EXPORTED FUNCTIONS
88  *
89  *----------------------------------------------------------------------------
90  */
91 extern MEM_PSC_FLOW_BLOCK* memRecPlatSpecFlowArray[];
92
93 /* -----------------------------------------------------------------------------*/
94 /**
95  *
96  *    This function gets platform specific configuration such as Max Freq., Slow Mode, Dram Term,
97  *    and so on.
98  *
99  *     @param[in]       *NBPtr       Pointer to MEM_NB_BLOCK
100  *     @return          TRUE - Successfully execute platform specific configuration flow.
101  *     @return          FALSE - Fail to execute platform specific configuration flow.
102  *
103  */
104 BOOLEAN
105 MemPRecPSCFlow (
106   IN OUT   MEM_NB_BLOCK *NBPtr
107   )
108 {
109   UINT8 i;
110
111   i = 0;
112   while (memRecPlatSpecFlowArray[i] != NULL) {
113     if ((memRecPlatSpecFlowArray[i])->DramTerm (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
114       if ((memRecPlatSpecFlowArray[i])->ODTPattern (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
115         if ((memRecPlatSpecFlowArray[i])->SAO (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
116           if ((memRecPlatSpecFlowArray[i])->MR0WrCL (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
117             if ((memRecPlatSpecFlowArray[i])->RC2IBT (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
118               if ((memRecPlatSpecFlowArray[i])->RC10OpSpeed (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
119                 if ((memRecPlatSpecFlowArray[i])->LRIBT (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
120                   if ((memRecPlatSpecFlowArray[i])->LRNPR (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
121                     if ((memRecPlatSpecFlowArray[i])->LRNLR (NBPtr, (memRecPlatSpecFlowArray[i])->EntryOfTables)) {
122                       return TRUE;
123                     }
124                   }
125                 }
126               }
127             }
128           }
129         }
130       }
131     }
132     i++;
133   }
134   return FALSE;
135 }
136
137 /* -----------------------------------------------------------------------------*/
138 /**
139  *
140  *     This function constructs the rank type map of Dimm0, Dimm1, Dimm2. Also it counts the number
141  *     of dimm in the table.
142  *
143  *     @param[in]       Dimm0       Rank type of Dimm0
144  *     @param[in]       Dimm1       Rank type of Dimm1
145  *     @param[in]       Dimm2       Rank type of Dimm2
146  *     @param[in, out]       *RankTypeInTable       Pointer to RankTypeInTable variable
147  *
148  *
149  */
150 VOID
151 MemPRecConstructRankTypeMap (
152   IN       UINT16 Dimm0,
153   IN       UINT16 Dimm1,
154   IN       UINT16 Dimm2,
155   IN OUT   UINT16 *RankTypeInTable
156   )
157 {
158   UINT8 i;
159   UINT16 RT;
160   UINT8 BitShift;
161
162   *RankTypeInTable = 0;
163   RT = 0;
164   BitShift = 0;
165
166   for (i = 0; i < MAX_DIMMS_PER_CHANNEL; i++) {
167     switch (i) {
168     case 0:
169       RT = (Dimm0 == 0) ? NP : Dimm0;
170       BitShift = 0;
171       break;
172     case 1:
173       RT = (Dimm1 == 0) ? NP : Dimm1;
174       BitShift = 4;
175       break;
176     case 2:
177       RT = (Dimm2 == 0) ? NP : Dimm2;
178       BitShift = 8;
179       break;
180     default:
181       // dimm3 is not used, fills nibble3 with "NP"
182       RT = NP;
183       BitShift = 12;
184     }
185     *RankTypeInTable |= RT << BitShift;
186   }
187 }
188
189 /*-----------------------------------------------------------------------------*/
190 /**
191  *     MemPIsIdSupported
192  *      This function matches the CPU_LOGICAL_ID and PackageType with certain criteria to
193  *      determine if it is supported by this NB type.
194  *
195  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
196  *     @param[in]       LogicalId - CPU_LOGICAL_ID
197  *     @param[in]       PackageType - Package Type
198  *
199  *     @return          TRUE -  NB type is matched !
200  *     @return          FALSE - NB type is not matched !
201  *
202  */
203 BOOLEAN
204 MemPRecIsIdSupported (
205   IN OUT   MEM_NB_BLOCK *NBPtr,
206   IN       CPU_LOGICAL_ID LogicalId,
207   IN       UINT8 PackageType
208   )
209 {
210   CPUID_DATA CpuId;
211   UINT8 PkgType;
212
213   LibAmdCpuidRead (AMD_CPUID_FMF, &CpuId, &(NBPtr->MemPtr->StdHeader));
214   PkgType = (UINT8) (CpuId.EBX_Reg >> 28) & 0xF; // bit 31:28
215
216   if (((NBPtr->MCTPtr->LogicalCpuid.Family & LogicalId.Family) != 0)
217       && ((NBPtr->MCTPtr->LogicalCpuid.Revision & LogicalId.Revision) != 0)) {
218     if ((PackageType == PT_DONT_CARE) || (PackageType == PkgType)) {
219       return TRUE;
220     }
221   }
222   return FALSE;
223 }
224
225 /* -----------------------------------------------------------------------------*/
226 /**
227  *
228  *    This function returns the rank type map of a channel.
229  *
230  *     @param[in]       *CurrentChannel       Pointer to CH_DEF_STRUCT
231  *
232  *     @return          UINT16 - The map of rank type.
233  *
234  */
235 UINT16
236 MemPRecGetPsRankType (
237   IN       CH_DEF_STRUCT *CurrentChannel
238   )
239 {
240   UINT8 i;
241   UINT16 DIMMRankType;
242
243   DIMMRankType = 0;
244   for (i = 0; i < MAX_DIMMS_PER_CHANNEL; i++) {
245     if ((CurrentChannel->DimmQrPresent & (UINT8) 1 << i) != 0) {
246       if (i < 2) {
247         DIMMRankType |= (UINT16) 8 << (i << 2);
248       }
249     } else if ((CurrentChannel->DimmDrPresent & (UINT8) 1 << i) != 0) {
250       DIMMRankType |= (UINT16) 4 << (i << 2);
251     } else if ((CurrentChannel->DimmSRPresent & (UINT8) 1 << i) != 0) {
252       DIMMRankType |= (UINT16) 2 << (i << 2);
253     } else {
254       DIMMRankType |= (UINT16) 1 << (i << 2);
255     }
256   }
257   return DIMMRankType;
258 }