AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / cpuBist.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU BIST Status Check Implementation.
6  *
7  * Implement CPU BIST Status checking
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (C) 2012 Advanced Micro Devices, Inc.
19  * All rights reserved.
20  *
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.
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
30  *       from this software without specific prior written permission.
31  *
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.
42  *
43  ******************************************************************************
44  */
45
46 /*----------------------------------------------------------------------------------------
47  *                            M O D U L E S    U S E D
48  *----------------------------------------------------------------------------------------
49  */
50 #include "AGESA.h"
51 #include "amdlib.h"
52 #include "Ids.h"
53 #include "cpuRegisters.h"
54 #include "GeneralServices.h"
55 #include "cpuServices.h"
56 #include "cpuApicUtilities.h"
57 #include "Filecode.h"
58 CODE_GROUP (G1_PEICC)
59 RDATA_GROUP (G2_PEI)
60 #define FILECODE PROC_CPU_CPUBIST_FILECODE
61
62 /*----------------------------------------------------------------------------------------
63  *           P R O T O T Y P E S     O F     L O C A L     F U  N C T I O N S
64  *----------------------------------------------------------------------------------------
65  */
66
67 UINT32
68 STATIC
69 GetBistResults (
70   IN       AMD_CONFIG_PARAMS *StdHeader
71   );
72
73  /*----------------------------------------------------------------------------------------
74   *                          E X P O R T E D    F U N C T I O N S
75   *----------------------------------------------------------------------------------------
76  */
77
78  /*---------------------------------------------------------------------------------------*/
79  /**
80   *
81   * This function checks the status of BIST and places the error status in the event log
82   * if there are any errors
83   *
84   * @param[in]      StdHeader              Header for library and services
85   *
86   * @retval         AGESA_SUCCESS          No BIST errors have been logged.
87   * @retval         AGESA_ALERT            BIST errors have been detected and added to the
88   *                                        event log.
89   */
90 AGESA_STATUS
91 CheckBistStatus (
92   IN       AMD_CONFIG_PARAMS *StdHeader
93   )
94 {
95   UINT32                Socket;
96   UINT32                Core;
97   UINT32                BscSocket;
98   UINT32                BscCoreNum;
99   UINT32                NumberOfSockets;
100   UINT32                NumberOfCores;
101   UINT32                Ignored;
102   UINT32                ReturnCode;
103   AGESA_STATUS          IgnoredSts;
104   AGESA_STATUS          AgesaStatus;
105   AP_TASK               TaskPtr;
106
107   // Make sure that Standard Header is valid
108   ASSERT (StdHeader != NULL);
109   ASSERT (IsBsp (StdHeader, &IgnoredSts));
110
111   AgesaStatus = AGESA_SUCCESS;
112
113   // Get the BscSocket, BscCoreNum and NumberOfSockets in the system
114   IdentifyCore (StdHeader, &BscSocket, &Ignored, &BscCoreNum, &IgnoredSts);
115   NumberOfSockets = GetPlatformNumberOfSockets ();
116
117   // Setup TaskPtr struct to execute routine on APs
118   TaskPtr.FuncAddress.PfApTaskO = GetBistResults;
119   TaskPtr.DataTransfer.DataSizeInDwords = 0;
120   TaskPtr.ExeFlags = TASK_HAS_OUTPUT | WAIT_FOR_CORE;
121
122   for (Socket = 0; Socket < NumberOfSockets; Socket++) {
123     if (GetActiveCoresInGivenSocket (Socket, &NumberOfCores, StdHeader)) {
124       for (Core = 0; Core < NumberOfCores; Core++) {
125         if ((Socket != BscSocket) || (Core != BscCoreNum)) {
126           ReturnCode = ApUtilRunCodeOnSocketCore ((UINT8)Socket, (UINT8)Core, &TaskPtr, StdHeader);
127         } else {
128           ReturnCode = TaskPtr.FuncAddress.PfApTaskO (StdHeader);
129         }
130
131         // If BIST value is non-zero, add to BSP's event log
132         if (ReturnCode != 0) {
133           IDS_HDT_CONSOLE (CPU_TRACE, "  BIST failure: socket %d core %d, status = 0x%x\n", Socket, Core, ReturnCode);
134           AgesaStatus = AGESA_ALERT;
135           PutEventLog (AGESA_ALERT,
136                        CPU_EVENT_BIST_ERROR,
137                        ReturnCode, Socket, Core, 0, StdHeader);
138         }
139       }
140     }
141   }
142
143   return AgesaStatus;
144 }
145
146 /*----------------------------------------------------------------------------------------
147  *                          L O C A L          F U N C T I O N S
148  *----------------------------------------------------------------------------------------
149 */
150
151 /*---------------------------------------------------------------------------------------*/
152 /**
153  *
154  * Reads the lower 32 bits of the BIST register
155  *
156  * @param[in]      StdHeader              Header for library and services
157  *
158  * @retval         Value of the BIST register
159 */
160 UINT32
161 STATIC
162 GetBistResults (
163   IN       AMD_CONFIG_PARAMS *StdHeader
164   )
165 {
166   UINT64   BistResults;
167
168   // Read MSRC001_0060 BIST Results Register
169   LibAmdMsrRead (MSR_BIST, &BistResults, StdHeader);
170
171   return (UINT32) (BistResults & 0xFFFFFFFF);
172 }