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/module.h>
45 #include <linux/kernel.h>
46 #include <linux/miscdevice.h>
48 #include <linux/proc_fs.h>
49 #include <linux/init.h>
50 #include <linux/file.h>
51 #include <linux/pci.h>
52 #include <linux/version.h>
53 #include <linux/sched.h>
54 #include <linux/smp_lock.h> /* For (un)lock_kernel */
56 #include <linux/pagemap.h>
57 #include <linux/i2c.h>
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
59 #include <linux/mutex.h>
61 #if defined(__alpha__) || defined(__powerpc__)
62 #include <asm/pgtable.h> /* For pte_wrprotect */
66 #include <asm/uaccess.h>
70 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
72 #include <linux/types.h>
73 #include <linux/agp_backend.h>
75 #include <linux/workqueue.h>
76 #include <linux/poll.h>
77 #include <asm/pgalloc.h>
79 #include <linux/slab.h>
80 #include <linux/idr.h>
82 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
83 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
93 #include "drm_os_linux.h"
94 #include "drm_hashtab.h"
95 #include "drm_internal.h"
100 /* If you want the memory alloc debug functionality, change define below */
101 /* #define DEBUG_MEMORY */
103 /***********************************************************************/
104 /** \name DRM template customization defaults */
107 /* driver capabilities and requirements mask */
108 #define DRIVER_USE_AGP 0x1
109 #define DRIVER_REQUIRE_AGP 0x2
110 #define DRIVER_USE_MTRR 0x4
111 #define DRIVER_PCI_DMA 0x8
112 #define DRIVER_SG 0x10
113 #define DRIVER_HAVE_DMA 0x20
114 #define DRIVER_HAVE_IRQ 0x40
115 #define DRIVER_IRQ_SHARED 0x80
116 #define DRIVER_IRQ_VBL 0x100
117 #define DRIVER_DMA_QUEUE 0x200
118 #define DRIVER_FB_DMA 0x400
119 #define DRIVER_IRQ_VBL2 0x800
124 /***********************************************************************/
125 /** \name Begin the DRM... */
128 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
129 also include looping detection. */
131 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
132 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
133 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
134 #define DRM_LOOPING_LIMIT 5000000
135 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
136 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
138 #define DRM_FLAG_DEBUG 0x01
140 #define DRM_MEM_DMA 0
141 #define DRM_MEM_SAREA 1
142 #define DRM_MEM_DRIVER 2
143 #define DRM_MEM_MAGIC 3
144 #define DRM_MEM_IOCTLS 4
145 #define DRM_MEM_MAPS 5
146 #define DRM_MEM_VMAS 6
147 #define DRM_MEM_BUFS 7
148 #define DRM_MEM_SEGS 8
149 #define DRM_MEM_PAGES 9
150 #define DRM_MEM_FILES 10
151 #define DRM_MEM_QUEUES 11
152 #define DRM_MEM_CMDS 12
153 #define DRM_MEM_MAPPINGS 13
154 #define DRM_MEM_BUFLISTS 14
155 #define DRM_MEM_AGPLISTS 15
156 #define DRM_MEM_TOTALAGP 16
157 #define DRM_MEM_BOUNDAGP 17
158 #define DRM_MEM_CTXBITMAP 18
159 #define DRM_MEM_STUB 19
160 #define DRM_MEM_SGLISTS 20
161 #define DRM_MEM_CTXLIST 21
162 #define DRM_MEM_MM 22
163 #define DRM_MEM_HASHTAB 23
164 #define DRM_MEM_OBJECTS 24
165 #define DRM_MEM_FENCE 25
166 #define DRM_MEM_TTM 26
167 #define DRM_MEM_BUFOBJ 27
169 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
170 #define DRM_MAP_HASH_OFFSET 0x10000000
171 #define DRM_MAP_HASH_ORDER 12
172 #define DRM_OBJECT_HASH_ORDER 12
173 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
174 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
176 * This should be small enough to allow the use of kmalloc for hash tables
177 * instead of vmalloc.
180 #define DRM_FILE_HASH_ORDER 8
181 #define DRM_MM_INIT_MAX_PAGES 256
185 #include "drm_compat.h"
188 /***********************************************************************/
189 /** \name Macros to make printk easier */
195 * \param fmt printf() like format string.
196 * \param arg arguments
198 #define DRM_ERROR(fmt, arg...) \
199 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
202 * Memory error output.
204 * \param area memory area where the error occurred.
205 * \param fmt printf() like format string.
206 * \param arg arguments
208 #define DRM_MEM_ERROR(area, fmt, arg...) \
209 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
210 drm_mem_stats[area].name , ##arg)
211 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
216 * \param fmt printf() like format string.
217 * \param arg arguments
220 #define DRM_DEBUG(fmt, arg...) \
224 "[" DRM_NAME ":%s] " fmt , \
225 __FUNCTION__ , ##arg); \
228 #define DRM_DEBUG(fmt, arg...) do { } while (0)
231 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
233 #define DRM_PROC_PRINT(fmt, arg...) \
234 len += sprintf(&buf[len], fmt , ##arg); \
235 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
237 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
238 len += sprintf(&buf[len], fmt , ##arg); \
239 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
243 /***********************************************************************/
244 /** \name Internal types and structures */
247 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
248 #define DRM_MIN(a,b) min(a,b)
249 #define DRM_MAX(a,b) max(a,b)
251 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
252 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
253 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
255 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
257 * Get the private SAREA mapping.
259 * \param _dev DRM device.
260 * \param _ctx context number.
261 * \param _map output mapping.
263 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
264 (_map) = (_dev)->context_sareas[_ctx]; \
268 * Test that the hardware lock is held by the caller, returning otherwise.
270 * \param dev DRM device.
271 * \param file_priv DRM file private pointer of the caller.
273 #define LOCK_TEST_WITH_RETURN( dev, file_priv ) \
275 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
276 dev->lock.file_priv != file_priv ) { \
277 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
278 __FUNCTION__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
279 dev->lock.file_priv, file_priv ); \
285 * Copy and IOCTL return string to user space
287 #define DRM_COPY( name, value ) \
288 len = strlen( value ); \
289 if ( len > name##_len ) len = name##_len; \
290 name##_len = strlen( value ); \
291 if ( len && name ) { \
292 if ( copy_to_user( name, value, len ) ) \
297 * Ioctl function type.
299 * \param dev DRM device structure
300 * \param data pointer to kernel-space stored data, copied in and out according
301 * to ioctl description.
302 * \param file_priv DRM file private pointer.
304 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
305 struct drm_file *file_priv);
307 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
311 #define DRM_MASTER 0x2
312 #define DRM_ROOT_ONLY 0x4
314 struct drm_ioctl_desc {
320 * Creates a driver or general drm_ioctl_desc array entry for the given
321 * ioctl, for use by drm_ioctl().
323 #define DRM_IOCTL_DEF(ioctl, func, flags) \
324 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
326 struct drm_magic_entry {
327 struct list_head head;
328 struct drm_hash_item hash_item;
329 struct drm_file *priv;
332 struct drm_vma_entry {
333 struct list_head head;
334 struct vm_area_struct *vma;
342 int idx; /**< Index into master buflist */
343 int total; /**< Buffer size */
344 int order; /**< log-base-2(total) */
345 int used; /**< Amount of buffer in use (for DMA) */
346 unsigned long offset; /**< Byte offset (used internally) */
347 void *address; /**< Address of buffer */
348 unsigned long bus_address; /**< Bus address of buffer */
349 struct drm_buf *next; /**< Kernel-only: used for free list */
350 __volatile__ int waiting; /**< On kernel DMA queue */
351 __volatile__ int pending; /**< On hardware DMA queue */
352 wait_queue_head_t dma_wait; /**< Processes waiting */
353 struct drm_file *file_priv; /**< Private of holding file descr */
354 int context; /**< Kernel queue for this buffer */
355 int while_locked; /**< Dispatch this buffer while locked */
363 } list; /**< Which list we're on */
365 int dev_priv_size; /**< Size of buffer private storage */
366 void *dev_private; /**< Per-buffer private storage */
369 /** bufs is one longer than it has to be */
370 struct drm_waitlist {
371 int count; /**< Number of possible buffers */
372 struct drm_buf **bufs; /**< List of pointers to buffers */
373 struct drm_buf **rp; /**< Read pointer */
374 struct drm_buf **wp; /**< Write pointer */
375 struct drm_buf **end; /**< End pointer */
376 spinlock_t read_lock;
377 spinlock_t write_lock;
380 struct drm_freelist {
381 int initialized; /**< Freelist in use */
382 atomic_t count; /**< Number of free buffers */
383 struct drm_buf *next; /**< End pointer */
385 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
386 int low_mark; /**< Low water mark */
387 int high_mark; /**< High water mark */
388 atomic_t wfh; /**< If waiting for high mark */
392 typedef struct drm_dma_handle {
399 * Buffer entry. There is one of this for each buffer size order.
401 struct drm_buf_entry {
402 int buf_size; /**< size */
403 int buf_count; /**< number of buffers */
404 struct drm_buf *buflist; /**< buffer list */
407 struct drm_dma_handle **seglist;
408 struct drm_freelist freelist;
419 /** File private data */
427 unsigned long ioctl_count;
428 struct list_head lhead;
429 struct drm_head *head;
430 int remove_auth_on_close;
431 unsigned long lock_count;
434 * The user object hash table is global and resides in the
435 * drm_device structure. We protect the lists and hash tables with the
436 * device struct_mutex. A bit coarse-grained but probably the best
440 struct list_head refd_objects;
442 struct drm_open_hash refd_object_hash[_DRM_NO_REF_TYPES];
446 struct list_head fbs;
451 atomic_t use_count; /**< Outstanding uses (+1) */
452 atomic_t finalization; /**< Finalization in progress */
453 atomic_t block_count; /**< Count of processes waiting */
454 atomic_t block_read; /**< Queue blocked for reads */
455 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
456 atomic_t block_write; /**< Queue blocked for writes */
457 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
459 atomic_t total_queued; /**< Total queued statistic */
460 atomic_t total_flushed; /**< Total flushes statistic */
461 atomic_t total_locks; /**< Total locks statistics */
463 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
464 struct drm_waitlist waitlist; /**< Pending buffers */
465 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
471 struct drm_lock_data {
472 struct drm_hw_lock *hw_lock; /**< Hardware lock */
473 /** Private of lock holder's file (NULL=kernel) */
474 struct drm_file *file_priv;
475 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
476 unsigned long lock_time; /**< Time of last lock in jiffies */
478 uint32_t kernel_waiters;
479 uint32_t user_waiters;
486 struct drm_device_dma {
488 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
489 int buf_count; /**< total number of buffers */
490 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
492 int page_count; /**< number of pages */
493 unsigned long *pagelist; /**< page list */
494 unsigned long byte_count;
496 _DRM_DMA_USE_AGP = 0x01,
497 _DRM_DMA_USE_SG = 0x02,
498 _DRM_DMA_USE_FB = 0x04,
499 _DRM_DMA_USE_PCI_RO = 0x08
505 * AGP memory entry. Stored as a doubly linked list.
508 unsigned long handle; /**< handle */
510 unsigned long bound; /**< address */
512 struct list_head head;
518 * \sa drm_agp_init() and drm_device::agp.
520 struct drm_agp_head {
521 DRM_AGP_KERN agp_info; /**< AGP device information */
522 struct list_head memory;
523 unsigned long mode; /**< AGP mode */
524 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
525 struct agp_bridge_data *bridge;
527 int enabled; /**< whether the AGP bus as been enabled */
528 int acquired; /**< whether the AGP device has been acquired */
531 int cant_use_aperture;
532 unsigned long page_mask;
536 * Scatter-gather memory.
539 unsigned long handle;
542 struct page **pagelist;
548 struct drm_hw_lock *lock;
553 * Generic memory manager structs
557 struct list_head fl_entry;
558 struct list_head ml_entry;
567 struct list_head fl_entry;
568 struct list_head ml_entry;
575 struct drm_map_list {
576 struct list_head head; /**< list head */
577 struct drm_hash_item hash;
578 struct drm_map *map; /**< mapping */
580 struct drm_mm_node *file_offset_node;
583 typedef struct drm_map drm_local_map_t;
586 * Context handle list
588 struct drm_ctx_list {
589 struct list_head head; /**< list head */
590 drm_context_t handle; /**< context handle */
591 struct drm_file *tag; /**< associated fd private data */
595 struct list_head head;
596 unsigned int sequence;
598 struct task_struct *task;
601 /* location of GART table */
602 #define DRM_ATI_GART_MAIN 1
603 #define DRM_ATI_GART_FB 2
605 #define DRM_ATI_GART_PCI 1
606 #define DRM_ATI_GART_PCIE 2
607 #define DRM_ATI_GART_IGP 3
609 struct drm_ati_pcigart_info {
610 int gart_table_location;
614 drm_local_map_t mapping;
618 #include "drm_objects.h"
619 #include "drm_edid.h"
620 #include "drm_crtc.h"
623 * DRM driver structure. This structure represent the common code for
624 * a family of cards. There will one drm_device for each card present
629 int (*load) (struct drm_device *, unsigned long flags);
630 int (*firstopen) (struct drm_device *);
631 int (*open) (struct drm_device *, struct drm_file *);
632 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
633 void (*postclose) (struct drm_device *, struct drm_file *);
634 void (*lastclose) (struct drm_device *);
635 int (*unload) (struct drm_device *);
636 int (*suspend) (struct drm_device *);
637 int (*resume) (struct drm_device *);
638 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
639 void (*dma_ready) (struct drm_device *);
640 int (*dma_quiescent) (struct drm_device *);
641 int (*context_ctor) (struct drm_device *dev, int context);
642 int (*context_dtor) (struct drm_device *dev, int context);
643 int (*kernel_context_switch) (struct drm_device *dev, int old,
645 void (*kernel_context_switch_unlock) (struct drm_device *dev);
646 int (*vblank_wait) (struct drm_device *dev, unsigned int *sequence);
647 int (*vblank_wait2) (struct drm_device *dev, unsigned int *sequence);
648 int (*dri_library_name) (struct drm_device *dev, char * buf);
651 * Called by \c drm_device_is_agp. Typically used to determine if a
652 * card is really attached to AGP or not.
654 * \param dev DRM device handle
657 * One of three values is returned depending on whether or not the
658 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
659 * (return of 1), or may or may not be AGP (return of 2).
661 int (*device_is_agp) (struct drm_device *dev);
663 /* these have to be filled in */
664 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
665 void (*irq_preinstall) (struct drm_device *dev);
666 void (*irq_postinstall) (struct drm_device *dev);
667 void (*irq_uninstall) (struct drm_device *dev);
668 void (*reclaim_buffers) (struct drm_device *dev,
669 struct drm_file *file_priv);
670 void (*reclaim_buffers_locked) (struct drm_device *dev,
671 struct drm_file *file_priv);
672 void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
673 struct drm_file *file_priv);
674 unsigned long (*get_map_ofs) (struct drm_map *map);
675 unsigned long (*get_reg_ofs) (struct drm_device *dev);
676 void (*set_version) (struct drm_device *dev,
677 struct drm_set_version *sv);
679 /* FB routines, if present */
680 int (*fb_probe)(struct drm_device *dev, struct drm_crtc *crtc);
681 int (*fb_remove)(struct drm_device *dev, struct drm_crtc *crtc);
683 struct drm_fence_driver *fence_driver;
684 struct drm_bo_driver *bo_driver;
696 struct drm_ioctl_desc *ioctls;
698 struct file_operations fops;
699 struct pci_driver pci_driver;
703 * DRM head structure. This structure represent a video head on a card
704 * that may contain multiple heads. Embed one per head of these in the
705 * private drm_device structure.
708 int minor; /**< Minor device number */
709 struct drm_device *dev;
710 struct proc_dir_entry *dev_root; /**< proc directory entry */
711 dev_t device; /**< Device number for mknod */
712 struct class_device *dev_class;
717 * DRM device structure. This structure represent a complete card that
718 * may contain multiple heads.
721 struct device dev; /**< Linux device */
722 char *unique; /**< Unique identifier: e.g., busid */
723 int unique_len; /**< Length of unique field */
724 char *devname; /**< For /proc/interrupts */
725 int if_version; /**< Highest interface version set */
727 int blocked; /**< Blocked due to VC switch? */
731 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
732 struct mutex struct_mutex; /**< For others */
735 /** \name Usage Counters */
737 int open_count; /**< Outstanding files open */
738 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
739 atomic_t vma_count; /**< Outstanding vma areas open */
740 int buf_use; /**< Buffers in use -- cannot alloc */
741 atomic_t buf_alloc; /**< Buffer allocation in progress */
744 /** \name Performance counters */
746 unsigned long counters;
747 enum drm_stat_type types[15];
751 /** \name Authentication */
753 struct list_head filelist;
754 struct drm_open_hash magiclist;
755 struct list_head magicfree;
758 /** \name Memory management */
760 struct list_head maplist; /**< Linked list of regions */
761 int map_count; /**< Number of mappable regions */
762 struct drm_open_hash map_hash; /**< User token hash table for maps */
763 struct drm_mm offset_manager; /**< User token manager */
764 struct drm_open_hash object_hash; /**< User token hash table for objects */
765 struct address_space *dev_mapping; /**< For unmap_mapping_range() */
766 struct page *ttm_dummy_page;
768 /** \name Context handle management */
770 struct list_head ctxlist; /**< Linked list of context handles */
771 int ctx_count; /**< Number of context handles */
772 struct mutex ctxlist_mutex; /**< For ctxlist */
776 struct list_head vmalist; /**< List of vmas (for debugging) */
777 struct drm_lock_data lock; /**< Information on hardware lock */
780 /** \name DMA queues (contexts) */
782 int queue_count; /**< Number of active DMA queues */
783 int queue_reserved; /**< Number of reserved DMA queues */
784 int queue_slots; /**< Actual length of queuelist */
785 struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */
786 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
789 /** \name Context support */
791 int irq; /**< Interrupt used by board */
792 int irq_enabled; /**< True if irq handler is enabled */
793 __volatile__ long context_flag; /**< Context swapping flag */
794 __volatile__ long interrupt_flag; /**< Interruption handler flag */
795 __volatile__ long dma_flag; /**< DMA dispatch flag */
796 struct timer_list timer; /**< Timer for delaying ctx switch */
797 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
798 int last_checked; /**< Last context checked for DMA */
799 int last_context; /**< Last current context */
800 unsigned long last_switch; /**< jiffies at last context switch */
803 struct work_struct work;
805 /** \name VBLANK IRQ support */
808 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
809 atomic_t vbl_received;
810 atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
812 struct list_head vbl_sigs; /**< signal list to send on VBLANK */
813 struct list_head vbl_sigs2; /**< signals to send on secondary VBLANK */
814 unsigned int vbl_pending;
815 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
816 void (*locked_tasklet_func)(struct drm_device *dev);
822 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
823 wait_queue_head_t buf_readers; /**< Processes waiting to read */
824 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
826 struct drm_agp_head *agp; /**< AGP data */
828 struct pci_dev *pdev; /**< PCI device structure */
829 int pci_vendor; /**< PCI vendor id */
830 int pci_device; /**< PCI device id */
832 struct pci_controller *hose;
834 struct drm_sg_mem *sg; /**< Scatter gather memory */
835 void *dev_private; /**< device private data */
836 struct drm_sigdata sigdata; /**< For block_all_signals */
839 struct drm_driver *driver;
840 drm_local_map_t *agp_buffer_map;
841 unsigned int agp_buffer_token;
842 struct drm_head primary; /**< primary screen head */
844 struct drm_fence_manager fm;
845 struct drm_buffer_manager bm;
847 /** \name Drawable information */
853 /* DRM mode setting */
854 struct drm_mode_config mode_config;
858 struct drm_agp_ttm_backend {
859 struct drm_ttm_backend backend;
861 struct agp_bridge_data *bridge;
866 typedef struct ati_pcigart_ttm_backend {
867 struct drm_ttm_backend backend;
869 void (*gart_flush_fn)(struct drm_device *dev);
870 struct drm_ati_pcigart_info *gart_info;
871 unsigned long offset;
875 struct drm_device *dev;
876 } ati_pcigart_ttm_backend_t;
878 static __inline__ int drm_core_check_feature(struct drm_device *dev,
881 return ((dev->driver->driver_features & feature) ? 1 : 0);
885 #define drm_get_pci_domain(dev) dev->hose->index
887 #define drm_get_pci_domain(dev) 0
891 static inline int drm_core_has_AGP(struct drm_device *dev)
893 return drm_core_check_feature(dev, DRIVER_USE_AGP);
896 #define drm_core_has_AGP(dev) (0)
900 static inline int drm_core_has_MTRR(struct drm_device *dev)
902 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
905 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
907 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
910 return mtrr_add(offset, size, flags, 1);
913 static inline int drm_mtrr_del(int handle, unsigned long offset,
914 unsigned long size, unsigned int flags)
916 return mtrr_del(handle, offset, size);
920 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
926 static inline int drm_mtrr_del(int handle, unsigned long offset,
927 unsigned long size, unsigned int flags)
932 #define drm_core_has_MTRR(dev) (0)
933 #define DRM_MTRR_WC 0
937 /******************************************************************/
938 /** \name Internal function definitions */
941 /* Driver support (drm_drv.h) */
942 extern int drm_fb_loaded;
943 extern int drm_init(struct drm_driver *driver,
944 struct pci_device_id *pciidlist);
945 extern void drm_exit(struct drm_driver *driver);
946 extern void drm_cleanup_pci(struct pci_dev *pdev);
947 extern int drm_ioctl(struct inode *inode, struct file *filp,
948 unsigned int cmd, unsigned long arg);
949 extern long drm_unlocked_ioctl(struct file *filp,
950 unsigned int cmd, unsigned long arg);
951 extern long drm_compat_ioctl(struct file *filp,
952 unsigned int cmd, unsigned long arg);
954 extern int drm_lastclose(struct drm_device *dev);
956 /* Device support (drm_fops.h) */
957 extern int drm_open(struct inode *inode, struct file *filp);
958 extern int drm_stub_open(struct inode *inode, struct file *filp);
959 extern int drm_fasync(int fd, struct file *filp, int on);
960 extern int drm_release(struct inode *inode, struct file *filp);
961 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
963 /* Mapping support (drm_vm.h) */
964 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
965 extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
966 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
967 extern pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma);
969 /* Memory management support (drm_memory.h) */
970 #include "drm_memory.h"
971 extern void drm_mem_init(void);
972 extern int drm_mem_info(char *buf, char **start, off_t offset,
973 int request, int *eof, void *data);
974 extern void *drm_calloc(size_t nmemb, size_t size, int area);
975 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
976 extern unsigned long drm_alloc_pages(int order, int area);
977 extern void drm_free_pages(unsigned long address, int order, int area);
978 extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
979 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
980 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
981 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
983 extern void drm_free_memctl(size_t size);
984 extern int drm_alloc_memctl(size_t size);
985 extern void drm_query_memctl(uint64_t *cur_used,
987 uint64_t *low_threshold,
988 uint64_t *high_threshold,
989 uint64_t *emer_threshold);
990 extern void drm_init_memctl(size_t low_threshold,
991 size_t high_threshold,
994 /* Misc. IOCTL support (drm_ioctl.h) */
995 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
996 struct drm_file *file_priv);
997 extern int drm_getunique(struct drm_device *dev, void *data,
998 struct drm_file *file_priv);
999 extern int drm_setunique(struct drm_device *dev, void *data,
1000 struct drm_file *file_priv);
1001 extern int drm_getmap(struct drm_device *dev, void *data,
1002 struct drm_file *file_priv);
1003 extern int drm_getclient(struct drm_device *dev, void *data,
1004 struct drm_file *file_priv);
1005 extern int drm_getstats(struct drm_device *dev, void *data,
1006 struct drm_file *file_priv);
1007 extern int drm_setversion(struct drm_device *dev, void *data,
1008 struct drm_file *file_priv);
1009 extern int drm_noop(struct drm_device *dev, void *data,
1010 struct drm_file *file_priv);
1012 /* Context IOCTL support (drm_context.h) */
1013 extern int drm_resctx(struct drm_device *dev, void *data,
1014 struct drm_file *file_priv);
1015 extern int drm_addctx(struct drm_device *dev, void *data,
1016 struct drm_file *file_priv);
1017 extern int drm_modctx(struct drm_device *dev, void *data,
1018 struct drm_file *file_priv);
1019 extern int drm_getctx(struct drm_device *dev, void *data,
1020 struct drm_file *file_priv);
1021 extern int drm_switchctx(struct drm_device *dev, void *data,
1022 struct drm_file *file_priv);
1023 extern int drm_newctx(struct drm_device *dev, void *data,
1024 struct drm_file *file_priv);
1025 extern int drm_rmctx(struct drm_device *dev, void *data,
1026 struct drm_file *file_priv);
1028 extern int drm_ctxbitmap_init(struct drm_device *dev);
1029 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1030 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1032 extern int drm_setsareactx(struct drm_device *dev, void *data,
1033 struct drm_file *file_priv);
1034 extern int drm_getsareactx(struct drm_device *dev, void *data,
1035 struct drm_file *file_priv);
1037 /* Drawable IOCTL support (drm_drawable.h) */
1038 extern int drm_adddraw(struct drm_device *dev, void *data,
1039 struct drm_file *file_priv);
1040 extern int drm_rmdraw(struct drm_device *dev, void *data,
1041 struct drm_file *file_priv);
1042 extern int drm_update_drawable_info(struct drm_device *dev, void *data,
1043 struct drm_file *file_priv);
1044 extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1046 extern void drm_drawable_free_all(struct drm_device *dev);
1048 /* Authentication IOCTL support (drm_auth.h) */
1049 extern int drm_getmagic(struct drm_device *dev, void *data,
1050 struct drm_file *file_priv);
1051 extern int drm_authmagic(struct drm_device *dev, void *data,
1052 struct drm_file *file_priv);
1054 /* Locking IOCTL support (drm_lock.h) */
1055 extern int drm_lock(struct drm_device *dev, void *data,
1056 struct drm_file *file_priv);
1057 extern int drm_unlock(struct drm_device *dev, void *data,
1058 struct drm_file *file_priv);
1059 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1060 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1061 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1062 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1065 * These are exported to drivers so that they can implement fencing using
1066 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1069 extern int drm_i_have_hw_lock(struct drm_device *dev,
1070 struct drm_file *file_priv);
1072 /* Buffer management support (drm_bufs.h) */
1073 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1074 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1075 extern int drm_addbufs_fb (struct drm_device *dev, struct drm_buf_desc * request);
1076 extern int drm_addmap(struct drm_device *dev, unsigned int offset,
1077 unsigned int size, enum drm_map_type type,
1078 enum drm_map_flags flags, drm_local_map_t ** map_ptr);
1079 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1080 struct drm_file *file_priv);
1081 extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1082 extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
1083 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1084 struct drm_file *file_priv);
1085 extern int drm_addbufs(struct drm_device *dev, void *data,
1086 struct drm_file *file_priv);
1087 extern int drm_infobufs(struct drm_device *dev, void *data,
1088 struct drm_file *file_priv);
1089 extern int drm_markbufs(struct drm_device *dev, void *data,
1090 struct drm_file *file_priv);
1091 extern int drm_freebufs(struct drm_device *dev, void *data,
1092 struct drm_file *file_priv);
1093 extern int drm_mapbufs(struct drm_device *dev, void *data,
1094 struct drm_file *file_priv);
1095 extern int drm_order(unsigned long size);
1096 extern unsigned long drm_get_resource_start(struct drm_device *dev,
1097 unsigned int resource);
1098 extern unsigned long drm_get_resource_len(struct drm_device *dev,
1099 unsigned int resource);
1100 extern struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
1101 drm_local_map_t *map);
1104 /* DMA support (drm_dma.h) */
1105 extern int drm_dma_setup(struct drm_device *dev);
1106 extern void drm_dma_takedown(struct drm_device *dev);
1107 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1108 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1109 struct drm_file *filp);
1111 /* IRQ support (drm_irq.h) */
1112 extern int drm_control(struct drm_device *dev, void *data,
1113 struct drm_file *file_priv);
1114 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1115 extern int drm_irq_install(struct drm_device *dev);
1116 extern int drm_irq_uninstall(struct drm_device *dev);
1117 extern void drm_driver_irq_preinstall(struct drm_device *dev);
1118 extern void drm_driver_irq_postinstall(struct drm_device *dev);
1119 extern void drm_driver_irq_uninstall(struct drm_device *dev);
1121 extern int drm_wait_vblank(struct drm_device *dev, void *data,
1122 struct drm_file *file_priv);
1123 extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq);
1124 extern void drm_vbl_send_signals(struct drm_device *dev);
1125 extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
1127 /* AGP/GART support (drm_agpsupport.h) */
1128 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1129 extern int drm_agp_acquire(struct drm_device *dev);
1130 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1131 struct drm_file *file_priv);
1132 extern int drm_agp_release(struct drm_device *dev);
1133 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1134 struct drm_file *file_priv);
1135 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1136 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1137 struct drm_file *file_priv);
1138 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1139 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1140 struct drm_file *file_priv);
1141 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1142 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1143 struct drm_file *file_priv);
1144 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1145 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1146 struct drm_file *file_priv);
1147 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1148 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1149 struct drm_file *file_priv);
1150 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1151 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1152 struct drm_file *file_priv);
1153 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
1154 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
1156 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1158 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1159 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1160 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1161 extern struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev);
1162 extern void drm_agp_chipset_flush(struct drm_device *dev);
1163 /* Stub support (drm_stub.h) */
1164 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1165 struct drm_driver *driver);
1166 extern int drm_put_dev(struct drm_device *dev);
1167 extern int drm_put_head(struct drm_head * head);
1168 extern unsigned int drm_debug; /* 1 to enable debug output */
1169 extern unsigned int drm_cards_limit;
1170 extern struct drm_head **drm_heads;
1171 extern struct class *drm_class;
1172 extern struct proc_dir_entry *drm_proc_root;
1174 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1176 /* Proc support (drm_proc.h) */
1177 extern int drm_proc_init(struct drm_device *dev,
1179 struct proc_dir_entry *root,
1180 struct proc_dir_entry **dev_root);
1181 extern int drm_proc_cleanup(int minor,
1182 struct proc_dir_entry *root,
1183 struct proc_dir_entry *dev_root);
1185 /* Scatter Gather Support (drm_scatter.h) */
1186 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1187 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1188 struct drm_file *file_priv);
1189 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1190 extern int drm_sg_free(struct drm_device *dev, void *data,
1191 struct drm_file *file_priv);
1193 /* ATI PCIGART support (ati_pcigart.h) */
1194 extern int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1195 extern int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1196 extern struct drm_ttm_backend *ati_pcigart_init_ttm(struct drm_device *dev, struct drm_ati_pcigart_info *info, void (*gart_flush_fn)(struct drm_device *dev));
1198 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1199 size_t align, dma_addr_t maxaddr);
1200 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1201 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1203 /* sysfs support (drm_sysfs.c) */
1204 struct drm_sysfs_class;
1205 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1206 extern void drm_sysfs_destroy(void);
1207 extern int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head);
1208 extern void drm_sysfs_device_remove(struct drm_device *dev);
1211 * Basic memory manager support (drm_mm.c)
1214 extern struct drm_mm_node * drm_mm_get_block(struct drm_mm_node * parent, unsigned long size,
1215 unsigned alignment);
1216 extern void drm_mm_put_block(struct drm_mm_node *cur);
1217 extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
1218 unsigned alignment, int best_match);
1219 extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
1220 extern void drm_mm_takedown(struct drm_mm *mm);
1221 extern int drm_mm_clean(struct drm_mm *mm);
1222 extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
1223 extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
1224 extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
1226 static inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
1231 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1232 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1234 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1237 struct drm_map_list *_entry;
1238 list_for_each_entry(_entry, &dev->maplist, head)
1239 if (_entry->user_token == token)
1244 static __inline__ int drm_device_is_agp(struct drm_device *dev)
1246 if ( dev->driver->device_is_agp != NULL ) {
1247 int err = (*dev->driver->device_is_agp)(dev);
1254 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1257 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1259 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1262 static __inline__ void drm_core_dropmap(struct drm_map *map)
1266 #ifndef DEBUG_MEMORY
1267 /** Wrapper around kmalloc() */
1268 static __inline__ void *drm_alloc(size_t size, int area)
1270 return kmalloc(size, GFP_KERNEL);
1273 /** Wrapper around kfree() */
1274 static __inline__ void drm_free(void *pt, size_t size, int area)
1279 extern void *drm_alloc(size_t size, int area);
1280 extern void drm_free(void *pt, size_t size, int area);
1284 * Accounting variants of standard calls.
1287 static inline void *drm_ctl_alloc(size_t size, int area)
1290 if (drm_alloc_memctl(size))
1292 ret = drm_alloc(size, area);
1294 drm_free_memctl(size);
1298 static inline void *drm_ctl_calloc(size_t nmemb, size_t size, int area)
1302 if (drm_alloc_memctl(nmemb*size))
1304 ret = drm_calloc(nmemb, size, area);
1306 drm_free_memctl(nmemb*size);
1310 static inline void drm_ctl_free(void *pt, size_t size, int area)
1312 drm_free(pt, size, area);
1313 drm_free_memctl(size);
1316 static inline size_t drm_size_align(size_t size)
1319 if (size > PAGE_SIZE)
1320 return PAGE_ALIGN(size);
1322 while (tmpSize < size)
1325 return (size_t) tmpSize;
1331 #endif /* __KERNEL__ */