2 This is service binding for Hash driver.
4 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 EFI_SERVICE_BINDING_PROTOCOL mHash2ServiceBindingProtocol
= {
12 Hash2ServiceBindingCreateChild
,
13 Hash2ServiceBindingDestroyChild
17 Creates a child handle with a set of I/O services.
19 @param[in] This Protocol instance pointer.
20 @param[in, out] ChildHandle Pointer to the handle of the child to create. If
21 it is NULL, then a new handle is created. If
22 it is not NULL, then the I/O services are added
23 to the existing child handle.
25 @retval EFI_SUCCESS The protocol was added to ChildHandle.
26 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
27 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
29 @retval Others The child handle was not created.
34 Hash2ServiceBindingCreateChild (
35 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
36 IN OUT EFI_HANDLE
*ChildHandle
40 HASH2_SERVICE_DATA
*Hash2ServiceData
;
41 HASH2_INSTANCE_DATA
*Instance
;
44 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
45 return EFI_INVALID_PARAMETER
;
48 Hash2ServiceData
= HASH2_SERVICE_DATA_FROM_THIS (This
);
51 // Allocate buffer for the new instance.
53 Instance
= AllocateZeroPool (sizeof (HASH2_INSTANCE_DATA
));
54 if (Instance
== NULL
) {
55 return EFI_OUT_OF_RESOURCES
;
59 // Init the instance data.
61 Instance
->Signature
= HASH2_INSTANCE_DATA_SIGNATURE
;
62 CopyMem (&Instance
->Hash2Protocol
, &mHash2Protocol
, sizeof (Instance
->Hash2Protocol
));
63 Instance
->Hash2ServiceData
= Hash2ServiceData
;
65 Status
= gBS
->InstallMultipleProtocolInterfaces (
67 &gEfiHash2ProtocolGuid
,
68 &Instance
->Hash2Protocol
,
71 if (EFI_ERROR (Status
)) {
76 Instance
->Handle
= *ChildHandle
;
79 // Add the child instance into ChildrenList.
81 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
83 InsertTailList (&Hash2ServiceData
->ChildrenList
, &Instance
->InstEntry
);
85 gBS
->RestoreTPL (OldTpl
);
92 Destroys a child handle with a set of I/O services.
94 The DestroyChild() function does the opposite of CreateChild(). It removes a
95 protocol that was installed by CreateChild() from ChildHandle. If the removed
96 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.
98 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL
100 @param[in] ChildHandle Handle of the child to destroy.
102 @retval EFI_SUCCESS The protocol was removed from ChildHandle.
103 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that
105 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
106 @retval EFI_ACCESS_DENIED The protocol could not be removed from the
107 ChildHandle because its services are being
109 @retval Others The child handle was not destroyed.
114 Hash2ServiceBindingDestroyChild (
115 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
116 IN EFI_HANDLE ChildHandle
120 HASH2_SERVICE_DATA
*Hash2ServiceData
;
121 EFI_HASH2_PROTOCOL
*Hash2Protocol
;
122 HASH2_INSTANCE_DATA
*Instance
;
126 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
127 return EFI_INVALID_PARAMETER
;
130 Hash2ServiceData
= HASH2_SERVICE_DATA_FROM_THIS (This
);
133 // Check if this ChildHandle is valid
136 for(Entry
= (&Hash2ServiceData
->ChildrenList
)->ForwardLink
; Entry
!= (&Hash2ServiceData
->ChildrenList
); Entry
= Entry
->ForwardLink
) {
137 Instance
= HASH2_INSTANCE_DATA_FROM_LINK (Entry
);
138 if (Instance
->Handle
== ChildHandle
) {
144 if (Instance
== NULL
) {
145 DEBUG ((EFI_D_ERROR
, "Hash2ServiceBindingDestroyChild - Invalid handle\n"));
146 return EFI_UNSUPPORTED
;
152 Status
= gBS
->HandleProtocol (
154 &gEfiHash2ProtocolGuid
,
155 (VOID
**)&Hash2Protocol
157 if (EFI_ERROR (Status
)) {
161 ASSERT (Hash2Protocol
== &Instance
->Hash2Protocol
);
164 // Uninstall the Hash protocol.
166 Status
= gBS
->UninstallMultipleProtocolInterfaces (
168 &gEfiHash2ProtocolGuid
,
169 &Instance
->Hash2Protocol
,
172 if (EFI_ERROR (Status
)) {
176 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
179 // Remove this instance from the ChildrenList.
181 RemoveEntryList (&Instance
->InstEntry
);
183 gBS
->RestoreTPL (OldTpl
);
191 The entry point for Hash driver which installs the service binding protocol.
193 @param[in] ImageHandle The image handle of the driver.
194 @param[in] SystemTable The system table.
196 @retval EFI_SUCCESS The service binding protocols is successfully installed.
197 @retval Others Other errors as indicated.
202 Hash2DriverEntryPoint (
203 IN EFI_HANDLE ImageHandle
,
204 IN EFI_SYSTEM_TABLE
*SystemTable
208 HASH2_SERVICE_DATA
*Hash2ServiceData
;
211 // Initialize the Hash Service Data.
213 Hash2ServiceData
= AllocateZeroPool (sizeof (HASH2_SERVICE_DATA
));
214 if (Hash2ServiceData
== NULL
) {
215 return EFI_OUT_OF_RESOURCES
;
218 Hash2ServiceData
->Signature
= HASH2_SERVICE_DATA_SIGNATURE
;
219 CopyMem (&Hash2ServiceData
->ServiceBinding
, &mHash2ServiceBindingProtocol
, sizeof (EFI_SERVICE_BINDING_PROTOCOL
));
220 InitializeListHead (&Hash2ServiceData
->ChildrenList
);
223 // Install the HASH Service Binding Protocol
225 Status
= gBS
->InstallMultipleProtocolInterfaces (
226 &Hash2ServiceData
->ServiceHandle
,
227 &gEfiHash2ServiceBindingProtocolGuid
,
228 &Hash2ServiceData
->ServiceBinding
,
231 if (EFI_ERROR (Status
)) {
232 FreePool (Hash2ServiceData
);