vgaarb.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #endif
  68. #if defined(CONFIG_VGA_ARB)
  69. extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
  70. #else
  71. static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
  72. #endif
  73. /**
  74. * vga_get_interruptible
  75. * @pdev: pci device of the VGA card or NULL for the system default
  76. * @rsrc: bit mask of resources to acquire and lock
  77. *
  78. * Shortcut to vga_get with interruptible set to true.
  79. *
  80. * On success, release the VGA resource again with vga_put().
  81. */
  82. static inline int vga_get_interruptible(struct pci_dev *pdev,
  83. unsigned int rsrc)
  84. {
  85. return vga_get(pdev, rsrc, 1);
  86. }
  87. /**
  88. * vga_get_uninterruptible - shortcut to vga_get()
  89. * @pdev: pci device of the VGA card or NULL for the system default
  90. * @rsrc: bit mask of resources to acquire and lock
  91. *
  92. * Shortcut to vga_get with interruptible set to false.
  93. *
  94. * On success, release the VGA resource again with vga_put().
  95. */
  96. static inline int vga_get_uninterruptible(struct pci_dev *pdev,
  97. unsigned int rsrc)
  98. {
  99. return vga_get(pdev, rsrc, 0);
  100. }
  101. #if defined(CONFIG_VGA_ARB)
  102. extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
  103. #else
  104. static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; }
  105. #endif
  106. #if defined(CONFIG_VGA_ARB)
  107. extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
  108. #else
  109. #define vga_put(pdev, rsrc)
  110. #endif
  111. #ifdef CONFIG_VGA_ARB
  112. extern struct pci_dev *vga_default_device(void);
  113. extern void vga_set_default_device(struct pci_dev *pdev);
  114. #else
  115. static inline struct pci_dev *vga_default_device(void) { return NULL; };
  116. static inline void vga_set_default_device(struct pci_dev *pdev) { };
  117. #endif
  118. /*
  119. * Architectures should define this if they have several
  120. * independent PCI domains that can afford concurrent VGA
  121. * decoding
  122. */
  123. #ifndef __ARCH_HAS_VGA_CONFLICT
  124. static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
  125. {
  126. return 1;
  127. }
  128. #endif
  129. #if defined(CONFIG_VGA_ARB)
  130. int vga_client_register(struct pci_dev *pdev, void *cookie,
  131. void (*irq_set_state)(void *cookie, bool state),
  132. unsigned int (*set_vga_decode)(void *cookie, bool state));
  133. #else
  134. static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
  135. void (*irq_set_state)(void *cookie, bool state),
  136. unsigned int (*set_vga_decode)(void *cookie, bool state))
  137. {
  138. return 0;
  139. }
  140. #endif
  141. #endif /* LINUX_VGA_H */