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