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