]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/MonoStatusCode/PlatformStatusCode.c
BaseTools: Fix corner-cases of --hash feature
[mirror_edk2.git] / Vlv2TbltDevicePkg / MonoStatusCode / PlatformStatusCode.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7
8
9 Module Name:
10
11
12 PlatformStatusCode.c
13
14 Abstract:
15
16 Contains Platform specific implementations required to use status codes.
17
18 --*/
19
20 #include "PlatformStatusCode.h"
21 #include <PchRegs.h>
22 #include <PlatformBaseAddresses.h>
23 #include <Library/PeiServicesLib.h>
24 #include <Library/PcdLib.h>
25
26 typedef struct {
27 EFI_STATUS_CODE_DATA DataHeader;
28 EFI_HANDLE Handle;
29 } PEIM_FILE_HANDLE_EXTENDED_DATA;
30
31 #define CONFIG_PORT0 0x4E
32 #define PCI_IDX 0xCF8
33 #define PCI_DAT 0xCFC
34
35 #define PCI_LPC_BASE (0x8000F800)
36 #define PCI_LPC_REG(x) (PCI_LPC_BASE + (x))
37
38 //
39 // Function implementations
40 //
41 BOOLEAN
42 PeiCodeTypeToPostCode (
43 IN EFI_STATUS_CODE_TYPE CodeType,
44 IN EFI_STATUS_CODE_VALUE Value,
45 OUT UINT8 *PostCode
46 );
47
48 /**
49 Provide a port 80 status code
50
51 @param Same as ReportStatusCode PPI
52
53 @retval EFI_SUCCESS Always returns success.
54
55 **/
56 EFI_STATUS
57 EFIAPI
58 Port80ReportStatusCode (
59 IN CONST EFI_PEI_SERVICES **PeiServices,
60 IN EFI_STATUS_CODE_TYPE CodeType,
61 IN EFI_STATUS_CODE_VALUE Value,
62 IN UINT32 Instance,
63 IN CONST EFI_GUID *CallerId,
64 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
65 )
66
67 {
68 EFI_STATUS Status;
69 EFI_FV_FILE_INFO FvFileInfo;
70 UINT16 Port80Code = 0;
71
72 //
73 // Progress or error code, Output Port 80h card.
74 //
75 if (!PeiCodeTypeToPostCode (CodeType, Value, (UINT8 *)&Port80Code)) {
76 if ((Data != NULL) && (Value ==(EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN))){
77 Status = PeiServicesFfsGetFileInfo (
78 ((PEIM_FILE_HANDLE_EXTENDED_DATA *) (Data + 1))->Handle,
79 &FvFileInfo
80 );
81 if (!EFI_ERROR (Status)) {
82 Port80Code = (FvFileInfo.FileName.Data4[6]<<8) + (FvFileInfo.FileName.Data4[7]);
83 }
84 }
85 }
86 if (Port80Code != 0){
87 IoWrite16 (0x80, (UINT16) Port80Code);
88 DEBUG ((EFI_D_ERROR, "POSTCODE=<%04x>\n", Port80Code));
89 }
90 return EFI_SUCCESS;
91 }
92
93 /**
94 Provide a serial status code
95
96 @param Same as ReportStatusCode PPI
97
98 @retval EFI_SUCCESS Always returns success.
99
100 **/
101 EFI_STATUS
102 EFIAPI
103 SerialReportStatusCode (
104 IN CONST EFI_PEI_SERVICES **PeiServices,
105 IN EFI_STATUS_CODE_TYPE CodeType,
106 IN EFI_STATUS_CODE_VALUE Value,
107 IN UINT32 Instance,
108 IN CONST EFI_GUID * CallerId,
109 IN CONST EFI_STATUS_CODE_DATA * Data OPTIONAL
110 )
111 {
112 CHAR8 *Filename;
113 CHAR8 *Description;
114 CHAR8 *Format;
115 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
116 UINT32 ErrorLevel;
117 UINT32 LineNumber;
118 UINTN CharCount;
119 BASE_LIST Marker;
120
121 Buffer[0] = '\0';
122
123 if (Data != NULL &&
124 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
125 //
126 // Print ASSERT() information into output buffer.
127 //
128 CharCount = AsciiSPrint (
129 Buffer,
130 sizeof (Buffer),
131 "\n\rPEI_ASSERT!: %a (%d): %a\n\r",
132 Filename,
133 LineNumber,
134 Description
135 );
136 } else if (Data != NULL &&
137 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
138 //
139 // Print DEBUG() information into output buffer.
140 //
141 CharCount = AsciiBSPrint (
142 Buffer,
143 sizeof (Buffer),
144 Format,
145 Marker
146 );
147 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
148 //
149 // Print ERROR information into output buffer.
150 //
151 CharCount = AsciiSPrint (
152 Buffer,
153 sizeof (Buffer),
154 "ERROR: C%x:V%x I%x",
155 CodeType,
156 Value,
157 Instance
158 );
159
160 ASSERT(CharCount > 0);
161
162 if (CallerId != NULL) {
163 CharCount += AsciiSPrint (
164 &Buffer[CharCount],
165 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
166 " %g",
167 CallerId
168 );
169 }
170
171 if (Data != NULL) {
172 CharCount += AsciiSPrint (
173 &Buffer[CharCount],
174 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
175 " %x",
176 Data
177 );
178 }
179
180 CharCount += AsciiSPrint (
181 &Buffer[CharCount],
182 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
183 "\n\r"
184 );
185 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
186 //
187 // Print PROGRESS information into output buffer.
188 //
189 CharCount = AsciiSPrint (
190 Buffer,
191 sizeof (Buffer),
192 "PROGRESS CODE: V%x I%x\n\r",
193 Value,
194 Instance
195 );
196 } else if (Data != NULL &&
197 CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&
198 ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType == EfiStringAscii) {
199 //
200 // EFI_STATUS_CODE_STRING_DATA
201 //
202 CharCount = AsciiSPrint (
203 Buffer,
204 sizeof (Buffer),
205 "%a\n\r",
206 ((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii
207 );
208 } else {
209 //
210 // Code type is not defined.
211 //
212 CharCount = AsciiSPrint (
213 Buffer,
214 sizeof (Buffer),
215 "Undefined: C%x:V%x I%x\n\r",
216 CodeType,
217 Value,
218 Instance
219 );
220 }
221
222 //
223 // Call SerialPort Lib function to do print.
224 //
225 SerialPortWrite ((UINT8 *) Buffer, CharCount);
226
227 return EFI_SUCCESS;
228 }
229
230 /**
231
232 Call all status code listeners in the MonoStatusCode.
233
234 @param PeiServices The PEI core services table.
235 @param CodeType Type of Status Code.
236 @param Value Value to output for Status Code.
237 @param Instance Instance Number of this status code.
238 @param CallerId ID of the caller of this status code.
239 @param Data Optional data associated with this status code.
240
241 @retval EFI_SUCCESS If status code is successfully reported.
242 @retval EFI_NOT_AVAILABLE_YET If StatusCodePpi has not been installed.
243
244 **/
245 EFI_STATUS
246 EFIAPI
247 PlatformReportStatusCode (
248 IN CONST EFI_PEI_SERVICES **PeiServices,
249 IN EFI_STATUS_CODE_TYPE CodeType,
250 IN EFI_STATUS_CODE_VALUE Value,
251 IN UINT32 Instance,
252 IN CONST EFI_GUID * CallerId,
253 IN CONST EFI_STATUS_CODE_DATA * Data OPTIONAL
254 )
255 {
256 //
257 // If we are in debug mode, we will allow serial status codes
258 //
259 SerialReportStatusCode (PeiServices, CodeType, Value, Instance, CallerId, Data);
260
261 Port80ReportStatusCode (PeiServices, CodeType, Value, Instance, CallerId, Data);
262
263 return EFI_SUCCESS;
264 }
265
266 /**
267 Install the PEIM. Initialize listeners, publish the PPI and HOB for PEI and
268 DXE use respectively.
269
270 @param FfsHeader FV this PEIM was loaded from.
271 @param PeiServices General purpose services available to every PEIM.
272
273 @retval EFI_SUCCESS The function always returns success.
274
275 **/
276 EFI_STATUS
277 EFIAPI
278 InstallMonoStatusCode (
279 IN EFI_FFS_FILE_HEADER *FfsHeader,
280 IN CONST EFI_PEI_SERVICES **PeiServices
281 )
282 {
283
284 //
285 // Initialize all listeners
286 //
287 InitializeMonoStatusCode (FfsHeader, PeiServices);
288
289 //
290 // Publish the listener in a HOB for DXE use.
291 //
292 InitializeDxeReportStatusCode (PeiServices);
293
294 return EFI_SUCCESS;
295 }
296
297 #define V_PCH_ILB_IRQE_UARTIRQEN_IRQ3 BIT3 // UART IRQ3 Enable
298 #define V_PCH_ILB_IRQE_UARTIRQEN_IRQ4 BIT4 // UART IRQ4 Enable
299 #define PCIEX_BASE_ADDRESS 0xE0000000
300 #define PciD31F0RegBase PCIEX_BASE_ADDRESS + (UINT32) (31 << 15)
301 #define SB_RCBA 0xfed1c000
302
303 extern PCH_STEPPING EFIAPI PchStepping (VOID);
304
305 VOID
306 RamDebugInit (
307 VOID
308 );
309
310 /**
311 Enable legacy decoding on ICH6
312
313 @param none
314
315 @retval EFI_SUCCESS Always returns success.
316
317 **/
318 EFI_STATUS
319 EnableInternalUart(
320 VOID
321 )
322 {
323
324 //
325 // Program and enable PMC Base.
326 //
327 IoWrite32 (PCI_IDX, PCI_LPC_REG(R_PCH_LPC_PMC_BASE));
328 IoWrite32 (PCI_DAT, (PMC_BASE_ADDRESS | B_PCH_LPC_PMC_BASE_EN));
329
330 //
331 // Enable COM1 for debug message output.
332 //
333 MmioAndThenOr32 (PMC_BASE_ADDRESS + R_PCH_PMC_GEN_PMCON_1, (UINT32) (~(B_PCH_PMC_GEN_PMCON_SUS_PWR_FLR + B_PCH_PMC_GEN_PMCON_PWROK_FLR)), BIT24);
334
335 //
336 // Silicon Steppings
337 //
338 if (PchStepping()>= PchB0)
339 MmioOr8 (ILB_BASE_ADDRESS + R_PCH_ILB_IRQE, (UINT8) V_PCH_ILB_IRQE_UARTIRQEN_IRQ4);
340 else
341 MmioOr8 (ILB_BASE_ADDRESS + R_PCH_ILB_IRQE, (UINT8) V_PCH_ILB_IRQE_UARTIRQEN_IRQ3);
342 MmioAnd32(IO_BASE_ADDRESS + 0x0520, (UINT32)~(0x00000187));
343 MmioOr32 (IO_BASE_ADDRESS + 0x0520, (UINT32)0x81); // UART3_RXD-L
344 MmioAnd32(IO_BASE_ADDRESS + 0x0530, (UINT32)~(0x00000007));
345 MmioOr32 (IO_BASE_ADDRESS + 0x0530, (UINT32)0x1); // UART3_RXD-L
346 MmioOr8 (PciD31F0RegBase + R_PCH_LPC_UART_CTRL, (UINT8) B_PCH_LPC_UART_CTRL_COM1_EN);
347
348 return EFI_SUCCESS;
349 }
350
351 /**
352 INIT the SIO. Ported this code and I don't undertand the comments either.
353
354 @param FfsHeader FV this PEIM was loaded from.
355 @param PeiServices General purpose services available to every PEIM.
356
357 None
358
359 **/
360 VOID
361 EFIAPI
362 PlatformInitializeStatusCode (
363 IN EFI_FFS_FILE_HEADER *FfsHeader,
364 IN CONST EFI_PEI_SERVICES **PeiServices
365 )
366 {
367
368 //
369 // Enable internal COM1 on South Cluster.
370 //
371 EnableInternalUart();
372
373
374 //
375 // Initialize additional debug status code listeners.
376 //
377 SerialPortInitialize();
378
379 }
380 //#endif //EFI_DEBUG
381