vgaarb.h 7.1 KB

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