zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 1 | /* $NoKeywords:$ */ |
| 2 | /** |
| 3 | * @file |
| 4 | * |
| 5 | * mprc2ibt.c |
| 6 | * |
| 7 | * A sub-engine which extracts RC2[IBT] value for RDIMM configuration. |
| 8 | * |
| 9 | * @xrefitem bom "File Content Label" "Release Content" |
| 10 | * @e project: AGESA |
| 11 | * @e sub-project: (Mem/Ps) |
| 12 | * @e \$Revision: 63425 $ @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $ |
| 13 | * |
| 14 | **/ |
| 15 | /***************************************************************************** |
| 16 | * |
Siyuan Wang | 641f00c | 2013-06-08 11:50:55 +0800 | [diff] [blame] | 17 | * 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. |
zbao | 7d94cf9 | 2012-07-02 14:19:14 +0800 | [diff] [blame] | 41 | * *************************************************************************** |
| 42 | * |
| 43 | */ |
| 44 | /* |
| 45 | *---------------------------------------------------------------------------- |
| 46 | * MODULES USED |
| 47 | * |
| 48 | *---------------------------------------------------------------------------- |
| 49 | */ |
| 50 | |
| 51 | |
| 52 | |
| 53 | #include "AGESA.h" |
| 54 | #include "AdvancedApi.h" |
| 55 | #include "amdlib.h" |
| 56 | #include "Ids.h" |
| 57 | #include "cpuFamRegisters.h" |
| 58 | #include "cpuRegisters.h" |
| 59 | #include "OptionMemory.h" |
| 60 | #include "PlatformMemoryConfiguration.h" |
| 61 | #include "mu.h" |
| 62 | #include "ma.h" |
| 63 | #include "mp.h" |
| 64 | #include "merrhdl.h" |
| 65 | #include "GeneralServices.h" |
| 66 | #include "Filecode.h" |
| 67 | CODE_GROUP (G2_PEI) |
| 68 | RDATA_GROUP (G2_PEI) |
| 69 | #define FILECODE PROC_MEM_PS_MPRC2IBT_FILECODE |
| 70 | |
| 71 | |
| 72 | /*---------------------------------------------------------------------------- |
| 73 | * DEFINITIONS AND MACROS |
| 74 | * |
| 75 | *---------------------------------------------------------------------------- |
| 76 | */ |
| 77 | /*---------------------------------------------------------------------------- |
| 78 | * TYPEDEFS AND STRUCTURES |
| 79 | * |
| 80 | *---------------------------------------------------------------------------- |
| 81 | */ |
| 82 | /*---------------------------------------------------------------------------- |
| 83 | * PROTOTYPES OF LOCAL FUNCTIONS |
| 84 | * |
| 85 | *---------------------------------------------------------------------------- |
| 86 | */ |
| 87 | /*---------------------------------------------------------------------------- |
| 88 | * EXPORTED FUNCTIONS |
| 89 | * |
| 90 | *---------------------------------------------------------------------------- |
| 91 | */ |
| 92 | /* -----------------------------------------------------------------------------*/ |
| 93 | /** |
| 94 | * |
| 95 | * A sub-function which extracts RC2[IBT] value from a input table and stores extracted |
| 96 | * value to a specific address. |
| 97 | * |
| 98 | * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK |
| 99 | * @param[in] *EntryOfTables Pointer to MEM_PSC_TABLE_BLOCK |
| 100 | * |
| 101 | * @return TRUE - Table values can be extracted for all present dimms/ranks |
| 102 | * @return FALSE - Table values cannot be extracted for all present dimms/ranks |
| 103 | * |
| 104 | */ |
| 105 | BOOLEAN |
| 106 | MemPGetRC2IBT ( |
| 107 | IN OUT MEM_NB_BLOCK *NBPtr, |
| 108 | IN MEM_PSC_TABLE_BLOCK *EntryOfTables |
| 109 | ) |
| 110 | { |
| 111 | UINT8 i; |
| 112 | UINT8 MaxDimmPerCh; |
| 113 | UINT8 NOD; |
| 114 | UINT8 DimmIndex; |
| 115 | UINT8 TableSize; |
| 116 | UINT32 CurDDRrate; |
| 117 | UINT8 DDR3Voltage; |
| 118 | UINT16 RankTypeOfPopulatedDimm; |
| 119 | UINT16 RankTypeInTable; |
| 120 | CPU_LOGICAL_ID LogicalCpuid; |
| 121 | UINT8 PackageType; |
| 122 | UINT8 TgtDimmType; |
| 123 | UINT8 NumOfReg; |
| 124 | UINT8 PsoDimmMaskRc2Ibt; |
| 125 | UINT8 NoEntryDimmMask; |
| 126 | PSCFG_MR2IBT_ENTRY *TblPtr; |
| 127 | PSCFG_MR2IBT_ENTRY *OrgTblPtr; |
| 128 | CH_DEF_STRUCT *CurrentChannel; |
| 129 | |
| 130 | CurrentChannel = NBPtr->ChannelPtr; |
| 131 | |
| 132 | if (CurrentChannel->RegDimmPresent == 0) { |
| 133 | return TRUE; |
| 134 | } |
| 135 | |
| 136 | TblPtr = NULL; |
| 137 | TableSize = 0; |
| 138 | PackageType = 0; |
| 139 | NoEntryDimmMask = 0; |
| 140 | LogicalCpuid.Family = AMD_FAMILY_UNKNOWN; |
| 141 | MaxDimmPerCh = GetMaxDimmsPerChannel (NBPtr->RefPtr->PlatformMemoryConfiguration, NBPtr->MCTPtr->SocketId, CurrentChannel->ChannelID); |
| 142 | NOD = (UINT8) 1 << (MaxDimmPerCh - 1); |
| 143 | |
| 144 | i = 0; |
| 145 | // Obtain table pointer, table size, Logical Cpuid and PSC type according to NB type and package type. |
| 146 | while (EntryOfTables->TblEntryOfRC2IBT[i] != NULL) { |
| 147 | if (((EntryOfTables->TblEntryOfRC2IBT[i])->Header.NumOfDimm & NOD) != 0) { |
| 148 | LogicalCpuid = (EntryOfTables->TblEntryOfRC2IBT[i])->Header.LogicalCpuid; |
| 149 | PackageType = (EntryOfTables->TblEntryOfRC2IBT[i])->Header.PackageType; |
| 150 | // |
| 151 | // Determine if this is the expected NB Type |
| 152 | // |
| 153 | if (MemPIsIdSupported (NBPtr, LogicalCpuid, PackageType)) { |
| 154 | TblPtr = (PSCFG_MR2IBT_ENTRY *) ((EntryOfTables->TblEntryOfRC2IBT[i])->TBLPtr); |
| 155 | TableSize = (EntryOfTables->TblEntryOfRC2IBT[i])->TableSize; |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | i++; |
| 160 | } |
| 161 | |
| 162 | // Check whether no table entry is found. |
| 163 | if (EntryOfTables->TblEntryOfRC2IBT[i] == NULL) { |
| 164 | IDS_HDT_CONSOLE (MEM_FLOW, "\nNo RC2 IBT table\n"); |
| 165 | return FALSE; |
| 166 | } |
| 167 | |
| 168 | CurDDRrate = (UINT32) (1 << (CurrentChannel->DCTPtr->Timings.Speed / 66)); |
| 169 | DDR3Voltage = (UINT8) (1 << CONVERT_VDDIO_TO_ENCODED (NBPtr->RefPtr->DDR3Voltage)); |
| 170 | RankTypeOfPopulatedDimm = MemPGetPsRankType (CurrentChannel); |
| 171 | |
| 172 | OrgTblPtr = TblPtr; |
| 173 | for (DimmIndex = 0; DimmIndex < MAX_DIMMS_PER_CHANNEL; DimmIndex++) { |
| 174 | TblPtr = OrgTblPtr; |
| 175 | NumOfReg = NBPtr->PsPtr->NumOfReg[DimmIndex]; |
| 176 | if ((CurrentChannel->ChDimmValid & (UINT8) (1 << DimmIndex)) != 0) { |
| 177 | if ((CurrentChannel->DimmQrPresent & (UINT8) (1 << DimmIndex)) != 0) { |
| 178 | TgtDimmType = DIMM_QR; |
| 179 | } else if ((CurrentChannel->DimmDrPresent & (UINT8) (1 << DimmIndex)) != 0) { |
| 180 | TgtDimmType = DIMM_DR; |
| 181 | } else { |
| 182 | TgtDimmType = DIMM_SR; |
| 183 | } |
| 184 | |
| 185 | for (i = 0; i < TableSize; i++) { |
| 186 | MemPConstructRankTypeMap ((UINT16) TblPtr->Dimm0, (UINT16) TblPtr->Dimm1, (UINT16) TblPtr->Dimm2, &RankTypeInTable); |
| 187 | if ((TblPtr->DimmPerCh & NOD) != 0) { |
| 188 | if ((TblPtr->DDRrate & CurDDRrate) != 0) { |
| 189 | if ((TblPtr->VDDIO & DDR3Voltage) != 0) { |
| 190 | if ((RankTypeInTable & RankTypeOfPopulatedDimm) == RankTypeOfPopulatedDimm) { |
| 191 | if ((TblPtr->Dimm & TgtDimmType) != 0) { |
| 192 | // If TblPtr->NumOfReg == 0x0F, that means the condition will be TRUE regardless of NumRegisters in DIMM |
| 193 | if ((TblPtr->NumOfReg == 0xF) || (TblPtr->NumOfReg == NumOfReg)) { |
| 194 | CurrentChannel->CtrlWrd02[DimmIndex] = (UINT8) ((TblPtr->IBT & 0x1) << 2); |
| 195 | CurrentChannel->CtrlWrd08[DimmIndex] = (UINT8) ((TblPtr->IBT & 0xE) >> 1); |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | TblPtr++; |
| 204 | } |
| 205 | |
| 206 | if (i == TableSize) { |
| 207 | NoEntryDimmMask |= (UINT8) 1 << DimmIndex; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // |
| 213 | // If there are no entries for certain Dimm(s), check if overriding value existed for them. If not, return FALSE. |
| 214 | // |
| 215 | PsoDimmMaskRc2Ibt = (UINT8) MemPProceedTblDrvOverride (NBPtr, NBPtr->RefPtr->PlatformMemoryConfiguration, PSO_TBLDRV_RC2_IBT); |
| 216 | if (NoEntryDimmMask != 0) { |
| 217 | if ((NoEntryDimmMask & PsoDimmMaskRc2Ibt) != NoEntryDimmMask) { |
| 218 | IDS_HDT_CONSOLE (MEM_FLOW, "\nNo RC2 IBT entries\n"); |
| 219 | PutEventLog (AGESA_ERROR, MEM_ERROR_RC2_IBT_NOT_FOUND, NBPtr->Node, NBPtr->Dct, NBPtr->Channel, 0, &NBPtr->MemPtr->StdHeader); |
| 220 | SetMemError (AGESA_ERROR, NBPtr->MCTPtr); |
| 221 | if (!NBPtr->MemPtr->ErrorHandling (NBPtr->MCTPtr, NBPtr->Dct, EXCLUDE_ALL_CHIPSEL, &NBPtr->MemPtr->StdHeader)) { |
| 222 | ASSERT (FALSE); |
| 223 | } |
| 224 | return FALSE; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | return TRUE; |
| 229 | } |