]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCodeCommon.c
Some minor refinements for function header.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Dxe / DxeStatusCodeCommon.c
1 /** @file
2 Status code driver for IA32/X64/EBC 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 **/
14
15 #include "DxeStatusCode.h"
16
17 EFI_EVENT mVirtualAddressChangeEvent = NULL;
18 EFI_HANDLE mHandle = NULL;
19
20 //
21 // Declaration of status code protocol.
22 //
23 EFI_STATUS_CODE_PROTOCOL mEfiStatusCodeProtocol = {
24 ReportDispatcher
25 };
26
27 //
28 // Report operation nest status.
29 // If it is set, then the report operation has nested.
30 //
31 UINT32 mStatusCodeNestStatus = 0;
32
33 /**
34 Entry point of DXE Status Code Driver.
35
36 This function is the entry point of this DXE Status Code Driver.
37 It installs Status Code Runtime Protocol, and registers event for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
38
39 @param ImageHandle The firmware allocated handle for the EFI image.
40 @param SystemTable A pointer to the EFI System Table.
41
42 @retval EFI_SUCCESS The entry point is executed successfully.
43
44 **/
45 EFI_STATUS
46 EFIAPI
47 DxeStatusCodeDriverEntry (
48 IN EFI_HANDLE ImageHandle,
49 IN EFI_SYSTEM_TABLE *SystemTable
50 )
51 {
52 EFI_STATUS Status;
53
54 //
55 // Dispatch initialization request to supported devices
56 //
57 InitializationDispatcherWorker ();
58
59 //
60 // Install Status Code Runtime Protocol implementation as defined in PI Specification.
61 //
62 Status = gBS->InstallMultipleProtocolInterfaces (
63 &mHandle,
64 &gEfiStatusCodeRuntimeProtocolGuid,
65 &mEfiStatusCodeProtocol,
66 NULL
67 );
68 ASSERT_EFI_ERROR (Status);
69
70 Status = gBS->CreateEventEx (
71 EVT_NOTIFY_SIGNAL,
72 TPL_NOTIFY,
73 VirtualAddressChangeCallBack,
74 NULL,
75 &gEfiEventVirtualAddressChangeGuid,
76 &mVirtualAddressChangeEvent
77 );
78 ASSERT_EFI_ERROR (Status);
79
80 return EFI_SUCCESS;
81 }
82
83 /**
84 Report status code to all supported device.
85
86 This function implements EFI_STATUS_CODE_PROTOCOL.ReportStatusCode().
87 It calls into the workers which dispatches the platform specific listeners.
88
89 @param CodeType Indicates the type of status code being reported.
90 @param Value Describes the current status of a hardware or software entity.
91 This included information about the class and subclass that is used to
92 classify the entity as well as an operation.
93 @param Instance The enumeration of a hardware or software entity within
94 the system. Valid instance numbers start with 1.
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
97 different callers.
98 @param Data This optional parameter may be used to pass additional data.
99
100 @retval EFI_SUCCESS The function completed successfully
101 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
102
103 **/
104 EFI_STATUS
105 EFIAPI
106 ReportDispatcher (
107 IN EFI_STATUS_CODE_TYPE CodeType,
108 IN EFI_STATUS_CODE_VALUE Value,
109 IN UINT32 Instance,
110 IN EFI_GUID *CallerId OPTIONAL,
111 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
112 )
113 {
114 //
115 // Use atom operation to avoid the reentant of report.
116 // If current status is not zero, then the function is reentrancy.
117 //
118 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus, 0, 1) == 1) {
119 return EFI_DEVICE_ERROR;
120 }
121
122 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial) || FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
123 SerialStatusCodeReportWorker (
124 CodeType,
125 Value,
126 Instance,
127 CallerId,
128 Data
129 );
130 }
131 if (FeaturePcdGet (PcdStatusCodeUseRuntimeMemory)) {
132 RtMemoryStatusCodeReportWorker (
133 CodeType,
134 Value,
135 Instance
136 );
137 }
138 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {
139 DataHubStatusCodeReportWorker (
140 CodeType,
141 Value,
142 Instance,
143 CallerId,
144 Data
145 );
146 }
147 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {
148 //
149 // Call OEM hook status code library API to report status code to OEM device
150 //
151 OemHookStatusCodeReport (
152 CodeType,
153 Value,
154 Instance,
155 CallerId,
156 Data
157 );
158 }
159
160 //
161 // Restore the nest status of report
162 //
163 InterlockedCompareExchange32 (&mStatusCodeNestStatus, 1, 0);
164
165 return EFI_SUCCESS;
166 }
167
168
169 /**
170 Virtual address change notification call back. It converts global pointer
171 to virtual address.
172
173 @param Event Event whose notification function is being invoked.
174 @param Context Pointer to the notification function's context, which is
175 always zero in current implementation.
176
177 **/
178 VOID
179 EFIAPI
180 VirtualAddressChangeCallBack (
181 IN EFI_EVENT Event,
182 IN VOID *Context
183 )
184 {
185 //
186 // Convert memory status code table to virtual address;
187 //
188 EfiConvertPointer (
189 0,
190 (VOID **) &mRtMemoryStatusCodeTable
191 );
192 }
193