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