![]() |
|
|||
0001 /* 0002 * vga_switcheroo.h - Support for laptop with dual GPU using one set of outputs 0003 * 0004 * Copyright (c) 2010 Red Hat Inc. 0005 * Author : Dave Airlie <airlied@redhat.com> 0006 * 0007 * Copyright (c) 2015 Lukas Wunner <lukas@wunner.de> 0008 * 0009 * Permission is hereby granted, free of charge, to any person obtaining a 0010 * copy of this software and associated documentation files (the "Software"), 0011 * to deal in the Software without restriction, including without limitation 0012 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 0013 * and/or sell copies of the Software, and to permit persons to whom the 0014 * Software is furnished to do so, subject to the following conditions: 0015 * 0016 * The above copyright notice and this permission notice (including the next 0017 * paragraph) shall be included in all copies or substantial portions of the 0018 * Software. 0019 * 0020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 0023 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0024 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 0025 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 0026 * DEALINGS 0027 * IN THE SOFTWARE. 0028 * 0029 */ 0030 0031 #ifndef _LINUX_VGA_SWITCHEROO_H_ 0032 #define _LINUX_VGA_SWITCHEROO_H_ 0033 0034 #include <linux/fb.h> 0035 0036 struct pci_dev; 0037 0038 /** 0039 * enum vga_switcheroo_handler_flags_t - handler flags bitmask 0040 * @VGA_SWITCHEROO_CAN_SWITCH_DDC: whether the handler is able to switch the 0041 * DDC lines separately. This signals to clients that they should call 0042 * drm_get_edid_switcheroo() to probe the EDID 0043 * @VGA_SWITCHEROO_NEEDS_EDP_CONFIG: whether the handler is unable to switch 0044 * the AUX channel separately. This signals to clients that the active 0045 * GPU needs to train the link and communicate the link parameters to the 0046 * inactive GPU (mediated by vga_switcheroo). The inactive GPU may then 0047 * skip the AUX handshake and set up its output with these pre-calibrated 0048 * values (DisplayPort specification v1.1a, section 2.5.3.3) 0049 * 0050 * Handler flags bitmask. Used by handlers to declare their capabilities upon 0051 * registering with vga_switcheroo. 0052 */ 0053 enum vga_switcheroo_handler_flags_t { 0054 VGA_SWITCHEROO_CAN_SWITCH_DDC = (1 << 0), 0055 VGA_SWITCHEROO_NEEDS_EDP_CONFIG = (1 << 1), 0056 }; 0057 0058 /** 0059 * enum vga_switcheroo_state - client power state 0060 * @VGA_SWITCHEROO_OFF: off 0061 * @VGA_SWITCHEROO_ON: on 0062 * @VGA_SWITCHEROO_NOT_FOUND: client has not registered with vga_switcheroo. 0063 * Only used in vga_switcheroo_get_client_state() which in turn is only 0064 * called from hda_intel.c 0065 * 0066 * Client power state. 0067 */ 0068 enum vga_switcheroo_state { 0069 VGA_SWITCHEROO_OFF, 0070 VGA_SWITCHEROO_ON, 0071 /* below are referred only from vga_switcheroo_get_client_state() */ 0072 VGA_SWITCHEROO_NOT_FOUND, 0073 }; 0074 0075 /** 0076 * enum vga_switcheroo_client_id - client identifier 0077 * @VGA_SWITCHEROO_UNKNOWN_ID: initial identifier assigned to vga clients. 0078 * Determining the id requires the handler, so GPUs are given their 0079 * true id in a delayed fashion in vga_switcheroo_enable() 0080 * @VGA_SWITCHEROO_IGD: integrated graphics device 0081 * @VGA_SWITCHEROO_DIS: discrete graphics device 0082 * @VGA_SWITCHEROO_MAX_CLIENTS: currently no more than two GPUs are supported 0083 * 0084 * Client identifier. Audio clients use the same identifier & 0x100. 0085 */ 0086 enum vga_switcheroo_client_id { 0087 VGA_SWITCHEROO_UNKNOWN_ID = 0x1000, 0088 VGA_SWITCHEROO_IGD = 0, 0089 VGA_SWITCHEROO_DIS, 0090 VGA_SWITCHEROO_MAX_CLIENTS, 0091 }; 0092 0093 /** 0094 * struct vga_switcheroo_handler - handler callbacks 0095 * @init: initialize handler. 0096 * Optional. This gets called when vga_switcheroo is enabled, i.e. when 0097 * two vga clients have registered. It allows the handler to perform 0098 * some delayed initialization that depends on the existence of the 0099 * vga clients. Currently only the radeon and amdgpu drivers use this. 0100 * The return value is ignored 0101 * @switchto: switch outputs to given client. 0102 * Mandatory. For muxless machines this should be a no-op. Returning 0 0103 * denotes success, anything else failure (in which case the switch is 0104 * aborted) 0105 * @switch_ddc: switch DDC lines to given client. 0106 * Optional. Should return the previous DDC owner on success or a 0107 * negative int on failure 0108 * @power_state: cut or reinstate power of given client. 0109 * Optional. The return value is ignored 0110 * @get_client_id: determine if given pci device is integrated or discrete GPU. 0111 * Mandatory 0112 * 0113 * Handler callbacks. The multiplexer itself. The @switchto and @get_client_id 0114 * methods are mandatory, all others may be set to NULL. 0115 */ 0116 struct vga_switcheroo_handler { 0117 int (*init)(void); 0118 int (*switchto)(enum vga_switcheroo_client_id id); 0119 int (*switch_ddc)(enum vga_switcheroo_client_id id); 0120 int (*power_state)(enum vga_switcheroo_client_id id, 0121 enum vga_switcheroo_state state); 0122 enum vga_switcheroo_client_id (*get_client_id)(struct pci_dev *pdev); 0123 }; 0124 0125 /** 0126 * struct vga_switcheroo_client_ops - client callbacks 0127 * @set_gpu_state: do the equivalent of suspend/resume for the card. 0128 * Mandatory. This should not cut power to the discrete GPU, 0129 * which is the job of the handler 0130 * @reprobe: poll outputs. 0131 * Optional. This gets called after waking the GPU and switching 0132 * the outputs to it 0133 * @can_switch: check if the device is in a position to switch now. 0134 * Mandatory. The client should return false if a user space process 0135 * has one of its device files open 0136 * @gpu_bound: notify the client id to audio client when the GPU is bound. 0137 * 0138 * Client callbacks. A client can be either a GPU or an audio device on a GPU. 0139 * The @set_gpu_state and @can_switch methods are mandatory, @reprobe may be 0140 * set to NULL. For audio clients, the @reprobe member is bogus. 0141 * OTOH, @gpu_bound is only for audio clients, and not used for GPU clients. 0142 */ 0143 struct vga_switcheroo_client_ops { 0144 void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state); 0145 void (*reprobe)(struct pci_dev *dev); 0146 bool (*can_switch)(struct pci_dev *dev); 0147 void (*gpu_bound)(struct pci_dev *dev, enum vga_switcheroo_client_id); 0148 }; 0149 0150 #if defined(CONFIG_VGA_SWITCHEROO) 0151 void vga_switcheroo_unregister_client(struct pci_dev *dev); 0152 int vga_switcheroo_register_client(struct pci_dev *dev, 0153 const struct vga_switcheroo_client_ops *ops, 0154 bool driver_power_control); 0155 int vga_switcheroo_register_audio_client(struct pci_dev *pdev, 0156 const struct vga_switcheroo_client_ops *ops, 0157 struct pci_dev *vga_dev); 0158 0159 void vga_switcheroo_client_fb_set(struct pci_dev *dev, 0160 struct fb_info *info); 0161 0162 int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler, 0163 enum vga_switcheroo_handler_flags_t handler_flags); 0164 void vga_switcheroo_unregister_handler(void); 0165 enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void); 0166 int vga_switcheroo_lock_ddc(struct pci_dev *pdev); 0167 int vga_switcheroo_unlock_ddc(struct pci_dev *pdev); 0168 0169 int vga_switcheroo_process_delayed_switch(void); 0170 0171 bool vga_switcheroo_client_probe_defer(struct pci_dev *pdev); 0172 enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev); 0173 0174 int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain); 0175 void vga_switcheroo_fini_domain_pm_ops(struct device *dev); 0176 #else 0177 0178 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {} 0179 static inline int vga_switcheroo_register_client(struct pci_dev *dev, 0180 const struct vga_switcheroo_client_ops *ops, bool driver_power_control) { return 0; } 0181 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {} 0182 static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler, 0183 enum vga_switcheroo_handler_flags_t handler_flags) { return 0; } 0184 static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev, 0185 const struct vga_switcheroo_client_ops *ops, 0186 struct pci_dev *vga_dev) { return 0; } 0187 static inline void vga_switcheroo_unregister_handler(void) {} 0188 static inline enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void) { return 0; } 0189 static inline int vga_switcheroo_lock_ddc(struct pci_dev *pdev) { return -ENODEV; } 0190 static inline int vga_switcheroo_unlock_ddc(struct pci_dev *pdev) { return -ENODEV; } 0191 static inline int vga_switcheroo_process_delayed_switch(void) { return 0; } 0192 static inline bool vga_switcheroo_client_probe_defer(struct pci_dev *pdev) { return false; } 0193 static inline enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev) { return VGA_SWITCHEROO_ON; } 0194 0195 static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; } 0196 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {} 0197 0198 #endif 0199 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |