AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / NB / OR / mnmctor.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mnmctor.c
6  *
7  * Northbridge Orochi MCT supporting functions
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/NB/OR)
12  * @e \$Revision: 51634 $ @e \$Date: 2011-04-26 03:12:52 -0600 (Tue, 26 Apr 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  *----------------------------------------------------------------------------
48  *                                MODULES USED
49  *
50  *----------------------------------------------------------------------------
51  */
52
53
54
55 #include "AGESA.h"
56 #include "amdlib.h"
57 #include "Ids.h"
58 #include "mport.h"
59 #include "mm.h"
60 #include "mn.h"
61 #include "OptionMemory.h"       // need def for MEM_FEAT_BLOCK_NB
62 #include "cpuFeatures.h"
63 #include "mnor.h"
64 #include "Filecode.h"
65 CODE_GROUP (G3_DXE)
66 RDATA_GROUP (G3_DXE)
67
68
69 #define FILECODE PROC_MEM_NB_OR_MNMCTOR_FILECODE
70 /*----------------------------------------------------------------------------
71  *                          DEFINITIONS AND MACROS
72  *
73  *----------------------------------------------------------------------------
74  */
75
76 /*----------------------------------------------------------------------------
77  *                           TYPEDEFS AND STRUCTURES
78  *
79  *----------------------------------------------------------------------------
80  */
81
82 /*----------------------------------------------------------------------------
83  *                        PROTOTYPES OF LOCAL FUNCTIONS
84  *
85  *----------------------------------------------------------------------------
86  */
87
88
89 /*----------------------------------------------------------------------------
90  *                            EXPORTED FUNCTIONS
91  *
92  *----------------------------------------------------------------------------
93  */
94 extern BUILD_OPT_CFG UserOptions;
95
96 /* -----------------------------------------------------------------------------*/
97 /**
98  *
99  *
100  *   This function sets final values for specific registers.
101  *
102  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
103  *
104  *     @return          TRUE -  No fatal error occurs.
105  *     @return          FALSE - Fatal error occurs.
106  */
107
108 BOOLEAN
109 MemNFinalizeMctOr (
110   IN OUT   MEM_NB_BLOCK *NBPtr
111   )
112 {
113   MEM_DATA_STRUCT *MemPtr;
114   MEM_PARAMETER_STRUCT *RefPtr;
115   DRAM_PREFETCH_MODE DramPrefetchMode;
116   UINT16 Speed;
117   UINT32 Value32;
118   UINT8 DcqBwThrotWm;
119   UINT8 DcqBwThrotWm1;
120   UINT8 DcqBwThrotWm2;
121   UINT8 Dct;
122
123   MemPtr = NBPtr->MemPtr;
124   RefPtr = MemPtr->ParameterListPtr;
125   DramPrefetchMode = MemPtr->PlatFormConfig->PlatformProfile.AdvancedPerformanceProfile.DramPrefetchMode;
126   Speed = NBPtr->DCTPtr->Timings.Speed;
127   //
128   // F2x11C
129   //
130   // FlushWrOnStpGnt = 0
131   // PrefThreeConf = 110b
132   // PrefTwoConf = 011b
133   // PrefOneConf = 10b
134   // PrefConfSat = 00b
135   // PrefIoDis = 0
136   // PrefCpuDis = 0
137   // MctWrLimit = 10h
138   // DctWrLimit = 01b
139   Value32 = MemNGetBitFieldNb (NBPtr, BFMctCfgHiReg);
140   Value32 &= 0xD003CF80;
141   Value32 |= 0x0CE00041;
142   MemNSetBitFieldNb (NBPtr, BFMctCfgHiReg, Value32);
143
144   if (DramPrefetchMode == DISABLE_DRAM_PREFETCH_FOR_IO || DramPrefetchMode == DISABLE_DRAM_PREFETCHER) {
145     MemNSetBitFieldNb (NBPtr, BFPrefIoDis, 1);
146   }
147
148   if (DramPrefetchMode == DISABLE_DRAM_PREFETCH_FOR_CPU || DramPrefetchMode == DISABLE_DRAM_PREFETCHER) {
149     MemNSetBitFieldNb (NBPtr, BFPrefCpuDis, 1);
150   }
151
152   if (Speed == DDR667_FREQUENCY) {
153     DcqBwThrotWm = 0;
154     DcqBwThrotWm1 = 3;
155     DcqBwThrotWm2 = 4;
156   } else if (Speed == DDR800_FREQUENCY) {
157     DcqBwThrotWm = 0;
158     DcqBwThrotWm1 = 3;
159     DcqBwThrotWm2 = 5;
160   } else if (Speed == DDR1066_FREQUENCY) {
161     DcqBwThrotWm = 0;
162     DcqBwThrotWm1 = 4;
163     DcqBwThrotWm2 = 6;
164   } else if (Speed == DDR1333_FREQUENCY) {
165     DcqBwThrotWm = 0;
166     DcqBwThrotWm1 = 5;
167     DcqBwThrotWm2 = 8;
168   } else if  (Speed == DDR1600_FREQUENCY) {
169     DcqBwThrotWm = 0;
170     DcqBwThrotWm1 = 6;
171     DcqBwThrotWm2 = 9;
172   } else if  (Speed == DDR1866_FREQUENCY) {
173     DcqBwThrotWm = 0;
174     DcqBwThrotWm1 = 7;
175     DcqBwThrotWm2 = 10;
176   } else {
177     DcqBwThrotWm = 0;
178     DcqBwThrotWm1 = 8;
179     DcqBwThrotWm2 = 12;
180   }
181
182   //
183   // F2x1B0
184   //
185   // DcqBwThrotWm
186   // PrefFiveConf = 111b
187   // PrefFourConf = 111b
188   // EnSplitDctLimits = 1
189   // CohPrefPrbLmt = IF (PrbFltrEn) THEN 000b ELSE 001b ENDIF
190   // AdapPrefNegativeStep = 00b
191   // AdapPrefPositiveStep = 00b
192   // AdapPrefMissRatio = 01b
193   Value32 = MemNGetBitFieldNb (NBPtr, BFExtMctCfgLoReg);
194   Value32 &= 0x003FE8C0;
195   Value32 |= 0x0FC01001;
196   Value32 |= (UINT32) DcqBwThrotWm << 28;
197   MemNSetBitFieldNb (NBPtr, BFExtMctCfgLoReg, Value32);
198
199   //
200   // F2x1B4
201   //
202   // DcqBwThrotWm2
203   // DcqBwThrotWm1
204   Value32 = MemNGetBitFieldNb (NBPtr, BFExtMctCfgHiReg);
205   Value32 &= 0xF7FFFC00;
206   Value32 |= (((UINT32) DcqBwThrotWm2 << 5) | (UINT32) DcqBwThrotWm1);
207   // FlushWrOnS3StpGnt to 1
208   Value32 |= (UINT32) 1 << 27;
209   MemNSetBitFieldNb (NBPtr, BFExtMctCfgHiReg, Value32);
210
211   for (Dct = 0; Dct < MAX_DCTS_PER_NODE_OR; Dct++) {
212     MemNSwitchDCTNb (NBPtr, Dct);
213
214     if (NBPtr->DCTPtr->Timings.DctMemSize != 0) {
215       //
216       // Phy Power Saving
217       //
218       MemNPhyPowerSavingUnb (NBPtr);
219       //
220       // Power Down Enable
221       //
222       if (NBPtr->RefPtr->EnablePowerDown) {
223         MemNSetBitFieldNb (NBPtr, BFPowerDownEn, 1);
224       }
225     }
226   }
227
228   // Set LockDramCfg
229   if (IsFeatureEnabled (C6Cstate, NBPtr->MemPtr->PlatFormConfig, &(NBPtr->MemPtr->StdHeader))) {
230     IDS_SKIP_HOOK (IDS_TRACE_MODE, NBPtr, &NBPtr->MemPtr->StdHeader) {
231         MemNSetBitFieldNb (NBPtr, BFLockDramCfg, 1);
232     }
233   }
234
235   return (BOOLEAN) (NBPtr->MCTPtr->ErrCode < AGESA_FATAL);
236 }
237
238
239 /*----------------------------------------------------------------------------
240  *                              LOCAL FUNCTIONS
241  *
242  *----------------------------------------------------------------------------
243  */
244  /*-----------------------------------------------------------------------------
245  *
246  *
247  *     This function handles scrubber register settings for orochi.
248  *
249  *     @param[in,out]  *NBPtr     - Pointer to the MEM_NB_BLOCK
250  *     @param[in,out]  OptParam   - If the function is called before scrub rate is set or after
251  *                                  TRUE    function is called before scrub rate is set
252  *                                  FALSE   function is called after scrub rate is set
253  *
254  *     @return    TRUE
255  * ----------------------------------------------------------------------------
256  */
257 BOOLEAN
258 MemNScrubberErratumOr (
259   IN OUT   MEM_NB_BLOCK *NBPtr,
260   IN OUT   VOID *OptParam
261   )
262 {
263   UINT8 L3Scrub;
264   UINT8 DramScrub;
265
266   if (*(BOOLEAN *) OptParam == TRUE) {
267     MemNSwitchDCTNb (NBPtr, 0);
268   } else {
269     ASSERT (NBPtr->Dct == 0);
270     L3Scrub = (UINT8) MemNGetBitFieldNb (NBPtr, BFL3Scrub);
271     DramScrub = (UINT8) MemNGetBitFieldNb (NBPtr, BFDramScrub);
272
273     // Set scrubber for DCT1
274     MemNSwitchDCTNb (NBPtr, 1);
275     MemNSetBitFieldNb (NBPtr, BFL3Scrub, L3Scrub);
276     MemNSetBitFieldNb (NBPtr, BFDramScrub, DramScrub);
277   }
278
279   return TRUE;
280 }
281
282 /* -----------------------------------------------------------------------------*/
283 /**
284  *
285  *
286  *   This function changes DataTxFifoWrDly based on training result of WrDatDly
287  *
288  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
289  *     @param[in,out]  OptParam   - Optional parameter
290  *
291  *     @return    TRUE
292  */
293
294 BOOLEAN
295 MemNDataTxFifoWrDlyOverrideOr (
296   IN OUT   MEM_NB_BLOCK *NBPtr,
297   IN OUT   VOID *OptParam
298   )
299 {
300   UINT8 i;
301   UINT8 Dct;
302   UINT8 ByteLane;
303   UINT16 CsEnabled;
304   BOOLEAN DataTxFifoWrDly;
305
306   // This should be done only after DQS Position training
307   if (NBPtr->NbFreqChgState <= 1) {
308     return TRUE;
309   }
310
311   // Set DataTxFifoWrDly based on WrDatDly
312   // if all WrDatDly of populated dimms on a DCT are equal to 7h
313   // Set DataTxFifoWrDly to >= 2h
314   for (Dct = 0; Dct < 2; Dct ++) {
315     MemNSwitchDCTNb (NBPtr, Dct);
316     DataTxFifoWrDly = TRUE;
317     CsEnabled = NBPtr->DCTPtr->Timings.CsEnabled;
318     for (i = 0; i < MAX_DIMMS_PER_CHANNEL; i ++) {
319       if ((CsEnabled & (UINT16) (3 << (i << 1))) != 0) {
320         for (ByteLane = 0; ByteLane < (NBPtr->MCTPtr->Status[SbEccDimms] ? 9 : 8); ByteLane++) {
321           if ((GetTrainDlyFromHeapNb (NBPtr, AccessWrDatDly, DIMM_BYTE_ACCESS (i, ByteLane)) >> 5) != 7) {
322             DataTxFifoWrDly = FALSE;
323             break;
324           }
325         }
326         if (!DataTxFifoWrDly) {
327           break;
328         }
329       }
330     }
331
332     if (DataTxFifoWrDly) {
333       if (MemNGetBitFieldNb (NBPtr, BFDataTxFifoWrDly) < 2) {
334         MemNSetBitFieldNb (NBPtr, BFDataTxFifoWrDly, 2);
335       }
336     }
337   }
338
339   return TRUE;
340 }