Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 1 | /* |
Jesse Barnes | e2d4304 | 2009-09-17 09:40:31 -0700 | [diff] [blame] | 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. |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 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> |
Tiago Vignatti | c0db9cb | 2010-05-24 18:24:31 +0300 | [diff] [blame] | 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 | * |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #ifndef LINUX_VGA_H |
Doug Goldstein | a6a1a09 | 2010-07-20 15:22:25 -0700 | [diff] [blame] | 32 | #define LINUX_VGA_H |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 33 | |
Matthew Garrett | 1a39b31 | 2012-04-16 16:26:02 -0400 | [diff] [blame] | 34 | #include <video/vga.h> |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 35 | |
| 36 | /* Legacy VGA regions */ |
| 37 | #define VGA_RSRC_NONE 0x00 |
| 38 | #define VGA_RSRC_LEGACY_IO 0x01 |
| 39 | #define VGA_RSRC_LEGACY_MEM 0x02 |
| 40 | #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM) |
| 41 | /* Non-legacy access */ |
| 42 | #define VGA_RSRC_NORMAL_IO 0x04 |
| 43 | #define VGA_RSRC_NORMAL_MEM 0x08 |
| 44 | |
| 45 | /* Passing that instead of a pci_dev to use the system "default" |
| 46 | * device, that is the one used by vgacon. Archs will probably |
| 47 | * have to provide their own vga_default_device(); |
| 48 | */ |
| 49 | #define VGA_DEFAULT_DEVICE (NULL) |
| 50 | |
Randy Dunlap | 6069a4c | 2012-01-30 11:43:52 -0800 | [diff] [blame] | 51 | struct pci_dev; |
| 52 | |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 53 | /* For use by clients */ |
| 54 | |
| 55 | /** |
| 56 | * vga_set_legacy_decoding |
| 57 | * |
| 58 | * @pdev: pci device of the VGA card |
| 59 | * @decodes: bit mask of what legacy regions the card decodes |
| 60 | * |
| 61 | * Indicates to the arbiter if the card decodes legacy VGA IOs, |
| 62 | * legacy VGA Memory, both, or none. All cards default to both, |
| 63 | * the card driver (fbdev for example) should tell the arbiter |
| 64 | * if it has disabled legacy decoding, so the card can be left |
| 65 | * out of the arbitration process (and can be safe to take |
| 66 | * interrupts at any time. |
| 67 | */ |
Alex Williamson | 0ea18b4 | 2015-04-07 11:14:38 -0600 | [diff] [blame] | 68 | #if defined(CONFIG_VGA_ARB) |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 69 | extern void vga_set_legacy_decoding(struct pci_dev *pdev, |
Ingo Molnar | 7c32928 | 2009-09-23 09:52:18 +1000 | [diff] [blame] | 70 | unsigned int decodes); |
Alex Williamson | 0ea18b4 | 2015-04-07 11:14:38 -0600 | [diff] [blame] | 71 | #else |
| 72 | static inline void vga_set_legacy_decoding(struct pci_dev *pdev, |
| 73 | unsigned int decodes) { }; |
| 74 | #endif |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 75 | |
Chris Wilson | 04cbe1d | 2010-08-19 21:29:43 +0100 | [diff] [blame] | 76 | #if defined(CONFIG_VGA_ARB) |
| 77 | extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible); |
| 78 | #else |
| 79 | static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; } |
| 80 | #endif |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 81 | |
| 82 | /** |
Daniel Vetter | b754b35 | 2016-08-12 22:48:56 +0200 | [diff] [blame] | 83 | * vga_get_interruptible |
| 84 | * @pdev: pci device of the VGA card or NULL for the system default |
| 85 | * @rsrc: bit mask of resources to acquire and lock |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 86 | * |
Daniel Vetter | b754b35 | 2016-08-12 22:48:56 +0200 | [diff] [blame] | 87 | * Shortcut to vga_get with interruptible set to true. |
| 88 | * |
| 89 | * On success, release the VGA resource again with vga_put(). |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 90 | */ |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 91 | static inline int vga_get_interruptible(struct pci_dev *pdev, |
Dave Airlie | 6ac3bd5 | 2009-08-19 15:21:57 +1000 | [diff] [blame] | 92 | unsigned int rsrc) |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 93 | { |
| 94 | return vga_get(pdev, rsrc, 1); |
| 95 | } |
| 96 | |
| 97 | /** |
Daniel Vetter | b754b35 | 2016-08-12 22:48:56 +0200 | [diff] [blame] | 98 | * vga_get_uninterruptible - shortcut to vga_get() |
| 99 | * @pdev: pci device of the VGA card or NULL for the system default |
| 100 | * @rsrc: bit mask of resources to acquire and lock |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 101 | * |
Daniel Vetter | b754b35 | 2016-08-12 22:48:56 +0200 | [diff] [blame] | 102 | * Shortcut to vga_get with interruptible set to false. |
| 103 | * |
| 104 | * On success, release the VGA resource again with vga_put(). |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 105 | */ |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 106 | static inline int vga_get_uninterruptible(struct pci_dev *pdev, |
Dave Airlie | 6ac3bd5 | 2009-08-19 15:21:57 +1000 | [diff] [blame] | 107 | unsigned int rsrc) |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 108 | { |
| 109 | return vga_get(pdev, rsrc, 0); |
| 110 | } |
| 111 | |
Chris Wilson | 04cbe1d | 2010-08-19 21:29:43 +0100 | [diff] [blame] | 112 | #if defined(CONFIG_VGA_ARB) |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 113 | extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc); |
Chris Wilson | 04cbe1d | 2010-08-19 21:29:43 +0100 | [diff] [blame] | 114 | #else |
| 115 | static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; } |
| 116 | #endif |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 117 | |
Chris Wilson | 04cbe1d | 2010-08-19 21:29:43 +0100 | [diff] [blame] | 118 | #if defined(CONFIG_VGA_ARB) |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 119 | extern void vga_put(struct pci_dev *pdev, unsigned int rsrc); |
Chris Wilson | 04cbe1d | 2010-08-19 21:29:43 +0100 | [diff] [blame] | 120 | #else |
| 121 | #define vga_put(pdev, rsrc) |
| 122 | #endif |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 123 | |
| 124 | |
Matthew Garrett | 6e079d5 | 2012-05-03 09:29:01 +0100 | [diff] [blame] | 125 | #ifdef CONFIG_VGA_ARB |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 126 | extern struct pci_dev *vga_default_device(void); |
Matthew Garrett | 1a39b31 | 2012-04-16 16:26:02 -0400 | [diff] [blame] | 127 | extern void vga_set_default_device(struct pci_dev *pdev); |
Matthew Garrett | 6e079d5 | 2012-05-03 09:29:01 +0100 | [diff] [blame] | 128 | #else |
| 129 | static inline struct pci_dev *vga_default_device(void) { return NULL; }; |
| 130 | static inline void vga_set_default_device(struct pci_dev *pdev) { }; |
| 131 | #endif |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 132 | |
Daniel Vetter | b754b35 | 2016-08-12 22:48:56 +0200 | [diff] [blame] | 133 | /* |
| 134 | * Architectures should define this if they have several |
| 135 | * independent PCI domains that can afford concurrent VGA |
| 136 | * decoding |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 137 | */ |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 138 | #ifndef __ARCH_HAS_VGA_CONFLICT |
| 139 | static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2) |
| 140 | { |
| 141 | return 1; |
| 142 | } |
| 143 | #endif |
| 144 | |
Ingo Molnar | 7c32928 | 2009-09-23 09:52:18 +1000 | [diff] [blame] | 145 | #if defined(CONFIG_VGA_ARB) |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 146 | int vga_client_register(struct pci_dev *pdev, void *cookie, |
| 147 | void (*irq_set_state)(void *cookie, bool state), |
| 148 | unsigned int (*set_vga_decode)(void *cookie, bool state)); |
Ingo Molnar | 7c32928 | 2009-09-23 09:52:18 +1000 | [diff] [blame] | 149 | #else |
| 150 | static inline int vga_client_register(struct pci_dev *pdev, void *cookie, |
| 151 | void (*irq_set_state)(void *cookie, bool state), |
| 152 | unsigned int (*set_vga_decode)(void *cookie, bool state)) |
| 153 | { |
| 154 | return 0; |
| 155 | } |
| 156 | #endif |
Benjamin Herrenschmidt | deb2d2e | 2009-08-11 15:52:06 +1000 | [diff] [blame] | 157 | |
| 158 | #endif /* LINUX_VGA_H */ |