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