TianoCore EDK2 master
Loading...
Searching...
No Matches
TdInfo.c
Go to the documentation of this file.
1
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
13#include <Uefi/UefiBaseType.h>
14#include <Library/TdxLib.h>
16
17UINT64 mTdSharedPageMask = 0;
18UINT32 mTdMaxVCpuNum = 0;
19UINT32 mTdVCpuNum = 0;
20BOOLEAN mTdDataReturned = FALSE;
21
33BOOLEAN
35 VOID
36 )
37{
38 UINT64 Status;
39 TD_RETURN_DATA TdReturnData;
40 UINT8 Gpaw;
41
42 Status = TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData);
43 if (Status == TDX_EXIT_REASON_SUCCESS) {
44 Gpaw = (UINT8)(TdReturnData.TdInfo.Gpaw & 0x3f);
45 mTdSharedPageMask = 1ULL << (Gpaw - 1);
46 mTdMaxVCpuNum = TdReturnData.TdInfo.MaxVcpus;
47 mTdVCpuNum = TdReturnData.TdInfo.NumVcpus;
48 mTdDataReturned = TRUE;
49 } else {
50 DEBUG ((DEBUG_ERROR, "Failed call TDCALL_TDINFO. %llx\n", Status));
51 mTdDataReturned = FALSE;
52 }
53
54 return mTdDataReturned;
55}
56
66UINT64
67EFIAPI
69 VOID
70 )
71{
72 if (mTdDataReturned) {
73 return mTdSharedPageMask;
74 }
75
76 return GetTdInfo () ? mTdSharedPageMask : 0;
77}
78
85UINT32
86EFIAPI
88 VOID
89 )
90{
91 if (mTdDataReturned) {
92 return mTdMaxVCpuNum;
93 }
94
95 return GetTdInfo () ? mTdMaxVCpuNum : 0;
96}
97
104UINT32
105EFIAPI
107 VOID
108 )
109{
110 if (mTdDataReturned) {
111 return mTdVCpuNum;
112 }
113
114 return GetTdInfo () ? mTdVCpuNum : 0;
115}
UINTN EFIAPI TdCall(IN UINT64 Leaf, IN UINT64 Arg1, IN UINT64 Arg2, IN UINT64 Arg3, IN OUT VOID *Results)
Definition: IntelTdxNull.c:31
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define DEBUG(Expression)
Definition: DebugLib.h:434
BOOLEAN GetTdInfo(VOID)
Definition: TdInfo.c:34
UINT32 EFIAPI TdMaxVCpuNum(VOID)
Definition: TdInfo.c:87
UINT64 EFIAPI TdSharedPageMask(VOID)
Definition: TdInfo.c:68
UINT32 EFIAPI TdVCpuNum(VOID)
Definition: TdInfo.c:106