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