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 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <FrameworkDxe.h>
11 #include <Guid/DataHubStatusCodeRecord.h>
12 #include <Guid/StatusCodeDataTypeId.h>
13 #include <Guid/StatusCodeDataTypeDebug.h>
14 #include <Protocol/DataHub.h>
15 #include <Protocol/SimpleTextOut.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiDriverEntryPoint.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
22 EFI_DATA_HUB_PROTOCOL
*mDataHub
= NULL
;
24 EFI_EVENT mDataHubStdErrEvent
;
27 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
28 handler reads the Data Hub and sends any DEBUG info to StdErr.
30 @param Event The event that occured, not used
31 @param Context DataHub Protocol Pointer
35 DataHubStdErrEventHandler (
41 EFI_DATA_HUB_PROTOCOL
*DataHub
;
42 EFI_DATA_RECORD_HEADER
*Record
;
43 DATA_HUB_STATUS_CODE_DATA_RECORD
*DataRecord
;
45 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Sto
;
48 DataHub
= (EFI_DATA_HUB_PROTOCOL
*) Context
;
51 // If StdErr is not yet initialized just return a DEBUG print in the BDS
52 // after consoles are connect will make sure data gets flushed properly
53 // when StdErr is available.
59 if (gST
->StdErr
== NULL
) {
64 // Mtc of zero means return the next record that has not been read by the
69 Status
= DataHub
->GetNextRecord (DataHub
, &Mtc
, &mDataHubStdErrEvent
, &Record
);
70 if (!EFI_ERROR (Status
)) {
71 if (CompareGuid (&Record
->DataRecordGuid
, &gEfiDataHubStatusCodeRecordGuid
)) {
72 DataRecord
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (((CHAR8
*) Record
) + Record
->HeaderSize
);
74 if (DataRecord
->Data
.HeaderSize
> 0) {
75 if (CompareGuid (&DataRecord
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
77 // If the Data record is from a DEBUG () then send it to Standard Error
80 OldAttribute
= Sto
->Mode
->Attribute
;
81 Sto
->SetAttribute (Sto
, EFI_TEXT_ATTR (EFI_MAGENTA
, EFI_BLACK
));
82 Sto
->OutputString (Sto
, (CHAR16
*) (DataRecord
+ 1));
83 Sto
->SetAttribute (Sto
, OldAttribute
);
88 } while ((Mtc
!= 0) && !EFI_ERROR (Status
));
92 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
93 handler reads the Data Hub and sends any DEBUG info to StdErr.
95 @param ImageHandle Image handle of this driver.
96 @param SystemTable Pointer to EFI system table.
98 @retval EFI_SUCCESS The event handler was registered.
99 @retval EFI_OUT_OF_RESOURCES The event hadler was not registered due to lack of system resources.
103 DataHubStdErrInitialize (
104 IN EFI_HANDLE ImageHandle
,
105 IN EFI_SYSTEM_TABLE
*SystemTable
111 gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**) &mDataHub
);
113 // Should never fail due to Depex grammer.
115 ASSERT (mDataHub
!= NULL
);
118 // Create an event and register it with the filter driver
120 Status
= gBS
->CreateEvent (
123 DataHubStdErrEventHandler
,
127 if (EFI_ERROR (Status
)) {
131 DataClass
= EFI_DATA_RECORD_CLASS_DEBUG
| EFI_DATA_RECORD_CLASS_ERROR
;
132 Status
= mDataHub
->RegisterFilterDriver (
139 if (EFI_ERROR (Status
)) {
140 gBS
->CloseEvent (mDataHubStdErrEvent
);