aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2009-08-11 01:52:06 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-09-09 16:29:36 -0400
commitdeb2d2ecd43dfc51efe71eed7128fda514da96c6 (patch)
treeba05339620bc285265f88d2c7c43df5fc25b732c /include
parent500559a92dd36af7cee95ed2f5b7722fb95a82e7 (diff)
PCI/GPU: implement VGA arbitration on Linux
Background: Graphic devices are accessed through ranges in I/O or memory space. While most modern devices allow relocation of such ranges, some "Legacy" VGA devices implemented on PCI will typically have the same "hard-decoded" addresses as they did on ISA. For more details see "PCI Bus Binding to IEEE Std 1275-1994 Standard for Boot (Initialization Configuration) Firmware Revision 2.1" Section 7, Legacy Devices. The Resource Access Control (RAC) module inside the X server currently does the task of arbitration when more than one legacy device co-exists on the same machine. But the problem happens when these devices are trying to be accessed by different userspace clients (e.g. two server in parallel). Their address assignments conflict. Therefore an arbitration scheme _outside_ of the X server is needed to control the sharing of these resources. This document introduces the operation of the VGA arbiter implemented for Linux kernel. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Tiago Vignatti <tiago.vignatti@nokia.com> Signed-off-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/pci.h2
-rw-r--r--include/linux/vgaarb.h195
2 files changed, 197 insertions, 0 deletions
diff --git a/include/linux/pci.h b/include/linux/pci.h
index a90f9402079..6dbb1fd30e5 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -806,6 +806,8 @@ int pci_cfg_space_size_ext(struct pci_dev *dev);
806int pci_cfg_space_size(struct pci_dev *dev); 806int pci_cfg_space_size(struct pci_dev *dev);
807unsigned char pci_bus_max_busnr(struct pci_bus *bus); 807unsigned char pci_bus_max_busnr(struct pci_bus *bus);
808 808
809int pci_set_vga_state(struct pci_dev *pdev, bool decode,
810 unsigned int command_bits, bool change_bridge);
809/* kmem_cache style wrapper around pci_alloc_consistent() */ 811/* kmem_cache style wrapper around pci_alloc_consistent() */
810 812
811#include <linux/dmapool.h> 813#include <linux/dmapool.h>
diff --git a/include/linux/vgaarb.h b/include/linux/vgaarb.h
new file mode 100644
index 00000000000..68229ce80fd
--- /dev/null
+++ b/include/linux/vgaarb.h
@@ -0,0 +1,195 @@
1/*
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 *
49 * 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 ?
52 *
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,
84 unsigned int rsrc)
85{
86 return vga_get(pdev, rsrc, 1);
87}
88
89/**
90 * vga_get_interruptible
91 *
92 * Shortcut to vga_get
93 */
94
95static inline int vga_get_uninterruptible(struct pci_dev *pdev,
96 unsigned int rsrc)
97{
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
168/*
169 * Register a client with the VGA arbitration logic
170 * return value: number of VGA devices in system.
171 *
172 * Clients have two callback mechanisms they can use.
173 * irq enable/disable callback -
174 * If a client can't disable its GPUs VGA resources, then we
175 * need to be able to ask it to turn off its irqs when we
176 * turn off its mem and io decoding.
177 * set_vga_decode
178 * If a client can disable its GPU VGA resource, it will
179 * get a callback from this to set the encode/decode state
180 *
181 * Clients with disable abilities should check the return value
182 * of this function and if the VGA device count is > 1, should
183 * disable VGA decoding resources.
184 *
185 * Rationale: we cannot disable VGA decode resources unconditionally
186 * some single GPU laptops seem to require ACPI or BIOS access to the
187 * VGA registers to control things like backlights etc.
188 * Hopefully newer multi-GPU laptops do something saner, and desktops
189 * won't have any special ACPI for this.
190 */
191int vga_client_register(struct pci_dev *pdev, void *cookie,
192 void (*irq_set_state)(void *cookie, bool state),
193 unsigned int (*set_vga_decode)(void *cookie, bool state));
194
195#endif /* LINUX_VGA_H */