TianoCore EDK2 master
Loading...
Searching...
No Matches
Driver.c
Go to the documentation of this file.
1
9#include "Driver.h"
10
11EFI_SERVICE_BINDING_PROTOCOL mHash2ServiceBindingProtocol = {
14};
15
33EFIAPI
36 IN OUT EFI_HANDLE *ChildHandle
37 )
38{
39 EFI_STATUS Status;
40 HASH2_SERVICE_DATA *Hash2ServiceData;
41 HASH2_INSTANCE_DATA *Instance;
42 EFI_TPL OldTpl;
43
44 if ((This == NULL) || (ChildHandle == NULL)) {
45 return EFI_INVALID_PARAMETER;
46 }
47
48 Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);
49
50 //
51 // Allocate buffer for the new instance.
52 //
53 Instance = AllocateZeroPool (sizeof (HASH2_INSTANCE_DATA));
54 if (Instance == NULL) {
55 return EFI_OUT_OF_RESOURCES;
56 }
57
58 //
59 // Init the instance data.
60 //
61 Instance->Signature = HASH2_INSTANCE_DATA_SIGNATURE;
62 CopyMem (&Instance->Hash2Protocol, &mHash2Protocol, sizeof (Instance->Hash2Protocol));
63 Instance->Hash2ServiceData = Hash2ServiceData;
64
65 Status = gBS->InstallMultipleProtocolInterfaces (
66 ChildHandle,
67 &gEfiHash2ProtocolGuid,
68 &Instance->Hash2Protocol,
69 NULL
70 );
71 if (EFI_ERROR (Status)) {
72 FreePool (Instance);
73 return Status;
74 }
75
76 Instance->Handle = *ChildHandle;
77
78 //
79 // Add the child instance into ChildrenList.
80 //
81 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
82
83 InsertTailList (&Hash2ServiceData->ChildrenList, &Instance->InstEntry);
84
85 gBS->RestoreTPL (OldTpl);
86
87 return Status;
88}
89
112EFIAPI
115 IN EFI_HANDLE ChildHandle
116 )
117{
118 EFI_STATUS Status;
119 HASH2_SERVICE_DATA *Hash2ServiceData;
120 EFI_HASH2_PROTOCOL *Hash2Protocol;
121 HASH2_INSTANCE_DATA *Instance;
122 EFI_TPL OldTpl;
123 LIST_ENTRY *Entry;
124
125 if ((This == NULL) || (ChildHandle == NULL)) {
126 return EFI_INVALID_PARAMETER;
127 }
128
129 Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);
130
131 //
132 // Check if this ChildHandle is valid
133 //
134 Instance = NULL;
135 for (Entry = (&Hash2ServiceData->ChildrenList)->ForwardLink; Entry != (&Hash2ServiceData->ChildrenList); Entry = Entry->ForwardLink) {
136 Instance = HASH2_INSTANCE_DATA_FROM_LINK (Entry);
137 if (Instance->Handle == ChildHandle) {
138 break;
139 } else {
140 Instance = NULL;
141 }
142 }
143
144 if (Instance == NULL) {
145 DEBUG ((DEBUG_ERROR, "Hash2ServiceBindingDestroyChild - Invalid handle\n"));
146 return EFI_UNSUPPORTED;
147 }
148
149 //
150 // Get HashProtocol
151 //
152 Status = gBS->HandleProtocol (
153 ChildHandle,
154 &gEfiHash2ProtocolGuid,
155 (VOID **)&Hash2Protocol
156 );
157 if (EFI_ERROR (Status)) {
158 return Status;
159 }
160
161 ASSERT (Hash2Protocol == &Instance->Hash2Protocol);
162
163 //
164 // Uninstall the Hash protocol.
165 //
166 Status = gBS->UninstallMultipleProtocolInterfaces (
167 ChildHandle,
168 &gEfiHash2ProtocolGuid,
169 &Instance->Hash2Protocol,
170 NULL
171 );
172 if (EFI_ERROR (Status)) {
173 return Status;
174 }
175
176 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
177
178 //
179 // Remove this instance from the ChildrenList.
180 //
181 RemoveEntryList (&Instance->InstEntry);
182
183 gBS->RestoreTPL (OldTpl);
184
185 FreePool (Instance);
186
187 return Status;
188}
189
201EFIAPI
203 IN EFI_HANDLE ImageHandle,
204 IN EFI_SYSTEM_TABLE *SystemTable
205 )
206{
207 EFI_STATUS Status;
208 HASH2_SERVICE_DATA *Hash2ServiceData;
209
210 //
211 // Initialize the Hash Service Data.
212 //
213 Hash2ServiceData = AllocateZeroPool (sizeof (HASH2_SERVICE_DATA));
214 if (Hash2ServiceData == NULL) {
215 return EFI_OUT_OF_RESOURCES;
216 }
217
218 Hash2ServiceData->Signature = HASH2_SERVICE_DATA_SIGNATURE;
219 CopyMem (&Hash2ServiceData->ServiceBinding, &mHash2ServiceBindingProtocol, sizeof (EFI_SERVICE_BINDING_PROTOCOL));
220 InitializeListHead (&Hash2ServiceData->ChildrenList);
221
222 //
223 // Install the HASH Service Binding Protocol
224 //
225 Status = gBS->InstallMultipleProtocolInterfaces (
226 &Hash2ServiceData->ServiceHandle,
227 &gEfiHash2ServiceBindingProtocolGuid,
228 &Hash2ServiceData->ServiceBinding,
229 NULL
230 );
231 if (EFI_ERROR (Status)) {
232 FreePool (Hash2ServiceData);
233 }
234
235 return Status;
236}
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI Hash2ServiceBindingCreateChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN OUT EFI_HANDLE *ChildHandle)
Definition: Driver.c:34
EFI_STATUS EFIAPI Hash2DriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Driver.c:202
EFI_STATUS EFIAPI Hash2ServiceBindingDestroyChild(IN EFI_SERVICE_BINDING_PROTOCOL *This, IN EFI_HANDLE ChildHandle)
Definition: Driver.c:113
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS