2 This is service binding for Hash driver.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_SERVICE_BINDING_PROTOCOL mHash2ServiceBindingProtocol
= {
18 Hash2ServiceBindingCreateChild
,
19 Hash2ServiceBindingDestroyChild
23 Creates a child handle with a set of I/O services.
25 @param[in] This Protocol instance pointer.
26 @param[in, out] ChildHandle Pointer to the handle of the child to create. If
27 it is NULL, then a new handle is created. If
28 it is not NULL, then the I/O services are added
29 to the existing child handle.
31 @retval EFI_SUCCES The protocol was added to ChildHandle.
32 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
33 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
35 @retval Others The child handle was not created.
40 Hash2ServiceBindingCreateChild (
41 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
42 IN OUT EFI_HANDLE
*ChildHandle
46 HASH2_SERVICE_DATA
*Hash2ServiceData
;
47 HASH2_INSTANCE_DATA
*Instance
;
50 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
51 return EFI_INVALID_PARAMETER
;
54 Hash2ServiceData
= HASH2_SERVICE_DATA_FROM_THIS (This
);
57 // Allocate buffer for the new instance.
59 Instance
= AllocateZeroPool (sizeof (HASH2_INSTANCE_DATA
));
60 if (Instance
== NULL
) {
61 return EFI_OUT_OF_RESOURCES
;
65 // Init the instance data.
67 Instance
->Signature
= HASH2_INSTANCE_DATA_SIGNATURE
;
68 CopyMem (&Instance
->Hash2Protocol
, &mHash2Protocol
, sizeof (Instance
->Hash2Protocol
));
69 Instance
->Hash2ServiceData
= Hash2ServiceData
;
71 Status
= gBS
->InstallMultipleProtocolInterfaces (
73 &gEfiHash2ProtocolGuid
,
74 &Instance
->Hash2Protocol
,
77 if (EFI_ERROR (Status
)) {
82 Instance
->Handle
= *ChildHandle
;
85 // Add the child instance into ChildrenList.
87 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
89 InsertTailList (&Hash2ServiceData
->ChildrenList
, &Instance
->InstEntry
);
91 gBS
->RestoreTPL (OldTpl
);
98 Destroys a child handle with a set of I/O services.
100 The DestroyChild() function does the opposite of CreateChild(). It removes a
101 protocol that was installed by CreateChild() from ChildHandle. If the removed
102 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.
104 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL
106 @param[in] ChildHandle Handle of the child to destroy.
108 @retval EFI_SUCCES The protocol was removed from ChildHandle.
109 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that
111 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
112 @retval EFI_ACCESS_DENIED The protocol could not be removed from the
113 ChildHandle because its services are being
115 @retval Others The child handle was not destroyed.
120 Hash2ServiceBindingDestroyChild (
121 IN EFI_SERVICE_BINDING_PROTOCOL
*This
,
122 IN EFI_HANDLE ChildHandle
126 HASH2_SERVICE_DATA
*Hash2ServiceData
;
127 EFI_HASH2_PROTOCOL
*Hash2Protocol
;
128 HASH2_INSTANCE_DATA
*Instance
;
132 if ((This
== NULL
) || (ChildHandle
== NULL
)) {
133 return EFI_INVALID_PARAMETER
;
136 Hash2ServiceData
= HASH2_SERVICE_DATA_FROM_THIS (This
);
139 // Check if this ChildHandle is valid
142 for(Entry
= (&Hash2ServiceData
->ChildrenList
)->ForwardLink
; Entry
!= (&Hash2ServiceData
->ChildrenList
); Entry
= Entry
->ForwardLink
) {
143 Instance
= HASH2_INSTANCE_DATA_FROM_LINK (Entry
);
144 if (Instance
->Handle
== ChildHandle
) {
150 if (Instance
== NULL
) {
151 DEBUG ((EFI_D_ERROR
, "Hash2ServiceBindingDestroyChild - Invalid handle\n"));
152 return EFI_UNSUPPORTED
;
158 Status
= gBS
->HandleProtocol (
160 &gEfiHash2ProtocolGuid
,
161 (VOID
**)&Hash2Protocol
163 if (EFI_ERROR (Status
)) {
167 ASSERT (Hash2Protocol
== &Instance
->Hash2Protocol
);
170 // Uninstall the Hash protocol.
172 Status
= gBS
->UninstallMultipleProtocolInterfaces (
174 &gEfiHash2ProtocolGuid
,
175 &Instance
->Hash2Protocol
,
178 if (EFI_ERROR (Status
)) {
182 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
185 // Remove this instance from the ChildrenList.
187 RemoveEntryList (&Instance
->InstEntry
);
189 gBS
->RestoreTPL (OldTpl
);
197 The entry point for Hash driver which installs the service binding protocol.
199 @param[in] ImageHandle The image handle of the driver.
200 @param[in] SystemTable The system table.
202 @retval EFI_SUCCES The service binding protocols is successfully installed.
203 @retval Others Other errors as indicated.
208 Hash2DriverEntryPoint (
209 IN EFI_HANDLE ImageHandle
,
210 IN EFI_SYSTEM_TABLE
*SystemTable
214 HASH2_SERVICE_DATA
*Hash2ServiceData
;
217 // Initialize the Hash Service Data.
219 Hash2ServiceData
= AllocateZeroPool (sizeof (HASH2_SERVICE_DATA
));
220 if (Hash2ServiceData
== NULL
) {
221 return EFI_OUT_OF_RESOURCES
;
224 Hash2ServiceData
->Signature
= HASH2_SERVICE_DATA_SIGNATURE
;
225 CopyMem (&Hash2ServiceData
->ServiceBinding
, &mHash2ServiceBindingProtocol
, sizeof (EFI_SERVICE_BINDING_PROTOCOL
));
226 InitializeListHead (&Hash2ServiceData
->ChildrenList
);
229 // Install the HASH Service Binding Protocol
231 Status
= gBS
->InstallMultipleProtocolInterfaces (
232 &Hash2ServiceData
->ServiceHandle
,
233 &gEfiHash2ServiceBindingProtocolGuid
,
234 &Hash2ServiceData
->ServiceBinding
,
237 if (EFI_ERROR (Status
)) {
238 FreePool (Hash2ServiceData
);