From nobody Sat Dec 28 11:36:46 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 1496942023239554.8826140119427; Thu, 8 Jun 2017 10:13:43 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C1A221967BEB; Thu, 8 Jun 2017 10:12:31 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 2AE8720082E76 for ; Thu, 8 Jun 2017 10:12:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8F64C01CB8B; Thu, 8 Jun 2017 17:13:37 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-122.phx2.redhat.com [10.3.116.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 262447F1C3; Thu, 8 Jun 2017 17:13:36 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E8F64C01CB8B Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lersek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E8F64C01CB8B From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 8 Jun 2017 19:13:29 +0200 Message-Id: <20170608171333.17937-2-lersek@redhat.com> In-Reply-To: <20170608171333.17937-1-lersek@redhat.com> References: <20170608171333.17937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 08 Jun 2017 17:13:38 +0000 (UTC) Subject: [edk2] [PATCH 1/5] OvmfPkg: introduce Q35TsegSizeLib (class header and sole lib instance) X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen 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" OvmfPkg contains three modules that work with the TSEG (SMRAM) size: PlatformPei (PEIM), SmmAccessPei (PEIM), and SmmAccess2Dxe (DXE_DRIVER). These modules open-code the interpretation of the ESMRAMC register's TSEG_SZ bit-field. That is OK as long as we stick with the Q35 hardware spec and nothing more, but it makes it difficult to benefit from an upcoming QEMU feature, namely extended TSEG sizes. Introduce the Q35TsegSizeLib class, and its sole lib instance, for extracting / centralizing TSEG size querying and interpretation. This library instance is self contained and does not consume dynamic PCDs (for example, it doesn't consume PcdOvmfHostBridgePciDevId), because such PCDs tend to be set in PlatformPei, but the dispatch order between PlatformPei and SmmAccessPei is unspecified (both have TRUE for DEPEX). In the next few patches we're going to rebase the three listed modules to Q35TsegSizeLib. As introduced, the library instance only captures the currently supported TSEG sizes. Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/OvmfPkg.dec | 5 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.inf | 47 +++++ OvmfPkg/Include/Library/Q35TsegSizeLib.h | 74 ++++++++ OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.c | 186 ++++++++++++++++++= ++ 7 files changed, 315 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 5627be0bab0a..7b9220369b95 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -27,14 +27,19 @@ [LibraryClasses] # LoadLinuxLib|Include/Library/LoadLinuxLib.h =20 ## @libraryclass Save and restore variables using a file # NvVarsFileLib|Include/Library/NvVarsFileLib.h =20 + ## @libraryclass Utility library to query TSEG size-related quantities= on + # Q35. + # + Q35TsegSizeLib|Include/Library/Q35TsegSizeLib.h + ## @libraryclass Access QEMU's firmware configuration interface # QemuFwCfgLib|Include/Library/QemuFwCfgLib.h =20 ## @libraryclass S3 support for QEMU fw_cfg # QemuFwCfgS3Lib|Include/Library/QemuFwCfgS3Lib.h diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 0647f346257a..8917c2f7b085 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -129,14 +129,15 @@ [LibraryClasses] UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf DevicePathLib|MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDev= icePathLibDevicePathProtocol.inf NvVarsFileLib|OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf + Q35TsegSizeLib|OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeS= ecurityManagementLib.inf NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 1182b1858a7d..56e9c5b790d7 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -134,14 +134,15 @@ [LibraryClasses] UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf DevicePathLib|MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDev= icePathLibDevicePathProtocol.inf NvVarsFileLib|OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf + Q35TsegSizeLib|OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeS= ecurityManagementLib.inf NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 636dfb1b5638..618b72bffa80 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -134,14 +134,15 @@ [LibraryClasses] UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf DevicePathLib|MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDev= icePathLibDevicePathProtocol.inf NvVarsFileLib|OvmfPkg/Library/NvVarsFileLib/NvVarsFileLib.inf + Q35TsegSizeLib|OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.inf FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeS= ecurityManagementLib.inf NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf diff --git a/OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.inf b/OvmfPkg/Li= brary/Q35TsegSizeLib/Q35TsegSizeLib.inf new file mode 100644 index 000000000000..8f99e55b8c48 --- /dev/null +++ b/OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.inf @@ -0,0 +1,47 @@ +## @file +# Utility library to query TSEG size-related quantities on Q35. +# +# Copyright (C) 2017, Red Hat, Inc. +# +# This program and the accompanying materials are licensed and made availa= ble +# 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, WI= THOUT +# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D Q35TsegSizeLib + FILE_GUID =3D 6019578F-0078-46D4-86EE-06C486A304D2 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D Q35TsegSizeLib|PEIM DXE_DRIVER + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + Q35TsegSizeLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + PciLib + +[FeaturePcd] + gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire + +[FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes diff --git a/OvmfPkg/Include/Library/Q35TsegSizeLib.h b/OvmfPkg/Include/Lib= rary/Q35TsegSizeLib.h new file mode 100644 index 000000000000..580ef6887931 --- /dev/null +++ b/OvmfPkg/Include/Library/Q35TsegSizeLib.h @@ -0,0 +1,74 @@ +/** @file + Utility library to query TSEG size-related quantities on Q35. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + 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, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#ifndef __Q35_TSEG_SIZE_LIB__ +#define __Q35_TSEG_SIZE_LIB__ + +/** + Query the preferred size of TSEG, in megabytes. + + The caller is responsible for calling this function only on the Q35 boar= d. If + the function is called on another board, the function logs an informative + error message and does not return. + + @return The preferred size of TSEG, expressed in megabytes. +**/ +UINT16 +EFIAPI +Q35TsegSizeGetPreferredMbytes ( + VOID + ); + +/** + Query the ESMRAMC.TSEG_SZ bit-field value that corresponds to the prefer= red + TSEG size. + + The caller is responsible for calling this function only on the Q35 boar= d. If + the function is called on another board, the function logs an informative + error message and does not return. + + @return The ESMRAMC.TSEG_SZ bit-field value that corresponds to the + preferred TSEG size. The return value is a subset of + MCH_ESMRAMC_TSEG_MASK, defined in . +**/ +UINT8 +EFIAPI +Q35TsegSizeGetPreferredEsmramcTsegSzMask ( + VOID + ); + +/** + Extract the TSEG_SZ bit-field from the passed in ESMRAMC register value,= and + return the number of megabytes that it represents. + + The caller is responsible for calling this function only on the Q35 boar= d. If + the function is called on another board, the function logs an informative + error message and does not return. + + @param[in] EsmramcVal The ESMRAMC register value to extract the TSEG_SZ + bit-field from, using MCH_ESMRAMC_TSEG_MASK from + . If the extracted + bit-field cannot be mapped to a MB count, the fun= ction + logs an error message and does not return. + + @return The number of megabytes that the extracted TSEG_SZ bit-field + represents. +**/ +UINT16 +EFIAPI +Q35TsegSizeConvertEsmramcValToMbytes ( + IN UINT8 EsmramcVal + ); + +#endif diff --git a/OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.c b/OvmfPkg/Libr= ary/Q35TsegSizeLib/Q35TsegSizeLib.c new file mode 100644 index 000000000000..db57a8b308de --- /dev/null +++ b/OvmfPkg/Library/Q35TsegSizeLib/Q35TsegSizeLib.c @@ -0,0 +1,186 @@ +/** @file + Utility library to query TSEG size-related quantities on Q35. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + 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, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include +#include +#include +#include +#include + +STATIC BOOLEAN mPreferencesInitialized; +STATIC UINT8 mPreferredEsmramcTsegSzMask; + +/** + Fetch the preferences into static variables that are going to be used by= the + public functions of this library instance. + + The Q35 board requirement documented on those interfaces is commonly enf= orced + here. +**/ +STATIC +VOID +Q35TsegSizeGetPreferences ( + VOID + ) +{ + UINT16 HostBridgeDevId; + + if (mPreferencesInitialized) { + return; + } + + // + // This function should only be reached if SMRAM support is required. + // + ASSERT (FeaturePcdGet (PcdSmmSmramRequire)); + + HostBridgeDevId =3D PciRead16 (OVMF_HOSTBRIDGE_DID); + if (HostBridgeDevId !=3D INTEL_Q35_MCH_DEVICE_ID) { + DEBUG (( + DEBUG_ERROR, + "%a: %a: no TSEG (SMRAM) on host bridge DID=3D0x%04x; " + "only DID=3D0x%04x (Q35) is supported\n", + gEfiCallerBaseName, + __FUNCTION__, + HostBridgeDevId, + INTEL_Q35_MCH_DEVICE_ID + )); + ASSERT (FALSE); + CpuDeadLoop (); + } + + mPreferencesInitialized =3D TRUE; + + switch (FixedPcdGet8 (PcdQ35TsegMbytes)) { + case 1: + mPreferredEsmramcTsegSzMask =3D MCH_ESMRAMC_TSEG_1MB; + break; + case 2: + mPreferredEsmramcTsegSzMask =3D MCH_ESMRAMC_TSEG_2MB; + break; + case 8: + mPreferredEsmramcTsegSzMask =3D MCH_ESMRAMC_TSEG_8MB; + break; + default: + ASSERT (FALSE); + } +} + + +/** + Query the preferred size of TSEG, in megabytes. + + The caller is responsible for calling this function only on the Q35 boar= d. If + the function is called on another board, the function logs an informative + error message and does not return. + + @return The preferred size of TSEG, expressed in megabytes. +**/ +UINT16 +EFIAPI +Q35TsegSizeGetPreferredMbytes ( + VOID + ) +{ + // + // Query the ESMRAMC.TSEG_SZ preference and convert it to megabytes. + // + return Q35TsegSizeConvertEsmramcValToMbytes ( + Q35TsegSizeGetPreferredEsmramcTsegSzMask () + ); +} + + +/** + Query the ESMRAMC.TSEG_SZ bit-field value that corresponds to the prefer= red + TSEG size. + + The caller is responsible for calling this function only on the Q35 boar= d. If + the function is called on another board, the function logs an informative + error message and does not return. + + @return The ESMRAMC.TSEG_SZ bit-field value that corresponds to the + preferred TSEG size. The return value is a subset of + MCH_ESMRAMC_TSEG_MASK, defined in . +**/ +UINT8 +EFIAPI +Q35TsegSizeGetPreferredEsmramcTsegSzMask ( + VOID + ) +{ + Q35TsegSizeGetPreferences (); + return mPreferredEsmramcTsegSzMask; +} + + +/** + Extract the TSEG_SZ bit-field from the passed in ESMRAMC register value,= and + return the number of megabytes that it represents. + + The caller is responsible for calling this function only on the Q35 boar= d. If + the function is called on another board, the function logs an informative + error message and does not return. + + @param[in] EsmramcVal The ESMRAMC register value to extract the TSEG_SZ + bit-field from, using MCH_ESMRAMC_TSEG_MASK from + . If the extracted + bit-field cannot be mapped to a MB count, the fun= ction + logs an error message and does not return. + + @return The number of megabytes that the extracted TSEG_SZ bit-field + represents. +**/ +UINT16 +EFIAPI +Q35TsegSizeConvertEsmramcValToMbytes ( + IN UINT8 EsmramcVal + ) +{ + UINT8 TsegSizeBits; + UINT16 Mbytes; + + Q35TsegSizeGetPreferences (); + + TsegSizeBits =3D EsmramcVal & MCH_ESMRAMC_TSEG_MASK; + switch (TsegSizeBits) { + case MCH_ESMRAMC_TSEG_1MB: + Mbytes =3D 1; + break; + case MCH_ESMRAMC_TSEG_2MB: + Mbytes =3D 2; + break; + case MCH_ESMRAMC_TSEG_8MB: + Mbytes =3D 8; + break; + default: + DEBUG (( + DEBUG_ERROR, + "%a: %a: unknown TsegSizeBits=3D0x%02x\n", + gEfiCallerBaseName, + __FUNCTION__, + TsegSizeBits + )); + ASSERT (FALSE); + CpuDeadLoop (); + + // + // Keep compilers happy. + // + Mbytes =3D 0; + } + + return Mbytes; +} --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel