blob: b572f80bdfd527d10a9793047c6d2f7c14f0d685 [file] [log] [blame]
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +10001/*
Jesse Barnese2d43042009-09-17 09:40:31 -07002 * 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.
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +10004 *
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>
Tiago Vignattic0db9cb2010-05-24 18:24:31 +03008 *
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 *
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100029 */
30
31#ifndef LINUX_VGA_H
Doug Goldsteina6a1a092010-07-20 15:22:25 -070032#define LINUX_VGA_H
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100033
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100034
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
43
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();
47 */
48#define VGA_DEFAULT_DEVICE (NULL)
49
Randy Dunlap6069a4c2012-01-30 11:43:52 -080050struct pci_dev;
51
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100052/* For use by clients */
53
54/**
55 * vga_set_legacy_decoding
56 *
57 * @pdev: pci device of the VGA card
58 * @decodes: bit mask of what legacy regions the card decodes
59 *
60 * Indicates to the arbiter if the card decodes legacy VGA IOs,
61 * legacy VGA Memory, both, or none. All cards default to both,
62 * the card driver (fbdev for example) should tell the arbiter
63 * if it has disabled legacy decoding, so the card can be left
64 * out of the arbitration process (and can be safe to take
65 * interrupts at any time.
66 */
67extern void vga_set_legacy_decoding(struct pci_dev *pdev,
Ingo Molnar7c329282009-09-23 09:52:18 +100068 unsigned int decodes);
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100069
70/**
71 * vga_get - acquire & locks VGA resources
72 *
Dave Airlie6ac3bd52009-08-19 15:21:57 +100073 * @pdev: pci device of the VGA card or NULL for the system default
74 * @rsrc: bit mask of resources to acquire and lock
75 * @interruptible: blocking should be interruptible by signals ?
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100076 *
77 * This function acquires VGA resources for the given
78 * card and mark those resources locked. If the resource requested
79 * are "normal" (and not legacy) resources, the arbiter will first check
80 * wether the card is doing legacy decoding for that type of resource. If
81 * yes, the lock is "converted" into a legacy resource lock.
82 * The arbiter will first look for all VGA cards that might conflict
Lucas De Marchi25985ed2011-03-30 22:57:33 -030083 * and disable their IOs and/or Memory access, including VGA forwarding
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +100084 * on P2P bridges if necessary, so that the requested resources can
85 * be used. Then, the card is marked as locking these resources and
86 * the IO and/or Memory accesse are enabled on the card (including
87 * VGA forwarding on parent P2P bridges if any).
88 * This function will block if some conflicting card is already locking
89 * one of the required resources (or any resource on a different bus
90 * segment, since P2P bridges don't differenciate VGA memory and IO
91 * afaik). You can indicate wether this blocking should be interruptible
92 * by a signal (for userland interface) or not.
93 * Must not be called at interrupt time or in atomic context.
94 * If the card already owns the resources, the function succeeds.
95 * Nested calls are supported (a per-resource counter is maintained)
96 */
97
Chris Wilson04cbe1d2010-08-19 21:29:43 +010098#if defined(CONFIG_VGA_ARB)
99extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
100#else
101static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
102#endif
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000103
104/**
105 * vga_get_interruptible
106 *
107 * Shortcut to vga_get
108 */
109
110static inline int vga_get_interruptible(struct pci_dev *pdev,
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000111 unsigned int rsrc)
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000112{
113 return vga_get(pdev, rsrc, 1);
114}
115
116/**
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000117 * vga_get_uninterruptible
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000118 *
119 * Shortcut to vga_get
120 */
121
122static inline int vga_get_uninterruptible(struct pci_dev *pdev,
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000123 unsigned int rsrc)
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000124{
125 return vga_get(pdev, rsrc, 0);
126}
127
128/**
129 * vga_tryget - try to acquire & lock legacy VGA resources
130 *
131 * @pdev: pci devivce of VGA card or NULL for system default
132 * @rsrc: bit mask of resources to acquire and lock
133 *
134 * This function performs the same operation as vga_get(), but
135 * will return an error (-EBUSY) instead of blocking if the resources
136 * are already locked by another card. It can be called in any context
137 */
138
Chris Wilson04cbe1d2010-08-19 21:29:43 +0100139#if defined(CONFIG_VGA_ARB)
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000140extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
Chris Wilson04cbe1d2010-08-19 21:29:43 +0100141#else
142static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; }
143#endif
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000144
145/**
146 * vga_put - release lock on legacy VGA resources
147 *
148 * @pdev: pci device of VGA card or NULL for system default
149 * @rsrc: but mask of resource to release
150 *
151 * This function releases resources previously locked by vga_get()
152 * or vga_tryget(). The resources aren't disabled right away, so
153 * that a subsequence vga_get() on the same card will succeed
154 * immediately. Resources have a counter, so locks are only
155 * released if the counter reaches 0.
156 */
157
Chris Wilson04cbe1d2010-08-19 21:29:43 +0100158#if defined(CONFIG_VGA_ARB)
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000159extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
Chris Wilson04cbe1d2010-08-19 21:29:43 +0100160#else
161#define vga_put(pdev, rsrc)
162#endif
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000163
164
165/**
166 * vga_default_device
167 *
168 * This can be defined by the platform. The default implementation
169 * is rather dumb and will probably only work properly on single
170 * vga card setups and/or x86 platforms.
171 *
172 * If your VGA default device is not PCI, you'll have to return
173 * NULL here. In this case, I assume it will not conflict with
174 * any PCI card. If this is not true, I'll have to define two archs
175 * hooks for enabling/disabling the VGA default device if that is
176 * possible. This may be a problem with real _ISA_ VGA cards, in
177 * addition to a PCI one. I don't know at this point how to deal
178 * with that card. Can theirs IOs be disabled at all ? If not, then
179 * I suppose it's a matter of having the proper arch hook telling
180 * us about it, so we basically never allow anybody to succeed a
181 * vga_get()...
182 */
183
184#ifndef __ARCH_HAS_VGA_DEFAULT_DEVICE
185extern struct pci_dev *vga_default_device(void);
186#endif
187
188/**
189 * vga_conflicts
190 *
191 * Architectures should define this if they have several
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300192 * independent PCI domains that can afford concurrent VGA
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000193 * decoding
194 */
195
196#ifndef __ARCH_HAS_VGA_CONFLICT
197static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
198{
199 return 1;
200}
201#endif
202
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000203/**
204 * vga_client_register
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000205 *
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000206 * @pdev: pci device of the VGA client
207 * @cookie: client cookie to be used in callbacks
208 * @irq_set_state: irq state change callback
209 * @set_vga_decode: vga decode change callback
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000210 *
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000211 * return value: 0 on success, -1 on failure
212 * Register a client with the VGA arbitration logic
213 *
214 * Clients have two callback mechanisms they can use.
215 * irq enable/disable callback -
216 * If a client can't disable its GPUs VGA resources, then we
217 * need to be able to ask it to turn off its irqs when we
218 * turn off its mem and io decoding.
219 * set_vga_decode
220 * If a client can disable its GPU VGA resource, it will
221 * get a callback from this to set the encode/decode state
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000222 *
223 * Rationale: we cannot disable VGA decode resources unconditionally
224 * some single GPU laptops seem to require ACPI or BIOS access to the
225 * VGA registers to control things like backlights etc.
226 * Hopefully newer multi-GPU laptops do something saner, and desktops
227 * won't have any special ACPI for this.
Dave Airlie6ac3bd52009-08-19 15:21:57 +1000228 * They driver will get a callback when VGA arbitration is first used
229 * by userspace since we some older X servers have issues.
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000230 */
Ingo Molnar7c329282009-09-23 09:52:18 +1000231#if defined(CONFIG_VGA_ARB)
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000232int vga_client_register(struct pci_dev *pdev, void *cookie,
233 void (*irq_set_state)(void *cookie, bool state),
234 unsigned int (*set_vga_decode)(void *cookie, bool state));
Ingo Molnar7c329282009-09-23 09:52:18 +1000235#else
236static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
237 void (*irq_set_state)(void *cookie, bool state),
238 unsigned int (*set_vga_decode)(void *cookie, bool state))
239{
240 return 0;
241}
242#endif
Benjamin Herrenschmidtdeb2d2e2009-08-11 15:52:06 +1000243
244#endif /* LINUX_VGA_H */