diff options
author | Xie, Yuanhao <yuanhao.xie@intel.com> | 2023-06-28 16:47:21 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-07-11 02:47:27 +0000 |
commit | 243212b0d0bb33d0a64db8cd974d243e5aefdf3d (patch) | |
tree | 0431b5494b3c41f0ec6aca6c328bc3b4a93e64fa | |
parent | 88f436883b45b090adaec2099728d224e47ff51f (diff) | |
download | edk2-243212b0d0bb33d0a64db8cd974d243e5aefdf3d.tar.gz |
UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop.
Refactor the logic for placing APs in
Mwait/Runloop into a separate function.
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
-rw-r--r-- | UefiCpuPkg/Library/MpInitLib/MpLib.c | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index 9560b39220..e8dd640f9b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -659,6 +659,54 @@ PlaceAPInHltLoop ( }
/**
+ This function place APs in Mwait or Run loop.
+
+ @param[in] ApLoopMode Ap Loop Mode
+ @param[in] ApStartupSignalBuffer Pointer to Ap Startup Signal Buffer
+ @param[in] ApTargetCState Ap Target CState
+**/
+VOID
+PlaceAPInMwaitLoopOrRunLoop (
+ IN UINT8 ApLoopMode,
+ IN volatile UINT32 *ApStartupSignalBuffer,
+ IN UINT8 ApTargetCState
+ )
+{
+ while (TRUE) {
+ DisableInterrupts ();
+ if (ApLoopMode == ApInMwaitLoop) {
+ //
+ // Place AP in MWAIT-loop
+ //
+ AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0);
+ if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
+ //
+ // Check AP start-up signal again.
+ // If AP start-up signal is not set, place AP into
+ // the specified C-state
+ //
+ AsmMwait (ApTargetCState << 4, 0);
+ }
+ } else if (ApLoopMode == ApInRunLoop) {
+ //
+ // Place AP in Run-loop
+ //
+ CpuPause ();
+ } else {
+ ASSERT (FALSE);
+ }
+
+ //
+ // If AP start-up signal is written, AP is waken up
+ // otherwise place AP in loop again
+ //
+ if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
+ break;
+ }
+ }
+}
+
+/**
This function will be called from AP reset code if BSP uses WakeUpAP.
@param[in] ExchangeInfo Pointer to the MP exchange info buffer
@@ -838,39 +886,8 @@ ApWakeupFunction ( //
// Never run here
//
- }
-
- while (TRUE) {
- DisableInterrupts ();
- if (CpuMpData->ApLoopMode == ApInMwaitLoop) {
- //
- // Place AP in MWAIT-loop
- //
- AsmMonitor ((UINTN)ApStartupSignalBuffer, 0, 0);
- if (*ApStartupSignalBuffer != WAKEUP_AP_SIGNAL) {
- //
- // Check AP start-up signal again.
- // If AP start-up signal is not set, place AP into
- // the specified C-state
- //
- AsmMwait (CpuMpData->ApTargetCState << 4, 0);
- }
- } else if (CpuMpData->ApLoopMode == ApInRunLoop) {
- //
- // Place AP in Run-loop
- //
- CpuPause ();
- } else {
- ASSERT (FALSE);
- }
-
- //
- // If AP start-up signal is written, AP is waken up
- // otherwise place AP in loop again
- //
- if (*ApStartupSignalBuffer == WAKEUP_AP_SIGNAL) {
- break;
- }
+ } else {
+ PlaceAPInMwaitLoopOrRunLoop (CpuMpData->ApLoopMode, ApStartupSignalBuffer, CpuMpData->ApTargetCState);
}
}
}
|