2015-08-13 10:24:17 +02:00
|
|
|
/** @file
|
|
|
|
The module entry point for Tcg2 configuration module.
|
|
|
|
|
2024-05-24 09:00:30 +02:00
|
|
|
Copyright (c) 2015 - 2024, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:06:56 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2015-08-13 10:24:17 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include <Guid/TpmInstance.h>
|
2024-06-04 03:52:52 +02:00
|
|
|
#include <Guid/Tcg2AcpiCommunicateBuffer.h>
|
|
|
|
#include <Guid/TpmNvsMm.h>
|
2015-08-13 10:24:17 +02:00
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
#include <Library/PeiServicesLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
2024-05-24 09:00:30 +02:00
|
|
|
#include <Library/HobLib.h>
|
2024-06-04 03:52:52 +02:00
|
|
|
#include <Library/MmUnblockMemoryLib.h>
|
2015-08-13 10:24:17 +02:00
|
|
|
|
|
|
|
#include <Ppi/ReadOnlyVariable2.h>
|
|
|
|
#include <Ppi/TpmInitialized.h>
|
|
|
|
#include <Protocol/Tcg2Protocol.h>
|
|
|
|
|
|
|
|
#include "Tcg2ConfigNvData.h"
|
2019-09-05 17:08:19 +02:00
|
|
|
#include "Tcg2Internal.h"
|
2015-08-13 10:24:17 +02:00
|
|
|
|
|
|
|
TPM_INSTANCE_ID mTpmInstanceId[] = TPM_INSTANCE_ID_LIST;
|
|
|
|
|
|
|
|
CONST EFI_PEI_PPI_DESCRIPTOR gTpmSelectedPpi = {
|
|
|
|
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
|
|
&gEfiTpmDeviceSelectedGuid,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR mTpmInitializationDonePpiList = {
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
|
|
|
|
&gPeiTpmInitializationDonePpiGuid,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This routine check both SetupVariable and real TPM device, and return final TpmDevice configuration.
|
|
|
|
|
|
|
|
@param SetupTpmDevice TpmDevice configuration in setup driver
|
|
|
|
|
|
|
|
@return TpmDevice configuration
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
DetectTpmDevice (
|
|
|
|
IN UINT8 SetupTpmDevice
|
|
|
|
);
|
|
|
|
|
2024-06-04 03:52:52 +02:00
|
|
|
/**
|
|
|
|
Build gEdkiiTcg2AcpiCommunicateBufferHobGuid.
|
|
|
|
|
|
|
|
@param[in] PeiServices General purpose services available to every PEIM.
|
|
|
|
@param[in] NotifyDescriptor The notification structure this PEIM registered on install.
|
|
|
|
@param[in] Ppi The memory discovered PPI. Not used.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The function completed successfully.
|
|
|
|
@retval others Failed to build Tcg2AcpiCommunicateBuffer Hob.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
BuildTcg2AcpiCommunicateBufferHob (
|
|
|
|
IN EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
|
|
|
|
IN VOID *Ppi
|
|
|
|
)
|
|
|
|
{
|
|
|
|
TCG2_ACPI_COMMUNICATE_BUFFER *Tcg2AcpiCommunicateBufferHob;
|
|
|
|
EFI_STATUS Status;
|
2024-08-21 04:05:34 +02:00
|
|
|
EFI_PHYSICAL_ADDRESS Buffer;
|
2024-06-04 03:52:52 +02:00
|
|
|
UINTN Pages;
|
|
|
|
|
2024-08-21 03:50:14 +02:00
|
|
|
Pages = EFI_SIZE_TO_PAGES (sizeof (TCG_NVS));
|
2024-08-21 04:05:34 +02:00
|
|
|
Status = PeiServicesAllocatePages (
|
|
|
|
EfiACPIMemoryNVS,
|
|
|
|
Pages,
|
|
|
|
&Buffer
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
Status = MmUnblockMemoryRequest (Buffer, Pages);
|
2024-06-04 03:52:52 +02:00
|
|
|
if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tcg2AcpiCommunicateBufferHob = BuildGuidHob (&gEdkiiTcg2AcpiCommunicateBufferHobGuid, sizeof (TCG2_ACPI_COMMUNICATE_BUFFER));
|
|
|
|
ASSERT (Tcg2AcpiCommunicateBufferHob != NULL);
|
2024-08-21 04:05:34 +02:00
|
|
|
Tcg2AcpiCommunicateBufferHob->Tcg2AcpiCommunicateBuffer = Buffer;
|
2024-06-04 03:52:52 +02:00
|
|
|
Tcg2AcpiCommunicateBufferHob->Pages = Pages;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList = {
|
|
|
|
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
|
|
|
&gEfiPeiMemoryDiscoveredPpiGuid,
|
|
|
|
BuildTcg2AcpiCommunicateBufferHob
|
|
|
|
};
|
|
|
|
|
2015-08-13 10:24:17 +02:00
|
|
|
/**
|
|
|
|
The entry point for Tcg2 configuration driver.
|
|
|
|
|
|
|
|
@param FileHandle Handle of the file being invoked.
|
|
|
|
@param PeiServices Describes the list of possible PEI Services.
|
|
|
|
|
2019-10-09 09:20:15 +02:00
|
|
|
@retval EFI_SUCCESS Convert variable to PCD successfully.
|
2015-08-13 10:24:17 +02:00
|
|
|
@retval Others Fail to convert variable to PCD.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
Tcg2ConfigPeimEntryPoint (
|
|
|
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Size;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_STATUS Status2;
|
|
|
|
EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi;
|
|
|
|
TCG2_CONFIGURATION Tcg2Configuration;
|
|
|
|
UINTN Index;
|
|
|
|
UINT8 TpmDevice;
|
2024-05-24 09:00:30 +02:00
|
|
|
VOID *Hob;
|
2021-12-05 23:54:12 +01:00
|
|
|
|
2015-08-13 10:24:17 +02:00
|
|
|
Status = PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NULL, (VOID **)&VariablePpi);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
Size = sizeof (Tcg2Configuration);
|
|
|
|
Status = VariablePpi->GetVariable (
|
|
|
|
VariablePpi,
|
|
|
|
TCG2_STORAGE_NAME,
|
|
|
|
&gTcg2ConfigFormSetGuid,
|
|
|
|
NULL,
|
|
|
|
&Size,
|
|
|
|
&Tcg2Configuration
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Variable not ready, set default value
|
|
|
|
//
|
|
|
|
Tcg2Configuration.TpmDevice = TPM_DEVICE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Validation
|
|
|
|
//
|
|
|
|
if ((Tcg2Configuration.TpmDevice > TPM_DEVICE_MAX) || (Tcg2Configuration.TpmDevice < TPM_DEVICE_MIN)) {
|
|
|
|
Tcg2Configuration.TpmDevice = TPM_DEVICE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Although we have SetupVariable info, we still need detect TPM device manually.
|
|
|
|
//
|
2021-11-17 04:21:36 +01:00
|
|
|
DEBUG ((DEBUG_INFO, "Tcg2Configuration.TpmDevice from Setup: %x\n", Tcg2Configuration.TpmDevice));
|
2015-08-13 10:24:17 +02:00
|
|
|
|
|
|
|
if (PcdGetBool (PcdTpmAutoDetection)) {
|
|
|
|
TpmDevice = DetectTpmDevice (Tcg2Configuration.TpmDevice);
|
2021-11-17 04:21:36 +01:00
|
|
|
DEBUG ((DEBUG_INFO, "TpmDevice final: %x\n", TpmDevice));
|
2015-08-13 10:24:17 +02:00
|
|
|
if (TpmDevice != TPM_DEVICE_NULL) {
|
|
|
|
Tcg2Configuration.TpmDevice = TpmDevice;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TpmDevice = Tcg2Configuration.TpmDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Convert variable to PCD.
|
2019-10-09 09:20:15 +02:00
|
|
|
// This is work-around because there is no guarantee DynamicHiiPcd can return correct value in DXE phase.
|
2015-08-13 10:24:17 +02:00
|
|
|
// Using DynamicPcd instead.
|
|
|
|
//
|
|
|
|
// NOTE: Tcg2Configuration variable contains the desired TpmDevice type,
|
|
|
|
// while PcdTpmInstanceGuid PCD contains the real detected TpmDevice type
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < sizeof (mTpmInstanceId)/sizeof (mTpmInstanceId[0]); Index++) {
|
|
|
|
if (TpmDevice == mTpmInstanceId[Index].TpmDevice) {
|
|
|
|
Size = sizeof (mTpmInstanceId[Index].TpmInstanceGuid);
|
2015-10-16 03:46:19 +02:00
|
|
|
Status = PcdSetPtrS (PcdTpmInstanceGuid, &Size, &mTpmInstanceId[Index].TpmInstanceGuid);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
2021-11-17 04:21:36 +01:00
|
|
|
DEBUG ((DEBUG_INFO, "TpmDevice PCD: %g\n", &mTpmInstanceId[Index].TpmInstanceGuid));
|
2015-08-13 10:24:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-24 09:00:30 +02:00
|
|
|
//
|
|
|
|
// Build Hob for PcdTpmInstanceGuid
|
|
|
|
//
|
|
|
|
Hob = BuildGuidDataHob (
|
|
|
|
&gEdkiiTpmInstanceHobGuid,
|
2024-07-04 09:15:15 +02:00
|
|
|
(VOID *)PcdGetPtr (PcdTpmInstanceGuid),
|
2024-05-24 09:00:30 +02:00
|
|
|
sizeof (EFI_GUID)
|
|
|
|
);
|
|
|
|
ASSERT (Hob != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Build Hob for PcdTcgPhysicalPresenceInterfaceVer
|
|
|
|
//
|
|
|
|
Hob = BuildGuidDataHob (
|
|
|
|
&gEdkiiTcgPhysicalPresenceInterfaceVerHobGuid,
|
2024-07-04 09:15:15 +02:00
|
|
|
(VOID *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer),
|
2024-05-24 09:00:30 +02:00
|
|
|
AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer))
|
|
|
|
);
|
|
|
|
ASSERT (Hob != NULL);
|
|
|
|
|
2024-06-04 03:52:52 +02:00
|
|
|
PeiServicesNotifyPpi (&mPostMemNotifyList);
|
|
|
|
|
2015-08-13 10:24:17 +02:00
|
|
|
//
|
|
|
|
// Selection done
|
|
|
|
//
|
|
|
|
Status = PeiServicesInstallPpi (&gTpmSelectedPpi);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
//
|
2020-02-07 02:08:18 +01:00
|
|
|
// Even if no TPM is selected or detected, we still need install TpmInitializationDonePpi.
|
2015-08-13 10:24:17 +02:00
|
|
|
// Because TcgPei or Tcg2Pei will not run, but we still need a way to notify other driver.
|
|
|
|
// Other driver can know TPM initialization state by TpmInitializedPpi.
|
|
|
|
//
|
|
|
|
if (CompareGuid (PcdGetPtr (PcdTpmInstanceGuid), &gEfiTpmDeviceInstanceNoneGuid)) {
|
|
|
|
Status2 = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);
|
|
|
|
ASSERT_EFI_ERROR (Status2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|