restricted ia64 patches to ia64 again, they still break builds on
[linux-flexiantxendom0-3.2.10.git] / drivers / char / drm / drmP.h
1 /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2  * Created: Mon Jan  4 10:05:05 1999 by faith@precisioninsight.com
3  *
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * All rights reserved.
7  *
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:
14  *
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.
18  *
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  * VA LINUX SYSTEMS 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
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Authors:
28  *    Rickard E. (Rik) Faith <faith@valinux.com>
29  *    Gareth Hughes <gareth@valinux.com>
30  */
31
32 #ifndef _DRM_P_H_
33 #define _DRM_P_H_
34
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/version.h>
52 #include <linux/jiffies.h>
53 #include <linux/smp_lock.h>     /* For (un)lock_kernel */
54 #include <linux/mm.h>
55 #if defined(__alpha__) || defined(__powerpc__)
56 #include <asm/pgtable.h> /* For pte_wrprotect */
57 #endif
58 #include <asm/io.h>
59 #include <asm/mman.h>
60 #include <asm/uaccess.h>
61 #ifdef CONFIG_MTRR
62 #include <asm/mtrr.h>
63 #endif
64 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
65 #include <linux/types.h>
66 #include <linux/agp_backend.h>
67 #endif
68 #include <linux/workqueue.h>
69 #include <linux/poll.h>
70 #include <asm/pgalloc.h>
71 #include "drm.h"
72
73 #include "drm_os_linux.h"
74
75 /* DRM template customization defaults
76  */
77 #ifndef __HAVE_AGP
78 #define __HAVE_AGP              0
79 #endif
80 #ifndef __HAVE_MTRR
81 #define __HAVE_MTRR             0
82 #endif
83 #ifndef __HAVE_CTX_BITMAP
84 #define __HAVE_CTX_BITMAP       0
85 #endif
86 #ifndef __HAVE_DMA
87 #define __HAVE_DMA              0
88 #endif
89 #ifndef __HAVE_DMA_IRQ
90 #define __HAVE_DMA_IRQ          0
91 #endif
92 #ifndef __HAVE_DMA_WAITLIST
93 #define __HAVE_DMA_WAITLIST     0
94 #endif
95 #ifndef __HAVE_DMA_FREELIST
96 #define __HAVE_DMA_FREELIST     0
97 #endif
98
99 #define __REALLY_HAVE_AGP       (__HAVE_AGP && (defined(CONFIG_AGP) || \
100                                                 defined(CONFIG_AGP_MODULE)))
101 #define __REALLY_HAVE_MTRR      (__HAVE_MTRR && defined(CONFIG_MTRR))
102 #define __REALLY_HAVE_SG        (__HAVE_SG)
103
104 /* Begin the DRM...
105  */
106
107 #define DRM_DEBUG_CODE 2          /* Include debugging code (if > 1, then
108                                      also include looping detection. */
109
110 #define DRM_HASH_SIZE         16 /* Size of key hash table                */
111 #define DRM_KERNEL_CONTEXT    0  /* Change drm_resctx if changed          */
112 #define DRM_RESERVED_CONTEXTS 1  /* Change drm_resctx if changed          */
113 #define DRM_LOOPING_LIMIT     5000000
114 #define DRM_BSZ               1024 /* Buffer size for /dev/drm? output    */
115 #define DRM_TIME_SLICE        (HZ/20)  /* Time slice for GLXContexts      */
116 #define DRM_LOCK_SLICE        1 /* Time slice for lock, in jiffies        */
117
118 #define DRM_FLAG_DEBUG    0x01
119
120 #define DRM_MEM_DMA        0
121 #define DRM_MEM_SAREA      1
122 #define DRM_MEM_DRIVER     2
123 #define DRM_MEM_MAGIC      3
124 #define DRM_MEM_IOCTLS     4
125 #define DRM_MEM_MAPS       5
126 #define DRM_MEM_VMAS       6
127 #define DRM_MEM_BUFS       7
128 #define DRM_MEM_SEGS       8
129 #define DRM_MEM_PAGES      9
130 #define DRM_MEM_FILES     10
131 #define DRM_MEM_QUEUES    11
132 #define DRM_MEM_CMDS      12
133 #define DRM_MEM_MAPPINGS  13
134 #define DRM_MEM_BUFLISTS  14
135 #define DRM_MEM_AGPLISTS  15
136 #define DRM_MEM_TOTALAGP  16
137 #define DRM_MEM_BOUNDAGP  17
138 #define DRM_MEM_CTXBITMAP 18
139 #define DRM_MEM_STUB      19
140 #define DRM_MEM_SGLISTS   20
141
142 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
143
144                                 /* Backward compatibility section */
145 #ifndef minor
146 #define minor(x) MINOR((x))
147 #endif
148
149 #ifndef MODULE_LICENSE
150 #define MODULE_LICENSE(x) 
151 #endif
152
153 #ifndef preempt_disable
154 #define preempt_disable()
155 #define preempt_enable()
156 #endif
157
158 #ifndef pte_offset_map 
159 #define pte_offset_map pte_offset
160 #define pte_unmap(pte)
161 #endif
162
163 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19)
164 static inline struct page * vmalloc_to_page(void * vmalloc_addr)
165 {
166         unsigned long addr = (unsigned long) vmalloc_addr;
167         struct page *page = NULL;
168         pgd_t *pgd = pgd_offset_k(addr);
169         pmd_t *pmd;
170         pte_t *ptep, pte;
171   
172         if (!pgd_none(*pgd)) {
173                 pmd = pmd_offset(pgd, addr);
174                 if (!pmd_none(*pmd)) {
175                         preempt_disable();
176                         ptep = pte_offset_map(pmd, addr);
177                         pte = *ptep;
178                         if (pte_present(pte))
179                                 page = pte_page(pte);
180                         pte_unmap(ptep);
181                         preempt_enable();
182                 }
183         }
184         return page;
185 }
186 #endif
187
188 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
189 #define DRM_RPR_ARG(vma)
190 #else
191 #define DRM_RPR_ARG(vma) vma,
192 #endif
193
194
195 #define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
196
197                                 /* Macros to make printk easier */
198 #define DRM_ERROR(fmt, arg...) \
199         printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
200 #define DRM_MEM_ERROR(area, fmt, arg...) \
201         printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
202                DRM(mem_stats)[area].name , ##arg)
203 #define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
204
205 #if DRM_DEBUG_CODE
206 #define DRM_DEBUG(fmt, arg...)                                          \
207         do {                                                            \
208                 if ( DRM(flags) & DRM_FLAG_DEBUG )                      \
209                         printk(KERN_DEBUG                               \
210                                "[" DRM_NAME ":%s] " fmt ,       \
211                                __FUNCTION__ , ##arg);                   \
212         } while (0)
213 #else
214 #define DRM_DEBUG(fmt, arg...)           do { } while (0)
215 #endif
216
217 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
218
219 #define DRM_PROC_PRINT(fmt, arg...)                                     \
220    len += sprintf(&buf[len], fmt , ##arg);                              \
221    if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
222
223 #define DRM_PROC_PRINT_RET(ret, fmt, arg...)                            \
224    len += sprintf(&buf[len], fmt , ##arg);                              \
225    if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
226
227                                 /* Mapping helper macros */
228 #define DRM_IOREMAP(map)                                                \
229         (map)->handle = DRM(ioremap)( (map)->offset, (map)->size )
230
231 #define DRM_IOREMAP_NOCACHE(map)                                        \
232         (map)->handle = DRM(ioremap_nocache)((map)->offset, (map)->size)
233
234 #define DRM_IOREMAPFREE(map)                                            \
235         do {                                                            \
236                 if ( (map)->handle && (map)->size )                     \
237                         DRM(ioremapfree)( (map)->handle, (map)->size ); \
238         } while (0)
239
240 #define DRM_FIND_MAP(_map, _o)                                                          \
241 do {                                                                                    \
242         struct list_head *_list;                                                        \
243         list_for_each( _list, &dev->maplist->head ) {                                   \
244                 drm_map_list_t *_entry = list_entry( _list, drm_map_list_t, head );     \
245                 if ( _entry->map &&                                                     \
246                      _entry->map->offset == (_o) ) {                                    \
247                         (_map) = _entry->map;                                           \
248                         break;                                                          \
249                 }                                                                       \
250         }                                                                               \
251 } while(0)
252 #define DRM_DROP_MAP(_map)
253
254                                 /* Internal types and structures */
255 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
256 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
257 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
258
259 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
260 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
261 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
262
263 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {       \
264         (_map) = (_dev)->context_sareas[_ctx];          \
265 } while(0)
266
267 #define LOCK_TEST_WITH_RETURN( dev, filp )                              \
268 do {                                                                    \
269         if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) ||           \
270              dev->lock.filp != filp ) {                         \
271                 DRM_ERROR( "%s called without lock held\n",             \
272                            __FUNCTION__ );                              \
273                 return -EINVAL;                                         \
274         }                                                               \
275 } while (0)
276
277
278 typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
279                          unsigned int cmd, unsigned long arg );
280
281 typedef struct drm_pci_list {
282         u16 vendor;
283         u16 device;
284 } drm_pci_list_t;
285
286 typedef struct drm_ioctl_desc {
287         drm_ioctl_t          *func;
288         int                  auth_needed;
289         int                  root_only;
290 } drm_ioctl_desc_t;
291
292 typedef struct drm_devstate {
293         pid_t             owner;        /* X server pid holding x_lock */
294
295 } drm_devstate_t;
296
297 typedef struct drm_magic_entry {
298         drm_magic_t            magic;
299         struct drm_file        *priv;
300         struct drm_magic_entry *next;
301 } drm_magic_entry_t;
302
303 typedef struct drm_magic_head {
304         struct drm_magic_entry *head;
305         struct drm_magic_entry *tail;
306 } drm_magic_head_t;
307
308 typedef struct drm_vma_entry {
309         struct vm_area_struct *vma;
310         struct drm_vma_entry  *next;
311         pid_t                 pid;
312 } drm_vma_entry_t;
313
314 typedef struct drm_buf {
315         int               idx;         /* Index into master buflist          */
316         int               total;       /* Buffer size                        */
317         int               order;       /* log-base-2(total)                  */
318         int               used;        /* Amount of buffer in use (for DMA)  */
319         unsigned long     offset;      /* Byte offset (used internally)      */
320         void              *address;    /* Address of buffer                  */
321         unsigned long     bus_address; /* Bus address of buffer              */
322         struct drm_buf    *next;       /* Kernel-only: used for free list    */
323         __volatile__ int  waiting;     /* On kernel DMA queue                */
324         __volatile__ int  pending;     /* On hardware DMA queue              */
325         wait_queue_head_t dma_wait;    /* Processes waiting                  */
326         struct file       *filp;       /* Pointer to holding file descr      */
327         int               context;     /* Kernel queue for this buffer       */
328         int               while_locked;/* Dispatch this buffer while locked  */
329         enum {
330                 DRM_LIST_NONE    = 0,
331                 DRM_LIST_FREE    = 1,
332                 DRM_LIST_WAIT    = 2,
333                 DRM_LIST_PEND    = 3,
334                 DRM_LIST_PRIO    = 4,
335                 DRM_LIST_RECLAIM = 5
336         }                 list;        /* Which list we're on                */
337
338
339         int               dev_priv_size; /* Size of buffer private stoarge   */
340         void              *dev_private;  /* Per-buffer private storage       */
341 } drm_buf_t;
342
343
344                                 /* bufs is one longer than it has to be */
345 typedef struct drm_waitlist {
346         int               count;        /* Number of possible buffers      */
347         drm_buf_t         **bufs;       /* List of pointers to buffers     */
348         drm_buf_t         **rp;         /* Read pointer                    */
349         drm_buf_t         **wp;         /* Write pointer                   */
350         drm_buf_t         **end;        /* End pointer                     */
351         spinlock_t        read_lock;
352         spinlock_t        write_lock;
353 } drm_waitlist_t;
354
355 typedef struct drm_freelist {
356         int               initialized; /* Freelist in use                  */
357         atomic_t          count;       /* Number of free buffers           */
358         drm_buf_t         *next;       /* End pointer                      */
359
360         wait_queue_head_t waiting;     /* Processes waiting on free bufs   */
361         int               low_mark;    /* Low water mark                   */
362         int               high_mark;   /* High water mark                  */
363         atomic_t          wfh;         /* If waiting for high mark         */
364         spinlock_t        lock;
365 } drm_freelist_t;
366
367 typedef struct drm_buf_entry {
368         int               buf_size;
369         int               buf_count;
370         drm_buf_t         *buflist;
371         int               seg_count;
372         int               page_order;
373         unsigned long     *seglist;
374
375         drm_freelist_t    freelist;
376 } drm_buf_entry_t;
377
378 typedef struct drm_hw_lock {
379         __volatile__ unsigned int lock;
380         char                      padding[60]; /* Pad to cache line */
381 } drm_hw_lock_t;
382
383 typedef struct drm_file {
384         int               authenticated;
385         int               minor;
386         pid_t             pid;
387         uid_t             uid;
388         drm_magic_t       magic;
389         unsigned long     ioctl_count;
390         struct drm_file   *next;
391         struct drm_file   *prev;
392         struct drm_device *dev;
393         int               remove_auth_on_close;
394         unsigned long     lock_count;
395 } drm_file_t;
396
397
398 typedef struct drm_queue {
399         atomic_t          use_count;    /* Outstanding uses (+1)            */
400         atomic_t          finalization; /* Finalization in progress         */
401         atomic_t          block_count;  /* Count of processes waiting       */
402         atomic_t          block_read;   /* Queue blocked for reads          */
403         wait_queue_head_t read_queue;   /* Processes waiting on block_read  */
404         atomic_t          block_write;  /* Queue blocked for writes         */
405         wait_queue_head_t write_queue;  /* Processes waiting on block_write */
406 #if 1
407         atomic_t          total_queued; /* Total queued statistic           */
408         atomic_t          total_flushed;/* Total flushes statistic          */
409         atomic_t          total_locks;  /* Total locks statistics           */
410 #endif
411         drm_ctx_flags_t   flags;        /* Context preserving and 2D-only   */
412         drm_waitlist_t    waitlist;     /* Pending buffers                  */
413         wait_queue_head_t flush_queue;  /* Processes waiting until flush    */
414 } drm_queue_t;
415
416 typedef struct drm_lock_data {
417         drm_hw_lock_t     *hw_lock;     /* Hardware lock                   */
418         struct file       *filp;        /* File descr of lock holder (0=kernel)   */
419         wait_queue_head_t lock_queue;   /* Queue of blocked processes      */
420         unsigned long     lock_time;    /* Time of last lock in jiffies    */
421 } drm_lock_data_t;
422
423 typedef struct drm_device_dma {
424
425         drm_buf_entry_t   bufs[DRM_MAX_ORDER+1];
426         int               buf_count;
427         drm_buf_t         **buflist;    /* Vector of pointers info bufs    */
428         int               seg_count;
429         int               page_count;
430         unsigned long     *pagelist;
431         unsigned long     byte_count;
432         enum {
433                 _DRM_DMA_USE_AGP = 0x01,
434                 _DRM_DMA_USE_SG  = 0x02
435         } flags;
436
437                                 /* DMA support */
438         drm_buf_t         *this_buffer; /* Buffer being sent               */
439         drm_buf_t         *next_buffer; /* Selected buffer to send         */
440         drm_queue_t       *next_queue;  /* Queue from which buffer selected*/
441         wait_queue_head_t waiting;      /* Processes waiting on free bufs  */
442 } drm_device_dma_t;
443
444 #if __REALLY_HAVE_AGP
445 typedef struct drm_agp_mem {
446         unsigned long      handle;
447         agp_memory         *memory;
448         unsigned long      bound; /* address */
449         int                pages;
450         struct drm_agp_mem *prev;
451         struct drm_agp_mem *next;
452 } drm_agp_mem_t;
453
454 typedef struct drm_agp_head {
455         agp_kern_info      agp_info;
456         drm_agp_mem_t      *memory;
457         unsigned long      mode;
458         int                enabled;
459         int                acquired;
460         unsigned long      base;
461         int                agp_mtrr;
462         int                cant_use_aperture;
463         unsigned long      page_mask;
464 } drm_agp_head_t;
465 #endif
466
467 typedef struct drm_sg_mem {
468         unsigned long   handle;
469         void            *virtual;
470         int             pages;
471         struct page     **pagelist;
472         dma_addr_t      *busaddr;
473 } drm_sg_mem_t;
474
475 typedef struct drm_sigdata {
476         int           context;
477         drm_hw_lock_t *lock;
478 } drm_sigdata_t;
479
480 typedef struct drm_map_list {
481         struct list_head        head;
482         drm_map_t               *map;
483 } drm_map_list_t;
484
485 typedef drm_map_t drm_local_map_t;
486
487 #if __HAVE_VBL_IRQ
488
489 typedef struct drm_vbl_sig {
490         struct list_head        head;
491         unsigned int            sequence;
492         struct siginfo          info;
493         struct task_struct      *task;
494 } drm_vbl_sig_t;
495
496 #endif
497
498 typedef struct drm_device {
499         const char        *name;        /* Simple driver name              */
500         char              *unique;      /* Unique identifier: e.g., busid  */
501         int               unique_len;   /* Length of unique field          */
502         dev_t             device;       /* Device number for mknod         */
503         char              *devname;     /* For /proc/interrupts            */
504
505         int               blocked;      /* Blocked due to VC switch?       */
506         struct proc_dir_entry *root;    /* Root for this device's entries  */
507
508                                 /* Locks */
509         spinlock_t        count_lock;   /* For inuse, open_count, buf_use  */
510         struct semaphore  struct_sem;   /* For others                      */
511
512                                 /* Usage Counters */
513         int               open_count;   /* Outstanding files open          */
514         atomic_t          ioctl_count;  /* Outstanding IOCTLs pending      */
515         atomic_t          vma_count;    /* Outstanding vma areas open      */
516         int               buf_use;      /* Buffers in use -- cannot alloc  */
517         atomic_t          buf_alloc;    /* Buffer allocation in progress   */
518
519                                 /* Performance counters */
520         unsigned long     counters;
521         drm_stat_type_t   types[15];
522         atomic_t          counts[15];
523
524                                 /* Authentication */
525         drm_file_t        *file_first;
526         drm_file_t        *file_last;
527         drm_magic_head_t  magiclist[DRM_HASH_SIZE];
528
529                                 /* Memory management */
530         drm_map_list_t    *maplist;     /* Linked list of regions          */
531
532         drm_map_t         **context_sareas;
533         int               max_context;
534
535         drm_vma_entry_t   *vmalist;     /* List of vmas (for debugging)    */
536         drm_lock_data_t   lock;         /* Information on hardware lock    */
537
538                                 /* DMA queues (contexts) */
539         int               queue_count;  /* Number of active DMA queues     */
540         int               queue_reserved; /* Number of reserved DMA queues */
541         int               queue_slots;  /* Actual length of queuelist      */
542         drm_queue_t       **queuelist;  /* Vector of pointers to DMA queues */
543         drm_device_dma_t  *dma;         /* Optional pointer for DMA support */
544
545                                 /* Context support */
546         int               irq;          /* Interrupt used by board         */
547         __volatile__ long context_flag; /* Context swapping flag           */
548         __volatile__ long interrupt_flag; /* Interruption handler flag     */
549         __volatile__ long dma_flag;     /* DMA dispatch flag               */
550         struct timer_list timer;        /* Timer for delaying ctx switch   */
551         wait_queue_head_t context_wait; /* Processes waiting on ctx switch */
552         int               last_checked; /* Last context checked for DMA    */
553         int               last_context; /* Last current context            */
554         unsigned long     last_switch;  /* jiffies at last context switch  */
555         struct work_struct                work;
556 #if __HAVE_VBL_IRQ
557         wait_queue_head_t vbl_queue;
558         atomic_t          vbl_received;
559         spinlock_t        vbl_lock;
560         drm_vbl_sig_t     vbl_sigs;
561         unsigned int      vbl_pending;
562 #endif
563         cycles_t          ctx_start;
564         cycles_t          lck_start;
565
566                                 /* Callback to X server for context switch
567                                    and for heavy-handed reset. */
568         char              buf[DRM_BSZ]; /* Output buffer                   */
569         char              *buf_rp;      /* Read pointer                    */
570         char              *buf_wp;      /* Write pointer                   */
571         char              *buf_end;     /* End pointer                     */
572         struct fasync_struct *buf_async;/* Processes waiting for SIGIO     */
573         wait_queue_head_t buf_readers;  /* Processes waiting to read       */
574         wait_queue_head_t buf_writers;  /* Processes waiting to ctx switch */
575
576 #if __REALLY_HAVE_AGP
577         drm_agp_head_t    *agp;
578 #endif
579         struct pci_dev *pdev;
580 #ifdef __alpha__
581 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3)
582         struct pci_controler *hose;
583 #else
584         struct pci_controller *hose;
585 #endif
586 #endif
587         drm_sg_mem_t      *sg;  /* Scatter gather memory */
588         unsigned long     *ctx_bitmap;
589         void              *dev_private;
590         drm_sigdata_t     sigdata; /* For block_all_signals */
591         sigset_t          sigmask;
592 } drm_device_t;
593
594
595 /* ================================================================
596  * Internal function definitions
597  */
598
599                                 /* Misc. support (drm_init.h) */
600 extern int           DRM(flags);
601 extern void          DRM(parse_options)( char *s );
602 extern int           DRM(cpu_valid)( void );
603
604                                 /* Driver support (drm_drv.h) */
605 extern int           DRM(version)(struct inode *inode, struct file *filp,
606                                   unsigned int cmd, unsigned long arg);
607 extern int           DRM(open)(struct inode *inode, struct file *filp);
608 extern int           DRM(release)(struct inode *inode, struct file *filp);
609 extern int           DRM(ioctl)(struct inode *inode, struct file *filp,
610                                 unsigned int cmd, unsigned long arg);
611 extern int           DRM(lock)(struct inode *inode, struct file *filp,
612                                unsigned int cmd, unsigned long arg);
613 extern int           DRM(unlock)(struct inode *inode, struct file *filp,
614                                  unsigned int cmd, unsigned long arg);
615
616                                 /* Device support (drm_fops.h) */
617 extern int           DRM(open_helper)(struct inode *inode, struct file *filp,
618                                       drm_device_t *dev);
619 extern int           DRM(flush)(struct file *filp);
620 extern int           DRM(fasync)(int fd, struct file *filp, int on);
621
622                                 /* Mapping support (drm_vm.h) */
623 extern struct page *DRM(vm_nopage)(struct vm_area_struct *vma,
624                                    unsigned long address,
625                                    int write_access);
626 extern struct page *DRM(vm_shm_nopage)(struct vm_area_struct *vma,
627                                        unsigned long address,
628                                        int write_access);
629 extern struct page *DRM(vm_dma_nopage)(struct vm_area_struct *vma,
630                                        unsigned long address,
631                                        int write_access);
632 extern struct page *DRM(vm_sg_nopage)(struct vm_area_struct *vma,
633                                       unsigned long address,
634                                       int write_access);
635 extern void          DRM(vm_open)(struct vm_area_struct *vma);
636 extern void          DRM(vm_close)(struct vm_area_struct *vma);
637 extern void          DRM(vm_shm_close)(struct vm_area_struct *vma);
638 extern int           DRM(mmap_dma)(struct file *filp,
639                                    struct vm_area_struct *vma);
640 extern int           DRM(mmap)(struct file *filp, struct vm_area_struct *vma);
641 extern unsigned int  DRM(poll)(struct file *filp, struct poll_table_struct *wait);
642 extern ssize_t       DRM(read)(struct file *filp, char *buf, size_t count, loff_t *off);
643
644                                 /* Memory management support (drm_memory.h) */
645 extern void          DRM(mem_init)(void);
646 extern int           DRM(mem_info)(char *buf, char **start, off_t offset,
647                                    int request, int *eof, void *data);
648 extern void          *DRM(alloc)(size_t size, int area);
649 extern void          *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
650                                    int area);
651 extern void          DRM(free)(void *pt, size_t size, int area);
652 extern unsigned long DRM(alloc_pages)(int order, int area);
653 extern void          DRM(free_pages)(unsigned long address, int order,
654                                      int area);
655 extern void          *DRM(ioremap)(unsigned long offset, unsigned long size);
656 extern void          *DRM(ioremap_nocache)(unsigned long offset, unsigned long size);
657 extern void          DRM(ioremapfree)(void *pt, unsigned long size);
658
659 #if __REALLY_HAVE_AGP
660 extern agp_memory    *DRM(alloc_agp)(int pages, u32 type);
661 extern int           DRM(free_agp)(agp_memory *handle, int pages);
662 extern int           DRM(bind_agp)(agp_memory *handle, unsigned int start);
663 extern int           DRM(unbind_agp)(agp_memory *handle);
664 #endif
665
666                                 /* Misc. IOCTL support (drm_ioctl.h) */
667 extern int           DRM(irq_busid)(struct inode *inode, struct file *filp,
668                                     unsigned int cmd, unsigned long arg);
669 extern int           DRM(getunique)(struct inode *inode, struct file *filp,
670                                     unsigned int cmd, unsigned long arg);
671 extern int           DRM(setunique)(struct inode *inode, struct file *filp,
672                                     unsigned int cmd, unsigned long arg);
673 extern int           DRM(getmap)(struct inode *inode, struct file *filp,
674                                  unsigned int cmd, unsigned long arg);
675 extern int           DRM(getclient)(struct inode *inode, struct file *filp,
676                                     unsigned int cmd, unsigned long arg);
677 extern int           DRM(getstats)(struct inode *inode, struct file *filp,
678                                    unsigned int cmd, unsigned long arg);
679
680                                 /* Context IOCTL support (drm_context.h) */
681 extern int           DRM(resctx)( struct inode *inode, struct file *filp,
682                                   unsigned int cmd, unsigned long arg );
683 extern int           DRM(addctx)( struct inode *inode, struct file *filp,
684                                   unsigned int cmd, unsigned long arg );
685 extern int           DRM(modctx)( struct inode *inode, struct file *filp,
686                                   unsigned int cmd, unsigned long arg );
687 extern int           DRM(getctx)( struct inode *inode, struct file *filp,
688                                   unsigned int cmd, unsigned long arg );
689 extern int           DRM(switchctx)( struct inode *inode, struct file *filp,
690                                      unsigned int cmd, unsigned long arg );
691 extern int           DRM(newctx)( struct inode *inode, struct file *filp,
692                                   unsigned int cmd, unsigned long arg );
693 extern int           DRM(rmctx)( struct inode *inode, struct file *filp,
694                                  unsigned int cmd, unsigned long arg );
695
696 extern int           DRM(context_switch)(drm_device_t *dev, int old, int new);
697 extern int           DRM(context_switch_complete)(drm_device_t *dev, int new);
698
699 #if __HAVE_CTX_BITMAP
700 extern int           DRM(ctxbitmap_init)( drm_device_t *dev );
701 extern void          DRM(ctxbitmap_cleanup)( drm_device_t *dev );
702 #endif
703
704 extern int           DRM(setsareactx)( struct inode *inode, struct file *filp,
705                                        unsigned int cmd, unsigned long arg );
706 extern int           DRM(getsareactx)( struct inode *inode, struct file *filp,
707                                        unsigned int cmd, unsigned long arg );
708
709                                 /* Drawable IOCTL support (drm_drawable.h) */
710 extern int           DRM(adddraw)(struct inode *inode, struct file *filp,
711                                   unsigned int cmd, unsigned long arg);
712 extern int           DRM(rmdraw)(struct inode *inode, struct file *filp,
713                                  unsigned int cmd, unsigned long arg);
714
715
716                                 /* Authentication IOCTL support (drm_auth.h) */
717 extern int           DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
718                                     drm_magic_t magic);
719 extern int           DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
720 extern int           DRM(getmagic)(struct inode *inode, struct file *filp,
721                                    unsigned int cmd, unsigned long arg);
722 extern int           DRM(authmagic)(struct inode *inode, struct file *filp,
723                                     unsigned int cmd, unsigned long arg);
724
725                                 /* Placeholder for ioctls past */
726 extern int           DRM(noop)(struct inode *inode, struct file *filp,
727                                   unsigned int cmd, unsigned long arg);
728
729                                 /* Locking IOCTL support (drm_lock.h) */
730 extern int           DRM(lock_take)(__volatile__ unsigned int *lock,
731                                     unsigned int context);
732 extern int           DRM(lock_transfer)(drm_device_t *dev,
733                                         __volatile__ unsigned int *lock,
734                                         unsigned int context);
735 extern int           DRM(lock_free)(drm_device_t *dev,
736                                     __volatile__ unsigned int *lock,
737                                     unsigned int context);
738 extern int           DRM(notifier)(void *priv);
739
740                                 /* Buffer management support (drm_bufs.h) */
741 extern int           DRM(order)( unsigned long size );
742 extern int           DRM(addmap)( struct inode *inode, struct file *filp,
743                                   unsigned int cmd, unsigned long arg );
744 extern int           DRM(rmmap)( struct inode *inode, struct file *filp,
745                                  unsigned int cmd, unsigned long arg );
746 #if __HAVE_DMA
747 extern int           DRM(addbufs)( struct inode *inode, struct file *filp,
748                                    unsigned int cmd, unsigned long arg );
749 extern int           DRM(infobufs)( struct inode *inode, struct file *filp,
750                                     unsigned int cmd, unsigned long arg );
751 extern int           DRM(markbufs)( struct inode *inode, struct file *filp,
752                                     unsigned int cmd, unsigned long arg );
753 extern int           DRM(freebufs)( struct inode *inode, struct file *filp,
754                                     unsigned int cmd, unsigned long arg );
755 extern int           DRM(mapbufs)( struct inode *inode, struct file *filp,
756                                    unsigned int cmd, unsigned long arg );
757
758                                 /* DMA support (drm_dma.h) */
759 extern int           DRM(dma_setup)(drm_device_t *dev);
760 extern void          DRM(dma_takedown)(drm_device_t *dev);
761 extern void          DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
762 extern void          DRM(reclaim_buffers)( struct file *filp );
763 #if __HAVE_DMA_IRQ
764 extern int           DRM(control)( struct inode *inode, struct file *filp,
765                                    unsigned int cmd, unsigned long arg );
766 extern int           DRM(irq_install)( drm_device_t *dev, int irq );
767 extern int           DRM(irq_uninstall)( drm_device_t *dev );
768 extern irqreturn_t   DRM(dma_service)( int irq, void *device,
769                                        struct pt_regs *regs );
770 extern void          DRM(driver_irq_preinstall)( drm_device_t *dev );
771 extern void          DRM(driver_irq_postinstall)( drm_device_t *dev );
772 extern void          DRM(driver_irq_uninstall)( drm_device_t *dev );
773 #if __HAVE_VBL_IRQ
774 extern int           DRM(wait_vblank)(struct inode *inode, struct file *filp,
775                                       unsigned int cmd, unsigned long arg);
776 extern int           DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
777 extern void          DRM(vbl_send_signals)( drm_device_t *dev );
778 #endif
779 #if __HAVE_DMA_IRQ_BH
780 extern void          DRM(dma_immediate_bh)( void *dev );
781 #endif
782 #endif
783
784 #endif /* __HAVE_DMA */
785
786 #if __REALLY_HAVE_AGP
787                                 /* AGP/GART support (drm_agpsupport.h) */
788 extern drm_agp_head_t *DRM(agp_init)(void);
789 extern void           DRM(agp_uninit)(void);
790 extern int            DRM(agp_acquire)(struct inode *inode, struct file *filp,
791                                        unsigned int cmd, unsigned long arg);
792 extern void           DRM(agp_do_release)(void);
793 extern int            DRM(agp_release)(struct inode *inode, struct file *filp,
794                                        unsigned int cmd, unsigned long arg);
795 extern int            DRM(agp_enable)(struct inode *inode, struct file *filp,
796                                       unsigned int cmd, unsigned long arg);
797 extern int            DRM(agp_info)(struct inode *inode, struct file *filp,
798                                     unsigned int cmd, unsigned long arg);
799 extern int            DRM(agp_alloc)(struct inode *inode, struct file *filp,
800                                      unsigned int cmd, unsigned long arg);
801 extern int            DRM(agp_free)(struct inode *inode, struct file *filp,
802                                     unsigned int cmd, unsigned long arg);
803 extern int            DRM(agp_unbind)(struct inode *inode, struct file *filp,
804                                       unsigned int cmd, unsigned long arg);
805 extern int            DRM(agp_bind)(struct inode *inode, struct file *filp,
806                                     unsigned int cmd, unsigned long arg);
807 extern agp_memory     *DRM(agp_allocate_memory)(size_t pages, u32 type);
808 extern int            DRM(agp_free_memory)(agp_memory *handle);
809 extern int            DRM(agp_bind_memory)(agp_memory *handle, off_t start);
810 extern int            DRM(agp_unbind_memory)(agp_memory *handle);
811 #endif
812
813                                 /* Stub support (drm_stub.h) */
814 int                   DRM(stub_register)(const char *name,
815                                          struct file_operations *fops,
816                                          drm_device_t *dev);
817 int                   DRM(stub_unregister)(int minor);
818
819                                 /* Proc support (drm_proc.h) */
820 extern struct proc_dir_entry *DRM(proc_init)(drm_device_t *dev,
821                                              int minor,
822                                              struct proc_dir_entry *root,
823                                              struct proc_dir_entry **dev_root);
824 extern int            DRM(proc_cleanup)(int minor,
825                                         struct proc_dir_entry *root,
826                                         struct proc_dir_entry *dev_root);
827
828 #if __HAVE_SG
829                                 /* Scatter Gather Support (drm_scatter.h) */
830 extern void           DRM(sg_cleanup)(drm_sg_mem_t *entry);
831 extern int            DRM(sg_alloc)(struct inode *inode, struct file *filp,
832                                     unsigned int cmd, unsigned long arg);
833 extern int            DRM(sg_free)(struct inode *inode, struct file *filp,
834                                    unsigned int cmd, unsigned long arg);
835 #endif
836
837                                /* ATI PCIGART support (ati_pcigart.h) */
838 extern int            DRM(ati_pcigart_init)(drm_device_t *dev,
839                                             unsigned long *addr,
840                                             dma_addr_t *bus_addr);
841 extern int            DRM(ati_pcigart_cleanup)(drm_device_t *dev,
842                                                unsigned long addr,
843                                                dma_addr_t bus_addr);
844
845 #endif /* __KERNEL__ */
846 #endif