]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/DataHub/DataHubStdErr/Dxe/DataHubStdErr.c
Corrected uses of IntelFrameworkPkg header files.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / DataHub / DataHubStdErr / Dxe / DataHubStdErr.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 DataHubStdErr.c
15
16 Abstract:
17
18 Data Hub filter driver that takes DEBUG () info from Data Hub and writes it
19 to StdErr if it exists.
20
21 --*/
22
23 //
24 // The package level header files this module uses
25 //
26 #include <FrameworkDxe.h>
27
28 //
29 // The protocols, PPI and GUID defintions for this module
30 //
31 #include <Guid/StatusCode.h>
32 #include <Guid/StatusCodeDataTypeId.h>
33 #include <Protocol/DataHub.h>
34 #include <Protocol/SimpleTextOut.h>
35 //
36 // The Library classes this module consumes
37 //
38 #include <Library/DebugLib.h>
39 #include <Library/UefiDriverEntryPoint.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
42
43 EFI_DATA_HUB_PROTOCOL *mDataHub = NULL;
44
45 EFI_EVENT mDataHubStdErrEvent;
46
47 STATIC
48 VOID
49 EFIAPI
50 DataHubStdErrEventHandler (
51 IN EFI_EVENT Event,
52 IN VOID *Context
53 )
54 /*++
55
56 Routine Description:
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.
59
60 Arguments:
61 Event - The event that occured, not used
62 Context - DataHub Protocol Pointer
63
64 Returns:
65 None.
66
67 --*/
68 {
69 EFI_STATUS Status;
70 EFI_DATA_HUB_PROTOCOL *DataHub;
71 EFI_DATA_RECORD_HEADER *Record;
72 DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;
73 UINT64 Mtc;
74 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
75 INT32 OldAttribute;
76
77 DataHub = (EFI_DATA_HUB_PROTOCOL *) Context;
78
79 //
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.
83 //
84 if (gST == NULL) {
85 return ;
86 }
87
88 if (gST->StdErr == NULL) {
89 return ;
90 }
91 //
92 // Mtc of zero means return the next record that has not been read by the
93 // event handler.
94 //
95 Mtc = 0;
96 do {
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);
101
102 if (DataRecord->Data.HeaderSize > 0) {
103 if (CompareGuid (&DataRecord->Data.Type, &gEfiStatusCodeDataTypeDebugGuid)) {
104 //
105 // If the Data record is from a DEBUG () then send it to Standard Error
106 //
107 Sto = gST->StdErr;
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);
112 }
113 }
114 }
115 }
116 } while ((Mtc != 0) && !EFI_ERROR (Status));
117 }
118
119 EFI_STATUS
120 EFIAPI
121 DataHubStdErrInitialize (
122 IN EFI_HANDLE ImageHandle,
123 IN EFI_SYSTEM_TABLE *SystemTable
124 )
125 /*++
126
127 Routine Description:
128
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.
131
132 Arguments:
133
134 ImageHandle - Image handle of this driver.
135 SystemTable - Pointer to EFI system table.
136
137 Returns:
138
139 EFI_SUCCESS - The event handler was registered.
140 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
141 system resources.
142
143 --*/
144 {
145 EFI_STATUS Status;
146 UINT64 DataClass;
147
148 gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID **) &mDataHub);
149 //
150 // Should never fail due to Depex grammer.
151 //
152 ASSERT (mDataHub != NULL);
153
154 //
155 // Create an event and register it with the filter driver
156 //
157 Status = gBS->CreateEvent (
158 EVT_NOTIFY_SIGNAL,
159 TPL_CALLBACK,
160 DataHubStdErrEventHandler,
161 mDataHub,
162 &mDataHubStdErrEvent
163 );
164 if (EFI_ERROR (Status)) {
165 return Status;
166 }
167
168 DataClass = EFI_DATA_RECORD_CLASS_DEBUG | EFI_DATA_RECORD_CLASS_ERROR;
169 Status = mDataHub->RegisterFilterDriver (
170 mDataHub,
171 mDataHubStdErrEvent,
172 TPL_CALLBACK,
173 DataClass,
174 NULL
175 );
176 if (EFI_ERROR (Status)) {
177 gBS->CloseEvent (mDataHubStdErrEvent);
178 }
179
180 return Status;
181 }