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