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