]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/TrEEConfig/TrEEConfigDriver.c
Remove unused variable attribute flag.
[mirror_edk2.git] / SecurityPkg / Tcg / TrEEConfig / TrEEConfigDriver.c
1 /** @file
2 The module entry point for TrEE configuration module.
3
4 Copyright (c) 2013, 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 "TrEEConfigImpl.h"
16
17 extern TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1];
18
19 /**
20 The entry point for TrEE 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 TrEEConfigDriverEntryPoint (
34 IN EFI_HANDLE ImageHandle,
35 IN EFI_SYSTEM_TABLE *SystemTable
36 )
37 {
38 EFI_STATUS Status;
39 TREE_CONFIG_PRIVATE_DATA *PrivateData;
40 TREE_CONFIGURATION TrEEConfiguration;
41 UINTN Index;
42 UINTN DataSize;
43
44 Status = gBS->OpenProtocol (
45 ImageHandle,
46 &gEfiCallerIdGuid,
47 NULL,
48 ImageHandle,
49 ImageHandle,
50 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
51 );
52 if (!EFI_ERROR (Status)) {
53 return EFI_ALREADY_STARTED;
54 }
55
56 //
57 // Create a private data structure.
58 //
59 PrivateData = AllocateCopyPool (sizeof (TREE_CONFIG_PRIVATE_DATA), &mTrEEConfigPrivateDateTemplate);
60 ASSERT (PrivateData != NULL);
61
62 //
63 // Install private GUID.
64 //
65 Status = gBS->InstallMultipleProtocolInterfaces (
66 &ImageHandle,
67 &gEfiCallerIdGuid,
68 PrivateData,
69 NULL
70 );
71 ASSERT_EFI_ERROR (Status);
72
73 DataSize = sizeof(TrEEConfiguration);
74 Status = gRT->GetVariable (
75 TREE_STORAGE_NAME,
76 &gTrEEConfigFormSetGuid,
77 NULL,
78 &DataSize,
79 &TrEEConfiguration
80 );
81 if (EFI_ERROR (Status)) {
82 }
83 //
84 // We should always reinit PP request.
85 //
86 TrEEConfiguration.Tpm2Operation = TREE_PHYSICAL_PRESENCE_NO_ACTION;
87
88 //
89 // Sync data from PCD to variable, so that we do not need detect again in S3 phase.
90 //
91
92 //
93 // Get data from PCD to make sure data consistant - platform driver is suppose to construct this PCD accroding to Variable
94 //
95 for (Index = 0; Index < sizeof(mTpmInstanceId)/sizeof(mTpmInstanceId[0]); Index++) {
96 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid), &mTpmInstanceId[Index].TpmInstanceGuid)) {
97 TrEEConfiguration.TpmDevice = mTpmInstanceId[Index].TpmDevice;
98 break;
99 }
100 }
101
102 //
103 // Save to variable so platform driver can get it.
104 //
105 Status = gRT->SetVariable (
106 TREE_STORAGE_NAME,
107 &gTrEEConfigFormSetGuid,
108 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
109 sizeof(TrEEConfiguration),
110 &TrEEConfiguration
111 );
112 ASSERT_EFI_ERROR (Status);
113
114 //
115 // Install TrEE configuration form
116 //
117 Status = InstallTrEEConfigForm (PrivateData);
118 if (EFI_ERROR (Status)) {
119 goto ErrorExit;
120 }
121
122 return EFI_SUCCESS;
123
124 ErrorExit:
125 if (PrivateData != NULL) {
126 UninstallTrEEConfigForm (PrivateData);
127 }
128
129 return Status;
130 }
131
132 /**
133 Unload the TrEE configuration form.
134
135 @param[in] ImageHandle The driver's image handle.
136
137 @retval EFI_SUCCESS The TrEE configuration form is unloaded.
138 @retval Others Failed to unload the form.
139
140 **/
141 EFI_STATUS
142 EFIAPI
143 TrEEConfigDriverUnload (
144 IN EFI_HANDLE ImageHandle
145 )
146 {
147 EFI_STATUS Status;
148 TREE_CONFIG_PRIVATE_DATA *PrivateData;
149
150 Status = gBS->HandleProtocol (
151 ImageHandle,
152 &gEfiCallerIdGuid,
153 (VOID **) &PrivateData
154 );
155 if (EFI_ERROR (Status)) {
156 return Status;
157 }
158
159 ASSERT (PrivateData->Signature == TREE_CONFIG_PRIVATE_DATA_SIGNATURE);
160
161 gBS->UninstallMultipleProtocolInterfaces (
162 &ImageHandle,
163 &gEfiCallerIdGuid,
164 PrivateData,
165 NULL
166 );
167
168 UninstallTrEEConfigForm (PrivateData);
169
170 return EFI_SUCCESS;
171 }