vgaarb.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * The VGA aribiter manages VGA space routing and VGA resource decode to
  3. * allow multiple VGA devices to be used in a system in a safe way.
  4. *
  5. * (C) Copyright 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
  6. * (C) Copyright 2007 Paulo R. Zanoni <przanoni@gmail.com>
  7. * (C) Copyright 2007, 2009 Tiago Vignatti <vignatti@freedesktop.org>
  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_H
  31. #define LINUX_VGA_H
  32. #include <video/vga.h>
  33. /* Legacy VGA regions */
  34. #define VGA_RSRC_NONE 0x00
  35. #define VGA_RSRC_LEGACY_IO 0x01
  36. #define VGA_RSRC_LEGACY_MEM 0x02
  37. #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
  38. /* Non-legacy access */
  39. #define VGA_RSRC_NORMAL_IO 0x04
  40. #define VGA_RSRC_NORMAL_MEM 0x08
  41. /* Passing that instead of a pci_dev to use the system "default"
  42. * device, that is the one used by vgacon. Archs will probably
  43. * have to provide their own vga_default_device();
  44. */
  45. #define VGA_DEFAULT_DEVICE (NULL)
  46. struct pci_dev;
  47. /* For use by clients */
  48. /**
  49. * vga_set_legacy_decoding
  50. *
  51. * @pdev: pci device of the VGA card
  52. * @decodes: bit mask of what legacy regions the card decodes
  53. *
  54. * Indicates to the arbiter if the card decodes legacy VGA IOs,
  55. * legacy VGA Memory, both, or none. All cards default to both,
  56. * the card driver (fbdev for example) should tell the arbiter
  57. * if it has disabled legacy decoding, so the card can be left
  58. * out of the arbitration process (and can be safe to take
  59. * interrupts at any time.
  60. */
  61. #if defined(CONFIG_VGA_ARB)
  62. extern void vga_set_legacy_decoding(struct pci_dev *pdev,
  63. unsigned int decodes);
  64. #else
  65. static inline void vga_set_legacy_decoding(struct pci_dev *pdev,
  66. unsigned int decodes)
  67. {
  68. }
  69. #endif
  70. /**
  71. * vga_get - acquire & locks VGA resources
  72. *
  73. * @pdev: pci device of the VGA card or NULL for the system default
  74. * @rsrc: bit mask of resources to acquire and lock
  75. * @interruptible: blocking should be interruptible by signals ?
  76. *
  77. * This function acquires VGA resources for the given
  78. * card and mark those resources locked. If the resource requested
  79. * are "normal" (and not legacy) resources, the arbiter will first check
  80. * whether the card is doing legacy decoding for that type of resource. If
  81. * yes, the lock is "converted" into a legacy resource lock.
  82. * The arbiter will first look for all VGA cards that might conflict
  83. * and disable their IOs and/or Memory access, including VGA forwarding
  84. * on P2P bridges if necessary, so that the requested resources can
  85. * be used. Then, the card is marked as locking these resources and
  86. * the IO and/or Memory accesse are enabled on the card (including
  87. * VGA forwarding on parent P2P bridges if any).
  88. * This function will block if some conflicting card is already locking
  89. * one of the required resources (or any resource on a different bus
  90. * segment, since P2P bridges don't differenciate VGA memory and IO
  91. * afaik). You can indicate whether this blocking should be interruptible
  92. * by a signal (for userland interface) or not.
  93. * Must not be called at interrupt time or in atomic context.
  94. * If the card already owns the resources, the function succeeds.
  95. * Nested calls are supported (a per-resource counter is maintained)
  96. */
  97. #if defined(CONFIG_VGA_ARB)
  98. extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
  99. #else
  100. static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
  101. #endif
  102. /**
  103. * vga_get_interruptible
  104. *
  105. * Shortcut to vga_get
  106. */
  107. static inline int vga_get_interruptible(struct pci_dev *pdev,
  108. unsigned int rsrc)
  109. {
  110. return vga_get(pdev, rsrc, 1);
  111. }
  112. /**
  113. * vga_get_uninterruptible
  114. *
  115. * Shortcut to vga_get
  116. */
  117. static inline int vga_get_uninterruptible(struct pci_dev *pdev,
  118. unsigned int rsrc)
  119. {
  120. return vga_get(pdev, rsrc, 0);
  121. }
  122. /**
  123. * vga_tryget - try to acquire & lock legacy VGA resources
  124. *
  125. * @pdev: pci devivce of VGA card or NULL for system default
  126. * @rsrc: bit mask of resources to acquire and lock
  127. *
  128. * This function performs the same operation as vga_get(), but
  129. * will return an error (-EBUSY) instead of blocking if the resources
  130. * are already locked by another card. It can be called in any context
  131. */
  132. #if defined(CONFIG_VGA_ARB)
  133. extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
  134. #else
  135. static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; }
  136. #endif
  137. /**
  138. * vga_put - release lock on legacy VGA resources
  139. *
  140. * @pdev: pci device of VGA card or NULL for system default
  141. * @rsrc: but mask of resource to release
  142. *
  143. * This function releases resources previously locked by vga_get()
  144. * or vga_tryget(). The resources aren't disabled right away, so
  145. * that a subsequence vga_get() on the same card will succeed
  146. * immediately. Resources have a counter, so locks are only
  147. * released if the counter reaches 0.
  148. */
  149. #if defined(CONFIG_VGA_ARB)
  150. extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
  151. #else
  152. #define vga_put(pdev, rsrc)
  153. #endif
  154. /**
  155. * vga_default_device
  156. *
  157. * This can be defined by the platform. The default implementation
  158. * is rather dumb and will probably only work properly on single
  159. * vga card setups and/or x86 platforms.
  160. *
  161. * If your VGA default device is not PCI, you'll have to return
  162. * NULL here. In this case, I assume it will not conflict with
  163. * any PCI card. If this is not true, I'll have to define two archs
  164. * hooks for enabling/disabling the VGA default device if that is
  165. * possible. This may be a problem with real _ISA_ VGA cards, in
  166. * addition to a PCI one. I don't know at this point how to deal
  167. * with that card. Can theirs IOs be disabled at all ? If not, then
  168. * I suppose it's a matter of having the proper arch hook telling
  169. * us about it, so we basically never allow anybody to succeed a
  170. * vga_get()...
  171. */
  172. #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
  173. #ifdef CONFIG_VGA_ARB
  174. extern struct pci_dev *vga_default_device(void);
  175. extern void vga_set_default_device(struct pci_dev *pdev);
  176. #else
  177. static inline struct pci_dev *vga_default_device(void) { return NULL; };
  178. static inline void vga_set_default_device(struct pci_dev *pdev) { };
  179. #endif
  180. #endif
  181. /**
  182. * vga_conflicts
  183. *
  184. * Architectures should define this if they have several
  185. * independent PCI domains that can afford concurrent VGA
  186. * decoding
  187. */
  188. #ifndef __ARCH_HAS_VGA_CONFLICT
  189. static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
  190. {
  191. return 1;
  192. }
  193. #endif
  194. /**
  195. * vga_client_register
  196. *
  197. * @pdev: pci device of the VGA client
  198. * @cookie: client cookie to be used in callbacks
  199. * @irq_set_state: irq state change callback
  200. * @set_vga_decode: vga decode change callback
  201. *
  202. * return value: 0 on success, -1 on failure
  203. * Register a client with the VGA arbitration logic
  204. *
  205. * Clients have two callback mechanisms they can use.
  206. * irq enable/disable callback -
  207. * If a client can't disable its GPUs VGA resources, then we
  208. * need to be able to ask it to turn off its irqs when we
  209. * turn off its mem and io decoding.
  210. * set_vga_decode
  211. * If a client can disable its GPU VGA resource, it will
  212. * get a callback from this to set the encode/decode state
  213. *
  214. * Rationale: we cannot disable VGA decode resources unconditionally
  215. * some single GPU laptops seem to require ACPI or BIOS access to the
  216. * VGA registers to control things like backlights etc.
  217. * Hopefully newer multi-GPU laptops do something saner, and desktops
  218. * won't have any special ACPI for this.
  219. * They driver will get a callback when VGA arbitration is first used
  220. * by userspace since we some older X servers have issues.
  221. */
  222. #if defined(CONFIG_VGA_ARB)
  223. int vga_client_register(struct pci_dev *pdev, void *cookie,
  224. void (*irq_set_state)(void *cookie, bool state),
  225. unsigned int (*set_vga_decode)(void *cookie, bool state));
  226. #else
  227. static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
  228. void (*irq_set_state)(void *cookie, bool state),
  229. unsigned int (*set_vga_decode)(void *cookie, bool state))
  230. {
  231. return 0;
  232. }
  233. #endif
  234. #endif /* LINUX_VGA_H */