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.
24 #include <FrameworkDxe.h>
27 #include <Guid/DataHubStatusCodeRecord.h>
28 #include <Guid/StatusCodeDataTypeId.h>
29 #include <Protocol/DataHub.h>
30 #include <Protocol/SimpleTextOut.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
37 EFI_DATA_HUB_PROTOCOL
*mDataHub
= NULL
;
39 EFI_EVENT mDataHubStdErrEvent
;
44 DataHubStdErrEventHandler (
51 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
52 handler reads the Data Hub and sends any DEBUG info to StdErr.
55 Event - The event that occured, not used
56 Context - DataHub Protocol Pointer
64 EFI_DATA_HUB_PROTOCOL
*DataHub
;
65 EFI_DATA_RECORD_HEADER
*Record
;
66 DATA_HUB_STATUS_CODE_DATA_RECORD
*DataRecord
;
68 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Sto
;
71 DataHub
= (EFI_DATA_HUB_PROTOCOL
*) Context
;
74 // If StdErr is not yet initialized just return a DEBUG print in the BDS
75 // after consoles are connect will make sure data gets flushed properly
76 // when StdErr is availible.
82 if (gST
->StdErr
== NULL
) {
86 // Mtc of zero means return the next record that has not been read by the
91 Status
= DataHub
->GetNextRecord (DataHub
, &Mtc
, &mDataHubStdErrEvent
, &Record
);
92 if (!EFI_ERROR (Status
)) {
93 if (CompareGuid (&Record
->DataRecordGuid
, &gEfiDataHubStatusCodeRecordGuid
)) {
94 DataRecord
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (((CHAR8
*) Record
) + Record
->HeaderSize
);
96 if (DataRecord
->Data
.HeaderSize
> 0) {
97 if (CompareGuid (&DataRecord
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
99 // If the Data record is from a DEBUG () then send it to Standard Error
102 OldAttribute
= Sto
->Mode
->Attribute
;
103 Sto
->SetAttribute (Sto
, EFI_TEXT_ATTR (EFI_MAGENTA
, EFI_BLACK
));
104 Sto
->OutputString (Sto
, (CHAR16
*) (DataRecord
+ 1));
105 Sto
->SetAttribute (Sto
, OldAttribute
);
110 } while ((Mtc
!= 0) && !EFI_ERROR (Status
));
115 DataHubStdErrInitialize (
116 IN EFI_HANDLE ImageHandle
,
117 IN EFI_SYSTEM_TABLE
*SystemTable
123 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
124 handler reads the Data Hub and sends any DEBUG info to StdErr.
128 ImageHandle - Image handle of this driver.
129 SystemTable - Pointer to EFI system table.
133 EFI_SUCCESS - The event handler was registered.
134 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
142 gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**) &mDataHub
);
144 // Should never fail due to Depex grammer.
146 ASSERT (mDataHub
!= NULL
);
149 // Create an event and register it with the filter driver
151 Status
= gBS
->CreateEvent (
154 DataHubStdErrEventHandler
,
158 if (EFI_ERROR (Status
)) {
162 DataClass
= EFI_DATA_RECORD_CLASS_DEBUG
| EFI_DATA_RECORD_CLASS_ERROR
;
163 Status
= mDataHub
->RegisterFilterDriver (
170 if (EFI_ERROR (Status
)) {
171 gBS
->CloseEvent (mDataHubStdErrEvent
);