Home | History | Annotate | Download | only in CpuDxe
      1 /** @file
      2   CPU DXE MP support
      3 
      4   Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
      5   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 
     13 **/
     14 
     15 #ifndef _CPU_MP_H_
     16 #define _CPU_MP_H_
     17 
     18 /**
     19   Initialize Multi-processor support.
     20 
     21 **/
     22 VOID
     23 InitializeMpSupport (
     24   VOID
     25   );
     26 
     27 /**
     28   This service retrieves the number of logical processor in the platform
     29   and the number of those logical processors that are enabled on this boot.
     30   This service may only be called from the BSP.
     31 
     32   This function is used to retrieve the following information:
     33     - The number of logical processors that are present in the system.
     34     - The number of enabled logical processors in the system at the instant
     35       this call is made.
     36 
     37   Because MP Service Protocol provides services to enable and disable processors
     38   dynamically, the number of enabled logical processors may vary during the
     39   course of a boot session.
     40 
     41   If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
     42   If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
     43   EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
     44   is returned in NumberOfProcessors, the number of currently enabled processor
     45   is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
     46 
     47   @param[in]  This                        A pointer to the EFI_MP_SERVICES_PROTOCOL
     48                                           instance.
     49   @param[out] NumberOfProcessors          Pointer to the total number of logical
     50                                           processors in the system, including the BSP
     51                                           and disabled APs.
     52   @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled logical
     53                                           processors that exist in system, including
     54                                           the BSP.
     55 
     56   @retval EFI_SUCCESS             The number of logical processors and enabled
     57                                   logical processors was retrieved.
     58   @retval EFI_DEVICE_ERROR        The calling processor is an AP.
     59   @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL.
     60   @retval EFI_INVALID_PARAMETER   NumberOfEnabledProcessors is NULL.
     61 
     62 **/
     63 EFI_STATUS
     64 EFIAPI
     65 GetNumberOfProcessors (
     66   IN  EFI_MP_SERVICES_PROTOCOL  *This,
     67   OUT UINTN                     *NumberOfProcessors,
     68   OUT UINTN                     *NumberOfEnabledProcessors
     69   );
     70 
     71 /**
     72   Gets detailed MP-related information on the requested processor at the
     73   instant this call is made. This service may only be called from the BSP.
     74 
     75   This service retrieves detailed MP-related information about any processor
     76   on the platform. Note the following:
     77     - The processor information may change during the course of a boot session.
     78     - The information presented here is entirely MP related.
     79 
     80   Information regarding the number of caches and their sizes, frequency of operation,
     81   slot numbers is all considered platform-related information and is not provided
     82   by this service.
     83 
     84   @param[in]  This                  A pointer to the EFI_MP_SERVICES_PROTOCOL
     85                                     instance.
     86   @param[in]  ProcessorNumber       The handle number of processor.
     87   @param[out] ProcessorInfoBuffer   A pointer to the buffer where information for
     88                                     the requested processor is deposited.
     89 
     90   @retval EFI_SUCCESS             Processor information was returned.
     91   @retval EFI_DEVICE_ERROR        The calling processor is an AP.
     92   @retval EFI_INVALID_PARAMETER   ProcessorInfoBuffer is NULL.
     93   @retval EFI_NOT_FOUND           The processor with the handle specified by
     94                                   ProcessorNumber does not exist in the platform.
     95 
     96 **/
     97 EFI_STATUS
     98 EFIAPI
     99 GetProcessorInfo (
    100   IN  EFI_MP_SERVICES_PROTOCOL   *This,
    101   IN  UINTN                      ProcessorNumber,
    102   OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer
    103   );
    104 
    105 /**
    106   This service executes a caller provided function on all enabled APs. APs can
    107   run either simultaneously or one at a time in sequence. This service supports
    108   both blocking and non-blocking requests. The non-blocking requests use EFI
    109   events so the BSP can detect when the APs have finished. This service may only
    110   be called from the BSP.
    111 
    112   This function is used to dispatch all the enabled APs to the function specified
    113   by Procedure.  If any enabled AP is busy, then EFI_NOT_READY is returned
    114   immediately and Procedure is not started on any AP.
    115 
    116   If SingleThread is TRUE, all the enabled APs execute the function specified by
    117   Procedure one by one, in ascending order of processor handle number. Otherwise,
    118   all the enabled APs execute the function specified by Procedure simultaneously.
    119 
    120   If WaitEvent is NULL, execution is in blocking mode. The BSP waits until all
    121   APs finish or TimeoutInMicroseconds expires. Otherwise, execution is in non-blocking
    122   mode, and the BSP returns from this service without waiting for APs. If a
    123   non-blocking mode is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
    124   is signaled, then EFI_UNSUPPORTED must be returned.
    125 
    126   If the timeout specified by TimeoutInMicroseconds expires before all APs return
    127   from Procedure, then Procedure on the failed APs is terminated. All enabled APs
    128   are always available for further calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
    129   and EFI_MP_SERVICES_PROTOCOL.StartupThisAP(). If FailedCpuList is not NULL, its
    130   content points to the list of processor handle numbers in which Procedure was
    131   terminated.
    132 
    133   Note: It is the responsibility of the consumer of the EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
    134   to make sure that the nature of the code that is executed on the BSP and the
    135   dispatched APs is well controlled. The MP Services Protocol does not guarantee
    136   that the Procedure function is MP-safe. Hence, the tasks that can be run in
    137   parallel are limited to certain independent tasks and well-controlled exclusive
    138   code. EFI services and protocols may not be called by APs unless otherwise
    139   specified.
    140 
    141   In blocking execution mode, BSP waits until all APs finish or
    142   TimeoutInMicroseconds expires.
    143 
    144   In non-blocking execution mode, BSP is freed to return to the caller and then
    145   proceed to the next task without having to wait for APs. The following
    146   sequence needs to occur in a non-blocking execution mode:
    147 
    148     -# The caller that intends to use this MP Services Protocol in non-blocking
    149        mode creates WaitEvent by calling the EFI CreateEvent() service.  The caller
    150        invokes EFI_MP_SERVICES_PROTOCOL.StartupAllAPs(). If the parameter WaitEvent
    151        is not NULL, then StartupAllAPs() executes in non-blocking mode. It requests
    152        the function specified by Procedure to be started on all the enabled APs,
    153        and releases the BSP to continue with other tasks.
    154     -# The caller can use the CheckEvent() and WaitForEvent() services to check
    155        the state of the WaitEvent created in step 1.
    156     -# When the APs complete their task or TimeoutInMicroSecondss expires, the MP
    157        Service signals WaitEvent by calling the EFI SignalEvent() function. If
    158        FailedCpuList is not NULL, its content is available when WaitEvent is
    159        signaled. If all APs returned from Procedure prior to the timeout, then
    160        FailedCpuList is set to NULL. If not all APs return from Procedure before
    161        the timeout, then FailedCpuList is filled in with the list of the failed
    162        APs. The buffer is allocated by MP Service Protocol using AllocatePool().
    163        It is the caller's responsibility to free the buffer with FreePool() service.
    164     -# This invocation of SignalEvent() function informs the caller that invoked
    165        EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() that either all the APs completed
    166        the specified task or a timeout occurred. The contents of FailedCpuList
    167        can be examined to determine which APs did not complete the specified task
    168        prior to the timeout.
    169 
    170   @param[in]  This                    A pointer to the EFI_MP_SERVICES_PROTOCOL
    171                                       instance.
    172   @param[in]  Procedure               A pointer to the function to be run on
    173                                       enabled APs of the system. See type
    174                                       EFI_AP_PROCEDURE.
    175   @param[in]  SingleThread            If TRUE, then all the enabled APs execute
    176                                       the function specified by Procedure one by
    177                                       one, in ascending order of processor handle
    178                                       number.  If FALSE, then all the enabled APs
    179                                       execute the function specified by Procedure
    180                                       simultaneously.
    181   @param[in]  WaitEvent               The event created by the caller with CreateEvent()
    182                                       service.  If it is NULL, then execute in
    183                                       blocking mode. BSP waits until all APs finish
    184                                       or TimeoutInMicroseconds expires.  If it's
    185                                       not NULL, then execute in non-blocking mode.
    186                                       BSP requests the function specified by
    187                                       Procedure to be started on all the enabled
    188                                       APs, and go on executing immediately. If
    189                                       all return from Procedure, or TimeoutInMicroseconds
    190                                       expires, this event is signaled. The BSP
    191                                       can use the CheckEvent() or WaitForEvent()
    192                                       services to check the state of event.  Type
    193                                       EFI_EVENT is defined in CreateEvent() in
    194                                       the Unified Extensible Firmware Interface
    195                                       Specification.
    196   @param[in]  TimeoutInMicroseconds   Indicates the time limit in microseconds for
    197                                       APs to return from Procedure, either for
    198                                       blocking or non-blocking mode. Zero means
    199                                       infinity.  If the timeout expires before
    200                                       all APs return from Procedure, then Procedure
    201                                       on the failed APs is terminated. All enabled
    202                                       APs are available for next function assigned
    203                                       by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
    204                                       or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
    205                                       If the timeout expires in blocking mode,
    206                                       BSP returns EFI_TIMEOUT.  If the timeout
    207                                       expires in non-blocking mode, WaitEvent
    208                                       is signaled with SignalEvent().
    209   @param[in]  ProcedureArgument       The parameter passed into Procedure for
    210                                       all APs.
    211   @param[out] FailedCpuList           If NULL, this parameter is ignored. Otherwise,
    212                                       if all APs finish successfully, then its
    213                                       content is set to NULL. If not all APs
    214                                       finish before timeout expires, then its
    215                                       content is set to address of the buffer
    216                                       holding handle numbers of the failed APs.
    217                                       The buffer is allocated by MP Service Protocol,
    218                                       and it's the caller's responsibility to
    219                                       free the buffer with FreePool() service.
    220                                       In blocking mode, it is ready for consumption
    221                                       when the call returns. In non-blocking mode,
    222                                       it is ready when WaitEvent is signaled.  The
    223                                       list of failed CPU is terminated by
    224                                       END_OF_CPU_LIST.
    225 
    226   @retval EFI_SUCCESS             In blocking mode, all APs have finished before
    227                                   the timeout expired.
    228   @retval EFI_SUCCESS             In non-blocking mode, function has been dispatched
    229                                   to all enabled APs.
    230   @retval EFI_UNSUPPORTED         A non-blocking mode request was made after the
    231                                   UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
    232                                   signaled.
    233   @retval EFI_DEVICE_ERROR        Caller processor is AP.
    234   @retval EFI_NOT_STARTED         No enabled APs exist in the system.
    235   @retval EFI_NOT_READY           Any enabled APs are busy.
    236   @retval EFI_TIMEOUT             In blocking mode, the timeout expired before
    237                                   all enabled APs have finished.
    238   @retval EFI_INVALID_PARAMETER   Procedure is NULL.
    239 
    240 **/
    241 EFI_STATUS
    242 EFIAPI
    243 StartupAllAPs (
    244   IN  EFI_MP_SERVICES_PROTOCOL  *This,
    245   IN  EFI_AP_PROCEDURE          Procedure,
    246   IN  BOOLEAN                   SingleThread,
    247   IN  EFI_EVENT                 WaitEvent               OPTIONAL,
    248   IN  UINTN                     TimeoutInMicroseconds,
    249   IN  VOID                      *ProcedureArgument      OPTIONAL,
    250   OUT UINTN                     **FailedCpuList         OPTIONAL
    251   );
    252 
    253 /**
    254   This service lets the caller get one enabled AP to execute a caller-provided
    255   function. The caller can request the BSP to either wait for the completion
    256   of the AP or just proceed with the next task by using the EFI event mechanism.
    257   See EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() for more details on non-blocking
    258   execution support.  This service may only be called from the BSP.
    259 
    260   This function is used to dispatch one enabled AP to the function specified by
    261   Procedure passing in the argument specified by ProcedureArgument.  If WaitEvent
    262   is NULL, execution is in blocking mode. The BSP waits until the AP finishes or
    263   TimeoutInMicroSecondss expires. Otherwise, execution is in non-blocking mode.
    264   BSP proceeds to the next task without waiting for the AP. If a non-blocking mode
    265   is requested after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled,
    266   then EFI_UNSUPPORTED must be returned.
    267 
    268   If the timeout specified by TimeoutInMicroseconds expires before the AP returns
    269   from Procedure, then execution of Procedure by the AP is terminated. The AP is
    270   available for subsequent calls to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() and
    271   EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
    272 
    273   @param[in]  This                    A pointer to the EFI_MP_SERVICES_PROTOCOL
    274                                       instance.
    275   @param[in]  Procedure               A pointer to the function to be run on
    276                                       enabled APs of the system. See type
    277                                       EFI_AP_PROCEDURE.
    278   @param[in]  ProcessorNumber         The handle number of the AP. The range is
    279                                       from 0 to the total number of logical
    280                                       processors minus 1. The total number of
    281                                       logical processors can be retrieved by
    282                                       EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
    283   @param[in]  WaitEvent               The event created by the caller with CreateEvent()
    284                                       service.  If it is NULL, then execute in
    285                                       blocking mode. BSP waits until all APs finish
    286                                       or TimeoutInMicroseconds expires.  If it's
    287                                       not NULL, then execute in non-blocking mode.
    288                                       BSP requests the function specified by
    289                                       Procedure to be started on all the enabled
    290                                       APs, and go on executing immediately. If
    291                                       all return from Procedure or TimeoutInMicroseconds
    292                                       expires, this event is signaled. The BSP
    293                                       can use the CheckEvent() or WaitForEvent()
    294                                       services to check the state of event.  Type
    295                                       EFI_EVENT is defined in CreateEvent() in
    296                                       the Unified Extensible Firmware Interface
    297                                       Specification.
    298   @param[in]  TimeoutInMicroseconds   Indicates the time limit in microseconds for
    299                                       APs to return from Procedure, either for
    300                                       blocking or non-blocking mode. Zero means
    301                                       infinity.  If the timeout expires before
    302                                       all APs return from Procedure, then Procedure
    303                                       on the failed APs is terminated. All enabled
    304                                       APs are available for next function assigned
    305                                       by EFI_MP_SERVICES_PROTOCOL.StartupAllAPs()
    306                                       or EFI_MP_SERVICES_PROTOCOL.StartupThisAP().
    307                                       If the timeout expires in blocking mode,
    308                                       BSP returns EFI_TIMEOUT.  If the timeout
    309                                       expires in non-blocking mode, WaitEvent
    310                                       is signaled with SignalEvent().
    311   @param[in]  ProcedureArgument       The parameter passed into Procedure for
    312                                       all APs.
    313   @param[out] Finished                If NULL, this parameter is ignored.  In
    314                                       blocking mode, this parameter is ignored.
    315                                       In non-blocking mode, if AP returns from
    316                                       Procedure before the timeout expires, its
    317                                       content is set to TRUE. Otherwise, the
    318                                       value is set to FALSE. The caller can
    319                                       determine if the AP returned from Procedure
    320                                       by evaluating this value.
    321 
    322   @retval EFI_SUCCESS             In blocking mode, specified AP finished before
    323                                   the timeout expires.
    324   @retval EFI_SUCCESS             In non-blocking mode, the function has been
    325                                   dispatched to specified AP.
    326   @retval EFI_UNSUPPORTED         A non-blocking mode request was made after the
    327                                   UEFI event EFI_EVENT_GROUP_READY_TO_BOOT was
    328                                   signaled.
    329   @retval EFI_DEVICE_ERROR        The calling processor is an AP.
    330   @retval EFI_TIMEOUT             In blocking mode, the timeout expired before
    331                                   the specified AP has finished.
    332   @retval EFI_NOT_READY           The specified AP is busy.
    333   @retval EFI_NOT_FOUND           The processor with the handle specified by
    334                                   ProcessorNumber does not exist.
    335   @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the BSP or disabled AP.
    336   @retval EFI_INVALID_PARAMETER   Procedure is NULL.
    337 
    338 **/
    339 EFI_STATUS
    340 EFIAPI
    341 StartupThisAP (
    342   IN  EFI_MP_SERVICES_PROTOCOL  *This,
    343   IN  EFI_AP_PROCEDURE          Procedure,
    344   IN  UINTN                     ProcessorNumber,
    345   IN  EFI_EVENT                 WaitEvent               OPTIONAL,
    346   IN  UINTN                     TimeoutInMicroseconds,
    347   IN  VOID                      *ProcedureArgument      OPTIONAL,
    348   OUT BOOLEAN                   *Finished               OPTIONAL
    349   );
    350 
    351 /**
    352   This service switches the requested AP to be the BSP from that point onward.
    353   This service changes the BSP for all purposes.   This call can only be performed
    354   by the current BSP.
    355 
    356   This service switches the requested AP to be the BSP from that point onward.
    357   This service changes the BSP for all purposes. The new BSP can take over the
    358   execution of the old BSP and continue seamlessly from where the old one left
    359   off. This service may not be supported after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT
    360   is signaled.
    361 
    362   If the BSP cannot be switched prior to the return from this service, then
    363   EFI_UNSUPPORTED must be returned.
    364 
    365   @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
    366   @param[in] ProcessorNumber   The handle number of AP that is to become the new
    367                                BSP. The range is from 0 to the total number of
    368                                logical processors minus 1. The total number of
    369                                logical processors can be retrieved by
    370                                EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
    371   @param[in] EnableOldBSP      If TRUE, then the old BSP will be listed as an
    372                                enabled AP. Otherwise, it will be disabled.
    373 
    374   @retval EFI_SUCCESS             BSP successfully switched.
    375   @retval EFI_UNSUPPORTED         Switching the BSP cannot be completed prior to
    376                                   this service returning.
    377   @retval EFI_UNSUPPORTED         Switching the BSP is not supported.
    378   @retval EFI_SUCCESS             The calling processor is an AP.
    379   @retval EFI_NOT_FOUND           The processor with the handle specified by
    380                                   ProcessorNumber does not exist.
    381   @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the current BSP or
    382                                   a disabled AP.
    383   @retval EFI_NOT_READY           The specified AP is busy.
    384 
    385 **/
    386 EFI_STATUS
    387 EFIAPI
    388 SwitchBSP (
    389   IN EFI_MP_SERVICES_PROTOCOL  *This,
    390   IN  UINTN                    ProcessorNumber,
    391   IN  BOOLEAN                  EnableOldBSP
    392   );
    393 
    394 /**
    395   This service lets the caller enable or disable an AP from this point onward.
    396   This service may only be called from the BSP.
    397 
    398   This service allows the caller enable or disable an AP from this point onward.
    399   The caller can optionally specify the health status of the AP by Health. If
    400   an AP is being disabled, then the state of the disabled AP is implementation
    401   dependent. If an AP is enabled, then the implementation must guarantee that a
    402   complete initialization sequence is performed on the AP, so the AP is in a state
    403   that is compatible with an MP operating system. This service may not be supported
    404   after the UEFI Event EFI_EVENT_GROUP_READY_TO_BOOT is signaled.
    405 
    406   If the enable or disable AP operation cannot be completed prior to the return
    407   from this service, then EFI_UNSUPPORTED must be returned.
    408 
    409   @param[in] This              A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
    410   @param[in] ProcessorNumber   The handle number of AP that is to become the new
    411                                BSP. The range is from 0 to the total number of
    412                                logical processors minus 1. The total number of
    413                                logical processors can be retrieved by
    414                                EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
    415   @param[in] EnableAP          Specifies the new state for the processor for
    416                                enabled, FALSE for disabled.
    417   @param[in] HealthFlag        If not NULL, a pointer to a value that specifies
    418                                the new health status of the AP. This flag
    419                                corresponds to StatusFlag defined in
    420                                EFI_MP_SERVICES_PROTOCOL.GetProcessorInfo(). Only
    421                                the PROCESSOR_HEALTH_STATUS_BIT is used. All other
    422                                bits are ignored.  If it is NULL, this parameter
    423                                is ignored.
    424 
    425   @retval EFI_SUCCESS             The specified AP was enabled or disabled successfully.
    426   @retval EFI_UNSUPPORTED         Enabling or disabling an AP cannot be completed
    427                                   prior to this service returning.
    428   @retval EFI_UNSUPPORTED         Enabling or disabling an AP is not supported.
    429   @retval EFI_DEVICE_ERROR        The calling processor is an AP.
    430   @retval EFI_NOT_FOUND           Processor with the handle specified by ProcessorNumber
    431                                   does not exist.
    432   @retval EFI_INVALID_PARAMETER   ProcessorNumber specifies the BSP.
    433 
    434 **/
    435 EFI_STATUS
    436 EFIAPI
    437 EnableDisableAP (
    438   IN  EFI_MP_SERVICES_PROTOCOL  *This,
    439   IN  UINTN                     ProcessorNumber,
    440   IN  BOOLEAN                   EnableAP,
    441   IN  UINT32                    *HealthFlag OPTIONAL
    442   );
    443 
    444 /**
    445   This return the handle number for the calling processor.  This service may be
    446   called from the BSP and APs.
    447 
    448   This service returns the processor handle number for the calling processor.
    449   The returned value is in the range from 0 to the total number of logical
    450   processors minus 1. The total number of logical processors can be retrieved
    451   with EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors(). This service may be
    452   called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
    453   is returned. Otherwise, the current processors handle number is returned in
    454   ProcessorNumber, and EFI_SUCCESS is returned.
    455 
    456   @param[in]  This             A pointer to the EFI_MP_SERVICES_PROTOCOL instance.
    457   @param[out] ProcessorNumber  The handle number of AP that is to become the new
    458                                BSP. The range is from 0 to the total number of
    459                                logical processors minus 1. The total number of
    460                                logical processors can be retrieved by
    461                                EFI_MP_SERVICES_PROTOCOL.GetNumberOfProcessors().
    462 
    463   @retval EFI_SUCCESS             The current processor handle number was returned
    464                                   in ProcessorNumber.
    465   @retval EFI_INVALID_PARAMETER   ProcessorNumber is NULL.
    466 
    467 **/
    468 EFI_STATUS
    469 EFIAPI
    470 WhoAmI (
    471   IN EFI_MP_SERVICES_PROTOCOL  *This,
    472   OUT UINTN                    *ProcessorNumber
    473   );
    474 
    475 #endif // _CPU_MP_H_
    476 
    477