From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048571243151.27594227550674; Thu, 9 Mar 2017 00:36:11 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 067D18038C; Thu, 9 Mar 2017 00:36:09 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C1A1E80289 for ; Thu, 9 Mar 2017 00:36:07 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:07 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:06 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930897" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:43 +0800 Message-Id: <20170309083553.6016-2-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 01/11] UefiCpuPkg/AcpiCpuData: Update RegisterTableEntry type X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current RegisterTableEntry filed in CPU_REGISTER_TABLE is one pointer to CPU_REGISTER_TABLE_ENTRY. If CPU register table wants to be passed from 32b= it PEI to x64 DXE/SMM, x64 DXE/SMM cannot get the correct RegisterTableEntry. This update is to update RegisterTableEntry type to EFI_PHYSICAL_ADDRESS and make RegisterTableEntry is fixed length. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c | 6 +++--- UefiCpuPkg/Include/AcpiCpuData.h | 6 +++--- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c b/UefiCpuPkg/CpuS3DataDxe/= CpuS3Data.c index 3489b95..07c7102 100644 --- a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c +++ b/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c @@ -9,7 +9,7 @@ number of CPUs reported by the MP Services Protocol, so thi= s module does not support hot plug CPUs. This module can be copied into a CPU specific pack= age and customized if these additional features are required. =20 -Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.
Copyright (c) 2015, Red Hat, Inc. =20 This program and the accompanying materials @@ -246,12 +246,12 @@ CpuS3DataInitialize ( RegisterTable[Index].InitialApicId =3D (UINT32)ProcessorInfoBuffe= r.ProcessorId; RegisterTable[Index].TableLength =3D 0; RegisterTable[Index].AllocatedSize =3D 0; - RegisterTable[Index].RegisterTableEntry =3D NULL; + RegisterTable[Index].RegisterTableEntry =3D 0; =20 RegisterTable[NumberOfCpus + Index].InitialApicId =3D (UINT32)Pro= cessorInfoBuffer.ProcessorId; RegisterTable[NumberOfCpus + Index].TableLength =3D 0; RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; - RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D NULL; + RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; } AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Re= gisterTable; AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(R= egisterTable + NumberOfCpus); diff --git a/UefiCpuPkg/Include/AcpiCpuData.h b/UefiCpuPkg/Include/AcpiCpuD= ata.h index 12e9692..130eb90 100644 --- a/UefiCpuPkg/Include/AcpiCpuData.h +++ b/UefiCpuPkg/Include/AcpiCpuData.h @@ -1,7 +1,7 @@ /** @file Definitions for CPU S3 data. =20 -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2017, Intel Corporation. All rights reserved.
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 @@ -55,10 +55,10 @@ typedef struct { // UINT32 InitialApicId; // - // Buffer of CPU_REGISTER_TABLE_ENTRY structures. This buffer must be + // Physical address of CPU_REGISTER_TABLE_ENTRY structures. This buffer= must be // allocated below 4GB from memory of type EfiACPIMemoryNVS. // - CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry; + EFI_PHYSICAL_ADDRESS RegisterTableEntry; } CPU_REGISTER_TABLE; =20 // diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/= CpuS3.c index 532b7c4..12efc1f 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -1,7 +1,7 @@ /** @file Code for Processor S3 restoration =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
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 @@ -826,13 +826,12 @@ CopyRegisterTable ( =20 CopyMem (DestinationRegisterTableList, SourceRegisterTableList, NumberOf= Cpus * sizeof (CPU_REGISTER_TABLE)); for (Index =3D 0; Index < NumberOfCpus; Index++) { - DestinationRegisterTableList[Index].RegisterTableEntry =3D AllocatePoo= l (DestinationRegisterTableList[Index].AllocatedSize); - ASSERT (DestinationRegisterTableList[Index].RegisterTableEntry !=3D NU= LL); - CopyMem (DestinationRegisterTableList[Index].RegisterTableEntry, Sourc= eRegisterTableList[Index].RegisterTableEntry, DestinationRegisterTableList[= Index].AllocatedSize); + RegisterTableEntry =3D AllocatePool (DestinationRegisterTableList[Inde= x].AllocatedSize); + ASSERT (RegisterTableEntry !=3D NULL); + CopyMem (RegisterTableEntry, (VOID *)(UINTN)SourceRegisterTableList[In= dex].RegisterTableEntry, DestinationRegisterTableList[Index].AllocatedSize); // // Go though all MSRs in register table to initialize MSR spin lock // - RegisterTableEntry =3D DestinationRegisterTableList[Index].RegisterTab= leEntry; for (Index1 =3D 0; Index1 < DestinationRegisterTableList[Index].TableL= ength; Index1++, RegisterTableEntry++) { if ((RegisterTableEntry->RegisterType =3D=3D Msr) && (RegisterTableE= ntry->ValidBitLength < 64)) { // @@ -841,6 +840,7 @@ CopyRegisterTable ( InitMsrSpinLockByIndex (RegisterTableEntry->Index); } } + DestinationRegisterTableList[Index].RegisterTableEntry =3D (EFI_PHYSIC= AL_ADDRESS)(UINTN)RegisterTableEntry; } } =20 --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 14890485735081003.9734283709498; Thu, 9 Mar 2017 00:36:13 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 379588038B; Thu, 9 Mar 2017 00:36:11 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3DA2C80390 for ; Thu, 9 Mar 2017 00:36:09 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:09 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:07 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930903" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:44 +0800 Message-Id: <20170309083553.6016-3-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 02/11] UefiCpuPkg/CpuS3DataDxe: Consume the existing PcdCpuS3DataAddress X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If PCD PcdCpuS3DataAddress is set before, CpuS3DataDxe should get RegisterT= able and PreSmmRegisterTable from existing PCD pointed buffer and needn't to all= ocate new buffer for RegisterTable and PreSmmRegisterTable. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c | 54 ++++++++++++++++++++++-----------= ---- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c b/UefiCpuPkg/CpuS3DataDxe/= CpuS3Data.c index 07c7102..dccb406 100644 --- a/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c +++ b/UefiCpuPkg/CpuS3DataDxe/CpuS3Data.c @@ -160,12 +160,18 @@ CpuS3DataInitialize ( VOID *Gdt; VOID *Idt; EFI_EVENT Event; + ACPI_CPU_DATA *OldAcpiCpuData; =20 if (!PcdGetBool (PcdAcpiS3Enable)) { return EFI_UNSUPPORTED; } =20 // + // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA stru= cture + // + OldAcpiCpuData =3D (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddre= ss); + + // // Allocate ACPI NVS memory below 4G memory for use on ACPI S3 resume. // AcpiCpuDataEx =3D AllocateAcpiNvsMemoryBelow4G (sizeof (ACPI_CPU_DATA_EX= )); @@ -229,32 +235,38 @@ CpuS3DataInitialize ( AcpiCpuDataEx->GdtrProfile.Base =3D (UINTN)Gdt; AcpiCpuDataEx->IdtrProfile.Base =3D (UINTN)Idt; =20 - // - // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable f= or all CPUs - // - TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); - RegisterTable =3D (CPU_REGISTER_TABLE *)AllocateAcpiNvsMemoryBelow4G (Ta= bleSize); - ASSERT (RegisterTable !=3D NULL); - for (Index =3D 0; Index < NumberOfCpus; Index++) { - Status =3D MpServices->GetProcessorInfo ( + if (OldAcpiCpuData !=3D NULL) { + AcpiCpuData->RegisterTable =3D OldAcpiCpuData->RegisterTable; + AcpiCpuData->PreSmmInitRegisterTable =3D OldAcpiCpuData->PreSmmInitReg= isterTable; + } else { + // + // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable= for all CPUs + // + TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); + RegisterTable =3D (CPU_REGISTER_TABLE *)AllocateAcpiNvsMemoryBelow4G (= TableSize); + ASSERT (RegisterTable !=3D NULL); + + for (Index =3D 0; Index < NumberOfCpus; Index++) { + Status =3D MpServices->GetProcessorInfo ( MpServices, Index, &ProcessorInfoBuffer ); - ASSERT_EFI_ERROR (Status); - - RegisterTable[Index].InitialApicId =3D (UINT32)ProcessorInfoBuffe= r.ProcessorId; - RegisterTable[Index].TableLength =3D 0; - RegisterTable[Index].AllocatedSize =3D 0; - RegisterTable[Index].RegisterTableEntry =3D 0; - - RegisterTable[NumberOfCpus + Index].InitialApicId =3D (UINT32)Pro= cessorInfoBuffer.ProcessorId; - RegisterTable[NumberOfCpus + Index].TableLength =3D 0; - RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; - RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; + ASSERT_EFI_ERROR (Status); + + RegisterTable[Index].InitialApicId =3D (UINT32)ProcessorInfoBuf= fer.ProcessorId; + RegisterTable[Index].TableLength =3D 0; + RegisterTable[Index].AllocatedSize =3D 0; + RegisterTable[Index].RegisterTableEntry =3D 0; + + RegisterTable[NumberOfCpus + Index].InitialApicId =3D (UINT32)P= rocessorInfoBuffer.ProcessorId; + RegisterTable[NumberOfCpus + Index].TableLength =3D 0; + RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; + RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; + } + AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= RegisterTable; + AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= (RegisterTable + NumberOfCpus); } - AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Re= gisterTable; - AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(R= egisterTable + NumberOfCpus); =20 // // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA stru= cture --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048576333198.03211823359788; Thu, 9 Mar 2017 00:36:16 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 69FC380393; Thu, 9 Mar 2017 00:36:11 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9CA7680390 for ; Thu, 9 Mar 2017 00:36:10 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:10 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:09 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930908" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:45 +0800 Message-Id: <20170309083553.6016-4-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 03/11] UefiCpuPkg/PiSmmCpuDxeSmm: Skip if AllocatedSize is 0 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Needn't to copy register table if AllocatedSize is 0. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/= CpuS3.c index 12efc1f..f24d3d7 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -826,18 +826,20 @@ CopyRegisterTable ( =20 CopyMem (DestinationRegisterTableList, SourceRegisterTableList, NumberOf= Cpus * sizeof (CPU_REGISTER_TABLE)); for (Index =3D 0; Index < NumberOfCpus; Index++) { - RegisterTableEntry =3D AllocatePool (DestinationRegisterTableList[Inde= x].AllocatedSize); - ASSERT (RegisterTableEntry !=3D NULL); - CopyMem (RegisterTableEntry, (VOID *)(UINTN)SourceRegisterTableList[In= dex].RegisterTableEntry, DestinationRegisterTableList[Index].AllocatedSize); - // - // Go though all MSRs in register table to initialize MSR spin lock - // - for (Index1 =3D 0; Index1 < DestinationRegisterTableList[Index].TableL= ength; Index1++, RegisterTableEntry++) { - if ((RegisterTableEntry->RegisterType =3D=3D Msr) && (RegisterTableE= ntry->ValidBitLength < 64)) { - // - // Initialize MSR spin lock only for those MSRs need bit field wri= ting - // - InitMsrSpinLockByIndex (RegisterTableEntry->Index); + if (DestinationRegisterTableList[Index].AllocatedSize !=3D 0) { + RegisterTableEntry =3D AllocatePool (DestinationRegisterTableList[In= dex].AllocatedSize); + ASSERT (RegisterTableEntry !=3D NULL); + CopyMem (RegisterTableEntry, (VOID *)(UINTN)SourceRegisterTableList[= Index].RegisterTableEntry, DestinationRegisterTableList[Index].AllocatedSiz= e); + // + // Go though all MSRs in register table to initialize MSR spin lock + // + for (Index1 =3D 0; Index1 < DestinationRegisterTableList[Index].Tabl= eLength; Index1++, RegisterTableEntry++) { + if ((RegisterTableEntry->RegisterType =3D=3D Msr) && (RegisterTabl= eEntry->ValidBitLength < 64)) { + // + // Initialize MSR spin lock only for those MSRs need bit field w= riting + // + InitMsrSpinLockByIndex (RegisterTableEntry->Index); + } } } DestinationRegisterTableList[Index].RegisterTableEntry =3D (EFI_PHYSIC= AL_ADDRESS)(UINTN)RegisterTableEntry; --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048578619672.1796955351521; Thu, 9 Mar 2017 00:36:18 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9EB6C80392; Thu, 9 Mar 2017 00:36:13 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3369680396 for ; Thu, 9 Mar 2017 00:36:12 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:12 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:10 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930916" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:46 +0800 Message-Id: <20170309083553.6016-5-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 04/11] UefiCpuPkg/Msr: Add CPUID signature check MACROs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" All model-specific MSRs are related to processor signatures that are define= d in each section in Chapter 35 Model-Specific-Registers (MSR), Intel(R) 64 and IA-32 Architectures Software Developer's Manual, Volume 3, September 2016. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/Include/Register/Msr/AtomMsr.h | 22 ++++++++++++++++++++= +- UefiCpuPkg/Include/Register/Msr/BroadwellMsr.h | 21 ++++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/Core2Msr.h | 19 ++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/CoreMsr.h | 18 +++++++++++++++++- UefiCpuPkg/Include/Register/Msr/GoldmontMsr.h | 18 +++++++++++++++++- UefiCpuPkg/Include/Register/Msr/HaswellEMsr.h | 18 +++++++++++++++++- UefiCpuPkg/Include/Register/Msr/HaswellMsr.h | 20 +++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/IvyBridgeMsr.h | 18 +++++++++++++++++- UefiCpuPkg/Include/Register/Msr/NehalemMsr.h | 21 ++++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/P6Msr.h | 23 ++++++++++++++++++++= ++- UefiCpuPkg/Include/Register/Msr/Pentium4Msr.h | 15 ++++++++++++++- UefiCpuPkg/Include/Register/Msr/PentiumMMsr.h | 18 +++++++++++++++++- UefiCpuPkg/Include/Register/Msr/PentiumMsr.h | 20 +++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/SandyBridgeMsr.h | 19 ++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/SilvermontMsr.h | 22 ++++++++++++++++++++= +- UefiCpuPkg/Include/Register/Msr/SkylakeMsr.h | 19 ++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/Xeon5600Msr.h | 19 ++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/XeonDMsr.h | 19 ++++++++++++++++++- UefiCpuPkg/Include/Register/Msr/XeonE7Msr.h | 18 +++++++++++++++++- UefiCpuPkg/Include/Register/Msr/XeonPhiMsr.h | 18 +++++++++++++++++- 20 files changed, 365 insertions(+), 20 deletions(-) diff --git a/UefiCpuPkg/Include/Register/Msr/AtomMsr.h b/UefiCpuPkg/Include= /Register/Msr/AtomMsr.h index c314195..b276469 100644 --- a/UefiCpuPkg/Include/Register/Msr/AtomMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/AtomMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,26 @@ #include =20 /** + Is Intel(R) Atom(TM) Processor Family? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_ATOM_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x1C || \ + DisplayModel =3D=3D 0x26 || \ + DisplayModel =3D=3D 0x27 || \ + DisplayModel =3D=3D 0x35 || \ + DisplayModel =3D=3D 0x36 \ + ) \ + ) + +/** Shared. Model Specific Platform ID (R). =20 @param ECX MSR_ATOM_PLATFORM_ID (0x00000017) diff --git a/UefiCpuPkg/Include/Register/Msr/BroadwellMsr.h b/UefiCpuPkg/In= clude/Register/Msr/BroadwellMsr.h index 1c3c2dc..90bd523 100644 --- a/UefiCpuPkg/Include/Register/Msr/BroadwellMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/BroadwellMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,25 @@ #include =20 /** + Is Intel processors based on the Broadwell microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_BROADWELL_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x3D || \ + DisplayModel =3D=3D 0x47 || \ + DisplayModel =3D=3D 0x4F || \ + DisplayModel =3D=3D 0x56 \ + ) \ + ) + +/** Thread. See Table 35-2. See Section 18.4.2, "Global Counter Control Facilities.". =20 diff --git a/UefiCpuPkg/Include/Register/Msr/Core2Msr.h b/UefiCpuPkg/Includ= e/Register/Msr/Core2Msr.h index 9f0e790..9ebca5e 100644 --- a/UefiCpuPkg/Include/Register/Msr/Core2Msr.h +++ b/UefiCpuPkg/Include/Register/Msr/Core2Msr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,23 @@ #include =20 /** + Is Intel(R) Core(TM) 2 Processor Family? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_CORE2_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x0F || \ + DisplayModel =3D=3D 0x17 \ + ) \ + ) + +/** Shared. Model Specific Platform ID (R). =20 @param ECX MSR_CORE2_PLATFORM_ID (0x00000017) diff --git a/UefiCpuPkg/Include/Register/Msr/CoreMsr.h b/UefiCpuPkg/Include= /Register/Msr/CoreMsr.h index 0902aa9..4897c74 100644 --- a/UefiCpuPkg/Include/Register/Msr/CoreMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/CoreMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Intel Core Solo and Intel Core Duo Processors? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_CORE_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x0E \ + ) \ + ) + +/** Unique. See Section 35.22, "MSRs in Pentium Processors," and see Table 3= 5-2. =20 @param ECX MSR_CORE_P5_MC_ADDR (0x00000000) diff --git a/UefiCpuPkg/Include/Register/Msr/GoldmontMsr.h b/UefiCpuPkg/Inc= lude/Register/Msr/GoldmontMsr.h index 58b9c57..5730918 100644 --- a/UefiCpuPkg/Include/Register/Msr/GoldmontMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/GoldmontMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Intel Atom processors based on the Goldmont microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_GOLDMONT_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x5C \ + ) \ + ) + +/** Core. Control Features in Intel 64Processor (R/W). =20 @param ECX MSR_GOLDMONT_FEATURE_CONTROL (0x0000003A) diff --git a/UefiCpuPkg/Include/Register/Msr/HaswellEMsr.h b/UefiCpuPkg/Inc= lude/Register/Msr/HaswellEMsr.h index 7b190b5..b737a9e 100644 --- a/UefiCpuPkg/Include/Register/Msr/HaswellEMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/HaswellEMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Intel processors based on the Haswell-E microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_HASWELL_E_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x3F \ + ) \ + ) + +/** Package. Configured State of Enabled Processor Core Count and Logical Processor Count (RO) - After a Power-On RESET, enumerates factory configuration of the number of processor cores and logical processors in= the diff --git a/UefiCpuPkg/Include/Register/Msr/HaswellMsr.h b/UefiCpuPkg/Incl= ude/Register/Msr/HaswellMsr.h index 8bf2c38..3cd1584 100644 --- a/UefiCpuPkg/Include/Register/Msr/HaswellMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/HaswellMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,24 @@ #include =20 /** + Is Intel processors based on the Haswell microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_HASWELL_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x3C || \ + DisplayModel =3D=3D 0x45 || \ + DisplayModel =3D=3D 0x46 \ + ) \ + ) + +/** Package. =20 @param ECX MSR_HASWELL_PLATFORM_INFO (0x000000CE) diff --git a/UefiCpuPkg/Include/Register/Msr/IvyBridgeMsr.h b/UefiCpuPkg/In= clude/Register/Msr/IvyBridgeMsr.h index 41cbd2e..9eb0799 100644 --- a/UefiCpuPkg/Include/Register/Msr/IvyBridgeMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/IvyBridgeMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Intel processors based on the Ivy Bridge microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_IVY_BRIDGE_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x3A \ + ) \ + ) + +/** Package. See http://biosbits.org. =20 @param ECX MSR_IVY_BRIDGE_PLATFORM_INFO (0x000000CE) diff --git a/UefiCpuPkg/Include/Register/Msr/NehalemMsr.h b/UefiCpuPkg/Incl= ude/Register/Msr/NehalemMsr.h index 20e60df..94aebba 100644 --- a/UefiCpuPkg/Include/Register/Msr/NehalemMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/NehalemMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,25 @@ #include =20 /** + Is Intel processors based on the Nehalem microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_NEHALEM_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x1A || \ + DisplayModel =3D=3D 0x1E || \ + DisplayModel =3D=3D 0x1F || \ + DisplayModel =3D=3D 0x2E \ + ) \ + ) + +/** Package. Model Specific Platform ID (R). =20 @param ECX MSR_NEHALEM_PLATFORM_ID (0x00000017) diff --git a/UefiCpuPkg/Include/Register/Msr/P6Msr.h b/UefiCpuPkg/Include/R= egister/Msr/P6Msr.h index ef90800..aec2e2c 100644 --- a/UefiCpuPkg/Include/Register/Msr/P6Msr.h +++ b/UefiCpuPkg/Include/Register/Msr/P6Msr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,27 @@ #include =20 /** + Is P6 Family Processors? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_P6_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x03 || \ + DisplayModel =3D=3D 0x05 || \ + DisplayModel =3D=3D 0x07 || \ + DisplayModel =3D=3D 0x08 || \ + DisplayModel =3D=3D 0x0A || \ + DisplayModel =3D=3D 0x0B \ + ) \ + ) + +/** See Section 35.22, "MSRs in Pentium Processors.". =20 @param ECX MSR_P6_P5_MC_ADDR (0x00000000) diff --git a/UefiCpuPkg/Include/Register/Msr/Pentium4Msr.h b/UefiCpuPkg/Inc= lude/Register/Msr/Pentium4Msr.h index 6cf68b2..8922d56 100644 --- a/UefiCpuPkg/Include/Register/Msr/Pentium4Msr.h +++ b/UefiCpuPkg/Include/Register/Msr/Pentium4Msr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,19 @@ #include =20 /** + Is Pentium(R) 4 Processors? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_PENTIUM_4_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x0F \ + ) + +/** 3, 4, 6. Shared. See Section 8.10.5, "Monitor/Mwait Address Range Determination.". =20 diff --git a/UefiCpuPkg/Include/Register/Msr/PentiumMMsr.h b/UefiCpuPkg/Inc= lude/Register/Msr/PentiumMMsr.h index 294a381..70d54c8 100644 --- a/UefiCpuPkg/Include/Register/Msr/PentiumMMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/PentiumMMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Pentium M Processors? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_PENTIUM_M_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x0D \ + ) \ + ) + +/** See Section 35.22, "MSRs in Pentium Processors.". =20 @param ECX MSR_PENTIUM_M_P5_MC_ADDR (0x00000000) diff --git a/UefiCpuPkg/Include/Register/Msr/PentiumMsr.h b/UefiCpuPkg/Incl= ude/Register/Msr/PentiumMsr.h index cd846ea..9b2578b 100644 --- a/UefiCpuPkg/Include/Register/Msr/PentiumMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/PentiumMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,24 @@ #include =20 /** + Is Pentium Processors? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_PENTIUM_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x05 && \ + ( \ + DisplayModel =3D=3D 0x01 || \ + DisplayModel =3D=3D 0x02 || \ + DisplayModel =3D=3D 0x04 \ + ) \ + ) + +/** See Section 15.10.2, "Pentium Processor Machine-Check Exception Handling= .". =20 @param ECX MSR_PENTIUM_P5_MC_ADDR (0x00000000) diff --git a/UefiCpuPkg/Include/Register/Msr/SandyBridgeMsr.h b/UefiCpuPkg/= Include/Register/Msr/SandyBridgeMsr.h index 1819ecb..c8a0b97 100644 --- a/UefiCpuPkg/Include/Register/Msr/SandyBridgeMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/SandyBridgeMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,23 @@ #include =20 /** + Is Intel processors based on the Sandy Bridge microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_SANDY_BRIDGE_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x2A || \ + DisplayModel =3D=3D 0x2D \ + ) \ + ) + +/** Thread. SMI Counter (R/O). =20 @param ECX MSR_SANDY_BRIDGE_SMI_COUNT (0x00000034) diff --git a/UefiCpuPkg/Include/Register/Msr/SilvermontMsr.h b/UefiCpuPkg/I= nclude/Register/Msr/SilvermontMsr.h index b3b6b76..ec09bf3 100644 --- a/UefiCpuPkg/Include/Register/Msr/SilvermontMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/SilvermontMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,26 @@ #include =20 /** + Is Intel processors based on the Silvermont microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_SILVERMONT_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x37 || \ + DisplayModel =3D=3D 0x4A || \ + DisplayModel =3D=3D 0x4D || \ + DisplayModel =3D=3D 0x5A || \ + DisplayModel =3D=3D 0x5D \ + ) \ + ) + +/** Module. Model Specific Platform ID (R). =20 @param ECX MSR_SILVERMONT_PLATFORM_ID (0x00000017) diff --git a/UefiCpuPkg/Include/Register/Msr/SkylakeMsr.h b/UefiCpuPkg/Incl= ude/Register/Msr/SkylakeMsr.h index 23ca3e1..7166e5f 100644 --- a/UefiCpuPkg/Include/Register/Msr/SkylakeMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/SkylakeMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,23 @@ #include =20 /** + Is Intel processors based on the Skylake microarchitecture? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_SKYLAKE_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x4E || \ + DisplayModel =3D=3D 0x5E \ + ) \ + ) + +/** Package. Maximum Ratio Limit of Turbo Mode RO if MSR_PLATFORM_INFO.[28] = =3D 0, RW if MSR_PLATFORM_INFO.[28] =3D 1. =20 diff --git a/UefiCpuPkg/Include/Register/Msr/Xeon5600Msr.h b/UefiCpuPkg/Inc= lude/Register/Msr/Xeon5600Msr.h index ea22e22..ad7128a 100644 --- a/UefiCpuPkg/Include/Register/Msr/Xeon5600Msr.h +++ b/UefiCpuPkg/Include/Register/Msr/Xeon5600Msr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,23 @@ #include =20 /** + Is Intel(R) Xeon(R) Processor Series 5600? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_XEON_5600_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x25 || \ + DisplayModel =3D=3D 0x2C \ + ) \ + ) + +/** Core. AES Configuration (RW-L) Privileged post-BIOS agent must provide a= #GP handler to handle unsuccessful read of this MSR. =20 diff --git a/UefiCpuPkg/Include/Register/Msr/XeonDMsr.h b/UefiCpuPkg/Includ= e/Register/Msr/XeonDMsr.h index 5e7e13a..7b31288 100644 --- a/UefiCpuPkg/Include/Register/Msr/XeonDMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/XeonDMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,23 @@ #include =20 /** + Is Intel(R) Xeon(R) Processor D product Family? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_XEON_D_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x4F || \ + DisplayModel =3D=3D 0x56 \ + ) \ + ) + +/** Package. Protected Processor Inventory Number Enable Control (R/W). =20 @param ECX MSR_XEON_D_PPIN_CTL (0x0000004E) diff --git a/UefiCpuPkg/Include/Register/Msr/XeonE7Msr.h b/UefiCpuPkg/Inclu= de/Register/Msr/XeonE7Msr.h index d14ef21..d509660 100644 --- a/UefiCpuPkg/Include/Register/Msr/XeonE7Msr.h +++ b/UefiCpuPkg/Include/Register/Msr/XeonE7Msr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Intel(R) Xeon(R) Processor E7 Family? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_XEON_E7_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x2F \ + ) \ + ) + +/** Core. AES Configuration (RW-L) Privileged post-BIOS agent must provide a= #GP handler to handle unsuccessful read of this MSR. =20 diff --git a/UefiCpuPkg/Include/Register/Msr/XeonPhiMsr.h b/UefiCpuPkg/Incl= ude/Register/Msr/XeonPhiMsr.h index 853d83b..43354d1 100644 --- a/UefiCpuPkg/Include/Register/Msr/XeonPhiMsr.h +++ b/UefiCpuPkg/Include/Register/Msr/XeonPhiMsr.h @@ -6,7 +6,7 @@ returned is a single 32-bit or 64-bit value, then a data structure is not provided for that MSR. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -27,6 +27,22 @@ #include =20 /** + Is Intel(R) Xeon(R) Phi(TM) processor Family? + + @param DisplayFamily Display Family ID + @param DisplayModel Display Model ID + + @retval TRUE Yes, it is. + @retval FALSE No, it isn't. +**/ +#define IS_XEON_PHI_PROCESSOR(DisplayFamily, DisplayModel) \ + (DisplayFamily =3D=3D 0x06 && \ + ( \ + DisplayModel =3D=3D 0x57 \ + ) \ + ) + +/** Thread. SMI Counter (R/O). =20 @param ECX MSR_XEON_PHI_SMI_COUNT (0x00000034) --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048582560383.3620283981911; Thu, 9 Mar 2017 00:36:22 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 033D78039C; Thu, 9 Mar 2017 00:36:15 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D317580399 for ; Thu, 9 Mar 2017 00:36:13 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:13 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:12 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930927" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:47 +0800 Message-Id: <20170309083553.6016-6-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 05/11] UefiCpuPkg/UefiCpuPkg.dec: Add a set of CPU features PCDs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" PcdCpuFeaturesSupport supports PcdsFixedAtBuild/PcdsPatchableInModule types= and used to add/remove CPU feature from firmware during build time. PcdCpuFeaturesUserConfiguration supports all PCD types and used to configur= ate CPU features by platforms. PcdCpuFeaturesCapability supports PcdsDynamic PCD and used to indicate the = CPU features capability on processors. PcdCpuFeaturesSetting supports PcdsDynamic PCD and used to indicate the cur= rent CPU features setting on processors. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/UefiCpuPkg.dec | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index c37b4d5..c4b43e2 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -1,7 +1,7 @@ ## @file UefiCpuPkg.dec # This Package provides UEFI compatible CPU modules and libraries. # -# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
# # This program and the accompanying materials are licensed and made availa= ble under # the terms and conditions of the BSD License which accompanies this distr= ibution. @@ -181,6 +181,10 @@ # @Prompt MSEG size. gUefiCpuPkgTokenSpaceGuid.PcdCpuMsegSize|0x200000|UINT32|0x32132112 =20 + ## Specifies the supported CPU features bit in array + # @Prompt Supported CPU features + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSupport|{0xFF, 0xFF, 0xFF, 0xFF,= 0xFF, 0xFF, 0xFF, 0xFF}|VOID*|0x00000016 + [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] ## Specifies max supported number of Logical Processors. # @Prompt Configure max supported number of Logical Processors @@ -226,6 +230,10 @@ # @Prompt SMM CPU Synchronization Method. gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode|0x00|UINT8|0x60000014 =20 + ## Specifies user's desired settings for enabling/disabling processor fe= atures. + # @Prompt User settings for enabling/disabling processor features. + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesUserConfiguration|{0x00, 0x00, 0= x00, 0x00, 0x00, 0x00, 0x00, 0x00}|VOID*|0x00000017 + [PcdsDynamic, PcdsDynamicEx] ## Contains the pointer to a CPU S3 data buffer of structure ACPI_CPU_DA= TA. # @Prompt The pointer to a CPU S3 data buffer. @@ -237,5 +245,15 @@ # @ValidList 0x80000001 | 0 gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugDataAddress|0x0|UINT64|0x60000011 =20 + ## Indicates processor feature capabilities, each bit corresponding to a= specific feature. + # @Prompt Processor feature capabilities. + # @ValidList 0x80000001 | 0 + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesCapability|{0x00, 0x00, 0x00, 0x= 00, 0x00, 0x00, 0x00, 0x00}|VOID*|0x00000018 + + ## Specifies actual settings for processor features, each bit correspond= ing to a specific feature. + # @Prompt Actual processor feature settings. + # @ValidList 0x80000001 | 0 + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSetting|{0x00, 0x00, 0x00, 0x00,= 0x00, 0x00, 0x00, 0x00}|VOID*|0x00000019 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 14890485862311012.6925808617918; Thu, 9 Mar 2017 00:36:26 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 35ACA8039F; Thu, 9 Mar 2017 00:36:16 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 661188039F for ; Thu, 9 Mar 2017 00:36:15 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:15 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:13 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930936" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:48 +0800 Message-Id: <20170309083553.6016-7-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 06/11] UefiCpuPkg: Add GUID gEdkiiCpuFeaturesSetDoneGuid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" GUID gEdkiiCpuFeaturesSetDoneGuid is used to indicate if CPU feature related setting are set finished. For example, PCD PcdCpuFeaturesUserConfiguration. On PEI phase, one gEdkiiCpuFeaturesSetDoneGuid PPI will be installed after platform set CPU feature setting. On DXE phase, one gEdkiiCpuFeaturesSetDoneGuid Protocol will be installed a= fter platform set CPU feature setting. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/Include/Guid/CpuFeaturesSetDone.h | 26 ++++++++++++++++++++++++= ++ UefiCpuPkg/UefiCpuPkg.dec | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 UefiCpuPkg/Include/Guid/CpuFeaturesSetDone.h diff --git a/UefiCpuPkg/Include/Guid/CpuFeaturesSetDone.h b/UefiCpuPkg/Incl= ude/Guid/CpuFeaturesSetDone.h new file mode 100644 index 0000000..8b1592e --- /dev/null +++ b/UefiCpuPkg/Include/Guid/CpuFeaturesSetDone.h @@ -0,0 +1,26 @@ +/** @file + CPU Features Set Done PPI/Protocol should be installed after CPU features + configuration are set. + +Copyright (c) 2016, Intel Corporation. All rights reserved.
+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 IMPLI= ED. + +**/ + +#ifndef _CPU_FEATURES_INIT_DONE_H_ +#define _CPU_FEATURES_INIT_DONE_H_ + +#define EDKII_CPU_FEATURES_SET_DONE_GUID \ + { \ + { 0xa82485ce, 0xad6b, 0x4101, { 0x99, 0xd3, 0xe1, 0x35, 0x8c, 0x9e, 0x= 7e, 0x37 } \ + } + +extern EFI_GUID gEdkiiCpuFeaturesSetDoneGuid; + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index c4b43e2..1443e82 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -65,6 +65,9 @@ ## Include/Guid/MicrocodeFmp.h gMicrocodeFmpImageTypeIdGuid =3D { 0x96d4fdcd, 0x1502, 0x424d, { 0x= 9d, 0x4c, 0x9b, 0x12, 0xd2, 0xdc, 0xae, 0x5c } } =20 + ## Include/Guid/CpuFeaturesSetDone.h + gEdkiiCpuFeaturesSetDoneGuid =3D { 0xa82485ce, 0xad6b, 0x4101, { 0x99,= 0xd3, 0xe1, 0x35, 0x8c, 0x9e, 0x7e, 0x37 }} + [Protocols] ## Include/Protocol/SmmCpuService.h gEfiSmmCpuServiceProtocolGuid =3D { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94,= 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048587846264.34164301917053; Thu, 9 Mar 2017 00:36:27 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6C11E80399; Thu, 9 Mar 2017 00:36:20 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3DBA680289 for ; Thu, 9 Mar 2017 00:36:19 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:19 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:15 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930951" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:49 +0800 Message-Id: <20170309083553.6016-8-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 07/11] UefiCpuPkg: Add GUID gEdkiiCpuFeaturesInitDoneGuid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" GUID gEdkiiCpuFeaturesInitDoneGuid is used to indicate if CPU features have= been initialized. On PEI phase, one gEdkiiCpuFeaturesInitDoneGuid PPI will be installed after= CPU features initialized. On DXE phase, one gEdkiiCpuFeaturesInitDoneGuid Protocol will be installed = after CPU features initialized. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/Include/Guid/CpuFeaturesInitDone.h | 26 +++++++++++++++++++++++= +++ UefiCpuPkg/UefiCpuPkg.dec | 3 +++ 2 files changed, 29 insertions(+) create mode 100644 UefiCpuPkg/Include/Guid/CpuFeaturesInitDone.h diff --git a/UefiCpuPkg/Include/Guid/CpuFeaturesInitDone.h b/UefiCpuPkg/Inc= lude/Guid/CpuFeaturesInitDone.h new file mode 100644 index 0000000..ef17da5 --- /dev/null +++ b/UefiCpuPkg/Include/Guid/CpuFeaturesInitDone.h @@ -0,0 +1,26 @@ +/** @file + CPU Features Init Done PPI/Protocol should be installed after CPU featur= es + are initialized. + +Copyright (c) 2016, Intel Corporation. All rights reserved.
+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 IMPLI= ED. + +**/ + +#ifndef _CPU_FEATURES_INIT_DONE_H_ +#define _CPU_FEATURES_INIT_DONE_H_ + +#define EDKII_CPU_FEATURES_INIT_DONE_GUID \ + { \ + { 0xc77c3a41, 0x61ab, 0x4143, { 0x98, 0x3e, 0x33, 0x39, 0x28, 0x6, 0x2= 8, 0xe5 } \ + } + +extern EFI_GUID gEdkiiCpuFeaturesInitDoneGuid; + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 1443e82..f7abe1c 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -68,6 +68,9 @@ ## Include/Guid/CpuFeaturesSetDone.h gEdkiiCpuFeaturesSetDoneGuid =3D { 0xa82485ce, 0xad6b, 0x4101, { 0x99,= 0xd3, 0xe1, 0x35, 0x8c, 0x9e, 0x7e, 0x37 }} =20 + ## Include/Guid/CpuFeaturesInitDone.h + gEdkiiCpuFeaturesInitDoneGuid =3D { 0xc77c3a41, 0x61ab, 0x4143, { 0x98,= 0x3e, 0x33, 0x39, 0x28, 0x6, 0x28, 0xe5 }} + [Protocols] ## Include/Protocol/SmmCpuService.h gEfiSmmCpuServiceProtocolGuid =3D { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94,= 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048591819406.53336667056533; Thu, 9 Mar 2017 00:36:31 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9E3B1803A5; Thu, 9 Mar 2017 00:36:21 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 834CB803A3 for ; Thu, 9 Mar 2017 00:36:20 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:20 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:18 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930965" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:50 +0800 Message-Id: <20170309083553.6016-9-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 08/11] UefiCpuPkg/Include/Library: Add Register CPU Features Library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Register CPU Features Library is used to register/manage/program CPU featur= es. NULL CPU features library instance could consume it register CPU features functions. CPU Feature module could consume this library to detect/analysis/program CPU features on BSP/APs. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- .../Include/Library/RegisterCpuFeaturesLib.h | 516 +++++++++++++++++= ++++ UefiCpuPkg/UefiCpuPkg.dec | 5 + 2 files changed, 521 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h diff --git a/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h b/UefiCpuP= kg/Include/Library/RegisterCpuFeaturesLib.h new file mode 100644 index 0000000..5b974e7 --- /dev/null +++ b/UefiCpuPkg/Include/Library/RegisterCpuFeaturesLib.h @@ -0,0 +1,516 @@ +/** @file + Register CPU Features Library to register and manage CPU features. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#ifndef __REGISTER_CPU_FEATURES_LIB_H__ +#define __REGISTER_CPU_FEATURES_LIB_H__ + +#include +#include +#include + +/// +/// Defines used to identify a CPU feature. The lower 16-bits are used to +/// identify a unique CPU feature and the value represents a bit number in +/// a bit mask. The upper 16-bits are bit mask values that are used as +/// modifiers of a CPU feature. When used in a list, the define value +/// CPU_FEATURE_END is used to terminate a list of CPU feature values. +/// @{ +#define CPU_FEATURE_AESNI 0 +#define CPU_FEATURE_TURBO_MODE 1 +#define CPU_FEATURE_MWAIT 2 +#define CPU_FEATURE_ACPI 3 +#define CPU_FEATURE_EIST 4 +#define CPU_FEATURE_XD 5 +#define CPU_FEATURE_FASTSTRINGS 6 +#define CPU_FEATURE_VMX 7 +#define CPU_FEATURE_SMX 8 +#define CPU_FEATURE_SENTER 9 +#define CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER 10 +#define CPU_FEATURE_LIMIT_CPUID_MAX_VAL 11 +#define CPU_FEATURE_MCE 12 +#define CPU_FEATURE_MCA 13 +#define CPU_FEATURE_MCG_CTL 14 +#define CPU_FEATURE_PENDING_BREAK 15 +#define CPU_FEATURE_C1E 16 +#define CPU_FEATURE_C1_AUTO_DEMOTION 17 +#define CPU_FEATURE_C3_AUTO_DEMOTION 18 +#define CPU_FEATURE_C1_AUTO_UNDEMOTION 19 +#define CPU_FEATURE_C3_AUTO_UNDEMOTION 20 +#define CPU_FEATURE_C_STATE 21 +#define CPU_FEATURE_TM 22 +#define CPU_FEATURE_TM2 23 +#define CPU_FEATURE_X2APIC 24 +#define CPU_FEATURE_RESERVED_25 25 +#define CPU_FEATURE_RESERVED_26 26 +#define CPU_FEATURE_RESERVED_27 27 +#define CPU_FEATURE_RESERVED_28 28 +#define CPU_FEATURE_RESERVED_29 29 +#define CPU_FEATURE_RESERVED_30 30 +#define CPU_FEATURE_RESERVED_31 31 + +#define CPU_FEATURE_L2_PREFETCHER (32+0) +#define CPU_FEATURE_L1_DATA_PREFETCHER (32+1) +#define CPU_FEATURE_HARDWARE_PREFETCHER (32+2) +#define CPU_FEATURE_ADJACENT_CACHE_LINE_PREFETCH (32+3) +#define CPU_FEATURE_DCU_PREFETCHER (32+4) +#define CPU_FEATURE_IP_PREFETCHER (32+5) +#define CPU_FEATURE_MLC_STREAMER_PREFETCHER (32+6) +#define CPU_FEATURE_MLC_SPATIAL_PREFETCHER (32+7) +#define CPU_FEATURE_THREE_STRICK_COUNTER (32+8) +#define CPU_FEATURE_APIC_TPR_UPDATE_MESSAGE (32+9) +#define CPU_FEATURE_ENERGY_PERFORMANCE_BIAS (32+10) + +#define CPU_FEATURE_BEFORE_ALL BIT27 +#define CPU_FEATURE_AFTER_ALL BIT28 +#define CPU_FEATURE_BEFORE BIT29 +#define CPU_FEATURE_AFTER BIT30 +#define CPU_FEATURE_END MAX_UINT32 +/// @} + +/// +/// CPU Information passed into the SupportFunc and InitializeFunc of the +/// RegisterCpuFeature() library function. This structure contains inform= ation +/// that is commonly used during CPU feature detection and initialization. +/// +typedef struct { + /// + /// The package that the CPU resides + /// + EFI_PROCESSOR_INFORMATION ProcessorInfo; + /// + /// The Display Family of the CPU computed from CPUID leaf CPUID_VERSION= _INFO + /// + UINT32 DisplayFamily; + /// + /// The Display Model of the CPU computed from CPUID leaf CPUID_VERSION_= INFO + /// + UINT32 DisplayModel; + /// + /// The Stepping ID of the CPU computed from CPUID leaf CPUID_VERSION_IN= FO + /// + UINT32 SteppingId; + /// + /// The Processor Type of the CPU computed from CPUID leaf CPUID_VERSION= _INFO + /// + UINT32 ProcessorType; + /// + /// Bit field structured returned in ECX from CPUID leaf CPUID_VERSION_I= NFO + /// + CPUID_VERSION_INFO_ECX CpuIdVersionInfoEcx; + /// + /// Bit field structured returned in EDX from CPUID leaf CPUID_VERSION_I= NFO + /// + CPUID_VERSION_INFO_EDX CpuIdVersionInfoEdx; +} REGISTER_CPU_FEATURE_INFORMATION; + +/** + Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask. + If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/= data + associated with that feature should be optimized away if compiler + optimizations are enabled. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesSupport. + + @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureSupported ( + IN UINT32 Feature + ); + +/** + Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesSetting. + + @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureInSetting ( + IN UINT32 Feature + ); + +/** + Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesCapability. + + @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureCapability ( + IN UINT32 Feature + ); + +/** + Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bi= t mask. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesUserConfiguration. + + @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguratio= n. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfigur= ation. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureUserConfiguration ( + IN UINT32 Feature + ); + +/** + Prepares for the data used by CPU feature detection and initialization. + + @param[in] NumberOfProcessors The number of CPUs in the platform. + + @return Pointer to a buffer of CPU related configuration data. + + @note This service could be called by BSP only. +**/ +typedef +VOID * +(EFIAPI *CPU_FEATURE_GET_CONFIG_DATA)( + IN UINTN NumberOfProcessors + ); + +/** + Detects if CPU feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE CPU feature is supported. + @retval FALSE CPU feature is not supported. + + @note This service could be called by BSP/APs. +**/ +typedef +BOOLEAN +(EFIAPI *CPU_FEATURE_SUPPORT)( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes CPU feature to specific state. + + This service does not initialize hardware and only produces entries in t= he + Register Table for specified processor. Hardware initialization on BSP/A= Ps + will be done in CpuFeaturesInitialize(). + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the CPU feature must be enabl= ed. + If FALSE, then the CPU feature must be disa= bled. + + @retval RETURN_SUCCESS CPU feature is initialized. + + @note This service could be called by BSP only. +**/ +typedef +RETURN_STATUS +(EFIAPI *CPU_FEATURE_INITIALIZE)( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Registers a CPU Feature. + + @param GetConfigDataFunc CPU feature get configuration data function. = This + is an optional parameter that may be NULL. I= f NULL, + then the most recently registered function fo= r the + CPU feature is used. If no functions are reg= istered + for a CPU feature, then the CPU configuration= data + for the registered feature is NULL. + @param SupportFunc CPU feature support function. This is an opt= ional + parameter that may be NULL. If NULL, then th= e most + recently registered function for the CPU feat= ure is + used. If no functions are registered for a CPU + feature, then the CPU feature is assumed to be + supported by all CPUs. + @param InitializeFunc CPU feature initialize function. This is an = optional + parameter that may be NULL. If NULL, then th= e most + recently registered function for the CPU feat= ure is + used. If no functions are registered for a CPU + feature, then the CPU feature initialization = is + skipped. + @param ... Variable argument list of UINT32 CPU feature = value. + Values with no modifiers are the features pro= vided + by the registered functions. + Values with CPU_FEATURE_BEFORE modifier are f= eatures + that must be initialized after the features p= rovided + by the registered functions are used. + Values with CPU_FEATURE_AFTER modifier are fe= atures + that must be initialized before the features = provided + by the registered functions are used. + The last argument in this variable argument l= ist must + always be CPU_FEATURE_END. + + @retval RETURN_SUCCESS The CPU feature was successfully regis= tered. + @retval RETURN_OUT_OF_RESOURCES There are not enough resources to regi= ster + the CPU feature. + @retval RETURN_UNSUPPORTED Registration of the CPU feature is not + supported due to a circular dependency= between + BEFORE and AFTER features. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +RegisterCpuFeature ( + IN CHAR8 *FeatureName, OPTIONAL + IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc, OPTIONAL + IN CPU_FEATURE_SUPPORT SupportFunc, OPTIONAL + IN CPU_FEATURE_INITIALIZE InitializeFunc, OPTIONAL + ... + ); + +/** + Performs CPU features detection. + + This service will invoke MP service to check CPU features' + capabilities on BSP/APs. + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +CpuFeaturesDetect ( + VOID + ); + +/** + Performs CPU features Initialization. + + This service will invoke MP service to perform CPU features + initialization on BSP/APs per user configuration. + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +CpuFeaturesInitialize ( + VOID + ); + +/** + Switches to assigned BSP after CPU features initialization. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +SwitchBspAfterFeaturesInitialize ( + IN UINTN ProcessorNumber + ); + +/** + Adds an entry in specified register table. + + This function adds an entry in specified register table, with given regi= ster type, + register index, bit section and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] ValueMask Mask of bits in register to write + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +CpuRegisterTableWrite ( + IN UINTN ProcessorNumber, + IN REGISTER_TYPE RegisterType, + IN UINT32 Index, + IN UINT64 ValueMask, + IN UINT64 Value + ); + +/** + Adds an entry in specified Pre-SMM register table. + + This function adds an entry in specified register table, with given regi= ster type, + register index, bit section and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] ValueMask Mask of bits in register to write + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +PreSmmCpuRegisterTableWrite ( + IN UINTN ProcessorNumber, + IN REGISTER_TYPE RegisterType, + IN UINT32 Index, + IN UINT64 ValueMask, + IN UINT64 Value + ); + +/** + Adds a 32-bit register write entry in specified register table. + + This macro adds an entry in specified register table, with given registe= r type, + register index, and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +#define CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, Index, V= alue) \ + do { = \ + CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT3= 2, Value); \ + } while(FALSE); + +/** + Adds a 64-bit register write entry in specified register table. + + This macro adds an entry in specified register table, with given registe= r type, + register index, and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +#define CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, Index, V= alue) \ + do { = \ + CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX_UINT6= 4, Value); \ + } while(FALSE); + +/** + Adds a bit field write entry in specified register table. + + This macro adds an entry in specified register table, with given registe= r type, + register index, bit field section, and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program. + @param[in] Index Index of the register to program. + @param[in] Type The data type name of a register structure. + @param[in] Field The bit fiel name in register structure to = write. + @param[in] Value Value to write to the bit field. + + @note This service could be called by BSP only. +**/ +#define CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterType, Inde= x, Type, Field, Value) \ + do { = \ + UINT64 ValueMask; = \ + ValueMask =3D 0; = \ + ((Type *)(&ValueMask))->Field =3D MAX_UINT64; = \ + CpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, ValueMask= , Value); \ + } while(FALSE); + +/** + Adds a 32-bit register write entry in specified register table. + + This macro adds an entry in specified register table, with given registe= r type, + register index, and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +#define PRE_SMM_CPU_REGISTER_TABLE_WRITE32(ProcessorNumber, RegisterType, = Index, Value) \ + do { = \ + PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX= _UINT32, Value); \ + } while(FALSE); + +/** + Adds a 64-bit register write entry in specified register table. + + This macro adds an entry in specified register table, with given registe= r type, + register index, and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +#define PRE_SMM_CPU_REGISTER_TABLE_WRITE64(ProcessorNumber, RegisterType, = Index, Value) \ + do { = \ + PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, MAX= _UINT64, Value); \ + } while(FALSE); + +/** + Adds a bit field write entry in specified register table. + + This macro adds an entry in specified register table, with given registe= r type, + register index, bit field section, and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program. + @param[in] Index Index of the register to program. + @param[in] Type The data type name of a register structure. + @param[in] Field The bit fiel name in register structure to = write. + @param[in] Value Value to write to the bit field. + + @note This service could be called by BSP only. +**/ +#define PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD(ProcessorNumber, RegisterTy= pe, Index, Type, Field, Value) \ + do { = \ + UINT64 ValueMask; = \ + ValueMask =3D 0; = \ + ((Type *)(&ValueMask))->Field =3D MAX_UINT64; = \ + PreSmmCpuRegisterTableWrite (ProcessorNumber, RegisterType, Index, Val= ueMask, Value); \ + } while(FALSE); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index f7abe1c..04c7c1e 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -29,6 +29,11 @@ ## UefiCpuLib|Include/Library/UefiCpuLib.h =20 + ## @libraryclass Defines some routines that are used to register/manag= e/program + ## CPU features. + ## + UefiCpuLib|Include/Library/RegisterCpuFeaturesLib.h + [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Provides functions to manage MTRR settings on IA32 an= d X64 CPUs. ## --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048593531274.3163940045756; Thu, 9 Mar 2017 00:36:33 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D8233803A3; Thu, 9 Mar 2017 00:36:24 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E0B9D80289 for ; Thu, 9 Mar 2017 00:36:23 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:23 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:20 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930976" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:51 +0800 Message-Id: <20170309083553.6016-10-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 09/11] UefiCpuPkg: Add PEI/DXE Register CPU Features Library instances X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" PEI Register CPU Features Library instance is used to register/manager/prog= ram CPU features on PEI phase. DXE Register CPU Features Library instance is used to register/manager/prog= ram CPU features on DXE phase. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 700 +++++++++++++++++= ++ .../DxeRegisterCpuFeaturesLib.c | 266 +++++++ .../DxeRegisterCpuFeaturesLib.inf | 62 ++ .../PeiRegisterCpuFeaturesLib.c | 390 +++++++++++ .../PeiRegisterCpuFeaturesLib.inf | 64 ++ .../RegisterCpuFeaturesLib/RegisterCpuFeatures.h | 193 ++++++ .../RegisterCpuFeaturesDxe.uni | 22 + .../RegisterCpuFeaturesLib.c | 770 +++++++++++++++++= ++++ UefiCpuPkg/UefiCpuPkg.dsc | 6 +- 9 files changed, 2472 insertions(+), 1 deletion(-) create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesIn= itialize.c create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCp= uFeaturesLib.c create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCp= uFeaturesLib.inf create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCp= uFeaturesLib.c create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCp= uFeaturesLib.inf create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFe= atures.h create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFe= aturesDxe.uni create mode 100644 UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFe= aturesLib.c diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ= e.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c new file mode 100644 index 0000000..30dc0b8 --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c @@ -0,0 +1,700 @@ +/** @file + CPU Features Initialize functions. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "RegisterCpuFeatures.h" + +/** + Worker function to save PcdCpuFeaturesCapability.=20 + =20 + @param[in] SupportedFeatureMask The pointer to CPU feature bits mask b= uffer +*/ +VOID +SetCapabilityPcd ( + IN UINT8 *SupportedFeatureMask + ) +{=20 + EFI_STATUS Status; + UINTN BitMaskSize; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesCapability); + Status =3D PcdSetPtrS (PcdCpuFeaturesCapability, &BitMaskSize, Supported= FeatureMask); + ASSERT_EFI_ERROR (Status); +} + +/** + Worker function to save PcdCpuFeaturesSetting.=20 + =20 + @param[in] SupportedFeatureMask The pointer to CPU feature bits mask b= uffer +**/ +VOID +SetSettingPcd ( + IN UINT8 *SupportedFeatureMask + ) +{=20 + EFI_STATUS Status; + UINTN BitMaskSize; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSetting); + Status =3D PcdSetPtrS (PcdCpuFeaturesSetting, &BitMaskSize, SupportedFea= tureMask); + ASSERT_EFI_ERROR (Status); +} + +/** + Worker function to get PcdCpuFeaturesSupport.=20 + =20 + @return The pointer to CPU feature bits mask buffer. +**/ +UINT8 * +GetSupportPcds ( + VOID + ) +{ + UINTN BitMaskSize; + UINT8 *SupportBitMask; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + SupportBitMask =3D AllocateZeroPool (BitMaskSize); + SupportBitMask =3D (UINT8 *) PcdGetPtr (PcdCpuFeaturesSupport); + + return SupportBitMask; +} + +/** + Worker function to get PcdCpuFeaturesUserConfiguration.=20 + =20 + @return The pointer to CPU feature bits mask buffer. +**/ +UINT8 * +GetConfigurationPcds ( + VOID + ) +{ + UINTN BitMaskSize; + UINT8 *SupportBitMask; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesUserConfiguration); + SupportBitMask =3D AllocateZeroPool (BitMaskSize); + SupportBitMask =3D (UINT8 *) PcdGetPtr (PcdCpuFeaturesUserConfiguration); + + return SupportBitMask; +} + +/** + Collects CPU type and feature information. + + @param[in, out] CpuInfo The pointer to CPU feature information +**/ +VOID +FillProcessorInfo ( + IN OUT REGISTER_CPU_FEATURE_INFORMATION *CpuInfo + ) +{ + CPUID_VERSION_INFO_EAX Eax; + CPUID_VERSION_INFO_ECX Ecx; + CPUID_VERSION_INFO_EDX Edx; + UINT32 DisplayedFamily; + UINT32 DisplayedModel; + + AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, &Ecx.Uint32, &Edx.Uint3= 2); + + DisplayedFamily =3D Eax.Bits.FamilyId; + if (Eax.Bits.FamilyId =3D=3D 0x0F) { + DisplayedFamily |=3D (Eax.Bits.ExtendedFamilyId << 4); + } + + DisplayedModel =3D Eax.Bits.Model; + if (Eax.Bits.FamilyId =3D=3D 0x06 || Eax.Bits.FamilyId =3D=3D 0x0f) { + DisplayedModel |=3D (Eax.Bits.ExtendedModelId << 4); + } + + CpuInfo->DisplayFamily =3D DisplayedFamily; + CpuInfo->DisplayModel =3D DisplayedModel; + CpuInfo->SteppingId =3D Eax.Bits.SteppingId; + CpuInfo->ProcessorType =3D Eax.Bits.ProcessorType; + CpuInfo->CpuIdVersionInfoEcx.Uint32 =3D Ecx.Uint32; + CpuInfo->CpuIdVersionInfoEdx.Uint32 =3D Edx.Uint32; +} + +/** + Prepares for private data used for CPU features. + + @param[in] NumberOfCpus Number of processor in system +**/ +VOID +CpuInitDataInitialize ( + IN UINTN NumberOfCpus + ) +{ + EFI_STATUS Status; + UINTN ProcessorNumber; + EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; + UINTN Index; + CPU_FEATURES_ENTRY *CpuFeature; + CPU_FEATURES_INIT_ORDER *InitOrder; + CPU_FEATURES_DATA *CpuFeaturesData; + LIST_ENTRY *Entry; + + CpuFeaturesData =3D GetCpuFeaturesData (); + CpuFeaturesData->InitOrder =3D AllocateZeroPool (sizeof (CPU_FEATURES_IN= IT_ORDER) * NumberOfCpus); + ASSERT (CpuFeaturesData->InitOrder !=3D NULL); + CpuFeaturesData->BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + + // + // Collect CPU Features information + // + Entry =3D GetFirstNode (&CpuFeaturesData->FeatureList); + Index =3D 0; + while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) { + CpuFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); + ASSERT (CpuFeature->InitializeFunc !=3D NULL); + if (CpuFeature->GetConfigDataFunc !=3D NULL) { + CpuFeature->ConfigData =3D CpuFeature->GetConfigDataFunc (NumberOfCp= us); + } + Entry =3D Entry->ForwardLink; + } + + for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) { + InitOrder =3D &CpuFeaturesData->InitOrder[ProcessorNumber]; + InitOrder->FeaturesSupportedMask =3D AllocateZeroPool (CpuFeaturesData= ->BitMaskSize); + InitializeListHead (&InitOrder->OrderList); + Status =3D GetProcessorInformation (ProcessorNumber, &ProcessorInfoBuf= fer); + ASSERT_EFI_ERROR (Status); + CopyMem ( + &InitOrder->CpuInfo.ProcessorInfo, + &ProcessorInfoBuffer, + sizeof (EFI_PROCESSOR_INFORMATION) + ); + } + // + // Get support and configuration PCDs + // + CpuFeaturesData->SupportPcds =3D GetSupportPcds (); + CpuFeaturesData->ConfigurationPcds =3D GetConfigurationPcds (); +} + +/** + Worker function to do OR operation on CPU feature supported bits mask bu= ffer. + =20 + @param[in] SupportedFeatureMask The pointer to CPU feature bits mask b= uffer + @param[in] OrFeatureBitMask The feature bit mask to do OR operation +**/ +VOID +SupportedMaskOr ( + IN UINT8 *SupportedFeatureMask, + IN UINT8 *OrFeatureBitMask + ) +{ + UINTN Index; + UINTN BitMaskSize; + UINT8 *Data1; + UINT8 *Data2; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + Data1 =3D SupportedFeatureMask; + Data2 =3D OrFeatureBitMask; + for (Index =3D 0; Index < BitMaskSize; Index++) { + *(Data1++) |=3D *(Data2++); + } +} + +/** + Worker function to do AND operation on CPU feature supported bits mask b= uffer. + =20 + @param[in] SupportedFeatureMask The pointer to CPU feature bits mask b= uffer + @param[in] AndFeatureBitMask The feature bit mask to do AND operati= on +**/ +VOID +SupportedMaskAnd ( + IN UINT8 *SupportedFeatureMask, + IN UINT8 *AndFeatureBitMask + ) +{ + UINTN Index; + UINTN BitMaskSize; + UINT8 *Data1; + UINT8 *Data2; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + Data1 =3D SupportedFeatureMask; + Data2 =3D AndFeatureBitMask; + for (Index =3D 0; Index < BitMaskSize; Index++) { + *(Data1++) &=3D *(Data2++); + } +} + +/** + Worker function to check if the compared CPU feature set in the CPU feat= ure + supported bits mask buffer. + =20 + @param[in] SupportedFeatureMask The pointer to CPU feature bits mask = buffer + @param[in] ComparedFeatureBitMask The feature bit mask to be compared + + @retval TRUE The ComparedFeatureBitMask is set in CPU feature supporte= d bits + mask buffer. + @retval FALSE The ComparedFeatureBitMask is not set in CPU feature supp= orted bits + mask buffer. +**/ +BOOLEAN +IsBitMaskMatch ( + IN UINT8 *SupportedFeatureMask, + IN UINT8 *ComparedFeatureBitMask + ) +{ + UINTN Index; + UINTN BitMaskSize; + UINT8 *Data1; + UINT8 *Data2; + =20 + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + + Data1 =3D SupportedFeatureMask; + Data2 =3D ComparedFeatureBitMask; + for (Index =3D 0; Index < BitMaskSize; Index++) { + if (((*(Data1++)) & (*(Data2++))) !=3D 0) { + return TRUE; + } + } + return FALSE; +} + +/** + Collects processor data for calling processor. + + @param[in,out] Buffer The pointer to private data buffer. +**/ +VOID +EFIAPI +CollectProcessorData ( + IN OUT VOID *Buffer + ) +{ + UINTN ProcessorNumber; + CPU_FEATURES_ENTRY *CpuFeature; + REGISTER_CPU_FEATURE_INFORMATION *CpuInfo; + LIST_ENTRY *Entry; + CPU_FEATURES_DATA *CpuFeaturesData; + + CpuFeaturesData =3D GetCpuFeaturesData (); + ProcessorNumber =3D GetProcessorIndex (); + CpuInfo =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo; + // + // collect processor information + // + FillProcessorInfo (CpuInfo); + Entry =3D GetFirstNode (&CpuFeaturesData->FeatureList); + while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) { + CpuFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); + if (IsBitMaskMatch (CpuFeaturesData->SupportPcds, CpuFeature->FeatureM= ask)) { =20 + if (CpuFeature->SupportFunc =3D=3D NULL) { + // + // If SupportFunc is NULL, then the feature is supported. + // + SupportedMaskOr ( + CpuFeaturesData->InitOrder[ProcessorNumber].FeaturesSupportedMas= k, + CpuFeature->FeatureMask + ); + } else if (CpuFeature->SupportFunc (ProcessorNumber, CpuInfo, CpuFea= ture->ConfigData)) { + SupportedMaskOr ( + CpuFeaturesData->InitOrder[ProcessorNumber].FeaturesSupportedMas= k, + CpuFeature->FeatureMask + ); + } + } + Entry =3D Entry->ForwardLink;=20 + } +} + +/** + Dump the contents of a CPU register table. + + @param[in] ProcessorNumber The index of the CPU to show the register t= able contents. + + @note This service could be called by BSP only. +**/ +VOID +DumpRegisterTableOnProcessor ( + IN UINTN ProcessorNumber + ) +{ + CPU_FEATURES_DATA *CpuFeaturesData; + UINTN FeatureIndex; + CPU_REGISTER_TABLE *RegisterTable; + CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry; + CPU_REGISTER_TABLE_ENTRY *RegisterTableEntryHead; + + CpuFeaturesData =3D GetCpuFeaturesData (); + // + // Debug information + // + RegisterTable =3D &CpuFeaturesData->RegisterTable[ProcessorNumber]; + DEBUG ((DEBUG_INFO, "RegisterTable->TableLength =3D %d\n", RegisterTable= ->TableLength)); + + RegisterTableEntryHead =3D (CPU_REGISTER_TABLE_ENTRY *) (UINTN) Register= Table->RegisterTableEntry; + + for (FeatureIndex =3D 0; FeatureIndex < RegisterTable->TableLength; Feat= ureIndex++) { + RegisterTableEntry =3D &RegisterTableEntryHead[FeatureIndex]; + switch (RegisterTableEntry->RegisterType) { + case Msr: + DEBUG ((DEBUG_INFO, "Processor: %d: MSR: %x, Bit Start: %d, Bit Le= ngth: %d, Value: %lx\r\n", ProcessorNumber, RegisterTableEntry->Index, Regi= sterTableEntry->ValidBitStart, RegisterTableEntry->ValidBitLength, Register= TableEntry->Value)); + break; + case ControlRegister: + DEBUG ((DEBUG_INFO, "Processor: %d: CR: %x, Bit Start: %d, Bit Le= ngth: %d, Value: %lx\r\n", ProcessorNumber, RegisterTableEntry->Index, Regi= sterTableEntry->ValidBitStart, RegisterTableEntry->ValidBitLength, Register= TableEntry->Value)); + break; + case MemoryMapped: + DEBUG ((DEBUG_INFO, "Processor: %d: MMIO: %x, Bit Start: %d, Bit Le= ngth: %d, Value: %lx\r\n", ProcessorNumber, RegisterTableEntry->Index, Regi= sterTableEntry->ValidBitStart, RegisterTableEntry->ValidBitLength, Register= TableEntry->Value)); + break; + case CacheControl: + DEBUG ((DEBUG_INFO, "Processor: %d: CACHE: %x, Bit Start: %d, Bit Le= ngth: %d, Value: %lx\r\n", ProcessorNumber, RegisterTableEntry->Index, Regi= sterTableEntry->ValidBitStart, RegisterTableEntry->ValidBitLength, Register= TableEntry->Value)); + break; + default: + break; + } =20 + } +} + +/** + Analysis register CPU features on each processor and save CPU setting in= CPU register table. + + @param[in] NumberOfCpus Number of processor in system + +**/ +VOID +AnalysisProcessorFeatures ( + IN UINTN NumberOfCpus + ) +{ + EFI_STATUS Status; + UINTN ProcessorNumber; + CPU_FEATURES_ENTRY *CpuFeature; + CPU_FEATURES_ENTRY *CpuFeatureInOrder; + CPU_FEATURES_INIT_ORDER *CpuInitOrder; + REGISTER_CPU_FEATURE_INFORMATION *CpuInfo; + LIST_ENTRY *Entry; + CPU_FEATURES_DATA *CpuFeaturesData; + + CpuFeaturesData =3D GetCpuFeaturesData (); + CpuFeaturesData->CapabilityPcds =3D AllocatePool (CpuFeaturesData->BitMa= skSize); + SetMem (CpuFeaturesData->CapabilityPcds, CpuFeaturesData->BitMaskSize, 0= xFF); + for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) { + CpuInitOrder =3D &CpuFeaturesData->InitOrder[ProcessorNumber]; + // + // Calculate the last capability on all processors + // + SupportedMaskAnd (CpuFeaturesData->CapabilityPcds, CpuInitOrder->Featu= resSupportedMask); + } + // + // Calculate the last setting + // + + CpuFeaturesData->SettingPcds =3D AllocateCopyPool (CpuFeaturesData->BitM= askSize, CpuFeaturesData->CapabilityPcds); + SupportedMaskAnd (CpuFeaturesData->SettingPcds, CpuFeaturesData->Configu= rationPcds); + + // + // Save PCDs and display CPU PCDs + // + SetCapabilityPcd (CpuFeaturesData->CapabilityPcds); + SetSettingPcd (CpuFeaturesData->SettingPcds); + + // + // Dump the last CPU feature list + // + DEBUG_CODE ( + DEBUG ((DEBUG_INFO, "Last CPU features list...\n")); + Entry =3D GetFirstNode (&CpuFeaturesData->FeatureList); + while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) { + CpuFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); + DumpCpuFeature (CpuFeature); + Entry =3D Entry->ForwardLink; + } + DEBUG ((DEBUG_INFO, "PcdCpuFeaturesSupport:\n")); + DumpCpuFeatureMask (CpuFeaturesData->SupportPcds); + DEBUG ((DEBUG_INFO, "PcdCpuFeaturesUserConfiguration:\n")); + DumpCpuFeatureMask (CpuFeaturesData->ConfigurationPcds); + DEBUG ((DEBUG_INFO, "PcdCpuFeaturesCapability:\n")); + DumpCpuFeatureMask (CpuFeaturesData->CapabilityPcds); + DEBUG ((DEBUG_INFO, "PcdCpuFeaturesSetting:\n")); + DumpCpuFeatureMask (CpuFeaturesData->SettingPcds); + ); + + for (ProcessorNumber =3D 0; ProcessorNumber < NumberOfCpus; ProcessorNum= ber++) { + CpuInitOrder =3D &CpuFeaturesData->InitOrder[ProcessorNumber]; + Entry =3D GetFirstNode (&CpuFeaturesData->FeatureList); + while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) { + // + // Insert each feature into processor's order list + // + CpuFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); + if (IsBitMaskMatch (CpuFeature->FeatureMask, CpuFeaturesData->Settin= gPcds)) { + CpuFeatureInOrder =3D AllocateCopyPool (sizeof (CPU_FEATURES_ENTRY= ), CpuFeature); + InsertTailList (&CpuInitOrder->OrderList, &CpuFeatureInOrder->Link= ); + } + Entry =3D Entry->ForwardLink;=20 + } + // + // Go through ordered feature list to initialize CPU features + // + CpuInfo =3D &CpuFeaturesData->InitOrder[ProcessorNumber].CpuInfo; + Entry =3D GetFirstNode (&CpuInitOrder->OrderList); + while (!IsNull (&CpuInitOrder->OrderList, Entry)) { + CpuFeatureInOrder =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); + Status =3D CpuFeatureInOrder->InitializeFunc (ProcessorNumber, CpuIn= fo, CpuFeatureInOrder->ConfigData, TRUE); + ASSERT_EFI_ERROR (Status); + Entry =3D Entry->ForwardLink;=20 + } + // + // Dump the RegisterTable + // + DumpRegisterTableOnProcessor (ProcessorNumber); + } +} + +/** + Initialize the CPU registers from a register table. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + + @note This service could be called by BSP/APs. +**/ +VOID +ProgramProcessorRegister ( + IN UINTN ProcessorNumber + ) +{ + CPU_FEATURES_DATA *CpuFeaturesData; + CPU_REGISTER_TABLE *RegisterTable; + CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry; + UINTN Index; + UINTN Value; + CPU_REGISTER_TABLE_ENTRY *RegisterTableEntryHead; + + CpuFeaturesData =3D GetCpuFeaturesData (); + RegisterTable =3D &CpuFeaturesData->RegisterTable[ProcessorNumber]; + + // + // Traverse Register Table of this logical processor + // + RegisterTableEntryHead =3D (CPU_REGISTER_TABLE_ENTRY *) (UINTN) Register= Table->RegisterTableEntry; + + for (Index =3D 0; Index < RegisterTable->TableLength; Index++) { + + RegisterTableEntry =3D &RegisterTableEntryHead[Index]; + =20 + // + // Check the type of specified register + // + switch (RegisterTableEntry->RegisterType) { + // + // The specified register is Control Register + // + case ControlRegister: + switch (RegisterTableEntry->Index) { + case 0: + Value =3D AsmReadCr0 (); + Value =3D (UINTN) BitFieldWrite64 ( + Value, + RegisterTableEntry->ValidBitStart, + RegisterTableEntry->ValidBitStart + RegisterTabl= eEntry->ValidBitLength - 1, + RegisterTableEntry->Value + ); + AsmWriteCr0 (Value); + break; + case 2: + Value =3D AsmReadCr2 (); + Value =3D (UINTN) BitFieldWrite64 ( + Value, + RegisterTableEntry->ValidBitStart, + RegisterTableEntry->ValidBitStart + RegisterTabl= eEntry->ValidBitLength - 1, + RegisterTableEntry->Value + ); + AsmWriteCr2 (Value); + break; + case 3: + Value =3D AsmReadCr3 (); + Value =3D (UINTN) BitFieldWrite64 ( + Value, + RegisterTableEntry->ValidBitStart, + RegisterTableEntry->ValidBitStart + RegisterTabl= eEntry->ValidBitLength - 1, + RegisterTableEntry->Value + ); + AsmWriteCr3 (Value); + break; + case 4: + Value =3D AsmReadCr4 (); + Value =3D (UINTN) BitFieldWrite64 ( + Value, + RegisterTableEntry->ValidBitStart, + RegisterTableEntry->ValidBitStart + RegisterTabl= eEntry->ValidBitLength - 1, + RegisterTableEntry->Value + ); + AsmWriteCr4 (Value); + break; + case 8: + // + // Do we need to support CR8? + // + break; + default: + break; + } + break; + // + // The specified register is Model Specific Register + // + case Msr: + // + // Get lock to avoid Package/Core scope MSRs programming issue in pa= rallel execution mode + // + AcquireSpinLock (&CpuFeaturesData->MsrLock); + if (RegisterTableEntry->ValidBitLength >=3D 64) { + // + // If length is not less than 64 bits, then directly write without= reading + // + AsmWriteMsr64 ( + RegisterTableEntry->Index, + RegisterTableEntry->Value + ); + } else { + // + // Set the bit section according to bit start and length + // + AsmMsrBitFieldWrite64 ( + RegisterTableEntry->Index, + RegisterTableEntry->ValidBitStart, + RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBit= Length - 1, + RegisterTableEntry->Value + ); + } + ReleaseSpinLock (&CpuFeaturesData->MsrLock); + break; + // + // MemoryMapped operations + // + case MemoryMapped: + AcquireSpinLock (&CpuFeaturesData->MemoryMappedLock); + MmioBitFieldWrite32 ( + RegisterTableEntry->Index, + RegisterTableEntry->ValidBitStart, + RegisterTableEntry->ValidBitStart + RegisterTableEntry->ValidBitLe= ngth - 1, + (UINT32)RegisterTableEntry->Value + ); + ReleaseSpinLock (&CpuFeaturesData->MemoryMappedLock); + break; + // + // Enable or disable cache + // + case CacheControl: + // + // If value of the entry is 0, then disable cache. Otherwise, enabl= e cache. + // + if (RegisterTableEntry->Value =3D=3D 0) { + AsmDisableCache (); + } else { + AsmEnableCache (); + } + break; + + default: + break; + } + } +} + +/** + Programs registers for the calling processor. + + @param[in,out] Buffer The pointer to private data buffer. + +**/ +VOID +EFIAPI +SetProcessorRegister ( + IN OUT VOID *Buffer + ) +{ + UINTN ProcessorNumber; + + ProcessorNumber =3D GetProcessorIndex (); + ProgramProcessorRegister (ProcessorNumber); +} + +/** + Performs CPU features detection. + + This service will invoke MP service to check CPU features' + capabilities on BSP/APs. + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +CpuFeaturesDetect ( + VOID + ) +{ + UINTN NumberOfCpus; + UINTN NumberOfEnabledProcessors; + + GetNumberOfProcessor (&NumberOfCpus, &NumberOfEnabledProcessors); + + CpuInitDataInitialize (NumberOfCpus); + + // + // Wakeup all APs for data collection. + // + StartupAPsWorker (CollectProcessorData); + + // + // Collect data on BSP + // + CollectProcessorData (NULL); + + AnalysisProcessorFeatures (NumberOfCpus); +} + +/** + Performs CPU features Initialization. + + This service will invoke MP service to perform CPU features + initialization on BSP/APs per user configuration. + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +CpuFeaturesInitialize ( + VOID + ) +{ + CPU_FEATURES_DATA *CpuFeaturesData; + UINTN OldBspNumber; + + CpuFeaturesData =3D GetCpuFeaturesData (); + + OldBspNumber =3D GetProcessorIndex(); + CpuFeaturesData->BspNumber =3D OldBspNumber; + // + // Wakeup all APs for programming. + // + StartupAPsWorker (SetProcessorRegister); + // + // Programming BSP + // + SetProcessorRegister (NULL); + // + // Switch to new BSP if required + // + if (CpuFeaturesData->BspNumber !=3D OldBspNumber) { + SwitchNewBsp (CpuFeaturesData->BspNumber); + } +} diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeatur= esLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesL= ib.c new file mode 100644 index 0000000..0063551 --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c @@ -0,0 +1,266 @@ +/** @file + CPU Register Table Library functions. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include + +#include + +#include "RegisterCpuFeatures.h" + +CPU_FEATURES_DATA mCpuFeaturesData =3D {0}; +static EFI_MP_SERVICES_PROTOCOL *mMpServices =3D NULL; + +/** + Worker function to get CPU_FEATURES_DATA pointer. + + @return Pointer to CPU_FEATURES_DATA. +**/ +CPU_FEATURES_DATA * +GetCpuFeaturesData ( + VOID + ) +{ + return &mCpuFeaturesData; +} + +/** + Worker function to get EFI_MP_SERVICES_PROTOCOL pointer. + + @return Pointer to EFI_MP_SERVICES_PROTOCOL. +**/ +EFI_MP_SERVICES_PROTOCOL * +GetMpProtocol ( + VOID + ) +{ + EFI_STATUS Status; + + if (mMpServices =3D=3D NULL) { + // + // Get MP Services Protocol + // + Status =3D gBS->LocateProtocol ( + &gEfiMpServiceProtocolGuid, + NULL, + (VOID **)&mMpServices + ); + ASSERT_EFI_ERROR (Status); + } + + ASSERT (mMpServices !=3D NULL); + return mMpServices; +} + +/** + Worker function to return processor index. + + @return The processor index. +**/ +UINTN +GetProcessorIndex ( + VOID + ) +{ + EFI_STATUS Status; + UINTN ProcessorIndex; + EFI_MP_SERVICES_PROTOCOL *MpServices; + =20 + MpServices =3D GetMpProtocol (); + Status =3D MpServices->WhoAmI(MpServices, &ProcessorIndex); + ASSERT_EFI_ERROR (Status); + return ProcessorIndex; +} + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + + @return Status of MpServices->GetProcessorInfo(). +**/ +EFI_STATUS +GetProcessorInformation ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer + ) +{ + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpServices; + =20 + MpServices =3D GetMpProtocol (); + Status =3D MpServices->GetProcessorInfo ( + MpServices, + ProcessorNumber, + ProcessorInfoBuffer + ); + return Status; +} + +/** + Worker function to execute a caller provided function on all enabled APs. + =20 + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. +**/ +VOID +StartupAPsWorker ( + IN EFI_AP_PROCEDURE Procedure + ) +{ + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpServices; + =20 + MpServices =3D GetMpProtocol (); + // + // Wakeup all APs + // + Status =3D MpServices->StartupAllAPs ( + MpServices, + Procedure, + FALSE, + NULL, + 0,=20 + NULL, + NULL + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Worker function to switch the requested AP to be the BSP from that point= onward. + + @param[in] ProcessorNumber The handle number of AP that is to become t= he new BSP. +**/ +VOID +SwitchNewBsp ( + IN UINTN ProcessorNumber + ) +{ + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpServices; + =20 + MpServices =3D GetMpProtocol (); + // + // Wakeup all APs + // + Status =3D MpServices->SwitchBSP ( + MpServices, + ProcessorNumber, + TRUE + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Worker function to retrieve the number of logical processor in the platf= orm. + =20 + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. +**/ +VOID +GetNumberOfProcessor ( + OUT UINTN *NumberOfCpus, + OUT UINTN *NumberOfEnabledProcessors + ) +{ + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpServices; + =20 + MpServices =3D GetMpProtocol (); + + // + // Get the number of CPUs + // + Status =3D MpServices->GetNumberOfProcessors ( + MpServices, + NumberOfCpus, + NumberOfEnabledProcessors + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Allocates ACPI NVS memory to save ACPI_CPU_DATA. + + @return Pointer to allocated ACPI_CPU_DATA. +**/ +ACPI_CPU_DATA * +AllocateAcpiCpuData ( + VOID + ) +{ + // + // CpuS3DataDxe will do it. + // + ASSERT (FALSE); + return NULL; +} + +/** + Enlarges CPU register table for each processor. + + @param[in, out] RegisterTable Pointer processor's CPU register table +**/ +VOID +EnlargeRegisterTable ( + IN OUT CPU_REGISTER_TABLE *RegisterTable + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Address; + UINTN AllocatePages; + + Address =3D BASE_4GB - 1; + AllocatePages =3D RegisterTable->AllocatedSize / EFI_PAGE_SIZE; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiACPIMemoryNVS, + AllocatePages + 1, + &Address + ); + ASSERT_EFI_ERROR (Status); + + // + // If there are records existing in the register table, then copy its co= ntents + // to new region and free the old one. + // + if (RegisterTable->AllocatedSize > 0) { + CopyMem ( + (VOID *) (UINTN) Address, + (VOID *) (UINTN) RegisterTable->RegisterTableEntry, + RegisterTable->AllocatedSize + ); + // + // RegisterTableEntry is allocated by gBS->AllocatePages() service. + // So, gBS->FreePages() service is used to free it. + // + gBS->FreePages ( + RegisterTable->RegisterTableEntry, + AllocatePages + ); + } + + // + // Adjust the allocated size and register table base address. + // + RegisterTable->AllocatedSize +=3D EFI_PAGE_SIZE; + RegisterTable->RegisterTableEntry =3D Address; +} diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeatur= esLib.inf b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeature= sLib.inf new file mode 100644 index 0000000..abffd11 --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.i= nf @@ -0,0 +1,62 @@ +## @file +# Register CPU Features Library DXE instance. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeRegisterCpuFeaturesLib + MODULE_UNI_FILE =3D DxeRegisterCpuFeaturesLib.uni + FILE_GUID =3D ADE8F745-AA2E-49f6-8ED4-746B34867E52 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RegisterCpuFeaturesLib|DXE_DRIVER + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources.common] + DxeRegisterCpuFeaturesLib.c + RegisterCpuFeaturesLib.c + RegisterCpuFeatures.h + CpuFeaturesInitialize.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + LocalApicLib + BaseMemoryLib + MemoryAllocationLib + SynchronizationLib + UefiBootServicesTableLib + IoLib + +[Protocols] + gEfiMpServiceProtocolGuid ## = CONSUMES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuS3DataAddress ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSupport ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesUserConfiguration ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesCapability ## = PRODUCES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSetting ## = PRODUCES + +[Depex] + gEfiMpServiceProtocolGuid AND gEdkiiCpuFeaturesSetDoneGuid diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeatur= esLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesL= ib.c new file mode 100644 index 0000000..12a516a --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.c @@ -0,0 +1,390 @@ +/** @file + CPU Register Table Library functions. + + Copyright (c) 2016, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include + +#include +#include +#include +#include +#include "RegisterCpuFeatures.h" + +#define REGISTER_CPU_FEATURES_GUID \ + { \ + 0xa694c467, 0x697a, 0x446b, { 0xb9, 0x29, 0x5b, 0x14, 0xa0, 0xcf, 0x39= , 0xf } \ + } + +EFI_GUID mRegisterCpuFeaturesHobGuid =3D REGISTER_CPU_FEATURES_GUID; + +/** + Worker function to get CPU_FEATURES_DATA pointer. + + @return Pointer to CPU_FEATURES_DATA. +**/ +CPU_FEATURES_DATA * +GetCpuFeaturesData ( + VOID + ) +{ + CPU_FEATURES_DATA *CpuInitData; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *DataInHob; + UINT64 Data64; + + CpuInitData =3D NULL; + GuidHob =3D GetFirstGuidHob (&mRegisterCpuFeaturesHobGuid); + if (GuidHob !=3D NULL) { + DataInHob =3D GET_GUID_HOB_DATA (GuidHob); + CpuInitData =3D (CPU_FEATURES_DATA *) (*(UINTN *) DataInHob); + ASSERT (CpuInitData !=3D NULL); + } else { + CpuInitData =3D AllocateZeroPool (sizeof (CPU_FEATURES_DATA)); + ASSERT (CpuInitData !=3D NULL); + // + // Build location of CPU MP DATA buffer in HOB + // + Data64 =3D (UINT64) (UINTN) CpuInitData; + BuildGuidDataHob ( + &mRegisterCpuFeaturesHobGuid, + (VOID *) &Data64, + sizeof (UINT64) + ); + } + + return CpuInitData; +} + +/** + Worker function to get MP PPI service pointer. + + @return PEI PPI service pointer. +**/ +EFI_PEI_MP_SERVICES_PPI * +GetMpPpi ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + + // + // Get MP Services Protocol + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiMpServicesPpiGuid, + 0, + NULL, + (VOID **)&CpuMpPpi + ); + ASSERT_EFI_ERROR (Status); + return CpuMpPpi; +} + +/** + Worker function to return processor index. + + @return The processor index. +**/ +UINTN +GetProcessorIndex ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + UINTN ProcessorIndex; + + CpuMpPpi =3D GetMpPpi (); + + Status =3D CpuMpPpi->WhoAmI(GetPeiServicesTablePointer (), CpuMpPpi, &Pr= ocessorIndex); + ASSERT_EFI_ERROR (Status); + return ProcessorIndex; +} + +/** + Worker function to MP-related information on the requested processor at = the + instant this call is made. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + + @return Status of MpServices->GetProcessorInfo(). +**/ +EFI_STATUS +GetProcessorInformation ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer + ) +{ + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + EFI_STATUS Status; + + CpuMpPpi =3D GetMpPpi (); + Status =3D CpuMpPpi->GetProcessorInfo ( + GetPeiServicesTablePointer(), + CpuMpPpi, + ProcessorNumber, + ProcessorInfoBuffer + ); + return Status; +} + +/** + Worker function to execute a caller provided function on all enabled APs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. +**/ +VOID +StartupAPsWorker ( + IN EFI_AP_PROCEDURE Procedure + ) +{ + EFI_STATUS Status; + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + + // + // Get MP Services Protocol + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiMpServicesPpiGuid, + 0, + NULL, + (VOID **)&CpuMpPpi + ); + ASSERT_EFI_ERROR (Status); + + // + // Wakeup all APs for data collection. + // + Status =3D CpuMpPpi->StartupAllAPs ( + GetPeiServicesTablePointer (), + CpuMpPpi, + Procedure, + FALSE, + 0, + NULL + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Worker function to switch the requested AP to be the BSP from that point= onward. + + @param[in] ProcessorNumber The handle number of AP that is to become t= he new BSP. +**/ +VOID +SwitchNewBsp ( + IN UINTN ProcessorNumber + ) +{ + EFI_STATUS Status; + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + + // + // Get MP Services Protocol + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiMpServicesPpiGuid, + 0, + NULL, + (VOID **)&CpuMpPpi + ); + ASSERT_EFI_ERROR (Status); + + // + // Wakeup all APs for data collection. + // + Status =3D CpuMpPpi->SwitchBSP ( + GetPeiServicesTablePointer (), + CpuMpPpi, + ProcessorNumber, + TRUE + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Worker function to retrieve the number of logical processor in the platf= orm. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. +**/ +VOID +GetNumberOfProcessor ( + OUT UINTN *NumberOfCpus, + OUT UINTN *NumberOfEnabledProcessors + ) +{ + EFI_STATUS Status; + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + + // + // Get MP Services Protocol + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiMpServicesPpiGuid, + 0, + NULL, + (VOID **)&CpuMpPpi + ); + ASSERT_EFI_ERROR (Status); + + // + // Get the number of CPUs + // + Status =3D CpuMpPpi->GetNumberOfProcessors ( + GetPeiServicesTablePointer (), + CpuMpPpi, + NumberOfCpus, + NumberOfEnabledProcessors + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Allocates ACPI NVS memory to save ACPI_CPU_DATA. + + @return Pointer to allocated ACPI_CPU_DATA. +**/ +ACPI_CPU_DATA * +AllocateAcpiCpuData ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PEI_MP_SERVICES_PPI *CpuMpPpi; + UINTN NumberOfCpus; + UINTN NumberOfEnabledProcessors; + ACPI_CPU_DATA *AcpiCpuData; + EFI_PHYSICAL_ADDRESS Address; + UINTN TableSize; + CPU_REGISTER_TABLE *RegisterTable; + UINTN Index; + EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer; + + Status =3D PeiServicesAllocatePages ( + EfiACPIMemoryNVS, + EFI_SIZE_TO_PAGES (sizeof (ACPI_CPU_DATA)), + &Address + ); + ASSERT_EFI_ERROR (Status); + AcpiCpuData =3D (ACPI_CPU_DATA *) (UINTN) Address; + ASSERT (AcpiCpuData !=3D NULL); + + // + // Get MP Services Protocol + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiMpServicesPpiGuid, + 0, + NULL, + (VOID **)&CpuMpPpi + ); + ASSERT_EFI_ERROR (Status); + + // + // Get the number of CPUs + // + Status =3D CpuMpPpi->GetNumberOfProcessors ( + GetPeiServicesTablePointer (), + CpuMpPpi, + &NumberOfCpus, + &NumberOfEnabledProcessors + ); + ASSERT_EFI_ERROR (Status); + AcpiCpuData->NumberOfCpus =3D (UINT32)NumberOfCpus; + + // + // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable f= or all CPUs + // + TableSize =3D 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); + Status =3D PeiServicesAllocatePages ( + EfiACPIMemoryNVS, + EFI_SIZE_TO_PAGES (TableSize), + &Address + ); + ASSERT_EFI_ERROR (Status); + RegisterTable =3D (CPU_REGISTER_TABLE *) (UINTN) Address; + + for (Index =3D 0; Index < NumberOfCpus; Index++) { + Status =3D CpuMpPpi->GetProcessorInfo ( + GetPeiServicesTablePointer (), + CpuMpPpi, + Index, + &ProcessorInfoBuffer + ); + ASSERT_EFI_ERROR (Status); + + RegisterTable[Index].InitialApicId =3D (UINT32)ProcessorInfoBuffe= r.ProcessorId; + RegisterTable[Index].TableLength =3D 0; + RegisterTable[Index].AllocatedSize =3D 0; + RegisterTable[Index].RegisterTableEntry =3D 0; + + RegisterTable[NumberOfCpus + Index].InitialApicId =3D (UINT32)Pro= cessorInfoBuffer.ProcessorId; + RegisterTable[NumberOfCpus + Index].TableLength =3D 0; + RegisterTable[NumberOfCpus + Index].AllocatedSize =3D 0; + RegisterTable[NumberOfCpus + Index].RegisterTableEntry =3D 0; + } + AcpiCpuData->RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Re= gisterTable; + AcpiCpuData->PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(R= egisterTable + NumberOfCpus); + + return AcpiCpuData; +} + +/** + Enlarges CPU register table for each processor. + + @param[in, out] RegisterTable Pointer processor's CPU register table +**/ +VOID +EnlargeRegisterTable ( + IN OUT CPU_REGISTER_TABLE *RegisterTable + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Address; + UINTN AllocatePages; + + AllocatePages =3D RegisterTable->AllocatedSize / EFI_PAGE_SIZE; + Status =3D PeiServicesAllocatePages ( + EfiACPIMemoryNVS, + AllocatePages + 1, + &Address + ); + ASSERT_EFI_ERROR (Status); + + // + // If there are records existing in the register table, then copy its co= ntents + // to new region and free the old one. + // + if (RegisterTable->AllocatedSize > 0) { + CopyMem ( + (VOID *) (UINTN) Address, + (VOID *) (UINTN) RegisterTable->RegisterTableEntry, + RegisterTable->AllocatedSize + ); + } + + // + // Adjust the allocated size and register table base address. + // + RegisterTable->AllocatedSize +=3D EFI_PAGE_SIZE; + RegisterTable->RegisterTableEntry =3D Address; +} diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeatur= esLib.inf b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeature= sLib.inf new file mode 100644 index 0000000..0090714 --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.i= nf @@ -0,0 +1,64 @@ +## @file +# Register CPU Features Library PEI instance. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiRegisterCpuFeaturesLib + MODULE_UNI_FILE =3D PeiRegisterCpuFeaturesLib.uni + FILE_GUID =3D D8855DB3-8348-41B5-BDA4-385351767D41 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RegisterCpuFeaturesLib|PEIM + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources.common] + PeiRegisterCpuFeaturesLib.c + RegisterCpuFeaturesLib.c + RegisterCpuFeatures.h + CpuFeaturesInitialize.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + LocalApicLib + BaseMemoryLib + MemoryAllocationLib + SynchronizationLib + HobLib + PeiServicesLib + PeiServicesTablePointerLib + IoLib + +[Ppis] + gEfiPeiMpServicesPpiGuid ## = CONSUMES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuS3DataAddress ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSupport ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesUserConfiguration ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesCapability ## = PRODUCES + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSetting ## = PRODUCES + +[Depex] + gEfiPeiMpServicesPpiGuid AND gEdkiiCpuFeaturesSetDoneGuid diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.= h b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h new file mode 100644 index 0000000..2b136b6 --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h @@ -0,0 +1,193 @@ +/** @file + CPU Register Table Library definitions. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#ifndef _REGISTER_CPU_FEATURES_H_ +#define _REGISTER_CPU_FEATURES_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define CPU_FEATURE_ENTRY_SIGNATURE SIGNATURE_32 ('C', 'F', 'E', 'S') + +#define CPU_FEATURE_NAME_SIZE 128 + +typedef struct { + REGISTER_CPU_FEATURE_INFORMATION CpuInfo; + UINT8 *FeaturesSupportedMask; + LIST_ENTRY OrderList; +} CPU_FEATURES_INIT_ORDER; + +typedef struct { + UINT32 Signature; + LIST_ENTRY Link; + UINT8 *FeatureMask; + CHAR8 *FeatureName; + CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc; + CPU_FEATURE_SUPPORT SupportFunc; + CPU_FEATURE_INITIALIZE InitializeFunc; + UINT8 *BeforeFeatureBitMask; + UINT8 *AfterFeatureBitMask; + VOID *ConfigData; + BOOLEAN BeforeAll; + BOOLEAN AfterAll; +} CPU_FEATURES_ENTRY; + +typedef struct { + UINTN FeaturesCount; + UINT32 BitMaskSize; + SPIN_LOCK MsrLock; + SPIN_LOCK MemoryMappedLock; + LIST_ENTRY FeatureList; + + CPU_FEATURES_INIT_ORDER *InitOrder; + UINT8 *SupportPcds; + UINT8 *CapabilityPcds; + UINT8 *ConfigurationPcds; + UINT8 *SettingPcds; + + CPU_REGISTER_TABLE *RegisterTable; + CPU_REGISTER_TABLE *PreSmmRegisterTable; + UINTN BspNumber; +} CPU_FEATURES_DATA; + +#define CPU_FEATURE_ENTRY_FROM_LINK(a) \ + CR ( \ + (a), \ + CPU_FEATURES_ENTRY, \ + Link, \ + CPU_FEATURE_ENTRY_SIGNATURE \ + ) + +/** + Worker function to get CPU_FEATURES_DATA pointer. + + @return Pointer to CPU_FEATURES_DATA. +**/ +CPU_FEATURES_DATA * +GetCpuFeaturesData ( + VOID + ); + +/** + Enlarges CPU register table for each processor. + + @param[in, out] RegisterTable Pointer processor's CPU register table +**/ +VOID +EnlargeRegisterTable ( + IN OUT CPU_REGISTER_TABLE *RegisterTable + ); + +/** + Allocates ACPI NVS memory to save ACPI_CPU_DATA. + + @return Pointer to allocated ACPI_CPU_DATA. +**/ +ACPI_CPU_DATA * +AllocateAcpiCpuData ( + VOID + ); + +/** + Worker function to return processor index. + + @return The processor index. +**/ +UINTN +GetProcessorIndex ( + VOID + ); + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + + @return Status of MpServices->GetProcessorInfo(). +**/ +EFI_STATUS +GetProcessorInformation ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer + ); + +/** + Worker function to execute a caller provided function on all enabled APs. + + @param[in] Procedure A pointer to the function to be run = on + enabled APs of the system. +**/ +VOID +StartupAPsWorker ( + IN EFI_AP_PROCEDURE Procedure + ); + +/** + Worker function to retrieve the number of logical processor in the platf= orm. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. +**/ +VOID +GetNumberOfProcessor ( + OUT UINTN *NumberOfCpus, + OUT UINTN *NumberOfEnabledProcessors + ); + +/** + Worker function to switch the requested AP to be the BSP from that point= onward. + + @param[in] ProcessorNumber The handle number of AP that is to become t= he new BSP. +**/ +VOID +SwitchNewBsp ( + IN UINTN ProcessorNumber + ); + +/** + Function that uses DEBUG() macros to display the contents of a a CPU fea= ture bit mask. + + @param[in] FeatureMask A pointer to the CPU feature bit mask. +**/ +VOID +DumpCpuFeatureMask ( + IN UINT8 *FeatureMask + ); + +/** + Dump CPU feature name or CPU feature bit mask. + + @param[in] CpuFeature Pointer to CPU_FEATURES_ENTRY +**/ +VOID +DumpCpuFeature ( + IN CPU_FEATURES_ENTRY *CpuFeature + ); + +#endif diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesD= xe.uni b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesDxe.u= ni new file mode 100644 index 0000000..b0c313b --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesDxe.uni @@ -0,0 +1,22 @@ +// /** @file +// CPU Register Table Library instance. +// +// CPU Register Table Library instance. +// +// Copyright (c) 2016, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "CPU Register Tabl= e Library instance" + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Register Tabl= e Library instance." + diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesL= ib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c new file mode 100644 index 0000000..7a1470b --- /dev/null +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c @@ -0,0 +1,770 @@ +/** @file + CPU Register Table Library functions. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "RegisterCpuFeatures.h" + +/** + Checks if two CPU feature bit masks are equal. + + @param[in] FirstFeatureMask The first input CPU feature bit mask + @param[in] SecondFeatureMask The second input CPU feature bit mask + + @retval TRUE Two CPU feature bit masks are equal. + @retval FALSE Two CPU feature bit masks are not equal. +**/ +BOOLEAN +IsCpuFeatureMatch ( + IN UINT8 *FirstFeatureMask, + IN UINT8 *SecondFeatureMask + ) +{ + UINT32 BitMaskSize; + + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + if (CompareMem (FirstFeatureMask, SecondFeatureMask, BitMaskSize) =3D=3D= 0) { + return TRUE; + } else { + return FALSE; + } +} + +/** + Function that uses DEBUG() macros to display the contents of a a CPU fea= ture bit mask. + + @param[in] FeatureMask A pointer to the CPU feature bit mask. +**/ +VOID +DumpCpuFeatureMask ( + IN UINT8 *FeatureMask + ) +{ + UINTN Index; + UINT8 *Data8; + UINT32 BitMaskSize; + + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + Data8 =3D (UINT8 *) FeatureMask; + for (Index =3D 0; Index < BitMaskSize; Index++) { + DEBUG ((DEBUG_INFO, " %02x ", *Data8++)); + } + DEBUG ((DEBUG_INFO, "\n")); +} + +/** + Dump CPU feature name or CPU feature bit mask. + + @param[in] CpuFeature Pointer to CPU_FEATURES_ENTRY +**/ +VOID +DumpCpuFeature ( + IN CPU_FEATURES_ENTRY *CpuFeature + ) +{ + + if (CpuFeature->FeatureName !=3D NULL) { + DEBUG ((DEBUG_INFO, "FeatureName: %a\n", CpuFeature->FeatureName)); + } else { + DEBUG ((DEBUG_INFO, "FeatureMask =3D ")); + DumpCpuFeatureMask (CpuFeature->FeatureMask); + } +} + +/** + Determines if the feature bit mask is in dependent CPU feature bit mask = buffer. + + @param[in] FeatureMask Pointer to CPU feature bit mask + @param[in] DependentBitMask Pointer to dependent CPU feature bit mask= buffer + + @retval TRUE The feature bit mask is in dependent CPU feature bit mask = buffer. + @retval FALSE The feature bit mask is not in dependent CPU feature bit m= ask buffer. +**/ +BOOLEAN +IsBitMaskMatchCheck ( + IN UINT8 *FeatureMask, + IN UINT8 *DependentBitMask + ) +{ + UINTN Index; + UINTN BitMaskSize; + UINT8 *Data1; + UINT8 *Data2; + + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + + Data1 =3D FeatureMask; + Data2 =3D DependentBitMask; + for (Index =3D 0; Index < BitMaskSize; Index++) { + if (((*(Data1++)) & (*(Data2++))) !=3D 0) { + return TRUE; + } + } + return FALSE; +} + +/** + Checks and adjusts CPU features order per dependency relationship. + + @param[in] FeatureList Pointer to CPU feature list +**/ +VOID +CheckCpuFeaturesDependency ( + IN LIST_ENTRY *FeatureList + ) +{ + LIST_ENTRY *CurrentEntry; + CPU_FEATURES_ENTRY *CpuFeature; + LIST_ENTRY *CheckEntry; + CPU_FEATURES_ENTRY *CheckFeature; + BOOLEAN Swapped; + LIST_ENTRY *TempEntry; + + CurrentEntry =3D GetFirstNode (FeatureList); + while (!IsNull (FeatureList, CurrentEntry)) { + Swapped =3D FALSE; + CpuFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (CurrentEntry); + if (CpuFeature->BeforeAll) { + // + // Check all features dispatched before this entry + // + CheckEntry =3D GetFirstNode (FeatureList); + while (CheckEntry !=3D CurrentEntry) { + CheckFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (CheckEntry); + if (!CheckFeature->BeforeAll) { + // + // If this feature has no BeforeAll flag and is dispatched befor= e CpuFeature, + // insert currentEntry before Checked feature + // + RemoveEntryList (CurrentEntry); + InsertTailList (CheckEntry, CurrentEntry); + Swapped =3D TRUE; + break; + } + CheckEntry =3D CheckEntry->ForwardLink; + } + if (Swapped) { + continue; + } + } + + if (CpuFeature->AfterAll) { + // + // Check all features dispatched after this entry + // + CheckEntry =3D GetNextNode (FeatureList, CurrentEntry); + while (!IsNull (FeatureList, CheckEntry)) { + CheckFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (CheckEntry); + if (!CheckFeature->AfterAll) { + // + // If this feature has no AfterAll flag and is dispatched after = CpuFeature, + // insert currentEntry after Checked feature + // + TempEntry =3D GetNextNode (FeatureList, CurrentEntry); + RemoveEntryList (CurrentEntry); + InsertHeadList (CheckEntry, CurrentEntry); + CurrentEntry =3D TempEntry; + Swapped =3D TRUE; + break; + } + CheckEntry =3D CheckEntry->ForwardLink; + } + if (Swapped) { + continue; + } + } + + if (CpuFeature->BeforeFeatureBitMask !=3D NULL) { + // + // Check all features dispatched before this entry + // + CheckEntry =3D GetFirstNode (FeatureList); + while (CheckEntry !=3D CurrentEntry) { + CheckFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (CheckEntry); + if (IsBitMaskMatchCheck (CheckFeature->FeatureMask, CpuFeature->Be= foreFeatureBitMask)) { + // + // If there is dependency, swap them + // + RemoveEntryList (CurrentEntry); + InsertTailList (CheckEntry, CurrentEntry); + Swapped =3D TRUE; + break; + } + CheckEntry =3D CheckEntry->ForwardLink; + } + if (Swapped) { + continue; + } + } + + if (CpuFeature->AfterFeatureBitMask !=3D NULL) { + // + // Check all features dispatched after this entry + // + CheckEntry =3D GetNextNode (FeatureList, CurrentEntry); + while (!IsNull (FeatureList, CheckEntry)) { + CheckFeature =3D CPU_FEATURE_ENTRY_FROM_LINK (CheckEntry); + if (IsBitMaskMatchCheck (CheckFeature->FeatureMask, CpuFeature->Af= terFeatureBitMask)) { + // + // If there is dependency, swap them + // + TempEntry =3D GetNextNode (FeatureList, CurrentEntry); + RemoveEntryList (CurrentEntry); + InsertHeadList (CheckEntry, CurrentEntry); + CurrentEntry =3D TempEntry; + Swapped =3D TRUE; + break; + } + CheckEntry =3D CheckEntry->ForwardLink; + } + if (Swapped) { + continue; + } + } + // + // No swap happened, check the next feature + // + CurrentEntry =3D CurrentEntry->ForwardLink; + } +} + +/** + Worker function to register CPU Feature. + + @param[in] CpuFeature Pointer to CPU feature entry + + @retval RETURN_SUCCESS The CPU feature was successfully regis= tered. + @retval RETURN_OUT_OF_RESOURCES There are not enough resources to regi= ster + the CPU feature. + @retval RETURN_UNSUPPORTED Registration of the CPU feature is not + supported due to a circular dependency= between + BEFORE and AFTER features. +**/ +RETURN_STATUS +RegisterCpuFeatureWorker ( + IN CPU_FEATURES_ENTRY *CpuFeature + ) +{ + EFI_STATUS Status; + CPU_FEATURES_DATA *CpuFeaturesData; + CPU_FEATURES_ENTRY *CpuFeatureEntry; + LIST_ENTRY *Entry; + UINT32 BitMaskSize; + BOOLEAN FeatureExist; + + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + CpuFeaturesData =3D GetCpuFeaturesData (); + if (CpuFeaturesData->FeaturesCount =3D=3D 0) { + InitializeListHead (&CpuFeaturesData->FeatureList); + InitializeSpinLock (&CpuFeaturesData->MsrLock); + InitializeSpinLock (&CpuFeaturesData->MemoryMappedLock); + CpuFeaturesData->BitMaskSize =3D BitMaskSize; + } + ASSERT (CpuFeaturesData->BitMaskSize =3D=3D BitMaskSize); + + FeatureExist =3D FALSE; + Entry =3D GetFirstNode (&CpuFeaturesData->FeatureList); + while (!IsNull (&CpuFeaturesData->FeatureList, Entry)) { + CpuFeatureEntry =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); + if (IsCpuFeatureMatch (CpuFeature->FeatureMask, CpuFeatureEntry->Featu= reMask)) { + // + // If this feature already registered + // + FeatureExist =3D TRUE; + break; + } + Entry =3D Entry->ForwardLink; + } + + if (!FeatureExist) { + DEBUG ((DEBUG_INFO, "[NEW] ")); + DumpCpuFeature (CpuFeature); + InsertTailList (&CpuFeaturesData->FeatureList, &CpuFeature->Link); + CpuFeaturesData->FeaturesCount++; + } else { + DEBUG ((DEBUG_INFO, "[OVERRIDE] ")); + DumpCpuFeature (CpuFeature); + // + // Overwrite original parameters of CPU feature + // + if (CpuFeature->GetConfigDataFunc !=3D NULL) { + CpuFeatureEntry->GetConfigDataFunc =3D CpuFeature->GetConfigDataFunc; + } + if (CpuFeature->SupportFunc !=3D NULL) { + CpuFeatureEntry->SupportFunc =3D CpuFeature->SupportFunc; + } + if (CpuFeature->InitializeFunc !=3D NULL) { + CpuFeatureEntry->InitializeFunc =3D CpuFeature->InitializeFunc; + } + if (CpuFeature->FeatureName !=3D NULL) { + if (CpuFeatureEntry->FeatureName =3D=3D NULL) { + CpuFeatureEntry->FeatureName =3D AllocatePool (CPU_FEATURE_NAME_SI= ZE); + ASSERT (CpuFeatureEntry->FeatureName !=3D NULL); + } + Status =3D AsciiStrCpyS (CpuFeatureEntry->FeatureName, CPU_FEATURE_N= AME_SIZE, CpuFeature->FeatureName); + ASSERT_EFI_ERROR (Status); + FreePool (CpuFeature->FeatureName); + } + if (CpuFeature->BeforeFeatureBitMask !=3D NULL) { + if (CpuFeatureEntry->BeforeFeatureBitMask !=3D NULL) { + FreePool (CpuFeatureEntry->BeforeFeatureBitMask); + } + CpuFeatureEntry->BeforeFeatureBitMask =3D CpuFeature->BeforeFeatureB= itMask; + } + if (CpuFeature->AfterFeatureBitMask !=3D NULL) { + if (CpuFeatureEntry->AfterFeatureBitMask !=3D NULL) { + FreePool (CpuFeatureEntry->AfterFeatureBitMask); + } + CpuFeatureEntry->AfterFeatureBitMask =3D CpuFeature->AfterFeatureBit= Mask; + } + CpuFeatureEntry->BeforeAll =3D CpuFeature->BeforeAll; + CpuFeatureEntry->AfterAll =3D CpuFeature->AfterAll; + + FreePool (CpuFeature->FeatureMask); + FreePool (CpuFeature); + } + // + // Verify CPU features dependency can change CPU feature order + // + CheckCpuFeaturesDependency (&CpuFeaturesData->FeatureList); + return RETURN_SUCCESS; +} + +/** + Sets CPU feature bit mask in CPU feature bit mask buffer. + + @param[in] FeaturesBitMask Pointer to CPU feature bit mask buffer + @param[in] Feature The bit number of the CPU feature + @param[in] BitMaskSize CPU feature bit mask buffer size +**/ +VOID +SetCpuFeaturesBitMask ( + IN UINT8 **FeaturesBitMask, + IN UINT32 Feature, + IN UINTN BitMaskSize + ) +{ + UINT8 *CpuFeaturesBitMask; + + ASSERT (FeaturesBitMask !=3D NULL); + CpuFeaturesBitMask =3D *FeaturesBitMask; + if (CpuFeaturesBitMask =3D=3D NULL) { + CpuFeaturesBitMask =3D AllocateZeroPool (BitMaskSize); + ASSERT (CpuFeaturesBitMask !=3D NULL); + *FeaturesBitMask =3D CpuFeaturesBitMask; + } + + CpuFeaturesBitMask +=3D (Feature / 8); + *CpuFeaturesBitMask |=3D (UINT8) (1 << (Feature % 8)); +} + +/** + Registers a CPU Feature. + + @param GetConfigDataFunc CPU feature get configuration data function. = This + is an optional parameter that may be NULL. I= f NULL, + then the most recently registered function fo= r the + CPU feature is used. If no functions are reg= istered + for a CPU feature, then the CPU configuration= data + for the registered feature is NULL. + @param SupportFunc CPU feature support function. This is an opt= ional + parameter that may be NULL. If NULL, then th= e most + recently registered function for the CPU feat= ure is + used. If no functions are registered for a CPU + feature, then the CPU feature is assumed to be + supported by all CPUs. + @param InitializeFunc CPU feature initialize function. This is an = optional + parameter that may be NULL. If NULL, then th= e most + recently registered function for the CPU feat= ure is + used. If no functions are registered for a CPU + feature, then the CPU feature initialization = is + skipped. + @param ... Variable argument list of UINT32 CPU feature = value. + Values with no modifiers are the features pro= vided + by the registered functions. + Values with CPU_FEATURE_BEFORE modifier are f= eatures + that must be initialized after the features p= rovided + by the registered functions are used. + Values with CPU_FEATURE_AFTER modifier are fe= atures + that must be initialized before the features = provided + by the registered functions are used. + The last argument in this variable argument l= ist must + always be CPU_FEATURE_END. + + @retval RETURN_SUCCESS The CPU feature was successfully regis= tered. + @retval RETURN_OUT_OF_RESOURCES There are not enough resources to regi= ster + the CPU feature. + @retval RETURN_UNSUPPORTED Registration of the CPU feature is not + supported due to a circular dependency= between + BEFORE and AFTER features. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +RegisterCpuFeature ( + IN CHAR8 *FeatureName, OPTIONAL + IN CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc, OPTIONAL + IN CPU_FEATURE_SUPPORT SupportFunc, OPTIONAL + IN CPU_FEATURE_INITIALIZE InitializeFunc, OPTIONAL + ... + ) +{ + EFI_STATUS Status; + VA_LIST Marker; + UINT32 Feature; + UINTN BitMaskSize; + CPU_FEATURES_ENTRY *CpuFeature; + UINT8 *FeatureMask; + UINT8 *BeforeFeatureBitMask; + UINT8 *AfterFeatureBitMask; + BOOLEAN BeforeAll; + BOOLEAN AfterAll; + + FeatureMask =3D NULL; + BeforeFeatureBitMask =3D NULL; + AfterFeatureBitMask =3D NULL; + BeforeAll =3D FALSE; + AfterAll =3D FALSE; + + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + + VA_START (Marker, InitializeFunc); + Feature =3D VA_ARG (Marker, UINT32); + while (Feature !=3D CPU_FEATURE_END) { + ASSERT ((Feature & (CPU_FEATURE_BEFORE | CPU_FEATURE_AFTER)) + !=3D (CPU_FEATURE_BEFORE | CPU_FEATURE_AFTER)); + ASSERT ((Feature & (CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL)) + !=3D (CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL)); + if (Feature < CPU_FEATURE_BEFORE) { + BeforeAll =3D ((Feature & CPU_FEATURE_BEFORE_ALL) !=3D 0) ? TRUE : F= ALSE; + AfterAll =3D ((Feature & CPU_FEATURE_AFTER_ALL) !=3D 0) ? TRUE : FA= LSE; + Feature &=3D ~(CPU_FEATURE_BEFORE_ALL | CPU_FEATURE_AFTER_ALL); + ASSERT (FeatureMask =3D=3D NULL); + SetCpuFeaturesBitMask (&FeatureMask, Feature, BitMaskSize); + } else if ((Feature & CPU_FEATURE_BEFORE) !=3D 0) { + SetCpuFeaturesBitMask (&BeforeFeatureBitMask, Feature & ~CPU_FEATURE= _BEFORE, BitMaskSize); + } else if ((Feature & CPU_FEATURE_AFTER) !=3D 0) { + SetCpuFeaturesBitMask (&AfterFeatureBitMask, Feature & ~CPU_FEATURE_= AFTER, BitMaskSize); + } + Feature =3D VA_ARG (Marker, UINT32); + } + VA_END (Marker); + + CpuFeature =3D AllocateZeroPool (sizeof (CPU_FEATURES_ENTRY)); + ASSERT (CpuFeature !=3D NULL); + CpuFeature->Signature =3D CPU_FEATURE_ENTRY_SIGNATURE; + CpuFeature->FeatureMask =3D FeatureMask; + CpuFeature->BeforeFeatureBitMask =3D BeforeFeatureBitMask; + CpuFeature->AfterFeatureBitMask =3D AfterFeatureBitMask; + CpuFeature->BeforeAll =3D BeforeAll; + CpuFeature->AfterAll =3D AfterAll; + CpuFeature->GetConfigDataFunc =3D GetConfigDataFunc; + CpuFeature->SupportFunc =3D SupportFunc; + CpuFeature->InitializeFunc =3D InitializeFunc; + if (FeatureName !=3D NULL) { + CpuFeature->FeatureName =3D AllocatePool (CPU_FEATURE_NAME_SI= ZE); + ASSERT (CpuFeature->FeatureName !=3D NULL); + Status =3D AsciiStrCpyS (CpuFeature->FeatureName, CPU_FEATURE_NAME_SIZ= E, FeatureName); + ASSERT_EFI_ERROR (Status); + } + + Status =3D RegisterCpuFeatureWorker (CpuFeature); + ASSERT_EFI_ERROR (Status); + + return RETURN_SUCCESS; +} + +/** + Add an entry in specified register table. + + This function adds an entry in specified register table, with given regi= ster type, + register index, bit section and value. + + @param[in] PreSmmFlag If TRUE, entry will be added into PreSmm re= gister table + If FALSE, entry will be added into register= table + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] ValidBitStart Start of the bit section + @param[in] ValidBitLength Length of the bit section + @param[in] Value Value to write +**/ +VOID +CpuRegisterTableWriteWorker ( + IN BOOLEAN PreSmmFlag, + IN UINTN ProcessorNumber, + IN REGISTER_TYPE RegisterType, + IN UINT32 Index, + IN UINT8 ValidBitStart, + IN UINT8 ValidBitLength, + IN UINT64 Value + ) +{ + EFI_STATUS Status; + CPU_FEATURES_DATA *CpuFeaturesData; + ACPI_CPU_DATA *AcpiCpuData; + CPU_REGISTER_TABLE *RegisterTable; + CPU_REGISTER_TABLE_ENTRY *RegisterTableEntry; + + CpuFeaturesData =3D GetCpuFeaturesData (); + if (CpuFeaturesData->RegisterTable =3D=3D NULL) { + AcpiCpuData =3D (ACPI_CPU_DATA *) (UINTN) PcdGet64 (PcdCpuS3DataAddres= s); + if (AcpiCpuData =3D=3D NULL) { + AcpiCpuData =3D AllocateAcpiCpuData (); + ASSERT (AcpiCpuData !=3D NULL); + // + // Set PcdCpuS3DataAddress to the base address of the ACPI_CPU_DATA = structure + // + Status =3D PcdSet64S (PcdCpuS3DataAddress, (UINT64)(UINTN)AcpiCpuDat= a); + ASSERT_EFI_ERROR (Status); + } + ASSERT (AcpiCpuData->RegisterTable !=3D 0); + CpuFeaturesData->RegisterTable =3D (CPU_REGISTER_TABLE *) (UINTN) Acpi= CpuData->RegisterTable; + CpuFeaturesData->PreSmmRegisterTable =3D (CPU_REGISTER_TABLE *) (UINTN= ) AcpiCpuData->PreSmmInitRegisterTable; + } + + if (PreSmmFlag) { + RegisterTable =3D &CpuFeaturesData->PreSmmRegisterTable[ProcessorNumbe= r]; + } else { + RegisterTable =3D &CpuFeaturesData->RegisterTable[ProcessorNumber]; + } + + if (RegisterTable->TableLength =3D=3D RegisterTable->AllocatedSize / siz= eof (CPU_REGISTER_TABLE_ENTRY)) { + EnlargeRegisterTable (RegisterTable); + } + + // + // Append entry in the register table. + // + RegisterTableEntry =3D (CPU_REGISTER_TABLE_ENTRY *) (UINTN) RegisterTabl= e->RegisterTableEntry; + RegisterTableEntry[RegisterTable->TableLength].RegisterType =3D Regist= erType; + RegisterTableEntry[RegisterTable->TableLength].Index =3D Index; + RegisterTableEntry[RegisterTable->TableLength].ValidBitStart =3D ValidB= itStart; + RegisterTableEntry[RegisterTable->TableLength].ValidBitLength =3D ValidB= itLength; + RegisterTableEntry[RegisterTable->TableLength].Value =3D Value; + + RegisterTable->TableLength++; +} + +/** + Adds an entry in specified register table. + + This function adds an entry in specified register table, with given regi= ster type, + register index, bit section and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] ValueMask Mask of bits in register to write + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +CpuRegisterTableWrite ( + IN UINTN ProcessorNumber, + IN REGISTER_TYPE RegisterType, + IN UINT32 Index, + IN UINT64 ValueMask, + IN UINT64 Value + ) +{ + UINT8 Start; + UINT8 End; + UINT8 Length; + + Start =3D (UINT8)LowBitSet64 (ValueMask); + End =3D (UINT8)HighBitSet64 (ValueMask); + Length =3D End - Start + 1; + CpuRegisterTableWriteWorker (FALSE, ProcessorNumber, RegisterType, Index= , Start, Length, Value); +} + +/** + Adds an entry in specified Pre-SMM register table. + + This function adds an entry in specified register table, with given regi= ster type, + register index, bit section and value. + + @param[in] ProcessorNumber The index of the CPU to add a register tabl= e entry. + @param[in] RegisterType Type of the register to program + @param[in] Index Index of the register to program + @param[in] ValueMask Mask of bits in register to write + @param[in] Value Value to write + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +PreSmmCpuRegisterTableWrite ( + IN UINTN ProcessorNumber, + IN REGISTER_TYPE RegisterType, + IN UINT32 Index, + IN UINT64 ValueMask, + IN UINT64 Value + ) +{ + UINT8 Start; + UINT8 End; + UINT8 Length; + + Start =3D (UINT8)LowBitSet64 (ValueMask); + End =3D (UINT8)HighBitSet64 (ValueMask); + Length =3D End - Start + 1; + CpuRegisterTableWriteWorker (TRUE, ProcessorNumber, RegisterType, Index,= Start, Length, Value); +} + +/** + Worker function to determine if a CPU feature is set in input CPU featur= e bit mask buffer. + + @param[in] CpuBitMask CPU feature bit mask buffer + @param[in] CpuBitMaskSize The size of CPU feature bit mask buffer + @param[in] Feature The bit number of the CPU feature + + @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport. + +**/ +BOOLEAN +IsCpuFeatureSetInCpuPcd ( + IN UINT8 *CpuBitMask, + IN UINTN CpuBitMaskSize, + IN UINT32 Feature + ) +{ + if ((Feature >> 3) >=3D CpuBitMaskSize) { + return FALSE; + } + return ((*(CpuBitMask + (Feature >> 3)) & (1 << (Feature & 0x07))) !=3D = 0); +} + +/** + Determines if a CPU feature is enabled in PcdCpuFeaturesSupport bit mask. + If a CPU feature is disabled in PcdCpuFeaturesSupport then all the code/= data + associated with that feature should be optimized away if compiler + optimizations are enabled. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesSupport + + @retval TRUE The CPU feature is set in PcdCpuFeaturesSupport. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesSupport. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureSupported ( + IN UINT32 Feature + ) +{ + return IsCpuFeatureSetInCpuPcd ( + (UINT8 *)PcdGetPtr (PcdCpuFeaturesSupport), + PcdGetSize (PcdCpuFeaturesSupport), + Feature + ); +} + +/** + Determines if a CPU feature is set in PcdCpuFeaturesSetting bit mask. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesSetting + + @retval TRUE The CPU feature is set in PcdCpuFeaturesSetting. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesSetting. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureInSetting ( + IN UINT32 Feature + ) +{ + return IsCpuFeatureSetInCpuPcd ( + (UINT8 *)PcdGetPtr (PcdCpuFeaturesSetting), + PcdGetSize (PcdCpuFeaturesSetting), + Feature + ); +} + +/** + Determines if a CPU feature is set in PcdCpuFeaturesCapability bit mask. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesCapability + + @retval TRUE The CPU feature is set in PcdCpuFeaturesCapability. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesCapability. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureCapability ( + IN UINT32 Feature + ) +{ + return IsCpuFeatureSetInCpuPcd ( + (UINT8 *)PcdGetPtr (PcdCpuFeaturesCapability), + PcdGetSize (PcdCpuFeaturesCapability), + Feature + ); + +} + +/** + Determines if a CPU feature is set in PcdCpuFeaturesUserConfiguration bi= t mask. + + @param[in] Feature The bit number of the CPU feature to check in the P= CD + PcdCpuFeaturesUserConfiguration + + @retval TRUE The CPU feature is set in PcdCpuFeaturesUserConfiguratio= n. + @retval FALSE The CPU feature is not set in PcdCpuFeaturesUserConfigur= ation. + + @note This service could be called by BSP only. +**/ +BOOLEAN +EFIAPI +IsCpuFeatureUserConfiguration ( + IN UINT32 Feature + ) +{ + return IsCpuFeatureSetInCpuPcd ( + (UINT8 *)PcdGetPtr (PcdCpuFeaturesUserConfiguration), + PcdGetSize (PcdCpuFeaturesUserConfiguration), + Feature + ); + +} + +/** + Switches to assigned BSP after CPU features initialization. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + + @note This service could be called by BSP only. +**/ +VOID +EFIAPI +SwitchBspAfterFeaturesInitialize ( + IN UINTN ProcessorNumber + ) +{ + CPU_FEATURES_DATA *CpuFeaturesData; + + CpuFeaturesData =3D GetCpuFeaturesData (); + CpuFeaturesData->BspNumber =3D ProcessorNumber; +} + diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 3922f2d..59a702f 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -1,7 +1,7 @@ ## @file # UefiCpuPkg Package # -# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the B= SD License @@ -76,6 +76,7 @@ HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf + RegisterCpuFeaturesLib|UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegi= sterCpuFeaturesLib.inf =20 [LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/= PeiServicesTablePointerLibIdt.inf @@ -89,6 +90,7 @@ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + RegisterCpuFeaturesLib|UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegi= sterCpuFeaturesLib.inf =20 [LibraryClasses.common.DXE_SMM_DRIVER] SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableL= ib.inf @@ -126,6 +128,8 @@ UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf UefiCpuPkg/Library/MtrrLib/MtrrLib.inf UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf + UefiCpuPkg/Library/RegisterCpuFeaturesLib/PeiRegisterCpuFeaturesLib.inf + UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.i= nf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1489048596722508.1327635804075; Thu, 9 Mar 2017 00:36:36 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1D02A80391; Thu, 9 Mar 2017 00:36:28 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A73798038F for ; Thu, 9 Mar 2017 00:36:26 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:26 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:22 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930990" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:52 +0800 Message-Id: <20170309083553.6016-11-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 10/11] UefiCpuPkg: Add NULL CPU Common Features Library instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This NULL CPU common Features Library instance will register some CPU featu= res defined in Intel(R) 64 and IA-32 Architectures Software Developer's Manual, Volume 3, September 2016, Chapter 35 Model-Specific-Registers (MSR). Add PCD PcdCpuClockModulationDutyCycle and PcdIsPowerOnReset consumed by NU= LL CPU Common Features Library instance. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/Library/CpuCommonFeaturesLib/Aesni.c | 94 +++ UefiCpuPkg/Library/CpuCommonFeaturesLib/C1e.c | 79 ++ .../Library/CpuCommonFeaturesLib/ClockModulation.c | 106 +++ .../CpuCommonFeaturesLib/CpuCommonFeatures.h | 852 +++++++++++++++++= ++++ .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c | 227 ++++++ .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf | 68 ++ .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.uni | 25 + UefiCpuPkg/Library/CpuCommonFeaturesLib/Eist.c | 81 ++ .../Library/CpuCommonFeaturesLib/ExecuteDisable.c | 91 +++ .../Library/CpuCommonFeaturesLib/FastStrings.c | 52 ++ .../Library/CpuCommonFeaturesLib/FeatureControl.c | 315 ++++++++ .../CpuCommonFeaturesLib/LimitCpuIdMaxval.c | 82 ++ .../Library/CpuCommonFeaturesLib/MachineCheck.c | 231 ++++++ .../Library/CpuCommonFeaturesLib/MonitorMwait.c | 79 ++ .../Library/CpuCommonFeaturesLib/PendingBreak.c | 90 +++ UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c | 81 ++ UefiCpuPkg/UefiCpuPkg.dec | 11 + 17 files changed, 2564 insertions(+) create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/Aesni.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/C1e.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation= .c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatur= es.h create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatur= esLib.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatur= esLib.inf create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatur= esLib.uni create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/Eist.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/ExecuteDisable.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/FastStrings.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/LimitCpuIdMaxva= l.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/MonitorMwait.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/PendingBreak.c create mode 100644 UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/Aesni.c b/UefiCpuPkg/L= ibrary/CpuCommonFeaturesLib/Aesni.c new file mode 100644 index 0000000..6aebf0d --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/Aesni.c @@ -0,0 +1,94 @@ +/** @file + AESNI feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if AESNI feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE AESNI feature is supported. + @retval FALSE AESNI feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +AesniSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + if (IS_SANDY_BRIDGE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayM= odel) || + IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayMod= el) || + IS_XEON_5600_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayMode= l) || + IS_XEON_PHI_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel= )) { + return (CpuInfo->CpuIdVersionInfoEcx.Bits.AESNI =3D=3D 1); + } + return FALSE; +} + +/** + Initializes AESNI feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the AESNI feature must be ena= bled. + If FALSE, then the AESNI feature must be di= sabled. + + @retval RETURN_SUCCESS AESNI feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +AesniInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + // + // SANDY_BRIDGE, SILVERMONT, XEON_5600 and XEON_PHI have the same MSR in= dex, + // Simply use MSR_SANDY_BRIDGE_FEATURE_CONFIG here + // + // + // SANDY_BRIDGE, SILVERMONT, XEON_5600 and XEON_PHI have the same MSR in= dex, + // Simply use MSR_SANDY_BRIDGE_FEATURE_CONFIG here + // + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_SANDY_BRIDGE_FEATURE_CONFIG, + MSR_SANDY_BRIDGE_FEATURE_CONFIG_REGISTER, + Bits.AESConfiguration, + BIT1 | ((State) ? 0 : BIT0) + ); + + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/C1e.c b/UefiCpuPkg/Lib= rary/CpuCommonFeaturesLib/C1e.c new file mode 100644 index 0000000..116590f --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/C1e.c @@ -0,0 +1,79 @@ +/** @file + C1E feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if C1E feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE C1E feature is supported. + @retval FALSE C1E feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +C1eSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return IS_NEHALEM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayMod= el); +} + +/** + Initializes C1E feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the C1E feature must be enabl= ed. + If FALSE, then the C1E feature must be disa= bled. + + @retval RETURN_SUCCESS C1E feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +C1eInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_NEHALEM_POWER_CTL, + MSR_NEHALEM_POWER_CTL_REGISTER, + Bits.C1EEnable, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c b/Ue= fiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c new file mode 100644 index 0000000..adbe075 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c @@ -0,0 +1,106 @@ +/** @file + Clock Modulation feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if Clock Modulation feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Clock Modulation feature is supported. + @retval FALSE Clock Modulation feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +ClockModulationSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return (CpuInfo->CpuIdVersionInfoEdx.Bits.ACPI =3D=3D 1); +} + +/** + Initializes Clock Modulation feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Clock Modulation feature = must be enabled. + If FALSE, then the Clock Modulation feature= must be disabled. + + @retval RETURN_SUCCESS Clock Modulation feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +ClockModulationInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + if (IS_SANDY_BRIDGE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayM= odel)) { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_SANDY_BRIDGE_IA32_CLOCK_MODULATION, + MSR_SANDY_BRIDGE_IA32_CLOCK_MODULATION_REGISTER, + Bits.OnDemandClockModulationDutyCycle, + PcdGet8 (PcdCpuClockModulationDutyCycle) + ); + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_SANDY_BRIDGE_IA32_CLOCK_MODULATION, + MSR_SANDY_BRIDGE_IA32_CLOCK_MODULATION_REGISTER, + Bits.OnDemandClockModulationEnable, + (State) ? 1 : 0 + ); + } else { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_CLOCK_MODULATION, + MSR_IA32_CLOCK_MODULATION_REGISTER, + Bits.OnDemandClockModulationDutyCycle, + PcdGet8 (PcdCpuClockModulationDutyCycle) + ); + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_CLOCK_MODULATION, + MSR_IA32_CLOCK_MODULATION_REGISTER, + Bits.OnDemandClockModulationEnable, + (State) ? 1 : 0 + ); + } + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h b/= UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h new file mode 100644 index 0000000..51c9d5b --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h @@ -0,0 +1,852 @@ +/** @file + CPU Common features library header file. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#ifndef _CPU_COMMON_FEATURES_H_ +#define _CPU_COMMON_FEATURES_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/** + Detects if AESNI feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE AESNI feature is supported. + @retval FALSE AESNI feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +AesniSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes AESNI feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the AESNI feature must be ena= bled. + If FALSE, then the AESNI feature must be di= sabled. + + @retval RETURN_SUCCESS AESNI feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +AesniInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Clock Modulation feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Clock Modulation feature is supported. + @retval FALSE Clock Modulation feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +ClockModulationSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Clock Modulation feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Clock Modulation feature = must be enabled. + If FALSE, then the Clock Modulation feature= must be disabled. + + @retval RETURN_SUCCESS Clock Modulation feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +ClockModulationInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Enhanced Intel SpeedStep feature supported on current process= or. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Enhanced Intel SpeedStep feature is supported. + @retval FALSE Enhanced Intel SpeedStep feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +EistSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Enhanced Intel SpeedStep feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Enhanced Intel SpeedStep = feature + must be enabled. + If FALSE, then the Enhanced Intel SpeedStep= feature + must be disabled. + + @retval RETURN_SUCCESS Enhanced Intel SpeedStep feature is initial= ized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +EistInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Execute Disable feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Execute Disable feature is supported. + @retval FALSE Execute Disable feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +ExecuteDisableSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Execute Disable feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Execute Disable feature m= ust be enabled. + If FALSE, then the Execute Disable feature = must be disabled. + + @retval RETURN_SUCCESS Execute Disable feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +ExecuteDisableInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Initializes Fast-Strings feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Fast-Strings feature must= be enabled. + If FALSE, then the Fast-Strings feature mus= t be disabled. + + @retval RETURN_SUCCESS Fast-Strings feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +FastStringsInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if MONITOR/MWAIT feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE MONITOR/MWAIT feature is supported. + @retval FALSE MONITOR/MWAIT feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +MonitorMwaitSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes MONITOR/MWAIT feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the MONITOR/MWAIT feature mus= t be enabled. + If FALSE, then the MONITOR/MWAIT feature mu= st be disabled. + + @retval RETURN_SUCCESS MONITOR/MWAIT feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +MonitorMwaitInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if VMX feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE VMX feature is supported. + @retval FALSE VMX feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +VmxSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes VMX inside SMX feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the VMX inside SMX feature mu= st be enabled. + If FALSE, then the VMX inside SMX feature m= ust be disabled. + + @retval RETURN_SUCCESS VMX inside SMX feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +VmxInsideSmxInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Initializes SENTER feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the SENTER feature must be en= abled. + If FALSE, then the SENTER feature must be d= isabled. + + @retval RETURN_SUCCESS SENTER feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +SenterInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Lock Feature Control Register feature supported on current pr= ocessor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Lock Feature Control Register feature is supported. + @retval FALSE Lock Feature Control Register feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +LockFeatureControlRegisterSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Lock Feature Control Register feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Lock Feature Control Regi= ster feature must be enabled. + If FALSE, then the Lock Feature Control Reg= ister feature must be disabled. + + @retval RETURN_SUCCESS Lock Feature Control Register feature is in= itialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +LockFeatureControlRegisterInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if SMX feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE SMX feature is supported. + @retval FALSE SMX feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +SmxSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes VMX outside SMX feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the VMX outside SMX feature m= ust be enabled. + If FALSE, then the VMX outside SMX feature = must be disabled. + + @retval RETURN_SUCCESS VMX outside SMX feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +VmxOutsideSmxInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if LimitCpuidMaxval feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE LimitCpuidMaxval feature is supported. + @retval FALSE LimitCpuidMaxval feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +LimitCpuidMaxvalSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes LimitCpuidMaxval feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the LimitCpuidMaxval feature = must be enabled. + If FALSE, then the LimitCpuidMaxval feature= must be disabled. + + @retval RETURN_SUCCESS LimitCpuidMaxval feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +LimitCpuidMaxvalInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Machine Check Exception feature supported on current processo= r. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Machine Check Exception feature is supported. + @retval FALSE Machine Check Exception feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +MceSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Machine Check Exception feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Machine Check Exception f= eature must be enabled. + If FALSE, then the Machine Check Exception = feature must be disabled. + + @retval RETURN_SUCCESS Machine Check Exception feature is initiali= zed. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +MceInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Machine Check Architecture feature supported on current proce= ssor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Machine Check Architecture feature is supported. + @retval FALSE Machine Check Architecture feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +McaSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Machine Check Architecture feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Machine Check Architectur= e feature must be enabled. + If FALSE, then the Machine Check Architectu= re feature must be disabled. + + @retval RETURN_SUCCESS Machine Check Architecture feature is initi= alized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +McaInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if IA32_MCG_CTL feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE IA32_MCG_CTL feature is supported. + @retval FALSE IA32_MCG_CTL feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +McgCtlSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes IA32_MCG_CTL feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the IA32_MCG_CTL feature must= be enabled. + If FALSE, then the IA32_MCG_CTL feature mus= t be disabled. + + @retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +McgCtlInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if Pending Break feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Pending Break feature is supported. + @retval FALSE Pending Break feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +PendingBreakSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes Pending Break feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Pending Break feature mus= t be enabled. + If FALSE, then the Pending Break feature mu= st be disabled. + + @retval RETURN_SUCCESS Pending Break feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +PendingBreakInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if C1E feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE C1E feature is supported. + @retval FALSE C1E feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +C1eSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes C1E feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the C1E feature must be enabl= ed. + If FALSE, then the C1E feature must be disa= bled. + + @retval RETURN_SUCCESS C1E feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +C1eInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Detects if X2Apci feature supported on current processor. + + Detect if X2Apci has been already enabled. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE X2Apci feature is supported. + @retval FALSE X2Apci feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +X2ApicSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ); + +/** + Initializes X2Apci feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the X2Apci feature must be en= abled. + If FALSE, then the X2Apci feature must be d= isabled. + + @retval RETURN_SUCCESS X2Apci feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +X2ApicInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ); + +/** + Prepares for the data used by CPU feature detection and initialization. + + @param[in] NumberOfProcessors The number of CPUs in the platform. + + @return Pointer to a buffer of CPU related configuration data. + + @note This service could be called by BSP only. +**/ +VOID * +EFIAPI +FeatureControlGetConfigData ( + IN UINTN NumberOfProcessors + ); + +#endif diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c= b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c new file mode 100644 index 0000000..f5dbaef --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c @@ -0,0 +1,227 @@ +/** @file + This library registers CPU features defined in Intel(R) 64 and IA-32 + Architectures Software Developer's Manual. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Register CPU features. + + @retval RETURN_SUCCESS Register successfully +**/ +RETURN_STATUS +EFIAPI +CpuCommonFeaturesLibConstructor ( + VOID + ) +{ + RETURN_STATUS Status; + + if (IsCpuFeatureSupported (CPU_FEATURE_AESNI)) { + Status =3D RegisterCpuFeature ( + "AESNI", + NULL, + AesniSupport, + AesniInitialize, + CPU_FEATURE_AESNI, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_MWAIT)) { + Status =3D RegisterCpuFeature ( + "MWAIT", + NULL, + MonitorMwaitSupport, + MonitorMwaitInitialize, + CPU_FEATURE_MWAIT, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_ACPI)) { + Status =3D RegisterCpuFeature ( + "ACPI", + NULL, + ClockModulationSupport, + ClockModulationInitialize, + CPU_FEATURE_ACPI, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_EIST)) { + Status =3D RegisterCpuFeature ( + "EIST", + NULL, + EistSupport, + EistInitialize, + CPU_FEATURE_EIST, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_XD)) { + Status =3D RegisterCpuFeature ( + "Execute Disable", + NULL, + ExecuteDisableSupport, + ExecuteDisableInitialize, + CPU_FEATURE_XD, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_FASTSTRINGS)) { + Status =3D RegisterCpuFeature ( + "FastStrings", + NULL, + NULL, + FastStringsInitialize, + CPU_FEATURE_FASTSTRINGS, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER)) { + Status =3D RegisterCpuFeature ( + "Lock Feature Control Register", + FeatureControlGetConfigData, + LockFeatureControlRegisterSupport, + LockFeatureControlRegisterInitialize, + CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_SENTER)) { + Status =3D RegisterCpuFeature ( + "SENTER", + FeatureControlGetConfigData, + VmxSupport, + SenterInitialize, + CPU_FEATURE_SENTER, + CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEF= ORE, + CPU_FEATURE_SMX | CPU_FEATURE_AFTER, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_VMX)) { + Status =3D RegisterCpuFeature ( + "VMX", + FeatureControlGetConfigData, + VmxSupport, + VmxInsideSmxInitialize, + CPU_FEATURE_VMX, + CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEF= ORE, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_SMX)) { + Status =3D RegisterCpuFeature ( + "SMX", + FeatureControlGetConfigData, + SmxSupport, + VmxOutsideSmxInitialize, + CPU_FEATURE_SMX, + CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEF= ORE, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_LIMIT_CPUID_MAX_VAL)) { + Status =3D RegisterCpuFeature ( + "Limit CpuId Maximum Value", + NULL, + LimitCpuidMaxvalSupport, + LimitCpuidMaxvalInitialize, + CPU_FEATURE_LIMIT_CPUID_MAX_VAL, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_MCE)) { + Status =3D RegisterCpuFeature ( + "Machine Check Enable", + NULL, + MceSupport, + MceInitialize, + CPU_FEATURE_MCE, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_MCA)) { + Status =3D RegisterCpuFeature ( + "Machine Check Architect", + NULL, + McaSupport, + McaInitialize, + CPU_FEATURE_MCA, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_MCG_CTL)) { + Status =3D RegisterCpuFeature ( + "MCG_CTL", + NULL, + McgCtlSupport, + McgCtlInitialize, + CPU_FEATURE_MCG_CTL, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_PENDING_BREAK)) { + Status =3D RegisterCpuFeature ( + "Pending Break", + NULL, + PendingBreakSupport, + PendingBreakInitialize, + CPU_FEATURE_PENDING_BREAK, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_C1E)) { + Status =3D RegisterCpuFeature ( + "C1E", + NULL, + C1eSupport, + C1eInitialize, + CPU_FEATURE_C1E, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + if (IsCpuFeatureSupported (CPU_FEATURE_X2APIC)) { + Status =3D RegisterCpuFeature ( + "X2Apic", + NULL, + X2ApicSupport, + X2ApicInitialize, + CPU_FEATURE_X2APIC, + CPU_FEATURE_END + ); + ASSERT_EFI_ERROR (Status); + } + + return RETURN_SUCCESS; +} + + + diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.i= nf b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf new file mode 100644 index 0000000..7287d4e --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf @@ -0,0 +1,68 @@ +## @file +# NULL instance to register CPU features. +# +# This library registers CPU features defined in Intel(R) 64 and IA-32 +# Architectures Software Developer's Manual. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D CpuCommonFeaturesLib + MODULE_UNI_FILE =3D CpuCommonFeaturesLib.uni + FILE_GUID =3D 387A2490-81FC-4E7C-8E0A-3E58C30FCD0B + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NULL + + CONSTRUCTOR =3D CpuCommonFeaturesLibConstructor + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + CpuCommonFeaturesLib.c + CpuCommonFeatures.h + Aesni.c + C1e.c + ClockModulation.c + Eist.c + ExecuteDisable.c + FastStrings.c + FeatureControl.c + LimitCpuIdMaxval.c + MachineCheck.c + MonitorMwait.c + PendingBreak.c + X2Apic.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + RegisterCpuFeaturesLib + BaseMemoryLib + MemoryAllocationLib + LocalApicLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSupport # CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdCpuClockModulationDutyCycle # SOMETIME_CO= NSUMES + gUefiCpuPkgTokenSpaceGuid.PcdIsPowerOnReset # SOMETIME_CO= NSUMES + diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.u= ni b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.uni new file mode 100644 index 0000000..620766e --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.uni @@ -0,0 +1,25 @@ +// /** @file +// Dxe Crc32 Guided Section Extract library. +// +// This library doesn't produce any library class. The constructor functio= n uses +// ExtractGuidedSectionLib service to register CRC32 guided section handler +// that parses CRC32 encapsulation section and extracts raw data. +// +// It uses UEFI boot service CalculateCrc32 to authenticate 32 bit CRC val= ue. +// +// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD License +// which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Dxe Crc32 Guided = Section Extract library." + +#string STR_MODULE_DESCRIPTION #language en-US "This library does= n't produce any library class. The constructor function uses ExtractGuidedS= ectionLib service to register CRC32 guided section handler that parses CRC3= 2 encapsulation section and extracts raw data. It uses UEFI boot service Ca= lculateCrc32 to authenticate 32 bit CRC value." + diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/Eist.c b/UefiCpuPkg/Li= brary/CpuCommonFeaturesLib/Eist.c new file mode 100644 index 0000000..e1d3d42 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/Eist.c @@ -0,0 +1,81 @@ +/** @file + Enhanced Intel SpeedStep feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if Enhanced Intel SpeedStep feature supported on current process= or. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Enhanced Intel SpeedStep feature is supported. + @retval FALSE Enhanced Intel SpeedStep feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +EistSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return (CpuInfo->CpuIdVersionInfoEcx.Bits.EIST =3D=3D 1); +} + +/** + Initializes Enhanced Intel SpeedStep feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Enhanced Intel SpeedStep = feature + must be enabled. + If FALSE, then the Enhanced Intel SpeedStep= feature + must be disabled. + + @retval RETURN_SUCCESS Enhanced Intel SpeedStep feature is initial= ized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +EistInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_MISC_ENABLE, + MSR_IA32_MISC_ENABLE_REGISTER, + Bits.EIST, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/ExecuteDisable.c b/Uef= iCpuPkg/Library/CpuCommonFeaturesLib/ExecuteDisable.c new file mode 100644 index 0000000..cc3e040 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/ExecuteDisable.c @@ -0,0 +1,91 @@ +/** @file + Execute Disable feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if Execute Disable feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Execute Disable feature is supported. + @retval FALSE Execute Disable feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +ExecuteDisableSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + UINT32 Eax; + CPUID_EXTENDED_CPU_SIG_EDX Edx; + + AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL); + if (Eax <=3D CPUID_EXTENDED_FUNCTION) { + // + // Extended CPUID functions are not supported on this processor. + // + return FALSE; + } + + AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &Edx.Uint32); + return (Edx.Bits.NX !=3D 0); +} + +/** + Initializes Execute Disable feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Execute Disable feature m= ust be enabled. + If FALSE, then the Execute Disable feature = must be disabled. + + @retval RETURN_SUCCESS Execute Disable feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +ExecuteDisableInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_MISC_ENABLE, + MSR_IA32_MISC_ENABLE_REGISTER, + Bits.XD, + (State) ? 0 : 1 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FastStrings.c b/UefiCp= uPkg/Library/CpuCommonFeaturesLib/FastStrings.c new file mode 100644 index 0000000..4c3000d --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FastStrings.c @@ -0,0 +1,52 @@ +/** @file + Fast-Strings feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Initializes Fast-Strings feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Fast-Strings feature must= be enabled. + If FALSE, then the Fast-Strings feature mus= t be disabled. + + @retval RETURN_SUCCESS Fast-Strings feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +FastStringsInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_MISC_ENABLE, + MSR_IA32_MISC_ENABLE_REGISTER, + Bits.FastStrings, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c b/Uef= iCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c new file mode 100644 index 0000000..b022949 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c @@ -0,0 +1,315 @@ +/** @file + Features in MSR_IA32_FEATURE_CONTROL register. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Prepares for the data used by CPU feature detection and initialization. + + @param[in] NumberOfProcessors The number of CPUs in the platform. + + @return Pointer to a buffer of CPU related configuration data. + + @note This service could be called by BSP only. +**/ +VOID * +EFIAPI +FeatureControlGetConfigData ( + IN UINTN NumberOfProcessors + ) +{ + VOID *ConfigData; + + ConfigData =3D AllocateZeroPool (sizeof (MSR_IA32_FEATURE_CONTROL_REGIST= ER) * NumberOfProcessors); + ASSERT (ConfigData !=3D NULL); + return ConfigData; +} + +/** + Detects if VMX feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE VMX feature is supported. + @retval FALSE VMX feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +VmxSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + MsrRegister[ProcessorNumber].Uint64 =3D AsmReadMsr64 (MSR_IA32_FEATURE_C= ONTROL); + return (CpuInfo->CpuIdVersionInfoEcx.Bits.VMX =3D=3D 1); +} + +/** + Initializes VMX inside SMX feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the VMX inside SMX feature mu= st be enabled. + If FALSE, then the VMX inside SMX feature m= ust be disabled. + + @retval RETURN_SUCCESS VMX inside SMX feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +VmxInsideSmxInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + if (MsrRegister[ProcessorNumber].Bits.Lock =3D=3D 0) { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.EnableVmxInsideSmx, + (State) ? 1 : 0 + ); + } + return RETURN_SUCCESS; +} + +/** + Initializes SENTER feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the SENTER feature must be en= abled. + If FALSE, then the SENTER feature must be d= isabled. + + @retval RETURN_SUCCESS SENTER feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +SenterInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + if (MsrRegister[ProcessorNumber].Bits.Lock =3D=3D 0) { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.SenterLocalFunctionEnables, + (State) ? 0x7F : 0 + ); + + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.SenterGlobalEnable, + (State) ? 1 : 0 + ); + } + return RETURN_SUCCESS; +} + +/** + Detects if Lock Feature Control Register feature supported on current pr= ocessor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Lock Feature Control Register feature is supported. + @retval FALSE Lock Feature Control Register feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +LockFeatureControlRegisterSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + MsrRegister[ProcessorNumber].Uint64 =3D AsmReadMsr64 (MSR_IA32_FEATURE_C= ONTROL); + return TRUE; +} + +/** + Initializes Lock Feature Control Register feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Lock Feature Control Regi= ster feature must be enabled. + If FALSE, then the Lock Feature Control Reg= ister feature must be disabled. + + @retval RETURN_SUCCESS Lock Feature Control Register feature is in= itialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +LockFeatureControlRegisterInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (State =3D=3D TRUE); + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + if (MsrRegister[ProcessorNumber].Bits.Lock =3D=3D 0) { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.Lock, + 1 + ); + } + return RETURN_SUCCESS; +} + +/** + Detects if SMX feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE SMX feature is supported. + @retval FALSE SMX feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +SmxSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + MsrRegister[ProcessorNumber].Uint64 =3D AsmReadMsr64 (MSR_IA32_FEATURE_C= ONTROL); + return (CpuInfo->CpuIdVersionInfoEcx.Bits.SMX =3D=3D 1); +} + +/** + Initializes VMX outside SMX feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the VMX outside SMX feature m= ust be enabled. + If FALSE, then the VMX outside SMX feature = must be disabled. + + @retval RETURN_SUCCESS VMX outside SMX feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +VmxOutsideSmxInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + + ASSERT (ConfigData !=3D NULL); + MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; + if (MsrRegister[ProcessorNumber].Bits.Lock =3D=3D 0) { + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.EnableVmxOutsideSmx, + (State) ? 1 : 0 + ); + } + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/LimitCpuIdMaxval.c b/U= efiCpuPkg/Library/CpuCommonFeaturesLib/LimitCpuIdMaxval.c new file mode 100644 index 0000000..0f51fb3 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/LimitCpuIdMaxval.c @@ -0,0 +1,82 @@ +/** @file + LimitCpuidMaxval Feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if LimitCpuidMaxval feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE LimitCpuidMaxval feature is supported. + @retval FALSE LimitCpuidMaxval feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +LimitCpuidMaxvalSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + UINT32 Eax; + + AsmCpuid (CPUID_SIGNATURE, &Eax, NULL, NULL, NULL); + return (Eax > 3); +} + +/** + Initializes LimitCpuidMaxval feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the LimitCpuidMaxval feature = must be enabled. + If FALSE, then the LimitCpuidMaxval feature= must be disabled. + + @retval RETURN_SUCCESS LimitCpuidMaxval feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +LimitCpuidMaxvalInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_MISC_ENABLE, + MSR_IA32_MISC_ENABLE_REGISTER, + Bits.LimitCpuidMaxval, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c b/UefiC= puPkg/Library/CpuCommonFeaturesLib/MachineCheck.c new file mode 100644 index 0000000..2d9501b --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MachineCheck.c @@ -0,0 +1,231 @@ +/** @file + Machine Check features. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if Machine Check Exception feature supported on current processo= r. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Machine Check Exception feature is supported. + @retval FALSE Machine Check Exception feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +MceSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCE =3D=3D 1); +} + +/** + Initializes Machine Check Exception feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Machine Check Exception f= eature must be enabled. + If FALSE, then the Machine Check Exception = feature must be disabled. + + @retval RETURN_SUCCESS Machine Check Exception feature is initiali= zed. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +MceInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + // + // Set MCE bit in CR4 + // + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + ControlRegister, + 4, + IA32_CR4, + Bits.MCE, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} + +/** + Detects if Machine Check Architecture feature supported on current proce= ssor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Machine Check Architecture feature is supported. + @retval FALSE Machine Check Architecture feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +McaSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return (CpuInfo->CpuIdVersionInfoEdx.Bits.MCA =3D=3D 1); +} + +/** + Initializes Machine Check Architecture feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Machine Check Architectur= e feature must be enabled. + If FALSE, then the Machine Check Architectu= re feature must be disabled. + + @retval RETURN_SUCCESS Machine Check Architecture feature is initi= alized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +McaInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + MSR_IA32_MCG_CAP_REGISTER McgCap; + UINT32 BankIndex; + + McgCap.Uint64 =3D AsmReadMsr64 (MSR_IA32_MCG_CAP); + for (BankIndex =3D 0; BankIndex < (UINT32) McgCap.Bits.Count; BankIndex+= +) { + CPU_REGISTER_TABLE_WRITE64 ( + ProcessorNumber, + Msr, + MSR_IA32_MC0_CTL + BankIndex * 4, + MAX_UINT64 + ); + } + + if (PcdGetBool (PcdIsPowerOnReset)) { + for (BankIndex =3D 0; BankIndex < (UINTN) McgCap.Bits.Count; BankIndex= ++) { + CPU_REGISTER_TABLE_WRITE64 ( + ProcessorNumber, + Msr, + MSR_IA32_MC0_STATUS + BankIndex * 4, + 0 + ); + } + } + + return RETURN_SUCCESS; +} + +/** + Detects if IA32_MCG_CTL feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE IA32_MCG_CTL feature is supported. + @retval FALSE IA32_MCG_CTL feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +McgCtlSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + MSR_IA32_MCG_CAP_REGISTER McgCap; + + if (!McaSupport (ProcessorNumber, CpuInfo, ConfigData)) { + return FALSE; + } + McgCap.Uint64 =3D AsmReadMsr64 (MSR_IA32_MCG_CAP); + return (McgCap.Bits.MCG_CTL_P =3D=3D 1); +} + +/** + Initializes IA32_MCG_CTL feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the IA32_MCG_CTL feature must= be enabled. + If FALSE, then the IA32_MCG_CTL feature mus= t be disabled. + + @retval RETURN_SUCCESS IA32_MCG_CTL feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +McgCtlInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE64 ( + ProcessorNumber, + Msr, + MSR_IA32_MCG_CTL, + (State)? MAX_UINT64 : 0 + ); + return RETURN_SUCCESS; +} + diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/MonitorMwait.c b/UefiC= puPkg/Library/CpuCommonFeaturesLib/MonitorMwait.c new file mode 100644 index 0000000..b1c18bc --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/MonitorMwait.c @@ -0,0 +1,79 @@ +/** @file + MonitorMwait feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if MONITOR/MWAIT feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE MONITOR/MWAIT feature is supported. + @retval FALSE MONITOR/MWAIT feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +MonitorMwaitSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return (CpuInfo->CpuIdVersionInfoEcx.Bits.MONITOR =3D=3D 1); +} + +/** + Initializes MONITOR/MWAIT feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the MONITOR/MWAIT feature mus= t be enabled. + If FALSE, then the MONITOR/MWAIT feature mu= st be disabled. + + @retval RETURN_SUCCESS MONITOR/MWAIT feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +MonitorMwaitInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_MISC_ENABLE, + MSR_IA32_MISC_ENABLE_REGISTER, + Bits.MONITOR, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/PendingBreak.c b/UefiC= puPkg/Library/CpuCommonFeaturesLib/PendingBreak.c new file mode 100644 index 0000000..2a1fd95 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/PendingBreak.c @@ -0,0 +1,90 @@ +/** @file + Pending Break feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if Pending Break feature supported on current processor. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE Pending Break feature is supported. + @retval FALSE Pending Break feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +PendingBreakSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + if (IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) || + IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) || + IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) || + IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayMode= l) || + IS_PENTIUM_M_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayMode= l)) { + return (CpuInfo->CpuIdVersionInfoEdx.Bits.PBE =3D=3D 1); + } + return FALSE; +} + +/** + Initializes Pending Break feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the Pending Break feature mus= t be enabled. + If FALSE, then the Pending Break feature mu= st be disabled. + + @retval RETURN_SUCCESS Pending Break feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +PendingBreakInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + // + // ATOM, CORE2, CORE, PENTIUM_4 and IS_PENTIUM_M_PROCESSOR have the same= MSR index, + // Simply use MSR_ATOM_IA32_MISC_ENABLE here + // + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_ATOM_IA32_MISC_ENABLE, + MSR_ATOM_IA32_MISC_ENABLE_REGISTER, + Bits.FERR, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c b/UefiCpuPkg/= Library/CpuCommonFeaturesLib/X2Apic.c new file mode 100644 index 0000000..7720540 --- /dev/null +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/X2Apic.c @@ -0,0 +1,81 @@ +/** @file + X2Apic feature. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include "CpuCommonFeatures.h" + +/** + Detects if X2Apci feature supported on current processor. + + Detect if X2Apci has been already enabled. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + + @retval TRUE X2Apci feature is supported. + @retval FALSE X2Apci feature is not supported. + + @note This service could be called by BSP/APs. +**/ +BOOLEAN +EFIAPI +X2ApicSupport ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData OPTIONAL + ) +{ + return (GetApicMode () =3D=3D LOCAL_APIC_MODE_X2APIC); +} + +/** + Initializes X2Apci feature to specific state. + + @param[in] ProcessorNumber The index of the CPU executing this functio= n. + @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION + structure for the CPU executing this functi= on. + @param[in] ConfigData A pointer to the configuration buffer retur= ned + by CPU_FEATURE_GET_CONFIG_DATA. NULL if + CPU_FEATURE_GET_CONFIG_DATA was not provide= d in + RegisterCpuFeature(). + @param[in] State If TRUE, then the X2Apci feature must be en= abled. + If FALSE, then the X2Apci feature must be d= isabled. + + @retval RETURN_SUCCESS X2Apci feature is initialized. + + @note This service could be called by BSP only. +**/ +RETURN_STATUS +EFIAPI +X2ApicInitialize ( + IN UINTN ProcessorNumber, + IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, + IN VOID *ConfigData, OPTIONAL + IN BOOLEAN State + ) +{ + PRE_SMM_CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_APIC_BASE, + MSR_IA32_APIC_BASE_REGISTER, + Bits.EXTD, + (State) ? 1 : 0 + ); + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 04c7c1e..745f986 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -245,6 +245,17 @@ # @Prompt User settings for enabling/disabling processor features. gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesUserConfiguration|{0x00, 0x00, 0= x00, 0x00, 0x00, 0x00, 0x00, 0x00}|VOID*|0x00000017 =20 + ## Specifies the On-demand clock modulation duty cycle when ACPI feature= is enabled. + # @Prompt The encoded values for target duty cycle modulation. + # @ValidRange 0x80000001 | 0 - 15 + gUefiCpuPkgTokenSpaceGuid.PcdCpuClockModulationDutyCycle|0x0|UINT8|0x000= 0001A + + ## Indicates if the current boot is a power-on reset.

+ # TRUE - Current boot is a power-on reset.
+ # FALSE - Current boot is not a power-on reset.
+ # @Prompt Current boot is a power-on reset. + gUefiCpuPkgTokenSpaceGuid.PcdIsPowerOnReset|FALSE|BOOLEAN|0x0000001B + [PcdsDynamic, PcdsDynamicEx] ## Contains the pointer to a CPU S3 data buffer of structure ACPI_CPU_DA= TA. # @Prompt The pointer to a CPU S3 data buffer. --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 12:34:25 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 148904860024667.3747329220597; Thu, 9 Mar 2017 00:36:40 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5E810803AC; Thu, 9 Mar 2017 00:36:28 -0800 (PST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E3C3180391 for ; Thu, 9 Mar 2017 00:36:26 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2017 00:36:26 -0800 Received: from jfan12-desk.ccr.corp.intel.com ([10.239.158.57]) by fmsmga002.fm.intel.com with ESMTP; 09 Mar 2017 00:36:25 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,268,1486454400"; d="scan'208";a="1139930997" From: Jeff Fan To: edk2-devel@lists.01.org Date: Thu, 9 Mar 2017 16:35:53 +0800 Message-Id: <20170309083553.6016-12-jeff.fan@intel.com> X-Mailer: git-send-email 2.9.3.windows.2 In-Reply-To: <20170309083553.6016-1-jeff.fan@intel.com> References: <20170309083553.6016-1-jeff.fan@intel.com> Subject: [edk2] [PATCH 11/11] UefiCpuPkg: Add CPU Features PEI/DXE drivers X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Feng Tian MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" They will consume Register CPU Features library to detect and initialize CPU features. CpuFeaturesPei driver is used to initialize CPU features in PEI phase. CpuFeaturesDxe driver is used to initialize CPU features in DXE phase. Add PcdCpuFeaturesInitAfterSmmRelocation and PcdCpuFeaturesInitOnS3Resume that consumed by CpuFeaturesPei and CpuFeaturesDxe. Cc: Feng Tian Cc: Michael Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c | 122 +++++++++++++++++++++= ++++ UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf | 53 +++++++++++ UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.uni | 22 +++++ UefiCpuPkg/CpuFeatures/CpuFeaturesDxeExtra.uni | 20 ++++ UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c | 75 +++++++++++++++ UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf | 49 ++++++++++ UefiCpuPkg/CpuFeatures/CpuFeaturesPei.uni | 22 +++++ UefiCpuPkg/CpuFeatures/CpuFeaturesPeiExtra.uni | 20 ++++ UefiCpuPkg/UefiCpuPkg.dec | 8 ++ UefiCpuPkg/UefiCpuPkg.dsc | 8 ++ 10 files changed, 399 insertions(+) create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.uni create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesDxeExtra.uni create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesPei.uni create mode 100644 UefiCpuPkg/CpuFeatures/CpuFeaturesPeiExtra.uni diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c b/UefiCpuPkg/CpuFeatur= es/CpuFeaturesDxe.c new file mode 100644 index 0000000..f4f70cf --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.c @@ -0,0 +1,122 @@ +/** @file + CPU Features DXE driver to initialize CPU features. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + + +/** + Worker function to perform CPU feature initialization. + +**/ +VOID +CpuFeaturesInitializeWorker ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + + CpuFeaturesDetect (); + + CpuFeaturesInitialize (); + + // + // Install CPU Features Init Done Protocol + // + Handle =3D NULL; + Status =3D gBS->InstallProtocolInterface ( + &Handle, + &gEdkiiCpuFeaturesInitDoneGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Event notification that initialize CPU features when gEfiSmmConfiguratio= nProtocol installs. + + @param[in] Event The Event that is being processed, not= used. + @param[in] Context Event Context, not used. +**/ +VOID +EFIAPI +SmmConfigurationEventNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_SMM_CONFIGURATION_PROTOCOL *SmmConfiguration; + + // + // Make sure this notification is for this handler + // + Status =3D gBS->LocateProtocol (&gEfiSmmConfigurationProtocolGuid, NULL,= (VOID **)&SmmConfiguration); + if (EFI_ERROR (Status)) { + return; + } + + CpuFeaturesInitializeWorker (); +} + +/** + CPU Features driver entry point function. + + If PcdCpuFeaturesInitAfterSmmRelocation is TRUE, it will register one + SMM Configuration Protocol notify function to perform CPU features + initialization. Otherwise, it will perform CPU features initialization + directly. + + @param ImageHandle Image handle this driver. + @param SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS CPU Features is initialized successfully. +**/ +EFI_STATUS +EFIAPI +CpuFeaturesDxeInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + VOID *Registration; + + if (PcdGetBool (PcdCpuFeaturesInitAfterSmmRelocation)) { + // + // Install notification callback on SMM Configuration Protocol + // + EfiCreateProtocolNotifyEvent ( + &gEfiSmmConfigurationProtocolGuid, + TPL_CALLBACK, + SmmConfigurationEventNotify, + NULL, + &Registration + ); + } else { + CpuFeaturesInitializeWorker (); + } + + return EFI_SUCCESS; +} + diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf b/UefiCpuPkg/CpuFeat= ures/CpuFeaturesDxe.inf new file mode 100644 index 0000000..5a3e4f0 --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf @@ -0,0 +1,53 @@ +## @file +# CPU Features DXE driver. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D CpuFeaturesDxe + MODULE_UNI_FILE =3D CpuFeaturesDxe.uni + FILE_GUID =3D 63EB1B62-10C9-4693-88AC-AE0999EA87F8 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + + ENTRY_POINT =3D CpuFeaturesDxeInitialize + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiLib + UefiDriverEntryPoint + UefiBootServicesTableLib + RegisterCpuFeaturesLib + +[Sources] + CpuFeaturesDxe.c + +[Guids] + gEdkiiCpuFeaturesInitDoneGuid ## PRODU= CES + +[Protocols] + gEfiSmmConfigurationProtocolGuid ## SOMET= IME_CONSUMES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesInitAfterSmmRelocation ## CONSU= MES + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + CpuFeaturesDxeExtra.uni diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.uni b/UefiCpuPkg/CpuFeat= ures/CpuFeaturesDxe.uni new file mode 100644 index 0000000..6f27bb9 --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.uni @@ -0,0 +1,22 @@ +// /** @file +// CPU Features DXE driver. +// +// CPU Features DXE driver. +// +// Copyright (c) 2017, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "CPU Features DXE = driver to initialize CPU features." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Features DXE = driver to initialize CPU features." + diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesDxeExtra.uni b/UefiCpuPkg/Cp= uFeatures/CpuFeaturesDxeExtra.uni new file mode 100644 index 0000000..a236e1e --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesDxeExtra.uni @@ -0,0 +1,20 @@ +// /** @file +// CpuFeaturesDxe Localized Strings and Content +// +// Copyright (c) 2017, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"CPU Features DXE Driver" + + diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c b/UefiCpuPkg/CpuFeatur= es/CpuFeaturesPei.c new file mode 100644 index 0000000..6292f5b --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.c @@ -0,0 +1,75 @@ +/** @file + CPU Features PEIM driver to initialize CPU features. + + Copyright (c) 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include + +#include +#include +#include +#include + +#include + +EFI_PEI_PPI_DESCRIPTOR mPeiCpuFeaturesInitDonePpiDesc =3D { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEdkiiCpuFeaturesInitDoneGuid, + NULL +}; + +/** + CPU Features driver entry point function. + + It will perform CPU features initialization, except for + PcdCpuFeaturesInitOnS3Resume is FALSE on S3 resume. + + @param FileHandle Handle of the file being invoked. + @param PeiServices Describes the list of possible PEI Services. + + @retval EFI_SUCCESS CPU Features is initialized successfully. +**/ +EFI_STATUS +EFIAPI +CpuFeaturesPeimInitialize ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + EFI_BOOT_MODE BootMode; + + Status =3D PeiServicesGetBootMode (&BootMode); + ASSERT_EFI_ERROR (Status); + + if (BootMode =3D=3D BOOT_ON_S3_RESUME && + !PcdGetBool (PcdCpuFeaturesInitOnS3Resume)) { + // + // Does nothing when if PcdCpuFeaturesInitOnS3Resume is FLASE + // on S3 boot mode + // + return EFI_SUCCESS; + } + + CpuFeaturesDetect (); + + CpuFeaturesInitialize (); + + // + // Install CPU Features Init Done PPI + // + Status =3D PeiServicesInstallPpi(&mPeiCpuFeaturesInitDonePpiDesc); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf b/UefiCpuPkg/CpuFeat= ures/CpuFeaturesPei.inf new file mode 100644 index 0000000..e306bb2 --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf @@ -0,0 +1,49 @@ +## @file +# CPU Features PEIM driver. +# +# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D CpuFeaturesPei + MODULE_UNI_FILE =3D CpuFeaturesPei.uni + FILE_GUID =3D 183BB3E1-A1E5-4445-8AC9-0E83B6547E0E + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + + ENTRY_POINT =3D CpuFeaturesPeimInitialize + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PeimEntryPoint + PeiServicesLib + RegisterCpuFeaturesLib + +[Sources] + CpuFeaturesPei.c + +[Guids] + gEdkiiCpuFeaturesInitDoneGuid ## PRODU= CES + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesInitOnS3Resume ## CONSU= MES + +[Depex] + TRUE + +[UserExtensions.TianoCore."ExtraFiles"] + CpuFeaturesPeiExtra.uni diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.uni b/UefiCpuPkg/CpuFeat= ures/CpuFeaturesPei.uni new file mode 100644 index 0000000..f56dbd1 --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesPei.uni @@ -0,0 +1,22 @@ +// /** @file +// CPU Features PEIM driver. +// +// CPU Features PEIM driver. +// +// Copyright (c) 2017, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "CPU Features PEIM= driver to initialize CPU features." + +#string STR_MODULE_DESCRIPTION #language en-US "CPU Features PEIM= driver to initialize CPU features." + diff --git a/UefiCpuPkg/CpuFeatures/CpuFeaturesPeiExtra.uni b/UefiCpuPkg/Cp= uFeatures/CpuFeaturesPeiExtra.uni new file mode 100644 index 0000000..0ffc619 --- /dev/null +++ b/UefiCpuPkg/CpuFeatures/CpuFeaturesPeiExtra.uni @@ -0,0 +1,20 @@ +// /** @file +// CpuFeaturesPei Localized Strings and Content +// +// Copyright (c) 2017, Intel Corporation. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +// +// **/ + +#string STR_PROPERTIES_MODULE_NAME +#language en-US +"CPU Features PEIM Driver" + + diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 745f986..4a679bd 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -196,6 +196,14 @@ # @Prompt Supported CPU features gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesSupport|{0xFF, 0xFF, 0xFF, 0xFF,= 0xFF, 0xFF, 0xFF, 0xFF}|VOID*|0x00000016 =20 + ## Specifies if CPU features will be initialized after SMM relocation + # @Prompt if CPU features will be initialized after SMM relocation + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesInitAfterSmmRelocation|FALSE|BOO= LEAN|0x0000001C + + ## Specifies if CPU features will be initialized during S3 resume + # @Prompt if CPU features will be initialized during S3 resume + gUefiCpuPkgTokenSpaceGuid.PcdCpuFeaturesInitOnS3Resume|FALSE|BOOLEAN|0x0= 000001D + [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] ## Specifies max supported number of Logical Processors. # @Prompt Configure max supported number of Logical Processors diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 59a702f..1336b0c 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -114,6 +114,14 @@ =20 [Components.IA32, Components.X64] UefiCpuPkg/CpuDxe/CpuDxe.inf + UefiCpuPkg/CpuFeatures/CpuFeaturesPei.inf { + + NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf + } + UefiCpuPkg/CpuFeatures/CpuFeaturesDxe.inf { + + NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf + } UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf UefiCpuPkg/CpuMpPei/CpuMpPei.inf UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf --=20 2.9.3.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel