3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Data Hub filter driver that takes DEBUG () info from Data Hub and writes it
19 to StdErr if it exists.
25 EFI_DATA_HUB_PROTOCOL
*mDataHub
= NULL
;
27 EFI_EVENT mDataHubStdErrEvent
;
32 DataHubStdErrEventHandler (
39 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
40 handler reads the Data Hub and sends any DEBUG info to StdErr.
43 Event - The event that occured, not used
44 Context - DataHub Protocol Pointer
52 EFI_DATA_HUB_PROTOCOL
*DataHub
;
53 EFI_DATA_RECORD_HEADER
*Record
;
54 DATA_HUB_STATUS_CODE_DATA_RECORD
*DataRecord
;
56 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
;
59 DataHub
= (EFI_DATA_HUB_PROTOCOL
*) Context
;
62 // If StdErr is not yet initialized just return a DEBUG print in the BDS
63 // after consoles are connect will make sure data gets flushed properly
64 // when StdErr is availible.
70 if (gST
->StdErr
== NULL
) {
74 // Mtc of zero means return the next record that has not been read by the
79 Status
= DataHub
->GetNextRecord (DataHub
, &Mtc
, &mDataHubStdErrEvent
, &Record
);
80 if (!EFI_ERROR (Status
)) {
81 if (CompareGuid (&Record
->DataRecordGuid
, &gEfiStatusCodeGuid
)) {
82 DataRecord
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (((CHAR8
*) Record
) + Record
->HeaderSize
);
84 if (DataRecord
->Data
.HeaderSize
> 0) {
85 if (CompareGuid (&DataRecord
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
87 // If the Data record is from a DEBUG () then send it to Standard Error
90 OldAttribute
= Sto
->Mode
->Attribute
;
91 Sto
->SetAttribute (Sto
, EFI_TEXT_ATTR (EFI_MAGENTA
, EFI_BLACK
));
92 Sto
->OutputString (Sto
, (CHAR16
*) (DataRecord
+ 1));
93 Sto
->SetAttribute (Sto
, OldAttribute
);
98 } while ((Mtc
!= 0) && !EFI_ERROR (Status
));
103 DataHubStdErrInitialize (
104 IN EFI_HANDLE ImageHandle
,
105 IN EFI_SYSTEM_TABLE
*SystemTable
111 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
112 handler reads the Data Hub and sends any DEBUG info to StdErr.
116 ImageHandle - Image handle of this driver.
117 SystemTable - Pointer to EFI system table.
121 EFI_SUCCESS - The event handler was registered.
122 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
130 gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**) &mDataHub
);
132 // Should never fail due to Depex grammer.
134 ASSERT (mDataHub
!= NULL
);
137 // Create an event and register it with the filter driver
139 Status
= gBS
->CreateEvent (
140 EFI_EVENT_NOTIFY_SIGNAL
,
142 DataHubStdErrEventHandler
,
146 if (EFI_ERROR (Status
)) {
150 DataClass
= EFI_DATA_RECORD_CLASS_DEBUG
| EFI_DATA_RECORD_CLASS_ERROR
;
151 Status
= mDataHub
->RegisterFilterDriver (
158 if (EFI_ERROR (Status
)) {
159 gBS
->CloseEvent (mDataHubStdErrEvent
);