Skip to content

Commit 4eebd5a

Browse files
Bruno Prémontdvhart
authored andcommitted
apple-gmux: lock iGP IO to protect from vgaarb changes
As GMUX depends on IO for iGP to be enabled and active, lock the IO at vgaarb level. This should prevent GPU driver for dGPU to disable IO for iGP while it tries to own legacy VGA IO. This fixes usage of backlight control combined with closed nvidia driver on some Apple dual-GPU (intel/nvidia) systems. On those systems loading nvidia driver disables intel IO decoding, disabling the gmux backlight controls as a side effect. Prior to commits moving boot_vga from (optional) efifb to less optional vgaarb this mis-behavior could be avoided by using right kernel config (efifb enabled but vgaarb disabled). This patch explicitly does not try to trigger vgaarb changes in order to avoid confusing already running graphics drivers. If IO has been mis-configured by vgaarb gmux will thus fail to probe. It is expected to load/probe gmux prior to graphics drivers. Fixes: ce027da # nvidia interaction Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=86121 Reported-by: Petri Hodju <petrihodju@yahoo.com> Tested-by: Petri Hodju <petrihodju@yahoo.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Matthew Garrett <matthew.garrett@nebula.com> Signed-off-by: Bruno Prémont <bonbons@linux-vserver.org> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
1 parent 0a63ca1 commit 4eebd5a

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

‎drivers/platform/x86/apple-gmux.c‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/delay.h>
2323
#include <linux/pci.h>
2424
#include <linux/vga_switcheroo.h>
25+
#include <linux/vgaarb.h>
2526
#include <acpi/video.h>
2627
#include <asm/io.h>
2728

@@ -31,6 +32,7 @@ struct apple_gmux_data {
3132
bool indexed;
3233
struct mutex index_lock;
3334

35+
struct pci_dev *pdev;
3436
struct backlight_device *bdev;
3537

3638
/* switcheroo data */
@@ -415,6 +417,23 @@ static int gmux_resume(struct device *dev)
415417
return 0;
416418
}
417419

420+
static struct pci_dev *gmux_get_io_pdev(void)
421+
{
422+
struct pci_dev *pdev = NULL;
423+
424+
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev))) {
425+
u16 cmd;
426+
427+
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
428+
if (!(cmd & PCI_COMMAND_IO))
429+
continue;
430+
431+
return pdev;
432+
}
433+
434+
return NULL;
435+
}
436+
418437
static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
419438
{
420439
struct apple_gmux_data *gmux_data;
@@ -425,6 +444,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
425444
int ret = -ENXIO;
426445
acpi_status status;
427446
unsigned long long gpe;
447+
struct pci_dev *pdev = NULL;
428448

429449
if (apple_gmux_data)
430450
return -EBUSY;
@@ -475,14 +495,31 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
475495
ver_minor = (version >> 16) & 0xff;
476496
ver_release = (version >> 8) & 0xff;
477497
} else {
478-
pr_info("gmux device not present\n");
498+
pr_info("gmux device not present or IO disabled\n");
479499
ret = -ENODEV;
480500
goto err_release;
481501
}
482502
}
483503
pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor,
484504
ver_release, (gmux_data->indexed ? "indexed" : "classic"));
485505

506+
/*
507+
* Apple systems with gmux are EFI based and normally don't use
508+
* VGA. In addition changing IO+MEM ownership between IGP and dGPU
509+
* disables IO/MEM used for backlight control on some systems.
510+
* Lock IO+MEM to GPU with active IO to prevent switch.
511+
*/
512+
pdev = gmux_get_io_pdev();
513+
if (pdev && vga_tryget(pdev,
514+
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM)) {
515+
pr_err("IO+MEM vgaarb-locking for PCI:%s failed\n",
516+
pci_name(pdev));
517+
ret = -EBUSY;
518+
goto err_release;
519+
} else if (pdev)
520+
pr_info("locked IO for PCI:%s\n", pci_name(pdev));
521+
gmux_data->pdev = pdev;
522+
486523
memset(&props, 0, sizeof(props));
487524
props.type = BACKLIGHT_PLATFORM;
488525
props.max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS);
@@ -574,6 +611,10 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
574611
err_notify:
575612
backlight_device_unregister(bdev);
576613
err_release:
614+
if (gmux_data->pdev)
615+
vga_put(gmux_data->pdev,
616+
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM);
617+
pci_dev_put(pdev);
577618
release_region(gmux_data->iostart, gmux_data->iolen);
578619
err_free:
579620
kfree(gmux_data);
@@ -593,6 +634,11 @@ static void gmux_remove(struct pnp_dev *pnp)
593634
&gmux_notify_handler);
594635
}
595636

637+
if (gmux_data->pdev) {
638+
vga_put(gmux_data->pdev,
639+
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM);
640+
pci_dev_put(gmux_data->pdev);
641+
}
596642
backlight_device_unregister(gmux_data->bdev);
597643

598644
release_region(gmux_data->iostart, gmux_data->iolen);

0 commit comments

Comments
 (0)