Update for SecurityPkg.
[mirror_edk2.git] / SecurityPkg / Tcg / TcgConfigDxe / TcgConfigDriver.c
1 /** @file
2 The module entry point for Tcg configuration module.
3
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "TcgConfigImpl.h"
16
17 /**
18 The entry point for Tcg configuration driver.
19
20 @param[in] ImageHandle The image handle of the driver.
21 @param[in] SystemTable The system table.
22
23 @retval EFI_ALREADY_STARTED The driver already exists in system.
24 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.
25 @retval EFI_SUCCES All the related protocols are installed on the driver.
26 @retval Others Fail to install protocols as indicated.
27
28 **/
29 EFI_STATUS
30 EFIAPI
31 TcgConfigDriverEntryPoint (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35 {
36 EFI_STATUS Status;
37 TCG_CONFIG_PRIVATE_DATA *PrivateData;
38 EFI_TCG_PROTOCOL *TcgProtocol;
39
40 Status = TisPcRequestUseTpm ((TIS_TPM_HANDLE) (UINTN) TPM_BASE_ADDRESS);
41 if (EFI_ERROR (Status)) {
42 DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));
43 return Status;
44 }
45
46 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol);
47 if (EFI_ERROR (Status)) {
48 TcgProtocol = NULL;
49 }
50
51 Status = gBS->OpenProtocol (
52 ImageHandle,
53 &gEfiCallerIdGuid,
54 NULL,
55 ImageHandle,
56 ImageHandle,
57 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
58 );
59 if (!EFI_ERROR (Status)) {
60 return EFI_ALREADY_STARTED;
61 }
62
63 //
64 // Create a private data structure.
65 //
66 PrivateData = AllocateCopyPool (sizeof (TCG_CONFIG_PRIVATE_DATA), &mTcgConfigPrivateDateTemplate);
67 if (PrivateData == NULL) {
68 return EFI_OUT_OF_RESOURCES;
69 }
70
71 PrivateData->TcgProtocol = TcgProtocol;
72 PrivateData->HideTpm = (BOOLEAN) (PcdGetBool (PcdHideTpmSupport) && PcdGetBool (PcdHideTpm));
73
74 //
75 // Install TCG configuration form
76 //
77 Status = InstallTcgConfigForm (PrivateData);
78 if (EFI_ERROR (Status)) {
79 goto ErrorExit;
80 }
81
82 //
83 // Install private GUID.
84 //
85 Status = gBS->InstallMultipleProtocolInterfaces (
86 &ImageHandle,
87 &gEfiCallerIdGuid,
88 PrivateData,
89 NULL
90 );
91
92 if (EFI_ERROR (Status)) {
93 goto ErrorExit;
94 }
95
96 return EFI_SUCCESS;
97
98 ErrorExit:
99 if (PrivateData != NULL) {
100 UninstallTcgConfigForm (PrivateData);
101 }
102
103 return Status;
104 }
105
106 /**
107 Unload the Tcg configuration form.
108
109 @param[in] ImageHandle The driver's image handle.
110
111 @retval EFI_SUCCESS The Tcg configuration form is unloaded.
112 @retval Others Failed to unload the form.
113
114 **/
115 EFI_STATUS
116 EFIAPI
117 TcgConfigDriverUnload (
118 IN EFI_HANDLE ImageHandle
119 )
120 {
121 EFI_STATUS Status;
122 TCG_CONFIG_PRIVATE_DATA *PrivateData;
123
124 Status = gBS->HandleProtocol (
125 ImageHandle,
126 &gEfiCallerIdGuid,
127 (VOID **) &PrivateData
128 );
129 if (EFI_ERROR (Status)) {
130 return Status;
131 }
132
133 ASSERT (PrivateData->Signature == TCG_CONFIG_PRIVATE_DATA_SIGNATURE);
134
135 gBS->UninstallMultipleProtocolInterfaces (
136 &ImageHandle,
137 &gEfiCallerIdGuid,
138 PrivateData,
139 NULL
140 );
141
142 UninstallTcgConfigForm (PrivateData);
143
144 return EFI_SUCCESS;
145 }