]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Dxe/SerialStatusCodeWorker.c
Add some definitions for efi event in Uefi/UefiSpec.h to follow spec.
[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 #include "DxeStatusCode.h"
19
20 STATIC
21 EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;
22
23 /**
24 Initialize serial status code worker.
25
26 @return The function always return EFI_SUCCESS
27
28 **/
29 EFI_STATUS
30 EfiSerialStatusCodeInitializeWorker (
31 VOID
32 )
33 {
34 EFI_STATUS Status;
35
36 Status = gBS->LocateProtocol (
37 &gEfiSerialIoProtocolGuid,
38 NULL,
39 (VOID **) &mSerialIoProtocol
40 );
41
42 ASSERT_EFI_ERROR (Status);
43
44 return EFI_SUCCESS;
45 }
46
47
48 /**
49 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
50
51 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
52
53 @param Value Describes the current status of a hardware or software entity.
54 This included information about the class and subclass that is used to classify the entity
55 as well as an operation. For progress codes, the operation is the current activity.
56 For error codes, it is the exception. For debug codes, it is not defined at this time.
57 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
58 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
59
60 @param Instance The enumeration of a hardware or software entity within the system.
61 A system may contain multiple entities that match a class/subclass pairing.
62 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
63 not meaningful, or not relevant. Valid instance numbers start with 1.
64
65
66 @param CallerId This optional parameter may be used to identify the caller.
67 This parameter allows the status code driver to apply different rules to different callers.
68 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
69
70
71 @param Data This optional parameter may be used to pass additional data
72
73 @retval EFI_SUCCESS Success to report status code to serial I/O.
74 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
75
76 **/
77 EFI_STATUS
78 SerialStatusCodeReportWorker (
79 IN EFI_STATUS_CODE_TYPE CodeType,
80 IN EFI_STATUS_CODE_VALUE Value,
81 IN UINT32 Instance,
82 IN EFI_GUID *CallerId,
83 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
84 )
85 {
86 CHAR8 *Filename;
87 CHAR8 *Description;
88 CHAR8 *Format;
89 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
90 UINT32 ErrorLevel;
91 UINT32 LineNumber;
92 UINTN CharCount;
93 VA_LIST Marker;
94 EFI_DEBUG_INFO *DebugInfo;
95 EFI_TPL CurrentTpl;
96
97
98 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
99 if (EfiAtRuntime ()) {
100 return EFI_DEVICE_ERROR;
101 }
102 CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
103 gBS->RestoreTPL (CurrentTpl);
104
105 if (CurrentTpl > TPL_CALLBACK ) {
106 return EFI_DEVICE_ERROR;
107 }
108 }
109
110 Buffer[0] = '\0';
111
112 if (Data != NULL &&
113 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
114 //
115 // Print ASSERT() information into output buffer.
116 //
117 CharCount = AsciiSPrint (
118 Buffer,
119 EFI_STATUS_CODE_DATA_MAX_SIZE,
120 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
121 Filename,
122 LineNumber,
123 Description
124 );
125 } else if (Data != NULL &&
126 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
127 //
128 // Print DEBUG() information into output buffer.
129 //
130 CharCount = AsciiVSPrint (
131 Buffer,
132 EFI_STATUS_CODE_DATA_MAX_SIZE,
133 Format,
134 Marker
135 );
136 } else if (Data != NULL &&
137 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
138 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
139 //
140 // Print specific data into output buffer.
141 //
142 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
143 Marker = (VA_LIST) (DebugInfo + 1);
144 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
145
146 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
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 EFI_STATUS_CODE_DATA_MAX_SIZE,
154 "ERROR: C%x:V%x I%x",
155 CodeType,
156 Value,
157 Instance
158 );
159
160 //
161 // Make sure we don't try to print values that weren't
162 // intended to be printed, especially NULL GUID pointers.
163 //
164
165 if (CallerId != NULL) {
166 CharCount += AsciiSPrint (
167 &Buffer[CharCount - 1],
168 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
169 " %g",
170 CallerId
171 );
172 }
173
174 if (Data != NULL) {
175 CharCount += AsciiSPrint (
176 &Buffer[CharCount - 1],
177 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
178 " %x",
179 Data
180 );
181 }
182
183 CharCount += AsciiSPrint (
184 &Buffer[CharCount - 1],
185 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
186 "\n\r"
187 );
188 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
189 CharCount = AsciiSPrint (
190 Buffer,
191 EFI_STATUS_CODE_DATA_MAX_SIZE,
192 "PROGRESS CODE: V%x I%x\n\r",
193 Value,
194 Instance
195 );
196 } else {
197 CharCount = AsciiSPrint (
198 Buffer,
199 EFI_STATUS_CODE_DATA_MAX_SIZE,
200 "Undefined: C%x:V%x I%x\n\r",
201 CodeType,
202 Value,
203 Instance
204 );
205 }
206
207
208 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
209 //
210 // Callout to SerialPort Lib function to do print.
211 //
212 SerialPortWrite ((UINT8 *) Buffer, CharCount);
213 }
214 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
215 mSerialIoProtocol->Write (
216 mSerialIoProtocol,
217 &CharCount,
218 Buffer
219 );
220 }
221
222 return EFI_SUCCESS;
223 }