Add EDID quirk handling
[platform/upstream/libdrm.git] / linux-core / 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 #ifdef __KERNEL__
38 #ifdef __alpha__
39 /* add include of current.h so that "current" is defined
40  * before static inline funcs in wait.h. Doing this so we
41  * can build the DRM (part of PI DRI). 4/21/2000 S + B */
42 #include <asm/current.h>
43 #endif                          /* __alpha__ */
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/miscdevice.h>
47 #include <linux/fs.h>
48 #include <linux/proc_fs.h>
49 #include <linux/init.h>
50 #include <linux/file.h>
51 #include <linux/pci.h>
52 #include <linux/version.h>
53 #include <linux/sched.h>
54 #include <linux/smp_lock.h>     /* For (un)lock_kernel */
55 #include <linux/dma-mapping.h>
56 #include <linux/mm.h>
57 #include <linux/pagemap.h>
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
59 #include <linux/mutex.h>
60 #endif
61 #if defined(__alpha__) || defined(__powerpc__)
62 #include <asm/pgtable.h>        /* For pte_wrprotect */
63 #endif
64 #include <asm/io.h>
65 #include <asm/mman.h>
66 #include <asm/uaccess.h>
67 #ifdef CONFIG_MTRR
68 #include <asm/mtrr.h>
69 #endif
70 #include <asm/agp.h>
71 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
72 #include <linux/types.h>
73 #include <linux/agp_backend.h>
74 #endif
75 #include <linux/workqueue.h>
76 #include <linux/poll.h>
77 #include <asm/pgalloc.h>
78 #include "drm.h"
79 #include <linux/slab.h>
80 #include <linux/idr.h>
81
82 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
83 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
84
85 #include "drm_os_linux.h"
86 #include "drm_hashtab.h"
87 #include "drm_internal.h"
88
89 struct drm_device;
90 struct drm_file;
91
92 /* If you want the memory alloc debug functionality, change define below */
93 /* #define DEBUG_MEMORY */
94
95 /***********************************************************************/
96 /** \name DRM template customization defaults */
97 /*@{*/
98
99 /* driver capabilities and requirements mask */
100 #define DRIVER_USE_AGP     0x1
101 #define DRIVER_REQUIRE_AGP 0x2
102 #define DRIVER_USE_MTRR    0x4
103 #define DRIVER_PCI_DMA     0x8
104 #define DRIVER_SG          0x10
105 #define DRIVER_HAVE_DMA    0x20
106 #define DRIVER_HAVE_IRQ    0x40
107 #define DRIVER_IRQ_SHARED  0x80
108 #define DRIVER_DMA_QUEUE   0x100
109 #define DRIVER_FB_DMA      0x200
110 #define DRIVER_MODESET     0x400
111
112
113 /*@}*/
114
115 /***********************************************************************/
116 /** \name Begin the DRM... */
117 /*@{*/
118
119 #define DRM_DEBUG_CODE 2          /**< Include debugging code if > 1, then
120                                      also include looping detection. */
121
122 #define DRM_MAGIC_HASH_ORDER  4 /**< Size of key hash table. Must be power of 2. */
123 #define DRM_KERNEL_CONTEXT    0  /**< Change drm_resctx if changed */
124 #define DRM_RESERVED_CONTEXTS 1  /**< Change drm_resctx if changed */
125 #define DRM_LOOPING_LIMIT     5000000
126 #define DRM_TIME_SLICE        (HZ/20)  /**< Time slice for GLXContexts */
127 #define DRM_LOCK_SLICE        1 /**< Time slice for lock, in jiffies */
128
129 #define DRM_FLAG_DEBUG    0x01
130
131 #define DRM_MEM_DMA        0
132 #define DRM_MEM_SAREA      1
133 #define DRM_MEM_DRIVER     2
134 #define DRM_MEM_MAGIC      3
135 #define DRM_MEM_IOCTLS     4
136 #define DRM_MEM_MAPS       5
137 #define DRM_MEM_VMAS       6
138 #define DRM_MEM_BUFS       7
139 #define DRM_MEM_SEGS       8
140 #define DRM_MEM_PAGES      9
141 #define DRM_MEM_FILES     10
142 #define DRM_MEM_QUEUES    11
143 #define DRM_MEM_CMDS      12
144 #define DRM_MEM_MAPPINGS  13
145 #define DRM_MEM_BUFLISTS  14
146 #define DRM_MEM_AGPLISTS  15
147 #define DRM_MEM_TOTALAGP  16
148 #define DRM_MEM_BOUNDAGP  17
149 #define DRM_MEM_CTXBITMAP 18
150 #define DRM_MEM_STUB      19
151 #define DRM_MEM_SGLISTS   20
152 #define DRM_MEM_CTXLIST   21
153 #define DRM_MEM_MM        22
154 #define DRM_MEM_HASHTAB   23
155 #define DRM_MEM_OBJECTS   24
156 #define DRM_MEM_FENCE     25
157 #define DRM_MEM_TTM       26
158 #define DRM_MEM_BUFOBJ    27
159
160 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
161 #define DRM_MAP_HASH_OFFSET 0x10000000
162 #define DRM_MAP_HASH_ORDER 12
163 #define DRM_OBJECT_HASH_ORDER 12
164 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
165 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
166 /*
167  * This should be small enough to allow the use of kmalloc for hash tables
168  * instead of vmalloc.
169  */
170
171 #define DRM_FILE_HASH_ORDER 8
172 #define DRM_MM_INIT_MAX_PAGES 256
173
174 /*@}*/
175
176 #include "drm_compat.h"
177
178 /***********************************************************************/
179 /** \name Macros to make printk easier */
180 /*@{*/
181
182 /**
183  * Error output.
184  *
185  * \param fmt printf() like format string.
186  * \param arg arguments
187  */
188 #define DRM_ERROR(fmt, arg...) \
189         printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
190
191 /**
192  * Memory error output.
193  *
194  * \param area memory area where the error occurred.
195  * \param fmt printf() like format string.
196  * \param arg arguments
197  */
198 #define DRM_MEM_ERROR(area, fmt, arg...) \
199         printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
200                drm_mem_stats[area].name , ##arg)
201 #define DRM_INFO(fmt, arg...)  printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
202
203 /**
204  * Debug output.
205  *
206  * \param fmt printf() like format string.
207  * \param arg arguments
208  */
209 #if DRM_DEBUG_CODE
210 #define DRM_DEBUG(fmt, arg...)                                          \
211         do {                                                            \
212                 if ( drm_debug )                                        \
213                         printk(KERN_DEBUG                               \
214                                "[" DRM_NAME ":%s] " fmt ,               \
215                                __FUNCTION__ , ##arg);                   \
216         } while (0)
217 #else
218 #define DRM_DEBUG(fmt, arg...)           do { } while (0)
219 #endif
220
221 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
222
223 #define DRM_PROC_PRINT(fmt, arg...)                                     \
224    len += sprintf(&buf[len], fmt , ##arg);                              \
225    if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
226
227 #define DRM_PROC_PRINT_RET(ret, fmt, arg...)                            \
228    len += sprintf(&buf[len], fmt , ##arg);                              \
229    if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
230
231 /*@}*/
232
233 /***********************************************************************/
234 /** \name Internal types and structures */
235 /*@{*/
236
237 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
238 #define DRM_MIN(a,b) min(a,b)
239 #define DRM_MAX(a,b) max(a,b)
240
241 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
242 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
243 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
244
245 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
246 /**
247  * Get the private SAREA mapping.
248  *
249  * \param _dev DRM device.
250  * \param _ctx context number.
251  * \param _map output mapping.
252  */
253 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do {       \
254         (_map) = (_dev)->context_sareas[_ctx];          \
255 } while(0)
256
257 /**
258  * Test that the hardware lock is held by the caller, returning otherwise.
259  *
260  * \param dev DRM device.
261  * \param file_priv DRM file private pointer of the caller.
262  */
263 #define LOCK_TEST_WITH_RETURN( dev, file_priv )                         \
264 do {                                                                    \
265         if ( !_DRM_LOCK_IS_HELD( file_priv->master->lock.hw_lock->lock ) ||             \
266              file_priv->master->lock.file_priv != file_priv )   {                       \
267                 DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
268                            __FUNCTION__, _DRM_LOCK_IS_HELD( file_priv->master->lock.hw_lock->lock ),\
269                            file_priv->master->lock.file_priv, file_priv );              \
270                 return -EINVAL;                                         \
271         }                                                               \
272 } while (0)
273
274 /**
275  * Copy and IOCTL return string to user space
276  */
277 #define DRM_COPY( name, value )                                         \
278         len = strlen( value );                                          \
279         if ( len > name##_len ) len = name##_len;                       \
280         name##_len = strlen( value );                                   \
281         if ( len && name ) {                                            \
282                 if ( copy_to_user( name, value, len ) )                 \
283                         return -EFAULT;                                 \
284         }
285
286 /**
287  * Ioctl function type.
288  *
289  * \param dev DRM device structure
290  * \param data pointer to kernel-space stored data, copied in and out according
291  *             to ioctl description.
292  * \param file_priv DRM file private pointer.
293  */
294 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
295                         struct drm_file *file_priv);
296
297 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
298                                unsigned long arg);
299
300 #define DRM_AUTH        0x1
301 #define DRM_MASTER      0x2
302 #define DRM_ROOT_ONLY   0x4
303 #define DRM_CONTROL_ALLOW 0x8 // allow ioctl to operate on control node 
304
305 struct drm_ioctl_desc {
306         unsigned int cmd;
307         drm_ioctl_t *func;
308         int flags;
309 };
310 /**
311  * Creates a driver or general drm_ioctl_desc array entry for the given
312  * ioctl, for use by drm_ioctl().
313  */
314 #define DRM_IOCTL_DEF(ioctl, func, flags) \
315         [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
316
317 struct drm_magic_entry {
318         struct list_head head;
319         struct drm_hash_item hash_item;
320         struct drm_file *priv;
321 };
322
323 struct drm_vma_entry {
324         struct list_head head;
325         struct vm_area_struct *vma;
326         pid_t pid;
327 };
328
329 /**
330  * DMA buffer.
331  */
332 struct drm_buf {
333         int idx;                       /**< Index into master buflist */
334         int total;                     /**< Buffer size */
335         int order;                     /**< log-base-2(total) */
336         int used;                      /**< Amount of buffer in use (for DMA) */
337         unsigned long offset;          /**< Byte offset (used internally) */
338         void *address;                 /**< Address of buffer */
339         unsigned long bus_address;     /**< Bus address of buffer */
340         struct drm_buf *next;          /**< Kernel-only: used for free list */
341         __volatile__ int waiting;      /**< On kernel DMA queue */
342         __volatile__ int pending;      /**< On hardware DMA queue */
343         wait_queue_head_t dma_wait;    /**< Processes waiting */
344         struct drm_file *file_priv;    /**< Private of holding file descr */
345         int context;                   /**< Kernel queue for this buffer */
346         int while_locked;              /**< Dispatch this buffer while locked */
347         enum {
348                 DRM_LIST_NONE = 0,
349                 DRM_LIST_FREE = 1,
350                 DRM_LIST_WAIT = 2,
351                 DRM_LIST_PEND = 3,
352                 DRM_LIST_PRIO = 4,
353                 DRM_LIST_RECLAIM = 5
354         } list;                        /**< Which list we're on */
355
356         int dev_priv_size;              /**< Size of buffer private storage */
357         void *dev_private;              /**< Per-buffer private storage */
358 };
359
360 /** bufs is one longer than it has to be */
361 struct drm_waitlist {
362         int count;                      /**< Number of possible buffers */
363         struct drm_buf **bufs;          /**< List of pointers to buffers */
364         struct drm_buf **rp;                    /**< Read pointer */
365         struct drm_buf **wp;                    /**< Write pointer */
366         struct drm_buf **end;           /**< End pointer */
367         spinlock_t read_lock;
368         spinlock_t write_lock;
369 };
370
371 struct drm_freelist {
372         int initialized;               /**< Freelist in use */
373         atomic_t count;                /**< Number of free buffers */
374         struct drm_buf *next;          /**< End pointer */
375
376         wait_queue_head_t waiting;     /**< Processes waiting on free bufs */
377         int low_mark;                  /**< Low water mark */
378         int high_mark;                 /**< High water mark */
379         atomic_t wfh;                  /**< If waiting for high mark */
380         spinlock_t lock;
381 };
382
383 typedef struct drm_dma_handle {
384         dma_addr_t busaddr;
385         void *vaddr;
386         size_t size;
387 } drm_dma_handle_t;
388
389 /**
390  * Buffer entry.  There is one of this for each buffer size order.
391  */
392 struct drm_buf_entry {
393         int buf_size;                   /**< size */
394         int buf_count;                  /**< number of buffers */
395         struct drm_buf *buflist;                /**< buffer list */
396         int seg_count;
397         int page_order;
398         struct drm_dma_handle **seglist;
399         struct drm_freelist freelist;
400 };
401
402
403 enum drm_ref_type {
404         _DRM_REF_USE = 0,
405         _DRM_REF_TYPE1,
406         _DRM_NO_REF_TYPES
407 };
408
409
410 /** File private data */
411 struct drm_file {
412         int authenticated;
413         pid_t pid;
414         uid_t uid;
415         drm_magic_t magic;
416         unsigned long ioctl_count;
417         struct list_head lhead;
418         struct drm_minor *minor;
419         unsigned long lock_count;
420
421         /*
422          * The user object hash table is global and resides in the
423          * drm_device structure. We protect the lists and hash tables with the
424          * device struct_mutex. A bit coarse-grained but probably the best
425          * option.
426          */
427
428         struct list_head refd_objects;
429
430         struct drm_open_hash refd_object_hash[_DRM_NO_REF_TYPES];
431         struct file *filp;
432         void *driver_priv;
433
434         int is_master; /* this file private is a master for a minor */
435         struct drm_master *master; /* master this node is currently associated with
436                                       N.B. not always minor->master */
437         struct list_head fbs;
438 };
439
440 /** Wait queue */
441 struct drm_queue {
442         atomic_t use_count;             /**< Outstanding uses (+1) */
443         atomic_t finalization;          /**< Finalization in progress */
444         atomic_t block_count;           /**< Count of processes waiting */
445         atomic_t block_read;            /**< Queue blocked for reads */
446         wait_queue_head_t read_queue;   /**< Processes waiting on block_read */
447         atomic_t block_write;           /**< Queue blocked for writes */
448         wait_queue_head_t write_queue;  /**< Processes waiting on block_write */
449 #if 1
450         atomic_t total_queued;          /**< Total queued statistic */
451         atomic_t total_flushed;         /**< Total flushes statistic */
452         atomic_t total_locks;           /**< Total locks statistics */
453 #endif
454         enum drm_ctx_flags flags;       /**< Context preserving and 2D-only */
455         struct drm_waitlist waitlist;   /**< Pending buffers */
456         wait_queue_head_t flush_queue;  /**< Processes waiting until flush */
457 };
458
459 /**
460  * Lock data.
461  */
462 struct drm_lock_data {
463         struct drm_hw_lock *hw_lock;            /**< Hardware lock */
464         /** Private of lock holder's file (NULL=kernel) */
465         struct drm_file *file_priv;
466         wait_queue_head_t lock_queue;   /**< Queue of blocked processes */
467         unsigned long lock_time;        /**< Time of last lock in jiffies */
468         spinlock_t spinlock;
469         uint32_t kernel_waiters;
470         uint32_t user_waiters;
471         int idle_has_lock;
472 };
473
474 /**
475  * DMA data.
476  */
477 struct drm_device_dma {
478
479         struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
480         int buf_count;                  /**< total number of buffers */
481         struct drm_buf **buflist;               /**< Vector of pointers into drm_device_dma::bufs */
482         int seg_count;
483         int page_count;                 /**< number of pages */
484         unsigned long *pagelist;        /**< page list */
485         unsigned long byte_count;
486         enum {
487                 _DRM_DMA_USE_AGP = 0x01,
488                 _DRM_DMA_USE_SG = 0x02,
489                 _DRM_DMA_USE_FB = 0x04,
490                 _DRM_DMA_USE_PCI_RO = 0x08
491         } flags;
492
493 };
494
495 /**
496  * AGP memory entry.  Stored as a doubly linked list.
497  */
498 struct drm_agp_mem {
499         unsigned long handle;           /**< handle */
500         DRM_AGP_MEM *memory;
501         unsigned long bound;            /**< address */
502         int pages;
503         struct list_head head;
504 };
505
506 /**
507  * AGP data.
508  *
509  * \sa drm_agp_init() and drm_device::agp.
510  */
511 struct drm_agp_head {
512         DRM_AGP_KERN agp_info;          /**< AGP device information */
513         struct list_head memory;
514         unsigned long mode;             /**< AGP mode */
515 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
516         struct agp_bridge_data *bridge;
517 #endif
518         int enabled;                    /**< whether the AGP bus as been enabled */
519         int acquired;                   /**< whether the AGP device has been acquired */
520         unsigned long base;
521         int agp_mtrr;
522         int cant_use_aperture;
523         unsigned long page_mask;
524 };
525
526 /**
527  * Scatter-gather memory.
528  */
529 struct drm_sg_mem {
530         unsigned long handle;
531         void *virtual;
532         int pages;
533         struct page **pagelist;
534         dma_addr_t *busaddr;
535 };
536
537 struct drm_sigdata {
538         int context;
539         struct drm_hw_lock *lock;
540 };
541
542
543 /*
544  * Generic memory manager structs
545  */
546
547 struct drm_mm_node {
548         struct list_head fl_entry;
549         struct list_head ml_entry;
550         int free;
551         unsigned long start;
552         unsigned long size;
553         struct drm_mm *mm;
554         void *private;
555 };
556
557 struct drm_mm {
558         struct list_head fl_entry;
559         struct list_head ml_entry;
560 };
561
562
563 /**
564  * Mappings list
565  */
566 struct drm_map_list {
567         struct list_head head;          /**< list head */
568         struct drm_hash_item hash;
569         struct drm_map *map;                    /**< mapping */
570         uint64_t user_token;
571         struct drm_mm_node *file_offset_node;
572         struct drm_master *master; /** if this map is associated with a specific
573                                        master */
574 };
575
576 typedef struct drm_map drm_local_map_t;
577
578 /**
579  * Context handle list
580  */
581 struct drm_ctx_list {
582         struct list_head head;          /**< list head */
583         drm_context_t handle;           /**< context handle */
584         struct drm_file *tag;           /**< associated fd private data */
585 };
586
587 struct drm_vbl_sig {
588         struct list_head head;
589         unsigned int sequence;
590         struct siginfo info;
591         struct task_struct *task;
592 };
593
594 struct drm_hotplug_sig {
595         struct list_head head;
596         unsigned int counter;
597         struct siginfo info;
598         struct task_struct *task;
599 };
600
601 /* location of GART table */
602 #define DRM_ATI_GART_MAIN 1
603 #define DRM_ATI_GART_FB   2
604
605 #define DRM_ATI_GART_PCI 1
606 #define DRM_ATI_GART_PCIE 2
607 #define DRM_ATI_GART_IGP 3
608
609 struct drm_ati_pcigart_info {
610         int gart_table_location;
611         int gart_reg_if;
612         void *addr;
613         dma_addr_t bus_addr;
614         dma_addr_t table_mask;
615         dma_addr_t member_mask;
616         struct drm_dma_handle *table_handle;
617         drm_local_map_t mapping;
618         int table_size;
619 };
620
621 #include "drm_objects.h"
622 #include "drm_crtc.h"
623
624 /* per-master structure */
625 struct drm_master {
626         
627         struct list_head head; /**< each minor contains a list of masters */
628         struct drm_minor *minor; /**< link back to minor we are a master for */
629
630         char *unique;                   /**< Unique identifier: e.g., busid */
631         int unique_len;                 /**< Length of unique field */
632
633         int blocked;                    /**< Blocked due to VC switch? */
634
635         /** \name Authentication */
636         /*@{ */
637         struct drm_open_hash magiclist;
638         struct list_head magicfree;
639         /*@} */
640
641         struct drm_lock_data lock;              /**< Information on hardware lock */
642
643         void *driver_priv; /**< Private structure for driver to use */
644 };
645
646 /**
647  * DRM driver structure. This structure represent the common code for
648  * a family of cards. There will one drm_device for each card present
649  * in this family
650  */
651
652 struct drm_driver {
653         int (*load) (struct drm_device *, unsigned long flags);
654         int (*firstopen) (struct drm_device *);
655         int (*open) (struct drm_device *, struct drm_file *);
656         void (*preclose) (struct drm_device *, struct drm_file *file_priv);
657         void (*postclose) (struct drm_device *, struct drm_file *);
658         void (*lastclose) (struct drm_device *);
659         int (*unload) (struct drm_device *);
660         int (*suspend) (struct drm_device *, pm_message_t state);
661         int (*resume) (struct drm_device *);
662         int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
663         void (*dma_ready) (struct drm_device *);
664         int (*dma_quiescent) (struct drm_device *);
665         int (*context_ctor) (struct drm_device *dev, int context);
666         int (*context_dtor) (struct drm_device *dev, int context);
667         int (*kernel_context_switch) (struct drm_device *dev, int old,
668                                       int new);
669         void (*kernel_context_switch_unlock) (struct drm_device * dev);
670         /**
671          * get_vblank_counter - get raw hardware vblank counter
672          * @dev: DRM device
673          * @crtc: counter to fetch
674          *
675          * Driver callback for fetching a raw hardware vblank counter
676          * for @crtc.  If a device doesn't have a hardware counter, the
677          * driver can simply return the value of drm_vblank_count and
678          * make the enable_vblank() and disable_vblank() hooks into no-ops,
679          * leaving interrupts enabled at all times.
680          *
681          * Wraparound handling and loss of events due to modesetting is dealt
682          * with in the DRM core code.
683          *
684          * RETURNS
685          * Raw vblank counter value.
686          */
687         u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
688
689         /**
690          * enable_vblank - enable vblank interrupt events
691          * @dev: DRM device
692          * @crtc: which irq to enable
693          *
694          * Enable vblank interrupts for @crtc.  If the device doesn't have
695          * a hardware vblank counter, this routine should be a no-op, since
696          * interrupts will have to stay on to keep the count accurate.
697          *
698          * RETURNS
699          * Zero on success, appropriate errno if the given @crtc's vblank
700          * interrupt cannot be enabled.
701          */
702         int (*enable_vblank) (struct drm_device *dev, int crtc);
703
704         /**
705          * disable_vblank - disable vblank interrupt events
706          * @dev: DRM device
707          * @crtc: which irq to enable
708          *
709          * Disable vblank interrupts for @crtc.  If the device doesn't have
710          * a hardware vblank counter, this routine should be a no-op, since
711          * interrupts will have to stay on to keep the count accurate.
712          */
713         void (*disable_vblank) (struct drm_device *dev, int crtc);
714         int (*dri_library_name) (struct drm_device *dev, char * buf);
715
716         /**
717          * Called by \c drm_device_is_agp.  Typically used to determine if a
718          * card is really attached to AGP or not.
719          *
720          * \param dev  DRM device handle
721          *
722          * \returns
723          * One of three values is returned depending on whether or not the
724          * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
725          * (return of 1), or may or may not be AGP (return of 2).
726          */
727         int (*device_is_agp) (struct drm_device *dev);
728
729 /* these have to be filled in */
730          irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
731         void (*irq_preinstall) (struct drm_device *dev);
732         int (*irq_postinstall) (struct drm_device *dev);
733         void (*irq_uninstall) (struct drm_device *dev);
734         void (*reclaim_buffers) (struct drm_device *dev,
735                                  struct drm_file *file_priv);
736         void (*reclaim_buffers_locked) (struct drm_device *dev,
737                                         struct drm_file *file_priv);
738         void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
739                                             struct drm_file *file_priv);
740         unsigned long (*get_map_ofs) (struct drm_map *map);
741         unsigned long (*get_reg_ofs) (struct drm_device *dev);
742         void (*set_version) (struct drm_device *dev,
743                              struct drm_set_version *sv);
744
745         /* Master routines */
746         int (*master_create)(struct drm_device *dev, struct drm_master *master);
747         void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
748
749         struct drm_fence_driver *fence_driver;
750         struct drm_bo_driver *bo_driver;
751
752         int major;
753         int minor;
754         int patchlevel;
755         char *name;
756         char *desc;
757         char *date;
758
759 /* variables */
760         u32 driver_features;
761         int dev_priv_size;
762         struct drm_ioctl_desc *ioctls;
763         int num_ioctls;
764         struct file_operations fops;
765         struct pci_driver pci_driver;
766 };
767
768 #define DRM_MINOR_UNASSIGNED 0
769 #define DRM_MINOR_LEGACY 1
770 #define DRM_MINOR_CONTROL 2
771 #define DRM_MINOR_RENDER 3
772
773 /**
774  * DRM minor structure. This structure represents a drm minor number.
775  */
776 struct drm_minor {
777         int index;                      /**< Minor device number */
778         int type;                       /**< Control or render */
779         dev_t device;                   /**< Device number for mknod */
780         struct device kdev;             /**< Linux device */
781         struct drm_device *dev;
782         /* for render nodes */
783         struct proc_dir_entry *dev_root;  /**< proc directory entry */
784         struct class_device *dev_class;
785
786         /* for control nodes - a pointer to the current master for this control node */
787         struct drm_master *master; /* currently active master for this node */
788         struct list_head master_list;
789
790         struct drm_mode_group mode_group;
791 };
792
793
794 /**
795  * DRM device structure. This structure represent a complete card that
796  * may contain multiple heads.
797  */
798 struct drm_device {
799         char *devname;                  /**< For /proc/interrupts */
800         int if_version;                 /**< Highest interface version set */
801
802         /** \name Locks */
803         /*@{ */
804         spinlock_t count_lock;          /**< For inuse, drm_device::open_count, drm_device::buf_use */
805         struct mutex struct_mutex;      /**< For others */
806         /*@} */
807
808         /** \name Usage Counters */
809         /*@{ */
810         int open_count;                 /**< Outstanding files open */
811         atomic_t ioctl_count;           /**< Outstanding IOCTLs pending */
812         atomic_t vma_count;             /**< Outstanding vma areas open */
813         int buf_use;                    /**< Buffers in use -- cannot alloc */
814         atomic_t buf_alloc;             /**< Buffer allocation in progress */
815         /*@} */
816
817         /** \name Performance counters */
818         /*@{ */
819         unsigned long counters;
820         enum drm_stat_type types[15];
821         atomic_t counts[15];
822         /*@} */
823
824
825         /** \name Memory management */
826         /*@{ */
827         struct list_head maplist;       /**< Linked list of regions */
828         int map_count;                  /**< Number of mappable regions */
829         struct drm_open_hash map_hash;       /**< User token hash table for maps */
830         struct drm_mm offset_manager;        /**< User token manager */
831         struct drm_open_hash object_hash;    /**< User token hash table for objects */
832         struct address_space *dev_mapping;  /**< For unmap_mapping_range() */
833         struct page *ttm_dummy_page;
834
835         /** \name Context handle management */
836         /*@{ */
837         struct list_head ctxlist;       /**< Linked list of context handles */
838         int ctx_count;                  /**< Number of context handles */
839         struct mutex ctxlist_mutex;     /**< For ctxlist */
840
841         struct idr ctx_idr;
842
843         struct list_head vmalist;       /**< List of vmas (for debugging) */
844
845         struct list_head filelist;
846
847         /*@} */
848
849         /** \name DMA queues (contexts) */
850         /*@{ */
851         int queue_count;                /**< Number of active DMA queues */
852         int queue_reserved;             /**< Number of reserved DMA queues */
853         int queue_slots;                /**< Actual length of queuelist */
854         struct drm_queue **queuelist;   /**< Vector of pointers to DMA queues */
855         struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
856         /*@} */
857
858
859         /** \name Context support */
860         /*@{ */
861         int irq;                        /**< Interrupt used by board */
862         int irq_enabled;                /**< True if irq handler is enabled */
863         __volatile__ long context_flag; /**< Context swapping flag */
864         __volatile__ long interrupt_flag; /**< Interruption handler flag */
865         __volatile__ long dma_flag;     /**< DMA dispatch flag */
866         struct timer_list timer;        /**< Timer for delaying ctx switch */
867         wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
868         int last_checked;               /**< Last context checked for DMA */
869         int last_context;               /**< Last current context */
870         unsigned long last_switch;      /**< jiffies at last context switch */
871         /*@} */
872
873         struct work_struct work;
874
875         /** \name HOTPLUG IRQ support */
876         /*@{ */
877         wait_queue_head_t hotplug_queue;        /**< HOTPLUG wait queue */
878         spinlock_t hotplug_lock;
879         struct list_head *hotplug_sigs;         /**< signal list to send on HOTPLUG */
880         atomic_t hotplug_signal_pending;        /* number of signals pending on all crtcs*/
881
882         /*@} */
883
884         /** \name VBLANK IRQ support */
885         /*@{ */
886
887         wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
888         atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
889         spinlock_t vbl_lock;
890         struct list_head *vbl_sigs;             /**< signal list to send on VBLANK */
891         atomic_t vbl_signal_pending;    /* number of signals pending on all crtcs*/
892         atomic_t *vblank_refcount;      /* number of users of vblank interrupts per crtc */
893         u32 *last_vblank;               /* protected by dev->vbl_lock, used */
894                                         /* for wraparound handling */
895         u32 *vblank_offset;             /* used to track how many vblanks */
896         int *vblank_enabled;            /* so we don't call enable more than
897                                            once per disable */
898         u32 *vblank_premodeset;         /*  were lost during modeset */
899         struct timer_list vblank_disable_timer;
900
901         unsigned long max_vblank_count; /**< size of vblank counter register */
902         spinlock_t tasklet_lock;        /**< For drm_locked_tasklet */
903         void (*locked_tasklet_func)(struct drm_device *dev);
904
905         /*@} */
906         cycles_t ctx_start;
907         cycles_t lck_start;
908
909         struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
910         wait_queue_head_t buf_readers;  /**< Processes waiting to read */
911         wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
912
913         struct drm_agp_head *agp;               /**< AGP data */
914
915         struct pci_dev *pdev;           /**< PCI device structure */
916         int pci_vendor;                 /**< PCI vendor id */
917         int pci_device;                 /**< PCI device id */
918 #ifdef __alpha__
919         struct pci_controller *hose;
920 #endif
921         int num_crtcs;                  /**< Number of CRTCs on this device */
922         struct drm_sg_mem *sg;          /**< Scatter gather memory */
923         void *dev_private;              /**< device private data */
924         struct drm_sigdata sigdata;             /**< For block_all_signals */
925         sigset_t sigmask;
926
927         struct drm_driver *driver;
928         drm_local_map_t *agp_buffer_map;
929         unsigned int agp_buffer_token;
930
931         /* minor number for control node */
932         struct drm_minor *control;
933         struct drm_minor *primary;              /**< render type primary screen head */
934
935         struct drm_fence_manager fm;
936         struct drm_buffer_manager bm;
937
938         /** \name Drawable information */
939         /*@{ */
940         spinlock_t drw_lock;
941         struct idr drw_idr;
942         /*@} */
943
944         /* DRM mode setting */
945         struct drm_mode_config mode_config;
946 };
947
948 #if __OS_HAS_AGP
949 struct drm_agp_ttm_backend {
950         struct drm_ttm_backend backend;
951         DRM_AGP_MEM *mem;
952         struct agp_bridge_data *bridge;
953         int populated;
954 };
955 #endif
956
957 typedef struct ati_pcigart_ttm_backend {
958         struct drm_ttm_backend backend;
959         int populated;
960         void (*gart_flush_fn)(struct drm_device *dev);
961         struct drm_ati_pcigart_info *gart_info;
962         unsigned long offset;
963         struct page **pages;
964         int num_pages;
965         int bound;
966         struct drm_device *dev;
967 } ati_pcigart_ttm_backend_t;
968
969 static __inline__ int drm_core_check_feature(struct drm_device *dev,
970                                              int feature)
971 {
972         return ((dev->driver->driver_features & feature) ? 1 : 0);
973 }
974
975 #ifdef __alpha__
976 #define drm_get_pci_domain(dev) dev->hose->index
977 #else
978 #define drm_get_pci_domain(dev) 0
979 #endif
980
981 #if __OS_HAS_AGP
982 static inline int drm_core_has_AGP(struct drm_device *dev)
983 {
984         return drm_core_check_feature(dev, DRIVER_USE_AGP);
985 }
986 #else
987 #define drm_core_has_AGP(dev) (0)
988 #endif
989
990 #if __OS_HAS_MTRR
991 static inline int drm_core_has_MTRR(struct drm_device *dev)
992 {
993         return drm_core_check_feature(dev, DRIVER_USE_MTRR);
994 }
995
996 #define DRM_MTRR_WC             MTRR_TYPE_WRCOMB
997
998 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
999                                unsigned int flags)
1000 {
1001         return mtrr_add(offset, size, flags, 1);
1002 }
1003
1004 static inline int drm_mtrr_del(int handle, unsigned long offset,
1005                                unsigned long size, unsigned int flags)
1006 {
1007         return mtrr_del(handle, offset, size);
1008 }
1009
1010 #else
1011 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1012                                unsigned int flags)
1013 {
1014         return -ENODEV;
1015 }
1016
1017 static inline int drm_mtrr_del(int handle, unsigned long offset,
1018                                unsigned long size, unsigned int flags)
1019 {
1020         return -ENODEV;
1021 }
1022
1023 #define drm_core_has_MTRR(dev) (0)
1024 #define DRM_MTRR_WC             0
1025 #endif
1026
1027
1028 /******************************************************************/
1029 /** \name Internal function definitions */
1030 /*@{*/
1031
1032                                 /* Driver support (drm_drv.h) */
1033 extern int drm_fb_loaded;
1034 extern int drm_init(struct drm_driver *driver,
1035                               struct pci_device_id *pciidlist);
1036 extern void drm_exit(struct drm_driver *driver);
1037 extern void drm_cleanup_pci(struct pci_dev *pdev);
1038 extern int drm_ioctl(struct inode *inode, struct file *filp,
1039                      unsigned int cmd, unsigned long arg);
1040 extern long drm_unlocked_ioctl(struct file *filp,
1041                                unsigned int cmd, unsigned long arg);
1042 extern long drm_compat_ioctl(struct file *filp,
1043                              unsigned int cmd, unsigned long arg);
1044
1045 extern int drm_lastclose(struct drm_device *dev);
1046
1047                                 /* Device support (drm_fops.h) */
1048 extern int drm_open(struct inode *inode, struct file *filp);
1049 extern int drm_stub_open(struct inode *inode, struct file *filp);
1050 extern int drm_fasync(int fd, struct file *filp, int on);
1051 extern int drm_release(struct inode *inode, struct file *filp);
1052 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1053
1054                                 /* Mapping support (drm_vm.h) */
1055 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1056 extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
1057 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1058 extern pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma);
1059
1060                                 /* Memory management support (drm_memory.h) */
1061 #include "drm_memory.h"
1062 extern void drm_mem_init(void);
1063 extern int drm_mem_info(char *buf, char **start, off_t offset,
1064                         int request, int *eof, void *data);
1065 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1066 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
1067 extern unsigned long drm_alloc_pages(int order, int area);
1068 extern void drm_free_pages(unsigned long address, int order, int area);
1069 extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
1070 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
1071 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1072 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1073
1074 extern void drm_free_memctl(size_t size);
1075 extern int drm_alloc_memctl(size_t size);
1076 extern void drm_query_memctl(uint64_t *cur_used,
1077                              uint64_t *emer_used,
1078                              uint64_t *low_threshold,
1079                              uint64_t *high_threshold,
1080                              uint64_t *emer_threshold);
1081 extern void drm_init_memctl(size_t low_threshold,
1082                             size_t high_threshold,
1083                             size_t unit_size);
1084
1085                                 /* Misc. IOCTL support (drm_ioctl.h) */
1086 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1087                             struct drm_file *file_priv);
1088 extern int drm_getunique(struct drm_device *dev, void *data,
1089                          struct drm_file *file_priv);
1090 extern int drm_setunique(struct drm_device *dev, void *data,
1091                          struct drm_file *file_priv);
1092 extern int drm_getmap(struct drm_device *dev, void *data,
1093                       struct drm_file *file_priv);
1094 extern int drm_getclient(struct drm_device *dev, void *data,
1095                          struct drm_file *file_priv);
1096 extern int drm_getstats(struct drm_device *dev, void *data,
1097                         struct drm_file *file_priv);
1098 extern int drm_setversion(struct drm_device *dev, void *data,
1099                           struct drm_file *file_priv);
1100 extern int drm_noop(struct drm_device *dev, void *data,
1101                     struct drm_file *file_priv);
1102
1103                                 /* Context IOCTL support (drm_context.h) */
1104 extern int drm_resctx(struct drm_device *dev, void *data,
1105                       struct drm_file *file_priv);
1106 extern int drm_addctx(struct drm_device *dev, void *data,
1107                       struct drm_file *file_priv);
1108 extern int drm_modctx(struct drm_device *dev, void *data,
1109                       struct drm_file *file_priv);
1110 extern int drm_getctx(struct drm_device *dev, void *data,
1111                       struct drm_file *file_priv);
1112 extern int drm_switchctx(struct drm_device *dev, void *data,
1113                          struct drm_file *file_priv);
1114 extern int drm_newctx(struct drm_device *dev, void *data,
1115                       struct drm_file *file_priv);
1116 extern int drm_rmctx(struct drm_device *dev, void *data,
1117                      struct drm_file *file_priv);
1118
1119 extern int drm_ctxbitmap_init(struct drm_device *dev);
1120 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1121 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1122
1123 extern int drm_setsareactx(struct drm_device *dev, void *data,
1124                            struct drm_file *file_priv);
1125 extern int drm_getsareactx(struct drm_device *dev, void *data,
1126                            struct drm_file *file_priv);
1127
1128                                 /* Drawable IOCTL support (drm_drawable.h) */
1129 extern int drm_adddraw(struct drm_device *dev, void *data,
1130                        struct drm_file *file_priv);
1131 extern int drm_rmdraw(struct drm_device *dev, void *data,
1132                       struct drm_file *file_priv);
1133 extern int drm_update_drawable_info(struct drm_device *dev, void *data,
1134                                     struct drm_file *file_priv);
1135 extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1136                                                        drm_drawable_t id);
1137 extern void drm_drawable_free_all(struct drm_device *dev);
1138
1139                                 /* Authentication IOCTL support (drm_auth.h) */
1140 extern int drm_getmagic(struct drm_device *dev, void *data,
1141                         struct drm_file *file_priv);
1142 extern int drm_authmagic(struct drm_device *dev, void *data,
1143                          struct drm_file *file_priv);
1144
1145                                 /* Locking IOCTL support (drm_lock.h) */
1146 extern int drm_lock(struct drm_device *dev, void *data,
1147                     struct drm_file *file_priv);
1148 extern int drm_unlock(struct drm_device *dev, void *data,
1149                       struct drm_file *file_priv);
1150 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1151 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1152 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1153 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1154
1155 /*
1156  * These are exported to drivers so that they can implement fencing using
1157  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1158  */
1159
1160 extern int drm_i_have_hw_lock(struct drm_device *dev,
1161                               struct drm_file *file_priv);
1162
1163                                 /* Buffer management support (drm_bufs.h) */
1164 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1165 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1166 extern int drm_addbufs_fb (struct drm_device *dev, struct drm_buf_desc * request);
1167 extern int drm_addmap(struct drm_device *dev, unsigned int offset,
1168                       unsigned int size, enum drm_map_type type,
1169                       enum drm_map_flags flags, drm_local_map_t ** map_ptr);
1170 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1171                             struct drm_file *file_priv);
1172 extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1173 extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
1174 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1175                            struct drm_file *file_priv);
1176 extern int drm_addbufs(struct drm_device *dev, void *data,
1177                        struct drm_file *file_priv);
1178 extern int drm_infobufs(struct drm_device *dev, void *data,
1179                         struct drm_file *file_priv);
1180 extern int drm_markbufs(struct drm_device *dev, void *data,
1181                         struct drm_file *file_priv);
1182 extern int drm_freebufs(struct drm_device *dev, void *data,
1183                         struct drm_file *file_priv);
1184 extern int drm_mapbufs(struct drm_device *dev, void *data,
1185                        struct drm_file *file_priv);
1186 extern int drm_order(unsigned long size);
1187 extern unsigned long drm_get_resource_start(struct drm_device *dev,
1188                                             unsigned int resource);
1189 extern unsigned long drm_get_resource_len(struct drm_device *dev,
1190                                           unsigned int resource);
1191 extern struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
1192                                                   drm_local_map_t *map);
1193
1194
1195                                 /* DMA support (drm_dma.h) */
1196 extern int drm_dma_setup(struct drm_device *dev);
1197 extern void drm_dma_takedown(struct drm_device *dev);
1198 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1199 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1200                                      struct drm_file *filp);
1201
1202                                 /* IRQ support (drm_irq.h) */
1203 extern int drm_control(struct drm_device *dev, void *data,
1204                        struct drm_file *file_priv);
1205 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1206 extern int drm_irq_install(struct drm_device *dev);
1207 extern int drm_irq_uninstall(struct drm_device *dev);
1208 extern void drm_driver_irq_preinstall(struct drm_device *dev);
1209 extern void drm_driver_irq_postinstall(struct drm_device *dev);
1210 extern void drm_driver_irq_uninstall(struct drm_device *dev);
1211
1212 extern int drm_hotplug_init(struct drm_device *dev);
1213 extern int drm_wait_hotplug(struct drm_device *dev, void *data, struct drm_file *filp);
1214 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1215 extern int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *filp);
1216 extern int drm_wait_hotplug(struct drm_device *dev, void *data, struct drm_file *filp);
1217 extern int drm_vblank_wait(struct drm_device * dev, unsigned int *vbl_seq);
1218 extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
1219 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1220 extern void drm_update_vblank_count(struct drm_device *dev, int crtc);
1221 extern void drm_handle_vblank(struct drm_device *dev, int crtc);
1222 extern void drm_handle_hotplug(struct drm_device *dev);
1223 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1224 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1225
1226                                 /* Modesetting support */
1227 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1228                            struct drm_file *file_priv);
1229
1230                                 /* AGP/GART support (drm_agpsupport.h) */
1231 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1232 extern int drm_agp_acquire(struct drm_device *dev);
1233 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1234                                  struct drm_file *file_priv);
1235 extern int drm_agp_release(struct drm_device *dev);
1236 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1237                                  struct drm_file *file_priv);
1238 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1239 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1240                                 struct drm_file *file_priv);
1241 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1242 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1243                         struct drm_file *file_priv);
1244 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1245 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1246                          struct drm_file *file_priv);
1247 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1248 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1249                         struct drm_file *file_priv);
1250 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1251 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1252                           struct drm_file *file_priv);
1253 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1254 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1255                         struct drm_file *file_priv);
1256 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
1257 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
1258 #else
1259 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1260 #endif
1261 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1262 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1263 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1264 extern struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev);
1265 extern void drm_agp_chipset_flush(struct drm_device *dev);
1266                                 /* Stub support (drm_stub.h) */
1267 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1268                                struct drm_file *file_priv);
1269 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1270                                 struct drm_file *file_priv);
1271 extern struct drm_master *drm_get_master(struct drm_minor *minor);
1272 extern void drm_put_master(struct drm_master *master);
1273 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1274                      struct drm_driver *driver);
1275 extern int drm_put_dev(struct drm_device *dev);
1276 extern int drm_put_minor(struct drm_minor **minor);
1277 extern unsigned int drm_debug; /* 1 to enable debug output */
1278
1279 extern struct class *drm_class;
1280 extern struct proc_dir_entry *drm_proc_root;
1281
1282 extern struct idr drm_minors_idr;
1283
1284 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1285
1286                                 /* Proc support (drm_proc.h) */
1287 int drm_proc_init(struct drm_minor *minor, int minor_id,
1288                   struct proc_dir_entry *root);
1289 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1290
1291                                 /* Scatter Gather Support (drm_scatter.h) */
1292 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1293 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1294                         struct drm_file *file_priv);
1295 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1296 extern int drm_sg_free(struct drm_device *dev, void *data,
1297                        struct drm_file *file_priv);
1298
1299                                /* ATI PCIGART support (ati_pcigart.h) */
1300 extern int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1301 extern int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1302
1303 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1304                            size_t align, dma_addr_t maxaddr);
1305 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1306 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1307
1308                                /* sysfs support (drm_sysfs.c) */
1309 struct drm_sysfs_class;
1310 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1311 extern void drm_sysfs_destroy(void);
1312 extern int drm_sysfs_device_add(struct drm_minor *minor);
1313 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1314 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1315 extern char *drm_get_connector_status_name(enum drm_connector_status status);
1316 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1317 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1318
1319 /*
1320  * Basic memory manager support (drm_mm.c)
1321  */
1322
1323 extern struct drm_mm_node * drm_mm_get_block(struct drm_mm_node * parent, unsigned long size,
1324                                                unsigned alignment);
1325 extern void drm_mm_put_block(struct drm_mm_node *cur);
1326 extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
1327                                                 unsigned alignment, int best_match);
1328 extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
1329 extern void drm_mm_takedown(struct drm_mm *mm);
1330 extern int drm_mm_clean(struct drm_mm *mm);
1331 extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
1332 extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
1333 extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
1334 extern void drm_mm_print(struct drm_mm *mm, const char *name);
1335
1336 static inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
1337 {
1338         return block->mm;
1339 }
1340
1341 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1342 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1343
1344 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1345                                                    unsigned int token)
1346 {
1347         struct drm_map_list *_entry;
1348         list_for_each_entry(_entry, &dev->maplist, head)
1349                 if (_entry->user_token == token)
1350                         return _entry->map;
1351         return NULL;
1352 }
1353
1354 static __inline__ int drm_device_is_agp(struct drm_device *dev)
1355 {
1356         if ( dev->driver->device_is_agp != NULL ) {
1357                 int err = (*dev->driver->device_is_agp)(dev);
1358
1359                 if (err != 2) {
1360                         return err;
1361                 }
1362         }
1363
1364         return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1365 }
1366
1367 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1368 {
1369         return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1370 }
1371
1372 static __inline__ void drm_core_dropmap(struct drm_map *map)
1373 {
1374 }
1375
1376 #ifndef DEBUG_MEMORY
1377 /** Wrapper around kmalloc() */
1378 static __inline__ void *drm_alloc(size_t size, int area)
1379 {
1380         return kmalloc(size, GFP_KERNEL);
1381 }
1382
1383 /** Wrapper around kfree() */
1384 static __inline__ void drm_free(void *pt, size_t size, int area)
1385 {
1386         kfree(pt);
1387 }
1388 #else
1389 extern void *drm_alloc(size_t size, int area);
1390 extern void drm_free(void *pt, size_t size, int area);
1391 #endif
1392
1393 /*
1394  * Accounting variants of standard calls.
1395  */
1396
1397 static inline void *drm_ctl_alloc(size_t size, int area)
1398 {
1399         void *ret;
1400         if (drm_alloc_memctl(size))
1401                 return NULL;
1402         ret = drm_alloc(size, area);
1403         if (!ret)
1404                 drm_free_memctl(size);
1405         return ret;
1406 }
1407
1408 static inline void *drm_ctl_calloc(size_t nmemb, size_t size, int area)
1409 {
1410         void *ret;
1411
1412         if (drm_alloc_memctl(nmemb*size))
1413                 return NULL;
1414         ret = drm_calloc(nmemb, size, area);
1415         if (!ret)
1416                 drm_free_memctl(nmemb*size);
1417         return ret;
1418 }
1419
1420 static inline void drm_ctl_free(void *pt, size_t size, int area)
1421 {
1422         drm_free(pt, size, area);
1423         drm_free_memctl(size);
1424 }
1425
1426 /*@}*/
1427
1428 #endif                          /* __KERNEL__ */
1429 #endif