TianoCore EDK2 master
|
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/BaseCryptLib.h>
#include <Library/BaseMemoryLib.h>
#include <IndustryStandard/Tdx.h>
#include <IndustryStandard/IntelTdx.h>
#include <IndustryStandard/Tpm20.h>
#include <Library/TdxLib.h>
#include <Library/TdxMailboxLib.h>
#include <Library/SynchronizationLib.h>
#include <Pi/PiHob.h>
#include <WorkArea.h>
#include <ConfidentialComputingGuestAttr.h>
#include <Library/TdxHelperLib.h>
Go to the source code of this file.
Macros | |
#define | ALIGNED_2MB_MASK 0x1fffff |
#define | MEGABYTE_SHIFT 20 |
#define | ACCEPT_CHUNK_SIZE SIZE_32MB |
#define | AP_STACK_SIZE SIZE_16KB |
#define | APS_STACK_SIZE(CpusNum) (ALIGN_VALUE(CpusNum*AP_STACK_SIZE, SIZE_2MB)) |
TdxHelper Functions which are used in SEC phase
Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file SecTdxHelper.c.
#define ACCEPT_CHUNK_SIZE SIZE_32MB |
Definition at line 30 of file SecTdxHelper.c.
#define ALIGNED_2MB_MASK 0x1fffff |
Definition at line 27 of file SecTdxHelper.c.
#define AP_STACK_SIZE SIZE_16KB |
Definition at line 31 of file SecTdxHelper.c.
#define APS_STACK_SIZE | ( | CpusNum | ) | (ALIGN_VALUE(CpusNum*AP_STACK_SIZE, SIZE_2MB)) |
Definition at line 32 of file SecTdxHelper.c.
#define MEGABYTE_SHIFT 20 |
Definition at line 28 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI AcceptMemory | ( | IN CONST VOID * | VmmHobList, |
IN UINT32 | CpusNum, | ||
IN EFI_PHYSICAL_ADDRESS | APsStackStartAddress, | ||
IN EFI_PHYSICAL_ADDRESS | PhysicalAddressStart | ||
) |
BSP and APs work togeter to accept memory which is under the address of 4G.
[in] | VmmHobList | The Hoblist pass the firmware |
[in] | CpusNum | Number of vCPUs |
[in] | APsStackStartAddres | Start address of APs stack |
[in] | PhysicalAddressStart | Start physical address which to be accepted |
EFI_SUCCESS | Process the HobList successfully |
Others | Other errors as indicated |
Definition at line 404 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI AcceptMemoryForAPsStack | ( | IN CONST VOID * | VmmHobList, |
IN UINT32 | APsStackSize, | ||
OUT EFI_PHYSICAL_ADDRESS * | PhysicalAddressEnd | ||
) |
BSP accept a small piece of memory which will be used as APs stack.
[in] | VmmHobList | The Hoblist pass the firmware |
[in] | APsStackSize | APs stack size |
[out] | PhysicalAddressEnd | The physical end address of accepted memory in phase-1 |
EFI_SUCCESS | Process the HobList successfully |
Others | Other errors as indicated |
Definition at line 326 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI ApAcceptMemoryResourceRange | ( | UINT32 | CpuIndex, |
EFI_PHYSICAL_ADDRESS | PhysicalStart, | ||
EFI_PHYSICAL_ADDRESS | PhysicalEnd | ||
) |
This function is called by APs to accept memory.
CpuIndex | vCPU index of an AP |
PhysicalStart | Start address of a memory region which is to be accepted |
PhysicalEnd | End address of a memory region which is to be accepted |
EFI_SUCCESS | Successfully accept the memory |
Others | Other errors as indicated |
Definition at line 211 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI BspAcceptMemoryResourceRange | ( | IN EFI_PHYSICAL_ADDRESS | PhysicalAddress, |
IN EFI_PHYSICAL_ADDRESS | PhysicalEnd | ||
) |
This function will be called to accept pages. Only BSP accepts pages.
TDCALL(ACCEPT_PAGE) supports the accept page size of 4k and 2M. To simplify the implementation, the Memory to be accpeted is splitted into 3 parts: --------------— <– StartAddress1 (not 2M aligned) | part 1 | Length1 < 2M |------------—| <– StartAddress2 (2M aligned) | | Length2 = Integer multiples of 2M | part 2 | | | |------------—| <– StartAddress3 | part 3 | Length3 < 2M |------------—|
[in] | PhysicalAddress | Start physical adress |
[in] | PhysicalEnd | End physical address |
EFI_SUCCESS | Accept memory successfully |
Others | Other errors as indicated |
Definition at line 71 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI BspApAcceptMemoryResourceRange | ( | UINT32 | CpuIndex, |
UINT32 | CpusNum, | ||
EFI_PHYSICAL_ADDRESS | PhysicalStart, | ||
EFI_PHYSICAL_ADDRESS | PhysicalEnd | ||
) |
This function is called by BSP and APs to accept memory. Note: The input PhysicalStart/PhysicalEnd indicates the whole memory region to be accepted. BSP or AP only accepts one piece in the whole memory region.
CpuIndex | vCPU index |
CpusNum | Total vCPU number of a Tdx guest |
PhysicalStart | Start address of a memory region which is to be accepted |
PhysicalEnd | End address of a memory region which is to be accepted |
EFI_SUCCESS | Successfully accept the memory |
Other | Other errors as indicated |
Definition at line 169 of file SecTdxHelper.c.
STATIC EFI_STATUS HashAndExtendToRtmr | ( | IN UINT32 | RtmrIndex, |
IN VOID * | DataToHash, | ||
IN UINTN | DataToHashLen, | ||
OUT UINT8 * | Digest, | ||
IN UINTN | DigestLen | ||
) |
Calculate the sha384 of input Data and extend it to RTMR register.
RtmrIndex | Index of the RTMR register |
DataToHash | Data to be hashed |
DataToHashLen | Length of the data |
Digest | Hash value of the input data |
DigestLen | Length of the hash value |
EFI_SUCCESS | Successfully hash and extend to RTMR |
Others | Other errors as indicated |
Definition at line 823 of file SecTdxHelper.c.
EFI_STATUS InternalBuildGuidHobForTdxMeasurement | ( | VOID | ) |
Build the GuidHob for tdx measurements which were done in SEC phase. The measurement values are stored in WorkArea.
EFI_SUCCESS | The GuidHob is built successfully |
Others | Other errors as indicated |
Definition at line 173 of file TdxMeasurementHob.c.
STATIC BOOLEAN EFIAPI IsInValidList | ( | IN UINT32 | Value, |
IN UINT32 * | ValidList, | ||
IN UINT32 | ValidListLength | ||
) |
Check the value whether in the valid list.
[in] | Value | A value |
[in] | ValidList | A pointer to valid list |
[in] | ValidListLength | Length of valid list |
TRUE | The value is in valid list. |
FALSE | The value is not in valid list. |
Definition at line 505 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI MpAcceptMemoryResourceRange | ( | IN EFI_PHYSICAL_ADDRESS | PhysicalStart, |
IN EFI_PHYSICAL_ADDRESS | PhysicalEnd, | ||
IN OUT EFI_PHYSICAL_ADDRESS | APsStackAddress, | ||
IN UINT32 | CpusNum | ||
) |
This function is called by BSP. It coordinates BSP/APs to accept memory together.
PhysicalStart | Start address of a memory region which is to be accepted |
PhysicalEnd | End address of a memory region which is to be accepted |
APsStackAddress | APs stack address |
CpusNum | Total vCPU number of the Tdx guest |
EFI_SUCCESS | Successfully accept the memory |
Others | Other errors as indicated |
Definition at line 248 of file SecTdxHelper.c.
STATIC EFI_STATUS EFIAPI ProcessHobList | ( | IN CONST VOID * | VmmHobList | ) |
Processing the incoming HobList for the TDX
Firmware must parse list, and accept the pages of memory before their can be use by the guest.
[in] | VmmHobList | The Hoblist pass the firmware |
EFI_SUCCESS | Process the HobList successfully |
Others | Other errors as indicated |
Definition at line 726 of file SecTdxHelper.c.
EFI_STATUS EFIAPI TdxHelperBuildGuidHobForTdxMeasurement | ( | VOID | ) |
Build the GuidHob for tdx measurements which were done in SEC phase. The measurement values are stored in WorkArea.
EFI_SUCCESS | The GuidHob is built successfully |
Others | Other errors as indicated |
Definition at line 972 of file SecTdxHelper.c.
EFI_STATUS EFIAPI TdxHelperMeasureCfvImage | ( | VOID | ) |
In Tdx guest, Configuration FV (CFV) is treated as external input because it may contain the data provided by VMM. From the sucurity perspective Cfv image should be measured before it is consumed.
EFI_SUCCESS | Successfully measure the CFV image |
Others | Other error as indicated |
Definition at line 928 of file SecTdxHelper.c.
EFI_STATUS EFIAPI TdxHelperMeasureTdHob | ( | VOID | ) |
In Tdx guest, TdHob is passed from host VMM to guest firmware and it contains the information of the memory resource. From the security perspective before it is consumed, it should be measured and extended.
EFI_SUCCESS | Successfully measure the TdHob |
Others | Other error as indicated |
Definition at line 871 of file SecTdxHelper.c.
EFI_STATUS EFIAPI TdxHelperProcessTdHob | ( | VOID | ) |
In Tdx guest, some information need to be passed from host VMM to guest firmware. For example, the memory resource, etc. These information are prepared by host VMM and put in TdHob which is described in TdxMetadata. TDVF processes the TdHob to accept memories.
EFI_SUCCESS | Successfully process the TdHob |
Others | Other error as indicated |
Definition at line 773 of file SecTdxHelper.c.
Check the integrity of VMM Hob List.
[in] | VmmHobList | A pointer to Hob List |
TRUE | The Hob List is valid. |
FALSE | The Hob List is invalid. |
Definition at line 538 of file SecTdxHelper.c.