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