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