vga_switcheroo.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * vga_switcheroo.h - Support for laptop with dual GPU using one set of outputs
  3. *
  4. * Copyright (c) 2010 Red Hat Inc.
  5. * Author : Dave Airlie <airlied@redhat.com>
  6. *
  7. * Copyright (c) 2015 Lukas Wunner <lukas@wunner.de>
  8. *
  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. *
  29. */
  30. #ifndef _LINUX_VGA_SWITCHEROO_H_
  31. #define _LINUX_VGA_SWITCHEROO_H_
  32. #include <linux/fb.h>
  33. struct pci_dev;
  34. /**
  35. * enum vga_switcheroo_state - client power state
  36. * @VGA_SWITCHEROO_OFF: off
  37. * @VGA_SWITCHEROO_ON: on
  38. * @VGA_SWITCHEROO_NOT_FOUND: client has not registered with vga_switcheroo.
  39. * Only used in vga_switcheroo_get_client_state() which in turn is only
  40. * called from hda_intel.c
  41. *
  42. * Client power state.
  43. */
  44. enum vga_switcheroo_state {
  45. VGA_SWITCHEROO_OFF,
  46. VGA_SWITCHEROO_ON,
  47. /* below are referred only from vga_switcheroo_get_client_state() */
  48. VGA_SWITCHEROO_NOT_FOUND,
  49. };
  50. /**
  51. * enum vga_switcheroo_client_id - client identifier
  52. * @VGA_SWITCHEROO_UNKNOWN_ID: initial identifier assigned to vga clients.
  53. * Determining the id requires the handler, so GPUs are given their
  54. * true id in a delayed fashion in vga_switcheroo_enable()
  55. * @VGA_SWITCHEROO_IGD: integrated graphics device
  56. * @VGA_SWITCHEROO_DIS: discrete graphics device
  57. * @VGA_SWITCHEROO_MAX_CLIENTS: currently no more than two GPUs are supported
  58. *
  59. * Client identifier. Audio clients use the same identifier & 0x100.
  60. */
  61. enum vga_switcheroo_client_id {
  62. VGA_SWITCHEROO_UNKNOWN_ID = -1,
  63. VGA_SWITCHEROO_IGD,
  64. VGA_SWITCHEROO_DIS,
  65. VGA_SWITCHEROO_MAX_CLIENTS,
  66. };
  67. /**
  68. * struct vga_switcheroo_handler - handler callbacks
  69. * @init: initialize handler.
  70. * Optional. This gets called when vga_switcheroo is enabled, i.e. when
  71. * two vga clients have registered. It allows the handler to perform
  72. * some delayed initialization that depends on the existence of the
  73. * vga clients. Currently only the radeon and amdgpu drivers use this.
  74. * The return value is ignored
  75. * @switchto: switch outputs to given client.
  76. * Mandatory. For muxless machines this should be a no-op. Returning 0
  77. * denotes success, anything else failure (in which case the switch is
  78. * aborted)
  79. * @power_state: cut or reinstate power of given client.
  80. * Optional. The return value is ignored
  81. * @get_client_id: determine if given pci device is integrated or discrete GPU.
  82. * Mandatory
  83. *
  84. * Handler callbacks. The multiplexer itself. The @switchto and @get_client_id
  85. * methods are mandatory, all others may be set to NULL.
  86. */
  87. struct vga_switcheroo_handler {
  88. int (*init)(void);
  89. int (*switchto)(enum vga_switcheroo_client_id id);
  90. int (*power_state)(enum vga_switcheroo_client_id id,
  91. enum vga_switcheroo_state state);
  92. enum vga_switcheroo_client_id (*get_client_id)(struct pci_dev *pdev);
  93. };
  94. /**
  95. * struct vga_switcheroo_client_ops - client callbacks
  96. * @set_gpu_state: do the equivalent of suspend/resume for the card.
  97. * Mandatory. This should not cut power to the discrete GPU,
  98. * which is the job of the handler
  99. * @reprobe: poll outputs.
  100. * Optional. This gets called after waking the GPU and switching
  101. * the outputs to it
  102. * @can_switch: check if the device is in a position to switch now.
  103. * Mandatory. The client should return false if a user space process
  104. * has one of its device files open
  105. *
  106. * Client callbacks. A client can be either a GPU or an audio device on a GPU.
  107. * The @set_gpu_state and @can_switch methods are mandatory, @reprobe may be
  108. * set to NULL. For audio clients, the @reprobe member is bogus.
  109. */
  110. struct vga_switcheroo_client_ops {
  111. void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state);
  112. void (*reprobe)(struct pci_dev *dev);
  113. bool (*can_switch)(struct pci_dev *dev);
  114. };
  115. #if defined(CONFIG_VGA_SWITCHEROO)
  116. void vga_switcheroo_unregister_client(struct pci_dev *dev);
  117. int vga_switcheroo_register_client(struct pci_dev *dev,
  118. const struct vga_switcheroo_client_ops *ops,
  119. bool driver_power_control);
  120. int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
  121. const struct vga_switcheroo_client_ops *ops,
  122. enum vga_switcheroo_client_id id);
  123. void vga_switcheroo_client_fb_set(struct pci_dev *dev,
  124. struct fb_info *info);
  125. int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler);
  126. void vga_switcheroo_unregister_handler(void);
  127. int vga_switcheroo_process_delayed_switch(void);
  128. enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev);
  129. void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
  130. int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
  131. void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
  132. int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
  133. #else
  134. static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
  135. static inline int vga_switcheroo_register_client(struct pci_dev *dev,
  136. const struct vga_switcheroo_client_ops *ops, bool driver_power_control) { return 0; }
  137. static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
  138. static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_handler *handler) { return 0; }
  139. static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
  140. const struct vga_switcheroo_client_ops *ops,
  141. enum vga_switcheroo_client_id id) { return 0; }
  142. static inline void vga_switcheroo_unregister_handler(void) {}
  143. static inline int vga_switcheroo_process_delayed_switch(void) { return 0; }
  144. static inline enum vga_switcheroo_state vga_switcheroo_get_client_state(struct pci_dev *dev) { return VGA_SWITCHEROO_ON; }
  145. static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
  146. static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
  147. static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
  148. static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
  149. #endif
  150. #endif /* _LINUX_VGA_SWITCHEROO_H_ */