VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerUnitTest.c

最後變更 在這個檔案是 99404,由 vboxsync 提交於 2 年 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 7.5 KB
 
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/UefiBootServicesTableLib.h>
11#include <Protocol/Timer.h>
12
13/**
14 Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR buffer.
15 In PEIM, store original PeiServicePointer before new Idt table.
16
17 @return Pointer to the allocated IA32_DESCRIPTOR buffer.
18**/
19VOID *
20InitializeBspIdt (
21 VOID
22 )
23{
24 UINTN *NewIdtTable;
25 IA32_DESCRIPTOR *Idtr;
26
27 Idtr = AllocateZeroPool (sizeof (IA32_DESCRIPTOR));
28 ASSERT (Idtr != NULL);
29 NewIdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM);
30 ASSERT (NewIdtTable != NULL);
31 Idtr->Base = (UINTN)NewIdtTable;
32 Idtr->Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
33
34 AsmWriteIdtr (Idtr);
35 return Idtr;
36}
37
38/**
39 Retrieve the number of logical processor in the platform and the number of those logical processors that
40 are enabled on this boot.
41
42 @param[in] MpServices MP_SERVICES structure.
43 @param[out] NumberOfProcessors Pointer to the total number of logical processors in the system, including
44 the BSP and disabled APs.
45 @param[out] NumberOfEnabledProcessors Pointer to the number of processors in the system that are enabled.
46
47 @retval EFI_SUCCESS Retrieve the number of logical processor successfully
48 @retval Others Retrieve the number of logical processor unsuccessfully
49**/
50EFI_STATUS
51MpServicesUnitTestGetNumberOfProcessors (
52 IN MP_SERVICES MpServices,
53 OUT UINTN *NumberOfProcessors,
54 OUT UINTN *NumberOfEnabledProcessors
55 )
56{
57 return MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, NumberOfProcessors, NumberOfEnabledProcessors);
58}
59
60/**
61 Get the handle number for the calling processor.
62
63 @param[in] MpServices MP_SERVICES structure.
64 @param[out] ProcessorNumber The handle number for the calling processor.
65
66 @retval EFI_SUCCESS Get the handle number for the calling processor successfully.
67 @retval Others Get the handle number for the calling processor unsuccessfully.
68**/
69EFI_STATUS
70MpServicesUnitTestWhoAmI (
71 IN MP_SERVICES MpServices,
72 OUT UINTN *ProcessorNumber
73 )
74{
75 return MpServices.Protocol->WhoAmI (MpServices.Protocol, ProcessorNumber);
76}
77
78/**
79 Caller gets one enabled AP to execute a caller-provided function.
80
81 @param[in] MpServices MP_SERVICES structure.
82 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
83 @param[in] ProcessorNumber The handle number of the AP.
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
89 @retval EFI_SUCCESS Caller gets one enabled AP to execute a caller-provided function successfully
90 @retval Others Caller gets one enabled AP to execute a caller-provided function unsuccessfully
91**/
92EFI_STATUS
93MpServicesUnitTestStartupThisAP (
94 IN MP_SERVICES MpServices,
95 IN EFI_AP_PROCEDURE Procedure,
96 IN UINTN ProcessorNumber,
97 IN UINTN TimeoutInMicroSeconds,
98 IN VOID *ProcedureArgument
99 )
100{
101 return MpServices.Protocol->StartupThisAP (MpServices.Protocol, Procedure, ProcessorNumber, NULL, TimeoutInMicroSeconds, ProcedureArgument, NULL);
102}
103
104/**
105 Execute a caller provided function on all enabled APs.
106
107 @param[in] MpServices MP_SERVICES structure.
108 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
109 @param[in] SingleThread If TRUE, then all the enabled APs execute the function specified by Procedure
110 one by one, in ascending order of processor handle number.
111 If FALSE, then all the enabled APs execute the function specified by Procedure
112 simultaneously.
113 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
114 for blocking mode only. Zero means infinity.
115 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
116
117 @retval EFI_SUCCESS Execute a caller provided function on all enabled APs successfully
118 @retval Others Execute a caller provided function on all enabled APs unsuccessfully
119**/
120EFI_STATUS
121MpServicesUnitTestStartupAllAPs (
122 IN MP_SERVICES MpServices,
123 IN EFI_AP_PROCEDURE Procedure,
124 IN BOOLEAN SingleThread,
125 IN UINTN TimeoutInMicroSeconds,
126 IN VOID *ProcedureArgument
127 )
128{
129 return MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Procedure, SingleThread, NULL, TimeoutInMicroSeconds, ProcedureArgument, NULL);
130}
131
132/**
133 Get EFI_MP_SERVICES_PROTOCOL pointer.
134
135 @param[out] MpServices Pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored
136
137 @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned
138 @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not found
139**/
140EFI_STATUS
141GetMpServices (
142 OUT MP_SERVICES *MpServices
143 )
144{
145 return gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices->Protocol);
146}
147
148/**
149 Entry for CpuExceptionHandlerDxeTest driver.
150
151 @param ImageHandle Image handle this driver.
152 @param SystemTable Pointer to the System Table.
153
154 @retval EFI_SUCCESS The driver executed normally.
155
156**/
157EFI_STATUS
158EFIAPI
159CpuExceptionHandlerTestEntry (
160 IN EFI_HANDLE ImageHandle,
161 IN EFI_SYSTEM_TABLE *SystemTable
162 )
163{
164 EFI_STATUS Status;
165 UNIT_TEST_FRAMEWORK_HANDLE Framework;
166 EFI_TIMER_ARCH_PROTOCOL *TimerArchProtocol;
167 UINT64 TimerPeriod;
168
169 Framework = NULL;
170 TimerArchProtocol = NULL;
171 TimerPeriod = 0;
172
173 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
174
175 //
176 // Start setting up the test framework for running the tests.
177 //
178 Status = InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
179 if (EFI_ERROR (Status)) {
180 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
181 goto EXIT;
182 }
183
184 Status = AddCommonTestCase (Framework);
185 if (EFI_ERROR (Status)) {
186 DEBUG ((DEBUG_ERROR, "Failed in AddCommonTestCase. Status = %r\n", Status));
187 goto EXIT;
188 }
189
190 //
191 // If HpetTimer driver has been dispatched, disable HpetTimer before Unit Test.
192 //
193 gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&TimerArchProtocol);
194 if (TimerArchProtocol != NULL) {
195 Status = TimerArchProtocol->GetTimerPeriod (TimerArchProtocol, &TimerPeriod);
196 ASSERT_EFI_ERROR (Status);
197 if (TimerPeriod > 0) {
198 DEBUG ((DEBUG_INFO, "HpetTimer has been dispatched. Disable HpetTimer.\n"));
199 Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, 0);
200 ASSERT_EFI_ERROR (Status);
201 }
202 }
203
204 //
205 // Execute the tests.
206 //
207 Status = RunAllTestSuites (Framework);
208
209 //
210 // Restore HpetTimer after Unit Test.
211 //
212 if ((TimerArchProtocol != NULL) && (TimerPeriod > 0)) {
213 DEBUG ((DEBUG_INFO, "Restore HpetTimer after DxeCpuExceptionHandlerLib UnitTest.\n"));
214 Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, TimerPeriod);
215 ASSERT_EFI_ERROR (Status);
216 }
217
218EXIT:
219 if (Framework) {
220 FreeUnitTestFramework (Framework);
221 }
222
223 return Status;
224}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette