]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/DataHubStdErrDxe/DataHubStdErr.c
Correct all header files for doxygen format and correct the license issue for VgaClas...
[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 STATIC
35 VOID
36 EFIAPI
37 DataHubStdErrEventHandler (
38 IN EFI_EVENT Event,
39 IN VOID *Context
40 )
41 /*++
42
43 Routine Description:
44 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
45 handler reads the Data Hub and sends any DEBUG info to StdErr.
46
47 Arguments:
48 Event - The event that occured, not used
49 Context - DataHub Protocol Pointer
50
51 Returns:
52 None.
53
54 --*/
55 {
56 EFI_STATUS Status;
57 EFI_DATA_HUB_PROTOCOL *DataHub;
58 EFI_DATA_RECORD_HEADER *Record;
59 DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;
60 UINT64 Mtc;
61 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
62 INT32 OldAttribute;
63
64 DataHub = (EFI_DATA_HUB_PROTOCOL *) Context;
65
66 //
67 // If StdErr is not yet initialized just return a DEBUG print in the BDS
68 // after consoles are connect will make sure data gets flushed properly
69 // when StdErr is availible.
70 //
71 if (gST == NULL) {
72 return ;
73 }
74
75 if (gST->StdErr == NULL) {
76 return ;
77 }
78 //
79 // Mtc of zero means return the next record that has not been read by the
80 // event handler.
81 //
82 Mtc = 0;
83 do {
84 Status = DataHub->GetNextRecord (DataHub, &Mtc, &mDataHubStdErrEvent, &Record);
85 if (!EFI_ERROR (Status)) {
86 if (CompareGuid (&Record->DataRecordGuid, &gEfiDataHubStatusCodeRecordGuid)) {
87 DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (((CHAR8 *) Record) + Record->HeaderSize);
88
89 if (DataRecord->Data.HeaderSize > 0) {
90 if (CompareGuid (&DataRecord->Data.Type, &gEfiStatusCodeDataTypeDebugGuid)) {
91 //
92 // If the Data record is from a DEBUG () then send it to Standard Error
93 //
94 Sto = gST->StdErr;
95 OldAttribute = Sto->Mode->Attribute;
96 Sto->SetAttribute (Sto, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
97 Sto->OutputString (Sto, (CHAR16 *) (DataRecord + 1));
98 Sto->SetAttribute (Sto, OldAttribute);
99 }
100 }
101 }
102 }
103 } while ((Mtc != 0) && !EFI_ERROR (Status));
104 }
105
106 EFI_STATUS
107 EFIAPI
108 DataHubStdErrInitialize (
109 IN EFI_HANDLE ImageHandle,
110 IN EFI_SYSTEM_TABLE *SystemTable
111 )
112 /*++
113
114 Routine Description:
115
116 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
117 handler reads the Data Hub and sends any DEBUG info to StdErr.
118
119 Arguments:
120
121 ImageHandle - Image handle of this driver.
122 SystemTable - Pointer to EFI system table.
123
124 Returns:
125
126 EFI_SUCCESS - The event handler was registered.
127 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
128 system resources.
129
130 --*/
131 {
132 EFI_STATUS Status;
133 UINT64 DataClass;
134
135 gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID **) &mDataHub);
136 //
137 // Should never fail due to Depex grammer.
138 //
139 ASSERT (mDataHub != NULL);
140
141 //
142 // Create an event and register it with the filter driver
143 //
144 Status = gBS->CreateEvent (
145 EVT_NOTIFY_SIGNAL,
146 TPL_CALLBACK,
147 DataHubStdErrEventHandler,
148 mDataHub,
149 &mDataHubStdErrEvent
150 );
151 if (EFI_ERROR (Status)) {
152 return Status;
153 }
154
155 DataClass = EFI_DATA_RECORD_CLASS_DEBUG | EFI_DATA_RECORD_CLASS_ERROR;
156 Status = mDataHub->RegisterFilterDriver (
157 mDataHub,
158 mDataHubStdErrEvent,
159 TPL_CALLBACK,
160 DataClass,
161 NULL
162 );
163 if (EFI_ERROR (Status)) {
164 gBS->CloseEvent (mDataHubStdErrEvent);
165 }
166
167 return Status;
168 }