]> git.proxmox.com Git - mirror_edk2.git/blame - EdkUnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
Split UnixOemHookStatusCodeLib to PEI/DXE instances
[mirror_edk2.git] / EdkUnixPkg / Library / PeiUnixOemHookStatusCodeLib / UnixOemHookStatusCodeLib.c
CommitLineData
c9093a06 1/** @file\r
2 OEM hook status code library functions with no library constructor/destructor\r
3\r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 Module Name: UnixOemHookStatusCodeLib.c\r
14\r
15**/\r
16\r
17//\r
18// Cache of UnixThunk protocol \r
19//\r
20STATIC\r
21EFI_UNIX_THUNK_PROTOCOL *mUnix;\r
22\r
23//\r
24// Cache of standard output handle . \r
25//\r
26STATIC\r
27int mStdOut;\r
28\r
29/**\r
30\r
31 Initialize OEM status code device .\r
32\r
33 @return Always return EFI_SUCCESS.\r
34\r
35**/\r
36EFI_STATUS\r
37EFIAPI\r
38OemHookStatusCodeInitialize (\r
39 VOID\r
40 )\r
41{\r
42 PEI_UNIX_THUNK_PPI *UnixThunkPpi;\r
43 EFI_STATUS Status;\r
44\r
318275b2 45 \r
46 //\r
47 // Locate Unix ThunkPpi for retrieving standard output handle\r
48 //\r
49 Status = PeiServicesLocatePpi (\r
50 &gPeiUnixThunkPpiGuid,\r
51 0,\r
52 NULL,\r
53 (VOID **) &UnixThunkPpi\r
54 );\r
c9093a06 55\r
318275b2 56 ASSERT_EFI_ERROR (Status);\r
c9093a06 57\r
318275b2 58 mUnix = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();\r
59 \r
c9093a06 60 //\r
61 // Cache standard output handle.\r
62 //\r
63 mStdOut = 1;
64\r
65 return EFI_SUCCESS;\r
66}\r
67\r
68/**\r
69 Report status code to OEM device.\r
70 \r
71 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
72 \r
73 @param Value Describes the current status of a hardware or software entity. \r
74 This included information about the class and subclass that is used to classify the entity \r
75 as well as an operation. For progress codes, the operation is the current activity. \r
76 For error codes, it is the exception. For debug codes, it is not defined at this time. \r
77 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. \r
78 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
79 \r
80 @param Instance The enumeration of a hardware or software entity within the system. \r
81 A system may contain multiple entities that match a class/subclass pairing. \r
82 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, \r
83 not meaningful, or not relevant. Valid instance numbers start with 1.\r
84\r
85\r
86 @param CallerId This optional parameter may be used to identify the caller. \r
87 This parameter allows the status code driver to apply different rules to different callers. \r
88 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
89\r
90\r
91 @param Data This optional parameter may be used to pass additional data\r
92 \r
93 @return The function always return EFI_SUCCESS.\r
94\r
95**/\r
96EFI_STATUS\r
97EFIAPI\r
98OemHookStatusCodeReport (\r
99 IN EFI_STATUS_CODE_TYPE CodeType,\r
100 IN EFI_STATUS_CODE_VALUE Value,\r
101 IN UINT32 Instance,\r
102 IN EFI_GUID *CallerId, OPTIONAL\r
103 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
104 )\r
105{\r
106 CHAR8 *Filename;\r
107 CHAR8 *Description;\r
108 CHAR8 *Format;\r
109 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
110 UINT32 ErrorLevel;\r
111 UINT32 LineNumber;\r
112 UINTN CharCount;\r
113 VA_LIST Marker;\r
114 EFI_DEBUG_INFO *DebugInfo;\r
115\r
116 Buffer[0] = '\0';\r
117\r
118 if (Data != NULL &&\r
119 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
120 //\r
121 // Print ASSERT() information into output buffer.\r
122 //\r
123 CharCount = AsciiSPrint (\r
124 Buffer,\r
125 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
126 "\n\rASSERT!: %a (%d): %a\n\r",\r
127 Filename,\r
128 LineNumber,\r
129 Description\r
130 );\r
131\r
132 //\r
133 // Callout to standard output.\r
134 //\r
135 mUnix->Write (\r
136 mStdOut,\r
137 Buffer,\r
138 CharCount\r
139 );
140\r
141 return EFI_SUCCESS;\r
142\r
143 } else if (Data != NULL &&\r
144 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
145 //\r
146 // Print DEBUG() information into output buffer.\r
147 //\r
148 CharCount = AsciiVSPrint (\r
149 Buffer, \r
150 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
151 Format, \r
152 Marker\r
153 );\r
154 } else if (Data != NULL && \r
155 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
156 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
157 //\r
158 // Print specific data into output buffer.\r
159 //\r
160 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
161 Marker = (VA_LIST) (DebugInfo + 1);\r
162 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
163\r
164 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
165 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
166 //\r
167 // Print ERROR information into output buffer.\r
168 //\r
169 CharCount = AsciiSPrint (\r
170 Buffer, \r
171 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
172 "ERROR: C%x:V%x I%x", \r
173 CodeType, \r
174 Value, \r
175 Instance\r
176 );\r
177\r
178 //\r
179 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
180 //\r
181 \r
182 if (CallerId != NULL) {\r
183 CharCount += AsciiSPrint (\r
184 &Buffer[CharCount - 1],\r
185 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
186 " %g",\r
187 CallerId\r
188 );\r
189 }\r
190\r
191 if (Data != NULL) {\r
192 CharCount += AsciiSPrint (\r
193 &Buffer[CharCount - 1],\r
194 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
195 " %x",\r
196 Data\r
197 );\r
198 }\r
199\r
200 CharCount += AsciiSPrint (\r
201 &Buffer[CharCount - 1],\r
202 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
203 "\n\r"\r
204 );\r
205 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
206 CharCount = AsciiSPrint (\r
207 Buffer, \r
208 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
209 "PROGRESS CODE: V%x I%x\n\r", \r
210 Value, \r
211 Instance\r
212 );\r
213 } else {\r
214 CharCount = AsciiSPrint (\r
215 Buffer, \r
216 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
217 "Undefined: C%x:V%x I%x\n\r", \r
218 CodeType, \r
219 Value, \r
220 Instance\r
221 );\r
222 }\r
223\r
224 //\r
225 // Callout to standard output.\r
226 //\r
227 mUnix->Write (\r
228 mStdOut,\r
229 Buffer,\r
230 CharCount\r
231 );\r
232\r
233 return EFI_SUCCESS;\r
234}\r
235\r