Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /** |
b5e89ed5 | 2 | * \file drmP.h |
1da177e4 | 3 | * Private header for Direct Rendering Manager |
b5e89ed5 | 4 | * |
1da177e4 LT |
5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
6 | * \author Gareth Hughes <gareth@valinux.com> | |
7 | */ | |
8 | ||
9 | /* | |
10 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. | |
11 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. | |
12 | * All rights reserved. | |
13 | * | |
14 | * Permission is hereby granted, free of charge, to any person obtaining a | |
15 | * copy of this software and associated documentation files (the "Software"), | |
16 | * to deal in the Software without restriction, including without limitation | |
17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
18 | * and/or sell copies of the Software, and to permit persons to whom the | |
19 | * Software is furnished to do so, subject to the following conditions: | |
20 | * | |
21 | * The above copyright notice and this permission notice (including the next | |
22 | * paragraph) shall be included in all copies or substantial portions of the | |
23 | * Software. | |
24 | * | |
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
28 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
29 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
30 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
31 | * OTHER DEALINGS IN THE SOFTWARE. | |
32 | */ | |
33 | ||
34 | #ifndef _DRM_P_H_ | |
35 | #define _DRM_P_H_ | |
36 | ||
37 | /* If you want the memory alloc debug functionality, change define below */ | |
38 | /* #define DEBUG_MEMORY */ | |
39 | ||
40 | #ifdef __KERNEL__ | |
41 | #ifdef __alpha__ | |
42 | /* add include of current.h so that "current" is defined | |
43 | * before static inline funcs in wait.h. Doing this so we | |
44 | * can build the DRM (part of PI DRI). 4/21/2000 S + B */ | |
45 | #include <asm/current.h> | |
b5e89ed5 | 46 | #endif /* __alpha__ */ |
1da177e4 LT |
47 | #include <linux/module.h> |
48 | #include <linux/kernel.h> | |
49 | #include <linux/miscdevice.h> | |
50 | #include <linux/fs.h> | |
51 | #include <linux/proc_fs.h> | |
52 | #include <linux/init.h> | |
53 | #include <linux/file.h> | |
54 | #include <linux/pci.h> | |
1da177e4 LT |
55 | #include <linux/jiffies.h> |
56 | #include <linux/smp_lock.h> /* For (un)lock_kernel */ | |
b05c2385 | 57 | #include <linux/dma-mapping.h> |
1da177e4 LT |
58 | #include <linux/mm.h> |
59 | #include <linux/cdev.h> | |
30e2fb18 | 60 | #include <linux/mutex.h> |
1da177e4 | 61 | #if defined(__alpha__) || defined(__powerpc__) |
b5e89ed5 | 62 | #include <asm/pgtable.h> /* For pte_wrprotect */ |
1da177e4 LT |
63 | #endif |
64 | #include <asm/io.h> | |
65 | #include <asm/mman.h> | |
66 | #include <asm/uaccess.h> | |
67 | #ifdef CONFIG_MTRR | |
68 | #include <asm/mtrr.h> | |
69 | #endif | |
70 | #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE) | |
71 | #include <linux/types.h> | |
72 | #include <linux/agp_backend.h> | |
73 | #endif | |
74 | #include <linux/workqueue.h> | |
75 | #include <linux/poll.h> | |
76 | #include <asm/pgalloc.h> | |
77 | #include "drm.h" | |
78 | ||
62968144 DA |
79 | #include <linux/idr.h> |
80 | ||
1da177e4 LT |
81 | #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE))) |
82 | #define __OS_HAS_MTRR (defined(CONFIG_MTRR)) | |
83 | ||
c153f45f EA |
84 | struct drm_file; |
85 | struct drm_device; | |
86 | ||
1da177e4 | 87 | #include "drm_os_linux.h" |
3a1bd924 | 88 | #include "drm_hashtab.h" |
1da177e4 LT |
89 | |
90 | /***********************************************************************/ | |
91 | /** \name DRM template customization defaults */ | |
92 | /*@{*/ | |
93 | ||
94 | /* driver capabilities and requirements mask */ | |
95 | #define DRIVER_USE_AGP 0x1 | |
96 | #define DRIVER_REQUIRE_AGP 0x2 | |
97 | #define DRIVER_USE_MTRR 0x4 | |
98 | #define DRIVER_PCI_DMA 0x8 | |
99 | #define DRIVER_SG 0x10 | |
100 | #define DRIVER_HAVE_DMA 0x20 | |
101 | #define DRIVER_HAVE_IRQ 0x40 | |
102 | #define DRIVER_IRQ_SHARED 0x80 | |
1da177e4 | 103 | #define DRIVER_DMA_QUEUE 0x200 |
b84397d6 | 104 | #define DRIVER_FB_DMA 0x400 |
1da177e4 LT |
105 | |
106 | /***********************************************************************/ | |
107 | /** \name Begin the DRM... */ | |
108 | /*@{*/ | |
109 | ||
110 | #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then | |
111 | also include looping detection. */ | |
112 | ||
8669cbc5 | 113 | #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */ |
1da177e4 LT |
114 | #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */ |
115 | #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */ | |
116 | #define DRM_LOOPING_LIMIT 5000000 | |
1da177e4 LT |
117 | #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */ |
118 | #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */ | |
119 | ||
120 | #define DRM_FLAG_DEBUG 0x01 | |
121 | ||
122 | #define DRM_MEM_DMA 0 | |
123 | #define DRM_MEM_SAREA 1 | |
124 | #define DRM_MEM_DRIVER 2 | |
125 | #define DRM_MEM_MAGIC 3 | |
126 | #define DRM_MEM_IOCTLS 4 | |
127 | #define DRM_MEM_MAPS 5 | |
128 | #define DRM_MEM_VMAS 6 | |
129 | #define DRM_MEM_BUFS 7 | |
130 | #define DRM_MEM_SEGS 8 | |
131 | #define DRM_MEM_PAGES 9 | |
132 | #define DRM_MEM_FILES 10 | |
133 | #define DRM_MEM_QUEUES 11 | |
134 | #define DRM_MEM_CMDS 12 | |
135 | #define DRM_MEM_MAPPINGS 13 | |
136 | #define DRM_MEM_BUFLISTS 14 | |
137 | #define DRM_MEM_AGPLISTS 15 | |
138 | #define DRM_MEM_TOTALAGP 16 | |
139 | #define DRM_MEM_BOUNDAGP 17 | |
140 | #define DRM_MEM_CTXBITMAP 18 | |
141 | #define DRM_MEM_STUB 19 | |
142 | #define DRM_MEM_SGLISTS 20 | |
3a1bd924 TH |
143 | #define DRM_MEM_CTXLIST 21 |
144 | #define DRM_MEM_MM 22 | |
145 | #define DRM_MEM_HASHTAB 23 | |
1da177e4 LT |
146 | |
147 | #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) | |
8d153f71 | 148 | #define DRM_MAP_HASH_OFFSET 0x10000000 |
1da177e4 | 149 | |
b5e89ed5 | 150 | /*@}*/ |
1da177e4 | 151 | |
1da177e4 LT |
152 | /***********************************************************************/ |
153 | /** \name Macros to make printk easier */ | |
154 | /*@{*/ | |
155 | ||
156 | /** | |
157 | * Error output. | |
158 | * | |
159 | * \param fmt printf() like format string. | |
160 | * \param arg arguments | |
161 | */ | |
162 | #define DRM_ERROR(fmt, arg...) \ | |
bf9d8929 | 163 | printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg) |
1da177e4 LT |
164 | |
165 | /** | |
166 | * Memory error output. | |
167 | * | |
168 | * \param area memory area where the error occurred. | |
169 | * \param fmt printf() like format string. | |
170 | * \param arg arguments | |
171 | */ | |
172 | #define DRM_MEM_ERROR(area, fmt, arg...) \ | |
bf9d8929 | 173 | printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \ |
1da177e4 LT |
174 | drm_mem_stats[area].name , ##arg) |
175 | ||
176 | #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg) | |
177 | ||
178 | /** | |
179 | * Debug output. | |
b5e89ed5 | 180 | * |
1da177e4 LT |
181 | * \param fmt printf() like format string. |
182 | * \param arg arguments | |
183 | */ | |
184 | #if DRM_DEBUG_CODE | |
185 | #define DRM_DEBUG(fmt, arg...) \ | |
186 | do { \ | |
187 | if ( drm_debug ) \ | |
188 | printk(KERN_DEBUG \ | |
189 | "[" DRM_NAME ":%s] " fmt , \ | |
bf9d8929 | 190 | __func__ , ##arg); \ |
1da177e4 LT |
191 | } while (0) |
192 | #else | |
193 | #define DRM_DEBUG(fmt, arg...) do { } while (0) | |
194 | #endif | |
195 | ||
196 | #define DRM_PROC_LIMIT (PAGE_SIZE-80) | |
197 | ||
198 | #define DRM_PROC_PRINT(fmt, arg...) \ | |
199 | len += sprintf(&buf[len], fmt , ##arg); \ | |
200 | if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; } | |
201 | ||
202 | #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \ | |
203 | len += sprintf(&buf[len], fmt , ##arg); \ | |
204 | if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; } | |
205 | ||
206 | /*@}*/ | |
207 | ||
1da177e4 LT |
208 | /***********************************************************************/ |
209 | /** \name Internal types and structures */ | |
210 | /*@{*/ | |
211 | ||
99a2657a | 212 | #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x) |
1da177e4 LT |
213 | |
214 | #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1)) | |
215 | #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x)) | |
216 | #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist) | |
217 | ||
218 | #define DRM_IF_VERSION(maj, min) (maj << 16 | min) | |
219 | /** | |
220 | * Get the private SAREA mapping. | |
221 | * | |
222 | * \param _dev DRM device. | |
223 | * \param _ctx context number. | |
224 | * \param _map output mapping. | |
225 | */ | |
226 | #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ | |
227 | (_map) = (_dev)->context_sareas[_ctx]; \ | |
228 | } while(0) | |
229 | ||
230 | /** | |
231 | * Test that the hardware lock is held by the caller, returning otherwise. | |
232 | * | |
233 | * \param dev DRM device. | |
234 | * \param filp file pointer of the caller. | |
235 | */ | |
c153f45f | 236 | #define LOCK_TEST_WITH_RETURN( dev, file_priv ) \ |
1da177e4 LT |
237 | do { \ |
238 | if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \ | |
c153f45f EA |
239 | dev->lock.file_priv != file_priv ) { \ |
240 | DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\ | |
bf9d8929 | 241 | __func__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\ |
c153f45f | 242 | dev->lock.file_priv, file_priv ); \ |
1da177e4 LT |
243 | return -EINVAL; \ |
244 | } \ | |
245 | } while (0) | |
246 | ||
247 | /** | |
248 | * Copy and IOCTL return string to user space | |
249 | */ | |
250 | #define DRM_COPY( name, value ) \ | |
251 | len = strlen( value ); \ | |
252 | if ( len > name##_len ) len = name##_len; \ | |
253 | name##_len = strlen( value ); \ | |
254 | if ( len && name ) { \ | |
255 | if ( copy_to_user( name, value, len ) ) \ | |
256 | return -EFAULT; \ | |
257 | } | |
b5e89ed5 | 258 | |
1da177e4 LT |
259 | /** |
260 | * Ioctl function type. | |
261 | * | |
262 | * \param inode device inode. | |
6c340eac | 263 | * \param file_priv DRM file private pointer. |
1da177e4 LT |
264 | * \param cmd command. |
265 | * \param arg argument. | |
266 | */ | |
c153f45f EA |
267 | typedef int drm_ioctl_t(struct drm_device *dev, void *data, |
268 | struct drm_file *file_priv); | |
1da177e4 | 269 | |
9a186645 DA |
270 | typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd, |
271 | unsigned long arg); | |
272 | ||
a7a2cc31 DA |
273 | #define DRM_AUTH 0x1 |
274 | #define DRM_MASTER 0x2 | |
275 | #define DRM_ROOT_ONLY 0x4 | |
276 | ||
c153f45f EA |
277 | struct drm_ioctl_desc { |
278 | unsigned int cmd; | |
b5e89ed5 | 279 | drm_ioctl_t *func; |
a7a2cc31 | 280 | int flags; |
c153f45f EA |
281 | }; |
282 | ||
283 | /** | |
284 | * Creates a driver or general drm_ioctl_desc array entry for the given | |
285 | * ioctl, for use by drm_ioctl(). | |
286 | */ | |
287 | #define DRM_IOCTL_DEF(ioctl, func, flags) \ | |
288 | [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags} | |
1da177e4 | 289 | |
8fc2fdf4 | 290 | struct drm_magic_entry { |
8669cbc5 | 291 | struct list_head head; |
e0be428e | 292 | struct drm_hash_item hash_item; |
b5e89ed5 | 293 | struct drm_file *priv; |
8fc2fdf4 | 294 | }; |
1da177e4 | 295 | |
8fc2fdf4 | 296 | struct drm_vma_entry { |
bd1b331f | 297 | struct list_head head; |
1da177e4 | 298 | struct vm_area_struct *vma; |
b5e89ed5 | 299 | pid_t pid; |
8fc2fdf4 | 300 | }; |
1da177e4 LT |
301 | |
302 | /** | |
303 | * DMA buffer. | |
304 | */ | |
056219e2 | 305 | struct drm_buf { |
b5e89ed5 DA |
306 | int idx; /**< Index into master buflist */ |
307 | int total; /**< Buffer size */ | |
308 | int order; /**< log-base-2(total) */ | |
309 | int used; /**< Amount of buffer in use (for DMA) */ | |
310 | unsigned long offset; /**< Byte offset (used internally) */ | |
311 | void *address; /**< Address of buffer */ | |
312 | unsigned long bus_address; /**< Bus address of buffer */ | |
313 | struct drm_buf *next; /**< Kernel-only: used for free list */ | |
314 | __volatile__ int waiting; /**< On kernel DMA queue */ | |
315 | __volatile__ int pending; /**< On hardware DMA queue */ | |
1da177e4 | 316 | wait_queue_head_t dma_wait; /**< Processes waiting */ |
6c340eac | 317 | struct drm_file *file_priv; /**< Private of holding file descr */ |
b5e89ed5 DA |
318 | int context; /**< Kernel queue for this buffer */ |
319 | int while_locked; /**< Dispatch this buffer while locked */ | |
1da177e4 | 320 | enum { |
b5e89ed5 DA |
321 | DRM_LIST_NONE = 0, |
322 | DRM_LIST_FREE = 1, | |
323 | DRM_LIST_WAIT = 2, | |
324 | DRM_LIST_PEND = 3, | |
325 | DRM_LIST_PRIO = 4, | |
1da177e4 | 326 | DRM_LIST_RECLAIM = 5 |
b5e89ed5 | 327 | } list; /**< Which list we're on */ |
1da177e4 | 328 | |
b5e89ed5 DA |
329 | int dev_priv_size; /**< Size of buffer private storage */ |
330 | void *dev_private; /**< Per-buffer private storage */ | |
056219e2 | 331 | }; |
1da177e4 | 332 | |
1da177e4 | 333 | /** bufs is one longer than it has to be */ |
cdd55a29 | 334 | struct drm_waitlist { |
b5e89ed5 | 335 | int count; /**< Number of possible buffers */ |
056219e2 DA |
336 | struct drm_buf **bufs; /**< List of pointers to buffers */ |
337 | struct drm_buf **rp; /**< Read pointer */ | |
338 | struct drm_buf **wp; /**< Write pointer */ | |
339 | struct drm_buf **end; /**< End pointer */ | |
b5e89ed5 DA |
340 | spinlock_t read_lock; |
341 | spinlock_t write_lock; | |
cdd55a29 | 342 | }; |
1da177e4 | 343 | |
cdd55a29 | 344 | struct drm_freelist { |
b5e89ed5 DA |
345 | int initialized; /**< Freelist in use */ |
346 | atomic_t count; /**< Number of free buffers */ | |
056219e2 | 347 | struct drm_buf *next; /**< End pointer */ |
1da177e4 LT |
348 | |
349 | wait_queue_head_t waiting; /**< Processes waiting on free bufs */ | |
b5e89ed5 DA |
350 | int low_mark; /**< Low water mark */ |
351 | int high_mark; /**< High water mark */ | |
352 | atomic_t wfh; /**< If waiting for high mark */ | |
353 | spinlock_t lock; | |
cdd55a29 | 354 | }; |
1da177e4 | 355 | |
ddf19b97 DA |
356 | typedef struct drm_dma_handle { |
357 | dma_addr_t busaddr; | |
358 | void *vaddr; | |
359 | size_t size; | |
360 | } drm_dma_handle_t; | |
361 | ||
1da177e4 LT |
362 | /** |
363 | * Buffer entry. There is one of this for each buffer size order. | |
364 | */ | |
cdd55a29 | 365 | struct drm_buf_entry { |
b5e89ed5 DA |
366 | int buf_size; /**< size */ |
367 | int buf_count; /**< number of buffers */ | |
056219e2 | 368 | struct drm_buf *buflist; /**< buffer list */ |
b5e89ed5 DA |
369 | int seg_count; |
370 | int page_order; | |
cdd55a29 | 371 | struct drm_dma_handle **seglist; |
b5e89ed5 | 372 | |
cdd55a29 DA |
373 | struct drm_freelist freelist; |
374 | }; | |
1da177e4 LT |
375 | |
376 | /** File private data */ | |
84b1fd10 | 377 | struct drm_file { |
b5e89ed5 | 378 | int authenticated; |
a7a2cc31 | 379 | int master; |
b5e89ed5 DA |
380 | pid_t pid; |
381 | uid_t uid; | |
382 | drm_magic_t magic; | |
383 | unsigned long ioctl_count; | |
bd1b331f | 384 | struct list_head lhead; |
2c14f28b | 385 | struct drm_minor *minor; |
b5e89ed5 DA |
386 | int remove_auth_on_close; |
387 | unsigned long lock_count; | |
6c340eac | 388 | struct file *filp; |
8562b3f2 | 389 | void *driver_priv; |
84b1fd10 | 390 | }; |
1da177e4 LT |
391 | |
392 | /** Wait queue */ | |
cdd55a29 | 393 | struct drm_queue { |
b5e89ed5 DA |
394 | atomic_t use_count; /**< Outstanding uses (+1) */ |
395 | atomic_t finalization; /**< Finalization in progress */ | |
396 | atomic_t block_count; /**< Count of processes waiting */ | |
397 | atomic_t block_read; /**< Queue blocked for reads */ | |
1da177e4 | 398 | wait_queue_head_t read_queue; /**< Processes waiting on block_read */ |
b5e89ed5 | 399 | atomic_t block_write; /**< Queue blocked for writes */ |
1da177e4 | 400 | wait_queue_head_t write_queue; /**< Processes waiting on block_write */ |
b5e89ed5 DA |
401 | atomic_t total_queued; /**< Total queued statistic */ |
402 | atomic_t total_flushed; /**< Total flushes statistic */ | |
403 | atomic_t total_locks; /**< Total locks statistics */ | |
c60ce623 | 404 | enum drm_ctx_flags flags; /**< Context preserving and 2D-only */ |
cdd55a29 | 405 | struct drm_waitlist waitlist; /**< Pending buffers */ |
1da177e4 | 406 | wait_queue_head_t flush_queue; /**< Processes waiting until flush */ |
cdd55a29 | 407 | }; |
1da177e4 LT |
408 | |
409 | /** | |
410 | * Lock data. | |
411 | */ | |
55910517 | 412 | struct drm_lock_data { |
c60ce623 | 413 | struct drm_hw_lock *hw_lock; /**< Hardware lock */ |
8562b3f2 DA |
414 | /** Private of lock holder's file (NULL=kernel) */ |
415 | struct drm_file *file_priv; | |
1da177e4 | 416 | wait_queue_head_t lock_queue; /**< Queue of blocked processes */ |
b5e89ed5 | 417 | unsigned long lock_time; /**< Time of last lock in jiffies */ |
040ac320 TH |
418 | spinlock_t spinlock; |
419 | uint32_t kernel_waiters; | |
420 | uint32_t user_waiters; | |
421 | int idle_has_lock; | |
55910517 | 422 | }; |
1da177e4 LT |
423 | |
424 | /** | |
425 | * DMA data. | |
426 | */ | |
cdd55a29 | 427 | struct drm_device_dma { |
1da177e4 | 428 | |
cdd55a29 | 429 | struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */ |
b5e89ed5 | 430 | int buf_count; /**< total number of buffers */ |
056219e2 | 431 | struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */ |
b5e89ed5 DA |
432 | int seg_count; |
433 | int page_count; /**< number of pages */ | |
434 | unsigned long *pagelist; /**< page list */ | |
435 | unsigned long byte_count; | |
1da177e4 LT |
436 | enum { |
437 | _DRM_DMA_USE_AGP = 0x01, | |
b5e89ed5 | 438 | _DRM_DMA_USE_SG = 0x02, |
3417f33e GS |
439 | _DRM_DMA_USE_FB = 0x04, |
440 | _DRM_DMA_USE_PCI_RO = 0x08 | |
1da177e4 LT |
441 | } flags; |
442 | ||
cdd55a29 | 443 | }; |
1da177e4 | 444 | |
b5e89ed5 | 445 | /** |
1da177e4 LT |
446 | * AGP memory entry. Stored as a doubly linked list. |
447 | */ | |
55910517 | 448 | struct drm_agp_mem { |
b5e89ed5 DA |
449 | unsigned long handle; /**< handle */ |
450 | DRM_AGP_MEM *memory; | |
451 | unsigned long bound; /**< address */ | |
452 | int pages; | |
bd1b331f | 453 | struct list_head head; |
55910517 | 454 | }; |
1da177e4 LT |
455 | |
456 | /** | |
457 | * AGP data. | |
458 | * | |
459 | * \sa drm_agp_init() and drm_device::agp. | |
460 | */ | |
55910517 | 461 | struct drm_agp_head { |
b5e89ed5 | 462 | DRM_AGP_KERN agp_info; /**< AGP device information */ |
bd1b331f | 463 | struct list_head memory; |
b5e89ed5 DA |
464 | unsigned long mode; /**< AGP mode */ |
465 | struct agp_bridge_data *bridge; | |
466 | int enabled; /**< whether the AGP bus as been enabled */ | |
467 | int acquired; /**< whether the AGP device has been acquired */ | |
468 | unsigned long base; | |
469 | int agp_mtrr; | |
470 | int cant_use_aperture; | |
471 | unsigned long page_mask; | |
55910517 | 472 | }; |
1da177e4 LT |
473 | |
474 | /** | |
475 | * Scatter-gather memory. | |
476 | */ | |
55910517 | 477 | struct drm_sg_mem { |
b5e89ed5 DA |
478 | unsigned long handle; |
479 | void *virtual; | |
480 | int pages; | |
481 | struct page **pagelist; | |
482 | dma_addr_t *busaddr; | |
55910517 | 483 | }; |
1da177e4 | 484 | |
55910517 | 485 | struct drm_sigdata { |
b5e89ed5 | 486 | int context; |
c60ce623 | 487 | struct drm_hw_lock *lock; |
55910517 | 488 | }; |
1da177e4 | 489 | |
8562b3f2 DA |
490 | |
491 | /* | |
492 | * Generic memory manager structs | |
493 | */ | |
494 | ||
495 | struct drm_mm_node { | |
496 | struct list_head fl_entry; | |
497 | struct list_head ml_entry; | |
498 | int free; | |
499 | unsigned long start; | |
500 | unsigned long size; | |
501 | struct drm_mm *mm; | |
502 | void *private; | |
503 | }; | |
504 | ||
505 | struct drm_mm { | |
506 | struct list_head fl_entry; | |
507 | struct list_head ml_entry; | |
508 | }; | |
509 | ||
510 | ||
1da177e4 LT |
511 | /** |
512 | * Mappings list | |
513 | */ | |
55910517 | 514 | struct drm_map_list { |
b5e89ed5 | 515 | struct list_head head; /**< list head */ |
e0be428e | 516 | struct drm_hash_item hash; |
c60ce623 | 517 | struct drm_map *map; /**< mapping */ |
8562b3f2 | 518 | uint64_t user_token; |
55910517 | 519 | }; |
1da177e4 | 520 | |
c60ce623 | 521 | typedef struct drm_map drm_local_map_t; |
1da177e4 LT |
522 | |
523 | /** | |
524 | * Context handle list | |
525 | */ | |
55910517 | 526 | struct drm_ctx_list { |
b5e89ed5 DA |
527 | struct list_head head; /**< list head */ |
528 | drm_context_t handle; /**< context handle */ | |
84b1fd10 | 529 | struct drm_file *tag; /**< associated fd private data */ |
55910517 | 530 | }; |
1da177e4 | 531 | |
55910517 | 532 | struct drm_vbl_sig { |
b5e89ed5 DA |
533 | struct list_head head; |
534 | unsigned int sequence; | |
535 | struct siginfo info; | |
536 | struct task_struct *task; | |
55910517 | 537 | }; |
1da177e4 | 538 | |
ea98a92f DA |
539 | /* location of GART table */ |
540 | #define DRM_ATI_GART_MAIN 1 | |
541 | #define DRM_ATI_GART_FB 2 | |
542 | ||
f2b04cd2 DA |
543 | #define DRM_ATI_GART_PCI 1 |
544 | #define DRM_ATI_GART_PCIE 2 | |
545 | #define DRM_ATI_GART_IGP 3 | |
546 | ||
55910517 | 547 | struct drm_ati_pcigart_info { |
ea98a92f | 548 | int gart_table_location; |
f2b04cd2 | 549 | int gart_reg_if; |
f26c473c | 550 | void *addr; |
ea98a92f | 551 | dma_addr_t bus_addr; |
b05c2385 DA |
552 | dma_addr_t table_mask; |
553 | struct drm_dma_handle *table_handle; | |
f26c473c | 554 | drm_local_map_t mapping; |
f2b04cd2 | 555 | int table_size; |
55910517 | 556 | }; |
ea98a92f | 557 | |
1da177e4 LT |
558 | /** |
559 | * DRM driver structure. This structure represent the common code for | |
560 | * a family of cards. There will one drm_device for each card present | |
561 | * in this family | |
562 | */ | |
1da177e4 | 563 | struct drm_driver { |
22eae947 DA |
564 | int (*load) (struct drm_device *, unsigned long flags); |
565 | int (*firstopen) (struct drm_device *); | |
84b1fd10 | 566 | int (*open) (struct drm_device *, struct drm_file *); |
6c340eac | 567 | void (*preclose) (struct drm_device *, struct drm_file *file_priv); |
84b1fd10 | 568 | void (*postclose) (struct drm_device *, struct drm_file *); |
22eae947 DA |
569 | void (*lastclose) (struct drm_device *); |
570 | int (*unload) (struct drm_device *); | |
b932ccb5 | 571 | int (*suspend) (struct drm_device *, pm_message_t state); |
e8b962b6 | 572 | int (*resume) (struct drm_device *); |
c153f45f | 573 | int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv); |
b5e89ed5 DA |
574 | void (*dma_ready) (struct drm_device *); |
575 | int (*dma_quiescent) (struct drm_device *); | |
84b1fd10 DA |
576 | int (*context_ctor) (struct drm_device *dev, int context); |
577 | int (*context_dtor) (struct drm_device *dev, int context); | |
578 | int (*kernel_context_switch) (struct drm_device *dev, int old, | |
b5e89ed5 | 579 | int new); |
ac741ab7 JB |
580 | void (*kernel_context_switch_unlock) (struct drm_device * dev); |
581 | /** | |
582 | * get_vblank_counter - get raw hardware vblank counter | |
583 | * @dev: DRM device | |
584 | * @crtc: counter to fetch | |
585 | * | |
586 | * Driver callback for fetching a raw hardware vblank counter | |
587 | * for @crtc. If a device doesn't have a hardware counter, the | |
588 | * driver can simply return the value of drm_vblank_count and | |
589 | * make the enable_vblank() and disable_vblank() hooks into no-ops, | |
590 | * leaving interrupts enabled at all times. | |
591 | * | |
592 | * Wraparound handling and loss of events due to modesetting is dealt | |
593 | * with in the DRM core code. | |
594 | * | |
595 | * RETURNS | |
596 | * Raw vblank counter value. | |
597 | */ | |
598 | u32 (*get_vblank_counter) (struct drm_device *dev, int crtc); | |
599 | ||
600 | /** | |
601 | * enable_vblank - enable vblank interrupt events | |
602 | * @dev: DRM device | |
603 | * @crtc: which irq to enable | |
604 | * | |
605 | * Enable vblank interrupts for @crtc. If the device doesn't have | |
606 | * a hardware vblank counter, this routine should be a no-op, since | |
607 | * interrupts will have to stay on to keep the count accurate. | |
608 | * | |
609 | * RETURNS | |
610 | * Zero on success, appropriate errno if the given @crtc's vblank | |
611 | * interrupt cannot be enabled. | |
612 | */ | |
613 | int (*enable_vblank) (struct drm_device *dev, int crtc); | |
614 | ||
615 | /** | |
616 | * disable_vblank - disable vblank interrupt events | |
617 | * @dev: DRM device | |
618 | * @crtc: which irq to enable | |
619 | * | |
620 | * Disable vblank interrupts for @crtc. If the device doesn't have | |
621 | * a hardware vblank counter, this routine should be a no-op, since | |
622 | * interrupts will have to stay on to keep the count accurate. | |
623 | */ | |
624 | void (*disable_vblank) (struct drm_device *dev, int crtc); | |
625 | int (*dri_library_name) (struct drm_device *dev, char * buf); | |
b5e89ed5 | 626 | |
cda17380 DA |
627 | /** |
628 | * Called by \c drm_device_is_agp. Typically used to determine if a | |
629 | * card is really attached to AGP or not. | |
630 | * | |
631 | * \param dev DRM device handle | |
632 | * | |
633 | * \returns | |
634 | * One of three values is returned depending on whether or not the | |
635 | * card is absolutely \b not AGP (return of 0), absolutely \b is AGP | |
636 | * (return of 1), or may or may not be AGP (return of 2). | |
637 | */ | |
84b1fd10 | 638 | int (*device_is_agp) (struct drm_device *dev); |
cda17380 | 639 | |
1da177e4 | 640 | /* these have to be filled in */ |
b5e89ed5 | 641 | |
22eae947 | 642 | irqreturn_t(*irq_handler) (DRM_IRQ_ARGS); |
84b1fd10 | 643 | void (*irq_preinstall) (struct drm_device *dev); |
ac741ab7 | 644 | int (*irq_postinstall) (struct drm_device *dev); |
84b1fd10 | 645 | void (*irq_uninstall) (struct drm_device *dev); |
6c340eac EA |
646 | void (*reclaim_buffers) (struct drm_device *dev, |
647 | struct drm_file * file_priv); | |
d985c108 | 648 | void (*reclaim_buffers_locked) (struct drm_device *dev, |
6c340eac | 649 | struct drm_file *file_priv); |
040ac320 | 650 | void (*reclaim_buffers_idlelocked) (struct drm_device *dev, |
6c340eac | 651 | struct drm_file *file_priv); |
c60ce623 | 652 | unsigned long (*get_map_ofs) (struct drm_map * map); |
84b1fd10 DA |
653 | unsigned long (*get_reg_ofs) (struct drm_device *dev); |
654 | void (*set_version) (struct drm_device *dev, | |
c60ce623 | 655 | struct drm_set_version *sv); |
22eae947 DA |
656 | |
657 | int major; | |
658 | int minor; | |
659 | int patchlevel; | |
660 | char *name; | |
661 | char *desc; | |
662 | char *date; | |
663 | ||
1da177e4 LT |
664 | u32 driver_features; |
665 | int dev_priv_size; | |
c153f45f | 666 | struct drm_ioctl_desc *ioctls; |
1da177e4 LT |
667 | int num_ioctls; |
668 | struct file_operations fops; | |
669 | struct pci_driver pci_driver; | |
670 | }; | |
671 | ||
2c14f28b DA |
672 | #define DRM_MINOR_UNASSIGNED 0 |
673 | #define DRM_MINOR_LEGACY 1 | |
674 | ||
1da177e4 | 675 | /** |
2c14f28b | 676 | * DRM minor structure. This structure represents a drm minor number. |
1da177e4 | 677 | */ |
2c14f28b DA |
678 | struct drm_minor { |
679 | int index; /**< Minor device number */ | |
680 | int type; /**< Control or render */ | |
681 | dev_t device; /**< Device number for mknod */ | |
682 | struct device kdev; /**< Linux device */ | |
1da177e4 LT |
683 | struct drm_device *dev; |
684 | struct proc_dir_entry *dev_root; /**< proc directory entry */ | |
84b1fd10 | 685 | }; |
1da177e4 LT |
686 | |
687 | /** | |
688 | * DRM device structure. This structure represent a complete card that | |
689 | * may contain multiple heads. | |
690 | */ | |
84b1fd10 | 691 | struct drm_device { |
b5e89ed5 DA |
692 | char *unique; /**< Unique identifier: e.g., busid */ |
693 | int unique_len; /**< Length of unique field */ | |
694 | char *devname; /**< For /proc/interrupts */ | |
695 | int if_version; /**< Highest interface version set */ | |
1da177e4 | 696 | |
b5e89ed5 | 697 | int blocked; /**< Blocked due to VC switch? */ |
1da177e4 LT |
698 | |
699 | /** \name Locks */ | |
b5e89ed5 DA |
700 | /*@{ */ |
701 | spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */ | |
30e2fb18 | 702 | struct mutex struct_mutex; /**< For others */ |
b5e89ed5 | 703 | /*@} */ |
1da177e4 LT |
704 | |
705 | /** \name Usage Counters */ | |
b5e89ed5 DA |
706 | /*@{ */ |
707 | int open_count; /**< Outstanding files open */ | |
708 | atomic_t ioctl_count; /**< Outstanding IOCTLs pending */ | |
709 | atomic_t vma_count; /**< Outstanding vma areas open */ | |
710 | int buf_use; /**< Buffers in use -- cannot alloc */ | |
711 | atomic_t buf_alloc; /**< Buffer allocation in progress */ | |
712 | /*@} */ | |
1da177e4 LT |
713 | |
714 | /** \name Performance counters */ | |
b5e89ed5 DA |
715 | /*@{ */ |
716 | unsigned long counters; | |
c60ce623 | 717 | enum drm_stat_type types[15]; |
b5e89ed5 DA |
718 | atomic_t counts[15]; |
719 | /*@} */ | |
1da177e4 LT |
720 | |
721 | /** \name Authentication */ | |
b5e89ed5 | 722 | /*@{ */ |
bd1b331f | 723 | struct list_head filelist; |
e0be428e | 724 | struct drm_open_hash magiclist; /**< magic hash table */ |
8669cbc5 | 725 | struct list_head magicfree; |
b5e89ed5 | 726 | /*@} */ |
1da177e4 LT |
727 | |
728 | /** \name Memory management */ | |
b5e89ed5 | 729 | /*@{ */ |
bd1b331f | 730 | struct list_head maplist; /**< Linked list of regions */ |
b5e89ed5 | 731 | int map_count; /**< Number of mappable regions */ |
e0be428e | 732 | struct drm_open_hash map_hash; /**< User token hash table for maps */ |
1da177e4 LT |
733 | |
734 | /** \name Context handle management */ | |
b5e89ed5 | 735 | /*@{ */ |
bd1b331f | 736 | struct list_head ctxlist; /**< Linked list of context handles */ |
b5e89ed5 | 737 | int ctx_count; /**< Number of context handles */ |
30e2fb18 | 738 | struct mutex ctxlist_mutex; /**< For ctxlist */ |
1da177e4 | 739 | |
62968144 | 740 | struct idr ctx_idr; |
1da177e4 | 741 | |
bd1b331f | 742 | struct list_head vmalist; /**< List of vmas (for debugging) */ |
55910517 | 743 | struct drm_lock_data lock; /**< Information on hardware lock */ |
b5e89ed5 | 744 | /*@} */ |
1da177e4 LT |
745 | |
746 | /** \name DMA queues (contexts) */ | |
b5e89ed5 DA |
747 | /*@{ */ |
748 | int queue_count; /**< Number of active DMA queues */ | |
749 | int queue_reserved; /**< Number of reserved DMA queues */ | |
750 | int queue_slots; /**< Actual length of queuelist */ | |
cdd55a29 DA |
751 | struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */ |
752 | struct drm_device_dma *dma; /**< Optional pointer for DMA support */ | |
b5e89ed5 | 753 | /*@} */ |
1da177e4 LT |
754 | |
755 | /** \name Context support */ | |
b5e89ed5 DA |
756 | /*@{ */ |
757 | int irq; /**< Interrupt used by board */ | |
758 | int irq_enabled; /**< True if irq handler is enabled */ | |
1da177e4 LT |
759 | __volatile__ long context_flag; /**< Context swapping flag */ |
760 | __volatile__ long interrupt_flag; /**< Interruption handler flag */ | |
761 | __volatile__ long dma_flag; /**< DMA dispatch flag */ | |
762 | struct timer_list timer; /**< Timer for delaying ctx switch */ | |
b5e89ed5 DA |
763 | wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */ |
764 | int last_checked; /**< Last context checked for DMA */ | |
765 | int last_context; /**< Last current context */ | |
766 | unsigned long last_switch; /**< jiffies at last context switch */ | |
767 | /*@} */ | |
768 | ||
769 | struct work_struct work; | |
1da177e4 | 770 | /** \name VBLANK IRQ support */ |
b5e89ed5 DA |
771 | /*@{ */ |
772 | ||
ac741ab7 JB |
773 | wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */ |
774 | atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */ | |
b5e89ed5 | 775 | spinlock_t vbl_lock; |
ac741ab7 JB |
776 | struct list_head *vbl_sigs; /**< signal list to send on VBLANK */ |
777 | atomic_t vbl_signal_pending; /* number of signals pending on all crtcs*/ | |
778 | atomic_t *vblank_refcount; /* number of users of vblank interrupts per crtc */ | |
779 | u32 *last_vblank; /* protected by dev->vbl_lock, used */ | |
780 | /* for wraparound handling */ | |
781 | u32 *vblank_offset; /* used to track how many vblanks */ | |
782 | int *vblank_enabled; /* so we don't call enable more than | |
783 | once per disable */ | |
784 | u32 *vblank_premodeset; /* were lost during modeset */ | |
785 | struct timer_list vblank_disable_timer; | |
786 | ||
787 | unsigned long max_vblank_count; /**< size of vblank counter register */ | |
2e54a007 MCA |
788 | spinlock_t tasklet_lock; /**< For drm_locked_tasklet */ |
789 | void (*locked_tasklet_func)(struct drm_device *dev); | |
b5e89ed5 DA |
790 | |
791 | /*@} */ | |
792 | cycles_t ctx_start; | |
793 | cycles_t lck_start; | |
794 | ||
1da177e4 LT |
795 | struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */ |
796 | wait_queue_head_t buf_readers; /**< Processes waiting to read */ | |
797 | wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */ | |
798 | ||
55910517 | 799 | struct drm_agp_head *agp; /**< AGP data */ |
1da177e4 | 800 | |
b5e89ed5 | 801 | struct pci_dev *pdev; /**< PCI device structure */ |
2f02cc3f EA |
802 | int pci_vendor; /**< PCI vendor id */ |
803 | int pci_device; /**< PCI device id */ | |
1da177e4 | 804 | #ifdef __alpha__ |
1da177e4 | 805 | struct pci_controller *hose; |
1da177e4 | 806 | #endif |
ac741ab7 | 807 | int num_crtcs; /**< Number of CRTCs on this device */ |
55910517 | 808 | struct drm_sg_mem *sg; /**< Scatter gather memory */ |
b5e89ed5 | 809 | void *dev_private; /**< device private data */ |
55910517 | 810 | struct drm_sigdata sigdata; /**< For block_all_signals */ |
b5e89ed5 DA |
811 | sigset_t sigmask; |
812 | ||
813 | struct drm_driver *driver; | |
814 | drm_local_map_t *agp_buffer_map; | |
d1f2b55a | 815 | unsigned int agp_buffer_token; |
2c14f28b | 816 | struct drm_minor *primary; /**< render type primary screen head */ |
bea5679f MCA |
817 | |
818 | /** \name Drawable information */ | |
819 | /*@{ */ | |
820 | spinlock_t drw_lock; | |
d4e2cbe9 | 821 | struct idr drw_idr; |
bea5679f | 822 | /*@} */ |
84b1fd10 | 823 | }; |
1da177e4 | 824 | |
b5e89ed5 DA |
825 | static __inline__ int drm_core_check_feature(struct drm_device *dev, |
826 | int feature) | |
1da177e4 LT |
827 | { |
828 | return ((dev->driver->driver_features & feature) ? 1 : 0); | |
829 | } | |
830 | ||
33229601 | 831 | #ifdef __alpha__ |
6244270e | 832 | #define drm_get_pci_domain(dev) dev->hose->index |
33229601 | 833 | #else |
9b1a51b6 | 834 | #define drm_get_pci_domain(dev) 0 |
33229601 DA |
835 | #endif |
836 | ||
1da177e4 LT |
837 | #if __OS_HAS_AGP |
838 | static inline int drm_core_has_AGP(struct drm_device *dev) | |
839 | { | |
b5e89ed5 | 840 | return drm_core_check_feature(dev, DRIVER_USE_AGP); |
1da177e4 LT |
841 | } |
842 | #else | |
843 | #define drm_core_has_AGP(dev) (0) | |
844 | #endif | |
845 | ||
846 | #if __OS_HAS_MTRR | |
847 | static inline int drm_core_has_MTRR(struct drm_device *dev) | |
848 | { | |
b5e89ed5 | 849 | return drm_core_check_feature(dev, DRIVER_USE_MTRR); |
1da177e4 | 850 | } |
269dc512 DA |
851 | |
852 | #define DRM_MTRR_WC MTRR_TYPE_WRCOMB | |
853 | ||
854 | static inline int drm_mtrr_add(unsigned long offset, unsigned long size, | |
855 | unsigned int flags) | |
856 | { | |
857 | return mtrr_add(offset, size, flags, 1); | |
858 | } | |
859 | ||
860 | static inline int drm_mtrr_del(int handle, unsigned long offset, | |
861 | unsigned long size, unsigned int flags) | |
862 | { | |
863 | return mtrr_del(handle, offset, size); | |
864 | } | |
865 | ||
1da177e4 LT |
866 | #else |
867 | #define drm_core_has_MTRR(dev) (0) | |
9c7d462e DA |
868 | |
869 | #define DRM_MTRR_WC 0 | |
870 | ||
871 | static inline int drm_mtrr_add(unsigned long offset, unsigned long size, | |
872 | unsigned int flags) | |
873 | { | |
874 | return 0; | |
875 | } | |
876 | ||
877 | static inline int drm_mtrr_del(int handle, unsigned long offset, | |
878 | unsigned long size, unsigned int flags) | |
879 | { | |
880 | return 0; | |
881 | } | |
1da177e4 LT |
882 | #endif |
883 | ||
884 | /******************************************************************/ | |
885 | /** \name Internal function definitions */ | |
886 | /*@{*/ | |
887 | ||
1da177e4 | 888 | /* Driver support (drm_drv.h) */ |
b5e89ed5 DA |
889 | extern int drm_init(struct drm_driver *driver); |
890 | extern void drm_exit(struct drm_driver *driver); | |
891 | extern int drm_ioctl(struct inode *inode, struct file *filp, | |
892 | unsigned int cmd, unsigned long arg); | |
893 | extern long drm_compat_ioctl(struct file *filp, | |
894 | unsigned int cmd, unsigned long arg); | |
84b1fd10 | 895 | extern int drm_lastclose(struct drm_device *dev); |
1da177e4 LT |
896 | |
897 | /* Device support (drm_fops.h) */ | |
b5e89ed5 DA |
898 | extern int drm_open(struct inode *inode, struct file *filp); |
899 | extern int drm_stub_open(struct inode *inode, struct file *filp); | |
b5e89ed5 DA |
900 | extern int drm_fasync(int fd, struct file *filp, int on); |
901 | extern int drm_release(struct inode *inode, struct file *filp); | |
1da177e4 LT |
902 | |
903 | /* Mapping support (drm_vm.h) */ | |
b5e89ed5 | 904 | extern int drm_mmap(struct file *filp, struct vm_area_struct *vma); |
ded23359 DA |
905 | extern unsigned long drm_core_get_map_ofs(struct drm_map * map); |
906 | extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev); | |
b5e89ed5 | 907 | extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); |
1da177e4 LT |
908 | |
909 | /* Memory management support (drm_memory.h) */ | |
910 | #include "drm_memory.h" | |
b5e89ed5 DA |
911 | extern void drm_mem_init(void); |
912 | extern int drm_mem_info(char *buf, char **start, off_t offset, | |
913 | int request, int *eof, void *data); | |
914 | extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area); | |
b5e89ed5 | 915 | |
84b1fd10 | 916 | extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type); |
b5e89ed5 DA |
917 | extern int drm_free_agp(DRM_AGP_MEM * handle, int pages); |
918 | extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start); | |
919 | extern int drm_unbind_agp(DRM_AGP_MEM * handle); | |
1da177e4 LT |
920 | |
921 | /* Misc. IOCTL support (drm_ioctl.h) */ | |
c153f45f EA |
922 | extern int drm_irq_by_busid(struct drm_device *dev, void *data, |
923 | struct drm_file *file_priv); | |
924 | extern int drm_getunique(struct drm_device *dev, void *data, | |
925 | struct drm_file *file_priv); | |
926 | extern int drm_setunique(struct drm_device *dev, void *data, | |
927 | struct drm_file *file_priv); | |
928 | extern int drm_getmap(struct drm_device *dev, void *data, | |
929 | struct drm_file *file_priv); | |
930 | extern int drm_getclient(struct drm_device *dev, void *data, | |
931 | struct drm_file *file_priv); | |
932 | extern int drm_getstats(struct drm_device *dev, void *data, | |
933 | struct drm_file *file_priv); | |
934 | extern int drm_setversion(struct drm_device *dev, void *data, | |
935 | struct drm_file *file_priv); | |
936 | extern int drm_noop(struct drm_device *dev, void *data, | |
937 | struct drm_file *file_priv); | |
1da177e4 LT |
938 | |
939 | /* Context IOCTL support (drm_context.h) */ | |
c153f45f EA |
940 | extern int drm_resctx(struct drm_device *dev, void *data, |
941 | struct drm_file *file_priv); | |
942 | extern int drm_addctx(struct drm_device *dev, void *data, | |
943 | struct drm_file *file_priv); | |
944 | extern int drm_modctx(struct drm_device *dev, void *data, | |
945 | struct drm_file *file_priv); | |
946 | extern int drm_getctx(struct drm_device *dev, void *data, | |
947 | struct drm_file *file_priv); | |
948 | extern int drm_switchctx(struct drm_device *dev, void *data, | |
949 | struct drm_file *file_priv); | |
950 | extern int drm_newctx(struct drm_device *dev, void *data, | |
951 | struct drm_file *file_priv); | |
952 | extern int drm_rmctx(struct drm_device *dev, void *data, | |
953 | struct drm_file *file_priv); | |
b5e89ed5 | 954 | |
84b1fd10 DA |
955 | extern int drm_ctxbitmap_init(struct drm_device *dev); |
956 | extern void drm_ctxbitmap_cleanup(struct drm_device *dev); | |
957 | extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); | |
b5e89ed5 | 958 | |
c153f45f EA |
959 | extern int drm_setsareactx(struct drm_device *dev, void *data, |
960 | struct drm_file *file_priv); | |
961 | extern int drm_getsareactx(struct drm_device *dev, void *data, | |
962 | struct drm_file *file_priv); | |
1da177e4 LT |
963 | |
964 | /* Drawable IOCTL support (drm_drawable.h) */ | |
c153f45f EA |
965 | extern int drm_adddraw(struct drm_device *dev, void *data, |
966 | struct drm_file *file_priv); | |
967 | extern int drm_rmdraw(struct drm_device *dev, void *data, | |
968 | struct drm_file *file_priv); | |
969 | extern int drm_update_drawable_info(struct drm_device *dev, void *data, | |
970 | struct drm_file *file_priv); | |
84b1fd10 | 971 | extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev, |
bea5679f | 972 | drm_drawable_t id); |
d4e2cbe9 | 973 | extern void drm_drawable_free_all(struct drm_device *dev); |
1da177e4 LT |
974 | |
975 | /* Authentication IOCTL support (drm_auth.h) */ | |
c153f45f EA |
976 | extern int drm_getmagic(struct drm_device *dev, void *data, |
977 | struct drm_file *file_priv); | |
978 | extern int drm_authmagic(struct drm_device *dev, void *data, | |
979 | struct drm_file *file_priv); | |
1da177e4 | 980 | |
1da177e4 | 981 | /* Locking IOCTL support (drm_lock.h) */ |
c153f45f EA |
982 | extern int drm_lock(struct drm_device *dev, void *data, |
983 | struct drm_file *file_priv); | |
984 | extern int drm_unlock(struct drm_device *dev, void *data, | |
985 | struct drm_file *file_priv); | |
55910517 DA |
986 | extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context); |
987 | extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context); | |
988 | extern void drm_idlelock_take(struct drm_lock_data *lock_data); | |
989 | extern void drm_idlelock_release(struct drm_lock_data *lock_data); | |
040ac320 TH |
990 | |
991 | /* | |
992 | * These are exported to drivers so that they can implement fencing using | |
993 | * DMA quiscent + idle. DMA quiescent usually requires the hardware lock. | |
994 | */ | |
995 | ||
c153f45f | 996 | extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv); |
1da177e4 LT |
997 | |
998 | /* Buffer management support (drm_bufs.h) */ | |
84b1fd10 DA |
999 | extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request); |
1000 | extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request); | |
1001 | extern int drm_addmap(struct drm_device *dev, unsigned int offset, | |
c60ce623 DA |
1002 | unsigned int size, enum drm_map_type type, |
1003 | enum drm_map_flags flags, drm_local_map_t ** map_ptr); | |
c153f45f EA |
1004 | extern int drm_addmap_ioctl(struct drm_device *dev, void *data, |
1005 | struct drm_file *file_priv); | |
1006 | extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map); | |
1007 | extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map); | |
1008 | extern int drm_rmmap_ioctl(struct drm_device *dev, void *data, | |
1009 | struct drm_file *file_priv); | |
1010 | extern int drm_addbufs(struct drm_device *dev, void *data, | |
1011 | struct drm_file *file_priv); | |
1012 | extern int drm_infobufs(struct drm_device *dev, void *data, | |
1013 | struct drm_file *file_priv); | |
1014 | extern int drm_markbufs(struct drm_device *dev, void *data, | |
1015 | struct drm_file *file_priv); | |
1016 | extern int drm_freebufs(struct drm_device *dev, void *data, | |
1017 | struct drm_file *file_priv); | |
1018 | extern int drm_mapbufs(struct drm_device *dev, void *data, | |
1019 | struct drm_file *file_priv); | |
b5e89ed5 | 1020 | extern int drm_order(unsigned long size); |
84b1fd10 | 1021 | extern unsigned long drm_get_resource_start(struct drm_device *dev, |
836cf046 | 1022 | unsigned int resource); |
84b1fd10 | 1023 | extern unsigned long drm_get_resource_len(struct drm_device *dev, |
836cf046 | 1024 | unsigned int resource); |
1da177e4 LT |
1025 | |
1026 | /* DMA support (drm_dma.h) */ | |
84b1fd10 DA |
1027 | extern int drm_dma_setup(struct drm_device *dev); |
1028 | extern void drm_dma_takedown(struct drm_device *dev); | |
056219e2 | 1029 | extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf); |
6c340eac EA |
1030 | extern void drm_core_reclaim_buffers(struct drm_device *dev, |
1031 | struct drm_file *filp); | |
1da177e4 LT |
1032 | |
1033 | /* IRQ support (drm_irq.h) */ | |
c153f45f EA |
1034 | extern int drm_control(struct drm_device *dev, void *data, |
1035 | struct drm_file *file_priv); | |
b5e89ed5 | 1036 | extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS); |
84b1fd10 DA |
1037 | extern int drm_irq_uninstall(struct drm_device *dev); |
1038 | extern void drm_driver_irq_preinstall(struct drm_device *dev); | |
1039 | extern void drm_driver_irq_postinstall(struct drm_device *dev); | |
1040 | extern void drm_driver_irq_uninstall(struct drm_device *dev); | |
b5e89ed5 | 1041 | |
ac741ab7 JB |
1042 | extern int drm_vblank_init(struct drm_device *dev, int num_crtcs); |
1043 | extern int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *filp); | |
1044 | extern int drm_vblank_wait(struct drm_device * dev, unsigned int *vbl_seq); | |
84b1fd10 | 1045 | extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*)); |
ac741ab7 JB |
1046 | extern u32 drm_vblank_count(struct drm_device *dev, int crtc); |
1047 | extern void drm_update_vblank_count(struct drm_device *dev, int crtc); | |
1048 | extern void drm_handle_vblank(struct drm_device *dev, int crtc); | |
1049 | extern int drm_vblank_get(struct drm_device *dev, int crtc); | |
1050 | extern void drm_vblank_put(struct drm_device *dev, int crtc); | |
1051 | ||
1052 | /* Modesetting support */ | |
1053 | extern int drm_modeset_ctl(struct drm_device *dev, void *data, | |
1054 | struct drm_file *file_priv); | |
1da177e4 LT |
1055 | |
1056 | /* AGP/GART support (drm_agpsupport.h) */ | |
55910517 | 1057 | extern struct drm_agp_head *drm_agp_init(struct drm_device *dev); |
84b1fd10 | 1058 | extern int drm_agp_acquire(struct drm_device *dev); |
c153f45f EA |
1059 | extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data, |
1060 | struct drm_file *file_priv); | |
84b1fd10 | 1061 | extern int drm_agp_release(struct drm_device *dev); |
c153f45f EA |
1062 | extern int drm_agp_release_ioctl(struct drm_device *dev, void *data, |
1063 | struct drm_file *file_priv); | |
84b1fd10 | 1064 | extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode); |
c153f45f EA |
1065 | extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data, |
1066 | struct drm_file *file_priv); | |
1067 | extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info); | |
1068 | extern int drm_agp_info_ioctl(struct drm_device *dev, void *data, | |
1069 | struct drm_file *file_priv); | |
84b1fd10 | 1070 | extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request); |
c153f45f EA |
1071 | extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data, |
1072 | struct drm_file *file_priv); | |
84b1fd10 | 1073 | extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request); |
c153f45f EA |
1074 | extern int drm_agp_free_ioctl(struct drm_device *dev, void *data, |
1075 | struct drm_file *file_priv); | |
84b1fd10 | 1076 | extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request); |
c153f45f EA |
1077 | extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data, |
1078 | struct drm_file *file_priv); | |
84b1fd10 | 1079 | extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request); |
c153f45f EA |
1080 | extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data, |
1081 | struct drm_file *file_priv); | |
1082 | extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type); | |
b5e89ed5 DA |
1083 | extern int drm_agp_free_memory(DRM_AGP_MEM * handle); |
1084 | extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start); | |
1085 | extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle); | |
1da177e4 LT |
1086 | |
1087 | /* Stub support (drm_stub.h) */ | |
1088 | extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent, | |
b5e89ed5 | 1089 | struct drm_driver *driver); |
84b1fd10 | 1090 | extern int drm_put_dev(struct drm_device *dev); |
2c14f28b | 1091 | extern int drm_put_minor(struct drm_minor **minor); |
b5e89ed5 | 1092 | extern unsigned int drm_debug; |
2c14f28b | 1093 | |
0650fd58 | 1094 | extern struct class *drm_class; |
1da177e4 LT |
1095 | extern struct proc_dir_entry *drm_proc_root; |
1096 | ||
2c14f28b DA |
1097 | extern struct idr drm_minors_idr; |
1098 | ||
da509d7a DA |
1099 | extern drm_local_map_t *drm_getsarea(struct drm_device *dev); |
1100 | ||
1da177e4 | 1101 | /* Proc support (drm_proc.h) */ |
2c14f28b DA |
1102 | extern int drm_proc_init(struct drm_minor *minor, int minor_id, |
1103 | struct proc_dir_entry *root); | |
1104 | extern int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root); | |
1da177e4 LT |
1105 | |
1106 | /* Scatter Gather Support (drm_scatter.h) */ | |
55910517 | 1107 | extern void drm_sg_cleanup(struct drm_sg_mem * entry); |
c153f45f EA |
1108 | extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data, |
1109 | struct drm_file *file_priv); | |
1110 | extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request); | |
1111 | extern int drm_sg_free(struct drm_device *dev, void *data, | |
1112 | struct drm_file *file_priv); | |
1da177e4 | 1113 | |
b5e89ed5 | 1114 | /* ATI PCIGART support (ati_pcigart.h) */ |
84b1fd10 | 1115 | extern int drm_ati_pcigart_init(struct drm_device *dev, |
55910517 | 1116 | struct drm_ati_pcigart_info * gart_info); |
84b1fd10 | 1117 | extern int drm_ati_pcigart_cleanup(struct drm_device *dev, |
55910517 | 1118 | struct drm_ati_pcigart_info * gart_info); |
1da177e4 | 1119 | |
84b1fd10 | 1120 | extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, |
9c8da5eb | 1121 | size_t align, dma_addr_t maxaddr); |
84b1fd10 DA |
1122 | extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah); |
1123 | extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah); | |
1da177e4 LT |
1124 | |
1125 | /* sysfs support (drm_sysfs.c) */ | |
e8b962b6 | 1126 | struct drm_sysfs_class; |
0650fd58 | 1127 | extern struct class *drm_sysfs_create(struct module *owner, char *name); |
e8b962b6 | 1128 | extern void drm_sysfs_destroy(void); |
2c14f28b DA |
1129 | extern int drm_sysfs_device_add(struct drm_minor *minor); |
1130 | extern void drm_sysfs_device_remove(struct drm_minor *minor); | |
1da177e4 | 1131 | |
3a1bd924 TH |
1132 | /* |
1133 | * Basic memory manager support (drm_mm.c) | |
1134 | */ | |
55910517 | 1135 | extern struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent, |
3a1bd924 TH |
1136 | unsigned long size, |
1137 | unsigned alignment); | |
8562b3f2 | 1138 | extern void drm_mm_put_block(struct drm_mm_node * cur); |
55910517 | 1139 | extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size, |
3a1bd924 | 1140 | unsigned alignment, int best_match); |
55910517 DA |
1141 | extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size); |
1142 | extern void drm_mm_takedown(struct drm_mm *mm); | |
1143 | extern int drm_mm_clean(struct drm_mm *mm); | |
1144 | extern unsigned long drm_mm_tail_space(struct drm_mm *mm); | |
1145 | extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size); | |
1146 | extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size); | |
3a1bd924 | 1147 | |
004a7727 CH |
1148 | extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev); |
1149 | extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev); | |
1da177e4 | 1150 | |
b5e89ed5 DA |
1151 | static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, |
1152 | unsigned int token) | |
1da177e4 | 1153 | { |
55910517 | 1154 | struct drm_map_list *_entry; |
bd1b331f | 1155 | list_for_each_entry(_entry, &dev->maplist, head) |
b5e89ed5 DA |
1156 | if (_entry->user_token == token) |
1157 | return _entry->map; | |
1da177e4 LT |
1158 | return NULL; |
1159 | } | |
1160 | ||
84b1fd10 | 1161 | static __inline__ int drm_device_is_agp(struct drm_device *dev) |
cda17380 | 1162 | { |
b5e89ed5 DA |
1163 | if (dev->driver->device_is_agp != NULL) { |
1164 | int err = (*dev->driver->device_is_agp) (dev); | |
1165 | ||
cda17380 DA |
1166 | if (err != 2) { |
1167 | return err; | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP); | |
1172 | } | |
1173 | ||
84b1fd10 | 1174 | static __inline__ int drm_device_is_pcie(struct drm_device *dev) |
ea98a92f DA |
1175 | { |
1176 | return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP); | |
1177 | } | |
1178 | ||
1da177e4 LT |
1179 | static __inline__ void drm_core_dropmap(struct drm_map *map) |
1180 | { | |
1181 | } | |
1182 | ||
1183 | #ifndef DEBUG_MEMORY | |
1184 | /** Wrapper around kmalloc() */ | |
1185 | static __inline__ void *drm_alloc(size_t size, int area) | |
1186 | { | |
1187 | return kmalloc(size, GFP_KERNEL); | |
1188 | } | |
1189 | ||
1190 | /** Wrapper around kfree() */ | |
1191 | static __inline__ void drm_free(void *pt, size_t size, int area) | |
1192 | { | |
1193 | kfree(pt); | |
1194 | } | |
b9523249 DA |
1195 | |
1196 | /** Wrapper around kcalloc() */ | |
1197 | static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area) | |
1198 | { | |
1199 | return kcalloc(nmemb, size, GFP_KERNEL); | |
1200 | } | |
1da177e4 LT |
1201 | #else |
1202 | extern void *drm_alloc(size_t size, int area); | |
1203 | extern void drm_free(void *pt, size_t size, int area); | |
b9523249 | 1204 | extern void *drm_calloc(size_t nmemb, size_t size, int area); |
1da177e4 LT |
1205 | #endif |
1206 | ||
1207 | /*@}*/ | |
1208 | ||
b5e89ed5 | 1209 | #endif /* __KERNEL__ */ |
1da177e4 | 1210 | #endif |