From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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 5AE1321A09130 for ; Wed, 6 Mar 2019 05:22:54 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AB2930B9302; Wed, 6 Mar 2019 13:22:54 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-158.rdu2.redhat.com [10.10.120.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A68D6090C; Wed, 6 Mar 2019 13:22:50 +0000 (UTC) To: Igor Druzhinin , edk2-devel@lists.01.org Cc: jordan.l.justen@intel.com, ard.biesheuvel@linaro.org, anthony.perard@citrix.com, julien.grall@arm.com, xen-devel@lists.xenproject.org References: <1551876056-28223-1-git-send-email-igor.druzhinin@citrix.com> <1551876056-28223-4-git-send-email-igor.druzhinin@citrix.com> From: Laszlo Ersek Message-ID: Date: Wed, 6 Mar 2019 14:22:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1551876056-28223-4-git-send-email-igor.druzhinin@citrix.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 06 Mar 2019 13:22:54 +0000 (UTC) Subject: Re: [PATCH RESEND 3/3] OvmfPkg/XenSupport: turn off address decoding before BAR sizing X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Mar 2019 13:22:55 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 03/06/19 13:40, Igor Druzhinin wrote: > 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. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Igor Druzhinin > --- > OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 34 +++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c > index 408fb24..9940335 100644 > --- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c > +++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c > @@ -55,6 +55,33 @@ PcatPciRootBridgeBarExisted ( > EnableInterrupts (); > } > > +#define EFI_PCI_COMMAND_DECODE ((UINT16)(EFI_PCI_COMMAND_IO_SPACE | \ > + EFI_PCI_COMMAND_MEMORY_SPACE)) I thought I asked you not to define a macro here that started with the "EFI_" prefix :/ http://mid.mail-archive.com/dd8e3c9e-cb76-d3fe-6a10-c0a41c714b56@redhat.com Laszlo > +STATIC > +VOID > +PcatPciRootBridgeDecoding ( > + IN UINTN Address, > + IN BOOLEAN Enabled, > + OUT UINT16 *OriginalValue > + ) > +{ > + UINT16 Value; > + > + // > + // Preserve the original value > + // > + Value = *OriginalValue; > + *OriginalValue = PciRead16 (Address); > + > + if (!Enabled) { > + if (*OriginalValue & EFI_PCI_COMMAND_DECODE) > + PciWrite16 (Address, *OriginalValue & ~EFI_PCI_COMMAND_DECODE); > + } else { > + if (Value & EFI_PCI_COMMAND_DECODE) > + PciWrite16 (Address, Value); > + } > +} > + > STATIC > VOID > PcatPciRootBridgeParseBars ( > @@ -76,6 +103,7 @@ PcatPciRootBridgeParseBars ( > UINT32 Value; > UINT32 OriginalUpperValue; > UINT32 UpperValue; > + UINT16 OriginalCommand; > UINT64 Mask; > UINTN Offset; > UINT64 Base; > @@ -83,6 +111,12 @@ PcatPciRootBridgeParseBars ( > UINT64 Limit; > PCI_ROOT_BRIDGE_APERTURE *MemAperture; > > + // Disable address decoding for every device before OVMF starts sizing it > + PcatPciRootBridgeDecoding ( > + PCI_LIB_ADDRESS (Bus, Device, Function, PCI_COMMAND_OFFSET), > + FALSE, &OriginalCommand > + ); > + > for (Offset = BarOffsetBase; Offset < BarOffsetEnd; Offset += sizeof (UINT32)) { > PcatPciRootBridgeBarExisted ( > PCI_LIB_ADDRESS (Bus, Device, Function, Offset), >