]>
Commit | Line | Data |
---|---|---|
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 | |
4 | \r | |
5 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
10 | #include <FrameworkDxe.h>\r | |
11 | #include <Guid/DataHubStatusCodeRecord.h>\r | |
12 | #include <Guid/StatusCodeDataTypeId.h>\r | |
13 | #include <Guid/StatusCodeDataTypeDebug.h>\r | |
14 | #include <Protocol/DataHub.h>\r | |
15 | #include <Protocol/SimpleTextOut.h>\r | |
16 | \r | |
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 | |
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 | |
30 | @param Event The event that occured, not used\r | |
31 | @param Context DataHub Protocol Pointer\r | |
32 | **/\r | |
33 | VOID\r | |
34 | EFIAPI\r | |
35 | DataHubStdErrEventHandler (\r | |
36 | IN EFI_EVENT Event,\r | |
37 | IN VOID *Context\r | |
38 | )\r | |
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 | |
53 | // when StdErr is available.\r | |
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 | |
62 | \r | |
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 | |
71 | if (CompareGuid (&Record->DataRecordGuid, &gEfiDataHubStatusCodeRecordGuid)) {\r | |
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 | |
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 | |
95 | @param ImageHandle Image handle of this driver.\r | |
96 | @param SystemTable Pointer to EFI system table.\r | |
97 | \r | |
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 | |
100 | **/\r | |
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 | |
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 | |
145 | \r |