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