2010-02-01 05:38:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Red Hat Inc.
|
|
|
|
* Author : Dave Airlie <airlied@redhat.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under GPLv2
|
|
|
|
*
|
|
|
|
* vga_switcheroo.c - Support for laptop with dual GPU using one set of outputs
|
|
|
|
|
|
|
|
Switcher interface - methods require for ATPX and DCM
|
|
|
|
- switchto - this throws the output MUX switch
|
|
|
|
- discrete_set_power - sets the power state for the discrete card
|
|
|
|
|
|
|
|
GPU driver interface
|
|
|
|
- set_gpu_state - this should do the equiv of s/r for the card
|
|
|
|
- this should *not* set the discrete power state
|
|
|
|
- switch_check - check if the device is in a position to switch now
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/dmi.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/fb.h>
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/vga_switcheroo.h>
|
|
|
|
|
2012-04-16 20:26:03 +00:00
|
|
|
#include <linux/vgaarb.h>
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
struct vga_switcheroo_client {
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct fb_info *fb_info;
|
|
|
|
int pwr_state;
|
2012-05-11 05:51:17 +00:00
|
|
|
const struct vga_switcheroo_client_ops *ops;
|
2010-02-01 05:38:10 +00:00
|
|
|
int id;
|
|
|
|
bool active;
|
2012-04-26 10:55:59 +00:00
|
|
|
struct list_head list;
|
2010-02-01 05:38:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_MUTEX(vgasr_mutex);
|
|
|
|
|
|
|
|
struct vgasr_priv {
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
bool delayed_switch_active;
|
|
|
|
enum vga_switcheroo_client_id delayed_client_id;
|
|
|
|
|
|
|
|
struct dentry *debugfs_root;
|
|
|
|
struct dentry *switch_file;
|
|
|
|
|
|
|
|
int registered_clients;
|
2012-04-26 10:55:59 +00:00
|
|
|
struct list_head clients;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
struct vga_switcheroo_handler *handler;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
|
|
|
|
static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv);
|
|
|
|
|
|
|
|
/* only one switcheroo per system */
|
2012-04-26 10:55:59 +00:00
|
|
|
static struct vgasr_priv vgasr_priv = {
|
|
|
|
.clients = LIST_HEAD_INIT(vgasr_priv.clients),
|
|
|
|
};
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler)
|
|
|
|
{
|
|
|
|
mutex_lock(&vgasr_mutex);
|
|
|
|
if (vgasr_priv.handler) {
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vgasr_priv.handler = handler;
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vga_switcheroo_register_handler);
|
|
|
|
|
|
|
|
void vga_switcheroo_unregister_handler(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&vgasr_mutex);
|
|
|
|
vgasr_priv.handler = NULL;
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vga_switcheroo_unregister_handler);
|
|
|
|
|
|
|
|
static void vga_switcheroo_enable(void)
|
|
|
|
{
|
|
|
|
int ret;
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *client;
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
/* call the handler to init */
|
|
|
|
vgasr_priv.handler->init();
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
list_for_each_entry(client, &vgasr_priv.clients, list) {
|
|
|
|
ret = vgasr_priv.handler->get_client_id(client->pdev);
|
2010-02-01 05:38:10 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
client->id = ret;
|
2010-02-01 05:38:10 +00:00
|
|
|
}
|
|
|
|
vga_switcheroo_debugfs_init(&vgasr_priv);
|
|
|
|
vgasr_priv.active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vga_switcheroo_register_client(struct pci_dev *pdev,
|
2012-05-11 05:51:17 +00:00
|
|
|
const struct vga_switcheroo_client_ops *ops)
|
2010-02-01 05:38:10 +00:00
|
|
|
{
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *client;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
client = kzalloc(sizeof(*client), GFP_KERNEL);
|
|
|
|
if (!client)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
client->pwr_state = VGA_SWITCHEROO_ON;
|
|
|
|
client->pdev = pdev;
|
2012-05-11 05:51:17 +00:00
|
|
|
client->ops = ops;
|
2012-04-26 10:55:59 +00:00
|
|
|
client->id = -1;
|
2012-04-16 20:26:03 +00:00
|
|
|
if (pdev == vga_default_device())
|
2012-04-26 10:55:59 +00:00
|
|
|
client->active = true;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
mutex_lock(&vgasr_mutex);
|
|
|
|
list_add_tail(&client->list, &vgasr_priv.clients);
|
|
|
|
vgasr_priv.registered_clients++;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
/* if we get two clients + handler */
|
2012-04-26 10:55:59 +00:00
|
|
|
if (vgasr_priv.registered_clients == 2 && vgasr_priv.handler) {
|
2010-02-01 05:38:10 +00:00
|
|
|
printk(KERN_INFO "vga_switcheroo: enabled\n");
|
|
|
|
vga_switcheroo_enable();
|
|
|
|
}
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vga_switcheroo_register_client);
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
static struct vga_switcheroo_client *
|
|
|
|
find_client_from_pci(struct list_head *head, struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct vga_switcheroo_client *client;
|
|
|
|
list_for_each_entry(client, head, list)
|
|
|
|
if (client->pdev == pdev)
|
|
|
|
return client;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vga_switcheroo_client *
|
|
|
|
find_client_from_id(struct list_head *head, int client_id)
|
|
|
|
{
|
|
|
|
struct vga_switcheroo_client *client;
|
|
|
|
list_for_each_entry(client, head, list)
|
|
|
|
if (client->id == client_id)
|
|
|
|
return client;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vga_switcheroo_client *
|
|
|
|
find_active_client(struct list_head *head)
|
|
|
|
{
|
|
|
|
struct vga_switcheroo_client *client;
|
|
|
|
list_for_each_entry(client, head, list)
|
|
|
|
if (client->active == true)
|
|
|
|
return client;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
void vga_switcheroo_unregister_client(struct pci_dev *pdev)
|
|
|
|
{
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *client;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
mutex_lock(&vgasr_mutex);
|
2012-04-26 10:55:59 +00:00
|
|
|
client = find_client_from_pci(&vgasr_priv.clients, pdev);
|
|
|
|
if (client) {
|
|
|
|
list_del(&client->list);
|
|
|
|
kfree(client);
|
|
|
|
vgasr_priv.registered_clients--;
|
2010-02-01 05:38:10 +00:00
|
|
|
}
|
|
|
|
printk(KERN_INFO "vga_switcheroo: disabled\n");
|
|
|
|
vga_switcheroo_debugfs_fini(&vgasr_priv);
|
|
|
|
vgasr_priv.active = false;
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vga_switcheroo_unregister_client);
|
|
|
|
|
|
|
|
void vga_switcheroo_client_fb_set(struct pci_dev *pdev,
|
|
|
|
struct fb_info *info)
|
|
|
|
{
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *client;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
mutex_lock(&vgasr_mutex);
|
2012-04-26 10:55:59 +00:00
|
|
|
client = find_client_from_pci(&vgasr_priv.clients, pdev);
|
|
|
|
if (client)
|
|
|
|
client->fb_info = info;
|
2010-02-01 05:38:10 +00:00
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vga_switcheroo_client_fb_set);
|
|
|
|
|
|
|
|
static int vga_switcheroo_show(struct seq_file *m, void *v)
|
|
|
|
{
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *client;
|
|
|
|
int i = 0;
|
2010-02-01 05:38:10 +00:00
|
|
|
mutex_lock(&vgasr_mutex);
|
2012-04-26 10:55:59 +00:00
|
|
|
list_for_each_entry(client, &vgasr_priv.clients, list) {
|
2010-12-06 02:30:31 +00:00
|
|
|
seq_printf(m, "%d:%s:%c:%s:%s\n", i,
|
2012-04-26 10:55:59 +00:00
|
|
|
client->id == VGA_SWITCHEROO_DIS ? "DIS" : "IGD",
|
|
|
|
client->active ? '+' : ' ',
|
|
|
|
client->pwr_state ? "Pwr" : "Off",
|
|
|
|
pci_name(client->pdev));
|
|
|
|
i++;
|
2010-02-01 05:38:10 +00:00
|
|
|
}
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vga_switcheroo_debugfs_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, vga_switcheroo_show, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vga_switchon(struct vga_switcheroo_client *client)
|
|
|
|
{
|
2010-12-06 02:31:50 +00:00
|
|
|
if (vgasr_priv.handler->power_state)
|
|
|
|
vgasr_priv.handler->power_state(client->id, VGA_SWITCHEROO_ON);
|
2010-02-01 05:38:10 +00:00
|
|
|
/* call the driver callback to turn on device */
|
2012-05-11 05:51:17 +00:00
|
|
|
client->ops->set_gpu_state(client->pdev, VGA_SWITCHEROO_ON);
|
2010-02-01 05:38:10 +00:00
|
|
|
client->pwr_state = VGA_SWITCHEROO_ON;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vga_switchoff(struct vga_switcheroo_client *client)
|
|
|
|
{
|
|
|
|
/* call the driver callback to turn off device */
|
2012-05-11 05:51:17 +00:00
|
|
|
client->ops->set_gpu_state(client->pdev, VGA_SWITCHEROO_OFF);
|
2010-12-06 02:31:50 +00:00
|
|
|
if (vgasr_priv.handler->power_state)
|
|
|
|
vgasr_priv.handler->power_state(client->id, VGA_SWITCHEROO_OFF);
|
2010-02-01 05:38:10 +00:00
|
|
|
client->pwr_state = VGA_SWITCHEROO_OFF;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-07 04:24:25 +00:00
|
|
|
/* stage one happens before delay */
|
|
|
|
static int vga_switchto_stage1(struct vga_switcheroo_client *new_client)
|
2010-02-01 05:38:10 +00:00
|
|
|
{
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *active;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
active = find_active_client(&vgasr_priv.clients);
|
2010-02-01 05:38:10 +00:00
|
|
|
if (!active)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (new_client->pwr_state == VGA_SWITCHEROO_OFF)
|
|
|
|
vga_switchon(new_client);
|
|
|
|
|
2012-04-16 20:26:03 +00:00
|
|
|
vga_set_default_device(new_client->pdev);
|
|
|
|
|
2010-12-07 04:24:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* post delay */
|
|
|
|
static int vga_switchto_stage2(struct vga_switcheroo_client *new_client)
|
|
|
|
{
|
|
|
|
int ret;
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *active;
|
2010-12-07 04:24:25 +00:00
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
active = find_active_client(&vgasr_priv.clients);
|
2010-12-07 04:24:25 +00:00
|
|
|
if (!active)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
active->active = false;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
if (new_client->fb_info) {
|
|
|
|
struct fb_event event;
|
|
|
|
event.info = new_client->fb_info;
|
|
|
|
fb_notifier_call_chain(FB_EVENT_REMAP_ALL_CONSOLE, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = vgasr_priv.handler->switchto(new_client->id);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2012-05-11 05:51:17 +00:00
|
|
|
if (new_client->ops->reprobe)
|
|
|
|
new_client->ops->reprobe(new_client->pdev);
|
2010-12-06 22:57:57 +00:00
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
if (active->pwr_state == VGA_SWITCHEROO_ON)
|
|
|
|
vga_switchoff(active);
|
|
|
|
|
|
|
|
new_client->active = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
static bool check_can_switch(void)
|
|
|
|
{
|
|
|
|
struct vga_switcheroo_client *client;
|
|
|
|
|
|
|
|
list_for_each_entry(client, &vgasr_priv.clients, list) {
|
2012-05-11 05:51:17 +00:00
|
|
|
if (!client->ops->can_switch(client->pdev)) {
|
2012-04-26 10:55:59 +00:00
|
|
|
printk(KERN_ERR "vga_switcheroo: client %x refused switch\n", client->id);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
static ssize_t
|
|
|
|
vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
|
|
|
|
size_t cnt, loff_t *ppos)
|
|
|
|
{
|
|
|
|
char usercmd[64];
|
|
|
|
const char *pdev_name;
|
2012-04-26 10:55:59 +00:00
|
|
|
int ret;
|
2010-02-01 05:38:10 +00:00
|
|
|
bool delay = false, can_switch;
|
2010-12-06 02:35:52 +00:00
|
|
|
bool just_mux = false;
|
2010-02-01 05:38:10 +00:00
|
|
|
int client_id = -1;
|
|
|
|
struct vga_switcheroo_client *client = NULL;
|
|
|
|
|
|
|
|
if (cnt > 63)
|
|
|
|
cnt = 63;
|
|
|
|
|
|
|
|
if (copy_from_user(usercmd, ubuf, cnt))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
mutex_lock(&vgasr_mutex);
|
|
|
|
|
2010-04-27 21:11:03 +00:00
|
|
|
if (!vgasr_priv.active) {
|
|
|
|
cnt = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
/* pwr off the device not in use */
|
|
|
|
if (strncmp(usercmd, "OFF", 3) == 0) {
|
2012-04-26 10:55:59 +00:00
|
|
|
list_for_each_entry(client, &vgasr_priv.clients, list) {
|
|
|
|
if (client->active)
|
2010-02-01 05:38:10 +00:00
|
|
|
continue;
|
2012-04-26 10:55:59 +00:00
|
|
|
if (client->pwr_state == VGA_SWITCHEROO_ON)
|
|
|
|
vga_switchoff(client);
|
2010-02-01 05:38:10 +00:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* pwr on the device not in use */
|
|
|
|
if (strncmp(usercmd, "ON", 2) == 0) {
|
2012-04-26 10:55:59 +00:00
|
|
|
list_for_each_entry(client, &vgasr_priv.clients, list) {
|
|
|
|
if (client->active)
|
2010-02-01 05:38:10 +00:00
|
|
|
continue;
|
2012-04-26 10:55:59 +00:00
|
|
|
if (client->pwr_state == VGA_SWITCHEROO_OFF)
|
|
|
|
vga_switchon(client);
|
2010-02-01 05:38:10 +00:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* request a delayed switch - test can we switch now */
|
|
|
|
if (strncmp(usercmd, "DIGD", 4) == 0) {
|
|
|
|
client_id = VGA_SWITCHEROO_IGD;
|
|
|
|
delay = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(usercmd, "DDIS", 4) == 0) {
|
|
|
|
client_id = VGA_SWITCHEROO_DIS;
|
|
|
|
delay = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp(usercmd, "IGD", 3) == 0)
|
|
|
|
client_id = VGA_SWITCHEROO_IGD;
|
|
|
|
|
|
|
|
if (strncmp(usercmd, "DIS", 3) == 0)
|
|
|
|
client_id = VGA_SWITCHEROO_DIS;
|
|
|
|
|
2011-01-07 05:12:27 +00:00
|
|
|
if (strncmp(usercmd, "MIGD", 4) == 0) {
|
2010-12-06 02:35:52 +00:00
|
|
|
just_mux = true;
|
|
|
|
client_id = VGA_SWITCHEROO_IGD;
|
|
|
|
}
|
2011-01-07 05:12:27 +00:00
|
|
|
if (strncmp(usercmd, "MDIS", 4) == 0) {
|
2010-12-06 02:35:52 +00:00
|
|
|
just_mux = true;
|
|
|
|
client_id = VGA_SWITCHEROO_DIS;
|
|
|
|
}
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
if (client_id == -1)
|
|
|
|
goto out;
|
2012-04-26 10:55:59 +00:00
|
|
|
client = find_client_from_id(&vgasr_priv.clients, client_id);
|
|
|
|
if (!client)
|
|
|
|
goto out;
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
vgasr_priv.delayed_switch_active = false;
|
2010-12-06 02:35:52 +00:00
|
|
|
|
|
|
|
if (just_mux) {
|
|
|
|
ret = vgasr_priv.handler->switchto(client_id);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
if (client->active)
|
2011-05-15 14:32:50 +00:00
|
|
|
goto out;
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
/* okay we want a switch - test if devices are willing to switch */
|
2012-04-26 10:55:59 +00:00
|
|
|
can_switch = check_can_switch();
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
if (can_switch == false && delay == false)
|
|
|
|
goto out;
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
if (can_switch) {
|
2010-02-01 05:38:10 +00:00
|
|
|
pdev_name = pci_name(client->pdev);
|
2010-12-07 04:24:25 +00:00
|
|
|
ret = vga_switchto_stage1(client);
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "vga_switcheroo: switching failed stage 1 %d\n", ret);
|
|
|
|
|
|
|
|
ret = vga_switchto_stage2(client);
|
2010-02-01 05:38:10 +00:00
|
|
|
if (ret)
|
2010-12-07 04:24:25 +00:00
|
|
|
printk(KERN_ERR "vga_switcheroo: switching failed stage 2 %d\n", ret);
|
|
|
|
|
2010-02-01 05:38:10 +00:00
|
|
|
} else {
|
|
|
|
printk(KERN_INFO "vga_switcheroo: setting delayed switch to client %d\n", client->id);
|
|
|
|
vgasr_priv.delayed_switch_active = true;
|
|
|
|
vgasr_priv.delayed_client_id = client_id;
|
|
|
|
|
2010-12-07 04:24:25 +00:00
|
|
|
ret = vga_switchto_stage1(client);
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "vga_switcheroo: delayed switching stage 1 failed %d\n", ret);
|
2010-02-01 05:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations vga_switcheroo_debugfs_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = vga_switcheroo_debugfs_open,
|
|
|
|
.write = vga_switcheroo_debugfs_write,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vga_switcheroo_debugfs_fini(struct vgasr_priv *priv)
|
|
|
|
{
|
|
|
|
if (priv->switch_file) {
|
|
|
|
debugfs_remove(priv->switch_file);
|
|
|
|
priv->switch_file = NULL;
|
|
|
|
}
|
|
|
|
if (priv->debugfs_root) {
|
|
|
|
debugfs_remove(priv->debugfs_root);
|
|
|
|
priv->debugfs_root = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv)
|
|
|
|
{
|
|
|
|
/* already initialised */
|
|
|
|
if (priv->debugfs_root)
|
|
|
|
return 0;
|
|
|
|
priv->debugfs_root = debugfs_create_dir("vgaswitcheroo", NULL);
|
|
|
|
|
|
|
|
if (!priv->debugfs_root) {
|
|
|
|
printk(KERN_ERR "vga_switcheroo: Cannot create /sys/kernel/debug/vgaswitcheroo\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->switch_file = debugfs_create_file("switch", 0644,
|
|
|
|
priv->debugfs_root, NULL, &vga_switcheroo_debugfs_fops);
|
|
|
|
if (!priv->switch_file) {
|
|
|
|
printk(KERN_ERR "vga_switcheroo: cannot create /sys/kernel/debug/vgaswitcheroo/switch\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
vga_switcheroo_debugfs_fini(priv);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vga_switcheroo_process_delayed_switch(void)
|
|
|
|
{
|
2012-04-26 10:55:59 +00:00
|
|
|
struct vga_switcheroo_client *client;
|
2010-02-01 05:38:10 +00:00
|
|
|
const char *pdev_name;
|
|
|
|
int ret;
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
|
|
|
mutex_lock(&vgasr_mutex);
|
|
|
|
if (!vgasr_priv.delayed_switch_active)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
printk(KERN_INFO "vga_switcheroo: processing delayed switch to %d\n", vgasr_priv.delayed_client_id);
|
|
|
|
|
2012-04-26 10:55:59 +00:00
|
|
|
client = find_client_from_id(&vgasr_priv.clients,
|
|
|
|
vgasr_priv.delayed_client_id);
|
|
|
|
if (!client || !check_can_switch())
|
2010-02-01 05:38:10 +00:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
pdev_name = pci_name(client->pdev);
|
2010-12-07 04:24:25 +00:00
|
|
|
ret = vga_switchto_stage2(client);
|
2010-02-01 05:38:10 +00:00
|
|
|
if (ret)
|
2010-12-07 04:24:25 +00:00
|
|
|
printk(KERN_ERR "vga_switcheroo: delayed switching failed stage 2 %d\n", ret);
|
2010-02-01 05:38:10 +00:00
|
|
|
|
|
|
|
vgasr_priv.delayed_switch_active = false;
|
|
|
|
err = 0;
|
|
|
|
err:
|
|
|
|
mutex_unlock(&vgasr_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(vga_switcheroo_process_delayed_switch);
|
|
|
|
|