OSDN Git Service

drm: initial mode object groups.
[android-x86/external-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         /* FB routines, if present */
746         int (*fb_probe)(struct drm_device *dev, struct drm_crtc *crtc, struct drm_connector *connector);
747         int (*fb_remove)(struct drm_device *dev, struct drm_framebuffer *fb);
748         int (*fb_resize)(struct drm_device *dev, struct drm_crtc *crtc);
749
750         /* Master routines */
751         int (*master_create)(struct drm_device *dev, struct drm_master *master);
752         void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
753
754         struct drm_fence_driver *fence_driver;
755         struct drm_bo_driver *bo_driver;
756
757         int major;
758         int minor;
759         int patchlevel;
760         char *name;
761         char *desc;
762         char *date;
763
764 /* variables */
765         u32 driver_features;
766         int dev_priv_size;
767         struct drm_ioctl_desc *ioctls;
768         int num_ioctls;
769         struct file_operations fops;
770         struct pci_driver pci_driver;
771 };
772
773 #define DRM_MINOR_UNASSIGNED 0
774 #define DRM_MINOR_LEGACY 1
775 #define DRM_MINOR_CONTROL 2
776 #define DRM_MINOR_RENDER 3
777
778 /**
779  * DRM minor structure. This structure represents a drm minor number.
780  */
781 struct drm_minor {
782         int index;                      /**< Minor device number */
783         int type;                       /**< Control or render */
784         dev_t device;                   /**< Device number for mknod */
785         struct device kdev;             /**< Linux device */
786         struct drm_device *dev;
787         /* for render nodes */
788         struct proc_dir_entry *dev_root;  /**< proc directory entry */
789         struct class_device *dev_class;
790
791         /* for control nodes - a pointer to the current master for this control node */
792         struct drm_master *master; /* currently active master for this node */
793         struct list_head master_list;
794
795         struct drm_mode_group mode_group;
796 };
797
798
799 /**
800  * DRM device structure. This structure represent a complete card that
801  * may contain multiple heads.
802  */
803 struct drm_device {
804         char *devname;                  /**< For /proc/interrupts */
805         int if_version;                 /**< Highest interface version set */
806
807         /** \name Locks */
808         /*@{ */
809         spinlock_t count_lock;          /**< For inuse, drm_device::open_count, drm_device::buf_use */
810         struct mutex struct_mutex;      /**< For others */
811         /*@} */
812
813         /** \name Usage Counters */
814         /*@{ */
815         int open_count;                 /**< Outstanding files open */
816         atomic_t ioctl_count;           /**< Outstanding IOCTLs pending */
817         atomic_t vma_count;             /**< Outstanding vma areas open */
818         int buf_use;                    /**< Buffers in use -- cannot alloc */
819         atomic_t buf_alloc;             /**< Buffer allocation in progress */
820         /*@} */
821
822         /** \name Performance counters */
823         /*@{ */
824         unsigned long counters;
825         enum drm_stat_type types[15];
826         atomic_t counts[15];
827         /*@} */
828
829
830         /** \name Memory management */
831         /*@{ */
832         struct list_head maplist;       /**< Linked list of regions */
833         int map_count;                  /**< Number of mappable regions */
834         struct drm_open_hash map_hash;       /**< User token hash table for maps */
835         struct drm_mm offset_manager;        /**< User token manager */
836         struct drm_open_hash object_hash;    /**< User token hash table for objects */
837         struct address_space *dev_mapping;  /**< For unmap_mapping_range() */
838         struct page *ttm_dummy_page;
839
840         /** \name Context handle management */
841         /*@{ */
842         struct list_head ctxlist;       /**< Linked list of context handles */
843         int ctx_count;                  /**< Number of context handles */
844         struct mutex ctxlist_mutex;     /**< For ctxlist */
845
846         struct idr ctx_idr;
847
848         struct list_head vmalist;       /**< List of vmas (for debugging) */
849
850         struct list_head filelist;
851
852         /*@} */
853
854         /** \name DMA queues (contexts) */
855         /*@{ */
856         int queue_count;                /**< Number of active DMA queues */
857         int queue_reserved;             /**< Number of reserved DMA queues */
858         int queue_slots;                /**< Actual length of queuelist */
859         struct drm_queue **queuelist;   /**< Vector of pointers to DMA queues */
860         struct drm_device_dma *dma;             /**< Optional pointer for DMA support */
861         /*@} */
862
863
864         /** \name Context support */
865         /*@{ */
866         int irq;                        /**< Interrupt used by board */
867         int irq_enabled;                /**< True if irq handler is enabled */
868         __volatile__ long context_flag; /**< Context swapping flag */
869         __volatile__ long interrupt_flag; /**< Interruption handler flag */
870         __volatile__ long dma_flag;     /**< DMA dispatch flag */
871         struct timer_list timer;        /**< Timer for delaying ctx switch */
872         wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
873         int last_checked;               /**< Last context checked for DMA */
874         int last_context;               /**< Last current context */
875         unsigned long last_switch;      /**< jiffies at last context switch */
876         /*@} */
877
878         struct work_struct work;
879
880         /** \name HOTPLUG IRQ support */
881         /*@{ */
882         wait_queue_head_t hotplug_queue;        /**< HOTPLUG wait queue */
883         spinlock_t hotplug_lock;
884         struct list_head *hotplug_sigs;         /**< signal list to send on HOTPLUG */
885         atomic_t hotplug_signal_pending;        /* number of signals pending on all crtcs*/
886
887         /*@} */
888
889         /** \name VBLANK IRQ support */
890         /*@{ */
891
892         wait_queue_head_t *vbl_queue;   /**< VBLANK wait queue */
893         atomic_t *_vblank_count;        /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
894         spinlock_t vbl_lock;
895         struct list_head *vbl_sigs;             /**< signal list to send on VBLANK */
896         atomic_t vbl_signal_pending;    /* number of signals pending on all crtcs*/
897         atomic_t *vblank_refcount;      /* number of users of vblank interrupts per crtc */
898         u32 *last_vblank;               /* protected by dev->vbl_lock, used */
899                                         /* for wraparound handling */
900         u32 *vblank_offset;             /* used to track how many vblanks */
901         int *vblank_enabled;            /* so we don't call enable more than
902                                            once per disable */
903         u32 *vblank_premodeset;         /*  were lost during modeset */
904         struct timer_list vblank_disable_timer;
905
906         unsigned long max_vblank_count; /**< size of vblank counter register */
907         spinlock_t tasklet_lock;        /**< For drm_locked_tasklet */
908         void (*locked_tasklet_func)(struct drm_device *dev);
909
910         /*@} */
911         cycles_t ctx_start;
912         cycles_t lck_start;
913
914         struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
915         wait_queue_head_t buf_readers;  /**< Processes waiting to read */
916         wait_queue_head_t buf_writers;  /**< Processes waiting to ctx switch */
917
918         struct drm_agp_head *agp;               /**< AGP data */
919
920         struct pci_dev *pdev;           /**< PCI device structure */
921         int pci_vendor;                 /**< PCI vendor id */
922         int pci_device;                 /**< PCI device id */
923 #ifdef __alpha__
924         struct pci_controller *hose;
925 #endif
926         int num_crtcs;                  /**< Number of CRTCs on this device */
927         struct drm_sg_mem *sg;          /**< Scatter gather memory */
928         void *dev_private;              /**< device private data */
929         struct drm_sigdata sigdata;             /**< For block_all_signals */
930         sigset_t sigmask;
931
932         struct drm_driver *driver;
933         drm_local_map_t *agp_buffer_map;
934         unsigned int agp_buffer_token;
935
936         /* minor number for control node */
937         struct drm_minor *control;
938         struct drm_minor *primary;              /**< render type primary screen head */
939
940         struct drm_fence_manager fm;
941         struct drm_buffer_manager bm;
942
943         /** \name Drawable information */
944         /*@{ */
945         spinlock_t drw_lock;
946         struct idr drw_idr;
947         /*@} */
948
949         /* DRM mode setting */
950         struct drm_mode_config mode_config;
951 };
952
953 #if __OS_HAS_AGP
954 struct drm_agp_ttm_backend {
955         struct drm_ttm_backend backend;
956         DRM_AGP_MEM *mem;
957         struct agp_bridge_data *bridge;
958         int populated;
959 };
960 #endif
961
962 typedef struct ati_pcigart_ttm_backend {
963         struct drm_ttm_backend backend;
964         int populated;
965         void (*gart_flush_fn)(struct drm_device *dev);
966         struct drm_ati_pcigart_info *gart_info;
967         unsigned long offset;
968         struct page **pages;
969         int num_pages;
970         int bound;
971         struct drm_device *dev;
972 } ati_pcigart_ttm_backend_t;
973
974 static __inline__ int drm_core_check_feature(struct drm_device *dev,
975                                              int feature)
976 {
977         return ((dev->driver->driver_features & feature) ? 1 : 0);
978 }
979
980 #ifdef __alpha__
981 #define drm_get_pci_domain(dev) dev->hose->index
982 #else
983 #define drm_get_pci_domain(dev) 0
984 #endif
985
986 #if __OS_HAS_AGP
987 static inline int drm_core_has_AGP(struct drm_device *dev)
988 {
989         return drm_core_check_feature(dev, DRIVER_USE_AGP);
990 }
991 #else
992 #define drm_core_has_AGP(dev) (0)
993 #endif
994
995 #if __OS_HAS_MTRR
996 static inline int drm_core_has_MTRR(struct drm_device *dev)
997 {
998         return drm_core_check_feature(dev, DRIVER_USE_MTRR);
999 }
1000
1001 #define DRM_MTRR_WC             MTRR_TYPE_WRCOMB
1002
1003 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1004                                unsigned int flags)
1005 {
1006         return mtrr_add(offset, size, flags, 1);
1007 }
1008
1009 static inline int drm_mtrr_del(int handle, unsigned long offset,
1010                                unsigned long size, unsigned int flags)
1011 {
1012         return mtrr_del(handle, offset, size);
1013 }
1014
1015 #else
1016 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1017                                unsigned int flags)
1018 {
1019         return -ENODEV;
1020 }
1021
1022 static inline int drm_mtrr_del(int handle, unsigned long offset,
1023                                unsigned long size, unsigned int flags)
1024 {
1025         return -ENODEV;
1026 }
1027
1028 #define drm_core_has_MTRR(dev) (0)
1029 #define DRM_MTRR_WC             0
1030 #endif
1031
1032
1033 /******************************************************************/
1034 /** \name Internal function definitions */
1035 /*@{*/
1036
1037                                 /* Driver support (drm_drv.h) */
1038 extern int drm_fb_loaded;
1039 extern int drm_init(struct drm_driver *driver,
1040                               struct pci_device_id *pciidlist);
1041 extern void drm_exit(struct drm_driver *driver);
1042 extern void drm_cleanup_pci(struct pci_dev *pdev);
1043 extern int drm_ioctl(struct inode *inode, struct file *filp,
1044                      unsigned int cmd, unsigned long arg);
1045 extern long drm_unlocked_ioctl(struct file *filp,
1046                                unsigned int cmd, unsigned long arg);
1047 extern long drm_compat_ioctl(struct file *filp,
1048                              unsigned int cmd, unsigned long arg);
1049
1050 extern int drm_lastclose(struct drm_device *dev);
1051
1052                                 /* Device support (drm_fops.h) */
1053 extern int drm_open(struct inode *inode, struct file *filp);
1054 extern int drm_stub_open(struct inode *inode, struct file *filp);
1055 extern int drm_fasync(int fd, struct file *filp, int on);
1056 extern int drm_release(struct inode *inode, struct file *filp);
1057 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1058
1059                                 /* Mapping support (drm_vm.h) */
1060 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1061 extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
1062 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1063 extern pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma);
1064
1065                                 /* Memory management support (drm_memory.h) */
1066 #include "drm_memory.h"
1067 extern void drm_mem_init(void);
1068 extern int drm_mem_info(char *buf, char **start, off_t offset,
1069                         int request, int *eof, void *data);
1070 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1071 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
1072 extern unsigned long drm_alloc_pages(int order, int area);
1073 extern void drm_free_pages(unsigned long address, int order, int area);
1074 extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
1075 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
1076 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1077 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1078
1079 extern void drm_free_memctl(size_t size);
1080 extern int drm_alloc_memctl(size_t size);
1081 extern void drm_query_memctl(uint64_t *cur_used,
1082                              uint64_t *emer_used,
1083                              uint64_t *low_threshold,
1084                              uint64_t *high_threshold,
1085                              uint64_t *emer_threshold);
1086 extern void drm_init_memctl(size_t low_threshold,
1087                             size_t high_threshold,
1088                             size_t unit_size);
1089
1090                                 /* Misc. IOCTL support (drm_ioctl.h) */
1091 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1092                             struct drm_file *file_priv);
1093 extern int drm_getunique(struct drm_device *dev, void *data,
1094                          struct drm_file *file_priv);
1095 extern int drm_setunique(struct drm_device *dev, void *data,
1096                          struct drm_file *file_priv);
1097 extern int drm_getmap(struct drm_device *dev, void *data,
1098                       struct drm_file *file_priv);
1099 extern int drm_getclient(struct drm_device *dev, void *data,
1100                          struct drm_file *file_priv);
1101 extern int drm_getstats(struct drm_device *dev, void *data,
1102                         struct drm_file *file_priv);
1103 extern int drm_setversion(struct drm_device *dev, void *data,
1104                           struct drm_file *file_priv);
1105 extern int drm_noop(struct drm_device *dev, void *data,
1106                     struct drm_file *file_priv);
1107
1108                                 /* Context IOCTL support (drm_context.h) */
1109 extern int drm_resctx(struct drm_device *dev, void *data,
1110                       struct drm_file *file_priv);
1111 extern int drm_addctx(struct drm_device *dev, void *data,
1112                       struct drm_file *file_priv);
1113 extern int drm_modctx(struct drm_device *dev, void *data,
1114                       struct drm_file *file_priv);
1115 extern int drm_getctx(struct drm_device *dev, void *data,
1116                       struct drm_file *file_priv);
1117 extern int drm_switchctx(struct drm_device *dev, void *data,
1118                          struct drm_file *file_priv);
1119 extern int drm_newctx(struct drm_device *dev, void *data,
1120                       struct drm_file *file_priv);
1121 extern int drm_rmctx(struct drm_device *dev, void *data,
1122                      struct drm_file *file_priv);
1123
1124 extern int drm_ctxbitmap_init(struct drm_device *dev);
1125 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1126 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1127
1128 extern int drm_setsareactx(struct drm_device *dev, void *data,
1129                            struct drm_file *file_priv);
1130 extern int drm_getsareactx(struct drm_device *dev, void *data,
1131                            struct drm_file *file_priv);
1132
1133                                 /* Drawable IOCTL support (drm_drawable.h) */
1134 extern int drm_adddraw(struct drm_device *dev, void *data,
1135                        struct drm_file *file_priv);
1136 extern int drm_rmdraw(struct drm_device *dev, void *data,
1137                       struct drm_file *file_priv);
1138 extern int drm_update_drawable_info(struct drm_device *dev, void *data,
1139                                     struct drm_file *file_priv);
1140 extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1141                                                        drm_drawable_t id);
1142 extern void drm_drawable_free_all(struct drm_device *dev);
1143
1144                                 /* Authentication IOCTL support (drm_auth.h) */
1145 extern int drm_getmagic(struct drm_device *dev, void *data,
1146                         struct drm_file *file_priv);
1147 extern int drm_authmagic(struct drm_device *dev, void *data,
1148                          struct drm_file *file_priv);
1149
1150                                 /* Locking IOCTL support (drm_lock.h) */
1151 extern int drm_lock(struct drm_device *dev, void *data,
1152                     struct drm_file *file_priv);
1153 extern int drm_unlock(struct drm_device *dev, void *data,
1154                       struct drm_file *file_priv);
1155 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1156 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1157 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1158 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1159
1160 /*
1161  * These are exported to drivers so that they can implement fencing using
1162  * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1163  */
1164
1165 extern int drm_i_have_hw_lock(struct drm_device *dev,
1166                               struct drm_file *file_priv);
1167
1168                                 /* Buffer management support (drm_bufs.h) */
1169 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1170 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1171 extern int drm_addbufs_fb (struct drm_device *dev, struct drm_buf_desc * request);
1172 extern int drm_addmap(struct drm_device *dev, unsigned int offset,
1173                       unsigned int size, enum drm_map_type type,
1174                       enum drm_map_flags flags, drm_local_map_t ** map_ptr);
1175 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1176                             struct drm_file *file_priv);
1177 extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1178 extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
1179 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1180                            struct drm_file *file_priv);
1181 extern int drm_addbufs(struct drm_device *dev, void *data,
1182                        struct drm_file *file_priv);
1183 extern int drm_infobufs(struct drm_device *dev, void *data,
1184                         struct drm_file *file_priv);
1185 extern int drm_markbufs(struct drm_device *dev, void *data,
1186                         struct drm_file *file_priv);
1187 extern int drm_freebufs(struct drm_device *dev, void *data,
1188                         struct drm_file *file_priv);
1189 extern int drm_mapbufs(struct drm_device *dev, void *data,
1190                        struct drm_file *file_priv);
1191 extern int drm_order(unsigned long size);
1192 extern unsigned long drm_get_resource_start(struct drm_device *dev,
1193                                             unsigned int resource);
1194 extern unsigned long drm_get_resource_len(struct drm_device *dev,
1195                                           unsigned int resource);
1196 extern struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
1197                                                   drm_local_map_t *map);
1198
1199
1200                                 /* DMA support (drm_dma.h) */
1201 extern int drm_dma_setup(struct drm_device *dev);
1202 extern void drm_dma_takedown(struct drm_device *dev);
1203 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1204 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1205                                      struct drm_file *filp);
1206
1207                                 /* IRQ support (drm_irq.h) */
1208 extern int drm_control(struct drm_device *dev, void *data,
1209                        struct drm_file *file_priv);
1210 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1211 extern int drm_irq_install(struct drm_device *dev);
1212 extern int drm_irq_uninstall(struct drm_device *dev);
1213 extern void drm_driver_irq_preinstall(struct drm_device *dev);
1214 extern void drm_driver_irq_postinstall(struct drm_device *dev);
1215 extern void drm_driver_irq_uninstall(struct drm_device *dev);
1216
1217 extern int drm_hotplug_init(struct drm_device *dev);
1218 extern int drm_wait_hotplug(struct drm_device *dev, void *data, struct drm_file *filp);
1219 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1220 extern int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *filp);
1221 extern int drm_wait_hotplug(struct drm_device *dev, void *data, struct drm_file *filp);
1222 extern int drm_vblank_wait(struct drm_device * dev, unsigned int *vbl_seq);
1223 extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
1224 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1225 extern void drm_update_vblank_count(struct drm_device *dev, int crtc);
1226 extern void drm_handle_vblank(struct drm_device *dev, int crtc);
1227 extern void drm_handle_hotplug(struct drm_device *dev);
1228 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1229 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1230
1231                                 /* Modesetting support */
1232 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1233                            struct drm_file *file_priv);
1234
1235                                 /* AGP/GART support (drm_agpsupport.h) */
1236 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1237 extern int drm_agp_acquire(struct drm_device *dev);
1238 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1239                                  struct drm_file *file_priv);
1240 extern int drm_agp_release(struct drm_device *dev);
1241 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1242                                  struct drm_file *file_priv);
1243 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1244 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1245                                 struct drm_file *file_priv);
1246 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1247 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1248                         struct drm_file *file_priv);
1249 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1250 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1251                          struct drm_file *file_priv);
1252 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1253 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1254                         struct drm_file *file_priv);
1255 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1256 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1257                           struct drm_file *file_priv);
1258 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1259 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1260                         struct drm_file *file_priv);
1261 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
1262 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
1263 #else
1264 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1265 #endif
1266 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1267 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1268 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1269 extern struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev);
1270 extern void drm_agp_chipset_flush(struct drm_device *dev);
1271                                 /* Stub support (drm_stub.h) */
1272 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1273                                struct drm_file *file_priv);
1274 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1275                                 struct drm_file *file_priv);
1276 extern struct drm_master *drm_get_master(struct drm_minor *minor);
1277 extern void drm_put_master(struct drm_master *master);
1278 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1279                      struct drm_driver *driver);
1280 extern int drm_put_dev(struct drm_device *dev);
1281 extern int drm_put_minor(struct drm_minor **minor);
1282 extern unsigned int drm_debug; /* 1 to enable debug output */
1283
1284 extern struct class *drm_class;
1285 extern struct proc_dir_entry *drm_proc_root;
1286
1287 extern struct idr drm_minors_idr;
1288
1289 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1290
1291                                 /* Proc support (drm_proc.h) */
1292 int drm_proc_init(struct drm_minor *minor, int minor_id,
1293                   struct proc_dir_entry *root);
1294 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1295
1296                                 /* Scatter Gather Support (drm_scatter.h) */
1297 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1298 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1299                         struct drm_file *file_priv);
1300 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1301 extern int drm_sg_free(struct drm_device *dev, void *data,
1302                        struct drm_file *file_priv);
1303
1304                                /* ATI PCIGART support (ati_pcigart.h) */
1305 extern int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1306 extern int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1307
1308 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1309                            size_t align, dma_addr_t maxaddr);
1310 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1311 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1312
1313                                /* sysfs support (drm_sysfs.c) */
1314 struct drm_sysfs_class;
1315 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1316 extern void drm_sysfs_destroy(void);
1317 extern int drm_sysfs_device_add(struct drm_minor *minor);
1318 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1319 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1320 extern char *drm_get_connector_status_name(enum drm_connector_status status);
1321 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1322 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1323
1324 /*
1325  * Basic memory manager support (drm_mm.c)
1326  */
1327
1328 extern struct drm_mm_node * drm_mm_get_block(struct drm_mm_node * parent, unsigned long size,
1329                                                unsigned alignment);
1330 extern void drm_mm_put_block(struct drm_mm_node *cur);
1331 extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
1332                                                 unsigned alignment, int best_match);
1333 extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
1334 extern void drm_mm_takedown(struct drm_mm *mm);
1335 extern int drm_mm_clean(struct drm_mm *mm);
1336 extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
1337 extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
1338 extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
1339 extern void drm_mm_print(struct drm_mm *mm, const char *name);
1340
1341 static inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
1342 {
1343         return block->mm;
1344 }
1345
1346 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1347 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1348
1349 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1350                                                    unsigned int token)
1351 {
1352         struct drm_map_list *_entry;
1353         list_for_each_entry(_entry, &dev->maplist, head)
1354                 if (_entry->user_token == token)
1355                         return _entry->map;
1356         return NULL;
1357 }
1358
1359 static __inline__ int drm_device_is_agp(struct drm_device *dev)
1360 {
1361         if ( dev->driver->device_is_agp != NULL ) {
1362                 int err = (*dev->driver->device_is_agp)(dev);
1363
1364                 if (err != 2) {
1365                         return err;
1366                 }
1367         }
1368
1369         return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1370 }
1371
1372 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1373 {
1374         return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1375 }
1376
1377 static __inline__ void drm_core_dropmap(struct drm_map *map)
1378 {
1379 }
1380
1381 #ifndef DEBUG_MEMORY
1382 /** Wrapper around kmalloc() */
1383 static __inline__ void *drm_alloc(size_t size, int area)
1384 {
1385         return kmalloc(size, GFP_KERNEL);
1386 }
1387
1388 /** Wrapper around kfree() */
1389 static __inline__ void drm_free(void *pt, size_t size, int area)
1390 {
1391         kfree(pt);
1392 }
1393 #else
1394 extern void *drm_alloc(size_t size, int area);
1395 extern void drm_free(void *pt, size_t size, int area);
1396 #endif
1397
1398 /*
1399  * Accounting variants of standard calls.
1400  */
1401
1402 static inline void *drm_ctl_alloc(size_t size, int area)
1403 {
1404         void *ret;
1405         if (drm_alloc_memctl(size))
1406                 return NULL;
1407         ret = drm_alloc(size, area);
1408         if (!ret)
1409                 drm_free_memctl(size);
1410         return ret;
1411 }
1412
1413 static inline void *drm_ctl_calloc(size_t nmemb, size_t size, int area)
1414 {
1415         void *ret;
1416
1417         if (drm_alloc_memctl(nmemb*size))
1418                 return NULL;
1419         ret = drm_calloc(nmemb, size, area);
1420         if (!ret)
1421                 drm_free_memctl(nmemb*size);
1422         return ret;
1423 }
1424
1425 static inline void drm_ctl_free(void *pt, size_t size, int area)
1426 {
1427         drm_free(pt, size, area);
1428         drm_free_memctl(size);
1429 }
1430
1431 /*@}*/
1432
1433 #endif                          /* __KERNEL__ */
1434 #endif