string: factorize skip_spaces and export it to be generally available
[safe/jmp/linux-2.6] / include / linux / vgaarb.h
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
10 #ifndef LINUX_VGA_H
11
12 #include <asm/vga.h>
13
14 /* Legacy VGA regions */
15 #define VGA_RSRC_NONE          0x00
16 #define VGA_RSRC_LEGACY_IO     0x01
17 #define VGA_RSRC_LEGACY_MEM    0x02
18 #define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
19 /* Non-legacy access */
20 #define VGA_RSRC_NORMAL_IO     0x04
21 #define VGA_RSRC_NORMAL_MEM    0x08
22
23 /* Passing that instead of a pci_dev to use the system "default"
24  * device, that is the one used by vgacon. Archs will probably
25  * have to provide their own vga_default_device();
26  */
27 #define VGA_DEFAULT_DEVICE     (NULL)
28
29 /* For use by clients */
30
31 /**
32  *     vga_set_legacy_decoding
33  *
34  *     @pdev: pci device of the VGA card
35  *     @decodes: bit mask of what legacy regions the card decodes
36  *
37  *     Indicates to the arbiter if the card decodes legacy VGA IOs,
38  *     legacy VGA Memory, both, or none. All cards default to both,
39  *     the card driver (fbdev for example) should tell the arbiter
40  *     if it has disabled legacy decoding, so the card can be left
41  *     out of the arbitration process (and can be safe to take
42  *     interrupts at any time.
43  */
44 extern void vga_set_legacy_decoding(struct pci_dev *pdev,
45                                     unsigned int decodes);
46
47 /**
48  *     vga_get         - acquire & locks VGA resources
49  *
50  *     @pdev: pci device of the VGA card or NULL for the system default
51  *     @rsrc: bit mask of resources to acquire and lock
52  *     @interruptible: blocking should be interruptible by signals ?
53  *
54  *     This function acquires VGA resources for the given
55  *     card and mark those resources locked. If the resource requested
56  *     are "normal" (and not legacy) resources, the arbiter will first check
57  *     wether the card is doing legacy decoding for that type of resource. If
58  *     yes, the lock is "converted" into a legacy resource lock.
59  *     The arbiter will first look for all VGA cards that might conflict
60  *     and disable their IOs and/or Memory access, inlcuding VGA forwarding
61  *     on P2P bridges if necessary, so that the requested resources can
62  *     be used. Then, the card is marked as locking these resources and
63  *     the IO and/or Memory accesse are enabled on the card (including
64  *     VGA forwarding on parent P2P bridges if any).
65  *     This function will block if some conflicting card is already locking
66  *     one of the required resources (or any resource on a different bus
67  *     segment, since P2P bridges don't differenciate VGA memory and IO
68  *     afaik). You can indicate wether this blocking should be interruptible
69  *     by a signal (for userland interface) or not.
70  *     Must not be called at interrupt time or in atomic context.
71  *     If the card already owns the resources, the function succeeds.
72  *     Nested calls are supported (a per-resource counter is maintained)
73  */
74
75 extern int vga_get(struct pci_dev *pdev, unsigned int rsrc,
76                                                                                         int interruptible);
77
78 /**
79  *     vga_get_interruptible
80  *
81  *     Shortcut to vga_get
82  */
83
84 static inline int vga_get_interruptible(struct pci_dev *pdev,
85                                         unsigned int rsrc)
86 {
87        return vga_get(pdev, rsrc, 1);
88 }
89
90 /**
91  *     vga_get_uninterruptible
92  *
93  *     Shortcut to vga_get
94  */
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
102 /**
103  *     vga_tryget      - try to acquire & lock legacy VGA resources
104  *
105  *     @pdev: pci devivce of VGA card or NULL for system default
106  *     @rsrc: bit mask of resources to acquire and lock
107  *
108  *     This function performs the same operation as vga_get(), but
109  *     will return an error (-EBUSY) instead of blocking if the resources
110  *     are already locked by another card. It can be called in any context
111  */
112
113 extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
114
115 /**
116  *     vga_put         - release lock on legacy VGA resources
117  *
118  *     @pdev: pci device of VGA card or NULL for system default
119  *     @rsrc: but mask of resource to release
120  *
121  *     This function releases resources previously locked by vga_get()
122  *     or vga_tryget(). The resources aren't disabled right away, so
123  *     that a subsequence vga_get() on the same card will succeed
124  *     immediately. Resources have a counter, so locks are only
125  *     released if the counter reaches 0.
126  */
127
128 extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
129
130
131 /**
132  *     vga_default_device
133  *
134  *     This can be defined by the platform. The default implementation
135  *     is rather dumb and will probably only work properly on single
136  *     vga card setups and/or x86 platforms.
137  *
138  *     If your VGA default device is not PCI, you'll have to return
139  *     NULL here. In this case, I assume it will not conflict with
140  *     any PCI card. If this is not true, I'll have to define two archs
141  *     hooks for enabling/disabling the VGA default device if that is
142  *     possible. This may be a problem with real _ISA_ VGA cards, in
143  *     addition to a PCI one. I don't know at this point how to deal
144  *     with that card. Can theirs IOs be disabled at all ? If not, then
145  *     I suppose it's a matter of having the proper arch hook telling
146  *     us about it, so we basically never allow anybody to succeed a
147  *     vga_get()...
148  */
149
150 #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
151 extern struct pci_dev *vga_default_device(void);
152 #endif
153
154 /**
155  *     vga_conflicts
156  *
157  *     Architectures should define this if they have several
158  *     independant PCI domains that can afford concurrent VGA
159  *     decoding
160  */
161
162 #ifndef __ARCH_HAS_VGA_CONFLICT
163 static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
164 {
165        return 1;
166 }
167 #endif
168
169 /**
170  *      vga_client_register
171  *
172  *      @pdev: pci device of the VGA client
173  *      @cookie: client cookie to be used in callbacks
174  *      @irq_set_state: irq state change callback
175  *      @set_vga_decode: vga decode change callback
176  *
177  *      return value: 0 on success, -1 on failure
178  *      Register a client with the VGA arbitration logic
179  *
180  *      Clients have two callback mechanisms they can use.
181  *      irq enable/disable callback -
182  *              If a client can't disable its GPUs VGA resources, then we
183  *              need to be able to ask it to turn off its irqs when we
184  *              turn off its mem and io decoding.
185  *      set_vga_decode
186  *              If a client can disable its GPU VGA resource, it will
187  *              get a callback from this to set the encode/decode state
188  *
189  * Rationale: we cannot disable VGA decode resources unconditionally
190  * some single GPU laptops seem to require ACPI or BIOS access to the
191  * VGA registers to control things like backlights etc.
192  * Hopefully newer multi-GPU laptops do something saner, and desktops
193  * won't have any special ACPI for this.
194  * They driver will get a callback when VGA arbitration is first used
195  * by userspace since we some older X servers have issues.
196  */
197 #if defined(CONFIG_VGA_ARB)
198 int vga_client_register(struct pci_dev *pdev, void *cookie,
199                         void (*irq_set_state)(void *cookie, bool state),
200                         unsigned int (*set_vga_decode)(void *cookie, bool state));
201 #else
202 static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
203                                       void (*irq_set_state)(void *cookie, bool state),
204                                       unsigned int (*set_vga_decode)(void *cookie, bool state))
205 {
206         return 0;
207 }
208 #endif
209
210 #endif /* LINUX_VGA_H */