1 | /** @file
|
---|
2 | Unit tests of the CpuExceptionHandlerLib.
|
---|
3 |
|
---|
4 | Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "CpuExceptionHandlerTest.h"
|
---|
10 | #include <Library/PeimEntryPoint.h>
|
---|
11 | #include <Library/PeiServicesLib.h>
|
---|
12 | #include <Library/PeiServicesTablePointerLib.h>
|
---|
13 |
|
---|
14 | /**
|
---|
15 | Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR buffer.
|
---|
16 | In PEIM, store original PeiServicePointer before new Idt table.
|
---|
17 |
|
---|
18 | @return Pointer to the allocated IA32_DESCRIPTOR buffer.
|
---|
19 | **/
|
---|
20 | VOID *
|
---|
21 | InitializeBspIdt (
|
---|
22 | VOID
|
---|
23 | )
|
---|
24 | {
|
---|
25 | UINTN *NewIdtTable;
|
---|
26 | IA32_DESCRIPTOR *Idtr;
|
---|
27 |
|
---|
28 | Idtr = AllocateZeroPool (sizeof (IA32_DESCRIPTOR));
|
---|
29 | ASSERT (Idtr != NULL);
|
---|
30 | NewIdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM + sizeof (UINTN));
|
---|
31 | ASSERT (NewIdtTable != NULL);
|
---|
32 | //
|
---|
33 | // Store original PeiServicePointer before new Idt table
|
---|
34 | //
|
---|
35 | *NewIdtTable = (UINTN)GetPeiServicesTablePointer ();
|
---|
36 | NewIdtTable = (UINTN *)((UINTN)NewIdtTable + sizeof (UINTN));
|
---|
37 |
|
---|
38 | Idtr->Base = (UINTN)NewIdtTable;
|
---|
39 | Idtr->Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
|
---|
40 |
|
---|
41 | AsmWriteIdtr (Idtr);
|
---|
42 | return Idtr;
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | Retrieve the number of logical processor in the platform and the number of those logical processors that
|
---|
47 | are enabled on this boot.
|
---|
48 |
|
---|
49 | @param[in] MpServices MP_SERVICES structure.
|
---|
50 | @param[out] NumberOfProcessors Pointer to the total number of logical processors in the system, including
|
---|
51 | the BSP and disabled APs.
|
---|
52 | @param[out] NumberOfEnabledProcessors Pointer to the number of processors in the system that are enabled.
|
---|
53 |
|
---|
54 | @retval EFI_SUCCESS Retrieve the number of logical processor successfully
|
---|
55 | @retval Others Retrieve the number of logical processor unsuccessfully
|
---|
56 | **/
|
---|
57 | EFI_STATUS
|
---|
58 | MpServicesUnitTestGetNumberOfProcessors (
|
---|
59 | IN MP_SERVICES MpServices,
|
---|
60 | OUT UINTN *NumberOfProcessors,
|
---|
61 | OUT UINTN *NumberOfEnabledProcessors
|
---|
62 | )
|
---|
63 | {
|
---|
64 | return MpServices.Ppi->GetNumberOfProcessors (MpServices.Ppi, NumberOfProcessors, NumberOfEnabledProcessors);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | Caller gets one enabled AP to execute a caller-provided function.
|
---|
69 |
|
---|
70 | @param[in] MpServices MP_SERVICES structure.
|
---|
71 | @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
|
---|
72 | @param[in] ProcessorNumber The handle number of the AP.
|
---|
73 | @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
|
---|
74 | for blocking mode only. Zero means infinity.
|
---|
75 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
|
---|
76 |
|
---|
77 |
|
---|
78 | @retval EFI_SUCCESS Caller gets one enabled AP to execute a caller-provided function successfully
|
---|
79 | @retval Others Caller gets one enabled AP to execute a caller-provided function unsuccessfully
|
---|
80 | **/
|
---|
81 | EFI_STATUS
|
---|
82 | MpServicesUnitTestStartupThisAP (
|
---|
83 | IN MP_SERVICES MpServices,
|
---|
84 | IN EFI_AP_PROCEDURE Procedure,
|
---|
85 | IN UINTN ProcessorNumber,
|
---|
86 | IN UINTN TimeoutInMicroSeconds,
|
---|
87 | IN VOID *ProcedureArgument
|
---|
88 | )
|
---|
89 | {
|
---|
90 | return MpServices.Ppi->StartupThisAP (MpServices.Ppi, Procedure, ProcessorNumber, TimeoutInMicroSeconds, ProcedureArgument);
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | Execute a caller provided function on all enabled APs.
|
---|
95 |
|
---|
96 | @param[in] MpServices MP_SERVICES structure.
|
---|
97 | @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
|
---|
98 | @param[in] SingleThread If TRUE, then all the enabled APs execute the function specified by Procedure
|
---|
99 | one by one, in ascending order of processor handle number.
|
---|
100 | If FALSE, then all the enabled APs execute the function specified by Procedure
|
---|
101 | simultaneously.
|
---|
102 | @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
|
---|
103 | for blocking mode only. Zero means infinity.
|
---|
104 | @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
|
---|
105 |
|
---|
106 | @retval EFI_SUCCESS Execute a caller provided function on all enabled APs successfully
|
---|
107 | @retval Others Execute a caller provided function on all enabled APs unsuccessfully
|
---|
108 | **/
|
---|
109 | EFI_STATUS
|
---|
110 | MpServicesUnitTestStartupAllAPs (
|
---|
111 | IN MP_SERVICES MpServices,
|
---|
112 | IN EFI_AP_PROCEDURE Procedure,
|
---|
113 | IN BOOLEAN SingleThread,
|
---|
114 | IN UINTN TimeoutInMicroSeconds,
|
---|
115 | IN VOID *ProcedureArgument
|
---|
116 | )
|
---|
117 | {
|
---|
118 | return MpServices.Ppi->StartupAllAPs (MpServices.Ppi, Procedure, SingleThread, TimeoutInMicroSeconds, ProcedureArgument);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | Get the handle number for the calling processor.
|
---|
123 |
|
---|
124 | @param[in] MpServices MP_SERVICES structure.
|
---|
125 | @param[out] ProcessorNumber The handle number for the calling processor.
|
---|
126 |
|
---|
127 | @retval EFI_SUCCESS Get the handle number for the calling processor successfully.
|
---|
128 | @retval Others Get the handle number for the calling processor unsuccessfully.
|
---|
129 | **/
|
---|
130 | EFI_STATUS
|
---|
131 | MpServicesUnitTestWhoAmI (
|
---|
132 | IN MP_SERVICES MpServices,
|
---|
133 | OUT UINTN *ProcessorNumber
|
---|
134 | )
|
---|
135 | {
|
---|
136 | return MpServices.Ppi->WhoAmI (MpServices.Ppi, ProcessorNumber);
|
---|
137 | }
|
---|
138 |
|
---|
139 | /**
|
---|
140 | Get EDKII_PEI_MP_SERVICES2_PPI pointer.
|
---|
141 |
|
---|
142 | @param[out] MpServices Pointer to the buffer where EDKII_PEI_MP_SERVICES2_PPI is stored
|
---|
143 |
|
---|
144 | @retval EFI_SUCCESS EDKII_PEI_MP_SERVICES2_PPI interface is returned
|
---|
145 | @retval EFI_NOT_FOUND EDKII_PEI_MP_SERVICES2_PPI interface is not found
|
---|
146 | **/
|
---|
147 | EFI_STATUS
|
---|
148 | GetMpServices (
|
---|
149 | OUT MP_SERVICES *MpServices
|
---|
150 | )
|
---|
151 | {
|
---|
152 | return PeiServicesLocatePpi (&gEdkiiPeiMpServices2PpiGuid, 0, NULL, (VOID **)&MpServices->Ppi);
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | Entry point of CpuExceptionHandlerPeiTest PEIM.
|
---|
157 |
|
---|
158 | @param[in] FileHandle Handle of the file being invoked.
|
---|
159 | @param[in] PeiServices Describes the list of possible PEI Services.
|
---|
160 |
|
---|
161 | @retval EFI_SUCCESS The PEIM executed normally.
|
---|
162 |
|
---|
163 | **/
|
---|
164 | EFI_STATUS
|
---|
165 | EFIAPI
|
---|
166 | PeiEntryPoint (
|
---|
167 | IN EFI_PEI_FILE_HANDLE FileHandle,
|
---|
168 | IN CONST EFI_PEI_SERVICES **PeiServices
|
---|
169 | )
|
---|
170 | {
|
---|
171 | EFI_STATUS Status;
|
---|
172 | UNIT_TEST_FRAMEWORK_HANDLE Framework;
|
---|
173 |
|
---|
174 | Framework = NULL;
|
---|
175 |
|
---|
176 | DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
|
---|
177 |
|
---|
178 | //
|
---|
179 | // Start setting up the test framework for running the tests.
|
---|
180 | //
|
---|
181 | Status = InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
|
---|
182 | if (EFI_ERROR (Status)) {
|
---|
183 | DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
|
---|
184 | goto EXIT;
|
---|
185 | }
|
---|
186 |
|
---|
187 | Status = AddCommonTestCase (Framework);
|
---|
188 | if (EFI_ERROR (Status)) {
|
---|
189 | DEBUG ((DEBUG_ERROR, "Failed in AddCommonTestCase. Status = %r\n", Status));
|
---|
190 | goto EXIT;
|
---|
191 | }
|
---|
192 |
|
---|
193 | //
|
---|
194 | // Execute the tests.
|
---|
195 | //
|
---|
196 | Status = RunAllTestSuites (Framework);
|
---|
197 |
|
---|
198 | EXIT:
|
---|
199 | if (Framework) {
|
---|
200 | FreeUnitTestFramework (Framework);
|
---|
201 | }
|
---|
202 |
|
---|
203 | return Status;
|
---|
204 | }
|
---|