AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / NB / HY / mnothy.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mnothy.c
6  *
7  * Northbridge Non-SPD timings for Hydra
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/NB/HY)
12  * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 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 "Ids.h"
57 #include "mm.h"
58 #include "mn.h"
59 #include "OptionMemory.h"       // need def for MEM_FEAT_BLOCK_NB
60 #include "mnhy.h"
61 #include "Filecode.h"
62 CODE_GROUP (G1_PEICC)
63 RDATA_GROUP (G2_PEI)
64
65 #define FILECODE PROC_MEM_NB_HY_MNOTHY_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 VOID
84 STATIC
85 MemNSetOtherTimingHY (
86   IN OUT   MEM_NB_BLOCK *NBPtr
87   );
88
89 /*
90 UINT32
91 STATIC
92 MemNGetODTDelaysHy (
93   IN OUT   MEM_NB_BLOCK *NBPtr
94   );
95 */
96
97 /*----------------------------------------------------------------------------
98  *                            EXPORTED FUNCTIONS
99  *
100  *----------------------------------------------------------------------------
101  */
102
103 extern BUILD_OPT_CFG UserOptions;
104
105 /* -----------------------------------------------------------------------------*/
106 /**
107  *
108  *
109  *   This function sets the non-SPD timings
110  *
111  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
112  *
113  *     @return          TRUE -  No fatal error occurs.
114  *     @return          FALSE - Fatal error occurs.
115  */
116
117 BOOLEAN
118 MemNOtherTimingHy (
119   IN OUT   MEM_NB_BLOCK *NBPtr
120   )
121 {
122   MemNSwitchDCTNb (NBPtr, 0);
123   if (NBPtr->DCTPtr->Timings.DctDimmValid > 0) {
124     MemNSetOtherTimingHY (NBPtr);
125     MemNPowerDownCtlNb (NBPtr);
126     MemNEnDLLShutDownHy (NBPtr);
127   }
128
129   MemNSwitchDCTNb (NBPtr, 1);
130   if ((NBPtr->DCTPtr->Timings.DctDimmValid > 0) && (NBPtr->MCTPtr->GangedMode == FALSE)) {
131     MemNSetOtherTimingHY (NBPtr);
132     MemNPowerDownCtlNb (NBPtr);
133     MemNEnDLLShutDownHy (NBPtr);
134   }
135   return (BOOLEAN) (NBPtr->MCTPtr->ErrCode < AGESA_FATAL);
136 }
137
138 /*----------------------------------------------------------------------------
139  *                              LOCAL FUNCTIONS
140  *
141  *----------------------------------------------------------------------------
142  */
143
144 /* -----------------------------------------------------------------------------*/
145 /**
146  *
147  *
148  *   This function sets the non-SPD timings  in PCI registers
149  *
150  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
151  *
152  */
153
154 VOID
155 STATIC
156 MemNSetOtherTimingHY (
157   IN OUT   MEM_NB_BLOCK *NBPtr
158   )
159 {
160
161   MemNSetBitFieldNb (NBPtr, BFTrdrd, MemNGetTrdrdNb (NBPtr));
162   MemNSetBitFieldNb (NBPtr, BFTwrwr, MemNGetTwrwrNb (NBPtr));
163   MemNSetBitFieldNb (NBPtr, BFTwrrd, MemNGetTwrrdNb (NBPtr));
164   MemNSetBitFieldNb (NBPtr, BFTrwtTO, MemNGetTrwtTONb (NBPtr));
165   MemNSetBitFieldNb (NBPtr, BFTrwtWB, MemNGetTrwtWBNb (NBPtr));
166 }
167
168 /* -----------------------------------------------------------------------------*/
169 /**
170  *
171  *
172  *   This function gets the ODT delays
173  *
174  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
175  *
176  */
177
178 /*
179 UINT32
180 STATIC
181 MemNGetODTDelaysHy (
182   IN OUT   MEM_NB_BLOCK *NBPtr
183   )
184 {
185   INT8 Ld;
186   UINT32 ODTDelays;
187   //
188   // On revision D processors, the BIOS must additionally configure the ODT pattern
189   // and the ODT switching delays.
190   //
191   // Program F2x[1, 0]9C_x83 DRAM Phy ODT Assertion Control Register based on Burst length.
192   //     -Read the Burst Length from F2x[1, 0]84[BurstCtrl].
193   //     -Value of 2, BL = 4 else assume BL=8.
194   //     -Initialize ODTDelays based on BL value
195   //     -WrOdtOnDuration [14:12] = BL / 2 + 1
196   //     -WrOdtTrnOnDly [10:8] = 0
197   //     -RdOdtOnDuration [6:4] = BL / 2 + 1
198   //
199   ODTDelays = (MemNGetBitFieldNb (NBPtr, BFBurstCtrl) == 2) ? 0x00003030 : 0x00005050;
200
201   // RdOdtTrnOnDly [3:0] < (CL-CWL) or (CL-CWL - 1)
202   // See BKDG F2x[1, 0]9C_x83 DRAM Phy ODT Assertion Control Register [3:0]
203   Ld = ((INT8)MemNGetBitFieldNb (NBPtr, BFTcl) + 1) - ((INT8)MemNGetBitFieldNb (NBPtr, BFTcwl) + 5);
204   if (Ld < 0) {
205     Ld = 0;
206   }
207   if (Ld > 7) {
208     Ld = 7;
209   }
210   ODTDelays += Ld;
211   return ODTDelays;
212 }
213 */
214
215 /* -----------------------------------------------------------------------------*/
216 /**
217  *
218  *
219  *   This function enables power down mode
220  *
221  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
222  *
223  */
224
225 /*
226 VOID
227 STATIC
228 MemNPowerDownCtlHY (
229   IN OUT   MEM_NB_BLOCK *NBPtr
230   )
231 {
232   MEM_PARAMETER_STRUCT *RefPtr;
233   UINT8 PowerDownMode;
234
235   RefPtr = NBPtr->RefPtr;
236
237   // we can't enable powerdown mode when doing WL
238   if (RefPtr->EnablePowerDown) {
239     MemNSetBitFieldNb (NBPtr, BFPowerDownEn, 1);
240     PowerDownMode = (UINT8) UserOptions.CfgPowerDownMode;
241     IDS_OPTION_HOOK (IDS_POWERDOWN_MODE, &PowerDownMode, &(NBPtr->MemPtr->StdHeader));
242     if (PowerDownMode) {
243       MemNSetBitFieldNb (NBPtr, BFPowerDownMode, 1);
244     }
245   }
246 }
247 */