AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x15 / OR / F15OrSharedMsrTable.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD Family_15 Orochi Shared MSR table with values as defined in BKDG
6  *
7  * @xrefitem bom "File Content Label" "Release Content"
8  * @e project:      AGESA
9  * @e sub-project:  CPU/Family/0x15/OR
10  * @e \$Revision: 53046 $   @e \$Date: 2011-05-13 20:20:37 -0600 (Fri, 13 May 2011) $
11  *
12  */
13 /*
14  ******************************************************************************
15  *
16  * Copyright (C) 2012 Advanced Micro Devices, Inc.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are met:
21  *     * Redistributions of source code must retain the above copyright
22  *       notice, this list of conditions and the following disclaimer.
23  *     * Redistributions in binary form must reproduce the above copyright
24  *       notice, this list of conditions and the following disclaimer in the
25  *       documentation and/or other materials provided with the distribution.
26  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
27  *       its contributors may be used to endorse or promote products derived
28  *       from this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  ******************************************************************************
42  */
43
44 /*----------------------------------------------------------------------------------------
45  *                             M O D U L E S    U S E D
46  *----------------------------------------------------------------------------------------
47  */
48 #include "AGESA.h"
49 #include "amdlib.h"
50 #include "cpuRegisters.h"
51 #include "Table.h"
52 #include "cpuServices.h"
53 #include "GeneralServices.h"
54 #include "cpuF15OrPowerMgmt.h"
55 #include "OptionMultiSocket.h"
56 #include "Filecode.h"
57 CODE_GROUP (G3_DXE)
58 RDATA_GROUP (G3_DXE)
59
60 #define FILECODE PROC_CPU_FAMILY_0X15_OR_F15ORSHAREDMSRTABLE_FILECODE
61
62
63 /*----------------------------------------------------------------------------------------
64  *                   D E F I N I T I O N S    A N D    M A C R O S
65  *----------------------------------------------------------------------------------------
66  */
67 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
68 /*----------------------------------------------------------------------------------------
69  *                  T Y P E D E F S     A N D     S T R U C T U R E S
70  *----------------------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------------------
74  *           P R O T O T Y P E S     O F     L O C A L     F U N C T I O N S
75  *----------------------------------------------------------------------------------------
76  */
77 VOID
78 F15OrFpCfgInit (
79   IN       UINT32              Data,
80   IN       AMD_CONFIG_PARAMS   *StdHeader
81   );
82
83 /*----------------------------------------------------------------------------------------
84  *                          E X P O R T E D    F U N C T I O N S
85  *----------------------------------------------------------------------------------------
86  */
87 STATIC CONST MSR_TYPE_ENTRY_INITIALIZER ROMDATA F15OrSharedMsrRegisters[] =
88 {
89 //  M S R    T a b l e s
90 // ----------------------
91
92 // MSR_TOM2 (0xC001001D)
93 // bits[63:0] - TOP_MEM2 = 0
94   {
95     MsrRegister,
96     {
97       AMD_FAMILY_15,                      // CpuFamily
98       AMD_F15_OR_ALL                      // CpuRevision
99     },
100     {AMD_PF_ALL},                         // platformFeatures
101     {{
102       MSR_TOM2,                           // MSR Address - Shared
103       0x0000000000000000,                 // OR Mask
104       0xFFFFFFFFFFFFFFFF,                 // NAND Mask
105     }}
106   },
107
108 // MSR_SYS_CFG (0xC0010010)
109 // bit[21] MtrrTom2En = 1
110   {
111     MsrRegister,
112     {
113       AMD_FAMILY_15,                      // CpuFamily
114       AMD_F15_OR_ALL                      // CpuRevision
115     },
116     {AMD_PF_ALL},                         // platformFeatures
117     {{
118       MSR_SYS_CFG,                        // MSR Address - Shared
119       (1 << 21),                          // OR Mask
120       (1 << 21),                          // NAND Mask
121     }}
122   },
123
124 // MSR_MC1_CTL_MASK (0xC0010045)
125 // bit[15] BSRP = 1, Erratum #593, OR-ALL
126 // bit[18] DEIBP = 1, Erratum #586, OR-ALL
127   {
128     MsrRegister,
129     {
130       AMD_FAMILY_15,                      // CpuFamily
131       AMD_F15_OR_ALL                      // CpuRevision
132     },
133     {AMD_PF_ALL},                         // platformFeatures
134     {{
135       MSR_MC1_CTL_MASK,                   // MSR Address
136       0x0000000000048000,                 // OR Mask
137       0x0000000000048000,                 // NAND Mask
138     }}
139   },
140
141 // MSR_CU_CFG (0xC0011023)
142 // bit[10] PbForceRespInOrder = 0
143   {
144     MsrRegister,
145     {
146       AMD_FAMILY_15,                    // CpuFamily
147       AMD_F15_OR_ALL                    // CpuRevision
148     },
149     {AMD_PF_ALL},                       // platformFeatures
150     {{
151       MSR_CU_CFG,                       // MSR Address - Shared
152       0,                                // OR Mask
153       0x00000400,                       // NAND Mask
154     }}
155   },
156
157 // MSR_DE_CFG (0xC0011029)
158 // bit[10] ResyncPredSingleDispDis = 1
159   {
160     MsrRegister,
161     {
162       AMD_FAMILY_15,                    // CpuFamily
163       AMD_F15_OR_ALL                    // CpuRevision
164     },
165     {AMD_PF_ALL},                       // platformFeatures
166     {{
167       MSR_DE_CFG,                       // MSR Address - Shared
168       0x0000000000000400,               // OR Mask
169       0x0000000000000400,               // NAND Mask
170     }}
171   },
172
173 // MSR_CU_CFG2 (0xC001102A)
174 // bit[50] = 1
175 // bit[11] = 1, Erratum #503, OR-ALL
176 // bit[10] = 1
177   {
178     MsrRegister,
179     {
180       AMD_FAMILY_15,                    // CpuFamily
181       AMD_F15_OR_ALL                    // CpuRevision
182     },
183     {AMD_PF_ALL},                       // platformFeatures
184     {{
185       MSR_CU_CFG2,                      // MSR Address - Shared
186       0x0004000000000C00,               // OR Mask
187       0x0004000000000C00,               // NAND Mask
188     }}
189   },
190
191 // MSR_CU_CFG3 (0xC001102B)
192 // bit[42] PwcDisableWalkerSharing = 1
193   {
194     MsrRegister,
195     {
196       AMD_FAMILY_15,                    // CpuFamily
197       AMD_F15_OR_ALL                    // CpuRevision
198     },
199     {AMD_PF_ALL},                       // platformFeatures
200     {{
201       MSR_CU_CFG3,                      // MSR Address
202       0x0000040000000000,               // OR Mask
203       0x0000040000000000,               // NAND Mask
204     }}
205   },
206 };
207
208
209 // Compute Unit Count Dependent MSR Table
210
211 STATIC CONST MSR_CU_TYPE_ENTRY_INITIALIZER ROMDATA F15OrSharedMsrCuRegisters[] =
212 {
213 //  M S R    T a b l e s
214 // ----------------------
215
216   // MSR_CU_CFG2 (0xC001102A)
217   // bits[7:6] - ThrottleNbInterface[1:0] = 0
218   // bits[37:36] - ThrottleNbInterface[3:2] = 0
219   {
220     CompUnitCountsMsr,
221     {
222       AMD_FAMILY_15,                      // CpuFamily
223       AMD_F15_OR_ALL                      // CpuRevision
224     },
225     {AMD_PF_ALL},                         // platformFeatures
226     {{
227           {(COMPUTE_UNIT_RANGE_0 (1, 1) | COUNT_RANGE_NONE)}, // 1 compute unit
228       {
229         MSR_CU_CFG2,                        // MSR Address - Shared
230         0x0000000000000000,                 // OR Mask
231         0x00000030000000C0,                 // NAND Mask
232       }
233     }}
234   },
235
236   // MSR_CU_CFG2 (0xC001102A)
237   // bits[7:6] - ThrottleNbInterface[1:0] = 1
238   // bits[37:36] - ThrottleNbInterface[3:2] = 0
239   {
240     CompUnitCountsMsr,
241     {
242       AMD_FAMILY_15,                      // CpuFamily
243       AMD_F15_OR_ALL                      // CpuRevision
244     },
245     {AMD_PF_ALL},                         // platformFeatures
246     {{
247           {(COMPUTE_UNIT_RANGE_0 (2, 2) | COUNT_RANGE_NONE)}, // 2 compute units
248       {
249         MSR_CU_CFG2,                        // MSR Address - Shared
250         0x0000000000000040,                 // OR Mask
251         0x00000030000000C0,                 // NAND Mask
252       }
253     }}
254   },
255
256   // MSR_CU_CFG2 (0xC001102A)
257   // bits[7:6] - ThrottleNbInterface[1:0] = 2
258   // bits[37:36] - ThrottleNbInterface[3:2] = 0
259   {
260     CompUnitCountsMsr,
261     {
262       AMD_FAMILY_15,                      // CpuFamily
263       AMD_F15_OR_ALL                      // CpuRevision
264     },
265     {AMD_PF_ALL},                         // platformFeatures
266     {{
267           {(COMPUTE_UNIT_RANGE_0 (3, 3) | COUNT_RANGE_NONE)}, // 3 compute units
268       {
269         MSR_CU_CFG2,                        // MSR Address - Shared
270         0x0000000000000080,                 // OR Mask
271         0x00000030000000C0,                 // NAND Mask
272       }
273     }}
274   },
275
276   // MSR_CU_CFG2 (0xC001102A)
277   // bits[7:6] - ThrottleNbInterface[1:0] = 3
278   // bits[37:36] - ThrottleNbInterface[3:2] = 0
279   {
280     CompUnitCountsMsr,
281     {
282       AMD_FAMILY_15,                      // CpuFamily
283       AMD_F15_OR_ALL                      // CpuRevision
284     },
285     {AMD_PF_ALL},                         // platformFeatures
286     {{
287           {(COMPUTE_UNIT_RANGE_0 (4, 4) | COUNT_RANGE_NONE)}, // 4 compute units
288       {
289         MSR_CU_CFG2,                        // MSR Address - Shared
290         0x00000000000000C0,                 // OR Mask
291         0x00000030000000C0,                 // NAND Mask
292       }
293     }}
294   },
295 };
296
297 // Shared MSRs with Special Programming Requirements Table
298
299 STATIC CONST FAM_SPECIFIC_WORKAROUND_TYPE_ENTRY_INITIALIZER ROMDATA F15OrSharedMsrWorkarounds[] =
300 {
301   // MSR_FP_CFG (0xC0011028)
302   // bit[16] -     DiDtMode = F3x1FC[0]
303   // bits[22:18] - DiDtCfg0 = F3x1FC[5:1]
304   // bits[34:27] - DiDtCfg1 = F3x1FC[13:6]
305   {
306     FamSpecificWorkaround,
307     {
308       AMD_FAMILY_15_OR,
309       AMD_F15_OR_ALL
310     },
311     {AMD_PF_ALL},
312     {{
313       F15OrFpCfgInit,
314       0x00000000
315     }}
316   },
317 };
318
319
320
321 CONST REGISTER_TABLE ROMDATA F15OrSharedMsrRegisterTable = {
322   CorePairPrimary,
323   (sizeof (F15OrSharedMsrRegisters) / sizeof (TABLE_ENTRY_FIELDS)),
324   (TABLE_ENTRY_FIELDS *) &F15OrSharedMsrRegisters,
325 };
326
327
328 CONST REGISTER_TABLE ROMDATA F15OrSharedMsrCuRegisterTable = {
329   CorePairPrimary,
330   (sizeof (F15OrSharedMsrCuRegisters) / sizeof (TABLE_ENTRY_FIELDS)),
331   (TABLE_ENTRY_FIELDS *) &F15OrSharedMsrCuRegisters,
332 };
333
334 CONST REGISTER_TABLE ROMDATA F15OrSharedMsrWorkaroundTable = {
335   CorePairPrimary,
336   (sizeof (F15OrSharedMsrWorkarounds) / sizeof (TABLE_ENTRY_FIELDS)),
337   (TABLE_ENTRY_FIELDS *) &F15OrSharedMsrWorkarounds,
338 };
339
340
341 /*---------------------------------------------------------------------------------------*/
342 /**
343  * Update the FP_CFG MSR in current processor for Family15h OR.
344  *
345  * This function satisfies the programming requirements for the FP_CFG MSR.
346  *
347  * @param[in]   Data         The table data value, for example to indicate which CPU and Platform types matched.
348  * @param[in]   StdHeader    Config handle for library and services.
349  *
350  */
351 VOID
352 F15OrFpCfgInit (
353   IN       UINT32              Data,
354   IN       AMD_CONFIG_PARAMS   *StdHeader
355   )
356 {
357   UINT32       ProductInfo;
358   UINT64       FpCfg;
359   PCI_ADDR     PciAddress;
360
361   if (IsWarmReset (StdHeader)) {
362     OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
363     PciAddress.Address.Function = FUNC_3;
364     PciAddress.Address.Register = PRCT_INFO_REG;
365     LibAmdPciRead (AccessWidth32, PciAddress, &ProductInfo, StdHeader);
366
367     LibAmdMsrRead (MSR_FP_CFG, &FpCfg, StdHeader);
368     ((FP_CFG_MSR *) &FpCfg)->DiDtMode = ((PRODUCT_INFO_REGISTER *) &ProductInfo)->DiDtMode;
369     ((FP_CFG_MSR *) &FpCfg)->DiDtCfg0 = ((PRODUCT_INFO_REGISTER *) &ProductInfo)->DiDtCfg0;
370     ((FP_CFG_MSR *) &FpCfg)->DiDtCfg1 = ((PRODUCT_INFO_REGISTER *) &ProductInfo)->DiDtCfg1;
371     ((FP_CFG_MSR *) &FpCfg)->AlwaysOnThrottle = ((PRODUCT_INFO_REGISTER *) &ProductInfo)->AlwaysOnThrottle;
372     ((FP_CFG_MSR *) &FpCfg)->Pipe3ThrottleDis = ((PRODUCT_INFO_REGISTER *) &ProductInfo)->Pipe3ThrottleDis;
373     LibAmdMsrWrite (MSR_FP_CFG, &FpCfg, StdHeader);
374   }
375 }
376