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.
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>
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:
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
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
35 /* Legacy VGA regions */
36 #define VGA_RSRC_NONE 0x00
37 #define VGA_RSRC_LEGACY_IO 0x01
38 #define VGA_RSRC_LEGACY_MEM 0x02
39 #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
40 /* Non-legacy access */
41 #define VGA_RSRC_NORMAL_IO 0x04
42 #define VGA_RSRC_NORMAL_MEM 0x08
44 /* Passing that instead of a pci_dev to use the system "default"
45 * device, that is the one used by vgacon. Archs will probably
46 * have to provide their own vga_default_device();
48 #define VGA_DEFAULT_DEVICE (NULL)
50 /* For use by clients */
53 * vga_set_legacy_decoding
55 * @pdev: pci device of the VGA card
56 * @decodes: bit mask of what legacy regions the card decodes
58 * Indicates to the arbiter if the card decodes legacy VGA IOs,
59 * legacy VGA Memory, both, or none. All cards default to both,
60 * the card driver (fbdev for example) should tell the arbiter
61 * if it has disabled legacy decoding, so the card can be left
62 * out of the arbitration process (and can be safe to take
63 * interrupts at any time.
65 extern void vga_set_legacy_decoding(struct pci_dev
*pdev
,
66 unsigned int decodes
);
69 * vga_get - acquire & locks VGA resources
71 * @pdev: pci device of the VGA card or NULL for the system default
72 * @rsrc: bit mask of resources to acquire and lock
73 * @interruptible: blocking should be interruptible by signals ?
75 * This function acquires VGA resources for the given
76 * card and mark those resources locked. If the resource requested
77 * are "normal" (and not legacy) resources, the arbiter will first check
78 * wether the card is doing legacy decoding for that type of resource. If
79 * yes, the lock is "converted" into a legacy resource lock.
80 * The arbiter will first look for all VGA cards that might conflict
81 * and disable their IOs and/or Memory access, including VGA forwarding
82 * on P2P bridges if necessary, so that the requested resources can
83 * be used. Then, the card is marked as locking these resources and
84 * the IO and/or Memory accesse are enabled on the card (including
85 * VGA forwarding on parent P2P bridges if any).
86 * This function will block if some conflicting card is already locking
87 * one of the required resources (or any resource on a different bus
88 * segment, since P2P bridges don't differenciate VGA memory and IO
89 * afaik). You can indicate wether this blocking should be interruptible
90 * by a signal (for userland interface) or not.
91 * Must not be called at interrupt time or in atomic context.
92 * If the card already owns the resources, the function succeeds.
93 * Nested calls are supported (a per-resource counter is maintained)
96 #if defined(CONFIG_VGA_ARB)
97 extern int vga_get(struct pci_dev
*pdev
, unsigned int rsrc
, int interruptible
);
99 static inline int vga_get(struct pci_dev
*pdev
, unsigned int rsrc
, int interruptible
) { return 0; }
103 * vga_get_interruptible
105 * Shortcut to vga_get
108 static inline int vga_get_interruptible(struct pci_dev
*pdev
,
111 return vga_get(pdev
, rsrc
, 1);
115 * vga_get_uninterruptible
117 * Shortcut to vga_get
120 static inline int vga_get_uninterruptible(struct pci_dev
*pdev
,
123 return vga_get(pdev
, rsrc
, 0);
127 * vga_tryget - try to acquire & lock legacy VGA resources
129 * @pdev: pci devivce of VGA card or NULL for system default
130 * @rsrc: bit mask of resources to acquire and lock
132 * This function performs the same operation as vga_get(), but
133 * will return an error (-EBUSY) instead of blocking if the resources
134 * are already locked by another card. It can be called in any context
137 #if defined(CONFIG_VGA_ARB)
138 extern int vga_tryget(struct pci_dev
*pdev
, unsigned int rsrc
);
140 static inline int vga_tryget(struct pci_dev
*pdev
, unsigned int rsrc
) { return 0; }
144 * vga_put - release lock on legacy VGA resources
146 * @pdev: pci device of VGA card or NULL for system default
147 * @rsrc: but mask of resource to release
149 * This function releases resources previously locked by vga_get()
150 * or vga_tryget(). The resources aren't disabled right away, so
151 * that a subsequence vga_get() on the same card will succeed
152 * immediately. Resources have a counter, so locks are only
153 * released if the counter reaches 0.
156 #if defined(CONFIG_VGA_ARB)
157 extern void vga_put(struct pci_dev
*pdev
, unsigned int rsrc
);
159 #define vga_put(pdev, rsrc)
166 * This can be defined by the platform. The default implementation
167 * is rather dumb and will probably only work properly on single
168 * vga card setups and/or x86 platforms.
170 * If your VGA default device is not PCI, you'll have to return
171 * NULL here. In this case, I assume it will not conflict with
172 * any PCI card. If this is not true, I'll have to define two archs
173 * hooks for enabling/disabling the VGA default device if that is
174 * possible. This may be a problem with real _ISA_ VGA cards, in
175 * addition to a PCI one. I don't know at this point how to deal
176 * with that card. Can theirs IOs be disabled at all ? If not, then
177 * I suppose it's a matter of having the proper arch hook telling
178 * us about it, so we basically never allow anybody to succeed a
182 #ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
183 extern struct pci_dev
*vga_default_device(void);
189 * Architectures should define this if they have several
190 * independent PCI domains that can afford concurrent VGA
194 #ifndef __ARCH_HAS_VGA_CONFLICT
195 static inline int vga_conflicts(struct pci_dev
*p1
, struct pci_dev
*p2
)
202 * vga_client_register
204 * @pdev: pci device of the VGA client
205 * @cookie: client cookie to be used in callbacks
206 * @irq_set_state: irq state change callback
207 * @set_vga_decode: vga decode change callback
209 * return value: 0 on success, -1 on failure
210 * Register a client with the VGA arbitration logic
212 * Clients have two callback mechanisms they can use.
213 * irq enable/disable callback -
214 * If a client can't disable its GPUs VGA resources, then we
215 * need to be able to ask it to turn off its irqs when we
216 * turn off its mem and io decoding.
218 * If a client can disable its GPU VGA resource, it will
219 * get a callback from this to set the encode/decode state
221 * Rationale: we cannot disable VGA decode resources unconditionally
222 * some single GPU laptops seem to require ACPI or BIOS access to the
223 * VGA registers to control things like backlights etc.
224 * Hopefully newer multi-GPU laptops do something saner, and desktops
225 * won't have any special ACPI for this.
226 * They driver will get a callback when VGA arbitration is first used
227 * by userspace since we some older X servers have issues.
229 #if defined(CONFIG_VGA_ARB)
230 int vga_client_register(struct pci_dev
*pdev
, void *cookie
,
231 void (*irq_set_state
)(void *cookie
, bool state
),
232 unsigned int (*set_vga_decode
)(void *cookie
, bool state
));
234 static inline int vga_client_register(struct pci_dev
*pdev
, void *cookie
,
235 void (*irq_set_state
)(void *cookie
, bool state
),
236 unsigned int (*set_vga_decode
)(void *cookie
, bool state
))
242 #endif /* LINUX_VGA_H */
This page took 0.034152 seconds and 5 git commands to generate.