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