]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Dxe/Ipf/DxeStatusCodeIpf.c
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / Ipf / DxeStatusCodeIpf.c
1 /** @file
2 * Status code driver for IPF architecture.
3
4 Copyright (c) 2006, 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: DxeStatusCodeIpf.c
14
15 **/
16
17 #include "DxeStatusCode.h"
18
19
20 /**
21 Report status code to all supported device.
22 Calls into the workers which dispatches the platform specific
23 listeners.
24
25 @param Type Indicates the type of status code being reported.
26 The type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
27 @param Value Describes the current status of a hardware or software entity.
28 This includes information about the class and subclass that is used to classify the entity
29 as well as an operation. For progress codes, the operation is the current activity.
30 For error codes, it is the exception. For debug codes, it is not defined at this time.
31 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
32 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
33 @param Instance The enumeration of a hardware or software entity within the system.
34 A system may contain multiple entities that match a class/subclass pairing.
35 The instance differentiates between them. An instance of 0 indicates that instance
36 information is unavailable, not meaningful, or not relevant. Valid instance numbers start with 1.
37 @param CallerId This optional parameter may be used to identify the caller.
38 This parameter allows the status code driver to apply different rules to different callers.
39 @param Data This optional parameter may be used to pass additional data.
40 Type EFI_STATUS_CODE_DATA is defined in "Related Definitions" below.
41 The contents of this data type may have additional GUID-specific data. The standard GUIDs and
42 their associated data structures are defined in the Intel? Platform Innovation Framework for EFI Status Codes Specification.
43
44 @return Always return EFI_SUCCESS.
45
46 **/
47 STATIC
48 EFI_STATUS
49 EFIAPI
50 ReportDispatcher (
51 IN EFI_STATUS_CODE_TYPE Type,
52 IN EFI_STATUS_CODE_VALUE Value,
53 IN UINT32 Instance,
54 IN EFI_GUID *CallerId OPTIONAL,
55 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
56 );
57
58 //
59 // Declaration of status code protocol.
60 //
61 STATIC
62 EFI_STATUS_CODE_PROTOCOL mEfiStatusCodeProtocol = {
63 ReportDispatcher
64 };
65
66 //
67 // Delaration of DXE status code controller
68 //
69 DXE_STATUS_CODE_CONTROLLER gDxeStatusCode = {
70 //
71 // Initialize nest status as non nested.
72 //
73 0,
74 {NULL, NULL}
75 };
76
77 /**
78 Report status code to all supported device.
79 Calls into the workers which dispatches the platform specific
80 listeners.
81
82 @param CodeType Indicates the type of status code being reported.
83 The type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
84 @param Value Describes the current status of a hardware or software entity.
85 This includes information about the class and subclass that is used to classify the entity
86 as well as an operation. For progress codes, the operation is the current activity.
87 For error codes, it is the exception. For debug codes, it is not defined at this time.
88 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
89 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
90 @param Instance The enumeration of a hardware or software entity within the system.
91 A system may contain multiple entities that match a class/subclass pairing.
92 The instance differentiates between them. An instance of 0 indicates that instance
93 information is unavailable, not meaningful, or not relevant. Valid instance numbers start with 1.
94 @param CallerId This optional parameter may be used to identify the caller.
95 This parameter allows the status code driver to apply different rules to different callers.
96 @param Data This optional parameter may be used to pass additional data.
97 Type EFI_STATUS_CODE_DATA is defined in "Related Definitions" below.
98 The contents of this data type may have additional GUID-specific data. The standard GUIDs and
99 their associated data structures are defined in the Intel? Platform Innovation Framework for EFI Status Codes Specification.
100
101 @return Always return EFI_SUCCESS.
102
103 **/
104 STATIC
105 EFI_STATUS
106 EFIAPI
107 ReportDispatcher (
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 //
116 // Use atom operation to avoid the reentant of report.
117 // If current status is not zero, then the function is reentrancy.
118 //
119 if (1 == InterlockedCompareExchange32 (&gDxeStatusCode.StatusCodeNestStatus, 0, 1)) {
120 return EFI_DEVICE_ERROR;
121 }
122
123 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial) || FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
124 SerialStatusCodeReportWorker (
125 CodeType,
126 Value,
127 Instance,
128 CallerId,
129 Data
130 );
131 }
132 if (FeaturePcdGet (PcdStatusCodeUseRuntimeMemory)) {
133 RtMemoryStatusCodeReportWorker (
134 gDxeStatusCode.RtMemoryStatusCodeTable[PHYSICAL_MODE],
135 CodeType,
136 Value,
137 Instance
138 );
139 }
140 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {
141 DataHubStatusCodeReportWorker (
142 CodeType,
143 Value,
144 Instance,
145 CallerId,
146 Data
147 );
148 }
149 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {
150 OemHookStatusCodeReport (
151 CodeType,
152 Value,
153 Instance,
154 CallerId,
155 Data
156 );
157 }
158
159 //
160 // Restore the nest status of report
161 //
162 InterlockedCompareExchange32 (&gDxeStatusCode.StatusCodeNestStatus, 1, 0);
163
164 return EFI_SUCCESS;
165 }
166
167
168 /**
169
170 Main entry for Extended SAL ReportStatusCode Services
171
172 @param FunctionId Function Id which needed to be called
173 @param Arg2 Efi status code type
174 @param Arg3 Efi status code value
175 @param Arg4 Instance number
176 @param Arg5 Caller Id
177 @param Arg6 Efi status code data
178 @param Arg7 Not used
179 @param Arg8 Not used
180 @param ExtendedSalProc Esal Proc pointer
181 @param VirtualMode If this function is called in virtual mode
182 @param Global This module's global variable pointer
183
184 @return Value returned in SAL_RETURN_REGS
185
186 --*/
187 STATIC
188 SAL_RETURN_REGS
189 EFIAPI
190 ReportEsalServiceEntry (
191 IN UINT64 FunctionId,
192 IN UINT64 Arg2,
193 IN UINT64 Arg3,
194 IN UINT64 Arg4,
195 IN UINT64 Arg5,
196 IN UINT64 Arg6,
197 IN UINT64 Arg7,
198 IN UINT64 Arg8,
199 IN SAL_EXTENDED_SAL_PROC ExtendedSalProc,
200 IN BOOLEAN VirtualMode,
201 IN VOID *Global
202 )
203 {
204 SAL_RETURN_REGS ReturnVal;
205 DXE_STATUS_CODE_CONTROLLER *DxeStatusCode;
206
207 switch (FunctionId) {
208
209 case ReportStatusCodeServiceFunctionId:
210
211 DxeStatusCode = (DXE_STATUS_CODE_CONTROLLER *) Global;
212
213 //
214 // Use atom operation to avoid the reentant of report.
215 // If current status is not zero, then the function is reentrancy.
216 //
217 if (1 == InterlockedCompareExchange32 (&DxeStatusCode->StatusCodeNestStatus, 0, 1)) {
218 ReturnVal.Status = EFI_DEVICE_ERROR;
219 return ReturnVal;
220 }
221
222 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial) || FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
223 SerialStatusCodeReportWorker (
224 (EFI_STATUS_CODE_TYPE) Arg2,
225 (EFI_STATUS_CODE_VALUE) Arg3,
226 (UINT32) Arg4,
227 (EFI_GUID *) Arg5,
228 (EFI_STATUS_CODE_DATA *) Arg6
229 );
230 }
231 if (FeaturePcdGet (PcdStatusCodeUseRuntimeMemory)) {
232 RtMemoryStatusCodeReportWorker (
233 DxeStatusCode->RtMemoryStatusCodeTable[VirtualMode],
234 (EFI_STATUS_CODE_TYPE) Arg2,
235 (EFI_STATUS_CODE_VALUE) Arg3,
236 (UINT32) Arg4
237 );
238 }
239 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {
240 DataHubStatusCodeReportWorker (
241 (EFI_STATUS_CODE_TYPE) Arg2,
242 (EFI_STATUS_CODE_VALUE) Arg3,
243 (UINT32) Arg4,
244 (EFI_GUID *) Arg5,
245 (EFI_STATUS_CODE_DATA *) Arg6
246 );
247 }
248 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {
249 OemHookStatusCodeReport (
250 (EFI_STATUS_CODE_TYPE) Arg2,
251 (EFI_STATUS_CODE_VALUE) Arg3,
252 (UINT32) Arg4,
253 (EFI_GUID *) Arg5,
254 (EFI_STATUS_CODE_DATA *) Arg6
255 );
256 }
257
258 //
259 // Restore the nest status of report
260 //
261 InterlockedCompareExchange32 (&DxeStatusCode->StatusCodeNestStatus, 1, 0);
262
263 ReturnVal.Status = EFI_SUCCESS;
264
265 break;
266
267 default:
268 ReturnVal.Status = EFI_SAL_INVALID_ARGUMENT;
269 break;
270 }
271
272 return ReturnVal;
273 }
274
275 /**
276
277 Install the ReportStatusCode runtime service.
278
279 @param ImageHandle Image handle of the loaded driver
280 @param SystemTable Pointer to the System Table
281
282 @return The function always returns success.
283
284 **/
285 EFI_STATUS
286 DxeStatusCodeDriverEntry (
287 IN EFI_HANDLE ImageHandle,
288 IN EFI_SYSTEM_TABLE *SystemTable
289 )
290 {
291 EFI_STATUS Status;
292 EFI_HANDLE Handle = NULL;
293
294 //
295 // Dispatch initialization request to supported devices
296 //
297 InitializationDispatcherWorker ();
298
299 //
300 // Install Status Code Architectural Protocol implementation as defined in Tiano
301 // Architecture Specification.
302 //
303 Status = gBS->InstallMultipleProtocolInterfaces (
304 &Handle,
305 &gEfiStatusCodeRuntimeProtocolGuid,
306 &mEfiStatusCodeProtocol,
307 NULL
308 );
309 ASSERT_EFI_ERROR (Status);
310
311 //
312 // Initialize ESAL capabilities.
313 //
314 Status = RegisterEsalClass (
315 &gEfiExtendedSalStatusCodeServicesProtocolGuid,
316 &gDxeStatusCode,
317 ReportEsalServiceEntry,
318 StatusCodeFunctionId,
319 NULL
320 );
321 ASSERT_EFI_ERROR (Status);
322
323 return EFI_SUCCESS;
324 }
325
326
327 /**
328 Virtual address change notification call back. It converts physical mode global pointer to
329 virtual mode.
330
331 @param Event Event whose notification function is being invoked.
332 @param Context Pointer to the notification function's context, which is
333 always zero in current implementation.
334
335 **/
336 VOID
337 EFIAPI
338 VirtualAddressChangeCallBack (
339 IN EFI_EVENT Event,
340 IN VOID *Context
341 )
342 {
343 gDxeStatusCode.RtMemoryStatusCodeTable[VIRTUAL_MODE] =
344 gDxeStatusCode.RtMemoryStatusCodeTable[PHYSICAL_MODE];
345
346 //
347 // Convert the physical mode pointer to virtual mode point.
348 //
349 EfiConvertPointer (
350 0,
351 (VOID **) &gDxeStatusCode.RtMemoryStatusCodeTable[VIRTUAL_MODE]
352 );
353 }
354