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