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