blob: 49ed5e879fcae2eba91e4b8bf7902f3c2caea36b [file] [log] [blame]
zbao7d94cf92012-07-02 14:19:14 +08001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * mttecc.c
6 *
7 * Technology ECC byte support
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: (Mem/Tech)
12 * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $
13 *
14 **/
15/*****************************************************************************
16*
Siyuan Wang641f00c2013-06-08 11:50:55 +080017 * Copyright (c) 2008 - 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.
zbao7d94cf92012-07-02 14:19:14 +080041* ***************************************************************************
42*
43*/
44
45/*
46 *----------------------------------------------------------------------------
47 * MODULES USED
48 *
49 *----------------------------------------------------------------------------
50 */
51
52
53#include "AGESA.h"
54#include "Ids.h"
55#include "mm.h"
56#include "mn.h"
57#include "mt.h"
58#include "Filecode.h"
59CODE_GROUP (G1_PEICC)
60RDATA_GROUP (G1_PEICC)
61
62#define FILECODE PROC_MEM_TECH_MTTECC_FILECODE
63/*----------------------------------------------------------------------------
64 * DEFINITIONS AND MACROS
65 *
66 *----------------------------------------------------------------------------
67 */
68
69/*----------------------------------------------------------------------------
70 * TYPEDEFS AND STRUCTURES
71 *
72 *----------------------------------------------------------------------------
73 */
74
75/*----------------------------------------------------------------------------
76 * PROTOTYPES OF LOCAL FUNCTIONS
77 *
78 *----------------------------------------------------------------------------
79 */
80
81VOID
82STATIC
83MemTCalcDQSEccTmg (
84 IN OUT MEM_TECH_BLOCK *TechPtr,
85 IN UINT8 Dimm,
86 IN UINT8 Type,
87 IN OUT VOID *DlyArray
88 );
89
90/*----------------------------------------------------------------------------
91 * EXPORTED FUNCTIONS
92 *
93 *----------------------------------------------------------------------------
94 */
95
96/* -----------------------------------------------------------------------------*/
97/**
98 *
99 * This function sets the DQS ECC timings
100 *
101 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
102 *
103 * @return TRUE - No fatal error occurs.
104 * @return FALSE - Fatal error occurs.
105 */
106
107BOOLEAN
108MemTSetDQSEccTmgs (
109 IN OUT MEM_TECH_BLOCK *TechPtr
110 )
111{
112 UINT8 Dct;
113 UINT8 Dimm;
114 UINT8 i;
115
116 MEM_NB_BLOCK *NBPtr;
117 CH_DEF_STRUCT *ChannelPtr;
118
119 NBPtr = TechPtr->NBPtr;
120 if (NBPtr->MCTPtr->NodeMemSize) {
121 for (Dct = 0; Dct < NBPtr->DctCount; Dct++) {
122 NBPtr->SwitchDCT (NBPtr, Dct);
123 if (NBPtr->DCTPtr->Timings.DctMemSize != 0) {
124 ChannelPtr = NBPtr->ChannelPtr;
125 for (Dimm = 0; Dimm < MAX_DIMMS_PER_CHANNEL; Dimm++) {
126 if (NBPtr->DCTPtr->Timings.CsEnabled & ((UINT16)1 << (Dimm * 2))) {
127 i = Dimm * TechPtr->DlyTableWidth ();
128 MemTCalcDQSEccTmg (TechPtr, Dimm, AccessRcvEnDly, &ChannelPtr->RcvEnDlys[i]);
129 MemTCalcDQSEccTmg (TechPtr, Dimm, AccessRdDqsDly, &ChannelPtr->RdDqsDlys[i]);
130 MemTCalcDQSEccTmg (TechPtr, Dimm, AccessWrDatDly, &ChannelPtr->WrDatDlys[i]);
131 }
132 }
133 }
134 }
135 }
136 return (BOOLEAN) (NBPtr->MCTPtr->ErrCode < AGESA_FATAL);
137}
138
139/*----------------------------------------------------------------------------
140 * LOCAL FUNCTIONS
141 *
142 *----------------------------------------------------------------------------
143 */
144
145/* -----------------------------------------------------------------------------*/
146/**
147 *
148 * This function calculates the DQS ECC timings
149 *
150 * @param[in,out] *TechPtr - Pointer to the MEM_TECH_BLOCK
151 * @param[in] Dimm - Dimm number
152 * @param[in] Type - Type of DQS timing
153 * @param[in,out] *DlyArray - Pointer to the array of delays per this Dimm
154 *
155 */
156
157VOID
158STATIC
159MemTCalcDQSEccTmg (
160 IN OUT MEM_TECH_BLOCK *TechPtr,
161 IN UINT8 Dimm,
162 IN UINT8 Type,
163 IN OUT VOID *DlyArray
164 )
165{
166 UINT8 i;
167 UINT8 j;
168 UINT8 Scale;
169 UINT8 EccByte;
170 UINT16 ByteiDly;
171 UINT16 BytejDly;
172 UINT16 EccDly;
173 UINT8 *WrDqsDly;
174 MEM_NB_BLOCK *NBPtr;
175 CH_DEF_STRUCT *ChannelPtr;
176
177 NBPtr = TechPtr->NBPtr;
178 ChannelPtr = NBPtr->ChannelPtr;
179
180 EccByte = TechPtr->MaxByteLanes ();
181 i = (UINT8) (ChannelPtr->DctEccDqsLike & 0xFF);
182 j = (UINT8) (ChannelPtr->DctEccDqsLike >> 8);
183 Scale = ChannelPtr->DctEccDqsScale;
184 WrDqsDly = &ChannelPtr->WrDqsDlys[Dimm * TechPtr->DlyTableWidth ()];
185
186 if (Type == AccessRcvEnDly) {
187 ByteiDly = ((UINT16 *) DlyArray)[i];
188 BytejDly = ((UINT16 *) DlyArray)[j];
189 } else {
190 ByteiDly = ((UINT8 *) DlyArray)[i];
191 BytejDly = ((UINT8 *) DlyArray)[j];
192 }
193
194 //
195 // For WrDatDly, Subtract TxDqs Delay to get
196 // TxDq-TxDqs Delta, which is what should be averaged.
197 //
198 if (Type == AccessWrDatDly) {
199 ByteiDly = ByteiDly - WrDqsDly[i];
200 BytejDly = BytejDly - WrDqsDly[j];
201 }
202
203 if (BytejDly > ByteiDly) {
204 EccDly = ByteiDly + (UINT8) (((UINT16) (BytejDly - ByteiDly) * Scale + 0x77) / 0xFF);
205 // Round up --^
206 } else {
207 EccDly = BytejDly + (UINT8) (((UINT16) (ByteiDly - BytejDly) * (0xFF - Scale) + 0x77) / 0xFF);
208 // Round up --^
209 }
210
211 if (Type == AccessRcvEnDly) {
212 ((UINT16 *) DlyArray)[EccByte] = EccDly;
213 } else {
214 ((UINT8 *) DlyArray)[EccByte] = (UINT8) EccDly;
215 }
216
217 //
218 // For WrDatDly, Add back the TxDqs value for ECC bytelane
219 //
220 if (Type == AccessWrDatDly) {
221 EccDly = EccDly + WrDqsDly[EccByte];
222 }
223
224 NBPtr->SetTrainDly (NBPtr, Type, DIMM_BYTE_ACCESS (Dimm, EccByte), EccDly);
225}