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