]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
Remove BaseMemoryTest PPI and related producers and consumers.
[mirror_edk2.git] / UnixPkg / Library / PeiUnixOemHookStatusCodeLib / UnixOemHookStatusCodeLib.c
CommitLineData
804405e7 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//
804405e7 31EFI_UNIX_THUNK_PROTOCOL *mUnix;
32
33//
34// Cache of standard output handle .
35//
804405e7 36int mStdOut;
37
38/**
39
40 Initialize OEM status code device .
41
42 @return Always return EFI_SUCCESS.
43
44**/
45EFI_STATUS
46EFIAPI
47OemHookStatusCodeInitialize (
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**/
105EFI_STATUS
106EFIAPI
107OemHookStatusCodeReport (
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 VA_LIST Marker;
123 EFI_DEBUG_INFO *DebugInfo;
124
125 Buffer[0] = '\0';
126
127 if (Data != NULL &&
128 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
129 //
130 // Print ASSERT() information into output buffer.
131 //
132 CharCount = AsciiSPrint (
133 Buffer,
134 EFI_STATUS_CODE_DATA_MAX_SIZE,
135 "\n\rASSERT!: %a (%d): %a\n\r",
136 Filename,
137 LineNumber,
138 Description
139 );
140
141 //
142 // Callout to standard output.
143 //
144 mUnix->Write (
145 mStdOut,
146 Buffer,
147 CharCount
148 );
149
150 return EFI_SUCCESS;
151
152 } else if (Data != NULL &&
153 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
154 //
155 // Print DEBUG() information into output buffer.
156 //
157 CharCount = AsciiVSPrint (
158 Buffer,
159 EFI_STATUS_CODE_DATA_MAX_SIZE,
160 Format,
161 Marker
162 );
163 } else if (Data != NULL &&
164 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
165 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
166 //
167 // Print specific data into output buffer.
168 //
169 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
170 Marker = (VA_LIST) (DebugInfo + 1);
171 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
172
173 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
174 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
175 //
176 // Print ERROR information into output buffer.
177 //
178 CharCount = AsciiSPrint (
179 Buffer,
180 EFI_STATUS_CODE_DATA_MAX_SIZE,
181 "ERROR: C%x:V%x I%x",
182 CodeType,
183 Value,
184 Instance
185 );
186
187 //
188 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
189 //
190
191 if (CallerId != NULL) {
192 CharCount += AsciiSPrint (
193 &Buffer[CharCount - 1],
194 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
195 " %g",
196 CallerId
197 );
198 }
199
200 if (Data != NULL) {
201 CharCount += AsciiSPrint (
202 &Buffer[CharCount - 1],
203 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
204 " %x",
205 Data
206 );
207 }
208
209 CharCount += AsciiSPrint (
210 &Buffer[CharCount - 1],
211 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
212 "\n\r"
213 );
214 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
215 CharCount = AsciiSPrint (
216 Buffer,
217 EFI_STATUS_CODE_DATA_MAX_SIZE,
218 "PROGRESS CODE: V%x I%x\n\r",
219 Value,
220 Instance
221 );
222 } else {
223 CharCount = AsciiSPrint (
224 Buffer,
225 EFI_STATUS_CODE_DATA_MAX_SIZE,
226 "Undefined: C%x:V%x I%x\n\r",
227 CodeType,
228 Value,
229 Instance
230 );
231 }
232
233 //
234 // Callout to standard output.
235 //
236 mUnix->Write (
237 mStdOut,
238 Buffer,
239 CharCount
240 );
241
242 return EFI_SUCCESS;
243}
244