blob: b8cc066b3f36d8b8c8d00d6cba0402ddaaf6d00d [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/* $NoKeywords:$ */
2/**
3 * @file
4 *
5 * mfemp.c
6 *
7 * Feature EMP initialization functions
8 *
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: (Mem/Feat/ECC)
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'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
50#include "AGESA.h"
51#include "mm.h"
52#include "mn.h"
53#include "Ids.h"
54#include "GeneralServices.h"
55#include "Filecode.h"
56CODE_GROUP (G2_PEI)
57RDATA_GROUP (G2_PEI)
58
59#define FILECODE PROC_MEM_FEAT_ECC_MFEMP_FILECODE
60/*----------------------------------------------------------------------------
61 * DEFINITIONS AND MACROS
62 *
63 *----------------------------------------------------------------------------
64 */
65
66/*----------------------------------------------------------------------------
67 * TYPEDEFS AND STRUCTURES
68 *
69 *----------------------------------------------------------------------------
70 */
71
72/*----------------------------------------------------------------------------
73 * PROTOTYPES OF LOCAL FUNCTIONS
74 *
75 *----------------------------------------------------------------------------
76 */
77BOOLEAN
efdesign9884cbce22011-08-04 12:09:17 -060078MemFInitEMP (
79 IN OUT MEM_NB_BLOCK *NBPtr
80 );
81
82BOOLEAN
Frank Vibrans2b4c8312011-02-14 18:30:54 +000083STATIC
84IsPowerOfTwo (
85 IN UINT32 TestNumber
86 );
87
88/*
89 *-----------------------------------------------------------------------------
90 * EXPORTED FUNCTIONS
91 *
92 *-----------------------------------------------------------------------------
93 */
94
95extern BUILD_OPT_CFG UserOptions;
96
97/* -----------------------------------------------------------------------------*/
98/**
99 *
100 *
101 * This function initializes EMP (Enhanced Memory Protection)
102 *
103 * @param[in,out] *NBPtr - Pointer to the MEM_NB_BLOCK
104 *
105 * @return TRUE - This feature is enabled.
106 * @return FALSE - This feature is not enabled.
107 */
108
109BOOLEAN
110MemFInitEMP (
111 IN OUT MEM_NB_BLOCK *NBPtr
112 )
113{
114 MEM_PARAMETER_STRUCT *RefPtr;
115 DIE_STRUCT *MCTPtr;
116
117 ASSERT (NBPtr != NULL);
118
119 RefPtr = NBPtr->RefPtr;
120 MCTPtr = NBPtr->MCTPtr;
121 if (RefPtr->EnableEccFeature) {
122 if (NBPtr->GetBitField (NBPtr, BFEnhMemProtCap) == 0) {
123 PutEventLog (AGESA_WARNING, MEM_WARNING_EMP_NOT_SUPPORTED, 0, 0, 0, 0, &NBPtr->MemPtr->StdHeader);
124 MCTPtr->ErrStatus[EsbEMPNotSupported] = TRUE;
125 } else if (RefPtr->EnableChannelIntlv || RefPtr->EnableBankIntlv || RefPtr->EnableBankSwizzle) {
126 PutEventLog (AGESA_WARNING, MEM_WARNING_EMP_CONFLICT, 0, 0, 0, 0, &NBPtr->MemPtr->StdHeader);
127 MCTPtr->ErrStatus[EsbEMPConflict] = TRUE;
128 } else if ((!MCTPtr->GangedMode) &&
129 (!IsPowerOfTwo (MCTPtr->DctData[0].Timings.DctMemSize) &&
130 !IsPowerOfTwo (MCTPtr->DctData[1].Timings.DctMemSize))) {
131 PutEventLog (AGESA_WARNING, MEM_WARNING_EMP_NOT_ENABLED, 0, 0, 0, 0, &NBPtr->MemPtr->StdHeader);
132 MCTPtr->ErrStatus[EsbEMPDis] = TRUE;
133 } else {
134 // Reduce memory size to 7/8 of the original memory size
135 ASSERT ((MCTPtr->NodeMemSize % 8) == 0);
136 NBPtr->SetBitField (NBPtr, BFDramHoleValid, 0);
137 MCTPtr->NodeMemSize = (MCTPtr->NodeMemSize / 8) * 7;
138 NBPtr->HtMemMapInit (NBPtr);
139 NBPtr->CpuMemTyping (NBPtr);
140
141 // Enable EMP
142 NBPtr->SetBitField (NBPtr, BFDramEccEn, 1);
143
144 // Scrub CTL settings for Dcache, L2
145 NBPtr->SetBitField (NBPtr, BFL2Scrub, UserOptions.CfgScrubL2Rate);
146 NBPtr->SetBitField (NBPtr, BFDcacheScrub, UserOptions.CfgScrubDcRate);
147
148 NBPtr->SetBitField (NBPtr, BFSyncOnUcEccEn, UserOptions.CfgEccSyncFlood);
149 return TRUE;
150 }
151 }
152 return FALSE;
153}
154
155/*----------------------------------------------------------------------------
156 * LOCAL FUNCTIONS
157 *
158 *----------------------------------------------------------------------------
159 */
160
161/* -----------------------------------------------------------------------------*/
162/**
163 *
164 *
165 * This function checks to see if the input is power of two.
166 *
167 * @param[in] TestNumber - Value to check for power of two
168 *
169 * @return TRUE - is power of two
170 * FALSE - is not power of two
171 */
172BOOLEAN
173STATIC
174IsPowerOfTwo (
175 IN UINT32 TestNumber
176 )
177{
178 return (BOOLEAN) ((TestNumber & (TestNumber - 1)) == 0);
179}