VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/TdxLib/TdInfo.c@ 101297

Last change on this file since 101297 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1/** @file
2
3 Fetch the Tdx info.
4
5 Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
12#include <IndustryStandard/Tdx.h>
13#include <Uefi/UefiBaseType.h>
14#include <Library/TdxLib.h>
15#include <Library/BaseMemoryLib.h>
16
17UINT64 mTdSharedPageMask = 0;
18UINT32 mTdMaxVCpuNum = 0;
19UINT32 mTdVCpuNum = 0;
20BOOLEAN mTdDataReturned = FALSE;
21
22/**
23 This function call TDCALL_TDINFO to get the TD_RETURN_DATA.
24 If the TDCALL is successful, populate below variables:
25 - mTdSharedPageMask
26 - mTdMaxVCpunum
27 - mTdVCpuNum
28 - mTdDataReturned
29
30 @return TRUE The TDCALL is successful and above variables are populated.
31 @return FALSE The TDCALL is failed. Above variables are not set.
32**/
33BOOLEAN
34GetTdInfo (
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
57/**
58 This function gets the Td guest shared page mask.
59
60 The guest indicates if a page is shared using the Guest Physical Address
61 (GPA) Shared (S) bit. If the GPA Width(GPAW) is 48, the S-bit is bit-47.
62 If the GPAW is 52, the S-bit is bit-51.
63
64 @return Shared page bit mask
65**/
66UINT64
67EFIAPI
68TdSharedPageMask (
69 VOID
70 )
71{
72 if (mTdDataReturned) {
73 return mTdSharedPageMask;
74 }
75
76 return GetTdInfo () ? mTdSharedPageMask : 0;
77}
78
79/**
80 This function gets the maximum number of Virtual CPUs that are usable for
81 Td Guest.
82
83 @return maximum Virtual CPUs number
84**/
85UINT32
86EFIAPI
87TdMaxVCpuNum (
88 VOID
89 )
90{
91 if (mTdDataReturned) {
92 return mTdMaxVCpuNum;
93 }
94
95 return GetTdInfo () ? mTdMaxVCpuNum : 0;
96}
97
98/**
99 This function gets the number of Virtual CPUs that are usable for Td
100 Guest.
101
102 @return Virtual CPUs number
103**/
104UINT32
105EFIAPI
106TdVCpuNum (
107 VOID
108 )
109{
110 if (mTdDataReturned) {
111 return mTdVCpuNum;
112 }
113
114 return GetTdInfo () ? mTdVCpuNum : 0;
115}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette