Skip to contentSkip to conversation

Split VGA default selection from VGA arbiter

PATCH Superseded Daniel Axtens 4 participants 11 messages Aug 4, 2017 – Aug 13, 2017

Subsystems (6)
DRM drivers x86 DRM misc PowerPC +2 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Split VGA default selection from VGA arbiter

This is approach 3 of my patch series to sort out Xorg autoconfiguration for the Hibmc card beind a Hisilicon bridge on arm64.

Approach 1 was a simple quirk for the card+bridge to mark it as default. This higlighted the fact that the default card was picked by the arbiter, which assumed legacy resources. The lack of legacy resources leads to quirks in ppc and concerns in arm land, so a more generic approach was desired.

Approach 2 allowed platforms to opt in to a class enable hook that added a card as default if there was no default. This:

- was possibly racy as ACPI PCI init and vgaarb are both subsys initcalls.

- didn't check to see if a card had a driver.

- meant that platforms for which the vga arbiter didn't make sense still needed it.

This is approach 3. It pulls the default handling out of the arbiter, into its own file and behind its own Kconfig option. It adds the extra detection as a late initcall and an enable hook that only operates after the initcall, so it's not racy. It checks for drivers. It means people can turn off the vga arbiter. It works sensibly for modules too.

Patch 1 cleans up the powerpc fixup, as with approach 2.
Patch 2 is the big split.
Patch 3 moves ppc over, as with approach 2.
There is no need for an arm-specific patch this time as the Kconfig option is on by default.

Regards,
Daniel

Daniel Axtens (3):
powerpc: simplify and fix VGA default device behaviour Split VGA default device handler out of VGA arbiter
powerpc: replace vga_fixup() with generic code

 arch/ia64/pci/fixup.c            |   2 +-
 arch/powerpc/kernel/pci-common.c |  13 ----
 arch/x86/pci/fixup.c             |   2 +-
 arch/x86/video/fbdev.c           |   2 +-
 drivers/gpu/vga/Kconfig          |  12 +++
 drivers/gpu/vga/Makefile         |   1 +
 drivers/gpu/vga/vga_default.c    | 159 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/vga/vga_switcheroo.c |   2 +-
 drivers/gpu/vga/vgaarb.c         |  41 +---------
 drivers/pci/pci-sysfs.c          |   2 +-
 include/linux/vga_default.h      |  44 +++++++++++
 include/linux/vgaarb.h           |  14 ----
 12 files changed, 224 insertions(+), 70 deletions(-)
 create mode 100644 drivers/gpu/vga/vga_default.c
 create mode 100644 include/linux/vga_default.h
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 powerpc: simplify and fix VGA default device behaviour

Some powerpc devices provide a PCI display that isn't picked up by the VGA arbiter, presumably because it doesn't support the PCI legacy VGA ranges.

Commit c2e1d84523ad ("powerpc: Set default VGA device") introduced an arch quirk to mark these devices as default to fix X autoconfig.

The commit message stated that the patch:

Ensures a default VGA is always set if a graphics adapter is present, even if firmware did not initialize it. If more than one graphics adapter is present, ensure the one initialized by firmware is set as the default VGA device.

The patch used the following test to decide whether or not to mark a device as default:

  pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  if ((cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) || !vga_default_device())
          vga_set_default_device(pdev);

This doesn't seem like it works quite as intended. Because of the logical OR, the default device will be set in 2 cases:

1) if there is no default device
OR
2) if this device has normal memory/IO decoding turned on

This will work as intended if there is only one device, but if there are multiple devices, we may override the device the VGA arbiter picked.

Instead, set a device as default if there is no default device AND this device decodes.

This will not change behaviour on single-headed systems.

---

Tested in TCG (the card provided by qemu doesn't automatically register with vgaarb, so the relevant code path has been tested) but I would appreciate any tests on real hardware.

Informal benh ack: https://patchwork.kernel.org/patch/9850235/

---
 arch/powerpc/kernel/pci-common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kernel/pci-common.c +4 -1
index 341a7469cab8..c95fdda3a2dc 100644
@@ -1746,8 +1746,11 @@ static void fixup_vga(struct pci_dev *pdev)
 {
 	u16 cmd;
 
+	if (vga_default_device())
+		return;
+
 	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
-	if ((cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) || !vga_default_device())
+	if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
 		vga_set_default_device(pdev);
 
 }
Signature · 1 line
2.11.0
#4 lore raw

PATCH 2/3 Split VGA default device handler out of VGA arbiter

In reply to Daniel Axtens

A system without PCI legacy resources (e.g. ARM64, powerpc) may find that no default/boot VGA device has been marked, because the VGA arbiter checks for legacy resource decoding before marking a card as default.

Split the small bit of code that does default VGA handling out from the arbiter. Add a Kconfig option to allow the kernel to be built with just the default handling, or the arbiter and default handling. (You can try with the arbiter and no default handling - I can't see why that wouldn't work but it seems a bit odd to try.)

Add handling for devices that should be marked as default but aren't handled by the vga arbiter by adding a late initcall and a class enable hook. If there is no default from vgaarb then the first card that is enabled, has a driver bound, and can decode memory or I/O will be marked as default.

---

I haven't tested this particularly deeply just yet as I wanted to see if anyone had Strong Feelings before I put too much time into testing. I have verified that it works on ppc with qemu TCG, both with and without the following patch.

I know this adds another config option and that's a bit sad, but we can't include it unconditionally as it depends on PCI. Suggestions welcome.

---
 arch/ia64/pci/fixup.c            |   2 +-
 arch/powerpc/kernel/pci-common.c |   2 +-
 arch/x86/pci/fixup.c             |   2 +-
 arch/x86/video/fbdev.c           |   2 +-
 drivers/gpu/vga/Kconfig          |  12 +++
 drivers/gpu/vga/Makefile         |   1 +
 drivers/gpu/vga/vga_default.c    | 159 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/vga/vga_switcheroo.c |   2 +-
 drivers/gpu/vga/vgaarb.c         |  41 +---------
 drivers/pci/pci-sysfs.c          |   2 +-
 include/linux/vga_default.h      |  44 +++++++++++
 include/linux/vgaarb.h           |  14 ----
 12 files changed, 225 insertions(+), 58 deletions(-)
 create mode 100644 drivers/gpu/vga/vga_default.c
 create mode 100644 include/linux/vga_default.h
arch/ia64/pci/fixup.c +1 -1
index 41caa99add51..b35d1cf4501a 100644
@@ -5,7 +5,7 @@
 
 #include <linux/pci.h>
 #include <linux/init.h>
-#include <linux/vgaarb.h>
+#include <linux/vga_default.h>
 #include <linux/screen_info.h>
 
 #include <asm/machvec.h>
arch/powerpc/kernel/pci-common.c +1 -1
index c95fdda3a2dc..6cfaec107374 100644
@@ -31,7 +31,7 @@
 #include <linux/irq.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
-#include <linux/vgaarb.h>
+#include <linux/vga_default.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
arch/x86/pci/fixup.c +1 -1
index 11e407489db0..b1254bc09a45 100644
@@ -5,7 +5,7 @@
 #include <linux/delay.h>
 #include <linux/dmi.h>
 #include <linux/pci.h>
-#include <linux/vgaarb.h>
+#include <linux/vga_default.h>
 #include <asm/hpet.h>
 #include <asm/pci_x86.h>
 
arch/x86/video/fbdev.c +1 -1
index 9fd24846d094..62cfa74ea86e 100644
@@ -9,7 +9,7 @@
 #include <linux/fb.h>
 #include <linux/pci.h>
 #include <linux/module.h>
-#include <linux/vgaarb.h>
+#include <linux/vga_default.h>
 
 int fb_is_primary_device(struct fb_info *info)
 {
drivers/gpu/vga/Kconfig +12 -0
index 29437eabe095..81d4105aecf6 100644
@@ -1,3 +1,14 @@
+config VGA_DEFAULT
+	bool "VGA Default Device Support" if EXPERT
+	default y
+	depends on PCI
+	help
+	  Some programs find it helpful to know what VGA device is the default.
+	  On platforms like x86 this means the device used by the BIOS to show
+	  early boot messages. On other platforms this may be an arbitrary PCI
+	  graphics card. Select this to have a default device recorded within
+	  the kernel and exposed to userspace through sysfs.
+
 config VGA_ARB
 	bool "VGA Arbitration" if EXPERT
 	default y
@@ -22,6 +33,7 @@ config VGA_SWITCHEROO
 	depends on X86
 	depends on ACPI
 	select VGA_ARB
+	select VGA_DEFAULT
 	help
 	  Many laptops released in 2008/9/10 have two GPUs with a multiplexer
 	  to switch between them. This adds support for dynamic switching when
drivers/gpu/vga/Makefile +1 -0
index 14ca30b75d0a..1e30f90d40fb 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_VGA_ARB)  += vgaarb.o
+obj-$(CONFIG_VGA_DEFAULT) += vga_default.o
 obj-$(CONFIG_VGA_SWITCHEROO) += vga_switcheroo.o
drivers/gpu/vga/vga_default.c new file +159 -0

159 lines not on this page · raw message

drivers/gpu/vga/vga_switcheroo.c +1 -1
index 3cd153c6d271..6612ec7981b6 100644
@@ -41,7 +41,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
-#include <linux/vgaarb.h>
+#include <linux/vga_default.h>
 #include <linux/vga_switcheroo.h>
 
 /**
drivers/gpu/vga/vgaarb.c +3 -38

71 lines not on this page · raw message

drivers/pci/pci-sysfs.c +1 -1
index 2f3780b50723..c174b427ea2b 100644
@@ -27,7 +27,7 @@
 #include <linux/security.h>
 #include <linux/pci-aspm.h>
 #include <linux/slab.h>
-#include <linux/vgaarb.h>
+#include <linux/vga_default.h>
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
 #include "pci.h"
include/linux/vga_default.h new file +44 -0

44 lines not on this page · raw message

include/linux/vgaarb.h +0 -14
index ee162e3e879b..953e1955efbe 100644
@@ -42,12 +42,6 @@
 #define VGA_RSRC_NORMAL_IO     0x04
 #define VGA_RSRC_NORMAL_MEM    0x08
 
-/* Passing that instead of a pci_dev to use the system "default"
- * device, that is the one used by vgacon. Archs will probably
- * have to provide their own vga_default_device();
- */
-#define VGA_DEFAULT_DEVICE     (NULL)
-
 struct pci_dev;
 
 /* For use by clients */
@@ -122,14 +116,6 @@ extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
 #endif
 
 
-#ifdef CONFIG_VGA_ARB
-extern struct pci_dev *vga_default_device(void);
-extern void vga_set_default_device(struct pci_dev *pdev);
-#else
-static inline struct pci_dev *vga_default_device(void) { return NULL; };
-static inline void vga_set_default_device(struct pci_dev *pdev) { };
-#endif
-
 /*
  * Architectures should define this if they have several
  * independent PCI domains that can afford concurrent VGA
Signature · 1 line
2.11.0
#7 lore raw

PATCH 3/3 powerpc: replace vga_fixup() with generic code

In reply to Daniel Axtens

Currently, we do a PCI fixup to mark a default card so that Xorg autoconfiguration works.

There is a new generic method to do this sort of vga fixup, and it occurs by default.

Drop our old method.

This method is different:
- it will only mark a card as default if a driver is bound
- the marking will happen at late_initcall time, or even later if a card is enabled later on (via an ENABLE hook). Currently things are enabled in a FINAL hook.

This *does* change behaviour under some circumstances.

For example, pseries_le_defconfig doesn't have DRM drivers for many of the qemu GPU models, including the 'standard' vga. So when a VM with that GPU boots, no driver binds the GPU, and it does *not* get marked as default. Previously, it would have been marked as default.

As it turns out Xorg (at least Xorg v1.19.3) can still autoconfigure it, as Xorg is smart about OpenFirmware framebuffer devices.

If the right GPU driver is available, and the OpenFirmware fb driver is removed, the device *is* marked as a boot GPU. (If the OpenFirmware driver is around, it enables the PCI device but doesn't bind to it, making it ineligible to be the default card. Then, when the right driver is loaded, the enable hook doesn't fire because the card has already been enabled. Fun!) So everything works as intended, I guess.

---

This would benefit from some tests on real hardware.

---
 arch/powerpc/kernel/pci-common.c | 16 ----------------
 1 file changed, 16 deletions(-)
arch/powerpc/kernel/pci-common.c +0 -16
index 6cfaec107374..65cd5bad5ad6 100644
@@ -31,7 +31,6 @@
 #include <linux/irq.h>
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
-#include <linux/vga_default.h>
 
 #include <asm/processor.h>
 #include <asm/io.h>
@@ -1741,18 +1740,3 @@ static void fixup_hide_host_resource_fsl(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MOTOROLA, PCI_ANY_ID, fixup_hide_host_resource_fsl);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, fixup_hide_host_resource_fsl);
-
-static void fixup_vga(struct pci_dev *pdev)
-{
-	u16 cmd;
-
-	if (vga_default_device())
-		return;
-
-	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
-	if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
-		vga_set_default_device(pdev);
-
-}
-DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
-			      PCI_CLASS_DISPLAY_VGA, 8, fixup_vga);
Signature · 1 line
2.11.0
reviewer
#5 lore raw

Re: [PATCH 2/3] Split VGA default device handler out of VGA arbiter

In reply to Daniel Axtens
Quoted 4 lines · Daniel Axtens

A system without PCI legacy resources (e.g. ARM64, powerpc) may find that no default/boot VGA device has been marked, because the VGA arbiter checks for legacy resource decoding before marking a card as default.

Would it be feasible to just sprinkle some "if (IS_ENABLED(CONFIG_X86))" over the portions of vgaarb.c that deal with legacy resources?

I'm missing some context as to the negative consequences you're experiencing on other arches (the cover letter merely refers to "quirks in ppc and concerns in arm land" and is missing links to archived versions of v1 and v2), but clearly legacy resources are x86-specific so any code dealing with them seems superfluous on other arches and should be marked as such.

Please cc dri-devel when proposing changes to vgaarb.c (see MAINTAINERS).

Thanks,

Lukas

#6 lore raw

Re: [PATCH 2/3] Split VGA default device handler out of VGA arbiter

Hi Lukas,

Let me reply "back-to-front":

Quoted 2 lines

Please cc dri-devel when proposing changes to vgaarb.c (see MAINTAINERS).

Sorry, will do in future.

Quoted 6 lines

I'm missing some context as to the negative consequences you're experiencing on other arches (the cover letter merely refers to "quirks in ppc and concerns in arm land" and is missing links to archived versions of v1 and v2), but clearly legacy resources are x86-specific so any code dealing with them seems superfluous on other arches and should be marked as such.

Quirk/v1: https://www.spinics.net/lists/linux-pci/msg62865.html
Approach 2: https://www.spinics.net/lists/linux-pci/msg63092.html

            https://www.spinics.net/lists/linux-pci/msg63083.html

The quirk in powerpc land that I'm referring to is arch/powerpc/kernel/pci-common.c::fixup_vga() which is a class enable hook that marks the first VGA device it comes across as default if the arbiter has not marked one.

The arm concerns are ventaliated in the threads I linked - they boil down to "why do we need the arbiter at all on platforms without legacy resources? Can't we do this more simply?"

Quoted 2 lines

Would it be feasible to just sprinkle some "if (IS_ENABLED(CONFIG_X86))" over the portions of vgaarb.c that deal with legacy resources?

Yes and no. That would disable the unnecessary chunks of the VGA arbiter, but we then still have to figure out how to mark devices as default if not with the arbiter.

Regards,
Daniel

Quoted 4 lines

Thanks,

Lukas

#8 lore raw

PATCH 3/3 powerpc: replace vga_fixup() with generic code

In reply to Daniel Axtens
Quoted 14 lines · Daniel Axtens

Currently, we do a PCI fixup to mark a default card so that Xorg autoconfiguration works.

There is a new generic method to do this sort of vga fixup, and it occurs by default.

Drop our old method.

This method is different:
- it will only mark a card as default if a driver is bound
- the marking will happen at late_initcall time, or even later if a card is enabled later on (via an ENABLE hook). Currently things are enabled in a FINAL hook.

Quoted 4 lines

This *does* change behaviour under some circumstances.

For example, pseries_le_defconfig doesn't have DRM drivers for many of the qemu GPU models, including the 'standard' vga.

Should we enable them/it?

cheers

#9 lore raw

PATCH 3/3 powerpc: replace vga_fixup() with generic code

Quoted 16 lines · Michael Ellerman
Quoted 14 lines · Daniel Axtens

Currently, we do a PCI fixup to mark a default card so that Xorg autoconfiguration works.

There is a new generic method to do this sort of vga fixup, and it occurs by default.

Drop our old method.

This method is different:
- it will only mark a card as default if a driver is bound
- the marking will happen at late_initcall time, or even later if a card is enabled later on (via an ENABLE hook). Currently things are enabled in a FINAL hook.

Quoted 6 lines
Quoted 4 lines

This *does* change behaviour under some circumstances.

For example, pseries_le_defconfig doesn't have DRM drivers for many of the qemu GPU models, including the 'standard' vga.

Should we enable them/it?

Hard to say.

The 'standard' vga module (bochs_drm) was blacklisted by Ubuntu - apparently at IBM's request [0] - some years back. Even if you un-blacklist it, I had trouble with getting it and the openfirmware framebuffer driver to play nicely together. It may not be worth the trouble for bochs_drm.

There's a better case for including some of the more modern drivers - maybe QXL and virtio - but I wasn't able to test them: my particular build of qemu/TCG refused to start with them and I didn't feel like rebuilding/debugging qemu.

It would also be legitmate to say that you're focussing on headless use with pseries_*defconfig and not include them: you need to bring in the DRM core if you want these drivers.

HTH.

Regards,
Daniel

[0] https://bugs.launchpad.net/ubuntu/+source/kmod/+bug/1378648

Quoted 2 lines

cheers

#10 lore raw

PATCH 3/3 powerpc: replace vga_fixup() with generic code

Quoted 33 lines · Daniel Axtens
Quoted 16 lines · Michael Ellerman
Quoted 14 lines · Daniel Axtens

Currently, we do a PCI fixup to mark a default card so that Xorg autoconfiguration works.

There is a new generic method to do this sort of vga fixup, and it occurs by default.

Drop our old method.

This method is different:
- it will only mark a card as default if a driver is bound
- the marking will happen at late_initcall time, or even later if a card is enabled later on (via an ENABLE hook). Currently things are enabled in a FINAL hook.

Quoted 6 lines
Quoted 4 lines

This *does* change behaviour under some circumstances.

For example, pseries_le_defconfig doesn't have DRM drivers for many of the qemu GPU models, including the 'standard' vga.

Should we enable them/it?

Hard to say.

The 'standard' vga module (bochs_drm) was blacklisted by Ubuntu - apparently at IBM's request [0] - some years back. Even if you un-blacklist it, I had trouble with getting it and the openfirmware framebuffer driver to play nicely together. It may not be worth the trouble for bochs_drm.

Quoted 4 lines

There's a better case for including some of the more modern drivers - maybe QXL and virtio - but I wasn't able to test them: my particular build of qemu/TCG refused to start with them and I didn't feel like rebuilding/debugging qemu.

Yeah OK. Sounds like a bit of mess :)

I'll leave it unless someone who knows Qemu/Gfx etc. tells me otherwise.

Quoted 3 lines

It would also be legitmate to say that you're focussing on headless use with pseries_*defconfig and not include them: you need to bring in the DRM core if you want these drivers.

True. There's a bit of a tension there between making them useful configs for developers and also turning on as much code as possible so it gets tested.

Arguably we should have DRM enabled because the distros will.

cheers

#2 lore raw

PATCH 1/3 powerpc: simplify and fix VGA default device behaviour

In reply to Daniel Axtens
Quoted 24 lines · Daniel Axtens

Some powerpc devices provide a PCI display that isn't picked up by the VGA arbiter, presumably because it doesn't support the PCI legacy VGA ranges.

Commit c2e1d84523ad ("powerpc: Set default VGA device") introduced an arch quirk to mark these devices as default to fix X autoconfig.

The commit message stated that the patch:

Ensures a default VGA is always set if a graphics adapter is present, even if firmware did not initialize it. If more than one graphics adapter is present, ensure the one initialized by firmware is set as the default VGA device.

The patch used the following test to decide whether or not to mark a device as default:

  pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  if ((cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) || !vga_default_device())
          vga_set_default_device(pdev);

This doesn't seem like it works quite as intended. Because of the logical OR, the default device will be set in 2 cases:

Quoted 7 lines

1) if there is no default device
OR
2) if this device has normal memory/IO decoding turned on

This will work as intended if there is only one device, but if there are multiple devices, we may override the device the VGA arbiter picked.

This quirk only runs on VGA class devices. If there's more than one VGA device in the system, and we assume that firmware only enables PCI_COMMAND_IO or PCI_COMMAND_MEMORY on "the one initialized by firmware", which seems reasonable to me, I think the existing code does match the commit message.

We set the first VGA device we find to be the default. Then, if we find another VGA device that's enabled, we make *it* the default instead.

Quoted 4 lines

Instead, set a device as default if there is no default device AND this device decodes.

This will not change behaviour on single-headed systems.

If there is no enabled VGA device on the system, your new code means there will be no default VGA device.

It's not clear from this changelog what problem this patch solves. Maybe it's the "some displays not being picked up by the VGA arbiter" you mentioned, but there's not enough detail to connect it with the patch, especially since the patch means we'll set the default device in fewer cases than we did before.

With the patch, we only set the default if we find an enabled VGA device. Previously we also set the default if we found a VGA device that had not been enabled.

Quoted 34 lines

---

Tested in TCG (the card provided by qemu doesn't automatically register with vgaarb, so the relevant code path has been tested) but I would appreciate any tests on real hardware.

Informal benh ack: https://patchwork.kernel.org/patch/9850235/

---
 arch/powerpc/kernel/pci-common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kernel/pci-common.c +4 -1
index 341a7469cab8..c95fdda3a2dc 100644
@@ -1746,8 +1746,11 @@ static void fixup_vga(struct pci_dev *pdev)
 {
 	u16 cmd;
 
+	if (vga_default_device())
+		return;
+
 	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
-	if ((cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) || !vga_default_device())
+	if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
 		vga_set_default_device(pdev);
 
 }
Signature · 1 line
2.11.0
#3 lore raw

PATCH 1/3 powerpc: simplify and fix VGA default device behaviour

Hi Bjorn,

Thanks for reading the patch and providing some feedback.

Quoted 14 lines
Quoted 3 lines

This will work as intended if there is only one device, but if there are multiple devices, we may override the device the VGA arbiter picked.

This quirk only runs on VGA class devices. If there's more than one VGA device in the system, and we assume that firmware only enables PCI_COMMAND_IO or PCI_COMMAND_MEMORY on "the one initialized by firmware", which seems reasonable to me, I think the existing code does match the commit message.

We set the first VGA device we find to be the default. Then, if we find another VGA device that's enabled, we make *it* the default instead.

Quoted 7 lines
Quoted 4 lines

Instead, set a device as default if there is no default device AND this device decodes.

This will not change behaviour on single-headed systems.

If there is no enabled VGA device on the system, your new code means there will be no default VGA device.

Ah. Right you are.

Quoted 10 lines

It's not clear from this changelog what problem this patch solves. Maybe it's the "some displays not being picked up by the VGA arbiter" you mentioned, but there's not enough detail to connect it with the patch, especially since the patch means we'll set the default device in fewer cases than we did before.

With the patch, we only set the default if we find an enabled VGA device. Previously we also set the default if we found a VGA device that had not been enabled.

My overall problem is not having default devices on some machines. Initially, to solve this, I wanted to make this code generic. To do that I wanted to make sure it played nice with the vga arbiter, so not overriding default devices willy-nilly was a requirement. Evidently, I was overly keen and restricted its behaviour too much.

Regardless, in this current approach I don't make this powerpc code generic after all, so this patch is unnecessary. I will remove it for v2, which I will post after further testing.

I document the effects of the new approach for powerpc in more detail in patch 3 of this series. If powerpc wants to keep the existing approach we can arrange for that too; it's a simple matter of ifdefs.

Regards,
Daniel

Quoted 35 lines
Quoted 35 lines

---

Tested in TCG (the card provided by qemu doesn't automatically register with vgaarb, so the relevant code path has been tested) but I would appreciate any tests on real hardware.

Informal benh ack: https://patchwork.kernel.org/patch/9850235/

---
 arch/powerpc/kernel/pci-common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kernel/pci-common.c +4 -1
index 341a7469cab8..c95fdda3a2dc 100644
@@ -1746,8 +1746,11 @@ static void fixup_vga(struct pci_dev *pdev)
 {
 	u16 cmd;
 
+	if (vga_default_device())
+		return;
+
 	pci_read_config_word(pdev, PCI_COMMAND, &cmd);
-	if ((cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) || !vga_default_device())
+	if (cmd & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
 		vga_set_default_device(pdev);
 
 }
Signature · 1 line
2.11.0