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