TianoCore EDK2 master
Loading...
Searching...
No Matches
TdxMailbox.c
Go to the documentation of this file.
1
10#include <Library/DebugLib.h>
12#include <Library/PcdLib.h>
13#include <Library/CpuLib.h>
15#include <Uefi/UefiBaseType.h>
19
25UINT32
26EFIAPI
28 VOID
29 )
30{
31 UINT64 Status;
32 TD_RETURN_DATA TdReturnData;
33
34 Status = TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData);
35 if (Status == TDX_EXIT_REASON_SUCCESS) {
36 return TdReturnData.TdInfo.NumVcpus;
37 } else {
38 DEBUG ((DEBUG_ERROR, "Failed call TDCALL_TDINFO. %llx\n", Status));
39 }
40
41 return 0;
42}
43
47volatile VOID *
48EFIAPI
50 VOID
51 )
52{
53 return (VOID *)(UINTN)PcdGet32 (PcdOvmfSecGhcbBackupBase);
54}
55
64VOID
65EFIAPI
67 IN UINT16 Command,
68 IN UINT64 WakeupVector,
69 IN UINT64 WakeupArgs1,
70 IN UINT64 WakeupArgs2,
71 IN UINT64 WakeupArgs3,
72 IN UINT64 WakeupArgs4
73 )
74{
75 volatile MP_WAKEUP_MAILBOX *MailBox;
76
77 MailBox = (volatile MP_WAKEUP_MAILBOX *)GetTdxMailBox ();
78 MailBox->ApicId = MP_CPU_PROTECTED_MODE_MAILBOX_APICID_INVALID;
79 MailBox->WakeUpVector = 0;
80 MailBox->Command = MpProtectedModeWakeupCommandNoop;
81 MailBox->ApicId = MP_CPU_PROTECTED_MODE_MAILBOX_APICID_BROADCAST;
82 MailBox->WakeUpVector = WakeupVector;
83 MailBox->WakeUpArgs1 = WakeupArgs1;
84 MailBox->WakeUpArgs2 = WakeupArgs2;
85 MailBox->WakeUpArgs3 = WakeupArgs3;
86 MailBox->WakeUpArgs4 = WakeupArgs4;
87 AsmCpuid (0x01, NULL, NULL, NULL, NULL);
88 MailBox->Command = Command;
89 AsmCpuid (0x01, NULL, NULL, NULL, NULL);
90 return;
91}
92
96VOID
97EFIAPI
99 VOID
100 )
101{
102 volatile MP_WAKEUP_MAILBOX *MailBox;
103 UINT32 NumOfCpus;
104
105 NumOfCpus = GetCpusNum ();
106 MailBox = (volatile MP_WAKEUP_MAILBOX *)GetTdxMailBox ();
107
108 DEBUG ((DEBUG_VERBOSE, "Waiting for APs to arriving. NumOfCpus=%d, MailBox=%p\n", NumOfCpus, MailBox));
109 while (MailBox->NumCpusArriving != (NumOfCpus -1)) {
110 CpuPause ();
111 }
112
113 DEBUG ((DEBUG_VERBOSE, "Releasing APs\n"));
114 MailBox->NumCpusExiting = NumOfCpus;
115 InterlockedIncrement ((UINT32 *)&MailBox->NumCpusArriving);
116}
117
121VOID
122EFIAPI
124 VOID
125 )
126{
127 volatile MP_WAKEUP_MAILBOX *MailBox;
128
129 MailBox = (volatile MP_WAKEUP_MAILBOX *)GetTdxMailBox ();
130 DEBUG ((DEBUG_VERBOSE, "Waiting for APs to finish\n"));
131 while (MailBox->NumCpusExiting != 1 ) {
132 CpuPause ();
133 }
134
135 DEBUG ((DEBUG_VERBOSE, "Restarting APs\n"));
136 MailBox->Command = MpProtectedModeWakeupCommandNoop;
137 MailBox->NumCpusArriving = 0;
138 InterlockedDecrement ((UINT32 *)&MailBox->NumCpusExiting);
139}
UINT64 UINTN
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 CpuPause(VOID)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
Definition: CpuId.c:36
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
UINT32 EFIAPI InterlockedIncrement(IN volatile UINT32 *Value)
UINT32 EFIAPI InterlockedDecrement(IN volatile UINT32 *Value)
VOID EFIAPI MpSerializeStart(VOID)
Definition: TdxMailbox.c:98
volatile VOID *EFIAPI GetTdxMailBox(VOID)
Definition: TdxMailbox.c:49
VOID EFIAPI MpSendWakeupCommand(IN UINT16 Command, IN UINT64 WakeupVector, IN UINT64 WakeupArgs1, IN UINT64 WakeupArgs2, IN UINT64 WakeupArgs3, IN UINT64 WakeupArgs4)
Definition: TdxMailbox.c:66
VOID EFIAPI MpSerializeEnd(VOID)
Definition: TdxMailbox.c:123
UINT32 EFIAPI GetCpusNum(VOID)
Definition: TdxMailbox.c:27