]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Hash2DxeCrypto/Driver.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
c411b485 11EFI_SERVICE_BINDING_PROTOCOL mHash2ServiceBindingProtocol = {\r
724dcbb2
JY
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
d6b926e7 25 @retval EFI_SUCCESS The protocol was added to ChildHandle.\r
724dcbb2 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
c411b485
MK
35 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
36 IN OUT EFI_HANDLE *ChildHandle\r
724dcbb2
JY
37 )\r
38{\r
c411b485
MK
39 EFI_STATUS Status;\r
40 HASH2_SERVICE_DATA *Hash2ServiceData;\r
41 HASH2_INSTANCE_DATA *Instance;\r
42 EFI_TPL OldTpl;\r
724dcbb2
JY
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
724dcbb2
JY
90/**\r
91 Destroys a child handle with a set of I/O services.\r
92\r
93 The DestroyChild() function does the opposite of CreateChild(). It removes a\r
94 protocol that was installed by CreateChild() from ChildHandle. If the removed\r
95 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
96\r
97 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
98 instance.\r
99 @param[in] ChildHandle Handle of the child to destroy.\r
100\r
d6b926e7 101 @retval EFI_SUCCESS The protocol was removed from ChildHandle.\r
724dcbb2
JY
102 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that\r
103 is being removed.\r
104 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
105 @retval EFI_ACCESS_DENIED The protocol could not be removed from the\r
106 ChildHandle because its services are being\r
107 used.\r
108 @retval Others The child handle was not destroyed.\r
109\r
110**/\r
111EFI_STATUS\r
112EFIAPI\r
113Hash2ServiceBindingDestroyChild (\r
c411b485
MK
114 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
115 IN EFI_HANDLE ChildHandle\r
724dcbb2
JY
116 )\r
117{\r
c411b485
MK
118 EFI_STATUS Status;\r
119 HASH2_SERVICE_DATA *Hash2ServiceData;\r
120 EFI_HASH2_PROTOCOL *Hash2Protocol;\r
121 HASH2_INSTANCE_DATA *Instance;\r
122 EFI_TPL OldTpl;\r
123 LIST_ENTRY *Entry;\r
724dcbb2
JY
124\r
125 if ((This == NULL) || (ChildHandle == NULL)) {\r
126 return EFI_INVALID_PARAMETER;\r
127 }\r
128\r
129 Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);\r
130\r
131 //\r
132 // Check if this ChildHandle is valid\r
133 //\r
134 Instance = NULL;\r
c411b485 135 for (Entry = (&Hash2ServiceData->ChildrenList)->ForwardLink; Entry != (&Hash2ServiceData->ChildrenList); Entry = Entry->ForwardLink) {\r
724dcbb2
JY
136 Instance = HASH2_INSTANCE_DATA_FROM_LINK (Entry);\r
137 if (Instance->Handle == ChildHandle) {\r
138 break;\r
139 } else {\r
140 Instance = NULL;\r
141 }\r
142 }\r
c411b485 143\r
724dcbb2 144 if (Instance == NULL) {\r
e905fbb0 145 DEBUG ((DEBUG_ERROR, "Hash2ServiceBindingDestroyChild - Invalid handle\n"));\r
724dcbb2
JY
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
d6b926e7 196 @retval EFI_SUCCESS The service binding protocols is successfully installed.\r
724dcbb2
JY
197 @retval Others Other errors as indicated.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202Hash2DriverEntryPoint (\r
c411b485
MK
203 IN EFI_HANDLE ImageHandle,\r
204 IN EFI_SYSTEM_TABLE *SystemTable\r
724dcbb2
JY
205 )\r
206{\r
c411b485
MK
207 EFI_STATUS Status;\r
208 HASH2_SERVICE_DATA *Hash2ServiceData;\r
724dcbb2
JY
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
c411b485 218 Hash2ServiceData->Signature = HASH2_SERVICE_DATA_SIGNATURE;\r
724dcbb2
JY
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