[PATCH 3/6] vga-switcheroo: notify clients of pending/completed switch events
Daniel Dadap
ddadap at nvidia.com
Mon Jul 27 20:51:09 UTC 2020
Add a new vga-switcheroo client callback to allow clients to register
for receiving notifications when a mux switch is pending, completed,
or failed. This allows individual client drivers to prepare for or
respond to mux switches to and from the registered client device.
Signed-off-by: Daniel Dadap <ddadap at nvidia.com>
---
drivers/gpu/vga/vga_switcheroo.c | 29 ++++++++++++++++++++++++++++-
include/linux/vga_switcheroo.h | 18 ++++++++++++++++++
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index a4fc78c4bf4f..6392dc92696b 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -756,14 +756,41 @@ static int vga_switchto_stage2(struct vga_switcheroo_client *new_client,
if (new_client->fb_info)
fbcon_remap_all(new_client->fb_info);
+ if (active->ops->notify)
+ active->ops->notify(active->pdev,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_AWAY,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_PENDING);
+ if (new_client->ops->notify)
+ new_client->ops->notify(new_client->pdev,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_TO,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_PENDING);
+
active->switched = false;
mutex_lock(&vgasr_priv.mux_hw_lock);
ret = vgasr_priv.handler->switchto(new_client->id);
mutex_unlock(&vgasr_priv.mux_hw_lock);
- if (ret)
+ if (ret) {
+ if (active->ops->notify)
+ active->ops->notify(active->pdev,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_AWAY,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_FAILED);
+ if (new_client->ops->notify)
+ new_client->ops->notify(new_client->pdev,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_TO,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_FAILED);
return ret;
+ }
new_client->switched = true;
+ if (active->ops->notify)
+ active->ops->notify(active->pdev,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_AWAY,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_COMPLETE);
+ if (new_client->ops->notify)
+ new_client->ops->notify(new_client->pdev,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_TO,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_COMPLETE);
+
if (new_client->ops->reprobe)
new_client->ops->reprobe(new_client->pdev);
diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
index 63e6d6e5786e..2dc8ebc84fd4 100644
--- a/include/linux/vga_switcheroo.h
+++ b/include/linux/vga_switcheroo.h
@@ -90,6 +90,17 @@ enum vga_switcheroo_client_id {
VGA_SWITCHEROO_MAX_CLIENTS,
};
+enum vga_switcheroo_notify_direction {
+ VGA_SWITCHEROO_NOTIFY_SWITCH_TO,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_AWAY,
+};
+
+enum vga_switcheroo_notify_action {
+ VGA_SWITCHEROO_NOTIFY_SWITCH_PENDING,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_COMPLETE,
+ VGA_SWITCHEROO_NOTIFY_SWITCH_FAILED,
+};
+
/**
* struct vga_switcheroo_handler - handler callbacks
* @init: initialize handler.
@@ -134,6 +145,10 @@ struct vga_switcheroo_handler {
* Mandatory. The client should return false if a user space process
* has one of its device files open
* @gpu_bound: notify the client id to audio client when the GPU is bound.
+ * @notify: notify clients of pending and completed switches
+ * Optional. This gets called for both active and inactive clients,
+ * before a switch begins, and after a switch successfully completes
+ * or fails.
*
* Client callbacks. A client can be either a GPU or an audio device on a GPU.
* The @set_gpu_state and @can_switch methods are mandatory, @reprobe may be
@@ -145,6 +160,9 @@ struct vga_switcheroo_client_ops {
void (*reprobe)(struct pci_dev *dev);
bool (*can_switch)(struct pci_dev *dev);
void (*gpu_bound)(struct pci_dev *dev, enum vga_switcheroo_client_id);
+ void (*notify)(struct pci_dev *dev,
+ enum vga_switcheroo_notify_direction,
+ enum vga_switcheroo_notify_action);
};
#if defined(CONFIG_VGA_SWITCHEROO)
--
2.18.4
More information about the dri-devel
mailing list