1 /* SPDX-License-Identifier: MIT */ 2 3 /* 4 * The VGA aribiter manages VGA space routing and VGA resource decode to 5 * allow multiple VGA devices to be used in a system in a safe way. 6 * 7 * (C) Copyright 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org> 8 * (C) Copyright 2007 Paulo R. Zanoni <przanoni@gmail.com> 9 * (C) Copyright 2007, 2009 Tiago Vignatti <vignatti@freedesktop.org> 10 */ 11 12 #ifndef LINUX_VGA_H 13 #define LINUX_VGA_H 14 15 #include <video/vga.h> 16 17 struct pci_dev; 18 19 /* Legacy VGA regions */ 20 #define VGA_RSRC_NONE 0x00 21 #define VGA_RSRC_LEGACY_IO 0x01 22 #define VGA_RSRC_LEGACY_MEM 0x02 23 #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM) 24 /* Non-legacy access */ 25 #define VGA_RSRC_NORMAL_IO 0x04 26 #define VGA_RSRC_NORMAL_MEM 0x08 27 28 #ifdef CONFIG_VGA_ARB 29 void vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes); 30 int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible); 31 void vga_put(struct pci_dev *pdev, unsigned int rsrc); 32 struct pci_dev *vga_default_device(void); 33 void vga_set_default_device(struct pci_dev *pdev); 34 int vga_remove_vgacon(struct pci_dev *pdev); 35 int vga_client_register(struct pci_dev *pdev, 36 unsigned int (*set_decode)(void *data, bool state), 37 void *data); 38 #else /* CONFIG_VGA_ARB */ 39 static inline void vga_set_legacy_decoding(struct pci_dev *pdev, 40 unsigned int decodes) 41 { 42 }; 43 static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, 44 int interruptible) 45 { 46 return 0; 47 } 48 static inline void vga_put(struct pci_dev *pdev, unsigned int rsrc) 49 { 50 } 51 static inline struct pci_dev *vga_default_device(void) 52 { 53 return NULL; 54 } 55 static inline void vga_set_default_device(struct pci_dev *pdev) 56 { 57 } 58 static inline int vga_remove_vgacon(struct pci_dev *pdev) 59 { 60 return 0; 61 } 62 static inline int vga_client_register(struct pci_dev *pdev, 63 unsigned int (*set_decode)(void *data, bool state), 64 void *data) 65 { 66 return 0; 67 } 68 #endif /* CONFIG_VGA_ARB */ 69 70 /** 71 * vga_get_interruptible 72 * @pdev: pci device of the VGA card or NULL for the system default 73 * @rsrc: bit mask of resources to acquire and lock 74 * 75 * Shortcut to vga_get with interruptible set to true. 76 * 77 * On success, release the VGA resource again with vga_put(). 78 */ 79 static inline int vga_get_interruptible(struct pci_dev *pdev, 80 unsigned int rsrc) 81 { 82 return vga_get(pdev, rsrc, 1); 83 } 84 85 /** 86 * vga_get_uninterruptible - shortcut to vga_get() 87 * @pdev: pci device of the VGA card or NULL for the system default 88 * @rsrc: bit mask of resources to acquire and lock 89 * 90 * Shortcut to vga_get with interruptible set to false. 91 * 92 * On success, release the VGA resource again with vga_put(). 93 */ 94 static inline int vga_get_uninterruptible(struct pci_dev *pdev, 95 unsigned int rsrc) 96 { 97 return vga_get(pdev, rsrc, 0); 98 } 99 100 static inline void vga_client_unregister(struct pci_dev *pdev) 101 { 102 vga_client_register(pdev, NULL, NULL); 103 } 104 105 #endif /* LINUX_VGA_H */ 106