All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-12  5:08 Daniel Axtens
  2017-07-12 20:04   ` Bjorn Helgaas
  0 siblings, 1 reply; 27+ messages in thread
From: Daniel Axtens @ 2017-07-12  5:08 UTC (permalink / raw)
  To: linux-pci; +Cc: Daniel Axtens, Xinliang Liu, Rongrong Zou

The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610) that
are not spec-compliant: the VGA Enable bit is hardwired to 0 and
writes do not change it.

The HiSilicon engineers report that the bridge does not forward the
0xa0000-0xbffff mem range and the 0x3b0-0x3bb and 0x3c0-0x3df I/O
ranges.

Because the VGA Enable bit is hardwired to 0, the VGA arbiter refuses
to mark any card behind it as the boot device. This breaks Xorg
auto-detection.

However, the hibmc VGA card (PCI ID 19e5:1711) has been tested and is
known to work when behind these bridges. (It does not require the
legacy resources to operate.)

Provide a quirk so that this combination of bridge and card is eligible
to be the default VGA card. This fixes Xorg auto-detection on the D05.

Cc: Xinliang Liu <z.liuxinliang@hisilicon.com>
Cc: Rongrong Zou <zourongrong@gmail.com>
Signed-off-by: Daniel Axtens <dja@axtens.net>
---

v3: fix commit message
v4: fix comment (forgot to git add/git commit, sorry for the noise)

---
 drivers/pci/quirks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 16e6cd86ad71..b42324cba29e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -25,6 +25,7 @@
 #include <linux/sched.h>
 #include <linux/ktime.h>
 #include <linux/mm.h>
+#include <linux/vgaarb.h>
 #include <asm/dma.h>	/* isa_dma_bridge_buggy */
 #include "pci.h"
 
@@ -4664,3 +4665,52 @@ static void quirk_intel_no_flr(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1502, quirk_intel_no_flr);
 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1503, quirk_intel_no_flr);
+
+/*
+ * The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610)
+ * that are not spec-compliant: the VGA Enable bit is hardwired to 0
+ * and writes do not change it. The bridge does not forward legacy
+ * memory or I/O resources.
+ *
+ * Because the VGA Enable bit is hardwired to 0, the VGA arbiter
+ * refuses to mark any card behind it as the boot device. However, the
+ * hibmc VGA card (PCI ID 19e5:1711) has been tested and is known to
+ * work when behind these bridges.
+ *
+ * If we have this bridge, this card, and no default card already,
+ * mark the card as default.
+ */
+static void hibmc_fixup_vgaarb(struct pci_dev *pdev)
+{
+	struct pci_dev *bridge;
+	struct pci_bus *bus;
+	u16 config;
+
+	bus = pdev->bus;
+	bridge = bus->self;
+	if (!bridge)
+		return;
+
+	if (!pci_is_bridge(bridge))
+		return;
+
+	if (bridge->vendor != PCI_VENDOR_ID_HUAWEI ||
+	    bridge->device != 0x1610)
+		return;
+
+	pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
+			     &config);
+	if (config & PCI_BRIDGE_CTL_VGA) {
+		/*
+		 * Weirdly, this bridge *is* spec compliant, so bail
+		 * and let vgaarb do its job
+		 */
+		return;
+	}
+
+	if (vga_default_device())
+		return;
+
+	vga_set_default_device(pdev);
+}
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0x1711, hibmc_fixup_vgaarb);
-- 
2.11.0

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-12  5:08 [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge Daniel Axtens
@ 2017-07-12 20:04   ` Bjorn Helgaas
  0 siblings, 0 replies; 27+ messages in thread
From: Bjorn Helgaas @ 2017-07-12 20:04 UTC (permalink / raw)
  To: Daniel Axtens
  Cc: linux-pci, Will Deacon, Xinliang Liu, Catalin Marinas,
	Rongrong Zou, linux-arm-kernel

[+cc Catalin, Will, linux-arm-kernel]

On Wed, Jul 12, 2017 at 03:08:11PM +1000, Daniel Axtens wrote:
> The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610) that
> are not spec-compliant: the VGA Enable bit is hardwired to 0 and
> writes do not change it.
> 
> The HiSilicon engineers report that the bridge does not forward the
> 0xa0000-0xbffff mem range and the 0x3b0-0x3bb and 0x3c0-0x3df I/O
> ranges.
> 
> Because the VGA Enable bit is hardwired to 0, the VGA arbiter refuses
> to mark any card behind it as the boot device. This breaks Xorg
> auto-detection.
> 
> However, the hibmc VGA card (PCI ID 19e5:1711) has been tested and is
> known to work when behind these bridges. (It does not require the
> legacy resources to operate.)
> 
> Provide a quirk so that this combination of bridge and card is eligible
> to be the default VGA card. This fixes Xorg auto-detection on the D05.
> 
> Cc: Xinliang Liu <z.liuxinliang@hisilicon.com>
> Cc: Rongrong Zou <zourongrong@gmail.com>
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
> 
> v3: fix commit message
> v4: fix comment (forgot to git add/git commit, sorry for the noise)
> 
> ---
>  drivers/pci/quirks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index 16e6cd86ad71..b42324cba29e 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -25,6 +25,7 @@
>  #include <linux/sched.h>
>  #include <linux/ktime.h>
>  #include <linux/mm.h>
> +#include <linux/vgaarb.h>
>  #include <asm/dma.h>	/* isa_dma_bridge_buggy */
>  #include "pci.h"
>  
> @@ -4664,3 +4665,52 @@ static void quirk_intel_no_flr(struct pci_dev *dev)
>  }
>  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1502, quirk_intel_no_flr);
>  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1503, quirk_intel_no_flr);
> +
> +/*
> + * The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610)
> + * that are not spec-compliant: the VGA Enable bit is hardwired to 0
> + * and writes do not change it. The bridge does not forward legacy
> + * memory or I/O resources.
> + *
> + * Because the VGA Enable bit is hardwired to 0, the VGA arbiter
> + * refuses to mark any card behind it as the boot device. However, the
> + * hibmc VGA card (PCI ID 19e5:1711) has been tested and is known to
> + * work when behind these bridges.
> + *
> + * If we have this bridge, this card, and no default card already,
> + * mark the card as default.
> + */
> +static void hibmc_fixup_vgaarb(struct pci_dev *pdev)
> +{
> +	struct pci_dev *bridge;
> +	struct pci_bus *bus;
> +	u16 config;
> +
> +	bus = pdev->bus;
> +	bridge = bus->self;
> +	if (!bridge)
> +		return;
> +
> +	if (!pci_is_bridge(bridge))
> +		return;
> +
> +	if (bridge->vendor != PCI_VENDOR_ID_HUAWEI ||
> +	    bridge->device != 0x1610)
> +		return;
> +
> +	pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
> +			     &config);
> +	if (config & PCI_BRIDGE_CTL_VGA) {
> +		/*
> +		 * Weirdly, this bridge *is* spec compliant, so bail
> +		 * and let vgaarb do its job
> +		 */
> +		return;
> +	}
> +
> +	if (vga_default_device())
> +		return;
> +
> +	vga_set_default_device(pdev);
> +}
> +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0x1711, hibmc_fixup_vgaarb);

Is this quirk useful on any arch other than arm64?  Per
drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.

Would it make sense to put this quirk in arch/arm64/kernel/pci.c?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-12 20:04   ` Bjorn Helgaas
  0 siblings, 0 replies; 27+ messages in thread
From: Bjorn Helgaas @ 2017-07-12 20:04 UTC (permalink / raw)
  To: linux-arm-kernel

[+cc Catalin, Will, linux-arm-kernel]

On Wed, Jul 12, 2017 at 03:08:11PM +1000, Daniel Axtens wrote:
> The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610) that
> are not spec-compliant: the VGA Enable bit is hardwired to 0 and
> writes do not change it.
> 
> The HiSilicon engineers report that the bridge does not forward the
> 0xa0000-0xbffff mem range and the 0x3b0-0x3bb and 0x3c0-0x3df I/O
> ranges.
> 
> Because the VGA Enable bit is hardwired to 0, the VGA arbiter refuses
> to mark any card behind it as the boot device. This breaks Xorg
> auto-detection.
> 
> However, the hibmc VGA card (PCI ID 19e5:1711) has been tested and is
> known to work when behind these bridges. (It does not require the
> legacy resources to operate.)
> 
> Provide a quirk so that this combination of bridge and card is eligible
> to be the default VGA card. This fixes Xorg auto-detection on the D05.
> 
> Cc: Xinliang Liu <z.liuxinliang@hisilicon.com>
> Cc: Rongrong Zou <zourongrong@gmail.com>
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
> 
> v3: fix commit message
> v4: fix comment (forgot to git add/git commit, sorry for the noise)
> 
> ---
>  drivers/pci/quirks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> index 16e6cd86ad71..b42324cba29e 100644
> --- a/drivers/pci/quirks.c
> +++ b/drivers/pci/quirks.c
> @@ -25,6 +25,7 @@
>  #include <linux/sched.h>
>  #include <linux/ktime.h>
>  #include <linux/mm.h>
> +#include <linux/vgaarb.h>
>  #include <asm/dma.h>	/* isa_dma_bridge_buggy */
>  #include "pci.h"
>  
> @@ -4664,3 +4665,52 @@ static void quirk_intel_no_flr(struct pci_dev *dev)
>  }
>  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1502, quirk_intel_no_flr);
>  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1503, quirk_intel_no_flr);
> +
> +/*
> + * The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610)
> + * that are not spec-compliant: the VGA Enable bit is hardwired to 0
> + * and writes do not change it. The bridge does not forward legacy
> + * memory or I/O resources.
> + *
> + * Because the VGA Enable bit is hardwired to 0, the VGA arbiter
> + * refuses to mark any card behind it as the boot device. However, the
> + * hibmc VGA card (PCI ID 19e5:1711) has been tested and is known to
> + * work when behind these bridges.
> + *
> + * If we have this bridge, this card, and no default card already,
> + * mark the card as default.
> + */
> +static void hibmc_fixup_vgaarb(struct pci_dev *pdev)
> +{
> +	struct pci_dev *bridge;
> +	struct pci_bus *bus;
> +	u16 config;
> +
> +	bus = pdev->bus;
> +	bridge = bus->self;
> +	if (!bridge)
> +		return;
> +
> +	if (!pci_is_bridge(bridge))
> +		return;
> +
> +	if (bridge->vendor != PCI_VENDOR_ID_HUAWEI ||
> +	    bridge->device != 0x1610)
> +		return;
> +
> +	pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
> +			     &config);
> +	if (config & PCI_BRIDGE_CTL_VGA) {
> +		/*
> +		 * Weirdly, this bridge *is* spec compliant, so bail
> +		 * and let vgaarb do its job
> +		 */
> +		return;
> +	}
> +
> +	if (vga_default_device())
> +		return;
> +
> +	vga_set_default_device(pdev);
> +}
> +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0x1711, hibmc_fixup_vgaarb);

Is this quirk useful on any arch other than arm64?  Per
drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.

Would it make sense to put this quirk in arch/arm64/kernel/pci.c?

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

* RE: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-12 20:04   ` Bjorn Helgaas
@ 2017-07-13 10:29     ` Gabriele Paoloni
  -1 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-13 10:29 UTC (permalink / raw)
  To: Bjorn Helgaas, Daniel Axtens
  Cc: linux-pci, Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel

Hi Bjorn, Daniel

[...]

>=20
> Is this quirk useful on any arch other than arm64?  Per
> drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
>=20
> Would it make sense to put this quirk in arch/arm64/kernel/pci.c?

Indeed our host controller depends on ARM64 so maybe it would make
sense to move the quirk arch/arm64/kernel/pci.c; however regardless
why is it strictly required for a VGA device to be legacy one in order
to make it the default boot device?
i.e. couldn't we have:

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 0f5b2dd..a6b606c 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *=
pdev)
 	/* Deal with VGA default device. Use first enabled one
 	 * by default if arch doesn't have it's own hook
 	 */
-	if (vga_default =3D=3D NULL &&
-	    ((vgadev->owns & VGA_RSRC_LEGACY_MASK) =3D=3D VGA_RSRC_LEGACY_MASK)) =
{
+	if (vga_default =3D=3D NULL) {
 		vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
 		vga_set_default_device(pdev);
 	}

?
Thanks
Gab

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-13 10:29     ` Gabriele Paoloni
  0 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-13 10:29 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Bjorn, Daniel

[...]

> 
> Is this quirk useful on any arch other than arm64?  Per
> drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> 
> Would it make sense to put this quirk in arch/arm64/kernel/pci.c?

Indeed our host controller depends on ARM64 so maybe it would make
sense to move the quirk arch/arm64/kernel/pci.c; however regardless
why is it strictly required for a VGA device to be legacy one in order
to make it the default boot device?
i.e. couldn't we have:

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 0f5b2dd..a6b606c 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
 	/* Deal with VGA default device. Use first enabled one
 	 * by default if arch doesn't have it's own hook
 	 */
-	if (vga_default == NULL &&
-	    ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
+	if (vga_default == NULL) {
 		vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
 		vga_set_default_device(pdev);
 	}

?
Thanks
Gab

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-13 10:29     ` Gabriele Paoloni
@ 2017-07-13 11:29       ` Bjorn Helgaas
  -1 siblings, 0 replies; 27+ messages in thread
From: Bjorn Helgaas @ 2017-07-13 11:29 UTC (permalink / raw)
  To: Gabriele Paoloni
  Cc: Benjamin Herrenschmidt, David Airlie, linux-pci, Will Deacon,
	Liuxinliang (Matthew Liu),
	Alex Williamson, Catalin Marinas, Rongrong Zou, Daniel Vetter,
	linux-arm-kernel, Daniel Axtens

[+cc Ben, David, Daniel, Alex]

On Thu, Jul 13, 2017 at 10:29:25AM +0000, Gabriele Paoloni wrote:
> Hi Bjorn, Daniel
> 
> [...]
> 
> > 
> > Is this quirk useful on any arch other than arm64?  Per
> > drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> > 
> > Would it make sense to put this quirk in arch/arm64/kernel/pci.c?
> 
> Indeed our host controller depends on ARM64 so maybe it would make
> sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> why is it strictly required for a VGA device to be legacy one in order
> to make it the default boot device?
> i.e. couldn't we have:
> 
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 0f5b2dd..a6b606c 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
>  	/* Deal with VGA default device. Use first enabled one
>  	 * by default if arch doesn't have it's own hook
>  	 */
> -	if (vga_default == NULL &&
> -	    ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> +	if (vga_default == NULL) {
>  		vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
>  		vga_set_default_device(pdev);
>  	}

I don't know enough about the VGA arbiter to answer this.  This test was
part of the initial implementation: deb2d2ecd43d ("PCI/GPU: implement VGA
arbitration on Linux") by Ben.

Bjorn

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-13 11:29       ` Bjorn Helgaas
  0 siblings, 0 replies; 27+ messages in thread
From: Bjorn Helgaas @ 2017-07-13 11:29 UTC (permalink / raw)
  To: linux-arm-kernel

[+cc Ben, David, Daniel, Alex]

On Thu, Jul 13, 2017 at 10:29:25AM +0000, Gabriele Paoloni wrote:
> Hi Bjorn, Daniel
> 
> [...]
> 
> > 
> > Is this quirk useful on any arch other than arm64?  Per
> > drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> > 
> > Would it make sense to put this quirk in arch/arm64/kernel/pci.c?
> 
> Indeed our host controller depends on ARM64 so maybe it would make
> sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> why is it strictly required for a VGA device to be legacy one in order
> to make it the default boot device?
> i.e. couldn't we have:
> 
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 0f5b2dd..a6b606c 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
>  	/* Deal with VGA default device. Use first enabled one
>  	 * by default if arch doesn't have it's own hook
>  	 */
> -	if (vga_default == NULL &&
> -	    ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> +	if (vga_default == NULL) {
>  		vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
>  		vga_set_default_device(pdev);
>  	}

I don't know enough about the VGA arbiter to answer this.  This test was
part of the initial implementation: deb2d2ecd43d ("PCI/GPU: implement VGA
arbitration on Linux") by Ben.

Bjorn

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-13 11:29       ` Bjorn Helgaas
@ 2017-07-13 20:45         ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-13 20:45 UTC (permalink / raw)
  To: Bjorn Helgaas, Gabriele Paoloni
  Cc: Daniel Axtens, linux-pci, Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel,
	David Airlie, Daniel Vetter, Alex Williamson

On Thu, 2017-07-13 at 06:29 -0500, Bjorn Helgaas wrote:
> > Indeed our host controller depends on ARM64 so maybe it would make
> > sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> > why is it strictly required for a VGA device to be legacy one in order
> > to make it the default boot device?
> > i.e. couldn't we have:
> > 
> > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> > index 0f5b2dd..a6b606c 100644
> > --- a/drivers/gpu/vga/vgaarb.c
> > +++ b/drivers/gpu/vga/vgaarb.c
> > @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
> >        /* Deal with VGA default device. Use first enabled one
> >         * by default if arch doesn't have it's own hook
> >         */
> > -     if (vga_default == NULL &&
> > -         ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> > +     if (vga_default == NULL) {
> >                vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
> >                vga_set_default_device(pdev);
> >        }
> 
> I don't know enough about the VGA arbiter to answer this.  This test was
> part of the initial implementation: deb2d2ecd43d ("PCI/GPU: implement VGA
> arbitration on Linux") by Ben.

The above simply uses the first device that has memory and IO enabled
as the default device (you don't need to have a default device).

This is essentially picking up whatever device had been initialized
by the BIOS/firmware as default. This is needed for example on x86
where the BIOS tends to only initialize one device. 

I'm not sure what problem you are trying to solve here ?

Cheers,
Ben.

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-13 20:45         ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-13 20:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 2017-07-13 at 06:29 -0500, Bjorn Helgaas wrote:
> > Indeed our host controller depends on ARM64 so maybe it would make
> > sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> > why is it strictly required for a VGA device to be legacy one in order
> > to make it the default boot device?
> > i.e. couldn't we have:
> > 
> > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> > index 0f5b2dd..a6b606c 100644
> > --- a/drivers/gpu/vga/vgaarb.c
> > +++ b/drivers/gpu/vga/vgaarb.c
> > @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
> > ???????/* Deal with VGA default device. Use first enabled one
> > ??????? * by default if arch doesn't have it's own hook
> > ??????? */
> > -?????if (vga_default == NULL &&
> > -???????? ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> > +?????if (vga_default == NULL) {
> > ???????????????vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
> > ???????????????vga_set_default_device(pdev);
> > ???????}
> 
> I don't know enough about the VGA arbiter to answer this.? This test was
> part of the initial implementation: deb2d2ecd43d ("PCI/GPU: implement VGA
> arbitration on Linux") by Ben.

The above simply uses the first device that has memory and IO enabled
as the default device (you don't need to have a default device).

This is essentially picking up whatever device had been initialized
by the BIOS/firmware as default. This is needed for example on x86
where the BIOS tends to only initialize one device. 

I'm not sure what problem you are trying to solve here ?

Cheers,
Ben.

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-13 11:29       ` Bjorn Helgaas
@ 2017-07-13 21:11         ` Alex Williamson
  -1 siblings, 0 replies; 27+ messages in thread
From: Alex Williamson @ 2017-07-13 21:11 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Gabriele Paoloni, Daniel Axtens, linux-pci,
	Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel,
	Benjamin Herrenschmidt, David Airlie, Daniel Vetter

On Thu, 13 Jul 2017 06:29:38 -0500
Bjorn Helgaas <helgaas@kernel.org> wrote:

> [+cc Ben, David, Daniel, Alex]
> 
> On Thu, Jul 13, 2017 at 10:29:25AM +0000, Gabriele Paoloni wrote:
> > Hi Bjorn, Daniel
> > 
> > [...]
> >   
> > > 
> > > Is this quirk useful on any arch other than arm64?  Per
> > > drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> > > 
> > > Would it make sense to put this quirk in arch/arm64/kernel/pci.c?  
> > 
> > Indeed our host controller depends on ARM64 so maybe it would make
> > sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> > why is it strictly required for a VGA device to be legacy one in order
> > to make it the default boot device?
> > i.e. couldn't we have:
> > 
> > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> > index 0f5b2dd..a6b606c 100644
> > --- a/drivers/gpu/vga/vgaarb.c
> > +++ b/drivers/gpu/vga/vgaarb.c
> > @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
> >  	/* Deal with VGA default device. Use first enabled one
> >  	 * by default if arch doesn't have it's own hook
> >  	 */
> > -	if (vga_default == NULL &&
> > -	    ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> > +	if (vga_default == NULL) {
> >  		vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
> >  		vga_set_default_device(pdev);
> >  	}  


"Legacy" is the breadcrumb we use to try to pick the same device for
default VGA as the system firmware used as the boot VGA.  There can be
multiple VGA devices in the system, the change above would simply make
the first discovered device be the default VGA.  That would break many,
many systems.  If legacy VGA ranges mean nothing on ARM64, then follow
the powerpc lead and make an arch quirk that simply selects the first
enabled VGA device as the default.  VGA routing is part of the PCI spec
though, so the default of selecting the device with routing enabled
makes sense.  Thanks,

Alex

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-13 21:11         ` Alex Williamson
  0 siblings, 0 replies; 27+ messages in thread
From: Alex Williamson @ 2017-07-13 21:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 13 Jul 2017 06:29:38 -0500
Bjorn Helgaas <helgaas@kernel.org> wrote:

> [+cc Ben, David, Daniel, Alex]
> 
> On Thu, Jul 13, 2017 at 10:29:25AM +0000, Gabriele Paoloni wrote:
> > Hi Bjorn, Daniel
> > 
> > [...]
> >   
> > > 
> > > Is this quirk useful on any arch other than arm64?  Per
> > > drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> > > 
> > > Would it make sense to put this quirk in arch/arm64/kernel/pci.c?  
> > 
> > Indeed our host controller depends on ARM64 so maybe it would make
> > sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> > why is it strictly required for a VGA device to be legacy one in order
> > to make it the default boot device?
> > i.e. couldn't we have:
> > 
> > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> > index 0f5b2dd..a6b606c 100644
> > --- a/drivers/gpu/vga/vgaarb.c
> > +++ b/drivers/gpu/vga/vgaarb.c
> > @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
> >  	/* Deal with VGA default device. Use first enabled one
> >  	 * by default if arch doesn't have it's own hook
> >  	 */
> > -	if (vga_default == NULL &&
> > -	    ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> > +	if (vga_default == NULL) {
> >  		vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
> >  		vga_set_default_device(pdev);
> >  	}  


"Legacy" is the breadcrumb we use to try to pick the same device for
default VGA as the system firmware used as the boot VGA.  There can be
multiple VGA devices in the system, the change above would simply make
the first discovered device be the default VGA.  That would break many,
many systems.  If legacy VGA ranges mean nothing on ARM64, then follow
the powerpc lead and make an arch quirk that simply selects the first
enabled VGA device as the default.  VGA routing is part of the PCI spec
though, so the default of selecting the device with routing enabled
makes sense.  Thanks,

Alex

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-13 21:11         ` Alex Williamson
@ 2017-07-13 21:21           ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-13 21:21 UTC (permalink / raw)
  To: Alex Williamson, Bjorn Helgaas
  Cc: Gabriele Paoloni, Daniel Axtens, linux-pci,
	Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel,
	David Airlie, Daniel Vetter

On Thu, 2017-07-13 at 15:11 -0600, Alex Williamson wrote:
> > >       */
> > > -   if (vga_default == NULL &&
> > > -       ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> > > +   if (vga_default == NULL) {
> > >              vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
> > >              vga_set_default_device(pdev);
> > >      }  
> 
> 
> "Legacy" is the breadcrumb we use to try to pick the same device for
> default VGA as the system firmware used as the boot VGA.  There can be
> multiple VGA devices in the system, the change above would simply make
> the first discovered device be the default VGA.  That would break many,
> many systems.  If legacy VGA ranges mean nothing on ARM64, then follow
> the powerpc lead and make an arch quirk that simply selects the first
> enabled VGA device as the default.  VGA routing is part of the PCI spec
> though, so the default of selecting the device with routing enabled
> makes sense.  Thanks,

"Legacy" there iirc also means that it has decoding enabled at boot. If
you pick the first one you may pick a device that doesn't and hasn't
been initialized by any driver (good old BIOS-initialized text mode).

Cheers,
Ben.

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-13 21:21           ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-13 21:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, 2017-07-13 at 15:11 -0600, Alex Williamson wrote:
> > > ????? */
> > > -???if (vga_default == NULL &&
> > > -?????? ((vgadev->owns & VGA_RSRC_LEGACY_MASK) == VGA_RSRC_LEGACY_MASK)) {
> > > +???if (vga_default == NULL) {
> > > ?????????????vgaarb_info(&pdev->dev, "setting as boot VGA device\n");
> > > ?????????????vga_set_default_device(pdev);
> > > ?????}? 
> 
> 
> "Legacy" is the breadcrumb we use to try to pick the same device for
> default VGA as the system firmware used as the boot VGA.? There can be
> multiple VGA devices in the system, the change above would simply make
> the first discovered device be the default VGA.? That would break many,
> many systems.? If legacy VGA ranges mean nothing on ARM64, then follow
> the powerpc lead and make an arch quirk that simply selects the first
> enabled VGA device as the default.? VGA routing is part of the PCI spec
> though, so the default of selecting the device with routing enabled
> makes sense.? Thanks,

"Legacy" there iirc also means that it has decoding enabled at boot. If
you pick the first one you may pick a device that doesn't and hasn't
been initialized by any driver (good old BIOS-initialized text mode).

Cheers,
Ben.

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-12 20:04   ` Bjorn Helgaas
@ 2017-07-14  1:35     ` Will Deacon
  -1 siblings, 0 replies; 27+ messages in thread
From: Will Deacon @ 2017-07-14  1:35 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Daniel Axtens, linux-pci, Xinliang Liu, Rongrong Zou,
	Catalin Marinas, linux-arm-kernel

Hi Bjorn,

On Wed, Jul 12, 2017 at 03:04:30PM -0500, Bjorn Helgaas wrote:
> [+cc Catalin, Will, linux-arm-kernel]
> 
> On Wed, Jul 12, 2017 at 03:08:11PM +1000, Daniel Axtens wrote:
> > The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610) that
> > are not spec-compliant: the VGA Enable bit is hardwired to 0 and
> > writes do not change it.
> > 
> > The HiSilicon engineers report that the bridge does not forward the
> > 0xa0000-0xbffff mem range and the 0x3b0-0x3bb and 0x3c0-0x3df I/O
> > ranges.
> > 
> > Because the VGA Enable bit is hardwired to 0, the VGA arbiter refuses
> > to mark any card behind it as the boot device. This breaks Xorg
> > auto-detection.
> > 
> > However, the hibmc VGA card (PCI ID 19e5:1711) has been tested and is
> > known to work when behind these bridges. (It does not require the
> > legacy resources to operate.)
> > 
> > Provide a quirk so that this combination of bridge and card is eligible
> > to be the default VGA card. This fixes Xorg auto-detection on the D05.
> > 
> > Cc: Xinliang Liu <z.liuxinliang@hisilicon.com>
> > Cc: Rongrong Zou <zourongrong@gmail.com>
> > Signed-off-by: Daniel Axtens <dja@axtens.net>
> > ---
> > 
> > v3: fix commit message
> > v4: fix comment (forgot to git add/git commit, sorry for the noise)
> > 
> > ---
> >  drivers/pci/quirks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 50 insertions(+)
> > 
> > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> > index 16e6cd86ad71..b42324cba29e 100644
> > --- a/drivers/pci/quirks.c
> > +++ b/drivers/pci/quirks.c
> > @@ -25,6 +25,7 @@
> >  #include <linux/sched.h>
> >  #include <linux/ktime.h>
> >  #include <linux/mm.h>
> > +#include <linux/vgaarb.h>
> >  #include <asm/dma.h>	/* isa_dma_bridge_buggy */
> >  #include "pci.h"
> >  
> > @@ -4664,3 +4665,52 @@ static void quirk_intel_no_flr(struct pci_dev *dev)
> >  }
> >  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1502, quirk_intel_no_flr);
> >  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1503, quirk_intel_no_flr);
> > +
> > +/*
> > + * The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610)
> > + * that are not spec-compliant: the VGA Enable bit is hardwired to 0
> > + * and writes do not change it. The bridge does not forward legacy
> > + * memory or I/O resources.
> > + *
> > + * Because the VGA Enable bit is hardwired to 0, the VGA arbiter
> > + * refuses to mark any card behind it as the boot device. However, the
> > + * hibmc VGA card (PCI ID 19e5:1711) has been tested and is known to
> > + * work when behind these bridges.
> > + *
> > + * If we have this bridge, this card, and no default card already,
> > + * mark the card as default.
> > + */
> > +static void hibmc_fixup_vgaarb(struct pci_dev *pdev)
> > +{
> > +	struct pci_dev *bridge;
> > +	struct pci_bus *bus;
> > +	u16 config;
> > +
> > +	bus = pdev->bus;
> > +	bridge = bus->self;
> > +	if (!bridge)
> > +		return;
> > +
> > +	if (!pci_is_bridge(bridge))
> > +		return;
> > +
> > +	if (bridge->vendor != PCI_VENDOR_ID_HUAWEI ||
> > +	    bridge->device != 0x1610)
> > +		return;
> > +
> > +	pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
> > +			     &config);
> > +	if (config & PCI_BRIDGE_CTL_VGA) {
> > +		/*
> > +		 * Weirdly, this bridge *is* spec compliant, so bail
> > +		 * and let vgaarb do its job
> > +		 */
> > +		return;
> > +	}
> > +
> > +	if (vga_default_device())
> > +		return;
> > +
> > +	vga_set_default_device(pdev);
> > +}
> > +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0x1711, hibmc_fixup_vgaarb);
> 
> Is this quirk useful on any arch other than arm64?  Per
> drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> 
> Would it make sense to put this quirk in arch/arm64/kernel/pci.c?

We've resisted adding PCI quirks in the arch directory so far, so I'd rather
it lived in the PCI code if you don't have a strong objection to that.
Hardware vendors have a tendency to reuse broken IP, so it's not beyond the
realms of imagination that this quirk might be needed for another part some
day (e.g. based on 32-bit ARM).

Will

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14  1:35     ` Will Deacon
  0 siblings, 0 replies; 27+ messages in thread
From: Will Deacon @ 2017-07-14  1:35 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Bjorn,

On Wed, Jul 12, 2017 at 03:04:30PM -0500, Bjorn Helgaas wrote:
> [+cc Catalin, Will, linux-arm-kernel]
> 
> On Wed, Jul 12, 2017 at 03:08:11PM +1000, Daniel Axtens wrote:
> > The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610) that
> > are not spec-compliant: the VGA Enable bit is hardwired to 0 and
> > writes do not change it.
> > 
> > The HiSilicon engineers report that the bridge does not forward the
> > 0xa0000-0xbffff mem range and the 0x3b0-0x3bb and 0x3c0-0x3df I/O
> > ranges.
> > 
> > Because the VGA Enable bit is hardwired to 0, the VGA arbiter refuses
> > to mark any card behind it as the boot device. This breaks Xorg
> > auto-detection.
> > 
> > However, the hibmc VGA card (PCI ID 19e5:1711) has been tested and is
> > known to work when behind these bridges. (It does not require the
> > legacy resources to operate.)
> > 
> > Provide a quirk so that this combination of bridge and card is eligible
> > to be the default VGA card. This fixes Xorg auto-detection on the D05.
> > 
> > Cc: Xinliang Liu <z.liuxinliang@hisilicon.com>
> > Cc: Rongrong Zou <zourongrong@gmail.com>
> > Signed-off-by: Daniel Axtens <dja@axtens.net>
> > ---
> > 
> > v3: fix commit message
> > v4: fix comment (forgot to git add/git commit, sorry for the noise)
> > 
> > ---
> >  drivers/pci/quirks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 50 insertions(+)
> > 
> > diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
> > index 16e6cd86ad71..b42324cba29e 100644
> > --- a/drivers/pci/quirks.c
> > +++ b/drivers/pci/quirks.c
> > @@ -25,6 +25,7 @@
> >  #include <linux/sched.h>
> >  #include <linux/ktime.h>
> >  #include <linux/mm.h>
> > +#include <linux/vgaarb.h>
> >  #include <asm/dma.h>	/* isa_dma_bridge_buggy */
> >  #include "pci.h"
> >  
> > @@ -4664,3 +4665,52 @@ static void quirk_intel_no_flr(struct pci_dev *dev)
> >  }
> >  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1502, quirk_intel_no_flr);
> >  DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1503, quirk_intel_no_flr);
> > +
> > +/*
> > + * The HiSilicon D05 board has some PCI bridges (PCI ID 19e5:1610)
> > + * that are not spec-compliant: the VGA Enable bit is hardwired to 0
> > + * and writes do not change it. The bridge does not forward legacy
> > + * memory or I/O resources.
> > + *
> > + * Because the VGA Enable bit is hardwired to 0, the VGA arbiter
> > + * refuses to mark any card behind it as the boot device. However, the
> > + * hibmc VGA card (PCI ID 19e5:1711) has been tested and is known to
> > + * work when behind these bridges.
> > + *
> > + * If we have this bridge, this card, and no default card already,
> > + * mark the card as default.
> > + */
> > +static void hibmc_fixup_vgaarb(struct pci_dev *pdev)
> > +{
> > +	struct pci_dev *bridge;
> > +	struct pci_bus *bus;
> > +	u16 config;
> > +
> > +	bus = pdev->bus;
> > +	bridge = bus->self;
> > +	if (!bridge)
> > +		return;
> > +
> > +	if (!pci_is_bridge(bridge))
> > +		return;
> > +
> > +	if (bridge->vendor != PCI_VENDOR_ID_HUAWEI ||
> > +	    bridge->device != 0x1610)
> > +		return;
> > +
> > +	pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
> > +			     &config);
> > +	if (config & PCI_BRIDGE_CTL_VGA) {
> > +		/*
> > +		 * Weirdly, this bridge *is* spec compliant, so bail
> > +		 * and let vgaarb do its job
> > +		 */
> > +		return;
> > +	}
> > +
> > +	if (vga_default_device())
> > +		return;
> > +
> > +	vga_set_default_device(pdev);
> > +}
> > +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0x1711, hibmc_fixup_vgaarb);
> 
> Is this quirk useful on any arch other than arm64?  Per
> drivers/pci/dwc/Kconfig, CONFIG_PCI_HISI depends on CONFIG_ARM64.
> 
> Would it make sense to put this quirk in arch/arm64/kernel/pci.c?

We've resisted adding PCI quirks in the arch directory so far, so I'd rather
it lived in the PCI code if you don't have a strong objection to that.
Hardware vendors have a tendency to reuse broken IP, so it's not beyond the
realms of imagination that this quirk might be needed for another part some
day (e.g. based on 32-bit ARM).

Will

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

* RE: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-13 20:45         ` Benjamin Herrenschmidt
@ 2017-07-14 12:14           ` Gabriele Paoloni
  -1 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-14 12:14 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Bjorn Helgaas
  Cc: David Airlie, linux-pci, Will Deacon, Liuxinliang (Matthew Liu),
	Alex Williamson, Catalin Marinas, Rongrong Zou, Daniel Vetter,
	linux-arm-kernel, Daniel Axtens

SGkgQmVuDQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogQmVuamFtaW4g
SGVycmVuc2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GRldmljZS4uLg0KDQpJIHdhcyB0cnlpbmcgdG8gdW5kZXJzdGFuZCB3aHkgYSBkZWZh
dWx0IGRldmljZSBoYXMgdG8gYmUgbGVnYWN5Li4uYnV0IEkgdGhpbmsNCnRoaXMgd2FzIGFuc3dl
cmVkIGJ5IGJvdGggeW91IGFuZCBBbGV4IGluIG90aGVyIGZvbGxvd3MtdXAuLi4NCg0KVGhhbmtz
DQpHYWIgDQoNCj4gDQo+IENoZWVycywNCj4gQmVuLg0KDQpfX19fX19fX19fX19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fX19fX19fXwpsaW51eC1hcm0ta2VybmVsIG1haWxpbmcgbGlzdAps
aW51eC1hcm0ta2VybmVsQGxpc3RzLmluZnJhZGVhZC5vcmcKaHR0cDovL2xpc3RzLmluZnJhZGVh
ZC5vcmcvbWFpbG1hbi9saXN0aW5mby9saW51eC1hcm0ta2VybmVsCg==

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14 12:14           ` Gabriele Paoloni
  0 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-14 12:14 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Ben

> -----Original Message-----
> From: Benjamin Herrenschmidt [mailto:benh at kernel.crashing.org]
> Sent: 13 July 2017 21:45
> To: Bjorn Helgaas; Gabriele Paoloni
> Cc: Daniel Axtens; linux-pci at vger.kernel.org; Liuxinliang (Matthew
> Liu); Rongrong Zou; Catalin Marinas; Will Deacon; linux-arm-
> kernel at lists.infradead.org; David Airlie; Daniel Vetter; Alex
> Williamson
> Subject: Re: [PATCH v4] PCI: Support hibmc VGA cards behind a
> misbehaving HiSilicon bridge
> 
> On Thu, 2017-07-13 at 06:29 -0500, Bjorn Helgaas wrote:
> > > Indeed our host controller depends on ARM64 so maybe it would make
> > > sense to move the quirk arch/arm64/kernel/pci.c; however regardless
> > > why is it strictly required for a VGA device to be legacy one in
> order
> > > to make it the default boot device?
> > > i.e. couldn't we have:
> > >
> > > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> > > index 0f5b2dd..a6b606c 100644
> > > --- a/drivers/gpu/vga/vgaarb.c
> > > +++ b/drivers/gpu/vga/vgaarb.c
> > > @@ -667,8 +667,7 @@ static bool vga_arbiter_add_pci_device(struct
> pci_dev *pdev)
> > > ???????/* Deal with VGA default device. Use first enabled one
> > > ??????? * by default if arch doesn't have it's own hook
> > > ??????? */
> > > -?????if (vga_default == NULL &&
> > > -???????? ((vgadev->owns & VGA_RSRC_LEGACY_MASK) ==
> VGA_RSRC_LEGACY_MASK)) {
> > > +?????if (vga_default == NULL) {
> > > ???????????????vgaarb_info(&pdev->dev, "setting as boot VGA
> device\n");
> > > ???????????????vga_set_default_device(pdev);
> > > ???????}
> >
> > I don't know enough about the VGA arbiter to answer this.? This test
> was
> > part of the initial implementation: deb2d2ecd43d ("PCI/GPU: implement
> VGA
> > arbitration on Linux") by Ben.
> 
> The above simply uses the first device that has memory and IO enabled
> as the default device (you don't need to have a default device).
> 
> This is essentially picking up whatever device had been initialized
> by the BIOS/firmware as default. This is needed for example on x86
> where the BIOS tends to only initialize one device.
> 
> I'm not sure what problem you are trying to solve here ?

Well our host platform does not support legacy devices and therefore we find
ourselves without a default VGA device...

I was trying to understand why a default device has to be legacy...but I think
this was answered by both you and Alex in other follows-up...

Thanks
Gab 

> 
> Cheers,
> Ben.

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

* RE: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-13 21:21           ` Benjamin Herrenschmidt
@ 2017-07-14 12:26             ` Gabriele Paoloni
  -1 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-14 12:26 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Alex Williamson, Bjorn Helgaas
  Cc: David Airlie, linux-pci, Will Deacon, Liuxinliang (Matthew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FkLm9yZy9t
YWlsbWFuL2xpc3RpbmZvL2xpbnV4LWFybS1rZXJuZWwK

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14 12:26             ` Gabriele Paoloni
  0 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-14 12:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Ben, Alex

> -----Original Message-----
> From: Benjamin Herrenschmidt [mailto:benh at kernel.crashing.org]
> Sent: 13 July 2017 22:21
> To: Alex Williamson; Bjorn Helgaas
> Cc: Gabriele Paoloni; Daniel Axtens; linux-pci at vger.kernel.org;
> Liuxinliang (Matthew Liu); Rongrong Zou; Catalin Marinas; Will Deacon;
> linux-arm-kernel at lists.infradead.org; David Airlie; Daniel Vetter
> Subject: Re: [PATCH v4] PCI: Support hibmc VGA cards behind a
> misbehaving HiSilicon bridge
> 
> On Thu, 2017-07-13 at 15:11 -0600, Alex Williamson wrote:
> > > > ????? */
> > > > -???if (vga_default == NULL &&
> > > > -?????? ((vgadev->owns & VGA_RSRC_LEGACY_MASK) ==
> VGA_RSRC_LEGACY_MASK)) {
> > > > +???if (vga_default == NULL) {
> > > > ?????????????vgaarb_info(&pdev->dev, "setting as boot VGA
> device\n");
> > > > ?????????????vga_set_default_device(pdev);
> > > > ?????}
> >
> >
> > "Legacy" is the breadcrumb we use to try to pick the same device for
> > default VGA as the system firmware used as the boot VGA.? There can
> be
> > multiple VGA devices in the system, the change above would simply
> make
> > the first discovered device be the default VGA.? That would break
> many,
> > many systems.? If legacy VGA ranges mean nothing on ARM64, then
> follow
> > the powerpc lead and make an arch quirk that simply selects the first
> > enabled VGA device as the default.? VGA routing is part of the PCI
> spec
> > though, so the default of selecting the device with routing enabled
> > makes sense.? Thanks,
> 
> "Legacy" there iirc also means that it has decoding enabled at boot. If
> you pick the first one you may pick a device that doesn't and hasn't
> been initialized by any driver (good old BIOS-initialized text mode).

Right so effectively if there is a legacy dev we should pick that up;
however what about the following code:

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 92f1452..ab3ad9a 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -1424,6 +1424,14 @@ static int __init vga_arb_device_init(void)
 
 	list_for_each_entry(vgadev, &vga_list, list) {
 		struct device *dev = &vgadev->pdev->dev;
+
+		/* if no legacy device has been set as default VGA
+		 * device, just pick up the first one in the list */
+		if (vga_default == NULL) {
+			vgaarb_info(dev, "setting as boot VGA device\n");
+			vga_set_default_device(vgadev->pdev);
+		}
+
 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
 		/*
 		 * Override vga_arbiter_add_pci_device()'s I/O based detection 

Above after we have filled the list of VGA devices by iterating over all
PCI devices we check if no legacy one has been set as default VGA device
yet: therefore we set the first VGA device in the list as default one...

Do you think it would work?

Thanks
Gab

> 
> Cheers,
> Ben.

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-14 12:26             ` Gabriele Paoloni
@ 2017-07-14 13:50               ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-14 13:50 UTC (permalink / raw)
  To: Gabriele Paoloni, Alex Williamson, Bjorn Helgaas
  Cc: Daniel Axtens, linux-pci, Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel,
	David Airlie, Daniel Vetter

On Fri, 2017-07-14 at 12:26 +0000, Gabriele Paoloni wrote:
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 92f1452..ab3ad9a 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -1424,6 +1424,14 @@ static int __init vga_arb_device_init(void)
>  
>         list_for_each_entry(vgadev, &vga_list, list) {
>                 struct device *dev = &vgadev->pdev->dev;
> +
> +               /* if no legacy device has been set as default VGA
> +                * device, just pick up the first one in the list */
> +               if (vga_default == NULL) {
> +                       vgaarb_info(dev, "setting as boot VGA device\n");
> +                       vga_set_default_device(vgadev->pdev);
> +               }
> +
>  #if defined(CONFIG_X86) || defined(CONFIG_IA64)
>                 /*
>                  * Override vga_arbiter_add_pci_device()'s I/O based detection 
> 
> Above after we have filled the list of VGA devices by iterating over all
> PCI devices we check if no legacy one has been set as default VGA device
> yet: therefore we set the first VGA device in the list as default one...
> 
> Do you think it would work?

I honestly don't remember all of the details of the arbiter but just
make sure that it won't think that device is enabled for things like
VGA etc... if it's memory/IO decode weren't enabled.

I'd rather we have no default device until a driver actually picks up
though, and then, if we still have no default, use the first driver to
pick up.

Ben.

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14 13:50               ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-14 13:50 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, 2017-07-14 at 12:26 +0000, Gabriele Paoloni wrote:
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 92f1452..ab3ad9a 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -1424,6 +1424,14 @@ static int __init vga_arb_device_init(void)
> ?
> ????????list_for_each_entry(vgadev, &vga_list, list) {
> ????????????????struct device *dev = &vgadev->pdev->dev;
> +
> +???????????????/* if no legacy device has been set as default VGA
> +??????????????? * device, just pick up the first one in the list */
> +???????????????if (vga_default == NULL) {
> +???????????????????????vgaarb_info(dev, "setting as boot VGA device\n");
> +???????????????????????vga_set_default_device(vgadev->pdev);
> +???????????????}
> +
> ?#if defined(CONFIG_X86) || defined(CONFIG_IA64)
> ????????????????/*
> ???????????????? * Override vga_arbiter_add_pci_device()'s I/O based detection 
> 
> Above after we have filled the list of VGA devices by iterating over all
> PCI devices we check if no legacy one has been set as default VGA device
> yet: therefore we set the first VGA device in the list as default one...
> 
> Do you think it would work?

I honestly don't remember all of the details of the arbiter but just
make sure that it won't think that device is enabled for things like
VGA etc... if it's memory/IO decode weren't enabled.

I'd rather we have no default device until a driver actually picks up
though, and then, if we still have no default, use the first driver to
pick up.

Ben.

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-14 12:26             ` Gabriele Paoloni
@ 2017-07-14 14:43               ` Alex Williamson
  -1 siblings, 0 replies; 27+ messages in thread
From: Alex Williamson @ 2017-07-14 14:43 UTC (permalink / raw)
  To: Gabriele Paoloni
  Cc: Benjamin Herrenschmidt, Bjorn Helgaas, Daniel Axtens, linux-pci,
	Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel,
	David Airlie, Daniel Vetter

On Fri, 14 Jul 2017 12:26:05 +0000
Gabriele Paoloni <gabriele.paoloni@huawei.com> wrote:

> Hi Ben, Alex
>=20
> > -----Original Message-----
> > From: Benjamin Herrenschmidt [mailto:benh@kernel.crashing.org]
> > Sent: 13 July 2017 22:21
> > To: Alex Williamson; Bjorn Helgaas
> > Cc: Gabriele Paoloni; Daniel Axtens; linux-pci@vger.kernel.org;
> > Liuxinliang (Matthew Liu); Rongrong Zou; Catalin Marinas; Will Deacon;
> > linux-arm-kernel@lists.infradead.org; David Airlie; Daniel Vetter
> > Subject: Re: [PATCH v4] PCI: Support hibmc VGA cards behind a
> > misbehaving HiSilicon bridge
> >=20
> > On Thu, 2017-07-13 at 15:11 -0600, Alex Williamson wrote: =20
> > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */
> > > > > -=C2=A0=C2=A0=C2=A0if (vga_default =3D=3D NULL &&
> > > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((vgadev->owns & VGA_RSRC_L=
EGACY_MASK) =3D=3D =20
> > VGA_RSRC_LEGACY_MASK)) { =20
> > > > > +=C2=A0=C2=A0=C2=A0if (vga_default =3D=3D NULL) {
> > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0vgaarb_info(&pdev->dev, "setting as boot VGA =20
> > device\n"); =20
> > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0vga_set_default_device(pdev);
> > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0} =20
> > >
> > >
> > > "Legacy" is the breadcrumb we use to try to pick the same device for
> > > default VGA as the system firmware used as the boot VGA.=C2=A0 There =
can =20
> > be =20
> > > multiple VGA devices in the system, the change above would simply =20
> > make =20
> > > the first discovered device be the default VGA.=C2=A0 That would brea=
k =20
> > many, =20
> > > many systems.=C2=A0 If legacy VGA ranges mean nothing on ARM64, then =
=20
> > follow =20
> > > the powerpc lead and make an arch quirk that simply selects the first
> > > enabled VGA device as the default.=C2=A0 VGA routing is part of the P=
CI =20
> > spec =20
> > > though, so the default of selecting the device with routing enabled
> > > makes sense.=C2=A0 Thanks, =20
> >=20
> > "Legacy" there iirc also means that it has decoding enabled at boot. If
> > you pick the first one you may pick a device that doesn't and hasn't
> > been initialized by any driver (good old BIOS-initialized text mode). =
=20
>=20
> Right so effectively if there is a legacy dev we should pick that up;
> however what about the following code:
>=20
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 92f1452..ab3ad9a 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -1424,6 +1424,14 @@ static int __init vga_arb_device_init(void)
> =20
>  	list_for_each_entry(vgadev, &vga_list, list) {
>  		struct device *dev =3D &vgadev->pdev->dev;
> +
> +		/* if no legacy device has been set as default VGA
> +		 * device, just pick up the first one in the list */
> +		if (vga_default =3D=3D NULL) {
> +			vgaarb_info(dev, "setting as boot VGA device\n");
> +			vga_set_default_device(vgadev->pdev);
> +		}
> +
>  #if defined(CONFIG_X86) || defined(CONFIG_IA64)
>  		/*
>  		 * Override vga_arbiter_add_pci_device()'s I/O based detection=20
>=20
> Above after we have filled the list of VGA devices by iterating over all
> PCI devices we check if no legacy one has been set as default VGA device
> yet: therefore we set the first VGA device in the list as default one...
>=20
> Do you think it would work?

I'd suggest at least looking for an enabled device as fixup_vga() does,
perhaps that would even be enough to remove that arch quirk.  Thanks,

Alex

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14 14:43               ` Alex Williamson
  0 siblings, 0 replies; 27+ messages in thread
From: Alex Williamson @ 2017-07-14 14:43 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, 14 Jul 2017 12:26:05 +0000
Gabriele Paoloni <gabriele.paoloni@huawei.com> wrote:

> Hi Ben, Alex
> 
> > -----Original Message-----
> > From: Benjamin Herrenschmidt [mailto:benh at kernel.crashing.org]
> > Sent: 13 July 2017 22:21
> > To: Alex Williamson; Bjorn Helgaas
> > Cc: Gabriele Paoloni; Daniel Axtens; linux-pci at vger.kernel.org;
> > Liuxinliang (Matthew Liu); Rongrong Zou; Catalin Marinas; Will Deacon;
> > linux-arm-kernel at lists.infradead.org; David Airlie; Daniel Vetter
> > Subject: Re: [PATCH v4] PCI: Support hibmc VGA cards behind a
> > misbehaving HiSilicon bridge
> > 
> > On Thu, 2017-07-13 at 15:11 -0600, Alex Williamson wrote:  
> > > > > ????? */
> > > > > -???if (vga_default == NULL &&
> > > > > -?????? ((vgadev->owns & VGA_RSRC_LEGACY_MASK) ==  
> > VGA_RSRC_LEGACY_MASK)) {  
> > > > > +???if (vga_default == NULL) {
> > > > > ?????????????vgaarb_info(&pdev->dev, "setting as boot VGA  
> > device\n");  
> > > > > ?????????????vga_set_default_device(pdev);
> > > > > ?????}  
> > >
> > >
> > > "Legacy" is the breadcrumb we use to try to pick the same device for
> > > default VGA as the system firmware used as the boot VGA.? There can  
> > be  
> > > multiple VGA devices in the system, the change above would simply  
> > make  
> > > the first discovered device be the default VGA.? That would break  
> > many,  
> > > many systems.? If legacy VGA ranges mean nothing on ARM64, then  
> > follow  
> > > the powerpc lead and make an arch quirk that simply selects the first
> > > enabled VGA device as the default.? VGA routing is part of the PCI  
> > spec  
> > > though, so the default of selecting the device with routing enabled
> > > makes sense.? Thanks,  
> > 
> > "Legacy" there iirc also means that it has decoding enabled at boot. If
> > you pick the first one you may pick a device that doesn't and hasn't
> > been initialized by any driver (good old BIOS-initialized text mode).  
> 
> Right so effectively if there is a legacy dev we should pick that up;
> however what about the following code:
> 
> diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> index 92f1452..ab3ad9a 100644
> --- a/drivers/gpu/vga/vgaarb.c
> +++ b/drivers/gpu/vga/vgaarb.c
> @@ -1424,6 +1424,14 @@ static int __init vga_arb_device_init(void)
>  
>  	list_for_each_entry(vgadev, &vga_list, list) {
>  		struct device *dev = &vgadev->pdev->dev;
> +
> +		/* if no legacy device has been set as default VGA
> +		 * device, just pick up the first one in the list */
> +		if (vga_default == NULL) {
> +			vgaarb_info(dev, "setting as boot VGA device\n");
> +			vga_set_default_device(vgadev->pdev);
> +		}
> +
>  #if defined(CONFIG_X86) || defined(CONFIG_IA64)
>  		/*
>  		 * Override vga_arbiter_add_pci_device()'s I/O based detection 
> 
> Above after we have filled the list of VGA devices by iterating over all
> PCI devices we check if no legacy one has been set as default VGA device
> yet: therefore we set the first VGA device in the list as default one...
> 
> Do you think it would work?

I'd suggest at least looking for an enabled device as fixup_vga() does,
perhaps that would even be enough to remove that arch quirk.  Thanks,

Alex

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

* RE: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-14 13:50               ` Benjamin Herrenschmidt
@ 2017-07-14 17:03                 ` Gabriele Paoloni
  -1 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-14 17:03 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Alex Williamson, Bjorn Helgaas
  Cc: David Airlie, linux-pci, Will Deacon, Liuxinliang (Matthew Liu),
	Catalin Marinas, Rongrong Zou, Daniel Vetter, linux-arm-kernel,
	Daniel Axtens

SGkgQWxleCwgQmVuDQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogQmVu
amFtaW4gSGVycmVuc2NobWlkdCBbbWFpbHRvOmJlbmhAa2VybmVsLmNyYXNoaW5nLm9yZ10NCj4g
U2VudDogMTQgSnVseSAyMDE3IDE0OjUwDQo+IFRvOiBHYWJyaWVsZSBQYW9sb25pOyBBbGV4IFdp
bGxpYW1zb247IEJqb3JuIEhlbGdhYXMNCj4gQ2M6IERhbmllbCBBeHRlbnM7IGxpbnV4LXBjaUB2
Z2VyLmtlcm5lbC5vcmc7IExpdXhpbmxpYW5nIChNYXR0aGV3DQo+IExpdSk7IFJvbmdyb25nIFpv
dTsgQ2F0YWxpbiBNYXJpbmFzOyBXaWxsIERlYWNvbjsgbGludXgtYXJtLQ0KPiBrZXJuZWxAbGlz
dHMuaW5mcmFkZWFkLm9yZzsgRGF2aWQgQWlybGllOyBEYW5pZWwgVmV0dGVyDQo+IFN1YmplY3Q6
IFJlOiBbUEFUQ0ggdjRdIFBDSTogU3VwcG9ydCBoaWJtYyBWR0EgY2FyZHMgYmVoaW5kIGENCj4g
bWlzYmVoYXZpbmcgSGlTaWxpY29uIGJyaWRnZQ0KPiANCj4gT24gRnJpLCAyMDE3LTA3LTE0IGF0
IDEyOjI2ICswMDAwLCBHYWJyaWVsZSBQYW9sb25pIHdyb3RlOg0KPiA+IGRpZmYgLS1naXQgYS9k
cml2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VyIHdpbGwgcHJvYmUgb3RoZXJ3aXNlIGl0IHdp
bGwgbm90Lg0KDQpBcmUgeW91IHN1Z2dlc3RpbmcgdG8gYWRkIHRoZSBjb2RlIGFib3ZlIGluIHBj
aV9kZXZpY2VfYWRkKCkgYWZ0ZXIgZGV2aWNlX2FkZCgpDQphbmQgYWZ0ZXIgY2hlY2tpbmcgdGhh
dCBhIGRyaXZlciBoYXMgYmVlbiBib3VuZCBmb3Igc3VjaCBkZXY/DQoNClRoYW5rcw0KR2FiDQoN
Cg0KPiANCj4gQmVuLg0KDQpfX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f
X19fX19fXwpsaW51eC1hcm0ta2VybmVsIG1haWxpbmcgbGlzdApsaW51eC1hcm0ta2VybmVsQGxp
c3RzLmluZnJhZGVhZC5vcmcKaHR0cDovL2xpc3RzLmluZnJhZGVhZC5vcmcvbWFpbG1hbi9saXN0
aW5mby9saW51eC1hcm0ta2VybmVsCg==

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14 17:03                 ` Gabriele Paoloni
  0 siblings, 0 replies; 27+ messages in thread
From: Gabriele Paoloni @ 2017-07-14 17:03 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Alex, Ben

> -----Original Message-----
> From: Benjamin Herrenschmidt [mailto:benh at kernel.crashing.org]
> Sent: 14 July 2017 14:50
> To: Gabriele Paoloni; Alex Williamson; Bjorn Helgaas
> Cc: Daniel Axtens; linux-pci at vger.kernel.org; Liuxinliang (Matthew
> Liu); Rongrong Zou; Catalin Marinas; Will Deacon; linux-arm-
> kernel at lists.infradead.org; David Airlie; Daniel Vetter
> Subject: Re: [PATCH v4] PCI: Support hibmc VGA cards behind a
> misbehaving HiSilicon bridge
> 
> On Fri, 2017-07-14 at 12:26 +0000, Gabriele Paoloni wrote:
> > diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
> > index 92f1452..ab3ad9a 100644
> > --- a/drivers/gpu/vga/vgaarb.c
> > +++ b/drivers/gpu/vga/vgaarb.c
> > @@ -1424,6 +1424,14 @@ static int __init vga_arb_device_init(void)
> >
> > ????????list_for_each_entry(vgadev, &vga_list, list) {
> > ????????????????struct device *dev = &vgadev->pdev->dev;
> > +
> > +???????????????/* if no legacy device has been set as default VGA
> > +??????????????? * device, just pick up the first one in the list */
> > +???????????????if (vga_default == NULL) {
> > +???????????????????????vgaarb_info(dev, "setting as boot VGA
> device\n");
> > +???????????????????????vga_set_default_device(vgadev->pdev);
> > +???????????????}
> > +
> > ?#if defined(CONFIG_X86) || defined(CONFIG_IA64)
> > ????????????????/*
> > ???????????????? * Override vga_arbiter_add_pci_device()'s I/O based
> detection
> >
> > Above after we have filled the list of VGA devices by iterating over
> all
> > PCI devices we check if no legacy one has been set as default VGA
> device
> > yet: therefore we set the first VGA device in the list as default
> one...
> >
> > Do you think it would work?
> 
> I honestly don't remember all of the details of the arbiter but just
> make sure that it won't think that device is enabled for things like
> VGA etc... if it's memory/IO decode weren't enabled.
> 

I think the following one should make sure that MEM/IO response are
enabled (also as suggested by Alex)

diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 92f1452..a90c48c 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -1424,6 +1424,21 @@ static int __init vga_arb_device_init(void)
 
 	list_for_each_entry(vgadev, &vga_list, list) {
 		struct device *dev = &vgadev->pdev->dev;
+
+		/* if no legacy device has been set as default VGA device,
+		 * justpick up the first one in the list capable of responding to
+		 * mem and io requests*/
+		if (vga_default == NULL) {
+			u16 cmd;
+
+			pci_read_config_word(vgadev->pdev, PCI_COMMAND, &cmd);
+			if ((cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) ||
+					!vga_default_device()) {
+				vga_set_default_device(vgadev->pdev);
+				vgaarb_info(dev, "setting as boot VGA device\n");
+			}
+		}
+
 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
 		/*
 		 * Override vga_arbiter_add_pci_device()'s I/O based detection


Also the above one could allow us to get rid of fixup_vga in powerpc....


> I'd rather we have no default device until a driver actually picks up
> though, and then, if we still have no default, use the first driver to
> pick up.

Well from my understanding the PCI host controller driver will enumerate
all the devices in the PCI hierarchy and call pci_device_add() for each of
them, that in turn will call device_add(), at this stage if there is a
driver available for the device such driver will probe otherwise it will not.

Are you suggesting to add the code above in pci_device_add() after device_add()
and after checking that a driver has been bound for such dev?

Thanks
Gab


> 
> Ben.

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

* Re: [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
  2017-07-14 17:03                 ` Gabriele Paoloni
@ 2017-07-14 23:54                   ` Benjamin Herrenschmidt
  -1 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-14 23:54 UTC (permalink / raw)
  To: Gabriele Paoloni, Alex Williamson, Bjorn Helgaas
  Cc: Daniel Axtens, linux-pci, Liuxinliang (Matthew Liu),
	Rongrong Zou, Catalin Marinas, Will Deacon, linux-arm-kernel,
	David Airlie, Daniel Vetter

On Fri, 2017-07-14 at 17:03 +0000, Gabriele Paoloni wrote:
> > I'd rather we have no default device until a driver actually picks up
> > though, and then, if we still have no default, use the first driver to
> > pick up.
> 
> Well from my understanding the PCI host controller driver will enumerate
> all the devices in the PCI hierarchy and call pci_device_add() for each of
> them, that in turn will call device_add(), at this stage if there is a
> driver available for the device such driver will probe otherwise it will not.
> 
> Are you suggesting to add the code above in pci_device_add() after device_add()
> and after checking that a driver has been bound for such dev?

I don't like us turning on MEM/IO decoding on a device that has
potentially not been initialized by its driver.

Ben.

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

* [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge
@ 2017-07-14 23:54                   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2017-07-14 23:54 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, 2017-07-14 at 17:03 +0000, Gabriele Paoloni wrote:
> > I'd rather we have no default device until a driver actually picks up
> > though, and then, if we still have no default, use the first driver to
> > pick up.
> 
> Well from my understanding the PCI host controller driver will enumerate
> all the devices in the PCI hierarchy and call pci_device_add() for each of
> them, that in turn will call device_add(), at this stage if there is a
> driver available for the device such driver will probe otherwise it will not.
> 
> Are you suggesting to add the code above in pci_device_add() after device_add()
> and after checking that a driver has been bound for such dev?

I don't like us turning on MEM/IO decoding on a device that has
potentially not been initialized by its driver.

Ben.

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

end of thread, other threads:[~2017-07-14 23:54 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-12  5:08 [PATCH v4] PCI: Support hibmc VGA cards behind a misbehaving HiSilicon bridge Daniel Axtens
2017-07-12 20:04 ` Bjorn Helgaas
2017-07-12 20:04   ` Bjorn Helgaas
2017-07-13 10:29   ` Gabriele Paoloni
2017-07-13 10:29     ` Gabriele Paoloni
2017-07-13 11:29     ` Bjorn Helgaas
2017-07-13 11:29       ` Bjorn Helgaas
2017-07-13 20:45       ` Benjamin Herrenschmidt
2017-07-13 20:45         ` Benjamin Herrenschmidt
2017-07-14 12:14         ` Gabriele Paoloni
2017-07-14 12:14           ` Gabriele Paoloni
2017-07-13 21:11       ` Alex Williamson
2017-07-13 21:11         ` Alex Williamson
2017-07-13 21:21         ` Benjamin Herrenschmidt
2017-07-13 21:21           ` Benjamin Herrenschmidt
2017-07-14 12:26           ` Gabriele Paoloni
2017-07-14 12:26             ` Gabriele Paoloni
2017-07-14 13:50             ` Benjamin Herrenschmidt
2017-07-14 13:50               ` Benjamin Herrenschmidt
2017-07-14 17:03               ` Gabriele Paoloni
2017-07-14 17:03                 ` Gabriele Paoloni
2017-07-14 23:54                 ` Benjamin Herrenschmidt
2017-07-14 23:54                   ` Benjamin Herrenschmidt
2017-07-14 14:43             ` Alex Williamson
2017-07-14 14:43               ` Alex Williamson
2017-07-14  1:35   ` Will Deacon
2017-07-14  1:35     ` Will Deacon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.