AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Main / merrhdl.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * merrhdl.c
6  *
7  * Memory error handling
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Main)
12  * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  *
14  **/
15 /*****************************************************************************
16 *
17 * Copyright (C) 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.
41 *
42 * ***************************************************************************
43 *
44 */
45
46 /*
47  *----------------------------------------------------------------------------
48  *                                MODULES USED
49  *
50  *----------------------------------------------------------------------------
51  */
52
53 #include "AGESA.h"
54 #include "amdlib.h"
55 #include "Ids.h"
56 #include "OptionMemory.h"
57 #include "mm.h"
58 #include "mn.h"
59 #include "mt.h"
60 #include "heapManager.h"
61 #include "merrhdl.h"
62 #include "Filecode.h"
63 CODE_GROUP (G1_PEICC)
64 RDATA_GROUP (G2_PEI)
65
66 #define FILECODE PROC_MEM_MAIN_MERRHDL_FILECODE
67
68 extern MEM_FEAT_BLOCK_MAIN MemFeatMain;
69 /*----------------------------------------------------------------------------
70  *                          DEFINITIONS AND MACROS
71  *
72  *----------------------------------------------------------------------------
73  */
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  *  This function handle errors occur in memory code.
97  *
98  *
99  *     @param[in,out]   *MCTPtr - pointer to DIE_STRUCT.
100  *     @param[in,out]   DCT - DCT that needs to be handled.
101  *     @param[in,out]   ChipSelMask - Chip select mask that needs to be handled
102  *     @param[in,out]   *StdHeader - pointer to AMD_CONFIG_PARAMS
103  *
104  *     @return          TRUE -  No fatal error occurs.
105  *     @return          FALSE - Fatal error occurs.
106  */
107 BOOLEAN
108 MemErrHandle (
109   IN       DIE_STRUCT *MCTPtr,
110   IN       UINT8  DCT,
111   IN       UINT16  ChipSelMask,
112   IN       AMD_CONFIG_PARAMS *StdHeader
113   )
114 {
115   BOOLEAN ErrorRecovery;
116   BOOLEAN IgnoreErr;
117   DCT_STRUCT *DCTPtr;
118   UINT8 CurrentDCT;
119   LOCATE_HEAP_PTR LocHeap;
120   MEM_NB_BLOCK *NBPtr;
121   MEM_MAIN_DATA_BLOCK mmData;
122
123   DCTPtr = MCTPtr->DctData;
124   ErrorRecovery = TRUE;
125   IgnoreErr = FALSE;
126   IDS_OPTION_HOOK (IDS_MEM_ERROR_RECOVERY, &ErrorRecovery, StdHeader);
127
128   if (ErrorRecovery) {
129     if (DCT == EXCLUDE_ALL_DCT) {
130       // Exclude all DCTs on a node
131       for (CurrentDCT = 0; CurrentDCT < MCTPtr->DctCount; CurrentDCT++) {
132         DCTPtr[CurrentDCT].Timings.CsTestFail = DCTPtr[CurrentDCT].Timings.CsPresent;
133       }
134     } else if (ChipSelMask == EXCLUDE_ALL_CHIPSEL) {
135       // Exclude the specified DCT
136       DCTPtr[DCT].Timings.CsTestFail = DCTPtr[DCT].Timings.CsPresent;
137     } else {
138       // Exclude the chip select that has been marked out
139       DCTPtr[DCT].Timings.CsTestFail |= ChipSelMask & DCTPtr[DCT].Timings.CsPresent;
140       IDS_OPTION_HOOK (IDS_LOADCARD_ERROR_RECOVERY, &DCTPtr[DCT], StdHeader);
141     }
142
143     // Exclude the failed dimm to recovery from error
144     if (MCTPtr->NodeMemSize != 0) {
145       LocHeap.BufferHandle = AMD_MEM_AUTO_HANDLE;
146       if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
147         // NB block has already been constructed by main block.
148         // No need to construct it here.
149         NBPtr = (MEM_NB_BLOCK *)LocHeap.BufferPtr;
150         if (!NBPtr->SharedPtr->NodeMap[MCTPtr->NodeId].IsValid) {
151           // Memory map has not been calculated, no need to remap memory across node here.
152           // Only need to remap memory within the node.
153           NBPtr = &NBPtr[MCTPtr->NodeId];
154           NBPtr->FeatPtr->ExcludeDIMM (NBPtr);
155         } else {
156           // Need to remap memory across the whole system.
157           mmData.MemPtr = NBPtr->MemPtr;
158           mmData.mmSharedPtr = NBPtr->SharedPtr;
159           mmData.NBPtr = NBPtr;
160           mmData.TechPtr = (MEM_TECH_BLOCK *) (&NBPtr[NBPtr->MemPtr->DieCount]);
161           mmData.DieCount = NBPtr->MemPtr->DieCount;
162           if (!MemFeatMain.ExcludeDIMM (&mmData)) {
163             return FALSE;
164           }
165         }
166       }
167       // If allocation fails, that means the code is not running at BSP.
168       // Parallel training is in process.
169       // Remap for parallel training will be done when control returns to BSP.
170     }
171     return TRUE;
172   } else {
173     IDS_OPTION_HOOK (IDS_MEM_IGNORE_ERROR, &IgnoreErr, StdHeader);
174     if (IgnoreErr) {
175       return TRUE;
176     }
177     SetMemError (AGESA_FATAL, MCTPtr);
178     // ErrorRecovery is FALSE
179     return FALSE;
180   }
181 }
182
183 /*----------------------------------------------------------------------------
184  *                              LOCAL FUNCTIONS
185  *
186  *----------------------------------------------------------------------------
187  */
188