vgaarb.h 9.0 KB

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