]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/MpServicesOnFrameworkMpServicesThunk/MpServicesOnFrameworkMpServicesThunk.h
5b420715829e7db8819875529d2a80fefaf162d1
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / MpServicesOnFrameworkMpServicesThunk / MpServicesOnFrameworkMpServicesThunk.h
1 /** @file
2 Include file for PI MP Services Protocol Thunk.
3
4 Copyright (c) 2009 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 Module Name:
13
14 **/
15
16 #ifndef _MP_SERVICES_ON_FRAMEWORK_MP_SERVICES_THUNK_
17 #define _MP_SERVICES_ON_FRAMEWORK_MP_SERVICES_THUNK_
18
19 #include <Protocol/MpService.h>
20 #include <Protocol/FrameworkMpService.h>
21 #include <Protocol/GenericMemoryTest.h>
22
23 #include <Library/BaseLib.h>
24 #include <Library/SynchronizationLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/UefiLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/DxeServicesTableLib.h>
32 #include <Library/IoLib.h>
33 #include <Library/TimerLib.h>
34
35 #define AP_STACK_SIZE 0x8000
36 #define MAX_CPU_NUMBER 256
37
38 //
39 // Bit definition for IPI
40 //
41 #define BROADCAST_MODE_ALL_EXCLUDING_SELF_BIT 0xC0000
42 #define SPECIFY_CPU_MODE_BIT 0x00000
43 #define TRIGGER_MODE_LEVEL_BIT 0x08000
44 #define ASSERT_BIT 0x04000
45
46 //
47 // Local APIC register definition for IPI.
48 //
49 #define APIC_REGISTER_ICR_LOW_OFFSET 0x300
50 #define APIC_REGISTER_ICR_HIGH_OFFSET 0x310
51
52 typedef struct {
53 UINTN Lock;
54 VOID *StackStart;
55 UINTN StackSize;
56 VOID *ApFunction;
57 IA32_DESCRIPTOR GdtrProfile;
58 UINT32 BufferStart;
59 UINT32 Cr3;
60 } MP_CPU_EXCHANGE_INFO;
61
62 typedef struct {
63 UINT8 *RendezvousFunnelAddress;
64 UINTN PModeEntryOffset;
65 UINTN FlatJumpOffset;
66 UINTN LModeEntryOffset;
67 UINTN LongJumpOffset;
68 UINTN Size;
69 } MP_ASSEMBLY_ADDRESS_MAP;
70
71 typedef enum {
72 CpuStateIdle,
73 CpuStateReady,
74 CpuStateBusy,
75 CpuStateFinished,
76 CpuStateDisabled
77 } CPU_STATE;
78
79 //
80 // Define Individual Processor Data block.
81 //
82 typedef struct {
83 EFI_AP_PROCEDURE volatile Procedure;
84 VOID* volatile Parameter;
85
86 EFI_EVENT WaitEvent;
87 BOOLEAN *Finished;
88 UINT64 ExpectedTime;
89 UINT64 CurrentTime;
90 UINT64 TotalTime;
91
92 SPIN_LOCK CpuDataLock;
93 CPU_STATE volatile State;
94
95 } CPU_DATA_BLOCK;
96
97 //
98 // Define MP data block which consumes individual processor block.
99 //
100 typedef struct {
101 SPIN_LOCK APSerializeLock;
102
103 EFI_EVENT CheckAPsEvent;
104
105 UINTN FinishCount;
106 UINTN StartCount;
107
108 BOOLEAN CpuList[MAX_CPU_NUMBER];
109
110 EFI_AP_PROCEDURE Procedure;
111 VOID *ProcArguments;
112 BOOLEAN SingleThread;
113 EFI_EVENT WaitEvent;
114 UINTN **FailedCpuList;
115 UINT64 ExpectedTime;
116 UINT64 CurrentTime;
117 UINT64 TotalTime;
118
119 CPU_DATA_BLOCK CpuData[MAX_CPU_NUMBER];
120 } MP_SYSTEM_DATA;
121
122 /**
123 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
124
125 This service retrieves the number of logical processor in the platform
126 and the number of those logical processors that are enabled on this boot.
127 This service may only be called from the BSP.
128
129 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
130 @param NumberOfProcessors Pointer to the total number of logical processors in the system,
131 including the BSP and disabled APs.
132 @param NumberOfEnabledProcessors Pointer to the number of enabled logical processors that exist
133 in system, including the BSP.
134
135 @retval EFI_SUCCESS Number of logical processors and enabled logical processors retrieved..
136 @retval EFI_DEVICE_ERROR Caller processor is AP.
137 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL
138 @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL
139
140 **/
141 EFI_STATUS
142 EFIAPI
143 GetNumberOfProcessors (
144 IN EFI_MP_SERVICES_PROTOCOL *This,
145 OUT UINTN *NumberOfProcessors,
146 OUT UINTN *NumberOfEnabledProcessors
147 );
148
149 /**
150 Implementation of GetNumberOfProcessors() service of MP Services Protocol.
151
152 Gets detailed MP-related information on the requested processor at the
153 instant this call is made. This service may only be called from the BSP.
154
155 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
156 @param ProcessorNumber The handle number of processor.
157 @param ProcessorInfoBuffer A pointer to the buffer where information for the requested processor is deposited.
158
159 @retval EFI_SUCCESS Processor information successfully returned.
160 @retval EFI_DEVICE_ERROR Caller processor is AP.
161 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL
162 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
163
164 **/
165 EFI_STATUS
166 EFIAPI
167 GetProcessorInfo (
168 IN EFI_MP_SERVICES_PROTOCOL *This,
169 IN UINTN ProcessorNumber,
170 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
171 );
172
173 /**
174 Implementation of StartupAllAPs() service of MP Services Protocol.
175
176 This service lets the caller get all enabled APs to execute a caller-provided function.
177 This service may only be called from the BSP.
178
179 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
180 @param Procedure A pointer to the function to be run on enabled APs of the system.
181 @param SingleThread Indicates whether to execute the function simultaneously or one by one..
182 @param WaitEvent The event created by the caller.
183 If it is NULL, then execute in blocking mode.
184 If it is not NULL, then execute in non-blocking mode.
185 @param TimeoutInMicroSeconds The time limit in microseconds for this AP to finish the function.
186 Zero means infinity.
187 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
188 @param FailedCpuList The list of processor numbers that fail to finish the function before
189 TimeoutInMicrosecsond expires.
190
191 @retval EFI_SUCCESS In blocking mode, all APs have finished before the timeout expired.
192 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to all enabled APs.
193 @retval EFI_DEVICE_ERROR Caller processor is AP.
194 @retval EFI_NOT_STARTED No enabled AP exists in the system.
195 @retval EFI_NOT_READY Any enabled AP is busy.
196 @retval EFI_TIMEOUT In blocking mode, The timeout expired before all enabled APs have finished.
197 @retval EFI_INVALID_PARAMETER Procedure is NULL.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 StartupAllAPs (
203 IN EFI_MP_SERVICES_PROTOCOL *This,
204 IN EFI_AP_PROCEDURE Procedure,
205 IN BOOLEAN SingleThread,
206 IN EFI_EVENT WaitEvent OPTIONAL,
207 IN UINTN TimeoutInMicroSeconds,
208 IN VOID *ProcedureArgument OPTIONAL,
209 OUT UINTN **FailedCpuList OPTIONAL
210 );
211
212 /**
213 Implementation of StartupThisAP() service of MP Services Protocol.
214
215 This service lets the caller get one enabled AP to execute a caller-provided function.
216 This service may only be called from the BSP.
217
218 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
219 @param Procedure A pointer to the function to be run on the designated AP.
220 @param ProcessorNumber The handle number of AP..
221 @param WaitEvent The event created by the caller.
222 If it is NULL, then execute in blocking mode.
223 If it is not NULL, then execute in non-blocking mode.
224 @param TimeoutInMicroseconds The time limit in microseconds for this AP to finish the function.
225 Zero means infinity.
226 @param ProcedureArgument Pointer to the optional parameter of the assigned function.
227 @param Finished Indicates whether AP has finished assigned function.
228 In blocking mode, it is ignored.
229
230 @retval EFI_SUCCESS In blocking mode, specified AP has finished before the timeout expires.
231 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched to specified AP.
232 @retval EFI_DEVICE_ERROR Caller processor is AP.
233 @retval EFI_TIMEOUT In blocking mode, the timeout expires before specified AP has finished.
234 @retval EFI_NOT_READY Specified AP is busy.
235 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
236 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
237 @retval EFI_INVALID_PARAMETER Procedure is NULL.
238
239 **/
240 EFI_STATUS
241 EFIAPI
242 StartupThisAP (
243 IN EFI_MP_SERVICES_PROTOCOL *This,
244 IN EFI_AP_PROCEDURE Procedure,
245 IN UINTN ProcessorNumber,
246 IN EFI_EVENT WaitEvent OPTIONAL,
247 IN UINTN TimeoutInMicroseconds,
248 IN VOID *ProcedureArgument OPTIONAL,
249 OUT BOOLEAN *Finished OPTIONAL
250 );
251
252 /**
253 Implementation of SwitchBSP() service of MP Services Protocol.
254
255 This service switches the requested AP to be the BSP from that point onward.
256 This service may only be called from the current BSP.
257
258 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
259 @param ProcessorNumber The handle number of processor.
260 @param EnableOldBSP Whether to enable or disable the original BSP.
261
262 @retval EFI_SUCCESS BSP successfully switched.
263 @retval EFI_DEVICE_ERROR Caller processor is AP.
264 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
265 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
266 @retval EFI_NOT_READY Specified AP is busy.
267
268 **/
269 EFI_STATUS
270 EFIAPI
271 SwitchBSP (
272 IN EFI_MP_SERVICES_PROTOCOL *This,
273 IN UINTN ProcessorNumber,
274 IN BOOLEAN EnableOldBSP
275 );
276
277 /**
278 Implementation of EnableDisableAP() service of MP Services Protocol.
279
280 This service lets the caller enable or disable an AP.
281 This service may only be called from the BSP.
282
283 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
284 @param ProcessorNumber The handle number of processor.
285 @param EnableAP Indicates whether the newstate of the AP is enabled or disabled.
286 @param HealthFlag Indicates new health state of the AP..
287
288 @retval EFI_SUCCESS AP successfully enabled or disabled.
289 @retval EFI_DEVICE_ERROR Caller processor is AP.
290 @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber does not exist.
291 @retval EFI_INVALID_PARAMETERS ProcessorNumber specifies the BSP.
292
293 **/
294 EFI_STATUS
295 EFIAPI
296 EnableDisableAP (
297 IN EFI_MP_SERVICES_PROTOCOL *This,
298 IN UINTN ProcessorNumber,
299 IN BOOLEAN EnableAP,
300 IN UINT32 *HealthFlag OPTIONAL
301 );
302
303 /**
304 Implementation of WhoAmI() service of MP Services Protocol.
305
306 This service lets the caller processor get its handle number.
307 This service may be called from the BSP and APs.
308
309 @param This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
310 @param ProcessorNumber Pointer to the handle number of AP.
311
312 @retval EFI_SUCCESS Processor number successfully returned.
313 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL
314
315 **/
316 EFI_STATUS
317 EFIAPI
318 WhoAmI (
319 IN EFI_MP_SERVICES_PROTOCOL *This,
320 OUT UINTN *ProcessorNumber
321 );
322
323 /**
324 Checks APs' status periodically.
325
326 This function is triggerred by timer perodically to check the
327 state of APs for StartupAllAPs() and StartupThisAP() executed
328 in non-blocking mode.
329
330 @param Event Event triggered.
331 @param Context Parameter passed with the event.
332
333 **/
334 VOID
335 EFIAPI
336 CheckAPsStatus (
337 IN EFI_EVENT Event,
338 IN VOID *Context
339 );
340
341 /**
342 Checks status of all APs.
343
344 This function checks whether all APs have finished task assigned by StartupAllAPs(),
345 and whether timeout expires.
346
347 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().
348 @retval EFI_TIMEOUT The timeout expires.
349 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.
350
351 **/
352 EFI_STATUS
353 CheckAllAPs (
354 VOID
355 );
356
357 /**
358 Checks status of specified AP.
359
360 This function checks whether specified AP has finished task assigned by StartupThisAP(),
361 and whether timeout expires.
362
363 @param ProcessorNumber The handle number of processor.
364
365 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().
366 @retval EFI_TIMEOUT The timeout expires.
367 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.
368
369 **/
370 EFI_STATUS
371 CheckThisAP (
372 UINTN ProcessorNumber
373 );
374
375 /**
376 Calculate timeout value and return the current performance counter value.
377
378 Calculate the number of performance counter ticks required for a timeout.
379 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
380 as infinity.
381
382 @param TimeoutInMicroseconds Timeout value in microseconds.
383 @param CurrentTime Returns the current value of the performance counter.
384
385 @return Expected timestamp counter for timeout.
386 If TimeoutInMicroseconds is 0, return value is also 0, which is recognized
387 as infinity.
388
389 **/
390 UINT64
391 CalculateTimeout (
392 IN UINTN TimeoutInMicroseconds,
393 OUT UINT64 *CurrentTime
394 );
395
396 /**
397 Checks whether timeout expires.
398
399 Check whether the number of ellapsed performance counter ticks required for a timeout condition
400 has been reached. If Timeout is zero, which means infinity, return value is always FALSE.
401
402 @param PreviousTime On input, the value of the performance counter when it was last read.
403 On output, the current value of the performance counter
404 @param TotalTime The total amount of ellapsed time in performance counter ticks.
405 @param Timeout The number of performance counter ticks required to reach a timeout condition.
406
407 @retval TRUE A timeout condition has been reached.
408 @retval FALSE A timeout condition has not been reached.
409
410 **/
411 BOOLEAN
412 CheckTimeout (
413 IN OUT UINT64 *PreviousTime,
414 IN UINT64 *TotalTime,
415 IN UINT64 Timeout
416 );
417
418 /**
419 Searches for the next waiting AP.
420
421 Search for the next AP that is put in waiting state by single-threaded StartupAllAPs().
422
423 @param NextProcessorNumber Pointer to the processor number of the next waiting AP.
424
425 @retval EFI_SUCCESS The next waiting AP has been found.
426 @retval EFI_NOT_FOUND No waiting AP exists.
427
428 **/
429 EFI_STATUS
430 GetNextWaitingProcessorNumber (
431 OUT UINTN *NextProcessorNumber
432 );
433
434 /**
435 Wrapper function for all procedures assigned to AP.
436
437 Wrapper function for all procedures assigned to AP via MP service protocol.
438 It controls states of AP and invokes assigned precedure.
439
440 **/
441 VOID
442 ApProcWrapper (
443 VOID
444 );
445
446 /**
447 Function to wake up a specified AP and assign procedure to it.
448
449 @param ProcessorNumber Handle number of the specified processor.
450 @param Procedure Procedure to assign.
451 @param ProcArguments Argument for Procedure.
452
453 **/
454 VOID
455 WakeUpAp (
456 IN UINTN ProcessorNumber,
457 IN EFI_AP_PROCEDURE Procedure,
458 IN VOID *ProcArguments
459 );
460
461 /**
462 Terminate AP's task and set it to idle state.
463
464 This function terminates AP's task due to timeout by sending INIT-SIPI,
465 and sends it to idle state.
466
467 @param ProcessorNumber Handle number of the specified processor.
468
469 **/
470 VOID
471 ResetProcessorToIdleState (
472 UINTN ProcessorNumber
473 );
474
475 /**
476 Worker function of EnableDisableAP ()
477
478 Worker function of EnableDisableAP (). Changes state of specified processor.
479
480 @param ProcessorNumber Processor number of specified AP.
481 @param NewState Desired state of the specified AP.
482
483 @retval EFI_SUCCESS AP's state successfully changed.
484
485 **/
486 EFI_STATUS
487 ChangeCpuState (
488 IN UINTN ProcessorNumber,
489 IN BOOLEAN NewState
490 );
491
492 /**
493 Gets the processor number of BSP.
494
495 @return The processor number of BSP.
496
497 **/
498 UINTN
499 GetBspNumber (
500 VOID
501 );
502
503 /**
504 Get address map of RendezvousFunnelProc.
505
506 This function gets address map of RendezvousFunnelProc.
507
508 @param AddressMap Output buffer for address map information
509
510 **/
511 VOID
512 AsmGetAddressMap (
513 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
514 );
515
516 #endif