]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDriver.c
fb06624fdb8f182ac83578dbb54a2af080a79c04
[mirror_edk2.git] / SecurityPkg / Tcg / TcgConfigDxe / TcgConfigDriver.c
1 /** @file
2 The module entry point for Tcg configuration module.
3
4 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "TcgConfigImpl.h"
10 #include <Guid/TpmInstance.h>
11
12 /**
13 The entry point for Tcg configuration driver.
14
15 @param[in] ImageHandle The image handle of the driver.
16 @param[in] SystemTable The system table.
17
18 @retval EFI_ALREADY_STARTED The driver already exists in system.
19 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of resources.
20 @retval EFI_SUCCES All the related protocols are installed on the driver.
21 @retval Others Fail to install protocols as indicated.
22
23 **/
24 EFI_STATUS
25 EFIAPI
26 TcgConfigDriverEntryPoint (
27 IN EFI_HANDLE ImageHandle,
28 IN EFI_SYSTEM_TABLE *SystemTable
29 )
30 {
31 EFI_STATUS Status;
32 TCG_CONFIG_PRIVATE_DATA *PrivateData;
33 EFI_TCG_PROTOCOL *TcgProtocol;
34
35 if (!CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceTpm12Guid)){
36 DEBUG ((EFI_D_ERROR, "No TPM12 instance required!\n"));
37 return EFI_UNSUPPORTED;
38 }
39
40 Status = Tpm12RequestUseTpm ();
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->Configuration = AllocatePool (sizeof (TCG_CONFIGURATION));
72 if (PrivateData->Configuration == NULL) {
73 Status = EFI_OUT_OF_RESOURCES;
74 goto ErrorExit;
75 }
76
77 PrivateData->TcgProtocol = TcgProtocol;
78
79 //
80 // Install TCG configuration form
81 //
82 Status = InstallTcgConfigForm (PrivateData);
83 if (EFI_ERROR (Status)) {
84 goto ErrorExit;
85 }
86
87 //
88 // Install private GUID.
89 //
90 Status = gBS->InstallMultipleProtocolInterfaces (
91 &ImageHandle,
92 &gEfiCallerIdGuid,
93 PrivateData,
94 NULL
95 );
96
97 if (EFI_ERROR (Status)) {
98 goto ErrorExit;
99 }
100
101 return EFI_SUCCESS;
102
103 ErrorExit:
104 if (PrivateData != NULL) {
105 UninstallTcgConfigForm (PrivateData);
106 }
107
108 return Status;
109 }
110
111 /**
112 Unload the Tcg configuration form.
113
114 @param[in] ImageHandle The driver's image handle.
115
116 @retval EFI_SUCCESS The Tcg configuration form is unloaded.
117 @retval Others Failed to unload the form.
118
119 **/
120 EFI_STATUS
121 EFIAPI
122 TcgConfigDriverUnload (
123 IN EFI_HANDLE ImageHandle
124 )
125 {
126 EFI_STATUS Status;
127 TCG_CONFIG_PRIVATE_DATA *PrivateData;
128
129 Status = gBS->HandleProtocol (
130 ImageHandle,
131 &gEfiCallerIdGuid,
132 (VOID **) &PrivateData
133 );
134 if (EFI_ERROR (Status)) {
135 return Status;
136 }
137
138 ASSERT (PrivateData->Signature == TCG_CONFIG_PRIVATE_DATA_SIGNATURE);
139
140 gBS->UninstallMultipleProtocolInterfaces (
141 ImageHandle,
142 &gEfiCallerIdGuid,
143 PrivateData,
144 NULL
145 );
146
147 UninstallTcgConfigForm (PrivateData);
148
149 return EFI_SUCCESS;
150 }