drm: add simple DRM memory manager, and hash table
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / char / drm / drmP.h
blobc93985bb91a20912a824c32f6613ffda23ca1aa2
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 #include <linux/mm.h>
58 #include <linux/cdev.h>
59 #include <linux/mutex.h>
60 #if defined(__alpha__) || defined(__powerpc__)
61 #include <asm/pgtable.h> /* For pte_wrprotect */
62 #endif
63 #include <asm/io.h>
64 #include <asm/mman.h>
65 #include <asm/uaccess.h>
66 #ifdef CONFIG_MTRR
67 #include <asm/mtrr.h>
68 #endif
69 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
70 #include <linux/types.h>
71 #include <linux/agp_backend.h>
72 #endif
73 #include <linux/workqueue.h>
74 #include <linux/poll.h>
75 #include <asm/pgalloc.h>
76 #include "drm.h"
78 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
79 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
81 #include "drm_os_linux.h"
82 #include "drm_hashtab.h"
84 /***********************************************************************/
85 /** \name DRM template customization defaults */
86 /*@{*/
88 /* driver capabilities and requirements mask */
89 #define DRIVER_USE_AGP 0x1
90 #define DRIVER_REQUIRE_AGP 0x2
91 #define DRIVER_USE_MTRR 0x4
92 #define DRIVER_PCI_DMA 0x8
93 #define DRIVER_SG 0x10
94 #define DRIVER_HAVE_DMA 0x20
95 #define DRIVER_HAVE_IRQ 0x40
96 #define DRIVER_IRQ_SHARED 0x80
97 #define DRIVER_IRQ_VBL 0x100
98 #define DRIVER_DMA_QUEUE 0x200
99 #define DRIVER_FB_DMA 0x400
101 /***********************************************************************/
102 /** \name Begin the DRM... */
103 /*@{*/
105 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
106 also include looping detection. */
108 #define DRM_HASH_SIZE 16 /**< Size of key hash table. Must be power of 2. */
109 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
110 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
111 #define DRM_LOOPING_LIMIT 5000000
112 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
113 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
115 #define DRM_FLAG_DEBUG 0x01
117 #define DRM_MEM_DMA 0
118 #define DRM_MEM_SAREA 1
119 #define DRM_MEM_DRIVER 2
120 #define DRM_MEM_MAGIC 3
121 #define DRM_MEM_IOCTLS 4
122 #define DRM_MEM_MAPS 5
123 #define DRM_MEM_VMAS 6
124 #define DRM_MEM_BUFS 7
125 #define DRM_MEM_SEGS 8
126 #define DRM_MEM_PAGES 9
127 #define DRM_MEM_FILES 10
128 #define DRM_MEM_QUEUES 11
129 #define DRM_MEM_CMDS 12
130 #define DRM_MEM_MAPPINGS 13
131 #define DRM_MEM_BUFLISTS 14
132 #define DRM_MEM_AGPLISTS 15
133 #define DRM_MEM_TOTALAGP 16
134 #define DRM_MEM_BOUNDAGP 17
135 #define DRM_MEM_CTXBITMAP 18
136 #define DRM_MEM_STUB 19
137 #define DRM_MEM_SGLISTS 20
138 #define DRM_MEM_CTXLIST 21
139 #define DRM_MEM_MM 22
140 #define DRM_MEM_HASHTAB 23
142 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
144 /*@}*/
146 /***********************************************************************/
147 /** \name Macros to make printk easier */
148 /*@{*/
151 * Error output.
153 * \param fmt printf() like format string.
154 * \param arg arguments
156 #define DRM_ERROR(fmt, arg...) \
157 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
160 * Memory error output.
162 * \param area memory area where the error occurred.
163 * \param fmt printf() like format string.
164 * \param arg arguments
166 #define DRM_MEM_ERROR(area, fmt, arg...) \
167 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
168 drm_mem_stats[area].name , ##arg)
170 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
173 * Debug output.
175 * \param fmt printf() like format string.
176 * \param arg arguments
178 #if DRM_DEBUG_CODE
179 #define DRM_DEBUG(fmt, arg...) \
180 do { \
181 if ( drm_debug ) \
182 printk(KERN_DEBUG \
183 "[" DRM_NAME ":%s] " fmt , \
184 __FUNCTION__ , ##arg); \
185 } while (0)
186 #else
187 #define DRM_DEBUG(fmt, arg...) do { } while (0)
188 #endif
190 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
192 #define DRM_PROC_PRINT(fmt, arg...) \
193 len += sprintf(&buf[len], fmt , ##arg); \
194 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
196 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
197 len += sprintf(&buf[len], fmt , ##arg); \
198 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
200 /*@}*/
202 /***********************************************************************/
203 /** \name Internal types and structures */
204 /*@{*/
206 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
208 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
209 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
210 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
212 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
214 * Get the private SAREA mapping.
216 * \param _dev DRM device.
217 * \param _ctx context number.
218 * \param _map output mapping.
220 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
221 (_map) = (_dev)->context_sareas[_ctx]; \
222 } while(0)
225 * Test that the hardware lock is held by the caller, returning otherwise.
227 * \param dev DRM device.
228 * \param filp file pointer of the caller.
230 #define LOCK_TEST_WITH_RETURN( dev, filp ) \
231 do { \
232 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
233 dev->lock.filp != filp ) { \
234 DRM_ERROR( "%s called without lock held\n", \
235 __FUNCTION__ ); \
236 return -EINVAL; \
238 } while (0)
241 * Copy and IOCTL return string to user space
243 #define DRM_COPY( name, value ) \
244 len = strlen( value ); \
245 if ( len > name##_len ) len = name##_len; \
246 name##_len = strlen( value ); \
247 if ( len && name ) { \
248 if ( copy_to_user( name, value, len ) ) \
249 return -EFAULT; \
253 * Ioctl function type.
255 * \param inode device inode.
256 * \param filp file pointer.
257 * \param cmd command.
258 * \param arg argument.
260 typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
261 unsigned int cmd, unsigned long arg);
263 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
264 unsigned long arg);
266 #define DRM_AUTH 0x1
267 #define DRM_MASTER 0x2
268 #define DRM_ROOT_ONLY 0x4
270 typedef struct drm_ioctl_desc {
271 drm_ioctl_t *func;
272 int flags;
273 } drm_ioctl_desc_t;
275 typedef struct drm_devstate {
276 pid_t owner; /**< X server pid holding x_lock */
277 } drm_devstate_t;
279 typedef struct drm_magic_entry {
280 drm_magic_t magic;
281 struct drm_file *priv;
282 struct drm_magic_entry *next;
283 } drm_magic_entry_t;
285 typedef struct drm_magic_head {
286 struct drm_magic_entry *head;
287 struct drm_magic_entry *tail;
288 } drm_magic_head_t;
290 typedef struct drm_vma_entry {
291 struct vm_area_struct *vma;
292 struct drm_vma_entry *next;
293 pid_t pid;
294 } drm_vma_entry_t;
297 * DMA buffer.
299 typedef struct drm_buf {
300 int idx; /**< Index into master buflist */
301 int total; /**< Buffer size */
302 int order; /**< log-base-2(total) */
303 int used; /**< Amount of buffer in use (for DMA) */
304 unsigned long offset; /**< Byte offset (used internally) */
305 void *address; /**< Address of buffer */
306 unsigned long bus_address; /**< Bus address of buffer */
307 struct drm_buf *next; /**< Kernel-only: used for free list */
308 __volatile__ int waiting; /**< On kernel DMA queue */
309 __volatile__ int pending; /**< On hardware DMA queue */
310 wait_queue_head_t dma_wait; /**< Processes waiting */
311 struct file *filp; /**< Pointer to holding file descr */
312 int context; /**< Kernel queue for this buffer */
313 int while_locked; /**< Dispatch this buffer while locked */
314 enum {
315 DRM_LIST_NONE = 0,
316 DRM_LIST_FREE = 1,
317 DRM_LIST_WAIT = 2,
318 DRM_LIST_PEND = 3,
319 DRM_LIST_PRIO = 4,
320 DRM_LIST_RECLAIM = 5
321 } list; /**< Which list we're on */
323 int dev_priv_size; /**< Size of buffer private storage */
324 void *dev_private; /**< Per-buffer private storage */
325 } drm_buf_t;
327 /** bufs is one longer than it has to be */
328 typedef struct drm_waitlist {
329 int count; /**< Number of possible buffers */
330 drm_buf_t **bufs; /**< List of pointers to buffers */
331 drm_buf_t **rp; /**< Read pointer */
332 drm_buf_t **wp; /**< Write pointer */
333 drm_buf_t **end; /**< End pointer */
334 spinlock_t read_lock;
335 spinlock_t write_lock;
336 } drm_waitlist_t;
338 typedef struct drm_freelist {
339 int initialized; /**< Freelist in use */
340 atomic_t count; /**< Number of free buffers */
341 drm_buf_t *next; /**< End pointer */
343 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
344 int low_mark; /**< Low water mark */
345 int high_mark; /**< High water mark */
346 atomic_t wfh; /**< If waiting for high mark */
347 spinlock_t lock;
348 } drm_freelist_t;
350 typedef struct drm_dma_handle {
351 dma_addr_t busaddr;
352 void *vaddr;
353 size_t size;
354 } drm_dma_handle_t;
357 * Buffer entry. There is one of this for each buffer size order.
359 typedef struct drm_buf_entry {
360 int buf_size; /**< size */
361 int buf_count; /**< number of buffers */
362 drm_buf_t *buflist; /**< buffer list */
363 int seg_count;
364 int page_order;
365 drm_dma_handle_t **seglist;
367 drm_freelist_t freelist;
368 } drm_buf_entry_t;
370 /** File private data */
371 typedef struct drm_file {
372 int authenticated;
373 int master;
374 int minor;
375 pid_t pid;
376 uid_t uid;
377 drm_magic_t magic;
378 unsigned long ioctl_count;
379 struct drm_file *next;
380 struct drm_file *prev;
381 struct drm_head *head;
382 int remove_auth_on_close;
383 unsigned long lock_count;
384 void *driver_priv;
385 } drm_file_t;
387 /** Wait queue */
388 typedef struct drm_queue {
389 atomic_t use_count; /**< Outstanding uses (+1) */
390 atomic_t finalization; /**< Finalization in progress */
391 atomic_t block_count; /**< Count of processes waiting */
392 atomic_t block_read; /**< Queue blocked for reads */
393 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
394 atomic_t block_write; /**< Queue blocked for writes */
395 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
396 #if 1
397 atomic_t total_queued; /**< Total queued statistic */
398 atomic_t total_flushed; /**< Total flushes statistic */
399 atomic_t total_locks; /**< Total locks statistics */
400 #endif
401 drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
402 drm_waitlist_t waitlist; /**< Pending buffers */
403 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
404 } drm_queue_t;
407 * Lock data.
409 typedef struct drm_lock_data {
410 drm_hw_lock_t *hw_lock; /**< Hardware lock */
411 struct file *filp; /**< File descr of lock holder (0=kernel) */
412 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
413 unsigned long lock_time; /**< Time of last lock in jiffies */
414 } drm_lock_data_t;
417 * DMA data.
419 typedef struct drm_device_dma {
421 drm_buf_entry_t bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
422 int buf_count; /**< total number of buffers */
423 drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
424 int seg_count;
425 int page_count; /**< number of pages */
426 unsigned long *pagelist; /**< page list */
427 unsigned long byte_count;
428 enum {
429 _DRM_DMA_USE_AGP = 0x01,
430 _DRM_DMA_USE_SG = 0x02,
431 _DRM_DMA_USE_FB = 0x04
432 } flags;
434 } drm_device_dma_t;
437 * AGP memory entry. Stored as a doubly linked list.
439 typedef struct drm_agp_mem {
440 unsigned long handle; /**< handle */
441 DRM_AGP_MEM *memory;
442 unsigned long bound; /**< address */
443 int pages;
444 struct drm_agp_mem *prev; /**< previous entry */
445 struct drm_agp_mem *next; /**< next entry */
446 } drm_agp_mem_t;
449 * AGP data.
451 * \sa drm_agp_init() and drm_device::agp.
453 typedef struct drm_agp_head {
454 DRM_AGP_KERN agp_info; /**< AGP device information */
455 drm_agp_mem_t *memory; /**< memory entries */
456 unsigned long mode; /**< AGP mode */
457 struct agp_bridge_data *bridge;
458 int enabled; /**< whether the AGP bus as been enabled */
459 int acquired; /**< whether the AGP device has been acquired */
460 unsigned long base;
461 int agp_mtrr;
462 int cant_use_aperture;
463 unsigned long page_mask;
464 } drm_agp_head_t;
467 * Scatter-gather memory.
469 typedef struct drm_sg_mem {
470 unsigned long handle;
471 void *virtual;
472 int pages;
473 struct page **pagelist;
474 dma_addr_t *busaddr;
475 } drm_sg_mem_t;
477 typedef struct drm_sigdata {
478 int context;
479 drm_hw_lock_t *lock;
480 } drm_sigdata_t;
483 * Mappings list
485 typedef struct drm_map_list {
486 struct list_head head; /**< list head */
487 drm_map_t *map; /**< mapping */
488 unsigned int user_token;
489 } drm_map_list_t;
491 typedef drm_map_t drm_local_map_t;
494 * Context handle list
496 typedef struct drm_ctx_list {
497 struct list_head head; /**< list head */
498 drm_context_t handle; /**< context handle */
499 drm_file_t *tag; /**< associated fd private data */
500 } drm_ctx_list_t;
502 typedef struct drm_vbl_sig {
503 struct list_head head;
504 unsigned int sequence;
505 struct siginfo info;
506 struct task_struct *task;
507 } drm_vbl_sig_t;
509 /* location of GART table */
510 #define DRM_ATI_GART_MAIN 1
511 #define DRM_ATI_GART_FB 2
513 typedef struct ati_pcigart_info {
514 int gart_table_location;
515 int is_pcie;
516 void *addr;
517 dma_addr_t bus_addr;
518 drm_local_map_t mapping;
519 } drm_ati_pcigart_info;
522 * Generic memory manager structs
524 typedef struct drm_mm_node {
525 struct list_head fl_entry;
526 struct list_head ml_entry;
527 int free;
528 unsigned long start;
529 unsigned long size;
530 void *private;
531 } drm_mm_node_t;
533 typedef struct drm_mm {
534 drm_mm_node_t root_node;
535 } drm_mm_t;
538 * DRM driver structure. This structure represent the common code for
539 * a family of cards. There will one drm_device for each card present
540 * in this family
542 struct drm_device;
544 struct drm_driver {
545 int (*load) (struct drm_device *, unsigned long flags);
546 int (*firstopen) (struct drm_device *);
547 int (*open) (struct drm_device *, drm_file_t *);
548 void (*preclose) (struct drm_device *, struct file * filp);
549 void (*postclose) (struct drm_device *, drm_file_t *);
550 void (*lastclose) (struct drm_device *);
551 int (*unload) (struct drm_device *);
552 int (*dma_ioctl) (DRM_IOCTL_ARGS);
553 void (*dma_ready) (struct drm_device *);
554 int (*dma_quiescent) (struct drm_device *);
555 int (*context_ctor) (struct drm_device * dev, int context);
556 int (*context_dtor) (struct drm_device * dev, int context);
557 int (*kernel_context_switch) (struct drm_device * dev, int old,
558 int new);
559 void (*kernel_context_switch_unlock) (struct drm_device * dev,
560 drm_lock_t *lock);
561 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
562 int (*dri_library_name) (struct drm_device *dev, char *buf);
565 * Called by \c drm_device_is_agp. Typically used to determine if a
566 * card is really attached to AGP or not.
568 * \param dev DRM device handle
570 * \returns
571 * One of three values is returned depending on whether or not the
572 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
573 * (return of 1), or may or may not be AGP (return of 2).
575 int (*device_is_agp) (struct drm_device * dev);
577 /* these have to be filled in */
579 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
580 void (*irq_preinstall) (struct drm_device * dev);
581 void (*irq_postinstall) (struct drm_device * dev);
582 void (*irq_uninstall) (struct drm_device * dev);
583 void (*reclaim_buffers) (struct drm_device * dev, struct file * filp);
584 void (*reclaim_buffers_locked) (struct drm_device *dev,
585 struct file *filp);
586 unsigned long (*get_map_ofs) (drm_map_t * map);
587 unsigned long (*get_reg_ofs) (struct drm_device * dev);
588 void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
590 int major;
591 int minor;
592 int patchlevel;
593 char *name;
594 char *desc;
595 char *date;
597 u32 driver_features;
598 int dev_priv_size;
599 drm_ioctl_desc_t *ioctls;
600 int num_ioctls;
601 struct file_operations fops;
602 struct pci_driver pci_driver;
606 * DRM head structure. This structure represent a video head on a card
607 * that may contain multiple heads. Embed one per head of these in the
608 * private drm_device structure.
610 typedef struct drm_head {
611 int minor; /**< Minor device number */
612 struct drm_device *dev;
613 struct proc_dir_entry *dev_root; /**< proc directory entry */
614 dev_t device; /**< Device number for mknod */
615 struct class_device *dev_class;
616 } drm_head_t;
619 * DRM device structure. This structure represent a complete card that
620 * may contain multiple heads.
622 typedef struct drm_device {
623 char *unique; /**< Unique identifier: e.g., busid */
624 int unique_len; /**< Length of unique field */
625 char *devname; /**< For /proc/interrupts */
626 int if_version; /**< Highest interface version set */
628 int blocked; /**< Blocked due to VC switch? */
630 /** \name Locks */
631 /*@{ */
632 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
633 struct mutex struct_mutex; /**< For others */
634 /*@} */
636 /** \name Usage Counters */
637 /*@{ */
638 int open_count; /**< Outstanding files open */
639 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
640 atomic_t vma_count; /**< Outstanding vma areas open */
641 int buf_use; /**< Buffers in use -- cannot alloc */
642 atomic_t buf_alloc; /**< Buffer allocation in progress */
643 /*@} */
645 /** \name Performance counters */
646 /*@{ */
647 unsigned long counters;
648 drm_stat_type_t types[15];
649 atomic_t counts[15];
650 /*@} */
652 /** \name Authentication */
653 /*@{ */
654 drm_file_t *file_first; /**< file list head */
655 drm_file_t *file_last; /**< file list tail */
656 drm_magic_head_t magiclist[DRM_HASH_SIZE]; /**< magic hash table */
657 /*@} */
659 /** \name Memory management */
660 /*@{ */
661 drm_map_list_t *maplist; /**< Linked list of regions */
662 int map_count; /**< Number of mappable regions */
664 /** \name Context handle management */
665 /*@{ */
666 drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
667 int ctx_count; /**< Number of context handles */
668 struct mutex ctxlist_mutex; /**< For ctxlist */
670 drm_map_t **context_sareas; /**< per-context SAREA's */
671 int max_context;
673 drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
674 drm_lock_data_t lock; /**< Information on hardware lock */
675 /*@} */
677 /** \name DMA queues (contexts) */
678 /*@{ */
679 int queue_count; /**< Number of active DMA queues */
680 int queue_reserved; /**< Number of reserved DMA queues */
681 int queue_slots; /**< Actual length of queuelist */
682 drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
683 drm_device_dma_t *dma; /**< Optional pointer for DMA support */
684 /*@} */
686 /** \name Context support */
687 /*@{ */
688 int irq; /**< Interrupt used by board */
689 int irq_enabled; /**< True if irq handler is enabled */
690 __volatile__ long context_flag; /**< Context swapping flag */
691 __volatile__ long interrupt_flag; /**< Interruption handler flag */
692 __volatile__ long dma_flag; /**< DMA dispatch flag */
693 struct timer_list timer; /**< Timer for delaying ctx switch */
694 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
695 int last_checked; /**< Last context checked for DMA */
696 int last_context; /**< Last current context */
697 unsigned long last_switch; /**< jiffies at last context switch */
698 /*@} */
700 struct work_struct work;
701 /** \name VBLANK IRQ support */
702 /*@{ */
704 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
705 atomic_t vbl_received;
706 spinlock_t vbl_lock;
707 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
708 unsigned int vbl_pending;
710 /*@} */
711 cycles_t ctx_start;
712 cycles_t lck_start;
714 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
715 wait_queue_head_t buf_readers; /**< Processes waiting to read */
716 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
718 drm_agp_head_t *agp; /**< AGP data */
720 struct pci_dev *pdev; /**< PCI device structure */
721 #ifdef __alpha__
722 struct pci_controller *hose;
723 #endif
724 drm_sg_mem_t *sg; /**< Scatter gather memory */
725 unsigned long *ctx_bitmap; /**< context bitmap */
726 void *dev_private; /**< device private data */
727 drm_sigdata_t sigdata; /**< For block_all_signals */
728 sigset_t sigmask;
730 struct drm_driver *driver;
731 drm_local_map_t *agp_buffer_map;
732 unsigned int agp_buffer_token;
733 drm_head_t primary; /**< primary screen head */
734 } drm_device_t;
736 static __inline__ int drm_core_check_feature(struct drm_device *dev,
737 int feature)
739 return ((dev->driver->driver_features & feature) ? 1 : 0);
742 #ifdef __alpha__
743 #define drm_get_pci_domain(dev) dev->hose->bus->number
744 #else
745 #define drm_get_pci_domain(dev) pci_domain_nr(dev->pdev->bus)
746 #endif
748 #if __OS_HAS_AGP
749 static inline int drm_core_has_AGP(struct drm_device *dev)
751 return drm_core_check_feature(dev, DRIVER_USE_AGP);
753 #else
754 #define drm_core_has_AGP(dev) (0)
755 #endif
757 #if __OS_HAS_MTRR
758 static inline int drm_core_has_MTRR(struct drm_device *dev)
760 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
763 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
765 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
766 unsigned int flags)
768 return mtrr_add(offset, size, flags, 1);
771 static inline int drm_mtrr_del(int handle, unsigned long offset,
772 unsigned long size, unsigned int flags)
774 return mtrr_del(handle, offset, size);
777 #else
778 #define drm_core_has_MTRR(dev) (0)
780 #define DRM_MTRR_WC 0
782 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
783 unsigned int flags)
785 return 0;
788 static inline int drm_mtrr_del(int handle, unsigned long offset,
789 unsigned long size, unsigned int flags)
791 return 0;
793 #endif
795 /******************************************************************/
796 /** \name Internal function definitions */
797 /*@{*/
799 /* Driver support (drm_drv.h) */
800 extern int drm_init(struct drm_driver *driver);
801 extern void drm_exit(struct drm_driver *driver);
802 extern int drm_ioctl(struct inode *inode, struct file *filp,
803 unsigned int cmd, unsigned long arg);
804 extern long drm_compat_ioctl(struct file *filp,
805 unsigned int cmd, unsigned long arg);
806 extern int drm_lastclose(drm_device_t *dev);
808 /* Device support (drm_fops.h) */
809 extern int drm_open(struct inode *inode, struct file *filp);
810 extern int drm_stub_open(struct inode *inode, struct file *filp);
811 extern int drm_fasync(int fd, struct file *filp, int on);
812 extern int drm_release(struct inode *inode, struct file *filp);
814 /* Mapping support (drm_vm.h) */
815 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
816 extern unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
818 /* Memory management support (drm_memory.h) */
819 #include "drm_memory.h"
820 extern void drm_mem_init(void);
821 extern int drm_mem_info(char *buf, char **start, off_t offset,
822 int request, int *eof, void *data);
823 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
824 extern void *drm_ioremap(unsigned long offset, unsigned long size,
825 drm_device_t * dev);
826 extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev);
828 extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
829 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
830 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
831 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
833 /* Misc. IOCTL support (drm_ioctl.h) */
834 extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
835 unsigned int cmd, unsigned long arg);
836 extern int drm_getunique(struct inode *inode, struct file *filp,
837 unsigned int cmd, unsigned long arg);
838 extern int drm_setunique(struct inode *inode, struct file *filp,
839 unsigned int cmd, unsigned long arg);
840 extern int drm_getmap(struct inode *inode, struct file *filp,
841 unsigned int cmd, unsigned long arg);
842 extern int drm_getclient(struct inode *inode, struct file *filp,
843 unsigned int cmd, unsigned long arg);
844 extern int drm_getstats(struct inode *inode, struct file *filp,
845 unsigned int cmd, unsigned long arg);
846 extern int drm_setversion(struct inode *inode, struct file *filp,
847 unsigned int cmd, unsigned long arg);
848 extern int drm_noop(struct inode *inode, struct file *filp,
849 unsigned int cmd, unsigned long arg);
851 /* Context IOCTL support (drm_context.h) */
852 extern int drm_resctx(struct inode *inode, struct file *filp,
853 unsigned int cmd, unsigned long arg);
854 extern int drm_addctx(struct inode *inode, struct file *filp,
855 unsigned int cmd, unsigned long arg);
856 extern int drm_modctx(struct inode *inode, struct file *filp,
857 unsigned int cmd, unsigned long arg);
858 extern int drm_getctx(struct inode *inode, struct file *filp,
859 unsigned int cmd, unsigned long arg);
860 extern int drm_switchctx(struct inode *inode, struct file *filp,
861 unsigned int cmd, unsigned long arg);
862 extern int drm_newctx(struct inode *inode, struct file *filp,
863 unsigned int cmd, unsigned long arg);
864 extern int drm_rmctx(struct inode *inode, struct file *filp,
865 unsigned int cmd, unsigned long arg);
867 extern int drm_ctxbitmap_init(drm_device_t * dev);
868 extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
869 extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
871 extern int drm_setsareactx(struct inode *inode, struct file *filp,
872 unsigned int cmd, unsigned long arg);
873 extern int drm_getsareactx(struct inode *inode, struct file *filp,
874 unsigned int cmd, unsigned long arg);
876 /* Drawable IOCTL support (drm_drawable.h) */
877 extern int drm_adddraw(struct inode *inode, struct file *filp,
878 unsigned int cmd, unsigned long arg);
879 extern int drm_rmdraw(struct inode *inode, struct file *filp,
880 unsigned int cmd, unsigned long arg);
882 /* Authentication IOCTL support (drm_auth.h) */
883 extern int drm_getmagic(struct inode *inode, struct file *filp,
884 unsigned int cmd, unsigned long arg);
885 extern int drm_authmagic(struct inode *inode, struct file *filp,
886 unsigned int cmd, unsigned long arg);
888 /* Locking IOCTL support (drm_lock.h) */
889 extern int drm_lock(struct inode *inode, struct file *filp,
890 unsigned int cmd, unsigned long arg);
891 extern int drm_unlock(struct inode *inode, struct file *filp,
892 unsigned int cmd, unsigned long arg);
893 extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
894 extern int drm_lock_free(drm_device_t * dev,
895 __volatile__ unsigned int *lock, unsigned int context);
897 /* Buffer management support (drm_bufs.h) */
898 extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
899 extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
900 extern int drm_addmap(drm_device_t * dev, unsigned int offset,
901 unsigned int size, drm_map_type_t type,
902 drm_map_flags_t flags, drm_local_map_t ** map_ptr);
903 extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
904 unsigned int cmd, unsigned long arg);
905 extern int drm_rmmap(drm_device_t * dev, drm_local_map_t * map);
906 extern int drm_rmmap_locked(drm_device_t * dev, drm_local_map_t * map);
907 extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
908 unsigned int cmd, unsigned long arg);
910 extern int drm_order(unsigned long size);
911 extern int drm_addbufs(struct inode *inode, struct file *filp,
912 unsigned int cmd, unsigned long arg);
913 extern int drm_infobufs(struct inode *inode, struct file *filp,
914 unsigned int cmd, unsigned long arg);
915 extern int drm_markbufs(struct inode *inode, struct file *filp,
916 unsigned int cmd, unsigned long arg);
917 extern int drm_freebufs(struct inode *inode, struct file *filp,
918 unsigned int cmd, unsigned long arg);
919 extern int drm_mapbufs(struct inode *inode, struct file *filp,
920 unsigned int cmd, unsigned long arg);
921 extern unsigned long drm_get_resource_start(drm_device_t * dev,
922 unsigned int resource);
923 extern unsigned long drm_get_resource_len(drm_device_t * dev,
924 unsigned int resource);
926 /* DMA support (drm_dma.h) */
927 extern int drm_dma_setup(drm_device_t * dev);
928 extern void drm_dma_takedown(drm_device_t * dev);
929 extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
930 extern void drm_core_reclaim_buffers(drm_device_t * dev, struct file *filp);
932 /* IRQ support (drm_irq.h) */
933 extern int drm_control(struct inode *inode, struct file *filp,
934 unsigned int cmd, unsigned long arg);
935 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
936 extern int drm_irq_uninstall(drm_device_t * dev);
937 extern void drm_driver_irq_preinstall(drm_device_t * dev);
938 extern void drm_driver_irq_postinstall(drm_device_t * dev);
939 extern void drm_driver_irq_uninstall(drm_device_t * dev);
941 extern int drm_wait_vblank(struct inode *inode, struct file *filp,
942 unsigned int cmd, unsigned long arg);
943 extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
944 extern void drm_vbl_send_signals(drm_device_t * dev);
946 /* AGP/GART support (drm_agpsupport.h) */
947 extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
948 extern int drm_agp_acquire(drm_device_t * dev);
949 extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
950 unsigned int cmd, unsigned long arg);
951 extern int drm_agp_release(drm_device_t * dev);
952 extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
953 unsigned int cmd, unsigned long arg);
954 extern int drm_agp_enable(drm_device_t * dev, drm_agp_mode_t mode);
955 extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
956 unsigned int cmd, unsigned long arg);
957 extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t * info);
958 extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
959 unsigned int cmd, unsigned long arg);
960 extern int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
961 extern int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
962 unsigned int cmd, unsigned long arg);
963 extern int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
964 extern int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
965 unsigned int cmd, unsigned long arg);
966 extern int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
967 extern int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
968 unsigned int cmd, unsigned long arg);
969 extern int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
970 extern int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
971 unsigned int cmd, unsigned long arg);
972 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge,
973 size_t pages, u32 type);
974 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
975 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
976 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
978 /* Stub support (drm_stub.h) */
979 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
980 struct drm_driver *driver);
981 extern int drm_put_dev(drm_device_t * dev);
982 extern int drm_put_head(drm_head_t * head);
983 extern unsigned int drm_debug;
984 extern unsigned int drm_cards_limit;
985 extern drm_head_t **drm_heads;
986 extern struct class *drm_class;
987 extern struct proc_dir_entry *drm_proc_root;
989 /* Proc support (drm_proc.h) */
990 extern int drm_proc_init(drm_device_t * dev,
991 int minor,
992 struct proc_dir_entry *root,
993 struct proc_dir_entry **dev_root);
994 extern int drm_proc_cleanup(int minor,
995 struct proc_dir_entry *root,
996 struct proc_dir_entry *dev_root);
998 /* Scatter Gather Support (drm_scatter.h) */
999 extern void drm_sg_cleanup(drm_sg_mem_t * entry);
1000 extern int drm_sg_alloc(struct inode *inode, struct file *filp,
1001 unsigned int cmd, unsigned long arg);
1002 extern int drm_sg_free(struct inode *inode, struct file *filp,
1003 unsigned int cmd, unsigned long arg);
1005 /* ATI PCIGART support (ati_pcigart.h) */
1006 extern int drm_ati_pcigart_init(drm_device_t * dev,
1007 drm_ati_pcigart_info * gart_info);
1008 extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
1009 drm_ati_pcigart_info * gart_info);
1011 extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
1012 size_t align, dma_addr_t maxaddr);
1013 extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
1014 extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah);
1016 /* sysfs support (drm_sysfs.c) */
1017 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1018 extern void drm_sysfs_destroy(struct class *cs);
1019 extern struct class_device *drm_sysfs_device_add(struct class *cs,
1020 drm_head_t *head);
1021 extern void drm_sysfs_device_remove(struct class_device *class_dev);
1024 * Basic memory manager support (drm_mm.c)
1026 extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent,
1027 unsigned long size,
1028 unsigned alignment);
1029 extern void drm_mm_put_block(drm_mm_t *mm, drm_mm_node_t *cur);
1030 extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
1031 unsigned alignment, int best_match);
1032 extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
1033 extern void drm_mm_takedown(drm_mm_t *mm);
1035 /* Inline replacements for DRM_IOREMAP macros */
1036 static __inline__ void drm_core_ioremap(struct drm_map *map,
1037 struct drm_device *dev)
1039 map->handle = drm_ioremap(map->offset, map->size, dev);
1042 #if 0
1043 static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
1044 struct drm_device *dev)
1046 map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
1048 #endif /* 0 */
1050 static __inline__ void drm_core_ioremapfree(struct drm_map *map,
1051 struct drm_device *dev)
1053 if (map->handle && map->size)
1054 drm_ioremapfree(map->handle, map->size, dev);
1057 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1058 unsigned int token)
1060 drm_map_list_t *_entry;
1061 list_for_each_entry(_entry, &dev->maplist->head, head)
1062 if (_entry->user_token == token)
1063 return _entry->map;
1064 return NULL;
1067 static __inline__ int drm_device_is_agp(drm_device_t * dev)
1069 if (dev->driver->device_is_agp != NULL) {
1070 int err = (*dev->driver->device_is_agp) (dev);
1072 if (err != 2) {
1073 return err;
1077 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1080 static __inline__ int drm_device_is_pcie(drm_device_t * dev)
1082 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1085 static __inline__ void drm_core_dropmap(struct drm_map *map)
1089 #ifndef DEBUG_MEMORY
1090 /** Wrapper around kmalloc() */
1091 static __inline__ void *drm_alloc(size_t size, int area)
1093 return kmalloc(size, GFP_KERNEL);
1096 /** Wrapper around kfree() */
1097 static __inline__ void drm_free(void *pt, size_t size, int area)
1099 kfree(pt);
1102 /** Wrapper around kcalloc() */
1103 static __inline__ void *drm_calloc(size_t nmemb, size_t size, int area)
1105 return kcalloc(nmemb, size, GFP_KERNEL);
1107 #else
1108 extern void *drm_alloc(size_t size, int area);
1109 extern void drm_free(void *pt, size_t size, int area);
1110 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1111 #endif
1113 /*@}*/
1115 extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
1116 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1118 #ifndef pci_pretty_name
1119 #define pci_pretty_name(dev) ""
1120 #endif
1122 #endif /* __KERNEL__ */
1123 #endif