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