Revision: 18168
          http://sourceforge.net/p/edk2/code/18168
Author:   vanjeff
Date:     2015-08-06 06:57:47 +0000 (Thu, 06 Aug 2015)
Log Message:
-----------
UefiCpuPkg/CpuMpPei: Update files format to DOS

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>

Modified Paths:
--------------
    trunk/edk2/UefiCpuPkg/CpuMpPei/CpuBist.c
    trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.c
    trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.h
    trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
    trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc
    trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm
    trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm
    trunk/edk2/UefiCpuPkg/CpuMpPei/Microcode.c
    trunk/edk2/UefiCpuPkg/CpuMpPei/Microcode.h
    trunk/edk2/UefiCpuPkg/CpuMpPei/PeiMpServices.c
    trunk/edk2/UefiCpuPkg/CpuMpPei/PeiMpServices.h
    trunk/edk2/UefiCpuPkg/CpuMpPei/X64/MpEqu.inc
    trunk/edk2/UefiCpuPkg/CpuMpPei/X64/MpFuncs.asm
    trunk/edk2/UefiCpuPkg/CpuMpPei/X64/MpFuncs.nasm

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/CpuBist.c
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/CpuBist.c    2015-08-06 05:45:32 UTC (rev 
18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/CpuBist.c    2015-08-06 06:57:47 UTC (rev 
18168)
@@ -1,260 +1,260 @@
-/** @file
-  Update and publish processors' BIST information.
-
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD 
License
-  which accompanies this distribution.  The full text of the license may be 
found at
-  http://opensource.org/licenses/bsd-license.php
-
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "CpuMpPei.h"
-
-EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2Ppi = {
-  SecPlatformInformation2
-};
-
-EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2Ppi = {
-  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
-  &gEfiSecPlatformInformation2PpiGuid,
-  &mSecPlatformInformation2Ppi
-};
-
-/**
-  Implementation of the PlatformInformation2 service in 
EFI_SEC_PLATFORM_INFORMATION2_PPI.
-
-  @param  PeiServices                The pointer to the PEI Services Table.
-  @param  StructureSize              The pointer to the variable describing 
size of the input buffer.
-  @param  PlatformInformationRecord2 The pointer to the 
EFI_SEC_PLATFORM_INFORMATION_RECORD2.
-
-  @retval EFI_SUCCESS                The data was successfully returned.
-  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current 
buffer size needed to
-                                     hold the record is returned in 
StructureSize.
-
-**/
-EFI_STATUS
-EFIAPI
-SecPlatformInformation2 (
-  IN CONST EFI_PEI_SERVICES                   **PeiServices,
-  IN OUT UINT64                               *StructureSize,
-     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
-  )
-{
-  PEI_CPU_MP_DATA                      *PeiCpuMpData;
-  UINTN                                BistInformationSize;
-  UINTN                                CpuIndex;
-  EFI_SEC_PLATFORM_INFORMATION_CPU     *CpuInstance;
-
-  PeiCpuMpData = GetMpHobData ();
-
-  BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +
-                        sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * 
PeiCpuMpData->CpuCount;
-  //
-  // return the information size if input buffer size is too small
-  //
-  if ((*StructureSize) < (UINT64) BistInformationSize) {
-    *StructureSize = (UINT64) BistInformationSize;
-    return EFI_BUFFER_TOO_SMALL;
-  }
-
-  PlatformInformationRecord2->NumberOfCpus = PeiCpuMpData->CpuCount;
-  CpuInstance = PlatformInformationRecord2->CpuInstance;
-  for (CpuIndex = 0; CpuIndex < PeiCpuMpData->CpuCount; CpuIndex ++) {
-    CpuInstance[CpuIndex].CpuLocation                = 
PeiCpuMpData->CpuData[CpuIndex].ApicId;
-    CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags = 
PeiCpuMpData->CpuData[CpuIndex].Health;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Worker function to get CPUs' BIST by calling SecPlatformInformationPpi
-  or SecPlatformInformation2Ppi.
-
-  @param  PeiServices         Pointer to PEI Services Table
-  @param  Guid                PPI Guid
-  @param  PpiDescriptor       Return a pointer to instance of the
-                              EFI_PEI_PPI_DESCRIPTOR
-  @param  BistInformationData Pointer to BIST information data
-
-  @retval EFI_SUCCESS         Retrieve of the BIST data successfully
-  @retval EFI_NOT_FOUND       No sec platform information(2) ppi export
-  @retval EFI_DEVICE_ERROR    Failed to get CPU Information
-
-**/
-EFI_STATUS
-GetBistInfoFromPpi (
-  IN CONST EFI_PEI_SERVICES     **PeiServices,
-  IN CONST EFI_GUID             *Guid,
-     OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
-     OUT VOID                   **BistInformationData
-  )
-{
-  EFI_STATUS                            Status;
-  EFI_SEC_PLATFORM_INFORMATION2_PPI     *SecPlatformInformation2Ppi;
-  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;
-  UINT64                                InformationSize;
-
-  Status = PeiServicesLocatePpi (
-             Guid,                                // GUID
-             0,                                   // INSTANCE
-             PpiDescriptor,                       // EFI_PEI_PPI_DESCRIPTOR
-             (VOID **)&SecPlatformInformation2Ppi // PPI
-             );
-  if (Status == EFI_NOT_FOUND) {
-    return EFI_NOT_FOUND;
-  }
-
-  if (Status == EFI_SUCCESS) {
-    //
-    // Get the size of the sec platform information2(BSP/APs' BIST data)
-    //
-    InformationSize         = 0;
-    SecPlatformInformation2 = NULL;
-    Status = SecPlatformInformation2Ppi->PlatformInformation2 (
-                                           PeiServices,
-                                           &InformationSize,
-                                           SecPlatformInformation2
-                                           );
-    if (Status == EFI_BUFFER_TOO_SMALL) {
-      Status = PeiServicesAllocatePool (
-                 (UINTN) InformationSize,
-                 (VOID **) &SecPlatformInformation2
-                 );
-      if (Status == EFI_SUCCESS) {
-        //
-        // Retrieve BIST data
-        //
-        Status = SecPlatformInformation2Ppi->PlatformInformation2 (
-                                               PeiServices,
-                                               &InformationSize,
-                                               SecPlatformInformation2
-                                               );
-        if (Status == EFI_SUCCESS) {
-          *BistInformationData = SecPlatformInformation2;
-          return EFI_SUCCESS;
-        }
-      }
-    }
-  }
-
-  return EFI_DEVICE_ERROR;
-}
-
-/**
-  Collects BIST data from PPI.
-
-  This function collects BIST data from Sec Platform Information2 PPI
-  or SEC Platform Information PPI.
-
-  @param PeiServices         Pointer to PEI Services Table
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-
-**/
-VOID
-CollectBistDataFromPpi (
-  IN CONST EFI_PEI_SERVICES             **PeiServices,
-  IN PEI_CPU_MP_DATA                    *PeiCpuMpData
-  )
-{
-  EFI_STATUS                            Status;
-  EFI_PEI_PPI_DESCRIPTOR                *SecInformationDescriptor;
-  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;
-  EFI_SEC_PLATFORM_INFORMATION_RECORD   *SecPlatformInformation;
-  UINTN                                 NumberOfData;
-  EFI_SEC_PLATFORM_INFORMATION_CPU      *CpuInstance;
-  EFI_SEC_PLATFORM_INFORMATION_CPU      BspCpuInstance;
-  UINTN                                 ProcessorNumber;
-  UINTN                                 CpuIndex;
-  PEI_CPU_DATA                          *CpuData;
-
-  SecPlatformInformation2 = NULL;
-  SecPlatformInformation  = NULL;
-  NumberOfData            = 0;
-  CpuInstance             = NULL;
-
-  //
-  // Get BIST information from Sec Platform Information2 Ppi firstly
-  //
-  Status = GetBistInfoFromPpi (
-             PeiServices,
-             &gEfiSecPlatformInformation2PpiGuid,
-             &SecInformationDescriptor,
-             (VOID *) &SecPlatformInformation2
-             );
-  if (Status == EFI_SUCCESS) {
-    //
-    // Sec Platform Information2 PPI includes BSP/APs' BIST information
-    //
-    NumberOfData = SecPlatformInformation2->NumberOfCpus;
-    CpuInstance  = SecPlatformInformation2->CpuInstance;
-  } else {
-    //
-    // Otherwise, get BIST information from Sec Platform Information Ppi
-    //
-    Status = GetBistInfoFromPpi (
-               PeiServices,
-               &gEfiSecPlatformInformationPpiGuid,
-               &SecInformationDescriptor,
-               (VOID *) &SecPlatformInformation
-               );
-    if (Status == EFI_SUCCESS) {
-      NumberOfData = 1;
-      //
-      // SEC Platform Information only includes BSP's BIST information
-      // and does not have BSP's APIC ID
-      //
-      BspCpuInstance.CpuLocation = GetInitialApicId ();
-      BspCpuInstance.InfoRecord.IA32HealthFlags.Uint32  = 
SecPlatformInformation->IA32HealthFlags.Uint32;
-      CpuInstance = &BspCpuInstance;
-    } else {
-      DEBUG ((EFI_D_INFO, "Does not find any stored CPU BIST information from 
PPI!\n"));
-    }
-  }
-  for (ProcessorNumber = 0; ProcessorNumber < PeiCpuMpData->CpuCount; 
ProcessorNumber ++) {
-    CpuData = &PeiCpuMpData->CpuData[ProcessorNumber];
-    for (CpuIndex = 0; CpuIndex < NumberOfData; CpuIndex ++) {
-      ASSERT (CpuInstance != NULL);
-      if (CpuData->ApicId == CpuInstance[CpuIndex].CpuLocation) {
-        //
-        // Update processor's BIST data if it is already stored before
-        //
-        CpuData->Health = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;
-      }
-    }
-    if (CpuData->Health.Uint32 != 0) {
-      //
-      // Report Status Code that self test is failed
-      //
-      REPORT_STATUS_CODE (
-        EFI_ERROR_CODE | EFI_ERROR_MAJOR,
-        (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST)
-        );
-    }
-    DEBUG ((EFI_D_INFO, "  APICID - 0x%08x, BIST - 0x%08x\n",
-            PeiCpuMpData->CpuData[ProcessorNumber].ApicId,
-            PeiCpuMpData->CpuData[ProcessorNumber].Health.Uint32
-            ));
-  }
-
-  if (SecPlatformInformation2 != NULL && NumberOfData < 
PeiCpuMpData->CpuCount) {
-    //
-    // Reinstall SecPlatformInformation2 PPI to include new BIST inforamtion
-    //
-    Status = PeiServicesReInstallPpi (
-               SecInformationDescriptor,
-               &mPeiSecPlatformInformation2Ppi
-               );
-    ASSERT_EFI_ERROR (Status);
-  } else {
-    //
-    // Install SecPlatformInformation2 PPI to include new BIST inforamtion
-    //
-    Status = PeiServicesInstallPpi (&mPeiSecPlatformInformation2Ppi);
-    ASSERT_EFI_ERROR(Status);
-  }
-}
+/** @file
+  Update and publish processors' BIST information.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "CpuMpPei.h"
+
+EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2Ppi = {
+  SecPlatformInformation2
+};
+
+EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2Ppi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gEfiSecPlatformInformation2PpiGuid,
+  &mSecPlatformInformation2Ppi
+};
+
+/**
+  Implementation of the PlatformInformation2 service in 
EFI_SEC_PLATFORM_INFORMATION2_PPI.
+
+  @param  PeiServices                The pointer to the PEI Services Table.
+  @param  StructureSize              The pointer to the variable describing 
size of the input buffer.
+  @param  PlatformInformationRecord2 The pointer to the 
EFI_SEC_PLATFORM_INFORMATION_RECORD2.
+
+  @retval EFI_SUCCESS                The data was successfully returned.
+  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current 
buffer size needed to
+                                     hold the record is returned in 
StructureSize.
+
+**/
+EFI_STATUS
+EFIAPI
+SecPlatformInformation2 (
+  IN CONST EFI_PEI_SERVICES                   **PeiServices,
+  IN OUT UINT64                               *StructureSize,
+     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
+  )
+{
+  PEI_CPU_MP_DATA                      *PeiCpuMpData;
+  UINTN                                BistInformationSize;
+  UINTN                                CpuIndex;
+  EFI_SEC_PLATFORM_INFORMATION_CPU     *CpuInstance;
+
+  PeiCpuMpData = GetMpHobData ();
+
+  BistInformationSize = sizeof (EFI_SEC_PLATFORM_INFORMATION_RECORD2) +
+                        sizeof (EFI_SEC_PLATFORM_INFORMATION_CPU) * 
PeiCpuMpData->CpuCount;
+  //
+  // return the information size if input buffer size is too small
+  //
+  if ((*StructureSize) < (UINT64) BistInformationSize) {
+    *StructureSize = (UINT64) BistInformationSize;
+    return EFI_BUFFER_TOO_SMALL;
+  }
+
+  PlatformInformationRecord2->NumberOfCpus = PeiCpuMpData->CpuCount;
+  CpuInstance = PlatformInformationRecord2->CpuInstance;
+  for (CpuIndex = 0; CpuIndex < PeiCpuMpData->CpuCount; CpuIndex ++) {
+    CpuInstance[CpuIndex].CpuLocation                = 
PeiCpuMpData->CpuData[CpuIndex].ApicId;
+    CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags = 
PeiCpuMpData->CpuData[CpuIndex].Health;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Worker function to get CPUs' BIST by calling SecPlatformInformationPpi
+  or SecPlatformInformation2Ppi.
+
+  @param  PeiServices         Pointer to PEI Services Table
+  @param  Guid                PPI Guid
+  @param  PpiDescriptor       Return a pointer to instance of the
+                              EFI_PEI_PPI_DESCRIPTOR
+  @param  BistInformationData Pointer to BIST information data
+
+  @retval EFI_SUCCESS         Retrieve of the BIST data successfully
+  @retval EFI_NOT_FOUND       No sec platform information(2) ppi export
+  @retval EFI_DEVICE_ERROR    Failed to get CPU Information
+
+**/
+EFI_STATUS
+GetBistInfoFromPpi (
+  IN CONST EFI_PEI_SERVICES     **PeiServices,
+  IN CONST EFI_GUID             *Guid,
+     OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
+     OUT VOID                   **BistInformationData
+  )
+{
+  EFI_STATUS                            Status;
+  EFI_SEC_PLATFORM_INFORMATION2_PPI     *SecPlatformInformation2Ppi;
+  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;
+  UINT64                                InformationSize;
+
+  Status = PeiServicesLocatePpi (
+             Guid,                                // GUID
+             0,                                   // INSTANCE
+             PpiDescriptor,                       // EFI_PEI_PPI_DESCRIPTOR
+             (VOID **)&SecPlatformInformation2Ppi // PPI
+             );
+  if (Status == EFI_NOT_FOUND) {
+    return EFI_NOT_FOUND;
+  }
+
+  if (Status == EFI_SUCCESS) {
+    //
+    // Get the size of the sec platform information2(BSP/APs' BIST data)
+    //
+    InformationSize         = 0;
+    SecPlatformInformation2 = NULL;
+    Status = SecPlatformInformation2Ppi->PlatformInformation2 (
+                                           PeiServices,
+                                           &InformationSize,
+                                           SecPlatformInformation2
+                                           );
+    if (Status == EFI_BUFFER_TOO_SMALL) {
+      Status = PeiServicesAllocatePool (
+                 (UINTN) InformationSize,
+                 (VOID **) &SecPlatformInformation2
+                 );
+      if (Status == EFI_SUCCESS) {
+        //
+        // Retrieve BIST data
+        //
+        Status = SecPlatformInformation2Ppi->PlatformInformation2 (
+                                               PeiServices,
+                                               &InformationSize,
+                                               SecPlatformInformation2
+                                               );
+        if (Status == EFI_SUCCESS) {
+          *BistInformationData = SecPlatformInformation2;
+          return EFI_SUCCESS;
+        }
+      }
+    }
+  }
+
+  return EFI_DEVICE_ERROR;
+}
+
+/**
+  Collects BIST data from PPI.
+
+  This function collects BIST data from Sec Platform Information2 PPI
+  or SEC Platform Information PPI.
+
+  @param PeiServices         Pointer to PEI Services Table
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+
+**/
+VOID
+CollectBistDataFromPpi (
+  IN CONST EFI_PEI_SERVICES             **PeiServices,
+  IN PEI_CPU_MP_DATA                    *PeiCpuMpData
+  )
+{
+  EFI_STATUS                            Status;
+  EFI_PEI_PPI_DESCRIPTOR                *SecInformationDescriptor;
+  EFI_SEC_PLATFORM_INFORMATION_RECORD2  *SecPlatformInformation2;
+  EFI_SEC_PLATFORM_INFORMATION_RECORD   *SecPlatformInformation;
+  UINTN                                 NumberOfData;
+  EFI_SEC_PLATFORM_INFORMATION_CPU      *CpuInstance;
+  EFI_SEC_PLATFORM_INFORMATION_CPU      BspCpuInstance;
+  UINTN                                 ProcessorNumber;
+  UINTN                                 CpuIndex;
+  PEI_CPU_DATA                          *CpuData;
+
+  SecPlatformInformation2 = NULL;
+  SecPlatformInformation  = NULL;
+  NumberOfData            = 0;
+  CpuInstance             = NULL;
+
+  //
+  // Get BIST information from Sec Platform Information2 Ppi firstly
+  //
+  Status = GetBistInfoFromPpi (
+             PeiServices,
+             &gEfiSecPlatformInformation2PpiGuid,
+             &SecInformationDescriptor,
+             (VOID *) &SecPlatformInformation2
+             );
+  if (Status == EFI_SUCCESS) {
+    //
+    // Sec Platform Information2 PPI includes BSP/APs' BIST information
+    //
+    NumberOfData = SecPlatformInformation2->NumberOfCpus;
+    CpuInstance  = SecPlatformInformation2->CpuInstance;
+  } else {
+    //
+    // Otherwise, get BIST information from Sec Platform Information Ppi
+    //
+    Status = GetBistInfoFromPpi (
+               PeiServices,
+               &gEfiSecPlatformInformationPpiGuid,
+               &SecInformationDescriptor,
+               (VOID *) &SecPlatformInformation
+               );
+    if (Status == EFI_SUCCESS) {
+      NumberOfData = 1;
+      //
+      // SEC Platform Information only includes BSP's BIST information
+      // and does not have BSP's APIC ID
+      //
+      BspCpuInstance.CpuLocation = GetInitialApicId ();
+      BspCpuInstance.InfoRecord.IA32HealthFlags.Uint32  = 
SecPlatformInformation->IA32HealthFlags.Uint32;
+      CpuInstance = &BspCpuInstance;
+    } else {
+      DEBUG ((EFI_D_INFO, "Does not find any stored CPU BIST information from 
PPI!\n"));
+    }
+  }
+  for (ProcessorNumber = 0; ProcessorNumber < PeiCpuMpData->CpuCount; 
ProcessorNumber ++) {
+    CpuData = &PeiCpuMpData->CpuData[ProcessorNumber];
+    for (CpuIndex = 0; CpuIndex < NumberOfData; CpuIndex ++) {
+      ASSERT (CpuInstance != NULL);
+      if (CpuData->ApicId == CpuInstance[CpuIndex].CpuLocation) {
+        //
+        // Update processor's BIST data if it is already stored before
+        //
+        CpuData->Health = CpuInstance[CpuIndex].InfoRecord.IA32HealthFlags;
+      }
+    }
+    if (CpuData->Health.Uint32 != 0) {
+      //
+      // Report Status Code that self test is failed
+      //
+      REPORT_STATUS_CODE (
+        EFI_ERROR_CODE | EFI_ERROR_MAJOR,
+        (EFI_COMPUTING_UNIT_HOST_PROCESSOR | EFI_CU_HP_EC_SELF_TEST)
+        );
+    }
+    DEBUG ((EFI_D_INFO, "  APICID - 0x%08x, BIST - 0x%08x\n",
+            PeiCpuMpData->CpuData[ProcessorNumber].ApicId,
+            PeiCpuMpData->CpuData[ProcessorNumber].Health.Uint32
+            ));
+  }
+
+  if (SecPlatformInformation2 != NULL && NumberOfData < 
PeiCpuMpData->CpuCount) {
+    //
+    // Reinstall SecPlatformInformation2 PPI to include new BIST inforamtion
+    //
+    Status = PeiServicesReInstallPpi (
+               SecInformationDescriptor,
+               &mPeiSecPlatformInformation2Ppi
+               );
+    ASSERT_EFI_ERROR (Status);
+  } else {
+    //
+    // Install SecPlatformInformation2 PPI to include new BIST inforamtion
+    //
+    Status = PeiServicesInstallPpi (&mPeiSecPlatformInformation2Ppi);
+    ASSERT_EFI_ERROR(Status);
+  }
+}

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.c
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.c   2015-08-06 05:45:32 UTC (rev 
18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.c   2015-08-06 06:57:47 UTC (rev 
18168)
@@ -1,566 +1,566 @@
-/** @file
-  CPU PEI Module installs CPU Multiple Processor PPI.
-
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD 
License
-  which accompanies this distribution.  The full text of the license may be 
found at
-  http://opensource.org/licenses/bsd-license.php
-
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "CpuMpPei.h"
-
-//
-// Global Descriptor Table (GDT)
-//
-GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = {
-/* selector { Global Segment Descriptor                              } */
-/* 0x00 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, 
//null descriptor
-/* 0x08 */  {{0xffff, 0,  0,  0x2,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//linear data segment descriptor
-/* 0x10 */  {{0xffff, 0,  0,  0xf,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//linear code segment descriptor
-/* 0x18 */  {{0xffff, 0,  0,  0x3,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//system data segment descriptor
-/* 0x20 */  {{0xffff, 0,  0,  0xa,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//system code segment descriptor
-/* 0x28 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, 
//spare segment descriptor
-/* 0x30 */  {{0xffff, 0,  0,  0x2,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//system data segment descriptor
-/* 0x38 */  {{0xffff, 0,  0,  0xa,  1,  0,  1,  0xf,  0,  1, 0,  1,  0}}, 
//system code segment descriptor
-/* 0x40 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, 
//spare segment descriptor
-};
-
-//
-// IA32 Gdt register
-//
-GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt = {
-  sizeof (mGdtEntries) - 1,
-  (UINTN) mGdtEntries
-  };
-
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
-  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | 
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
-  &gEfiEndOfPeiSignalPpiGuid,
-  CpuMpEndOfPeiCallback
-};
-
-/**
-  Sort the APIC ID of all processors.
-
-  This function sorts the APIC ID of all processors so that processor number is
-  assigned in the ascending order of APIC ID which eases MP debugging.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-**/
-VOID
-SortApicId (
-  IN PEI_CPU_MP_DATA   *PeiCpuMpData
-  )
-{
-  UINTN             Index1;
-  UINTN             Index2;
-  UINTN             Index3;
-  UINT32            ApicId;
-  EFI_HEALTH_FLAGS  Health;
-  UINT32            ApCount;
-
-  ApCount = PeiCpuMpData->CpuCount - 1;
-
-  if (ApCount != 0) {
-    for (Index1 = 0; Index1 < ApCount; Index1++) {
-      Index3 = Index1;
-      //
-      // Sort key is the hardware default APIC ID
-      //
-      ApicId = PeiCpuMpData->CpuData[Index1].ApicId;
-      for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
-        if (ApicId > PeiCpuMpData->CpuData[Index2].ApicId) {
-          Index3 = Index2;
-          ApicId = PeiCpuMpData->CpuData[Index2].ApicId;
-        }
-      }
-      if (Index3 != Index1) {
-        PeiCpuMpData->CpuData[Index3].ApicId = 
PeiCpuMpData->CpuData[Index1].ApicId;
-        PeiCpuMpData->CpuData[Index1].ApicId = ApicId;
-        Health = PeiCpuMpData->CpuData[Index3].Health;
-        PeiCpuMpData->CpuData[Index3].Health = 
PeiCpuMpData->CpuData[Index1].Health;
-        PeiCpuMpData->CpuData[Index1].Health = Health;
-      }
-    }
-
-    //
-    // Get the processor number for the BSP
-    //
-    ApicId = GetInitialApicId ();
-    for (Index1 = 0; Index1 < PeiCpuMpData->CpuCount; Index1++) {
-      if (PeiCpuMpData->CpuData[Index1].ApicId == ApicId) {
-        PeiCpuMpData->BspNumber = (UINT32) Index1;
-        break;
-      }
-    }
-  }
-}
-
-/**
-  Get CPU MP Data pointer from the Guided HOB.
-
-  @return  Pointer to Pointer to PEI CPU MP Data
-**/
-PEI_CPU_MP_DATA *
-GetMpHobData (
-  VOID
-  )
-{
-  EFI_HOB_GUID_TYPE       *GuidHob;
-  VOID                    *DataInHob;
-  PEI_CPU_MP_DATA         *CpuMpData;
-
-  CpuMpData = NULL;
-  GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
-  if (GuidHob != NULL) {
-    DataInHob = GET_GUID_HOB_DATA (GuidHob);
-    CpuMpData = (PEI_CPU_MP_DATA *)(*(UINTN *)DataInHob);
-  }
-  ASSERT (CpuMpData != NULL);
-  return CpuMpData;
-}
-
-/**
-  This function will be called from AP reset code if BSP uses WakeUpAP.
-
-  @param ExchangeInfo     Pointer to the MP exchange info buffer
-  @param NumApsExecuting  Number of curret executing AP
-**/
-VOID
-EFIAPI
-ApCFunction (
-  IN MP_CPU_EXCHANGE_INFO      *ExchangeInfo,
-  IN UINTN                     NumApsExecuting
-  )
-{
-  PEI_CPU_MP_DATA            *PeiCpuMpData;
-  UINTN                      ProcessorNumber;
-  EFI_AP_PROCEDURE           Procedure;
-  UINTN                      BistData;
-
-  PeiCpuMpData = ExchangeInfo->PeiCpuMpData;
-  if (PeiCpuMpData->InitFlag) {
-    //
-    // This is first time AP wakeup, get BIST inforamtion from AP stack
-    //
-    BistData = *(UINTN *) (PeiCpuMpData->Buffer + NumApsExecuting * 
PeiCpuMpData->CpuApStackSize - sizeof (UINTN));
-    PeiCpuMpData->CpuData[NumApsExecuting].ApicId        = GetInitialApicId ();
-    PeiCpuMpData->CpuData[NumApsExecuting].Health.Uint32 = (UINT32) BistData;
-    //
-    // Sync BSP's Mtrr table to all wakeup APs and load microcode on APs.
-    //
-    MtrrSetAllMtrrs (&PeiCpuMpData->MtrrTable);
-    MicrocodeDetect ();
-  } else {
-    //
-    // Execute AP function if AP is not disabled
-    //
-    GetProcessorNumber (PeiCpuMpData, &ProcessorNumber);
-    if ((PeiCpuMpData->CpuData[ProcessorNumber].State != CpuStateDisabled) &&
-        (PeiCpuMpData->ApFunction != 0)) {
-      PeiCpuMpData->CpuData[ProcessorNumber].State = CpuStateBusy;
-      Procedure = (EFI_AP_PROCEDURE)(UINTN)PeiCpuMpData->ApFunction;
-      Procedure ((VOID *)(UINTN)PeiCpuMpData->ApFunctionArgument);
-      PeiCpuMpData->CpuData[ProcessorNumber].State = CpuStateIdle;
-    }
-  }
-
-  //
-  // AP finished executing C code
-  //
-  InterlockedIncrement ((UINT32 *)&PeiCpuMpData->FinishedCount);
-
-  AsmCliHltLoop ();
-}
-
-/**
-  This function will be called by BSP to wakeup AP.
-
-  @param PeiCpuMpData       Pointer to PEI CPU MP Data
-  @param Broadcast          TRUE:  Send broadcast IPI to all APs
-                            FALSE: Send IPI to AP by ApicId
-  @param ApicId             Apic ID for the processor to be waked
-  @param Procedure          The function to be invoked by AP
-  @param ProcedureArgument  The argument to be passed into AP function
-**/
-VOID
-WakeUpAP (
-  IN PEI_CPU_MP_DATA           *PeiCpuMpData,
-  IN BOOLEAN                   Broadcast,
-  IN UINT32                    ApicId,
-  IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL
-  IN VOID                      *ProcedureArgument      OPTIONAL
-  )
-{
-  volatile MP_CPU_EXCHANGE_INFO    *ExchangeInfo;
-
-  PeiCpuMpData->ApFunction         = (UINTN) Procedure;
-  PeiCpuMpData->ApFunctionArgument = (UINTN) ProcedureArgument;
-  PeiCpuMpData->FinishedCount      = 0;
-
-  ExchangeInfo                     = PeiCpuMpData->MpCpuExchangeInfo;
-  ExchangeInfo->Lock               = 0;
-  ExchangeInfo->StackStart         = PeiCpuMpData->Buffer;
-  ExchangeInfo->StackSize          = PeiCpuMpData->CpuApStackSize;
-  ExchangeInfo->BufferStart        = PeiCpuMpData->WakeupBuffer;
-  ExchangeInfo->PmodeOffset        = PeiCpuMpData->AddressMap.PModeEntryOffset;
-  ExchangeInfo->LmodeOffset        = PeiCpuMpData->AddressMap.LModeEntryOffset;
-  ExchangeInfo->Cr3                = AsmReadCr3 ();
-  ExchangeInfo->CFunction          = (UINTN) ApCFunction;
-  ExchangeInfo->NumApsExecuting    = 0;
-  ExchangeInfo->PeiCpuMpData       = PeiCpuMpData;
-
-  //
-  // Get the BSP's data of GDT and IDT
-  //
-  CopyMem ((VOID *)&ExchangeInfo->GdtrProfile, &mGdt, sizeof(mGdt));
-  AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile);
-
-  if (Broadcast) {
-    SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
-  } else {
-    SendInitSipiSipi (ApicId, (UINT32) ExchangeInfo->BufferStart);
-  }
-
-  return ;
-}
-
-/**
-  Get available system memory below 1MB by specified size.
-
-  @param  WakeupBufferSize   Wakeup buffer size required
-
-  @retval other   Return wakeup buffer address below 1MB.
-  @retval -1      Cannot find free memory below 1MB.
-**/
-UINTN
-GetWakeupBuffer (
-  IN UINTN                WakeupBufferSize
-  )
-{
-  EFI_PEI_HOB_POINTERS    Hob;
-  UINTN                   WakeupBufferStart;
-  UINTN                   WakeupBufferEnd;
-
-  //
-  // Get the HOB list for processing
-  //
-  Hob.Raw = GetHobList ();
-
-  //
-  // Collect memory ranges
-  //
-  while (!END_OF_HOB_LIST (Hob)) {
-    if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
-      if ((Hob.ResourceDescriptor->PhysicalStart < BASE_1MB) &&
-          (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) 
&&
-          ((Hob.ResourceDescriptor->ResourceAttribute &
-            (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED |
-             EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED |
-             EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED
-             )) == 0)
-           ) {
-        //
-        // Need memory under 1MB to be collected here
-        //
-        WakeupBufferEnd = (UINTN) (Hob.ResourceDescriptor->PhysicalStart + 
Hob.ResourceDescriptor->ResourceLength);
-        if (WakeupBufferEnd > BASE_1MB) {
-          //
-          // Wakeup buffer should be under 1MB
-          //
-          WakeupBufferEnd = BASE_1MB;
-        }
-        //
-        // Wakeup buffer should be aligned on 4KB
-        //
-        WakeupBufferStart = (WakeupBufferEnd - WakeupBufferSize) & ~(SIZE_4KB 
- 1);
-        if (WakeupBufferStart < Hob.ResourceDescriptor->PhysicalStart) {
-          continue;
-        }
-        //
-        // Create a memory allocation HOB.
-        //
-        BuildMemoryAllocationHob (
-          WakeupBufferStart,
-          WakeupBufferSize,
-          EfiBootServicesData
-          );
-        return WakeupBufferStart;
-      }
-    }
-    //
-    // Find the next HOB
-    //
-    Hob.Raw = GET_NEXT_HOB (Hob);
-  }
-
-  return (UINTN) -1;
-}
-
-/**
-  Get available system memory below 1MB by specified size.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-**/
-VOID
-BackupAndPrepareWakeupBuffer(
-  IN PEI_CPU_MP_DATA         *PeiCpuMpData
-  )
-{
-  CopyMem (
-    (VOID *) PeiCpuMpData->BackupBuffer,
-    (VOID *) PeiCpuMpData->WakeupBuffer,
-    PeiCpuMpData->BackupBufferSize
-    );
-  CopyMem (
-    (VOID *) PeiCpuMpData->WakeupBuffer,
-    (VOID *) PeiCpuMpData->AddressMap.RendezvousFunnelAddress,
-    PeiCpuMpData->AddressMap.RendezvousFunnelSize
-    );
-}
-
-/**
-  Restore wakeup buffer data.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-**/
-VOID
-RestoreWakeupBuffer(
-  IN PEI_CPU_MP_DATA         *PeiCpuMpData
-  )
-{
-  CopyMem ((VOID *) PeiCpuMpData->WakeupBuffer, (VOID *) 
PeiCpuMpData->BackupBuffer, PeiCpuMpData->BackupBufferSize);
-}
-
-/**
-  This function will get CPU count in the system.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-
-  @return  AP processor count
-**/
-UINT32
-CountProcessorNumber (
-  IN PEI_CPU_MP_DATA            *PeiCpuMpData
-  )
-{
-  //
-  // Load Microcode on BSP
-  //
-  MicrocodeDetect ();
-  //
-  // Store BSP's MTRR setting
-  //
-  MtrrGetAllMtrrs (&PeiCpuMpData->MtrrTable);
-  //
-  // Send broadcast IPI to APs to wakeup APs
-  //
-  PeiCpuMpData->InitFlag = 1;
-  WakeUpAP (PeiCpuMpData, TRUE, 0, NULL, NULL);
-  //
-  // Wait for AP task to complete and then exit.
-  //
-  MicroSecondDelay (PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds));
-  PeiCpuMpData->InitFlag  = 0;
-  PeiCpuMpData->CpuCount += (UINT32) 
PeiCpuMpData->MpCpuExchangeInfo->NumApsExecuting;
-  //
-  // Sort BSP/Aps by CPU APIC ID in ascending order
-  //
-  SortApicId (PeiCpuMpData);
-
-  DEBUG ((EFI_D_INFO, "CpuMpPei: Find %d processors in system.\n", 
PeiCpuMpData->CpuCount));
-  return PeiCpuMpData->CpuCount;
-}
-
-/**
-  Prepare for AP wakeup buffer and copy AP reset code into it.
-
-  Get wakeup buffer below 1MB. Allocate memory for CPU MP Data and APs Stack.
-
-  @return   Pointer to PEI CPU MP Data
-**/
-PEI_CPU_MP_DATA *
-PrepareAPStartupVector (
-  VOID
-  )
-{
-  EFI_STATUS                    Status;
-  UINT32                        MaxCpuCount;
-  PEI_CPU_MP_DATA               *PeiCpuMpData;
-  EFI_PHYSICAL_ADDRESS          Buffer;
-  UINTN                         BufferSize;
-  UINTN                         WakeupBuffer;
-  UINTN                         WakeupBufferSize;
-  MP_ASSEMBLY_ADDRESS_MAP       AddressMap;
-
-  AsmGetAddressMap (&AddressMap);
-  WakeupBufferSize = AddressMap.RendezvousFunnelSize + sizeof 
(MP_CPU_EXCHANGE_INFO);
-  WakeupBuffer     = GetWakeupBuffer ((WakeupBufferSize + SIZE_4KB - 1) & 
~(SIZE_4KB - 1));
-  ASSERT (WakeupBuffer != (UINTN) -1);
-  DEBUG ((EFI_D_INFO, "CpuMpPei: WakeupBuffer = 0x%x\n", WakeupBuffer));
-
-  //
-  // Allocate Pages for APs stack, CPU MP Data and backup buffer for wakeup 
buffer
-  //
-  MaxCpuCount = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
-  BufferSize  = PcdGet32 (PcdCpuApStackSize) * MaxCpuCount + sizeof 
(PEI_CPU_MP_DATA)
-                  + WakeupBufferSize + sizeof (PEI_CPU_DATA) * MaxCpuCount;
-  Status = PeiServicesAllocatePages (
-             EfiBootServicesData,
-             EFI_SIZE_TO_PAGES (BufferSize),
-             &Buffer
-             );
-  ASSERT_EFI_ERROR (Status);
-
-  PeiCpuMpData = (PEI_CPU_MP_DATA *) (UINTN) (Buffer + PcdGet32 
(PcdCpuApStackSize) * MaxCpuCount);
-  PeiCpuMpData->Buffer            = (UINTN) Buffer;
-  PeiCpuMpData->CpuApStackSize    = PcdGet32 (PcdCpuApStackSize);
-  PeiCpuMpData->WakeupBuffer      = WakeupBuffer;
-  PeiCpuMpData->BackupBuffer      = (UINTN)PeiCpuMpData + sizeof 
(PEI_CPU_MP_DATA);
-  PeiCpuMpData->BackupBufferSize  = WakeupBufferSize;
-  PeiCpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN) 
(WakeupBuffer + AddressMap.RendezvousFunnelSize);
-
-  PeiCpuMpData->CpuCount                 = 1;
-  PeiCpuMpData->BspNumber                = 0;
-  PeiCpuMpData->CpuData                  = (PEI_CPU_DATA *) 
(PeiCpuMpData->MpCpuExchangeInfo + 1);
-  PeiCpuMpData->CpuData[0].ApicId        = GetInitialApicId ();
-  PeiCpuMpData->CpuData[0].Health.Uint32 = 0;
-  PeiCpuMpData->EndOfPeiFlag             = FALSE;
-  CopyMem (&PeiCpuMpData->AddressMap, &AddressMap, sizeof 
(MP_ASSEMBLY_ADDRESS_MAP));
-
-  //
-  // Backup original data and copy AP reset code in it
-  //
-  BackupAndPrepareWakeupBuffer(PeiCpuMpData);
-
-  return PeiCpuMpData;
-}
-
-/**
-  Notify function on End Of Pei PPI.
-
-  On S3 boot, this function will restore wakeup buffer data.
-  On normal boot, this function will flag wakeup buffer to be un-used type.
-
-  @param  PeiServices        The pointer to the PEI Services Table.
-  @param  NotifyDescriptor   Address of the notification descriptor data 
structure.
-  @param  Ppi                Address of the PPI that was installed.
-
-  @retval EFI_SUCCESS        When everything is OK.
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMpEndOfPeiCallback (
-  IN      EFI_PEI_SERVICES        **PeiServices,
-  IN EFI_PEI_NOTIFY_DESCRIPTOR    *NotifyDescriptor,
-  IN VOID                         *Ppi
-  )
-{
-  EFI_STATUS                Status;
-  EFI_BOOT_MODE             BootMode;
-  PEI_CPU_MP_DATA           *PeiCpuMpData;
-  EFI_PEI_HOB_POINTERS      Hob;
-  EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
-
-  DEBUG ((EFI_D_INFO, "CpuMpPei: CpuMpEndOfPeiCallback () invokded\n"));
-
-  Status = PeiServicesGetBootMode (&BootMode);
-  ASSERT_EFI_ERROR (Status);
-
-  PeiCpuMpData = GetMpHobData ();
-  ASSERT (PeiCpuMpData != NULL);
-
-  if (BootMode != BOOT_ON_S3_RESUME) {
-    //
-    // Get the HOB list for processing
-    //
-    Hob.Raw = GetHobList ();
-    //
-    // Collect memory ranges
-    //
-    while (!END_OF_HOB_LIST (Hob)) {
-      if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
-        MemoryHob = Hob.MemoryAllocation;
-        if(MemoryHob->AllocDescriptor.MemoryBaseAddress == 
PeiCpuMpData->WakeupBuffer) {
-          //
-          // Flag this HOB type to un-used
-          //
-          GET_HOB_TYPE (Hob) = EFI_HOB_TYPE_UNUSED;
-          break;
-        }
-      }
-      Hob.Raw = GET_NEXT_HOB (Hob);
-    }
-  } else {
-    RestoreWakeupBuffer (PeiCpuMpData);
-    PeiCpuMpData->EndOfPeiFlag = TRUE;
-  }
-  return EFI_SUCCESS;
-}
-
-/**
-  The Entry point of the MP CPU PEIM.
-
-  This function will wakeup APs and collect CPU AP count and install the
-  Mp Service Ppi.
-
-  @param  FileHandle    Handle of the file being invoked.
-  @param  PeiServices   Describes the list of possible PEI Services.
-
-  @retval EFI_SUCCESS   MpServicePpi is installed successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMpPeimInit (
-  IN       EFI_PEI_FILE_HANDLE  FileHandle,
-  IN CONST EFI_PEI_SERVICES     **PeiServices
-  )
-{
-  EFI_STATUS           Status;
-  PEI_CPU_MP_DATA      *PeiCpuMpData;
-  UINT32               ProcessorCount;
-
-  //
-  // Load new GDT table on BSP
-  //
-  AsmInitializeGdt (&mGdt);
-  //
-  // Get wakeup buffer and copy AP reset code in it
-  //
-  PeiCpuMpData = PrepareAPStartupVector ();
-  //
-  // Count processor number and collect processor information
-  //
-  ProcessorCount = CountProcessorNumber (PeiCpuMpData);
-  //
-  // Build location of PEI CPU MP DATA buffer in HOB
-  //
-  BuildGuidDataHob (
-    &gEfiCallerIdGuid,
-    (VOID *)&PeiCpuMpData,
-    sizeof(UINT64)
-    );
-  //
-  // Update and publish CPU BIST information
-  //
-  CollectBistDataFromPpi (PeiServices, PeiCpuMpData);
-  //
-  // register an event for EndOfPei
-  //
-  Status  = PeiServicesNotifyPpi (&mNotifyList);
-  ASSERT_EFI_ERROR (Status);
-  //
-  // Install CPU MP PPI
-  //
-  Status = PeiServicesInstallPpi(&mPeiCpuMpPpiDesc);
-  ASSERT_EFI_ERROR (Status);
-
-  return Status;
-}
+/** @file
+  CPU PEI Module installs CPU Multiple Processor PPI.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include "CpuMpPei.h"
+
+//
+// Global Descriptor Table (GDT)
+//
+GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = {
+/* selector { Global Segment Descriptor                              } */
+/* 0x00 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, 
//null descriptor
+/* 0x08 */  {{0xffff, 0,  0,  0x2,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//linear data segment descriptor
+/* 0x10 */  {{0xffff, 0,  0,  0xf,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//linear code segment descriptor
+/* 0x18 */  {{0xffff, 0,  0,  0x3,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//system data segment descriptor
+/* 0x20 */  {{0xffff, 0,  0,  0xa,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//system code segment descriptor
+/* 0x28 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, 
//spare segment descriptor
+/* 0x30 */  {{0xffff, 0,  0,  0x2,  1,  0,  1,  0xf,  0,  0, 1,  1,  0}}, 
//system data segment descriptor
+/* 0x38 */  {{0xffff, 0,  0,  0xa,  1,  0,  1,  0xf,  0,  1, 0,  1,  0}}, 
//system code segment descriptor
+/* 0x40 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}}, 
//spare segment descriptor
+};
+
+//
+// IA32 Gdt register
+//
+GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR mGdt = {
+  sizeof (mGdtEntries) - 1,
+  (UINTN) mGdtEntries
+  };
+
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
+  (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | 
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gEfiEndOfPeiSignalPpiGuid,
+  CpuMpEndOfPeiCallback
+};
+
+/**
+  Sort the APIC ID of all processors.
+
+  This function sorts the APIC ID of all processors so that processor number is
+  assigned in the ascending order of APIC ID which eases MP debugging.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+**/
+VOID
+SortApicId (
+  IN PEI_CPU_MP_DATA   *PeiCpuMpData
+  )
+{
+  UINTN             Index1;
+  UINTN             Index2;
+  UINTN             Index3;
+  UINT32            ApicId;
+  EFI_HEALTH_FLAGS  Health;
+  UINT32            ApCount;
+
+  ApCount = PeiCpuMpData->CpuCount - 1;
+
+  if (ApCount != 0) {
+    for (Index1 = 0; Index1 < ApCount; Index1++) {
+      Index3 = Index1;
+      //
+      // Sort key is the hardware default APIC ID
+      //
+      ApicId = PeiCpuMpData->CpuData[Index1].ApicId;
+      for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
+        if (ApicId > PeiCpuMpData->CpuData[Index2].ApicId) {
+          Index3 = Index2;
+          ApicId = PeiCpuMpData->CpuData[Index2].ApicId;
+        }
+      }
+      if (Index3 != Index1) {
+        PeiCpuMpData->CpuData[Index3].ApicId = 
PeiCpuMpData->CpuData[Index1].ApicId;
+        PeiCpuMpData->CpuData[Index1].ApicId = ApicId;
+        Health = PeiCpuMpData->CpuData[Index3].Health;
+        PeiCpuMpData->CpuData[Index3].Health = 
PeiCpuMpData->CpuData[Index1].Health;
+        PeiCpuMpData->CpuData[Index1].Health = Health;
+      }
+    }
+
+    //
+    // Get the processor number for the BSP
+    //
+    ApicId = GetInitialApicId ();
+    for (Index1 = 0; Index1 < PeiCpuMpData->CpuCount; Index1++) {
+      if (PeiCpuMpData->CpuData[Index1].ApicId == ApicId) {
+        PeiCpuMpData->BspNumber = (UINT32) Index1;
+        break;
+      }
+    }
+  }
+}
+
+/**
+  Get CPU MP Data pointer from the Guided HOB.
+
+  @return  Pointer to Pointer to PEI CPU MP Data
+**/
+PEI_CPU_MP_DATA *
+GetMpHobData (
+  VOID
+  )
+{
+  EFI_HOB_GUID_TYPE       *GuidHob;
+  VOID                    *DataInHob;
+  PEI_CPU_MP_DATA         *CpuMpData;
+
+  CpuMpData = NULL;
+  GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);
+  if (GuidHob != NULL) {
+    DataInHob = GET_GUID_HOB_DATA (GuidHob);
+    CpuMpData = (PEI_CPU_MP_DATA *)(*(UINTN *)DataInHob);
+  }
+  ASSERT (CpuMpData != NULL);
+  return CpuMpData;
+}
+
+/**
+  This function will be called from AP reset code if BSP uses WakeUpAP.
+
+  @param ExchangeInfo     Pointer to the MP exchange info buffer
+  @param NumApsExecuting  Number of curret executing AP
+**/
+VOID
+EFIAPI
+ApCFunction (
+  IN MP_CPU_EXCHANGE_INFO      *ExchangeInfo,
+  IN UINTN                     NumApsExecuting
+  )
+{
+  PEI_CPU_MP_DATA            *PeiCpuMpData;
+  UINTN                      ProcessorNumber;
+  EFI_AP_PROCEDURE           Procedure;
+  UINTN                      BistData;
+
+  PeiCpuMpData = ExchangeInfo->PeiCpuMpData;
+  if (PeiCpuMpData->InitFlag) {
+    //
+    // This is first time AP wakeup, get BIST inforamtion from AP stack
+    //
+    BistData = *(UINTN *) (PeiCpuMpData->Buffer + NumApsExecuting * 
PeiCpuMpData->CpuApStackSize - sizeof (UINTN));
+    PeiCpuMpData->CpuData[NumApsExecuting].ApicId        = GetInitialApicId ();
+    PeiCpuMpData->CpuData[NumApsExecuting].Health.Uint32 = (UINT32) BistData;
+    //
+    // Sync BSP's Mtrr table to all wakeup APs and load microcode on APs.
+    //
+    MtrrSetAllMtrrs (&PeiCpuMpData->MtrrTable);
+    MicrocodeDetect ();
+  } else {
+    //
+    // Execute AP function if AP is not disabled
+    //
+    GetProcessorNumber (PeiCpuMpData, &ProcessorNumber);
+    if ((PeiCpuMpData->CpuData[ProcessorNumber].State != CpuStateDisabled) &&
+        (PeiCpuMpData->ApFunction != 0)) {
+      PeiCpuMpData->CpuData[ProcessorNumber].State = CpuStateBusy;
+      Procedure = (EFI_AP_PROCEDURE)(UINTN)PeiCpuMpData->ApFunction;
+      Procedure ((VOID *)(UINTN)PeiCpuMpData->ApFunctionArgument);
+      PeiCpuMpData->CpuData[ProcessorNumber].State = CpuStateIdle;
+    }
+  }
+
+  //
+  // AP finished executing C code
+  //
+  InterlockedIncrement ((UINT32 *)&PeiCpuMpData->FinishedCount);
+
+  AsmCliHltLoop ();
+}
+
+/**
+  This function will be called by BSP to wakeup AP.
+
+  @param PeiCpuMpData       Pointer to PEI CPU MP Data
+  @param Broadcast          TRUE:  Send broadcast IPI to all APs
+                            FALSE: Send IPI to AP by ApicId
+  @param ApicId             Apic ID for the processor to be waked
+  @param Procedure          The function to be invoked by AP
+  @param ProcedureArgument  The argument to be passed into AP function
+**/
+VOID
+WakeUpAP (
+  IN PEI_CPU_MP_DATA           *PeiCpuMpData,
+  IN BOOLEAN                   Broadcast,
+  IN UINT32                    ApicId,
+  IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL
+  IN VOID                      *ProcedureArgument      OPTIONAL
+  )
+{
+  volatile MP_CPU_EXCHANGE_INFO    *ExchangeInfo;
+
+  PeiCpuMpData->ApFunction         = (UINTN) Procedure;
+  PeiCpuMpData->ApFunctionArgument = (UINTN) ProcedureArgument;
+  PeiCpuMpData->FinishedCount      = 0;
+
+  ExchangeInfo                     = PeiCpuMpData->MpCpuExchangeInfo;
+  ExchangeInfo->Lock               = 0;
+  ExchangeInfo->StackStart         = PeiCpuMpData->Buffer;
+  ExchangeInfo->StackSize          = PeiCpuMpData->CpuApStackSize;
+  ExchangeInfo->BufferStart        = PeiCpuMpData->WakeupBuffer;
+  ExchangeInfo->PmodeOffset        = PeiCpuMpData->AddressMap.PModeEntryOffset;
+  ExchangeInfo->LmodeOffset        = PeiCpuMpData->AddressMap.LModeEntryOffset;
+  ExchangeInfo->Cr3                = AsmReadCr3 ();
+  ExchangeInfo->CFunction          = (UINTN) ApCFunction;
+  ExchangeInfo->NumApsExecuting    = 0;
+  ExchangeInfo->PeiCpuMpData       = PeiCpuMpData;
+
+  //
+  // Get the BSP's data of GDT and IDT
+  //
+  CopyMem ((VOID *)&ExchangeInfo->GdtrProfile, &mGdt, sizeof(mGdt));
+  AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile);
+
+  if (Broadcast) {
+    SendInitSipiSipiAllExcludingSelf ((UINT32) ExchangeInfo->BufferStart);
+  } else {
+    SendInitSipiSipi (ApicId, (UINT32) ExchangeInfo->BufferStart);
+  }
+
+  return ;
+}
+
+/**
+  Get available system memory below 1MB by specified size.
+
+  @param  WakeupBufferSize   Wakeup buffer size required
+
+  @retval other   Return wakeup buffer address below 1MB.
+  @retval -1      Cannot find free memory below 1MB.
+**/
+UINTN
+GetWakeupBuffer (
+  IN UINTN                WakeupBufferSize
+  )
+{
+  EFI_PEI_HOB_POINTERS    Hob;
+  UINTN                   WakeupBufferStart;
+  UINTN                   WakeupBufferEnd;
+
+  //
+  // Get the HOB list for processing
+  //
+  Hob.Raw = GetHobList ();
+
+  //
+  // Collect memory ranges
+  //
+  while (!END_OF_HOB_LIST (Hob)) {
+    if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
+      if ((Hob.ResourceDescriptor->PhysicalStart < BASE_1MB) &&
+          (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) 
&&
+          ((Hob.ResourceDescriptor->ResourceAttribute &
+            (EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED |
+             EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED |
+             EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED
+             )) == 0)
+           ) {
+        //
+        // Need memory under 1MB to be collected here
+        //
+        WakeupBufferEnd = (UINTN) (Hob.ResourceDescriptor->PhysicalStart + 
Hob.ResourceDescriptor->ResourceLength);
+        if (WakeupBufferEnd > BASE_1MB) {
+          //
+          // Wakeup buffer should be under 1MB
+          //
+          WakeupBufferEnd = BASE_1MB;
+        }
+        //
+        // Wakeup buffer should be aligned on 4KB
+        //
+        WakeupBufferStart = (WakeupBufferEnd - WakeupBufferSize) & ~(SIZE_4KB 
- 1);
+        if (WakeupBufferStart < Hob.ResourceDescriptor->PhysicalStart) {
+          continue;
+        }
+        //
+        // Create a memory allocation HOB.
+        //
+        BuildMemoryAllocationHob (
+          WakeupBufferStart,
+          WakeupBufferSize,
+          EfiBootServicesData
+          );
+        return WakeupBufferStart;
+      }
+    }
+    //
+    // Find the next HOB
+    //
+    Hob.Raw = GET_NEXT_HOB (Hob);
+  }
+
+  return (UINTN) -1;
+}
+
+/**
+  Get available system memory below 1MB by specified size.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+**/
+VOID
+BackupAndPrepareWakeupBuffer(
+  IN PEI_CPU_MP_DATA         *PeiCpuMpData
+  )
+{
+  CopyMem (
+    (VOID *) PeiCpuMpData->BackupBuffer,
+    (VOID *) PeiCpuMpData->WakeupBuffer,
+    PeiCpuMpData->BackupBufferSize
+    );
+  CopyMem (
+    (VOID *) PeiCpuMpData->WakeupBuffer,
+    (VOID *) PeiCpuMpData->AddressMap.RendezvousFunnelAddress,
+    PeiCpuMpData->AddressMap.RendezvousFunnelSize
+    );
+}
+
+/**
+  Restore wakeup buffer data.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+**/
+VOID
+RestoreWakeupBuffer(
+  IN PEI_CPU_MP_DATA         *PeiCpuMpData
+  )
+{
+  CopyMem ((VOID *) PeiCpuMpData->WakeupBuffer, (VOID *) 
PeiCpuMpData->BackupBuffer, PeiCpuMpData->BackupBufferSize);
+}
+
+/**
+  This function will get CPU count in the system.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+
+  @return  AP processor count
+**/
+UINT32
+CountProcessorNumber (
+  IN PEI_CPU_MP_DATA            *PeiCpuMpData
+  )
+{
+  //
+  // Load Microcode on BSP
+  //
+  MicrocodeDetect ();
+  //
+  // Store BSP's MTRR setting
+  //
+  MtrrGetAllMtrrs (&PeiCpuMpData->MtrrTable);
+  //
+  // Send broadcast IPI to APs to wakeup APs
+  //
+  PeiCpuMpData->InitFlag = 1;
+  WakeUpAP (PeiCpuMpData, TRUE, 0, NULL, NULL);
+  //
+  // Wait for AP task to complete and then exit.
+  //
+  MicroSecondDelay (PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds));
+  PeiCpuMpData->InitFlag  = 0;
+  PeiCpuMpData->CpuCount += (UINT32) 
PeiCpuMpData->MpCpuExchangeInfo->NumApsExecuting;
+  //
+  // Sort BSP/Aps by CPU APIC ID in ascending order
+  //
+  SortApicId (PeiCpuMpData);
+
+  DEBUG ((EFI_D_INFO, "CpuMpPei: Find %d processors in system.\n", 
PeiCpuMpData->CpuCount));
+  return PeiCpuMpData->CpuCount;
+}
+
+/**
+  Prepare for AP wakeup buffer and copy AP reset code into it.
+
+  Get wakeup buffer below 1MB. Allocate memory for CPU MP Data and APs Stack.
+
+  @return   Pointer to PEI CPU MP Data
+**/
+PEI_CPU_MP_DATA *
+PrepareAPStartupVector (
+  VOID
+  )
+{
+  EFI_STATUS                    Status;
+  UINT32                        MaxCpuCount;
+  PEI_CPU_MP_DATA               *PeiCpuMpData;
+  EFI_PHYSICAL_ADDRESS          Buffer;
+  UINTN                         BufferSize;
+  UINTN                         WakeupBuffer;
+  UINTN                         WakeupBufferSize;
+  MP_ASSEMBLY_ADDRESS_MAP       AddressMap;
+
+  AsmGetAddressMap (&AddressMap);
+  WakeupBufferSize = AddressMap.RendezvousFunnelSize + sizeof 
(MP_CPU_EXCHANGE_INFO);
+  WakeupBuffer     = GetWakeupBuffer ((WakeupBufferSize + SIZE_4KB - 1) & 
~(SIZE_4KB - 1));
+  ASSERT (WakeupBuffer != (UINTN) -1);
+  DEBUG ((EFI_D_INFO, "CpuMpPei: WakeupBuffer = 0x%x\n", WakeupBuffer));
+
+  //
+  // Allocate Pages for APs stack, CPU MP Data and backup buffer for wakeup 
buffer
+  //
+  MaxCpuCount = PcdGet32(PcdCpuMaxLogicalProcessorNumber);
+  BufferSize  = PcdGet32 (PcdCpuApStackSize) * MaxCpuCount + sizeof 
(PEI_CPU_MP_DATA)
+                  + WakeupBufferSize + sizeof (PEI_CPU_DATA) * MaxCpuCount;
+  Status = PeiServicesAllocatePages (
+             EfiBootServicesData,
+             EFI_SIZE_TO_PAGES (BufferSize),
+             &Buffer
+             );
+  ASSERT_EFI_ERROR (Status);
+
+  PeiCpuMpData = (PEI_CPU_MP_DATA *) (UINTN) (Buffer + PcdGet32 
(PcdCpuApStackSize) * MaxCpuCount);
+  PeiCpuMpData->Buffer            = (UINTN) Buffer;
+  PeiCpuMpData->CpuApStackSize    = PcdGet32 (PcdCpuApStackSize);
+  PeiCpuMpData->WakeupBuffer      = WakeupBuffer;
+  PeiCpuMpData->BackupBuffer      = (UINTN)PeiCpuMpData + sizeof 
(PEI_CPU_MP_DATA);
+  PeiCpuMpData->BackupBufferSize  = WakeupBufferSize;
+  PeiCpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN) 
(WakeupBuffer + AddressMap.RendezvousFunnelSize);
+
+  PeiCpuMpData->CpuCount                 = 1;
+  PeiCpuMpData->BspNumber                = 0;
+  PeiCpuMpData->CpuData                  = (PEI_CPU_DATA *) 
(PeiCpuMpData->MpCpuExchangeInfo + 1);
+  PeiCpuMpData->CpuData[0].ApicId        = GetInitialApicId ();
+  PeiCpuMpData->CpuData[0].Health.Uint32 = 0;
+  PeiCpuMpData->EndOfPeiFlag             = FALSE;
+  CopyMem (&PeiCpuMpData->AddressMap, &AddressMap, sizeof 
(MP_ASSEMBLY_ADDRESS_MAP));
+
+  //
+  // Backup original data and copy AP reset code in it
+  //
+  BackupAndPrepareWakeupBuffer(PeiCpuMpData);
+
+  return PeiCpuMpData;
+}
+
+/**
+  Notify function on End Of Pei PPI.
+
+  On S3 boot, this function will restore wakeup buffer data.
+  On normal boot, this function will flag wakeup buffer to be un-used type.
+
+  @param  PeiServices        The pointer to the PEI Services Table.
+  @param  NotifyDescriptor   Address of the notification descriptor data 
structure.
+  @param  Ppi                Address of the PPI that was installed.
+
+  @retval EFI_SUCCESS        When everything is OK.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuMpEndOfPeiCallback (
+  IN      EFI_PEI_SERVICES        **PeiServices,
+  IN EFI_PEI_NOTIFY_DESCRIPTOR    *NotifyDescriptor,
+  IN VOID                         *Ppi
+  )
+{
+  EFI_STATUS                Status;
+  EFI_BOOT_MODE             BootMode;
+  PEI_CPU_MP_DATA           *PeiCpuMpData;
+  EFI_PEI_HOB_POINTERS      Hob;
+  EFI_HOB_MEMORY_ALLOCATION *MemoryHob;
+
+  DEBUG ((EFI_D_INFO, "CpuMpPei: CpuMpEndOfPeiCallback () invokded\n"));
+
+  Status = PeiServicesGetBootMode (&BootMode);
+  ASSERT_EFI_ERROR (Status);
+
+  PeiCpuMpData = GetMpHobData ();
+  ASSERT (PeiCpuMpData != NULL);
+
+  if (BootMode != BOOT_ON_S3_RESUME) {
+    //
+    // Get the HOB list for processing
+    //
+    Hob.Raw = GetHobList ();
+    //
+    // Collect memory ranges
+    //
+    while (!END_OF_HOB_LIST (Hob)) {
+      if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
+        MemoryHob = Hob.MemoryAllocation;
+        if(MemoryHob->AllocDescriptor.MemoryBaseAddress == 
PeiCpuMpData->WakeupBuffer) {
+          //
+          // Flag this HOB type to un-used
+          //
+          GET_HOB_TYPE (Hob) = EFI_HOB_TYPE_UNUSED;
+          break;
+        }
+      }
+      Hob.Raw = GET_NEXT_HOB (Hob);
+    }
+  } else {
+    RestoreWakeupBuffer (PeiCpuMpData);
+    PeiCpuMpData->EndOfPeiFlag = TRUE;
+  }
+  return EFI_SUCCESS;
+}
+
+/**
+  The Entry point of the MP CPU PEIM.
+
+  This function will wakeup APs and collect CPU AP count and install the
+  Mp Service Ppi.
+
+  @param  FileHandle    Handle of the file being invoked.
+  @param  PeiServices   Describes the list of possible PEI Services.
+
+  @retval EFI_SUCCESS   MpServicePpi is installed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuMpPeimInit (
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  EFI_STATUS           Status;
+  PEI_CPU_MP_DATA      *PeiCpuMpData;
+  UINT32               ProcessorCount;
+
+  //
+  // Load new GDT table on BSP
+  //
+  AsmInitializeGdt (&mGdt);
+  //
+  // Get wakeup buffer and copy AP reset code in it
+  //
+  PeiCpuMpData = PrepareAPStartupVector ();
+  //
+  // Count processor number and collect processor information
+  //
+  ProcessorCount = CountProcessorNumber (PeiCpuMpData);
+  //
+  // Build location of PEI CPU MP DATA buffer in HOB
+  //
+  BuildGuidDataHob (
+    &gEfiCallerIdGuid,
+    (VOID *)&PeiCpuMpData,
+    sizeof(UINT64)
+    );
+  //
+  // Update and publish CPU BIST information
+  //
+  CollectBistDataFromPpi (PeiServices, PeiCpuMpData);
+  //
+  // register an event for EndOfPei
+  //
+  Status  = PeiServicesNotifyPpi (&mNotifyList);
+  ASSERT_EFI_ERROR (Status);
+  //
+  // Install CPU MP PPI
+  //
+  Status = PeiServicesInstallPpi(&mPeiCpuMpPpiDesc);
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.h
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.h   2015-08-06 05:45:32 UTC (rev 
18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.h   2015-08-06 06:57:47 UTC (rev 
18168)
@@ -1,302 +1,302 @@
-/** @file
-  Definitions to install Multiple Processor PPI.
-
-  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD 
License
-  which accompanies this distribution.  The full text of the license may be 
found at
-  http://opensource.org/licenses/bsd-license.php
-
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#ifndef _CPU_MP_PEI_H_
-#define _CPU_MP_PEI_H_
-
-#include <PiPei.h>
-
-#include <Ppi/MpServices.h>
-#include <Ppi/SecPlatformInformation.h>
-#include <Ppi/SecPlatformInformation2.h>
-#include <Ppi/EndOfPeiPhase.h>
-
-#include <Register/LocalApic.h>
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/HobLib.h>
-#include <Library/LocalApicLib.h>
-#include <Library/MtrrLib.h>
-#include <Library/PcdLib.h>
-#include <Library/PeimEntryPoint.h>
-#include <Library/PeiServicesLib.h>
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/SynchronizationLib.h>
-#include <Library/TimerLib.h>
-#include <Library/UefiCpuLib.h>
-
-#include "Microcode.h"
-
-//
-// AP state
-//
-typedef enum {
-  CpuStateIdle,
-  CpuStateBusy,
-  CpuStateDisabled
-} CPU_STATE;
-
-//
-// AP reset code information
-//
-typedef struct {
-  UINT8             *RendezvousFunnelAddress;
-  UINTN             PModeEntryOffset;
-  UINTN             LModeEntryOffset;
-  UINTN             RendezvousFunnelSize;
-} MP_ASSEMBLY_ADDRESS_MAP;
-
-//
-// CPU exchange information for switch BSP
-//
-typedef struct {
-  UINT8             State;        // offset 0
-  UINTN             StackPointer; // offset 4 / 8
-  IA32_DESCRIPTOR   Gdtr;         // offset 8 / 16
-  IA32_DESCRIPTOR   Idtr;         // offset 14 / 26
-} CPU_EXCHANGE_ROLE_INFO;
-
-typedef struct _PEI_CPU_MP_DATA  PEI_CPU_MP_DATA;
-
-#pragma pack()
-
-typedef union {
-  struct {
-    UINT32  LimitLow    : 16;
-    UINT32  BaseLow     : 16;
-    UINT32  BaseMid     : 8;
-    UINT32  Type        : 4;
-    UINT32  System      : 1;
-    UINT32  Dpl         : 2;
-    UINT32  Present     : 1;
-    UINT32  LimitHigh   : 4;
-    UINT32  Software    : 1;
-    UINT32  Reserved    : 1;
-    UINT32  DefaultSize : 1;
-    UINT32  Granularity : 1;
-    UINT32  BaseHigh    : 8;
-  } Bits;
-  UINT64  Uint64;
-} IA32_GDT;
-
-//
-// MP CPU exchange information for AP reset code
-//
-typedef struct {
-  UINTN                 Lock;
-  UINTN                 StackStart;
-  UINTN                 StackSize;
-  UINTN                 CFunction;
-  IA32_DESCRIPTOR       GdtrProfile;
-  IA32_DESCRIPTOR       IdtrProfile;
-  UINTN                 BufferStart;
-  UINTN                 PmodeOffset;
-  UINTN                 NumApsExecuting;
-  UINTN                 LmodeOffset;
-  UINTN                 Cr3;
-  PEI_CPU_MP_DATA       *PeiCpuMpData;
-} MP_CPU_EXCHANGE_INFO;
-
-#pragma pack()
-
-typedef struct {
-  UINT32                         ApicId;
-  EFI_HEALTH_FLAGS               Health;
-  CPU_STATE                      State;
-  BOOLEAN                        CpuHealthy;
-} PEI_CPU_DATA;
-
-//
-// PEI CPU MP Data save in memory
-//
-struct _PEI_CPU_MP_DATA {
-  UINT32                         CpuCount;
-  UINT32                         BspNumber;
-  UINTN                          Buffer;
-  UINTN                          CpuApStackSize;
-  MP_ASSEMBLY_ADDRESS_MAP        AddressMap;
-  UINTN                          WakeupBuffer;
-  UINTN                          BackupBuffer;
-  UINTN                          BackupBufferSize;
-  UINTN                          ApFunction;
-  UINTN                          ApFunctionArgument;
-  volatile UINT32                FinishedCount;
-  BOOLEAN                        EndOfPeiFlag;
-  BOOLEAN                        InitFlag;
-  CPU_EXCHANGE_ROLE_INFO         BSPInfo;
-  CPU_EXCHANGE_ROLE_INFO         APInfo;
-  MTRR_SETTINGS                  MtrrTable;
-  PEI_CPU_DATA                   *CpuData;
-  volatile MP_CPU_EXCHANGE_INFO  *MpCpuExchangeInfo;
-};
-extern EFI_PEI_PPI_DESCRIPTOR   mPeiCpuMpPpiDesc;
-
-
-/**
-  Assembly code to get starting address and size of the rendezvous entry for 
APs.
-  Information for fixing a jump instruction in the code is also returned.
-
-  @param AddressMap  Output buffer for address map information.
-**/
-VOID
-EFIAPI
-AsmGetAddressMap (
-  OUT MP_ASSEMBLY_ADDRESS_MAP    *AddressMap
-  );
-
-/**
-  Assembly code to load GDT table and update segment accordingly.
-
-  @param Gdtr   Pointer to GDT descriptor
-**/
-VOID
-EFIAPI
-AsmInitializeGdt (
-  IN IA32_DESCRIPTOR  *Gdtr
-  );
-
-/**
-  Assembly code to do CLI-HALT loop.
-
-**/
-VOID
-EFIAPI
-AsmCliHltLoop (
-  VOID
-  );
-
-/**
-  Get available system memory below 1MB by specified size.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-**/
-VOID
-BackupAndPrepareWakeupBuffer(
-  IN PEI_CPU_MP_DATA         *PeiCpuMpData
-  );
-
-/**
-  Restore wakeup buffer data.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-**/
-VOID
-RestoreWakeupBuffer(
-  IN PEI_CPU_MP_DATA         *PeiCpuMpData
-  );
-
-/**
-  Notify function on End Of Pei PPI.
-
-  On S3 boot, this function will restore wakeup buffer data.
-  On normal boot, this function will flag wakeup buffer to be un-used type.
-
-  @param  PeiServices        The pointer to the PEI Services Table.
-  @param  NotifyDescriptor   Address of the notification descriptor data 
structure.
-  @param  Ppi                Address of the PPI that was installed.
-
-  @retval EFI_SUCCESS        When everything is OK.
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMpEndOfPeiCallback (
-  IN      EFI_PEI_SERVICES        **PeiServices,
-  IN EFI_PEI_NOTIFY_DESCRIPTOR    *NotifyDescriptor,
-  IN VOID                         *Ppi
-  );
-
-/**
-  This function will be called by BSP to wakeup AP.
-
-  @param PeiCpuMpData       Pointer to PEI CPU MP Data
-  @param Broadcast          TRUE:  Send broadcast IPI to all APs
-                            FALSE: Send IPI to AP by ApicId
-  @param ApicId             Apic ID for the processor to be waked
-  @param Procedure          The function to be invoked by AP
-  @param ProcedureArgument  The argument to be passed into AP function
-**/
-VOID
-WakeUpAP (
-  IN PEI_CPU_MP_DATA           *PeiCpuMpData,
-  IN BOOLEAN                   Broadcast,
-  IN UINT32                    ApicId,
-  IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL
-  IN VOID                      *ProcedureArgument      OPTIONAL
-  );
-
-/**
-  Get CPU MP Data pointer from the Guided HOB.
-
-  @return  Pointer to Pointer to PEI CPU MP Data
-**/
-PEI_CPU_MP_DATA *
-GetMpHobData (
-  VOID
-  );
-
-/**
-  Find the current Processor number by APIC ID.
-
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-  @param ProcessorNumber     Return the pocessor number found
-
-  @retval EFI_SUCCESS        ProcessorNumber is found and returned.
-  @retval EFI_NOT_FOUND      ProcessorNumber is not found.
-**/
-EFI_STATUS
-GetProcessorNumber (
-  IN PEI_CPU_MP_DATA         *PeiCpuMpData,
-  OUT UINTN                  *ProcessorNumber
-  );
-
-/**
-  Collects BIST data from PPI.
-
-  This function collects BIST data from Sec Platform Information2 PPI
-  or SEC Platform Information PPI.
-
-  @param PeiServices         Pointer to PEI Services Table
-  @param PeiCpuMpData        Pointer to PEI CPU MP Data
-
-**/
-VOID
-CollectBistDataFromPpi (
-  IN CONST EFI_PEI_SERVICES             **PeiServices,
-  IN PEI_CPU_MP_DATA                    *PeiCpuMpData
-  );
-
-/**
-  Implementation of the PlatformInformation2 service in 
EFI_SEC_PLATFORM_INFORMATION2_PPI.
-
-  @param  PeiServices                The pointer to the PEI Services Table.
-  @param  StructureSize              The pointer to the variable describing 
size of the input buffer.
-  @param  PlatformInformationRecord2 The pointer to the 
EFI_SEC_PLATFORM_INFORMATION_RECORD2.
-
-  @retval EFI_SUCCESS                The data was successfully returned.
-  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current 
buffer size needed to
-                                     hold the record is returned in 
StructureSize.
-
-**/
-EFI_STATUS
-EFIAPI
-SecPlatformInformation2 (
-  IN CONST EFI_PEI_SERVICES                   **PeiServices,
-  IN OUT UINT64                               *StructureSize,
-     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
-  );
-
-#endif
+/** @file
+  Definitions to install Multiple Processor PPI.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _CPU_MP_PEI_H_
+#define _CPU_MP_PEI_H_
+
+#include <PiPei.h>
+
+#include <Ppi/MpServices.h>
+#include <Ppi/SecPlatformInformation.h>
+#include <Ppi/SecPlatformInformation2.h>
+#include <Ppi/EndOfPeiPhase.h>
+
+#include <Register/LocalApic.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/LocalApicLib.h>
+#include <Library/MtrrLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PeimEntryPoint.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/SynchronizationLib.h>
+#include <Library/TimerLib.h>
+#include <Library/UefiCpuLib.h>
+
+#include "Microcode.h"
+
+//
+// AP state
+//
+typedef enum {
+  CpuStateIdle,
+  CpuStateBusy,
+  CpuStateDisabled
+} CPU_STATE;
+
+//
+// AP reset code information
+//
+typedef struct {
+  UINT8             *RendezvousFunnelAddress;
+  UINTN             PModeEntryOffset;
+  UINTN             LModeEntryOffset;
+  UINTN             RendezvousFunnelSize;
+} MP_ASSEMBLY_ADDRESS_MAP;
+
+//
+// CPU exchange information for switch BSP
+//
+typedef struct {
+  UINT8             State;        // offset 0
+  UINTN             StackPointer; // offset 4 / 8
+  IA32_DESCRIPTOR   Gdtr;         // offset 8 / 16
+  IA32_DESCRIPTOR   Idtr;         // offset 14 / 26
+} CPU_EXCHANGE_ROLE_INFO;
+
+typedef struct _PEI_CPU_MP_DATA  PEI_CPU_MP_DATA;
+
+#pragma pack()
+
+typedef union {
+  struct {
+    UINT32  LimitLow    : 16;
+    UINT32  BaseLow     : 16;
+    UINT32  BaseMid     : 8;
+    UINT32  Type        : 4;
+    UINT32  System      : 1;
+    UINT32  Dpl         : 2;
+    UINT32  Present     : 1;
+    UINT32  LimitHigh   : 4;
+    UINT32  Software    : 1;
+    UINT32  Reserved    : 1;
+    UINT32  DefaultSize : 1;
+    UINT32  Granularity : 1;
+    UINT32  BaseHigh    : 8;
+  } Bits;
+  UINT64  Uint64;
+} IA32_GDT;
+
+//
+// MP CPU exchange information for AP reset code
+//
+typedef struct {
+  UINTN                 Lock;
+  UINTN                 StackStart;
+  UINTN                 StackSize;
+  UINTN                 CFunction;
+  IA32_DESCRIPTOR       GdtrProfile;
+  IA32_DESCRIPTOR       IdtrProfile;
+  UINTN                 BufferStart;
+  UINTN                 PmodeOffset;
+  UINTN                 NumApsExecuting;
+  UINTN                 LmodeOffset;
+  UINTN                 Cr3;
+  PEI_CPU_MP_DATA       *PeiCpuMpData;
+} MP_CPU_EXCHANGE_INFO;
+
+#pragma pack()
+
+typedef struct {
+  UINT32                         ApicId;
+  EFI_HEALTH_FLAGS               Health;
+  CPU_STATE                      State;
+  BOOLEAN                        CpuHealthy;
+} PEI_CPU_DATA;
+
+//
+// PEI CPU MP Data save in memory
+//
+struct _PEI_CPU_MP_DATA {
+  UINT32                         CpuCount;
+  UINT32                         BspNumber;
+  UINTN                          Buffer;
+  UINTN                          CpuApStackSize;
+  MP_ASSEMBLY_ADDRESS_MAP        AddressMap;
+  UINTN                          WakeupBuffer;
+  UINTN                          BackupBuffer;
+  UINTN                          BackupBufferSize;
+  UINTN                          ApFunction;
+  UINTN                          ApFunctionArgument;
+  volatile UINT32                FinishedCount;
+  BOOLEAN                        EndOfPeiFlag;
+  BOOLEAN                        InitFlag;
+  CPU_EXCHANGE_ROLE_INFO         BSPInfo;
+  CPU_EXCHANGE_ROLE_INFO         APInfo;
+  MTRR_SETTINGS                  MtrrTable;
+  PEI_CPU_DATA                   *CpuData;
+  volatile MP_CPU_EXCHANGE_INFO  *MpCpuExchangeInfo;
+};
+extern EFI_PEI_PPI_DESCRIPTOR   mPeiCpuMpPpiDesc;
+
+
+/**
+  Assembly code to get starting address and size of the rendezvous entry for 
APs.
+  Information for fixing a jump instruction in the code is also returned.
+
+  @param AddressMap  Output buffer for address map information.
+**/
+VOID
+EFIAPI
+AsmGetAddressMap (
+  OUT MP_ASSEMBLY_ADDRESS_MAP    *AddressMap
+  );
+
+/**
+  Assembly code to load GDT table and update segment accordingly.
+
+  @param Gdtr   Pointer to GDT descriptor
+**/
+VOID
+EFIAPI
+AsmInitializeGdt (
+  IN IA32_DESCRIPTOR  *Gdtr
+  );
+
+/**
+  Assembly code to do CLI-HALT loop.
+
+**/
+VOID
+EFIAPI
+AsmCliHltLoop (
+  VOID
+  );
+
+/**
+  Get available system memory below 1MB by specified size.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+**/
+VOID
+BackupAndPrepareWakeupBuffer(
+  IN PEI_CPU_MP_DATA         *PeiCpuMpData
+  );
+
+/**
+  Restore wakeup buffer data.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+**/
+VOID
+RestoreWakeupBuffer(
+  IN PEI_CPU_MP_DATA         *PeiCpuMpData
+  );
+
+/**
+  Notify function on End Of Pei PPI.
+
+  On S3 boot, this function will restore wakeup buffer data.
+  On normal boot, this function will flag wakeup buffer to be un-used type.
+
+  @param  PeiServices        The pointer to the PEI Services Table.
+  @param  NotifyDescriptor   Address of the notification descriptor data 
structure.
+  @param  Ppi                Address of the PPI that was installed.
+
+  @retval EFI_SUCCESS        When everything is OK.
+
+**/
+EFI_STATUS
+EFIAPI
+CpuMpEndOfPeiCallback (
+  IN      EFI_PEI_SERVICES        **PeiServices,
+  IN EFI_PEI_NOTIFY_DESCRIPTOR    *NotifyDescriptor,
+  IN VOID                         *Ppi
+  );
+
+/**
+  This function will be called by BSP to wakeup AP.
+
+  @param PeiCpuMpData       Pointer to PEI CPU MP Data
+  @param Broadcast          TRUE:  Send broadcast IPI to all APs
+                            FALSE: Send IPI to AP by ApicId
+  @param ApicId             Apic ID for the processor to be waked
+  @param Procedure          The function to be invoked by AP
+  @param ProcedureArgument  The argument to be passed into AP function
+**/
+VOID
+WakeUpAP (
+  IN PEI_CPU_MP_DATA           *PeiCpuMpData,
+  IN BOOLEAN                   Broadcast,
+  IN UINT32                    ApicId,
+  IN EFI_AP_PROCEDURE          Procedure,              OPTIONAL
+  IN VOID                      *ProcedureArgument      OPTIONAL
+  );
+
+/**
+  Get CPU MP Data pointer from the Guided HOB.
+
+  @return  Pointer to Pointer to PEI CPU MP Data
+**/
+PEI_CPU_MP_DATA *
+GetMpHobData (
+  VOID
+  );
+
+/**
+  Find the current Processor number by APIC ID.
+
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+  @param ProcessorNumber     Return the pocessor number found
+
+  @retval EFI_SUCCESS        ProcessorNumber is found and returned.
+  @retval EFI_NOT_FOUND      ProcessorNumber is not found.
+**/
+EFI_STATUS
+GetProcessorNumber (
+  IN PEI_CPU_MP_DATA         *PeiCpuMpData,
+  OUT UINTN                  *ProcessorNumber
+  );
+
+/**
+  Collects BIST data from PPI.
+
+  This function collects BIST data from Sec Platform Information2 PPI
+  or SEC Platform Information PPI.
+
+  @param PeiServices         Pointer to PEI Services Table
+  @param PeiCpuMpData        Pointer to PEI CPU MP Data
+
+**/
+VOID
+CollectBistDataFromPpi (
+  IN CONST EFI_PEI_SERVICES             **PeiServices,
+  IN PEI_CPU_MP_DATA                    *PeiCpuMpData
+  );
+
+/**
+  Implementation of the PlatformInformation2 service in 
EFI_SEC_PLATFORM_INFORMATION2_PPI.
+
+  @param  PeiServices                The pointer to the PEI Services Table.
+  @param  StructureSize              The pointer to the variable describing 
size of the input buffer.
+  @param  PlatformInformationRecord2 The pointer to the 
EFI_SEC_PLATFORM_INFORMATION_RECORD2.
+
+  @retval EFI_SUCCESS                The data was successfully returned.
+  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current 
buffer size needed to
+                                     hold the record is returned in 
StructureSize.
+
+**/
+EFI_STATUS
+EFIAPI
+SecPlatformInformation2 (
+  IN CONST EFI_PEI_SERVICES                   **PeiServices,
+  IN OUT UINT64                               *StructureSize,
+     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
+  );
+
+#endif

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.inf 2015-08-06 05:45:32 UTC (rev 
18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/CpuMpPei.inf 2015-08-06 06:57:47 UTC (rev 
18168)
@@ -1,90 +1,90 @@
-## @file
-#  CPU driver installs CPU PI Multi-processor PPI.
-#
-#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD 
License
-#  which accompanies this distribution.  The full text of the license may be 
found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
-#
-##
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = CpuMpPei
-  MODULE_UNI_FILE                = CpuMpPei.uni
-  FILE_GUID                      = EDADEB9D-DDBA-48BD-9D22-C1C169C8C5C6
-  MODULE_TYPE                    = PEIM
-  VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = CpuMpPeimInit
-
-#
-# The following information is for reference only and not required by the 
build tools.
-#
-#  VALID_ARCHITECTURES           = IA32 X64
-#
-
-[Sources]
-  CpuMpPei.h
-  CpuMpPei.c
-  CpuBist.c
-  Microcode.h
-  Microcode.c
-  PeiMpServices.h
-  PeiMpServices.c
-
-[Sources.IA32]
-  Ia32/MpEqu.inc
-  Ia32/MpFuncs.asm  | MSFT
-  Ia32/MpFuncs.asm  | INTEL
-  Ia32/MpFuncs.nasm | GCC
-
-[Sources.X64]
-  X64/MpEqu.inc
-  X64/MpFuncs.asm  | MSFT
-  X64/MpFuncs.asm  | INTEL
-  X64/MpFuncs.nasm | GCC
-
-[Packages]
-  MdePkg/MdePkg.dec
-  UefiCpuPkg/UefiCpuPkg.dec
-
-[LibraryClasses]
-  BaseLib
-  BaseMemoryLib
-  DebugLib
-  HobLib
-  LocalApicLib
-  MtrrLib
-  PcdLib
-  PeimEntryPoint
-  PeiServicesLib
-  ReportStatusCodeLib
-  SynchronizationLib
-  TimerLib
-  UefiCpuLib
-
-[Ppis]
-  gEfiPeiMpServicesPpiGuid                      ## PRODUCES
-  gEfiEndOfPeiSignalPpiGuid                     ## NOTIFY
-  gEfiSecPlatformInformationPpiGuid             ## SOMETIMES_CONSUMES
-  ## SOMETIMES_CONSUMES
-  ## SOMETIMES_PRODUCES
-  gEfiSecPlatformInformation2PpiGuid
-
-[Pcd]
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber        ## CONSUMES
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds      ## CONSUMES
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize                      ## CONSUMES
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress            ## CONSUMES
-  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize         ## CONSUMES
-
-[Depex]
-  gEfiPeiMemoryDiscoveredPpiGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
-  CpuMpPeiExtra.uni
-
+## @file
+#  CPU driver installs CPU PI Multi-processor PPI.
+#
+#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD 
License
+#  which accompanies this distribution.  The full text of the license may be 
found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = CpuMpPei
+  MODULE_UNI_FILE                = CpuMpPei.uni
+  FILE_GUID                      = EDADEB9D-DDBA-48BD-9D22-C1C169C8C5C6
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = CpuMpPeimInit
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64
+#
+
+[Sources]
+  CpuMpPei.h
+  CpuMpPei.c
+  CpuBist.c
+  Microcode.h
+  Microcode.c
+  PeiMpServices.h
+  PeiMpServices.c
+
+[Sources.IA32]
+  Ia32/MpEqu.inc
+  Ia32/MpFuncs.asm  | MSFT
+  Ia32/MpFuncs.asm  | INTEL
+  Ia32/MpFuncs.nasm | GCC
+
+[Sources.X64]
+  X64/MpEqu.inc
+  X64/MpFuncs.asm  | MSFT
+  X64/MpFuncs.asm  | INTEL
+  X64/MpFuncs.nasm | GCC
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  DebugLib
+  HobLib
+  LocalApicLib
+  MtrrLib
+  PcdLib
+  PeimEntryPoint
+  PeiServicesLib
+  ReportStatusCodeLib
+  SynchronizationLib
+  TimerLib
+  UefiCpuLib
+
+[Ppis]
+  gEfiPeiMpServicesPpiGuid                      ## PRODUCES
+  gEfiEndOfPeiSignalPpiGuid                     ## NOTIFY
+  gEfiSecPlatformInformationPpiGuid             ## SOMETIMES_CONSUMES
+  ## SOMETIMES_CONSUMES
+  ## SOMETIMES_PRODUCES
+  gEfiSecPlatformInformation2PpiGuid
+
+[Pcd]
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber        ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds      ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize                      ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress            ## CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize         ## CONSUMES
+
+[Depex]
+  gEfiPeiMemoryDiscoveredPpiGuid
+
+[UserExtensions.TianoCore."ExtraFiles"]
+  CpuMpPeiExtra.uni
+

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc       2015-08-06 05:45:32 UTC 
(rev 18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpEqu.inc       2015-08-06 06:57:47 UTC 
(rev 18168)
@@ -1,40 +1,40 @@
-;------------------------------------------------------------------------------
 ;
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-; This program and the accompanying materials
-; are licensed and made available under the terms and conditions of the BSD 
License
-; which accompanies this distribution.  The full text of the license may be 
found at
-; http://opensource.org/licenses/bsd-license.php.
-;
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;
-; Module Name:
-;
-;   MpEqu.inc
-;
-; Abstract:
-;
-;   This is the equates file for Multiple Processor support
-;
-;-------------------------------------------------------------------------------
-
-PROTECT_MODE_CS               equ        10h
-PROTECT_MODE_DS               equ        18h
-
-VacantFlag                    equ        00h
-NotVacantFlag                 equ        0ffh
-
-CPU_SWITCH_STATE_IDLE         equ        0
-CPU_SWITCH_STATE_STORED       equ        1
-CPU_SWITCH_STATE_LOADED       equ        2
-
-LockLocation                  equ        (RendezvousFunnelProcEnd - 
RendezvousFunnelProcStart)
-StackStartAddressLocation     equ        LockLocation + 04h
-StackSizeLocation             equ        LockLocation + 08h
-ApProcedureLocation           equ        LockLocation + 0Ch
-GdtrLocation                  equ        LockLocation + 10h
-IdtrLocation                  equ        LockLocation + 16h
-BufferStartLocation           equ        LockLocation + 1Ch
-PmodeOffsetLocation           equ        LockLocation + 20h
-NumApsExecutingLoction        equ        LockLocation + 24h
-
+;------------------------------------------------------------------------------
 ;
+; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD 
License
+; which accompanies this distribution.  The full text of the license may be 
found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   MpEqu.inc
+;
+; Abstract:
+;
+;   This is the equates file for Multiple Processor support
+;
+;-------------------------------------------------------------------------------
+
+PROTECT_MODE_CS               equ        10h
+PROTECT_MODE_DS               equ        18h
+
+VacantFlag                    equ        00h
+NotVacantFlag                 equ        0ffh
+
+CPU_SWITCH_STATE_IDLE         equ        0
+CPU_SWITCH_STATE_STORED       equ        1
+CPU_SWITCH_STATE_LOADED       equ        2
+
+LockLocation                  equ        (RendezvousFunnelProcEnd - 
RendezvousFunnelProcStart)
+StackStartAddressLocation     equ        LockLocation + 04h
+StackSizeLocation             equ        LockLocation + 08h
+ApProcedureLocation           equ        LockLocation + 0Ch
+GdtrLocation                  equ        LockLocation + 10h
+IdtrLocation                  equ        LockLocation + 16h
+BufferStartLocation           equ        LockLocation + 1Ch
+PmodeOffsetLocation           equ        LockLocation + 20h
+NumApsExecutingLoction        equ        LockLocation + 24h
+

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm     2015-08-06 05:45:32 UTC 
(rev 18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.asm     2015-08-06 06:57:47 UTC 
(rev 18168)
@@ -1,276 +1,276 @@
-;------------------------------------------------------------------------------
 ;
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-; This program and the accompanying materials
-; are licensed and made available under the terms and conditions of the BSD 
License
-; which accompanies this distribution.  The full text of the license may be 
found at
-; http://opensource.org/licenses/bsd-license.php.
-;
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;
-; Module Name:
-;
-;   MpFuncs32.asm
-;
-; Abstract:
-;
-;   This is the assembly code for MP support
-;
-;-------------------------------------------------------------------------------
-
-.686p
-.model  flat
-
-include  MpEqu.inc
-InitializeFloatingPointUnits PROTO C
-
-.code
-
-;-------------------------------------------------------------------------------------
-;RendezvousFunnelProc  procedure follows. All APs execute their procedure. This
-;procedure serializes all the AP processors through an Init sequence. It must 
be
-;noted that APs arrive here very raw...ie: real mode, no stack.
-;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
-;IS IN MACHINE CODE.
-;-------------------------------------------------------------------------------------
-RendezvousFunnelProc   PROC  PUBLIC
-RendezvousFunnelProcStart::
-; At this point CS = 0x(vv00) and ip= 0x0.
-; Save BIST information to ebp firstly
-    db 66h,  08bh, 0e8h                 ; mov        ebp, eax    ; save BIST 
information
-
-    db 8ch,0c8h                         ; mov        ax,cs
-    db 8eh,0d8h                         ; mov        ds,ax
-    db 8eh,0c0h                         ; mov        es,ax
-    db 8eh,0d0h                         ; mov        ss,ax
-    db 33h,0c0h                         ; xor        ax,ax
-    db 8eh,0e0h                         ; mov        fs,ax
-    db 8eh,0e8h                         ; mov        gs,ax
-
-    db 0BEh                             ; opcode of mov si, mem16
-    dw BufferStartLocation              ; mov        si, BufferStartLocation
-    db 66h,  8Bh, 1Ch                   ; mov        ebx,dword ptr [si]
-
-    db 0BFh                             ; opcode of mov di, mem16
-    dw PmodeOffsetLocation              ; mov        di, PmodeOffsetLocation
-    db 66h,  8Bh, 05h                   ; mov        eax,dword ptr [di]
-    db 8Bh,  0F8h                       ; mov        di, ax
-    db 83h,  0EFh,06h                   ; sub        di, 06h
-    db 66h,  03h, 0C3h                  ; add        eax, ebx
-    db 66h,  89h, 05h                   ; mov        dword ptr [di],eax
-
-    db 0BEh                             ; opcode of mov si, mem16
-    dw GdtrLocation                     ; mov        si, GdtrLocation
-    db 66h                              ; db         66h
-    db 2Eh,  0Fh, 01h, 14h              ; lgdt       fword ptr cs:[si]
-
-    db 0BEh
-    dw IdtrLocation                     ; mov        si, IdtrLocation
-    db 66h                              ; db         66h
-    db 2Eh,0Fh, 01h, 1Ch                ; lidt       fword ptr cs:[si]
-
-    db 33h,  0C0h                       ; xor        ax,  ax
-    db 8Eh,  0D8h                       ; mov        ds,  ax
-
-    db 0Fh,  20h, 0C0h                  ; mov        eax, cr0            ;Get 
control register 0
-    db 66h,  83h, 0C8h, 03h             ; or         eax, 000000003h     ;Set 
PE bit (bit #0) & MP
-    db 0Fh,  22h, 0C0h                  ; mov        cr0, eax
-
-    db 66h,  67h, 0EAh                  ; far jump
-    dd 0h                               ; 32-bit offset
-    dw PROTECT_MODE_CS                  ; 16-bit selector
-
-Flat32Start::                           ; protected mode entry point
-    mov        ax, PROTECT_MODE_DS
-    mov        ds, ax
-    mov        es, ax
-    mov        fs, ax
-    mov        gs, ax
-    mov        ss, ax
-
-    mov        esi, ebx
-    mov        edi, esi
-    add        edi, LockLocation
-    mov        eax, NotVacantFlag
-
-TestLock:
-    xchg       dword ptr [edi], eax
-    cmp        eax, NotVacantFlag
-    jz         TestLock
-
-    mov        edi, esi
-    add        edi, NumApsExecutingLoction
-    inc        dword ptr [edi]
-    mov        ebx, dword ptr [edi]
-
-ProgramStack:
-    mov        edi, esi
-    add        edi, StackSizeLocation
-    mov        eax, dword ptr [edi]
-    mov        edi, esi
-    add        edi, StackStartAddressLocation
-    add        eax, dword ptr [edi]
-    mov        esp, eax
-    mov        dword ptr [edi], eax
-
-Releaselock:
-    mov        eax, VacantFlag
-    mov        edi, esi
-    add        edi, LockLocation
-    xchg       dword ptr [edi], eax
-
-CProcedureInvoke:
-    push       ebp               ; push BIST data at top of AP stack
-    xor        ebp, ebp          ; clear ebp for call stack trace
-    push       ebp
-    mov        ebp, esp
-
-    mov        eax, InitializeFloatingPointUnits
-    call       eax               ; Call assembly function to initialize FPU 
per UEFI spec
-
-    push       ebx               ; Push NumApsExecuting
-    mov        eax, esi
-    add        eax, LockLocation
-    push       eax               ; push address of exchange info data buffer
-
-    mov        edi, esi
-    add        edi, ApProcedureLocation
-    mov        eax, dword ptr [edi]
-
-    call       eax               ; invoke C function
-
-    jmp        $                  ; never reach here
-
-RendezvousFunnelProc   ENDP
-RendezvousFunnelProcEnd::
-
-AsmCliHltLoop PROC near C PUBLIC
-    cli
-    hlt
-    jmp        $-2
-AsmCliHltLoop ENDP
-
-;-------------------------------------------------------------------------------------
-;  AsmGetAddressMap (&AddressMap);
-;-------------------------------------------------------------------------------------
-AsmGetAddressMap   PROC  near C  PUBLIC
-    pushad
-    mov        ebp,esp
-
-    mov        ebx, dword ptr [ebp+24h]
-    mov        dword ptr [ebx], RendezvousFunnelProcStart
-    mov        dword ptr [ebx +  4h], Flat32Start - RendezvousFunnelProcStart
-    mov        dword ptr [ebx +  8h], 0
-    mov        dword ptr [ebx + 0ch], RendezvousFunnelProcEnd - 
RendezvousFunnelProcStart
-
-    popad
-    ret
-AsmGetAddressMap   ENDP
-
-PAUSE32   MACRO
-    DB      0F3h
-    DB      090h
-    ENDM
-
-;-------------------------------------------------------------------------------------
-;AsmExchangeRole procedure follows. This procedure executed by current BSP, 
that is
-;about to become an AP. It switches it'stack with the current AP.
-;AsmExchangeRole (IN   CPU_EXCHANGE_INFO    *MyInfo, IN   CPU_EXCHANGE_INFO    
*OthersInfo);
-;-------------------------------------------------------------------------------------
-AsmExchangeRole   PROC  near C  PUBLIC
-    ; DO NOT call other functions in this function, since 2 CPU may use 1 stack
-    ; at the same time. If 1 CPU try to call a function, stack will be 
corrupted.
-    pushad
-    mov        ebp,esp
-
-    ; esi contains MyInfo pointer
-    mov        esi, dword ptr [ebp+24h]
-
-    ; edi contains OthersInfo pointer
-    mov        edi, dword ptr [ebp+28h]
-
-    ;Store EFLAGS, GDTR and IDTR register to stack
-    pushfd
-    mov        eax, cr4
-    push       eax       ; push cr4 firstly
-    mov        eax, cr0
-    push       eax
-
-    sgdt       fword ptr [esi+8]
-    sidt       fword ptr [esi+14]
-
-    ; Store the its StackPointer
-    mov        dword ptr [esi+4],esp
-
-    ; update its switch state to STORED
-    mov        byte ptr [esi], CPU_SWITCH_STATE_STORED
-
-WaitForOtherStored:
-    ; wait until the other CPU finish storing its state
-    cmp        byte ptr [edi], CPU_SWITCH_STATE_STORED
-    jz         OtherStored
-    PAUSE32
-    jmp        WaitForOtherStored
-
-OtherStored:
-    ; Since another CPU already stored its state, load them
-    ; load GDTR value
-    lgdt       fword ptr [edi+8]
-
-    ; load IDTR value
-    lidt       fword ptr [edi+14]
-
-    ; load its future StackPointer
-    mov        esp, dword ptr [edi+4]
-
-    ; update the other CPU's switch state to LOADED
-    mov        byte ptr [edi], CPU_SWITCH_STATE_LOADED
-
-WaitForOtherLoaded:
-    ; wait until the other CPU finish loading new state,
-    ; otherwise the data in stack may corrupt
-    cmp        byte ptr [esi], CPU_SWITCH_STATE_LOADED
-    jz         OtherLoaded
-    PAUSE32
-    jmp        WaitForOtherLoaded
-
-OtherLoaded:
-    ; since the other CPU already get the data it want, leave this procedure
-    pop        eax
-    mov        cr0, eax
-    pop        eax
-    mov        cr4, eax
-    popfd
-
-    popad
-    ret
-AsmExchangeRole   ENDP
-
-AsmInitializeGdt   PROC  near C  PUBLIC
-  push         ebp
-  mov          ebp, esp
-  pushad
-  mov          edi, [ebp + 8]      ; Load GDT register
-
-  mov          ax,cs               ; Get the selector data from our code image
-  mov          es,ax
-  lgdt         FWORD PTR es:[edi]  ; and update the GDTR
-
-  push         PROTECT_MODE_CS
-  lea          eax, SetCodeSelectorFarJump
-  push         eax
-  retf
-SetCodeSelectorFarJump:
-  mov          ax, PROTECT_MODE_DS ; Update the Base for the new selectors, too
-  mov          ds, ax
-  mov          es, ax
-  mov          fs, ax
-  mov          gs, ax
-  mov          ss, ax
-
-  popad
-  pop          ebp
-  ret
-AsmInitializeGdt  ENDP
-
-END
+;------------------------------------------------------------------------------
 ;
+; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD 
License
+; which accompanies this distribution.  The full text of the license may be 
found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+;   MpFuncs32.asm
+;
+; Abstract:
+;
+;   This is the assembly code for MP support
+;
+;-------------------------------------------------------------------------------
+
+.686p
+.model  flat
+
+include  MpEqu.inc
+InitializeFloatingPointUnits PROTO C
+
+.code
+
+;-------------------------------------------------------------------------------------
+;RendezvousFunnelProc  procedure follows. All APs execute their procedure. This
+;procedure serializes all the AP processors through an Init sequence. It must 
be
+;noted that APs arrive here very raw...ie: real mode, no stack.
+;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC
+;IS IN MACHINE CODE.
+;-------------------------------------------------------------------------------------
+RendezvousFunnelProc   PROC  PUBLIC
+RendezvousFunnelProcStart::
+; At this point CS = 0x(vv00) and ip= 0x0.
+; Save BIST information to ebp firstly
+    db 66h,  08bh, 0e8h                 ; mov        ebp, eax    ; save BIST 
information
+
+    db 8ch,0c8h                         ; mov        ax,cs
+    db 8eh,0d8h                         ; mov        ds,ax
+    db 8eh,0c0h                         ; mov        es,ax
+    db 8eh,0d0h                         ; mov        ss,ax
+    db 33h,0c0h                         ; xor        ax,ax
+    db 8eh,0e0h                         ; mov        fs,ax
+    db 8eh,0e8h                         ; mov        gs,ax
+
+    db 0BEh                             ; opcode of mov si, mem16
+    dw BufferStartLocation              ; mov        si, BufferStartLocation
+    db 66h,  8Bh, 1Ch                   ; mov        ebx,dword ptr [si]
+
+    db 0BFh                             ; opcode of mov di, mem16
+    dw PmodeOffsetLocation              ; mov        di, PmodeOffsetLocation
+    db 66h,  8Bh, 05h                   ; mov        eax,dword ptr [di]
+    db 8Bh,  0F8h                       ; mov        di, ax
+    db 83h,  0EFh,06h                   ; sub        di, 06h
+    db 66h,  03h, 0C3h                  ; add        eax, ebx
+    db 66h,  89h, 05h                   ; mov        dword ptr [di],eax
+
+    db 0BEh                             ; opcode of mov si, mem16
+    dw GdtrLocation                     ; mov        si, GdtrLocation
+    db 66h                              ; db         66h
+    db 2Eh,  0Fh, 01h, 14h              ; lgdt       fword ptr cs:[si]
+
+    db 0BEh
+    dw IdtrLocation                     ; mov        si, IdtrLocation
+    db 66h                              ; db         66h
+    db 2Eh,0Fh, 01h, 1Ch                ; lidt       fword ptr cs:[si]
+
+    db 33h,  0C0h                       ; xor        ax,  ax
+    db 8Eh,  0D8h                       ; mov        ds,  ax
+
+    db 0Fh,  20h, 0C0h                  ; mov        eax, cr0            ;Get 
control register 0
+    db 66h,  83h, 0C8h, 03h             ; or         eax, 000000003h     ;Set 
PE bit (bit #0) & MP
+    db 0Fh,  22h, 0C0h                  ; mov        cr0, eax
+
+    db 66h,  67h, 0EAh                  ; far jump
+    dd 0h                               ; 32-bit offset
+    dw PROTECT_MODE_CS                  ; 16-bit selector
+
+Flat32Start::                           ; protected mode entry point
+    mov        ax, PROTECT_MODE_DS
+    mov        ds, ax
+    mov        es, ax
+    mov        fs, ax
+    mov        gs, ax
+    mov        ss, ax
+
+    mov        esi, ebx
+    mov        edi, esi
+    add        edi, LockLocation
+    mov        eax, NotVacantFlag
+
+TestLock:
+    xchg       dword ptr [edi], eax
+    cmp        eax, NotVacantFlag
+    jz         TestLock
+
+    mov        edi, esi
+    add        edi, NumApsExecutingLoction
+    inc        dword ptr [edi]
+    mov        ebx, dword ptr [edi]
+
+ProgramStack:
+    mov        edi, esi
+    add        edi, StackSizeLocation
+    mov        eax, dword ptr [edi]
+    mov        edi, esi
+    add        edi, StackStartAddressLocation
+    add        eax, dword ptr [edi]
+    mov        esp, eax
+    mov        dword ptr [edi], eax
+
+Releaselock:
+    mov        eax, VacantFlag
+    mov        edi, esi
+    add        edi, LockLocation
+    xchg       dword ptr [edi], eax
+
+CProcedureInvoke:
+    push       ebp               ; push BIST data at top of AP stack
+    xor        ebp, ebp          ; clear ebp for call stack trace
+    push       ebp
+    mov        ebp, esp
+
+    mov        eax, InitializeFloatingPointUnits
+    call       eax               ; Call assembly function to initialize FPU 
per UEFI spec
+
+    push       ebx               ; Push NumApsExecuting
+    mov        eax, esi
+    add        eax, LockLocation
+    push       eax               ; push address of exchange info data buffer
+
+    mov        edi, esi
+    add        edi, ApProcedureLocation
+    mov        eax, dword ptr [edi]
+
+    call       eax               ; invoke C function
+
+    jmp        $                  ; never reach here
+
+RendezvousFunnelProc   ENDP
+RendezvousFunnelProcEnd::
+
+AsmCliHltLoop PROC near C PUBLIC
+    cli
+    hlt
+    jmp        $-2
+AsmCliHltLoop ENDP
+
+;-------------------------------------------------------------------------------------
+;  AsmGetAddressMap (&AddressMap);
+;-------------------------------------------------------------------------------------
+AsmGetAddressMap   PROC  near C  PUBLIC
+    pushad
+    mov        ebp,esp
+
+    mov        ebx, dword ptr [ebp+24h]
+    mov        dword ptr [ebx], RendezvousFunnelProcStart
+    mov        dword ptr [ebx +  4h], Flat32Start - RendezvousFunnelProcStart
+    mov        dword ptr [ebx +  8h], 0
+    mov        dword ptr [ebx + 0ch], RendezvousFunnelProcEnd - 
RendezvousFunnelProcStart
+
+    popad
+    ret
+AsmGetAddressMap   ENDP
+
+PAUSE32   MACRO
+    DB      0F3h
+    DB      090h
+    ENDM
+
+;-------------------------------------------------------------------------------------
+;AsmExchangeRole procedure follows. This procedure executed by current BSP, 
that is
+;about to become an AP. It switches it'stack with the current AP.
+;AsmExchangeRole (IN   CPU_EXCHANGE_INFO    *MyInfo, IN   CPU_EXCHANGE_INFO    
*OthersInfo);
+;-------------------------------------------------------------------------------------
+AsmExchangeRole   PROC  near C  PUBLIC
+    ; DO NOT call other functions in this function, since 2 CPU may use 1 stack
+    ; at the same time. If 1 CPU try to call a function, stack will be 
corrupted.
+    pushad
+    mov        ebp,esp
+
+    ; esi contains MyInfo pointer
+    mov        esi, dword ptr [ebp+24h]
+
+    ; edi contains OthersInfo pointer
+    mov        edi, dword ptr [ebp+28h]
+
+    ;Store EFLAGS, GDTR and IDTR register to stack
+    pushfd
+    mov        eax, cr4
+    push       eax       ; push cr4 firstly
+    mov        eax, cr0
+    push       eax
+
+    sgdt       fword ptr [esi+8]
+    sidt       fword ptr [esi+14]
+
+    ; Store the its StackPointer
+    mov        dword ptr [esi+4],esp
+
+    ; update its switch state to STORED
+    mov        byte ptr [esi], CPU_SWITCH_STATE_STORED
+
+WaitForOtherStored:
+    ; wait until the other CPU finish storing its state
+    cmp        byte ptr [edi], CPU_SWITCH_STATE_STORED
+    jz         OtherStored
+    PAUSE32
+    jmp        WaitForOtherStored
+
+OtherStored:
+    ; Since another CPU already stored its state, load them
+    ; load GDTR value
+    lgdt       fword ptr [edi+8]
+
+    ; load IDTR value
+    lidt       fword ptr [edi+14]
+
+    ; load its future StackPointer
+    mov        esp, dword ptr [edi+4]
+
+    ; update the other CPU's switch state to LOADED
+    mov        byte ptr [edi], CPU_SWITCH_STATE_LOADED
+
+WaitForOtherLoaded:
+    ; wait until the other CPU finish loading new state,
+    ; otherwise the data in stack may corrupt
+    cmp        byte ptr [esi], CPU_SWITCH_STATE_LOADED
+    jz         OtherLoaded
+    PAUSE32
+    jmp        WaitForOtherLoaded
+
+OtherLoaded:
+    ; since the other CPU already get the data it want, leave this procedure
+    pop        eax
+    mov        cr0, eax
+    pop        eax
+    mov        cr4, eax
+    popfd
+
+    popad
+    ret
+AsmExchangeRole   ENDP
+
+AsmInitializeGdt   PROC  near C  PUBLIC
+  push         ebp
+  mov          ebp, esp
+  pushad
+  mov          edi, [ebp + 8]      ; Load GDT register
+
+  mov          ax,cs               ; Get the selector data from our code image
+  mov          es,ax
+  lgdt         FWORD PTR es:[edi]  ; and update the GDTR
+
+  push         PROTECT_MODE_CS
+  lea          eax, SetCodeSelectorFarJump
+  push         eax
+  retf
+SetCodeSelectorFarJump:
+  mov          ax, PROTECT_MODE_DS ; Update the Base for the new selectors, too
+  mov          ds, ax
+  mov          es, ax
+  mov          fs, ax
+  mov          gs, ax
+  mov          ss, ax
+
+  popad
+  pop          ebp
+  ret
+AsmInitializeGdt  ENDP
+
+END

Modified: trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm
===================================================================
--- trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm    2015-08-06 05:45:32 UTC 
(rev 18167)
+++ trunk/edk2/UefiCpuPkg/CpuMpPei/Ia32/MpFuncs.nasm    2015-08-06 06:57:47 UTC 
(rev 18168)
@@ -1,255 +1,255 @@
-;------------------------------------------------------------------------------
 ;
-; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
-; This program and the accompanying materials
-; are licensed and made available under the terms and conditions of the BSD 
License
-; which accompanies this distribution.  The full text of the license may be 
found at
-; http://opensource.org/licenses/bsd-license.php.
-;
-; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-;
-; Module Name:
-;
-;   MpFuncs.nasm
-;
-; Abstract:
-;
-;   This is the assembly code for MP support
-;
-;-------------------------------------------------------------------------------
-
-%include "MpEqu.inc"
-extern ASM_PFX(InitializeFloatingPointUnits)
-
-SECTION .text
-
-;-------------------------------------------------------------------------------------

@@ Diff output truncated at 100000 characters. @@

------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to