Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / char / drm / drmP.h
blobc5200d165763336c508f8815f1ef92dc5f5ae6d8
1 /**
2 * \file drmP.h
3 * Private header for Direct Rendering Manager
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
7 */
9 /*
10 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
11 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
12 * All rights reserved.
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:
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.
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.
34 #ifndef _DRM_P_H_
35 #define _DRM_P_H_
37 /* If you want the memory alloc debug functionality, change define below */
38 /* #define DEBUG_MEMORY */
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 <<<<<<< HEAD:drivers/char/drm/drmP.h
58 =======
59 #include <linux/dma-mapping.h>
60 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/drmP.h
61 #include <linux/mm.h>
62 #include <linux/cdev.h>
63 #include <linux/mutex.h>
64 #if defined(__alpha__) || defined(__powerpc__)
65 #include <asm/pgtable.h> /* For pte_wrprotect */
66 #endif
67 #include <asm/io.h>
68 #include <asm/mman.h>
69 #include <asm/uaccess.h>
70 #ifdef CONFIG_MTRR
71 #include <asm/mtrr.h>
72 #endif
73 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
74 #include <linux/types.h>
75 #include <linux/agp_backend.h>
76 #endif
77 #include <linux/workqueue.h>
78 #include <linux/poll.h>
79 #include <asm/pgalloc.h>
80 #include "drm.h"
82 #include <linux/idr.h>
84 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
85 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
87 struct drm_file;
88 struct drm_device;
90 #include "drm_os_linux.h"
91 #include "drm_hashtab.h"
93 /***********************************************************************/
94 /** \name DRM template customization defaults */
95 /*@{*/
97 /* driver capabilities and requirements mask */
98 #define DRIVER_USE_AGP 0x1
99 #define DRIVER_REQUIRE_AGP 0x2
100 #define DRIVER_USE_MTRR 0x4
101 #define DRIVER_PCI_DMA 0x8
102 #define DRIVER_SG 0x10
103 #define DRIVER_HAVE_DMA 0x20
104 #define DRIVER_HAVE_IRQ 0x40
105 #define DRIVER_IRQ_SHARED 0x80
106 #define DRIVER_IRQ_VBL 0x100
107 #define DRIVER_DMA_QUEUE 0x200
108 #define DRIVER_FB_DMA 0x400
109 #define DRIVER_IRQ_VBL2 0x800
111 /***********************************************************************/
112 /** \name Begin the DRM... */
113 /*@{*/
115 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
116 also include looping detection. */
118 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
119 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
120 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
121 #define DRM_LOOPING_LIMIT 5000000
122 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
123 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
125 #define DRM_FLAG_DEBUG 0x01
127 #define DRM_MEM_DMA 0
128 #define DRM_MEM_SAREA 1
129 #define DRM_MEM_DRIVER 2
130 #define DRM_MEM_MAGIC 3
131 #define DRM_MEM_IOCTLS 4
132 #define DRM_MEM_MAPS 5
133 #define DRM_MEM_VMAS 6
134 #define DRM_MEM_BUFS 7
135 #define DRM_MEM_SEGS 8
136 #define DRM_MEM_PAGES 9
137 #define DRM_MEM_FILES 10
138 #define DRM_MEM_QUEUES 11
139 #define DRM_MEM_CMDS 12
140 #define DRM_MEM_MAPPINGS 13
141 #define DRM_MEM_BUFLISTS 14
142 #define DRM_MEM_AGPLISTS 15
143 #define DRM_MEM_TOTALAGP 16
144 #define DRM_MEM_BOUNDAGP 17
145 #define DRM_MEM_CTXBITMAP 18
146 #define DRM_MEM_STUB 19
147 #define DRM_MEM_SGLISTS 20
148 #define DRM_MEM_CTXLIST 21
149 #define DRM_MEM_MM 22
150 #define DRM_MEM_HASHTAB 23
152 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
153 #define DRM_MAP_HASH_OFFSET 0x10000000
155 /*@}*/
157 /***********************************************************************/
158 /** \name Macros to make printk easier */
159 /*@{*/
162 * Error output.
164 * \param fmt printf() like format string.
165 * \param arg arguments
167 #define DRM_ERROR(fmt, arg...) \
168 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
171 * Memory error output.
173 * \param area memory area where the error occurred.
174 * \param fmt printf() like format string.
175 * \param arg arguments
177 #define DRM_MEM_ERROR(area, fmt, arg...) \
178 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
179 drm_mem_stats[area].name , ##arg)
181 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
184 * Debug output.
186 * \param fmt printf() like format string.
187 * \param arg arguments
189 #if DRM_DEBUG_CODE
190 #define DRM_DEBUG(fmt, arg...) \
191 do { \
192 if ( drm_debug ) \
193 printk(KERN_DEBUG \
194 "[" DRM_NAME ":%s] " fmt , \
195 __FUNCTION__ , ##arg); \
196 } while (0)
197 #else
198 #define DRM_DEBUG(fmt, arg...) do { } while (0)
199 #endif
201 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
203 #define DRM_PROC_PRINT(fmt, arg...) \
204 len += sprintf(&buf[len], fmt , ##arg); \
205 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
207 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
208 len += sprintf(&buf[len], fmt , ##arg); \
209 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
211 /*@}*/
213 /***********************************************************************/
214 /** \name Internal types and structures */
215 /*@{*/
217 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
219 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
220 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
221 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
223 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
225 * Get the private SAREA mapping.
227 * \param _dev DRM device.
228 * \param _ctx context number.
229 * \param _map output mapping.
231 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
232 (_map) = (_dev)->context_sareas[_ctx]; \
233 } while(0)
236 * Test that the hardware lock is held by the caller, returning otherwise.
238 * \param dev DRM device.
239 * \param filp file pointer of the caller.
241 #define LOCK_TEST_WITH_RETURN( dev, file_priv ) \
242 do { \
243 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
244 dev->lock.file_priv != file_priv ) { \
245 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
246 __FUNCTION__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
247 dev->lock.file_priv, file_priv ); \
248 return -EINVAL; \
250 } while (0)
253 * Copy and IOCTL return string to user space
255 #define DRM_COPY( name, value ) \
256 len = strlen( value ); \
257 if ( len > name##_len ) len = name##_len; \
258 name##_len = strlen( value ); \
259 if ( len && name ) { \
260 if ( copy_to_user( name, value, len ) ) \
261 return -EFAULT; \
265 * Ioctl function type.
267 * \param inode device inode.
268 * \param file_priv DRM file private pointer.
269 * \param cmd command.
270 * \param arg argument.
272 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
273 struct drm_file *file_priv);
275 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
276 unsigned long arg);
278 #define DRM_AUTH 0x1
279 #define DRM_MASTER 0x2
280 #define DRM_ROOT_ONLY 0x4
282 struct drm_ioctl_desc {
283 unsigned int cmd;
284 drm_ioctl_t *func;
285 int flags;
289 * Creates a driver or general drm_ioctl_desc array entry for the given
290 * ioctl, for use by drm_ioctl().
292 #define DRM_IOCTL_DEF(ioctl, func, flags) \
293 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
295 struct drm_magic_entry {
296 struct list_head head;
297 struct drm_hash_item hash_item;
298 struct drm_file *priv;
301 struct drm_vma_entry {
302 struct list_head head;
303 struct vm_area_struct *vma;
304 pid_t pid;
308 * DMA buffer.
310 struct drm_buf {
311 int idx; /**< Index into master buflist */
312 int total; /**< Buffer size */
313 int order; /**< log-base-2(total) */
314 int used; /**< Amount of buffer in use (for DMA) */
315 unsigned long offset; /**< Byte offset (used internally) */
316 void *address; /**< Address of buffer */
317 unsigned long bus_address; /**< Bus address of buffer */
318 struct drm_buf *next; /**< Kernel-only: used for free list */
319 __volatile__ int waiting; /**< On kernel DMA queue */
320 __volatile__ int pending; /**< On hardware DMA queue */
321 wait_queue_head_t dma_wait; /**< Processes waiting */
322 struct drm_file *file_priv; /**< Private of holding file descr */
323 int context; /**< Kernel queue for this buffer */
324 int while_locked; /**< Dispatch this buffer while locked */
325 enum {
326 DRM_LIST_NONE = 0,
327 DRM_LIST_FREE = 1,
328 DRM_LIST_WAIT = 2,
329 DRM_LIST_PEND = 3,
330 DRM_LIST_PRIO = 4,
331 DRM_LIST_RECLAIM = 5
332 } list; /**< Which list we're on */
334 int dev_priv_size; /**< Size of buffer private storage */
335 void *dev_private; /**< Per-buffer private storage */
338 /** bufs is one longer than it has to be */
339 struct drm_waitlist {
340 int count; /**< Number of possible buffers */
341 struct drm_buf **bufs; /**< List of pointers to buffers */
342 struct drm_buf **rp; /**< Read pointer */
343 struct drm_buf **wp; /**< Write pointer */
344 struct drm_buf **end; /**< End pointer */
345 spinlock_t read_lock;
346 spinlock_t write_lock;
349 struct drm_freelist {
350 int initialized; /**< Freelist in use */
351 atomic_t count; /**< Number of free buffers */
352 struct drm_buf *next; /**< End pointer */
354 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
355 int low_mark; /**< Low water mark */
356 int high_mark; /**< High water mark */
357 atomic_t wfh; /**< If waiting for high mark */
358 spinlock_t lock;
361 typedef struct drm_dma_handle {
362 dma_addr_t busaddr;
363 void *vaddr;
364 size_t size;
365 } drm_dma_handle_t;
368 * Buffer entry. There is one of this for each buffer size order.
370 struct drm_buf_entry {
371 int buf_size; /**< size */
372 int buf_count; /**< number of buffers */
373 struct drm_buf *buflist; /**< buffer list */
374 int seg_count;
375 int page_order;
376 struct drm_dma_handle **seglist;
378 struct drm_freelist freelist;
381 /** File private data */
382 struct drm_file {
383 int authenticated;
384 int master;
385 int minor;
386 pid_t pid;
387 uid_t uid;
388 drm_magic_t magic;
389 unsigned long ioctl_count;
390 struct list_head lhead;
391 struct drm_head *head;
392 int remove_auth_on_close;
393 unsigned long lock_count;
394 struct file *filp;
395 void *driver_priv;
398 /** Wait queue */
399 struct drm_queue {
400 atomic_t use_count; /**< Outstanding uses (+1) */
401 atomic_t finalization; /**< Finalization in progress */
402 atomic_t block_count; /**< Count of processes waiting */
403 atomic_t block_read; /**< Queue blocked for reads */
404 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
405 atomic_t block_write; /**< Queue blocked for writes */
406 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
407 atomic_t total_queued; /**< Total queued statistic */
408 atomic_t total_flushed; /**< Total flushes statistic */
409 atomic_t total_locks; /**< Total locks statistics */
410 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
411 struct drm_waitlist waitlist; /**< Pending buffers */
412 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
416 * Lock data.
418 struct drm_lock_data {
419 struct drm_hw_lock *hw_lock; /**< Hardware lock */
420 /** Private of lock holder's file (NULL=kernel) */
421 struct drm_file *file_priv;
422 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
423 unsigned long lock_time; /**< Time of last lock in jiffies */
424 spinlock_t spinlock;
425 uint32_t kernel_waiters;
426 uint32_t user_waiters;
427 int idle_has_lock;
431 * DMA data.
433 struct drm_device_dma {
435 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
436 int buf_count; /**< total number of buffers */
437 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
438 int seg_count;
439 int page_count; /**< number of pages */
440 unsigned long *pagelist; /**< page list */
441 unsigned long byte_count;
442 enum {
443 _DRM_DMA_USE_AGP = 0x01,
444 _DRM_DMA_USE_SG = 0x02,
445 _DRM_DMA_USE_FB = 0x04,
446 _DRM_DMA_USE_PCI_RO = 0x08
447 } flags;
452 * AGP memory entry. Stored as a doubly linked list.
454 struct drm_agp_mem {
455 unsigned long handle; /**< handle */
456 DRM_AGP_MEM *memory;
457 unsigned long bound; /**< address */
458 int pages;
459 struct list_head head;
463 * AGP data.
465 * \sa drm_agp_init() and drm_device::agp.
467 struct drm_agp_head {
468 DRM_AGP_KERN agp_info; /**< AGP device information */
469 struct list_head memory;
470 unsigned long mode; /**< AGP mode */
471 struct agp_bridge_data *bridge;
472 int enabled; /**< whether the AGP bus as been enabled */
473 int acquired; /**< whether the AGP device has been acquired */
474 unsigned long base;
475 int agp_mtrr;
476 int cant_use_aperture;
477 unsigned long page_mask;
481 * Scatter-gather memory.
483 struct drm_sg_mem {
484 unsigned long handle;
485 void *virtual;
486 int pages;
487 struct page **pagelist;
488 dma_addr_t *busaddr;
491 struct drm_sigdata {
492 int context;
493 struct drm_hw_lock *lock;
498 * Generic memory manager structs
501 struct drm_mm_node {
502 struct list_head fl_entry;
503 struct list_head ml_entry;
504 int free;
505 unsigned long start;
506 unsigned long size;
507 struct drm_mm *mm;
508 void *private;
511 struct drm_mm {
512 struct list_head fl_entry;
513 struct list_head ml_entry;
518 * Mappings list
520 struct drm_map_list {
521 struct list_head head; /**< list head */
522 struct drm_hash_item hash;
523 struct drm_map *map; /**< mapping */
524 uint64_t user_token;
527 typedef struct drm_map drm_local_map_t;
530 * Context handle list
532 struct drm_ctx_list {
533 struct list_head head; /**< list head */
534 drm_context_t handle; /**< context handle */
535 struct drm_file *tag; /**< associated fd private data */
538 struct drm_vbl_sig {
539 struct list_head head;
540 unsigned int sequence;
541 struct siginfo info;
542 struct task_struct *task;
545 /* location of GART table */
546 #define DRM_ATI_GART_MAIN 1
547 #define DRM_ATI_GART_FB 2
549 #define DRM_ATI_GART_PCI 1
550 #define DRM_ATI_GART_PCIE 2
551 #define DRM_ATI_GART_IGP 3
553 struct drm_ati_pcigart_info {
554 int gart_table_location;
555 int gart_reg_if;
556 void *addr;
557 dma_addr_t bus_addr;
558 <<<<<<< HEAD:drivers/char/drm/drmP.h
559 =======
560 dma_addr_t table_mask;
561 struct drm_dma_handle *table_handle;
562 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/drmP.h
563 drm_local_map_t mapping;
564 int table_size;
568 * DRM driver structure. This structure represent the common code for
569 * a family of cards. There will one drm_device for each card present
570 * in this family
572 struct drm_driver {
573 int (*load) (struct drm_device *, unsigned long flags);
574 int (*firstopen) (struct drm_device *);
575 int (*open) (struct drm_device *, struct drm_file *);
576 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
577 void (*postclose) (struct drm_device *, struct drm_file *);
578 void (*lastclose) (struct drm_device *);
579 int (*unload) (struct drm_device *);
580 <<<<<<< HEAD:drivers/char/drm/drmP.h
581 int (*suspend) (struct drm_device *);
582 =======
583 int (*suspend) (struct drm_device *, pm_message_t state);
584 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/drmP.h
585 int (*resume) (struct drm_device *);
586 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
587 void (*dma_ready) (struct drm_device *);
588 int (*dma_quiescent) (struct drm_device *);
589 int (*context_ctor) (struct drm_device *dev, int context);
590 int (*context_dtor) (struct drm_device *dev, int context);
591 int (*kernel_context_switch) (struct drm_device *dev, int old,
592 int new);
593 void (*kernel_context_switch_unlock) (struct drm_device *dev);
594 int (*vblank_wait) (struct drm_device *dev, unsigned int *sequence);
595 int (*vblank_wait2) (struct drm_device *dev, unsigned int *sequence);
596 int (*dri_library_name) (struct drm_device *dev, char *buf);
599 * Called by \c drm_device_is_agp. Typically used to determine if a
600 * card is really attached to AGP or not.
602 * \param dev DRM device handle
604 * \returns
605 * One of three values is returned depending on whether or not the
606 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
607 * (return of 1), or may or may not be AGP (return of 2).
609 int (*device_is_agp) (struct drm_device *dev);
611 /* these have to be filled in */
613 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
614 void (*irq_preinstall) (struct drm_device *dev);
615 void (*irq_postinstall) (struct drm_device *dev);
616 void (*irq_uninstall) (struct drm_device *dev);
617 void (*reclaim_buffers) (struct drm_device *dev,
618 struct drm_file * file_priv);
619 void (*reclaim_buffers_locked) (struct drm_device *dev,
620 struct drm_file *file_priv);
621 void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
622 struct drm_file *file_priv);
623 unsigned long (*get_map_ofs) (struct drm_map * map);
624 unsigned long (*get_reg_ofs) (struct drm_device *dev);
625 void (*set_version) (struct drm_device *dev,
626 struct drm_set_version *sv);
628 int major;
629 int minor;
630 int patchlevel;
631 char *name;
632 char *desc;
633 char *date;
635 u32 driver_features;
636 int dev_priv_size;
637 struct drm_ioctl_desc *ioctls;
638 int num_ioctls;
639 struct file_operations fops;
640 struct pci_driver pci_driver;
644 * DRM head structure. This structure represent a video head on a card
645 * that may contain multiple heads. Embed one per head of these in the
646 * private drm_device structure.
648 struct drm_head {
649 int minor; /**< Minor device number */
650 struct drm_device *dev;
651 struct proc_dir_entry *dev_root; /**< proc directory entry */
652 dev_t device; /**< Device number for mknod */
653 struct class_device *dev_class;
657 * DRM device structure. This structure represent a complete card that
658 * may contain multiple heads.
660 struct drm_device {
661 struct device dev; /**< Linux device */
662 char *unique; /**< Unique identifier: e.g., busid */
663 int unique_len; /**< Length of unique field */
664 char *devname; /**< For /proc/interrupts */
665 int if_version; /**< Highest interface version set */
667 int blocked; /**< Blocked due to VC switch? */
669 /** \name Locks */
670 /*@{ */
671 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
672 struct mutex struct_mutex; /**< For others */
673 /*@} */
675 /** \name Usage Counters */
676 /*@{ */
677 int open_count; /**< Outstanding files open */
678 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
679 atomic_t vma_count; /**< Outstanding vma areas open */
680 int buf_use; /**< Buffers in use -- cannot alloc */
681 atomic_t buf_alloc; /**< Buffer allocation in progress */
682 /*@} */
684 /** \name Performance counters */
685 /*@{ */
686 unsigned long counters;
687 enum drm_stat_type types[15];
688 atomic_t counts[15];
689 /*@} */
691 /** \name Authentication */
692 /*@{ */
693 struct list_head filelist;
694 struct drm_open_hash magiclist; /**< magic hash table */
695 struct list_head magicfree;
696 /*@} */
698 /** \name Memory management */
699 /*@{ */
700 struct list_head maplist; /**< Linked list of regions */
701 int map_count; /**< Number of mappable regions */
702 struct drm_open_hash map_hash; /**< User token hash table for maps */
704 /** \name Context handle management */
705 /*@{ */
706 struct list_head ctxlist; /**< Linked list of context handles */
707 int ctx_count; /**< Number of context handles */
708 struct mutex ctxlist_mutex; /**< For ctxlist */
710 struct idr ctx_idr;
712 struct list_head vmalist; /**< List of vmas (for debugging) */
713 struct drm_lock_data lock; /**< Information on hardware lock */
714 /*@} */
716 /** \name DMA queues (contexts) */
717 /*@{ */
718 int queue_count; /**< Number of active DMA queues */
719 int queue_reserved; /**< Number of reserved DMA queues */
720 int queue_slots; /**< Actual length of queuelist */
721 struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */
722 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
723 /*@} */
725 /** \name Context support */
726 /*@{ */
727 int irq; /**< Interrupt used by board */
728 int irq_enabled; /**< True if irq handler is enabled */
729 __volatile__ long context_flag; /**< Context swapping flag */
730 __volatile__ long interrupt_flag; /**< Interruption handler flag */
731 __volatile__ long dma_flag; /**< DMA dispatch flag */
732 struct timer_list timer; /**< Timer for delaying ctx switch */
733 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
734 int last_checked; /**< Last context checked for DMA */
735 int last_context; /**< Last current context */
736 unsigned long last_switch; /**< jiffies at last context switch */
737 /*@} */
739 struct work_struct work;
740 /** \name VBLANK IRQ support */
741 /*@{ */
743 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
744 atomic_t vbl_received;
745 atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
746 spinlock_t vbl_lock;
747 struct list_head vbl_sigs; /**< signal list to send on VBLANK */
748 struct list_head vbl_sigs2; /**< signals to send on secondary VBLANK */
749 unsigned int vbl_pending;
750 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
751 void (*locked_tasklet_func)(struct drm_device *dev);
753 /*@} */
754 cycles_t ctx_start;
755 cycles_t lck_start;
757 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
758 wait_queue_head_t buf_readers; /**< Processes waiting to read */
759 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
761 struct drm_agp_head *agp; /**< AGP data */
763 struct pci_dev *pdev; /**< PCI device structure */
764 int pci_vendor; /**< PCI vendor id */
765 int pci_device; /**< PCI device id */
766 #ifdef __alpha__
767 struct pci_controller *hose;
768 #endif
769 struct drm_sg_mem *sg; /**< Scatter gather memory */
770 void *dev_private; /**< device private data */
771 struct drm_sigdata sigdata; /**< For block_all_signals */
772 sigset_t sigmask;
774 struct drm_driver *driver;
775 drm_local_map_t *agp_buffer_map;
776 unsigned int agp_buffer_token;
777 struct drm_head primary; /**< primary screen head */
779 /** \name Drawable information */
780 /*@{ */
781 spinlock_t drw_lock;
782 struct idr drw_idr;
783 /*@} */
786 static __inline__ int drm_core_check_feature(struct drm_device *dev,
787 int feature)
789 return ((dev->driver->driver_features & feature) ? 1 : 0);
792 #ifdef __alpha__
793 #define drm_get_pci_domain(dev) dev->hose->index
794 #else
795 #define drm_get_pci_domain(dev) 0
796 #endif
798 #if __OS_HAS_AGP
799 static inline int drm_core_has_AGP(struct drm_device *dev)
801 return drm_core_check_feature(dev, DRIVER_USE_AGP);
803 #else
804 #define drm_core_has_AGP(dev) (0)
805 #endif
807 #if __OS_HAS_MTRR
808 static inline int drm_core_has_MTRR(struct drm_device *dev)
810 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
813 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
815 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
816 unsigned int flags)
818 return mtrr_add(offset, size, flags, 1);
821 static inline int drm_mtrr_del(int handle, unsigned long offset,
822 unsigned long size, unsigned int flags)
824 return mtrr_del(handle, offset, size);
827 #else
828 #define drm_core_has_MTRR(dev) (0)
830 #define DRM_MTRR_WC 0
832 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
833 unsigned int flags)
835 return 0;
838 static inline int drm_mtrr_del(int handle, unsigned long offset,
839 unsigned long size, unsigned int flags)
841 return 0;
843 #endif
845 /******************************************************************/
846 /** \name Internal function definitions */
847 /*@{*/
849 /* Driver support (drm_drv.h) */
850 extern int drm_init(struct drm_driver *driver);
851 extern void drm_exit(struct drm_driver *driver);
852 extern int drm_ioctl(struct inode *inode, struct file *filp,
853 unsigned int cmd, unsigned long arg);
854 extern long drm_compat_ioctl(struct file *filp,
855 unsigned int cmd, unsigned long arg);
856 extern int drm_lastclose(struct drm_device *dev);
858 /* Device support (drm_fops.h) */
859 extern int drm_open(struct inode *inode, struct file *filp);
860 extern int drm_stub_open(struct inode *inode, struct file *filp);
861 extern int drm_fasync(int fd, struct file *filp, int on);
862 extern int drm_release(struct inode *inode, struct file *filp);
864 /* Mapping support (drm_vm.h) */
865 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
866 extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
867 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
868 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
870 /* Memory management support (drm_memory.h) */
871 #include "drm_memory.h"
872 extern void drm_mem_init(void);
873 extern int drm_mem_info(char *buf, char **start, off_t offset,
874 int request, int *eof, void *data);
875 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
877 extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
878 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
879 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
880 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
882 /* Misc. IOCTL support (drm_ioctl.h) */
883 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
884 struct drm_file *file_priv);
885 extern int drm_getunique(struct drm_device *dev, void *data,
886 struct drm_file *file_priv);
887 extern int drm_setunique(struct drm_device *dev, void *data,
888 struct drm_file *file_priv);
889 extern int drm_getmap(struct drm_device *dev, void *data,
890 struct drm_file *file_priv);
891 extern int drm_getclient(struct drm_device *dev, void *data,
892 struct drm_file *file_priv);
893 extern int drm_getstats(struct drm_device *dev, void *data,
894 struct drm_file *file_priv);
895 extern int drm_setversion(struct drm_device *dev, void *data,
896 struct drm_file *file_priv);
897 extern int drm_noop(struct drm_device *dev, void *data,
898 struct drm_file *file_priv);
900 /* Context IOCTL support (drm_context.h) */
901 extern int drm_resctx(struct drm_device *dev, void *data,
902 struct drm_file *file_priv);
903 extern int drm_addctx(struct drm_device *dev, void *data,
904 struct drm_file *file_priv);
905 extern int drm_modctx(struct drm_device *dev, void *data,
906 struct drm_file *file_priv);
907 extern int drm_getctx(struct drm_device *dev, void *data,
908 struct drm_file *file_priv);
909 extern int drm_switchctx(struct drm_device *dev, void *data,
910 struct drm_file *file_priv);
911 extern int drm_newctx(struct drm_device *dev, void *data,
912 struct drm_file *file_priv);
913 extern int drm_rmctx(struct drm_device *dev, void *data,
914 struct drm_file *file_priv);
916 extern int drm_ctxbitmap_init(struct drm_device *dev);
917 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
918 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
920 extern int drm_setsareactx(struct drm_device *dev, void *data,
921 struct drm_file *file_priv);
922 extern int drm_getsareactx(struct drm_device *dev, void *data,
923 struct drm_file *file_priv);
925 /* Drawable IOCTL support (drm_drawable.h) */
926 extern int drm_adddraw(struct drm_device *dev, void *data,
927 struct drm_file *file_priv);
928 extern int drm_rmdraw(struct drm_device *dev, void *data,
929 struct drm_file *file_priv);
930 extern int drm_update_drawable_info(struct drm_device *dev, void *data,
931 struct drm_file *file_priv);
932 extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
933 drm_drawable_t id);
934 extern void drm_drawable_free_all(struct drm_device *dev);
936 /* Authentication IOCTL support (drm_auth.h) */
937 extern int drm_getmagic(struct drm_device *dev, void *data,
938 struct drm_file *file_priv);
939 extern int drm_authmagic(struct drm_device *dev, void *data,
940 struct drm_file *file_priv);
942 /* Locking IOCTL support (drm_lock.h) */
943 extern int drm_lock(struct drm_device *dev, void *data,
944 struct drm_file *file_priv);
945 extern int drm_unlock(struct drm_device *dev, void *data,
946 struct drm_file *file_priv);
947 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
948 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
949 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
950 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
953 * These are exported to drivers so that they can implement fencing using
954 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
957 extern int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv);
959 /* Buffer management support (drm_bufs.h) */
960 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
961 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
962 extern int drm_addmap(struct drm_device *dev, unsigned int offset,
963 unsigned int size, enum drm_map_type type,
964 enum drm_map_flags flags, drm_local_map_t ** map_ptr);
965 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
966 struct drm_file *file_priv);
967 extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
968 extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
969 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
970 struct drm_file *file_priv);
971 extern int drm_addbufs(struct drm_device *dev, void *data,
972 struct drm_file *file_priv);
973 extern int drm_infobufs(struct drm_device *dev, void *data,
974 struct drm_file *file_priv);
975 extern int drm_markbufs(struct drm_device *dev, void *data,
976 struct drm_file *file_priv);
977 extern int drm_freebufs(struct drm_device *dev, void *data,
978 struct drm_file *file_priv);
979 extern int drm_mapbufs(struct drm_device *dev, void *data,
980 struct drm_file *file_priv);
981 extern int drm_order(unsigned long size);
982 extern unsigned long drm_get_resource_start(struct drm_device *dev,
983 unsigned int resource);
984 extern unsigned long drm_get_resource_len(struct drm_device *dev,
985 unsigned int resource);
987 /* DMA support (drm_dma.h) */
988 extern int drm_dma_setup(struct drm_device *dev);
989 extern void drm_dma_takedown(struct drm_device *dev);
990 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
991 extern void drm_core_reclaim_buffers(struct drm_device *dev,
992 struct drm_file *filp);
994 /* IRQ support (drm_irq.h) */
995 extern int drm_control(struct drm_device *dev, void *data,
996 struct drm_file *file_priv);
997 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
998 extern int drm_irq_uninstall(struct drm_device *dev);
999 extern void drm_driver_irq_preinstall(struct drm_device *dev);
1000 extern void drm_driver_irq_postinstall(struct drm_device *dev);
1001 extern void drm_driver_irq_uninstall(struct drm_device *dev);
1003 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1004 struct drm_file *file_priv);
1005 extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1006 extern void drm_vbl_send_signals(struct drm_device *dev);
1007 extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
1009 /* AGP/GART support (drm_agpsupport.h) */
1010 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1011 extern int drm_agp_acquire(struct drm_device *dev);
1012 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1013 struct drm_file *file_priv);
1014 extern int drm_agp_release(struct drm_device *dev);
1015 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1016 struct drm_file *file_priv);
1017 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1018 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1019 struct drm_file *file_priv);
1020 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1021 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1022 struct drm_file *file_priv);
1023 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1024 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1025 struct drm_file *file_priv);
1026 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1027 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1028 struct drm_file *file_priv);
1029 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1030 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1031 struct drm_file *file_priv);
1032 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1033 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1034 struct drm_file *file_priv);
1035 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1036 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1037 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1038 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1040 /* Stub support (drm_stub.h) */
1041 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1042 struct drm_driver *driver);
1043 extern int drm_put_dev(struct drm_device *dev);
1044 extern int drm_put_head(struct drm_head *head);
1045 extern unsigned int drm_debug;
1046 extern unsigned int drm_cards_limit;
1047 extern struct drm_head **drm_heads;
1048 extern struct class *drm_class;
1049 extern struct proc_dir_entry *drm_proc_root;
1051 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1053 /* Proc support (drm_proc.h) */
1054 extern int drm_proc_init(struct drm_device *dev,
1055 int minor,
1056 struct proc_dir_entry *root,
1057 struct proc_dir_entry **dev_root);
1058 extern int drm_proc_cleanup(int minor,
1059 struct proc_dir_entry *root,
1060 struct proc_dir_entry *dev_root);
1062 /* Scatter Gather Support (drm_scatter.h) */
1063 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1064 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1065 struct drm_file *file_priv);
1066 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1067 extern int drm_sg_free(struct drm_device *dev, void *data,
1068 struct drm_file *file_priv);
1070 /* ATI PCIGART support (ati_pcigart.h) */
1071 extern int drm_ati_pcigart_init(struct drm_device *dev,
1072 struct drm_ati_pcigart_info * gart_info);
1073 extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1074 struct drm_ati_pcigart_info * gart_info);
1076 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1077 size_t align, dma_addr_t maxaddr);
1078 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1079 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1081 /* sysfs support (drm_sysfs.c) */
1082 struct drm_sysfs_class;
1083 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1084 extern void drm_sysfs_destroy(void);
1085 extern int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head);
1086 extern void drm_sysfs_device_remove(struct drm_device *dev);
1089 * Basic memory manager support (drm_mm.c)
1091 extern struct drm_mm_node *drm_mm_get_block(struct drm_mm_node * parent,
1092 unsigned long size,
1093 unsigned alignment);
1094 extern void drm_mm_put_block(struct drm_mm_node * cur);
1095 extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
1096 unsigned alignment, int best_match);
1097 extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
1098 extern void drm_mm_takedown(struct drm_mm *mm);
1099 extern int drm_mm_clean(struct drm_mm *mm);
1100 extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
1101 extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
1102 extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
1104 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1105 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1107 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1108 unsigned int token)
1110 struct drm_map_list *_entry;
1111 list_for_each_entry(_entry, &dev->maplist, head)
1112 if (_entry->user_token == token)
1113 return _entry->map;
1114 return NULL;
1117 static __inline__ int drm_device_is_agp(struct drm_device *dev)
1119 if (dev->driver->device_is_agp != NULL) {
1120 int err = (*dev->driver->device_is_agp) (dev);
1122 if (err != 2) {
1123 return err;
1127 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1130 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1132 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1135 static __inline__ void drm_core_dropmap(struct drm_map *map)
1139 #ifndef DEBUG_MEMORY
1140 /** Wrapper around kmalloc() */
1141 static __inline__ void *drm_alloc(size_t size, int area)
1143 return kmalloc(size, GFP_KERNEL);
1146 /** Wrapper around kfree() */
1147 static __inline__ void drm_free(void *pt, size_t size, int area)
1149 kfree(pt);
1152 /** Wrapper around kcalloc() */
1153 static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
1155 return kcalloc(nmemb, size, GFP_KERNEL);
1157 #else
1158 extern void *drm_alloc(size_t size, int area);
1159 extern void drm_free(void *pt, size_t size, int area);
1160 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1161 #endif
1163 /*@}*/
1165 #endif /* __KERNEL__ */
1166 #endif