/** @file\r
- CPU DXE Module.\r
+ CPU DXE Module to produce CPU MP Protocol.\r
\r
- Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include "CpuDxe.h"\r
#include "CpuMp.h"\r
\r
-UINTN gMaxLogicalProcessorNumber;\r
-UINTN gApStackSize;\r
-\r
-VOID *mCommonStack = 0;\r
-VOID *mTopOfApCommonStack = 0;\r
-VOID *mApStackStart = 0;\r
-\r
-volatile UINTN mNumberOfProcessors;\r
+EFI_HANDLE mMpServiceHandle = NULL;\r
+UINTN mNumberOfProcessors = 1;\r
\r
EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = {\r
- NULL, // GetNumberOfProcessors,\r
- NULL, // GetProcessorInfo,\r
- NULL, // StartupAllAPs,\r
- NULL, // StartupThisAP,\r
- NULL, // SwitchBSP,\r
- NULL, // EnableDisableAP,\r
- NULL // WhoAmI\r
+ GetNumberOfProcessors,\r
+ GetProcessorInfo,\r
+ StartupAllAPs,\r
+ StartupThisAP,\r
+ SwitchBSP,\r
+ EnableDisableAP,\r
+ WhoAmI\r
};\r
\r
/**\r
- Application Processors do loop routine\r
- after switch to its own stack.\r
+ This service retrieves the number of logical processor in the platform\r
+ and the number of those logical processors that are enabled on this boot.\r
+ This service may only be called from the BSP.\r
+\r
+ This function is used to retrieve the following information:\r
+ - The number of logical processors that are present in the system.\r
+ - The number of enabled logical processors in the system at the instant\r
+ this call is made.\r
+\r
+ Because MP Service Protocol provides services to enable and disable processors\r
+ dynamically, the number of enabled logical processors may vary during the\r
+ course of a boot session.\r
+\r
+ If this service is called from an AP, then EFI_DEVICE_ERROR is returned.\r
+ If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then\r
+ EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors\r
+ is returned in NumberOfProcessors, the number of currently enabled processor\r
+ is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.\r
\r
- @param Context1 A pointer to the context to pass into the function.\r
- @param Context2 A pointer to the context to pass into the function.\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+ instance.\r
+ @param[out] NumberOfProcessors Pointer to the total number of logical\r
+ processors in the system, including the BSP\r
+ and disabled APs.\r
+ @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical\r
+ processors that exist in system, including\r
+ the BSP.\r
+\r
+ @retval EFI_SUCCESS The number of logical processors and enabled\r
+ logical processors was retrieved.\r
+ @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
+ @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.\r
+ @retval EFI_INVALID_PARAMETER NumberOfEnabledProcessors is NULL.\r
\r
**/\r
-VOID\r
-ProcessorToIdleState (\r
- IN VOID *Context1, OPTIONAL\r
- IN VOID *Context2 OPTIONAL\r
+EFI_STATUS\r
+EFIAPI\r
+GetNumberOfProcessors (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ OUT UINTN *NumberOfProcessors,\r
+ OUT UINTN *NumberOfEnabledProcessors\r
)\r
{\r
- DEBUG ((DEBUG_INFO, "Ap apicid is %d\n", GetApicId ()));\r
+ if ((NumberOfProcessors == NULL) || (NumberOfEnabledProcessors == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
\r
- AsmApDoneWithCommonStack ();\r
+ return MpInitLibGetNumberOfProcessors (\r
+ NumberOfProcessors,\r
+ NumberOfEnabledProcessors\r
+ );\r
+}\r
\r
- CpuSleep ();\r
- CpuDeadLoop ();\r
+/**\r
+ Gets detailed MP-related information on the requested processor at the\r
+ instant this call is made. This service may only be called from the BSP.\r
+\r
+ This service retrieves detailed MP-related information about any processor\r
+ on the platform. Note the following:\r
+ - The processor information may change during the course of a boot session.\r
+ - The information presented here is entirely MP related.\r
+\r
+ Information regarding the number of caches and their sizes, frequency of operation,\r
+ slot numbers is all considered platform-related information and is not provided\r
+ by this service.\r
+\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+ instance.\r
+ @param[in] ProcessorNumber The handle number of processor.\r
+ @param[out] ProcessorInfoBuffer A pointer to the buffer where information for\r
+ the requested processor is deposited.\r
+\r
+ @retval EFI_SUCCESS Processor information was returned.\r
+ @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
+ @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r
+ @retval EFI_NOT_FOUND The processor with the handle specified by\r
+ ProcessorNumber does not exist in the platform.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetProcessorInfo (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ IN UINTN ProcessorNumber,\r
+ OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer\r
+ )\r
+{\r
+ return MpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, NULL);\r
}\r
\r
/**\r
- Application Processor C code entry point.\r
+ This service executes a caller provided function on all enabled APs. APs can\r
+ run either simultaneously or one at a time in sequence. This service supports\r
+ both blocking and non-blocking requests. The non-blocking requests use EFI\r
+ events so the BSP can detect when the APs have finished. This service may only\r
+ be called from the BSP.\r
+\r
+ This function is used to dispatch all the enabled APs to the function specified\r
+ by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned\r
+ immediately and Procedure is not started on any AP.\r
+\r
+ If SingleThread is TRUE, all the enabled APs execute the function specified by\r
+ Procedure one by one, in ascending order of processor handle number. Otherwise,\r
+ all the enabled APs execute the function specified by Procedure simultaneously.\r
+\r
+ If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all\r
+ APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking\r
+ mode, and the BSP returns from this service without waiting for APs. If a\r
+ non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT\r
+ is signaled, then EFI_UNSUPPORTED must be returned.\r
+\r
+ If the timeout specified by TimeoutInMicroseconds expires before all APs return\r
+ from Procedure, then Procedure on the failed APs is terminated. All enabled APs\r
+ are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r
+ and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its\r
+ content points to the list of processor handle numbers in which Procedure was\r
+ terminated.\r
+\r
+ Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r
+ to make sure that the nature of the code that is executed on the BSP and the\r
+ dispatched APs is well controlled. The MP Services Protocol does not guarantee\r
+ that the Procedure function is MP-safe. Hence, the tasks that can be run in\r
+ parallel are limited to certain independent tasks and well-controlled exclusive\r
+ code. EFI services and protocols may not be called by APs unless otherwise\r
+ specified.\r
+\r
+ In blocking execution mode, BSP waits until all APs finish or\r
+ TimeoutInMicroseconds expires.\r
+\r
+ In non-blocking execution mode, BSP is freed to return to the caller and then\r
+ proceed to the next task without having to wait for APs. The following\r
+ sequence needs to occur in a non-blocking execution mode:\r
+\r
+ -# The caller that intends to use this MP Services Protocol in non-blocking\r
+ mode creates WaitEvent by calling the EFI CreateEvent() service. The caller\r
+ invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent\r
+ is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests\r
+ the function specified by Procedure to be started on all the enabled APs,\r
+ and releases the BSP to continue with other tasks.\r
+ -# The caller can use the CheckEvent() and WaitForEvent() services to check\r
+ the state of the WaitEvent created in step 1.\r
+ -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP\r
+ Service signals WaitEvent by calling the EFI SignalEvent() function. If\r
+ FailedCpuList is not NULL, its content is available when WaitEvent is\r
+ signaled. If all APs returned from Procedure prior to the timeout, then\r
+ FailedCpuList is set to NULL. If not all APs return from Procedure before\r
+ the timeout, then FailedCpuList is filled in with the list of the failed\r
+ APs. The buffer is allocated by MP Service Protocol using AllocatePool().\r
+ It is the caller's responsibility to free the buffer with FreePool() service.\r
+ -# This invocation of SignalEvent() function informs the caller that invoked\r
+ EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed\r
+ the specified task or a timeout occurred. The contents of FailedCpuList\r
+ can be examined to determine which APs did not complete the specified task\r
+ prior to the timeout.\r
+\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+ instance.\r
+ @param[in] Procedure A pointer to the function to be run on\r
+ enabled APs of the system. See type\r
+ EFI_AP_PROCEDURE.\r
+ @param[in] SingleThread If TRUE, then all the enabled APs execute\r
+ the function specified by Procedure one by\r
+ one, in ascending order of processor handle\r
+ number. If FALSE, then all the enabled APs\r
+ execute the function specified by Procedure\r
+ simultaneously.\r
+ @param[in] WaitEvent The event created by the caller with CreateEvent()\r
+ service. If it is NULL, then execute in\r
+ blocking mode. BSP waits until all APs finish\r
+ or TimeoutInMicroseconds expires. If it's\r
+ not NULL, then execute in non-blocking mode.\r
+ BSP requests the function specified by\r
+ Procedure to be started on all the enabled\r
+ APs, and go on executing immediately. If\r
+ all return from Procedure, or TimeoutInMicroseconds\r
+ expires, this event is signaled. The BSP\r
+ can use the CheckEvent() or WaitForEvent()\r
+ services to check the state of event. Type\r
+ EFI_EVENT is defined in CreateEvent() in\r
+ the Unified Extensible Firmware Interface\r
+ Specification.\r
+ @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
+ APs to return from Procedure, either for\r
+ blocking or non-blocking mode. Zero means\r
+ infinity. If the timeout expires before\r
+ all APs return from Procedure, then Procedure\r
+ on the failed APs is terminated. All enabled\r
+ APs are available for next function assigned\r
+ by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r
+ or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
+ If the timeout expires in blocking mode,\r
+ BSP returns EFI_TIMEOUT. If the timeout\r
+ expires in non-blocking mode, WaitEvent\r
+ is signaled with SignalEvent().\r
+ @param[in] ProcedureArgument The parameter passed into Procedure for\r
+ all APs.\r
+ @param[out] FailedCpuList If NULL, this parameter is ignored. Otherwise,\r
+ if all APs finish successfully, then its\r
+ content is set to NULL. If not all APs\r
+ finish before timeout expires, then its\r
+ content is set to address of the buffer\r
+ holding handle numbers of the failed APs.\r
+ The buffer is allocated by MP Service Protocol,\r
+ and it's the caller's responsibility to\r
+ free the buffer with FreePool() service.\r
+ In blocking mode, it is ready for consumption\r
+ when the call returns. In non-blocking mode,\r
+ it is ready when WaitEvent is signaled. The\r
+ list of failed CPU is terminated by\r
+ END_OF_CPU_LIST.\r
+\r
+ @retval EFI_SUCCESS In blocking mode, all APs have finished before\r
+ the timeout expired.\r
+ @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r
+ to all enabled APs.\r
+ @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r
+ UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
+ signaled.\r
+ @retval EFI_DEVICE_ERROR Caller processor is AP.\r
+ @retval EFI_NOT_STARTED No enabled APs exist in the system.\r
+ @retval EFI_NOT_READY Any enabled APs are busy.\r
+ @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r
+ all enabled APs have finished.\r
+ @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
\r
**/\r
-VOID\r
+EFI_STATUS\r
EFIAPI\r
-ApEntryPointInC (\r
- VOID\r
+StartupAllAPs (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ IN EFI_AP_PROCEDURE Procedure,\r
+ IN BOOLEAN SingleThread,\r
+ IN EFI_EVENT WaitEvent OPTIONAL,\r
+ IN UINTN TimeoutInMicroseconds,\r
+ IN VOID *ProcedureArgument OPTIONAL,\r
+ OUT UINTN **FailedCpuList OPTIONAL\r
)\r
{\r
- mNumberOfProcessors++;\r
- mApStackStart = (UINT8*)mApStackStart + gApStackSize;\r
-\r
- SwitchStack (\r
- (SWITCH_STACK_ENTRY_POINT)(UINTN)ProcessorToIdleState,\r
- NULL,\r
- NULL,\r
- mApStackStart);\r
+ return MpInitLibStartupAllAPs (\r
+ Procedure,\r
+ SingleThread,\r
+ WaitEvent,\r
+ TimeoutInMicroseconds,\r
+ ProcedureArgument,\r
+ FailedCpuList\r
+ );\r
}\r
\r
+/**\r
+ This service lets the caller get one enabled AP to execute a caller-provided\r
+ function. The caller can request the BSP to either wait for the completion\r
+ of the AP or just proceed with the next task by using the EFI event mechanism.\r
+ See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking\r
+ execution support. This service may only be called from the BSP.\r
+\r
+ This function is used to dispatch one enabled AP to the function specified by\r
+ Procedure passing in the argument specified by ProcedureArgument. If WaitEvent\r
+ is NULL, execution is in blocking mode. The BSP waits until the AP finishes or\r
+ TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.\r
+ BSP proceeds to the next task without waiting for the AP. If a non-blocking mode\r
+ is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,\r
+ then EFI_UNSUPPORTED must be returned.\r
+\r
+ If the timeout specified by TimeoutInMicroseconds expires before the AP returns\r
+ from Procedure, then execution of Procedure by the AP is terminated. The AP is\r
+ available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and\r
+ EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
+\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL\r
+ instance.\r
+ @param[in] Procedure A pointer to the function to be run on the\r
+ designated AP of the system. See type\r
+ EFI_AP_PROCEDURE.\r
+ @param[in] ProcessorNumber The handle number of the AP. The range is\r
+ from 0 to the total number of logical\r
+ processors minus 1. The total number of\r
+ logical processors can be retrieved by\r
+ EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+ @param[in] WaitEvent The event created by the caller with CreateEvent()\r
+ service. If it is NULL, then execute in\r
+ blocking mode. BSP waits until this AP finish\r
+ or TimeoutInMicroSeconds expires. If it's\r
+ not NULL, then execute in non-blocking mode.\r
+ BSP requests the function specified by\r
+ Procedure to be started on this AP,\r
+ and go on executing immediately. If this AP\r
+ return from Procedure or TimeoutInMicroSeconds\r
+ expires, this event is signaled. The BSP\r
+ can use the CheckEvent() or WaitForEvent()\r
+ services to check the state of event. Type\r
+ EFI_EVENT is defined in CreateEvent() in\r
+ the Unified Extensible Firmware Interface\r
+ Specification.\r
+ @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
+ this AP to finish this Procedure, either for\r
+ blocking or non-blocking mode. Zero means\r
+ infinity. If the timeout expires before\r
+ this AP returns from Procedure, then Procedure\r
+ on the AP is terminated. The\r
+ AP is available for next function assigned\r
+ by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()\r
+ or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().\r
+ If the timeout expires in blocking mode,\r
+ BSP returns EFI_TIMEOUT. If the timeout\r
+ expires in non-blocking mode, WaitEvent\r
+ is signaled with SignalEvent().\r
+ @param[in] ProcedureArgument The parameter passed into Procedure on the\r
+ specified AP.\r
+ @param[out] Finished If NULL, this parameter is ignored. In\r
+ blocking mode, this parameter is ignored.\r
+ In non-blocking mode, if AP returns from\r
+ Procedure before the timeout expires, its\r
+ content is set to TRUE. Otherwise, the\r
+ value is set to FALSE. The caller can\r
+ determine if the AP returned from Procedure\r
+ by evaluating this value.\r
+\r
+ @retval EFI_SUCCESS In blocking mode, specified AP finished before\r
+ the timeout expires.\r
+ @retval EFI_SUCCESS In non-blocking mode, the function has been\r
+ dispatched to specified AP.\r
+ @retval EFI_UNSUPPORTED A non-blocking mode request was made after the\r
+ UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was\r
+ signaled.\r
+ @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
+ @retval EFI_TIMEOUT In blocking mode, the timeout expired before\r
+ the specified AP has finished.\r
+ @retval EFI_NOT_READY The specified AP is busy.\r
+ @retval EFI_NOT_FOUND The processor with the handle specified by\r
+ ProcessorNumber does not exist.\r
+ @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.\r
+ @retval EFI_INVALID_PARAMETER Procedure is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StartupThisAP (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ IN EFI_AP_PROCEDURE Procedure,\r
+ IN UINTN ProcessorNumber,\r
+ IN EFI_EVENT WaitEvent OPTIONAL,\r
+ IN UINTN TimeoutInMicroseconds,\r
+ IN VOID *ProcedureArgument OPTIONAL,\r
+ OUT BOOLEAN *Finished OPTIONAL\r
+ )\r
+{\r
+ return MpInitLibStartupThisAP (\r
+ Procedure,\r
+ ProcessorNumber,\r
+ WaitEvent,\r
+ TimeoutInMicroseconds,\r
+ ProcedureArgument,\r
+ Finished\r
+ );\r
+}\r
\r
/**\r
- Initialize Multi-processor support.\r
+ This service switches the requested AP to be the BSP from that point onward.\r
+ This service changes the BSP for all purposes. This call can only be performed\r
+ by the current BSP.\r
+\r
+ This service switches the requested AP to be the BSP from that point onward.\r
+ This service changes the BSP for all purposes. The new BSP can take over the\r
+ execution of the old BSP and continue seamlessly from where the old one left\r
+ off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT\r
+ is signaled.\r
+\r
+ If the BSP cannot be switched prior to the return from this service, then\r
+ EFI_UNSUPPORTED must be returned.\r
+\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
+ @param[in] ProcessorNumber The handle number of AP that is to become the new\r
+ BSP. The range is from 0 to the total number of\r
+ logical processors minus 1. The total number of\r
+ logical processors can be retrieved by\r
+ EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+ @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r
+ enabled AP. Otherwise, it will be disabled.\r
+\r
+ @retval EFI_SUCCESS BSP successfully switched.\r
+ @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to\r
+ this service returning.\r
+ @retval EFI_UNSUPPORTED Switching the BSP is not supported.\r
+ @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
+ @retval EFI_NOT_FOUND The processor with the handle specified by\r
+ ProcessorNumber does not exist.\r
+ @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or\r
+ a disabled AP.\r
+ @retval EFI_NOT_READY The specified AP is busy.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SwitchBSP (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ IN UINTN ProcessorNumber,\r
+ IN BOOLEAN EnableOldBSP\r
+ )\r
+{\r
+ return MpInitLibSwitchBSP (ProcessorNumber, EnableOldBSP);\r
+}\r
+\r
+/**\r
+ This service lets the caller enable or disable an AP from this point onward.\r
+ This service may only be called from the BSP.\r
+\r
+ This service allows the caller enable or disable an AP from this point onward.\r
+ The caller can optionally specify the health status of the AP by Health. If\r
+ an AP is being disabled, then the state of the disabled AP is implementation\r
+ dependent. If an AP is enabled, then the implementation must guarantee that a\r
+ complete initialization sequence is performed on the AP, so the AP is in a state\r
+ that is compatible with an MP operating system. This service may not be supported\r
+ after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.\r
+\r
+ If the enable or disable AP operation cannot be completed prior to the return\r
+ from this service, then EFI_UNSUPPORTED must be returned.\r
+\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
+ @param[in] ProcessorNumber The handle number of AP.\r
+ The range is from 0 to the total number of\r
+ logical processors minus 1. The total number of\r
+ logical processors can be retrieved by\r
+ EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+ @param[in] EnableAP Specifies the new state for the processor for\r
+ enabled, FALSE for disabled.\r
+ @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r
+ the new health status of the AP. This flag\r
+ corresponds to StatusFlag defined in\r
+ EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only\r
+ the PROCESSOR_HEALTH_STATUS_BIT is used. All other\r
+ bits are ignored. If it is NULL, this parameter\r
+ is ignored.\r
+\r
+ @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r
+ @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed\r
+ prior to this service returning.\r
+ @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.\r
+ @retval EFI_DEVICE_ERROR The calling processor is an AP.\r
+ @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber\r
+ does not exist.\r
+ @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EnableDisableAP (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ IN UINTN ProcessorNumber,\r
+ IN BOOLEAN EnableAP,\r
+ IN UINT32 *HealthFlag OPTIONAL\r
+ )\r
+{\r
+ return MpInitLibEnableDisableAP (ProcessorNumber, EnableAP, HealthFlag);\r
+}\r
+\r
+/**\r
+ This return the handle number for the calling processor. This service may be\r
+ called from the BSP and APs.\r
+\r
+ This service returns the processor handle number for the calling processor.\r
+ The returned value is in the range from 0 to the total number of logical\r
+ processors minus 1. The total number of logical processors can be retrieved\r
+ with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be\r
+ called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER\r
+ is returned. Otherwise, the current processors handle number is returned in\r
+ ProcessorNumber, and EFI_SUCCESS is returned.\r
+\r
+ @param[in] This A pointer to the EFI_MP_SERVICES_PROTOCOL instance.\r
+ @param[out] ProcessorNumber Pointer to the handle number of AP.\r
+ The range is from 0 to the total number of\r
+ logical processors minus 1. The total number of\r
+ logical processors can be retrieved by\r
+ EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().\r
+\r
+ @retval EFI_SUCCESS The current processor handle number was returned\r
+ in ProcessorNumber.\r
+ @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WhoAmI (\r
+ IN EFI_MP_SERVICES_PROTOCOL *This,\r
+ OUT UINTN *ProcessorNumber\r
+ )\r
+{\r
+ return MpInitLibWhoAmI (ProcessorNumber);;\r
+}\r
+\r
+/**\r
+ Collects BIST data from HOB.\r
+\r
+ This function collects BIST data from HOB built from Sec Platform Information\r
+ PPI or SEC Platform Information2 PPI.\r
\r
**/\r
VOID\r
-InitializeMpSupport (\r
+CollectBistDataFromHob (\r
VOID\r
)\r
{\r
- gMaxLogicalProcessorNumber = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber);\r
- if (gMaxLogicalProcessorNumber < 1) {\r
- DEBUG ((DEBUG_ERROR, "Setting PcdCpuMaxLogicalProcessorNumber should be more than zero.\n"));\r
- return;\r
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+ EFI_SEC_PLATFORM_INFORMATION_RECORD2 *SecPlatformInformation2;\r
+ EFI_SEC_PLATFORM_INFORMATION_RECORD *SecPlatformInformation;\r
+ UINTN NumberOfData;\r
+ EFI_SEC_PLATFORM_INFORMATION_CPU *CpuInstance;\r
+ EFI_SEC_PLATFORM_INFORMATION_CPU BspCpuInstance;\r
+ UINTN ProcessorNumber;\r
+ EFI_PROCESSOR_INFORMATION ProcessorInfo;\r
+ EFI_HEALTH_FLAGS BistData;\r
+ UINTN CpuInstanceNumber;\r
+\r
+ SecPlatformInformation2 = NULL;\r
+ SecPlatformInformation = NULL;\r
+\r
+ //\r
+ // Get gEfiSecPlatformInformation2PpiGuid Guided HOB firstly\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformation2PpiGuid);\r
+ if (GuidHob != NULL) {\r
+ //\r
+ // Sec Platform Information2 PPI includes BSP/APs' BIST information\r
+ //\r
+ SecPlatformInformation2 = GET_GUID_HOB_DATA (GuidHob);\r
+ NumberOfData = SecPlatformInformation2->NumberOfCpus;\r
+ CpuInstance = SecPlatformInformation2->CpuInstance;\r
+ } else {\r
+ //\r
+ // Otherwise, get gEfiSecPlatformInformationPpiGuid Guided HOB\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformationPpiGuid);\r
+ if (GuidHob != NULL) {\r
+ SecPlatformInformation = GET_GUID_HOB_DATA (GuidHob);\r
+ NumberOfData = 1;\r
+ //\r
+ // SEC Platform Information only includes BSP's BIST information\r
+ // does not have BSP's APIC ID\r
+ //\r
+ BspCpuInstance.CpuLocation = GetApicId ();\r
+ BspCpuInstance.InfoRecord.IA32HealthFlags.Uint32 = SecPlatformInformation->IA32HealthFlags.Uint32;\r
+ CpuInstance = &BspCpuInstance;\r
+ } else {\r
+ DEBUG ((DEBUG_INFO, "Does not find any HOB stored CPU BIST information!\n"));\r
+ //\r
+ // Does not find any HOB stored BIST information\r
+ //\r
+ return;\r
+ }\r
}\r
\r
- if (gMaxLogicalProcessorNumber == 1) {\r
- return;\r
+ for (ProcessorNumber = 0; ProcessorNumber < mNumberOfProcessors; ProcessorNumber++) {\r
+ MpInitLibGetProcessorInfo (ProcessorNumber, &ProcessorInfo, &BistData);\r
+ for (CpuInstanceNumber = 0; CpuInstanceNumber < NumberOfData; CpuInstanceNumber++) {\r
+ if (ProcessorInfo.ProcessorId == CpuInstance[CpuInstanceNumber].CpuLocation) {\r
+ //\r
+ // Update CPU health status for MP Services Protocol according to BIST data.\r
+ //\r
+ BistData = CpuInstance[CpuInstanceNumber].InfoRecord.IA32HealthFlags;\r
+ }\r
+ }\r
+ if (BistData.Uint32 != 0) {\r
+ //\r
+ // Report Status Code that self test is failed\r
+ //\r
+ REPORT_STATUS_CODE (\r
+ EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+ (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST)\r
+ );\r
+ }\r
}\r
+}\r
+\r
+/**\r
+ Get GDT register value.\r
+\r
+ This function is mainly for AP purpose because AP may have different GDT\r
+ table than BSP.\r
+\r
+ @param[in,out] Buffer The pointer to private data buffer.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+GetGdtr (\r
+ IN OUT VOID *Buffer\r
+ )\r
+{\r
+ AsmReadGdtr ((IA32_DESCRIPTOR *)Buffer);\r
+}\r
+\r
+/**\r
+ Initializes CPU exceptions handlers for the sake of stack switch requirement.\r
+\r
+ This function is a wrapper of InitializeCpuExceptionHandlersEx. It's mainly\r
+ for the sake of AP's init because of EFI_AP_PROCEDURE API requirement.\r
+\r
+ @param[in,out] Buffer The pointer to private data buffer.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+InitializeExceptionStackSwitchHandlers (\r
+ IN OUT VOID *Buffer\r
+ )\r
+{\r
+ CPU_EXCEPTION_INIT_DATA *EssData;\r
+ IA32_DESCRIPTOR Idtr;\r
+ EFI_STATUS Status;\r
+\r
+ EssData = Buffer;\r
+ //\r
+ // We don't plan to replace IDT table with a new one, but we should not assume\r
+ // the AP's IDT is the same as BSP's IDT either.\r
+ //\r
+ AsmReadIdtr (&Idtr);\r
+ EssData->Ia32.IdtTable = (VOID *)Idtr.Base;\r
+ EssData->Ia32.IdtTableSize = Idtr.Limit + 1;\r
+ Status = InitializeCpuExceptionHandlersEx (NULL, EssData);\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+ Initializes MP exceptions handlers for the sake of stack switch requirement.\r
+\r
+ This function will allocate required resources required to setup stack switch\r
+ and pass them through CPU_EXCEPTION_INIT_DATA to each logic processor.\r
\r
- gApStackSize = (UINTN) PcdGet32 (PcdCpuApStackSize);\r
- ASSERT ((gApStackSize & (SIZE_4KB - 1)) == 0);\r
+**/\r
+VOID\r
+InitializeMpExceptionStackSwitchHandlers (\r
+ VOID\r
+ )\r
+{\r
+ UINTN Index;\r
+ UINTN Bsp;\r
+ UINTN ExceptionNumber;\r
+ UINTN OldGdtSize;\r
+ UINTN NewGdtSize;\r
+ UINTN NewStackSize;\r
+ IA32_DESCRIPTOR Gdtr;\r
+ CPU_EXCEPTION_INIT_DATA EssData;\r
+ UINT8 *GdtBuffer;\r
+ UINT8 *StackTop;\r
+\r
+ ExceptionNumber = FixedPcdGetSize (PcdCpuStackSwitchExceptionList);\r
+ NewStackSize = FixedPcdGet32 (PcdCpuKnownGoodStackSize) * ExceptionNumber;\r
+\r
+ StackTop = AllocateRuntimeZeroPool (NewStackSize * mNumberOfProcessors);\r
+ ASSERT (StackTop != NULL);\r
+ StackTop += NewStackSize * mNumberOfProcessors;\r
+\r
+ //\r
+ // The default exception handlers must have been initialized. Let's just skip\r
+ // it in this method.\r
+ //\r
+ EssData.Ia32.Revision = CPU_EXCEPTION_INIT_DATA_REV;\r
+ EssData.Ia32.InitDefaultHandlers = FALSE;\r
\r
- mApStackStart = AllocatePages (EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
- ASSERT (mApStackStart != NULL);\r
+ EssData.Ia32.StackSwitchExceptions = FixedPcdGetPtr(PcdCpuStackSwitchExceptionList);\r
+ EssData.Ia32.StackSwitchExceptionNumber = ExceptionNumber;\r
+ EssData.Ia32.KnownGoodStackSize = FixedPcdGet32(PcdCpuKnownGoodStackSize);\r
\r
//\r
- // the first buffer of stack size used for common stack, when the amount of AP\r
- // more than 1, we should never free the common stack which maybe used for AP reset.\r
+ // Initialize Gdtr to suppress incorrect compiler/analyzer warnings.\r
//\r
- mCommonStack = mApStackStart;\r
- mTopOfApCommonStack = (UINT8*) mApStackStart + gApStackSize;\r
- mApStackStart = mTopOfApCommonStack;\r
+ Gdtr.Base = 0;\r
+ Gdtr.Limit = 0;\r
+ MpInitLibWhoAmI (&Bsp);\r
+ for (Index = 0; Index < mNumberOfProcessors; ++Index) {\r
+ //\r
+ // To support stack switch, we need to re-construct GDT but not IDT.\r
+ //\r
+ if (Index == Bsp) {\r
+ GetGdtr (&Gdtr);\r
+ } else {\r
+ //\r
+ // AP might have different size of GDT from BSP.\r
+ //\r
+ MpInitLibStartupThisAP (GetGdtr, Index, NULL, 0, (VOID *)&Gdtr, NULL);\r
+ }\r
\r
- mNumberOfProcessors = 1;\r
+ //\r
+ // X64 needs only one TSS of current task working for all exceptions\r
+ // because of its IST feature. IA32 needs one TSS for each exception\r
+ // in addition to current task. Since AP is not supposed to allocate\r
+ // memory, we have to do it in BSP. To simplify the code, we allocate\r
+ // memory for IA32 case to cover both IA32 and X64 exception stack\r
+ // switch.\r
+ //\r
+ // Layout of memory to allocate for each processor:\r
+ // --------------------------------\r
+ // | Alignment | (just in case)\r
+ // --------------------------------\r
+ // | |\r
+ // | Original GDT |\r
+ // | |\r
+ // --------------------------------\r
+ // | Current task descriptor |\r
+ // --------------------------------\r
+ // | |\r
+ // | Exception task descriptors | X ExceptionNumber\r
+ // | |\r
+ // --------------------------------\r
+ // | Current task-state segment |\r
+ // --------------------------------\r
+ // | |\r
+ // | Exception task-state segment | X ExceptionNumber\r
+ // | |\r
+ // --------------------------------\r
+ //\r
+ OldGdtSize = Gdtr.Limit + 1;\r
+ EssData.Ia32.ExceptionTssDescSize = sizeof (IA32_TSS_DESCRIPTOR) *\r
+ (ExceptionNumber + 1);\r
+ EssData.Ia32.ExceptionTssSize = sizeof (IA32_TASK_STATE_SEGMENT) *\r
+ (ExceptionNumber + 1);\r
+ NewGdtSize = sizeof (IA32_TSS_DESCRIPTOR) +\r
+ OldGdtSize +\r
+ EssData.Ia32.ExceptionTssDescSize +\r
+ EssData.Ia32.ExceptionTssSize;\r
\r
- if (mNumberOfProcessors == 1) {\r
- FreePages (mCommonStack, EFI_SIZE_TO_PAGES (gMaxLogicalProcessorNumber * gApStackSize));\r
- return;\r
+ GdtBuffer = AllocateRuntimeZeroPool (NewGdtSize);\r
+ ASSERT (GdtBuffer != NULL);\r
+\r
+ //\r
+ // Make sure GDT table alignment\r
+ //\r
+ EssData.Ia32.GdtTable = ALIGN_POINTER(GdtBuffer, sizeof (IA32_TSS_DESCRIPTOR));\r
+ NewGdtSize -= ((UINT8 *)EssData.Ia32.GdtTable - GdtBuffer);\r
+ EssData.Ia32.GdtTableSize = NewGdtSize;\r
+\r
+ EssData.Ia32.ExceptionTssDesc = ((UINT8 *)EssData.Ia32.GdtTable + OldGdtSize);\r
+ EssData.Ia32.ExceptionTss = ((UINT8 *)EssData.Ia32.GdtTable + OldGdtSize +\r
+ EssData.Ia32.ExceptionTssDescSize);\r
+\r
+ EssData.Ia32.KnownGoodStackTop = (UINTN)StackTop;\r
+ DEBUG ((DEBUG_INFO,\r
+ "Exception stack top[cpu%lu]: 0x%lX\n",\r
+ (UINT64)(UINTN)Index,\r
+ (UINT64)(UINTN)StackTop));\r
+\r
+ if (Index == Bsp) {\r
+ InitializeExceptionStackSwitchHandlers (&EssData);\r
+ } else {\r
+ MpInitLibStartupThisAP (\r
+ InitializeExceptionStackSwitchHandlers,\r
+ Index,\r
+ NULL,\r
+ 0,\r
+ (VOID *)&EssData,\r
+ NULL\r
+ );\r
+ }\r
+\r
+ StackTop -= NewStackSize;\r
}\r
+}\r
\r
- if (mNumberOfProcessors < gMaxLogicalProcessorNumber) {\r
- FreePages (mApStackStart, EFI_SIZE_TO_PAGES ((gMaxLogicalProcessorNumber - mNumberOfProcessors) *\r
- gApStackSize));\r
+/**\r
+ Initializes MP exceptions handlers for special features, such as Heap Guard\r
+ and Stack Guard.\r
+**/\r
+VOID\r
+InitializeMpExceptionHandlers (\r
+ VOID\r
+ )\r
+{\r
+ //\r
+ // Enable non-stop mode for #PF triggered by Heap Guard or NULL Pointer\r
+ // Detection.\r
+ //\r
+ if (HEAP_GUARD_NONSTOP_MODE || NULL_DETECTION_NONSTOP_MODE) {\r
+ RegisterCpuInterruptHandler (EXCEPT_IA32_DEBUG, DebugExceptionHandler);\r
+ RegisterCpuInterruptHandler (EXCEPT_IA32_PAGE_FAULT, PageFaultExceptionHandler);\r
+ }\r
+\r
+ //\r
+ // Setup stack switch for Stack Guard feature.\r
+ //\r
+ if (PcdGetBool (PcdCpuStackGuard)) {\r
+ InitializeMpExceptionStackSwitchHandlers ();\r
}\r
}\r
+\r
+/**\r
+ Initialize Multi-processor support.\r
+\r
+**/\r
+VOID\r
+InitializeMpSupport (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN NumberOfProcessors;\r
+ UINTN NumberOfEnabledProcessors;\r
+\r
+ //\r
+ // Wakeup APs to do initialization\r
+ //\r
+ Status = MpInitLibInitialize ();\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);\r
+ mNumberOfProcessors = NumberOfProcessors;\r
+ DEBUG ((DEBUG_INFO, "Detect CPU count: %d\n", mNumberOfProcessors));\r
+\r
+ //\r
+ // Initialize special exception handlers for each logic processor.\r
+ //\r
+ InitializeMpExceptionHandlers ();\r
+\r
+ //\r
+ // Update CPU healthy information from Guided HOB\r
+ //\r
+ CollectBistDataFromHob ();\r
+\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &mMpServiceHandle,\r
+ &gEfiMpServiceProtocolGuid, &mMpServicesTemplate,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r