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 <[email protected]> 6 * (C) Copyright 2007 Paulo R. Zanoni <[email protected]> 7 * (C) Copyright 2007, 2009 Tiago Vignatti <[email protected]> 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 31 #ifndef LINUX_VGA_H 32 #define LINUX_VGA_H 33 34 #include <video/vga.h> 35 36 struct pci_dev; 37 38 /* Legacy VGA regions */ 39 #define VGA_RSRC_NONE 0x00 40 #define VGA_RSRC_LEGACY_IO 0x01 41 #define VGA_RSRC_LEGACY_MEM 0x02 42 #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM) 43 /* Non-legacy access */ 44 #define VGA_RSRC_NORMAL_IO 0x04 45 #define VGA_RSRC_NORMAL_MEM 0x08 46 47 #ifdef CONFIG_VGA_ARB 48 void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes); 49 int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible); 50 void vga_put(struct pci_dev *pdev, unsigned int rsrc); 51 struct pci_dev *vga_default_device(void); 52 void vga_set_default_device(struct pci_dev *pdev); 53 int vga_remove_vgacon(struct pci_dev *pdev); 54 int vga_client_register(struct pci_dev *pdev, 55 unsigned int (*set_decode)(struct pci_dev *pdev, bool state)); 56 #else /* CONFIG_VGA_ARB */ 57 static inline void vga_set_legacy_decoding(struct pci_dev *pdev, 58 unsigned int decodes) 59 { 60 }; 61 static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, 62 int interruptible) 63 { 64 return 0; 65 } 66 static inline void vga_put(struct pci_dev *pdev, unsigned int rsrc) 67 { 68 } 69 static inline struct pci_dev *vga_default_device(void) 70 { 71 return NULL; 72 } 73 static inline void vga_set_default_device(struct pci_dev *pdev) 74 { 75 } 76 static inline int vga_remove_vgacon(struct pci_dev *pdev) 77 { 78 return 0; 79 } 80 static inline int vga_client_register(struct pci_dev *pdev, 81 unsigned int (*set_decode)(struct pci_dev *pdev, bool state)) 82 { 83 return 0; 84 } 85 #endif /* CONFIG_VGA_ARB */ 86 87 /** 88 * vga_get_interruptible 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 true. 93 * 94 * On success, release the VGA resource again with vga_put(). 95 */ 96 static inline int vga_get_interruptible(struct pci_dev *pdev, 97 unsigned int rsrc) 98 { 99 return vga_get(pdev, rsrc, 1); 100 } 101 102 /** 103 * vga_get_uninterruptible - shortcut to vga_get() 104 * @pdev: pci device of the VGA card or NULL for the system default 105 * @rsrc: bit mask of resources to acquire and lock 106 * 107 * Shortcut to vga_get with interruptible set to false. 108 * 109 * On success, release the VGA resource again with vga_put(). 110 */ 111 static inline int vga_get_uninterruptible(struct pci_dev *pdev, 112 unsigned int rsrc) 113 { 114 return vga_get(pdev, rsrc, 0); 115 } 116 117 static inline void vga_client_unregister(struct pci_dev *pdev) 118 { 119 vga_client_register(pdev, NULL); 120 } 121 122 #endif /* LINUX_VGA_H */ 123