diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /ReferenceCode/ME/Ptt/Smm | |
download | zprj-master.tar.xz |
Diffstat (limited to 'ReferenceCode/ME/Ptt/Smm')
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/Ftpm.asl | 447 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.c | 847 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.cif | 13 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.dxs | 48 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.h | 158 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.inf | 106 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.mak | 69 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttHciSmm.sdl | 32 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttSmm.cif | 9 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.cif | 12 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.mak | 44 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.sdl | 33 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTableStorage.h | 31 | ||||
-rw-r--r-- | ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTables.inf | 38 |
14 files changed, 1887 insertions, 0 deletions
diff --git a/ReferenceCode/ME/Ptt/Smm/Ftpm.asl b/ReferenceCode/ME/Ptt/Smm/Ftpm.asl new file mode 100644 index 0000000..234bb42 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/Ftpm.asl @@ -0,0 +1,447 @@ +/**************************************************************************; +;* *; +;* Intel Confidential *; +;* *; +;* Intel Corporation - ACPI Reference Code for the Haswell *; +;* Family of Customer Reference Boards. *; +;* *; +;* *; +;* Copyright (c) 2012 Intel Corporation. All rights reserved *; +;* This software and associated documentation (if any) is furnished *; +;* under a license and may only be used or copied in accordance *; +;* with the terms of the license. Except as permitted by such *; +;* license, no part of this software or documentation may be *; +;* reproduced, stored in a retrieval system, or transmitted in any *; +;* form or by any means without the express written consent of *; +;* Intel Corporation. *; +;* *; +;* *; +;**************************************************************************/ +/*++ + This file contains an 'Intel Peripheral Driver' and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement +--*/ +/** @file + The TPM2 definition block in ACPI table for TrEE physical presence + and MemoryClear. +**/ + +DefinitionBlock ( + "Tpm.aml", + "SSDT", + 1, + "Intel_", + "Tpm2Tabl", + 0x1000 + ) +{ + External(PTTS) // PTT Solution Method Selection + External(PTTB) // PTT Buffer Address + + Scope (\_SB) + { + Device (TPM) + { + // + // Define _HID, "PNP0C31" is defined in + // "Secure Startup-FVE and TPM Admin BIOS and Platform Requirements" + // + Name (_HID, "MSFT0101") + + // + // Readable name of this device, don't know if this way is correct yet + // + Name (_STR, Unicode ("TPM 2.0 Device")) + + // + // Return the resource consumed by TPM device + // + Name (CRS, ResourceTemplate () { + Memory32Fixed (ReadOnly, 0xFED70000, 0x1000,PCRS) + }) + + + Method(_CRS,0) + { + CreateDWordField (CRS, \_SB.TPM.PCRS._BAS, CBAS) + Store (PTTB, CBAS) + Return(CRS) + } + + // + // Operational region for Smi port access + // + OperationRegion (SMIP, SystemIO, 0xB2, 1) + Field (SMIP, ByteAcc, NoLock, Preserve) + { + IOB2, 8 + } + + OperationRegion (FHCI, SystemMemory, 0xFED70000, 0x1000) + Field (FHCI, AnyAcc, NoLock, Preserve) + { + Offset(0x04), + HERR, 32, + Offset (0x40), + HCMD, 32, + Offset(0x44), + HSTS, 32, + } + // + // Operational region for TPM support, TPM Physical Presence and TPM Memory Clear + // Region Offset 0xFFFF0000 and Length 0xF0 will be fixed in C code. + // + OperationRegion (TNVS, SystemMemory, 0xFFFF0000, 0xF0) + Field (TNVS, AnyAcc, NoLock, Preserve) + { + PPIN, 8, // Software SMI for Physical Presence Interface + PPIP, 32, // Used for save physical presence paramter + PPRP, 32, // Physical Presence request operation response + PPRQ, 32, // Physical Presence request operation + LPPR, 32, // Last Physical Presence request operation + FRET, 32, // Physical Presence function return code + MCIN, 8, // Software SMI for Memory Clear Interface + MCIP, 32, // Used for save the Mor paramter + MORD, 32, // Memory Overwrite Request Data + MRET, 32 // Memory Overwrite function return code + } + + Method (PTS, 1, Serialized) + { + // + // Detect Sx state for MOR, only S4, S5 need to handle + // + If (LAnd (LLess (Arg0, 6), LGreater (Arg0, 3))) + { + // + // Bit4 -- DisableAutoDetect. 0 -- Firmware MAY autodetect. + // + If (LNot (And (MORD, 0x10))) + { + // + // Triggle the SMI through ACPI _PTS method. + // + Store (0x02, MCIP) + + // + // Triggle the SMI interrupt + // + Store (MCIN, IOB2) + } + } + Return (0) + } + + Method (_STA, 0) + { + Return (0x0f) + } + + // + // TCG Hardware Information + // + Method (HINF, 3, Serialized, 0, {BuffObj, PkgObj}, {UnknownObj, UnknownObj, UnknownObj}) // IntObj, IntObj, PkgObj + { + // + // Switch by function index + // + Switch (ToInteger(Arg1)) + { + Case (0) + { + // + // Standard query + // + Return (Buffer () {0x03}) + } + Case (1) + { + // + // Return failure if no TPM present + // + Name(TPMV, Package () {0x01, Package () {0x1, 0x20}}) + if (LEqual (_STA (), 0x00)) + { + Return (Package () {0x00}) + } + + // + // Return TPM version + // + Return (TPMV) + } + Default {BreakPoint} + } + Return (Buffer () {0}) + } + + Name(TPM2, Package (0x02){ + Zero, + Zero + }) + + Name(TPM3, Package (0x03){ + Zero, + Zero, + Zero + }) + + // + // TCG Physical Presence Interface + // + Method (TPPI, 3, Serialized, 0, {BuffObj, PkgObj, IntObj, StrObj}, {UnknownObj, UnknownObj, UnknownObj}) // IntObj, IntObj, PkgObj + { + // + // Switch by function index + // + Switch (ToInteger(Arg1)) + { + Case (0) + { + // + // Standard query, supports function 1-8 + // + Return (Buffer () {0xFF, 0x01}) + } + Case (1) + { + // + // a) Get Physical Presence Interface Version + // + Return ("1.2") + } + Case (2) + { + // + // b) Submit TPM Operation Request to Pre-OS Environment + // + + Store (DerefOf (Index (Arg2, 0x00)), PPRQ) + Store (0x02, PPIP) + + // + // Triggle the SMI interrupt + // + Store (PPIN, IOB2) + Return (FRET) + + + } + Case (3) + { + // + // c) Get Pending TPM Operation Requested By the OS + // + + Store (PPRQ, Index (TPM2, 0x01)) + Return (TPM2) + } + Case (4) + { + // + // d) Get Platform-Specific Action to Transition to Pre-OS Environment + // + Return (2) + } + Case (5) + { + // + // e) Return TPM Operation Response to OS Environment + // + Store (0x05, PPIP) + + // + // Triggle the SMI interrupt + // + Store (PPIN, IOB2) + + Store (LPPR, Index (TPM3, 0x01)) + Store (PPRP, Index (TPM3, 0x02)) + + Return (TPM3) + } + Case (6) + { + + // + // f) Submit preferred user language (Not implemented) + // + + Return (3) + + } + Case (7) + { + // + // g) Submit TPM Operation Request to Pre-OS Environment 2 + // + Store (7, PPIP) + Store (DerefOf (Index (Arg2, 0x00)), PPRQ) + + // + // Triggle the SMI interrupt + // + Store (PPIN, IOB2) + Return (FRET) + } + Case (8) + { + // + // e) Get User Confirmation Status for Operation + // + Store (8, PPIP) + Store (DerefOf (Index (Arg2, 0x00)), PPRQ) + + // + // Triggle the SMI interrupt + // + Store (PPIN, IOB2) + + Return (FRET) + } + + Default {BreakPoint} + } + Return (1) + } + + Method (TMCI, 3, Serialized, 0, IntObj, {UnknownObj, UnknownObj, UnknownObj}) // IntObj, IntObj, PkgObj + { + // + // Switch by function index + // + Switch (ToInteger (Arg1)) + { + Case (0) + { + // + // Standard query, supports function 1-1 + // + Return (Buffer () {0x03}) + } + Case (1) + { + // + // Save the Operation Value of the Request to MORD (reserved memory) + // + Store (DerefOf (Index (Arg2, 0x00)), MORD) + + // + // Triggle the SMI through ACPI _DSM method. + // + Store (0x01, MCIP) + + // + // Triggle the SMI interrupt + // + Store (MCIN, IOB2) + Return (MRET) + } + Default {BreakPoint} + } + Return (1) + } + + Method (TSMI, 3, Serialized, 0, IntObj, {UnknownObj, UnknownObj, UnknownObj}) // IntObj, IntObj, PkgObj + { + + // + // Operational region for TPM access + // + OperationRegion (TPMR, SystemMemory, PTTB, 0x1000) + Field (TPMR, AnyAcc, NoLock, Preserve) + { + Offset(0x04), + FERR, 32, + Offset(0x0c), + STRT, 32, + } + + // + // Switch by function index + // + Switch (ToInteger (Arg1)) + { + Case (0) + { + // + // Standard query, supports function 1-1 + // + Return (Buffer () {0x03}) + } + Case (1) + { + If(LEqual(PTTS, 0)) // GPDMA + { + If(LEqual(Or(And(HSTS,0x00000002),And(HSTS,0x00000001)),0x00000003)) + { + // + // Trigger the FTPM_CMD interrupt + // + Store (0x00000001, HCMD) + } + Else + { + //Set Error Bit + Store(0x00000001,FERR) + //Clear Start Bit + Store(0x00000000,STRT) + } + } + If(LEqual(PTTS, 1)) // MSFT QFE + { + // + // Trigger the FTPM_CMD interrupt + // + Store (0x00000000, HCMD) + } + Return (0) + } + Default {BreakPoint} + } + Return (1) + } + + Method (_DSM, 4, Serialized, 0, UnknownObj, {BuffObj, IntObj, IntObj, PkgObj}) + { + + // + // TCG Hardware Information + // + If(LEqual(Arg0, ToUUID ("cf8e16a5-c1e8-4e25-b712-4f54a96702c8"))) + { + Return (HINF (Arg1, Arg2, Arg3)) + } + + // + // TCG Physical Presence Interface + // + If(LEqual(Arg0, ToUUID ("3dddfaa6-361b-4eb4-a424-8d10089d1653"))) + { + Return (TPPI (Arg1, Arg2, Arg3)) + } + + // + // TCG Memory Clear Interface + // + If(LEqual(Arg0, ToUUID ("376054ed-cc13-4675-901c-4756d7f2d45d"))) + { + Return (TMCI (Arg1, Arg2, Arg3)) + } + + // + // TPM2 ACPI Start Method + // + If(LEqual(Arg0, ToUUID ("6bbf6cab-5463-4714-b7cd-f0203c0368d4"))) + { + Return (TSMI (Arg1, Arg2, Arg3)) + } + + Return (Buffer () {0}) + } + } + } +} diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.c b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.c new file mode 100644 index 0000000..570a554 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.c @@ -0,0 +1,847 @@ +/** @file + It updates TPM2 items in ACPI table and registers SMI2 callback + functions for TrEE physical presence, ClearMemory, and sample + for dTPM StartMethod. + + Caution: This module requires additional review when modified. + This driver will have external input - variable and ACPINvs data in SMM mode. + This external input must be validated carefully to avoid security issue. + + PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check. + +@copyright + Copyright (c) 2012 - 2013 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement + +**/ + +#include "PttHciSmm.h" +#include "MeAccess.h" +#include "HeciRegs.h" + +EFI_GUID gTpm2AcpiTableStorageGuid = TPM2_ACPI_TABLE_STORAGE_GUID; +EFI_GUID gEfiTrEEPhysicalPresenceGuid = EFI_TREE_PHYSICAL_PRESENCE_DATA_GUID; +EFI_GUID gEfiMemoryOverwriteControlDataGuid = MEMORY_ONLY_RESET_CONTROL_GUID; +EFI_GUID gEfiSmmVariableProtocolGuid = EFI_SMM_VARIABLE_PROTOCOL_GUID; +EFI_GUID gMeGlobalNvsAreaProtocolGuid = ME_GLOBAL_NVS_AREA_PROTOCOL_GUID; +EFI_GUID gMeSsdtAcpiTableStorageGuid = ME_SSDT_ACPI_TABLE_STORAGE_GUID; + +EFI_TPM2_ACPI_TABLE mTpm2AcpiTemplate = { + { + EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE, + sizeof (mTpm2AcpiTemplate), + EFI_TPM2_ACPI_TABLE_REVISION, + // + // Compiler initializes the remaining bytes to 0 + // These fields should be filled in in production + // + }, + 0, // Flags + (EFI_PHYSICAL_ADDRESS)(UINTN)0xFFFFFFFF, // Control Area + EFI_TPM2_ACPI_TABLE_START_METHOD_ACPI, +}; + +EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable; +TCG_NVS *mTcgNvs; +EFI_TPM2_ACPI_CONTROL_AREA mControlArea; // Smm copy, because we need cache Command & Response address +ME_GLOBAL_NVS_AREA_PROTOCOL mMeGlobalNvsAreaProtocol; +//<AMI_OVERRIDE> >>> +#define EFI_SMM_RUNTIME_SERVICES_TABLE_GUID \ + { 0x395c33fe, 0x287f, 0x413e, { 0xa0, 0x55, 0x80, 0x88, 0xc0, 0xe1, 0xd4, 0x3e } } + +EFI_RUNTIME_SERVICES *mRuntimeServices; + +EFI_STATUS +GetSmmRtTable ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GUID SmmRtServTableGuid = EFI_SMM_RUNTIME_SERVICES_TABLE_GUID; + EFI_SMM_BASE_PROTOCOL *SmmBase = NULL; + EFI_SMM_SYSTEM_TABLE *Smst = NULL; + EFI_CONFIGURATION_TABLE *Table = NULL; + UINTN Count = 0; + + Status = gBS->LocateProtocol( + &gEfiSmmBaseProtocolGuid, + NULL, + &SmmBase ); + if( EFI_ERROR(Status) ) return Status; + + Status = SmmBase->GetSmstLocation( SmmBase, &Smst ); + if( EFI_ERROR(Status) ) return Status; + + Table = Smst->SmmConfigurationTable; + Count = Smst->NumberOfTableEntries; + + mRuntimeServices = NULL; + for( ; Count ; --Count, ++Table ) + { + if( CompareGuid( &Table->VendorGuid, &SmmRtServTableGuid ) ) + { + mRuntimeServices = (EFI_RUNTIME_SERVICES*)Table->VendorTable; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} +//<AMI_OVERRIDE> <<< + +/** + Software SMI callback for TPM physical presence which is called from ACPI method. + + Caution: This function may receive untrusted input. + Variable and ACPINvs are external input, so this function will validate + its data structure to be valid value. + + @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). + @param[in] Context Points to an optional handler context which was specified when the + handler was registered. + + @retval EFI_SUCCESS The interrupt was handled successfully. +**/ +EFI_STATUS +EFIAPI +PhysicalPresenceCallback ( + IN EFI_HANDLE DispatchHandle, + IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext + ) +{ + EFI_STATUS Status; + UINTN DataSize; + EFI_TREE_PHYSICAL_PRESENCE PpData; + UINT8 Flags; + BOOLEAN RequestConfirmed; + + // + // Get the Physical Presence variable + // + DataSize = sizeof (EFI_TREE_PHYSICAL_PRESENCE); +//<AMI_OVERRIDE> >>> + Status = mRuntimeServices->GetVariable ( + TREE_PHYSICAL_PRESENCE_VARIABLE, + &gEfiTrEEPhysicalPresenceGuid, + NULL, + &DataSize, + &PpData + ); +//<AMI_OVERRIDE> <<< + if (EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + DEBUG ((EFI_D_INFO, "[TPM2] PP callback, Parameter = %x\n", mTcgNvs->PhysicalPresence.Parameter)); + if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) { + mTcgNvs->PhysicalPresence.LastRequest = PpData.LastPPRequest; + mTcgNvs->PhysicalPresence.Response = PpData.PPResponse; + } else if ((mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS) + || (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2)) { + if (PpData.PPRequest != mTcgNvs->PhysicalPresence.Request) { + PpData.PPRequest = (UINT8) mTcgNvs->PhysicalPresence.Request; + DataSize = sizeof (EFI_TREE_PHYSICAL_PRESENCE); +//<AMI_OVERRIDE> >>> + Status = mRuntimeServices->SetVariable ( + TREE_PHYSICAL_PRESENCE_VARIABLE, + &gEfiTrEEPhysicalPresenceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + DataSize, + &PpData + ); +//<AMI_OVERRIDE> <<< + } + + if (EFI_ERROR (Status)) { + mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_GENERAL_FAILURE; + return EFI_SUCCESS; + } + mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_SUCCESS; + } else if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST) { + Flags = PpData.Flags; + RequestConfirmed = FALSE; + + switch (mTcgNvs->PhysicalPresence.Request) { + + case TREE_PHYSICAL_PRESENCE_CLEAR_CONTROL_CLEAR: + case TREE_PHYSICAL_PRESENCE_CLEAR_CONTROL_CLEAR_2: + case TREE_PHYSICAL_PRESENCE_CLEAR_CONTROL_CLEAR_3: + case TREE_PHYSICAL_PRESENCE_CLEAR_CONTROL_CLEAR_4: + if ((Flags & TREE_FLAG_NO_PPI_CLEAR) != 0) { + RequestConfirmed = TRUE; + } + break; + + case TREE_PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE: + RequestConfirmed = TRUE; + break; + + case TREE_PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE: + break; + + default: + if (mTcgNvs->PhysicalPresence.Request <= TREE_PHYSICAL_PRESENCE_NO_ACTION_MAX) { + RequestConfirmed = TRUE; + } + break; + } + + if (RequestConfirmed) { + mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_ALLOWED_AND_PPUSER_NOT_REQUIRED; + } else { + mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_ALLOWED_AND_PPUSER_REQUIRED; + } + } + + return EFI_SUCCESS; +} + +/** + Software SMI callback for MemoryClear which is called from ACPI method. + + Caution: This function may receive untrusted input. + Variable and ACPINvs are external input, so this function will validate + its data structure to be valid value. + + @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister(). + @param[in] Context Points to an optional handler context which was specified when the + handler was registered. + + @retval EFI_SUCCESS The interrupt was handled successfully. +**/ +EFI_STATUS +EFIAPI +MemoryClearCallback ( + IN EFI_HANDLE DispatchHandle, + IN EFI_SMM_SW_DISPATCH_CONTEXT *DispatchContext + ) +{ + EFI_STATUS Status; + UINTN DataSize; + UINT8 MorControl; + + mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_SUCCESS; + if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE) { + MorControl = (UINT8) mTcgNvs->MemoryClear.Request; + } else if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_PTS_CLEAR_MOR_BIT) { + DataSize = sizeof (UINT8); +//<AMI_OVERRIDE> >>> + Status = mRuntimeServices->GetVariable ( + MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, + &gEfiMemoryOverwriteControlDataGuid, + NULL, + &DataSize, + &MorControl + ); +//<AMI_OVERRIDE> <<< + if (EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + + if (MOR_CLEAR_MEMORY_VALUE (MorControl) == 0x0) { + return EFI_SUCCESS; + } + MorControl &= ~MOR_CLEAR_MEMORY_BIT_MASK; + } + + DataSize = sizeof (UINT8); +//<AMI_OVERRIDE> >>> + Status = mRuntimeServices->SetVariable ( + MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, + &gEfiMemoryOverwriteControlDataGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + DataSize, + &MorControl + ); +//<AMI_OVERRIDE> <<< + if (EFI_ERROR (Status)) { + mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE; + } + + return EFI_SUCCESS; +} + +/** + Find the operation region in TCG ACPI table by given Name and Size, + and initialize it if the region is found. + + @param[in, out] Table The TPM item in ACPI table. + @param[in] Name The name string to find in TPM table. + @param[in] Size The size of the region to find. + + @return The allocated address for the found region. +**/ +VOID * +AssignOpRegion ( + EFI_ACPI_DESCRIPTION_HEADER *Table, + UINT32 Name, + UINT16 Size + ) +{ + EFI_STATUS Status; + AML_OP_REGION_32_8 *OpRegion; + EFI_PHYSICAL_ADDRESS MemoryAddress; + + MemoryAddress = 0xFFFFFFFF; + + // + // Patch some pointers for the ASL code before loading the SSDT. + // + for (OpRegion = (AML_OP_REGION_32_8 *) (Table + 1); + OpRegion <= (AML_OP_REGION_32_8 *) ((UINT8 *) Table + Table->Length); + OpRegion = (AML_OP_REGION_32_8 *) ((UINT8 *) OpRegion + 1)) { + if ((OpRegion->OpRegionOp == AML_EXT_REGION_OP) && + (OpRegion->NameString == Name) && + (OpRegion->DWordPrefix == AML_DWORD_PREFIX) && + (OpRegion->BytePrefix == AML_BYTE_PREFIX)) { + + Status = (gBS->AllocatePages)(AllocateMaxAddress, EfiACPIMemoryNVS, EFI_SIZE_TO_PAGES (Size), &MemoryAddress); + ASSERT_EFI_ERROR (Status); + ZeroMem ((VOID *)(UINTN)MemoryAddress, Size); + OpRegion->RegionOffset = (UINT32) (UINTN) MemoryAddress; + OpRegion->RegionLen = (UINT8) Size; + break; + } + } + + return (VOID *) (UINTN) MemoryAddress; +} + +VOID * +GetTpm2AcpiTableFromFv ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + EFI_FV_FILETYPE FileType; + UINT32 FvStatus; + EFI_FV_FILE_ATTRIBUTES Attributes; + UINTN Size; + UINTN Index; + INTN Instance; + EFI_ACPI_COMMON_HEADER *CurrentTable; + EFI_FIRMWARE_VOLUME_PROTOCOL *FwVol; + + /// + /// Locate protocol. + /// There is little chance we can't find an FV protocol + /// + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolumeProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + ASSERT_EFI_ERROR (Status); + + FwVol = NULL; + /// + /// Looking for FV with ACPI storage file + /// + for (Index = 0; Index < NumberOfHandles; Index++) { + /// + /// Get the protocol on this handle + /// This should not fail because of LocateHandleBuffer + /// + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiFirmwareVolumeProtocolGuid, + &FwVol + ); + ASSERT_EFI_ERROR (Status); + + /// + /// See if it has the ACPI storage file + /// + Size = 0; + FvStatus = 0; + Status = FwVol->ReadFile ( + FwVol, + &gTpm2AcpiTableStorageGuid, + NULL, + &Size, + &FileType, + &Attributes, + &FvStatus + ); + + /// + /// If we found it, then we are done + /// + if (Status == EFI_SUCCESS) { + break; + } else { + FwVol = NULL; + } + } + + if ((Index == NumberOfHandles) || (FwVol == NULL)) { + return NULL; + } + + Instance = 0; + CurrentTable = NULL; + + while (Status == EFI_SUCCESS) { + Status = FwVol->ReadSection ( + FwVol, + &gTpm2AcpiTableStorageGuid, + EFI_SECTION_RAW, + Instance, + &CurrentTable, + &Size, + &FvStatus + ); + + if (!EFI_ERROR (Status)) { + /// + /// Check the Signature ID to modify the table + /// + if ((((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Signature == EFI_SIGNATURE_32 ('S', 'S', 'D', 'T')) && + (((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->OemTableId == EFI_SIGNATURE_64 ('T', 'p', 'm', '2', 'T', 'a', 'b', 'l'))) { + // + // Find it. + // + break; + } + /// + /// Increment the instance + /// + Instance++; + CurrentTable = NULL; + } + } + + /// + /// Our exit status is determined by the success of the previous operations + /// If the protocol was found, Instance already points to it. + /// + /// + /// Free any allocated buffers + /// + (gBS->FreePool) (HandleBuffer); + + return CurrentTable; +} + +/** + Initialize and publish TPM items in ACPI table. + + @retval EFI_SUCCESS The TCG ACPI table is published successfully. + @retval Others The TCG ACPI table is not published. +**/ +EFI_STATUS +PublishAcpiTable ( + VOID + ) +{ + EFI_STATUS Status; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + UINTN TableKey; + EFI_ACPI_DESCRIPTION_HEADER *Table; + UINTN TableSize; + + Table = GetTpm2AcpiTableFromFv (); + ASSERT (Table != NULL); + + if (Table == NULL) { + return EFI_NOT_FOUND; + } + + TableSize = Table->Length; + + ASSERT (Table->OemTableId == EFI_SIGNATURE_64 ('T', 'p', 'm', '2', 'T', 'a', 'b', 'l')); + mTcgNvs = AssignOpRegion (Table, EFI_SIGNATURE_32 ('T', 'N', 'V', 'S'), (UINT16) sizeof (TCG_NVS)); + ASSERT (mTcgNvs != NULL); + + // + // Publish the TPM ACPI table + // + Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable); + ASSERT_EFI_ERROR (Status); + + TableKey = 0; + Status = AcpiTable->InstallAcpiTable ( + AcpiTable, + Table, + TableSize, + &TableKey + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +EFI_STATUS +PublishFtpmAcpiTable ( + VOID + ) +/** + Publish TPM2 ACPI table + + @retval EFI_SUCCESS The TPM2 ACPI table is published successfully. + @retval Others The TPM2 ACPI table is not published. +**/ +{ + EFI_STATUS Status; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + UINTN TableKey; + EFI_TPM2_ACPI_CONTROL_AREA *ControlArea; + ME_DATA_HOB *MeDataHob; + EFI_GUID gMeDataHobGuid = ME_DATA_HOB_GUID; + + /// + /// Construct ACPI table + /// + Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable); + ASSERT_EFI_ERROR (Status); + + MeDataHob = NULL; + MeDataHob = GetFirstGuidHob (&gMeDataHobGuid); + if (MeDataHob != NULL) { + (UINTN)mTpm2AcpiTemplate.AddressOfControlArea = MeDataHob->FtpmBufferAddress; + } else { + (UINTN) mTpm2AcpiTemplate.AddressOfControlArea = 0xFED70000; + } + + ControlArea = (EFI_TPM2_ACPI_CONTROL_AREA *)(UINTN)mTpm2AcpiTemplate.AddressOfControlArea; + ZeroMem (ControlArea, sizeof(*ControlArea)); + ControlArea->CommandSize = 0xF80; + ControlArea->ResponseSize = 0xF80; + ControlArea->Command = (UINTN)mTpm2AcpiTemplate.AddressOfControlArea + 0x80; + ControlArea->Response = (UINTN)mTpm2AcpiTemplate.AddressOfControlArea + 0x80; + CopyMem (&mControlArea, ControlArea, sizeof(mControlArea)); + + DEBUG ((EFI_D_INFO, "Ftpm Windows Buffer Control Area Address = %x\n", mTpm2AcpiTemplate.AddressOfControlArea)); + DEBUG ((EFI_D_INFO, "Ftpm Windows Command/Response Buffer Address = %x\n", ControlArea->Command)); + + Status = AcpiTable->InstallAcpiTable ( + AcpiTable, + &mTpm2AcpiTemplate, + sizeof(mTpm2AcpiTemplate), + &TableKey + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +BOOLEAN +IsFtpmEnabled ( + VOID + ) +{ + UINT32 IsPttEnabled; + UINT32 IsPttReady; + UINT32 MeFwSts4; + + IsPttEnabled = ( B_PTT_HCI_STS_ENABLED & MmioRead32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS)) ); + /// + /// Read ME FWSTS4 to check if TPM_DISCONNECT_ALL BIT[12] is set + /// + MeFwSts4 = HeciPciRead32(R_ME_HFS_4); + + /// + /// Read Ready Bit to identify if PTT is ready for accepting OS Commands + /// + IsPttReady = (B_PTT_HCI_STS_READY & MmioRead32((UINTN)(R_PTT_HCI_BASE_ADDRESS + R_PTT_HCI_STS))); + + if ( (IsPttEnabled == 0) || (MeFwSts4 & BIT12) || (IsPttReady == 0) ) { + return FALSE; + } + + return TRUE; +} + +EFI_STATUS +InitializeMeSsdtAcpiTables ( +IN EFI_HANDLE ImageHandle + ) +/** +@brief + Initialize MEFW SSDT ACPI tables + + @retval EFI_SUCCESS ACPI tables are initialized successfully + @retval EFI_NOT_FOUND ACPI tables not found +**/ +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + EFI_FV_FILETYPE FileType; + UINT32 FvStatus; + EFI_FV_FILE_ATTRIBUTES Attributes; + UINTN Size; + UINTN i; + EFI_FIRMWARE_VOLUME_PROTOCOL *FwVol; + INTN Instance; + EFI_ACPI_COMMON_HEADER *CurrentTable; + UINTN AcpiTableKey; + UINT8 *CurrPtr; + UINT8 *EndPtr; + UINT32 *Signature; + EFI_ACPI_DESCRIPTION_HEADER *MeAcpiTable; + EFI_ACPI_TABLE_PROTOCOL *AcpiTable; + + Status = (gBS->AllocatePool) (EfiReservedMemoryType, sizeof (ME_GLOBAL_NVS_AREA), (VOID **) &mMeGlobalNvsAreaProtocol.Area); + ASSERT_EFI_ERROR (Status); + ZeroMem ((VOID *) mMeGlobalNvsAreaProtocol.Area, sizeof (ME_GLOBAL_NVS_AREA)); + + FwVol = NULL; + MeAcpiTable = NULL; + + /// + /// Locate ACPI Table protocol + /// + DEBUG ((EFI_D_INFO, "Init ME SSDT table\n")); + Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, &AcpiTable); + if (Status != EFI_SUCCESS) { + DEBUG ((EFI_D_ERROR, "Fail to locate EfiAcpiTableProtocol.\n")); + return EFI_NOT_FOUND; + } + + /// + /// Locate protocol. + /// There is little chance we can't find an FV protocol + /// + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiFirmwareVolumeProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + ASSERT_EFI_ERROR (Status); + /// + /// Looking for FV with ACPI storage file + /// + for (i = 0; i < NumberOfHandles; i++) { + /// + /// Get the protocol on this handle + /// This should not fail because of LocateHandleBuffer + /// + Status = gBS->HandleProtocol ( + HandleBuffer[i], + &gEfiFirmwareVolumeProtocolGuid, + &FwVol + ); + ASSERT_EFI_ERROR (Status); + + /// + /// See if it has the ACPI storage file + /// + Size = 0; + FvStatus = 0; + Status = FwVol->ReadFile ( + FwVol, + &gMeSsdtAcpiTableStorageGuid, + NULL, + &Size, + &FileType, + &Attributes, + &FvStatus + ); + + /// + /// If we found it, then we are done + /// + if (Status == EFI_SUCCESS) { + break; + } + } + /// + /// Free any allocated buffers + /// + FreePool (HandleBuffer); + + /// + /// Sanity check that we found our data file + /// + ASSERT (FwVol != NULL); + if (FwVol == NULL) { + DEBUG ((EFI_D_INFO, "ME Global NVS table not found\n")); + return EFI_NOT_FOUND; + } + /// + /// Our exit status is determined by the success of the previous operations + /// If the protocol was found, Instance already points to it. + /// Read tables from the storage file. + /// + Instance = 0; + CurrentTable = NULL; + while (Status == EFI_SUCCESS) { + Status = FwVol->ReadSection ( + FwVol, + &gMeSsdtAcpiTableStorageGuid, + EFI_SECTION_RAW, + Instance, + &CurrentTable, + &Size, + &FvStatus + ); + + if (!EFI_ERROR (Status)) { + /// + /// Check the table ID to modify the table + /// + if (((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->OemTableId == EFI_SIGNATURE_64 ('M', 'e', 'S', 's', 'd', 't', ' ', 0)) { + MeAcpiTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable; + /// + /// Locate the SSDT package + /// + CurrPtr = (UINT8 *) MeAcpiTable; + EndPtr = CurrPtr + MeAcpiTable->Length; + + for (; CurrPtr <= EndPtr; CurrPtr++) { + Signature = (UINT32 *) (CurrPtr + 3); + if (*Signature == EFI_SIGNATURE_32 ('M', 'E', 'N', 'V')) { + ASSERT_EFI_ERROR (*(UINT32 *) (CurrPtr + 3 + sizeof (*Signature) + 2) == 0xFFFF0000); + ASSERT_EFI_ERROR (*(UINT16 *) (CurrPtr + 3 + sizeof (*Signature) + 2 + sizeof (UINT32) + 1) == 0xAA55); + /// + /// ME Global NVS Area address + /// + + *(UINT32 *) (CurrPtr + 3 + sizeof (*Signature) + 2) = (UINT32) (UINTN) mMeGlobalNvsAreaProtocol.Area; + /// + /// ME Global NVS Area size + /// + *(UINT16 *) (CurrPtr + 3 + sizeof (*Signature) + 2 + sizeof (UINT32) + 1) = + sizeof (ME_GLOBAL_NVS_AREA); + + AcpiTableKey = 0; + Status = AcpiTable->InstallAcpiTable ( + AcpiTable, + MeAcpiTable, + MeAcpiTable->Length, + &AcpiTableKey + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gMeGlobalNvsAreaProtocolGuid, + &mMeGlobalNvsAreaProtocol, + NULL + ); + ASSERT_EFI_ERROR (Status); + return EFI_SUCCESS; + } + } + } + /// + /// Increment the instance + /// + Instance++; + CurrentTable = NULL; + } + } + + return Status; +} +/** + The driver's entry point. + + It install callbacks for TPM physical presence and MemoryClear, and locate + SMM variable to be used in the callback function. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Others Some error occurs when executing this entry point. +**/ +EFI_STATUS +EFIAPI +InitializeFtpmSmm ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_SMM_SW_DISPATCH_PROTOCOL *SwDispatch; + EFI_SMM_SW_DISPATCH_CONTEXT SwContext; + EFI_HANDLE SwHandle; + ME_GLOBAL_NVS_AREA_PROTOCOL *MeGlobalNvsAreaProtocol; + ME_GLOBAL_NVS_AREA *MeGlobalNvsArea; + + if (!IsFtpmEnabled ()) { + DEBUG ((EFI_D_ERROR, "InitializeFtpmSmm - FTPM not enabled\n")); + return EFI_SUCCESS; + } + +if (GetCpuFamily() == EnumCpuHswUlt) { + Status = PublishAcpiTable (); + ASSERT_EFI_ERROR (Status); + + // + // Get the Sw dispatch protocol and register SMI callback functions. + // + Status = gBS->LocateProtocol (&gEfiSmmSwDispatchProtocolGuid, NULL, (VOID**)&SwDispatch); + ASSERT_EFI_ERROR (Status); + SwContext.SwSmiInputValue = EFI_TPM2_PP_SW_SMI; + Status = SwDispatch->Register (SwDispatch, PhysicalPresenceCallback, &SwContext, &SwHandle); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + mTcgNvs->PhysicalPresence.SoftwareSmi = (UINT8) SwContext.SwSmiInputValue; + + SwContext.SwSmiInputValue = EFI_TPM2_MOR_SW_SMI; + Status = SwDispatch->Register (SwDispatch, MemoryClearCallback, &SwContext, &SwHandle); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + mTcgNvs->MemoryClear.SoftwareSmi = (UINT8) SwContext.SwSmiInputValue; + +//<AMI_OVERRIDE> >>> + /// + /// Locate SmmVariableProtocol. + /// + //Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mSmmVariable); + //ASSERT_EFI_ERROR (Status); + + //We don't install SmmVariableProtocol in gBS, use gRT's variable + //service directly. + Status = GetSmmRtTable(); + ASSERT_EFI_ERROR (Status); +//<AMI_OVERRIDE> <<< + + Status = InitializeMeSsdtAcpiTables(ImageHandle); + ASSERT_EFI_ERROR (Status); + + /// + /// Publish TPM2 ACPI table + /// + Status = PublishFtpmAcpiTable(); + ASSERT_EFI_ERROR (Status); + + /// + /// Locate Global NVS and update PTT Buffer Address + /// + Status = gBS->LocateProtocol (&gMeGlobalNvsAreaProtocolGuid, NULL, (VOID **) &MeGlobalNvsAreaProtocol); + ASSERT_EFI_ERROR (Status); + + MeGlobalNvsArea = MeGlobalNvsAreaProtocol->Area; + MeGlobalNvsArea->PTTAddress = mTpm2AcpiTemplate.AddressOfControlArea; +} + + return EFI_SUCCESS; +} + diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.cif b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.cif new file mode 100644 index 0000000..d8a8e0d --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.cif @@ -0,0 +1,13 @@ +<component> + name = "PttHciSmm" + category = ModulePart + LocalRoot = "ReferenceCode\ME\Ptt\Smm\" + RefName = "PttHciSmm" +[files] +"PttHciSmm.sdl" +"PttHciSmm.mak" +"PttHciSmm.c" +"PttHciSmm.h" +"PttHciSmm.dxs" +"PttHciSmm.inf" +<endComponent> diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.dxs b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.dxs new file mode 100644 index 0000000..01b31c8 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.dxs @@ -0,0 +1,48 @@ +/** @file + Dependency expression source file. + +@copyright + Copyright (c) 2012 - 2013 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement + +**/ + + +// +// Common for R8 and R9 codebase +// +#include "AutoGen.h" +#include "DxeDepex.h" + +// +// BUILD_WITH_GLUELIB and BUILD_WITH_EDKII_GLUE_LIB are both "defined" in R8 codebase; +// BUILD_WITH_EDKII_GLUE_LIB is defined in Edk-Dev-Snapshot-20070228 and later version +// BUILD_WITH_GLUELIB and BUILD_WITH_EDKII_GLUE_LIB are "not defined" in R9 codebase. +// +#if defined (BUILD_WITH_GLUELIB) || defined (BUILD_WITH_EDKII_GLUE_LIB) +#include "EfiDepex.h" +#endif + +#include EFI_PROTOCOL_DEFINITION (AcpiTable) +#include EFI_PROTOCOL_DEFINITION (SmmSwDispatch) +//#include EFI_PROTOCOL_DEFINITION (SmmVariable) //<AMI_OVERRIDE> + +//<AMI_OVERRIDE> >>> +DEPENDENCY_START + EFI_ACPI_TABLE_PROTOCOL_GUID AND + EFI_SMM_SW_DISPATCH_PROTOCOL_GUID +DEPENDENCY_END +//<AMI_OVERRIDE> <<<
\ No newline at end of file diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.h b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.h new file mode 100644 index 0000000..3771d00 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.h @@ -0,0 +1,158 @@ +/** @file + The header file for Ftpm SMM driver. + +@copyright + Copyright (c) 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement + +**/ + +#ifndef __FTPM_SMM_H__ +#define __FTPM_SMM_H__ + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGlueDxe.h" + +#include EFI_PROTOCOL_DEPENDENCY (SmmBase) +#include EFI_PROTOCOL_DEPENDENCY (SmmSwDispatch) +#include EFI_PROTOCOL_DEPENDENCY (AcpiTable) +#include EFI_PROTOCOL_DEPENDENCY (FirmwareVolume) +#include EFI_PROTOCOL_DEPENDENCY (MeGlobalNvsArea) +#include EFI_GUID_DEFINITION (MeSsdtTableStorage) + +#include "Acpi.h" + +// +// Below definition is generic, but NOT in GreenH +// +#include EFI_PROTOCOL_DEPENDENCY (SmmVariable) + +#include "IndustryStandard\AcpiAml.h" +#ifndef EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE +#define EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE EFI_SIGNATURE_32('T', 'P', 'M', '2') +#endif + +#include "IndustryStandard\Tpm2Acpi.h" +#include EFI_GUID_DEFINITION (TrEEPhysicalPresenceData) +#include EFI_GUID_DEFINITION (MemoryOverwriteControl) + +// +// Below definition is chipset specific +// +#include EFI_GUID_DEFINITION (MeDataHob) +#include "CpuRegs.h" +#include "CpuPlatformLib.h" +#include "PttHciRegs.h" +#endif + +// +// Below definition is driver specific +// +#include "Tpm2AcpiTableStorage.h" + +#pragma pack(1) +typedef struct { + UINT8 SoftwareSmi; + UINT32 Parameter; + UINT32 Response; + UINT32 Request; + UINT32 LastRequest; + UINT32 ReturnCode; +} PHYSICAL_PRESENCE_NVS; + +typedef struct { + UINT8 SoftwareSmi; + UINT32 Parameter; + UINT32 Request; + UINT32 ReturnCode; +} MEMORY_CLEAR_NVS; + +typedef struct { + UINT8 SoftwareSmi; + UINT32 ReturnCode; +} START_METHOD_NVS; + +typedef struct { + PHYSICAL_PRESENCE_NVS PhysicalPresence; + MEMORY_CLEAR_NVS MemoryClear; + START_METHOD_NVS StartMethod; +} TCG_NVS; + +typedef struct { + UINT8 OpRegionOp; + UINT32 NameString; + UINT8 RegionSpace; + UINT8 DWordPrefix; + UINT32 RegionOffset; + UINT8 BytePrefix; + UINT8 RegionLen; +} AML_OP_REGION_32_8; +#pragma pack() + +// +// The definition for TCG physical presence ACPI function +// +#define ACPI_FUNCTION_GET_PHYSICAL_PRESENCE_INTERFACE_VERSION 1 +#define ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS 2 +#define ACPI_FUNCTION_GET_PENDING_REQUEST_BY_OS 3 +#define ACPI_FUNCTION_GET_PLATFORM_ACTION_TO_TRANSITION_TO_BIOS 4 +#define ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS 5 +#define ACPI_FUNCTION_SUBMIT_PREFERRED_USER_LANGUAGE 6 +#define ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2 7 +#define ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST 8 + +// +// The return code for Get User Confirmation Status for Operation +// +#define PP_REQUEST_NOT_IMPLEMENTED 0 +#define PP_REQUEST_BIOS_ONLY 1 +#define PP_REQUEST_BLOCKED 2 +#define PP_REQUEST_ALLOWED_AND_PPUSER_REQUIRED 3 +#define PP_REQUEST_ALLOWED_AND_PPUSER_NOT_REQUIRED 4 + +// +// The return code for Sumbit TPM Request to Pre-OS Environment +// and Sumbit TPM Request to Pre-OS Environment 2 +// +#define PP_SUBMIT_REQUEST_SUCCESS 0 +#define PP_SUBMIT_REQUEST_NOT_IMPLEMENTED 1 +#define PP_SUBMIT_REQUEST_GENERAL_FAILURE 2 +#define PP_SUBMIT_REQUEST_BLOCKED_BY_BIOS_SETTINGS 3 + +// +// The definition for TCG MOR +// +#define ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE 1 +#define ACPI_FUNCTION_PTS_CLEAR_MOR_BIT 2 + +// +// The return code for Memory Clear Interface Functions +// +#define MOR_REQUEST_SUCCESS 0 +#define MOR_REQUEST_GENERAL_FAILURE 1 + +// +// Below definition should be in platorm scope +// +// TBD: Use policy to input these data... +#ifndef EFI_TPM2_PP_SW_SMI +#define EFI_TPM2_PP_SW_SMI 0x9E +#endif +#ifndef EFI_TPM2_MOR_SW_SMI +#define EFI_TPM2_MOR_SW_SMI 0x9F +#endif + +#endif // __FTPM_SMM_H__ diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.inf b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.inf new file mode 100644 index 0000000..87e30f1 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.inf @@ -0,0 +1,106 @@ +## @file +# This driver implements TPM2 definition block in ACPI table and +# +#@copyright +# Copyright (c) 2012 Intel Corporation. All rights reserved +# This software and associated documentation (if any) is furnished +# under a license and may only be used or copied in accordance +# with the terms of the license. Except as permitted by such +# license, no part of this software or documentation may be +# reproduced, stored in a retrieval system, or transmitted in any +# form or by any means without the express written consent of +# Intel Corporation. +# +# This file contains an 'Intel Peripheral Driver' and uniquely +# identified as "Intel Reference Module" and is +# licensed for Intel CPUs and chipsets under the terms of your +# license agreement with Intel or your vendor. This file may +# be modified by the user, subject to additional terms of the +# license agreement +# + +[defines] + BASE_NAME = PttHciSmm + FILE_GUID = 8029a5b5-4088-48d2-96e0-f7052bc0a842 + COMPONENT_TYPE = RT_DRIVER + +[sources.common] + PttHciSmm.c + PttHciSmm.h +# +# Edk II Glue Driver Entry Point +# + EdkIIGlueSmmDriverEntryPoint.c + +[includes.common] + # + # Edk II Glue Library, some hearder are included by R9 header so have to include + # + $(EFI_SOURCE) + $(EFI_SOURCE)/Framework + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Include/Pei + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include/Library + $(EDK_SOURCE)/Foundation/Library/EdkIIGlueLib/Include/Common + + $(EDK_SOURCE)/Foundation/Efi + $(EDK_SOURCE)/Foundation + $(EDK_SOURCE)/Foundation/Framework + $(EDK_SOURCE)/Foundation/Framework/Guid + $(EDK_SOURCE)/Foundation/Include + $(EDK_SOURCE)/Foundation/Efi/Include + $(EDK_SOURCE)/Foundation/Framework/Include + $(EDK_SOURCE)/Foundation/Include/IndustryStandard + $(EDK_SOURCE)/Foundation/Core/Dxe + $(EDK_SOURCE)/Foundation/Library/Dxe/Include + + $(EFI_SOURCE)/$(PROJECT_CPU_ROOT) + $(EFI_SOURCE)/$(PROJECT_CPU_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_CPU_ROOT)/Include/Library + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include + $(EFI_SOURCE)/$(PROJECT_PCH_ROOT)/Include/Library + $(EFI_SOURCE)/$(PROJECT_ME_ROOT) + $(EFI_SOURCE)/$(PROJECT_ME_ROOT)/Library/MeKernel/Include + $(EFI_SOURCE)/$(PROJECT_ME_ROOT)/Heci/Include + $(EFI_SOURCE)/$(PROJECT_ME_ROOT)/Library/Ptt/Include + +# +# Typically the sample code referenced will be available in the code base already +# So keep this include at the end to defer to the source base definition +# and only use the sample code definition if source base does not include these files. +# + $(EFI_SOURCE)/$(PROJECT_ME_ROOT)/SampleCode + $(EFI_SOURCE)/$(PROJECT_ME_ROOT)/SampleCode/Include + +[libraries.common] + EdkIIGlueBaseLib + EdkIIGlueBaseMemoryLib + EdkIIGlueUefiBootServicesTableLib + EdkIIGlueUefiRuntimeServicesTableLib + EdkIIGlueSmmRuntimeDxeReportStatusCodeLib + EdkIIGlueDxeDebugLibReportStatusCode + EdkIIGlueDxeHobLib + CpuPlatformLib + EdkFrameworkProtocolLib + EdkProtocolLib + EdkIIGlueSmmFirmwarePerformanceLib + +[nmake.common] + IMAGE_ENTRY_POINT = _ModuleEntryPoint + DPX_SOURCE = PttHciSmm.dxs +# +# Module Entry Point +# + C_FLAGS = $(C_FLAGS) /D__EDKII_GLUE_MODULE_ENTRY_POINT__=InitializeFtpmSmm + C_FLAGS = $(C_FLAGS) /D __EDKII_GLUE_BASE_LIB__ \ + /D __EDKII_GLUE_BASE_MEMORY_LIB__ \ + /D __EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__ \ + /D __EDKII_GLUE_DXE_DEBUG_LIB_REPORT_STATUS_CODE__ \ + /D __EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__ \ + /D __EDKII_GLUE_DXE_HOB_LIB__ \ + /D PTT_FLAG diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.mak b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.mak new file mode 100644 index 0000000..1c6485a --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.mak @@ -0,0 +1,69 @@ +# MAK file for the ModulePart:PTTHciSmm +all : PttHciSmm + +PttHciSmm : $(BUILD_DIR)\PttHciSmm.mak PttHciSmmBin + +$(BUILD_DIR)\PttHciSmm.mak : $(PttHciSmm_DIR)\PttHciSmm.cif $(PttHciSmm_DIR)\PttHciSmm.mak $(CP_BUILD_RULES) + $(CIF2MAK) $(PttHciSmm_DIR)\PttHciSmm.cif $(CIF2MAK_DEFAULTS) + +PTTHciSmm_INCLUDES= \ + $(ACPI_PLATFORM_INCLUDES)\ + $(EDK_INCLUDES)\ + $(EdkIIGlueLib_INCLUDES)\ + $(ME_INCLUDES)\ + /I$(INTEL_COUGAR_POINT_INCLUDE_DIR)\ + /IReferenceCode\ME\SampleCode\ + $(PROJECT_CPU_INCLUDES) + +PTTHciSmm_LIBS=\ + $(EDKPROTOCOLLIB)\ + $(MeProtocolLib_LIB)\ + $(MeLibDxe_LIB)\ + $(MeChipsetDxeLib_LIB)\ + $(MeGuidLib_LIB)\ + $(EFISCRIPTLIB)\ + $(EDKFRAMEWORKPROTOCOLLIB)\ + $(EFIGUIDLIB)\ + $(EdkIIGlueBaseLib_LIB)\ +!IF "$(x64_BUILD)"=="1" + $(EdkIIGlueBaseLibX64_LIB)\ +!ELSE + $(EdkIIGlueBaseLibIA32_LIB)\ +!ENDIF + $(EdkIIGlueBaseIoLibIntrinsic_LIB)\ + $(EdkIIGlueDxeReportStatusCodeLib_LIB)\ + $(EdkIIGlueDxeDebugLibReportStatusCode_LIB)\ + $(EdkIIGlueUefiBootServicesTableLib_LIB)\ + $(EdkIIGlueUefiLib_LIB)\ + $(EdkIIGlueBasePciLibPciExpress_LIB)\ + $(EdkIIGlueDxeServicesTableLib_LIB)\ + $(EFIDRIVERLIB)\ + $(RcFviDxeLib_LIB)\ + $(PchPlatformDxeLib_LIB)\ + $(CpuPlatformLib_LIB)\ + $(EdkIIGlueDxeHobLib_LIB)\ + $(EdkIIGlueSmmRuntimeDxeReportStatusCodeLib_LIB)\ + +PTTHciSmm_DEFINES=$(MY_DEFINES)\ + /D"__EDKII_GLUE_MODULE_ENTRY_POINT__=InitializeFtpmSmm"\ + /D __EDKII_GLUE_BASE_LIB__ \ + /D __EDKII_GLUE_BASE_MEMORY_LIB__ \ + /D __EDKII_GLUE_SMM_RUNTIME_DXE_REPORT_STATUS_CODE_LIB__ \ + /D __EDKII_GLUE_DXE_DEBUG_LIB_REPORT_STATUS_CODE__ \ + /D __EDKII_GLUE_UEFI_BOOT_SERVICES_TABLE_LIB__ \ + /D __EDKII_GLUE_DXE_HOB_LIB__ \ + /D PTT_FLAG + +PTTHciSmmBin : $(PTTHciSmm_LIBS) + $(MAKE) /$(MAKEFLAGS) $(EDKIIGLUE_DEFAULTS)\ + /f $(BUILD_DIR)\PttHciSmm.mak all\ + MAKEFILE=$(BUILD_DIR)\PttHciSmm.mak\ + "MY_INCLUDES=$(PTTHciSmm_INCLUDES)"\ + "MY_DEFINES=$(PTTHciSmm_DEFINES)"\ + GUID=8029a5b5-4088-48d2-96e0-f7052bc0a842\ + DEPEX1=$(PttHciSmm_DIR)\PTTHciSmm.dxs\ + DEPEX1_TYPE=EFI_SECTION_DXE_DEPEX \ + ENTRY_POINT=_ModuleEntryPoint \ + TYPE=RT_DRIVER\ + EDKIIModule=SMMDRIVER\ + COMPRESS=1
\ No newline at end of file diff --git a/ReferenceCode/ME/Ptt/Smm/PttHciSmm.sdl b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.sdl new file mode 100644 index 0000000..1853239 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttHciSmm.sdl @@ -0,0 +1,32 @@ +TOKEN + Name = "PTTHciSmm_SUPPORT" + Value = "1" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes + Help = "Main switch to enable PTTHciSmm Suppport in Project" + Token = "IntelPTT_SUPPORT" "=" "1" +End + +MODULE + Help = "Includes HeciSmm.mak to Project" + File = "PttHciSmm.mak" +End + +ELINK + Name = "$(BUILD_DIR)\PttHciSmm.ffs" + Parent = "FV_MAIN" + InvokeOrder = AfterParent +End + +PATH + Name = "PttHciSmm_DIR" + Help = "PTT Hci SMM Driver files source directory" +End + +ELINK + Name = "/D PTT_FLAG" + Parent = "GLOBAL_DEFINES" + InvokeOrder = AfterParent +End diff --git a/ReferenceCode/ME/Ptt/Smm/PttSmm.cif b/ReferenceCode/ME/Ptt/Smm/PttSmm.cif new file mode 100644 index 0000000..d2c5c29 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttSmm.cif @@ -0,0 +1,9 @@ +<component> + name = "PttSmm" + category = ModulePart + LocalRoot = "ReferenceCode\ME\Ptt\Smm\" + RefName = "PttSmm" +[parts] +"PttHciSmm" +"PttSmmAcpi" +<endComponent> diff --git a/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.cif b/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.cif new file mode 100644 index 0000000..50eb85c --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.cif @@ -0,0 +1,12 @@ +<component> + name = "PttSmmAcpi" + category = ModulePart + LocalRoot = "ReferenceCode\ME\Ptt\Smm\" + RefName = "PttSmmAcpi" +[files] +"Ftpm.asl" +"Tpm2AcpiTables.inf" +"Tpm2AcpiTableStorage.h" +"PttSmmAcpi.mak" +"PttSmmAcpi.sdl" +<endComponent> diff --git a/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.mak b/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.mak new file mode 100644 index 0000000..24e7414 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.mak @@ -0,0 +1,44 @@ +#----------------------------------------------------------------------- +# ASL compiler definition +#----------------------------------------------------------------------- +MASL = $(SILENT)asl.exe # Microsoft ASL compiler +!IF "$(ACPIPLATFORM_ASL_COMPILER)"=="" +!ERROR It is an invalid path, please check your ASL compiler path. +!ENDIF + +IASL = $(ACPIPLATFORM_ASL_COMPILER) +#----------------------------------------------------------------------- +ASL_COMPILER = IASL # Default ASL compiler. Can be 'IASL' for Intel ASL and 'MASL' for Microsoft ASL compiler. +# Note. Msft. ASL compiler of version 1.0.14NT correctly process ACPI 2.0 extended ASL objects. +#----------------------------------------------------------------------- +EDK : PTTASL + +PTTASL: $(BUILD_DIR)\PTTACPI.ffs + +$(BUILD_DIR)\TPM.aml: $(INTEL_PTT_ASL_FILE) +!if "$(ASL_COMPILER)" == "MASL" + $(MASL) /Fo=$@ $** +!elseif "$(ASL_COMPILER)" == "IASL" + $(IASL) -p $(BUILD_DIR)\TPM.aml $(INTEL_PTT_ASL_FILE) +!endif + +$(BUILD_DIR)\TPM.sec: $(BUILD_DIR)\TPM.aml + $(GENSECTION) -I $** -O $@ -S EFI_SECTION_RAW + +$(BUILD_DIR)\PTTACPI.ffs: $(BUILD_DIR)\TPM.sec $(PttHciSmm_DIR)\PttSmmAcpi.mak + $(GENFFSFILE) -B $(BUILD_DIR) -V -o $@ -P1 <<$(BUILD_DIR)\PTTACPI.pkg +PACKAGE.INF +[.] +BASE_NAME = PTTACPI +FFS_FILEGUID = 7D279373-EECC-4d4f-AE2F-CEC4B706B06A +FFS_FILETYPE = EFI_FV_FILETYPE_FREEFORM +FFS_ATTRIB_CHECKSUM = TRUE + +IMAGE_SCRIPT = +{ + Compress (dummy) { + $(PROJECT_DIR)\$(BUILD_DIR)\TPM.sec + } +} +<<KEEP +#-----------------------------------------------------------------------
\ No newline at end of file diff --git a/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.sdl b/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.sdl new file mode 100644 index 0000000..b039d27 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/PttSmmAcpi.sdl @@ -0,0 +1,33 @@ +TOKEN + Name = "PTTSmmAcpi_SUPPORT" + Value = "1" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes + Help = "Main switch to enable PTTHciSmm Suppport in Project" + Token = "IntelPTT_SUPPORT" "=" "1" +End + +MODULE + Help = "Includes HeciSmm.mak to Project" + File = "PttSmmAcpi.mak" +End + +PATH + Name = "PttHciSmm_DIR" + Help = "PTT Hci SMM Driver files source directory" +End + +ELINK + Name = "$(BUILD_DIR)\PTTACPI.ffs" + Parent = "FV_MAIN" + InvokeOrder = AfterParent +End + +TOKEN + Name = "INTEL_PTT_ASL_FILE" + Value = "$(PttHciSmm_DIR)\Ftpm.asl" + TokenType = Expression + TargetMAK = Yes +End diff --git a/ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTableStorage.h b/ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTableStorage.h new file mode 100644 index 0000000..42a7e18 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTableStorage.h @@ -0,0 +1,31 @@ +/** @file + GUID definition for the TPM2 ACPI table storage file name + +@copyright + Copyright (c) 2012 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + This file contains an 'Intel Peripheral Driver' and uniquely + identified as "Intel Reference Module" and is + licensed for Intel CPUs and chipsets under the terms of your + license agreement with Intel or your vendor. This file may + be modified by the user, subject to additional terms of the + license agreement +**/ +#ifndef _TPM2_ACPI_TABLE_STORAGE_H_ +#define _TPM2_ACPI_TABLE_STORAGE_H_ + +#define TPM2_ACPI_TABLE_STORAGE_GUID \ + { \ + 0x7d279373, 0xeecc, 0x4d4f, 0xae, 0x2f, 0xce, 0xc4, 0xb7, 0x6, 0xb0, 0x6a \ + } + +extern EFI_GUID gTpm2AcpiTableStorageGuid; + +#endif diff --git a/ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTables.inf b/ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTables.inf new file mode 100644 index 0000000..e6e03a4 --- /dev/null +++ b/ReferenceCode/ME/Ptt/Smm/Tpm2AcpiTables.inf @@ -0,0 +1,38 @@ +## @file +# Component description file for the ACPI tables +# +#@copyright +# Copyright (c) 2012 Intel Corporation. All rights reserved +# This software and associated documentation (if any) is furnished +# under a license and may only be used or copied in accordance +# with the terms of the license. Except as permitted by such +# license, no part of this software or documentation may be +# reproduced, stored in a retrieval system, or transmitted in any +# form or by any means without the express written consent of +# Intel Corporation. +# +# This file contains an 'Intel Peripheral Driver' and uniquely +# identified as "Intel Reference Module" and is +# licensed for Intel CPUs and chipsets under the terms of your +# license agreement with Intel or your vendor. This file may +# be modified by the user, subject to additional terms of the +# license agreement +# + +[defines] +BASE_NAME = Tpm2AcpiTables +FILE_GUID = 7D279373-EECC-4d4f-AE2F-CEC4B706B06A +COMPONENT_TYPE = ACPITABLE +FFS_EXT = .ffs + +[sources.common] + Ftpm.ASL + +[libraries.common] + +[includes.common] + . + $(EFI_SOURCE) + $(EFI_SOURCE)\Include + +[nmake.common] |