]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Library / RegisterCpuFeaturesLib / PeiRegisterCpuFeaturesLib.c
index 82fe268812af64e35ffe35f36264610e5b7c0510..2b1553f9b84b25db6aef84b76f2ad1bfdc594745 100644 (file)
@@ -2,13 +2,7 @@
   CPU Register Table Library functions.\r
 \r
   Copyright (c) 2016, 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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -68,15 +62,15 @@ GetCpuFeaturesData (
 /**\r
   Worker function to get MP PPI service pointer.\r
 \r
-  @return PEI PPI service pointer.\r
+  @return MP_SERVICES variable.\r
 **/\r
-EFI_PEI_MP_SERVICES_PPI *\r
-GetMpPpi (\r
+MP_SERVICES\r
+GetMpService (\r
   VOID\r
   )\r
 {\r
   EFI_STATUS                 Status;\r
-  EFI_PEI_MP_SERVICES_PPI    *CpuMpPpi;\r
+  MP_SERVICES                MpService;\r
 \r
   //\r
   // Get MP Services Protocol\r
@@ -85,29 +79,36 @@ GetMpPpi (
              &gEfiPeiMpServicesPpiGuid,\r
              0,\r
              NULL,\r
-             (VOID **)&CpuMpPpi\r
+             (VOID **)&MpService.Ppi\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
-  return CpuMpPpi;\r
+  return MpService;\r
 }\r
 \r
 /**\r
   Worker function to return processor index.\r
 \r
+  @param  CpuFeaturesData    Cpu Feature Data structure.\r
+\r
   @return  The processor index.\r
 **/\r
 UINTN\r
 GetProcessorIndex (\r
-  VOID\r
+  IN CPU_FEATURES_DATA        *CpuFeaturesData\r
   )\r
 {\r
   EFI_STATUS                 Status;\r
   EFI_PEI_MP_SERVICES_PPI    *CpuMpPpi;\r
   UINTN                      ProcessorIndex;\r
 \r
-  CpuMpPpi = GetMpPpi ();\r
+  CpuMpPpi = CpuFeaturesData->MpService.Ppi;\r
 \r
-  Status = CpuMpPpi->WhoAmI(GetPeiServicesTablePointer (), CpuMpPpi, &ProcessorIndex);\r
+  //\r
+  // For two reasons which use NULL for WhoAmI:\r
+  // 1. This function will be called by APs and AP should not use PeiServices Table\r
+  // 2. Check WhoAmI implementation, this parameter will not be used.\r
+  //\r
+  Status = CpuMpPpi->WhoAmI(NULL, CpuMpPpi, &ProcessorIndex);\r
   ASSERT_EFI_ERROR (Status);\r
   return ProcessorIndex;\r
 }\r
@@ -130,8 +131,11 @@ GetProcessorInformation (
 {\r
   EFI_PEI_MP_SERVICES_PPI    *CpuMpPpi;\r
   EFI_STATUS                 Status;\r
+  CPU_FEATURES_DATA          *CpuFeaturesData;\r
+\r
+  CpuFeaturesData = GetCpuFeaturesData ();\r
+  CpuMpPpi = CpuFeaturesData->MpService.Ppi;\r
 \r
-  CpuMpPpi = GetMpPpi ();\r
   Status = CpuMpPpi->GetProcessorInfo (\r
                GetPeiServicesTablePointer(),\r
                CpuMpPpi,\r
@@ -146,25 +150,21 @@ GetProcessorInformation (
 \r
   @param[in]  Procedure               A pointer to the function to be run on\r
                                       enabled APs of the system.\r
+  @param[in]  MpEvent                 The Event used to sync the result.\r
+\r
 **/\r
 VOID\r
 StartupAPsWorker (\r
-  IN  EFI_AP_PROCEDURE                 Procedure\r
+  IN  EFI_AP_PROCEDURE                 Procedure,\r
+  IN  EFI_EVENT                        MpEvent\r
   )\r
 {\r
   EFI_STATUS                           Status;\r
   EFI_PEI_MP_SERVICES_PPI              *CpuMpPpi;\r
+  CPU_FEATURES_DATA                    *CpuFeaturesData;\r
 \r
-  //\r
-  // Get MP Services Protocol\r
-  //\r
-  Status = PeiServicesLocatePpi (\r
-             &gEfiPeiMpServicesPpiGuid,\r
-             0,\r
-             NULL,\r
-             (VOID **)&CpuMpPpi\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
+  CpuFeaturesData = GetCpuFeaturesData ();\r
+  CpuMpPpi = CpuFeaturesData->MpService.Ppi;\r
 \r
   //\r
   // Wakeup all APs for data collection.\r
@@ -175,7 +175,7 @@ StartupAPsWorker (
                  Procedure,\r
                  FALSE,\r
                  0,\r
-                 NULL\r
+                 CpuFeaturesData\r
                  );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
@@ -192,17 +192,10 @@ SwitchNewBsp (
 {\r
   EFI_STATUS                           Status;\r
   EFI_PEI_MP_SERVICES_PPI              *CpuMpPpi;\r
+  CPU_FEATURES_DATA                    *CpuFeaturesData;\r
 \r
-  //\r
-  // Get MP Services Protocol\r
-  //\r
-  Status = PeiServicesLocatePpi (\r
-             &gEfiPeiMpServicesPpiGuid,\r
-             0,\r
-             NULL,\r
-             (VOID **)&CpuMpPpi\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
+  CpuFeaturesData = GetCpuFeaturesData ();\r
+  CpuMpPpi = CpuFeaturesData->MpService.Ppi;\r
 \r
   //\r
   // Wakeup all APs for data collection.\r
@@ -234,17 +227,10 @@ GetNumberOfProcessor (
 {\r
   EFI_STATUS                 Status;\r
   EFI_PEI_MP_SERVICES_PPI    *CpuMpPpi;\r
+  CPU_FEATURES_DATA          *CpuFeaturesData;\r
 \r
-  //\r
-  // Get MP Services Protocol\r
-  //\r
-  Status = PeiServicesLocatePpi (\r
-             &gEfiPeiMpServicesPpiGuid,\r
-             0,\r
-             NULL,\r
-             (VOID **)&CpuMpPpi\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
+  CpuFeaturesData = GetCpuFeaturesData ();\r
+  CpuMpPpi = CpuFeaturesData->MpService.Ppi;\r
 \r
   //\r
   // Get the number of CPUs\r
@@ -257,3 +243,50 @@ GetNumberOfProcessor (
                          );\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
+\r
+/**\r
+  Performs CPU features Initialization.\r
+\r
+  This service will invoke MP service to perform CPU features\r
+  initialization on BSP/APs per user configuration.\r
+\r
+  @note This service could be called by BSP only.\r
+**/\r
+VOID\r
+EFIAPI\r
+CpuFeaturesInitialize (\r
+  VOID\r
+  )\r
+{\r
+  CPU_FEATURES_DATA          *CpuFeaturesData;\r
+  UINTN                      OldBspNumber;\r
+\r
+  CpuFeaturesData = GetCpuFeaturesData ();\r
+\r
+  OldBspNumber = GetProcessorIndex (CpuFeaturesData);\r
+  CpuFeaturesData->BspNumber = OldBspNumber;\r
+\r
+  //\r
+  // Known limitation: In PEI phase, CpuFeatures driver not\r
+  // support async mode execute tasks. So semaphore type\r
+  // register can't been used for this instance, must use\r
+  // DXE type instance.\r
+  //\r
+\r
+  //\r
+  // Wakeup all APs for programming.\r
+  //\r
+  StartupAPsWorker (SetProcessorRegister, NULL);\r
+  //\r
+  // Programming BSP\r
+  //\r
+  SetProcessorRegister (CpuFeaturesData);\r
+\r
+  //\r
+  // Switch to new BSP if required\r
+  //\r
+  if (CpuFeaturesData->BspNumber != OldBspNumber) {\r
+    SwitchNewBsp (CpuFeaturesData->BspNumber);\r
+  }\r
+}\r
+\r