From nobody Thu Dec 26 12:18:44 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 1506369527715940.3843464736051; Mon, 25 Sep 2017 12:58:47 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 41B3A2095E524; 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 B59B42095E51D for ; Mon, 25 Sep 2017 12:55:28 -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 081A75D697; Mon, 25 Sep 2017 19:58:40 +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 C21B460184; Mon, 25 Sep 2017 19:58:38 +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 081A75D697 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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:22 +0200 Message-Id: <20170925195824.10866-6-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.39]); Mon, 25 Sep 2017 19:58:40 +0000 (UTC) Subject: [edk2] [PATCH 5/7] OvmfPkg/PciHotPlugInitDxe: generalize RESOURCE_PADDING composition 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" PciHotPlugInitDxe has a static variable called "mPadding" (of type RESOURCE_PADDING), which describes two constant resource reservations: - MmioPadding: 2MB of non-prefetchable (hence 32-bit) MMIO space, - IoPadding: 512B of IO space. In the GetResourcePadding() member function of EFI_PCI_HOT_PLUG_INIT_PROTOCOL, the driver outputs a dynamically allocated verbatim copy of "mPadding", for PciBusDxe to consume in its ApplyResourcePadding() function. In a later patch, we're going to compose the set of resource reservations dynamically, based on QEMU hints. Generalize the RESOURCE_PADDING structure so that we may generate (or not generate) each resource type individually: - Replace the named "MmioPadding" and "IoPadding" fields in RESOURCE_PADDING with an array of descriptors, - remove "mPadding", - in GetResourcePadding(), request the same (default) reservations as before, as if we attempted and failed to fetch the QEMU hints. 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 | 163 ++++++++++++-------- 2 files changed, 99 insertions(+), 65 deletions(-) diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf b/OvmfPkg/PciHotP= lugInitDxe/PciHotPlugInit.inf index ea19206219b7..91729ae1ed04 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf @@ -28,8 +28,9 @@ [Packages] MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec =20 [LibraryClasses] + BaseMemoryLib DebugLib DevicePathLib MemoryAllocationLib UefiBootServicesTableLib diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c b/OvmfPkg/PciHotPlu= gInitDxe/PciHotPlugInit.c index 5c98f806def6..b1b2c5cd8ddc 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c @@ -14,8 +14,9 @@ **/ =20 #include =20 +#include #include #include #include #include @@ -41,83 +42,61 @@ STATIC EFI_PCI_HOT_PLUG_INIT_PROTOCOL mPciHotPlugInit; // // This structure is interpreted by the ApplyResourcePadding() function in= the // edk2 PCI Bus UEFI_DRIVER. // +// We can request padding for at most four resource types, each of which is +// optional, independently of the others: +// (a) bus numbers, +// (b) IO space, +// (c) non-prefetchable MMIO space (32-bit only), +// (d) prefetchable MMIO space (either 32-bit or 64-bit, never both). +// #pragma pack (1) typedef struct { - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR MmioPadding; - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR IoPadding; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR Padding[4]; EFI_ACPI_END_TAG_DESCRIPTOR EndDesc; } RESOURCE_PADDING; #pragma pack () =20 -STATIC CONST RESOURCE_PADDING mPadding =3D { - // - // MmioPadding - // - { - ACPI_ADDRESS_SPACE_DESCRIPTOR, // Desc - (UINT16)( // Len - sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - - OFFSET_OF ( - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR, - ResType - ) - ), - ACPI_ADDRESS_SPACE_TYPE_MEM, // ResType - 0, // GenFlag: - // ignored - 0, // SpecificFlag: - // non-prefetchable - 32, // AddrSpaceGranularity: - // reserve 32-bit aperture - 0, // AddrRangeMin: - // ignored - SIZE_2MB - 1, // AddrRangeMax: - // align at 2MB - 0, // AddrTranslationOffset: - // ignored - SIZE_2MB // AddrLen: - // 2MB padding - }, =20 - // - // IoPadding - // - { - ACPI_ADDRESS_SPACE_DESCRIPTOR, // Desc - (UINT16)( // Len - sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - - OFFSET_OF ( - EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR, - ResType - ) - ), - ACPI_ADDRESS_SPACE_TYPE_IO,// ResType - 0, // GenFlag: - // ignored - 0, // SpecificFlag: - // ignored - 0, // AddrSpaceGranularity: - // ignored - 0, // AddrRangeMin: - // ignored - 512 - 1, // AddrRangeMax: - // align at 512 IO ports - 0, // AddrTranslationOffset: - // ignored - 512 // AddrLen: - // 512 IO ports - }, +/** + Initialize a RESOURCE_PADDING object. + + @param[out] ResourcePadding The caller-allocated RESOURCE_PADDING objec= t to + initialize. +**/ +STATIC +VOID +InitializeResourcePadding ( + OUT RESOURCE_PADDING *ResourcePadding + ) +{ + UINTN Index; + + ZeroMem (ResourcePadding, sizeof *ResourcePadding); =20 // - // EndDesc + // Fill in the Padding fields that don't vary across resource types. // - { - ACPI_END_TAG_DESCRIPTOR, // Desc - 0 // Checksum: to be ignored + for (Index =3D 0; Index < ARRAY_SIZE (ResourcePadding->Padding); ++Index= ) { + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor; + + Descriptor =3D ResourcePadding->Padding + Index; + Descriptor->Desc =3D ACPI_ADDRESS_SPACE_DESCRIPTOR; + Descriptor->Len =3D (UINT16)( + sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - + OFFSET_OF ( + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR, + ResType + ) + ); } -}; + + // + // Fill in the End Tag. + // + ResourcePadding->EndDesc.Desc =3D ACPI_END_TAG_DESCRIPTOR; +} =20 =20 /** Returns a list of root Hot Plug Controllers (HPCs) that require @@ -274,8 +253,13 @@ GetResourcePadding ( OUT VOID **Padding, OUT EFI_HPC_PADDING_ATTRIBUTES *Attributes ) { + BOOLEAN DefaultIo; + BOOLEAN DefaultMmio; + RESOURCE_PADDING ReservationRequest; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *FirstResource; + DEBUG_CODE ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS *Address; CHAR16 *DevicePathString; =20 @@ -294,9 +278,58 @@ GetResourcePadding ( if (HpcState =3D=3D NULL || Padding =3D=3D NULL || Attributes =3D=3D NUL= L) { return EFI_INVALID_PARAMETER; } =20 - *Padding =3D AllocateCopyPool (sizeof mPadding, &mPadding); + DefaultIo =3D TRUE; + DefaultMmio =3D TRUE; + + // + // Init ReservationRequest, and point FirstResource one past the last + // descriptor entry. We're going to build the entries backwards from + // ReservationRequest.EndDesc. + // + InitializeResourcePadding (&ReservationRequest); + FirstResource =3D ReservationRequest.Padding + + ARRAY_SIZE (ReservationRequest.Padding); + + // + // (b) Reserve IO space. + // + 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 + } + + // + // (c) Reserve non-prefetchable MMIO space (32-bit only). + // + 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 + } + + // + // Output a copy of ReservationRequest from the lowest-address populated + // entry until the end of the structure (including + // ReservationRequest.EndDesc). If no reservations are necessary, we'll = only + // output the End Tag. + // + *Padding =3D AllocateCopyPool ( + (UINT8 *)(&ReservationRequest + 1) - (UINT8 *)FirstResource, + FirstResource + ); if (*Padding =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel