blob: 9e1b7bc2274629b4efead247d6e6a3f37e07b0bf [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * mt.c
6 *
7 * Common Technology file
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: (Mem/Tech)
12 * @e \$Revision: 36981 $ @e \$Date: 2010-08-27 23:21:43 +0800 (Fri, 27 Aug 2010) $
13 *
14 **/
15/*
16 *****************************************************************************
17 *
18 * Copyright (c) 2011, Advanced Micro Devices, Inc.
19 * All rights reserved.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100020 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000021 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100028 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000030 * from this software without specific prior written permission.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100031 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000032 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Edward O'Callaghan1542a6f2014-07-06 19:24:06 +100042 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000043 * ***************************************************************************
44 *
45 */
46
47/*
48 *----------------------------------------------------------------------------
49 * MODULES USED
50 *
51 *----------------------------------------------------------------------------
52 */
53
54
55#include "AGESA.h"
56#include "amdlib.h"
57#include "mport.h"
58#include "mm.h"
59#include "mn.h"
60#include "mu.h"
61#include "mt.h"
62#include "Filecode.h"
63CODE_GROUP (G1_PEICC)
64RDATA_GROUP (G1_PEICC)
65
66#define FILECODE PROC_MEM_TECH_MT_FILECODE
67/*----------------------------------------------------------------------------
68 * DEFINITIONS AND MACROS
69 *
70 *----------------------------------------------------------------------------
71 */
72
73/*----------------------------------------------------------------------------
74 * TYPEDEFS AND STRUCTURES
75 *
76 *----------------------------------------------------------------------------
77 */
78
79/*----------------------------------------------------------------------------
80 * PROTOTYPES OF LOCAL FUNCTIONS
81 *
82 *----------------------------------------------------------------------------
83 */
84BOOLEAN
85STATIC
86MemTDefaultTechnologyHook (
87 IN OUT MEM_TECH_BLOCK *TechPtr,
88 IN OUT VOID *OptParam
89 );
90/*----------------------------------------------------------------------------
91 * EXPORTED FUNCTIONS
92 *
93 *----------------------------------------------------------------------------
94 */
95
96/* -----------------------------------------------------------------------------*/
97/**
98 *
99 * This function is the default return for non-training technology features
100 *
101 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
102 */
103BOOLEAN
104MemTFeatDef (
105 IN OUT MEM_TECH_BLOCK *TechPtr
106 )
107{
108 return TRUE;
109}
110
111/* -----------------------------------------------------------------------------*/
112/**
113 *
114 * This function sets the TestFail bit for all CS that fail training.
115 *
116 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
117 */
118VOID
119MemTMarkTrainFail (
120 IN OUT MEM_TECH_BLOCK *TechPtr
121 )
122{
123 MEM_NB_BLOCK *NBPtr;
124 UINT8 Dct;
125 UINT8 ChipSel;
126
127 NBPtr = TechPtr->NBPtr;
128 for (Dct = 0; Dct < NBPtr->DctCount; Dct ++) {
129 NBPtr->SwitchDCT (NBPtr, Dct);
130 NBPtr->DCTPtr->Timings.CsEnabled &= ~NBPtr->DCTPtr->Timings.CsTrainFail;
131 for (ChipSel = 0; ChipSel < MAX_CS_PER_CHANNEL; ChipSel ++) {
132 if ((NBPtr->DCTPtr->Timings.CsTrainFail & ((UINT16)1 << ChipSel)) != 0) {
133 NBPtr->SetBitField (NBPtr, (BFCSBaseAddr0Reg + ChipSel), (UINT32)1 << BFTestFail);
134 }
135 }
136 }
137}
138
139/* -----------------------------------------------------------------------------*/
140/**
141 *
142 * This function sets the initial controller environment before training.
143 *
144 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
145 *
146 */
147
148VOID
149MemTBeginTraining (
150 IN OUT MEM_TECH_BLOCK *TechPtr
151 )
152{
153 S_UINT64 SMsr;
154 MEM_DATA_STRUCT *MemPtr;
155 MEM_NB_BLOCK *NBPtr;
156
157 NBPtr = TechPtr->NBPtr;
158 MemPtr = NBPtr->MemPtr;
159
160 LibAmdReadCpuReg (CR4_REG, &TechPtr->CR4reg);
161 LibAmdWriteCpuReg (CR4_REG, TechPtr->CR4reg | ((UINT32)1 << 9)); // enable SSE2
162
163 LibAmdMsrRead (HWCR, (UINT64 *) (&SMsr), &MemPtr->StdHeader); // HWCR
164 TechPtr->HwcrLo = SMsr.lo;
165 SMsr.lo |= 0x00020000; // turn on HWCR.wrap32dis
166 SMsr.lo &= 0xFFFF7FFF; // turn off HWCR.SSEDIS
167 LibAmdMsrWrite (HWCR, (UINT64 *) (&SMsr), &MemPtr->StdHeader);
168
169 TechPtr->DramEcc = (UINT8) NBPtr->GetBitField (NBPtr, BFDramEccEn);
170 NBPtr->SetBitField (NBPtr, BFDramEccEn, 0); // Disable ECC
171}
172
173/* -----------------------------------------------------------------------------*/
174/**
175 *
176 * This function sets the final controller environment after training.
177 *
178 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
179 *
180 */
181
182VOID
183MemTEndTraining (
184 IN OUT MEM_TECH_BLOCK *TechPtr
185 )
186{
187 S_UINT64 SMsr;
188 MEM_DATA_STRUCT *MemPtr;
189 MEM_NB_BLOCK *NBPtr;
190
191 NBPtr = TechPtr->NBPtr;
192 MemPtr = NBPtr->MemPtr;
193
194 LibAmdWriteCpuReg (CR4_REG, TechPtr->CR4reg);
195
196 LibAmdMsrRead (HWCR, (UINT64 *)&SMsr, &MemPtr->StdHeader);
197 SMsr.lo = TechPtr->HwcrLo;
198 LibAmdMsrWrite (HWCR, (UINT64 *)&SMsr, &MemPtr->StdHeader);
199
200 NBPtr->SetBitField (NBPtr, BFDramEccEn, TechPtr->DramEcc);
201}
202
203/* -----------------------------------------------------------------------------*/
204/**
205 *
206 * This function sets all the bytelanes/nibbles to the same delay value
207 *
208 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
209 * @param[in] Dly - Delay value to set
210 *
211 */
212
213VOID
214MemTSetDQSDelayAllCSR (
215 IN OUT MEM_TECH_BLOCK *TechPtr,
216 IN UINT8 Dly
217 )
218{
219 UINT8 i;
220 UINT8 MaxBytelanes;
221 MaxBytelanes = (TechPtr->NBPtr->MCTPtr->Status[SbEccDimms] && TechPtr->NBPtr->IsSupported[EccByteTraining]) ? 9 : 8;
222
223 for (i = 0; i < MaxBytelanes; i++) {
224 TechPtr->SetDQSDelayCSR (TechPtr, i, Dly);
225 }
226}
227/*-----------------------------------------------------------------------------
228 *
229 *
230 * This function is used to intialize common technology functions
231 *
232 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
233 * ----------------------------------------------------------------------------
234 */
235VOID
236MemTCommonTechInit (
237 IN OUT MEM_TECH_BLOCK *TechPtr
238 )
239{
240 UINT8 i;
241 for (i = 0; i < NumberOfTechHooks; i++) {
242 TechPtr->TechnologySpecificHook[i] = MemTDefaultTechnologyHook;
243 }
244}
245/*-----------------------------------------------------------------------------
246 *
247 *
248 * This function is an empty function used to intialize TechnologySpecificHook array
249 *
250 * @param[in,out] *TechPtr - Pointer to the MEM_NB_BLOCK
251 * @param[in,out] OptParam - Optional parameter
252 *
253 * @return FALSE - always
254 * ----------------------------------------------------------------------------
255 */
256BOOLEAN
257STATIC
258MemTDefaultTechnologyHook (
259 IN OUT MEM_TECH_BLOCK *TechPtr,
260 IN OUT VOID *OptParam
261 )
262{
263 return FALSE;
264}