2010-02-01 13:38:10 +08:00
|
|
|
/*
|
2015-08-23 21:18:55 +08:00
|
|
|
* vga_switcheroo.h - Support for laptop with dual GPU using one set of outputs
|
|
|
|
*
|
2010-02-01 13:38:10 +08:00
|
|
|
* Copyright (c) 2010 Red Hat Inc.
|
|
|
|
* Author : Dave Airlie <airlied@redhat.com>
|
|
|
|
*
|
2015-08-23 21:18:55 +08:00
|
|
|
* Copyright (c) 2015 Lukas Wunner <lukas@wunner.de>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
2010-02-01 13:38:10 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-06-14 20:02:35 +08:00
|
|
|
#ifndef _LINUX_VGA_SWITCHEROO_H_
|
|
|
|
#define _LINUX_VGA_SWITCHEROO_H_
|
|
|
|
|
2010-02-01 13:38:10 +08:00
|
|
|
#include <linux/fb.h>
|
|
|
|
|
2012-06-16 03:46:17 +08:00
|
|
|
struct pci_dev;
|
|
|
|
|
2016-01-12 03:09:20 +08:00
|
|
|
/**
|
|
|
|
* enum vga_switcheroo_handler_flags_t - handler flags bitmask
|
|
|
|
* @VGA_SWITCHEROO_CAN_SWITCH_DDC: whether the handler is able to switch the
|
|
|
|
* DDC lines separately. This signals to clients that they should call
|
|
|
|
* drm_get_edid_switcheroo() to probe the EDID
|
|
|
|
* @VGA_SWITCHEROO_NEEDS_EDP_CONFIG: whether the handler is unable to switch
|
|
|
|
* the AUX channel separately. This signals to clients that the active
|
|
|
|
* GPU needs to train the link and communicate the link parameters to the
|
|
|
|
* inactive GPU (mediated by vga_switcheroo). The inactive GPU may then
|
|
|
|
* skip the AUX handshake and set up its output with these pre-calibrated
|
|
|
|
* values (DisplayPort specification v1.1a, section 2.5.3.3)
|
|
|
|
*
|
|
|
|
* Handler flags bitmask. Used by handlers to declare their capabilities upon
|
|
|
|
* registering with vga_switcheroo.
|
|
|
|
*/
|
|
|
|
enum vga_switcheroo_handler_flags_t {
|
|
|
|
VGA_SWITCHEROO_CAN_SWITCH_DDC = (1 << 0),
|
|
|
|
VGA_SWITCHEROO_NEEDS_EDP_CONFIG = (1 << 1),
|
|
|
|
};
|
|
|
|
|
2015-08-23 21:18:55 +08:00
|
|
|
/**
|
|
|
|
* enum vga_switcheroo_state - client power state
|
|
|
|
* @VGA_SWITCHEROO_OFF: off
|
|
|
|
* @VGA_SWITCHEROO_ON: on
|
|
|
|
* @VGA_SWITCHEROO_NOT_FOUND: client has not registered with vga_switcheroo.
|
|
|
|
* Only used in vga_switcheroo_get_client_state() which in turn is only
|
|
|
|
* called from hda_intel.c
|
|
|
|
*
|
|
|
|
* Client power state.
|
|
|
|
*/
|
2010-02-01 13:38:10 +08:00
|
|
|
enum vga_switcheroo_state {
|
|
|
|
VGA_SWITCHEROO_OFF,
|
|
|
|
VGA_SWITCHEROO_ON,
|
2012-06-07 18:15:15 +08:00
|
|
|
/* below are referred only from vga_switcheroo_get_client_state() */
|
|
|
|
VGA_SWITCHEROO_NOT_FOUND,
|
2010-02-01 13:38:10 +08:00
|
|
|
};
|
|
|
|
|
2015-08-23 21:18:55 +08:00
|
|
|
/**
|
|
|
|
* enum vga_switcheroo_client_id - client identifier
|
2015-08-28 19:30:32 +08:00
|
|
|
* @VGA_SWITCHEROO_UNKNOWN_ID: initial identifier assigned to vga clients.
|
|
|
|
* Determining the id requires the handler, so GPUs are given their
|
|
|
|
* true id in a delayed fashion in vga_switcheroo_enable()
|
2015-08-23 21:18:55 +08:00
|
|
|
* @VGA_SWITCHEROO_IGD: integrated graphics device
|
|
|
|
* @VGA_SWITCHEROO_DIS: discrete graphics device
|
|
|
|
* @VGA_SWITCHEROO_MAX_CLIENTS: currently no more than two GPUs are supported
|
|
|
|
*
|
|
|
|
* Client identifier. Audio clients use the same identifier & 0x100.
|
|
|
|
*/
|
2010-02-01 13:38:10 +08:00
|
|
|
enum vga_switcheroo_client_id {
|
2018-07-17 16:20:50 +08:00
|
|
|
VGA_SWITCHEROO_UNKNOWN_ID = 0x1000,
|
|
|
|
VGA_SWITCHEROO_IGD = 0,
|
2010-02-01 13:38:10 +08:00
|
|
|
VGA_SWITCHEROO_DIS,
|
|
|
|
VGA_SWITCHEROO_MAX_CLIENTS,
|
|
|
|
};
|
|
|
|
|
2015-08-23 21:18:55 +08:00
|
|
|
/**
|
|
|
|
* struct vga_switcheroo_handler - handler callbacks
|
|
|
|
* @init: initialize handler.
|
|
|
|
* Optional. This gets called when vga_switcheroo is enabled, i.e. when
|
|
|
|
* two vga clients have registered. It allows the handler to perform
|
|
|
|
* some delayed initialization that depends on the existence of the
|
|
|
|
* vga clients. Currently only the radeon and amdgpu drivers use this.
|
|
|
|
* The return value is ignored
|
|
|
|
* @switchto: switch outputs to given client.
|
|
|
|
* Mandatory. For muxless machines this should be a no-op. Returning 0
|
|
|
|
* denotes success, anything else failure (in which case the switch is
|
|
|
|
* aborted)
|
vga_switcheroo: Add support for switching only the DDC
Originally by Seth Forshee <seth.forshee@canonical.com>, 2012-10-04:
During graphics driver initialization it's useful to be able to mux
only the DDC to the inactive client in order to read the EDID. Add
a switch_ddc callback to allow capable handlers to provide this
functionality, and add vga_switcheroo_switch_ddc() to allow DRM
to mux only the DDC.
Modified by Dave Airlie <airlied@gmail.com>, 2012-12-22:
I can't figure out why I didn't like this, but I rewrote this [...]
to lock/unlock the ddc lines [...]. I think I'd prefer something
like that otherwise the interface got really ugly.
Modified by Lukas Wunner <lukas@wunner.de>, 2015-04 - 2015-10:
Change semantics of ->switch_ddc handler callback to return previous
DDC owner. Original version tried to determine previous DDC owner
with find_active_client() but this fails if the inactive client
registers before the active client.
Don't lock vgasr_mutex in _lock_ddc() / _unlock_ddc(), it can cause
deadlocks because (a) during switch (with vgasr_mutex already held),
GPU is woken and probes its outputs, tries to re-acquire vgasr_mutex
to lock DDC lines; (b) Likewise during switch, GPU is suspended and
calls cancel_delayed_work_sync() to stop output polling, if poll
task is running at this moment we may wait forever for it to finish.
Instead, lock mux_hw_lock when unregistering the handler because
the only reason why we'd want to lock vgasr_mutex in _lock_ddc() /
_unlock_ddc() is to block the handler from disappearing while DDC
lines are switched.
Also acquire mux_hw_lock in stage2 to avoid race condition where
reading the EDID and switching happens simultaneously. Likewise on
MIGD / MDIS commands and on runtime suspend.
v2.1: Overhaul locking, squash commits (Daniel Vetter)
v2.2: Readability improvements (Thierry Reding)
v2.3: Overhaul locking once more
v2.4: Retain semantics of ->switchto handler callback to switch all
pins, including DDC (Daniel Vetter)
v5: Rename ddc_lock to mux_hw_lock: Since we acquire this both
when calling ->switch_ddc and ->switchto, it protects not just
access to the DDC lines but to the mux in general. This is in
line with the DRM convention to use low-level locks to avoid
concurrent hw access (e.g. i2c, dp_aux) which are often called
hw_lock (Daniel Vetter)
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=88861
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=61115
Tested-by: Lukas Wunner <lukas@wunner.de>
[MBP 9,1 2012 intel IVB + nvidia GK107 pre-retina 15"]
Cc: Seth Forshee <seth.forshee@canonical.com>
Cc: Dave Airlie <airlied@gmail.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/e81ae9722b84c5ed591805fee3ea6dbf5dc6c4b3.1452525860.git.lukas@wunner.de
2016-01-12 03:09:20 +08:00
|
|
|
* @switch_ddc: switch DDC lines to given client.
|
|
|
|
* Optional. Should return the previous DDC owner on success or a
|
|
|
|
* negative int on failure
|
2015-08-23 21:18:55 +08:00
|
|
|
* @power_state: cut or reinstate power of given client.
|
|
|
|
* Optional. The return value is ignored
|
|
|
|
* @get_client_id: determine if given pci device is integrated or discrete GPU.
|
|
|
|
* Mandatory
|
|
|
|
*
|
|
|
|
* Handler callbacks. The multiplexer itself. The @switchto and @get_client_id
|
|
|
|
* methods are mandatory, all others may be set to NULL.
|
|
|
|
*/
|
2010-02-01 13:38:10 +08:00
|
|
|
struct vga_switcheroo_handler {
|
2015-08-23 21:18:55 +08:00
|
|
|
int (*init)(void);
|
2010-02-01 13:38:10 +08:00
|
|
|
int (*switchto)(enum vga_switcheroo_client_id id);
|
vga_switcheroo: Add support for switching only the DDC
Originally by Seth Forshee <seth.forshee@canonical.com>, 2012-10-04:
During graphics driver initialization it's useful to be able to mux
only the DDC to the inactive client in order to read the EDID. Add
a switch_ddc callback to allow capable handlers to provide this
functionality, and add vga_switcheroo_switch_ddc() to allow DRM
to mux only the DDC.
Modified by Dave Airlie <airlied@gmail.com>, 2012-12-22:
I can't figure out why I didn't like this, but I rewrote this [...]
to lock/unlock the ddc lines [...]. I think I'd prefer something
like that otherwise the interface got really ugly.
Modified by Lukas Wunner <lukas@wunner.de>, 2015-04 - 2015-10:
Change semantics of ->switch_ddc handler callback to return previous
DDC owner. Original version tried to determine previous DDC owner
with find_active_client() but this fails if the inactive client
registers before the active client.
Don't lock vgasr_mutex in _lock_ddc() / _unlock_ddc(), it can cause
deadlocks because (a) during switch (with vgasr_mutex already held),
GPU is woken and probes its outputs, tries to re-acquire vgasr_mutex
to lock DDC lines; (b) Likewise during switch, GPU is suspended and
calls cancel_delayed_work_sync() to stop output polling, if poll
task is running at this moment we may wait forever for it to finish.
Instead, lock mux_hw_lock when unregistering the handler because
the only reason why we'd want to lock vgasr_mutex in _lock_ddc() /
_unlock_ddc() is to block the handler from disappearing while DDC
lines are switched.
Also acquire mux_hw_lock in stage2 to avoid race condition where
reading the EDID and switching happens simultaneously. Likewise on
MIGD / MDIS commands and on runtime suspend.
v2.1: Overhaul locking, squash commits (Daniel Vetter)
v2.2: Readability improvements (Thierry Reding)
v2.3: Overhaul locking once more
v2.4: Retain semantics of ->switchto handler callback to switch all
pins, including DDC (Daniel Vetter)
v5: Rename ddc_lock to mux_hw_lock: Since we acquire this both
when calling ->switch_ddc and ->switchto, it protects not just
access to the DDC lines but to the mux in general. This is in
line with the DRM convention to use low-level locks to avoid
concurrent hw access (e.g. i2c, dp_aux) which are often called
hw_lock (Daniel Vetter)
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=88861
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=61115
Tested-by: Lukas Wunner <lukas@wunner.de>
[MBP 9,1 2012 intel IVB + nvidia GK107 pre-retina 15"]
Cc: Seth Forshee <seth.forshee@canonical.com>
Cc: Dave Airlie <airlied@gmail.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/e81ae9722b84c5ed591805fee3ea6dbf5dc6c4b3.1452525860.git.lukas@wunner.de
2016-01-12 03:09:20 +08:00
|
|
|
int (*switch_ddc)(enum vga_switcheroo_client_id id);
|
2010-02-01 13:38:10 +08:00
|
|
|
int (*power_state)(enum vga_switcheroo_client_id id,
|
|
|
|
enum vga_switcheroo_state state);
|
2015-08-28 18:54:07 +08:00
|
|
|
enum vga_switcheroo_client_id (*get_client_id)(struct pci_dev *pdev);
|
2010-02-01 13:38:10 +08:00
|
|
|
};
|
|
|
|
|
2015-08-23 21:18:55 +08:00
|
|
|
/**
|
|
|
|
* struct vga_switcheroo_client_ops - client callbacks
|
|
|
|
* @set_gpu_state: do the equivalent of suspend/resume for the card.
|
|
|
|
* Mandatory. This should not cut power to the discrete GPU,
|
|
|
|
* which is the job of the handler
|
|
|
|
* @reprobe: poll outputs.
|
|
|
|
* Optional. This gets called after waking the GPU and switching
|
|
|
|
* the outputs to it
|
|
|
|
* @can_switch: check if the device is in a position to switch now.
|
|
|
|
* Mandatory. The client should return false if a user space process
|
|
|
|
* has one of its device files open
|
ALSA: hda - Enable runtime PM only for discrete GPU
The recent change of vga_switcheroo allowed the runtime PM for
HD-audio on AMD GPUs, but this also resulted in a regression. When
the HD-audio controller driver gets runtime-suspended, HD-audio link
is turned off, and the hotplug notification is ignored. This leads to
the inconsistent audio state (the connection isn't notified and ELD is
ignored).
The best fix would be to implement the proper ELD notification via the
audio component, but it's still not ready. As a quick workaround,
this patch adds the check of runtime_idle and allows the runtime
suspend only when the vga_switcheroo is bound with discrete GPU.
That is, a system with a single GPU and APU would be again without
runtime PM to keep the HD-audio link for the hotplug notification and
ELD read out.
Also, the codec->auto_runtime_pm flag is set only for the discrete GPU
at the time GPU gets bound via vga_switcheroo (i.e. only dGPU is
forcibly runtime-PM enabled), so that APU can still get the ELD
notification.
For identifying which GPU is bound, a new vga_switcheroo client
callback, gpu_bound, is implemented. The vga_switcheroo simply calls
this when GPU is bound, and tells whether it's dGPU or APU.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=200945
Fixes: 07f4f97d7b4b ("vga_switcheroo: Use device link for HDA controller")
Reported-by: Jian-Hong Pan <jian-hong@endlessm.com>
Tested-by: Jian-Hong Pan <jian-hong@endlessm.com>
Acked-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-09-10 22:20:25 +08:00
|
|
|
* @gpu_bound: notify the client id to audio client when the GPU is bound.
|
2015-08-23 21:18:55 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* set to NULL. For audio clients, the @reprobe member is bogus.
|
ALSA: hda - Enable runtime PM only for discrete GPU
The recent change of vga_switcheroo allowed the runtime PM for
HD-audio on AMD GPUs, but this also resulted in a regression. When
the HD-audio controller driver gets runtime-suspended, HD-audio link
is turned off, and the hotplug notification is ignored. This leads to
the inconsistent audio state (the connection isn't notified and ELD is
ignored).
The best fix would be to implement the proper ELD notification via the
audio component, but it's still not ready. As a quick workaround,
this patch adds the check of runtime_idle and allows the runtime
suspend only when the vga_switcheroo is bound with discrete GPU.
That is, a system with a single GPU and APU would be again without
runtime PM to keep the HD-audio link for the hotplug notification and
ELD read out.
Also, the codec->auto_runtime_pm flag is set only for the discrete GPU
at the time GPU gets bound via vga_switcheroo (i.e. only dGPU is
forcibly runtime-PM enabled), so that APU can still get the ELD
notification.
For identifying which GPU is bound, a new vga_switcheroo client
callback, gpu_bound, is implemented. The vga_switcheroo simply calls
this when GPU is bound, and tells whether it's dGPU or APU.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=200945
Fixes: 07f4f97d7b4b ("vga_switcheroo: Use device link for HDA controller")
Reported-by: Jian-Hong Pan <jian-hong@endlessm.com>
Tested-by: Jian-Hong Pan <jian-hong@endlessm.com>
Acked-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-09-10 22:20:25 +08:00
|
|
|
* OTOH, @gpu_bound is only for audio clients, and not used for GPU clients.
|
2015-08-23 21:18:55 +08:00
|
|
|
*/
|
2012-05-11 13:51:17 +08:00
|
|
|
struct vga_switcheroo_client_ops {
|
|
|
|
void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state);
|
|
|
|
void (*reprobe)(struct pci_dev *dev);
|
|
|
|
bool (*can_switch)(struct pci_dev *dev);
|
ALSA: hda - Enable runtime PM only for discrete GPU
The recent change of vga_switcheroo allowed the runtime PM for
HD-audio on AMD GPUs, but this also resulted in a regression. When
the HD-audio controller driver gets runtime-suspended, HD-audio link
is turned off, and the hotplug notification is ignored. This leads to
the inconsistent audio state (the connection isn't notified and ELD is
ignored).
The best fix would be to implement the proper ELD notification via the
audio component, but it's still not ready. As a quick workaround,
this patch adds the check of runtime_idle and allows the runtime
suspend only when the vga_switcheroo is bound with discrete GPU.
That is, a system with a single GPU and APU would be again without
runtime PM to keep the HD-audio link for the hotplug notification and
ELD read out.
Also, the codec->auto_runtime_pm flag is set only for the discrete GPU
at the time GPU gets bound via vga_switcheroo (i.e. only dGPU is
forcibly runtime-PM enabled), so that APU can still get the ELD
notification.
For identifying which GPU is bound, a new vga_switcheroo client
callback, gpu_bound, is implemented. The vga_switcheroo simply calls
this when GPU is bound, and tells whether it's dGPU or APU.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=200945
Fixes: 07f4f97d7b4b ("vga_switcheroo: Use device link for HDA controller")
Reported-by: Jian-Hong Pan <jian-hong@endlessm.com>
Tested-by: Jian-Hong Pan <jian-hong@endlessm.com>
Acked-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-09-10 22:20:25 +08:00
|
|
|
void (*gpu_bound)(struct pci_dev *dev, enum vga_switcheroo_client_id);
|
2012-05-11 13:51:17 +08:00
|
|
|
};
|
2010-02-01 13:38:10 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_VGA_SWITCHEROO)
|
|
|
|
void vga_switcheroo_unregister_client(struct pci_dev *dev);
|
|
|
|
int vga_switcheroo_register_client(struct pci_dev *dev,
|
2012-09-10 10:28:36 +08:00
|
|
|
const struct vga_switcheroo_client_ops *ops,
|
|
|
|
bool driver_power_control);
|
2012-04-26 20:29:48 +08:00
|
|
|
int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
|
|
|
|
const struct vga_switcheroo_client_ops *ops,
|
2018-07-17 16:20:50 +08:00
|
|
|
struct pci_dev *vga_dev);
|
2010-02-01 13:38:10 +08:00
|
|
|
|
|
|
|
void vga_switcheroo_client_fb_set(struct pci_dev *dev,
|
|
|
|
struct fb_info *info);
|
|
|
|
|
2016-01-12 03:09:20 +08:00
|
|
|
int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler,
|
|
|
|
enum vga_switcheroo_handler_flags_t handler_flags);
|
2010-02-01 13:38:10 +08:00
|
|
|
void vga_switcheroo_unregister_handler(void);
|
2016-01-12 03:09:20 +08:00
|
|
|
enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void);
|
vga_switcheroo: Add support for switching only the DDC
Originally by Seth Forshee <seth.forshee@canonical.com>, 2012-10-04:
During graphics driver initialization it's useful to be able to mux
only the DDC to the inactive client in order to read the EDID. Add
a switch_ddc callback to allow capable handlers to provide this
functionality, and add vga_switcheroo_switch_ddc() to allow DRM
to mux only the DDC.
Modified by Dave Airlie <airlied@gmail.com>, 2012-12-22:
I can't figure out why I didn't like this, but I rewrote this [...]
to lock/unlock the ddc lines [...]. I think I'd prefer something
like that otherwise the interface got really ugly.
Modified by Lukas Wunner <lukas@wunner.de>, 2015-04 - 2015-10:
Change semantics of ->switch_ddc handler callback to return previous
DDC owner. Original version tried to determine previous DDC owner
with find_active_client() but this fails if the inactive client
registers before the active client.
Don't lock vgasr_mutex in _lock_ddc() / _unlock_ddc(), it can cause
deadlocks because (a) during switch (with vgasr_mutex already held),
GPU is woken and probes its outputs, tries to re-acquire vgasr_mutex
to lock DDC lines; (b) Likewise during switch, GPU is suspended and
calls cancel_delayed_work_sync() to stop output polling, if poll
task is running at this moment we may wait forever for it to finish.
Instead, lock mux_hw_lock when unregistering the handler because
the only reason why we'd want to lock vgasr_mutex in _lock_ddc() /
_unlock_ddc() is to block the handler from disappearing while DDC
lines are switched.
Also acquire mux_hw_lock in stage2 to avoid race condition where
reading the EDID and switching happens simultaneously. Likewise on
MIGD / MDIS commands and on runtime suspend.
v2.1: Overhaul locking, squash commits (Daniel Vetter)
v2.2: Readability improvements (Thierry Reding)
v2.3: Overhaul locking once more
v2.4: Retain semantics of ->switchto handler callback to switch all
pins, including DDC (Daniel Vetter)
v5: Rename ddc_lock to mux_hw_lock: Since we acquire this both
when calling ->switch_ddc and ->switchto, it protects not just
access to the DDC lines but to the mux in general. This is in
line with the DRM convention to use low-level locks to avoid
concurrent hw access (e.g. i2c, dp_aux) which are often called
hw_lock (Daniel Vetter)
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=88861
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=61115
Tested-by: Lukas Wunner <lukas@wunner.de>
[MBP 9,1 2012 intel IVB + nvidia GK107 pre-retina 15"]
Cc: Seth Forshee <seth.forshee@canonical.com>
Cc: Dave Airlie <airlied@gmail.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/e81ae9722b84c5ed591805fee3ea6dbf5dc6c4b3.1452525860.git.lukas@wunner.de
2016-01-12 03:09:20 +08:00
|
|
|
int vga_switcheroo_lock_ddc(struct pci_dev *pdev);
|
|
|
|
int vga_switcheroo_unlock_ddc(struct pci_dev *pdev);
|
2010-02-01 13:38:10 +08:00
|
|
|
|
|
|
|
int vga_switcheroo_process_delayed_switch(void);
|
|
|
|
|
2016-05-31 17:13:27 +08:00
|
|
|
bool vga_switcheroo_client_probe_defer(struct pci_dev *pdev);
|
2015-08-28 17:56:26 +08:00
|
|
|
enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev);
|
2012-06-07 18:15:15 +08:00
|
|
|
|
2012-09-10 10:28:36 +08:00
|
|
|
int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
|
2014-09-13 05:51:29 +08:00
|
|
|
void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
|
2010-02-01 13:38:10 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
|
|
|
|
static inline int vga_switcheroo_register_client(struct pci_dev *dev,
|
2012-09-10 10:28:36 +08:00
|
|
|
const struct vga_switcheroo_client_ops *ops, bool driver_power_control) { return 0; }
|
2010-02-01 13:38:10 +08:00
|
|
|
static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
|
2016-01-12 03:09:20 +08:00
|
|
|
static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler,
|
|
|
|
enum vga_switcheroo_handler_flags_t handler_flags) { return 0; }
|
2012-04-26 20:29:48 +08:00
|
|
|
static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
|
|
|
|
const struct vga_switcheroo_client_ops *ops,
|
2018-07-17 16:20:50 +08:00
|
|
|
struct pci_dev *vga_dev) { return 0; }
|
2010-02-01 13:38:10 +08:00
|
|
|
static inline void vga_switcheroo_unregister_handler(void) {}
|
2016-01-12 03:09:20 +08:00
|
|
|
static inline enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void) { return 0; }
|
vga_switcheroo: Add support for switching only the DDC
Originally by Seth Forshee <seth.forshee@canonical.com>, 2012-10-04:
During graphics driver initialization it's useful to be able to mux
only the DDC to the inactive client in order to read the EDID. Add
a switch_ddc callback to allow capable handlers to provide this
functionality, and add vga_switcheroo_switch_ddc() to allow DRM
to mux only the DDC.
Modified by Dave Airlie <airlied@gmail.com>, 2012-12-22:
I can't figure out why I didn't like this, but I rewrote this [...]
to lock/unlock the ddc lines [...]. I think I'd prefer something
like that otherwise the interface got really ugly.
Modified by Lukas Wunner <lukas@wunner.de>, 2015-04 - 2015-10:
Change semantics of ->switch_ddc handler callback to return previous
DDC owner. Original version tried to determine previous DDC owner
with find_active_client() but this fails if the inactive client
registers before the active client.
Don't lock vgasr_mutex in _lock_ddc() / _unlock_ddc(), it can cause
deadlocks because (a) during switch (with vgasr_mutex already held),
GPU is woken and probes its outputs, tries to re-acquire vgasr_mutex
to lock DDC lines; (b) Likewise during switch, GPU is suspended and
calls cancel_delayed_work_sync() to stop output polling, if poll
task is running at this moment we may wait forever for it to finish.
Instead, lock mux_hw_lock when unregistering the handler because
the only reason why we'd want to lock vgasr_mutex in _lock_ddc() /
_unlock_ddc() is to block the handler from disappearing while DDC
lines are switched.
Also acquire mux_hw_lock in stage2 to avoid race condition where
reading the EDID and switching happens simultaneously. Likewise on
MIGD / MDIS commands and on runtime suspend.
v2.1: Overhaul locking, squash commits (Daniel Vetter)
v2.2: Readability improvements (Thierry Reding)
v2.3: Overhaul locking once more
v2.4: Retain semantics of ->switchto handler callback to switch all
pins, including DDC (Daniel Vetter)
v5: Rename ddc_lock to mux_hw_lock: Since we acquire this both
when calling ->switch_ddc and ->switchto, it protects not just
access to the DDC lines but to the mux in general. This is in
line with the DRM convention to use low-level locks to avoid
concurrent hw access (e.g. i2c, dp_aux) which are often called
hw_lock (Daniel Vetter)
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=88861
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=61115
Tested-by: Lukas Wunner <lukas@wunner.de>
[MBP 9,1 2012 intel IVB + nvidia GK107 pre-retina 15"]
Cc: Seth Forshee <seth.forshee@canonical.com>
Cc: Dave Airlie <airlied@gmail.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/e81ae9722b84c5ed591805fee3ea6dbf5dc6c4b3.1452525860.git.lukas@wunner.de
2016-01-12 03:09:20 +08:00
|
|
|
static inline int vga_switcheroo_lock_ddc(struct pci_dev *pdev) { return -ENODEV; }
|
|
|
|
static inline int vga_switcheroo_unlock_ddc(struct pci_dev *pdev) { return -ENODEV; }
|
2010-02-01 13:38:10 +08:00
|
|
|
static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
|
2016-05-31 17:13:27 +08:00
|
|
|
static inline bool vga_switcheroo_client_probe_defer(struct pci_dev *pdev) { return false; }
|
2015-08-28 17:56:26 +08:00
|
|
|
static inline enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev) { return VGA_SWITCHEROO_ON; }
|
2012-06-07 18:15:15 +08:00
|
|
|
|
2012-09-10 10:28:36 +08:00
|
|
|
static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
|
2014-09-13 05:51:29 +08:00
|
|
|
static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
|
2010-02-01 13:38:10 +08:00
|
|
|
|
|
|
|
#endif
|
2012-06-14 20:02:35 +08:00
|
|
|
#endif /* _LINUX_VGA_SWITCHEROO_H_ */
|