xref: /OK3568_Linux_fs/kernel/include/linux/vgaarb.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * The VGA aribiter manages VGA space routing and VGA resource decode to
3*4882a593Smuzhiyun  * allow multiple VGA devices to be used in a system in a safe way.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * (C) Copyright 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
6*4882a593Smuzhiyun  * (C) Copyright 2007 Paulo R. Zanoni <przanoni@gmail.com>
7*4882a593Smuzhiyun  * (C) Copyright 2007, 2009 Tiago Vignatti <vignatti@freedesktop.org>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
10*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
11*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
12*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
14*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
17*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
18*4882a593Smuzhiyun  * Software.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23*4882a593Smuzhiyun  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26*4882a593Smuzhiyun  * DEALINGS
27*4882a593Smuzhiyun  * IN THE SOFTWARE.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifndef LINUX_VGA_H
32*4882a593Smuzhiyun #define LINUX_VGA_H
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #include <video/vga.h>
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* Legacy VGA regions */
37*4882a593Smuzhiyun #define VGA_RSRC_NONE	       0x00
38*4882a593Smuzhiyun #define VGA_RSRC_LEGACY_IO     0x01
39*4882a593Smuzhiyun #define VGA_RSRC_LEGACY_MEM    0x02
40*4882a593Smuzhiyun #define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
41*4882a593Smuzhiyun /* Non-legacy access */
42*4882a593Smuzhiyun #define VGA_RSRC_NORMAL_IO     0x04
43*4882a593Smuzhiyun #define VGA_RSRC_NORMAL_MEM    0x08
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* Passing that instead of a pci_dev to use the system "default"
46*4882a593Smuzhiyun  * device, that is the one used by vgacon. Archs will probably
47*4882a593Smuzhiyun  * have to provide their own vga_default_device();
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun #define VGA_DEFAULT_DEVICE     (NULL)
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun struct pci_dev;
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /* For use by clients */
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /**
56*4882a593Smuzhiyun  *     vga_set_legacy_decoding
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  *     @pdev: pci device of the VGA card
59*4882a593Smuzhiyun  *     @decodes: bit mask of what legacy regions the card decodes
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  *     Indicates to the arbiter if the card decodes legacy VGA IOs,
62*4882a593Smuzhiyun  *     legacy VGA Memory, both, or none. All cards default to both,
63*4882a593Smuzhiyun  *     the card driver (fbdev for example) should tell the arbiter
64*4882a593Smuzhiyun  *     if it has disabled legacy decoding, so the card can be left
65*4882a593Smuzhiyun  *     out of the arbitration process (and can be safe to take
66*4882a593Smuzhiyun  *     interrupts at any time.
67*4882a593Smuzhiyun  */
68*4882a593Smuzhiyun #if defined(CONFIG_VGA_ARB)
69*4882a593Smuzhiyun extern void vga_set_legacy_decoding(struct pci_dev *pdev,
70*4882a593Smuzhiyun 				    unsigned int decodes);
71*4882a593Smuzhiyun #else
vga_set_legacy_decoding(struct pci_dev * pdev,unsigned int decodes)72*4882a593Smuzhiyun static inline void vga_set_legacy_decoding(struct pci_dev *pdev,
73*4882a593Smuzhiyun 					   unsigned int decodes) { };
74*4882a593Smuzhiyun #endif
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #if defined(CONFIG_VGA_ARB)
77*4882a593Smuzhiyun extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
78*4882a593Smuzhiyun #else
vga_get(struct pci_dev * pdev,unsigned int rsrc,int interruptible)79*4882a593Smuzhiyun static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
80*4882a593Smuzhiyun #endif
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /**
83*4882a593Smuzhiyun  * vga_get_interruptible
84*4882a593Smuzhiyun  * @pdev: pci device of the VGA card or NULL for the system default
85*4882a593Smuzhiyun  * @rsrc: bit mask of resources to acquire and lock
86*4882a593Smuzhiyun  *
87*4882a593Smuzhiyun  * Shortcut to vga_get with interruptible set to true.
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * On success, release the VGA resource again with vga_put().
90*4882a593Smuzhiyun  */
vga_get_interruptible(struct pci_dev * pdev,unsigned int rsrc)91*4882a593Smuzhiyun static inline int vga_get_interruptible(struct pci_dev *pdev,
92*4882a593Smuzhiyun 					unsigned int rsrc)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun        return vga_get(pdev, rsrc, 1);
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /**
98*4882a593Smuzhiyun  * vga_get_uninterruptible - shortcut to vga_get()
99*4882a593Smuzhiyun  * @pdev: pci device of the VGA card or NULL for the system default
100*4882a593Smuzhiyun  * @rsrc: bit mask of resources to acquire and lock
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  * Shortcut to vga_get with interruptible set to false.
103*4882a593Smuzhiyun  *
104*4882a593Smuzhiyun  * On success, release the VGA resource again with vga_put().
105*4882a593Smuzhiyun  */
vga_get_uninterruptible(struct pci_dev * pdev,unsigned int rsrc)106*4882a593Smuzhiyun static inline int vga_get_uninterruptible(struct pci_dev *pdev,
107*4882a593Smuzhiyun 					  unsigned int rsrc)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun        return vga_get(pdev, rsrc, 0);
110*4882a593Smuzhiyun }
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun #if defined(CONFIG_VGA_ARB)
113*4882a593Smuzhiyun extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
114*4882a593Smuzhiyun #else
115*4882a593Smuzhiyun #define vga_put(pdev, rsrc)
116*4882a593Smuzhiyun #endif
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun #ifdef CONFIG_VGA_ARB
120*4882a593Smuzhiyun extern struct pci_dev *vga_default_device(void);
121*4882a593Smuzhiyun extern void vga_set_default_device(struct pci_dev *pdev);
122*4882a593Smuzhiyun extern int vga_remove_vgacon(struct pci_dev *pdev);
123*4882a593Smuzhiyun #else
vga_default_device(void)124*4882a593Smuzhiyun static inline struct pci_dev *vga_default_device(void) { return NULL; };
vga_set_default_device(struct pci_dev * pdev)125*4882a593Smuzhiyun static inline void vga_set_default_device(struct pci_dev *pdev) { };
vga_remove_vgacon(struct pci_dev * pdev)126*4882a593Smuzhiyun static inline int vga_remove_vgacon(struct pci_dev *pdev) { return 0; };
127*4882a593Smuzhiyun #endif
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun /*
130*4882a593Smuzhiyun  * Architectures should define this if they have several
131*4882a593Smuzhiyun  * independent PCI domains that can afford concurrent VGA
132*4882a593Smuzhiyun  * decoding
133*4882a593Smuzhiyun  */
134*4882a593Smuzhiyun #ifndef __ARCH_HAS_VGA_CONFLICT
vga_conflicts(struct pci_dev * p1,struct pci_dev * p2)135*4882a593Smuzhiyun static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun        return 1;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun #endif
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun #if defined(CONFIG_VGA_ARB)
142*4882a593Smuzhiyun int vga_client_register(struct pci_dev *pdev, void *cookie,
143*4882a593Smuzhiyun 			void (*irq_set_state)(void *cookie, bool state),
144*4882a593Smuzhiyun 			unsigned int (*set_vga_decode)(void *cookie, bool state));
145*4882a593Smuzhiyun #else
vga_client_register(struct pci_dev * pdev,void * cookie,void (* irq_set_state)(void * cookie,bool state),unsigned int (* set_vga_decode)(void * cookie,bool state))146*4882a593Smuzhiyun static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
147*4882a593Smuzhiyun 				      void (*irq_set_state)(void *cookie, bool state),
148*4882a593Smuzhiyun 				      unsigned int (*set_vga_decode)(void *cookie, bool state))
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun 	return 0;
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun #endif
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun #endif /* LINUX_VGA_H */
155