]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/IntelTdx/Sec/X64/IntelTdxAPs.nasm
OvmfPkg: Enable APs to accept memory for TDVF
[mirror_edk2.git] / OvmfPkg / IntelTdx / Sec / X64 / IntelTdxAPs.nasm
1 ;------------------------------------------------------------------------------
2 ; @file
3 ; Intel TDX APs
4 ;
5 ; Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.<BR>
6 ; SPDX-License-Identifier: BSD-2-Clause-Patent
7 ;
8 ;------------------------------------------------------------------------------
9
10 %include "TdxCommondefs.inc"
11
12 ;
13 ; Note: BSP never gets here. APs will be unblocked by DXE
14 ;
15 ; R8 [31:0] NUM_VCPUS
16 ; [63:32] MAX_VCPUS
17 ; R9 [31:0] VCPU_INDEX
18 ;
19 ParkAp:
20
21 do_wait_loop:
22 ;
23 ; register itself in [rsp + CpuArrivalOffset]
24 ;
25 mov rax, 1
26 lock xadd dword [rsp + CpuArrivalOffset], eax
27 inc eax
28
29 .check_arrival_cnt:
30 cmp eax, r8d
31 je .check_command
32 mov eax, dword[rsp + CpuArrivalOffset]
33 jmp .check_arrival_cnt
34
35 .check_command:
36 mov eax, dword[rsp + CommandOffset]
37 cmp eax, MpProtectedModeWakeupCommandNoop
38 je .check_command
39
40 cmp eax, MpProtectedModeWakeupCommandWakeup
41 je .do_wakeup
42
43 cmp eax, MpProtectedModeWakeupCommandAcceptPages
44 je .do_accept_pages
45
46 ; Don't support this command, so ignore
47 jmp .check_command
48
49 .do_accept_pages:
50 ;
51 ; Read the top stack address from arguments
52 mov rsi, [rsp + AcceptPageArgsTopStackAddress]
53
54 ;
55 ; Calculate the top stack address of the AP.
56 ; ApStackAddr = BaseStackAddr + (vCpuIndex) * ApStackSize
57 xor rdx, rdx
58 xor rbx, rbx
59 xor rax, rax
60 mov eax, [rsp + AcceptPageArgsApStackSize]
61 mov ebx, r9d ; vCpuIndex
62 mul ebx
63 add rsi, rax ; now rsi is ApStackAddr
64
65 .start_accept_pages:
66 ;
67 ; Read the function address which will be called
68 mov rax, [rsp + WakeupVectorOffset]
69
70 ;
71 ; vCPU index as the first argument
72 mov ecx, r9d
73 mov rdx, [rsp + AcceptPageArgsPhysicalStart]
74 mov r8, [rsp + AcceptPageArgsPhysicalEnd]
75
76 ; save the Mailbox address to rbx
77 mov rbx, rsp
78
79 ;
80 ; set AP Stack
81 mov rsp, rsi
82 nop
83
84 ; save rax (the Mailbox address)
85 push rbx
86
87 call rax
88
89 ; recove rsp
90 pop rbx
91 mov rsp, rbx
92 ;
93 ; recover r8, r9
94 mov rax, 1
95 tdcall
96
97 mov eax, 0FFFFFFFFh
98 lock xadd dword [rsp + CpusExitingOffset], eax
99 dec eax
100
101 .check_exiting_cnt:
102 cmp eax, 0
103 je do_wait_loop
104 mov eax, dword[rsp + CpusExitingOffset]
105 jmp .check_exiting_cnt
106
107 .do_wakeup:
108 ;
109 ; BSP sets these variables before unblocking APs
110 ; RAX: WakeupVectorOffset
111 ; RBX: Relocated mailbox address
112 ; RBP: vCpuId
113 ;
114 mov rax, 0
115 mov eax, dword[rsp + WakeupVectorOffset]
116 mov rbx, [rsp + WakeupArgsRelocatedMailBox]
117 nop
118 jmp rax
119 jmp $