1) Fix bug in EdkUefiRuntimeLib.msa(EDKT155).
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / Common / 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 Module Name: DxeStatusCodeCommon.c
14
15 **/
16 #include "DxeStatusCode.h"
17
18
19 /**
20 Report status code to all supported device.
21 Calls into the workers which dispatches the platform specific
22 listeners.
23
24 @param Type Indicates the type of status code being reported.
25 The type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
26 @param Value Describes the current status of a hardware or software entity.
27 This includes information about the class and subclass that is used to classify the entity
28 as well as an operation. For progress codes, the operation is the current activity.
29 For error codes, it is the exception. For debug codes, it is not defined at this time.
30 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
31 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
32 @param Instance The enumeration of a hardware or software entity within the system.
33 A system may contain multiple entities that match a class/subclass pairing.
34 The instance differentiates between them. An instance of 0 indicates that instance
35 information is unavailable, not meaningful, or not relevant. Valid instance numbers start with 1.
36 @param CallerId This optional parameter may be used to identify the caller.
37 This parameter allows the status code driver to apply different rules to different callers.
38 @param Data This optional parameter may be used to pass additional data.
39 Type EFI_STATUS_CODE_DATA is defined in "Related Definitions" below.
40 The contents of this data type may have additional GUID-specific data. The standard GUIDs and
41 their associated data structures are defined in the Intel? Platform Innovation Framework for EFI Status Codes Specification.
42 **/
43 EFI_STATUS
44 EFIAPI
45 ReportDispatcher (
46 IN EFI_STATUS_CODE_TYPE Type,
47 IN EFI_STATUS_CODE_VALUE Value,
48 IN UINT32 Instance,
49 IN EFI_GUID *CallerId OPTIONAL,
50 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
51 );
52
53 //
54 // Declaration of status code protocol.
55 //
56 EFI_STATUS_CODE_PROTOCOL mEfiStatusCodeProtocol = {
57 ReportDispatcher
58 };
59
60 //
61 // Delaration of DXE status code controller
62 //
63 DXE_STATUS_CODE_CONTROLLER gDxeStatusCode = {
64 //
65 // Initialize nest status as non nested.
66 //
67 0,
68 {NULL, NULL}
69 };
70
71 /**
72
73 Install the ReportStatusCode runtime service.
74
75 @param ImageHandle Image handle of the loaded driver
76 @param SystemTable Pointer to the System Table
77
78 @return The function always returns success.
79
80 **/
81 EFI_STATUS
82 DxeStatusCodeDriverEntry (
83 IN EFI_HANDLE ImageHandle,
84 IN EFI_SYSTEM_TABLE *SystemTable
85 )
86 {
87 EFI_HANDLE Handle = NULL;
88 EFI_STATUS Status;
89
90 //
91 // Dispatch initialization request to supported devices
92 //
93 InitializationDispatcherWorker ();
94
95 //
96 // Install Status Code Architectural Protocol implementation as defined in Tiano
97 // Architecture Specification.
98 //
99 Status = gBS->InstallMultipleProtocolInterfaces (
100 &Handle,
101 &gEfiStatusCodeRuntimeProtocolGuid,
102 &mEfiStatusCodeProtocol,
103 NULL
104 );
105 ASSERT_EFI_ERROR (Status);
106
107 return Status;
108 }
109
110 /**
111 Report status code to all supported device.
112 Calls into the workers which dispatches the platform specific
113 listeners.
114
115 @param CodeType Indicates the type of status code being reported.
116 The type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
117 @param Value Describes the current status of a hardware or software entity.
118 This includes information about the class and subclass that is used to classify the entity
119 as well as an operation. For progress codes, the operation is the current activity.
120 For error codes, it is the exception. For debug codes, it is not defined at this time.
121 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
122 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
123 @param Instance The enumeration of a hardware or software entity within the system.
124 A system may contain multiple entities that match a class/subclass pairing.
125 The instance differentiates between them. An instance of 0 indicates that instance
126 information is unavailable, not meaningful, or not relevant. Valid instance numbers start with 1.
127 @param CallerId This optional parameter may be used to identify the caller.
128 This parameter allows the status code driver to apply different rules to different callers.
129 @param Data This optional parameter may be used to pass additional data.
130 Type EFI_STATUS_CODE_DATA is defined in "Related Definitions" below.
131 The contents of this data type may have additional GUID-specific data. The standard GUIDs and
132 their associated data structures are defined in the Intel? Platform Innovation Framework for EFI Status Codes Specification.
133 **/
134 EFI_STATUS
135 EFIAPI
136 ReportDispatcher (
137 IN EFI_STATUS_CODE_TYPE CodeType,
138 IN EFI_STATUS_CODE_VALUE Value,
139 IN UINT32 Instance,
140 IN EFI_GUID *CallerId OPTIONAL,
141 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
142 )
143 {
144 //
145 // Use atom operation to avoid the reentant of report.
146 // If current status is not zero, then the function is reentrancy.
147 //
148 if (InterlockedCompareExchange32 (&gDxeStatusCode.StatusCodeNestStatus, 0, 1)) {
149 return EFI_DEVICE_ERROR;
150 }
151
152 if (FeaturePcdGet (PcdStatusCodeUseEfiSerial) || FeaturePcdGet (PcdStatusCodeUseHardSerial)) {
153 SerialStatusCodeReportWorker (
154 CodeType,
155 Value,
156 Instance,
157 CallerId,
158 Data
159 );
160 }
161 if (FeaturePcdGet (PcdStatusCodeUseRuntimeMemory)) {
162 RtMemoryStatusCodeReportWorker (
163 gDxeStatusCode.RtMemoryStatusCodeTable[PHYSICAL_MODE],
164 CodeType,
165 Value,
166 Instance
167 );
168 }
169 if (FeaturePcdGet (PcdStatusCodeUseDataHub)) {
170 DataHubStatusCodeReportWorker (
171 CodeType,
172 Value,
173 Instance,
174 CallerId,
175 Data
176 );
177 }
178 if (FeaturePcdGet (PcdStatusCodeUseOEM)) {
179 OemHookStatusCodeReport (
180 CodeType,
181 Value,
182 Instance,
183 CallerId,
184 Data
185 );
186 }
187
188 //
189 // Restore the nest status of report
190 //
191 InterlockedCompareExchange32 (&gDxeStatusCode.StatusCodeNestStatus, 1, 0);
192
193 return EFI_SUCCESS;
194 }
195
196
197 /**
198 Virtual address change notification call back. It converts global pointer
199 to virtual address.
200
201 @param Event Event whose notification function is being invoked.
202 @param Context Pointer to the notification function¡¯s context, which is
203 always zero in current implementation.
204
205 **/
206 VOID
207 EFIAPI
208 VirtualAddressChangeCallBack (
209 IN EFI_EVENT Event,
210 IN VOID *Context
211 )
212 {
213 //
214 // Convert memory status code table to virtual address;
215 //
216 EfiConvertPointer (
217 0,
218 (VOID **) &gDxeStatusCode.RtMemoryStatusCodeTable[PHYSICAL_MODE]
219 );
220 }
221