]> git.proxmox.com Git - mirror_edk2.git/blob - 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
1 /**@file
2 Data Hub filter driver that takes DEBUG () info from Data Hub and writes it
3 to StdErr if it exists.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include <FrameworkDxe.h>
18
19
20 #include <Guid/DataHubStatusCodeRecord.h>
21 #include <Guid/StatusCodeDataTypeId.h>
22 #include <Guid/StatusCodeDataTypeDebug.h>
23 #include <Protocol/DataHub.h>
24 #include <Protocol/SimpleTextOut.h>
25
26 #include <Library/DebugLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30
31 EFI_DATA_HUB_PROTOCOL *mDataHub = NULL;
32
33 EFI_EVENT mDataHubStdErrEvent;
34
35 /**
36 Event handler registered with the Data Hub to parse EFI_DEBUG_CODE. This
37 handler reads the Data Hub and sends any DEBUG info to StdErr.
38
39 @param Event - The event that occured, not used
40 @param Context - DataHub Protocol Pointer
41 **/
42 VOID
43 EFIAPI
44 DataHubStdErrEventHandler (
45 IN EFI_EVENT Event,
46 IN VOID *Context
47 )
48 {
49 EFI_STATUS Status;
50 EFI_DATA_HUB_PROTOCOL *DataHub;
51 EFI_DATA_RECORD_HEADER *Record;
52 DATA_HUB_STATUS_CODE_DATA_RECORD *DataRecord;
53 UINT64 Mtc;
54 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
55 INT32 OldAttribute;
56
57 DataHub = (EFI_DATA_HUB_PROTOCOL *) Context;
58
59 //
60 // If StdErr is not yet initialized just return a DEBUG print in the BDS
61 // after consoles are connect will make sure data gets flushed properly
62 // when StdErr is availible.
63 //
64 if (gST == NULL) {
65 return ;
66 }
67
68 if (gST->StdErr == NULL) {
69 return ;
70 }
71 //
72 // Mtc of zero means return the next record that has not been read by the
73 // event handler.
74 //
75 Mtc = 0;
76 do {
77 Status = DataHub->GetNextRecord (DataHub, &Mtc, &mDataHubStdErrEvent, &Record);
78 if (!EFI_ERROR (Status)) {
79 if (CompareGuid (&Record->DataRecordGuid, &gEfiDataHubStatusCodeRecordGuid)) {
80 DataRecord = (DATA_HUB_STATUS_CODE_DATA_RECORD *) (((CHAR8 *) Record) + Record->HeaderSize);
81
82 if (DataRecord->Data.HeaderSize > 0) {
83 if (CompareGuid (&DataRecord->Data.Type, &gEfiStatusCodeDataTypeDebugGuid)) {
84 //
85 // If the Data record is from a DEBUG () then send it to Standard Error
86 //
87 Sto = gST->StdErr;
88 OldAttribute = Sto->Mode->Attribute;
89 Sto->SetAttribute (Sto, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
90 Sto->OutputString (Sto, (CHAR16 *) (DataRecord + 1));
91 Sto->SetAttribute (Sto, OldAttribute);
92 }
93 }
94 }
95 }
96 } while ((Mtc != 0) && !EFI_ERROR (Status));
97 }
98
99 /**
100 Register an event handler with the Data Hub to parse EFI_DEBUG_CODE. This
101 handler reads the Data Hub and sends any DEBUG info to StdErr.
102
103 @param ImageHandle - Image handle of this driver.
104 @param SystemTable - Pointer to EFI system table.
105
106 @retval EFI_SUCCESS - The event handler was registered.
107 @retval EFI_OUT_OF_RESOURCES - The event hadler was not registered due to lack of
108 system resources.
109 **/
110 EFI_STATUS
111 EFIAPI
112 DataHubStdErrInitialize (
113 IN EFI_HANDLE ImageHandle,
114 IN EFI_SYSTEM_TABLE *SystemTable
115 )
116 {
117 EFI_STATUS Status;
118 UINT64 DataClass;
119
120 gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID **) &mDataHub);
121 //
122 // Should never fail due to Depex grammer.
123 //
124 ASSERT (mDataHub != NULL);
125
126 //
127 // Create an event and register it with the filter driver
128 //
129 Status = gBS->CreateEvent (
130 EVT_NOTIFY_SIGNAL,
131 TPL_CALLBACK,
132 DataHubStdErrEventHandler,
133 mDataHub,
134 &mDataHubStdErrEvent
135 );
136 if (EFI_ERROR (Status)) {
137 return Status;
138 }
139
140 DataClass = EFI_DATA_RECORD_CLASS_DEBUG | EFI_DATA_RECORD_CLASS_ERROR;
141 Status = mDataHub->RegisterFilterDriver (
142 mDataHub,
143 mDataHubStdErrEvent,
144 TPL_CALLBACK,
145 DataClass,
146 NULL
147 );
148 if (EFI_ERROR (Status)) {
149 gBS->CloseEvent (mDataHubStdErrEvent);
150 }
151
152 return Status;
153 }
154