]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/Dxe/DataHubStatusCodeWorker.c
Update Coding style of status code.
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / Dxe / DataHubStatusCodeWorker.c
1 /** @file
2 Data Hub status code worker in DXE.
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: DataHubStatusCodeWorker.c
14
15 **/
16 #include "DxeStatusCode.h"
17
18 //
19 // Initialize FIFO to cache records.
20 //
21 STATIC
22 EFI_LOCK mFifoLock = EFI_INITIALIZE_LOCK_VARIABLE (EFI_TPL_HIGH_LEVEL);
23 STATIC
24 LIST_ENTRY mRecordsFifo = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsFifo);
25 STATIC
26 UINTN mNumberOfRecords = 0;
27 STATIC
28 EFI_EVENT mLogDataHubEvent;
29 //
30 // Cache data hub protocol.
31 //
32 STATIC
33 EFI_DATA_HUB_PROTOCOL *mDataHubProtocol;
34
35
36 /**
37 Return buffer of length DATAHUB_STATUSCODE_RECORD
38
39 @retval NULL Can not allocate free memeory for record.
40 @retval !NULL Point to buffer of record.
41
42 **/
43 DATAHUB_STATUSCODE_RECORD *
44 AcquireRecordBuffer (
45 VOID
46 )
47 {
48 DATAHUB_STATUSCODE_RECORD *Record;
49
50 Record = (DATAHUB_STATUSCODE_RECORD *) AllocateZeroPool (sizeof (DATAHUB_STATUSCODE_RECORD));
51 if (NULL == Record) {
52 return NULL;
53 }
54 Record->Signature = DATAHUB_STATUS_CODE_SIGNATURE;
55
56 EfiAcquireLock (&mFifoLock);
57 InsertTailList (&mRecordsFifo, &Record->Node);
58 mNumberOfRecords++;
59 EfiReleaseLock (&mFifoLock);
60
61 return Record;
62 }
63
64
65 /**
66 Release a mRecordBuffer entry allocated by AcquirRecordBuffer ().
67
68 @param Record Point to record buffer which is acquired by AcquirRecordBuffer()
69
70 **/
71 VOID
72 FreeRecordBuffer (
73 IN DATAHUB_STATUSCODE_RECORD *Record
74 )
75 {
76 ASSERT (Record != NULL);
77 ASSERT (mNumberOfRecords != 0);
78
79 EfiAcquireLock (&mFifoLock);
80 RemoveEntryList (&Record->Node);
81 mNumberOfRecords--;
82 EfiReleaseLock (&mFifoLock);
83
84 FreePool (Record);
85 }
86
87
88 /**
89 Report status code into DataHub.
90
91 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
92
93 @param Value Describes the current status of a hardware or software entity.
94 This included information about the class and subclass that is used to classify the entity
95 as well as an operation. For progress codes, the operation is the current activity.
96 For error codes, it is the exception. For debug codes, it is not defined at this time.
97 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
98 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
99
100 @param Instance The enumeration of a hardware or software entity within the system.
101 A system may contain multiple entities that match a class/subclass pairing.
102 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
103 not meaningful, or not relevant. Valid instance numbers start with 1.
104
105
106 @param CallerId This optional parameter may be used to identify the caller.
107 This parameter allows the status code driver to apply different rules to different callers.
108 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
109
110
111 @param Data This optional parameter may be used to pass additional data
112
113 @retval EFI_OUT_OF_RESOURCES Can not acquire record buffer.
114 @retval EFI_DEVICE_ERROR EFI serial device can not work after ExitBootService() is called .
115 @retval EFI_SUCCESS Success to cache status code and signal log data event.
116
117 **/
118 EFI_STATUS
119 DataHubStatusCodeReportWorker (
120 IN EFI_STATUS_CODE_TYPE CodeType,
121 IN EFI_STATUS_CODE_VALUE Value,
122 IN UINT32 Instance,
123 IN EFI_GUID *CallerId,
124 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
125 )
126 {
127 DATAHUB_STATUSCODE_RECORD *Record;
128 UINT32 ErrorLevel;
129 VA_LIST Marker;
130 CHAR8 *Format;
131 UINTN CharCount;
132
133 //
134 // See whether in runtime phase or not.
135 //
136 if (EfiAtRuntime ()) {
137 return EFI_DEVICE_ERROR;
138 }
139
140 Record = AcquireRecordBuffer ();
141 if (Record == NULL) {
142 //
143 // There are no empty record buffer in private buffers
144 //
145 return EFI_OUT_OF_RESOURCES;
146 }
147 //
148 // Construct Data Hub Extended Data
149 //
150 Record->CodeType = CodeType;
151 Record->Value = Value;
152 Record->Instance = Instance;
153
154 if (CallerId != NULL) {
155 CopyMem (&Record->CallerId, CallerId, sizeof (EFI_GUID));
156 }
157
158 if (Data != NULL) {
159 if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
160 CharCount = UnicodeVSPrintAsciiFormat (
161 (CHAR16 *) Record->ExtendData,
162 EFI_STATUS_CODE_DATA_MAX_SIZE,
163 Format,
164 Marker
165 );
166 //
167 // Change record data type from DebugType to String Type.
168 //
169 CopyGuid (&Record->Data.Type, &gEfiStatusCodeDataTypeStringGuid);
170 Record->Data.HeaderSize = Data->HeaderSize;
171 Record->Data.Size = (UINT16) ((CharCount + 1) * sizeof (CHAR16));
172 } else {
173 //
174 // Copy status code data header
175 //
176 CopyMem (&Record->Data, Data, sizeof (EFI_STATUS_CODE_DATA));
177
178 if (Data->Size > EFI_STATUS_CODE_DATA_MAX_SIZE) {
179 Record->Data.Size = EFI_STATUS_CODE_DATA_MAX_SIZE;
180 }
181 CopyMem (Record->ExtendData, Data + 1, Record->Data.Size);
182 }
183 }
184
185 gBS->SignalEvent (mLogDataHubEvent);
186
187 return EFI_SUCCESS;
188 }
189
190
191 /**
192 The Event handler which will be notified to log data in Data Hub.
193
194 @param Event Instance of the EFI_EVENT to signal whenever data is
195 available to be logged in the system.
196 @param Context Context of the event.
197
198 **/
199 VOID
200 EFIAPI
201 LogDataHubEventCallBack (
202 IN EFI_EVENT Event,
203 IN VOID *Context
204 )
205 {
206 DATAHUB_STATUSCODE_RECORD *Record;
207 UINT32 Size;
208 UINT64 DataRecordClass;
209 LIST_ENTRY *Node;
210
211 //
212 // Log DataRecord in Data Hub.
213 // Journal records fifo to find all record entry.
214 //
215 //
216 for (Node = mRecordsFifo.ForwardLink; Node != &mRecordsFifo;) {
217 Record = CR (Node, DATAHUB_STATUSCODE_RECORD, Node, DATAHUB_STATUS_CODE_SIGNATURE);
218 Node = Node->ForwardLink;
219
220 //
221 // Add in the size of the header we added.
222 //
223 Size = sizeof (DATAHUB_STATUSCODE_RECORD) + (UINT32) Record->Data.Size;
224
225 if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
226 DataRecordClass = EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
227 } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
228 DataRecordClass = EFI_DATA_RECORD_CLASS_ERROR;
229 } else if ((Record->CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
230 DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG;
231 } else {
232 //
233 // Should never get here.
234 //
235 DataRecordClass = EFI_DATA_RECORD_CLASS_DEBUG |
236 EFI_DATA_RECORD_CLASS_ERROR |
237 EFI_DATA_RECORD_CLASS_DATA |
238 EFI_DATA_RECORD_CLASS_PROGRESS_CODE;
239 }
240
241 //
242 // Log DataRecord in Data Hub
243 //
244
245 mDataHubProtocol->LogData (
246 mDataHubProtocol,
247 &gEfiStatusCodeGuid,
248 &gEfiStatusCodeRuntimeProtocolGuid,
249 DataRecordClass,
250 Record,
251 Size
252 );
253
254 FreeRecordBuffer (Record);
255 }
256 }
257
258
259 /**
260 Initialize data hubstatus code.
261 Create a data hub listener.
262
263 @return The function always return EFI_SUCCESS
264
265 **/
266 EFI_STATUS
267 DataHubStatusCodeInitializeWorker (
268 VOID
269 )
270 {
271 EFI_STATUS Status;
272
273 Status = gBS->LocateProtocol (
274 &gEfiDataHubProtocolGuid,
275 NULL,
276 (VOID **) &mDataHubProtocol
277 );
278 ASSERT_EFI_ERROR (Status);
279
280 //
281 // Create a Notify Event to log data in Data Hub
282 //
283 Status = gBS->CreateEvent (
284 EFI_EVENT_NOTIFY_SIGNAL,
285 EFI_TPL_CALLBACK,
286 LogDataHubEventCallBack,
287 NULL,
288 &mLogDataHubEvent
289 );
290
291 ASSERT_EFI_ERROR (Status);
292
293 return EFI_SUCCESS;
294 }
295
296