Blame view
include/linux/vga_switcheroo.h
8.62 KB
6a9ee8af3 vga_switcheroo: i... |
1 |
/* |
a645654b8 vga_switcheroo: D... |
2 3 |
* vga_switcheroo.h - Support for laptop with dual GPU using one set of outputs * |
6a9ee8af3 vga_switcheroo: i... |
4 5 6 |
* Copyright (c) 2010 Red Hat Inc. * Author : Dave Airlie <airlied@redhat.com> * |
a645654b8 vga_switcheroo: D... |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
* 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. |
6a9ee8af3 vga_switcheroo: i... |
28 |
* |
6a9ee8af3 vga_switcheroo: i... |
29 |
*/ |
d3decf3a0 vga_switcheroo: A... |
30 31 |
#ifndef _LINUX_VGA_SWITCHEROO_H_ #define _LINUX_VGA_SWITCHEROO_H_ |
6a9ee8af3 vga_switcheroo: i... |
32 |
#include <linux/fb.h> |
f8fee8f5a vga_switcheroo.h:... |
33 |
struct pci_dev; |
a645654b8 vga_switcheroo: D... |
34 |
/** |
156d7d412 vga_switcheroo: A... |
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
* 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), }; /** |
a645654b8 vga_switcheroo: D... |
55 56 57 |
* enum vga_switcheroo_state - client power state * @VGA_SWITCHEROO_OFF: off * @VGA_SWITCHEROO_ON: on |
a645654b8 vga_switcheroo: D... |
58 59 60 61 62 63 |
* @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. */ |
6a9ee8af3 vga_switcheroo: i... |
64 65 66 |
enum vga_switcheroo_state { VGA_SWITCHEROO_OFF, VGA_SWITCHEROO_ON, |
c8e9cf7bb vga_switcheroo: A... |
67 |
/* below are referred only from vga_switcheroo_get_client_state() */ |
c8e9cf7bb vga_switcheroo: A... |
68 |
VGA_SWITCHEROO_NOT_FOUND, |
6a9ee8af3 vga_switcheroo: i... |
69 |
}; |
a645654b8 vga_switcheroo: D... |
70 71 |
/** * enum vga_switcheroo_client_id - client identifier |
21c5ba8c1 vga_switcheroo: U... |
72 73 74 |
* @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() |
a645654b8 vga_switcheroo: D... |
75 76 77 78 79 80 |
* @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. */ |
6a9ee8af3 vga_switcheroo: i... |
81 |
enum vga_switcheroo_client_id { |
4aaf448fa vga_switcheroo: s... |
82 83 |
VGA_SWITCHEROO_UNKNOWN_ID = 0x1000, VGA_SWITCHEROO_IGD = 0, |
6a9ee8af3 vga_switcheroo: i... |
84 85 86 |
VGA_SWITCHEROO_DIS, VGA_SWITCHEROO_MAX_CLIENTS, }; |
a645654b8 vga_switcheroo: D... |
87 88 89 90 91 92 93 94 95 96 97 98 |
/** * 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) |
e4cb81d7e vga_switcheroo: A... |
99 100 101 |
* @switch_ddc: switch DDC lines to given client. * Optional. Should return the previous DDC owner on success or a * negative int on failure |
a645654b8 vga_switcheroo: D... |
102 103 104 105 106 107 108 109 |
* @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. */ |
6a9ee8af3 vga_switcheroo: i... |
110 |
struct vga_switcheroo_handler { |
a645654b8 vga_switcheroo: D... |
111 |
int (*init)(void); |
6a9ee8af3 vga_switcheroo: i... |
112 |
int (*switchto)(enum vga_switcheroo_client_id id); |
e4cb81d7e vga_switcheroo: A... |
113 |
int (*switch_ddc)(enum vga_switcheroo_client_id id); |
6a9ee8af3 vga_switcheroo: i... |
114 115 |
int (*power_state)(enum vga_switcheroo_client_id id, enum vga_switcheroo_state state); |
fa3e967ff vga_switcheroo: U... |
116 |
enum vga_switcheroo_client_id (*get_client_id)(struct pci_dev *pdev); |
6a9ee8af3 vga_switcheroo: i... |
117 |
}; |
a645654b8 vga_switcheroo: D... |
118 119 120 121 122 123 124 125 126 127 128 |
/** * 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 |
37a3a98ef ALSA: hda - Enabl... |
129 |
* @gpu_bound: notify the client id to audio client when the GPU is bound. |
a645654b8 vga_switcheroo: D... |
130 131 132 133 |
* * 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. |
37a3a98ef ALSA: hda - Enabl... |
134 |
* OTOH, @gpu_bound is only for audio clients, and not used for GPU clients. |
a645654b8 vga_switcheroo: D... |
135 |
*/ |
26ec685ff vga_switcheroo: I... |
136 137 138 139 |
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); |
37a3a98ef ALSA: hda - Enabl... |
140 |
void (*gpu_bound)(struct pci_dev *dev, enum vga_switcheroo_client_id); |
26ec685ff vga_switcheroo: I... |
141 |
}; |
6a9ee8af3 vga_switcheroo: i... |
142 143 144 145 |
#if defined(CONFIG_VGA_SWITCHEROO) void vga_switcheroo_unregister_client(struct pci_dev *dev); int vga_switcheroo_register_client(struct pci_dev *dev, |
0d69704ae gpu/vga_switchero... |
146 147 |
const struct vga_switcheroo_client_ops *ops, bool driver_power_control); |
3e9e63dbd vga_switcheroo: A... |
148 149 |
int vga_switcheroo_register_audio_client(struct pci_dev *pdev, const struct vga_switcheroo_client_ops *ops, |
4aaf448fa vga_switcheroo: s... |
150 |
struct pci_dev *vga_dev); |
6a9ee8af3 vga_switcheroo: i... |
151 152 153 |
void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info); |
156d7d412 vga_switcheroo: A... |
154 155 |
int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler, enum vga_switcheroo_handler_flags_t handler_flags); |
6a9ee8af3 vga_switcheroo: i... |
156 |
void vga_switcheroo_unregister_handler(void); |
156d7d412 vga_switcheroo: A... |
157 |
enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void); |
e4cb81d7e vga_switcheroo: A... |
158 159 |
int vga_switcheroo_lock_ddc(struct pci_dev *pdev); int vga_switcheroo_unlock_ddc(struct pci_dev *pdev); |
6a9ee8af3 vga_switcheroo: i... |
160 161 |
int vga_switcheroo_process_delayed_switch(void); |
b00e5334a vga_switcheroo: A... |
162 |
bool vga_switcheroo_client_probe_defer(struct pci_dev *pdev); |
203d027de vga_switcheroo: U... |
163 |
enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev); |
c8e9cf7bb vga_switcheroo: A... |
164 |
|
0d69704ae gpu/vga_switchero... |
165 |
int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain); |
766a53d05 vgaswitcheroo: ad... |
166 |
void vga_switcheroo_fini_domain_pm_ops(struct device *dev); |
6a9ee8af3 vga_switcheroo: i... |
167 168 169 170 |
#else static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {} static inline int vga_switcheroo_register_client(struct pci_dev *dev, |
0d69704ae gpu/vga_switchero... |
171 |
const struct vga_switcheroo_client_ops *ops, bool driver_power_control) { return 0; } |
6a9ee8af3 vga_switcheroo: i... |
172 |
static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {} |
156d7d412 vga_switcheroo: A... |
173 174 |
static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler, enum vga_switcheroo_handler_flags_t handler_flags) { return 0; } |
3e9e63dbd vga_switcheroo: A... |
175 176 |
static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev, const struct vga_switcheroo_client_ops *ops, |
4aaf448fa vga_switcheroo: s... |
177 |
struct pci_dev *vga_dev) { return 0; } |
6a9ee8af3 vga_switcheroo: i... |
178 |
static inline void vga_switcheroo_unregister_handler(void) {} |
156d7d412 vga_switcheroo: A... |
179 |
static inline enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void) { return 0; } |
e4cb81d7e vga_switcheroo: A... |
180 181 |
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; } |
6a9ee8af3 vga_switcheroo: i... |
182 |
static inline int vga_switcheroo_process_delayed_switch(void) { return 0; } |
b00e5334a vga_switcheroo: A... |
183 |
static inline bool vga_switcheroo_client_probe_defer(struct pci_dev *pdev) { return false; } |
203d027de vga_switcheroo: U... |
184 |
static inline enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev) { return VGA_SWITCHEROO_ON; } |
c8e9cf7bb vga_switcheroo: A... |
185 |
|
0d69704ae gpu/vga_switchero... |
186 |
static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; } |
766a53d05 vgaswitcheroo: ad... |
187 |
static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {} |
6a9ee8af3 vga_switcheroo: i... |
188 189 |
#endif |
d3decf3a0 vga_switcheroo: A... |
190 |
#endif /* _LINUX_VGA_SWITCHEROO_H_ */ |