From nobody Tue May 7 11:18:48 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1556223953; cv=none; d=zoho.com; s=zohoarc; b=ZSEoODUPQa2XQlIM5alBpxryUZvmbV2+B0HMFsRxERgdsO5gxAOMuFujz9wwsNhpfbp66bAV7NyvIsUhN6fJJvFDuBnUgbClqlgSlxwvBvkLp6sO1+7j5y5ml1TA6izwAoIeJR2SbAdzM6UXOoV2egVCc11fX61xc6/CrERNgiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556223953; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6P4FOl5pL+d9ZyBhpTlJ4pNeSeUQ2DnqO/G3VZ8EFnk=; b=NtCIs0PbPiUwLLLFwwHawYxEjQWUts2EVJr2gM/PWl+JHFCKTEt3s85UGYUIJSBEzrbb6qWpdLg5c/cL8NpPiz28JmiOWhQwwSPUjGYmzkbgD79PTv+ShnteSHJrheeQ+MY+txyf1igSLHJsigLNXJii/zLOCNttCCAdU54tsoM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1556223953615214.4284963782593; Thu, 25 Apr 2019 13:25:53 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkuy-0001Ii-NT; Thu, 25 Apr 2019 20:24:28 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkux-0001IT-LR for xen-devel@lists.xenproject.org; Thu, 25 Apr 2019 20:24:27 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1eebf84b-6798-11e9-843c-bc764e045a96; Thu, 25 Apr 2019 20:24:26 +0000 (UTC) X-Inumbo-ID: 1eebf84b-6798-11e9-843c-bc764e045a96 X-IronPort-AV: E=Sophos;i="5.60,394,1549929600"; d="scan'208";a="84450965" From: Igor Druzhinin To: Date: Thu, 25 Apr 2019 21:23:56 +0100 Message-ID: <1556223838-5176-2-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556223838-5176-1-git-send-email-igor.druzhinin@citrix.com> References: <1556223838-5176-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , ard.biesheuvel@linaro.org, jordan.l.justen@intel.com, julien.grall@arm.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org, lersek@redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This aperture doesn't exist in QEMU-XEN and hvmloader places BARs in arbitrary order disregarding prefetchable bit. This makes prefetchable and non-prefetchable BARs to follow each other that's quite likely with PCI passthrough devices. In that case, the existing code, that tries to work out aperture boundaries by reading hvmloader BAR placement, will report a bogus prefetchable aperture which overlaps with the regular one. It will eventually trigger an assertion in DXE PCI initialization code. Do the same thing as OVMF on QEMU-KVM and pass a non-existing aperture there. It's not necessary to pass additional allocation flags as we set ResourceAssigned flag on the root bridge which means they will be ignored. Reviewed-by: Anthony PERARD Signed-off-by: Igor Druzhinin --- OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 34 ++++++++++-------------= ---- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Librar= y/PciHostBridgeLib/XenSupport.c index afb2c5e..354b0a5 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c @@ -60,9 +60,7 @@ PcatPciRootBridgeParseBars ( IN UINTN BarOffsetEnd, IN PCI_ROOT_BRIDGE_APERTURE *Io, IN PCI_ROOT_BRIDGE_APERTURE *Mem, - IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G, - IN PCI_ROOT_BRIDGE_APERTURE *PMem, - IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G + IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G =20 ) { @@ -123,11 +121,7 @@ PcatPciRootBridgeParseBars ( // Length =3D ((~Length) + 1) & 0xffffffff; =20 - if ((Value & BIT3) =3D=3D BIT3) { - MemAperture =3D PMem; - } else { - MemAperture =3D Mem; - } + MemAperture =3D Mem; } else { // // 64bit @@ -143,11 +137,7 @@ PcatPciRootBridgeParseBars ( Length =3D Length | LShiftU64 ((UINT64) UpperValue, 32); Length =3D (~Length) + 1; =20 - if ((Value & BIT3) =3D=3D BIT3) { - MemAperture =3D PMemAbove4G; - } else { - MemAperture =3D MemAbove4G; - } + MemAperture =3D MemAbove4G; } =20 Limit =3D Base + Length - 1; @@ -164,6 +154,8 @@ PcatPciRootBridgeParseBars ( } } =20 +STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture =3D { MAX_UINT64, 0 }; + PCI_ROOT_BRIDGE * ScanForRootBridges ( UINTN *NumberOfRootBridges @@ -180,7 +172,7 @@ ScanForRootBridges ( UINT64 Base; UINT64 Limit; UINT64 Value; - PCI_ROOT_BRIDGE_APERTURE Io, Mem, MemAbove4G, PMem, PMemAbove4G, *MemApe= rture; + PCI_ROOT_BRIDGE_APERTURE Io, Mem, MemAbove4G, *MemAperture; PCI_ROOT_BRIDGE *RootBridges; UINTN BarOffsetEnd; =20 @@ -200,9 +192,7 @@ ScanForRootBridges ( ZeroMem (&Io, sizeof (Io)); ZeroMem (&Mem, sizeof (Mem)); ZeroMem (&MemAbove4G, sizeof (MemAbove4G)); - ZeroMem (&PMem, sizeof (PMem)); - ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G)); - Io.Base =3D Mem.Base =3D MemAbove4G.Base =3D PMem.Base =3D PMemAbove4G= .Base =3D MAX_UINT64; + Io.Base =3D Mem.Base =3D MemAbove4G.Base =3D MAX_UINT64; // // Scan all the PCI devices on the primary bus of the PCI root bridge // @@ -307,16 +297,17 @@ ScanForRootBridges ( =20 // // Get the Prefetchable Memory range that the PPB is decoding + // and merge it into Memory range // Value =3D Pci.Bridge.PrefetchableMemoryBase & 0x0f; Base =3D ((UINT32) Pci.Bridge.PrefetchableMemoryBase & 0xfff0) <= < 16; Limit =3D (((UINT32) Pci.Bridge.PrefetchableMemoryLimit & 0xfff0) << 16) | 0xfffff; - MemAperture =3D &PMem; + MemAperture =3D &Mem; if (Value =3D=3D BIT0) { Base |=3D LShiftU64 (Pci.Bridge.PrefetchableBaseUpper32, 32); Limit |=3D LShiftU64 (Pci.Bridge.PrefetchableLimitUpper32, 32); - MemAperture =3D &PMemAbove4G; + MemAperture =3D &MemAbove4G; } if (Base < Limit) { if (MemAperture->Base > Base) { @@ -367,8 +358,7 @@ ScanForRootBridges ( OFFSET_OF (PCI_TYPE00, Device.Bar), BarOffsetEnd, &Io, - &Mem, &MemAbove4G, - &PMem, &PMemAbove4G + &Mem, &MemAbove4G ); =20 // @@ -440,7 +430,7 @@ ScanForRootBridges ( InitRootBridge ( Attributes, Attributes, 0, (UINT8) PrimaryBus, (UINT8) SubBus, - &Io, &Mem, &MemAbove4G, &PMem, &PMemAbove4G, + &Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture, &RootBridges[*NumberOfRootBridges] ); RootBridges[*NumberOfRootBridges].ResourceAssigned =3D TRUE; --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue May 7 11:18:48 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1556223956; cv=none; d=zoho.com; s=zohoarc; b=CJOCphZnALEw3PfXqkwOF0C3rjOHy4tGD+yOWP4ZI9wYRWXfWPbG25nVuET+5MlOJgLGVrjhzEfTlZaQzGXeIdOC4awU+fyqvqHCyENTqlxmW70ux1aDOnsy4bGD+SSpdKG8KG1Zeb8gpYUavjEnn1WSoKrfpwzb1tT5vlDrjiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556223956; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4ja33xo8ERRD4xrL/h/xZ6TXg1vInnS654dFw3Foq68=; b=KgsvvodExFsS9xCfnDbuaqfB2gOXsoTXGHh+Pl1/PgfphoLiKDtr1faTVDx9poB/ORNoG1owwQJqXohaVfEdIk551Lt+tmW+dXKc/fd8Zxab+jbkzKM0kEnLTQNPAlqB0M+mNjGLJbjpGTDdyWKUJ3j6ZqhNsfjEVeMFcuUmOX4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1556223955404404.95055019414224; Thu, 25 Apr 2019 13:25:55 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkuz-0001J5-IW; Thu, 25 Apr 2019 20:24:29 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkuy-0001Im-Ta for xen-devel@lists.xenproject.org; Thu, 25 Apr 2019 20:24:28 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1f8cc5d2-6798-11e9-843c-bc764e045a96; Thu, 25 Apr 2019 20:24:27 +0000 (UTC) X-Inumbo-ID: 1f8cc5d2-6798-11e9-843c-bc764e045a96 X-IronPort-AV: E=Sophos;i="5.60,394,1549929600"; d="scan'208";a="84450975" From: Igor Druzhinin To: Date: Thu, 25 Apr 2019 21:23:57 +0100 Message-ID: <1556223838-5176-3-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556223838-5176-1-git-send-email-igor.druzhinin@citrix.com> References: <1556223838-5176-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 2/3] OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , ard.biesheuvel@linaro.org, jordan.l.justen@intel.com, julien.grall@arm.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org, lersek@redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In case BAR64 is placed below 4G choose the correct aperture. This fixes a failed assertion down the code path. Acked-by: Anthony PERARD Signed-off-by: Igor Druzhinin --- OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Librar= y/PciHostBridgeLib/XenSupport.c index 354b0a5..76fca53 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c @@ -137,7 +137,11 @@ PcatPciRootBridgeParseBars ( Length =3D Length | LShiftU64 ((UINT64) UpperValue, 32); Length =3D (~Length) + 1; =20 - MemAperture =3D MemAbove4G; + if (Base < BASE_4GB) { + MemAperture =3D Mem; + } else { + MemAperture =3D MemAbove4G; + } } =20 Limit =3D Base + Length - 1; --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue May 7 11:18:48 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1556223956; cv=none; d=zoho.com; s=zohoarc; b=hShicJAYL52lBIwJWhGq9zOuev7vGXwtTQMN6/uOjdquHs6HqpB3uYOtQX7vNxNOs/5L3phI1sgr16TuKhXuyzw71QkAcVAiF0l4HxO25lW3xGmmSRLBQuyCcXgTeB2eHQjPWqzN+sH4JLN5hLPNUTEPtAr2rZ5MpLKY/ROw8rM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556223956; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+hceu8cWhaKL4naBjcow5EPhHD66YAntc1yR72uVAlQ=; b=W/o+N+FCcrTIWuULD6VyW8lTzf/Tgd6eSKg0dIe9CqgHovH6UtIUY+9OXGlax6XAcd7c2LNpjR8h3td+nX6cdN1T6dgxsac8aDF511eqR2fN9AXzFLtRFldQdybRq1M1Oesg14MpU3CF9LTwsaMrcW7ELIt614eYy2afNr2stZM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1556223955291596.8956300504243; Thu, 25 Apr 2019 13:25:55 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkuz-0001Iq-0X; Thu, 25 Apr 2019 20:24:29 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkux-0001IV-LS for xen-devel@lists.xenproject.org; Thu, 25 Apr 2019 20:24:27 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1f20c595-6798-11e9-843c-bc764e045a96; Thu, 25 Apr 2019 20:24:26 +0000 (UTC) X-Inumbo-ID: 1f20c595-6798-11e9-843c-bc764e045a96 X-IronPort-AV: E=Sophos;i="5.60,394,1549929600"; d="scan'208";a="84450969" From: Igor Druzhinin To: Date: Thu, 25 Apr 2019 21:23:58 +0100 Message-ID: <1556223838-5176-4-git-send-email-igor.druzhinin@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556223838-5176-1-git-send-email-igor.druzhinin@citrix.com> References: <1556223838-5176-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 3/3] OvmfPkg/XenSupport: turn off address decoding before BAR sizing X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , ard.biesheuvel@linaro.org, jordan.l.justen@intel.com, julien.grall@arm.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org, lersek@redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Xen, hvmloader firmware leaves address decoding enabled for enumerated PCI device before jumping into OVMF. OVMF seems to expect it to be disabled and tries to size PCI BARs in several places without disabling it which causes BAR64, for example, being incorrectly placed by QEMU. Fix it by disabling PCI address decoding explicitly before the first attempt to size BARs on Xen. Signed-off-by: Igor Druzhinin Acked-by: Anthony PERARD Acked-by: Laszlo Ersek --- Changes in v3: - dropped unused arguments and rename PcatPciRootBridgeDecoding function - make mask application more clear as suggested --- OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Librar= y/PciHostBridgeLib/XenSupport.c index 76fca53..b41bd6b 100644 --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c @@ -49,6 +49,22 @@ PcatPciRootBridgeBarExisted ( EnableInterrupts (); } =20 +#define PCI_COMMAND_DECODE ((UINT16)(EFI_PCI_COMMAND_IO_SPACE | \ + EFI_PCI_COMMAND_MEMORY_SPACE)) +STATIC +VOID +PcatPciRootBridgeDecodingDisable ( + IN UINTN Address + ) +{ + UINT16 Value; + + Value =3D PciRead16 (Address); + if (Value & PCI_COMMAND_DECODE) { + PciWrite16 (Address, Value & ~(UINT32)PCI_COMMAND_DECODE); + } +} + STATIC VOID PcatPciRootBridgeParseBars ( @@ -75,6 +91,11 @@ PcatPciRootBridgeParseBars ( UINT64 Limit; PCI_ROOT_BRIDGE_APERTURE *MemAperture; =20 + // Disable address decoding for every device before OVMF starts sizing it + PcatPciRootBridgeDecodingDisable ( + PCI_LIB_ADDRESS (Bus, Device, Function, PCI_COMMAND_OFFSET) + ); + for (Offset =3D BarOffsetBase; Offset < BarOffsetEnd; Offset +=3D sizeof= (UINT32)) { PcatPciRootBridgeBarExisted ( PCI_LIB_ADDRESS (Bus, Device, Function, Offset), --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel