]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Dxe/SerialStatusCodeWorker.c
Follow up tracker:
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / SerialStatusCodeWorker.c
1
2 /** @file
3 Serial I/O status code reporting worker.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 Module Name: SerialStatusCodeWorker.c
15
16 **/
17
18 STATIC
19 EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;
20
21 /**
22 Initialize serial status code worker.
23
24 @return The function always return EFI_SUCCESS
25
26 **/
27 EFI_STATUS
28 EfiSerialStatusCodeInitializeWorker (
29 VOID
30 )
31 {
32 EFI_STATUS Status;
33
34 Status = gBS->LocateProtocol (
35 &gEfiSerialIoProtocolGuid,
36 NULL,
37 (VOID **) &mSerialIoProtocol
38 );
39
40 ASSERT_EFI_ERROR (Status);
41
42 return EFI_SUCCESS;
43 }
44
45
46 /**
47 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
48
49 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
50
51 @param Value Describes the current status of a hardware or software entity.
52 This included information about the class and subclass that is used to classify the entity
53 as well as an operation. For progress codes, the operation is the current activity.
54 For error codes, it is the exception. For debug codes, it is not defined at this time.
55 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
56 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
57
58 @param Instance The enumeration of a hardware or software entity within the system.
59 A system may contain multiple entities that match a class/subclass pairing.
60 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
61 not meaningful, or not relevant. Valid instance numbers start with 1.
62
63
64 @param CallerId This optional parameter may be used to identify the caller.
65 This parameter allows the status code driver to apply different rules to different callers.
66 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
67
68
69 @param Data This optional parameter may be used to pass additional data
70
71 @retval EFI_SUCCESS Success to report status code to serial I/O.
72 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
73
74 **/
75 EFI_STATUS
76 SerialStatusCodeReportWorker (
77 IN EFI_STATUS_CODE_TYPE CodeType,
78 IN EFI_STATUS_CODE_VALUE Value,
79 IN UINT32 Instance,
80 IN EFI_GUID *CallerId,
81 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
82 )
83 {
84 CHAR8 *Filename;
85 CHAR8 *Description;
86 CHAR8 *Format;
87 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
88 UINT32 ErrorLevel;
89 UINT32 LineNumber;
90 UINTN CharCount;
91 VA_LIST Marker;
92 EFI_DEBUG_INFO *DebugInfo;
93
94
95 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial) && EfiAtRuntime ()) {
96 return EFI_DEVICE_ERROR;
97 }
98
99 Buffer[0] = '\0';
100
101 if (Data != NULL &&
102 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
103 //
104 // Print ASSERT() information into output buffer.
105 //
106 CharCount = AsciiSPrint (
107 Buffer,
108 EFI_STATUS_CODE_DATA_MAX_SIZE,
109 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
110 Filename,
111 LineNumber,
112 Description
113 );
114 } else if (Data != NULL &&
115 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
116 //
117 // Print DEBUG() information into output buffer.
118 //
119 CharCount = AsciiVSPrint (
120 Buffer,
121 EFI_STATUS_CODE_DATA_MAX_SIZE,
122 Format,
123 Marker
124 );
125 } else if (Data != NULL &&
126 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
127 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
128 //
129 // Print specific data into output buffer.
130 //
131 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
132 Marker = (VA_LIST) (DebugInfo + 1);
133 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
134
135 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
136 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
137 //
138 // Print ERROR information into output buffer.
139 //
140 CharCount = AsciiSPrint (
141 Buffer,
142 EFI_STATUS_CODE_DATA_MAX_SIZE,
143 "ERROR: C%x:V%x I%x",
144 CodeType,
145 Value,
146 Instance
147 );
148
149 //
150 // Make sure we don't try to print values that weren't
151 // intended to be printed, especially NULL GUID pointers.
152 //
153
154 if (CallerId != NULL) {
155 CharCount += AsciiSPrint (
156 &Buffer[CharCount - 1],
157 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
158 " %g",
159 CallerId
160 );
161 }
162
163 if (Data != NULL) {
164 CharCount += AsciiSPrint (
165 &Buffer[CharCount - 1],
166 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
167 " %x",
168 Data
169 );
170 }
171
172 CharCount += AsciiSPrint (
173 &Buffer[CharCount - 1],
174 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
175 "\n\r"
176 );
177 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
178 CharCount = AsciiSPrint (
179 Buffer,
180 EFI_STATUS_CODE_DATA_MAX_SIZE,
181 "PROGRESS CODE: V%x I%x\n\r",
182 Value,
183 Instance
184 );
185 } else {
186 CharCount = AsciiSPrint (
187 Buffer,
188 EFI_STATUS_CODE_DATA_MAX_SIZE,
189 "Undefined: C%x:V%x I%x\n\r",
190 CodeType,
191 Value,
192 Instance
193 );
194 }
195
196
197 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
198 //
199 // Callout to SerialPort Lib function to do print.
200 //
201 SerialPortWrite ((UINT8 *) Buffer, CharCount);
202 }
203 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
204 mSerialIoProtocol->Write (
205 mSerialIoProtocol,
206 &CharCount,
207 Buffer
208 );
209 }
210
211 return EFI_SUCCESS;
212 }