2 The module entry point for TrEE configuration module.
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
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.
15 #include "TrEEConfigImpl.h"
17 extern TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1];
20 The entry point for TrEE configuration driver.
22 @param[in] ImageHandle The image handle of the driver.
23 @param[in] SystemTable The system table.
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.
33 TrEEConfigDriverEntryPoint (
34 IN EFI_HANDLE ImageHandle
,
35 IN EFI_SYSTEM_TABLE
*SystemTable
39 TREE_CONFIG_PRIVATE_DATA
*PrivateData
;
40 TREE_CONFIGURATION TrEEConfiguration
;
41 TREE_DEVICE_DETECTION TrEEDeviceDetection
;
44 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLockProtocol
;
46 Status
= gBS
->OpenProtocol (
52 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
54 if (!EFI_ERROR (Status
)) {
55 return EFI_ALREADY_STARTED
;
59 // Create a private data structure.
61 PrivateData
= AllocateCopyPool (sizeof (TREE_CONFIG_PRIVATE_DATA
), &mTrEEConfigPrivateDateTemplate
);
62 ASSERT (PrivateData
!= NULL
);
65 // Install private GUID.
67 Status
= gBS
->InstallMultipleProtocolInterfaces (
73 ASSERT_EFI_ERROR (Status
);
75 DataSize
= sizeof(TrEEConfiguration
);
76 Status
= gRT
->GetVariable (
78 &gTrEEConfigFormSetGuid
,
83 if (EFI_ERROR (Status
)) {
85 // Variable not ready, set default value
87 TrEEConfiguration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
93 if ((TrEEConfiguration
.TpmDevice
> TPM_DEVICE_MAX
) || (TrEEConfiguration
.TpmDevice
< TPM_DEVICE_MIN
)) {
94 TrEEConfiguration
.TpmDevice
= TPM_DEVICE_DEFAULT
;
98 // Save to variable so platform driver can get it.
100 Status
= gRT
->SetVariable (
102 &gTrEEConfigFormSetGuid
,
103 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
104 sizeof(TrEEConfiguration
),
107 if (EFI_ERROR (Status
)) {
108 DEBUG ((EFI_D_ERROR
, "TrEEConfigDriver: Fail to set TREE_STORAGE_NAME\n"));
112 // Sync data from PCD to variable, so that we do not need detect again in S3 phase.
114 TrEEDeviceDetection
.TpmDeviceDetected
= TPM_DEVICE_NULL
;
115 for (Index
= 0; Index
< sizeof(mTpmInstanceId
)/sizeof(mTpmInstanceId
[0]); Index
++) {
116 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &mTpmInstanceId
[Index
].TpmInstanceGuid
)) {
117 TrEEDeviceDetection
.TpmDeviceDetected
= mTpmInstanceId
[Index
].TpmDevice
;
122 PrivateData
->TpmDeviceDetected
= TrEEDeviceDetection
.TpmDeviceDetected
;
125 // Save to variable so platform driver can get it.
127 Status
= gRT
->SetVariable (
128 TREE_DEVICE_DETECTION_NAME
,
129 &gTrEEConfigFormSetGuid
,
130 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
131 sizeof(TrEEDeviceDetection
),
134 if (EFI_ERROR (Status
)) {
135 DEBUG ((EFI_D_ERROR
, "TrEEConfigDriver: Fail to set TREE_DEVICE_DETECTION_NAME\n"));
136 Status
= gRT
->SetVariable (
137 TREE_DEVICE_DETECTION_NAME
,
138 &gTrEEConfigFormSetGuid
,
139 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
143 ASSERT_EFI_ERROR (Status
);
147 // We should lock TrEEDeviceDetection, because it contains information needed at S3.
149 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**)&VariableLockProtocol
);
150 if (!EFI_ERROR (Status
)) {
151 Status
= VariableLockProtocol
->RequestToLock (
152 VariableLockProtocol
,
153 TREE_DEVICE_DETECTION_NAME
,
154 &gTrEEConfigFormSetGuid
156 ASSERT_EFI_ERROR (Status
);
160 // Install TrEE configuration form
162 Status
= InstallTrEEConfigForm (PrivateData
);
163 if (EFI_ERROR (Status
)) {
170 if (PrivateData
!= NULL
) {
171 UninstallTrEEConfigForm (PrivateData
);
178 Unload the TrEE configuration form.
180 @param[in] ImageHandle The driver's image handle.
182 @retval EFI_SUCCESS The TrEE configuration form is unloaded.
183 @retval Others Failed to unload the form.
188 TrEEConfigDriverUnload (
189 IN EFI_HANDLE ImageHandle
193 TREE_CONFIG_PRIVATE_DATA
*PrivateData
;
195 Status
= gBS
->HandleProtocol (
198 (VOID
**) &PrivateData
200 if (EFI_ERROR (Status
)) {
204 ASSERT (PrivateData
->Signature
== TREE_CONFIG_PRIVATE_DATA_SIGNATURE
);
206 gBS
->UninstallMultipleProtocolInterfaces (
213 UninstallTrEEConfigForm (PrivateData
);