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 // The package level header files this module uses
27 #include <Common/FrameworkStatusCode.h>
29 // The protocols, PPI and GUID defintions for this module
31 #include <Guid/StatusCode.h>
32 #include <Guid/StatusCodeDataTypeId.h>
33 #include <Protocol/DataHub.h>
34 #include <Protocol/SimpleTextOut.h>
36 // The Library classes this module consumes
38 #include <Library/DebugLib.h>
39 #include <Library/UefiDriverEntryPoint.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
43 EFI_DATA_HUB_PROTOCOL
*mDataHub
= NULL
;
45 EFI_EVENT mDataHubStdErrEvent
;
50 DataHubStdErrEventHandler (
57 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
58 handler reads the Data Hub and sends any DEBUG info to StdErr.
61 Event - The event that occured, not used
62 Context - DataHub Protocol Pointer
70 EFI_DATA_HUB_PROTOCOL
*DataHub
;
71 EFI_DATA_RECORD_HEADER
*Record
;
72 DATA_HUB_STATUS_CODE_DATA_RECORD
*DataRecord
;
74 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Sto
;
77 DataHub
= (EFI_DATA_HUB_PROTOCOL
*) Context
;
80 // If StdErr is not yet initialized just return a DEBUG print in the BDS
81 // after consoles are connect will make sure data gets flushed properly
82 // when StdErr is availible.
88 if (gST
->StdErr
== NULL
) {
92 // Mtc of zero means return the next record that has not been read by the
97 Status
= DataHub
->GetNextRecord (DataHub
, &Mtc
, &mDataHubStdErrEvent
, &Record
);
98 if (!EFI_ERROR (Status
)) {
99 if (CompareGuid (&Record
->DataRecordGuid
, &gEfiStatusCodeGuid
)) {
100 DataRecord
= (DATA_HUB_STATUS_CODE_DATA_RECORD
*) (((CHAR8
*) Record
) + Record
->HeaderSize
);
102 if (DataRecord
->Data
.HeaderSize
> 0) {
103 if (CompareGuid (&DataRecord
->Data
.Type
, &gEfiStatusCodeDataTypeDebugGuid
)) {
105 // If the Data record is from a DEBUG () then send it to Standard Error
108 OldAttribute
= Sto
->Mode
->Attribute
;
109 Sto
->SetAttribute (Sto
, EFI_TEXT_ATTR (EFI_MAGENTA
, EFI_BLACK
));
110 Sto
->OutputString (Sto
, (CHAR16
*) (DataRecord
+ 1));
111 Sto
->SetAttribute (Sto
, OldAttribute
);
116 } while ((Mtc
!= 0) && !EFI_ERROR (Status
));
121 DataHubStdErrInitialize (
122 IN EFI_HANDLE ImageHandle
,
123 IN EFI_SYSTEM_TABLE
*SystemTable
129 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
130 handler reads the Data Hub and sends any DEBUG info to StdErr.
134 ImageHandle - Image handle of this driver.
135 SystemTable - Pointer to EFI system table.
139 EFI_SUCCESS - The event handler was registered.
140 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
148 gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**) &mDataHub
);
150 // Should never fail due to Depex grammer.
152 ASSERT (mDataHub
!= NULL
);
155 // Create an event and register it with the filter driver
157 Status
= gBS
->CreateEvent (
160 DataHubStdErrEventHandler
,
164 if (EFI_ERROR (Status
)) {
168 DataClass
= EFI_DATA_RECORD_CLASS_DEBUG
| EFI_DATA_RECORD_CLASS_ERROR
;
169 Status
= mDataHub
->RegisterFilterDriver (
176 if (EFI_ERROR (Status
)) {
177 gBS
->CloseEvent (mDataHubStdErrEvent
);