]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/DataHubStdErrDxe/DataHubStdErr.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / DataHubStdErrDxe / DataHubStdErr.c
1 /**@file
2 Data Hub filter driver that takes DEBUG () info from Data Hub and writes it
3 to StdErr if it exists.
4
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
10
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.
13
14 **/
15
16
17 #include <FrameworkDxe.h>
18
19
20 #include <Guid/DataHubStatusCodeRecord.h>
21 #include <Guid/StatusCodeDataTypeId.h>
22 #include <Protocol/DataHub.h>
23 #include <Protocol/SimpleTextOut.h>
24
25 #include <Library/DebugLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29
30 EFI_DATA_HUB_PROTOCOL *mDataHub = NULL;
31
32 EFI_EVENT mDataHubStdErrEvent;
33
34 /**
35 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
36 handler reads the Data Hub and sends any DEBUG info to StdErr.
37
38 @param Event - The event that occured, not used
39 @param Context - DataHub Protocol Pointer
40 **/
41 VOID
42 EFIAPI
43 DataHubStdErrEventHandler (
44 IN EFI_EVENT Event,
45 IN VOID *Context
46 )
47 {
48 EFI_STATUS Status;
49 EFI_DATA_HUB_PROTOCOL *DataHub;
50 EFI_DATA_RECORD_HEADER *Record;
51 DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;
52 UINT64 Mtc;
53 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
54 INT32 OldAttribute;
55
56 DataHub = (EFI_DATA_HUB_PROTOCOL *) Context;
57
58 //
59 // If StdErr is not yet initialized just return a DEBUG print in the BDS
60 // after consoles are connect will make sure data gets flushed properly
61 // when StdErr is availible.
62 //
63 if (gST == NULL) {
64 return ;
65 }
66
67 if (gST->StdErr == NULL) {
68 return ;
69 }
70 //
71 // Mtc of zero means return the next record that has not been read by the
72 // event handler.
73 //
74 Mtc = 0;
75 do {
76 Status = DataHub->GetNextRecord (DataHub, &Mtc, &mDataHubStdErrEvent, &Record);
77 if (!EFI_ERROR (Status)) {
78 if (CompareGuid (&Record->DataRecordGuid, &gEfiDataHubStatusCodeRecordGuid)) {
79 DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (((CHAR8 *) Record) + Record->HeaderSize);
80
81 if (DataRecord->Data.HeaderSize > 0) {
82 if (CompareGuid (&DataRecord->Data.Type, &gEfiStatusCodeDataTypeDebugGuid)) {
83 //
84 // If the Data record is from a DEBUG () then send it to Standard Error
85 //
86 Sto = gST->StdErr;
87 OldAttribute = Sto->Mode->Attribute;
88 Sto->SetAttribute (Sto, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
89 Sto->OutputString (Sto, (CHAR16 *) (DataRecord + 1));
90 Sto->SetAttribute (Sto, OldAttribute);
91 }
92 }
93 }
94 }
95 } while ((Mtc != 0) && !EFI_ERROR (Status));
96 }
97
98 /**
99 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
100 handler reads the Data Hub and sends any DEBUG info to StdErr.
101
102 @param ImageHandle - Image handle of this driver.
103 @param SystemTable - Pointer to EFI system table.
104
105 @retval EFI_SUCCESS - The event handler was registered.
106 @retval EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
107 system resources.
108 **/
109 EFI_STATUS
110 EFIAPI
111 DataHubStdErrInitialize (
112 IN EFI_HANDLE ImageHandle,
113 IN EFI_SYSTEM_TABLE *SystemTable
114 )
115 {
116 EFI_STATUS Status;
117 UINT64 DataClass;
118
119 gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID **) &mDataHub);
120 //
121 // Should never fail due to Depex grammer.
122 //
123 ASSERT (mDataHub != NULL);
124
125 //
126 // Create an event and register it with the filter driver
127 //
128 Status = gBS->CreateEvent (
129 EVT_NOTIFY_SIGNAL,
130 TPL_CALLBACK,
131 DataHubStdErrEventHandler,
132 mDataHub,
133 &mDataHubStdErrEvent
134 );
135 if (EFI_ERROR (Status)) {
136 return Status;
137 }
138
139 DataClass = EFI_DATA_RECORD_CLASS_DEBUG | EFI_DATA_RECORD_CLASS_ERROR;
140 Status = mDataHub->RegisterFilterDriver (
141 mDataHub,
142 mDataHubStdErrEvent,
143 TPL_CALLBACK,
144 DataClass,
145 NULL
146 );
147 if (EFI_ERROR (Status)) {
148 gBS->CloseEvent (mDataHubStdErrEvent);
149 }
150
151 return Status;
152 }
153