From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Demharter Subject: [PATCH] Restore mux and power states after resume from hibernation Date: Mon, 28 Oct 2013 10:02:38 +0100 Message-ID: <526E282E.5030309@gmx.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070808020605000202030702" Return-path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DFBBE70F2 for ; Mon, 28 Oct 2013 02:02:45 -0700 (PDT) Received: from [10.21.40.126] ([212.227.66.36]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0M4WuC-1VtdgF0way-00yfjt for ; Mon, 28 Oct 2013 10:02:43 +0100 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org This is a multi-part message in MIME format. --------------070808020605000202030702 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi all, i've got a system with a muxed intel+ati card and had a problem with hibernation: Vgaswitcheroo didn't restore the states of the graphics cards and the state of the mux after resume. I have solved the issue with the attached patch. Can you please review it? Regards Stefan --------------070808020605000202030702 Content-Type: text/x-patch; name="switcheroo_hibernation.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="switcheroo_hibernation.patch" commit cd8f863a804d9388b09771640110577dddafc695 Author: Stefan Demharter Date: Thu Oct 24 00:06:09 2013 +0200 vgaswitcheroo: restore mux and power states after resume from hibernation. diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c index ec0ae2d..4731f02 100644 --- a/drivers/gpu/vga/vga_switcheroo.c +++ b/drivers/gpu/vga/vga_switcheroo.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -72,6 +73,46 @@ static struct vgasr_priv vgasr_priv = { .clients = LIST_HEAD_INIT(vgasr_priv.clients), }; +/* save state of mux to restore it upon hibernation resume */ +// Assume initial state after boot: mux is set to IGD +#define MUX_POWER_ON_STATE VGA_SWITCHEROO_IGD +static int mux_id = MUX_POWER_ON_STATE; + +static int vga_switchoff(struct vga_switcheroo_client *client); + +static int vga_resume(struct notifier_block *nb, + unsigned long val, void *ign) +{ + int ret = 0; + struct vga_switcheroo_client *client; + pr_info("vga_switcheroo: vga_resume %d %d %d\n", (int)val, PM_POST_HIBERNATION, mux_id); + if (val != PM_POST_HIBERNATION) return 0; + if (mux_id != VGA_SWITCHEROO_IGD) { + mutex_lock(&vgasr_mutex); + pr_info("vga_switcheroo: restoring switch to %d after hibernate\n", mux_id); + // Restore mux state + if (mux_id != MUX_POWER_ON_STATE) + ret = vgasr_priv.handler->switchto(mux_id); + // Restore power state + // Assumes all gpus have power after boot + list_for_each_entry(client, &vgasr_priv.clients, list) { + if (!client->pwr_state) { + // Device was powered off, so we redo that... + pr_info("vga_switcheroo: restoring power off of device %d after hibernate\n", client->id); + vga_switchoff(client); + } + } + mutex_unlock(&vgasr_mutex); + if (ret) pr_warn("vga_switcheroo: failed\n"); + } + return 0; +} + +static struct notifier_block vga_pm_nb = { + .notifier_call = vga_resume, + .priority = 0, +}; + static bool vga_switcheroo_ready(void) { /* we're ready if we get two clients + handler */ @@ -83,6 +124,7 @@ static void vga_switcheroo_enable(void) { int ret; struct vga_switcheroo_client *client; + register_pm_notifier(&vga_pm_nb); /* call the handler to init */ if (vgasr_priv.handler->init) @@ -119,14 +161,21 @@ int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) } EXPORT_SYMBOL(vga_switcheroo_register_handler); +// vgasr_mutex has to be locked from caller +void vga_switcheroo_disable(void) +{ + unregister_pm_notifier(&vga_pm_nb); + pr_info("vga_switcheroo: disabled\n"); + vga_switcheroo_debugfs_fini(&vgasr_priv); + vgasr_priv.active = false; +} + void vga_switcheroo_unregister_handler(void) { mutex_lock(&vgasr_mutex); vgasr_priv.handler = NULL; if (vgasr_priv.active) { - pr_info("vga_switcheroo: disabled\n"); - vga_switcheroo_debugfs_fini(&vgasr_priv); - vgasr_priv.active = false; + vga_switcheroo_disable(); } mutex_unlock(&vgasr_mutex); } @@ -235,9 +284,7 @@ void vga_switcheroo_unregister_client(struct pci_dev *pdev) kfree(client); } if (vgasr_priv.active && vgasr_priv.registered_clients < 2) { - printk(KERN_INFO "vga_switcheroo: disabled\n"); - vga_switcheroo_debugfs_fini(&vgasr_priv); - vgasr_priv.active = false; + vga_switcheroo_disable(); } mutex_unlock(&vgasr_mutex); } @@ -262,12 +309,13 @@ static int vga_switcheroo_show(struct seq_file *m, void *v) int i = 0; mutex_lock(&vgasr_mutex); list_for_each_entry(client, &vgasr_priv.clients, list) { - seq_printf(m, "%d:%s%s:%c:%s%s:%s\n", i, + seq_printf(m, "%d:%s%s:%c:%s%s:%s:%s\n", i, client_id(client) == VGA_SWITCHEROO_DIS ? "DIS" : "IGD", client_is_vga(client) ? "" : "-Audio", client->active ? '+' : ' ', client->driver_power_control ? "Dyn" : "", client->pwr_state ? "Pwr" : "Off", + client_id(client) == mux_id ? "mux" : "", pci_name(client->pdev)); i++; } @@ -304,6 +352,15 @@ static int vga_switchoff(struct vga_switcheroo_client *client) return 0; } +static int vga_switch_mux_to(int client_id) +{ + int ret = vgasr_priv.handler->switchto(client_id); + if (ret == 0) { + mux_id = client_id; + } + return ret; +} + static void set_audio_state(int id, int state) { struct vga_switcheroo_client *client; @@ -353,7 +410,7 @@ static int vga_switchto_stage2(struct vga_switcheroo_client *new_client) console_unlock(); } - ret = vgasr_priv.handler->switchto(new_client->id); + ret = vga_switch_mux_to(new_client->id); if (ret) return ret; @@ -468,7 +525,7 @@ vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf, vgasr_priv.delayed_switch_active = false; if (just_mux) { - ret = vgasr_priv.handler->switchto(client_id); + ret = vga_switch_mux_to(client_id); goto out; } --------------070808020605000202030702 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/dri-devel --------------070808020605000202030702--