]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Test/UnitTest/EfiMpServicesPpiProtocol/EfiMpServiceProtocolUnitTest.c
UefiCpuPkg/Test: Add unit tests for MP service PPI and Protocol
[mirror_edk2.git] / UefiCpuPkg / Test / UnitTest / EfiMpServicesPpiProtocol / EfiMpServiceProtocolUnitTest.c
1 /** @file
2 PEI Module to test EfiMpServiceProtocol.
3
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiDxe.h>
11 #include <Library/UefiBootServicesTableLib.h>
12 #include "EfiMpServicesUnitTestCommom.h"
13
14 #define UNIT_TEST_NAME "EfiMpServiceProtocol Unit Test"
15 #define UNIT_TEST_VERSION "0.1"
16
17 /**
18 Get EFI_MP_SERVICES_PROTOCOL pointer.
19
20 @param[out] MpServices Pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored
21
22 @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned
23 @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not found
24 **/
25 EFI_STATUS
26 MpServicesUnitTestGetMpServices (
27 OUT MP_SERVICES *MpServices
28 )
29 {
30 return gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices->Protocol);
31 }
32
33 /**
34 Retrieve the number of logical processor in the platform and the number of those logical processors that
35 are enabled on this boot.
36
37 @param[in] MpServices MP_SERVICES structure.
38 @param[out] NumberOfProcessors Pointer to the total number of logical processors in the system, including
39 the BSP and disabled APs.
40 @param[out] NumberOfEnabledProcessors Pointer to the number of processors in the system that are enabled.
41
42 @retval EFI_SUCCESS Retrieve the number of logical processor successfully
43 @retval Others Retrieve the number of logical processor unsuccessfully
44 **/
45 EFI_STATUS
46 MpServicesUnitTestGetNumberOfProcessors (
47 IN MP_SERVICES MpServices,
48 OUT UINTN *NumberOfProcessors,
49 OUT UINTN *NumberOfEnabledProcessors
50 )
51 {
52 return MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, NumberOfProcessors, NumberOfEnabledProcessors);
53 }
54
55 /**
56 Get detailed information on the requested logical processor.
57
58 @param[in] MpServices MP_SERVICES structure.
59 @param[in] ProcessorNumber The handle number of the processor.
60 @param[out] ProcessorInfoBuffer Pointer to the buffer where the processor information is stored.
61
62 @retval EFI_SUCCESS Get information on the requested logical processor successfully
63 @retval Others Get information on the requested logical processor unsuccessfully
64 **/
65 EFI_STATUS
66 MpServicesUnitTestGetProcessorInfo (
67 IN MP_SERVICES MpServices,
68 IN UINTN ProcessorNumber,
69 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
70 )
71 {
72 return MpServices.Protocol->GetProcessorInfo (MpServices.Protocol, ProcessorNumber, ProcessorInfoBuffer);
73 }
74
75 /**
76 Execute a caller provided function on all enabled APs.
77
78 @param[in] MpServices MP_SERVICES structure.
79 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
80 @param[in] SingleThread If TRUE, then all the enabled APs execute the function specified by Procedure
81 one by one, in ascending order of processor handle number.
82 If FALSE, then all the enabled APs execute the function specified by Procedure
83 simultaneously.
84 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
85 for blocking mode only. Zero means infinity.
86 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
87
88 @retval EFI_SUCCESS Execute a caller provided function on all enabled APs successfully
89 @retval Others Execute a caller provided function on all enabled APs unsuccessfully
90 **/
91 EFI_STATUS
92 MpServicesUnitTestStartupAllAPs (
93 IN MP_SERVICES MpServices,
94 IN EFI_AP_PROCEDURE Procedure,
95 IN BOOLEAN SingleThread,
96 IN UINTN TimeoutInMicroSeconds,
97 IN VOID *ProcedureArgument
98 )
99 {
100 return MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Procedure, SingleThread, NULL, TimeoutInMicroSeconds, ProcedureArgument, NULL);
101 }
102
103 /**
104 Caller gets one enabled AP to execute a caller-provided function.
105
106 @param[in] MpServices MP_SERVICES structure.
107 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
108 @param[in] ProcessorNumber The handle number of the AP.
109 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
110 for blocking mode only. Zero means infinity.
111 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
112
113
114 @retval EFI_SUCCESS Caller gets one enabled AP to execute a caller-provided function successfully
115 @retval Others Caller gets one enabled AP to execute a caller-provided function unsuccessfully
116 **/
117 EFI_STATUS
118 MpServicesUnitTestStartupThisAP (
119 IN MP_SERVICES MpServices,
120 IN EFI_AP_PROCEDURE Procedure,
121 IN UINTN ProcessorNumber,
122 IN UINTN TimeoutInMicroSeconds,
123 IN VOID *ProcedureArgument
124 )
125 {
126 return MpServices.Protocol->StartupThisAP (MpServices.Protocol, Procedure, ProcessorNumber, NULL, TimeoutInMicroSeconds, ProcedureArgument, NULL);
127 }
128
129 /**
130 Switch the requested AP to be the BSP from that point onward.
131
132 @param[in] MpServices MP_SERVICES structure.
133 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
134 @param[in] EnableOldBSP If TRUE, the old BSP will be listed as an enabled AP. Otherwise, it will be disabled.
135
136 @retval EFI_SUCCESS Switch the requested AP to be the BSP successfully
137 @retval Others Switch the requested AP to be the BSP unsuccessfully
138 **/
139 EFI_STATUS
140 MpServicesUnitTestSwitchBSP (
141 IN MP_SERVICES MpServices,
142 IN UINTN ProcessorNumber,
143 IN BOOLEAN EnableOldBSP
144 )
145 {
146 return MpServices.Protocol->SwitchBSP (MpServices.Protocol, ProcessorNumber, EnableOldBSP);
147 }
148
149 /**
150 Caller enables or disables an AP from this point onward.
151
152 @param[in] MpServices MP_SERVICES structure.
153 @param[in] ProcessorNumber The handle number of the AP.
154 @param[in] EnableAP Specifies the new state for the processor for enabled, FALSE for disabled.
155 @param[in] HealthFlag If not NULL, a pointer to a value that specifies the new health status of the AP.
156
157 @retval EFI_SUCCESS Caller enables or disables an AP successfully.
158 @retval Others Caller enables or disables an AP unsuccessfully.
159 **/
160 EFI_STATUS
161 MpServicesUnitTestEnableDisableAP (
162 IN MP_SERVICES MpServices,
163 IN UINTN ProcessorNumber,
164 IN BOOLEAN EnableAP,
165 IN UINT32 *HealthFlag
166 )
167 {
168 return MpServices.Protocol->EnableDisableAP (MpServices.Protocol, ProcessorNumber, EnableAP, HealthFlag);
169 }
170
171 /**
172 Get the handle number for the calling processor.
173
174 @param[in] MpServices MP_SERVICES structure.
175 @param[out] ProcessorNumber The handle number for the calling processor.
176
177 @retval EFI_SUCCESS Get the handle number for the calling processor successfully.
178 @retval Others Get the handle number for the calling processor unsuccessfully.
179 **/
180 EFI_STATUS
181 MpServicesUnitTestWhoAmI (
182 IN MP_SERVICES MpServices,
183 OUT UINTN *ProcessorNumber
184 )
185 {
186 return MpServices.Protocol->WhoAmI (MpServices.Protocol, ProcessorNumber);
187 }
188
189 /**
190 Standard DXE driver or UEFI application entry point for unit test execution from DXE or UEFI Shell.
191 Initialize the unit test framework, suite, and unit tests for the EfiMpServiceProtocol and run the unit test.
192
193 @param[in] ImageHandle The firmware allocated handle for the EFI image.
194 @param[in] SystemTable A pointer to the EFI System Table.
195
196 **/
197 EFI_STATUS
198 EFIAPI
199 DxeEntryPoint (
200 IN EFI_HANDLE ImageHandle,
201 IN EFI_SYSTEM_TABLE *SystemTable
202 )
203 {
204 EFI_STATUS Status;
205 UNIT_TEST_FRAMEWORK_HANDLE Framework;
206 MP_SERVICE_UT_CONTEXT Context;
207
208 Framework = NULL;
209 Context.MpServices.Ppi = NULL;
210 Context.CommonBuffer = NULL;
211 Context.DisabledApNumber = NULL;
212
213 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION));
214
215 //
216 // Start setting up the test framework for running the tests.
217 //
218 Status = InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCallerBaseName, UNIT_TEST_VERSION);
219 if (EFI_ERROR (Status)) {
220 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
221 goto EXIT;
222 }
223
224 //
225 // Create test suite and unit tests for both EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
226 //
227 Status = AddCommonTestCase (Framework, &Context);
228 if (EFI_ERROR (Status)) {
229 DEBUG ((DEBUG_ERROR, "Failed in AddCommonTestCase. Status = %r\n", Status));
230 goto EXIT;
231 }
232
233 //
234 // Execute the tests.
235 //
236 Status = RunAllTestSuites (Framework);
237
238 EXIT:
239 if (Framework != NULL) {
240 FreeUnitTestFramework (Framework);
241 }
242
243 return Status;
244 }