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
;
63 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
66 // Combine the storage for the internal structs and a copy of the log record.
67 // Record follows PrivateLogEntry. The consumer will be returned a pointer
68 // to Record so we don't what it to be the thing that was allocated from
69 // pool, so the consumer can't free an data record by mistake.
71 RecordSize
= sizeof (EFI_DATA_RECORD_HEADER
) + RawDataSize
;
72 TotalSize
= sizeof (EFI_DATA_ENTRY
) + RecordSize
;
75 // First try to get log time at TPL level <= TPL_CALLBACK.
77 ZeroMem (&LogTime
, sizeof (LogTime
));
78 if (EfiGetCurrentTpl() <= TPL_CALLBACK
) {
79 gRT
->GetTime (&LogTime
, NULL
);
83 // The Logging action is the critical section, so it is locked.
84 // The MTC asignment & update and logging must be an
85 // atomic operation, so use the lock.
87 Status
= EfiAcquireLockOrFail (&Private
->DataLock
);
88 if (EFI_ERROR (Status
)) {
90 // Reentrancy detected so exit!
95 LogEntry
= AllocatePool (TotalSize
);
97 if (LogEntry
== NULL
) {
98 EfiReleaseLock (&Private
->DataLock
);
99 return EFI_OUT_OF_RESOURCES
;
102 ZeroMem (LogEntry
, TotalSize
);
104 Record
= (EFI_DATA_RECORD_HEADER
*) (LogEntry
+ 1);
105 Raw
= (VOID
*) (Record
+ 1);
108 // Build Standard Log Header
110 Record
->Version
= EFI_DATA_RECORD_HEADER_VERSION
;
111 Record
->HeaderSize
= (UINT16
) sizeof (EFI_DATA_RECORD_HEADER
);
112 Record
->RecordSize
= RecordSize
;
113 CopyMem (&Record
->DataRecordGuid
, DataRecordGuid
, sizeof (EFI_GUID
));
114 CopyMem (&Record
->ProducerName
, ProducerName
, sizeof (EFI_GUID
));
115 Record
->DataRecordClass
= DataRecordClass
;
118 // Ensure LogMonotonicCount is not zero
120 Record
->LogMonotonicCount
= ++Private
->GlobalMonotonicCount
;
122 CopyMem (&Record
->LogTime
, &LogTime
, sizeof (LogTime
));
125 // Insert log into the internal linked list.
127 LogEntry
->Signature
= EFI_DATA_ENTRY_SIGNATURE
;
128 LogEntry
->Record
= Record
;
129 LogEntry
->RecordSize
= sizeof (EFI_DATA_ENTRY
) + RawDataSize
;
130 InsertTailList (&Private
->DataListHead
, &LogEntry
->Link
);
132 CopyMem (Raw
, RawData
, RawDataSize
);
134 EfiReleaseLock (&Private
->DataLock
);
137 // Send Signal to all the filter drivers which are interested
138 // in the record's class and guid.
140 Head
= &Private
->FilterDriverListHead
;
141 for (Link
= GetFirstNode(Head
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
142 FilterEntry
= FILTER_ENTRY_FROM_LINK (Link
);
143 if (((FilterEntry
->ClassFilter
& DataRecordClass
) != 0) &&
144 (CompareGuid (&FilterEntry
->FilterDataRecordGuid
, &gZeroGuid
) ||
145 CompareGuid (&FilterEntry
->FilterDataRecordGuid
, DataRecordGuid
))) {
146 gBS
->SignalEvent (FilterEntry
->Event
);
154 Search the Head doubly linked list for the passed in MTC. Return the
155 matching element in Head and the MTC on the next entry.
157 @param Head Head of Data Log linked list.
158 @param ClassFilter Only match the MTC if it is in the same Class as the
160 @param PtrCurrentMTC On IN contians MTC to search for. On OUT contians next
161 MTC in the data log list or zero if at end of the list.
163 @retval EFI_DATA_LOG_ENTRY Return pointer to data log data from Head list.
164 @retval NULL If no data record exists.
167 EFI_DATA_RECORD_HEADER
*
170 IN UINT64 ClassFilter
,
171 IN OUT UINT64
*PtrCurrentMTC
175 EFI_DATA_ENTRY
*LogEntry
;
177 BOOLEAN ReturnFirstEntry
;
178 EFI_DATA_RECORD_HEADER
*Record
;
179 EFI_DATA_ENTRY
*NextLogEntry
;
182 // If MonotonicCount == 0 just return the first one
184 ReturnFirstEntry
= (BOOLEAN
) (*PtrCurrentMTC
== 0);
187 for (Link
= GetFirstNode(Head
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
188 LogEntry
= DATA_ENTRY_FROM_LINK (Link
);
189 if ((LogEntry
->Record
->DataRecordClass
& ClassFilter
) == 0) {
191 // Skip any entry that does not have the correct ClassFilter
196 if ((LogEntry
->Record
->LogMonotonicCount
== *PtrCurrentMTC
) || ReturnFirstEntry
) {
198 // Return record to the user
200 Record
= LogEntry
->Record
;
203 // Calculate the next MTC value. If there is no next entry set
207 for (Link
= GetNextNode(Head
, Link
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
208 NextLogEntry
= DATA_ENTRY_FROM_LINK (Link
);
209 if ((NextLogEntry
->Record
->DataRecordClass
& ClassFilter
) != 0) {
211 // Return the MTC of the next thing to search for if found
213 *PtrCurrentMTC
= NextLogEntry
->Record
->LogMonotonicCount
;
218 // Record found exit loop and return
228 Search the Head list for a EFI_DATA_HUB_FILTER_DRIVER member that
229 represents Event and return it.
231 @param Head Pointer to head of dual linked list of EFI_DATA_HUB_FILTER_DRIVER structures.
232 @param Event Event to be search for in the Head list.
234 @retval EFI_DATA_HUB_FILTER_DRIVER Returned if Event stored in the Head doubly linked list.
235 @retval NULL If Event is not in the list
238 DATA_HUB_FILTER_DRIVER
*
239 FindFilterDriverByEvent (
244 DATA_HUB_FILTER_DRIVER
*FilterEntry
;
247 for (Link
= GetFirstNode(Head
); Link
!= Head
; Link
= GetNextNode(Head
, Link
)) {
248 FilterEntry
= FILTER_ENTRY_FROM_LINK (Link
);
249 if (FilterEntry
->Event
== Event
) {
259 Get a previously logged data record and the MonotonicCount for the next
260 availible Record. This allows all records or all records later
261 than a give MonotonicCount to be returned. If an optional FilterDriverEvent
262 is passed in with a MonotonicCout of zero return the first record
263 not yet read by the filter driver. If FilterDriverEvent is NULL and
264 MonotonicCount is zero return the first data record.
266 @param This Pointer to the EFI_DATA_HUB_PROTOCOL instance.
267 @param MonotonicCount Specifies the Record to return. On input, zero means
268 return the first record. On output, contains the next
269 record to availible. Zero indicates no more records.
270 @param FilterDriverEvent If FilterDriverEvent is not passed in a MonotonicCount
271 of zero, it means to return the first data record.
272 If FilterDriverEvent is passed in, then a MonotonicCount
273 of zero means to return the first data not yet read by
275 @param Record Returns a dynamically allocated memory buffer with a data
276 record that matches MonotonicCount.
278 @retval EFI_SUCCESS Data was returned in Record.
279 @retval EFI_INVALID_PARAMETER FilterDriverEvent was passed in but does not exist.
280 @retval EFI_NOT_FOUND MonotonicCount does not match any data record in the
281 system. If a MonotonicCount of zero was passed in, then
282 no data records exist in the system.
283 @retval EFI_OUT_OF_RESOURCES Record was not returned due to lack of system resources.
288 DataHubGetNextRecord (
289 IN EFI_DATA_HUB_PROTOCOL
*This
,
290 IN OUT UINT64
*MonotonicCount
,
291 IN EFI_EVENT
*FilterDriverEvent
, OPTIONAL
292 OUT EFI_DATA_RECORD_HEADER
**Record
295 DATA_HUB_INSTANCE
*Private
;
296 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
299 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
302 ClassFilter
= EFI_DATA_RECORD_CLASS_DEBUG
|
303 EFI_DATA_RECORD_CLASS_ERROR
|
304 EFI_DATA_RECORD_CLASS_DATA
|
305 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
308 // If FilterDriverEvent is NULL, then return the next record
310 if (FilterDriverEvent
== NULL
) {
311 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
312 if (*Record
== NULL
) {
313 return EFI_NOT_FOUND
;
319 // For events the beginning is the last unread record. This info is
320 // stored in the instance structure, so we must look up the event
323 FilterDriver
= FindFilterDriverByEvent (
324 &Private
->FilterDriverListHead
,
327 if (FilterDriver
== NULL
) {
328 return EFI_INVALID_PARAMETER
;
331 // Use the Class filter the event was created with.
333 ClassFilter
= FilterDriver
->ClassFilter
;
336 // Retrieve the next record or the first record.
338 if (*MonotonicCount
!= 0 || FilterDriver
->GetNextMonotonicCount
== 0) {
339 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
340 if (*Record
== NULL
) {
341 return EFI_NOT_FOUND
;
344 if (*MonotonicCount
!= 0) {
346 // If this was not the last record then update the count associated with the filter
348 FilterDriver
->GetNextMonotonicCount
= *MonotonicCount
;
351 // Save the MonotonicCount of the last record which has been read
353 FilterDriver
->GetNextMonotonicCount
= (*Record
)->LogMonotonicCount
;
359 // This is a request to read the first record that has not been read yet.
360 // Set MonotoicCount to the last record successfuly read
362 *MonotonicCount
= FilterDriver
->GetNextMonotonicCount
;
365 // Retrieve the last record successfuly read again, but do not return it since
366 // it has already been returned before.
368 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
369 if (*Record
== NULL
) {
370 return EFI_NOT_FOUND
;
373 if (*MonotonicCount
!= 0) {
375 // Update the count associated with the filter
377 FilterDriver
->GetNextMonotonicCount
= *MonotonicCount
;
380 // Retrieve the record after the last record successfuly read
382 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
383 if (*Record
== NULL
) {
384 return EFI_NOT_FOUND
;
392 This function registers the data hub filter driver that is represented
393 by FilterEvent. Only one instance of each FilterEvent can be registered.
394 After the FilterEvent is registered, it will be signaled so it can sync
395 with data records that have been recorded prior to the FilterEvent being
398 @param This Pointer to The EFI_DATA_HUB_PROTOCOL instance.
399 @param FilterEvent The EFI_EVENT to signal whenever data that matches
400 FilterClass is logged in the system.
401 @param FilterTpl The maximum EFI_TPL at which FilterEvent can be
402 signaled. It is strongly recommended that you use the
403 lowest EFI_TPL possible.
404 @param FilterClass FilterEvent will be signaled whenever a bit in
405 EFI_DATA_RECORD_HEADER.DataRecordClass is also set in
406 FilterClass. If FilterClass is zero, no class-based
407 filtering will be performed.
408 @param FilterDataRecordGuid FilterEvent will be signaled whenever FilterDataRecordGuid
409 matches EFI_DATA_RECORD_HEADER.DataRecordGuid. If
410 FilterDataRecordGuid is NULL, then no GUID-based filtering
413 @retval EFI_SUCCESS The filter driver event was registered.
414 @retval EFI_ALREADY_STARTED FilterEvent was previously registered and cannot be
416 @retval EFI_OUT_OF_RESOURCES The filter driver event was not registered due to lack of
422 DataHubRegisterFilterDriver (
423 IN EFI_DATA_HUB_PROTOCOL
* This
,
424 IN EFI_EVENT FilterEvent
,
425 IN EFI_TPL FilterTpl
,
426 IN UINT64 FilterClass
,
427 IN EFI_GUID
* FilterDataRecordGuid OPTIONAL
431 DATA_HUB_INSTANCE
*Private
;
432 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
434 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
436 FilterDriver
= (DATA_HUB_FILTER_DRIVER
*) AllocateZeroPool (sizeof (DATA_HUB_FILTER_DRIVER
));
437 if (FilterDriver
== NULL
) {
438 return EFI_OUT_OF_RESOURCES
;
441 // Initialize filter driver info
443 FilterDriver
->Signature
= EFI_DATA_HUB_FILTER_DRIVER_SIGNATURE
;
444 FilterDriver
->Event
= FilterEvent
;
445 FilterDriver
->Tpl
= FilterTpl
;
446 FilterDriver
->GetNextMonotonicCount
= 0;
447 if (FilterClass
== 0) {
448 FilterDriver
->ClassFilter
= EFI_DATA_RECORD_CLASS_DEBUG
|
449 EFI_DATA_RECORD_CLASS_ERROR
|
450 EFI_DATA_RECORD_CLASS_DATA
|
451 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
453 FilterDriver
->ClassFilter
= FilterClass
;
456 if (FilterDataRecordGuid
!= NULL
) {
457 CopyMem (&FilterDriver
->FilterDataRecordGuid
, FilterDataRecordGuid
, sizeof (EFI_GUID
));
460 // Search for duplicate entries
462 if (FindFilterDriverByEvent (&Private
->FilterDriverListHead
, FilterEvent
) != NULL
) {
463 FreePool (FilterDriver
);
464 return EFI_ALREADY_STARTED
;
467 // Make insertion an atomic operation with the lock.
469 EfiAcquireLock (&Private
->DataLock
);
470 InsertTailList (&Private
->FilterDriverListHead
, &FilterDriver
->Link
);
471 EfiReleaseLock (&Private
->DataLock
);
474 // Signal the Filter driver we just loaded so they will recieve all the
475 // previous history. If we did not signal here we would have to wait until
476 // the next data was logged to get the history. In a case where no next
477 // data was logged we would never get synced up.
479 gBS
->SignalEvent (FilterEvent
);
485 Remove a Filter Driver, so it no longer gets called when data
486 information is logged.
488 @param This Protocol instance structure
490 @param FilterEvent Event that represents a filter driver that is to be
493 @retval EFI_SUCCESS If FilterEvent was unregistered
494 @retval EFI_NOT_FOUND If FilterEvent does not exist
498 DataHubUnregisterFilterDriver (
499 IN EFI_DATA_HUB_PROTOCOL
*This
,
500 IN EFI_EVENT FilterEvent
503 DATA_HUB_INSTANCE
*Private
;
504 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
506 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
509 // Search for duplicate entries
511 FilterDriver
= FindFilterDriverByEvent (
512 &Private
->FilterDriverListHead
,
515 if (FilterDriver
== NULL
) {
516 return EFI_NOT_FOUND
;
519 // Make removal an atomic operation with the lock
521 EfiAcquireLock (&Private
->DataLock
);
522 RemoveEntryList (&FilterDriver
->Link
);
523 EfiReleaseLock (&Private
->DataLock
);
531 Driver's Entry point routine that install Driver to produce Data Hub protocol.
533 @param ImageHandle Module's image handle
534 @param SystemTable Pointer of EFI_SYSTEM_TABLE
536 @retval EFI_SUCCESS Logging Hub protocol installed
537 @retval Other No protocol installed, unload driver.
543 IN EFI_HANDLE ImageHandle
,
544 IN EFI_SYSTEM_TABLE
*SystemTable
548 UINT32 HighMontonicCount
;
550 mPrivateData
.Signature
= DATA_HUB_INSTANCE_SIGNATURE
;
551 mPrivateData
.DataHub
.LogData
= DataHubLogData
;
552 mPrivateData
.DataHub
.GetNextRecord
= DataHubGetNextRecord
;
553 mPrivateData
.DataHub
.RegisterFilterDriver
= DataHubRegisterFilterDriver
;
554 mPrivateData
.DataHub
.UnregisterFilterDriver
= DataHubUnregisterFilterDriver
;
557 // Initialize Private Data in CORE_LOGGING_HUB_INSTANCE that is
558 // required by this protocol
560 InitializeListHead (&mPrivateData
.DataListHead
);
561 InitializeListHead (&mPrivateData
.FilterDriverListHead
);
563 EfiInitializeLock (&mPrivateData
.DataLock
, TPL_NOTIFY
);
566 // Make sure we get a bigger MTC number on every boot!
568 Status
= gRT
->GetNextHighMonotonicCount (&HighMontonicCount
);
569 if (EFI_ERROR (Status
)) {
571 // if system service fails pick a sane value.
573 mPrivateData
.GlobalMonotonicCount
= 0;
575 mPrivateData
.GlobalMonotonicCount
= LShiftU64 ((UINT64
) HighMontonicCount
, 32);
578 // Make a new handle and install the protocol
580 mPrivateData
.Handle
= NULL
;
581 Status
= gBS
->InstallProtocolInterface (
582 &mPrivateData
.Handle
,
583 &gEfiDataHubProtocolGuid
,
584 EFI_NATIVE_INTERFACE
,
585 &mPrivateData
.DataHub