Commit 1a39b310 authored by Matthew Garrett's avatar Matthew Garrett Committed by Dave Airlie

vgaarb: Add support for setting the default video device (v2)

The default VGA device is a somewhat fluid concept on platforms with
multiple GPUs. Add support for setting it so switching code can update
things appropriately, and make sure that the sysfs code returns the right
device if it's changed.

v2: Updated to fix builds when __ARCH_HAS_VGA_DEFAULT_DEVICE is false.
Signed-off-by: default avatarMatthew Garrett <mjg@redhat.com>
Acked-by: default avatarH. Peter Anvin <hpa@zytor.com>
Acked-by: benh@kernel.crashing.org
Cc: airlied@redhat.com
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent f122c610
...@@ -136,6 +136,11 @@ struct pci_dev *vga_default_device(void) ...@@ -136,6 +136,11 @@ struct pci_dev *vga_default_device(void)
{ {
return vga_default; return vga_default;
} }
void vga_set_default_device(struct pci_dev *pdev)
{
vga_default = pdev;
}
#endif #endif
static inline void vga_irq_set_state(struct vga_device *vgadev, bool state) static inline void vga_irq_set_state(struct vga_device *vgadev, bool state)
...@@ -605,10 +610,12 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev) ...@@ -605,10 +610,12 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev)
goto bail; goto bail;
} }
#ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
if (vga_default == pdev) { if (vga_default == pdev) {
pci_dev_put(vga_default); pci_dev_put(vga_default);
vga_default = NULL; vga_default = NULL;
} }
#endif
if (vgadev->decodes & (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)) if (vgadev->decodes & (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM))
vga_decode_count--; vga_decode_count--;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/security.h> #include <linux/security.h>
#include <linux/pci-aspm.h> #include <linux/pci-aspm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vgaarb.h>
#include "pci.h" #include "pci.h"
static int sysfs_initialized; /* = 0 */ static int sysfs_initialized; /* = 0 */
...@@ -417,6 +418,10 @@ static ssize_t ...@@ -417,6 +418,10 @@ static ssize_t
boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf) boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct pci_dev *vga_dev = vga_default_device();
if (vga_dev)
return sprintf(buf, "%u\n", (pdev == vga_dev));
return sprintf(buf, "%u\n", return sprintf(buf, "%u\n",
!!(pdev->resource[PCI_ROM_RESOURCE].flags & !!(pdev->resource[PCI_ROM_RESOURCE].flags &
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef LINUX_VGA_H #ifndef LINUX_VGA_H
#define LINUX_VGA_H #define LINUX_VGA_H
#include <video/vga.h>
/* Legacy VGA regions */ /* Legacy VGA regions */
#define VGA_RSRC_NONE 0x00 #define VGA_RSRC_NONE 0x00
...@@ -181,6 +182,7 @@ extern void vga_put(struct pci_dev *pdev, unsigned int rsrc); ...@@ -181,6 +182,7 @@ extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
#ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
extern struct pci_dev *vga_default_device(void); extern struct pci_dev *vga_default_device(void);
extern void vga_set_default_device(struct pci_dev *pdev);
#endif #endif
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment