/
MpManagement.c
726 lines (611 loc) · 22.9 KB
/
MpManagement.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/** @file
MP management driver that supports the power management of AP on/off and
suspend/resume for all cores.
Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/BaseMemoryLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Pi/PiMultiPhase.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/MpService.h>
#include <Protocol/MpManagement.h>
#include "MpManagementInternal.h"
EFI_MP_SERVICES_PROTOCOL *mMpServices = NULL;
EFI_HANDLE mHandle = NULL;
UINTN mNumCpus = 0;
UINTN mBspIndex = 0;
volatile MP_MANAGEMENT_METADATA *mCommonBuffer = NULL;
/**
Fetches the number of processors and which processor is the BSP.
@param Mp MP Services Protocol.
@param NumProcessors Number of processors.
@param BspIndex The index of the BSP.
@return EFI_SUCCESS The routine completed successfully.
@return Others The routine failed due to some MP service calls.
**/
STATIC
EFI_STATUS
GetProcessorInformation (
IN EFI_MP_SERVICES_PROTOCOL *Mp,
OUT UINTN *NumProcessors,
OUT UINTN *BspIndex
)
{
EFI_STATUS Status;
UINTN NumEnabledProcessors;
Status = Mp->GetNumberOfProcessors (Mp, NumProcessors, &NumEnabledProcessors);
if (EFI_ERROR (Status)) {
return Status;
}
Status = Mp->WhoAmI (Mp, BspIndex);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/** Initialize the common buffer for all APs.
@param NumCpus The number of CPUs in the system.
@return EFI_SUCCESS on success, or an error code.
**/
EFI_STATUS
InitializeApCommonBuffer (
IN UINTN NumCpus,
OUT MP_MANAGEMENT_METADATA **CommonBuffer
)
{
UINTN Index;
EFI_STATUS Status;
if (CommonBuffer == NULL) {
return EFI_INVALID_PARAMETER;
}
*CommonBuffer = AllocateZeroPool (sizeof (MP_MANAGEMENT_METADATA) * NumCpus);
if (*CommonBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Status = EFI_SUCCESS;
for (Index = 0; Index < NumCpus; Index++) {
(*CommonBuffer)[Index].ApStatus = AP_STATE_OFF;
(*CommonBuffer)[Index].TargetStatus = AP_STATE_OFF;
(*CommonBuffer)[Index].ApTask = AP_TASK_IDLE;
(*CommonBuffer)[Index].ApBufferSize = EFI_PAGE_SIZE;
(*CommonBuffer)[Index].ApBuffer = AllocatePool ((*CommonBuffer)[Index].ApBufferSize);
if ((*CommonBuffer)[Index].ApBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
}
WriteBackDataCacheRange ((VOID *)(*CommonBuffer), sizeof (MP_MANAGEMENT_METADATA) * NumCpus);
Done:
if (EFI_ERROR (Status)) {
// Free any allocated pools if init failed.
for (Index = 0; Index < NumCpus; Index++) {
if ((*CommonBuffer)[Index].ApBuffer != NULL) {
FreePool ((*CommonBuffer)[Index].ApBuffer);
}
}
}
return Status;
}
/**
A BSP invoked function to perform self suspend. A timeout period needs
to be provided by the called to invoke self-wakeup service.
@param This MP Management Protocol.
@param BspPowerState The target power state the BSP should be
suspended to.
@param TargetPowerLevel The target power level of BSP when suspended,
certain architecture could require this value
to be paired with BspPowerState.
@param TimeoutInMicroseconds Time out in microseconds specified when the
timer should fire to wake up itself.
@return EFI_SUCCESS The routine completed successfully.
@return EFI_INVALID_PARAMETER The input power level or state is not within range.
@return Others Other failures from interrupt setup/restorations.
**/
EFI_STATUS
EFIAPI
MpMgmtBspSuspend (
IN MP_MANAGEMENT_PROTOCOL *This,
IN AP_POWER_STATE BspPowerState,
IN UINTN TargetPowerLevel, OPTIONAL
IN UINTN TimeoutInMicroseconds
)
{
EFI_STATUS Status;
EFI_HANDLE Handle;
if (BspPowerState >= AP_POWER_NUM) {
DEBUG ((DEBUG_ERROR, "%a The power state is not supported %d\n", __FUNCTION__, BspPowerState));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// set up timer and turn off others...
Status = CpuArchDisableAllInterruptsButSetupTimer (&Handle, TimeoutInMicroseconds);
switch (BspPowerState) {
case AP_POWER_C1:
DEBUG ((DEBUG_INFO, "%a See you later.\n", __FUNCTION__));
Status = CpuArchHalt ();
if (EFI_ERROR (Status)) {
// if we ever return from this power level, something is off.
DEBUG ((DEBUG_INFO, "%a failed to clock gate, and it is off now - %r.\n", __FUNCTION__, Status));
}
break;
case AP_POWER_C2:
DEBUG ((DEBUG_INFO, "%a Siesta time.\n", __FUNCTION__));
Status = CpuArchClockGate (TargetPowerLevel);
if (EFI_ERROR (Status)) {
// if we ever return from this power level, something is off.
DEBUG ((DEBUG_INFO, "%a failed to enter stand by, and it is off now - %r.\n", __FUNCTION__, Status));
}
break;
case AP_POWER_C3:
DEBUG ((DEBUG_INFO, "%a Good night.\n", __FUNCTION__));
// Setup a long jump buffer so that the cores can come back to the same place after resuming.
if (SetJump ((BASE_LIBRARY_JUMP_BUFFER *)(&(mCommonBuffer[mBspIndex].JumpBuffer))) == 0) {
Status = CpuArchSleep (TargetPowerLevel);
if (EFI_ERROR (Status)) {
// if we ever return from this power level, something is off.
DEBUG ((DEBUG_INFO, "%a failed to sleep, and it is off now - %r.\n", __FUNCTION__, Status));
} else {
// This does not make much sense, C3 sleep should not come back here.
ASSERT (FALSE);
}
} else {
// Got back from the C-states, do some more clean up for BSP.
}
break;
default:
ASSERT (FALSE);
break;
}
Done:
Status = CpuArchRestoreAllInterrupts (Handle);
return Status;
}
/**
Function to perform AP power on.
@param This MP Management Protocol.
@param ProcessorNumber The CPU index to be powered on.
@return EFI_SUCCESS The routine completed successfully.
@return EFI_INVALID_PARAMETER The CPU index is out of range.
@return EFI_NOT_READY The MP service is not initialized.
@return EFI_ALREADY_STARTED The target AP is already in ON state.
@return EFI_ABORTED The target AP is in unexpected states.
@return Others Other errors from MP services.
**/
STATIC
EFI_STATUS
EFIAPI
MpMgmtApOn (
IN MP_MANAGEMENT_PROTOCOL *This,
IN UINTN ProcessorNumber
)
{
EFI_STATUS Status;
UINTN StartIndex;
UINTN EndIndex;
UINTN Index;
if ((ProcessorNumber == mBspIndex) || ((ProcessorNumber > mNumCpus) && (ProcessorNumber != OPERATION_FOR_ALL_APS))) {
DEBUG ((DEBUG_ERROR, "%a The specified processor is not acceptable %d\n", __FUNCTION__, ProcessorNumber));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (mCommonBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "%a The common buffer is not set up\n", __FUNCTION__));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (mMpServices == NULL) {
DEBUG ((DEBUG_ERROR, "%a Mp service is not ready\n", __FUNCTION__));
Status = EFI_NOT_READY;
goto Done;
}
if (ProcessorNumber == OPERATION_FOR_ALL_APS) {
StartIndex = 0;
EndIndex = mNumCpus - 1;
} else {
StartIndex = ProcessorNumber;
EndIndex = ProcessorNumber;
}
Status = EFI_NOT_FOUND;
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
if (mCommonBuffer[Index].ApStatus == AP_STATE_ON) {
DEBUG ((DEBUG_WARN, "%a The specified processor (%d) is already in ON\n", __FUNCTION__, Index));
Status = EFI_ALREADY_STARTED;
continue;
}
if (mCommonBuffer[Index].ApStatus != AP_STATE_OFF) {
DEBUG ((DEBUG_ERROR, "%a The specified processor (%d) is already started\n", __FUNCTION__, Index));
Status = EFI_ABORTED;
break;
}
// Update the task flag to be active, AP will clear it once wake up.
mCommonBuffer[Index].TargetStatus = AP_STATE_ON;
ZeroMem (mCommonBuffer[Index].ApBuffer, mCommonBuffer[Index].ApBufferSize);
// This is the flag to release the core.
mCommonBuffer[Index].ApTask = AP_TASK_ACTIVE;
Status = mMpServices->StartupThisAP (
mMpServices,
ApFunction,
Index,
NULL,
1,
NULL,
NULL
);
// TODO: This is not quite right. The protocol will only support blocking mode after RTB...
if ((Status != EFI_SUCCESS) && (Status != EFI_TIMEOUT)) {
DEBUG ((DEBUG_ERROR, "%a Failed to start processor %d: %r\n", __FUNCTION__, Index, Status));
break;
} else {
Status = EFI_SUCCESS;
}
}
if (EFI_ERROR (Status)) {
goto Done;
}
// If successful, print the hellow world (blocking) from the APs.
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
// Loop till specified AP is up and running
while (mCommonBuffer[Index].ApTask != AP_TASK_IDLE) {
}
DEBUG ((DEBUG_INFO, "Initial message from common buffer: %a\n", (CHAR8 *)mCommonBuffer[Index].ApBuffer));
}
Done:
return Status;
}
/**
Function to perform AP power off.
@param This MP Management Protocol.
@param ProcessorNumber The CPU index to be powered off.
@return EFI_SUCCESS The routine completed successfully.
@return EFI_INVALID_PARAMETER The CPU index is out of range.
@return EFI_NOT_READY The MP service is not initialized.
@return EFI_ALREADY_STARTED The target AP is already in OFF state.
@return EFI_ABORTED The target AP is in unexpected states.
@return Others Other errors from MP services.
**/
STATIC
EFI_STATUS
EFIAPI
MpMgmtApOff (
IN MP_MANAGEMENT_PROTOCOL *This,
IN UINTN ProcessorNumber
)
{
EFI_STATUS Status;
UINTN StartIndex;
UINTN EndIndex;
UINTN Index;
if ((ProcessorNumber == mBspIndex) || ((ProcessorNumber > mNumCpus) && (ProcessorNumber != OPERATION_FOR_ALL_APS))) {
DEBUG ((DEBUG_ERROR, "%a The specified processor is not acceptable %d\n", __FUNCTION__, ProcessorNumber));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (mCommonBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "%a The common buffer is not set up\n", __FUNCTION__));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (ProcessorNumber == OPERATION_FOR_ALL_APS) {
StartIndex = 0;
EndIndex = mNumCpus - 1;
} else {
StartIndex = ProcessorNumber;
EndIndex = ProcessorNumber;
}
Status = EFI_NOT_FOUND;
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
if (mCommonBuffer[Index].ApStatus == AP_STATE_OFF) {
DEBUG ((DEBUG_WARN, "%a The specified processor (%d) is already in OFF state\n", __FUNCTION__, Index));
Status = EFI_ALREADY_STARTED;
continue;
}
if (mCommonBuffer[Index].ApStatus != AP_STATE_ON) {
DEBUG ((DEBUG_ERROR, "%a The specified processor (%d) is not in ON state (%d)\n", __FUNCTION__, Index, mCommonBuffer[Index].ApStatus));
Status = EFI_ABORTED;
break;
}
// Update the task flag to be active, AP will clear it once wake up.
mCommonBuffer[Index].TargetStatus = AP_STATE_OFF;
mCommonBuffer[Index].ApTask = AP_TASK_ACTIVE;
// At least we are successful for this AP.
Status = EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
goto Done;
}
// If successful, print the hellow world (blocking) from the APs.
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
// Loop till specified AP is up and running
while (mCommonBuffer[Index].ApTask != AP_TASK_IDLE) {
}
DEBUG ((DEBUG_INFO, "Last word from common buffer: %a\n", (CHAR8 *)mCommonBuffer[Index].ApBuffer));
}
// TODO: This is not ideal, but we could have messed up with the AP status here, wait for a bit to let the timer do the cleanup
gBS->Stall (50000);
Done:
return Status;
}
/**
Function to perform AP execution suspend.
@param This MP Management Protocol.
@param ProcessorNumber The CPU index to be powered off.
@param ApPowerState The intended power state the CPU should be suspended to.
The support input values are defined in AP_POWER_STATE.
@param TargetPowerLevel The target power level of AP when suspended, certain
architecture could require this value to be paired with
ApPowerState.
@return EFI_SUCCESS The routine completed successfully.
@return EFI_INVALID_PARAMETER The CPU index is out of range or power state is
not setup properly.
@return EFI_NOT_READY The MP service is not initialized.
@return EFI_ALREADY_STARTED The target AP is already in intended power state.
@return EFI_ABORTED The target AP is in unexpected states.
**/
STATIC
EFI_STATUS
EFIAPI
MpMgmtApSuspend (
IN MP_MANAGEMENT_PROTOCOL *This,
IN UINTN ProcessorNumber,
IN AP_POWER_STATE ApPowerState,
IN UINTN TargetPowerLevel OPTIONAL
)
{
EFI_STATUS Status;
UINTN StartIndex;
UINTN EndIndex;
UINTN Index;
UINTN InternalApPowerState;
if ((ProcessorNumber == mBspIndex) || ((ProcessorNumber > mNumCpus) && (ProcessorNumber != OPERATION_FOR_ALL_APS))) {
DEBUG ((DEBUG_ERROR, "%a The specified processor is not acceptable %d\n", __FUNCTION__, ProcessorNumber));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (mCommonBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "%a The common buffer is not set up\n", __FUNCTION__));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (ApPowerState >= AP_POWER_NUM) {
DEBUG ((DEBUG_ERROR, "%a The power state is not supported %d\n", __FUNCTION__, ApPowerState));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// Translate it to the internal state
switch (ApPowerState) {
case AP_POWER_C1:
InternalApPowerState = AP_STATE_SUSPEND_HALT;
break;
case AP_POWER_C2:
InternalApPowerState = AP_STATE_SUSPEND_CLOCK_GATE;
break;
case AP_POWER_C3:
InternalApPowerState = AP_STATE_SUSPEND_SLEEP;
break;
default:
// Should not happen...
ASSERT (FALSE);
break;
}
if (ProcessorNumber == OPERATION_FOR_ALL_APS) {
StartIndex = 0;
EndIndex = mNumCpus - 1;
} else {
StartIndex = ProcessorNumber;
EndIndex = ProcessorNumber;
}
Status = EFI_NOT_FOUND;
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
if (mCommonBuffer[Index].ApStatus == InternalApPowerState) {
DEBUG ((DEBUG_WARN, "%a The specified processor (%d) is already in expected state (%d)\n", __FUNCTION__, Index, InternalApPowerState));
Status = EFI_ALREADY_STARTED;
continue;
}
if (mCommonBuffer[Index].ApStatus != AP_STATE_ON) {
DEBUG ((DEBUG_ERROR, "%a The specified processor (%d) is not in ON state (%d)\n", __FUNCTION__, Index, mCommonBuffer[Index].ApStatus));
Status = EFI_ABORTED;
break;
}
// Update the task flag to be active, AP will clear it once wake up.
mCommonBuffer[Index].TargetStatus = InternalApPowerState;
mCommonBuffer[Index].TargetPowerState = TargetPowerLevel;
mCommonBuffer[Index].ApTask = AP_TASK_ACTIVE;
// At least we are successful for this AP.
Status = EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
goto Done;
}
// If successful, print the hellow world (blocking) from the APs.
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
// Loop till specified AP is up and running
while (mCommonBuffer[Index].ApTask != AP_TASK_IDLE) {
}
DEBUG ((DEBUG_INFO, "Suspend message from common buffer: %a\n", (CHAR8 *)mCommonBuffer[Index].ApBuffer));
}
// TODO: This is not ideal, but we could have messed up with the AP status here, wait for a bit to let the timer do the cleanup
gBS->Stall (50000);
Done:
return Status;
}
/**
Function to perform AP execution resumption.
@param This MP Management Protocol.
@param ProcessorNumber The CPU index to be powered off.
@return EFI_SUCCESS The routine completed successfully.
@return EFI_INVALID_PARAMETER The CPU index is out of range or power state is
not setup properly.
@return EFI_NOT_READY The MP service is not initialized.
@return EFI_ALREADY_STARTED The target AP is already in ON state.
@return EFI_ABORTED The target AP is in unexpected states.
**/
STATIC
EFI_STATUS
EFIAPI
MpMgmtApResume (
IN MP_MANAGEMENT_PROTOCOL *This,
IN UINTN ProcessorNumber
)
{
EFI_STATUS Status;
UINTN StartIndex;
UINTN EndIndex;
UINTN Index;
if ((ProcessorNumber == mBspIndex) || ((ProcessorNumber > mNumCpus) && (ProcessorNumber != OPERATION_FOR_ALL_APS))) {
DEBUG ((DEBUG_ERROR, "%a The specified processor is not acceptable %d\n", __FUNCTION__, ProcessorNumber));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (mCommonBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "%a The common buffer is not set up\n", __FUNCTION__));
Status = EFI_INVALID_PARAMETER;
goto Done;
}
if (ProcessorNumber == OPERATION_FOR_ALL_APS) {
StartIndex = 0;
EndIndex = mNumCpus - 1;
} else {
StartIndex = ProcessorNumber;
EndIndex = ProcessorNumber;
}
Status = EFI_NOT_FOUND;
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
if (mCommonBuffer[Index].ApStatus == AP_STATE_ON) {
DEBUG ((DEBUG_WARN, "%a The specified processor (%d) is already fully up\n", __FUNCTION__, Index));
Status = EFI_ALREADY_STARTED;
continue;
}
if ((mCommonBuffer[Index].ApStatus != AP_STATE_SUSPEND_HALT) &&
(mCommonBuffer[Index].ApStatus != AP_STATE_SUSPEND_CLOCK_GATE) &&
(mCommonBuffer[Index].ApStatus != AP_STATE_SUSPEND_SLEEP))
{
DEBUG ((DEBUG_ERROR, "%a The specified processor (%d) is not in expected state (%d)\n", __FUNCTION__, Index, mCommonBuffer[Index].ApStatus));
Status = EFI_ABORTED;
break;
}
// Update the task flag to be active, AP will clear it once wake up.
mCommonBuffer[Index].TargetStatus = AP_STATE_RESUME;
mCommonBuffer[Index].ApTask = AP_TASK_ACTIVE;
// Abstracted call to allow arch specific method to wake up this CPU
CpuArchWakeFromSleep (Index);
// At least we are successful for this AP.
Status = EFI_SUCCESS;
}
if (EFI_ERROR (Status)) {
goto Done;
}
// If successful, print the hellow world (blocking) from the APs.
for (Index = StartIndex; Index <= EndIndex; Index++) {
if (Index == mBspIndex) {
continue;
}
// Loop till specified AP is up and running
while (mCommonBuffer[Index].ApTask != AP_TASK_IDLE) {
}
DEBUG ((DEBUG_INFO, "Resume message from common buffer: %a\n", (CHAR8 *)mCommonBuffer[Index].ApBuffer));
}
Done:
return Status;
}
MP_MANAGEMENT_PROTOCOL mMpManagement = {
.BspSuspend = MpMgmtBspSuspend,
.ApOn = MpMgmtApOn,
.ApOff = MpMgmtApOff,
.ApSuspend = MpMgmtApSuspend,
.ApResume = MpMgmtApResume
};
/**
The user Entry Point for Application. The user code starts with this function
as the real entry point for the application.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
MpManagementEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *Image;
Status = gBS->HandleProtocol (
ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **)&Image
);
ASSERT_EFI_ERROR (Status);
//
// Parts of the code in this driver may be executed by other cores running
// with the MMU off so we need to ensure that everything is clean to the
// point of coherency (PoC)
//
WriteBackDataCacheRange (Image->ImageBase, Image->ImageSize);
Status = gBS->LocateProtocol (
&gEfiMpServiceProtocolGuid,
NULL,
(VOID **)&mMpServices
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to locate EFI_MP_SERVICES_PROTOCOL (%r). Not installed on platform?\n", Status));
goto Done;
}
Status = GetProcessorInformation (mMpServices, &mNumCpus, &mBspIndex);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Error: Failed to fetch processor information.\n"));
goto Done;
}
Status = InitializeApCommonBuffer (mNumCpus, (MP_MANAGEMENT_METADATA **)&mCommonBuffer);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Error: Failed to initialize Ap common buffer - %r.\n", Status));
goto Done;
}
Status = CpuMpArchInit (mNumCpus);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->InstallProtocolInterface (
&mHandle,
&gMpManagementProtocolGuid,
EFI_NATIVE_INTERFACE,
&mMpManagement
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Error: Failed to fetch processor information.\n"));
goto Done;
}
Done:
return Status;
}