Subversion Repositories Kolibri OS

Rev

Rev 5270 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5270 Rev 6082
1
/*
1
/*
2
 * The VGA aribiter manages VGA space routing and VGA resource decode to
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.
3
 * allow multiple VGA devices to be used in a system in a safe way.
4
 *
4
 *
5
 * (C) Copyright 2005 Benjamin Herrenschmidt 
5
 * (C) Copyright 2005 Benjamin Herrenschmidt 
6
 * (C) Copyright 2007 Paulo R. Zanoni 
6
 * (C) Copyright 2007 Paulo R. Zanoni 
7
 * (C) Copyright 2007, 2009 Tiago Vignatti 
7
 * (C) Copyright 2007, 2009 Tiago Vignatti 
8
 *
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * Permission is hereby granted, free of charge, to any person obtaining a
10
 * copy of this software and associated documentation files (the "Software"),
10
 * copy of this software and associated documentation files (the "Software"),
11
 * to deal in the Software without restriction, including without limitation
11
 * to deal in the Software without restriction, including without limitation
12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
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
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:
14
 * Software is furnished to do so, subject to the following conditions:
15
 *
15
 *
16
 * The above copyright notice and this permission notice (including the next
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
17
 * paragraph) shall be included in all copies or substantial portions of the
18
 * Software.
18
 * Software.
19
 *
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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,
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
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
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
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
25
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
 * DEALINGS
26
 * DEALINGS
27
 * IN THE SOFTWARE.
27
 * IN THE SOFTWARE.
28
 *
28
 *
29
 */
29
 */
30
 
30
 
31
#ifndef LINUX_VGA_H
31
#ifndef LINUX_VGA_H
32
#define LINUX_VGA_H
32
#define LINUX_VGA_H
33
 
33
 
34
//#include 
34
//#include 
35
 
35
 
36
/* Legacy VGA regions */
36
/* Legacy VGA regions */
37
#define VGA_RSRC_NONE	       0x00
37
#define VGA_RSRC_NONE	       0x00
38
#define VGA_RSRC_LEGACY_IO     0x01
38
#define VGA_RSRC_LEGACY_IO     0x01
39
#define VGA_RSRC_LEGACY_MEM    0x02
39
#define VGA_RSRC_LEGACY_MEM    0x02
40
#define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
40
#define VGA_RSRC_LEGACY_MASK   (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
41
/* Non-legacy access */
41
/* Non-legacy access */
42
#define VGA_RSRC_NORMAL_IO     0x04
42
#define VGA_RSRC_NORMAL_IO     0x04
43
#define VGA_RSRC_NORMAL_MEM    0x08
43
#define VGA_RSRC_NORMAL_MEM    0x08
44
 
44
 
45
/* Passing that instead of a pci_dev to use the system "default"
45
/* Passing that instead of a pci_dev to use the system "default"
46
 * device, that is the one used by vgacon. Archs will probably
46
 * device, that is the one used by vgacon. Archs will probably
47
 * have to provide their own vga_default_device();
47
 * have to provide their own vga_default_device();
48
 */
48
 */
49
#define VGA_DEFAULT_DEVICE     (NULL)
49
#define VGA_DEFAULT_DEVICE     (NULL)
50
 
50
 
51
struct pci_dev;
51
struct pci_dev;
52
 
52
 
53
/* For use by clients */
53
/* For use by clients */
54
 
54
 
55
/**
55
/**
56
 *     vga_set_legacy_decoding
56
 *     vga_set_legacy_decoding
57
 *
57
 *
58
 *     @pdev: pci device of the VGA card
58
 *     @pdev: pci device of the VGA card
59
 *     @decodes: bit mask of what legacy regions the card decodes
59
 *     @decodes: bit mask of what legacy regions the card decodes
60
 *
60
 *
61
 *     Indicates to the arbiter if the card decodes legacy VGA IOs,
61
 *     Indicates to the arbiter if the card decodes legacy VGA IOs,
62
 *     legacy VGA Memory, both, or none. All cards default to both,
62
 *     legacy VGA Memory, both, or none. All cards default to both,
63
 *     the card driver (fbdev for example) should tell the arbiter
63
 *     the card driver (fbdev for example) should tell the arbiter
64
 *     if it has disabled legacy decoding, so the card can be left
64
 *     if it has disabled legacy decoding, so the card can be left
65
 *     out of the arbitration process (and can be safe to take
65
 *     out of the arbitration process (and can be safe to take
66
 *     interrupts at any time.
66
 *     interrupts at any time.
67
 */
67
 */
-
 
68
#if defined(CONFIG_VGA_ARB)
68
extern void vga_set_legacy_decoding(struct pci_dev *pdev,
69
extern void vga_set_legacy_decoding(struct pci_dev *pdev,
69
				    unsigned int decodes);
70
				    unsigned int decodes);
-
 
71
#else
-
 
72
static inline void vga_set_legacy_decoding(struct pci_dev *pdev,
-
 
73
					   unsigned int decodes) { };
-
 
74
#endif
70
 
75
 
71
/**
76
/**
72
 *     vga_get         - acquire & locks VGA resources
77
 *     vga_get         - acquire & locks VGA resources
73
 *
78
 *
74
 *     @pdev: pci device of the VGA card or NULL for the system default
79
 *     @pdev: pci device of the VGA card or NULL for the system default
75
 *     @rsrc: bit mask of resources to acquire and lock
80
 *     @rsrc: bit mask of resources to acquire and lock
76
 *     @interruptible: blocking should be interruptible by signals ?
81
 *     @interruptible: blocking should be interruptible by signals ?
77
 *
82
 *
78
 *     This function acquires VGA resources for the given
83
 *     This function acquires VGA resources for the given
79
 *     card and mark those resources locked. If the resource requested
84
 *     card and mark those resources locked. If the resource requested
80
 *     are "normal" (and not legacy) resources, the arbiter will first check
85
 *     are "normal" (and not legacy) resources, the arbiter will first check
81
 *     whether the card is doing legacy decoding for that type of resource. If
86
 *     whether the card is doing legacy decoding for that type of resource. If
82
 *     yes, the lock is "converted" into a legacy resource lock.
87
 *     yes, the lock is "converted" into a legacy resource lock.
83
 *     The arbiter will first look for all VGA cards that might conflict
88
 *     The arbiter will first look for all VGA cards that might conflict
84
 *     and disable their IOs and/or Memory access, including VGA forwarding
89
 *     and disable their IOs and/or Memory access, including VGA forwarding
85
 *     on P2P bridges if necessary, so that the requested resources can
90
 *     on P2P bridges if necessary, so that the requested resources can
86
 *     be used. Then, the card is marked as locking these resources and
91
 *     be used. Then, the card is marked as locking these resources and
87
 *     the IO and/or Memory accesse are enabled on the card (including
92
 *     the IO and/or Memory accesse are enabled on the card (including
88
 *     VGA forwarding on parent P2P bridges if any).
93
 *     VGA forwarding on parent P2P bridges if any).
89
 *     This function will block if some conflicting card is already locking
94
 *     This function will block if some conflicting card is already locking
90
 *     one of the required resources (or any resource on a different bus
95
 *     one of the required resources (or any resource on a different bus
91
 *     segment, since P2P bridges don't differenciate VGA memory and IO
96
 *     segment, since P2P bridges don't differenciate VGA memory and IO
92
 *     afaik). You can indicate whether this blocking should be interruptible
97
 *     afaik). You can indicate whether this blocking should be interruptible
93
 *     by a signal (for userland interface) or not.
98
 *     by a signal (for userland interface) or not.
94
 *     Must not be called at interrupt time or in atomic context.
99
 *     Must not be called at interrupt time or in atomic context.
95
 *     If the card already owns the resources, the function succeeds.
100
 *     If the card already owns the resources, the function succeeds.
96
 *     Nested calls are supported (a per-resource counter is maintained)
101
 *     Nested calls are supported (a per-resource counter is maintained)
97
 */
102
 */
98
 
103
 
99
#if defined(CONFIG_VGA_ARB)
104
#if defined(CONFIG_VGA_ARB)
100
extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
105
extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
101
#else
106
#else
102
static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
107
static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
103
#endif
108
#endif
104
 
109
 
105
/**
110
/**
106
 *     vga_get_interruptible
111
 *     vga_get_interruptible
107
 *
112
 *
108
 *     Shortcut to vga_get
113
 *     Shortcut to vga_get
109
 */
114
 */
110
 
115
 
111
static inline int vga_get_interruptible(struct pci_dev *pdev,
116
static inline int vga_get_interruptible(struct pci_dev *pdev,
112
					unsigned int rsrc)
117
					unsigned int rsrc)
113
{
118
{
114
       return vga_get(pdev, rsrc, 1);
119
       return vga_get(pdev, rsrc, 1);
115
}
120
}
116
 
121
 
117
/**
122
/**
118
 *     vga_get_uninterruptible
123
 *     vga_get_uninterruptible
119
 *
124
 *
120
 *     Shortcut to vga_get
125
 *     Shortcut to vga_get
121
 */
126
 */
122
 
127
 
123
static inline int vga_get_uninterruptible(struct pci_dev *pdev,
128
static inline int vga_get_uninterruptible(struct pci_dev *pdev,
124
					  unsigned int rsrc)
129
					  unsigned int rsrc)
125
{
130
{
126
       return vga_get(pdev, rsrc, 0);
131
       return vga_get(pdev, rsrc, 0);
127
}
132
}
128
 
133
 
129
/**
134
/**
130
 *     vga_tryget      - try to acquire & lock legacy VGA resources
135
 *     vga_tryget      - try to acquire & lock legacy VGA resources
131
 *
136
 *
132
 *     @pdev: pci devivce of VGA card or NULL for system default
137
 *     @pdev: pci devivce of VGA card or NULL for system default
133
 *     @rsrc: bit mask of resources to acquire and lock
138
 *     @rsrc: bit mask of resources to acquire and lock
134
 *
139
 *
135
 *     This function performs the same operation as vga_get(), but
140
 *     This function performs the same operation as vga_get(), but
136
 *     will return an error (-EBUSY) instead of blocking if the resources
141
 *     will return an error (-EBUSY) instead of blocking if the resources
137
 *     are already locked by another card. It can be called in any context
142
 *     are already locked by another card. It can be called in any context
138
 */
143
 */
139
 
144
 
140
#if defined(CONFIG_VGA_ARB)
145
#if defined(CONFIG_VGA_ARB)
141
extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
146
extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
142
#else
147
#else
143
static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; }
148
static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; }
144
#endif
149
#endif
145
 
150
 
146
/**
151
/**
147
 *     vga_put         - release lock on legacy VGA resources
152
 *     vga_put         - release lock on legacy VGA resources
148
 *
153
 *
149
 *     @pdev: pci device of VGA card or NULL for system default
154
 *     @pdev: pci device of VGA card or NULL for system default
150
 *     @rsrc: but mask of resource to release
155
 *     @rsrc: but mask of resource to release
151
 *
156
 *
152
 *     This function releases resources previously locked by vga_get()
157
 *     This function releases resources previously locked by vga_get()
153
 *     or vga_tryget(). The resources aren't disabled right away, so
158
 *     or vga_tryget(). The resources aren't disabled right away, so
154
 *     that a subsequence vga_get() on the same card will succeed
159
 *     that a subsequence vga_get() on the same card will succeed
155
 *     immediately. Resources have a counter, so locks are only
160
 *     immediately. Resources have a counter, so locks are only
156
 *     released if the counter reaches 0.
161
 *     released if the counter reaches 0.
157
 */
162
 */
158
 
163
 
159
#if defined(CONFIG_VGA_ARB)
164
#if defined(CONFIG_VGA_ARB)
160
extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
165
extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
161
#else
166
#else
162
#define vga_put(pdev, rsrc)
167
#define vga_put(pdev, rsrc)
163
#endif
168
#endif
164
 
169
 
165
 
170
 
166
/**
171
/**
167
 *     vga_default_device
172
 *     vga_default_device
168
 *
173
 *
169
 *     This can be defined by the platform. The default implementation
174
 *     This can be defined by the platform. The default implementation
170
 *     is rather dumb and will probably only work properly on single
175
 *     is rather dumb and will probably only work properly on single
171
 *     vga card setups and/or x86 platforms.
176
 *     vga card setups and/or x86 platforms.
172
 *
177
 *
173
 *     If your VGA default device is not PCI, you'll have to return
178
 *     If your VGA default device is not PCI, you'll have to return
174
 *     NULL here. In this case, I assume it will not conflict with
179
 *     NULL here. In this case, I assume it will not conflict with
175
 *     any PCI card. If this is not true, I'll have to define two archs
180
 *     any PCI card. If this is not true, I'll have to define two archs
176
 *     hooks for enabling/disabling the VGA default device if that is
181
 *     hooks for enabling/disabling the VGA default device if that is
177
 *     possible. This may be a problem with real _ISA_ VGA cards, in
182
 *     possible. This may be a problem with real _ISA_ VGA cards, in
178
 *     addition to a PCI one. I don't know at this point how to deal
183
 *     addition to a PCI one. I don't know at this point how to deal
179
 *     with that card. Can theirs IOs be disabled at all ? If not, then
184
 *     with that card. Can theirs IOs be disabled at all ? If not, then
180
 *     I suppose it's a matter of having the proper arch hook telling
185
 *     I suppose it's a matter of having the proper arch hook telling
181
 *     us about it, so we basically never allow anybody to succeed a
186
 *     us about it, so we basically never allow anybody to succeed a
182
 *     vga_get()...
187
 *     vga_get()...
183
 */
188
 */
184
 
189
 
185
#ifdef CONFIG_VGA_ARB
190
#ifdef CONFIG_VGA_ARB
186
extern struct pci_dev *vga_default_device(void);
191
extern struct pci_dev *vga_default_device(void);
187
extern void vga_set_default_device(struct pci_dev *pdev);
192
extern void vga_set_default_device(struct pci_dev *pdev);
188
#else
193
#else
189
static inline struct pci_dev *vga_default_device(void) { return NULL; };
194
static inline struct pci_dev *vga_default_device(void) { return NULL; };
190
static inline void vga_set_default_device(struct pci_dev *pdev) { };
195
static inline void vga_set_default_device(struct pci_dev *pdev) { };
191
#endif
196
#endif
192
 
197
 
193
/**
198
/**
194
 *     vga_conflicts
199
 *     vga_conflicts
195
 *
200
 *
196
 *     Architectures should define this if they have several
201
 *     Architectures should define this if they have several
197
 *     independent PCI domains that can afford concurrent VGA
202
 *     independent PCI domains that can afford concurrent VGA
198
 *     decoding
203
 *     decoding
199
 */
204
 */
200
 
205
 
201
#ifndef __ARCH_HAS_VGA_CONFLICT
206
#ifndef __ARCH_HAS_VGA_CONFLICT
202
static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
207
static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
203
{
208
{
204
       return 1;
209
       return 1;
205
}
210
}
206
#endif
211
#endif
207
 
212
 
208
/**
213
/**
209
 *	vga_client_register
214
 *	vga_client_register
210
 *
215
 *
211
 *	@pdev: pci device of the VGA client
216
 *	@pdev: pci device of the VGA client
212
 *	@cookie: client cookie to be used in callbacks
217
 *	@cookie: client cookie to be used in callbacks
213
 *	@irq_set_state: irq state change callback
218
 *	@irq_set_state: irq state change callback
214
 *	@set_vga_decode: vga decode change callback
219
 *	@set_vga_decode: vga decode change callback
215
 *
220
 *
216
 * 	return value: 0 on success, -1 on failure
221
 * 	return value: 0 on success, -1 on failure
217
 * 	Register a client with the VGA arbitration logic
222
 * 	Register a client with the VGA arbitration logic
218
 *
223
 *
219
 *	Clients have two callback mechanisms they can use.
224
 *	Clients have two callback mechanisms they can use.
220
 *	irq enable/disable callback -
225
 *	irq enable/disable callback -
221
 *		If a client can't disable its GPUs VGA resources, then we
226
 *		If a client can't disable its GPUs VGA resources, then we
222
 *		need to be able to ask it to turn off its irqs when we
227
 *		need to be able to ask it to turn off its irqs when we
223
 *		turn off its mem and io decoding.
228
 *		turn off its mem and io decoding.
224
 *	set_vga_decode
229
 *	set_vga_decode
225
 *		If a client can disable its GPU VGA resource, it will
230
 *		If a client can disable its GPU VGA resource, it will
226
 *		get a callback from this to set the encode/decode state
231
 *		get a callback from this to set the encode/decode state
227
 *
232
 *
228
 * Rationale: we cannot disable VGA decode resources unconditionally
233
 * Rationale: we cannot disable VGA decode resources unconditionally
229
 * some single GPU laptops seem to require ACPI or BIOS access to the
234
 * some single GPU laptops seem to require ACPI or BIOS access to the
230
 * VGA registers to control things like backlights etc.
235
 * VGA registers to control things like backlights etc.
231
 * Hopefully newer multi-GPU laptops do something saner, and desktops
236
 * Hopefully newer multi-GPU laptops do something saner, and desktops
232
 * won't have any special ACPI for this.
237
 * won't have any special ACPI for this.
233
 * They driver will get a callback when VGA arbitration is first used
238
 * They driver will get a callback when VGA arbitration is first used
234
 * by userspace since we some older X servers have issues.
239
 * by userspace since we some older X servers have issues.
235
 */
240
 */
236
#if defined(CONFIG_VGA_ARB)
241
#if defined(CONFIG_VGA_ARB)
237
int vga_client_register(struct pci_dev *pdev, void *cookie,
242
int vga_client_register(struct pci_dev *pdev, void *cookie,
238
			void (*irq_set_state)(void *cookie, bool state),
243
			void (*irq_set_state)(void *cookie, bool state),
239
			unsigned int (*set_vga_decode)(void *cookie, bool state));
244
			unsigned int (*set_vga_decode)(void *cookie, bool state));
240
#else
245
#else
241
static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
246
static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
242
				      void (*irq_set_state)(void *cookie, bool state),
247
				      void (*irq_set_state)(void *cookie, bool state),
243
				      unsigned int (*set_vga_decode)(void *cookie, bool state))
248
				      unsigned int (*set_vga_decode)(void *cookie, bool state))
244
{
249
{
245
	return 0;
250
	return 0;
246
}
251
}
247
#endif
252
#endif
248
 
253
 
249
#endif /* LINUX_VGA_H */
254
#endif /* LINUX_VGA_H */