summaryrefslogtreecommitdiff
path: root/Board/CPU/CpuS3Pei
diff options
context:
space:
mode:
authorraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
committerraywu <raywu0301@gmail.com>2018-06-15 00:00:50 +0800
commitb7c51c9cf4864df6aabb99a1ae843becd577237c (patch)
treeeebe9b0d0ca03062955223097e57da84dd618b9a /Board/CPU/CpuS3Pei
downloadzprj-b7c51c9cf4864df6aabb99a1ae843becd577237c.tar.xz
init. 1AQQW051HEADmaster
Diffstat (limited to 'Board/CPU/CpuS3Pei')
-rw-r--r--Board/CPU/CpuS3Pei/AmiCpuS3Pei.c192
-rw-r--r--Board/CPU/CpuS3Pei/AmiCpuS3Pei.cif11
-rw-r--r--Board/CPU/CpuS3Pei/AmiCpuS3Pei.dxs72
-rw-r--r--Board/CPU/CpuS3Pei/AmiCpuS3Pei.mak66
-rw-r--r--Board/CPU/CpuS3Pei/AmiCpuS3Pei.sdl71
5 files changed, 412 insertions, 0 deletions
diff --git a/Board/CPU/CpuS3Pei/AmiCpuS3Pei.c b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.c
new file mode 100644
index 0000000..d8ae4d4
--- /dev/null
+++ b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.c
@@ -0,0 +1,192 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1987-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.c 2 9/28/12 5:40a Davidhsieh $
+//
+// $Revision: 2 $
+//
+// $Date: 9/28/12 5:40a $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.c $
+//
+// 2 9/28/12 5:40a Davidhsieh
+// Wait APIC idle after sending SMM IPI
+//
+// 1 9/26/12 10:45a Davidhsieh
+//
+//**********************************************************************
+//<AMI_FHDR_START>
+//
+// Name: AmiCpuS3Pei.c
+//
+// Description:
+//
+//<AMI_FHDR_END>
+//**********************************************************************
+//
+#include <PEI.h>
+#include <AmiPeiLib.h>
+#include <AmiCspLib.h>
+#include <Ppi\Stall.h>
+#include <Ppi\ReadOnlyVariable.h>
+#include <Setup.h>
+#include <token.h>
+#include "Core/CPU/CPU.h"
+#include "Core/CPU/CpuCspLib.h"
+
+EFI_GUID gSmmHobGuid = SMM_HOB_GUID;
+EFI_GUID gPeiReadOnlyVariablePpiGuid = EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID;
+EFI_GUID gEfiPeiStallPpiGuid = EFI_PEI_STALL_PPI_GUID;
+EFI_GUID gMpCpuApicIdDataGuid = MP_CPU_APIC_ID_DATA_GUID;
+
+#define SMM_ASM_FIXUP_SMM_BASE 0x38002
+#define SMM_ASM_FIXUP_IED_ZERO_MEM 0x38029
+#define SMM_ASM_BASE_CHANGE_FLAG 0x3808f
+#define APIC_SMI (2 << 8)
+#define APIC_DELIVERY_STATUS (1 << 12)
+#define APIC_LEVEL_ASSERT (1 << 14)
+#define APIC_NO_SHORT_HAND (0 << 18)
+
+
+//<AMI_PHDR_START>
+//----------------------------------------------------------------------------
+//
+// Procedure: AmiCpuS3PeiEntry
+//
+// Description: PEI Entry Point for Intel TXT Driver.
+//
+// Input: EFI_HANDLE - ImageHandle
+// EFI_SYSTEM_TABLE* - SystemTable
+//
+// Output: None.
+//
+//----------------------------------------------------------------------------
+//<AMI_PHDR_END>
+EFI_STATUS
+AmiCpuS3PeiEntry (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+)
+{
+ EFI_STATUS Status;
+ EFI_BOOT_MODE BootMode;
+ VOID *FirstHob;
+ SMM_HOB *SmmHob;
+ EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
+ EFI_PEI_STALL_PPI *PeiStall;
+ MP_CPU_APICID_DATA MpCpuApicIdData;
+ UINTN VariableSize = sizeof(MP_CPU_APICID_DATA);
+ BOOLEAN ApicIdFromVariable = FALSE;
+ VOID *SaveBuffer;
+ UINT8 ApicId;
+ UINT8 i, j=0;
+
+ (*PeiServices)->GetBootMode(PeiServices, &BootMode);
+
+ if (BootMode != BOOT_ON_S3_RESUME)
+ return EFI_SUCCESS;
+
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices, &gPeiReadOnlyVariablePpiGuid, 0, NULL, &ReadOnlyVariable
+ );
+ ASSERT_PEI_ERROR(PeiServices, Status);
+
+ Status = (*PeiServices)->LocatePpi(
+ PeiServices, &gEfiPeiStallPpiGuid, 0, NULL, &PeiStall
+ );
+ ASSERT_PEI_ERROR(PeiServices, Status);
+
+ if(!EFI_ERROR(Status)){
+ Status = ReadOnlyVariable->GetVariable (
+ PeiServices,
+ L"CPUS3APICID",
+ &gMpCpuApicIdDataGuid,
+ NULL,
+ &VariableSize,
+ &MpCpuApicIdData
+ );
+ if(Status == EFI_SUCCESS)
+ ApicIdFromVariable = TRUE; //If CPU S3 APIC ID data found, use local data as CPU APIC ID
+ }
+
+ (*PeiServices)->GetHobList(PeiServices, &FirstHob);
+ SmmHob = (SMM_HOB*)FirstHob;
+ while (!EFI_ERROR(Status = FindNextHobByType(EFI_HOB_TYPE_GUID_EXTENSION, &SmmHob)))
+ {
+ if (guidcmp(&SmmHob->EfiHobGuidType.Name, &gSmmHobGuid) == 0)
+ break;
+ }
+
+ if (!EFI_ERROR(Status))
+ {
+ //Allocate memory for temporarly perserve the 3000:8000 data.
+ Status = (*PeiServices)->AllocatePool(
+ PeiServices,
+ SmmGetBaseSaveBufferSize(),
+ &SaveBuffer
+ );
+ ASSERT_PEI_ERROR(PeiServices, Status);
+
+ SmmSetupDefaultHandler(SaveBuffer, SmmHob);
+
+ for (i = 0; i < SmmHob->NumCpus; ++i)
+ {
+ *(UINT32*)SMM_ASM_FIXUP_SMM_BASE = (UINT32)SmmHob->SmmBase[i];
+ *(volatile UINT8*)SMM_ASM_BASE_CHANGE_FLAG = 0; //Initialize Flag
+
+ if (ApicIdFromVariable) ApicId = MpCpuApicIdData.ApicId[i];
+ else ApicId = j;
+
+ MemReadWrite32((UINT32*)(LOCAL_APIC_BASE + APIC_ICR_HIGH_REGISTER), ApicId << 24, 0x00ffffff);
+ MemReadWrite32((UINT32*)(LOCAL_APIC_BASE + APIC_ICR_LOW_REGISTER), APIC_NO_SHORT_HAND + APIC_LEVEL_ASSERT + APIC_SMI, 0);
+
+ while (!(*(volatile UINT8*)SMM_ASM_BASE_CHANGE_FLAG))
+ {
+ CPULib_Pause(); //Wait on Flag
+ }
+ ++*(UINT16*)SMM_ASM_FIXUP_IED_ZERO_MEM; //Only 0, for first thread to clear IED memory.
+ PeiStall->Stall(PeiServices, PeiStall, 50);
+ //Wait until IPI is Idle
+ while(
+ MemRead32((UINT32*)(LOCAL_APIC_BASE + APIC_ICR_LOW_REGISTER)) & APIC_DELIVERY_STATUS
+ );
+
+ if (!ApicIdFromVariable){
+ if (IsHtEnabled()) j++;
+ else j += 2;
+ }
+ }
+
+ SmmRemoveDefaultHandler(SaveBuffer);
+ }
+
+ return EFI_SUCCESS;
+}
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1987-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Board/CPU/CpuS3Pei/AmiCpuS3Pei.cif b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.cif
new file mode 100644
index 0000000..ae15fb7
--- /dev/null
+++ b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.cif
@@ -0,0 +1,11 @@
+<component>
+ name = "AMI CPU S3 Pei"
+ category = ModulePart
+ LocalRoot = "Board\Cpu\CpuS3Pei"
+ RefName = "AmiCpuS3Pei"
+[files]
+"AmiCpuS3Pei.sdl"
+"AmiCpuS3Pei.mak"
+"AmiCpuS3Pei.c"
+"AmiCpuS3Pei.dxs"
+<endComponent>
diff --git a/Board/CPU/CpuS3Pei/AmiCpuS3Pei.dxs b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.dxs
new file mode 100644
index 0000000..1f0b684
--- /dev/null
+++ b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.dxs
@@ -0,0 +1,72 @@
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1987-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
+
+//**********************************************************************
+// $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.dxs 1 9/26/12 10:45a Davidhsieh $
+//
+// $Revision: 1 $
+//
+// $Date: 9/26/12 10:45a $
+//**********************************************************************
+// Revision History
+// ----------------
+// $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.dxs $
+//
+// 1 9/26/12 10:45a Davidhsieh
+//
+// 1 2/07/12 3:58a Davidhsieh
+//
+//**********************************************************************
+
+//<AMI_FHDR_START>
+//---------------------------------------------------------------------------
+// Name: CPUPEI.dxs
+//
+// Description: Dependency expression for CPU PEI component.
+// Currently it is dependent on the CPU IO & PCI CFG PPI.
+//
+//---------------------------------------------------------------------------
+//<AMI_FHDR_END>
+
+#include <pei.h>
+#include <ppi\CpuIo.h>
+#include <ppi\PciCfg.h>
+#include <Ppi\ReadOnlyVariable.h>
+#define PEI_SMM_ACCESS_PPI_GUID \
+ { \
+ 0x268f33a9, 0xcccd, 0x48be, 0x88, 0x17, 0x86, 0x5, 0x3a, 0xc3, 0x2e, 0xd6 \
+ }
+
+DEPENDENCY_START
+ EFI_PEI_PERMANENT_MEMORY_INSTALLED_PPI AND
+ EFI_PEI_MASTER_BOOT_MODE_PEIM_PPI AND
+ EFI_PEI_CPU_IO_PPI_INSTALLED_GUID AND
+ EFI_PEI_PCI_CFG_PPI_INSTALLED_GUID AND
+ PEI_SMM_ACCESS_PPI_GUID AND
+ EFI_PEI_READ_ONLY_VARIABLE_PPI_GUID
+DEPENDENCY_END
+
+//*************************************************************************
+//*************************************************************************
+//** **
+//** (C)Copyright 1987-2013, American Megatrends, Inc. **
+//** **
+//** All Rights Reserved. **
+//** **
+//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+//** **
+//** Phone: (770)-246-8600 **
+//** **
+//*************************************************************************
+//*************************************************************************
diff --git a/Board/CPU/CpuS3Pei/AmiCpuS3Pei.mak b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.mak
new file mode 100644
index 0000000..d628aa4
--- /dev/null
+++ b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.mak
@@ -0,0 +1,66 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1987-2013, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.mak 1 9/26/12 10:45a Davidhsieh $
+#
+# $Revision: 1 $
+#
+# $Date: 9/26/12 10:45a $
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.mak $
+#
+# 1 9/26/12 10:45a Davidhsieh
+#
+#
+#**********************************************************************
+#**********************************************************************
+#<AMI_FHDR_START>
+#
+# Name: AmiCpuS3Pei.mak
+#
+# Description: Makefile for AmiCpuS3Pei module.
+#
+#<AMI_FHDR_END>
+#**********************************************************************
+
+all : AmiCpuS3Pei
+
+AmiCpuS3Pei: $(BUILD_DIR)\AmiCpuS3Pei.mak AmiCpuS3PeiBin
+
+$(BUILD_DIR)\AmiCpuS3Pei.mak : $(AmiCpuS3Pei_DIR)\$(@B).cif $(AmiCpuS3Pei_DIR)\$(@B).mak $(BUILD_RULES)
+ $(CIF2MAK) $(AmiCpuS3Pei_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS)
+
+AmiCpuS3PeiBin : $(AMIPEILIB) $(AMICSPLib)
+ $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\
+ /f $(BUILD_DIR)\AmiCpuS3Pei.mak all\
+ MAKEFILE=$(BUILD_DIR)\AmiCpuS3Pei.mak \
+ GUID=F7D22BCA-1BCA-5591-CC8B-1CA98F2890FE \
+ ENTRY_POINT=AmiCpuS3PeiEntry\
+ TYPE=PEIM \
+ COMPRESS=0
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1987-2013, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
diff --git a/Board/CPU/CpuS3Pei/AmiCpuS3Pei.sdl b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.sdl
new file mode 100644
index 0000000..32a8622
--- /dev/null
+++ b/Board/CPU/CpuS3Pei/AmiCpuS3Pei.sdl
@@ -0,0 +1,71 @@
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1987-2013, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************
+#**********************************************************************
+# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.sdl 3 10/01/12 2:16a Davidhsieh $
+#
+# $Revision: 3 $
+#
+# $Date: 10/01/12 2:16a $
+#**********************************************************************
+# Revision History
+# ----------------
+# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Haswell/AMI Cpu PKG/AMI CPU S3 Pei/AmiCpuS3Pei.sdl $
+#
+# 3 10/01/12 2:16a Davidhsieh
+#
+# 2 9/27/12 12:26a Davidhsieh
+#
+# 1 9/26/12 10:45a Davidhsieh
+#
+#**********************************************************************
+TOKEN
+ Name = "AMI_CPU_S3_PEI_SUPPORT"
+ Value = "1"
+ Help = "Main switch to enable AMI CPU S3 PEI support in Project"
+ TokenType = Boolean
+ TargetEQU = Yes
+ TargetMAK = Yes
+ TargetH = Yes
+ Master = Yes
+End
+
+PATH
+ Name = "AmiCpuS3Pei_DIR"
+End
+
+MODULE
+ Help = "Includes AmiCpuS3Pei.mak to Project"
+ File = "AmiCpuS3Pei.mak"
+End
+
+ELINK
+ Name = "$(BUILD_DIR)\AmiCpuS3Pei.ffs"
+ Parent = "FV_BB"
+ Help = "AMI CPU S3 PEI component"
+ InvokeOrder = AfterParent
+End
+
+#*************************************************************************
+#*************************************************************************
+#** **
+#** (C)Copyright 1987-2013, American Megatrends, Inc. **
+#** **
+#** All Rights Reserved. **
+#** **
+#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
+#** **
+#** Phone: (770)-246-8600 **
+#** **
+#*************************************************************************
+#*************************************************************************