From nobody Thu Dec 26 12:53:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 1506369530383505.47311966635266; Mon, 25 Sep 2017 12:58:50 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7CEC52095E52C; Mon, 25 Sep 2017 12:55: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 5CB7E2095E526 for ; Mon, 25 Sep 2017 12:55:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E75281DFE; Mon, 25 Sep 2017 19:58:41 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-161.rdu2.redhat.com [10.10.120.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66CCB60176; Mon, 25 Sep 2017 19:58:40 +0000 (UTC) X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E75281DFE Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Mon, 25 Sep 2017 21:58:23 +0200 Message-Id: <20170925195824.10866-7-lersek@redhat.com> In-Reply-To: <20170925195824.10866-1-lersek@redhat.com> References: <20170925195824.10866-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 25 Sep 2017 19:58:41 +0000 (UTC) Subject: [edk2] [PATCH 6/7] OvmfPkg/PciHotPlugInitDxe: add helper functions for setting up paddings 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: Marcel Apfelbaum , Jordan Justen , Ruiyu Ni 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" Extract the SetIoPadding() and SetMmioPadding() functions, so that we can set EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR fields using parameter names and values that are more friendly than the original field names and their expected values. Introduce the HighBitSetRoundUp32() and HighBitSetRoundUp64() functions for calculating the last parameter ("SizeExponent") of SetIoPadding() and SetMmioPadding(). Put the new functions to use when requesting the default reservations. (In order to be consistent with a later patch, "SizeExponent" is calculated for SetIoPadding() with HighBitSetRoundUp64().) Cc: Jordan Justen Cc: Marcel Apfelbaum Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf | 1 + OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c | 165 ++++++++++++++++++-- 2 files changed, 156 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf b/OvmfPkg/PciHotP= lugInitDxe/PciHotPlugInit.inf index 91729ae1ed04..e0ec9baae1c2 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf @@ -28,8 +28,9 @@ [Packages] MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec =20 [LibraryClasses] + BaseLib BaseMemoryLib DebugLib DevicePathLib MemoryAllocationLib diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c b/OvmfPkg/PciHotPlu= gInitDxe/PciHotPlugInit.c index b1b2c5cd8ddc..39646973794b 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c @@ -14,8 +14,9 @@ **/ =20 #include =20 +#include #include #include #include #include @@ -97,8 +98,155 @@ InitializeResourcePadding ( ResourcePadding->EndDesc.Desc =3D ACPI_END_TAG_DESCRIPTOR; } =20 =20 +/** + Set up a descriptor entry for reserving IO space. + + @param[in,out] Descriptor The descriptor to configure. The caller shall= have + initialized Descriptor earlier, with + InitializeResourcePadding(). + + @param[in] SizeExponent The size and natural alignment of the reserva= tion + are determined by raising two to this power. +**/ +STATIC +VOID +SetIoPadding ( + IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor, + IN UINTN SizeExponent + ) +{ + Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_IO; + Descriptor->AddrLen =3D LShiftU64 (1, SizeExponent); + Descriptor->AddrRangeMax =3D Descriptor->AddrLen - 1; +} + + +/** + Set up a descriptor entry for reserving MMIO space. + + @param[in,out] Descriptor The descriptor to configure. The caller sha= ll + have initialized Descriptor earlier, with + InitializeResourcePadding(). + + @param[in] Prefetchable TRUE if the descriptor should reserve + prefetchable MMIO space. Pass FALSE for + reserving non-prefetchable MMIO space. + + @param[in] ThirtyTwoBitOnly TRUE if the reservation should be limited to + 32-bit address space. FALSE if the reservat= ion + can be satisfied from 64-bit address space. + ThirtyTwoBitOnly is ignored if Prefetchable= is + FALSE; in that case ThirtyTwoBitOnly is alw= ays + considered TRUE. + + @param[in] SizeExponent The size and natural alignment of the + reservation are determined by raising two to + this power. +**/ +STATIC +VOID +SetMmioPadding ( + IN OUT EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor, + IN BOOLEAN Prefetchable, + IN BOOLEAN ThirtyTwoBitOnly, + IN UINTN SizeExponent + ) +{ + Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; + if (Prefetchable) { + Descriptor->SpecificFlag =3D + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE; + Descriptor->AddrSpaceGranularity =3D ThirtyTwoBitOnly ? 32 : 64; + } else { + Descriptor->SpecificFlag =3D + EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_NON_CACHEABLE; + Descriptor->AddrSpaceGranularity =3D 32; + } + Descriptor->AddrLen =3D LShiftU64 (1, SizeExponent); + Descriptor->AddrRangeMax =3D Descriptor->AddrLen - 1; +} + + +/** + Round up a positive 32-bit value to the next whole power of two, and ret= urn + the bit position of the highest bit set in the result. Equivalent to + ceil(log2(x)). + + @param[in] Operand The 32-bit operand to evaluate. + + @retval -1 Operand is zero. + + @retval -1 Operand is positive, not a whole power of two, and roundi= ng it + up to the next power of two does not fit into 32 bits. + + @retval 0..31 Otherwise, return ceil(log2(Value)). +**/ +STATIC +INTN +HighBitSetRoundUp32 ( + IN UINT32 Operand + ) +{ + INTN HighBit; + + HighBit =3D HighBitSet32 (Operand); + if (HighBit =3D=3D -1) { + // + // Operand is zero. + // + return HighBit; + } + if ((Operand & (Operand - 1)) !=3D 0) { + // + // Operand is not a whole power of two. + // + ++HighBit; + } + return (HighBit < 32) ? HighBit : -1; +} + + +/** + Round up a positive 64-bit value to the next whole power of two, and ret= urn + the bit position of the highest bit set in the result. Equivalent to + ceil(log2(x)). + + @param[in] Operand The 64-bit operand to evaluate. + + @retval -1 Operand is zero. + + @retval -1 Operand is positive, not a whole power of two, and roundi= ng it + up to the next power of two does not fit into 64 bits. + + @retval 0..63 Otherwise, return ceil(log2(Value)). +**/ +STATIC +INTN +HighBitSetRoundUp64 ( + IN UINT64 Operand + ) +{ + INTN HighBit; + + HighBit =3D HighBitSet64 (Operand); + if (HighBit =3D=3D -1) { + // + // Operand is zero. + // + return HighBit; + } + if ((Operand & (Operand - 1)) !=3D 0) { + // + // Operand is not a whole power of two. + // + ++HighBit; + } + return (HighBit < 64) ? HighBit : -1; +} + + /** Returns a list of root Hot Plug Controllers (HPCs) that require initialization during the boot process. =20 @@ -297,12 +445,9 @@ GetResourcePadding ( if (DefaultIo) { // // Request defaults. // - --FirstResource; - FirstResource->ResType =3D ACPI_ADDRESS_SPACE_TYPE_IO; - FirstResource->AddrRangeMax =3D 512 - 1; // align at 512 IO ports - FirstResource->AddrLen =3D 512; // 512 IO ports + SetIoPadding (--FirstResource, (UINTN)HighBitSetRoundUp64 (512)); } =20 // // (c) Reserve non-prefetchable MMIO space (32-bit only). @@ -310,14 +455,14 @@ GetResourcePadding ( if (DefaultMmio) { // // Request defaults. // - --FirstResource; - FirstResource->ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; - FirstResource->SpecificFlag =3D 0; // non-prefetcha= ble - FirstResource->AddrSpaceGranularity =3D 32; // 32-bit apertu= re - FirstResource->AddrRangeMax =3D SIZE_2MB - 1; // align at 2MB - FirstResource->AddrLen =3D SIZE_2MB; // 2MB padding + SetMmioPadding ( + --FirstResource, + FALSE, + TRUE, + (UINTN)HighBitSetRoundUp32 (SIZE_2MB) + ); } =20 // // Output a copy of ReservationRequest from the lowest-address populated --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel