3 * Private header for Direct Rendering Manager
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
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
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.
39 /* add include of current.h so that "current" is defined
40 * before static inline funcs in wait.h. Doing this so we
41 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
42 #include <asm/current.h>
43 #endif /* __alpha__ */
44 #include <linux/config.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/miscdevice.h>
49 #include <linux/proc_fs.h>
50 #include <linux/init.h>
51 #include <linux/file.h>
52 #include <linux/pci.h>
53 #include <linux/version.h>
54 #include <linux/sched.h>
55 #include <linux/smp_lock.h> /* For (un)lock_kernel */
57 #include <linux/pagemap.h>
58 #if defined(__alpha__) || defined(__powerpc__)
59 #include <asm/pgtable.h> /* For pte_wrprotect */
63 #include <asm/uaccess.h>
67 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
68 #include <linux/types.h>
69 #include <linux/agp_backend.h>
71 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,41)
72 #define HAS_WORKQUEUE 0
74 #define HAS_WORKQUEUE 1
77 #include <linux/tqueue.h>
79 #include <linux/workqueue.h>
81 #include <linux/poll.h>
82 #include <asm/pgalloc.h>
83 #include <linux/sysdev.h>
86 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
87 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
89 #include "drm_os_linux.h"
91 /* If you want the memory alloc debug functionality, change define below */
92 /* #define DEBUG_MEMORY */
94 /***********************************************************************/
95 /** \name DRM template customization defaults */
98 /* driver capabilities and requirements mask */
99 #define DRIVER_USE_AGP 0x1
100 #define DRIVER_REQUIRE_AGP 0x2
101 #define DRIVER_USE_MTRR 0x4
102 #define DRIVER_PCI_DMA 0x8
103 #define DRIVER_SG 0x10
104 #define DRIVER_FB_DMA 0x20
105 #define DRIVER_HAVE_DMA 0x40
106 #define DRIVER_HAVE_IRQ 0x80
107 #define DRIVER_IRQ_SHARED 0x100
108 #define DRIVER_IRQ_VBL 0x200
109 #define DRIVER_DMA_QUEUE 0x400
113 /***********************************************************************/
114 /** \name Begin the DRM... */
117 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
118 also include looping detection. */
120 #define DRM_HASH_SIZE 16 /**< Size of key hash table. Must be power of 2. */
121 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
122 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
123 #define DRM_LOOPING_LIMIT 5000000
124 #define DRM_BSZ 1024 /**< Buffer size for /dev/drm? output */
125 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
126 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
128 #define DRM_FLAG_DEBUG 0x01
130 #define DRM_MEM_DMA 0
131 #define DRM_MEM_SAREA 1
132 #define DRM_MEM_DRIVER 2
133 #define DRM_MEM_MAGIC 3
134 #define DRM_MEM_IOCTLS 4
135 #define DRM_MEM_MAPS 5
136 #define DRM_MEM_VMAS 6
137 #define DRM_MEM_BUFS 7
138 #define DRM_MEM_SEGS 8
139 #define DRM_MEM_PAGES 9
140 #define DRM_MEM_FILES 10
141 #define DRM_MEM_QUEUES 11
142 #define DRM_MEM_CMDS 12
143 #define DRM_MEM_MAPPINGS 13
144 #define DRM_MEM_BUFLISTS 14
145 #define DRM_MEM_AGPLISTS 15
146 #define DRM_MEM_TOTALAGP 16
147 #define DRM_MEM_BOUNDAGP 17
148 #define DRM_MEM_CTXBITMAP 18
149 #define DRM_MEM_STUB 19
150 #define DRM_MEM_SGLISTS 20
151 #define DRM_MEM_CTXLIST 21
153 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
157 #include "drm_compat.h"
159 /***********************************************************************/
160 /** \name Macros to make printk easier */
166 * \param fmt printf() like format string.
167 * \param arg arguments
169 #define DRM_ERROR(fmt, arg...) \
170 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
173 * Memory error output.
175 * \param area memory area where the error occurred.
176 * \param fmt printf() like format string.
177 * \param arg arguments
179 #define DRM_MEM_ERROR(area, fmt, arg...) \
180 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
181 drm_mem_stats[area].name , ##arg)
182 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
187 * \param fmt printf() like format string.
188 * \param arg arguments
191 #define DRM_DEBUG(fmt, arg...) \
195 "[" DRM_NAME ":%s] " fmt , \
196 __FUNCTION__ , ##arg); \
199 #define DRM_DEBUG(fmt, arg...) do { } while (0)
202 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
204 #define DRM_PROC_PRINT(fmt, arg...) \
205 len += sprintf(&buf[len], fmt , ##arg); \
206 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
208 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
209 len += sprintf(&buf[len], fmt , ##arg); \
210 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
214 /***********************************************************************/
215 /** \name Internal types and structures */
218 #define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
219 #define DRM_MIN(a,b) ((a)<(b)?(a):(b))
220 #define DRM_MAX(a,b) ((a)>(b)?(a):(b))
222 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
223 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
224 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
226 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
228 * Get the private SAREA mapping.
230 * \param _dev DRM device.
231 * \param _ctx context number.
232 * \param _map output mapping.
234 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
235 (_map) = (_dev)->context_sareas[_ctx]; \
239 * Test that the hardware lock is held by the caller, returning otherwise.
241 * \param dev DRM device.
242 * \param filp file pointer of the caller.
244 #define LOCK_TEST_WITH_RETURN( dev, filp ) \
246 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
247 dev->lock.filp != filp ) { \
248 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
249 __FUNCTION__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
250 dev->lock.filp, filp ); \
256 * Copy and IOCTL return string to user space
258 #define DRM_COPY( name, value ) \
259 len = strlen( value ); \
260 if ( len > name##_len ) len = name##_len; \
261 name##_len = strlen( value ); \
262 if ( len && name ) { \
263 if ( copy_to_user( name, value, len ) ) \
268 * Ioctl function type.
270 * \param inode device inode.
271 * \param filp file pointer.
272 * \param cmd command.
273 * \param arg argument.
275 typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
276 unsigned int cmd, unsigned long arg);
278 typedef struct drm_ioctl_desc {
284 typedef struct drm_devstate {
285 pid_t owner; /**< X server pid holding x_lock */
288 typedef struct drm_magic_entry {
290 struct drm_file *priv;
291 struct drm_magic_entry *next;
294 typedef struct drm_magic_head {
295 struct drm_magic_entry *head;
296 struct drm_magic_entry *tail;
299 typedef struct drm_vma_entry {
300 struct vm_area_struct *vma;
301 struct drm_vma_entry *next;
308 typedef struct drm_buf {
309 int idx; /**< Index into master buflist */
310 int total; /**< Buffer size */
311 int order; /**< log-base-2(total) */
312 int used; /**< Amount of buffer in use (for DMA) */
313 unsigned long offset; /**< Byte offset (used internally) */
314 void *address; /**< Address of buffer */
315 unsigned long bus_address; /**< Bus address of buffer */
316 struct drm_buf *next; /**< Kernel-only: used for free list */
317 __volatile__ int waiting; /**< On kernel DMA queue */
318 __volatile__ int pending; /**< On hardware DMA queue */
319 wait_queue_head_t dma_wait; /**< Processes waiting */
320 struct file *filp; /**< Pointer to holding file descr */
321 int context; /**< Kernel queue for this buffer */
322 int while_locked; /**< Dispatch this buffer while locked */
330 } list; /**< Which list we're on */
332 int dev_priv_size; /**< Size of buffer private storage */
333 void *dev_private; /**< Per-buffer private storage */
336 /** bufs is one longer than it has to be */
337 typedef struct drm_waitlist {
338 int count; /**< Number of possible buffers */
339 drm_buf_t **bufs; /**< List of pointers to buffers */
340 drm_buf_t **rp; /**< Read pointer */
341 drm_buf_t **wp; /**< Write pointer */
342 drm_buf_t **end; /**< End pointer */
343 spinlock_t read_lock;
344 spinlock_t write_lock;
347 typedef struct drm_freelist {
348 int initialized; /**< Freelist in use */
349 atomic_t count; /**< Number of free buffers */
350 drm_buf_t *next; /**< End pointer */
352 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
353 int low_mark; /**< Low water mark */
354 int high_mark; /**< High water mark */
355 atomic_t wfh; /**< If waiting for high mark */
360 * Buffer entry. There is one of this for each buffer size order.
362 typedef struct drm_buf_entry {
363 int buf_size; /**< size */
364 int buf_count; /**< number of buffers */
365 drm_buf_t *buflist; /**< buffer list */
368 unsigned long *seglist;
370 drm_freelist_t freelist;
373 /** File private data */
374 typedef struct drm_file {
380 unsigned long ioctl_count;
381 struct drm_file *next;
382 struct drm_file *prev;
383 struct drm_head *head;
384 int remove_auth_on_close;
385 unsigned long lock_count;
390 typedef struct drm_queue {
391 atomic_t use_count; /**< Outstanding uses (+1) */
392 atomic_t finalization; /**< Finalization in progress */
393 atomic_t block_count; /**< Count of processes waiting */
394 atomic_t block_read; /**< Queue blocked for reads */
395 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
396 atomic_t block_write; /**< Queue blocked for writes */
397 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
399 atomic_t total_queued; /**< Total queued statistic */
400 atomic_t total_flushed; /**< Total flushes statistic */
401 atomic_t total_locks; /**< Total locks statistics */
403 drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
404 drm_waitlist_t waitlist; /**< Pending buffers */
405 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
411 typedef struct drm_lock_data {
412 drm_hw_lock_t *hw_lock; /**< Hardware lock */
413 struct file *filp; /**< File descr of lock holder (0=kernel) */
414 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
415 unsigned long lock_time; /**< Time of last lock in jiffies */
421 typedef struct drm_device_dma {
423 drm_buf_entry_t bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
424 int buf_count; /**< total number of buffers */
425 drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
427 int page_count; /**< number of pages */
428 unsigned long *pagelist; /**< page list */
429 unsigned long byte_count;
431 _DRM_DMA_USE_AGP = 0x01,
432 _DRM_DMA_USE_SG = 0x02,
433 _DRM_DMA_USE_FB = 0x04
439 * AGP memory entry. Stored as a doubly linked list.
441 typedef struct drm_agp_mem {
442 unsigned long handle; /**< handle */
444 unsigned long bound; /**< address */
446 struct drm_agp_mem *prev; /**< previous entry */
447 struct drm_agp_mem *next; /**< next entry */
453 * \sa drm_agp_init)() and drm_device::agp.
455 typedef struct drm_agp_head {
456 DRM_AGP_KERN agp_info; /**< AGP device information */
457 drm_agp_mem_t *memory; /**< memory entries */
458 unsigned long mode; /**< AGP mode */
459 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
460 struct agp_bridge_data *bridge;
462 int enabled; /**< whether the AGP bus as been enabled */
463 int acquired; /**< whether the AGP device has been acquired */
466 int cant_use_aperture;
467 unsigned long page_mask;
471 * Scatter-gather memory.
473 typedef struct drm_sg_mem {
474 unsigned long handle;
477 struct page **pagelist;
481 typedef struct drm_sigdata {
486 typedef struct drm_dma_handle {
495 typedef struct drm_map_list {
496 struct list_head head; /**< list head */
497 drm_map_t *map; /**< mapping */
500 typedef drm_map_t drm_local_map_t;
503 * Context handle list
505 typedef struct drm_ctx_list {
506 struct list_head head; /**< list head */
507 drm_context_t handle; /**< context handle */
508 drm_file_t *tag; /**< associated fd private data */
511 typedef struct drm_vbl_sig {
512 struct list_head head;
513 unsigned int sequence;
515 struct task_struct *task;
519 * DRM driver structure. This structure represent the common code for
520 * a family of cards. There will one drm_device for each card present
525 int (*preinit) (struct drm_device *, unsigned long flags);
526 void (*prerelease) (struct drm_device *, struct file * filp);
527 void (*pretakedown) (struct drm_device *);
528 int (*postcleanup) (struct drm_device *);
529 int (*presetup) (struct drm_device *);
530 int (*postsetup) (struct drm_device *);
531 int (*dma_ioctl) (DRM_IOCTL_ARGS);
532 /* these are opposites at the moment */
533 int (*open_helper) (struct drm_device *, drm_file_t *);
534 void (*free_filp_priv) (struct drm_device *, drm_file_t *);
536 void (*release) (struct drm_device *, struct file * filp);
537 void (*dma_ready) (struct drm_device *);
538 int (*dma_quiescent) (struct drm_device *);
539 int (*context_ctor) (struct drm_device * dev, int context);
540 int (*context_dtor) (struct drm_device * dev, int context);
541 int (*kernel_context_switch) (struct drm_device * dev, int old,
543 int (*kernel_context_switch_unlock) (struct drm_device * dev);
544 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
545 int (*power) (struct drm_device * dev, unsigned int state);
548 * Called by \c drm_device_is_agp. Typically used to determine if a
549 * card is really attached to AGP or not.
551 * \param dev DRM device handle
554 * One of three values is returned depending on whether or not the
555 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
556 * (return of 1), or may or may not be AGP (return of 2).
558 int (*device_is_agp) (struct drm_device * dev);
560 /* these have to be filled in */
561 int (*postinit) (struct drm_device *, unsigned long flags);
562 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
563 void (*irq_preinstall) (struct drm_device * dev);
564 void (*irq_postinstall) (struct drm_device * dev);
565 void (*irq_uninstall) (struct drm_device * dev);
566 void (*reclaim_buffers) (struct drm_device *dev, struct file * filp);
567 unsigned long (*get_map_ofs) (drm_map_t * map);
568 unsigned long (*get_reg_ofs) (struct drm_device * dev);
569 void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
570 int (*version) (drm_version_t * version);
575 drm_ioctl_desc_t *ioctls;
577 struct file_operations fops;
578 struct pci_driver pci_driver;
582 * DRM head structure. This structure represent a video head on a card
583 * that may contain multiple heads. Embed one per head of these in the
584 * private drm_device structure.
586 typedef struct drm_head {
587 int minor; /**< Minor device number */
588 struct drm_device *dev;
589 struct proc_dir_entry *dev_root; /**< proc directory entry */
590 dev_t device; /**< Device number for mknod */
591 struct class_device *dev_class;
595 * DRM device structure. This structure represent a complete card that
596 * may contain multiple heads.
598 typedef struct drm_device {
599 char *unique; /**< Unique identifier: e.g., busid */
600 int unique_len; /**< Length of unique field */
601 char *devname; /**< For /proc/interrupts */
602 int if_version; /**< Highest interface version set */
604 int blocked; /**< Blocked due to VC switch? */
608 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
609 struct semaphore struct_sem; /**< For others */
612 /** \name Usage Counters */
614 int open_count; /**< Outstanding files open */
615 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
616 atomic_t vma_count; /**< Outstanding vma areas open */
617 int buf_use; /**< Buffers in use -- cannot alloc */
618 atomic_t buf_alloc; /**< Buffer allocation in progress */
621 /** \name Performance counters */
623 unsigned long counters;
624 drm_stat_type_t types[15];
628 /** \name Authentication */
630 drm_file_t *file_first; /**< file list head */
631 drm_file_t *file_last; /**< file list tail */
632 drm_magic_head_t magiclist[DRM_HASH_SIZE]; /**< magic hash table */
635 /** \name Memory management */
637 drm_map_list_t *maplist; /**< Linked list of regions */
638 int map_count; /**< Number of mappable regions */
640 /** \name Context handle management */
642 drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
643 int ctx_count; /**< Number of context handles */
644 struct semaphore ctxlist_sem; /**< For ctxlist */
646 drm_map_t **context_sareas; /**< per-context SAREA's */
649 drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
650 drm_lock_data_t lock; /**< Information on hardware lock */
653 /** \name DMA queues (contexts) */
655 int queue_count; /**< Number of active DMA queues */
656 int queue_reserved; /**< Number of reserved DMA queues */
657 int queue_slots; /**< Actual length of queuelist */
658 drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
659 drm_device_dma_t *dma; /**< Optional pointer for DMA support */
662 /** \name Context support */
664 int irq; /**< Interrupt used by board */
665 int irq_enabled; /**< True if irq handler is enabled */
666 __volatile__ long context_flag; /**< Context swapping flag */
667 __volatile__ long interrupt_flag; /**< Interruption handler flag */
668 __volatile__ long dma_flag; /**< DMA dispatch flag */
669 struct timer_list timer; /**< Timer for delaying ctx switch */
670 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
671 int last_checked; /**< Last context checked for DMA */
672 int last_context; /**< Last current context */
673 unsigned long last_switch; /**< jiffies at last context switch */
679 struct work_struct work;
681 /** \name VBLANK IRQ support */
684 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
685 atomic_t vbl_received;
687 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
688 unsigned int vbl_pending;
694 char buf[DRM_BSZ]; /**< Output buffer */
695 char *buf_rp; /**< Read pointer */
696 char *buf_wp; /**< Write pointer */
697 char *buf_end; /**< End pointer */
698 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
699 wait_queue_head_t buf_readers; /**< Processes waiting to read */
700 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
702 drm_agp_head_t *agp; /**< AGP data */
704 struct pci_dev *pdev; /**< PCI device structure */
705 int pci_domain; /**< PCI bus domain number */
706 int pci_bus; /**< PCI bus number */
707 int pci_slot; /**< PCI slot number */
708 int pci_func; /**< PCI function number */
710 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3)
711 struct pci_controler *hose;
713 struct pci_controller *hose;
716 drm_sg_mem_t *sg; /**< Scatter gather memory */
717 unsigned long *ctx_bitmap; /**< context bitmap */
718 void *dev_private; /**< device private data */
719 drm_sigdata_t sigdata; /**< For block_all_signals */
722 struct drm_driver *driver;
723 drm_local_map_t *agp_buffer_map;
724 drm_head_t primary; /**< primary screen head */
726 struct sys_device sysdev; /**< Power Management device structure */
727 int sysdev_registered; /**< Whether the device has been registered */
730 static __inline__ int drm_core_check_feature(struct drm_device *dev,
733 return ((dev->driver->driver_features & feature) ? 1 : 0);
737 static inline int drm_core_has_AGP(struct drm_device *dev)
739 return drm_core_check_feature(dev, DRIVER_USE_AGP);
742 #define drm_core_has_AGP(dev) (0)
746 static inline int drm_core_has_MTRR(struct drm_device *dev)
748 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
751 #define drm_core_has_MTRR(dev) (0)
754 /******************************************************************/
755 /** \name Internal function definitions */
758 /* Driver support (drm_drv.h) */
759 extern int drm_fb_loaded;
760 extern int __devinit drm_init(struct drm_driver *driver,
761 struct pci_device_id *pciidlist);
762 extern void __exit drm_exit(struct drm_driver *driver);
763 extern void __exit drm_cleanup_pci(struct pci_dev *pdev);
764 extern int drm_ioctl(struct inode *inode, struct file *filp,
765 unsigned int cmd, unsigned long arg);
766 extern int drm_takedown(drm_device_t * dev);
768 /* Device support (drm_fops.h) */
769 extern int drm_open(struct inode *inode, struct file *filp);
770 extern int drm_stub_open(struct inode *inode, struct file *filp);
771 extern int drm_fasync(int fd, struct file *filp, int on);
772 extern int drm_release(struct inode *inode, struct file *filp);
773 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
775 /* Mapping support (drm_vm.h) */
776 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
777 extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
778 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
780 /* Memory management support (drm_memory.h) */
781 #include "drm_memory.h"
782 extern void drm_mem_init(void);
783 extern int drm_mem_info(char *buf, char **start, off_t offset,
784 int request, int *eof, void *data);
785 extern void *drm_calloc(size_t nmemb, size_t size, int area);
786 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
787 extern unsigned long drm_alloc_pages(int order, int area);
788 extern void drm_free_pages(unsigned long address, int order, int area);
789 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
790 extern DRM_AGP_MEM *drm_alloc_agp(int pages, u32 type);
792 extern DRM_AGP_MEM *drm_alloc_agp(struct agp_bridge_data *bridge, int pages, u32 type);
794 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
795 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
796 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
798 /* Misc. IOCTL support (drm_ioctl.h) */
799 extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
800 unsigned int cmd, unsigned long arg);
801 extern int drm_getunique(struct inode *inode, struct file *filp,
802 unsigned int cmd, unsigned long arg);
803 extern int drm_setunique(struct inode *inode, struct file *filp,
804 unsigned int cmd, unsigned long arg);
805 extern int drm_getmap(struct inode *inode, struct file *filp,
806 unsigned int cmd, unsigned long arg);
807 extern int drm_getclient(struct inode *inode, struct file *filp,
808 unsigned int cmd, unsigned long arg);
809 extern int drm_getstats(struct inode *inode, struct file *filp,
810 unsigned int cmd, unsigned long arg);
811 extern int drm_setversion(struct inode *inode, struct file *filp,
812 unsigned int cmd, unsigned long arg);
813 extern int drm_noop(struct inode *inode, struct file *filp,
814 unsigned int cmd, unsigned long arg);
816 /* Context IOCTL support (drm_context.h) */
817 extern int drm_resctx(struct inode *inode, struct file *filp,
818 unsigned int cmd, unsigned long arg);
819 extern int drm_addctx(struct inode *inode, struct file *filp,
820 unsigned int cmd, unsigned long arg);
821 extern int drm_modctx(struct inode *inode, struct file *filp,
822 unsigned int cmd, unsigned long arg);
823 extern int drm_getctx(struct inode *inode, struct file *filp,
824 unsigned int cmd, unsigned long arg);
825 extern int drm_switchctx(struct inode *inode, struct file *filp,
826 unsigned int cmd, unsigned long arg);
827 extern int drm_newctx(struct inode *inode, struct file *filp,
828 unsigned int cmd, unsigned long arg);
829 extern int drm_rmctx(struct inode *inode, struct file *filp,
830 unsigned int cmd, unsigned long arg);
832 extern int drm_context_switch_complete(drm_device_t * dev, int new);
834 extern int drm_ctxbitmap_init(drm_device_t * dev);
835 extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
836 extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
838 extern int drm_setsareactx(struct inode *inode, struct file *filp,
839 unsigned int cmd, unsigned long arg);
840 extern int drm_getsareactx(struct inode *inode, struct file *filp,
841 unsigned int cmd, unsigned long arg);
843 /* Drawable IOCTL support (drm_drawable.h) */
844 extern int drm_adddraw(struct inode *inode, struct file *filp,
845 unsigned int cmd, unsigned long arg);
846 extern int drm_rmdraw(struct inode *inode, struct file *filp,
847 unsigned int cmd, unsigned long arg);
849 /* Authentication IOCTL support (drm_auth.h) */
850 extern int drm_getmagic(struct inode *inode, struct file *filp,
851 unsigned int cmd, unsigned long arg);
852 extern int drm_authmagic(struct inode *inode, struct file *filp,
853 unsigned int cmd, unsigned long arg);
855 /* Locking IOCTL support (drm_lock.h) */
856 extern int drm_lock(struct inode *inode, struct file *filp,
857 unsigned int cmd, unsigned long arg);
858 extern int drm_unlock(struct inode *inode, struct file *filp,
859 unsigned int cmd, unsigned long arg);
860 extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
861 extern int drm_lock_free(drm_device_t * dev,
862 __volatile__ unsigned int *lock, unsigned int context);
864 /* Buffer management support (drm_bufs.h) */
865 extern int drm_addmap(struct inode *inode, struct file *filp,
866 unsigned int cmd, unsigned long arg);
867 extern int drm_rmmap(struct inode *inode, struct file *filp,
868 unsigned int cmd, unsigned long arg);
869 extern int drm_initmap(drm_device_t * dev, unsigned int offset,
870 unsigned int size, unsigned int resource, int type,
872 extern int drm_addbufs(struct inode *inode, struct file *filp,
873 unsigned int cmd, unsigned long arg);
874 extern int drm_infobufs(struct inode *inode, struct file *filp,
875 unsigned int cmd, unsigned long arg);
876 extern int drm_markbufs(struct inode *inode, struct file *filp,
877 unsigned int cmd, unsigned long arg);
878 extern int drm_freebufs(struct inode *inode, struct file *filp,
879 unsigned int cmd, unsigned long arg);
880 extern int drm_mapbufs(struct inode *inode, struct file *filp,
881 unsigned int cmd, unsigned long arg);
882 extern int drm_order(unsigned long size);
883 extern unsigned long drm_get_resource_start(drm_device_t *dev,
884 unsigned int resource);
885 extern unsigned long drm_get_resource_len(drm_device_t *dev,
886 unsigned int resource);
888 /* Power Management (drm_pm.h) */
889 extern int drm_pm_setup(drm_device_t *dev);
890 extern void drm_pm_takedown(drm_device_t *dev);
891 extern int drm_pm_init(void);
892 extern void drm_pm_cleanup(void);
894 /* DMA support (drm_dma.h) */
895 extern int drm_dma_setup(drm_device_t * dev);
896 extern void drm_dma_takedown(drm_device_t * dev);
897 extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
898 extern void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp);
900 /* IRQ support (drm_irq.h) */
901 extern int drm_control(struct inode *inode, struct file *filp,
902 unsigned int cmd, unsigned long arg);
903 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
904 extern int drm_irq_uninstall(drm_device_t *dev);
905 extern void drm_driver_irq_preinstall(drm_device_t * dev);
906 extern void drm_driver_irq_postinstall(drm_device_t * dev);
907 extern void drm_driver_irq_uninstall(drm_device_t * dev);
909 extern int drm_wait_vblank(struct inode *inode, struct file *filp,
910 unsigned int cmd, unsigned long arg);
911 extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
912 extern void drm_vbl_send_signals(drm_device_t * dev);
914 /* AGP/GART support (drm_agpsupport.h) */
915 extern drm_agp_head_t *drm_agp_init(drm_device_t *dev);
916 extern int drm_agp_acquire(struct inode *inode, struct file *filp,
917 unsigned int cmd, unsigned long arg);
918 extern void drm_agp_do_release(drm_device_t *dev);
919 extern int drm_agp_release(struct inode *inode, struct file *filp,
920 unsigned int cmd, unsigned long arg);
921 extern int drm_agp_enable(struct inode *inode, struct file *filp,
922 unsigned int cmd, unsigned long arg);
923 extern int drm_agp_info(struct inode *inode, struct file *filp,
924 unsigned int cmd, unsigned long arg);
925 extern int drm_agp_alloc(struct inode *inode, struct file *filp,
926 unsigned int cmd, unsigned long arg);
927 extern int drm_agp_free(struct inode *inode, struct file *filp,
928 unsigned int cmd, unsigned long arg);
929 extern int drm_agp_unbind(struct inode *inode, struct file *filp,
930 unsigned int cmd, unsigned long arg);
931 extern int drm_agp_bind(struct inode *inode, struct file *filp,
932 unsigned int cmd, unsigned long arg);
933 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
934 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
936 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
938 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
939 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
940 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
942 /* Stub support (drm_stub.h) */
943 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
944 struct drm_driver *driver);
945 extern int drm_put_dev(drm_device_t * dev);
946 extern int drm_put_head(drm_head_t * head);
947 extern unsigned int drm_debug; /* 1 to enable debug output */
948 extern unsigned int cards_limit;
949 extern drm_head_t **drm_heads;
950 extern struct drm_sysfs_class *drm_class;
951 extern struct proc_dir_entry *drm_proc_root;
953 /* Proc support (drm_proc.h) */
954 extern int drm_proc_init(drm_device_t * dev,
956 struct proc_dir_entry *root,
957 struct proc_dir_entry **dev_root);
958 extern int drm_proc_cleanup(int minor,
959 struct proc_dir_entry *root,
960 struct proc_dir_entry *dev_root);
962 /* Scatter Gather Support (drm_scatter.h) */
963 extern void drm_sg_cleanup(drm_sg_mem_t * entry);
964 extern int drm_sg_alloc(struct inode *inode, struct file *filp,
965 unsigned int cmd, unsigned long arg);
966 extern int drm_sg_free(struct inode *inode, struct file *filp,
967 unsigned int cmd, unsigned long arg);
969 /* ATI PCIGART support (ati_pcigart.h) */
970 extern int drm_ati_pcigart_init(drm_device_t * dev,
971 unsigned long *addr, dma_addr_t * bus_addr);
972 extern int drm_ati_pcigart_cleanup(drm_device_t * dev,
973 unsigned long addr, dma_addr_t bus_addr);
975 extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
976 size_t align, dma_addr_t maxaddr);
977 extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t *dmah);
978 extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t *dmah);
980 /* sysfs support (drm_sysfs.c) */
981 struct drm_sysfs_class;
982 extern struct drm_sysfs_class *drm_sysfs_create(struct module *owner,
984 extern void drm_sysfs_destroy(struct drm_sysfs_class *cs);
985 extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
987 struct device *device,
988 const char *fmt, ...);
989 extern void drm_sysfs_device_remove(dev_t dev);
991 /* Inline replacements for DRM_IOREMAP macros */
992 static __inline__ void drm_core_ioremap(struct drm_map *map,
993 struct drm_device *dev)
995 map->handle = drm_ioremap(map->offset, map->size, dev);
998 static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
999 struct drm_device *dev)
1001 map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
1004 static __inline__ void drm_core_ioremapfree(struct drm_map *map,
1005 struct drm_device *dev)
1007 if (map->handle && map->size)
1008 drm_ioremapfree(map->handle, map->size, dev);
1011 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1012 unsigned long offset)
1014 struct list_head *_list;
1015 list_for_each(_list, &dev->maplist->head) {
1016 drm_map_list_t *_entry =
1017 list_entry(_list, drm_map_list_t, head);
1018 if (_entry->map && _entry->map->offset == offset) {
1025 static __inline__ int drm_device_is_agp(drm_device_t *dev)
1027 if ( dev->driver->device_is_agp != NULL ) {
1028 int err = (*dev->driver->device_is_agp)( dev );
1035 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1038 static __inline__ void drm_core_dropmap(struct drm_map *map)
1042 #ifndef DEBUG_MEMORY
1043 /** Wrapper around kmalloc() */
1044 static __inline__ void *drm_alloc(size_t size, int area)
1046 return kmalloc(size, GFP_KERNEL);
1049 /** Wrapper around kfree() */
1050 static __inline__ void drm_free(void *pt, size_t size, int area)
1055 extern void *drm_alloc(size_t size, int area);
1056 extern void drm_free(void *pt, size_t size, int area);
1061 #endif /* __KERNEL__ */