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