[PATCH v3 3/8] SecurityPkg: Store physical presence code by submitting to PreOS func
Stefan Berger
Modify SavePpRequest to look like its TPM 2 equivalent SaveTcg2PpRequest
and have it submit the physical presence opcode to the PreOS function so that we can choose our own method for how to store it. Move the existing code into DxeTcgPhysicalPresenceLib.c and adapt the return codes. Cc: Jiewen Yao <jiewen.yao@...> Cc: Jian J Wang <jian.j.wang@...> Cc: Marc-André Lureau <marcandre.lureau@...> Signed-off-by: Stefan Berger <stefanb@...> --- .../DxeTcgPhysicalPresenceLib.c | 55 +++++++++++++++++++ SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c | 41 +++++--------- 2 files changed, 70 insertions(+), 26 deletions(-) diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c index ba1abe9e08..aa0031dd77 100644 --- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c +++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c @@ -1398,3 +1398,58 @@ TcgPhysicalPresenceLibNeedUserConfirm( return FALSE; } +/** + The handler for TPM physical presence function: + Submit TPM Operation Request to Pre-OS Environment and + Submit TPM Operation Request to Pre-OS Environment 2. + + Caution: This function may receive untrusted input. + + @param[in] OperationRequest TPM physical presence operation request. + + @return Return Code for Submit TPM Operation Request to Pre-OS Environment and + Submit TPM Operation Request to Pre-OS Environment 2. +**/ +UINT32 +EFIAPI +TcgPhysicalPresenceLibSubmitRequestToPreOSFunction ( + IN UINT32 OperationRequest + ) +{ + EFI_STATUS Status; + UINTN DataSize; + EFI_PHYSICAL_PRESENCE PpData; + + DEBUG ((DEBUG_INFO, "[TPM] SubmitRequestToPreOSFunction, Request = %x\n", OperationRequest)); + + // + // Get the Physical Presence variable + // + DataSize = sizeof (EFI_PHYSICAL_PRESENCE); + Status = gRT->GetVariable ( + PHYSICAL_PRESENCE_VARIABLE, + &gEfiPhysicalPresenceGuid, + NULL, + &DataSize, + &PpData + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status)); + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; + } + + PpData.PPRequest = (UINT8)OperationRequest; + Status = gRT->SetVariable ( + PHYSICAL_PRESENCE_VARIABLE, + &gEfiPhysicalPresenceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + DataSize, + &PpData + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[TPM] Set PP variable failure! Status = %r\n", Status)); + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; + } + + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS; +} diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c index 68cd62307c..61c072d1a3 100644 --- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c +++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c @@ -8,6 +8,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "TcgConfigImpl.h" +#include <IndustryStandard/TcgPhysicalPresence.h> +#include <Library/TcgPhysicalPresenceLib.h> + CHAR16 mTcgStorageName[] = L"TCG_CONFIGURATION"; TCG_CONFIG_PRIVATE_DATA mTcgConfigPrivateDateTemplate = { @@ -299,37 +302,23 @@ SavePpRequest ( ) { EFI_STATUS Status; - UINTN DataSize; - EFI_PHYSICAL_PRESENCE PpData; + UINT32 ReturnCode; // - // Save TPM command to variable. + // Submit TPM command to PreOS fuction // - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->GetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - NULL, - &DataSize, - &PpData - ); - if (EFI_ERROR (Status)) { - return Status; - } - - PpData.PPRequest = PpRequest; - Status = gRT->SetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - DataSize, - &PpData - ); - if (EFI_ERROR(Status)) { - return Status; + ReturnCode = TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest); + if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) { + Status = EFI_SUCCESS; + } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) { + Status = EFI_OUT_OF_RESOURCES; + } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) { + Status = EFI_UNSUPPORTED; + } else { + Status = EFI_DEVICE_ERROR; } - return EFI_SUCCESS; + return Status; } /** -- 2.31.1
|
|
[PATCH v3 2/8] OvmfPkg: Check for TPM 2 early to leave function early
Stefan Berger
TPM 1.2 and TPM 2 share QEMU's PPI memory/device and for the TPM 2 code
not to initilize over the TPM 1.2 initilization, leave the init function early without touching that memory. Cc: Gerd Hoffmann <kraxel@...> Cc: Marc-André Lureau <marcandre.lureau@...> Signed-off-by: Stefan Berger <stefanb@...> --- .../DxeTcg2PhysicalPresenceLib.c | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c index 33a470f6d8..f46a047235 100644 --- a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c +++ b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c @@ -94,7 +94,6 @@ QemuTpmInitPPI ( QEMU_FWCFG_TPM_CONFIG Config; EFI_PHYSICAL_ADDRESS PpiAddress64; EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; - UINTN Idx; if (mPpi != NULL) { return EFI_SUCCESS; @@ -105,6 +104,11 @@ QemuTpmInitPPI ( return Status; } + if (Config.TpmVersion != QEMU_TPM_VERSION_2) { + DEBUG ((DEBUG_ERROR, "[TPM2PP] Not setting up PPI. This is not a TPM 2.\n")); + return EFI_PROTOCOL_ERROR; + } + mPpi = (QEMU_TPM_PPI *)(UINTN)Config.PpiAddress; if (mPpi == NULL) { return EFI_PROTOCOL_ERROR; @@ -131,21 +135,18 @@ QemuTpmInitPPI ( goto InvalidPpiAddress; } - for (Idx = 0; Idx < ARRAY_SIZE (mPpi->Func); Idx++) { - mPpi->Func[Idx] = 0; - } - if (Config.TpmVersion == QEMU_TPM_VERSION_2) { - mPpi->Func[TCG2_PHYSICAL_PRESENCE_NO_ACTION] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_CHANGE_EPS] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID] = TPM_PPI_FLAGS; - mPpi->Func[TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID] = TPM_PPI_FLAGS; - } + ZeroMem ((void *)mPpi->Func, sizeof(mPpi->Func)); + + mPpi->Func[TCG2_PHYSICAL_PRESENCE_NO_ACTION] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_CHANGE_EPS] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID] = TPM_PPI_FLAGS; + mPpi->Func[TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID] = TPM_PPI_FLAGS; if (mPpi->In == 0) { mPpi->In = 1; @@ -833,10 +834,11 @@ Tcg2PhysicalPresenceLibProcessRequest ( Status = QemuTpmInitPPI (); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_INFO, "[TPM2PP] no PPI\n")); return ; } + DEBUG ((DEBUG_INFO, "[TPM2PP] Detected a TPM 2\n")); + // // Check S4 resume // -- 2.31.1
|
|
[PATCH v3 4/8] SecurityPkg: Declare PhysicalPresenceFlags variable and its properties
Stefan Berger
Declare the TPM 1.2 PhysicalPresenceFlags variable and its properties.
The effect of its properties is that once PhysicalPresenceFlags is defined it cannot be deleted from Linux: cd /sys/firmware/efi/efivars chattr -i PhysicalPresenceFlags-* rm -f PhysicalPresenceFlags-* It will still be there: ls PhysicalPresenceFlags-* Signed-off-by: Stefan Berger <stefanb@...> --- .../Library/AuthVariableLib/AuthServiceInternal.h | 1 + SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c | 11 +++++++++++ .../Library/AuthVariableLib/AuthVariableLib.inf | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h b/Se= curityPkg/Library/AuthVariableLib/AuthServiceInternal.h index 2bec637f75..fc2abdb96c 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h +++ b/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h @@ -30,6 +30,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D #include <Guid/AuthenticatedVariableFormat.h>=0D #include <Guid/ImageAuthentication.h>=0D +#include <Guid/PhysicalPresenceData.h>=0D =0D #define TWO_BYTE_ENCODE 0x82=0D =0D diff --git a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c b/Securi= tyPkg/Library/AuthVariableLib/AuthVariableLib.c index 122b3b0bf4..ae75f32d40 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c +++ b/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c @@ -89,6 +89,17 @@ VARIABLE_ENTRY_PROPERTY mAuthVarEntry[] =3D { MAX_UINTN=0D }=0D },=0D + {=0D + &gEfiPhysicalPresenceGuid,=0D + PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D + {=0D + VAR_CHECK_VARIABLE_PROPERTY_REVISION,=0D + VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY,=0D + VARIABLE_ATTRIBUTE_NV_BS,=0D + sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),=0D + MAX_UINTN=0D + }=0D + }=0D };=0D =0D VOID **mAuthVarAddressPointer[9];=0D diff --git a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf b/Secu= rityPkg/Library/AuthVariableLib/AuthVariableLib.inf index 8eadeebceb..d0ced0792c 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf +++ b/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf @@ -75,6 +75,10 @@ ## PRODUCES ## Variable:L"certdbv"=0D gEfiCertDbGuid=0D =0D + ## CONSUMES ## Variable:L"PhysicalPresenceFlags"=0D + ## PRODUCES ## Variable:L"PhysicalPresenceFlags"=0D + gEfiPhysicalPresenceGuid=0D +=0D ## CONSUMES ## Variable:L"VendorKeysNv"=0D ## PRODUCES ## Variable:L"VendorKeysNv"=0D gEfiVendorKeysNvGuid=0D --=20 2.31.1
|
|
[PATCH v3 7/8] OvmfPkg: Enable TPM 1.2 Physical Presence Opcode processing
Stefan Berger
Enable the processing of the TPM 1.2 physical presence opcodes.
This needs to be done before End-of-Dxe since otherwise the creation of the variables doesn't work. Signed-off-by: Stefan Berger <stefanb@...> --- OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 2 ++ OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c | 2 ++ OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg= /Library/PlatformBootManagerLib/BdsPlatform.c index 1765026de2..9c96c0cf69 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -379,7 +379,9 @@ PlatformBootManagerBeforeConsole ( =0D //=0D // Process TPM PPI request; this may require keyboard input=0D + // For variable creation and locking to work, this has to be done before= End-of-Dxe.=0D //=0D + TcgPhysicalPresenceLibProcessRequest ();=0D Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D =0D //=0D diff --git a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c b/Ov= mfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c index 950ab12c94..e9b4831bef 100644 --- a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c @@ -372,7 +372,9 @@ PlatformBootManagerBeforeConsole ( =0D //=0D // Process TPM PPI request=0D + // For variable creation and locking to work, this has to be done before= End-of-Dxe.=0D //=0D + TcgPhysicalPresenceLibProcessRequest ();=0D Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D =0D //=0D diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c b/Ovm= fPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c index fbc40dcb68..a6a9374505 100644 --- a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c @@ -335,7 +335,9 @@ PlatformBootManagerBeforeConsole ( =0D //=0D // Process TPM PPI request=0D + // For variable creation and locking to work, this has to be done before= End-of-Dxe.=0D //=0D + TcgPhysicalPresenceLibProcessRequest ();=0D Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D =0D //=0D --=20 2.31.1
|
|
[PATCH v3 8/8] OvmfPkg: add TPM 1.2 config menu
Stefan Berger
From: Gerd Hoffmann <kraxel@...>
When building OVMF with TPM 1.2 support enabled also include the configuration menu. Suggested-by: Stefan Berger <stefanb@...> Signed-off-by: Gerd Hoffmann <kraxel@...> Signed-off-by: Stefan Berger <stefanb@...> --- OvmfPkg/OvmfTpmComponentsDxe.dsc.inc | 1 + OvmfPkg/OvmfTpmDxe.fdf.inc | 1 + 2 files changed, 2 insertions(+) diff --git a/OvmfPkg/OvmfTpmComponentsDxe.dsc.inc b/OvmfPkg/OvmfTpmComponen= tsDxe.dsc.inc index 75ae09571e..cdcae42ad1 100644 --- a/OvmfPkg/OvmfTpmComponentsDxe.dsc.inc +++ b/OvmfPkg/OvmfTpmComponentsDxe.dsc.inc @@ -20,6 +20,7 @@ <LibraryClasses>=0D Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLib= DTpm.inf=0D }=0D + SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf=0D !endif=0D SecurityPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf {=0D <LibraryClasses>=0D diff --git a/OvmfPkg/OvmfTpmDxe.fdf.inc b/OvmfPkg/OvmfTpmDxe.fdf.inc index 7fc2bf8590..5907d8a8f1 100644 --- a/OvmfPkg/OvmfTpmDxe.fdf.inc +++ b/OvmfPkg/OvmfTpmDxe.fdf.inc @@ -5,6 +5,7 @@ !if $(TPM2_ENABLE) =3D=3D TRUE=0D !if $(TPM1_ENABLE) =3D=3D TRUE=0D INF SecurityPkg/Tcg/TcgDxe/TcgDxe.inf=0D +INF SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf=0D !endif=0D INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf=0D INF SecurityPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf=0D --=20 2.31.1
|
|
[PATCH v3 6/8] OvmfPkg: Enable physical presence interface for TPM 1.2
Stefan Berger
Enable the physical presence interface for TPM 1.2. It is required for the
TPM 1.2 menu to work. The changes to DxeTcgPhysicalPresenceLib.c are due to the device we are using in QEMU for presenting the supported PPI commands and results to the OS via ACPI as well as to store the PPI opcode to execute. Cc: Jiewen Yao <jiewen.yao@...> Cc: Jian J Wang <jian.j.wang@...> Cc: Ard Biesheuvel <ardb+tianocore@...> Cc: Jordan Justen <jordan.l.justen@...> Cc: Gerd Hoffmann <kraxel@...> Cc: Marc-André Lureau <marcandre.lureau@...> Signed-off-by: Stefan Berger <stefanb@...> --- OvmfPkg/Bhyve/BhyveX64.dsc | 1 + .../PlatformBootManagerLib/BdsPlatform.c | 1 + .../PlatformBootManagerLib.inf | 1 + .../DxeTcgPhysicalPresenceLib.c | 22 + .../DxeTcgPhysicalPresenceLib.inf | 27 + .../DxeTcgPhysicalPresenceLib.c | 481 +++++++++--------- .../DxeTcgPhysicalPresenceLib.inf | 14 +- OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfTpmLibs.dsc.inc | 4 + OvmfPkg/OvmfXen.dsc | 1 + .../Include/Library/TcgPhysicalPresenceLib.h | 39 ++ SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf | 1 + 12 files changed, 342 insertions(+), 251 deletions(-) create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index d8fe607d1c..c848451a2b 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -223,6 +223,7 @@ XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf + TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf [LibraryClasses.common] diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c index 2905356fc4..1765026de2 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -12,6 +12,7 @@ #include <Protocol/FirmwareVolume2.h> #include <Library/PlatformBmPrintScLib.h> #include <Library/Tcg2PhysicalPresenceLib.h> +#include <Library/TcgPhysicalPresenceLib.h> #include <Library/XenPlatformLib.h> diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index c249a3cf1e..f12975d065 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -54,6 +54,7 @@ ReportStatusCodeLib UefiLib PlatformBmPrintScLib + TcgPhysicalPresenceLib Tcg2PhysicalPresenceLib XenPlatformLib diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c new file mode 100644 index 0000000000..d434175717 --- /dev/null +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c @@ -0,0 +1,22 @@ +/** @file + NULL TcgPhysicalPresenceLib library instance + + Copyright (C) 2021, IBM Corporation + Copyright (c) 2018, Red Hat, Inc. + Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/TcgPhysicalPresenceLib.h> + +VOID +EFIAPI +TcgPhysicalPresenceLibProcessRequest ( + VOID + ) +{ + // + // do nothing + // +} diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf new file mode 100644 index 0000000000..4421c6c5b0 --- /dev/null +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf @@ -0,0 +1,27 @@ +# NULL TcgPhysicalPresenceLib library instance +# +# Under SecurityPkg, the corresponding library instance will check and +# execute TPM 1.2 request from OS or BIOS; the request may ask for user +# confirmation before execution. This Null instance implements a no-op +# Tcg2PhysicalPresenceLibProcessRequest(), without user interaction. +# +# Copyright (C) 2018, Red Hat, Inc. +# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxeTcgPhysicalPresenceLibNull + FILE_GUID = B648575C-ED00-4C0D-BD7F-B705B9B0CC93 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = TcgPhysicalPresenceLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER + +[Sources] + DxeTcgPhysicalPresenceLib.c + +[Packages] + MdePkg/MdePkg.dec + SecurityPkg/SecurityPkg.dec diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c index 8a3ae95012..df0d7b5c1a 100644 --- a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c @@ -15,18 +15,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <PiDxe.h> +#include <IndustryStandard/QemuTpm.h> +#include <IndustryStandard/TcgPhysicalPresence.h> + #include <Protocol/TcgService.h> -#include <Protocol/VariableLock.h> +#include <Library/HobLib.h> #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> +#include <Library/DxeServicesTableLib.h> #include <Library/UefiRuntimeServicesTableLib.h> #include <Library/UefiDriverEntryPoint.h> #include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiBootManagerLib.h> #include <Library/UefiLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/PrintLib.h> +#include <Library/QemuFwCfgLib.h> #include <Library/HiiLib.h> -#include <Guid/EventGroup.h> #include <Guid/PhysicalPresenceData.h> #include <Library/TcgPpVendorLib.h> @@ -34,6 +39,168 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_HII_HANDLE mPpStringPackHandle; +STATIC volatile QEMU_TPM_PPI *mPpi; + +#define TPM_PPI_PROVISION_FLAGS(PpiFlags) \ + ((PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) \ + ? QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ \ + : QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ + +#define TPM_PPI_CLEAR_FLAGS(PpiFlags) \ + ((PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0) \ + ? QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ \ + : QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ + +#define TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags) \ + ((PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0 && \ + (PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE) != 0) \ + ? QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ \ + : QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ + +/** + Reads QEMU PPI config from fw_cfg. + + @param[out] The Config structure to read to. + + @retval EFI_SUCCESS Operation completed successfully. + @retval EFI_PROTOCOL_ERROR Invalid fw_cfg entry size. +**/ +STATIC +EFI_STATUS +QemuTpmReadConfig ( + OUT QEMU_FWCFG_TPM_CONFIG *Config + ) +{ + EFI_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + + Status = QemuFwCfgFindFile ("etc/tpm/config", &FwCfgItem, &FwCfgSize); + if (EFI_ERROR (Status)) { + return Status; + } + + if (FwCfgSize != sizeof (*Config)) { + return EFI_PROTOCOL_ERROR; + } + + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (sizeof (*Config), Config); + return EFI_SUCCESS; +} + + +/** + Initilalize the QEMU PPI memory region's function array +**/ +STATIC +VOID +QemuTpmInitPPIFunc( + EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags + ) +{ + ZeroMem ((void *)mPpi->Func, sizeof(mPpi->Func)); + + mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_DISABLE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_ACTIVATE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_DEACTIVATE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_CLEAR_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_DEACTIVATE_DISABLE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_OPERATOR_AUTH] = TPM_PPI_PROVISION_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE] = TPM_PPI_CLEAR_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ; + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ; + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ; + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ; + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ; + mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ; + mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR] = TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE] = TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags); + mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR] = TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags); +} + + +/** + Initializes QEMU PPI memory region. + + @retval EFI_SUCCESS Operation completed successfully. + @retval EFI_PROTOCOL_ERROR PPI address is invalid. +**/ +STATIC +EFI_STATUS +QemuTpmInitPPI ( + VOID + ) +{ + EFI_STATUS Status; + QEMU_FWCFG_TPM_CONFIG Config; + EFI_PHYSICAL_ADDRESS PpiAddress64; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; + EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags; + + if (mPpi != NULL) { + return EFI_SUCCESS; + } + + Status = QemuTpmReadConfig (&Config); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Config.TpmVersion != QEMU_TPM_VERSION_1_2) { + DEBUG ((DEBUG_ERROR, "[TPM] Not setting up PPI. This is not a TPM 1.2.\n")); + return EFI_PROTOCOL_ERROR; + } + + mPpi = (QEMU_TPM_PPI *)(UINTN)Config.PpiAddress; + if (mPpi == NULL) { + return EFI_PROTOCOL_ERROR; + } + + DEBUG ((DEBUG_INFO, "[TPM] mPpi=%p version=%d\n", mPpi, Config.TpmVersion)); + + PpiAddress64 = (UINTN)mPpi; + if ((PpiAddress64 & ~(UINT64)EFI_PAGE_MASK) != + ((PpiAddress64 + sizeof *mPpi - 1) & ~(UINT64)EFI_PAGE_MASK)) { + DEBUG ((DEBUG_ERROR, "[TPM] mPpi crosses a page boundary\n")); + goto InvalidPpiAddress; + } + + Status = gDS->GetMemorySpaceDescriptor (PpiAddress64, &Descriptor); + if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) { + ASSERT_EFI_ERROR (Status); + goto InvalidPpiAddress; + } + if (!EFI_ERROR (Status) && + (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo && + Descriptor.GcdMemoryType != EfiGcdMemoryTypeNonExistent)) { + DEBUG ((DEBUG_ERROR, "[TPM] mPpi has an invalid memory type\n")); + goto InvalidPpiAddress; + } + + PpiFlags.PPFlags = 0; + QemuTpmInitPPIFunc(PpiFlags); + + if (mPpi->In == 0) { + mPpi->In = 1; + mPpi->Request = PHYSICAL_PRESENCE_NO_ACTION; + mPpi->LastRequest = PHYSICAL_PRESENCE_NO_ACTION; + mPpi->NextStep = PHYSICAL_PRESENCE_NO_ACTION; + } + + return EFI_SUCCESS; + +InvalidPpiAddress: + mPpi = NULL; + return EFI_PROTOCOL_ERROR; +} + /** Get string by string id from HII Interface. @@ -506,7 +673,7 @@ TcgPhysicalPresenceLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - mPpStringPackHandle = HiiAddPackages (&gEfiPhysicalPresenceGuid, ImageHandle, DxeTcgPhysicalPresenceLibStrings, NULL); + mPpStringPackHandle = HiiAddPackages (&gEfiPhysicalPresenceGuid, ImageHandle, TcgPhysicalPresenceLibQemuStrings, NULL); ASSERT (mPpStringPackHandle != NULL); return EFI_SUCCESS; @@ -875,6 +1042,10 @@ UserConfirm ( return FALSE; } + // Console for user interaction + // We need to connect all trusted consoles for TCG PP. Here we treat all consoles in OVMF to be trusted consoles. + EfiBootManagerConnectAllDefaultConsoles (); + TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_REJECT_KEY)); BufSize -= StrSize (ConfirmText); UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, TmpStr2); @@ -975,7 +1146,7 @@ HaveValidTpmRequest ( default: if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { - IsRequestValid = TcgPpVendorLibHasValidRequest (TcgPpData->PPRequest, Flags.PPFlags, RequestConfirmed); + IsRequestValid = FALSE; // vendor-specifc commands are not supported if (!IsRequestValid) { return FALSE; } else { @@ -1015,60 +1186,47 @@ HaveValidTpmRequest ( @param[in] Flags The physical presence interface flags. **/ +STATIC VOID ExecutePendingTpmRequest ( IN EFI_TCG_PROTOCOL *TcgProtocol, - IN EFI_PHYSICAL_PRESENCE *TcgPpData, IN EFI_PHYSICAL_PRESENCE_FLAGS Flags ) { EFI_STATUS Status; - UINTN DataSize; BOOLEAN RequestConfirmed; + EFI_PHYSICAL_PRESENCE TcgPpData; EFI_PHYSICAL_PRESENCE_FLAGS NewFlags; - BOOLEAN ResetRequired; - UINT32 NewPPFlags; - if (!HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) { + DEBUG ((DEBUG_INFO, "[TPM] Flags=%x, PPRequest=%x\n", Flags.PPFlags, mPpi->Request)); + + TcgPpData.PPRequest = (UINT8)mPpi->Request; + + if (!HaveValidTpmRequest(&TcgPpData, Flags, &RequestConfirmed)) { // // Invalid operation request. // - TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; - TcgPpData->LastPPRequest = TcgPpData->PPRequest; - TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION; - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->SetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - DataSize, - TcgPpData - ); + mPpi->Response = TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; + mPpi->LastRequest = mPpi->Request; + mPpi->Request = TCG_PHYSICAL_PRESENCE_NO_ACTION; + mPpi->RequestParameter = 0; return; } - ResetRequired = FALSE; - if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { - NewFlags = Flags; - NewPPFlags = NewFlags.PPFlags; - TcgPpData->PPResponse = TcgPpVendorLibExecutePendingRequest (TcgPpData->PPRequest, &NewPPFlags, &ResetRequired); - NewFlags.PPFlags = (UINT8)NewPPFlags; - } else { - if (!RequestConfirmed) { - // - // Print confirm text and wait for approval. - // - RequestConfirmed = UserConfirm (TcgPpData->PPRequest); - } - + if (!RequestConfirmed) { // - // Execute requested physical presence command + // Print confirm text and wait for approval. // - TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_USER_ABORT; - NewFlags = Flags; - if (RequestConfirmed) { - TcgPpData->PPResponse = ExecutePhysicalPresence (TcgProtocol, TcgPpData->PPRequest, &NewFlags); - } + RequestConfirmed = UserConfirm (mPpi->Request); + } + + // + // Execute requested physical presence command + // + mPpi->Response = TCG_PP_OPERATION_RESPONSE_USER_ABORT; + NewFlags = Flags; + if (RequestConfirmed) { + mPpi->Response = ExecutePhysicalPresence (TcgProtocol, mPpi->Request, &NewFlags); } // @@ -1085,39 +1243,32 @@ ExecutePendingTpmRequest ( if (EFI_ERROR (Status)) { return; } + + // + // Update the flags for the commands following PPFlags changes + // + QemuTpmInitPPIFunc(NewFlags); + + DEBUG ((DEBUG_INFO, "[TPM] New PPFlags = %x\n", NewFlags.PPFlags)); } // // Clear request // if ((NewFlags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) { - TcgPpData->LastPPRequest = TcgPpData->PPRequest; - TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION; + mPpi->LastRequest = mPpi->Request; + mPpi->Request = PHYSICAL_PRESENCE_NO_ACTION; + mPpi->RequestParameter = 0; } - // - // Save changes - // - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->SetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - DataSize, - TcgPpData - ); - if (EFI_ERROR (Status)) { - return; - } - - if (TcgPpData->PPResponse == TCG_PP_OPERATION_RESPONSE_USER_ABORT) { + if (mPpi->Response == TCG_PP_OPERATION_RESPONSE_USER_ABORT) { return; } // // Reset system to make new TPM settings in effect // - switch (TcgPpData->LastPPRequest) { + switch (mPpi->LastRequest) { case PHYSICAL_PRESENCE_ACTIVATE: case PHYSICAL_PRESENCE_DEACTIVATE: case PHYSICAL_PRESENCE_CLEAR: @@ -1131,17 +1282,10 @@ ExecutePendingTpmRequest ( case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE: break; default: - if (TcgPpData->LastPPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { - if (ResetRequired) { - break; - } else { - return ; - } - } - if (TcgPpData->PPRequest != PHYSICAL_PRESENCE_NO_ACTION) { - break; - } - return; + if (mPpi->Request != TCG_PHYSICAL_PRESENCE_NO_ACTION) { + break; + } + return; } Print (L"Rebooting system to make TPM settings in effect\n"); @@ -1172,11 +1316,24 @@ TcgPhysicalPresenceLibProcessRequest ( BOOLEAN LifetimeLock; BOOLEAN CmdEnable; UINTN DataSize; - EFI_PHYSICAL_PRESENCE TcgPpData; EFI_TCG_PROTOCOL *TcgProtocol; - EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol; EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags; + Status = QemuTpmInitPPI (); + if (EFI_ERROR (Status)) { + return ; + } + + DEBUG ((DEBUG_INFO, "[TPM] Detected a TPM 1.2\n")); + + // + // Check S4 resume + // + if (GetBootModeHob () == BOOT_ON_S4_RESUME) { + DEBUG ((DEBUG_INFO, "S4 Resume, Skip TPM PP process!\n")); + return ; + } + Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol); if (EFI_ERROR (Status)) { return ; @@ -1209,53 +1366,11 @@ TcgPhysicalPresenceLibProcessRequest ( } DEBUG ((DEBUG_INFO, "[TPM] PpiFlags = %x\n", PpiFlags.PPFlags)); - // - // This flags variable controls whether physical presence is required for TPM command. - // It should be protected from malicious software. We set it as read-only variable here. - // - Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol); - if (!EFI_ERROR (Status)) { - Status = VariableLockProtocol->RequestToLock ( - VariableLockProtocol, - PHYSICAL_PRESENCE_FLAGS_VARIABLE, - &gEfiPhysicalPresenceGuid - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "[TPM] Error when lock variable %s, Status = %r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status)); - ASSERT_EFI_ERROR (Status); - } - } - - // - // Initialize physical presence variable. - // - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->GetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - NULL, - &DataSize, - &TcgPpData - ); - if (EFI_ERROR (Status)) { - ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData)); - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->SetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - DataSize, - &TcgPpData - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "[TPM] Set physical presence variable failed, Status = %r\n", Status)); - return; - } - } + QemuTpmInitPPIFunc(PpiFlags); - DEBUG ((DEBUG_INFO, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags.PPFlags, TcgPpData.PPRequest)); + DEBUG ((DEBUG_INFO, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags.PPFlags, mPpi->Request)); - if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) { + if (mPpi->Request == PHYSICAL_PRESENCE_NO_ACTION) { // // No operation request // @@ -1291,8 +1406,8 @@ TcgPhysicalPresenceLibProcessRequest ( // // Execute pending TPM request. // - ExecutePendingTpmRequest (TcgProtocol, &TcgPpData, PpiFlags); - DEBUG ((DEBUG_INFO, "[TPM] PPResponse = %x\n", TcgPpData.PPResponse)); + ExecutePendingTpmRequest (TcgProtocol, PpiFlags); + DEBUG ((DEBUG_INFO, "[TPM] PPResponse = %x\n", mPpi->Response)); // // Lock physical presence. @@ -1300,104 +1415,6 @@ TcgPhysicalPresenceLibProcessRequest ( TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_NOTPRESENT | TPM_PHYSICAL_PRESENCE_LOCK); } -/** - Check if the pending TPM request needs user input to confirm. - - The TPM request may come from OS. This API will check if TPM request exists and need user - input to confirmation. - - @retval TRUE TPM needs input to confirm user physical presence. - @retval FALSE TPM doesn't need input to confirm user physical presence. - -**/ -BOOLEAN -EFIAPI -TcgPhysicalPresenceLibNeedUserConfirm( - VOID - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_PRESENCE TcgPpData; - UINTN DataSize; - BOOLEAN RequestConfirmed; - BOOLEAN LifetimeLock; - BOOLEAN CmdEnable; - EFI_TCG_PROTOCOL *TcgProtocol; - EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags; - - Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol); - if (EFI_ERROR (Status)) { - return FALSE; - } - - // - // Check Tpm requests - // - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->GetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - NULL, - &DataSize, - &TcgPpData - ); - if (EFI_ERROR (Status)) { - return FALSE; - } - - DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS); - Status = gRT->GetVariable ( - PHYSICAL_PRESENCE_FLAGS_VARIABLE, - &gEfiPhysicalPresenceGuid, - NULL, - &DataSize, - &PpiFlags - ); - if (EFI_ERROR (Status)) { - return FALSE; - } - - if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) { - // - // No operation request - // - return FALSE; - } - - if (!HaveValidTpmRequest(&TcgPpData, PpiFlags, &RequestConfirmed)) { - // - // Invalid operation request. - // - return FALSE; - } - - // - // Check Tpm Capability - // - Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable); - if (EFI_ERROR (Status)) { - return FALSE; - } - - if (!CmdEnable) { - if (LifetimeLock) { - // - // physicalPresenceCMDEnable is locked, can't execute physical presence command. - // - return FALSE; - } - } - - if (!RequestConfirmed) { - // - // Need UI to confirm - // - return TRUE; - } - - return FALSE; -} - /** The handler for TPM physical presence function: Submit TPM Operation Request to Pre-OS Environment and @@ -1416,40 +1433,16 @@ TcgPhysicalPresenceLibSubmitRequestToPreOSFunction ( IN UINT32 OperationRequest ) { - EFI_STATUS Status; - UINTN DataSize; - EFI_PHYSICAL_PRESENCE PpData; + EFI_STATUS Status; DEBUG ((DEBUG_INFO, "[TPM] SubmitRequestToPreOSFunction, Request = %x\n", OperationRequest)); - // - // Get the Physical Presence variable - // - DataSize = sizeof (EFI_PHYSICAL_PRESENCE); - Status = gRT->GetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - NULL, - &DataSize, - &PpData - ); + Status = QemuTpmInitPPI (); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status)); return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; } - PpData.PPRequest = (UINT8)OperationRequest; - Status = gRT->SetVariable ( - PHYSICAL_PRESENCE_VARIABLE, - &gEfiPhysicalPresenceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - DataSize, - &PpData - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "[TPM] Set PP variable failure! Status = %r\n", Status)); - return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE; - } + mPpi->Request = OperationRequest; return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS; } diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf index cfe14f20ca..a7f76d5918 100644 --- a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf @@ -16,9 +16,8 @@ [Defines] INF_VERSION = 0x00010005 - BASE_NAME = DxeTcgPhysicalPresenceLib - MODULE_UNI_FILE = DxeTcgPhysicalPresenceLib.uni - FILE_GUID = EBC43A46-34AC-4F07-A7F5-A5394619361C + BASE_NAME = TcgPhysicalPresenceLibQemu + FILE_GUID = DA5A2055-ACD6-49A1-8277-857f3A47BB0C MODULE_TYPE = DXE_DRIVER VERSION_STRING = 1.0 LIBRARY_CLASS = TcgPhysicalPresenceLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER @@ -37,19 +36,22 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec SecurityPkg/SecurityPkg.dec [LibraryClasses] MemoryAllocationLib + DxeServicesTableLib + HobLib + QemuFwCfgLib + UefiBootManagerLib UefiLib UefiBootServicesTableLib - UefiDriverEntryPoint UefiRuntimeServicesTableLib BaseMemoryLib DebugLib PrintLib HiiLib - TcgPpVendorLib [Protocols] gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES @@ -57,8 +59,6 @@ [Guids] ## SOMETIMES_CONSUMES ## HII - ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence" - ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresence" ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresenceFlags" ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags" gEfiPhysicalPresenceGuid diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 617f925395..5561b17587 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -225,6 +225,7 @@ OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf + TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf [LibraryClasses.common] diff --git a/OvmfPkg/OvmfTpmLibs.dsc.inc b/OvmfPkg/OvmfTpmLibs.dsc.inc index 418747b134..24b54861ed 100644 --- a/OvmfPkg/OvmfTpmLibs.dsc.inc +++ b/OvmfPkg/OvmfTpmLibs.dsc.inc @@ -5,6 +5,9 @@ !if $(TPM2_ENABLE) == TRUE !if $(TPM1_ENABLE) == TRUE Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf + TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf +!else + TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf !endif Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf @@ -13,4 +16,5 @@ !else Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf + TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf !endif diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index a31519e356..82bc3ea4aa 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -215,6 +215,7 @@ XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf + TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf diff --git a/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h b/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h index 9826a79742..6877c08e74 100644 --- a/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h +++ b/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h @@ -45,4 +45,43 @@ TcgPhysicalPresenceLibNeedUserConfirm( VOID ); +/** + The handler for TPM physical presence function: + Return TPM Operation Response to OS Environment. + + This API should be invoked in OS runtime phase to interface with ACPI method. + + @param[out] MostRecentRequest Most recent operation request. + @param[out] Response Response to the most recent operation request. + + @return Return Code for Return TPM Operation Response to OS Environment. +**/ +UINT32 +EFIAPI +Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction ( + OUT UINT32 *MostRecentRequest, + OUT UINT32 *Response + ); + +/** + The handler for TPM physical presence function: + Submit TPM Operation Request to Pre-OS Environment and + Submit TPM Operation Request to Pre-OS Environment 2. + + This API should be invoked in OS runtime phase to interface with ACPI method. + + Caution: This function may receive untrusted input. + + @param[in] OperationRequest TPM physical presence operation request. + @param[in] RequestParameter TPM physical presence operation request parameter. + + @return Return Code for Submit TPM Operation Request to Pre-OS Environment and + Submit TPM Operation Request to Pre-OS Environment 2. +**/ +UINT32 +EFIAPI +TcgPhysicalPresenceLibSubmitRequestToPreOSFunction ( + IN UINT32 OperationRequest + ); + #endif diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf index 24428e050c..b2f36fdbb2 100644 --- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf +++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf @@ -47,6 +47,7 @@ HiiLib PcdLib PrintLib + TcgPhysicalPresenceLib Tpm12DeviceLib [Guids] -- 2.31.1
|
|
[PATCH v3 5/8] OvmfPkg: Copy TPM 1.2 DxeTcgPhysicalPresenceLib.c from SecurityPkg
Stefan Berger
Copy the TPM 1.2 physical presence interface support from SecurityPkg
DxeTcgPhysicalPresenceLib.c along with its .inf and .uni files into OvmfPkg. Fix EFI_F_INFO and EFI_D_ERROR to meet code standards. Signed-off-by: Stefan Berger <stefanb@...> --- .../DxeTcgPhysicalPresenceLib.c | 1455 +++++++++++++++++ .../DxeTcgPhysicalPresenceLib.inf | 64 + .../DxeTcgPhysicalPresenceLib.uni | 22 + .../PhysicalPresenceStrings.uni | 46 + 4 files changed, 1587 insertions(+) create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysic= alPresenceLib.c create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysic= alPresenceLib.inf create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysic= alPresenceLib.uni create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPres= enceStrings.uni diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese= nceLib.c b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenc= eLib.c new file mode 100644 index 0000000000..8a3ae95012 --- /dev/null +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c @@ -0,0 +1,1455 @@ +/** @file=0D +=0D + Execute pending TPM requests from OS or BIOS and Lock TPM.=0D +=0D + Caution: This module requires additional review when modified.=0D + This driver will have external input - variable.=0D + This external input must be validated carefully to avoid security issue.= =0D +=0D + ExecutePendingTpmRequest() will receive untrusted input and do validatio= n.=0D +=0D +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include <PiDxe.h>=0D +=0D +#include <Protocol/TcgService.h>=0D +#include <Protocol/VariableLock.h>=0D +#include <Library/DebugLib.h>=0D +#include <Library/BaseMemoryLib.h>=0D +#include <Library/UefiRuntimeServicesTableLib.h>=0D +#include <Library/UefiDriverEntryPoint.h>=0D +#include <Library/UefiBootServicesTableLib.h>=0D +#include <Library/UefiLib.h>=0D +#include <Library/MemoryAllocationLib.h>=0D +#include <Library/PrintLib.h>=0D +#include <Library/HiiLib.h>=0D +#include <Guid/EventGroup.h>=0D +#include <Guid/PhysicalPresenceData.h>=0D +#include <Library/TcgPpVendorLib.h>=0D +=0D +#define CONFIRM_BUFFER_SIZE 4096=0D +=0D +EFI_HII_HANDLE mPpStringPackHandle;=0D +=0D +/**=0D + Get string by string id from HII Interface.=0D +=0D + @param[in] Id String ID.=0D +=0D + @retval CHAR16 * String from ID.=0D + @retval NULL If error occurs.=0D +=0D +**/=0D +CHAR16 *=0D +PhysicalPresenceGetStringById (=0D + IN EFI_STRING_ID Id=0D + )=0D +{=0D + return HiiGetString (mPpStringPackHandle, Id, NULL);=0D +}=0D +=0D +/**=0D + Get TPM physical presence permanent flags.=0D +=0D + @param[in] TcgProtocol EFI TCG Protocol instance.=0D + @param[out] LifetimeLock physicalPresenceLifetimeLock permanent flag.=0D + @param[out] CmdEnable physicalPresenceCMDEnable permanent flag.=0D +=0D + @retval EFI_SUCCESS Flags were returns successfully.=0D + @retval other Failed to locate EFI TCG Protocol.=0D +=0D +**/=0D +EFI_STATUS=0D +GetTpmCapability (=0D + IN EFI_TCG_PROTOCOL *TcgProtocol,=0D + OUT BOOLEAN *LifetimeLock,=0D + OUT BOOLEAN *CmdEnable=0D + )=0D +{=0D + EFI_STATUS Status;=0D + TPM_RQU_COMMAND_HDR *TpmRqu;=0D + TPM_RSP_COMMAND_HDR *TpmRsp;=0D + UINT32 *SendBufPtr;=0D + UINT8 SendBuffer[sizeof (*TpmRqu) + sizeof (= UINT32) * 3];=0D + TPM_PERMANENT_FLAGS *TpmPermanentFlags;=0D + UINT8 RecvBuffer[40];=0D +=0D + //=0D + // Fill request header=0D + //=0D + TpmRsp =3D (TPM_RSP_COMMAND_HDR*)RecvBuffer;=0D + TpmRqu =3D (TPM_RQU_COMMAND_HDR*)SendBuffer;=0D +=0D + TpmRqu->tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND);=0D + TpmRqu->paramSize =3D SwapBytes32 (sizeof (SendBuffer));=0D + TpmRqu->ordinal =3D SwapBytes32 (TPM_ORD_GetCapability);=0D +=0D + //=0D + // Set request parameter=0D + //=0D + SendBufPtr =3D (UINT32*)(TpmRqu + 1);=0D + WriteUnaligned32 (SendBufPtr++, SwapBytes32 (TPM_CAP_FLAG));=0D + WriteUnaligned32 (SendBufPtr++, SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMAN= ENT)));=0D + WriteUnaligned32 (SendBufPtr, SwapBytes32 (TPM_CAP_FLAG_PERMANENT));=0D +=0D + Status =3D TcgProtocol->PassThroughToTpm (=0D + TcgProtocol,=0D + sizeof (SendBuffer),=0D + (UINT8*)TpmRqu,=0D + sizeof (RecvBuffer),=0D + (UINT8*)&RecvBuffer=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + if ((TpmRsp->tag !=3D SwapBytes16 (TPM_TAG_RSP_COMMAND)) || (TpmRsp->ret= urnCode !=3D 0)) {=0D + return EFI_DEVICE_ERROR;=0D + }=0D +=0D + TpmPermanentFlags =3D (TPM_PERMANENT_FLAGS *)&RecvBuffer[sizeof (TPM_RSP= _COMMAND_HDR) + sizeof (UINT32)];=0D +=0D + if (LifetimeLock !=3D NULL) {=0D + *LifetimeLock =3D TpmPermanentFlags->physicalPresenceLifetimeLock;=0D + }=0D +=0D + if (CmdEnable !=3D NULL) {=0D + *CmdEnable =3D TpmPermanentFlags->physicalPresenceCMDEnable;=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Issue TSC_PhysicalPresence command to TPM.=0D +=0D + @param[in] TcgProtocol EFI TCG Protocol instance.=0D + @param[in] PhysicalPresence The state to set the TPM's Physical Pres= ence flags.=0D +=0D + @retval EFI_SUCCESS TPM executed the command successfully.=0D + @retval EFI_SECURITY_VIOLATION TPM returned error when executing the co= mmand.=0D + @retval other Failed to locate EFI TCG Protocol.=0D +=0D +**/=0D +EFI_STATUS=0D +TpmPhysicalPresence (=0D + IN EFI_TCG_PROTOCOL *TcgProtocol,=0D + IN TPM_PHYSICAL_PRESENCE PhysicalPresence=0D + )=0D +{=0D + EFI_STATUS Status;=0D + TPM_RQU_COMMAND_HDR *TpmRqu;=0D + TPM_PHYSICAL_PRESENCE *TpmPp;=0D + TPM_RSP_COMMAND_HDR TpmRsp;=0D + UINT8 Buffer[sizeof (*TpmRqu) + sizeof (*Tpm= Pp)];=0D +=0D + TpmRqu =3D (TPM_RQU_COMMAND_HDR*)Buffer;=0D + TpmPp =3D (TPM_PHYSICAL_PRESENCE*)(TpmRqu + 1);=0D +=0D + TpmRqu->tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND);=0D + TpmRqu->paramSize =3D SwapBytes32 (sizeof (Buffer));=0D + TpmRqu->ordinal =3D SwapBytes32 (TSC_ORD_PhysicalPresence);=0D + WriteUnaligned16 (TpmPp, (TPM_PHYSICAL_PRESENCE) SwapBytes16 (PhysicalPr= esence));=0D +=0D + Status =3D TcgProtocol->PassThroughToTpm (=0D + TcgProtocol,=0D + sizeof (Buffer),=0D + (UINT8*)TpmRqu,=0D + sizeof (TpmRsp),=0D + (UINT8*)&TpmRsp=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + if (TpmRsp.tag !=3D SwapBytes16 (TPM_TAG_RSP_COMMAND)) {=0D + return EFI_DEVICE_ERROR;=0D + }=0D +=0D + if (TpmRsp.returnCode !=3D 0) {=0D + //=0D + // If it fails, some requirements may be needed for this command.=0D + //=0D + return EFI_SECURITY_VIOLATION;=0D + }=0D +=0D + return Status;=0D +}=0D +=0D +/**=0D + Issue a TPM command for which no additional output data will be returned= .=0D +=0D + @param[in] TcgProtocol EFI TCG Protocol instance.=0D + @param[in] Ordinal TPM command code.=0D + @param[in] AdditionalParameterSize Additional parameter size.=0D + @param[in] AdditionalParameters Pointer to the Additional parameters= .=0D +=0D + @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during se= nding command to TPM or=0D + receiving response from = TPM.=0D + @retval Others Return code from the TPM= device after command execution.=0D +=0D +**/=0D +UINT32=0D +TpmCommandNoReturnData (=0D + IN EFI_TCG_PROTOCOL *TcgProtocol,=0D + IN TPM_COMMAND_CODE Ordinal,=0D + IN UINTN AdditionalParameterSize,=0D + IN VOID *AdditionalParameters=0D + )=0D +{=0D + EFI_STATUS Status;=0D + TPM_RQU_COMMAND_HDR *TpmRqu;=0D + TPM_RSP_COMMAND_HDR TpmRsp;=0D + UINT32 Size;=0D +=0D + TpmRqu =3D (TPM_RQU_COMMAND_HDR*) AllocatePool (sizeof (*TpmRqu) + Addit= ionalParameterSize);=0D + if (TpmRqu =3D=3D NULL) {=0D + return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D + }=0D +=0D + TpmRqu->tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND);=0D + Size =3D (UINT32)(sizeof (*TpmRqu) + AdditionalParameterSiz= e);=0D + TpmRqu->paramSize =3D SwapBytes32 (Size);=0D + TpmRqu->ordinal =3D SwapBytes32 (Ordinal);=0D + CopyMem (TpmRqu + 1, AdditionalParameters, AdditionalParameterSize);=0D +=0D + Status =3D TcgProtocol->PassThroughToTpm (=0D + TcgProtocol,=0D + Size,=0D + (UINT8*)TpmRqu,=0D + (UINT32)sizeof (TpmRsp),=0D + (UINT8*)&TpmRsp=0D + );=0D + FreePool (TpmRqu);=0D + if (EFI_ERROR (Status) || (TpmRsp.tag !=3D SwapBytes16 (TPM_TAG_RSP_COMM= AND))) {=0D + return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D + }=0D + return SwapBytes32 (TpmRsp.returnCode);=0D +}=0D +=0D +/**=0D + Execute physical presence operation requested by the OS.=0D +=0D + @param[in] TcgProtocol EFI TCG Protocol instance.=0D + @param[in] CommandCode Physical presence operation value.=0D + @param[in, out] PpiFlags The physical presence interface flag= s.=0D +=0D + @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Unknown physical presenc= e operation.=0D + @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during se= nding command to TPM or=0D + receiving response from = TPM.=0D + @retval Others Return code from the TPM= device after command execution.=0D +=0D +**/=0D +UINT32=0D +ExecutePhysicalPresence (=0D + IN EFI_TCG_PROTOCOL *TcgProtocol,=0D + IN UINT32 CommandCode,=0D + IN OUT EFI_PHYSICAL_PRESENCE_FLAGS *PpiFlags=0D + )=0D +{=0D + BOOLEAN BoolVal;=0D + UINT32 TpmResponse;=0D + UINT32 InData[5];=0D +=0D + switch (CommandCode) {=0D + case PHYSICAL_PRESENCE_ENABLE:=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_PhysicalEnable,=0D + 0,=0D + NULL=0D + );=0D +=0D + case PHYSICAL_PRESENCE_DISABLE:=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_PhysicalDisable,=0D + 0,=0D + NULL=0D + );=0D +=0D + case PHYSICAL_PRESENCE_ACTIVATE:=0D + BoolVal =3D FALSE;=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_PhysicalSetDeactivated,=0D + sizeof (BoolVal),=0D + &BoolVal=0D + );=0D +=0D + case PHYSICAL_PRESENCE_DEACTIVATE:=0D + BoolVal =3D TRUE;=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_PhysicalSetDeactivated,=0D + sizeof (BoolVal),=0D + &BoolVal=0D + );=0D +=0D + case PHYSICAL_PRESENCE_CLEAR:=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_ForceClear,=0D + 0,=0D + NULL=0D + );=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE= NCE_ENABLE, PpiFlags);=0D + if (TpmResponse =3D=3D 0) {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_ACTIVATE, PpiFlags);=0D + }=0D + return TpmResponse;=0D +=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE= NCE_DEACTIVATE, PpiFlags);=0D + if (TpmResponse =3D=3D 0) {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_DISABLE, PpiFlags);=0D + }=0D + return TpmResponse;=0D +=0D + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:=0D + BoolVal =3D TRUE;=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_SetOwnerInstall,=0D + sizeof (BoolVal),=0D + &BoolVal=0D + );=0D +=0D + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:=0D + BoolVal =3D FALSE;=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_SetOwnerInstall,=0D + sizeof (BoolVal),=0D + &BoolVal=0D + );=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D + //=0D + // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_SET_OWNER_I= NSTALL_TRUE=0D + // PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE will be executed after r= eboot=0D + //=0D + if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) = {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_ENABLE_ACTIVATE, PpiFlags);=0D + PpiFlags->PPFlags |=3D TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D + } else {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_SET_OWNER_INSTALL_TRUE, PpiFlags);=0D + PpiFlags->PPFlags &=3D ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D + }=0D + return TpmResponse;=0D +=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE= NCE_SET_OWNER_INSTALL_FALSE, PpiFlags);=0D + if (TpmResponse =3D=3D 0) {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_DEACTIVATE_DISABLE, PpiFlags);=0D + }=0D + return TpmResponse;=0D +=0D + case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D + InData[0] =3D SwapBytes32 (TPM_SET_STCLEAR_DATA); // Capa= bilityArea=0D + InData[1] =3D SwapBytes32 (sizeof(UINT32)); // SubC= apSize=0D + InData[2] =3D SwapBytes32 (TPM_SD_DEFERREDPHYSICALPRESENCE); // SubC= ap=0D + InData[3] =3D SwapBytes32 (sizeof(UINT32)); // SetV= alueSize=0D + InData[4] =3D SwapBytes32 (1); // Unow= nedFieldUpgrade; bit0=0D + return TpmCommandNoReturnData (=0D + TcgProtocol,=0D + TPM_ORD_SetCapability,=0D + sizeof (UINT32) * 5,=0D + InData=0D + );=0D +=0D + case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:=0D + //=0D + // TPM_SetOperatorAuth=0D + // This command requires UI to prompt user for Auth data=0D + // Here it is NOT implemented=0D + //=0D + return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D +=0D + case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE= NCE_CLEAR, PpiFlags);=0D + if (TpmResponse =3D=3D 0) {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_ENABLE_ACTIVATE, PpiFlags);=0D + }=0D + return TpmResponse;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:=0D + PpiFlags->PPFlags &=3D ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISIO= N;=0D + return 0;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:=0D + PpiFlags->PPFlags |=3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION= ;=0D + return 0;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:=0D + PpiFlags->PPFlags &=3D ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR;=0D + return 0;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:=0D + PpiFlags->PPFlags |=3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR;=0D + return 0;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:=0D + PpiFlags->PPFlags &=3D ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENA= NCE;=0D + return 0;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:=0D + PpiFlags->PPFlags |=3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENAN= CE;=0D + return 0;=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D + //=0D + // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR=0D + // PHYSICAL_PRESENCE_CLEAR will be executed after reboot.=0D + //=0D + if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) = {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_ENABLE_ACTIVATE, PpiFlags);=0D + PpiFlags->PPFlags |=3D TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D + } else {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_CLEAR, PpiFlags);=0D + PpiFlags->PPFlags &=3D ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D + }=0D + return TpmResponse;=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D + //=0D + // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR_ENABL= E_ACTIVATE=0D + // PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE will be executed after re= boot.=0D + //=0D + if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) = {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_ENABLE_ACTIVATE, PpiFlags);=0D + PpiFlags->PPFlags |=3D TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D + } else {=0D + TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE= SENCE_CLEAR_ENABLE_ACTIVATE, PpiFlags);=0D + PpiFlags->PPFlags &=3D ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D + }=0D + return TpmResponse;=0D +=0D + default:=0D + ;=0D + }=0D + return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D +}=0D +=0D +=0D +/**=0D + Read the specified key for user confirmation.=0D +=0D + @param[in] CautionKey If true, F12 is used as confirm key;=0D + If false, F10 is used as confirm key.=0D +=0D + @retval TRUE User confirmed the changes by input.=0D + @retval FALSE User discarded the changes or device error.=0D +=0D +**/=0D +BOOLEAN=0D +ReadUserKey (=0D + IN BOOLEAN CautionKey=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_INPUT_KEY Key;=0D + UINT16 InputKey;=0D + UINTN Index;=0D +=0D + InputKey =3D 0;=0D + do {=0D + Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);=0D + if (Status =3D=3D EFI_NOT_READY) {=0D + gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);=0D + continue;=0D + }=0D +=0D + if (Status =3D=3D EFI_DEVICE_ERROR) {=0D + return FALSE;=0D + }=0D +=0D + if (Key.ScanCode =3D=3D SCAN_ESC) {=0D + InputKey =3D Key.ScanCode;=0D + }=0D + if ((Key.ScanCode =3D=3D SCAN_F10) && !CautionKey) {=0D + InputKey =3D Key.ScanCode;=0D + }=0D + if ((Key.ScanCode =3D=3D SCAN_F12) && CautionKey) {=0D + InputKey =3D Key.ScanCode;=0D + }=0D + } while (InputKey =3D=3D 0);=0D +=0D + if (InputKey !=3D SCAN_ESC) {=0D + return TRUE;=0D + }=0D +=0D + return FALSE;=0D +}=0D +=0D +/**=0D + The constructor function register UNI strings into imageHandle.=0D +=0D + It will ASSERT() if that operation fails and it will always return EFI_S= UCCESS.=0D +=0D + @param ImageHandle The firmware allocated handle for the EFI image.=0D + @param SystemTable A pointer to the EFI System Table.=0D +=0D + @retval EFI_SUCCESS The constructor successfully added string package.= =0D + @retval Other value The constructor can't add string package.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +TcgPhysicalPresenceLibConstructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + mPpStringPackHandle =3D HiiAddPackages (&gEfiPhysicalPresenceGuid, Image= Handle, DxeTcgPhysicalPresenceLibStrings, NULL);=0D + ASSERT (mPpStringPackHandle !=3D NULL);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +/**=0D + Display the confirm text and get user confirmation.=0D +=0D + @param[in] TpmPpCommand The requested TPM physical presence command.=0D +=0D + @retval TRUE The user has confirmed the changes.=0D + @retval FALSE The user doesn't confirm the changes.=0D +**/=0D +BOOLEAN=0D +UserConfirm (=0D + IN UINT32 TpmPpCommand=0D + )=0D +{=0D + CHAR16 *ConfirmText;=0D + CHAR16 *TmpStr1;=0D + CHAR16 *TmpStr2;=0D + UINTN BufSize;=0D + BOOLEAN CautionKey;=0D + UINT16 Index;=0D + CHAR16 DstStr[81];=0D +=0D + TmpStr2 =3D NULL;=0D + CautionKey =3D FALSE;=0D + BufSize =3D CONFIRM_BUFFER_SIZE;=0D + ConfirmText =3D AllocateZeroPool (BufSize);=0D + ASSERT (ConfirmText !=3D NULL);=0D +=0D + switch (TpmPpCommand) {=0D + case PHYSICAL_PRESENCE_ENABLE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE)= );=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_DISABLE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISABLE= ));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_ACTIVATE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACTIVAT= E));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_DEACTIVATE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIV= ATE));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_CLEAR:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR))= ;=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize= / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_= ACTIVATE));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIV= ATE_DISABLE));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OF= F));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ALLOW_T= AKE_OWNERSHIP));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISALLO= W_TAKE_OWNERSHIP));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_ON= ));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_OF= F));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OF= F));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UNOWNED= _FIELD_UPGRADE));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UPGRADE= _HEAD_STR));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _MAINTAIN));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:=0D + //=0D + // TPM_SetOperatorAuth=0D + // This command requires UI to prompt user for Auth data=0D + // Here it is NOT implemented=0D + //=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR_T= URN_ON));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR_CONT));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_= PROVISION));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEA= D_STR));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_= KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_= INFO));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR))= ;=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEA= D_STR));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CL= EAR));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize= / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_= INFO));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_= MAINTAIN));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEA= D_STR));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _MAINTAIN));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_= INFO));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_= ACTIVATE_CLEAR));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize= / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D + CautionKey =3D TRUE;=0D + TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_= ACTIVATE_CLEAR_ENABLE_ACTIVATE));=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST= R));=0D + UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON= ));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING= _CLEAR_CONT));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION= _KEY));=0D + StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize = / sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D + FreePool (TmpStr1);=0D + break;=0D +=0D + default:=0D + ;=0D + }=0D +=0D + if (TmpStr2 =3D=3D NULL) {=0D + FreePool (ConfirmText);=0D + return FALSE;=0D + }=0D +=0D + TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_REJECT_KEY)= );=0D + BufSize -=3D StrSize (ConfirmText);=0D + UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, Tmp= Str2);=0D +=0D + DstStr[80] =3D L'\0';=0D + for (Index =3D 0; Index < StrLen (ConfirmText); Index +=3D 80) {=0D + StrnCpyS(DstStr, sizeof (DstStr) / sizeof (CHAR16), ConfirmText + Inde= x, sizeof (DstStr) / sizeof (CHAR16) - 1);=0D + Print (DstStr);=0D + }=0D +=0D + FreePool (TmpStr1);=0D + FreePool (TmpStr2);=0D + FreePool (ConfirmText);=0D +=0D + if (ReadUserKey (CautionKey)) {=0D + return TRUE;=0D + }=0D +=0D + return FALSE;=0D +}=0D +=0D +/**=0D + Check if there is a valid physical presence command request. Also update= s parameter value=0D + to whether the requested physical presence command already confirmed by = user=0D +=0D + @param[in] TcgPpData EFI TCG Physical Presence request data.= =0D + @param[in] Flags The physical presence interface flags.= =0D + @param[out] RequestConfirmed If the physical presence operation comm= and required user confirm from UI.=0D + True, it indicates the command doesn't = require user confirm, or already confirmed=0D + in last boot cycle by user.=0D + False, it indicates the command need us= er confirm from UI.=0D +=0D + @retval TRUE Physical Presence operation command is valid.=0D + @retval FALSE Physical Presence operation command is invalid.=0D +=0D +**/=0D +BOOLEAN=0D +HaveValidTpmRequest (=0D + IN EFI_PHYSICAL_PRESENCE *TcgPpData,=0D + IN EFI_PHYSICAL_PRESENCE_FLAGS Flags,=0D + OUT BOOLEAN *RequestConfirmed=0D + )=0D +{=0D + BOOLEAN IsRequestValid;=0D +=0D + *RequestConfirmed =3D FALSE;=0D +=0D + switch (TcgPpData->PPRequest) {=0D + case PHYSICAL_PRESENCE_NO_ACTION:=0D + *RequestConfirmed =3D TRUE;=0D + return TRUE;=0D + case PHYSICAL_PRESENCE_ENABLE:=0D + case PHYSICAL_PRESENCE_DISABLE:=0D + case PHYSICAL_PRESENCE_ACTIVATE:=0D + case PHYSICAL_PRESENCE_DEACTIVATE:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:=0D + case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D + case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:=0D + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) = !=3D 0) {=0D + *RequestConfirmed =3D TRUE;=0D + }=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_CLEAR:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) !=3D= 0) {=0D + *RequestConfirmed =3D TRUE;=0D + }=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE= ) !=3D 0) {=0D + *RequestConfirmed =3D TRUE;=0D + }=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D + if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) !=3D= 0 && (Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) !=3D = 0) {=0D + *RequestConfirmed =3D TRUE;=0D + }=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:=0D + *RequestConfirmed =3D TRUE;=0D + break;=0D +=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:=0D + case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:=0D + break;=0D +=0D + default:=0D + if (TcgPpData->PPRequest >=3D TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_= OPERATION) {=0D + IsRequestValid =3D TcgPpVendorLibHasValidRequest (TcgPpData->PPReq= uest, Flags.PPFlags, RequestConfirmed);=0D + if (!IsRequestValid) {=0D + return FALSE;=0D + } else {=0D + break;=0D + }=0D + } else {=0D + //=0D + // Wrong Physical Presence command=0D + //=0D + return FALSE;=0D + }=0D + }=0D +=0D + if ((Flags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) !=3D 0) {=0D + //=0D + // It had been confirmed in last boot, it doesn't need confirm again.= =0D + //=0D + *RequestConfirmed =3D TRUE;=0D + }=0D +=0D + //=0D + // Physical Presence command is correct=0D + //=0D + return TRUE;=0D +}=0D +=0D +=0D +/**=0D + Check and execute the requested physical presence command.=0D +=0D + Caution: This function may receive untrusted input.=0D + TcgPpData variable is external input, so this function will validate=0D + its data structure to be valid value.=0D +=0D + @param[in] TcgProtocol EFI TCG Protocol instance.=0D + @param[in] TcgPpData Point to the physical presence NV variab= le.=0D + @param[in] Flags The physical presence interface flags.=0D +=0D +**/=0D +VOID=0D +ExecutePendingTpmRequest (=0D + IN EFI_TCG_PROTOCOL *TcgProtocol,=0D + IN EFI_PHYSICAL_PRESENCE *TcgPpData,=0D + IN EFI_PHYSICAL_PRESENCE_FLAGS Flags=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN DataSize;=0D + BOOLEAN RequestConfirmed;=0D + EFI_PHYSICAL_PRESENCE_FLAGS NewFlags;=0D + BOOLEAN ResetRequired;=0D + UINT32 NewPPFlags;=0D +=0D + if (!HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) {=0D + //=0D + // Invalid operation request.=0D + //=0D + TcgPpData->PPResponse =3D TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D + TcgPpData->LastPPRequest =3D TcgPpData->PPRequest;=0D + TcgPpData->PPRequest =3D PHYSICAL_PRESENCE_NO_ACTION;=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D + Status =3D gRT->SetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A= CCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D + DataSize,=0D + TcgPpData=0D + );=0D + return;=0D + }=0D +=0D + ResetRequired =3D FALSE;=0D + if (TcgPpData->PPRequest >=3D TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPER= ATION) {=0D + NewFlags =3D Flags;=0D + NewPPFlags =3D NewFlags.PPFlags;=0D + TcgPpData->PPResponse =3D TcgPpVendorLibExecutePendingRequest (TcgPpDa= ta->PPRequest, &NewPPFlags, &ResetRequired);=0D + NewFlags.PPFlags =3D (UINT8)NewPPFlags;=0D + } else {=0D + if (!RequestConfirmed) {=0D + //=0D + // Print confirm text and wait for approval.=0D + //=0D + RequestConfirmed =3D UserConfirm (TcgPpData->PPRequest);=0D + }=0D +=0D + //=0D + // Execute requested physical presence command=0D + //=0D + TcgPpData->PPResponse =3D TCG_PP_OPERATION_RESPONSE_USER_ABORT;=0D + NewFlags =3D Flags;=0D + if (RequestConfirmed) {=0D + TcgPpData->PPResponse =3D ExecutePhysicalPresence (TcgProtocol, TcgP= pData->PPRequest, &NewFlags);=0D + }=0D + }=0D +=0D + //=0D + // Save the flags if it is updated.=0D + //=0D + if (CompareMem (&Flags, &NewFlags, sizeof(EFI_PHYSICAL_PRESENCE_FLAGS)) = !=3D 0) {=0D + Status =3D gRT->SetVariable (=0D + PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE= _ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D + sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),=0D + &NewFlags=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return;=0D + }=0D + }=0D +=0D + //=0D + // Clear request=0D + //=0D + if ((NewFlags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) {=0D + TcgPpData->LastPPRequest =3D TcgPpData->PPRequest;=0D + TcgPpData->PPRequest =3D PHYSICAL_PRESENCE_NO_ACTION;=0D + }=0D +=0D + //=0D + // Save changes=0D + //=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D + Status =3D gRT->SetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACC= ESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D + DataSize,=0D + TcgPpData=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return;=0D + }=0D +=0D + if (TcgPpData->PPResponse =3D=3D TCG_PP_OPERATION_RESPONSE_USER_ABORT) {= =0D + return;=0D + }=0D +=0D + //=0D + // Reset system to make new TPM settings in effect=0D + //=0D + switch (TcgPpData->LastPPRequest) {=0D + case PHYSICAL_PRESENCE_ACTIVATE:=0D + case PHYSICAL_PRESENCE_DEACTIVATE:=0D + case PHYSICAL_PRESENCE_CLEAR:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D + case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D + case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D + case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D + case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D + break;=0D + default:=0D + if (TcgPpData->LastPPRequest >=3D TCG_PHYSICAL_PRESENCE_VENDOR_SPECI= FIC_OPERATION) {=0D + if (ResetRequired) {=0D + break;=0D + } else {=0D + return ;=0D + }=0D + }=0D + if (TcgPpData->PPRequest !=3D PHYSICAL_PRESENCE_NO_ACTION) {=0D + break;=0D + }=0D + return;=0D + }=0D +=0D + Print (L"Rebooting system to make TPM settings in effect\n");=0D + gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);=0D + ASSERT (FALSE);=0D +}=0D +=0D +/**=0D + Check and execute the pending TPM request and Lock TPM.=0D +=0D + The TPM request may come from OS or BIOS. This API will display request = information and wait=0D + for user confirmation if TPM request exists. The TPM request will be sen= t to TPM device after=0D + the TPM request is confirmed, and one or more reset may be required to m= ake TPM request to=0D + take effect. At last, it will lock TPM to prevent TPM state change by ma= lware.=0D +=0D + This API should be invoked after console in and console out are all read= y as they are required=0D + to display request information and get user input to confirm the request= . This API should also=0D + be invoked as early as possible as TPM is locked in this function.=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +TcgPhysicalPresenceLibProcessRequest (=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + BOOLEAN LifetimeLock;=0D + BOOLEAN CmdEnable;=0D + UINTN DataSize;=0D + EFI_PHYSICAL_PRESENCE TcgPpData;=0D + EFI_TCG_PROTOCOL *TcgProtocol;=0D + EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol;=0D + EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;=0D +=0D + Status =3D gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&Tc= gProtocol);=0D + if (EFI_ERROR (Status)) {=0D + return ;=0D + }=0D +=0D + //=0D + // Initialize physical presence flags.=0D + //=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);=0D + Status =3D gRT->GetVariable (=0D + PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + NULL,=0D + &DataSize,=0D + &PpiFlags=0D + );=0D + if (EFI_ERROR (Status)) {=0D + PpiFlags.PPFlags =3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION;=0D + Status =3D gRT->SetVariable (=0D + PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE= _ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D + sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),=0D + &PpiFlags=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "[TPM] Set physical presence flag failed, Statu= s =3D %r\n", Status));=0D + return ;=0D + }=0D + }=0D + DEBUG ((DEBUG_INFO, "[TPM] PpiFlags =3D %x\n", PpiFlags.PPFlags));=0D +=0D + //=0D + // This flags variable controls whether physical presence is required fo= r TPM command.=0D + // It should be protected from malicious software. We set it as read-onl= y variable here.=0D + //=0D + Status =3D gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (= VOID **)&VariableLockProtocol);=0D + if (!EFI_ERROR (Status)) {=0D + Status =3D VariableLockProtocol->RequestToLock (=0D + VariableLockProtocol,=0D + PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D + &gEfiPhysicalPresenceGuid=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "[TPM] Error when lock variable %s, Status =3D = %r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status));=0D + ASSERT_EFI_ERROR (Status);=0D + }=0D + }=0D +=0D + //=0D + // Initialize physical presence variable.=0D + //=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D + Status =3D gRT->GetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + NULL,=0D + &DataSize,=0D + &TcgPpData=0D + );=0D + if (EFI_ERROR (Status)) {=0D + ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData));=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D + Status =3D gRT->SetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE= _ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D + DataSize,=0D + &TcgPpData=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "[TPM] Set physical presence variable failed, S= tatus =3D %r\n", Status));=0D + return;=0D + }=0D + }=0D +=0D + DEBUG ((DEBUG_INFO, "[TPM] Flags=3D%x, PPRequest=3D%x\n", PpiFlags.PPFla= gs, TcgPpData.PPRequest));=0D +=0D + if (TcgPpData.PPRequest =3D=3D PHYSICAL_PRESENCE_NO_ACTION) {=0D + //=0D + // No operation request=0D + //=0D + return;=0D + }=0D +=0D + Status =3D GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);=0D + if (EFI_ERROR (Status)) {=0D + return ;=0D + }=0D +=0D + if (!CmdEnable) {=0D + if (LifetimeLock) {=0D + //=0D + // physicalPresenceCMDEnable is locked, can't execute physical prese= nce command.=0D + //=0D + return ;=0D + }=0D + Status =3D TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_CMD= _ENABLE);=0D + if (EFI_ERROR (Status)) {=0D + return ;=0D + }=0D + }=0D +=0D + //=0D + // Set operator physical presence flags=0D + //=0D + Status =3D TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_PRESE= NT);=0D + if (EFI_ERROR (Status)) {=0D + return;=0D + }=0D +=0D + //=0D + // Execute pending TPM request.=0D + //=0D + ExecutePendingTpmRequest (TcgProtocol, &TcgPpData, PpiFlags);=0D + DEBUG ((DEBUG_INFO, "[TPM] PPResponse =3D %x\n", TcgPpData.PPResponse));= =0D +=0D + //=0D + // Lock physical presence.=0D + //=0D + TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_NOTPRESENT | TPM= _PHYSICAL_PRESENCE_LOCK);=0D +}=0D +=0D +/**=0D + Check if the pending TPM request needs user input to confirm.=0D +=0D + The TPM request may come from OS. This API will check if TPM request exi= sts and need user=0D + input to confirmation.=0D +=0D + @retval TRUE TPM needs input to confirm user physical presence= .=0D + @retval FALSE TPM doesn't need input to confirm user physical p= resence.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +TcgPhysicalPresenceLibNeedUserConfirm(=0D + VOID=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_PHYSICAL_PRESENCE TcgPpData;=0D + UINTN DataSize;=0D + BOOLEAN RequestConfirmed;=0D + BOOLEAN LifetimeLock;=0D + BOOLEAN CmdEnable;=0D + EFI_TCG_PROTOCOL *TcgProtocol;=0D + EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;=0D +=0D + Status =3D gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&Tc= gProtocol);=0D + if (EFI_ERROR (Status)) {=0D + return FALSE;=0D + }=0D +=0D + //=0D + // Check Tpm requests=0D + //=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D + Status =3D gRT->GetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + NULL,=0D + &DataSize,=0D + &TcgPpData=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return FALSE;=0D + }=0D +=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);=0D + Status =3D gRT->GetVariable (=0D + PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + NULL,=0D + &DataSize,=0D + &PpiFlags=0D + );=0D + if (EFI_ERROR (Status)) {=0D + return FALSE;=0D + }=0D +=0D + if (TcgPpData.PPRequest =3D=3D PHYSICAL_PRESENCE_NO_ACTION) {=0D + //=0D + // No operation request=0D + //=0D + return FALSE;=0D + }=0D +=0D + if (!HaveValidTpmRequest(&TcgPpData, PpiFlags, &RequestConfirmed)) {=0D + //=0D + // Invalid operation request.=0D + //=0D + return FALSE;=0D + }=0D +=0D + //=0D + // Check Tpm Capability=0D + //=0D + Status =3D GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);=0D + if (EFI_ERROR (Status)) {=0D + return FALSE;=0D + }=0D +=0D + if (!CmdEnable) {=0D + if (LifetimeLock) {=0D + //=0D + // physicalPresenceCMDEnable is locked, can't execute physical prese= nce command.=0D + //=0D + return FALSE;=0D + }=0D + }=0D +=0D + if (!RequestConfirmed) {=0D + //=0D + // Need UI to confirm=0D + //=0D + return TRUE;=0D + }=0D +=0D + return FALSE;=0D +}=0D +=0D +/**=0D + The handler for TPM physical presence function:=0D + Submit TPM Operation Request to Pre-OS Environment and=0D + Submit TPM Operation Request to Pre-OS Environment 2.=0D +=0D + Caution: This function may receive untrusted input.=0D +=0D + @param[in] OperationRequest TPM physical presence operation request= .=0D +=0D + @return Return Code for Submit TPM Operation Request to Pre-OS Environme= nt and=0D + Submit TPM Operation Request to Pre-OS Environment 2.=0D +**/=0D +UINT32=0D +EFIAPI=0D +TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (=0D + IN UINT32 OperationRequest=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN DataSize;=0D + EFI_PHYSICAL_PRESENCE PpData;=0D +=0D + DEBUG ((DEBUG_INFO, "[TPM] SubmitRequestToPreOSFunction, Request =3D %x\= n", OperationRequest));=0D +=0D + //=0D + // Get the Physical Presence variable=0D + //=0D + DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D + Status =3D gRT->GetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + NULL,=0D + &DataSize,=0D + &PpData=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "[TPM] Get PP variable failure! Status =3D %r\n",= Status));=0D + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;=0D + }=0D +=0D + PpData.PPRequest =3D (UINT8)OperationRequest;=0D + Status =3D gRT->SetVariable (=0D + PHYSICAL_PRESENCE_VARIABLE,=0D + &gEfiPhysicalPresenceGuid,=0D + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A= CCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D + DataSize,=0D + &PpData=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "[TPM] Set PP variable failure! Status =3D %r\n",= Status));=0D + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;=0D + }=0D +=0D + return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;=0D +}=0D diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese= nceLib.inf b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese= nceLib.inf new file mode 100644 index 0000000000..cfe14f20ca --- /dev/null +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.= inf @@ -0,0 +1,64 @@ +## @file=0D +# Executes pending TPM 1.2 requests from OS or BIOS and Locks TPM=0D +#=0D +# This library will check and execute TPM 1.2 request from OS or BIOS. Th= e request may=0D +# ask for user confirmation before execution. This Library will also lock= TPM physical=0D +# presence at last.=0D +#=0D +# Caution: This module requires additional review when modified.=0D +# This driver will have external input - variable.=0D +# This external input must be validated carefully to avoid security issue= .=0D +#=0D +# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D DxeTcgPhysicalPresenceLib=0D + MODULE_UNI_FILE =3D DxeTcgPhysicalPresenceLib.uni=0D + FILE_GUID =3D EBC43A46-34AC-4F07-A7F5-A5394619361C= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TcgPhysicalPresenceLib|DXE_DRIVER DXE= _RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER=0D + CONSTRUCTOR =3D TcgPhysicalPresenceLibConstructor=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 EBC=0D +#=0D +=0D +[Sources]=0D + DxeTcgPhysicalPresenceLib.c=0D + PhysicalPresenceStrings.uni=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + SecurityPkg/SecurityPkg.dec=0D +=0D +[LibraryClasses]=0D + MemoryAllocationLib=0D + UefiLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D + UefiRuntimeServicesTableLib=0D + BaseMemoryLib=0D + DebugLib=0D + PrintLib=0D + HiiLib=0D + TcgPpVendorLib=0D +=0D +[Protocols]=0D + gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES=0D + gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES=0D +=0D +[Guids]=0D + ## SOMETIMES_CONSUMES ## HII=0D + ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"=0D + ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresence"=0D + ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresenceFlags"=0D + ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"=0D + gEfiPhysicalPresenceGuid=0D diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese= nceLib.uni b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese= nceLib.uni new file mode 100644 index 0000000000..c7fcca5c65 --- /dev/null +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.= uni @@ -0,0 +1,22 @@ +// /** @file=0D +// Executes pending TPM 1.2 requests from OS or BIOS and Locks TPM=0D +//=0D +// This library will check and execute TPM 1.2 request from OS or BIOS. Th= e request may=0D +// ask for user confirmation before execution. This Library will also lock= TPM physical=0D +// presence at last.=0D +//=0D +// Caution: This module requires additional review when modified.=0D +// This driver will have external input - variable.=0D +// This external input must be validated carefully to avoid security issue= .=0D +//=0D +// Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>= =0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Executes pending = TPM 1.2 requests from OS or BIOS and Locks TPM"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "This library will= ask for user confirmation for the pending TPM physical present requests. O= nce confirmed, it will execute the request, and locks TPM physical presence= at last. Caution: This module requires additional review when modified. Th= is driver will have external input - variable. This external input must be = validated carefully to avoid security issue."=0D +=0D diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStr= ings.uni b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStrin= gs.uni new file mode 100644 index 0000000000..9d17432ef8 --- /dev/null +++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStrings.uni @@ -0,0 +1,46 @@ +/** @file=0D + String definitions for TPM 1.2 physical presence confirm text.=0D +=0D +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D +(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#langdef en-US "English"=0D +=0D +#string TPM_HEAD_STR #language en-US "A configuration = change was requested to %s this computer's TPM (Trusted Platform Module)\n\= n"=0D +#string TPM_PPI_HEAD_STR #language en-US "A configuration = change was requested to allow the Operating System to %s the computer's TPM= (Trusted Platform Module) without asking for user confirmation in the futu= re.\n\n"=0D +#string TPM_UPGRADE_HEAD_STR #language en-US "A configuration = change was requested to %s to the TPM's (Trusted Platform Module) firmware.= \n\n"=0D +=0D +#string TPM_ACCEPT_KEY #language en-US "Press F10 "=0D +#string TPM_CAUTION_KEY #language en-US "Press F12 "=0D +#string TPM_REJECT_KEY #language en-US "to %s the TPM \n= Press ESC to reject this change request and continue\n"=0D +=0D +#string TPM_ENABLE #language en-US "enable"=0D +#string TPM_DISABLE #language en-US "disable"=0D +#string TPM_ACTIVATE #language en-US "activate"=0D +#string TPM_DEACTIVATE #language en-US "deactivate"=0D +#string TPM_CLEAR #language en-US "clear"=0D +#string TPM_ENABLE_ACTIVATE #language en-US "enable and activ= ate"=0D +#string TPM_DEACTIVATE_DISABLE #language en-US "deactivate and d= isable"=0D +#string TPM_ALLOW_TAKE_OWNERSHIP #language en-US "allow a user to = take ownership of"=0D +#string TPM_DISALLOW_TAKE_OWNERSHIP #language en-US "disallow a user = to take ownership of"=0D +#string TPM_TURN_ON #language en-US "enable, activate= , and allow a user to take ownership of"=0D +#string TPM_TURN_OFF #language en-US "deactivate, disa= ble, and disallow a user to take ownership of"=0D +#string TPM_CLEAR_TURN_ON #language en-US "clear, enable, a= nd activate"=0D +#string TPM_ENABLE_ACTIVATE_CLEAR #language en-US "enable, activate= and clear"=0D +#string TPM_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE #language en-US = "enable, activate, clear, enable, and activate"=0D +#string TPM_UNOWNED_FIELD_UPGRADE #language en-US "allow field upgr= ade"=0D +=0D +#string TPM_NO_PPI_PROVISION #language en-US "provision"=0D +#string TPM_NO_PPI_MAINTAIN #language en-US "maintain"=0D +#string TPM_NO_PPI_INFO #language en-US "to approve futur= e Operating System requests "=0D +=0D +#string TPM_WARNING_MAINTAIN #language en-US "WARNING: Allowin= g changes to the TPM's firmware may affect the operation of the TPM and may= erase information stored on the TPM.\nYou may lose all created keys and ac= cess to data encrypted by these keys.\n\n"=0D +#string TPM_WARNING #language en-US "WARNING: Doing s= o might prevent security applications that rely on the TPM from functioning= as expected\n\n"=0D +#string TPM_WARNING_CLEAR #language en-US "WARNING: Clearin= g erases information stored on the TPM. You will lose all created keys and = access to data encrypted by these keys. "=0D +#string TPM_WARNING_CLEAR_CONT #language en-US "Take ownership a= s soon as possible after this step.\n\n"=0D +#string TPM_NOTE_OFF #language en-US "NOTE: This actio= n will turn off the TPM\n\n"=0D +#string TPM_NOTE_ON #language en-US "NOTE: This actio= n will turn on the TPM\n\n"=0D +#string TPM_NOTE_CLEAR #language en-US "NOTE: This actio= n does not clear the TPM, but by approving this configuration change, futur= e actions to clear the TPM will not require user confirmation.\n\n"=0D --=20 2.31.1
|
|
[PATCH v3 0/8] Add support for TPM 1.2 Physical Presence Interface and Menu
Stefan Berger
This series adds support for the full TPM 1.2 Physical Presence Interface
(PPI) and activates the TPM 1.2 menu at the end. PPI is a prerequisite for the menu to work. The modifications to the original code are mostly due to the fact that we are using a memory region for PPI in QEMU. I tried to keep them at a minimum. For the PPI Flags I am using a EFI variable just like the original code does. (SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c) The PhysicalPresenceFlags variable is write-protected (since v3) by adding an entry to AuthVariableLib.c. The consequence of locking the variable is that the processing of the physical presence opcodes, and with that write-access to that variable, had to be moved to before the end-of-DXE because afterwards it cannot be changed anymore. Regards, Stefan v3: - Moved processing of physical presence opcodes to before end-of-DXE - Write-protected PhysicalPresenceFlags variable by entry in AuthVariableLib.c v2: - Added patch that copies sources from SecurityPkg to OvmfPkg before changes - Use CONSTRUCTOR from DxeTcgPhysicalPresenceLib.inf - Other nits Gerd Hoffmann (1): OvmfPkg: add TPM 1.2 config menu Stefan Berger (7): OvmfPkg: Move processing of physical presence opcode before End-of-Dxe OvmfPkg: Check for TPM 2 early to leave function early SecurityPkg: Store physical presence code by submitting to PreOS func SecurityPkg: Declare PhysicalPresenceFlags variable and its properties OvmfPkg: Copy TPM 1.2 DxeTcgPhysicalPresenceLib.c from SecurityPkg OvmfPkg: Enable physical presence interface for TPM 1.2 OvmfPkg: Enable TPM 1.2 Physical Presence Opcode processing OvmfPkg/Bhyve/BhyveX64.dsc | 1 + .../PlatformBootManagerLib/BdsPlatform.c | 23 +- .../PlatformBootManagerLib.inf | 1 + .../PlatformBootManagerLibBhyve/BdsPlatform.c | 20 +- .../PlatformBootManagerLibGrub/BdsPlatform.c | 20 +- .../DxeTcg2PhysicalPresenceLib.c | 36 +- .../DxeTcgPhysicalPresenceLib.c | 22 + .../DxeTcgPhysicalPresenceLib.inf | 27 + .../DxeTcgPhysicalPresenceLib.c | 1448 +++++++++++++++++ .../DxeTcgPhysicalPresenceLib.inf | 64 + .../DxeTcgPhysicalPresenceLib.uni | 22 + .../PhysicalPresenceStrings.uni | 46 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfTpmComponentsDxe.dsc.inc | 1 + OvmfPkg/OvmfTpmDxe.fdf.inc | 1 + OvmfPkg/OvmfTpmLibs.dsc.inc | 4 + OvmfPkg/OvmfXen.dsc | 1 + .../Include/Library/TcgPhysicalPresenceLib.h | 39 + .../AuthVariableLib/AuthServiceInternal.h | 1 + .../Library/AuthVariableLib/AuthVariableLib.c | 11 + .../AuthVariableLib/AuthVariableLib.inf | 4 + .../DxeTcgPhysicalPresenceLib.c | 55 + SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf | 1 + SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c | 41 +- 24 files changed, 1819 insertions(+), 71 deletions(-) create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.uni create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStrings.uni -- 2.31.1
|
|
[PATCH v3 1/8] OvmfPkg: Move processing of physical presence opcode before End-of-Dxe
Stefan Berger
For variable creation and locking to work later on we need to
move the processing of the TPM physical presence opcode to before End-of-Dxe. Signed-off-by: Stefan Berger <stefanb@...> --- .../PlatformBootManagerLib/BdsPlatform.c | 20 +++++++++---------- .../PlatformBootManagerLibBhyve/BdsPlatform.c | 18 ++++++++--------- .../PlatformBootManagerLibGrub/BdsPlatform.c | 18 ++++++++--------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg= /Library/PlatformBootManagerLib/BdsPlatform.c index 186401296a..2905356fc4 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -371,6 +371,16 @@ PlatformBootManagerBeforeConsole ( //=0D EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);=0D =0D + // We need to connect all trusted consoles for TCG PP. Here we treat all= =0D + // consoles in OVMF to be trusted consoles.=0D + PlatformInitializeConsole (=0D + XenDetected() ? gXenPlatformConsole : gPlatformConsole);=0D +=0D + //=0D + // Process TPM PPI request; this may require keyboard input=0D + //=0D + Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D +=0D //=0D // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig= gers=0D // the preparation of S3 system information. That logic has a hard depen= dency=0D @@ -388,16 +398,6 @@ PlatformBootManagerBeforeConsole ( SaveS3BootScript ();=0D }=0D =0D - // We need to connect all trusted consoles for TCG PP. Here we treat all= =0D - // consoles in OVMF to be trusted consoles.=0D - PlatformInitializeConsole (=0D - XenDetected() ? gXenPlatformConsole : gPlatformConsole);=0D -=0D - //=0D - // Process TPM PPI request; this may require keyboard input=0D - //=0D - Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D -=0D //=0D // Prevent further changes to LockBoxes or SMRAM.=0D // Any TPM 2 Physical Presence Interface opcode must be handled before.= =0D diff --git a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c b/Ov= mfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c index e767c3b172..950ab12c94 100644 --- a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c @@ -366,15 +366,6 @@ PlatformBootManagerBeforeConsole ( //=0D EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);=0D =0D - //=0D - // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig= gers=0D - // the preparation of S3 system information. That logic has a hard depen= dency=0D - // on the presence of the FACS ACPI table. Since our ACPI tables are onl= y=0D - // installed after PCI enumeration completes, we must not trigger the S3= save=0D - // earlier, hence we can't signal End-of-Dxe earlier.=0D - //=0D - EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D -=0D // We need to connect all trusted consoles for TCG PP. Here we treat all= =0D // consoles in OVMF to be trusted consoles.=0D PlatformInitializeConsole (gPlatformConsole);=0D @@ -384,6 +375,15 @@ PlatformBootManagerBeforeConsole ( //=0D Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D =0D + //=0D + // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig= gers=0D + // the preparation of S3 system information. That logic has a hard depen= dency=0D + // on the presence of the FACS ACPI table. Since our ACPI tables are onl= y=0D + // installed after PCI enumeration completes, we must not trigger the S3= save=0D + // earlier, hence we can't signal End-of-Dxe earlier.=0D + //=0D + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D +=0D //=0D // Prevent further changes to LockBoxes or SMRAM.=0D // Any TPM 2 Physical Presence Interface opcode must be handled before.= =0D diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c b/Ovm= fPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c index fd80577355..fbc40dcb68 100644 --- a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c @@ -329,15 +329,6 @@ PlatformBootManagerBeforeConsole ( //=0D EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);=0D =0D - //=0D - // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig= gers=0D - // the preparation of S3 system information. That logic has a hard depen= dency=0D - // on the presence of the FACS ACPI table. Since our ACPI tables are onl= y=0D - // installed after PCI enumeration completes, we must not trigger the S3= save=0D - // earlier, hence we can't signal End-of-Dxe earlier.=0D - //=0D - EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D -=0D // We need to connect all trusted consoles for TCG PP. Here we treat all= =0D // consoles in OVMF to be trusted consoles.=0D PlatformInitializeConsole (gPlatformConsole);=0D @@ -347,6 +338,15 @@ PlatformBootManagerBeforeConsole ( //=0D Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D =0D + //=0D + // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig= gers=0D + // the preparation of S3 system information. That logic has a hard depen= dency=0D + // on the presence of the FACS ACPI table. Since our ACPI tables are onl= y=0D + // installed after PCI enumeration completes, we must not trigger the S3= save=0D + // earlier, hence we can't signal End-of-Dxe earlier.=0D + //=0D + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D +=0D //=0D // Prevent further changes to LockBoxes or SMRAM.=0D // Any TPM 2 Physical Presence Interface opcode must be handled before.= =0D --=20 2.31.1
|
|
Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4
Bret Barkelew
So, so, so refreshing to see automated consistency.  For UnitTestFrameworkPkg… Reviewed-by: Bret Barkelew <bret.barkelew@...>  - Bret Â
From: Michael D Kinney via groups.io
Sent: Tuesday, November 30, 2021 2:34 PM To: devel@edk2.groups.io; Kinney, Michael D; Michael Kubacki; Andrew Fish (afish@...); Lindholm, Leif Subject: [EXTERNAL] [edk2-devel] Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4 Â Hello, Â
|
|
Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4
Michael D Kinney
Hi Michael,
toggle quoted messageShow quoted text
This commit provides the background on why this content was copied into edk2 instead of used as a submodule. https://github.com/tianocore/edk2/commit/4751a48aeb2ab828b0a5cbdc585fd3642967cda1#diff-9f77cfa3b537eee28489f8713c17d8702330f5cef1795f154201dd463aabed27 I imagine the main reason for this request is to minimize the effort required to sync these copies with new versions. The scope right now is only 7 files. One alternative to help with the sync is for Abner to run uncrustify on the files from the upstream source on these 7 files and then do the diff to see if there is anything significant that needs to be merged. Abner, are you ok with doing this 2 step process to sync the files that were copied? Best regards, Mike
-----Original Message-----
|
|
Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4
Michael Kubacki
This can of course be done at a technical level but it smells of a code cohesion problem.
toggle quoted messageShow quoted text
The code is in the edk2 project so it would reason that it should be uniform in style with other code and at least close to the EDK II C Coding Standard Specification. Currently, git submodules and ignored path are already excluded in addition to the ability to mark packages in "audit mode" so they do not fail the results. I would personally prefer not to allow arbitrary subdirectories to diverge from the rest of the codebase / package but if there's consensus this is a good idea, I can look into adding it. Regards, Michael
On 12/1/2021 11:43 AM, Michael D Kinney wrote:
Hi Abner,
|
|
Re: EDK2 doxygen documentation - adding docs for stable tags?
Michael D Kinney
Hi Rebecca,
toggle quoted messageShow quoted text
It does not push to gitbook server. It is pushed to web pages hosted by GitHub. It uses gitbook tools to process MD files into published PDF, MOBI, HTML. For example, the EDK II Build Specification has repo in GitHub: https://github.com/tianocore-docs/edk2-BuildSpecification And the HTML version of the draft revision of this spec is published here: https://tianocore-docs.github.io/edk2-BuildSpecification/draft/ These are the web pages associated with tianocore-docs org. Thanks, Mike
-----Original Message-----
|
|
Re: EDK2 doxygen documentation - adding docs for stable tags?
Rebecca Cran
From what I can see, the tianocore-docs actions push to gitbooks, not tianocore.org?
toggle quoted messageShow quoted text
I don't think gitbooks will work for the doxygen pages. -- Rebecca Cran
On 11/30/21 20:21, Kinney, Michael D wrote:
Hi Rebecca,
|
|
Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4
Michael D Kinney
Hi Abner,
toggle quoted messageShow quoted text
Yes. That is possible. We are already excluding BaseTools. In order to get the file lists that apply to uncrustify, we would have to change from: git ls-files *.c *.h :!BaseTools/* To: git ls-files *.c *.h :!BaseTools/* :!RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/* However, I do not see a feature in the UncrustifyCheck to check all c/h files in RedFishPkg and exclude one of its directories. If we can specify an exclusion like this in the RedFishPkg YAML file, then I think that would work well. Michael Kubacki would have to comment on how we support this in EDK II CI checks. Best regards, Mike
-----Original Message-----
|
|
[PATCH 1/1] OvmfPkg/MemEncryptSevLib: Check the guest type before EsWorkarea access
Brijesh Singh
The commit 80e67af9afca added support for a generic workarea concept.
The workarea header contains the information of the guest type. The header is populated by ResetVector code during the guest detection. Currently, the InternalMemEncryptSevStatus() reads the EsWorkArea to determine the C-bit position. The EsWorkArea PCD is valid only for the SEV guest type. Add a check of the guest type before accessing the EsWorkArea PCD. Fixes: 80e67af9afca ("OvmfPkg: introduce a common work area") Cc: James Bottomley <jejb@...> Cc: Min Xu <min.m.xu@...> Cc: Jiewen Yao <jiewen.yao@...> Cc: Tom Lendacky <thomas.lendacky@...> Cc: Jordan Justen <jordan.l.justen@...> Cc: Ard Biesheuvel <ardb+tianocore@...> Cc: Erdem Aktas <erdemaktas@...> Cc: Gerd Hoffmann <kraxel@...> Cc: Qi Zhou <atmgnd@...> Signed-off-by: Brijesh Singh <brijesh.singh@...> --- .../DxeMemEncryptSevLib.inf | 2 + .../PeiMemEncryptSevLib.inf | 2 + .../SecMemEncryptSevLib.inf | 2 + .../PeiMemEncryptSevLibInternal.c | 50 +++++++++++++++- .../SecMemEncryptSevLibInternal.c | 58 ++++++++++++++++++- 5 files changed, 110 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf index f2e162d68076..03b66b986f1f 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf @@ -54,4 +54,6 @@ [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire [Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 03a78c32df28..16dd4d9d8b77 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -54,4 +54,6 @@ [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf index 279c38bfbc2c..a933cb33a9cb 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf @@ -48,4 +48,6 @@ [LibraryClasses] PcdLib [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c index e2fd109d120f..db4249ec0d7d 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c @@ -24,6 +24,52 @@ STATIC BOOLEAN mSevStatusChecked = FALSE; STATIC UINT64 mSevEncryptionMask = 0; STATIC BOOLEAN mSevEncryptionMaskSaved = FALSE; +/** + Determine if the SEV is active. + + During the early booting, GuestType is set in the work area. Verify that it + is an SEV guest. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled + + **/ +STATIC +BOOLEAN +IsSevGuest ( + VOID + ) +{ + OVMF_WORK_AREA *WorkArea; + + // + // Ensure that the size of the Confidential Computing work area header + // is same as what is provided through a fixed PCD. + // + ASSERT ((UINTN) FixedPcdGet32 (PcdOvmfConfidentialComputingWorkAreaHeader) == + sizeof(CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER)); + + WorkArea = (OVMF_WORK_AREA *) FixedPcdGet32 (PcdOvmfWorkAreaBase); + + return ((WorkArea != NULL) && (WorkArea->Header.GuestType == GUEST_TYPE_AMD_SEV)); +} + +STATIC +SEC_SEV_ES_WORK_AREA * +GetSevEsWorkArea ( + VOID + ) +{ + // + // Before accessing the Es workarea lets verify that its SEV guest + // + if (!IsSevGuest()) { + return NULL; + } + + return (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase); +} + /** Reads and sets the status of SEV features. @@ -43,7 +89,7 @@ InternalMemEncryptSevStatus ( ReadSevMsr = FALSE; - SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + SevEsWorkArea = GetSevEsWorkArea (); if (SevEsWorkArea != NULL && SevEsWorkArea->EncryptionMask != 0) { // // The MSR has been read before, so it is safe to read it again and avoid @@ -139,7 +185,7 @@ MemEncryptSevGetEncryptionMask ( if (!mSevEncryptionMaskSaved) { SEC_SEV_ES_WORK_AREA *SevEsWorkArea; - SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + SevEsWorkArea = GetSevEsWorkArea (); if (SevEsWorkArea != NULL) { mSevEncryptionMask = SevEsWorkArea->EncryptionMask; } else { diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c index 56d8f3f3183f..d7aff1fa40ba 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c @@ -17,6 +17,52 @@ #include <Register/Cpuid.h> #include <Uefi/UefiBaseType.h> +/** + Determine if the SEV is active. + + During the early booting, GuestType is set in the work area. Verify that it + is an SEV guest. + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled + + **/ +STATIC +BOOLEAN +IsSevGuest ( + VOID + ) +{ + OVMF_WORK_AREA *WorkArea; + + // + // Ensure that the size of the Confidential Computing work area header + // is same as what is provided through a fixed PCD. + // + ASSERT ((UINTN) FixedPcdGet32 (PcdOvmfConfidentialComputingWorkAreaHeader) == + sizeof(CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER)); + + WorkArea = (OVMF_WORK_AREA *) FixedPcdGet32 (PcdOvmfWorkAreaBase); + + return ((WorkArea != NULL) && (WorkArea->Header.GuestType == GUEST_TYPE_AMD_SEV)); +} + +STATIC +SEC_SEV_ES_WORK_AREA * +GetSevEsWorkArea ( + VOID + ) +{ + // + // Before accessing the Es workarea lets verify that its SEV guest + // + if (!IsSevGuest()) { + return NULL; + } + + return (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase); +} + /** Reads and sets the status of SEV features. @@ -35,7 +81,8 @@ InternalMemEncryptSevStatus ( ReadSevMsr = FALSE; - SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + + SevEsWorkArea = GetSevEsWorkArea (); if (SevEsWorkArea != NULL && SevEsWorkArea->EncryptionMask != 0) { // // The MSR has been read before, so it is safe to read it again and avoid @@ -115,7 +162,14 @@ MemEncryptSevGetEncryptionMask ( SEC_SEV_ES_WORK_AREA *SevEsWorkArea; UINT64 EncryptionMask; - SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + // + // Before accessing the Es workarea lets verify that its SEV guest + // + if (!IsSevGuest()) { + return 0; + } + + SevEsWorkArea = GetSevEsWorkArea (); if (SevEsWorkArea != NULL) { EncryptionMask = SevEsWorkArea->EncryptionMask; } else { -- 2.25.1
|
|
Re: [Patch 02/12] ArmPlatformPkg: Update YAML to ignore specific ECC files/errors
PierreGondois
Hi,
toggle quoted messageShow quoted text
If the exceptions to the yaml files are added to allow the unscrustify patches to pass the CI tests, shouldn't the same exceptions be removed once the patches are merged ? Regards, Pierre
On 11/23/21 10:21 PM, Michael D Kinney via groups.io wrote:
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3749
|
|
[PATCH 5/5] OvmfPkg: Install ACPI tables for Cloud Hypervisor
Boeuf, Sebastien
From: Sebastien Boeuf <sebastien.boeuf@...>
Adding support for retrieving the Cloud Hypervisor ACPI tables as a fallback mechanism if tables are not found through fw_cfg. Signed-off-by: Rob Bradford <robert.bradford@...> Signed-off-by: Sebastien Boeuf <sebastien.boeuf@...> --- OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c | 4 + OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 6 + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 + OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c | 117 ++++++++++++++++++++ OvmfPkg/Include/IndustryStandard/CloudHv.h | 5 + 5 files changed, 133 insertions(+) create mode 100644 OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c index 613a8ac97f..abd1f550d4 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c @@ -29,5 +29,9 @@ InstallAcpiTables ( EFI_STATUS Status; Status = InstallQemuFwCfgTables (AcpiTable); + if (EFI_ERROR (Status)) { + Status = InstallCloudHvTables (AcpiTable); + } + return Status; } diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h index bd4c26f07f..bee48a93da 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -19,6 +19,12 @@ typedef struct { typedef struct S3_CONTEXT S3_CONTEXT; +EFI_STATUS +EFIAPI +InstallCloudHvTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ); + EFI_STATUS EFIAPI InstallQemuFwCfgTables ( diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf index eedd3b5af3..3ac9054d75 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -24,6 +24,7 @@ AcpiPlatform.c AcpiPlatform.h BootScript.c + CloudHvAcpi.c EntryPoint.c PciDecoding.c QemuFwCfgAcpi.c diff --git a/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c b/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c new file mode 100644 index 0000000000..96c532cce6 --- /dev/null +++ b/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c @@ -0,0 +1,117 @@ +/** @file + OVMF ACPI Cloud Hypervisor support + + Copyright (c) 2021, Intel Corporation. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <IndustryStandard/CloudHv.h> // CLOUDHV_RSDP_ADDRESS +#include <Library/BaseLib.h> // CpuDeadLoop() +#include <Library/DebugLib.h> // DEBUG() + +#include "AcpiPlatform.h" + +// Get the ACPI tables from EBDA start +EFI_STATUS +EFIAPI +InstallCloudHvTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ) +{ + EFI_STATUS Status; + UINTN TableHandle; + + EFI_ACPI_DESCRIPTION_HEADER *Xsdt; + VOID *CurrentTableEntry; + UINTN CurrentTablePointer; + EFI_ACPI_DESCRIPTION_HEADER *CurrentTable; + UINTN Index; + UINTN NumberOfTableEntries; + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt2Table; + EFI_ACPI_DESCRIPTION_HEADER *DsdtTable; + Fadt2Table = NULL; + DsdtTable = NULL; + TableHandle = 0; + NumberOfTableEntries = 0; + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *AcpiRsdpStructurePtr = (VOID *)CLOUDHV_RSDP_ADDRESS; + + // If XSDT table is found, just install its tables. + // Otherwise, try to find and install the RSDT tables. + // + if (AcpiRsdpStructurePtr->XsdtAddress) { + // + // Retrieve the addresses of XSDT and + // calculate the number of its table entries. + // + Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) + AcpiRsdpStructurePtr->XsdtAddress; + NumberOfTableEntries = (Xsdt->Length - + sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / + sizeof (UINT64); + + // + // Install ACPI tables found in XSDT. + // + for (Index = 0; Index < NumberOfTableEntries; Index++) { + // + // Get the table entry from XSDT + // + CurrentTableEntry = (VOID *) ((UINT8 *) Xsdt + + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + + Index * sizeof (UINT64)); + CurrentTablePointer = (UINTN) *(UINT64 *)CurrentTableEntry; + CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTablePointer; + + // + // Install the XSDT tables + // + Status = AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + CurrentTable, + CurrentTable->Length, + &TableHandle + ); + + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR(Status); + return Status; + } + + // + // Get the X-DSDT table address from the table FADT + // + if (!AsciiStrnCmp ((CHAR8 *) &CurrentTable->Signature, "FACP", 4)) { + Fadt2Table = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *) + (UINTN) CurrentTablePointer; + DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Fadt2Table->XDsdt; + } + } + } else { + return EFI_NOT_FOUND; + } + + // + // Install DSDT table. If we reached this point without finding the DSDT, + // then we're out of sync with the hypervisor, and cannot continue. + // + if (DsdtTable == NULL) { + DEBUG ((DEBUG_ERROR, "%a: no DSDT found\n", __FUNCTION__)); + ASSERT (FALSE); + CpuDeadLoop (); + } + + Status = AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + DsdtTable, + DsdtTable->Length, + &TableHandle + ); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR(Status); + return Status; + } + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/Include/IndustryStandard/CloudHv.h b/OvmfPkg/Include/IndustryStandard/CloudHv.h index ad0e170795..3a01dbb7d7 100644 --- a/OvmfPkg/Include/IndustryStandard/CloudHv.h +++ b/OvmfPkg/Include/IndustryStandard/CloudHv.h @@ -37,4 +37,9 @@ // #define CLOUDHV_SMBIOS_ADDRESS 0xf0000 +// +// RSDP address +// +#define CLOUDHV_RSDP_ADDRESS 0xa0000 + #endif // __CLOUDHV_H__ -- 2.30.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
|
|
[PATCH 4/5] OvmfPkg: Generalize AcpiPlatformDxe
Boeuf, Sebastien
From: Sebastien Boeuf <sebastien.boeuf@...>
Don't make the package Qemu centric so that we can introduce some alternative support for other VMMs not using the fw_cfg mechanism. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@...> --- ArmVirtPkg/ArmVirtQemu.dsc | 2 +- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 2 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +- .../{QemuFwCfgAcpiPlatform.c => AcpiPlatform.c} | 4 ++-- .../{QemuFwCfgAcpiPlatformDxe.inf => AcpiPlatformDxe.inf} | 4 ++-- OvmfPkg/AmdSev/AmdSevX64.dsc | 2 +- OvmfPkg/AmdSev/AmdSevX64.fdf | 2 +- OvmfPkg/Microvm/MicrovmX64.dsc | 2 +- OvmfPkg/Microvm/MicrovmX64.fdf | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 2 +- OvmfPkg/OvmfPkgIa32.fdf | 2 +- OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- OvmfPkg/OvmfPkgIa32X64.fdf | 2 +- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/OvmfPkgX64.fdf | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) rename OvmfPkg/AcpiPlatformDxe/{QemuFwCfgAcpiPlatform.c => AcpiPlatform.c} (78%) rename OvmfPkg/AcpiPlatformDxe/{QemuFwCfgAcpiPlatformDxe.inf => AcpiPlatformDxe.inf} (90%) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 891e065311..84c28b0c1d 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -543,7 +543,7 @@ ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf [Components.AARCH64] MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf { + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { <LibraryClasses> NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc index f6a538df72..d4df6dede0 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -145,7 +145,7 @@ READ_LOCK_STATUS = TRUE !if $(ARCH) == AARCH64 INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf - INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf + INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf # # EBC support diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc index a8bb83b288..8e82c5050f 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -458,7 +458,7 @@ ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf [Components.AARCH64] MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf { + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf { <LibraryClasses> NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c similarity index 78% rename from OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c rename to OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c index 057a450af9..613a8ac97f 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c @@ -1,5 +1,5 @@ /** @file - OVMF ACPI Platform Driver using QEMU's fw-cfg interface + OVMF ACPI Platform Driver Copyright (C) 2015, Red Hat, Inc. Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR> @@ -10,7 +10,7 @@ #include "AcpiPlatform.h" /** - Effective entrypoint of QEMU fw-cfg Acpi Platform driver. + Effective entrypoint of Acpi Platform driver. @param ImageHandle @param SystemTable diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf similarity index 90% rename from OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf rename to OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf index dac25d1505..eedd3b5af3 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -1,5 +1,5 @@ ## @file -# OVMF ACPI Platform Driver using QEMU's fw-cfg interface +# OVMF ACPI Platform Driver # # Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR> # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -21,12 +21,12 @@ # [Sources] + AcpiPlatform.c AcpiPlatform.h BootScript.c EntryPoint.c PciDecoding.c QemuFwCfgAcpi.c - QemuFwCfgAcpiPlatform.c [Packages] MdeModulePkg/MdeModulePkg.dec diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 5ee5445116..14ab027f63 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -773,7 +773,7 @@ # ACPI Support # MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf # diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf index 5662609886..5b61da2edd 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.fdf +++ b/OvmfPkg/AmdSev/AmdSevX64.fdf @@ -271,7 +271,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf -INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf INF FatPkg/EnhancedFatDxe/Fat.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 617f925395..2c6f932d95 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -751,7 +751,7 @@ # ACPI Support # MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.fdf b/OvmfPkg/Microvm/MicrovmX64.fdf index 6314014f3d..459c639e5a 100644 --- a/OvmfPkg/Microvm/MicrovmX64.fdf +++ b/OvmfPkg/Microvm/MicrovmX64.fdf @@ -268,7 +268,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf -INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 6a5be97c05..61209e3db1 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -870,7 +870,7 @@ # ACPI Support # MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index 775ea2d710..6b37238634 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -281,7 +281,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf -INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 71227d1b70..a4447508bc 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -884,7 +884,7 @@ # ACPI Support # MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 9d8695922f..88f3e16656 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -285,7 +285,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf -INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 52f7598cf1..6b1d8d3247 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -882,7 +882,7 @@ # ACPI Support # MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index b6cc3cabdd..c97c4ae16c 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -301,7 +301,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf -INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf -- 2.30.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
|
|
[PATCH 3/5] OvmfPkg: Retrieve SMBIOS from Cloud Hypervisor
Boeuf, Sebastien
From: Sebastien Boeuf <sebastien.boeuf@...>
Add a fallback on the SMBIOS code to find the SMBIOS table for Cloud Hypervisor if it couldn't be found for Qemu through fw_cfg. Signed-off-by: Rob Bradford <robert.bradford@...> Signed-off-by: Sebastien Boeuf <sebastien.boeuf@...> --- OvmfPkg/Include/IndustryStandard/CloudHv.h | 5 +++ OvmfPkg/SmbiosPlatformDxe/CloudHv.c | 32 +++++++++++++++++++ OvmfPkg/SmbiosPlatformDxe/EntryPoint.c | 23 +++++++++++-- .../SmbiosPlatformDxe/SmbiosPlatformDxe.inf | 1 + 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 OvmfPkg/SmbiosPlatformDxe/CloudHv.c diff --git a/OvmfPkg/Include/IndustryStandard/CloudHv.h b/OvmfPkg/Include/IndustryStandard/CloudHv.h index 6ab18ad50d..ad0e170795 100644 --- a/OvmfPkg/Include/IndustryStandard/CloudHv.h +++ b/OvmfPkg/Include/IndustryStandard/CloudHv.h @@ -32,4 +32,9 @@ // #define CLOUDHV_MMIO_HOLE_SIZE 0x38000000 +// +// SMBIOS address +// +#define CLOUDHV_SMBIOS_ADDRESS 0xf0000 + #endif // __CLOUDHV_H__ diff --git a/OvmfPkg/SmbiosPlatformDxe/CloudHv.c b/OvmfPkg/SmbiosPlatformDxe/CloudHv.c new file mode 100644 index 0000000000..f56a810684 --- /dev/null +++ b/OvmfPkg/SmbiosPlatformDxe/CloudHv.c @@ -0,0 +1,32 @@ +/** @file + Find Cloud Hypervisor SMBIOS data. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <IndustryStandard/CloudHv.h> // CLOUDHV_SMBIOS_ADDRESS +#include <IndustryStandard/SmBios.h> // SMBIOS_TABLE_3_0_ENTRY_POINT + +/** + Locates and extracts the QEMU SMBIOS data if present in fw_cfg + + @return Address of extracted QEMU SMBIOS data + +**/ +UINT8 * +GetCloudHvSmbiosTables ( + VOID + ) +{ + SMBIOS_TABLE_3_0_ENTRY_POINT *CloudHvTables = (VOID *)CLOUDHV_SMBIOS_ADDRESS; + + if (CloudHvTables->AnchorString[0] == '_' && + CloudHvTables->AnchorString[1] == 'S' && + CloudHvTables->AnchorString[2] == 'M' && + CloudHvTables->AnchorString[3] == '3' && + CloudHvTables->AnchorString[4] == '_') { + return (UINT8*)(UINTN)CloudHvTables->TableAddress; + } + + return NULL; +} diff --git a/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c b/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c index d3b1836a04..28faabb46a 100644 --- a/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c +++ b/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c @@ -8,6 +8,11 @@ #include "SmbiosPlatformDxe.h" +UINT8 * +GetCloudHvSmbiosTables ( + VOID + ); + UINT8 * GetQemuSmbiosTables ( VOID @@ -32,14 +37,28 @@ SmbiosTablePublishEntry ( { EFI_STATUS Status; UINT8 *SmbiosTables; + BOOLEAN FreeTables = FALSE; Status = EFI_NOT_FOUND; // // Add QEMU SMBIOS data if found // SmbiosTables = GetQemuSmbiosTables (); - if (SmbiosTables != NULL) { - Status = InstallAllStructures (SmbiosTables); + if (SmbiosTables == NULL) { + SmbiosTables = GetCloudHvSmbiosTables (); + if (SmbiosTables == NULL) { + return EFI_NOT_FOUND; + } + } else { + FreeTables = TRUE; + } + + Status = InstallAllStructures (SmbiosTables); + + // + // Free SmbiosTables if allocated by Qemu. + // + if (FreeTables) { FreePool (SmbiosTables); } diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf index e239a631f2..365d96241e 100644 --- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf +++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf @@ -24,6 +24,7 @@ # [Sources] + CloudHv.c EntryPoint.c Qemu.c SmbiosPlatformDxe.c -- 2.30.2 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
|
|