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
;
289 UINT64 FilterMonotonicCount
;
291 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
294 FilterMonotonicCount
= 0;
295 ClassFilter
= EFI_DATA_RECORD_CLASS_DEBUG
|
296 EFI_DATA_RECORD_CLASS_ERROR
|
297 EFI_DATA_RECORD_CLASS_DATA
|
298 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
300 if (FilterDriverEvent
!= NULL
) {
302 // For events the beginning is the last unread record. This info is
303 // stored in the instance structure, so we must look up the event
306 FilterDriver
= FindFilterDriverByEvent (
307 &Private
->FilterDriverListHead
,
310 if (FilterDriver
== NULL
) {
311 return EFI_INVALID_PARAMETER
;
314 // Use the Class filter the event was created with.
316 ClassFilter
= FilterDriver
->ClassFilter
;
318 if (*MonotonicCount
== 0) {
320 // Use the MTC from the Filter Driver.
322 FilterMonotonicCount
= FilterDriver
->GetNextMonotonicCount
;
325 // The GetNextMonotonicCount field remembers the last value from the previous time.
326 // But we already processed this vaule, so we need to find the next one.
328 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, &FilterMonotonicCount
);
329 if (FilterMonotonicCount
!= 0) {
330 *MonotonicCount
= FilterMonotonicCount
;
333 if ((FilterDriver
->GetNextMonotonicCount
!= 0) && (FilterMonotonicCount
== 0)) {
335 // If there is no new record to get exit now.
338 return EFI_NOT_FOUND
;
345 *Record
= GetNextDataRecord (&Private
->DataListHead
, ClassFilter
, MonotonicCount
);
346 if (*Record
== NULL
) {
347 return EFI_NOT_FOUND
;
350 if (FilterDriver
!= NULL
) {
352 // If we have a filter driver update the records that have been read.
353 // If MonotonicCount is zero No more reacords left.
355 if (*MonotonicCount
== 0) {
357 // Save the current Record MonotonicCount.
359 FilterDriver
->GetNextMonotonicCount
= (*Record
)->LogMonotonicCount
;
362 // Point to next undread record
364 FilterDriver
->GetNextMonotonicCount
= *MonotonicCount
;
372 This function registers the data hub filter driver that is represented
373 by FilterEvent. Only one instance of each FilterEvent can be registered.
374 After the FilterEvent is registered, it will be signaled so it can sync
375 with data records that have been recorded prior to the FilterEvent being
378 @param This Pointer to The EFI_DATA_HUB_PROTOCOL instance.
379 @param FilterEvent The EFI_EVENT to signal whenever data that matches
380 FilterClass is logged in the system.
381 @param FilterTpl The maximum EFI_TPL at which FilterEvent can be
382 signaled. It is strongly recommended that you use the
383 lowest EFI_TPL possible.
384 @param FilterClass FilterEvent will be signaled whenever a bit in
385 EFI_DATA_RECORD_HEADER.DataRecordClass is also set in
386 FilterClass. If FilterClass is zero, no class-based
387 filtering will be performed.
388 @param FilterDataRecordGuid FilterEvent will be signaled whenever FilterDataRecordGuid
389 matches EFI_DATA_RECORD_HEADER.DataRecordGuid. If
390 FilterDataRecordGuid is NULL, then no GUID-based filtering
393 @retval EFI_SUCCESS The filter driver event was registered.
394 @retval EFI_ALREADY_STARTED FilterEvent was previously registered and cannot be
396 @retval EFI_OUT_OF_RESOURCES The filter driver event was not registered due to lack of
402 DataHubRegisterFilterDriver (
403 IN EFI_DATA_HUB_PROTOCOL
* This
,
404 IN EFI_EVENT FilterEvent
,
405 IN EFI_TPL FilterTpl
,
406 IN UINT64 FilterClass
,
407 IN EFI_GUID
* FilterDataRecordGuid OPTIONAL
411 DATA_HUB_INSTANCE
*Private
;
412 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
414 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
416 FilterDriver
= (DATA_HUB_FILTER_DRIVER
*) AllocateZeroPool (sizeof (DATA_HUB_FILTER_DRIVER
));
417 if (FilterDriver
== NULL
) {
418 return EFI_OUT_OF_RESOURCES
;
421 // Initialize filter driver info
423 FilterDriver
->Signature
= EFI_DATA_HUB_FILTER_DRIVER_SIGNATURE
;
424 FilterDriver
->Event
= FilterEvent
;
425 FilterDriver
->Tpl
= FilterTpl
;
426 FilterDriver
->GetNextMonotonicCount
= 0;
427 if (FilterClass
== 0) {
428 FilterDriver
->ClassFilter
= EFI_DATA_RECORD_CLASS_DEBUG
|
429 EFI_DATA_RECORD_CLASS_ERROR
|
430 EFI_DATA_RECORD_CLASS_DATA
|
431 EFI_DATA_RECORD_CLASS_PROGRESS_CODE
;
433 FilterDriver
->ClassFilter
= FilterClass
;
436 if (FilterDataRecordGuid
!= NULL
) {
437 CopyMem (&FilterDriver
->FilterDataRecordGuid
, FilterDataRecordGuid
, sizeof (EFI_GUID
));
440 // Search for duplicate entries
442 if (FindFilterDriverByEvent (&Private
->FilterDriverListHead
, FilterEvent
) != NULL
) {
443 FreePool (FilterDriver
);
444 return EFI_ALREADY_STARTED
;
447 // Make insertion an atomic operation with the lock.
449 EfiAcquireLock (&Private
->DataLock
);
450 InsertTailList (&Private
->FilterDriverListHead
, &FilterDriver
->Link
);
451 EfiReleaseLock (&Private
->DataLock
);
454 // Signal the Filter driver we just loaded so they will recieve all the
455 // previous history. If we did not signal here we would have to wait until
456 // the next data was logged to get the history. In a case where no next
457 // data was logged we would never get synced up.
459 gBS
->SignalEvent (FilterEvent
);
465 Remove a Filter Driver, so it no longer gets called when data
466 information is logged.
468 @param This Protocol instance structure
470 @param FilterEvent Event that represents a filter driver that is to be
473 @retval EFI_SUCCESS If FilterEvent was unregistered
474 @retval EFI_NOT_FOUND If FilterEvent does not exist
478 DataHubUnregisterFilterDriver (
479 IN EFI_DATA_HUB_PROTOCOL
*This
,
480 IN EFI_EVENT FilterEvent
483 DATA_HUB_INSTANCE
*Private
;
484 DATA_HUB_FILTER_DRIVER
*FilterDriver
;
486 Private
= DATA_HUB_INSTANCE_FROM_THIS (This
);
489 // Search for duplicate entries
491 FilterDriver
= FindFilterDriverByEvent (
492 &Private
->FilterDriverListHead
,
495 if (FilterDriver
== NULL
) {
496 return EFI_NOT_FOUND
;
499 // Make removal an atomic operation with the lock
501 EfiAcquireLock (&Private
->DataLock
);
502 RemoveEntryList (&FilterDriver
->Link
);
503 EfiReleaseLock (&Private
->DataLock
);
511 Driver's Entry point routine that install Driver to produce Data Hub protocol.
513 @param ImageHandle Module's image handle
514 @param SystemTable Pointer of EFI_SYSTEM_TABLE
516 @retval EFI_SUCCESS Logging Hub protocol installed
517 @retval Other No protocol installed, unload driver.
523 IN EFI_HANDLE ImageHandle
,
524 IN EFI_SYSTEM_TABLE
*SystemTable
528 UINT32 HighMontonicCount
;
530 mPrivateData
.Signature
= DATA_HUB_INSTANCE_SIGNATURE
;
531 mPrivateData
.DataHub
.LogData
= DataHubLogData
;
532 mPrivateData
.DataHub
.GetNextRecord
= DataHubGetNextRecord
;
533 mPrivateData
.DataHub
.RegisterFilterDriver
= DataHubRegisterFilterDriver
;
534 mPrivateData
.DataHub
.UnregisterFilterDriver
= DataHubUnregisterFilterDriver
;
537 // Initialize Private Data in CORE_LOGGING_HUB_INSTANCE that is
538 // required by this protocol
540 InitializeListHead (&mPrivateData
.DataListHead
);
541 InitializeListHead (&mPrivateData
.FilterDriverListHead
);
543 EfiInitializeLock (&mPrivateData
.DataLock
, TPL_NOTIFY
);
546 // Make sure we get a bigger MTC number on every boot!
548 Status
= gRT
->GetNextHighMonotonicCount (&HighMontonicCount
);
549 if (EFI_ERROR (Status
)) {
551 // if system service fails pick a sane value.
553 mPrivateData
.GlobalMonotonicCount
= 0;
555 mPrivateData
.GlobalMonotonicCount
= LShiftU64 ((UINT64
) HighMontonicCount
, 32);
558 // Make a new handle and install the protocol
560 mPrivateData
.Handle
= NULL
;
561 Status
= gBS
->InstallProtocolInterface (
562 &mPrivateData
.Handle
,
563 &gEfiDataHubProtocolGuid
,
564 EFI_NATIVE_INTERFACE
,
565 &mPrivateData
.DataHub