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