]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Hash2DxeCrypto/Driver.c
SecurityPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Hash2DxeCrypto / Driver.c
CommitLineData
724dcbb2
JY
1/** @file\r
2 This is service binding for Hash driver.\r
3\r
b3548d32 4Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
289b714b 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
724dcbb2
JY
6\r
7**/\r
8\r
9#include "Driver.h"\r
10\r
11EFI_SERVICE_BINDING_PROTOCOL mHash2ServiceBindingProtocol = {\r
12 Hash2ServiceBindingCreateChild,\r
13 Hash2ServiceBindingDestroyChild\r
14};\r
15\r
16/**\r
17 Creates a child handle with a set of I/O services.\r
18\r
19 @param[in] This Protocol instance pointer.\r
20 @param[in, out] ChildHandle Pointer to the handle of the child to create. If\r
21 it is NULL, then a new handle is created. If\r
22 it is not NULL, then the I/O services are added\r
23 to the existing child handle.\r
24\r
25 @retval EFI_SUCCES The protocol was added to ChildHandle.\r
26 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
7622e594 27 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r
724dcbb2
JY
28 create the child.\r
29 @retval Others The child handle was not created.\r
30\r
31**/\r
32EFI_STATUS\r
33EFIAPI\r
34Hash2ServiceBindingCreateChild (\r
35 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
36 IN OUT EFI_HANDLE *ChildHandle\r
37 )\r
38{\r
39 EFI_STATUS Status;\r
40 HASH2_SERVICE_DATA *Hash2ServiceData;\r
41 HASH2_INSTANCE_DATA *Instance;\r
42 EFI_TPL OldTpl;\r
43\r
44 if ((This == NULL) || (ChildHandle == NULL)) {\r
45 return EFI_INVALID_PARAMETER;\r
46 }\r
47\r
48 Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);\r
49\r
50 //\r
51 // Allocate buffer for the new instance.\r
52 //\r
53 Instance = AllocateZeroPool (sizeof (HASH2_INSTANCE_DATA));\r
54 if (Instance == NULL) {\r
55 return EFI_OUT_OF_RESOURCES;\r
56 }\r
57\r
58 //\r
59 // Init the instance data.\r
60 //\r
61 Instance->Signature = HASH2_INSTANCE_DATA_SIGNATURE;\r
62 CopyMem (&Instance->Hash2Protocol, &mHash2Protocol, sizeof (Instance->Hash2Protocol));\r
63 Instance->Hash2ServiceData = Hash2ServiceData;\r
64\r
65 Status = gBS->InstallMultipleProtocolInterfaces (\r
66 ChildHandle,\r
67 &gEfiHash2ProtocolGuid,\r
68 &Instance->Hash2Protocol,\r
69 NULL\r
70 );\r
71 if (EFI_ERROR (Status)) {\r
72 FreePool (Instance);\r
73 return Status;\r
74 }\r
75\r
76 Instance->Handle = *ChildHandle;\r
77\r
78 //\r
79 // Add the child instance into ChildrenList.\r
80 //\r
81 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
82\r
83 InsertTailList (&Hash2ServiceData->ChildrenList, &Instance->InstEntry);\r
84\r
85 gBS->RestoreTPL (OldTpl);\r
86\r
87 return Status;\r
88}\r
89\r
90\r
91/**\r
92 Destroys a child handle with a set of I/O services.\r
93\r
94 The DestroyChild() function does the opposite of CreateChild(). It removes a\r
95 protocol that was installed by CreateChild() from ChildHandle. If the removed\r
96 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
97\r
98 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
99 instance.\r
100 @param[in] ChildHandle Handle of the child to destroy.\r
101\r
102 @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
103 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that\r
104 is being removed.\r
105 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
106 @retval EFI_ACCESS_DENIED The protocol could not be removed from the\r
107 ChildHandle because its services are being\r
108 used.\r
109 @retval Others The child handle was not destroyed.\r
110\r
111**/\r
112EFI_STATUS\r
113EFIAPI\r
114Hash2ServiceBindingDestroyChild (\r
115 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
116 IN EFI_HANDLE ChildHandle\r
117 )\r
118{\r
119 EFI_STATUS Status;\r
120 HASH2_SERVICE_DATA *Hash2ServiceData;\r
121 EFI_HASH2_PROTOCOL *Hash2Protocol;\r
122 HASH2_INSTANCE_DATA *Instance;\r
123 EFI_TPL OldTpl;\r
124 LIST_ENTRY *Entry;\r
125\r
126 if ((This == NULL) || (ChildHandle == NULL)) {\r
127 return EFI_INVALID_PARAMETER;\r
128 }\r
129\r
130 Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);\r
131\r
132 //\r
133 // Check if this ChildHandle is valid\r
134 //\r
135 Instance = NULL;\r
136 for(Entry = (&Hash2ServiceData->ChildrenList)->ForwardLink; Entry != (&Hash2ServiceData->ChildrenList); Entry = Entry->ForwardLink) {\r
137 Instance = HASH2_INSTANCE_DATA_FROM_LINK (Entry);\r
138 if (Instance->Handle == ChildHandle) {\r
139 break;\r
140 } else {\r
141 Instance = NULL;\r
142 }\r
143 }\r
144 if (Instance == NULL) {\r
145 DEBUG ((EFI_D_ERROR, "Hash2ServiceBindingDestroyChild - Invalid handle\n"));\r
146 return EFI_UNSUPPORTED;\r
147 }\r
148\r
149 //\r
150 // Get HashProtocol\r
151 //\r
152 Status = gBS->HandleProtocol (\r
153 ChildHandle,\r
154 &gEfiHash2ProtocolGuid,\r
155 (VOID **)&Hash2Protocol\r
156 );\r
157 if (EFI_ERROR (Status)) {\r
158 return Status;\r
159 }\r
160\r
161 ASSERT (Hash2Protocol == &Instance->Hash2Protocol);\r
162\r
163 //\r
164 // Uninstall the Hash protocol.\r
165 //\r
166 Status = gBS->UninstallMultipleProtocolInterfaces (\r
167 ChildHandle,\r
168 &gEfiHash2ProtocolGuid,\r
169 &Instance->Hash2Protocol,\r
170 NULL\r
171 );\r
172 if (EFI_ERROR (Status)) {\r
173 return Status;\r
174 }\r
175\r
176 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
177\r
178 //\r
179 // Remove this instance from the ChildrenList.\r
180 //\r
181 RemoveEntryList (&Instance->InstEntry);\r
182\r
183 gBS->RestoreTPL (OldTpl);\r
184\r
185 FreePool (Instance);\r
186\r
187 return Status;\r
188}\r
189\r
190/**\r
191 The entry point for Hash driver which installs the service binding protocol.\r
192\r
193 @param[in] ImageHandle The image handle of the driver.\r
194 @param[in] SystemTable The system table.\r
195\r
196 @retval EFI_SUCCES The service binding protocols is successfully installed.\r
197 @retval Others Other errors as indicated.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202Hash2DriverEntryPoint (\r
203 IN EFI_HANDLE ImageHandle,\r
204 IN EFI_SYSTEM_TABLE *SystemTable\r
205 )\r
206{\r
207 EFI_STATUS Status;\r
208 HASH2_SERVICE_DATA *Hash2ServiceData;\r
209\r
210 //\r
211 // Initialize the Hash Service Data.\r
212 //\r
213 Hash2ServiceData = AllocateZeroPool (sizeof (HASH2_SERVICE_DATA));\r
214 if (Hash2ServiceData == NULL) {\r
215 return EFI_OUT_OF_RESOURCES;\r
216 }\r
217\r
218 Hash2ServiceData->Signature = HASH2_SERVICE_DATA_SIGNATURE;\r
219 CopyMem (&Hash2ServiceData->ServiceBinding, &mHash2ServiceBindingProtocol, sizeof (EFI_SERVICE_BINDING_PROTOCOL));\r
220 InitializeListHead (&Hash2ServiceData->ChildrenList);\r
221\r
222 //\r
223 // Install the HASH Service Binding Protocol\r
224 //\r
225 Status = gBS->InstallMultipleProtocolInterfaces (\r
226 &Hash2ServiceData->ServiceHandle,\r
227 &gEfiHash2ServiceBindingProtocolGuid,\r
228 &Hash2ServiceData->ServiceBinding,\r
229 NULL\r
230 );\r
231 if (EFI_ERROR (Status)) {\r
232 FreePool (Hash2ServiceData);\r
233 }\r
234\r
235 return Status;\r
b3548d32 236}\r