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