From: Stefan Demharter <stefan.demharter@gmx.net>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH] Restore mux and power states after resume from hibernation
Date: Mon, 28 Oct 2013 10:02:38 +0100 [thread overview]
Message-ID: <526E282E.5030309@gmx.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 285 bytes --]
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
[-- Attachment #2: switcheroo_hibernation.patch --]
[-- Type: text/x-patch, Size: 4924 bytes --]
commit cd8f863a804d9388b09771640110577dddafc695
Author: Stefan Demharter <stefan.demharter@gmx.net>
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 <linux/console.h>
#include <linux/vga_switcheroo.h>
#include <linux/pm_runtime.h>
+#include <linux/suspend.h>
#include <linux/vgaarb.h>
@@ -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;
}
[-- Attachment #3: Type: text/plain, Size: 159 bytes --]
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next reply other threads:[~2013-10-28 9:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-28 9:02 Stefan Demharter [this message]
2014-01-23 11:46 ` [PATCH] Restore mux and power states after resume from hibernation Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=526E282E.5030309@gmx.net \
--to=stefan.demharter@gmx.net \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.