]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
Remove unnecessary use of gEfiStatusCodeSpecificDataGuid and sync algorithm with...
[mirror_edk2.git] / UnixPkg / Library / DxeUnixOemHookStatusCodeLib / UnixOemHookStatusCodeLib.c
1 /** @file
2 OEM hook status code library functions with no library constructor/destructor
3
4 Copyright (c) 2006, 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 Module Name: UnixOemHookStatusCodeLib.c
14
15 **/
16 #include "PiDxe.h"
17 #include <Guid/StatusCodeDataTypeId.h>
18 #include "UnixDxe.h"
19 #include <Library/OemHookStatusCodeLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/PrintLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/ReportStatusCodeLib.h>
25 #include <FrameworkModuleBase.h>
26 #include <DebugInfo.h>
27
28 //
29 // Cache of UnixThunk protocol
30 //
31 EFI_UNIX_THUNK_PROTOCOL *mUnix;
32
33 //
34 // Cache of standard output handle .
35 //
36 int mStdOut;
37
38 /**
39
40 Initialize OEM status code device .
41
42 @return Always return EFI_SUCCESS.
43
44 **/
45 EFI_STATUS
46 EFIAPI
47 OemHookStatusCodeInitialize (
48 VOID
49 )
50 {
51 EFI_HOB_GUID_TYPE *GuidHob;
52
53 //
54 // Retrieve UnixThunkProtocol from GUID'ed HOB
55 //
56 GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);
57 ASSERT (GuidHob != NULL);
58 mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
59 ASSERT (mUnix != NULL);
60
61 //
62 // Cache standard output handle.
63 //
64 mStdOut = 1;
65
66 return EFI_SUCCESS;
67 }
68
69 /**
70 Report status code to OEM device.
71
72 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
73
74 @param Value Describes the current status of a hardware or software entity.
75 This included information about the class and subclass that is used to classify the entity
76 as well as an operation. For progress codes, the operation is the current activity.
77 For error codes, it is the exception. For debug codes, it is not defined at this time.
78 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
79 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
80
81 @param Instance The enumeration of a hardware or software entity within the system.
82 A system may contain multiple entities that match a class/subclass pairing.
83 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
84 not meaningful, or not relevant. Valid instance numbers start with 1.
85
86
87 @param CallerId This optional parameter may be used to identify the caller.
88 This parameter allows the status code driver to apply different rules to different callers.
89 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
90
91
92 @param Data This optional parameter may be used to pass additional data
93
94 @return The function always return EFI_SUCCESS.
95
96 **/
97 EFI_STATUS
98 EFIAPI
99 OemHookStatusCodeReport (
100 IN EFI_STATUS_CODE_TYPE CodeType,
101 IN EFI_STATUS_CODE_VALUE Value,
102 IN UINT32 Instance,
103 IN EFI_GUID *CallerId, OPTIONAL
104 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
105 )
106 {
107 CHAR8 *Filename;
108 CHAR8 *Description;
109 CHAR8 *Format;
110 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
111 UINT32 ErrorLevel;
112 UINT32 LineNumber;
113 UINTN CharCount;
114 BASE_LIST Marker;
115
116 Buffer[0] = '\0';
117
118 if (Data != NULL &&
119 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
120 //
121 // Print ASSERT() information into output buffer.
122 //
123 CharCount = AsciiSPrint (
124 Buffer,
125 EFI_STATUS_CODE_DATA_MAX_SIZE,
126 "\n\rASSERT!: %a (%d): %a\n\r",
127 Filename,
128 LineNumber,
129 Description
130 );
131
132 //
133 // Callout to standard output.
134 //
135 mUnix->Write (
136 mStdOut,
137 Buffer,
138 CharCount
139 );
140
141 return EFI_SUCCESS;
142
143 } else if (Data != NULL &&
144 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
145 //
146 // Print DEBUG() information into output buffer.
147 //
148 CharCount = AsciiBSPrint (
149 Buffer,
150 EFI_STATUS_CODE_DATA_MAX_SIZE,
151 Format,
152 Marker
153 );
154 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
155 //
156 // Print ERROR information into output buffer.
157 //
158 CharCount = AsciiSPrint (
159 Buffer,
160 EFI_STATUS_CODE_DATA_MAX_SIZE,
161 "ERROR: C%x:V%x I%x",
162 CodeType,
163 Value,
164 Instance
165 );
166
167 //
168 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
169 //
170
171 if (CallerId != NULL) {
172 CharCount += AsciiSPrint (
173 &Buffer[CharCount - 1],
174 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
175 " %g",
176 CallerId
177 );
178 }
179
180 if (Data != NULL) {
181 CharCount += AsciiSPrint (
182 &Buffer[CharCount - 1],
183 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
184 " %x",
185 Data
186 );
187 }
188
189 CharCount += AsciiSPrint (
190 &Buffer[CharCount - 1],
191 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
192 "\n\r"
193 );
194 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
195 CharCount = AsciiSPrint (
196 Buffer,
197 EFI_STATUS_CODE_DATA_MAX_SIZE,
198 "PROGRESS CODE: V%x I%x\n\r",
199 Value,
200 Instance
201 );
202 } else {
203 CharCount = AsciiSPrint (
204 Buffer,
205 EFI_STATUS_CODE_DATA_MAX_SIZE,
206 "Undefined: C%x:V%x I%x\n\r",
207 CodeType,
208 Value,
209 Instance
210 );
211 }
212
213 //
214 // Callout to standard output.
215 //
216 mUnix->Write (
217 mStdOut,
218 Buffer,
219 CharCount
220 );
221
222 return EFI_SUCCESS;
223 }
224