提交 36704c0c 编写于 作者: S Seth Forshee 提交者: Matthew Garrett

vga_switcheroo: Remove assumptions about registration/unregistration ordering

vga_switcheroo assumes that the handler will be registered before the
last client, otherwise switching will not be enabled. Likewise it's
assumed that the handler will not be unregistered without at least one
client also being unregistered, otherwise switching will remain enabled
despite no longer having a handler. These assumptions cannot be enforced
if the handler is in a separate driver from both clients, as with the
gmux found in Apple laptops. Remove this assumption.
Signed-off-by: NSeth Forshee <seth.forshee@canonical.com>
Signed-off-by: NMatthew Garrett <mjg@redhat.com>
上级 76b487dd
...@@ -70,27 +70,12 @@ static struct vgasr_priv vgasr_priv = { ...@@ -70,27 +70,12 @@ static struct vgasr_priv vgasr_priv = {
.clients = LIST_HEAD_INIT(vgasr_priv.clients), .clients = LIST_HEAD_INIT(vgasr_priv.clients),
}; };
int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) static bool vga_switcheroo_ready(void)
{
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); /* we're ready if we get two clients + handler */
vgasr_priv.handler = NULL; return !vgasr_priv.active &&
mutex_unlock(&vgasr_mutex); vgasr_priv.registered_clients == 2 && vgasr_priv.handler;
} }
EXPORT_SYMBOL(vga_switcheroo_unregister_handler);
static void vga_switcheroo_enable(void) static void vga_switcheroo_enable(void)
{ {
...@@ -113,6 +98,37 @@ static void vga_switcheroo_enable(void) ...@@ -113,6 +98,37 @@ static void vga_switcheroo_enable(void)
vgasr_priv.active = true; vgasr_priv.active = true;
} }
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;
if (vga_switcheroo_ready()) {
printk(KERN_INFO "vga_switcheroo: enabled\n");
vga_switcheroo_enable();
}
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;
if (vgasr_priv.active) {
pr_info("vga_switcheroo: disabled\n");
vga_switcheroo_debugfs_fini(&vgasr_priv);
vgasr_priv.active = false;
}
mutex_unlock(&vgasr_mutex);
}
EXPORT_SYMBOL(vga_switcheroo_unregister_handler);
static int register_client(struct pci_dev *pdev, static int register_client(struct pci_dev *pdev,
const struct vga_switcheroo_client_ops *ops, const struct vga_switcheroo_client_ops *ops,
int id, bool active) int id, bool active)
...@@ -134,9 +150,7 @@ static int register_client(struct pci_dev *pdev, ...@@ -134,9 +150,7 @@ static int register_client(struct pci_dev *pdev,
if (client_is_vga(client)) if (client_is_vga(client))
vgasr_priv.registered_clients++; vgasr_priv.registered_clients++;
/* if we get two clients + handler */ if (vga_switcheroo_ready()) {
if (!vgasr_priv.active &&
vgasr_priv.registered_clients == 2 && vgasr_priv.handler) {
printk(KERN_INFO "vga_switcheroo: enabled\n"); printk(KERN_INFO "vga_switcheroo: enabled\n");
vga_switcheroo_enable(); vga_switcheroo_enable();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册