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