2 This code produces the Data Hub protocol. It preloads the data hub
3 with status information copied in from PEI HOBs.
5 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 CONST EFI_GUID gZeroGuid
= { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
21 // Since this driver will only ever produce one instance of the Logging Hub
22 // protocol you are not required to dynamically allocate the PrivateData.
24 DATA_HUB_INSTANCE mPrivateData
;
27 Log data record into the data logging hub
29 @param This Protocol instance structure
30 @param DataRecordGuid GUID that defines record contents
31 @param ProducerName GUID that defines the name of the producer of the data
32 @param DataRecordClass Class that defines generic record type
33 @param RawData Data Log record as defined by DataRecordGuid
34 @param RawDataSize Size of Data Log data in bytes
36 @retval EFI_SUCCESS If data was logged
37 @retval EFI_OUT_OF_RESOURCES If data was not logged due to lack of system
43 IN EFI_DATA_HUB_PROTOCOL
*This
,
44 IN EFI_GUID
*DataRecordGuid
,
45 IN EFI_GUID
*ProducerName
,
46 IN UINT64 DataRecordClass
,
52 DATA_HUB_INSTANCE
*Private
;
53 EFI_DATA_ENTRY
*LogEntry
;
56 EFI_DATA_RECORD_HEADER
*Record
;
58 DATA_HUB_FILTER_DRIVER
*FilterEntry
;
62 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
65 // Combine the storage for the internal structs and a copy of the log record.
66 // Record follows PrivateLogEntry. The consumer will be returned a pointer
67 // to Record so we don't what it to be the thing that was allocated from
68 // pool, so the consumer can't free an data record by mistake.
70 RecordSize
= sizeof (EFI_DATA_RECORD_HEADER
) + RawDataSize
;
71 TotalSize
= sizeof (EFI_DATA_ENTRY
) + RecordSize
;
74 // The Logging action is the critical section, so it is locked.
75 // The MTC asignment & update, time, and logging must be an
76 // atomic operation, so use the lock.
78 Status
= EfiAcquireLockOrFail (&Private
->DataLock
);
79 if (EFI_ERROR (Status
)) {
81 // Reentrancy detected so exit!
86 LogEntry
= AllocatePool (TotalSize
);
88 if (LogEntry
== NULL
) {
89 EfiReleaseLock (&Private
->DataLock
);
90 return EFI_OUT_OF_RESOURCES
;
93 ZeroMem (LogEntry
, TotalSize
);
95 Record
= (EFI_DATA_RECORD_HEADER
*) (LogEntry
+ 1);
96 Raw
= (VOID
*) (Record
+ 1);
99 // Build Standard Log Header
101 Record
->Version
= EFI_DATA_RECORD_HEADER_VERSION
;
102 Record
->HeaderSize
= (UINT16
) sizeof (EFI_DATA_RECORD_HEADER
);
103 Record
->RecordSize
= RecordSize
;
104 CopyMem (&Record
->DataRecordGuid
, DataRecordGuid
, sizeof (EFI_GUID
));
105 CopyMem (&Record
->ProducerName
, ProducerName
, sizeof (EFI_GUID
));
106 Record
->DataRecordClass
= DataRecordClass
;
109 // Ensure LogMonotonicCount is not zero
111 Record
->LogMonotonicCount
= ++Private
->GlobalMonotonicCount
;
113 gRT
->GetTime (&Record
->LogTime
, NULL
);
116 // Insert log into the internal linked list.
118 LogEntry
->Signature
= EFI_DATA_ENTRY_SIGNATURE
;
119 LogEntry
->Record
= Record
;
120 LogEntry
->RecordSize
= sizeof (EFI_DATA_ENTRY
) + RawDataSize
;
121 InsertTailList (&Private
->DataListHead
, &LogEntry
->Link
);
123 CopyMem (Raw
, RawData
, RawDataSize
);
125 EfiReleaseLock (&Private
->DataLock
);
128 // Send Signal to all the filter drivers which are interested
129 // in the record's class and guid.
131 Head
= &Private
->FilterDriverListHead
;
132 for (Link
= GetFirstNode(Head
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
133 FilterEntry
= FILTER_ENTRY_FROM_LINK (Link
);
134 if (((FilterEntry
->ClassFilter
& DataRecordClass
) != 0) &&
135 (CompareGuid (&FilterEntry
->FilterDataRecordGuid
, &gZeroGuid
) ||
136 CompareGuid (&FilterEntry
->FilterDataRecordGuid
, DataRecordGuid
))) {
137 gBS
->SignalEvent (FilterEntry
->Event
);
145 Search the Head doubly linked list for the passed in MTC. Return the
146 matching element in Head and the MTC on the next entry.
148 @param Head Head of Data Log linked list.
149 @param ClassFilter Only match the MTC if it is in the same Class as the
151 @param PtrCurrentMTC On IN contians MTC to search for. On OUT contians next
152 MTC in the data log list or zero if at end of the list.
154 @retval EFI_DATA_LOG_ENTRY Return pointer to data log data from Head list.
155 @retval NULL If no data record exists.
158 EFI_DATA_RECORD_HEADER
*
161 IN UINT64 ClassFilter
,
162 IN OUT UINT64
*PtrCurrentMTC
166 EFI_DATA_ENTRY
*LogEntry
;
168 BOOLEAN ReturnFirstEntry
;
169 EFI_DATA_RECORD_HEADER
*Record
;
170 EFI_DATA_ENTRY
*NextLogEntry
;
173 // If MonotonicCount == 0 just return the first one
175 ReturnFirstEntry
= (BOOLEAN
) (*PtrCurrentMTC
== 0);
178 for (Link
= GetFirstNode(Head
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
179 LogEntry
= DATA_ENTRY_FROM_LINK (Link
);
180 if ((LogEntry
->Record
->DataRecordClass
& ClassFilter
) == 0) {
182 // Skip any entry that does not have the correct ClassFilter
187 if ((LogEntry
->Record
->LogMonotonicCount
== *PtrCurrentMTC
) || ReturnFirstEntry
) {
189 // Return record to the user
191 Record
= LogEntry
->Record
;
194 // Calculate the next MTC value. If there is no next entry set
198 for (Link
= GetNextNode(Head
, Link
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
199 NextLogEntry
= DATA_ENTRY_FROM_LINK (Link
);
200 if ((NextLogEntry
->Record
->DataRecordClass
& ClassFilter
) != 0) {
202 // Return the MTC of the next thing to search for if found
204 *PtrCurrentMTC
= NextLogEntry
->Record
->LogMonotonicCount
;
209 // Record found exit loop and return
219 Search the Head list for a EFI_DATA_HUB_FILTER_DRIVER member that
220 represents Event and return it.
222 @param Head Pointer to head of dual linked list of EFI_DATA_HUB_FILTER_DRIVER structures.
223 @param Event Event to be search for in the Head list.
225 @retval EFI_DATA_HUB_FILTER_DRIVER Returned if Event stored in the Head doubly linked list.
226 @retval NULL If Event is not in the list
229 DATA_HUB_FILTER_DRIVER
*
230 FindFilterDriverByEvent (
235 DATA_HUB_FILTER_DRIVER
*FilterEntry
;
238 for (Link
= GetFirstNode(Head
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
239 FilterEntry
= FILTER_ENTRY_FROM_LINK (Link
);
240 if (FilterEntry
->Event
== Event
) {
250 Get a previously logged data record and the MonotonicCount for the next
251 availible Record. This allows all records or all records later
252 than a give MonotonicCount to be returned. If an optional FilterDriverEvent
253 is passed in with a MonotonicCout of zero return the first record
254 not yet read by the filter driver. If FilterDriverEvent is NULL and
255 MonotonicCount is zero return the first data record.
257 @param This Pointer to the EFI_DATA_HUB_PROTOCOL instance.
258 @param MonotonicCount Specifies the Record to return. On input, zero means
259 return the first record. On output, contains the next
260 record to availible. Zero indicates no more records.
261 @param FilterDriverEvent If FilterDriverEvent is not passed in a MonotonicCount
262 of zero, it means to return the first data record.
263 If FilterDriverEvent is passed in, then a MonotonicCount
264 of zero means to return the first data not yet read by
266 @param Record Returns a dynamically allocated memory buffer with a data
267 record that matches MonotonicCount.
269 @retval EFI_SUCCESS Data was returned in Record.
270 @retval EFI_INVALID_PARAMETER FilterDriverEvent was passed in but does not exist.
271 @retval EFI_NOT_FOUND MonotonicCount does not match any data record in the
272 system. If a MonotonicCount of zero was passed in, then
273 no data records exist in the system.
274 @retval EFI_OUT_OF_RESOURCES Record was not returned due to lack of system resources.
279 DataHubGetNextRecord (
280 IN EFI_DATA_HUB_PROTOCOL
*This
,
281 IN OUT UINT64
*MonotonicCount
,
282 IN EFI_EVENT
*FilterDriverEvent
, OPTIONAL
283 OUT EFI_DATA_RECORD_HEADER
**Record
286 DATA_HUB_INSTANCE
*Private
;
287 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
290 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
293 ClassFilter
= EFI_DATA_RECORD_CLASS_DEBUG
|
294 EFI_DATA_RECORD_CLASS_ERROR
|
295 EFI_DATA_RECORD_CLASS_DATA
|
296 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
299 // If FilterDriverEvent is NULL, then return the next record
301 if (FilterDriverEvent
== NULL
) {
302 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
303 if (*Record
== NULL
) {
304 return EFI_NOT_FOUND
;
310 // For events the beginning is the last unread record. This info is
311 // stored in the instance structure, so we must look up the event
314 FilterDriver
= FindFilterDriverByEvent (
315 &Private
->FilterDriverListHead
,
318 if (FilterDriver
== NULL
) {
319 return EFI_INVALID_PARAMETER
;
322 // Use the Class filter the event was created with.
324 ClassFilter
= FilterDriver
->ClassFilter
;
327 // Retrieve the next record or the first record.
329 if (*MonotonicCount
!= 0 || FilterDriver
->GetNextMonotonicCount
== 0) {
330 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
331 if (*Record
== NULL
) {
332 return EFI_NOT_FOUND
;
335 if (*MonotonicCount
!= 0) {
337 // If this was not the last record then update the count associated with the filter
339 FilterDriver
->GetNextMonotonicCount
= *MonotonicCount
;
342 // Save the MonotonicCount of the last record which has been read
344 FilterDriver
->GetNextMonotonicCount
= (*Record
)->LogMonotonicCount
;
350 // This is a request to read the first record that has not been read yet.
351 // Set MonotoicCount to the last record successfuly read
353 *MonotonicCount
= FilterDriver
->GetNextMonotonicCount
;
356 // Retrieve the last record successfuly read again, but do not return it since
357 // it has already been returned before.
359 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
360 if (*Record
== NULL
) {
361 return EFI_NOT_FOUND
;
364 if (*MonotonicCount
!= 0) {
366 // Update the count associated with the filter
368 FilterDriver
->GetNextMonotonicCount
= *MonotonicCount
;
371 // Retrieve the record after the last record successfuly read
373 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
374 if (*Record
== NULL
) {
375 return EFI_NOT_FOUND
;
383 This function registers the data hub filter driver that is represented
384 by FilterEvent. Only one instance of each FilterEvent can be registered.
385 After the FilterEvent is registered, it will be signaled so it can sync
386 with data records that have been recorded prior to the FilterEvent being
389 @param This Pointer to The EFI_DATA_HUB_PROTOCOL instance.
390 @param FilterEvent The EFI_EVENT to signal whenever data that matches
391 FilterClass is logged in the system.
392 @param FilterTpl The maximum EFI_TPL at which FilterEvent can be
393 signaled. It is strongly recommended that you use the
394 lowest EFI_TPL possible.
395 @param FilterClass FilterEvent will be signaled whenever a bit in
396 EFI_DATA_RECORD_HEADER.DataRecordClass is also set in
397 FilterClass. If FilterClass is zero, no class-based
398 filtering will be performed.
399 @param FilterDataRecordGuid FilterEvent will be signaled whenever FilterDataRecordGuid
400 matches EFI_DATA_RECORD_HEADER.DataRecordGuid. If
401 FilterDataRecordGuid is NULL, then no GUID-based filtering
404 @retval EFI_SUCCESS The filter driver event was registered.
405 @retval EFI_ALREADY_STARTED FilterEvent was previously registered and cannot be
407 @retval EFI_OUT_OF_RESOURCES The filter driver event was not registered due to lack of
413 DataHubRegisterFilterDriver (
414 IN EFI_DATA_HUB_PROTOCOL
* This
,
415 IN EFI_EVENT FilterEvent
,
416 IN EFI_TPL FilterTpl
,
417 IN UINT64 FilterClass
,
418 IN EFI_GUID
* FilterDataRecordGuid OPTIONAL
422 DATA_HUB_INSTANCE
*Private
;
423 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
425 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
427 FilterDriver
= (DATA_HUB_FILTER_DRIVER
*) AllocateZeroPool (sizeof (DATA_HUB_FILTER_DRIVER
));
428 if (FilterDriver
== NULL
) {
429 return EFI_OUT_OF_RESOURCES
;
432 // Initialize filter driver info
434 FilterDriver
->Signature
= EFI_DATA_HUB_FILTER_DRIVER_SIGNATURE
;
435 FilterDriver
->Event
= FilterEvent
;
436 FilterDriver
->Tpl
= FilterTpl
;
437 FilterDriver
->GetNextMonotonicCount
= 0;
438 if (FilterClass
== 0) {
439 FilterDriver
->ClassFilter
= EFI_DATA_RECORD_CLASS_DEBUG
|
440 EFI_DATA_RECORD_CLASS_ERROR
|
441 EFI_DATA_RECORD_CLASS_DATA
|
442 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
444 FilterDriver
->ClassFilter
= FilterClass
;
447 if (FilterDataRecordGuid
!= NULL
) {
448 CopyMem (&FilterDriver
->FilterDataRecordGuid
, FilterDataRecordGuid
, sizeof (EFI_GUID
));
451 // Search for duplicate entries
453 if (FindFilterDriverByEvent (&Private
->FilterDriverListHead
, FilterEvent
) != NULL
) {
454 FreePool (FilterDriver
);
455 return EFI_ALREADY_STARTED
;
458 // Make insertion an atomic operation with the lock.
460 EfiAcquireLock (&Private
->DataLock
);
461 InsertTailList (&Private
->FilterDriverListHead
, &FilterDriver
->Link
);
462 EfiReleaseLock (&Private
->DataLock
);
465 // Signal the Filter driver we just loaded so they will recieve all the
466 // previous history. If we did not signal here we would have to wait until
467 // the next data was logged to get the history. In a case where no next
468 // data was logged we would never get synced up.
470 gBS
->SignalEvent (FilterEvent
);
476 Remove a Filter Driver, so it no longer gets called when data
477 information is logged.
479 @param This Protocol instance structure
481 @param FilterEvent Event that represents a filter driver that is to be
484 @retval EFI_SUCCESS If FilterEvent was unregistered
485 @retval EFI_NOT_FOUND If FilterEvent does not exist
489 DataHubUnregisterFilterDriver (
490 IN EFI_DATA_HUB_PROTOCOL
*This
,
491 IN EFI_EVENT FilterEvent
494 DATA_HUB_INSTANCE
*Private
;
495 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
497 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
500 // Search for duplicate entries
502 FilterDriver
= FindFilterDriverByEvent (
503 &Private
->FilterDriverListHead
,
506 if (FilterDriver
== NULL
) {
507 return EFI_NOT_FOUND
;
510 // Make removal an atomic operation with the lock
512 EfiAcquireLock (&Private
->DataLock
);
513 RemoveEntryList (&FilterDriver
->Link
);
514 EfiReleaseLock (&Private
->DataLock
);
522 Driver's Entry point routine that install Driver to produce Data Hub protocol.
524 @param ImageHandle Module's image handle
525 @param SystemTable Pointer of EFI_SYSTEM_TABLE
527 @retval EFI_SUCCESS Logging Hub protocol installed
528 @retval Other No protocol installed, unload driver.
534 IN EFI_HANDLE ImageHandle
,
535 IN EFI_SYSTEM_TABLE
*SystemTable
539 UINT32 HighMontonicCount
;
541 mPrivateData
.Signature
= DATA_HUB_INSTANCE_SIGNATURE
;
542 mPrivateData
.DataHub
.LogData
= DataHubLogData
;
543 mPrivateData
.DataHub
.GetNextRecord
= DataHubGetNextRecord
;
544 mPrivateData
.DataHub
.RegisterFilterDriver
= DataHubRegisterFilterDriver
;
545 mPrivateData
.DataHub
.UnregisterFilterDriver
= DataHubUnregisterFilterDriver
;
548 // Initialize Private Data in CORE_LOGGING_HUB_INSTANCE that is
549 // required by this protocol
551 InitializeListHead (&mPrivateData
.DataListHead
);
552 InitializeListHead (&mPrivateData
.FilterDriverListHead
);
554 EfiInitializeLock (&mPrivateData
.DataLock
, TPL_NOTIFY
);
557 // Make sure we get a bigger MTC number on every boot!
559 Status
= gRT
->GetNextHighMonotonicCount (&HighMontonicCount
);
560 if (EFI_ERROR (Status
)) {
562 // if system service fails pick a sane value.
564 mPrivateData
.GlobalMonotonicCount
= 0;
566 mPrivateData
.GlobalMonotonicCount
= LShiftU64 ((UINT64
) HighMontonicCount
, 32);
569 // Make a new handle and install the protocol
571 mPrivateData
.Handle
= NULL
;
572 Status
= gBS
->InstallProtocolInterface (
573 &mPrivateData
.Handle
,
574 &gEfiDataHubProtocolGuid
,
575 EFI_NATIVE_INTERFACE
,
576 &mPrivateData
.DataHub