blob: 69e1d4a1f1b3d122c53ec22eb13543219502c881 [file] [log] [blame]
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10001/*
Lukas Wunnera6456542015-08-23 15:18:55 +02002 * vga_switcheroo.h - Support for laptop with dual GPU using one set of outputs
3 *
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10004 * Copyright (c) 2010 Red Hat Inc.
5 * Author : Dave Airlie <airlied@redhat.com>
6 *
Lukas Wunnera6456542015-08-23 15:18:55 +02007 * Copyright (c) 2015 Lukas Wunner <lukas@wunner.de>
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10008 *
Lukas Wunnera6456542015-08-23 15:18:55 +02009 * 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 Airlie6a9ee8a2010-02-01 15:38:10 +100029 */
30
Ozan Çağlayand3decf32012-06-14 15:02:35 +030031#ifndef _LINUX_VGA_SWITCHEROO_H_
32#define _LINUX_VGA_SWITCHEROO_H_
33
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100034#include <linux/fb.h>
35
Randy Dunlapf8fee8f2012-06-15 12:46:17 -070036struct pci_dev;
37
Lukas Wunnera6456542015-08-23 15:18:55 +020038/**
39 * enum vga_switcheroo_state - client power state
40 * @VGA_SWITCHEROO_OFF: off
41 * @VGA_SWITCHEROO_ON: on
Lukas Wunnera6456542015-08-23 15:18:55 +020042 * @VGA_SWITCHEROO_NOT_FOUND: client has not registered with vga_switcheroo.
43 * Only used in vga_switcheroo_get_client_state() which in turn is only
44 * called from hda_intel.c
45 *
46 * Client power state.
47 */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100048enum vga_switcheroo_state {
49 VGA_SWITCHEROO_OFF,
50 VGA_SWITCHEROO_ON,
Takashi Iwaic8e9cf72012-06-07 12:15:15 +020051 /* below are referred only from vga_switcheroo_get_client_state() */
Takashi Iwaic8e9cf72012-06-07 12:15:15 +020052 VGA_SWITCHEROO_NOT_FOUND,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100053};
54
Lukas Wunnera6456542015-08-23 15:18:55 +020055/**
56 * enum vga_switcheroo_client_id - client identifier
Lukas Wunner21c5ba82015-08-28 13:30:32 +020057 * @VGA_SWITCHEROO_UNKNOWN_ID: initial identifier assigned to vga clients.
58 * Determining the id requires the handler, so GPUs are given their
59 * true id in a delayed fashion in vga_switcheroo_enable()
Lukas Wunnera6456542015-08-23 15:18:55 +020060 * @VGA_SWITCHEROO_IGD: integrated graphics device
61 * @VGA_SWITCHEROO_DIS: discrete graphics device
62 * @VGA_SWITCHEROO_MAX_CLIENTS: currently no more than two GPUs are supported
63 *
64 * Client identifier. Audio clients use the same identifier & 0x100.
65 */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100066enum vga_switcheroo_client_id {
Lukas Wunner21c5ba82015-08-28 13:30:32 +020067 VGA_SWITCHEROO_UNKNOWN_ID = -1,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100068 VGA_SWITCHEROO_IGD,
69 VGA_SWITCHEROO_DIS,
70 VGA_SWITCHEROO_MAX_CLIENTS,
71};
72
Lukas Wunnera6456542015-08-23 15:18:55 +020073/**
74 * struct vga_switcheroo_handler - handler callbacks
75 * @init: initialize handler.
76 * Optional. This gets called when vga_switcheroo is enabled, i.e. when
77 * two vga clients have registered. It allows the handler to perform
78 * some delayed initialization that depends on the existence of the
79 * vga clients. Currently only the radeon and amdgpu drivers use this.
80 * The return value is ignored
81 * @switchto: switch outputs to given client.
82 * Mandatory. For muxless machines this should be a no-op. Returning 0
83 * denotes success, anything else failure (in which case the switch is
84 * aborted)
85 * @power_state: cut or reinstate power of given client.
86 * Optional. The return value is ignored
87 * @get_client_id: determine if given pci device is integrated or discrete GPU.
88 * Mandatory
89 *
90 * Handler callbacks. The multiplexer itself. The @switchto and @get_client_id
91 * methods are mandatory, all others may be set to NULL.
92 */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100093struct vga_switcheroo_handler {
Lukas Wunnera6456542015-08-23 15:18:55 +020094 int (*init)(void);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100095 int (*switchto)(enum vga_switcheroo_client_id id);
96 int (*power_state)(enum vga_switcheroo_client_id id,
97 enum vga_switcheroo_state state);
Lukas Wunnerfa3e9672015-08-28 12:54:07 +020098 enum vga_switcheroo_client_id (*get_client_id)(struct pci_dev *pdev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100099};
100
Lukas Wunnera6456542015-08-23 15:18:55 +0200101/**
102 * struct vga_switcheroo_client_ops - client callbacks
103 * @set_gpu_state: do the equivalent of suspend/resume for the card.
104 * Mandatory. This should not cut power to the discrete GPU,
105 * which is the job of the handler
106 * @reprobe: poll outputs.
107 * Optional. This gets called after waking the GPU and switching
108 * the outputs to it
109 * @can_switch: check if the device is in a position to switch now.
110 * Mandatory. The client should return false if a user space process
111 * has one of its device files open
112 *
113 * Client callbacks. A client can be either a GPU or an audio device on a GPU.
114 * The @set_gpu_state and @can_switch methods are mandatory, @reprobe may be
115 * set to NULL. For audio clients, the @reprobe member is bogus.
116 */
Takashi Iwai26ec6852012-05-11 07:51:17 +0200117struct vga_switcheroo_client_ops {
118 void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state);
119 void (*reprobe)(struct pci_dev *dev);
120 bool (*can_switch)(struct pci_dev *dev);
121};
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000122
123#if defined(CONFIG_VGA_SWITCHEROO)
124void vga_switcheroo_unregister_client(struct pci_dev *dev);
125int vga_switcheroo_register_client(struct pci_dev *dev,
Dave Airlie0d697042012-09-10 12:28:36 +1000126 const struct vga_switcheroo_client_ops *ops,
127 bool driver_power_control);
Takashi Iwai3e9e63d2012-04-26 14:29:48 +0200128int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
129 const struct vga_switcheroo_client_ops *ops,
Lukas Wunnerfa3e9672015-08-28 12:54:07 +0200130 enum vga_switcheroo_client_id id);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000131
132void vga_switcheroo_client_fb_set(struct pci_dev *dev,
133 struct fb_info *info);
134
Lukas Wunner5d170132015-10-18 13:05:40 +0200135int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000136void vga_switcheroo_unregister_handler(void);
137
138int vga_switcheroo_process_delayed_switch(void);
139
Lukas Wunner203d0272015-08-28 11:56:26 +0200140enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev);
Takashi Iwaic8e9cf72012-06-07 12:15:15 +0200141
Dave Airlie0d697042012-09-10 12:28:36 +1000142void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
143
144int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
Alex Deucher766a53d2014-09-12 17:51:29 -0400145void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
Dave Airlie0d697042012-09-10 12:28:36 +1000146int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000147#else
148
149static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
150static inline int vga_switcheroo_register_client(struct pci_dev *dev,
Dave Airlie0d697042012-09-10 12:28:36 +1000151 const struct vga_switcheroo_client_ops *ops, bool driver_power_control) { return 0; }
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000152static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
Lukas Wunner5d170132015-10-18 13:05:40 +0200153static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
Takashi Iwai3e9e63d2012-04-26 14:29:48 +0200154static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
155 const struct vga_switcheroo_client_ops *ops,
Lukas Wunnerfa3e9672015-08-28 12:54:07 +0200156 enum vga_switcheroo_client_id id) { return 0; }
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000157static inline void vga_switcheroo_unregister_handler(void) {}
158static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
Lukas Wunner203d0272015-08-28 11:56:26 +0200159static inline enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev) { return VGA_SWITCHEROO_ON; }
Takashi Iwaic8e9cf72012-06-07 12:15:15 +0200160
Dave Airlie0d697042012-09-10 12:28:36 +1000161static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
162
163static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
Alex Deucher766a53d2014-09-12 17:51:29 -0400164static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
Dave Airlie0d697042012-09-10 12:28:36 +1000165static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000166
167#endif
Ozan Çağlayand3decf32012-06-14 15:02:35 +0300168#endif /* _LINUX_VGA_SWITCHEROO_H_ */