3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
16 Contains Platform specific implementations required to use status codes.
20 #include "PlatformStatusCode.h"
22 #include <PlatformBaseAddresses.h>
23 #include <Library/PeiServicesLib.h>
24 #include <Library/PcdLib.h>
27 EFI_STATUS_CODE_DATA DataHeader
;
29 } PEIM_FILE_HANDLE_EXTENDED_DATA
;
31 #define CONFIG_PORT0 0x4E
35 #define PCI_LPC_BASE (0x8000F800)
36 #define PCI_LPC_REG(x) (PCI_LPC_BASE + (x))
39 // Function implementations
42 PeiCodeTypeToPostCode (
43 IN EFI_STATUS_CODE_TYPE CodeType
,
44 IN EFI_STATUS_CODE_VALUE Value
,
49 Provide a port 80 status code
51 @param Same as ReportStatusCode PPI
53 @retval EFI_SUCCESS Always returns success.
58 Port80ReportStatusCode (
59 IN CONST EFI_PEI_SERVICES
**PeiServices
,
60 IN EFI_STATUS_CODE_TYPE CodeType
,
61 IN EFI_STATUS_CODE_VALUE Value
,
63 IN CONST EFI_GUID
*CallerId
,
64 IN CONST EFI_STATUS_CODE_DATA
*Data OPTIONAL
69 EFI_FV_FILE_INFO FvFileInfo
;
70 UINT16 Port80Code
= 0;
73 // Progress or error code, Output Port 80h card.
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
,
81 if (!EFI_ERROR (Status
)) {
82 Port80Code
= (FvFileInfo
.FileName
.Data4
[6]<<8) + (FvFileInfo
.FileName
.Data4
[7]);
87 IoWrite16 (0x80, (UINT16
) Port80Code
);
88 DEBUG ((EFI_D_ERROR
, "POSTCODE=<%04x>\n", Port80Code
));
94 Provide a serial status code
96 @param Same as ReportStatusCode PPI
98 @retval EFI_SUCCESS Always returns success.
103 SerialReportStatusCode (
104 IN CONST EFI_PEI_SERVICES
**PeiServices
,
105 IN EFI_STATUS_CODE_TYPE CodeType
,
106 IN EFI_STATUS_CODE_VALUE Value
,
108 IN CONST EFI_GUID
* CallerId
,
109 IN CONST EFI_STATUS_CODE_DATA
* Data OPTIONAL
115 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
124 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
126 // Print ASSERT() information into output buffer.
128 CharCount
= AsciiSPrint (
131 "\n\rPEI_ASSERT!: %a (%d): %a\n\r",
136 } else if (Data
!= NULL
&&
137 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
139 // Print DEBUG() information into output buffer.
141 CharCount
= AsciiBSPrint (
147 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
149 // Print ERROR information into output buffer.
151 CharCount
= AsciiSPrint (
154 "ERROR: C%x:V%x I%x",
160 ASSERT(CharCount
> 0);
162 if (CallerId
!= NULL
) {
163 CharCount
+= AsciiSPrint (
165 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
172 CharCount
+= AsciiSPrint (
174 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
180 CharCount
+= AsciiSPrint (
182 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
185 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
187 // Print PROGRESS information into output buffer.
189 CharCount
= AsciiSPrint (
192 "PROGRESS CODE: V%x I%x\n\r",
196 } else if (Data
!= NULL
&&
197 CompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeStringGuid
) &&
198 ((EFI_STATUS_CODE_STRING_DATA
*) Data
)->StringType
== EfiStringAscii
) {
200 // EFI_STATUS_CODE_STRING_DATA
202 CharCount
= AsciiSPrint (
206 ((EFI_STATUS_CODE_STRING_DATA
*) Data
)->String
.Ascii
210 // Code type is not defined.
212 CharCount
= AsciiSPrint (
215 "Undefined: C%x:V%x I%x\n\r",
223 // Call SerialPort Lib function to do print.
225 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
232 Call all status code listeners in the MonoStatusCode.
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.
241 @retval EFI_SUCCESS If status code is successfully reported.
242 @retval EFI_NOT_AVAILABLE_YET If StatusCodePpi has not been installed.
247 PlatformReportStatusCode (
248 IN CONST EFI_PEI_SERVICES
**PeiServices
,
249 IN EFI_STATUS_CODE_TYPE CodeType
,
250 IN EFI_STATUS_CODE_VALUE Value
,
252 IN CONST EFI_GUID
* CallerId
,
253 IN CONST EFI_STATUS_CODE_DATA
* Data OPTIONAL
257 // If we are in debug mode, we will allow serial status codes
259 SerialReportStatusCode (PeiServices
, CodeType
, Value
, Instance
, CallerId
, Data
);
261 Port80ReportStatusCode (PeiServices
, CodeType
, Value
, Instance
, CallerId
, Data
);
267 Install the PEIM. Initialize listeners, publish the PPI and HOB for PEI and
268 DXE use respectively.
270 @param FfsHeader FV this PEIM was loaded from.
271 @param PeiServices General purpose services available to every PEIM.
273 @retval EFI_SUCCESS The function always returns success.
278 InstallMonoStatusCode (
279 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
280 IN CONST EFI_PEI_SERVICES
**PeiServices
285 // Initialize all listeners
287 InitializeMonoStatusCode (FfsHeader
, PeiServices
);
290 // Publish the listener in a HOB for DXE use.
292 InitializeDxeReportStatusCode (PeiServices
);
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
303 extern PCH_STEPPING EFIAPI
PchStepping (VOID
);
311 Enable legacy decoding on ICH6
315 @retval EFI_SUCCESS Always returns success.
325 // Program and enable PMC Base.
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
));
331 // Enable COM1 for debug message output.
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
);
338 if (PchStepping()>= PchB0
)
339 MmioOr8 (ILB_BASE_ADDRESS
+ R_PCH_ILB_IRQE
, (UINT8
) V_PCH_ILB_IRQE_UARTIRQEN_IRQ4
);
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
);
352 INIT the SIO. Ported this code and I don't undertand the comments either.
354 @param FfsHeader FV this PEIM was loaded from.
355 @param PeiServices General purpose services available to every PEIM.
362 PlatformInitializeStatusCode (
363 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
364 IN CONST EFI_PEI_SERVICES
**PeiServices
369 // Enable internal COM1 on South Cluster.
371 EnableInternalUart();
375 // Initialize additional debug status code listeners.
377 SerialPortInitialize();