initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / char / drm / drmP.h
blob65351d5188fe001126b316981fe4e64999d48e72
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 */
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_
38 #ifdef __KERNEL__
39 #ifdef __alpha__
40 /* add include of current.h so that "current" is defined
41 * before static inline funcs in wait.h. Doing this so we
42 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
43 #include <asm/current.h>
44 #endif /* __alpha__ */
45 #include <linux/config.h>
46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/miscdevice.h>
49 #include <linux/fs.h>
50 #include <linux/proc_fs.h>
51 #include <linux/init.h>
52 #include <linux/file.h>
53 #include <linux/pci.h>
54 #include <linux/version.h>
55 #include <linux/jiffies.h>
56 #include <linux/smp_lock.h> /* For (un)lock_kernel */
57 #include <linux/mm.h>
58 #if defined(__alpha__) || defined(__powerpc__)
59 #include <asm/pgtable.h> /* For pte_wrprotect */
60 #endif
61 #include <asm/io.h>
62 #include <asm/mman.h>
63 #include <asm/uaccess.h>
64 #ifdef CONFIG_MTRR
65 #include <asm/mtrr.h>
66 #endif
67 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
68 #include <linux/types.h>
69 #include <linux/agp_backend.h>
70 #endif
71 #include <linux/workqueue.h>
72 #include <linux/poll.h>
73 #include <asm/pgalloc.h>
74 #include "drm.h"
76 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
77 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
79 #include "drm_os_linux.h"
81 /***********************************************************************/
82 /** \name DRM template customization defaults */
83 /*@{*/
85 /* driver capabilities and requirements mask */
86 #define DRIVER_USE_AGP 0x1
87 #define DRIVER_REQUIRE_AGP 0x2
88 #define DRIVER_USE_MTRR 0x4
89 #define DRIVER_PCI_DMA 0x8
90 #define DRIVER_SG 0x10
91 #define DRIVER_HAVE_DMA 0x20
92 #define DRIVER_HAVE_IRQ 0x40
93 #define DRIVER_IRQ_SHARED 0x80
94 #define DRIVER_IRQ_VBL 0x100
95 #define DRIVER_DMA_QUEUE 0x200
97 /***********************************************************************/
98 /** \name Begin the DRM... */
99 /*@{*/
101 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
102 also include looping detection. */
104 #define DRM_HASH_SIZE 16 /**< Size of key hash table. Must be power of 2. */
105 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
106 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
107 #define DRM_LOOPING_LIMIT 5000000
108 #define DRM_BSZ 1024 /**< Buffer size for /dev/drm? output */
109 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
110 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
112 #define DRM_FLAG_DEBUG 0x01
114 #define DRM_MEM_DMA 0
115 #define DRM_MEM_SAREA 1
116 #define DRM_MEM_DRIVER 2
117 #define DRM_MEM_MAGIC 3
118 #define DRM_MEM_IOCTLS 4
119 #define DRM_MEM_MAPS 5
120 #define DRM_MEM_VMAS 6
121 #define DRM_MEM_BUFS 7
122 #define DRM_MEM_SEGS 8
123 #define DRM_MEM_PAGES 9
124 #define DRM_MEM_FILES 10
125 #define DRM_MEM_QUEUES 11
126 #define DRM_MEM_CMDS 12
127 #define DRM_MEM_MAPPINGS 13
128 #define DRM_MEM_BUFLISTS 14
129 #define DRM_MEM_AGPLISTS 15
130 #define DRM_MEM_TOTALAGP 16
131 #define DRM_MEM_BOUNDAGP 17
132 #define DRM_MEM_CTXBITMAP 18
133 #define DRM_MEM_STUB 19
134 #define DRM_MEM_SGLISTS 20
135 #define DRM_MEM_CTXLIST 21
137 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
139 /*@}*/
142 /***********************************************************************/
143 /** \name Backward compatibility section */
144 /*@{*/
146 #ifndef MODULE_LICENSE
147 #define MODULE_LICENSE(x)
148 #endif
150 #ifndef preempt_disable
151 #define preempt_disable()
152 #define preempt_enable()
153 #endif
155 #ifndef pte_offset_map
156 #define pte_offset_map pte_offset
157 #define pte_unmap(pte)
158 #endif
160 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19)
161 static inline struct page * vmalloc_to_page(void * vmalloc_addr)
163 unsigned long addr = (unsigned long) vmalloc_addr;
164 struct page *page = NULL;
165 pgd_t *pgd = pgd_offset_k(addr);
166 pmd_t *pmd;
167 pte_t *ptep, pte;
169 if (!pgd_none(*pgd)) {
170 pmd = pmd_offset(pgd, addr);
171 if (!pmd_none(*pmd)) {
172 preempt_disable();
173 ptep = pte_offset_map(pmd, addr);
174 pte = *ptep;
175 if (pte_present(pte))
176 page = pte_page(pte);
177 pte_unmap(ptep);
178 preempt_enable();
181 return page;
183 #endif
185 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
186 #define DRM_RPR_ARG(vma)
187 #else
188 #define DRM_RPR_ARG(vma) vma,
189 #endif
191 #define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT)
193 /*@}*/
196 /***********************************************************************/
197 /** \name Macros to make printk easier */
198 /*@{*/
201 * Error output.
203 * \param fmt printf() like format string.
204 * \param arg arguments
206 #define DRM_ERROR(fmt, arg...) \
207 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
210 * Memory error output.
212 * \param area memory area where the error occurred.
213 * \param fmt printf() like format string.
214 * \param arg arguments
216 #define DRM_MEM_ERROR(area, fmt, arg...) \
217 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
218 DRM(mem_stats)[area].name , ##arg)
219 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
222 * Debug output.
224 * \param fmt printf() like format string.
225 * \param arg arguments
227 #if DRM_DEBUG_CODE
228 #define DRM_DEBUG(fmt, arg...) \
229 do { \
230 if ( DRM(flags) & DRM_FLAG_DEBUG ) \
231 printk(KERN_DEBUG \
232 "[" DRM_NAME ":%s] " fmt , \
233 __FUNCTION__ , ##arg); \
234 } while (0)
235 #else
236 #define DRM_DEBUG(fmt, arg...) do { } while (0)
237 #endif
239 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
241 #define DRM_PROC_PRINT(fmt, arg...) \
242 len += sprintf(&buf[len], fmt , ##arg); \
243 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
245 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
246 len += sprintf(&buf[len], fmt , ##arg); \
247 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
249 /*@}*/
252 /***********************************************************************/
253 /** \name Internal types and structures */
254 /*@{*/
256 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
257 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
258 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
260 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
261 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
262 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
264 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
266 * Get the private SAREA mapping.
268 * \param _dev DRM device.
269 * \param _ctx context number.
270 * \param _map output mapping.
272 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
273 (_map) = (_dev)->context_sareas[_ctx]; \
274 } while(0)
277 * Test that the hardware lock is held by the caller, returning otherwise.
279 * \param dev DRM device.
280 * \param filp file pointer of the caller.
282 #define LOCK_TEST_WITH_RETURN( dev, filp ) \
283 do { \
284 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
285 dev->lock.filp != filp ) { \
286 DRM_ERROR( "%s called without lock held\n", \
287 __FUNCTION__ ); \
288 return -EINVAL; \
290 } while (0)
293 * Ioctl function type.
295 * \param inode device inode.
296 * \param filp file pointer.
297 * \param cmd command.
298 * \param arg argument.
300 typedef int drm_ioctl_t( struct inode *inode, struct file *filp,
301 unsigned int cmd, unsigned long arg );
303 typedef struct drm_ioctl_desc {
304 drm_ioctl_t *func;
305 int auth_needed;
306 int root_only;
307 } drm_ioctl_desc_t;
309 typedef struct drm_devstate {
310 pid_t owner; /**< X server pid holding x_lock */
311 } drm_devstate_t;
313 typedef struct drm_magic_entry {
314 drm_magic_t magic;
315 struct drm_file *priv;
316 struct drm_magic_entry *next;
317 } drm_magic_entry_t;
319 typedef struct drm_magic_head {
320 struct drm_magic_entry *head;
321 struct drm_magic_entry *tail;
322 } drm_magic_head_t;
324 typedef struct drm_vma_entry {
325 struct vm_area_struct *vma;
326 struct drm_vma_entry *next;
327 pid_t pid;
328 } drm_vma_entry_t;
331 * DMA buffer.
333 typedef struct drm_buf {
334 int idx; /**< Index into master buflist */
335 int total; /**< Buffer size */
336 int order; /**< log-base-2(total) */
337 int used; /**< Amount of buffer in use (for DMA) */
338 unsigned long offset; /**< Byte offset (used internally) */
339 void *address; /**< Address of buffer */
340 unsigned long bus_address; /**< Bus address of buffer */
341 struct drm_buf *next; /**< Kernel-only: used for free list */
342 __volatile__ int waiting; /**< On kernel DMA queue */
343 __volatile__ int pending; /**< On hardware DMA queue */
344 wait_queue_head_t dma_wait; /**< Processes waiting */
345 struct file *filp; /**< Pointer to holding file descr */
346 int context; /**< Kernel queue for this buffer */
347 int while_locked;/**< Dispatch this buffer while locked */
348 enum {
349 DRM_LIST_NONE = 0,
350 DRM_LIST_FREE = 1,
351 DRM_LIST_WAIT = 2,
352 DRM_LIST_PEND = 3,
353 DRM_LIST_PRIO = 4,
354 DRM_LIST_RECLAIM = 5
355 } list; /**< Which list we're on */
357 int dev_priv_size; /**< Size of buffer private storage */
358 void *dev_private; /**< Per-buffer private storage */
359 } drm_buf_t;
362 /** bufs is one longer than it has to be */
363 typedef struct drm_waitlist {
364 int count; /**< Number of possible buffers */
365 drm_buf_t **bufs; /**< List of pointers to buffers */
366 drm_buf_t **rp; /**< Read pointer */
367 drm_buf_t **wp; /**< Write pointer */
368 drm_buf_t **end; /**< End pointer */
369 spinlock_t read_lock;
370 spinlock_t write_lock;
371 } drm_waitlist_t;
373 typedef struct drm_freelist {
374 int initialized; /**< Freelist in use */
375 atomic_t count; /**< Number of free buffers */
376 drm_buf_t *next; /**< End pointer */
378 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
379 int low_mark; /**< Low water mark */
380 int high_mark; /**< High water mark */
381 atomic_t wfh; /**< If waiting for high mark */
382 spinlock_t lock;
383 } drm_freelist_t;
386 * Buffer entry. There is one of this for each buffer size order.
388 typedef struct drm_buf_entry {
389 int buf_size; /**< size */
390 int buf_count; /**< number of buffers */
391 drm_buf_t *buflist; /**< buffer list */
392 int seg_count;
393 int page_order;
394 unsigned long *seglist;
396 drm_freelist_t freelist;
397 } drm_buf_entry_t;
399 /** File private data */
400 typedef struct drm_file {
401 int authenticated;
402 int minor;
403 pid_t pid;
404 uid_t uid;
405 drm_magic_t magic;
406 unsigned long ioctl_count;
407 struct drm_file *next;
408 struct drm_file *prev;
409 struct drm_device *dev;
410 int remove_auth_on_close;
411 unsigned long lock_count;
412 void *driver_priv;
413 } drm_file_t;
415 /** Wait queue */
416 typedef struct drm_queue {
417 atomic_t use_count; /**< Outstanding uses (+1) */
418 atomic_t finalization; /**< Finalization in progress */
419 atomic_t block_count; /**< Count of processes waiting */
420 atomic_t block_read; /**< Queue blocked for reads */
421 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
422 atomic_t block_write; /**< Queue blocked for writes */
423 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
424 #if 1
425 atomic_t total_queued; /**< Total queued statistic */
426 atomic_t total_flushed;/**< Total flushes statistic */
427 atomic_t total_locks; /**< Total locks statistics */
428 #endif
429 drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
430 drm_waitlist_t waitlist; /**< Pending buffers */
431 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
432 } drm_queue_t;
435 * Lock data.
437 typedef struct drm_lock_data {
438 drm_hw_lock_t *hw_lock; /**< Hardware lock */
439 struct file *filp; /**< File descr of lock holder (0=kernel) */
440 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
441 unsigned long lock_time; /**< Time of last lock in jiffies */
442 } drm_lock_data_t;
445 * DMA data.
447 typedef struct drm_device_dma {
449 drm_buf_entry_t bufs[DRM_MAX_ORDER+1]; /**< buffers, grouped by their size order */
450 int buf_count; /**< total number of buffers */
451 drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
452 int seg_count;
453 int page_count; /**< number of pages */
454 unsigned long *pagelist; /**< page list */
455 unsigned long byte_count;
456 enum {
457 _DRM_DMA_USE_AGP = 0x01,
458 _DRM_DMA_USE_SG = 0x02
459 } flags;
461 } drm_device_dma_t;
463 /**
464 * AGP memory entry. Stored as a doubly linked list.
466 typedef struct drm_agp_mem {
467 unsigned long handle; /**< handle */
468 DRM_AGP_MEM *memory;
469 unsigned long bound; /**< address */
470 int pages;
471 struct drm_agp_mem *prev; /**< previous entry */
472 struct drm_agp_mem *next; /**< next entry */
473 } drm_agp_mem_t;
476 * AGP data.
478 * \sa DRM(agp_init)() and drm_device::agp.
480 typedef struct drm_agp_head {
481 DRM_AGP_KERN agp_info; /**< AGP device information */
482 drm_agp_mem_t *memory; /**< memory entries */
483 unsigned long mode; /**< AGP mode */
484 int enabled; /**< whether the AGP bus as been enabled */
485 int acquired; /**< whether the AGP device has been acquired */
486 unsigned long base;
487 int agp_mtrr;
488 int cant_use_aperture;
489 unsigned long page_mask;
490 } drm_agp_head_t;
493 * Scatter-gather memory.
495 typedef struct drm_sg_mem {
496 unsigned long handle;
497 void *virtual;
498 int pages;
499 struct page **pagelist;
500 dma_addr_t *busaddr;
501 } drm_sg_mem_t;
503 typedef struct drm_sigdata {
504 int context;
505 drm_hw_lock_t *lock;
506 } drm_sigdata_t;
509 * Mappings list
511 typedef struct drm_map_list {
512 struct list_head head; /**< list head */
513 drm_map_t *map; /**< mapping */
514 } drm_map_list_t;
516 typedef drm_map_t drm_local_map_t;
519 * Context handle list
521 typedef struct drm_ctx_list {
522 struct list_head head; /**< list head */
523 drm_context_t handle; /**< context handle */
524 drm_file_t *tag; /**< associated fd private data */
525 } drm_ctx_list_t;
528 typedef struct drm_vbl_sig {
529 struct list_head head;
530 unsigned int sequence;
531 struct siginfo info;
532 struct task_struct *task;
533 } drm_vbl_sig_t;
536 /**
537 * DRM device functions structure
539 struct drm_device;
541 struct drm_driver_fn {
542 int (*preinit)(struct drm_device *);
543 int (*postinit)(struct drm_device *);
544 void (*prerelease)(struct drm_device *, struct file *filp);
545 void (*pretakedown)(struct drm_device *);
546 int (*postcleanup)(struct drm_device *);
547 int (*presetup)(struct drm_device *);
548 int (*postsetup)(struct drm_device *);
549 int (*open_helper)(struct drm_device *, drm_file_t *);
550 void (*free_filp_priv)(struct drm_device *, drm_file_t *);
551 void (*release)(struct drm_device *, struct file *filp);
552 void (*dma_ready)(struct drm_device *);
553 int (*dma_quiescent)(struct drm_device *);
554 int (*context_ctor)(struct drm_device *dev, int context);
555 int (*context_dtor)(struct drm_device *dev, int context);
556 int (*kernel_context_switch)(struct drm_device *dev, int old, int new);
557 void (*kernel_context_switch_unlock)(struct drm_device *dev, drm_lock_t *lock);
558 int (*vblank_wait)(struct drm_device *dev, unsigned int *sequence);
559 /* these have to be filled in */
560 irqreturn_t (*irq_handler)( DRM_IRQ_ARGS );
561 void (*irq_preinstall)(struct drm_device *dev);
562 void (*irq_postinstall)(struct drm_device *dev);
563 void (*irq_uninstall)(struct drm_device *dev);
564 void (*reclaim_buffers)(struct file *filp);
565 unsigned long (*get_map_ofs)(drm_map_t *map);
566 unsigned long (*get_reg_ofs)(struct drm_device *dev);
567 void (*set_version)(struct drm_device *dev, drm_set_version_t *sv);
570 * DRM device structure.
572 typedef struct drm_device {
573 const char *name; /**< Simple driver name */
574 char *unique; /**< Unique identifier: e.g., busid */
575 int unique_len; /**< Length of unique field */
576 dev_t device; /**< Device number for mknod */
577 char *devname; /**< For /proc/interrupts */
578 int minor; /**< Minor device number */
579 int if_version; /**< Highest interface version set */
581 int blocked; /**< Blocked due to VC switch? */
582 struct proc_dir_entry *root; /**< Root for this device's entries */
584 /** \name Locks */
585 /*@{*/
586 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
587 struct semaphore struct_sem; /**< For others */
588 /*@}*/
590 /** \name Usage Counters */
591 /*@{*/
592 int open_count; /**< Outstanding files open */
593 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
594 atomic_t vma_count; /**< Outstanding vma areas open */
595 int buf_use; /**< Buffers in use -- cannot alloc */
596 atomic_t buf_alloc; /**< Buffer allocation in progress */
597 /*@}*/
599 /** \name Performance counters */
600 /*@{*/
601 unsigned long counters;
602 drm_stat_type_t types[15];
603 atomic_t counts[15];
604 /*@}*/
606 /** \name Authentication */
607 /*@{*/
608 drm_file_t *file_first; /**< file list head */
609 drm_file_t *file_last; /**< file list tail */
610 drm_magic_head_t magiclist[DRM_HASH_SIZE]; /**< magic hash table */
611 /*@}*/
613 /** \name Memory management */
614 /*@{*/
615 drm_map_list_t *maplist; /**< Linked list of regions */
616 int map_count; /**< Number of mappable regions */
618 /** \name Context handle management */
619 /*@{*/
620 drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
621 int ctx_count; /**< Number of context handles */
622 struct semaphore ctxlist_sem; /**< For ctxlist */
624 drm_map_t **context_sareas; /**< per-context SAREA's */
625 int max_context;
627 drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
628 drm_lock_data_t lock; /**< Information on hardware lock */
629 /*@}*/
631 /** \name DMA queues (contexts) */
632 /*@{*/
633 int queue_count; /**< Number of active DMA queues */
634 int queue_reserved; /**< Number of reserved DMA queues */
635 int queue_slots; /**< Actual length of queuelist */
636 drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
637 drm_device_dma_t *dma; /**< Optional pointer for DMA support */
638 /*@}*/
640 /** \name Context support */
641 /*@{*/
642 int irq; /**< Interrupt used by board */
643 int irq_enabled; /**< True if irq handler is enabled */
644 __volatile__ long context_flag; /**< Context swapping flag */
645 __volatile__ long interrupt_flag; /**< Interruption handler flag */
646 __volatile__ long dma_flag; /**< DMA dispatch flag */
647 struct timer_list timer; /**< Timer for delaying ctx switch */
648 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
649 int last_checked; /**< Last context checked for DMA */
650 int last_context; /**< Last current context */
651 unsigned long last_switch; /**< jiffies at last context switch */
652 /*@}*/
654 struct work_struct work;
655 /** \name VBLANK IRQ support */
656 /*@{*/
658 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
659 atomic_t vbl_received;
660 spinlock_t vbl_lock;
661 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
662 unsigned int vbl_pending;
664 /*@}*/
665 cycles_t ctx_start;
666 cycles_t lck_start;
668 char buf[DRM_BSZ]; /**< Output buffer */
669 char *buf_rp; /**< Read pointer */
670 char *buf_wp; /**< Write pointer */
671 char *buf_end; /**< End pointer */
672 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
673 wait_queue_head_t buf_readers; /**< Processes waiting to read */
674 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
676 drm_agp_head_t *agp; /**< AGP data */
678 struct pci_dev *pdev; /**< PCI device structure */
679 int pci_domain; /**< PCI bus domain number */
680 int pci_bus; /**< PCI bus number */
681 int pci_slot; /**< PCI slot number */
682 int pci_func; /**< PCI function number */
683 #ifdef __alpha__
684 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3)
685 struct pci_controler *hose;
686 #else
687 struct pci_controller *hose;
688 #endif
689 #endif
690 drm_sg_mem_t *sg; /**< Scatter gather memory */
691 unsigned long *ctx_bitmap; /**< context bitmap */
692 void *dev_private; /**< device private data */
693 drm_sigdata_t sigdata; /**< For block_all_signals */
694 sigset_t sigmask;
696 struct drm_driver_fn fn_tbl;
697 drm_local_map_t *agp_buffer_map;
698 int dev_priv_size;
699 u32 driver_features;
700 } drm_device_t;
702 static __inline__ int drm_core_check_feature(struct drm_device *dev, int feature)
704 return ((dev->driver_features & feature) ? 1 : 0);
707 #if __OS_HAS_AGP
708 static inline int drm_core_has_AGP(struct drm_device *dev)
710 return drm_core_check_feature(dev, DRIVER_USE_AGP);
712 #else
713 #define drm_core_has_AGP(dev) (0)
714 #endif
716 #if __OS_HAS_MTRR
717 static inline int drm_core_has_MTRR(struct drm_device *dev)
719 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
721 #else
722 #define drm_core_has_MTRR(dev) (0)
723 #endif
725 extern void DRM(driver_register_fns)(struct drm_device *dev);
727 /******************************************************************/
728 /** \name Internal function definitions */
729 /*@{*/
731 /* Misc. support (drm_init.h) */
732 extern int DRM(flags);
733 extern void DRM(parse_options)( char *s );
734 extern int DRM(cpu_valid)( void );
736 /* Driver support (drm_drv.h) */
737 extern int DRM(version)(struct inode *inode, struct file *filp,
738 unsigned int cmd, unsigned long arg);
739 extern int DRM(open)(struct inode *inode, struct file *filp);
740 extern int DRM(release)(struct inode *inode, struct file *filp);
741 extern int DRM(ioctl)(struct inode *inode, struct file *filp,
742 unsigned int cmd, unsigned long arg);
743 extern int DRM(lock)(struct inode *inode, struct file *filp,
744 unsigned int cmd, unsigned long arg);
745 extern int DRM(unlock)(struct inode *inode, struct file *filp,
746 unsigned int cmd, unsigned long arg);
748 /* Device support (drm_fops.h) */
749 extern int DRM(open_helper)(struct inode *inode, struct file *filp,
750 drm_device_t *dev);
751 extern int DRM(flush)(struct file *filp);
752 extern int DRM(fasync)(int fd, struct file *filp, int on);
754 /* Mapping support (drm_vm.h) */
755 extern void DRM(vm_open)(struct vm_area_struct *vma);
756 extern void DRM(vm_close)(struct vm_area_struct *vma);
757 extern void DRM(vm_shm_close)(struct vm_area_struct *vma);
758 extern int DRM(mmap_dma)(struct file *filp,
759 struct vm_area_struct *vma);
760 extern int DRM(mmap)(struct file *filp, struct vm_area_struct *vma);
761 extern unsigned int DRM(poll)(struct file *filp, struct poll_table_struct *wait);
762 extern ssize_t DRM(read)(struct file *filp, char __user *buf, size_t count, loff_t *off);
764 /* Memory management support (drm_memory.h) */
765 extern void DRM(mem_init)(void);
766 extern int DRM(mem_info)(char *buf, char **start, off_t offset,
767 int request, int *eof, void *data);
768 extern void *DRM(alloc)(size_t size, int area);
769 extern void *DRM(calloc)(size_t nmemb, size_t size, int area);
770 extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
771 int area);
772 extern void DRM(free)(void *pt, size_t size, int area);
773 extern unsigned long DRM(alloc_pages)(int order, int area);
774 extern void DRM(free_pages)(unsigned long address, int order,
775 int area);
776 extern void *DRM(ioremap)(unsigned long offset, unsigned long size, drm_device_t *dev);
777 extern void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size,
778 drm_device_t *dev);
779 extern void DRM(ioremapfree)(void *pt, unsigned long size, drm_device_t *dev);
781 extern DRM_AGP_MEM *DRM(alloc_agp)(int pages, u32 type);
782 extern int DRM(free_agp)(DRM_AGP_MEM *handle, int pages);
783 extern int DRM(bind_agp)(DRM_AGP_MEM *handle, unsigned int start);
784 extern int DRM(unbind_agp)(DRM_AGP_MEM *handle);
786 /* Misc. IOCTL support (drm_ioctl.h) */
787 extern int DRM(irq_by_busid)(struct inode *inode, struct file *filp,
788 unsigned int cmd, unsigned long arg);
789 extern int DRM(getunique)(struct inode *inode, struct file *filp,
790 unsigned int cmd, unsigned long arg);
791 extern int DRM(setunique)(struct inode *inode, struct file *filp,
792 unsigned int cmd, unsigned long arg);
793 extern int DRM(getmap)(struct inode *inode, struct file *filp,
794 unsigned int cmd, unsigned long arg);
795 extern int DRM(getclient)(struct inode *inode, struct file *filp,
796 unsigned int cmd, unsigned long arg);
797 extern int DRM(getstats)(struct inode *inode, struct file *filp,
798 unsigned int cmd, unsigned long arg);
799 extern int DRM(setversion)(struct inode *inode, struct file *filp,
800 unsigned int cmd, unsigned long arg);
802 /* Context IOCTL support (drm_context.h) */
803 extern int DRM(resctx)( struct inode *inode, struct file *filp,
804 unsigned int cmd, unsigned long arg );
805 extern int DRM(addctx)( struct inode *inode, struct file *filp,
806 unsigned int cmd, unsigned long arg );
807 extern int DRM(modctx)( struct inode *inode, struct file *filp,
808 unsigned int cmd, unsigned long arg );
809 extern int DRM(getctx)( struct inode *inode, struct file *filp,
810 unsigned int cmd, unsigned long arg );
811 extern int DRM(switchctx)( struct inode *inode, struct file *filp,
812 unsigned int cmd, unsigned long arg );
813 extern int DRM(newctx)( struct inode *inode, struct file *filp,
814 unsigned int cmd, unsigned long arg );
815 extern int DRM(rmctx)( struct inode *inode, struct file *filp,
816 unsigned int cmd, unsigned long arg );
818 extern int DRM(context_switch)(drm_device_t *dev, int old, int new);
819 extern int DRM(context_switch_complete)(drm_device_t *dev, int new);
821 extern int DRM(ctxbitmap_init)( drm_device_t *dev );
822 extern void DRM(ctxbitmap_cleanup)( drm_device_t *dev );
824 extern int DRM(setsareactx)( struct inode *inode, struct file *filp,
825 unsigned int cmd, unsigned long arg );
826 extern int DRM(getsareactx)( struct inode *inode, struct file *filp,
827 unsigned int cmd, unsigned long arg );
829 /* Drawable IOCTL support (drm_drawable.h) */
830 extern int DRM(adddraw)(struct inode *inode, struct file *filp,
831 unsigned int cmd, unsigned long arg);
832 extern int DRM(rmdraw)(struct inode *inode, struct file *filp,
833 unsigned int cmd, unsigned long arg);
836 /* Authentication IOCTL support (drm_auth.h) */
837 extern int DRM(add_magic)(drm_device_t *dev, drm_file_t *priv,
838 drm_magic_t magic);
839 extern int DRM(remove_magic)(drm_device_t *dev, drm_magic_t magic);
840 extern int DRM(getmagic)(struct inode *inode, struct file *filp,
841 unsigned int cmd, unsigned long arg);
842 extern int DRM(authmagic)(struct inode *inode, struct file *filp,
843 unsigned int cmd, unsigned long arg);
845 /* Placeholder for ioctls past */
846 extern int DRM(noop)(struct inode *inode, struct file *filp,
847 unsigned int cmd, unsigned long arg);
849 /* Locking IOCTL support (drm_lock.h) */
850 extern int DRM(lock_take)(__volatile__ unsigned int *lock,
851 unsigned int context);
852 extern int DRM(lock_transfer)(drm_device_t *dev,
853 __volatile__ unsigned int *lock,
854 unsigned int context);
855 extern int DRM(lock_free)(drm_device_t *dev,
856 __volatile__ unsigned int *lock,
857 unsigned int context);
858 extern int DRM(notifier)(void *priv);
860 /* Buffer management support (drm_bufs.h) */
861 extern int DRM(order)( unsigned long size );
862 extern int DRM(addmap)( struct inode *inode, struct file *filp,
863 unsigned int cmd, unsigned long arg );
864 extern int DRM(rmmap)( struct inode *inode, struct file *filp,
865 unsigned int cmd, unsigned long arg );
866 extern int DRM(addbufs)( struct inode *inode, struct file *filp,
867 unsigned int cmd, unsigned long arg );
868 extern int DRM(infobufs)( struct inode *inode, struct file *filp,
869 unsigned int cmd, unsigned long arg );
870 extern int DRM(markbufs)( struct inode *inode, struct file *filp,
871 unsigned int cmd, unsigned long arg );
872 extern int DRM(freebufs)( struct inode *inode, struct file *filp,
873 unsigned int cmd, unsigned long arg );
874 extern int DRM(mapbufs)( struct inode *inode, struct file *filp,
875 unsigned int cmd, unsigned long arg );
877 /* DMA support (drm_dma.h) */
878 extern int DRM(dma_setup)(drm_device_t *dev);
879 extern void DRM(dma_takedown)(drm_device_t *dev);
880 extern void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
881 extern void DRM(reclaim_buffers)( struct file *filp );
883 /* IRQ support (drm_irq.h) */
884 extern int DRM(control)( struct inode *inode, struct file *filp,
885 unsigned int cmd, unsigned long arg );
886 extern int DRM(irq_install)( drm_device_t *dev );
887 extern int DRM(irq_uninstall)( drm_device_t *dev );
888 extern irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS );
889 extern void DRM(driver_irq_preinstall)( drm_device_t *dev );
890 extern void DRM(driver_irq_postinstall)( drm_device_t *dev );
891 extern void DRM(driver_irq_uninstall)( drm_device_t *dev );
893 extern int DRM(wait_vblank)(struct inode *inode, struct file *filp,
894 unsigned int cmd, unsigned long arg);
895 extern int DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
896 extern void DRM(vbl_send_signals)( drm_device_t *dev );
898 /* AGP/GART support (drm_agpsupport.h) */
899 extern drm_agp_head_t *DRM(agp_init)(void);
900 extern void DRM(agp_uninit)(void);
901 extern int DRM(agp_acquire)(struct inode *inode, struct file *filp,
902 unsigned int cmd, unsigned long arg);
903 extern void DRM(agp_do_release)(void);
904 extern int DRM(agp_release)(struct inode *inode, struct file *filp,
905 unsigned int cmd, unsigned long arg);
906 extern int DRM(agp_enable)(struct inode *inode, struct file *filp,
907 unsigned int cmd, unsigned long arg);
908 extern int DRM(agp_info)(struct inode *inode, struct file *filp,
909 unsigned int cmd, unsigned long arg);
910 extern int DRM(agp_alloc)(struct inode *inode, struct file *filp,
911 unsigned int cmd, unsigned long arg);
912 extern int DRM(agp_free)(struct inode *inode, struct file *filp,
913 unsigned int cmd, unsigned long arg);
914 extern int DRM(agp_unbind)(struct inode *inode, struct file *filp,
915 unsigned int cmd, unsigned long arg);
916 extern int DRM(agp_bind)(struct inode *inode, struct file *filp,
917 unsigned int cmd, unsigned long arg);
918 extern DRM_AGP_MEM *DRM(agp_allocate_memory)(size_t pages, u32 type);
919 extern int DRM(agp_free_memory)(DRM_AGP_MEM *handle);
920 extern int DRM(agp_bind_memory)(DRM_AGP_MEM *handle, off_t start);
921 extern int DRM(agp_unbind_memory)(DRM_AGP_MEM *handle);
923 /* Stub support (drm_stub.h) */
924 int DRM(stub_register)(const char *name,
925 struct file_operations *fops,
926 drm_device_t *dev);
927 int DRM(stub_unregister)(int minor);
929 /* Proc support (drm_proc.h) */
930 extern struct proc_dir_entry *DRM(proc_init)(drm_device_t *dev,
931 int minor,
932 struct proc_dir_entry *root,
933 struct proc_dir_entry **dev_root);
934 extern int DRM(proc_cleanup)(int minor,
935 struct proc_dir_entry *root,
936 struct proc_dir_entry *dev_root);
938 /* Scatter Gather Support (drm_scatter.h) */
939 extern void DRM(sg_cleanup)(drm_sg_mem_t *entry);
940 extern int DRM(sg_alloc)(struct inode *inode, struct file *filp,
941 unsigned int cmd, unsigned long arg);
942 extern int DRM(sg_free)(struct inode *inode, struct file *filp,
943 unsigned int cmd, unsigned long arg);
945 /* ATI PCIGART support (ati_pcigart.h) */
946 extern int DRM(ati_pcigart_init)(drm_device_t *dev,
947 unsigned long *addr,
948 dma_addr_t *bus_addr);
949 extern int DRM(ati_pcigart_cleanup)(drm_device_t *dev,
950 unsigned long addr,
951 dma_addr_t bus_addr);
954 /* Inline replacements for DRM_IOREMAP macros */
955 static __inline__ void drm_core_ioremap(struct drm_map *map, struct drm_device *dev)
957 map->handle = DRM(ioremap)( map->offset, map->size, dev );
960 static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, struct drm_device *dev)
962 map->handle = DRM(ioremap_nocache)(map->offset, map->size, dev);
965 static __inline__ void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev)
967 if ( map->handle && map->size )
968 DRM(ioremapfree)( map->handle, map->size, dev );
971 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev, unsigned long offset)
973 struct list_head *_list;
974 list_for_each( _list, &dev->maplist->head ) {
975 drm_map_list_t *_entry = list_entry( _list, drm_map_list_t, head );
976 if ( _entry->map &&
977 _entry->map->offset == offset ) {
978 return _entry->map;
981 return NULL;
984 static __inline__ void drm_core_dropmap(struct drm_map *map)
987 /*@}*/
989 extern unsigned long DRM(core_get_map_ofs)(drm_map_t *map);
990 extern unsigned long DRM(core_get_reg_ofs)(struct drm_device *dev);
992 #endif /* __KERNEL__ */
993 #endif