]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
Add TPM2 implementation.
[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
c1d93242 4Copyright (c) 2011 - 2013, 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
0c18794e 46 Status = TisPcRequestUseTpm ((TIS_TPM_HANDLE) (UINTN) TPM_BASE_ADDRESS);\r
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
76 \r
77 PrivateData->TcgProtocol = TcgProtocol;\r
81b7a609 78 PrivateData->HideTpm = (BOOLEAN) (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm));\r
0c18794e 79 \r
80 //\r
81 // Install TCG configuration form\r
82 //\r
83 Status = InstallTcgConfigForm (PrivateData);\r
84 if (EFI_ERROR (Status)) {\r
85 goto ErrorExit;\r
86 }\r
87\r
88 //\r
89 // Install private GUID.\r
90 // \r
91 Status = gBS->InstallMultipleProtocolInterfaces (\r
92 &ImageHandle,\r
a0c56a82 93 &gEfiCallerIdGuid,\r
0c18794e 94 PrivateData,\r
95 NULL\r
96 );\r
97\r
98 if (EFI_ERROR (Status)) {\r
99 goto ErrorExit;\r
100 }\r
101\r
102 return EFI_SUCCESS;\r
103\r
104ErrorExit:\r
105 if (PrivateData != NULL) {\r
106 UninstallTcgConfigForm (PrivateData);\r
107 } \r
108 \r
109 return Status;\r
110}\r
111\r
112/**\r
113 Unload the Tcg configuration form.\r
114\r
115 @param[in] ImageHandle The driver's image handle.\r
116\r
117 @retval EFI_SUCCESS The Tcg configuration form is unloaded.\r
118 @retval Others Failed to unload the form.\r
119\r
120**/\r
121EFI_STATUS\r
122EFIAPI\r
123TcgConfigDriverUnload (\r
124 IN EFI_HANDLE ImageHandle\r
125 )\r
126{\r
127 EFI_STATUS Status;\r
128 TCG_CONFIG_PRIVATE_DATA *PrivateData;\r
129\r
130 Status = gBS->HandleProtocol (\r
131 ImageHandle,\r
a0c56a82 132 &gEfiCallerIdGuid,\r
0c18794e 133 (VOID **) &PrivateData\r
134 ); \r
135 if (EFI_ERROR (Status)) {\r
136 return Status; \r
137 }\r
138 \r
139 ASSERT (PrivateData->Signature == TCG_CONFIG_PRIVATE_DATA_SIGNATURE);\r
140\r
141 gBS->UninstallMultipleProtocolInterfaces (\r
142 &ImageHandle,\r
a0c56a82 143 &gEfiCallerIdGuid,\r
0c18794e 144 PrivateData,\r
145 NULL\r
146 );\r
147 \r
148 UninstallTcgConfigForm (PrivateData);\r
149\r
150 return EFI_SUCCESS;\r
151}\r