]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/SerialStatusCodeWorker.c
Reviewed the code comments in the Include/Protocol directory for typos, grammar issue...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / RuntimeDxe / SerialStatusCodeWorker.c
1 /** @file
2 Serial I/O status code reporting worker.
3
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "StatusCodeRuntimeDxe.h"
16
17 EFI_SERIAL_IO_PROTOCOL *mSerialIoProtocol;
18
19 /**
20 Locates Serial I/O Protocol as initialization for serial status code worker.
21
22 @retval EFI_SUCCESS Serial I/O Protocol is successfully located.
23
24 **/
25 EFI_STATUS
26 EfiSerialStatusCodeInitializeWorker (
27 VOID
28 )
29 {
30 EFI_STATUS Status;
31
32 Status = gBS->LocateProtocol (
33 &gEfiSerialIoProtocolGuid,
34 NULL,
35 (VOID **) &mSerialIoProtocol
36 );
37
38 ASSERT_EFI_ERROR (Status);
39
40 return EFI_SUCCESS;
41 }
42
43
44 /**
45 Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
46
47 @param CodeType Indicates the type of status code being reported.
48 @param Value Describes the current status of a hardware or software entity.
49 This included information about the class and subclass that is used to
50 classify the entity as well as an operation.
51 @param Instance The enumeration of a hardware or software entity within
52 the system. Valid instance numbers start with 1.
53 @param CallerId This optional parameter may be used to identify the caller.
54 This parameter allows the status code driver to apply different rules to
55 different callers.
56 @param Data This optional parameter may be used to pass additional data.
57
58 @retval EFI_SUCCESS Status code reported to serial I/O successfully.
59 @retval EFI_DEVICE_ERROR EFI serial device cannot work after ExitBootService() is called.
60 @retval EFI_DEVICE_ERROR EFI serial device cannot work with TPL higher than TPL_CALLBACK.
61
62 **/
63 EFI_STATUS
64 SerialStatusCodeReportWorker (
65 IN EFI_STATUS_CODE_TYPE CodeType,
66 IN EFI_STATUS_CODE_VALUE Value,
67 IN UINT32 Instance,
68 IN EFI_GUID *CallerId,
69 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
70 )
71 {
72 CHAR8 *Filename;
73 CHAR8 *Description;
74 CHAR8 *Format;
75 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
76 UINT32 ErrorLevel;
77 UINT32 LineNumber;
78 UINTN CharCount;
79 BASE_LIST Marker;
80
81 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
82 if (EfiAtRuntime ()) {
83 return EFI_DEVICE_ERROR;
84 }
85 if (EfiGetCurrentTpl () > TPL_CALLBACK ) {
86 return EFI_DEVICE_ERROR;
87 }
88 }
89
90 Buffer[0] = '\0';
91
92 if (Data != NULL &&
93 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
94 //
95 // Print ASSERT() information into output buffer.
96 //
97 CharCount = AsciiSPrint (
98 Buffer,
99 sizeof (Buffer),
100 "\n\rDXE_ASSERT!: %a (%d): %a\n\r",
101 Filename,
102 LineNumber,
103 Description
104 );
105 } else if (Data != NULL &&
106 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
107 //
108 // Print DEBUG() information into output buffer.
109 //
110 CharCount = AsciiBSPrint (
111 Buffer,
112 sizeof (Buffer),
113 Format,
114 Marker
115 );
116 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
117 //
118 // Print ERROR information into output buffer.
119 //
120 CharCount = AsciiSPrint (
121 Buffer,
122 sizeof (Buffer),
123 "ERROR: C%x:V%x I%x",
124 CodeType,
125 Value,
126 Instance
127 );
128
129 if (CallerId != NULL) {
130 CharCount += AsciiSPrint (
131 &Buffer[CharCount - 1],
132 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
133 " %g",
134 CallerId
135 );
136 }
137
138 if (Data != NULL) {
139 CharCount += AsciiSPrint (
140 &Buffer[CharCount - 1],
141 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
142 " %x",
143 Data
144 );
145 }
146
147 CharCount += AsciiSPrint (
148 &Buffer[CharCount - 1],
149 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
150 "\n\r"
151 );
152 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
153 //
154 // Print PROGRESS information into output buffer.
155 //
156 CharCount = AsciiSPrint (
157 Buffer,
158 sizeof (Buffer),
159 "PROGRESS CODE: V%x I%x\n\r",
160 Value,
161 Instance
162 );
163 } else {
164 //
165 // Code type is not defined.
166 //
167 CharCount = AsciiSPrint (
168 Buffer,
169 sizeof (Buffer),
170 "Undefined: C%x:V%x I%x\n\r",
171 CodeType,
172 Value,
173 Instance
174 );
175 }
176
177
178 if (FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
179 //
180 // Call SerialPort Lib function to do print.
181 //
182 SerialPortWrite ((UINT8 *) Buffer, CharCount);
183 }
184 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial)) {
185 mSerialIoProtocol->Write (
186 mSerialIoProtocol,
187 &CharCount,
188 Buffer
189 );
190 }
191
192 return EFI_SUCCESS;
193 }
194