]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
SecuritPkg: Tcg2Smm: Add PlatformClass to TPM2 Table
[mirror_edk2.git] / SecurityPkg / Tcg / TcgConfigDxe / TcgConfigDriver.c
CommitLineData
0c18794e 1/** @file\r
2 The module entry point for Tcg configuration module.\r
3\r
c132457e 4Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
0c18794e 5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The 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 "TcgConfigImpl.h"\r
c1d93242 16#include <Guid/TpmInstance.h>\r
0c18794e 17\r
0c18794e 18/**\r
19 The entry point for Tcg configuration driver.\r
20\r
21 @param[in] ImageHandle The image handle of the driver.\r
22 @param[in] SystemTable The system table.\r
23\r
24 @retval EFI_ALREADY_STARTED The driver already exists in system.\r
25 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.\r
26 @retval EFI_SUCCES All the related protocols are installed on the driver.\r
27 @retval Others Fail to install protocols as indicated.\r
28\r
29**/\r
30EFI_STATUS\r
31EFIAPI\r
32TcgConfigDriverEntryPoint (\r
33 IN EFI_HANDLE ImageHandle,\r
34 IN EFI_SYSTEM_TABLE *SystemTable\r
35 )\r
36{\r
37 EFI_STATUS Status;\r
38 TCG_CONFIG_PRIVATE_DATA *PrivateData;\r
39 EFI_TCG_PROTOCOL *TcgProtocol;\r
40\r
c1d93242
JY
41 if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){\r
42 DEBUG ((EFI_D_ERROR, "No TPM12 instance required!\n"));\r
43 return EFI_UNSUPPORTED;\r
44 }\r
45\r
c132457e 46 Status = Tpm12RequestUseTpm ();\r
0c18794e 47 if (EFI_ERROR (Status)) {\r
48 DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));\r
49 return Status;\r
50 }\r
51\r
52 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r
53 if (EFI_ERROR (Status)) {\r
54 TcgProtocol = NULL;\r
55 }\r
56 \r
57 Status = gBS->OpenProtocol (\r
58 ImageHandle,\r
a0c56a82 59 &gEfiCallerIdGuid,\r
0c18794e 60 NULL,\r
61 ImageHandle,\r
62 ImageHandle,\r
63 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
64 );\r
65 if (!EFI_ERROR (Status)) {\r
66 return EFI_ALREADY_STARTED;\r
67 }\r
68 \r
69 //\r
70 // Create a private data structure.\r
71 //\r
72 PrivateData = AllocateCopyPool (sizeof (TCG_CONFIG_PRIVATE_DATA), &mTcgConfigPrivateDateTemplate);\r
73 if (PrivateData == NULL) {\r
74 return EFI_OUT_OF_RESOURCES;\r
75 }\r
1826b5e6
ZC
76\r
77 PrivateData->Configuration = AllocatePool (sizeof (TCG_CONFIGURATION));\r
78 if (PrivateData->Configuration == NULL) {\r
79 Status = EFI_OUT_OF_RESOURCES;\r
80 goto ErrorExit;\r
81 }\r
82\r
0c18794e 83 PrivateData->TcgProtocol = TcgProtocol;\r
1826b5e6 84\r
0c18794e 85 //\r
86 // Install TCG configuration form\r
87 //\r
88 Status = InstallTcgConfigForm (PrivateData);\r
89 if (EFI_ERROR (Status)) {\r
90 goto ErrorExit;\r
91 }\r
92\r
93 //\r
94 // Install private GUID.\r
95 // \r
96 Status = gBS->InstallMultipleProtocolInterfaces (\r
97 &ImageHandle,\r
a0c56a82 98 &gEfiCallerIdGuid,\r
0c18794e 99 PrivateData,\r
100 NULL\r
101 );\r
102\r
103 if (EFI_ERROR (Status)) {\r
104 goto ErrorExit;\r
105 }\r
106\r
107 return EFI_SUCCESS;\r
108\r
109ErrorExit:\r
110 if (PrivateData != NULL) {\r
111 UninstallTcgConfigForm (PrivateData);\r
112 } \r
113 \r
114 return Status;\r
115}\r
116\r
117/**\r
118 Unload the Tcg configuration form.\r
119\r
120 @param[in] ImageHandle The driver's image handle.\r
121\r
122 @retval EFI_SUCCESS The Tcg configuration form is unloaded.\r
123 @retval Others Failed to unload the form.\r
124\r
125**/\r
126EFI_STATUS\r
127EFIAPI\r
128TcgConfigDriverUnload (\r
129 IN EFI_HANDLE ImageHandle\r
130 )\r
131{\r
132 EFI_STATUS Status;\r
133 TCG_CONFIG_PRIVATE_DATA *PrivateData;\r
134\r
135 Status = gBS->HandleProtocol (\r
136 ImageHandle,\r
a0c56a82 137 &gEfiCallerIdGuid,\r
0c18794e 138 (VOID **) &PrivateData\r
139 ); \r
140 if (EFI_ERROR (Status)) {\r
141 return Status; \r
142 }\r
143 \r
144 ASSERT (PrivateData->Signature == TCG_CONFIG_PRIVATE_DATA_SIGNATURE);\r
145\r
146 gBS->UninstallMultipleProtocolInterfaces (\r
147 &ImageHandle,\r
a0c56a82 148 &gEfiCallerIdGuid,\r
0c18794e 149 PrivateData,\r
150 NULL\r
151 );\r
152 \r
153 UninstallTcgConfigForm (PrivateData);\r
154\r
155 return EFI_SUCCESS;\r
156}\r