Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 1 | /* |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 2 | * vga_switcheroo.h - Support for laptop with dual GPU using one set of outputs |
| 3 | * |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 4 | * Copyright (c) 2010 Red Hat Inc. |
| 5 | * Author : Dave Airlie <airlied@redhat.com> |
| 6 | * |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 Lukas Wunner <lukas@wunner.de> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 8 | * |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the next |
| 17 | * paragraph) shall be included in all copies or substantial portions of the |
| 18 | * Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 26 | * DEALINGS |
| 27 | * IN THE SOFTWARE. |
| 28 | * |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 29 | */ |
| 30 | |
Ozan Çağlayan | d3decf3 | 2012-06-14 15:02:35 +0300 | [diff] [blame] | 31 | #ifndef _LINUX_VGA_SWITCHEROO_H_ |
| 32 | #define _LINUX_VGA_SWITCHEROO_H_ |
| 33 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 34 | #include <linux/fb.h> |
| 35 | |
Randy Dunlap | f8fee8f | 2012-06-15 12:46:17 -0700 | [diff] [blame] | 36 | struct pci_dev; |
| 37 | |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 38 | /** |
| 39 | * enum vga_switcheroo_state - client power state |
| 40 | * @VGA_SWITCHEROO_OFF: off |
| 41 | * @VGA_SWITCHEROO_ON: on |
| 42 | * @VGA_SWITCHEROO_INIT: client has registered with vga_switcheroo but |
| 43 | * vga_switcheroo is not enabled, i.e. no second client or no handler |
| 44 | * has registered. Only used in vga_switcheroo_get_client_state() which |
| 45 | * in turn is only called from hda_intel.c |
| 46 | * @VGA_SWITCHEROO_NOT_FOUND: client has not registered with vga_switcheroo. |
| 47 | * Only used in vga_switcheroo_get_client_state() which in turn is only |
| 48 | * called from hda_intel.c |
| 49 | * |
| 50 | * Client power state. |
| 51 | */ |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 52 | enum vga_switcheroo_state { |
| 53 | VGA_SWITCHEROO_OFF, |
| 54 | VGA_SWITCHEROO_ON, |
Takashi Iwai | c8e9cf7 | 2012-06-07 12:15:15 +0200 | [diff] [blame] | 55 | /* below are referred only from vga_switcheroo_get_client_state() */ |
| 56 | VGA_SWITCHEROO_INIT, |
| 57 | VGA_SWITCHEROO_NOT_FOUND, |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 58 | }; |
| 59 | |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 60 | /** |
| 61 | * enum vga_switcheroo_client_id - client identifier |
| 62 | * @VGA_SWITCHEROO_IGD: integrated graphics device |
| 63 | * @VGA_SWITCHEROO_DIS: discrete graphics device |
| 64 | * @VGA_SWITCHEROO_MAX_CLIENTS: currently no more than two GPUs are supported |
| 65 | * |
| 66 | * Client identifier. Audio clients use the same identifier & 0x100. |
| 67 | */ |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 68 | enum vga_switcheroo_client_id { |
| 69 | VGA_SWITCHEROO_IGD, |
| 70 | VGA_SWITCHEROO_DIS, |
| 71 | VGA_SWITCHEROO_MAX_CLIENTS, |
| 72 | }; |
| 73 | |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 74 | /** |
| 75 | * struct vga_switcheroo_handler - handler callbacks |
| 76 | * @init: initialize handler. |
| 77 | * Optional. This gets called when vga_switcheroo is enabled, i.e. when |
| 78 | * two vga clients have registered. It allows the handler to perform |
| 79 | * some delayed initialization that depends on the existence of the |
| 80 | * vga clients. Currently only the radeon and amdgpu drivers use this. |
| 81 | * The return value is ignored |
| 82 | * @switchto: switch outputs to given client. |
| 83 | * Mandatory. For muxless machines this should be a no-op. Returning 0 |
| 84 | * denotes success, anything else failure (in which case the switch is |
| 85 | * aborted) |
| 86 | * @power_state: cut or reinstate power of given client. |
| 87 | * Optional. The return value is ignored |
| 88 | * @get_client_id: determine if given pci device is integrated or discrete GPU. |
| 89 | * Mandatory |
| 90 | * |
| 91 | * Handler callbacks. The multiplexer itself. The @switchto and @get_client_id |
| 92 | * methods are mandatory, all others may be set to NULL. |
| 93 | */ |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 94 | struct vga_switcheroo_handler { |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 95 | int (*init)(void); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 96 | int (*switchto)(enum vga_switcheroo_client_id id); |
| 97 | int (*power_state)(enum vga_switcheroo_client_id id, |
| 98 | enum vga_switcheroo_state state); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 99 | int (*get_client_id)(struct pci_dev *pdev); |
| 100 | }; |
| 101 | |
Lukas Wunner | a645654 | 2015-08-23 15:18:55 +0200 | [diff] [blame] | 102 | /** |
| 103 | * struct vga_switcheroo_client_ops - client callbacks |
| 104 | * @set_gpu_state: do the equivalent of suspend/resume for the card. |
| 105 | * Mandatory. This should not cut power to the discrete GPU, |
| 106 | * which is the job of the handler |
| 107 | * @reprobe: poll outputs. |
| 108 | * Optional. This gets called after waking the GPU and switching |
| 109 | * the outputs to it |
| 110 | * @can_switch: check if the device is in a position to switch now. |
| 111 | * Mandatory. The client should return false if a user space process |
| 112 | * has one of its device files open |
| 113 | * |
| 114 | * Client callbacks. A client can be either a GPU or an audio device on a GPU. |
| 115 | * The @set_gpu_state and @can_switch methods are mandatory, @reprobe may be |
| 116 | * set to NULL. For audio clients, the @reprobe member is bogus. |
| 117 | */ |
Takashi Iwai | 26ec685 | 2012-05-11 07:51:17 +0200 | [diff] [blame] | 118 | struct vga_switcheroo_client_ops { |
| 119 | void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state); |
| 120 | void (*reprobe)(struct pci_dev *dev); |
| 121 | bool (*can_switch)(struct pci_dev *dev); |
| 122 | }; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 123 | |
| 124 | #if defined(CONFIG_VGA_SWITCHEROO) |
| 125 | void vga_switcheroo_unregister_client(struct pci_dev *dev); |
| 126 | int vga_switcheroo_register_client(struct pci_dev *dev, |
Dave Airlie | 0d69704 | 2012-09-10 12:28:36 +1000 | [diff] [blame] | 127 | const struct vga_switcheroo_client_ops *ops, |
| 128 | bool driver_power_control); |
Takashi Iwai | 3e9e63d | 2012-04-26 14:29:48 +0200 | [diff] [blame] | 129 | int vga_switcheroo_register_audio_client(struct pci_dev *pdev, |
| 130 | const struct vga_switcheroo_client_ops *ops, |
Lukas Wunner | 21b4567 | 2015-08-27 16:43:43 +0200 | [diff] [blame^] | 131 | int id); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 132 | |
| 133 | void vga_switcheroo_client_fb_set(struct pci_dev *dev, |
| 134 | struct fb_info *info); |
| 135 | |
| 136 | int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler); |
| 137 | void vga_switcheroo_unregister_handler(void); |
| 138 | |
| 139 | int vga_switcheroo_process_delayed_switch(void); |
| 140 | |
Takashi Iwai | c8e9cf7 | 2012-06-07 12:15:15 +0200 | [diff] [blame] | 141 | int vga_switcheroo_get_client_state(struct pci_dev *dev); |
| 142 | |
Dave Airlie | 0d69704 | 2012-09-10 12:28:36 +1000 | [diff] [blame] | 143 | void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic); |
| 144 | |
| 145 | int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain); |
Alex Deucher | 766a53d | 2014-09-12 17:51:29 -0400 | [diff] [blame] | 146 | void vga_switcheroo_fini_domain_pm_ops(struct device *dev); |
Dave Airlie | 0d69704 | 2012-09-10 12:28:36 +1000 | [diff] [blame] | 147 | int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 148 | #else |
| 149 | |
| 150 | static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {} |
| 151 | static inline int vga_switcheroo_register_client(struct pci_dev *dev, |
Dave Airlie | 0d69704 | 2012-09-10 12:28:36 +1000 | [diff] [blame] | 152 | const struct vga_switcheroo_client_ops *ops, bool driver_power_control) { return 0; } |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 153 | static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {} |
| 154 | static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; } |
Takashi Iwai | 3e9e63d | 2012-04-26 14:29:48 +0200 | [diff] [blame] | 155 | static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev, |
| 156 | const struct vga_switcheroo_client_ops *ops, |
Lukas Wunner | 21b4567 | 2015-08-27 16:43:43 +0200 | [diff] [blame^] | 157 | int id) { return 0; } |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 158 | static inline void vga_switcheroo_unregister_handler(void) {} |
| 159 | static inline int vga_switcheroo_process_delayed_switch(void) { return 0; } |
Takashi Iwai | 505cff0 | 2012-06-08 12:49:17 +0200 | [diff] [blame] | 160 | static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return VGA_SWITCHEROO_ON; } |
Takashi Iwai | c8e9cf7 | 2012-06-07 12:15:15 +0200 | [diff] [blame] | 161 | |
Dave Airlie | 0d69704 | 2012-09-10 12:28:36 +1000 | [diff] [blame] | 162 | static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {} |
| 163 | |
| 164 | static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; } |
Alex Deucher | 766a53d | 2014-09-12 17:51:29 -0400 | [diff] [blame] | 165 | static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {} |
Dave Airlie | 0d69704 | 2012-09-10 12:28:36 +1000 | [diff] [blame] | 166 | static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; } |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 167 | |
| 168 | #endif |
Ozan Çağlayan | d3decf3 | 2012-06-14 15:02:35 +0300 | [diff] [blame] | 169 | #endif /* _LINUX_VGA_SWITCHEROO_H_ */ |