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