]>
Commit | Line | Data |
---|---|---|
2ab23929 | 1 | /** @file\r |
83f6d1a0 | 2 | This code produces the Data Hub protocol. It preloads the data hub\r |
3 | with status information copied in from PEI HOBs.\r | |
4 | \r | |
2ab23929 | 5 | Copyright (c) 2006 - 2009, Intel Corporation \r |
3db51098 | 6 | All rights reserved. This program and the accompanying materials \r |
7 | are licensed and made available under the terms and conditions of the BSD License \r | |
8 | which accompanies this distribution. The full text of the license may be found at \r | |
9 | http://opensource.org/licenses/bsd-license.php \r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
13 | \r | |
14 | **/\r | |
83f6d1a0 | 15 | \r |
16 | #include "DataHub.h"\r | |
17 | \r | |
18 | CONST EFI_GUID gZeroGuid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };\r | |
19 | \r | |
9f6531d1 | 20 | //\r |
9f6531d1 | 21 | // Since this driver will only ever produce one instance of the Logging Hub\r |
22 | // protocol you are not required to dynamically allocate the PrivateData.\r | |
23 | //\r | |
24 | DATA_HUB_INSTANCE mPrivateData;\r | |
25 | \r | |
83f6d1a0 | 26 | //\r |
27 | // Worker functions private to this file\r | |
28 | //\r | |
83f6d1a0 | 29 | DATA_HUB_FILTER_DRIVER *\r |
30 | FindFilterDriverByEvent (\r | |
31 | IN LIST_ENTRY *Head,\r | |
32 | IN EFI_EVENT Event\r | |
33 | );\r | |
34 | \r | |
83f6d1a0 | 35 | EFI_DATA_RECORD_HEADER *\r |
36 | GetNextDataRecord (\r | |
37 | IN LIST_ENTRY *Head,\r | |
38 | IN UINT64 ClassFilter,\r | |
39 | IN OUT UINT64 *PtrCurrentMTC\r | |
40 | );\r | |
41 | \r | |
a73d0c74 | 42 | /**\r |
a73d0c74 | 43 | Log data record into the data logging hub\r |
44 | \r | |
2ab23929 | 45 | @param This Protocol instance structure\r |
46 | @param DataRecordGuid GUID that defines record contents\r | |
47 | @param ProducerName GUID that defines the name of the producer of the data\r | |
48 | @param DataRecordClass Class that defines generic record type\r | |
49 | @param RawData Data Log record as defined by DataRecordGuid\r | |
50 | @param RawDataSize Size of Data Log data in bytes\r | |
a73d0c74 | 51 | \r |
2ab23929 | 52 | @retval EFI_SUCCESS If data was logged\r |
53 | @retval EFI_OUT_OF_RESOURCES If data was not logged due to lack of system \r | |
54 | resources.\r | |
a73d0c74 | 55 | **/\r |
83f6d1a0 | 56 | EFI_STATUS\r |
57 | EFIAPI\r | |
58 | DataHubLogData (\r | |
59 | IN EFI_DATA_HUB_PROTOCOL *This,\r | |
60 | IN EFI_GUID *DataRecordGuid,\r | |
61 | IN EFI_GUID *ProducerName,\r | |
62 | IN UINT64 DataRecordClass,\r | |
63 | IN VOID *RawData,\r | |
64 | IN UINT32 RawDataSize\r | |
65 | )\r | |
83f6d1a0 | 66 | {\r |
67 | EFI_STATUS Status;\r | |
68 | DATA_HUB_INSTANCE *Private;\r | |
69 | EFI_DATA_ENTRY *LogEntry;\r | |
70 | UINT32 TotalSize;\r | |
71 | UINT32 RecordSize;\r | |
72 | EFI_DATA_RECORD_HEADER *Record;\r | |
73 | VOID *Raw;\r | |
74 | DATA_HUB_FILTER_DRIVER *FilterEntry;\r | |
75 | LIST_ENTRY *Link;\r | |
76 | LIST_ENTRY *Head;\r | |
77 | \r | |
78 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
79 | \r | |
80 | //\r | |
81 | // Combine the storage for the internal structs and a copy of the log record.\r | |
82 | // Record follows PrivateLogEntry. The consumer will be returned a pointer\r | |
83 | // to Record so we don't what it to be the thing that was allocated from\r | |
84 | // pool, so the consumer can't free an data record by mistake.\r | |
85 | //\r | |
86 | RecordSize = sizeof (EFI_DATA_RECORD_HEADER) + RawDataSize;\r | |
87 | TotalSize = sizeof (EFI_DATA_ENTRY) + RecordSize;\r | |
88 | \r | |
89 | //\r | |
90 | // The Logging action is the critical section, so it is locked.\r | |
91 | // The MTC asignment & update, time, and logging must be an\r | |
92 | // atomic operation, so use the lock.\r | |
93 | //\r | |
94 | Status = EfiAcquireLockOrFail (&Private->DataLock);\r | |
95 | if (EFI_ERROR (Status)) {\r | |
96 | //\r | |
97 | // Reentrancy detected so exit!\r | |
98 | //\r | |
99 | return Status;\r | |
100 | }\r | |
101 | \r | |
102 | LogEntry = AllocatePool (TotalSize);\r | |
103 | \r | |
104 | if (LogEntry == NULL) {\r | |
105 | EfiReleaseLock (&Private->DataLock);\r | |
106 | return EFI_OUT_OF_RESOURCES;\r | |
107 | }\r | |
108 | \r | |
109 | ZeroMem (LogEntry, TotalSize);\r | |
110 | \r | |
111 | Record = (EFI_DATA_RECORD_HEADER *) (LogEntry + 1);\r | |
112 | Raw = (VOID *) (Record + 1);\r | |
113 | \r | |
114 | //\r | |
115 | // Build Standard Log Header\r | |
116 | //\r | |
117 | Record->Version = EFI_DATA_RECORD_HEADER_VERSION;\r | |
118 | Record->HeaderSize = sizeof (EFI_DATA_RECORD_HEADER);\r | |
119 | Record->RecordSize = RecordSize;\r | |
120 | CopyMem (&Record->DataRecordGuid, DataRecordGuid, sizeof (EFI_GUID));\r | |
121 | CopyMem (&Record->ProducerName, ProducerName, sizeof (EFI_GUID));\r | |
122 | Record->DataRecordClass = DataRecordClass;\r | |
123 | \r | |
41e4912f | 124 | //\r |
125 | // Ensure LogMonotonicCount is not zero\r | |
126 | //\r | |
127 | Record->LogMonotonicCount = ++Private->GlobalMonotonicCount;\r | |
83f6d1a0 | 128 | \r |
129 | gRT->GetTime (&Record->LogTime, NULL);\r | |
130 | \r | |
131 | //\r | |
132 | // Insert log into the internal linked list.\r | |
133 | //\r | |
134 | LogEntry->Signature = EFI_DATA_ENTRY_SIGNATURE;\r | |
135 | LogEntry->Record = Record;\r | |
136 | LogEntry->RecordSize = sizeof (EFI_DATA_ENTRY) + RawDataSize;\r | |
137 | InsertTailList (&Private->DataListHead, &LogEntry->Link);\r | |
138 | \r | |
139 | CopyMem (Raw, RawData, RawDataSize);\r | |
140 | \r | |
141 | EfiReleaseLock (&Private->DataLock);\r | |
142 | \r | |
143 | //\r | |
144 | // Send Signal to all the filter drivers which are interested\r | |
145 | // in the record's class and guid.\r | |
146 | //\r | |
147 | Head = &Private->FilterDriverListHead;\r | |
2ab23929 | 148 | for (Link = GetFirstNode(Head); Link != Head; Link = GetNextNode(Head, Link)) {\r |
83f6d1a0 | 149 | FilterEntry = FILTER_ENTRY_FROM_LINK (Link);\r |
150 | if (((FilterEntry->ClassFilter & DataRecordClass) != 0) &&\r | |
151 | (CompareGuid (&FilterEntry->FilterDataRecordGuid, &gZeroGuid) || \r | |
152 | CompareGuid (&FilterEntry->FilterDataRecordGuid, DataRecordGuid))) {\r | |
153 | gBS->SignalEvent (FilterEntry->Event);\r | |
154 | }\r | |
155 | }\r | |
156 | \r | |
157 | return EFI_SUCCESS;\r | |
158 | }\r | |
159 | \r | |
a73d0c74 | 160 | /**\r |
83f6d1a0 | 161 | \r |
162 | Get a previously logged data record and the MonotonicCount for the next\r | |
163 | availible Record. This allows all records or all records later \r | |
164 | than a give MonotonicCount to be returned. If an optional FilterDriverEvent\r | |
165 | is passed in with a MonotonicCout of zero return the first record \r | |
166 | not yet read by the filter driver. If FilterDriverEvent is NULL and \r | |
167 | MonotonicCount is zero return the first data record.\r | |
168 | \r | |
2ab23929 | 169 | @param This Pointer to the EFI_DATA_HUB_PROTOCOL instance.\r |
170 | @param MonotonicCount Specifies the Record to return. On input, zero means\r | |
171 | return the first record. On output, contains the next\r | |
172 | record to availible. Zero indicates no more records.\r | |
173 | @param FilterDriverEvent If FilterDriverEvent is not passed in a MonotonicCount \r | |
174 | of zero, it means to return the first data record. \r | |
175 | If FilterDriverEvent is passed in, then a MonotonicCount \r | |
176 | of zero means to return the first data not yet read by \r | |
177 | FilterDriverEvent.\r | |
178 | @param Record Returns a dynamically allocated memory buffer with a data \r | |
179 | record that matches MonotonicCount.\r | |
180 | \r | |
181 | @retval EFI_SUCCESS Data was returned in Record.\r | |
182 | @retval EFI_INVALID_PARAMETER FilterDriverEvent was passed in but does not exist.\r | |
183 | @retval EFI_NOT_FOUND MonotonicCount does not match any data record in the\r | |
184 | system. If a MonotonicCount of zero was passed in, then\r | |
185 | no data records exist in the system.\r | |
186 | @retval EFI_OUT_OF_RESOURCES Record was not returned due to lack of system resources.\r | |
83f6d1a0 | 187 | \r |
a73d0c74 | 188 | **/\r |
a73d0c74 | 189 | EFI_STATUS\r |
190 | EFIAPI\r | |
191 | DataHubGetNextRecord (\r | |
192 | IN EFI_DATA_HUB_PROTOCOL *This,\r | |
193 | IN OUT UINT64 *MonotonicCount,\r | |
194 | IN EFI_EVENT *FilterDriverEvent, OPTIONAL\r | |
195 | OUT EFI_DATA_RECORD_HEADER **Record\r | |
196 | )\r | |
83f6d1a0 | 197 | {\r |
198 | DATA_HUB_INSTANCE *Private;\r | |
199 | DATA_HUB_FILTER_DRIVER *FilterDriver;\r | |
200 | UINT64 ClassFilter;\r | |
201 | UINT64 FilterMonotonicCount;\r | |
202 | \r | |
203 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
204 | \r | |
205 | FilterDriver = NULL;\r | |
206 | FilterMonotonicCount = 0;\r | |
207 | ClassFilter = EFI_DATA_RECORD_CLASS_DEBUG |\r | |
208 | EFI_DATA_RECORD_CLASS_ERROR |\r | |
209 | EFI_DATA_RECORD_CLASS_DATA |\r | |
210 | EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
211 | \r | |
212 | if (FilterDriverEvent != NULL) {\r | |
213 | //\r | |
214 | // For events the beginning is the last unread record. This info is\r | |
215 | // stored in the instance structure, so we must look up the event\r | |
216 | // to get the data.\r | |
217 | //\r | |
218 | FilterDriver = FindFilterDriverByEvent (\r | |
219 | &Private->FilterDriverListHead,\r | |
220 | *FilterDriverEvent\r | |
221 | );\r | |
222 | if (FilterDriver == NULL) {\r | |
223 | return EFI_INVALID_PARAMETER;\r | |
224 | }\r | |
225 | //\r | |
226 | // Use the Class filter the event was created with.\r | |
227 | //\r | |
228 | ClassFilter = FilterDriver->ClassFilter;\r | |
229 | \r | |
230 | if (*MonotonicCount == 0) {\r | |
231 | //\r | |
232 | // Use the MTC from the Filter Driver.\r | |
233 | //\r | |
234 | FilterMonotonicCount = FilterDriver->GetNextMonotonicCount;\r | |
2ebbe08c | 235 | \r |
236 | //\r | |
237 | // The GetNextMonotonicCount field remembers the last value from the previous time.\r | |
238 | // But we already processed this vaule, so we need to find the next one.\r | |
239 | //\r | |
240 | *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, &FilterMonotonicCount);\r | |
83f6d1a0 | 241 | if (FilterMonotonicCount != 0) {\r |
2ebbe08c | 242 | *MonotonicCount = FilterMonotonicCount;\r |
243 | }\r | |
244 | \r | |
245 | if ((FilterDriver->GetNextMonotonicCount != 0) && (FilterMonotonicCount == 0)) {\r | |
83f6d1a0 | 246 | //\r |
2ebbe08c | 247 | // If there is no new record to get exit now.\r |
83f6d1a0 | 248 | //\r |
2ebbe08c | 249 | *MonotonicCount = 0;\r |
250 | return EFI_NOT_FOUND;\r | |
83f6d1a0 | 251 | }\r |
252 | }\r | |
253 | }\r | |
254 | //\r | |
255 | // Return the record\r | |
256 | //\r | |
257 | *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r | |
258 | if (*Record == NULL) {\r | |
259 | return EFI_NOT_FOUND;\r | |
260 | }\r | |
261 | \r | |
262 | if (FilterDriver != NULL) {\r | |
263 | //\r | |
264 | // If we have a filter driver update the records that have been read.\r | |
265 | // If MonotonicCount is zero No more reacords left.\r | |
266 | //\r | |
267 | if (*MonotonicCount == 0) {\r | |
41e4912f | 268 | //\r |
269 | // Save the current Record MonotonicCount.\r | |
270 | //\r | |
271 | FilterDriver->GetNextMonotonicCount = (*Record)->LogMonotonicCount;\r | |
83f6d1a0 | 272 | } else {\r |
273 | //\r | |
274 | // Point to next undread record\r | |
275 | //\r | |
276 | FilterDriver->GetNextMonotonicCount = *MonotonicCount;\r | |
277 | }\r | |
278 | }\r | |
279 | \r | |
280 | return EFI_SUCCESS;\r | |
281 | }\r | |
282 | \r | |
a73d0c74 | 283 | /**\r |
83f6d1a0 | 284 | This function registers the data hub filter driver that is represented \r |
285 | by FilterEvent. Only one instance of each FilterEvent can be registered.\r | |
286 | After the FilterEvent is registered, it will be signaled so it can sync \r | |
287 | with data records that have been recorded prior to the FilterEvent being \r | |
288 | registered.\r | |
289 | \r | |
2ab23929 | 290 | @param This Pointer to The EFI_DATA_HUB_PROTOCOL instance.\r |
291 | @param FilterEvent The EFI_EVENT to signal whenever data that matches \r | |
292 | FilterClass is logged in the system.\r | |
293 | @param FilterTpl The maximum EFI_TPL at which FilterEvent can be \r | |
294 | signaled. It is strongly recommended that you use the \r | |
295 | lowest EFI_TPL possible.\r | |
296 | @param FilterClass FilterEvent will be signaled whenever a bit in \r | |
297 | EFI_DATA_RECORD_HEADER.DataRecordClass is also set in \r | |
298 | FilterClass. If FilterClass is zero, no class-based \r | |
299 | filtering will be performed.\r | |
300 | @param FilterDataRecordGuid FilterEvent will be signaled whenever FilterDataRecordGuid \r | |
301 | matches EFI_DATA_RECORD_HEADER.DataRecordGuid. If \r | |
302 | FilterDataRecordGuid is NULL, then no GUID-based filtering \r | |
303 | will be performed. \r | |
304 | \r | |
305 | @retval EFI_SUCCESS The filter driver event was registered.\r | |
306 | @retval EFI_ALREADY_STARTED FilterEvent was previously registered and cannot be \r | |
307 | registered again.\r | |
308 | @retval EFI_OUT_OF_RESOURCES The filter driver event was not registered due to lack of \r | |
309 | system resources.\r | |
83f6d1a0 | 310 | \r |
a73d0c74 | 311 | **/\r |
a73d0c74 | 312 | EFI_STATUS\r |
313 | EFIAPI\r | |
314 | DataHubRegisterFilterDriver (\r | |
315 | IN EFI_DATA_HUB_PROTOCOL * This,\r | |
316 | IN EFI_EVENT FilterEvent,\r | |
317 | IN EFI_TPL FilterTpl,\r | |
318 | IN UINT64 FilterClass,\r | |
319 | IN EFI_GUID * FilterDataRecordGuid OPTIONAL\r | |
320 | )\r | |
321 | \r | |
83f6d1a0 | 322 | {\r |
323 | DATA_HUB_INSTANCE *Private;\r | |
324 | DATA_HUB_FILTER_DRIVER *FilterDriver;\r | |
325 | \r | |
326 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
327 | \r | |
328 | FilterDriver = (DATA_HUB_FILTER_DRIVER *) AllocateZeroPool (sizeof (DATA_HUB_FILTER_DRIVER));\r | |
329 | if (FilterDriver == NULL) {\r | |
330 | return EFI_OUT_OF_RESOURCES;\r | |
331 | }\r | |
332 | //\r | |
333 | // Initialize filter driver info\r | |
334 | //\r | |
335 | FilterDriver->Signature = EFI_DATA_HUB_FILTER_DRIVER_SIGNATURE;\r | |
336 | FilterDriver->Event = FilterEvent;\r | |
337 | FilterDriver->Tpl = FilterTpl;\r | |
338 | FilterDriver->GetNextMonotonicCount = 0;\r | |
339 | if (FilterClass == 0) {\r | |
340 | FilterDriver->ClassFilter = EFI_DATA_RECORD_CLASS_DEBUG |\r | |
341 | EFI_DATA_RECORD_CLASS_ERROR |\r | |
342 | EFI_DATA_RECORD_CLASS_DATA |\r | |
343 | EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
344 | } else {\r | |
345 | FilterDriver->ClassFilter = FilterClass;\r | |
346 | }\r | |
347 | \r | |
348 | if (FilterDataRecordGuid != NULL) {\r | |
349 | CopyMem (&FilterDriver->FilterDataRecordGuid, FilterDataRecordGuid, sizeof (EFI_GUID));\r | |
350 | }\r | |
351 | //\r | |
352 | // Search for duplicate entries\r | |
353 | //\r | |
354 | if (FindFilterDriverByEvent (&Private->FilterDriverListHead, FilterEvent) != NULL) {\r | |
355 | FreePool (FilterDriver);\r | |
356 | return EFI_ALREADY_STARTED;\r | |
357 | }\r | |
358 | //\r | |
359 | // Make insertion an atomic operation with the lock.\r | |
360 | //\r | |
361 | EfiAcquireLock (&Private->DataLock);\r | |
362 | InsertTailList (&Private->FilterDriverListHead, &FilterDriver->Link);\r | |
363 | EfiReleaseLock (&Private->DataLock);\r | |
364 | \r | |
365 | //\r | |
366 | // Signal the Filter driver we just loaded so they will recieve all the\r | |
367 | // previous history. If we did not signal here we would have to wait until\r | |
368 | // the next data was logged to get the history. In a case where no next\r | |
369 | // data was logged we would never get synced up.\r | |
370 | //\r | |
371 | gBS->SignalEvent (FilterEvent);\r | |
372 | \r | |
373 | return EFI_SUCCESS;\r | |
374 | }\r | |
375 | \r | |
a73d0c74 | 376 | /**\r |
83f6d1a0 | 377 | Remove a Filter Driver, so it no longer gets called when data \r |
378 | information is logged.\r | |
379 | \r | |
2ab23929 | 380 | @param This Protocol instance structure\r |
83f6d1a0 | 381 | \r |
2ab23929 | 382 | @param FilterEvent Event that represents a filter driver that is to be \r |
383 | Unregistered.\r | |
83f6d1a0 | 384 | \r |
2ab23929 | 385 | @retval EFI_SUCCESS If FilterEvent was unregistered\r |
386 | @retval EFI_NOT_FOUND If FilterEvent does not exist\r | |
a73d0c74 | 387 | **/\r |
a73d0c74 | 388 | EFI_STATUS\r |
389 | EFIAPI\r | |
390 | DataHubUnregisterFilterDriver (\r | |
391 | IN EFI_DATA_HUB_PROTOCOL *This,\r | |
392 | IN EFI_EVENT FilterEvent\r | |
393 | )\r | |
83f6d1a0 | 394 | {\r |
395 | DATA_HUB_INSTANCE *Private;\r | |
396 | DATA_HUB_FILTER_DRIVER *FilterDriver;\r | |
397 | \r | |
398 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
399 | \r | |
400 | //\r | |
401 | // Search for duplicate entries\r | |
402 | //\r | |
403 | FilterDriver = FindFilterDriverByEvent (\r | |
404 | &Private->FilterDriverListHead,\r | |
405 | FilterEvent\r | |
406 | );\r | |
407 | if (FilterDriver == NULL) {\r | |
408 | return EFI_NOT_FOUND;\r | |
409 | }\r | |
410 | //\r | |
411 | // Make removal an atomic operation with the lock\r | |
412 | //\r | |
413 | EfiAcquireLock (&Private->DataLock);\r | |
414 | RemoveEntryList (&FilterDriver->Link);\r | |
415 | EfiReleaseLock (&Private->DataLock);\r | |
416 | \r | |
417 | return EFI_SUCCESS;\r | |
418 | }\r | |
83f6d1a0 | 419 | \r |
a73d0c74 | 420 | /**\r |
83f6d1a0 | 421 | Search the Head list for a EFI_DATA_HUB_FILTER_DRIVER member that\r |
2ab23929 | 422 | represents Event and return it.\r |
83f6d1a0 | 423 | \r |
2ab23929 | 424 | @param Head Pointer to head of dual linked list of EFI_DATA_HUB_FILTER_DRIVER structures.\r |
425 | @param Event Event to be search for in the Head list.\r | |
83f6d1a0 | 426 | \r |
2ab23929 | 427 | @retval EFI_DATA_HUB_FILTER_DRIVER Returned if Event stored in the Head doubly linked list.\r |
428 | @retval NULL If Event is not in the list\r | |
a73d0c74 | 429 | \r |
430 | **/\r | |
a73d0c74 | 431 | DATA_HUB_FILTER_DRIVER *\r |
432 | FindFilterDriverByEvent (\r | |
433 | IN LIST_ENTRY *Head,\r | |
434 | IN EFI_EVENT Event\r | |
435 | )\r | |
83f6d1a0 | 436 | {\r |
437 | DATA_HUB_FILTER_DRIVER *FilterEntry;\r | |
438 | LIST_ENTRY *Link;\r | |
439 | \r | |
2ab23929 | 440 | for (Link = GetFirstNode(Head); Link != Head; Link = GetNextNode(Head, Link)) {\r |
83f6d1a0 | 441 | FilterEntry = FILTER_ENTRY_FROM_LINK (Link);\r |
442 | if (FilterEntry->Event == Event) {\r | |
443 | return FilterEntry;\r | |
444 | }\r | |
445 | }\r | |
446 | \r | |
447 | return NULL;\r | |
448 | }\r | |
449 | \r | |
a73d0c74 | 450 | /**\r |
83f6d1a0 | 451 | Search the Head doubly linked list for the passed in MTC. Return the \r |
2ab23929 | 452 | matching element in Head and the MTC on the next entry.\r |
83f6d1a0 | 453 | \r |
2ab23929 | 454 | @param Head Head of Data Log linked list.\r |
455 | @param ClassFilter Only match the MTC if it is in the same Class as the\r | |
456 | ClassFilter.\r | |
457 | @param PtrCurrentMTC On IN contians MTC to search for. On OUT contians next\r | |
458 | MTC in the data log list or zero if at end of the list.\r | |
83f6d1a0 | 459 | \r |
2ab23929 | 460 | @retval EFI_DATA_LOG_ENTRY Return pointer to data log data from Head list.\r |
461 | @retval NULL If no data record exists.\r | |
83f6d1a0 | 462 | \r |
a73d0c74 | 463 | **/\r |
a73d0c74 | 464 | EFI_DATA_RECORD_HEADER *\r |
465 | GetNextDataRecord (\r | |
466 | IN LIST_ENTRY *Head,\r | |
467 | IN UINT64 ClassFilter,\r | |
468 | IN OUT UINT64 *PtrCurrentMTC\r | |
469 | )\r | |
83f6d1a0 | 470 | \r |
83f6d1a0 | 471 | {\r |
472 | EFI_DATA_ENTRY *LogEntry;\r | |
473 | LIST_ENTRY *Link;\r | |
474 | BOOLEAN ReturnFirstEntry;\r | |
475 | EFI_DATA_RECORD_HEADER *Record;\r | |
476 | EFI_DATA_ENTRY *NextLogEntry;\r | |
477 | \r | |
478 | //\r | |
479 | // If MonotonicCount == 0 just return the first one\r | |
480 | //\r | |
481 | ReturnFirstEntry = (BOOLEAN) (*PtrCurrentMTC == 0);\r | |
482 | \r | |
483 | Record = NULL;\r | |
2ab23929 | 484 | for (Link = GetFirstNode(Head); Link != Head; Link = GetNextNode(Head, Link)) {\r |
83f6d1a0 | 485 | LogEntry = DATA_ENTRY_FROM_LINK (Link);\r |
486 | if ((LogEntry->Record->DataRecordClass & ClassFilter) == 0) {\r | |
487 | //\r | |
488 | // Skip any entry that does not have the correct ClassFilter\r | |
489 | //\r | |
490 | continue;\r | |
491 | }\r | |
492 | \r | |
493 | if ((LogEntry->Record->LogMonotonicCount == *PtrCurrentMTC) || ReturnFirstEntry) {\r | |
494 | //\r | |
495 | // Return record to the user\r | |
496 | //\r | |
497 | Record = LogEntry->Record;\r | |
498 | \r | |
499 | //\r | |
500 | // Calculate the next MTC value. If there is no next entry set\r | |
501 | // MTC to zero.\r | |
502 | //\r | |
503 | *PtrCurrentMTC = 0;\r | |
2ab23929 | 504 | for (Link = GetNextNode(Head, Link); Link != Head; Link = GetNextNode(Head, Link)) {\r |
83f6d1a0 | 505 | NextLogEntry = DATA_ENTRY_FROM_LINK (Link);\r |
506 | if ((NextLogEntry->Record->DataRecordClass & ClassFilter) != 0) {\r | |
507 | //\r | |
508 | // Return the MTC of the next thing to search for if found\r | |
509 | //\r | |
510 | *PtrCurrentMTC = NextLogEntry->Record->LogMonotonicCount;\r | |
511 | break;\r | |
512 | }\r | |
513 | }\r | |
514 | //\r | |
515 | // Record found exit loop and return\r | |
516 | //\r | |
517 | break;\r | |
518 | }\r | |
519 | }\r | |
520 | \r | |
521 | return Record;\r | |
522 | }\r | |
83f6d1a0 | 523 | \r |
a73d0c74 | 524 | /**\r |
2ab23929 | 525 | Driver's Entry point routine that install Driver to produce Data Hub protocol. \r |
83f6d1a0 | 526 | \r |
2ab23929 | 527 | @param ImageHandle Module's image handle\r |
528 | @param SystemTable Pointer of EFI_SYSTEM_TABLE\r | |
83f6d1a0 | 529 | \r |
2ab23929 | 530 | @retval EFI_SUCCESS Logging Hub protocol installed\r |
531 | @retval Other No protocol installed, unload driver.\r | |
83f6d1a0 | 532 | \r |
a73d0c74 | 533 | **/\r |
534 | EFI_STATUS\r | |
535 | EFIAPI\r | |
536 | DataHubInstall (\r | |
537 | IN EFI_HANDLE ImageHandle,\r | |
538 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
539 | )\r | |
83f6d1a0 | 540 | {\r |
541 | EFI_STATUS Status;\r | |
542 | UINT32 HighMontonicCount;\r | |
543 | \r | |
544 | mPrivateData.Signature = DATA_HUB_INSTANCE_SIGNATURE;\r | |
545 | mPrivateData.DataHub.LogData = DataHubLogData;\r | |
546 | mPrivateData.DataHub.GetNextRecord = DataHubGetNextRecord;\r | |
547 | mPrivateData.DataHub.RegisterFilterDriver = DataHubRegisterFilterDriver;\r | |
548 | mPrivateData.DataHub.UnregisterFilterDriver = DataHubUnregisterFilterDriver;\r | |
549 | \r | |
550 | //\r | |
551 | // Initialize Private Data in CORE_LOGGING_HUB_INSTANCE that is\r | |
2ab23929 | 552 | // required by this protocol\r |
83f6d1a0 | 553 | //\r |
554 | InitializeListHead (&mPrivateData.DataListHead);\r | |
555 | InitializeListHead (&mPrivateData.FilterDriverListHead);\r | |
556 | \r | |
557 | EfiInitializeLock (&mPrivateData.DataLock, TPL_NOTIFY);\r | |
558 | \r | |
559 | //\r | |
560 | // Make sure we get a bigger MTC number on every boot!\r | |
561 | //\r | |
562 | Status = gRT->GetNextHighMonotonicCount (&HighMontonicCount);\r | |
563 | if (EFI_ERROR (Status)) {\r | |
564 | //\r | |
565 | // if system service fails pick a sane value.\r | |
566 | //\r | |
567 | mPrivateData.GlobalMonotonicCount = 0;\r | |
568 | } else {\r | |
569 | mPrivateData.GlobalMonotonicCount = LShiftU64 ((UINT64) HighMontonicCount, 32);\r | |
570 | }\r | |
571 | //\r | |
572 | // Make a new handle and install the protocol\r | |
573 | //\r | |
574 | mPrivateData.Handle = NULL;\r | |
575 | Status = gBS->InstallProtocolInterface (\r | |
576 | &mPrivateData.Handle,\r | |
577 | &gEfiDataHubProtocolGuid,\r | |
578 | EFI_NATIVE_INTERFACE,\r | |
579 | &mPrivateData.DataHub\r | |
580 | );\r | |
581 | return Status;\r | |
582 | }\r | |
a73d0c74 | 583 | \r |