public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/3] Xen PCI passthrough fixes
@ 2019-03-04 15:04 Igor Druzhinin
  2019-03-04 15:04 ` [PATCH 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture Igor Druzhinin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Igor Druzhinin @ 2019-03-04 15:04 UTC (permalink / raw)
  To: edk2-devel
  Cc: jordan.l.justen, lersek, ard.biesheuvel, anthony.perard,
	julien.grall, Igor Druzhinin

Igor Druzhinin (3):
  OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge
    aperture
  OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64
  OvmfPkg/XenSupport: turn off address decoding before BAR sizing

 OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 44 ++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 7 deletions(-)

-- 
2.7.4



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture
  2019-03-04 15:04 [PATCH 0/3] Xen PCI passthrough fixes Igor Druzhinin
@ 2019-03-04 15:04 ` Igor Druzhinin
  2019-03-04 15:04 ` [PATCH 2/3] OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64 Igor Druzhinin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Igor Druzhinin @ 2019-03-04 15:04 UTC (permalink / raw)
  To: edk2-devel
  Cc: jordan.l.justen, lersek, ard.biesheuvel, anthony.perard,
	julien.grall, Igor Druzhinin

This aperture doesn't exist in OVMF and trying to use it causes
failing assertions later in cases there are prefetchable and
non-prefetchable BARs following each other. This configuration is
quite likely with some PCI passthrough devices.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
---
 OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index 9204179..c23c46d 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -129,11 +129,7 @@ PcatPciRootBridgeParseBars (
           //
           Length = ((~Length) + 1) & 0xffffffff;
 
-          if ((Value & BIT3) == BIT3) {
-            MemAperture = PMem;
-          } else {
-            MemAperture = Mem;
-          }
+          MemAperture = Mem;
         } else {
           //
           // 64bit
@@ -149,11 +145,7 @@ PcatPciRootBridgeParseBars (
           Length = Length | LShiftU64 ((UINT64) UpperValue, 32);
           Length = (~Length) + 1;
 
-          if ((Value & BIT3) == BIT3) {
-            MemAperture = PMemAbove4G;
-          } else {
-            MemAperture = MemAbove4G;
-          }
+          MemAperture = MemAbove4G;
         }
 
         Limit = Base + Length - 1;
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64
  2019-03-04 15:04 [PATCH 0/3] Xen PCI passthrough fixes Igor Druzhinin
  2019-03-04 15:04 ` [PATCH 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture Igor Druzhinin
@ 2019-03-04 15:04 ` Igor Druzhinin
  2019-03-04 15:04 ` [PATCH 3/3] OvmfPkg/XenSupport: turn off address decoding before BAR sizing Igor Druzhinin
  2019-03-06  2:30 ` [PATCH 0/3] Xen PCI passthrough fixes Konrad Rzeszutek Wilk
  3 siblings, 0 replies; 5+ messages in thread
From: Igor Druzhinin @ 2019-03-04 15:04 UTC (permalink / raw)
  To: edk2-devel
  Cc: jordan.l.justen, lersek, ard.biesheuvel, anthony.perard,
	julien.grall, Igor Druzhinin

In case BAR64 is placed below 4G choose the correct aperture.
This fixes a failed assertion down the code path.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
---
 OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index c23c46d..408fb24 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -145,7 +145,11 @@ PcatPciRootBridgeParseBars (
           Length = Length | LShiftU64 ((UINT64) UpperValue, 32);
           Length = (~Length) + 1;
 
-          MemAperture = MemAbove4G;
+          if (Base < 0x100000000) {
+            MemAperture = Mem;
+          } else {
+            MemAperture = MemAbove4G;
+          }
         }
 
         Limit = Base + Length - 1;
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] OvmfPkg/XenSupport: turn off address decoding before BAR sizing
  2019-03-04 15:04 [PATCH 0/3] Xen PCI passthrough fixes Igor Druzhinin
  2019-03-04 15:04 ` [PATCH 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture Igor Druzhinin
  2019-03-04 15:04 ` [PATCH 2/3] OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64 Igor Druzhinin
@ 2019-03-04 15:04 ` Igor Druzhinin
  2019-03-06  2:30 ` [PATCH 0/3] Xen PCI passthrough fixes Konrad Rzeszutek Wilk
  3 siblings, 0 replies; 5+ messages in thread
From: Igor Druzhinin @ 2019-03-04 15:04 UTC (permalink / raw)
  To: edk2-devel
  Cc: jordan.l.justen, lersek, ard.biesheuvel, anthony.perard,
	julien.grall, Igor Druzhinin

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 <igor.druzhinin@citrix.com>
---
 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))
+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),
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] Xen PCI passthrough fixes
  2019-03-04 15:04 [PATCH 0/3] Xen PCI passthrough fixes Igor Druzhinin
                   ` (2 preceding siblings ...)
  2019-03-04 15:04 ` [PATCH 3/3] OvmfPkg/XenSupport: turn off address decoding before BAR sizing Igor Druzhinin
@ 2019-03-06  2:30 ` Konrad Rzeszutek Wilk
  3 siblings, 0 replies; 5+ messages in thread
From: Konrad Rzeszutek Wilk @ 2019-03-06  2:30 UTC (permalink / raw)
  To: Igor Druzhinin
  Cc: edk2-devel, jordan.l.justen, julien.grall, anthony.perard, lersek

On Mon, Mar 04, 2019 at 03:04:05PM +0000, Igor Druzhinin wrote:
> Igor Druzhinin (3):

Could you also CC xen-devel please?
>   OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge
>     aperture
>   OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64
>   OvmfPkg/XenSupport: turn off address decoding before BAR sizing
> 
>  OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 44 ++++++++++++++++++++++-----
>  1 file changed, 37 insertions(+), 7 deletions(-)
> 
> -- 
> 2.7.4
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-06  2:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-04 15:04 [PATCH 0/3] Xen PCI passthrough fixes Igor Druzhinin
2019-03-04 15:04 ` [PATCH 1/3] OvmfPkg/XenSupport: remove usage of prefetchable PCI host bridge aperture Igor Druzhinin
2019-03-04 15:04 ` [PATCH 2/3] OvmfPkg/XenSupport: use a correct PCI host bridge aperture for BAR64 Igor Druzhinin
2019-03-04 15:04 ` [PATCH 3/3] OvmfPkg/XenSupport: turn off address decoding before BAR sizing Igor Druzhinin
2019-03-06  2:30 ` [PATCH 0/3] Xen PCI passthrough fixes Konrad Rzeszutek Wilk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox