blob: 1c0d6a8efbc4f93a376528cbd481bdf5dc1ea3dc [file] [log] [blame]
zbao7d94cf92012-07-02 14:19:14 +08001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * mfchi.c
6 *
7 * Feature Channel interleaving support
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: (Mem/Feat/Chintlv)
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 *----------------------------------------------------------------------------
48 * MODULES USED
49 *
50 *----------------------------------------------------------------------------
51 */
52
53
54
55#include "AGESA.h"
56#include "mm.h"
57#include "mn.h"
58#include "mfchi.h"
59#include "Ids.h"
60#include "GeneralServices.h"
61#include "Filecode.h"
62CODE_GROUP (G2_PEI)
63RDATA_GROUP (G2_PEI)
64
65#define FILECODE PROC_MEM_FEAT_CHINTLV_MFCHI_FILECODE
66/*----------------------------------------------------------------------------
67 * DEFINITIONS AND MACROS
68 *
69 *----------------------------------------------------------------------------
70 */
71#define _4GB_ (0x10000ul >> 10)
72
73/*----------------------------------------------------------------------------
74 * TYPEDEFS AND STRUCTURES
75 *
76 *----------------------------------------------------------------------------
77 */
78
79/*----------------------------------------------------------------------------
80 * PROTOTYPES OF LOCAL FUNCTIONS
81 *
82 *----------------------------------------------------------------------------
83 */
84
85/*----------------------------------------------------------------------------
86 * EXPORTED FUNCTIONS
87 *
88 *----------------------------------------------------------------------------
89 */
90
91/* -----------------------------------------------------------------------------*/
92/**
93 *
94 * MemFInterleaveChannels:
95 *
96 * Applies DIMM channel interleaving if enabled, if not ganged mode, and
97 * there are valid dimms in both channels. Called once per Node.
98 *
99 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
100 *
101 * @return TRUE - This feature is enabled.
102 * @return FALSE - This feature is not enabled.
103 */
104
105BOOLEAN
106MemFInterleaveChannels (
107 IN OUT MEM_NB_BLOCK *NBPtr
108 )
109{
110 UINT32 DramBase;
111 UINT32 DctSelBase;
112 UINT32 HoleSize;
113 UINT32 HoleBase;
114 UINT32 HoleOffset;
115 UINT32 Dct0Size;
116 UINT32 Dct1Size;
117 UINT32 SmallerDct;
118 UINT8 DctSelIntLvAddr;
119 UINT8 DctSelHi;
120 UINT8 DctSelHiRngEn;
121 UINT32 HoleValid;
122
123 MEM_PARAMETER_STRUCT *RefPtr;
124 DIE_STRUCT *MCTPtr;
125
126 ASSERT (NBPtr != NULL);
127
128 RefPtr = NBPtr->RefPtr;
129
130 DctSelIntLvAddr = NBPtr->DefDctSelIntLvAddr;
131 if (RefPtr->EnableChannelIntlv) {
132 HoleSize = 0;
133 HoleBase = 0;
134 if (RefPtr->GStatus[GsbSoftHole] || RefPtr->GStatus[GsbHWHole]) {
135 // HoleBase scaled from [47:16] to [47:26]
136 HoleBase = RefPtr->HoleBase >> 10;
137 HoleSize = _4GB_ - HoleBase;
138 }
139
140 MCTPtr = NBPtr->MCTPtr;
141
142 HoleValid = NBPtr->GetBitField (NBPtr, BFDramHoleValid);
143 if ((!MCTPtr->GangedMode) &&
144 (MCTPtr->DctData[0].Timings.DctMemSize != 0) &&
145 (MCTPtr->DctData[1].Timings.DctMemSize != 0)) {
146 // DramBase scaled [47:16] to [47:26]
147 DramBase = MCTPtr->NodeSysBase >> 10;
148 // Scale NodeSysLimit [47:16] to [47:26]
149 Dct1Size = (MCTPtr->NodeSysLimit + 1) >> 10;
150 Dct0Size = NBPtr->GetBitField (NBPtr, BFDctSelBaseOffset);
151 if ((Dct0Size >= _4GB_) && (DramBase < HoleBase)) {
152 Dct0Size -= HoleSize;
153 }
154 if ((Dct1Size >= _4GB_) && (DramBase < HoleBase)) {
155 Dct1Size -= HoleSize;
156 }
157 Dct1Size -= Dct0Size;
158 Dct0Size -= DramBase;
159
160 // Select the bigger size DCT to put in DctSelHi
161 DctSelHiRngEn = 1;
162 DctSelHi = 0;
163 SmallerDct = Dct1Size;
164 if (Dct1Size == Dct0Size) {
165 SmallerDct = 0;
166 DctSelHiRngEn = 0;
167 } else if (Dct1Size > Dct0Size) {
168 SmallerDct = Dct0Size;
169 DctSelHi = 1;
170 }
171
172 if (SmallerDct != 0) {
173 DctSelBase = (SmallerDct * 2) + DramBase;
174 } else {
175 DctSelBase = 0;
176 }
177 if ((DctSelBase >= HoleBase) && (DramBase < HoleBase)) {
178 DctSelBase += HoleSize;
179 }
180 IDS_OPTION_HOOK (IDS_CHANNEL_INTERLEAVE, &DctSelIntLvAddr, &(NBPtr->MemPtr->StdHeader));
181 NBPtr->SetBitField (NBPtr, BFDctSelBaseAddr, DctSelBase >> 1);
182 NBPtr->SetBitField (NBPtr, BFDctSelHiRngEn, DctSelHiRngEn);
183 NBPtr->SetBitField (NBPtr, BFDctSelHi, DctSelHi);
184 NBPtr->SetBitField (NBPtr, BFDctSelIntLvAddr, DctSelIntLvAddr);
185 NBPtr->SetBitField (NBPtr, BFDctSelIntLvEn, 1);
186
187 // DctSelBaseOffset = DctSelBaseAddr - Interleaved region
188 NBPtr->SetBitField (NBPtr, BFDctSelBaseOffset, DctSelBase - SmallerDct);
189
190 // Adjust DramHoleOffset
191 if (HoleValid != 0) {
192 HoleOffset = DramBase;
193 if ((DctSelBase < HoleBase) && (DctSelBase != 0)) {
194 HoleOffset += (DctSelBase - DramBase) >> 1;
195 }
196 HoleOffset += HoleSize;
197 NBPtr->SetBitField (NBPtr, BFDramHoleOffset, HoleOffset << 3);
198 }
199 } else {
200 //
201 // Channel Interleaving is requested but cannot be enabled
202 //
203 PutEventLog (AGESA_WARNING, MEM_WARNING_CHANNEL_INTERLEAVING_NOT_ENABLED, NBPtr->Node, 0, 0, 0, &NBPtr->MemPtr->StdHeader);
204 SetMemError (AGESA_WARNING, MCTPtr);
205 }
206
207 return TRUE;
208 } else {
209 return FALSE;
210 }
211}