]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/StatusCodeHandler/Pei/SerialStatusCodeWorker.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Pei / SerialStatusCodeWorker.c
1 /** @file
2 Serial I/O status code reporting worker.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 **/
7
8 #include "StatusCodeHandlerPei.h"
9
10 /**
11 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
12
13 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
14 @param CodeType Indicates the type of status code being reported.
15 @param Value Describes the current status of a hardware or
16 software entity. This includes information about the class and
17 subclass that is used to classify the entity as well as an operation.
18 For progress codes, the operation is the current activity.
19 For error codes, it is the exception.For debug codes,it is not defined at this time.
20 @param Instance The enumeration of a hardware or software entity within
21 the system. A system may contain multiple entities that match a class/subclass
22 pairing. The instance differentiates between them. An instance of 0 indicates
23 that instance information is unavailable, not meaningful, or not relevant.
24 Valid instance numbers start with 1.
25 @param CallerId This optional parameter may be used to identify the caller.
26 This parameter allows the status code driver to apply different rules to
27 different callers.
28 @param Data This optional parameter may be used to pass additional data.
29
30 @retval EFI_SUCCESS Status code reported to serial I/O successfully.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 SerialStatusCodeReportWorker (
36 IN CONST EFI_PEI_SERVICES **PeiServices,
37 IN EFI_STATUS_CODE_TYPE CodeType,
38 IN EFI_STATUS_CODE_VALUE Value,
39 IN UINT32 Instance,
40 IN CONST EFI_GUID *CallerId,
41 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
42 )
43 {
44 CHAR8 *Filename;
45 CHAR8 *Description;
46 CHAR8 *Format;
47 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
48 UINT32 ErrorLevel;
49 UINT32 LineNumber;
50 UINTN CharCount;
51 BASE_LIST Marker;
52
53 Buffer[0] = '\0';
54
55 if ((Data != NULL) &&
56 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber))
57 {
58 //
59 // Print ASSERT() information into output buffer.
60 //
61 CharCount = AsciiSPrint (
62 Buffer,
63 sizeof (Buffer),
64 "\n\rPEI_ASSERT!: %a (%d): %a\n\r",
65 Filename,
66 LineNumber,
67 Description
68 );
69 } else if ((Data != NULL) &&
70 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format))
71 {
72 //
73 // Print DEBUG() information into output buffer.
74 //
75 CharCount = AsciiBSPrint (
76 Buffer,
77 sizeof (Buffer),
78 Format,
79 Marker
80 );
81 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
82 //
83 // Print ERROR information into output buffer.
84 //
85 CharCount = AsciiSPrint (
86 Buffer,
87 sizeof (Buffer),
88 "ERROR: C%08x:V%08x I%x",
89 CodeType,
90 Value,
91 Instance
92 );
93
94 ASSERT (CharCount > 0);
95
96 if (CallerId != NULL) {
97 CharCount += AsciiSPrint (
98 &Buffer[CharCount],
99 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
100 " %g",
101 CallerId
102 );
103 }
104
105 if (Data != NULL) {
106 CharCount += AsciiSPrint (
107 &Buffer[CharCount],
108 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
109 " %x",
110 Data
111 );
112 }
113
114 CharCount += AsciiSPrint (
115 &Buffer[CharCount],
116 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
117 "\n\r"
118 );
119 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
120 //
121 // Print PROGRESS information into output buffer.
122 //
123 CharCount = AsciiSPrint (
124 Buffer,
125 sizeof (Buffer),
126 "PROGRESS CODE: V%08x I%x\n\r",
127 Value,
128 Instance
129 );
130 } else if ((Data != NULL) &&
131 CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) &&
132 (((EFI_STATUS_CODE_STRING_DATA *)Data)->StringType == EfiStringAscii))
133 {
134 //
135 // EFI_STATUS_CODE_STRING_DATA
136 //
137 CharCount = AsciiSPrint (
138 Buffer,
139 sizeof (Buffer),
140 "%a",
141 ((EFI_STATUS_CODE_STRING_DATA *)Data)->String.Ascii
142 );
143 } else {
144 //
145 // Code type is not defined.
146 //
147 CharCount = AsciiSPrint (
148 Buffer,
149 sizeof (Buffer),
150 "Undefined: C%08x:V%08x I%x\n\r",
151 CodeType,
152 Value,
153 Instance
154 );
155 }
156
157 //
158 // Call SerialPort Lib function to do print.
159 //
160 SerialPortWrite ((UINT8 *)Buffer, CharCount);
161
162 return EFI_SUCCESS;
163 }