Linux 2.4.0-test9pre1
[davej-history.git] / drivers / char / drm / drmP.h
blob2bfd4befa0ef841f2d2e8ee94cb0f17a94113086
1 /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All rights reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
27 * Authors:
28 * Rickard E. (Rik) Faith <faith@valinux.com>
32 #ifndef _DRM_P_H_
33 #define _DRM_P_H_
35 #ifdef __KERNEL__
36 #ifdef __alpha__
37 /* add include of current.h so that "current" is defined
38 * before static inline funcs in wait.h. Doing this so we
39 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
40 #include <asm/current.h>
41 #endif /* __alpha__ */
42 #include <linux/config.h>
43 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/miscdevice.h>
46 #include <linux/fs.h>
47 #include <linux/proc_fs.h>
48 #include <linux/init.h>
49 #include <linux/file.h>
50 #include <linux/pci.h>
51 #include <linux/wrapper.h>
52 #include <linux/version.h>
53 #include <linux/sched.h>
54 #include <linux/smp_lock.h> /* For (un)lock_kernel */
55 #include <linux/mm.h>
56 #ifdef __alpha__
57 #include <asm/pgtable.h> /* For pte_wrprotect */
58 #endif
59 #include <asm/io.h>
60 #include <asm/mman.h>
61 #include <asm/uaccess.h>
62 #ifdef CONFIG_MTRR
63 #include <asm/mtrr.h>
64 #endif
65 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
66 #include <linux/types.h>
67 #include <linux/agp_backend.h>
68 #endif
69 #if LINUX_VERSION_CODE >= 0x020100 /* KERNEL_VERSION(2,1,0) */
70 #include <linux/tqueue.h>
71 #include <linux/poll.h>
72 #endif
73 #if LINUX_VERSION_CODE < 0x020400
74 #include "compat-pre24.h"
75 #endif
76 #include "drm.h"
78 #define DRM_DEBUG_CODE 2 /* Include debugging code (if > 1, then
79 also include looping detection. */
80 #define DRM_DMA_HISTOGRAM 1 /* Make histogram of DMA latency. */
82 #define DRM_HASH_SIZE 16 /* Size of key hash table */
83 #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */
84 #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */
85 #define DRM_LOOPING_LIMIT 5000000
86 #define DRM_BSZ 1024 /* Buffer size for /dev/drm? output */
87 #define DRM_TIME_SLICE (HZ/20) /* Time slice for GLXContexts */
88 #define DRM_LOCK_SLICE 1 /* Time slice for lock, in jiffies */
90 #define DRM_FLAG_DEBUG 0x01
91 #define DRM_FLAG_NOCTX 0x02
93 #define DRM_MEM_DMA 0
94 #define DRM_MEM_SAREA 1
95 #define DRM_MEM_DRIVER 2
96 #define DRM_MEM_MAGIC 3
97 #define DRM_MEM_IOCTLS 4
98 #define DRM_MEM_MAPS 5
99 #define DRM_MEM_VMAS 6
100 #define DRM_MEM_BUFS 7
101 #define DRM_MEM_SEGS 8
102 #define DRM_MEM_PAGES 9
103 #define DRM_MEM_FILES 10
104 #define DRM_MEM_QUEUES 11
105 #define DRM_MEM_CMDS 12
106 #define DRM_MEM_MAPPINGS 13
107 #define DRM_MEM_BUFLISTS 14
108 #define DRM_MEM_AGPLISTS 15
109 #define DRM_MEM_TOTALAGP 16
110 #define DRM_MEM_BOUNDAGP 17
111 #define DRM_MEM_CTXBITMAP 18
113 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
115 /* Backward compatibility section */
116 /* _PAGE_WT changed to _PAGE_PWT in 2.2.6 */
117 #ifndef _PAGE_PWT
118 #define _PAGE_PWT _PAGE_WT
119 #endif
120 /* Wait queue declarations changed in 2.3.1 */
121 #ifndef DECLARE_WAITQUEUE
122 #define DECLARE_WAITQUEUE(w,c) struct wait_queue w = { c, NULL }
123 typedef struct wait_queue *wait_queue_head_t;
124 #define init_waitqueue_head(q) *q = NULL;
125 #endif
127 /* _PAGE_4M changed to _PAGE_PSE in 2.3.23 */
128 #ifndef _PAGE_PSE
129 #define _PAGE_PSE _PAGE_4M
130 #endif
132 /* vm_offset changed to vm_pgoff in 2.3.25 */
133 #if LINUX_VERSION_CODE < 0x020319
134 #define VM_OFFSET(vma) ((vma)->vm_offset)
135 #else
136 #define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
137 #endif
139 /* *_nopage return values defined in 2.3.26 */
140 #ifndef NOPAGE_SIGBUS
141 #define NOPAGE_SIGBUS 0
142 #endif
143 #ifndef NOPAGE_OOM
144 #define NOPAGE_OOM 0
145 #endif
147 /* module_init/module_exit added in 2.3.13 */
148 #ifndef module_init
149 #define module_init(x) int init_module(void) { return x(); }
150 #endif
151 #ifndef module_exit
152 #define module_exit(x) void cleanup_module(void) { x(); }
153 #endif
155 /* Generic cmpxchg added in 2.3.x */
156 #ifndef __HAVE_ARCH_CMPXCHG
157 /* Include this here so that driver can be
158 used with older kernels. */
159 #if defined(__alpha__)
160 static __inline__ unsigned long
161 __cmpxchg_u32(volatile int *m, int old, int new)
163 unsigned long prev, cmp;
165 __asm__ __volatile__(
166 "1: ldl_l %0,%2\n"
167 " cmpeq %0,%3,%1\n"
168 " beq %1,2f\n"
169 " mov %4,%1\n"
170 " stl_c %1,%2\n"
171 " beq %1,3f\n"
172 "2: mb\n"
173 ".subsection 2\n"
174 "3: br 1b\n"
175 ".previous"
176 : "=&r"(prev), "=&r"(cmp), "=m"(*m)
177 : "r"((long) old), "r"(new), "m"(*m));
179 return prev;
182 static __inline__ unsigned long
183 __cmpxchg_u64(volatile long *m, unsigned long old, unsigned long new)
185 unsigned long prev, cmp;
187 __asm__ __volatile__(
188 "1: ldq_l %0,%2\n"
189 " cmpeq %0,%3,%1\n"
190 " beq %1,2f\n"
191 " mov %4,%1\n"
192 " stq_c %1,%2\n"
193 " beq %1,3f\n"
194 "2: mb\n"
195 ".subsection 2\n"
196 "3: br 1b\n"
197 ".previous"
198 : "=&r"(prev), "=&r"(cmp), "=m"(*m)
199 : "r"((long) old), "r"(new), "m"(*m));
201 return prev;
204 static __inline__ unsigned long
205 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
207 switch (size) {
208 case 4:
209 return __cmpxchg_u32(ptr, old, new);
210 case 8:
211 return __cmpxchg_u64(ptr, old, new);
213 return old;
215 #define cmpxchg(ptr,o,n) \
216 ({ \
217 __typeof__(*(ptr)) _o_ = (o); \
218 __typeof__(*(ptr)) _n_ = (n); \
219 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
220 (unsigned long)_n_, sizeof(*(ptr))); \
223 #elif __i386__
224 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
225 unsigned long new, int size)
227 unsigned long prev;
228 switch (size) {
229 case 1:
230 __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
231 : "=a"(prev)
232 : "q"(new), "m"(*__xg(ptr)), "0"(old)
233 : "memory");
234 return prev;
235 case 2:
236 __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
237 : "=a"(prev)
238 : "q"(new), "m"(*__xg(ptr)), "0"(old)
239 : "memory");
240 return prev;
241 case 4:
242 __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
243 : "=a"(prev)
244 : "q"(new), "m"(*__xg(ptr)), "0"(old)
245 : "memory");
246 return prev;
248 return old;
251 #define cmpxchg(ptr,o,n) \
252 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o), \
253 (unsigned long)(n),sizeof(*(ptr))))
254 #endif /* i386 & alpha */
255 #endif
257 /* Macros to make printk easier */
258 #define DRM_ERROR(fmt, arg...) \
259 printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg)
260 #define DRM_MEM_ERROR(area, fmt, arg...) \
261 printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \
262 drm_mem_stats[area].name , ##arg)
263 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
265 #if DRM_DEBUG_CODE
266 #define DRM_DEBUG(fmt, arg...) \
267 do { \
268 if (drm_flags&DRM_FLAG_DEBUG) \
269 printk(KERN_DEBUG \
270 "[" DRM_NAME ":" __FUNCTION__ "] " fmt , \
271 ##arg); \
272 } while (0)
273 #else
274 #define DRM_DEBUG(fmt, arg...) do { } while (0)
275 #endif
277 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
279 #define DRM_PROC_PRINT(fmt, arg...) \
280 len += sprintf(&buf[len], fmt , ##arg); \
281 if (len > DRM_PROC_LIMIT) return len;
283 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
284 len += sprintf(&buf[len], fmt , ##arg); \
285 if (len > DRM_PROC_LIMIT) { ret; return len; }
287 /* Internal types and structures */
288 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
289 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
290 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
292 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
293 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
294 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
296 typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
297 unsigned int cmd, unsigned long arg);
299 typedef struct drm_ioctl_desc {
300 drm_ioctl_t *func;
301 int auth_needed;
302 int root_only;
303 } drm_ioctl_desc_t;
305 typedef struct drm_devstate {
306 pid_t owner; /* X server pid holding x_lock */
308 } drm_devstate_t;
310 typedef struct drm_magic_entry {
311 drm_magic_t magic;
312 struct drm_file *priv;
313 struct drm_magic_entry *next;
314 } drm_magic_entry_t;
316 typedef struct drm_magic_head {
317 struct drm_magic_entry *head;
318 struct drm_magic_entry *tail;
319 } drm_magic_head_t;
321 typedef struct drm_vma_entry {
322 struct vm_area_struct *vma;
323 struct drm_vma_entry *next;
324 pid_t pid;
325 } drm_vma_entry_t;
327 typedef struct drm_buf {
328 int idx; /* Index into master buflist */
329 int total; /* Buffer size */
330 int order; /* log-base-2(total) */
331 int used; /* Amount of buffer in use (for DMA) */
332 unsigned long offset; /* Byte offset (used internally) */
333 void *address; /* Address of buffer */
334 unsigned long bus_address; /* Bus address of buffer */
335 struct drm_buf *next; /* Kernel-only: used for free list */
336 __volatile__ int waiting; /* On kernel DMA queue */
337 __volatile__ int pending; /* On hardware DMA queue */
338 wait_queue_head_t dma_wait; /* Processes waiting */
339 pid_t pid; /* PID of holding process */
340 int context; /* Kernel queue for this buffer */
341 int while_locked;/* Dispatch this buffer while locked */
342 enum {
343 DRM_LIST_NONE = 0,
344 DRM_LIST_FREE = 1,
345 DRM_LIST_WAIT = 2,
346 DRM_LIST_PEND = 3,
347 DRM_LIST_PRIO = 4,
348 DRM_LIST_RECLAIM = 5
349 } list; /* Which list we're on */
351 #if DRM_DMA_HISTOGRAM
352 cycles_t time_queued; /* Queued to kernel DMA queue */
353 cycles_t time_dispatched; /* Dispatched to hardware */
354 cycles_t time_completed; /* Completed by hardware */
355 cycles_t time_freed; /* Back on freelist */
356 #endif
358 int dev_priv_size; /* Size of buffer private stoarge */
359 void *dev_private; /* Per-buffer private storage */
360 } drm_buf_t;
362 #if DRM_DMA_HISTOGRAM
363 #define DRM_DMA_HISTOGRAM_SLOTS 9
364 #define DRM_DMA_HISTOGRAM_INITIAL 10
365 #define DRM_DMA_HISTOGRAM_NEXT(current) ((current)*10)
366 typedef struct drm_histogram {
367 atomic_t total;
369 atomic_t queued_to_dispatched[DRM_DMA_HISTOGRAM_SLOTS];
370 atomic_t dispatched_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
371 atomic_t completed_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
373 atomic_t queued_to_completed[DRM_DMA_HISTOGRAM_SLOTS];
374 atomic_t queued_to_freed[DRM_DMA_HISTOGRAM_SLOTS];
376 atomic_t dma[DRM_DMA_HISTOGRAM_SLOTS];
377 atomic_t schedule[DRM_DMA_HISTOGRAM_SLOTS];
378 atomic_t ctx[DRM_DMA_HISTOGRAM_SLOTS];
379 atomic_t lacq[DRM_DMA_HISTOGRAM_SLOTS];
380 atomic_t lhld[DRM_DMA_HISTOGRAM_SLOTS];
381 } drm_histogram_t;
382 #endif
384 /* bufs is one longer than it has to be */
385 typedef struct drm_waitlist {
386 int count; /* Number of possible buffers */
387 drm_buf_t **bufs; /* List of pointers to buffers */
388 drm_buf_t **rp; /* Read pointer */
389 drm_buf_t **wp; /* Write pointer */
390 drm_buf_t **end; /* End pointer */
391 spinlock_t read_lock;
392 spinlock_t write_lock;
393 } drm_waitlist_t;
395 typedef struct drm_freelist {
396 int initialized; /* Freelist in use */
397 atomic_t count; /* Number of free buffers */
398 drm_buf_t *next; /* End pointer */
400 wait_queue_head_t waiting; /* Processes waiting on free bufs */
401 int low_mark; /* Low water mark */
402 int high_mark; /* High water mark */
403 atomic_t wfh; /* If waiting for high mark */
404 spinlock_t lock;
405 } drm_freelist_t;
407 typedef struct drm_buf_entry {
408 int buf_size;
409 int buf_count;
410 drm_buf_t *buflist;
411 int seg_count;
412 int page_order;
413 unsigned long *seglist;
415 drm_freelist_t freelist;
416 } drm_buf_entry_t;
418 typedef struct drm_hw_lock {
419 __volatile__ unsigned int lock;
420 char padding[60]; /* Pad to cache line */
421 } drm_hw_lock_t;
423 typedef struct drm_file {
424 int authenticated;
425 int minor;
426 pid_t pid;
427 uid_t uid;
428 drm_magic_t magic;
429 unsigned long ioctl_count;
430 struct drm_file *next;
431 struct drm_file *prev;
432 struct drm_device *dev;
433 } drm_file_t;
436 typedef struct drm_queue {
437 atomic_t use_count; /* Outstanding uses (+1) */
438 atomic_t finalization; /* Finalization in progress */
439 atomic_t block_count; /* Count of processes waiting */
440 atomic_t block_read; /* Queue blocked for reads */
441 wait_queue_head_t read_queue; /* Processes waiting on block_read */
442 atomic_t block_write; /* Queue blocked for writes */
443 wait_queue_head_t write_queue; /* Processes waiting on block_write */
444 atomic_t total_queued; /* Total queued statistic */
445 atomic_t total_flushed;/* Total flushes statistic */
446 atomic_t total_locks; /* Total locks statistics */
447 drm_ctx_flags_t flags; /* Context preserving and 2D-only */
448 drm_waitlist_t waitlist; /* Pending buffers */
449 wait_queue_head_t flush_queue; /* Processes waiting until flush */
450 } drm_queue_t;
452 typedef struct drm_lock_data {
453 drm_hw_lock_t *hw_lock; /* Hardware lock */
454 pid_t pid; /* PID of lock holder (0=kernel) */
455 wait_queue_head_t lock_queue; /* Queue of blocked processes */
456 unsigned long lock_time; /* Time of last lock in jiffies */
457 } drm_lock_data_t;
459 typedef struct drm_device_dma {
460 /* Performance Counters */
461 atomic_t total_prio; /* Total DRM_DMA_PRIORITY */
462 atomic_t total_bytes; /* Total bytes DMA'd */
463 atomic_t total_dmas; /* Total DMA buffers dispatched */
465 atomic_t total_missed_dma; /* Missed drm_do_dma */
466 atomic_t total_missed_lock; /* Missed lock in drm_do_dma */
467 atomic_t total_missed_free; /* Missed drm_free_this_buffer */
468 atomic_t total_missed_sched;/* Missed drm_dma_schedule */
470 atomic_t total_tried; /* Tried next_buffer */
471 atomic_t total_hit; /* Sent next_buffer */
472 atomic_t total_lost; /* Lost interrupt */
474 drm_buf_entry_t bufs[DRM_MAX_ORDER+1];
475 int buf_count;
476 drm_buf_t **buflist; /* Vector of pointers info bufs */
477 int seg_count;
478 int page_count;
479 unsigned long *pagelist;
480 unsigned long byte_count;
481 enum {
482 _DRM_DMA_USE_AGP = 0x01
483 } flags;
485 /* DMA support */
486 drm_buf_t *this_buffer; /* Buffer being sent */
487 drm_buf_t *next_buffer; /* Selected buffer to send */
488 drm_queue_t *next_queue; /* Queue from which buffer selected*/
489 wait_queue_head_t waiting; /* Processes waiting on free bufs */
490 } drm_device_dma_t;
492 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
493 typedef struct drm_agp_mem {
494 unsigned long handle;
495 agp_memory *memory;
496 unsigned long bound; /* address */
497 int pages;
498 struct drm_agp_mem *prev;
499 struct drm_agp_mem *next;
500 } drm_agp_mem_t;
502 typedef struct drm_agp_head {
503 agp_kern_info agp_info;
504 const char *chipset;
505 drm_agp_mem_t *memory;
506 unsigned long mode;
507 int enabled;
508 int acquired;
509 unsigned long base;
510 int agp_mtrr;
511 } drm_agp_head_t;
513 typedef struct {
514 void (*free_memory)(agp_memory *);
515 agp_memory *(*allocate_memory)(size_t, u32);
516 int (*bind_memory)(agp_memory *, off_t);
517 int (*unbind_memory)(agp_memory *);
518 void (*enable)(u32);
519 int (*acquire)(void);
520 void (*release)(void);
521 void (*copy_info)(agp_kern_info *);
522 } drm_agp_func_t;
524 extern drm_agp_func_t drm_agp;
525 #endif
527 typedef struct drm_sigdata {
528 int context;
529 drm_hw_lock_t *lock;
530 } drm_sigdata_t;
532 typedef struct drm_device {
533 const char *name; /* Simple driver name */
534 char *unique; /* Unique identifier: e.g., busid */
535 int unique_len; /* Length of unique field */
536 dev_t device; /* Device number for mknod */
537 char *devname; /* For /proc/interrupts */
539 int blocked; /* Blocked due to VC switch? */
540 struct proc_dir_entry *root; /* Root for this device's entries */
542 /* Locks */
543 spinlock_t count_lock; /* For inuse, open_count, buf_use */
544 struct semaphore struct_sem; /* For others */
546 /* Usage Counters */
547 int open_count; /* Outstanding files open */
548 atomic_t ioctl_count; /* Outstanding IOCTLs pending */
549 atomic_t vma_count; /* Outstanding vma areas open */
550 int buf_use; /* Buffers in use -- cannot alloc */
551 atomic_t buf_alloc; /* Buffer allocation in progress */
553 /* Performance Counters */
554 atomic_t total_open;
555 atomic_t total_close;
556 atomic_t total_ioctl;
557 atomic_t total_irq; /* Total interruptions */
558 atomic_t total_ctx; /* Total context switches */
560 atomic_t total_locks;
561 atomic_t total_unlocks;
562 atomic_t total_contends;
563 atomic_t total_sleeps;
565 /* Authentication */
566 drm_file_t *file_first;
567 drm_file_t *file_last;
568 drm_magic_head_t magiclist[DRM_HASH_SIZE];
570 /* Memory management */
571 drm_map_t **maplist; /* Vector of pointers to regions */
572 int map_count; /* Number of mappable regions */
574 drm_vma_entry_t *vmalist; /* List of vmas (for debugging) */
575 drm_lock_data_t lock; /* Information on hardware lock */
577 /* DMA queues (contexts) */
578 int queue_count; /* Number of active DMA queues */
579 int queue_reserved; /* Number of reserved DMA queues */
580 int queue_slots; /* Actual length of queuelist */
581 drm_queue_t **queuelist; /* Vector of pointers to DMA queues */
582 drm_device_dma_t *dma; /* Optional pointer for DMA support */
584 /* Context support */
585 int irq; /* Interrupt used by board */
586 __volatile__ long context_flag; /* Context swapping flag */
587 __volatile__ long interrupt_flag; /* Interruption handler flag */
588 __volatile__ long dma_flag; /* DMA dispatch flag */
589 struct timer_list timer; /* Timer for delaying ctx switch */
590 wait_queue_head_t context_wait; /* Processes waiting on ctx switch */
591 int last_checked; /* Last context checked for DMA */
592 int last_context; /* Last current context */
593 unsigned long last_switch; /* jiffies at last context switch */
594 struct tq_struct tq;
595 cycles_t ctx_start;
596 cycles_t lck_start;
597 #if DRM_DMA_HISTOGRAM
598 drm_histogram_t histo;
599 #endif
601 /* Callback to X server for context switch
602 and for heavy-handed reset. */
603 char buf[DRM_BSZ]; /* Output buffer */
604 char *buf_rp; /* Read pointer */
605 char *buf_wp; /* Write pointer */
606 char *buf_end; /* End pointer */
607 struct fasync_struct *buf_async;/* Processes waiting for SIGIO */
608 wait_queue_head_t buf_readers; /* Processes waiting to read */
609 wait_queue_head_t buf_writers; /* Processes waiting to ctx switch */
611 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
612 drm_agp_head_t *agp;
613 #endif
614 unsigned long *ctx_bitmap;
615 void *dev_private;
616 drm_sigdata_t sigdata; /* For block_all_signals */
617 sigset_t sigmask;
618 } drm_device_t;
621 /* Internal function definitions */
623 /* Misc. support (init.c) */
624 extern int drm_flags;
625 extern void drm_parse_options(char *s);
626 extern int drm_cpu_valid(void);
629 /* Device support (fops.c) */
630 extern int drm_open_helper(struct inode *inode, struct file *filp,
631 drm_device_t *dev);
632 extern int drm_flush(struct file *filp);
633 extern int drm_release(struct inode *inode, struct file *filp);
634 extern int drm_fasync(int fd, struct file *filp, int on);
635 extern ssize_t drm_read(struct file *filp, char *buf, size_t count,
636 loff_t *off);
637 extern int drm_write_string(drm_device_t *dev, const char *s);
638 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
640 /* Mapping support (vm.c) */
641 #if LINUX_VERSION_CODE < 0x020317
642 extern unsigned long drm_vm_nopage(struct vm_area_struct *vma,
643 unsigned long address,
644 int write_access);
645 extern unsigned long drm_vm_shm_nopage(struct vm_area_struct *vma,
646 unsigned long address,
647 int write_access);
648 extern unsigned long drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
649 unsigned long address,
650 int write_access);
651 extern unsigned long drm_vm_dma_nopage(struct vm_area_struct *vma,
652 unsigned long address,
653 int write_access);
654 #else
655 /* Return type changed in 2.3.23 */
656 extern struct page *drm_vm_nopage(struct vm_area_struct *vma,
657 unsigned long address,
658 int write_access);
659 extern struct page *drm_vm_shm_nopage(struct vm_area_struct *vma,
660 unsigned long address,
661 int write_access);
662 extern struct page *drm_vm_shm_nopage_lock(struct vm_area_struct *vma,
663 unsigned long address,
664 int write_access);
665 extern struct page *drm_vm_dma_nopage(struct vm_area_struct *vma,
666 unsigned long address,
667 int write_access);
668 #endif
669 extern void drm_vm_open(struct vm_area_struct *vma);
670 extern void drm_vm_close(struct vm_area_struct *vma);
671 extern int drm_mmap_dma(struct file *filp,
672 struct vm_area_struct *vma);
673 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
676 /* Proc support (proc.c) */
677 extern int drm_proc_init(drm_device_t *dev);
678 extern int drm_proc_cleanup(void);
680 /* Memory management support (memory.c) */
681 extern void drm_mem_init(void);
682 extern int drm_mem_info(char *buf, char **start, off_t offset,
683 int len, int *eof, void *data);
684 extern void *drm_alloc(size_t size, int area);
685 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size,
686 int area);
687 extern char *drm_strdup(const char *s, int area);
688 extern void drm_strfree(const char *s, int area);
689 extern void drm_free(void *pt, size_t size, int area);
690 extern unsigned long drm_alloc_pages(int order, int area);
691 extern void drm_free_pages(unsigned long address, int order,
692 int area);
693 extern void *drm_ioremap(unsigned long offset, unsigned long size);
694 extern void drm_ioremapfree(void *pt, unsigned long size);
696 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
697 extern agp_memory *drm_alloc_agp(int pages, u32 type);
698 extern int drm_free_agp(agp_memory *handle, int pages);
699 extern int drm_bind_agp(agp_memory *handle, unsigned int start);
700 extern int drm_unbind_agp(agp_memory *handle);
701 #endif
704 /* Buffer management support (bufs.c) */
705 extern int drm_order(unsigned long size);
706 extern int drm_addmap(struct inode *inode, struct file *filp,
707 unsigned int cmd, unsigned long arg);
708 extern int drm_addbufs(struct inode *inode, struct file *filp,
709 unsigned int cmd, unsigned long arg);
710 extern int drm_infobufs(struct inode *inode, struct file *filp,
711 unsigned int cmd, unsigned long arg);
712 extern int drm_markbufs(struct inode *inode, struct file *filp,
713 unsigned int cmd, unsigned long arg);
714 extern int drm_freebufs(struct inode *inode, struct file *filp,
715 unsigned int cmd, unsigned long arg);
716 extern int drm_mapbufs(struct inode *inode, struct file *filp,
717 unsigned int cmd, unsigned long arg);
720 /* Buffer list management support (lists.c) */
721 extern int drm_waitlist_create(drm_waitlist_t *bl, int count);
722 extern int drm_waitlist_destroy(drm_waitlist_t *bl);
723 extern int drm_waitlist_put(drm_waitlist_t *bl, drm_buf_t *buf);
724 extern drm_buf_t *drm_waitlist_get(drm_waitlist_t *bl);
726 extern int drm_freelist_create(drm_freelist_t *bl, int count);
727 extern int drm_freelist_destroy(drm_freelist_t *bl);
728 extern int drm_freelist_put(drm_device_t *dev, drm_freelist_t *bl,
729 drm_buf_t *buf);
730 extern drm_buf_t *drm_freelist_get(drm_freelist_t *bl, int block);
732 /* DMA support (gen_dma.c) */
733 extern void drm_dma_setup(drm_device_t *dev);
734 extern void drm_dma_takedown(drm_device_t *dev);
735 extern void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf);
736 extern void drm_reclaim_buffers(drm_device_t *dev, pid_t pid);
737 extern int drm_context_switch(drm_device_t *dev, int old, int new);
738 extern int drm_context_switch_complete(drm_device_t *dev, int new);
739 extern void drm_clear_next_buffer(drm_device_t *dev);
740 extern int drm_select_queue(drm_device_t *dev,
741 void (*wrapper)(unsigned long));
742 extern int drm_dma_enqueue(drm_device_t *dev, drm_dma_t *dma);
743 extern int drm_dma_get_buffers(drm_device_t *dev, drm_dma_t *dma);
744 #if DRM_DMA_HISTOGRAM
745 extern int drm_histogram_slot(unsigned long count);
746 extern void drm_histogram_compute(drm_device_t *dev, drm_buf_t *buf);
747 #endif
750 /* Misc. IOCTL support (ioctl.c) */
751 extern int drm_irq_busid(struct inode *inode, struct file *filp,
752 unsigned int cmd, unsigned long arg);
753 extern int drm_getunique(struct inode *inode, struct file *filp,
754 unsigned int cmd, unsigned long arg);
755 extern int drm_setunique(struct inode *inode, struct file *filp,
756 unsigned int cmd, unsigned long arg);
759 /* Context IOCTL support (context.c) */
760 extern int drm_resctx(struct inode *inode, struct file *filp,
761 unsigned int cmd, unsigned long arg);
762 extern int drm_addctx(struct inode *inode, struct file *filp,
763 unsigned int cmd, unsigned long arg);
764 extern int drm_modctx(struct inode *inode, struct file *filp,
765 unsigned int cmd, unsigned long arg);
766 extern int drm_getctx(struct inode *inode, struct file *filp,
767 unsigned int cmd, unsigned long arg);
768 extern int drm_switchctx(struct inode *inode, struct file *filp,
769 unsigned int cmd, unsigned long arg);
770 extern int drm_newctx(struct inode *inode, struct file *filp,
771 unsigned int cmd, unsigned long arg);
772 extern int drm_rmctx(struct inode *inode, struct file *filp,
773 unsigned int cmd, unsigned long arg);
776 /* Drawable IOCTL support (drawable.c) */
777 extern int drm_adddraw(struct inode *inode, struct file *filp,
778 unsigned int cmd, unsigned long arg);
779 extern int drm_rmdraw(struct inode *inode, struct file *filp,
780 unsigned int cmd, unsigned long arg);
783 /* Authentication IOCTL support (auth.c) */
784 extern int drm_add_magic(drm_device_t *dev, drm_file_t *priv,
785 drm_magic_t magic);
786 extern int drm_remove_magic(drm_device_t *dev, drm_magic_t magic);
787 extern int drm_getmagic(struct inode *inode, struct file *filp,
788 unsigned int cmd, unsigned long arg);
789 extern int drm_authmagic(struct inode *inode, struct file *filp,
790 unsigned int cmd, unsigned long arg);
793 /* Locking IOCTL support (lock.c) */
794 extern int drm_block(struct inode *inode, struct file *filp,
795 unsigned int cmd, unsigned long arg);
796 extern int drm_unblock(struct inode *inode, struct file *filp,
797 unsigned int cmd, unsigned long arg);
798 extern int drm_lock_take(__volatile__ unsigned int *lock,
799 unsigned int context);
800 extern int drm_lock_transfer(drm_device_t *dev,
801 __volatile__ unsigned int *lock,
802 unsigned int context);
803 extern int drm_lock_free(drm_device_t *dev,
804 __volatile__ unsigned int *lock,
805 unsigned int context);
806 extern int drm_finish(struct inode *inode, struct file *filp,
807 unsigned int cmd, unsigned long arg);
808 extern int drm_flush_unblock(drm_device_t *dev, int context,
809 drm_lock_flags_t flags);
810 extern int drm_flush_block_and_flush(drm_device_t *dev, int context,
811 drm_lock_flags_t flags);
812 extern int drm_notifier(void *priv);
814 /* Context Bitmap support (ctxbitmap.c) */
815 extern int drm_ctxbitmap_init(drm_device_t *dev);
816 extern void drm_ctxbitmap_cleanup(drm_device_t *dev);
817 extern int drm_ctxbitmap_next(drm_device_t *dev);
818 extern void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle);
820 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
821 /* AGP/GART support (agpsupport.c) */
822 extern drm_agp_head_t *drm_agp_init(void);
823 extern void drm_agp_uninit(void);
824 extern int drm_agp_acquire(struct inode *inode, struct file *filp,
825 unsigned int cmd, unsigned long arg);
826 extern int drm_agp_release(struct inode *inode, struct file *filp,
827 unsigned int cmd, unsigned long arg);
828 extern int drm_agp_enable(struct inode *inode, struct file *filp,
829 unsigned int cmd, unsigned long arg);
830 extern int drm_agp_info(struct inode *inode, struct file *filp,
831 unsigned int cmd, unsigned long arg);
832 extern int drm_agp_alloc(struct inode *inode, struct file *filp,
833 unsigned int cmd, unsigned long arg);
834 extern int drm_agp_free(struct inode *inode, struct file *filp,
835 unsigned int cmd, unsigned long arg);
836 extern int drm_agp_unbind(struct inode *inode, struct file *filp,
837 unsigned int cmd, unsigned long arg);
838 extern int drm_agp_bind(struct inode *inode, struct file *filp,
839 unsigned int cmd, unsigned long arg);
840 #endif
841 #endif
842 #endif