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