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