2 Data Hub filter driver that takes DEBUG () info from Data Hub and writes it
3 to StdErr if it exists.
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. 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.
17 #include <FrameworkDxe.h>
20 #include <Guid/DataHubStatusCodeRecord.h>
21 #include <Guid/StatusCodeDataTypeId.h>
22 #include <Protocol/DataHub.h>
23 #include <Protocol/SimpleTextOut.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
30 EFI_DATA_HUB_PROTOCOL
*mDataHub
= NULL
;
32 EFI_EVENT mDataHubStdErrEvent
;
37 DataHubStdErrEventHandler (
44 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
45 handler reads the Data Hub and sends any DEBUG info to StdErr.
48 Event - The event that occured, not used
49 Context - DataHub Protocol Pointer
57 EFI_DATA_HUB_PROTOCOL
*DataHub
;
58 EFI_DATA_RECORD_HEADER
*Record
;
59 DATA_HUB_STATUS_CODE_DATA_RECORD
*DataRecord
;
61 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Sto
;
64 DataHub
= (EFI_DATA_HUB_PROTOCOL
*) Context
;
67 // If StdErr is not yet initialized just return a DEBUG print in the BDS
68 // after consoles are connect will make sure data gets flushed properly
69 // when StdErr is availible.
75 if (gST
->StdErr
== NULL
) {
79 // Mtc of zero means return the next record that has not been read by the
84 Status
= DataHub
->GetNextRecord (DataHub
, &Mtc
, &mDataHubStdErrEvent
, &Record
);
85 if (!EFI_ERROR (Status
)) {
86 if (CompareGuid (&Record
->DataRecordGuid
, &gEfiDataHubStatusCodeRecordGuid
)) {
87 DataRecord
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (((CHAR8
*) Record
) + Record
->HeaderSize
);
89 if (DataRecord
->Data
.HeaderSize
> 0) {
90 if (CompareGuid (&DataRecord
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
92 // If the Data record is from a DEBUG () then send it to Standard Error
95 OldAttribute
= Sto
->Mode
->Attribute
;
96 Sto
->SetAttribute (Sto
, EFI_TEXT_ATTR (EFI_MAGENTA
, EFI_BLACK
));
97 Sto
->OutputString (Sto
, (CHAR16
*) (DataRecord
+ 1));
98 Sto
->SetAttribute (Sto
, OldAttribute
);
103 } while ((Mtc
!= 0) && !EFI_ERROR (Status
));
108 DataHubStdErrInitialize (
109 IN EFI_HANDLE ImageHandle
,
110 IN EFI_SYSTEM_TABLE
*SystemTable
116 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
117 handler reads the Data Hub and sends any DEBUG info to StdErr.
121 ImageHandle - Image handle of this driver.
122 SystemTable - Pointer to EFI system table.
126 EFI_SUCCESS - The event handler was registered.
127 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
135 gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**) &mDataHub
);
137 // Should never fail due to Depex grammer.
139 ASSERT (mDataHub
!= NULL
);
142 // Create an event and register it with the filter driver
144 Status
= gBS
->CreateEvent (
147 DataHubStdErrEventHandler
,
151 if (EFI_ERROR (Status
)) {
155 DataClass
= EFI_DATA_RECORD_CLASS_DEBUG
| EFI_DATA_RECORD_CLASS_ERROR
;
156 Status
= mDataHub
->RegisterFilterDriver (
163 if (EFI_ERROR (Status
)) {
164 gBS
->CloseEvent (mDataHubStdErrEvent
);