TianoCore EDK2 master
Loading...
Searching...
No Matches
Rtmr.c
Go to the documentation of this file.
1
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
13#include <Uefi/UefiBaseType.h>
14#include <Library/TdxLib.h>
18
19#define RTMR_COUNT 4
20#define TD_EXTEND_BUFFER_LEN (64 + 48)
21
22UINT8 mExtendBuffer[TD_EXTEND_BUFFER_LEN];
23
39EFIAPI
41 IN UINT32 *Data,
42 IN UINT32 DataLen,
43 IN UINT8 Index
44 )
45{
46 EFI_STATUS Status;
47 UINT64 TdCallStatus;
48 UINT8 *ExtendBuffer;
49
50 Status = EFI_SUCCESS;
51
52 ASSERT (Data != NULL);
53 ASSERT (DataLen == SHA384_DIGEST_SIZE);
54 ASSERT (Index < RTMR_COUNT);
55
56 if ((Data == NULL) || (DataLen != SHA384_DIGEST_SIZE) || (Index >= RTMR_COUNT)) {
57 return EFI_INVALID_PARAMETER;
58 }
59
60 // TD.RTMR.EXTEND requires 64B-aligned guest physical address of
61 // 48B-extension data. We use ALIGN_POINTER(Pointer, 64) to get
62 // the 64B-aligned guest physical address.
63 ExtendBuffer = ALIGN_POINTER (mExtendBuffer, 64);
64 ASSERT (((UINTN)ExtendBuffer & 0x3f) == 0);
65
66 ZeroMem (ExtendBuffer, SHA384_DIGEST_SIZE);
67 CopyMem (ExtendBuffer, Data, SHA384_DIGEST_SIZE);
68
69 TdCallStatus = TdCall (TDCALL_TDEXTENDRTMR, (UINT64)(UINTN)ExtendBuffer, Index, 0, 0);
70
71 if (TdCallStatus == TDX_EXIT_REASON_SUCCESS) {
72 Status = EFI_SUCCESS;
73 } else if (TdCallStatus == TDX_EXIT_REASON_OPERAND_INVALID) {
74 Status = EFI_INVALID_PARAMETER;
75 } else {
76 Status = EFI_DEVICE_ERROR;
77 }
78
79 if (Status != EFI_SUCCESS) {
80 DEBUG ((DEBUG_ERROR, "Error returned from TdExtendRtmr call - 0x%lx\n", TdCallStatus));
81 }
82
83 return Status;
84}
UINT64 UINTN
#define SHA384_DIGEST_SIZE
Definition: BaseCryptLib.h:49
UINTN EFIAPI TdCall(IN UINT64 Leaf, IN UINT64 Arg1, IN UINT64 Arg2, IN UINT64 Arg3, IN OUT VOID *Results)
Definition: IntelTdxNull.c:31
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define ALIGN_POINTER(Pointer, Alignment)
Definition: Base.h:963
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI TdExtendRtmr(IN UINT32 *Data, IN UINT32 DataLen, IN UINT8 Index)
Definition: Rtmr.c:40
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112