Update for SecurityPkg.
[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
4Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
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
16\r
0c18794e 17/**\r
18 The entry point for Tcg configuration driver.\r
19\r
20 @param[in] ImageHandle The image handle of the driver.\r
21 @param[in] SystemTable The system table.\r
22\r
23 @retval EFI_ALREADY_STARTED The driver already exists in system.\r
24 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.\r
25 @retval EFI_SUCCES All the related protocols are installed on the driver.\r
26 @retval Others Fail to install protocols as indicated.\r
27\r
28**/\r
29EFI_STATUS\r
30EFIAPI\r
31TcgConfigDriverEntryPoint (\r
32 IN EFI_HANDLE ImageHandle,\r
33 IN EFI_SYSTEM_TABLE *SystemTable\r
34 )\r
35{\r
36 EFI_STATUS Status;\r
37 TCG_CONFIG_PRIVATE_DATA *PrivateData;\r
38 EFI_TCG_PROTOCOL *TcgProtocol;\r
39\r
40 Status = TisPcRequestUseTpm ((TIS_TPM_HANDLE) (UINTN) TPM_BASE_ADDRESS);\r
41 if (EFI_ERROR (Status)) {\r
42 DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));\r
43 return Status;\r
44 }\r
45\r
46 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);\r
47 if (EFI_ERROR (Status)) {\r
48 TcgProtocol = NULL;\r
49 }\r
50 \r
51 Status = gBS->OpenProtocol (\r
52 ImageHandle,\r
a0c56a82 53 &gEfiCallerIdGuid,\r
0c18794e 54 NULL,\r
55 ImageHandle,\r
56 ImageHandle,\r
57 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
58 );\r
59 if (!EFI_ERROR (Status)) {\r
60 return EFI_ALREADY_STARTED;\r
61 }\r
62 \r
63 //\r
64 // Create a private data structure.\r
65 //\r
66 PrivateData = AllocateCopyPool (sizeof (TCG_CONFIG_PRIVATE_DATA), &mTcgConfigPrivateDateTemplate);\r
67 if (PrivateData == NULL) {\r
68 return EFI_OUT_OF_RESOURCES;\r
69 }\r
70 \r
71 PrivateData->TcgProtocol = TcgProtocol;\r
81b7a609 72 PrivateData->HideTpm = (BOOLEAN) (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm));\r
0c18794e 73 \r
74 //\r
75 // Install TCG configuration form\r
76 //\r
77 Status = InstallTcgConfigForm (PrivateData);\r
78 if (EFI_ERROR (Status)) {\r
79 goto ErrorExit;\r
80 }\r
81\r
82 //\r
83 // Install private GUID.\r
84 // \r
85 Status = gBS->InstallMultipleProtocolInterfaces (\r
86 &ImageHandle,\r
a0c56a82 87 &gEfiCallerIdGuid,\r
0c18794e 88 PrivateData,\r
89 NULL\r
90 );\r
91\r
92 if (EFI_ERROR (Status)) {\r
93 goto ErrorExit;\r
94 }\r
95\r
96 return EFI_SUCCESS;\r
97\r
98ErrorExit:\r
99 if (PrivateData != NULL) {\r
100 UninstallTcgConfigForm (PrivateData);\r
101 } \r
102 \r
103 return Status;\r
104}\r
105\r
106/**\r
107 Unload the Tcg configuration form.\r
108\r
109 @param[in] ImageHandle The driver's image handle.\r
110\r
111 @retval EFI_SUCCESS The Tcg configuration form is unloaded.\r
112 @retval Others Failed to unload the form.\r
113\r
114**/\r
115EFI_STATUS\r
116EFIAPI\r
117TcgConfigDriverUnload (\r
118 IN EFI_HANDLE ImageHandle\r
119 )\r
120{\r
121 EFI_STATUS Status;\r
122 TCG_CONFIG_PRIVATE_DATA *PrivateData;\r
123\r
124 Status = gBS->HandleProtocol (\r
125 ImageHandle,\r
a0c56a82 126 &gEfiCallerIdGuid,\r
0c18794e 127 (VOID **) &PrivateData\r
128 ); \r
129 if (EFI_ERROR (Status)) {\r
130 return Status; \r
131 }\r
132 \r
133 ASSERT (PrivateData->Signature == TCG_CONFIG_PRIVATE_DATA_SIGNATURE);\r
134\r
135 gBS->UninstallMultipleProtocolInterfaces (\r
136 &ImageHandle,\r
a0c56a82 137 &gEfiCallerIdGuid,\r
0c18794e 138 PrivateData,\r
139 NULL\r
140 );\r
141 \r
142 UninstallTcgConfigForm (PrivateData);\r
143\r
144 return EFI_SUCCESS;\r
145}\r