]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/DataHub/DataHubStdErr/Dxe/DataHubStdErr.c
Add DataHub & DataHubStdErr modules
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / DataHub / DataHubStdErr / Dxe / DataHubStdErr.c
CommitLineData
83f6d1a0 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 DataHubStdErr.c\r
15\r
16Abstract:\r
17\r
18 Data Hub filter driver that takes DEBUG () info from Data Hub and writes it\r
19 to StdErr if it exists.\r
20\r
21--*/\r
22\r
23//\r
24// The package level header files this module uses\r
25//\r
26#include <PiDxe.h>\r
27#include <Common/FrameworkStatusCode.h>\r
28//\r
29// The protocols, PPI and GUID defintions for this module\r
30//\r
31#include <Guid/StatusCode.h>\r
32#include <Guid/StatusCodeDataTypeId.h>\r
33#include <Protocol/DataHub.h>\r
34#include <Protocol/SimpleTextOut.h>\r
35//\r
36// The Library classes this module consumes\r
37//\r
38#include <Library/DebugLib.h>\r
39#include <Library/UefiDriverEntryPoint.h>\r
40#include <Library/BaseMemoryLib.h>\r
41#include <Library/UefiBootServicesTableLib.h>\r
42\r
43EFI_DATA_HUB_PROTOCOL *mDataHub = NULL;\r
44\r
45EFI_EVENT mDataHubStdErrEvent;\r
46\r
47STATIC\r
48VOID\r
49EFIAPI\r
50DataHubStdErrEventHandler (\r
51 IN EFI_EVENT Event,\r
52 IN VOID *Context\r
53 )\r
54/*++\r
55\r
56Routine Description:\r
57 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This\r
58 handler reads the Data Hub and sends any DEBUG info to StdErr.\r
59\r
60Arguments:\r
61 Event - The event that occured, not used\r
62 Context - DataHub Protocol Pointer\r
63\r
64Returns:\r
65 None.\r
66\r
67--*/\r
68{\r
69 EFI_STATUS Status;\r
70 EFI_DATA_HUB_PROTOCOL *DataHub;\r
71 EFI_DATA_RECORD_HEADER *Record;\r
72 DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;\r
73 UINT64 Mtc;\r
74 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;\r
75 INT32 OldAttribute;\r
76\r
77 DataHub = (EFI_DATA_HUB_PROTOCOL *) Context;\r
78\r
79 //\r
80 // If StdErr is not yet initialized just return a DEBUG print in the BDS\r
81 // after consoles are connect will make sure data gets flushed properly\r
82 // when StdErr is availible.\r
83 //\r
84 if (gST == NULL) {\r
85 return ;\r
86 }\r
87\r
88 if (gST->StdErr == NULL) {\r
89 return ;\r
90 }\r
91 //\r
92 // Mtc of zero means return the next record that has not been read by the\r
93 // event handler.\r
94 //\r
95 Mtc = 0;\r
96 do {\r
97 Status = DataHub->GetNextRecord (DataHub, &Mtc, &mDataHubStdErrEvent, &Record);\r
98 if (!EFI_ERROR (Status)) {\r
99 if (CompareGuid (&Record->DataRecordGuid, &gEfiStatusCodeGuid)) {\r
100 DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (((CHAR8 *) Record) + Record->HeaderSize);\r
101\r
102 if (DataRecord->Data.HeaderSize > 0) {\r
103 if (CompareGuid (&DataRecord->Data.Type, &gEfiStatusCodeDataTypeDebugGuid)) {\r
104 //\r
105 // If the Data record is from a DEBUG () then send it to Standard Error\r
106 //\r
107 Sto = gST->StdErr;\r
108 OldAttribute = Sto->Mode->Attribute;\r
109 Sto->SetAttribute (Sto, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));\r
110 Sto->OutputString (Sto, (CHAR16 *) (DataRecord + 1));\r
111 Sto->SetAttribute (Sto, OldAttribute);\r
112 }\r
113 }\r
114 }\r
115 }\r
116 } while ((Mtc != 0) && !EFI_ERROR (Status));\r
117}\r
118\r
119EFI_STATUS\r
120EFIAPI\r
121DataHubStdErrInitialize (\r
122 IN EFI_HANDLE ImageHandle,\r
123 IN EFI_SYSTEM_TABLE *SystemTable\r
124 )\r
125/*++\r
126\r
127Routine Description:\r
128\r
129 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This\r
130 handler reads the Data Hub and sends any DEBUG info to StdErr.\r
131\r
132Arguments:\r
133\r
134 ImageHandle - Image handle of this driver.\r
135 SystemTable - Pointer to EFI system table.\r
136\r
137Returns:\r
138\r
139 EFI_SUCCESS - The event handler was registered.\r
140 EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of\r
141 system resources.\r
142\r
143--*/\r
144{\r
145 EFI_STATUS Status;\r
146 UINT64 DataClass;\r
147\r
148 gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID **) &mDataHub);\r
149 //\r
150 // Should never fail due to Depex grammer.\r
151 //\r
152 ASSERT (mDataHub != NULL);\r
153\r
154 //\r
155 // Create an event and register it with the filter driver\r
156 //\r
157 Status = gBS->CreateEvent (\r
158 EVT_NOTIFY_SIGNAL,\r
159 TPL_CALLBACK,\r
160 DataHubStdErrEventHandler,\r
161 mDataHub,\r
162 &mDataHubStdErrEvent\r
163 );\r
164 if (EFI_ERROR (Status)) {\r
165 return Status;\r
166 }\r
167\r
168 DataClass = EFI_DATA_RECORD_CLASS_DEBUG | EFI_DATA_RECORD_CLASS_ERROR;\r
169 Status = mDataHub->RegisterFilterDriver (\r
170 mDataHub,\r
171 mDataHubStdErrEvent,\r
172 TPL_CALLBACK,\r
173 DataClass,\r
174 NULL\r
175 );\r
176 if (EFI_ERROR (Status)) {\r
177 gBS->CloseEvent (mDataHubStdErrEvent);\r
178 }\r
179\r
180 return Status;\r
181}\r