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