]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / Library / SmmCpuRendezvousLib / SmmCpuRendezvousLib.c
1 /** @file
2 SMM CPU Rendezvous sevice implement.
3
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Base.h>
10 #include <Uefi.h>
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MmServicesTableLib.h>
14 #include <Protocol/SmmCpuService.h>
15 #include <Library/SmmCpuRendezvousLib.h>
16
17 STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *mSmmCpuRendezvous = NULL;
18 STATIC VOID *mRegistration = NULL;
19
20 /**
21 Callback function to wait Smm cpu rendezvous service located.
22
23 SmmCpuRendezvousLib need to support MM_STANDALONE and DXE_SMM_DRIVER driver.
24 So do not use library constructor to locate the protocol.
25
26 @param[in] Protocol Points to the protocol's unique identifier.
27 @param[in] Interface Points to the interface instance.
28 @param[in] Handle The handle on which the interface was installed.
29
30 @retval EFI_SUCCESS Notification runs successfully.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 SmmCpuRendezvousProtocolNotify (
36 IN CONST EFI_GUID *Protocol,
37 IN VOID *Interface,
38 IN EFI_HANDLE Handle
39 )
40 {
41 EFI_STATUS Status;
42
43 Status = gMmst->MmLocateProtocol (
44 &gEdkiiSmmCpuRendezvousProtocolGuid,
45 NULL,
46 (VOID **)&mSmmCpuRendezvous
47 );
48 ASSERT_EFI_ERROR (Status);
49
50 return EFI_SUCCESS;
51 }
52
53 /**
54 This routine wait for all AP processors to arrive in SMM.
55
56 @param[in] BlockingMode Blocking mode or non-blocking mode.
57
58 @retval EFI_SUCCESS All avaiable APs arrived.
59 @retval EFI_TIMEOUT Wait for all APs until timeout.
60 @retval OTHER Fail to register SMM CPU Rendezvous service Protocol.
61 **/
62 EFI_STATUS
63 EFIAPI
64 SmmWaitForAllProcessor (
65 IN BOOLEAN BlockingMode
66 )
67 {
68 EFI_STATUS Status;
69
70 if ((mRegistration == NULL) && (mSmmCpuRendezvous == NULL)) {
71 //
72 // Locate SMM cpu rendezvous protocol for the first time execute the function.
73 //
74 Status = gMmst->MmLocateProtocol (
75 &gEdkiiSmmCpuRendezvousProtocolGuid,
76 NULL,
77 (VOID **)&mSmmCpuRendezvous
78 );
79 if (EFI_ERROR (Status)) {
80 Status = gMmst->MmRegisterProtocolNotify (
81 &gEdkiiSmmCpuRendezvousProtocolGuid,
82 SmmCpuRendezvousProtocolNotify,
83 &mRegistration
84 );
85 if (EFI_ERROR (Status)) {
86 return Status;
87 }
88 }
89 }
90
91 //
92 // The platform have not set up. It doesn't need smm cpu rendezvous.
93 //
94 if (mSmmCpuRendezvous == NULL) {
95 return EFI_SUCCESS;
96 }
97
98 Status = mSmmCpuRendezvous->WaitForAllProcessor (
99 mSmmCpuRendezvous,
100 BlockingMode
101 );
102 return Status;
103 }