]> git.proxmox.com Git - mirror_edk2.git/blob - EdkUnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
fix build broken issue
[mirror_edk2.git] / EdkUnixPkg / Library / PeiUnixOemHookStatusCodeLib / 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 PEI_UNIX_THUNK_PPI *UnixThunkPpi;
43 EFI_STATUS Status;
44
45
46 //
47 // Locate Unix ThunkPpi for retrieving standard output handle
48 //
49 Status = PeiServicesLocatePpi (
50 &gPeiUnixThunkPpiGuid,
51 0,
52 NULL,
53 (VOID **) &UnixThunkPpi
54 );
55
56 ASSERT_EFI_ERROR (Status);
57
58 mUnix = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();
59
60 //
61 // Cache standard output handle.
62 //
63 mStdOut = 1;
64
65 return EFI_SUCCESS;
66 }
67
68 /**
69 Report status code to OEM device.
70
71 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
72
73 @param Value Describes the current status of a hardware or software entity.
74 This included information about the class and subclass that is used to classify the entity
75 as well as an operation. For progress codes, the operation is the current activity.
76 For error codes, it is the exception. For debug codes, it is not defined at this time.
77 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
78 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
79
80 @param Instance The enumeration of a hardware or software entity within the system.
81 A system may contain multiple entities that match a class/subclass pairing.
82 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
83 not meaningful, or not relevant. Valid instance numbers start with 1.
84
85
86 @param CallerId This optional parameter may be used to identify the caller.
87 This parameter allows the status code driver to apply different rules to different callers.
88 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
89
90
91 @param Data This optional parameter may be used to pass additional data
92
93 @return The function always return EFI_SUCCESS.
94
95 **/
96 EFI_STATUS
97 EFIAPI
98 OemHookStatusCodeReport (
99 IN EFI_STATUS_CODE_TYPE CodeType,
100 IN EFI_STATUS_CODE_VALUE Value,
101 IN UINT32 Instance,
102 IN EFI_GUID *CallerId, OPTIONAL
103 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
104 )
105 {
106 CHAR8 *Filename;
107 CHAR8 *Description;
108 CHAR8 *Format;
109 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
110 UINT32 ErrorLevel;
111 UINT32 LineNumber;
112 UINTN CharCount;
113 VA_LIST Marker;
114 EFI_DEBUG_INFO *DebugInfo;
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 = AsciiVSPrint (
149 Buffer,
150 EFI_STATUS_CODE_DATA_MAX_SIZE,
151 Format,
152 Marker
153 );
154 } else if (Data != NULL &&
155 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
156 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
157 //
158 // Print specific data into output buffer.
159 //
160 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
161 Marker = (VA_LIST) (DebugInfo + 1);
162 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
163
164 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
165 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
166 //
167 // Print ERROR information into output buffer.
168 //
169 CharCount = AsciiSPrint (
170 Buffer,
171 EFI_STATUS_CODE_DATA_MAX_SIZE,
172 "ERROR: C%x:V%x I%x",
173 CodeType,
174 Value,
175 Instance
176 );
177
178 //
179 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
180 //
181
182 if (CallerId != NULL) {
183 CharCount += AsciiSPrint (
184 &Buffer[CharCount - 1],
185 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
186 " %g",
187 CallerId
188 );
189 }
190
191 if (Data != NULL) {
192 CharCount += AsciiSPrint (
193 &Buffer[CharCount - 1],
194 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
195 " %x",
196 Data
197 );
198 }
199
200 CharCount += AsciiSPrint (
201 &Buffer[CharCount - 1],
202 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
203 "\n\r"
204 );
205 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
206 CharCount = AsciiSPrint (
207 Buffer,
208 EFI_STATUS_CODE_DATA_MAX_SIZE,
209 "PROGRESS CODE: V%x I%x\n\r",
210 Value,
211 Instance
212 );
213 } else {
214 CharCount = AsciiSPrint (
215 Buffer,
216 EFI_STATUS_CODE_DATA_MAX_SIZE,
217 "Undefined: C%x:V%x I%x\n\r",
218 CodeType,
219 Value,
220 Instance
221 );
222 }
223
224 //
225 // Callout to standard output.
226 //
227 mUnix->Write (
228 mStdOut,
229 Buffer,
230 CharCount
231 );
232
233 return EFI_SUCCESS;
234 }
235