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 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
58 #include <linux/mutex.h>
60 #if defined(__alpha__) || defined(__powerpc__)
61 #include <asm/pgtable.h> /* For pte_wrprotect */
65 #include <asm/uaccess.h>
69 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
71 #include <linux/types.h>
72 #include <linux/agp_backend.h>
74 #include <linux/workqueue.h>
75 #include <linux/poll.h>
76 #include <asm/pgalloc.h>
78 #include <linux/slab.h>
80 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
81 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
83 #include "drm_os_linux.h"
84 #include "drm_hashtab.h"
86 /* If you want the memory alloc debug functionality, change define below */
87 /* #define DEBUG_MEMORY */
89 /***********************************************************************/
90 /** \name DRM template customization defaults */
93 /* driver capabilities and requirements mask */
94 #define DRIVER_USE_AGP 0x1
95 #define DRIVER_REQUIRE_AGP 0x2
96 #define DRIVER_USE_MTRR 0x4
97 #define DRIVER_PCI_DMA 0x8
98 #define DRIVER_SG 0x10
99 #define DRIVER_HAVE_DMA 0x20
100 #define DRIVER_HAVE_IRQ 0x40
101 #define DRIVER_IRQ_SHARED 0x80
102 #define DRIVER_IRQ_VBL 0x100
103 #define DRIVER_DMA_QUEUE 0x200
104 #define DRIVER_FB_DMA 0x400
105 #define DRIVER_IRQ_VBL2 0x800
110 /***********************************************************************/
111 /** \name Begin the DRM... */
114 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
115 also include looping detection. */
117 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
118 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
119 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
120 #define DRM_LOOPING_LIMIT 5000000
121 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
122 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
124 #define DRM_FLAG_DEBUG 0x01
126 #define DRM_MEM_DMA 0
127 #define DRM_MEM_SAREA 1
128 #define DRM_MEM_DRIVER 2
129 #define DRM_MEM_MAGIC 3
130 #define DRM_MEM_IOCTLS 4
131 #define DRM_MEM_MAPS 5
132 #define DRM_MEM_VMAS 6
133 #define DRM_MEM_BUFS 7
134 #define DRM_MEM_SEGS 8
135 #define DRM_MEM_PAGES 9
136 #define DRM_MEM_FILES 10
137 #define DRM_MEM_QUEUES 11
138 #define DRM_MEM_CMDS 12
139 #define DRM_MEM_MAPPINGS 13
140 #define DRM_MEM_BUFLISTS 14
141 #define DRM_MEM_AGPLISTS 15
142 #define DRM_MEM_TOTALAGP 16
143 #define DRM_MEM_BOUNDAGP 17
144 #define DRM_MEM_CTXBITMAP 18
145 #define DRM_MEM_STUB 19
146 #define DRM_MEM_SGLISTS 20
147 #define DRM_MEM_CTXLIST 21
148 #define DRM_MEM_MM 22
149 #define DRM_MEM_HASHTAB 23
150 #define DRM_MEM_OBJECTS 24
151 #define DRM_MEM_FENCE 25
152 #define DRM_MEM_TTM 26
153 #define DRM_MEM_BUFOBJ 27
155 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
156 #define DRM_MAP_HASH_OFFSET 0x10000000
157 #define DRM_MAP_HASH_ORDER 12
158 #define DRM_OBJECT_HASH_ORDER 12
159 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
160 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
161 #define DRM_MM_INIT_MAX_PAGES 256
165 #include "drm_compat.h"
167 /***********************************************************************/
168 /** \name Macros to make printk easier */
174 * \param fmt printf() like format string.
175 * \param arg arguments
177 #define DRM_ERROR(fmt, arg...) \
178 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
181 * Memory error output.
183 * \param area memory area where the error occurred.
184 * \param fmt printf() like format string.
185 * \param arg arguments
187 #define DRM_MEM_ERROR(area, fmt, arg...) \
188 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
189 drm_mem_stats[area].name , ##arg)
190 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
195 * \param fmt printf() like format string.
196 * \param arg arguments
199 #define DRM_DEBUG(fmt, arg...) \
203 "[" DRM_NAME ":%s] " fmt , \
204 __FUNCTION__ , ##arg); \
207 #define DRM_DEBUG(fmt, arg...) do { } while (0)
210 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
212 #define DRM_PROC_PRINT(fmt, arg...) \
213 len += sprintf(&buf[len], fmt , ##arg); \
214 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
216 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
217 len += sprintf(&buf[len], fmt , ##arg); \
218 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
222 /***********************************************************************/
223 /** \name Internal types and structures */
226 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
227 #define DRM_MIN(a,b) min(a,b)
228 #define DRM_MAX(a,b) max(a,b)
230 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
231 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
232 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
234 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
236 * Get the private SAREA mapping.
238 * \param _dev DRM device.
239 * \param _ctx context number.
240 * \param _map output mapping.
242 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
243 (_map) = (_dev)->context_sareas[_ctx]; \
247 * Test that the hardware lock is held by the caller, returning otherwise.
249 * \param dev DRM device.
250 * \param filp file pointer of the caller.
252 #define LOCK_TEST_WITH_RETURN( dev, filp ) \
254 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
255 dev->lock.filp != filp ) { \
256 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
257 __FUNCTION__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
258 dev->lock.filp, filp ); \
264 * Copy and IOCTL return string to user space
266 #define DRM_COPY( name, value ) \
267 len = strlen( value ); \
268 if ( len > name##_len ) len = name##_len; \
269 name##_len = strlen( value ); \
270 if ( len && name ) { \
271 if ( copy_to_user( name, value, len ) ) \
276 * Ioctl function type.
278 * \param inode device inode.
279 * \param filp file pointer.
280 * \param cmd command.
281 * \param arg argument.
283 typedef int drm_ioctl_t(struct inode *inode, struct file *filp,
284 unsigned int cmd, unsigned long arg);
286 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
290 #define DRM_MASTER 0x2
291 #define DRM_ROOT_ONLY 0x4
293 typedef struct drm_ioctl_desc {
298 typedef struct drm_devstate {
299 pid_t owner; /**< X server pid holding x_lock */
302 typedef struct drm_magic_entry {
303 drm_hash_item_t hash_item;
304 struct list_head head;
305 struct drm_file *priv;
308 typedef struct drm_magic_head {
309 struct drm_magic_entry *head;
310 struct drm_magic_entry *tail;
313 typedef struct drm_vma_entry {
314 struct vm_area_struct *vma;
315 struct drm_vma_entry *next;
322 typedef struct drm_buf {
323 int idx; /**< Index into master buflist */
324 int total; /**< Buffer size */
325 int order; /**< log-base-2(total) */
326 int used; /**< Amount of buffer in use (for DMA) */
327 unsigned long offset; /**< Byte offset (used internally) */
328 void *address; /**< Address of buffer */
329 unsigned long bus_address; /**< Bus address of buffer */
330 struct drm_buf *next; /**< Kernel-only: used for free list */
331 __volatile__ int waiting; /**< On kernel DMA queue */
332 __volatile__ int pending; /**< On hardware DMA queue */
333 wait_queue_head_t dma_wait; /**< Processes waiting */
334 struct file *filp; /**< Pointer to holding file descr */
335 int context; /**< Kernel queue for this buffer */
336 int while_locked; /**< Dispatch this buffer while locked */
344 } list; /**< Which list we're on */
346 int dev_priv_size; /**< Size of buffer private storage */
347 void *dev_private; /**< Per-buffer private storage */
350 /** bufs is one longer than it has to be */
351 typedef struct drm_waitlist {
352 int count; /**< Number of possible buffers */
353 drm_buf_t **bufs; /**< List of pointers to buffers */
354 drm_buf_t **rp; /**< Read pointer */
355 drm_buf_t **wp; /**< Write pointer */
356 drm_buf_t **end; /**< End pointer */
357 spinlock_t read_lock;
358 spinlock_t write_lock;
361 typedef struct drm_freelist {
362 int initialized; /**< Freelist in use */
363 atomic_t count; /**< Number of free buffers */
364 drm_buf_t *next; /**< End pointer */
366 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
367 int low_mark; /**< Low water mark */
368 int high_mark; /**< High water mark */
369 atomic_t wfh; /**< If waiting for high mark */
373 typedef struct drm_dma_handle {
380 * Buffer entry. There is one of this for each buffer size order.
382 typedef struct drm_buf_entry {
383 int buf_size; /**< size */
384 int buf_count; /**< number of buffers */
385 drm_buf_t *buflist; /**< buffer list */
388 drm_dma_handle_t **seglist;
389 drm_freelist_t freelist;
393 * This should be small enough to allow the use of kmalloc for hash tables
394 * instead of vmalloc.
397 #define DRM_FILE_HASH_ORDER 8
405 /** File private data */
406 typedef struct drm_file {
413 unsigned long ioctl_count;
414 struct drm_file *next;
415 struct drm_file *prev;
416 struct drm_head *head;
417 int remove_auth_on_close;
418 unsigned long lock_count;
421 * The user object hash table is global and resides in the
422 * drm_device structure. We protect the lists and hash tables with the
423 * device struct_mutex. A bit coarse-grained but probably the best
427 struct list_head refd_objects;
428 struct list_head user_objects;
430 drm_open_hash_t refd_object_hash[_DRM_NO_REF_TYPES];
435 typedef struct drm_queue {
436 atomic_t use_count; /**< Outstanding uses (+1) */
437 atomic_t finalization; /**< Finalization in progress */
438 atomic_t block_count; /**< Count of processes waiting */
439 atomic_t block_read; /**< Queue blocked for reads */
440 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
441 atomic_t block_write; /**< Queue blocked for writes */
442 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
444 atomic_t total_queued; /**< Total queued statistic */
445 atomic_t total_flushed; /**< Total flushes statistic */
446 atomic_t total_locks; /**< Total locks statistics */
448 drm_ctx_flags_t flags; /**< Context preserving and 2D-only */
449 drm_waitlist_t waitlist; /**< Pending buffers */
450 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
456 typedef struct drm_lock_data {
457 drm_hw_lock_t *hw_lock; /**< Hardware lock */
458 struct file *filp; /**< File descr of lock holder (0=kernel) */
459 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
460 unsigned long lock_time; /**< Time of last lock in jiffies */
466 typedef struct drm_device_dma {
468 drm_buf_entry_t bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
469 int buf_count; /**< total number of buffers */
470 drm_buf_t **buflist; /**< Vector of pointers into drm_device_dma::bufs */
472 int page_count; /**< number of pages */
473 unsigned long *pagelist; /**< page list */
474 unsigned long byte_count;
476 _DRM_DMA_USE_AGP = 0x01,
477 _DRM_DMA_USE_SG = 0x02,
478 _DRM_DMA_USE_FB = 0x04,
479 _DRM_DMA_USE_PCI_RO = 0x08
485 * AGP memory entry. Stored as a doubly linked list.
487 typedef struct drm_agp_mem {
488 unsigned long handle; /**< handle */
490 unsigned long bound; /**< address */
492 struct drm_agp_mem *prev; /**< previous entry */
493 struct drm_agp_mem *next; /**< next entry */
499 * \sa drm_agp_init)() and drm_device::agp.
501 typedef struct drm_agp_head {
502 DRM_AGP_KERN agp_info; /**< AGP device information */
503 drm_agp_mem_t *memory; /**< memory entries */
504 unsigned long mode; /**< AGP mode */
505 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
506 struct agp_bridge_data *bridge;
508 int enabled; /**< whether the AGP bus as been enabled */
509 int acquired; /**< whether the AGP device has been acquired */
512 int cant_use_aperture;
513 unsigned long page_mask;
517 * Scatter-gather memory.
519 typedef struct drm_sg_mem {
520 unsigned long handle;
523 struct page **pagelist;
527 typedef struct drm_sigdata {
534 * Generic memory manager structs
537 typedef struct drm_mm_node {
538 struct list_head fl_entry;
539 struct list_head ml_entry;
547 typedef struct drm_mm {
548 struct list_head fl_entry;
549 struct list_head ml_entry;
556 typedef struct drm_map_list {
557 struct list_head head; /**< list head */
558 drm_hash_item_t hash;
559 drm_map_t *map; /**< mapping */
560 drm_u64_t user_token;
561 drm_mm_node_t *file_offset_node;
564 typedef drm_map_t drm_local_map_t;
567 * Context handle list
569 typedef struct drm_ctx_list {
570 struct list_head head; /**< list head */
571 drm_context_t handle; /**< context handle */
572 drm_file_t *tag; /**< associated fd private data */
575 typedef struct drm_vbl_sig {
576 struct list_head head;
577 unsigned int sequence;
579 struct task_struct *task;
582 /* location of GART table */
583 #define DRM_ATI_GART_MAIN 1
584 #define DRM_ATI_GART_FB 2
586 typedef struct ati_pcigart_info {
587 int gart_table_location;
591 drm_local_map_t mapping;
592 } drm_ati_pcigart_info;
595 * User space objects and their references.
598 #define drm_user_object_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
606 * Add other user space object types here.
612 * A user object is a structure that helps the drm give out user handles
613 * to kernel internal objects and to keep track of these objects so that
614 * they can be destroyed, for example when the user space process exits.
615 * Designed to be accessible using a user space 32-bit handle.
618 typedef struct drm_user_object{
619 drm_hash_item_t hash;
620 struct list_head list;
621 drm_object_type_t type;
625 void (*ref_struct_locked) (drm_file_t *priv, struct drm_user_object *obj,
626 drm_ref_t ref_action);
627 void (*unref)(drm_file_t *priv, struct drm_user_object *obj,
628 drm_ref_t unref_action);
629 void (*remove)(drm_file_t *priv, struct drm_user_object *obj);
633 * A ref object is a structure which is used to
634 * keep track of references to user objects and to keep track of these
635 * references so that they can be destroyed for example when the user space
636 * process exits. Designed to be accessible using a pointer to the _user_ object.
640 typedef struct drm_ref_object {
641 drm_hash_item_t hash;
642 struct list_head list;
644 drm_ref_t unref_action;
647 struct drm_buffer_object;
651 #define _DRM_FLAG_MEMTYPE_FIXED 0x00000001 /* Fixed (on-card) PCI memory */
652 #define _DRM_FLAG_MEMTYPE_MAPPABLE 0x00000002 /* Memory mappable */
653 #define _DRM_FLAG_MEMTYPE_CACHED 0x00000004 /* Cached binding */
654 #define _DRM_FLAG_NEEDS_IOREMAP 0x00000008 /* Fixed memory needs ioremap
655 before kernel access. */
656 #define _DRM_FLAG_MEMTYPE_CMA 0x00000010 /* Can't map aperture */
657 #define _DRM_FLAG_MEMTYPE_CSELECT 0x00000020 /* Select caching */
660 typedef struct drm_mem_type_manager {
664 struct list_head lru;
665 struct list_head pinned;
667 unsigned long io_offset;
668 unsigned long io_size;
670 } drm_mem_type_manager_t;
672 typedef struct drm_bo_mem_reg {
673 drm_mm_node_t *mm_node;
675 unsigned long num_pages;
676 uint32_t page_alignment;
683 * buffer object driver
686 typedef struct drm_bo_driver{
687 const uint32_t *mem_type_prio;
688 const uint32_t *mem_busy_prio;
689 uint32_t num_mem_type_prio;
690 uint32_t num_mem_busy_prio;
691 drm_ttm_backend_t *(*create_ttm_backend_entry)
692 (struct drm_device *dev);
693 int (*fence_type)(uint32_t flags, uint32_t *class, uint32_t *type);
694 int (*invalidate_caches)(struct drm_device *dev, uint32_t flags);
695 int (*init_mem_type)(struct drm_device *dev, uint32_t type,
696 drm_mem_type_manager_t *man);
697 uint32_t (*evict_flags) (struct drm_device *dev, uint32_t type);
698 int (*move)(struct drm_buffer_object *bo,
699 int evict, int no_wait,
700 struct drm_bo_mem_reg *new_mem);
705 * DRM driver structure. This structure represent the common code for
706 * a family of cards. There will one drm_device for each card present
712 int (*load) (struct drm_device *, unsigned long flags);
713 int (*firstopen) (struct drm_device *);
714 int (*open) (struct drm_device *, drm_file_t *);
715 void (*preclose) (struct drm_device *, struct file * filp);
716 void (*postclose) (struct drm_device *, drm_file_t *);
717 void (*lastclose) (struct drm_device *);
718 int (*unload) (struct drm_device *);
719 int (*dma_ioctl) (DRM_IOCTL_ARGS);
720 void (*dma_ready) (struct drm_device *);
721 int (*dma_quiescent) (struct drm_device *);
722 int (*context_ctor) (struct drm_device * dev, int context);
723 int (*context_dtor) (struct drm_device * dev, int context);
724 int (*kernel_context_switch) (struct drm_device * dev, int old,
726 void (*kernel_context_switch_unlock) (struct drm_device * dev);
727 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
728 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
729 int (*dri_library_name) (struct drm_device * dev, char * buf);
732 * Called by \c drm_device_is_agp. Typically used to determine if a
733 * card is really attached to AGP or not.
735 * \param dev DRM device handle
738 * One of three values is returned depending on whether or not the
739 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
740 * (return of 1), or may or may not be AGP (return of 2).
742 int (*device_is_agp) (struct drm_device * dev);
744 /* these have to be filled in */
745 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
746 void (*irq_preinstall) (struct drm_device * dev);
747 void (*irq_postinstall) (struct drm_device * dev);
748 void (*irq_uninstall) (struct drm_device * dev);
749 void (*reclaim_buffers) (struct drm_device *dev, struct file * filp);
750 void (*reclaim_buffers_locked) (struct drm_device *dev,
752 unsigned long (*get_map_ofs) (drm_map_t * map);
753 unsigned long (*get_reg_ofs) (struct drm_device * dev);
754 void (*set_version) (struct drm_device * dev, drm_set_version_t * sv);
756 struct drm_fence_driver *fence_driver;
757 struct drm_bo_driver *bo_driver;
769 drm_ioctl_desc_t *ioctls;
771 struct file_operations fops;
772 struct pci_driver pci_driver;
776 * DRM head structure. This structure represent a video head on a card
777 * that may contain multiple heads. Embed one per head of these in the
778 * private drm_device structure.
780 typedef struct drm_head {
781 int minor; /**< Minor device number */
782 struct drm_device *dev;
783 struct proc_dir_entry *dev_root; /**< proc directory entry */
784 dev_t device; /**< Device number for mknod */
785 struct class_device *dev_class;
789 typedef struct drm_fence_driver{
793 uint32_t sequence_mask;
795 int (*emit) (struct drm_device *dev, uint32_t flags,
796 uint32_t *breadcrumb,
797 uint32_t *native_type);
798 void (*poke_flush) (struct drm_device *dev);
799 } drm_fence_driver_t;
801 #define _DRM_FENCE_TYPE_EXE 0x00
803 typedef struct drm_fence_manager{
808 * The list below should be maintained in sequence order and
809 * access is protected by the above spinlock.
812 struct list_head ring;
813 struct list_head *fence_types[32];
814 volatile uint32_t pending_flush;
815 wait_queue_head_t fence_queue;
816 int pending_exe_flush;
817 uint32_t last_exe_flush;
818 uint32_t exe_flush_sequence;
820 } drm_fence_manager_t;
822 typedef struct drm_buffer_manager{
823 struct mutex init_mutex;
824 struct mutex evict_mutex;
827 drm_file_t *last_to_validate;
828 drm_mem_type_manager_t man[DRM_BO_MEM_TYPES];
829 struct list_head unfenced;
830 struct list_head ddestroy;
831 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
832 struct work_struct wq;
834 struct delayed_work wq;
837 unsigned long cur_pages;
839 } drm_buffer_manager_t;
844 * DRM device structure. This structure represent a complete card that
845 * may contain multiple heads.
847 typedef struct drm_device {
848 char *unique; /**< Unique identifier: e.g., busid */
849 int unique_len; /**< Length of unique field */
850 char *devname; /**< For /proc/interrupts */
851 int if_version; /**< Highest interface version set */
853 int blocked; /**< Blocked due to VC switch? */
857 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
858 struct mutex struct_mutex; /**< For others */
861 /** \name Usage Counters */
863 int open_count; /**< Outstanding files open */
864 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
865 atomic_t vma_count; /**< Outstanding vma areas open */
866 int buf_use; /**< Buffers in use -- cannot alloc */
867 atomic_t buf_alloc; /**< Buffer allocation in progress */
870 /** \name Performance counters */
872 unsigned long counters;
873 drm_stat_type_t types[15];
877 /** \name Authentication */
879 drm_file_t *file_first; /**< file list head */
880 drm_file_t *file_last; /**< file list tail */
881 drm_open_hash_t magiclist;
882 struct list_head magicfree;
885 /** \name Memory management */
887 drm_map_list_t *maplist; /**< Linked list of regions */
888 int map_count; /**< Number of mappable regions */
889 drm_open_hash_t map_hash; /**< User token hash table for maps */
890 drm_mm_t offset_manager; /**< User token manager */
891 drm_open_hash_t object_hash; /**< User token hash table for objects */
892 struct address_space *dev_mapping; /**< For unmap_mapping_range() */
893 struct page *ttm_dummy_page;
895 /** \name Context handle management */
897 drm_ctx_list_t *ctxlist; /**< Linked list of context handles */
898 int ctx_count; /**< Number of context handles */
899 struct mutex ctxlist_mutex; /**< For ctxlist */
901 drm_map_t **context_sareas; /**< per-context SAREA's */
904 drm_vma_entry_t *vmalist; /**< List of vmas (for debugging) */
905 drm_lock_data_t lock; /**< Information on hardware lock */
908 /** \name DMA queues (contexts) */
910 int queue_count; /**< Number of active DMA queues */
911 int queue_reserved; /**< Number of reserved DMA queues */
912 int queue_slots; /**< Actual length of queuelist */
913 drm_queue_t **queuelist; /**< Vector of pointers to DMA queues */
914 drm_device_dma_t *dma; /**< Optional pointer for DMA support */
917 /** \name Context support */
919 int irq; /**< Interrupt used by board */
920 int irq_enabled; /**< True if irq handler is enabled */
921 __volatile__ long context_flag; /**< Context swapping flag */
922 __volatile__ long interrupt_flag; /**< Interruption handler flag */
923 __volatile__ long dma_flag; /**< DMA dispatch flag */
924 struct timer_list timer; /**< Timer for delaying ctx switch */
925 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
926 int last_checked; /**< Last context checked for DMA */
927 int last_context; /**< Last current context */
928 unsigned long last_switch; /**< jiffies at last context switch */
931 struct work_struct work;
933 /** \name VBLANK IRQ support */
936 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
937 atomic_t vbl_received;
938 atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
940 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
941 drm_vbl_sig_t vbl_sigs2; /**< signals to send on secondary VBLANK */
942 unsigned int vbl_pending;
943 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
944 void (*locked_tasklet_func)(struct drm_device *dev);
950 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
951 wait_queue_head_t buf_readers; /**< Processes waiting to read */
952 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
954 drm_agp_head_t *agp; /**< AGP data */
956 struct pci_dev *pdev; /**< PCI device structure */
957 int pci_vendor; /**< PCI vendor id */
958 int pci_device; /**< PCI device id */
960 struct pci_controller *hose;
962 drm_sg_mem_t *sg; /**< Scatter gather memory */
963 unsigned long *ctx_bitmap; /**< context bitmap */
964 void *dev_private; /**< device private data */
965 drm_sigdata_t sigdata; /**< For block_all_signals */
968 struct drm_driver *driver;
969 drm_local_map_t *agp_buffer_map;
970 unsigned int agp_buffer_token;
971 drm_head_t primary; /**< primary screen head */
973 drm_fence_manager_t fm;
974 drm_buffer_manager_t bm;
976 /** \name Drawable information */
979 unsigned int drw_bitfield_length;
981 unsigned int drw_info_length;
982 drm_drawable_info_t **drw_info;
987 typedef struct drm_agp_ttm_priv {
989 struct agp_bridge_data *bridge;
991 unsigned cached_type;
992 unsigned uncached_type;
997 typedef struct drm_fence_object{
998 drm_user_object_t base;
1002 * The below three fields are protected by the fence manager spinlock.
1005 struct list_head ring;
1007 uint32_t native_type;
1011 uint32_t flush_mask;
1012 uint32_t submitted_flush;
1013 } drm_fence_object_t;
1016 typedef struct drm_buffer_object{
1018 drm_user_object_t base;
1021 * If there is a possibility that the usage variable is zero,
1022 * then dev->struct_mutext should be locked before incrementing it.
1026 unsigned long buffer_start;
1028 unsigned long offset;
1030 drm_bo_mem_reg_t mem;
1032 struct list_head lru;
1033 struct list_head ddestroy;
1035 uint32_t fence_type;
1036 uint32_t fence_class;
1037 drm_fence_object_t *fence;
1038 uint32_t priv_flags;
1039 wait_queue_head_t event_queue;
1042 /* For pinned buffers */
1043 drm_mm_node_t *pinned_node;
1044 uint32_t pinned_mem_type;
1045 struct list_head pinned_lru;
1050 drm_map_list_t map_list;
1051 uint32_t memory_type;
1052 unsigned long bus_offset;
1057 #ifdef DRM_ODD_MM_COMPAT
1058 /* dev->struct_mutex only protected. */
1059 struct list_head vma_list;
1060 struct list_head p_mm_list;
1063 } drm_buffer_object_t;
1065 #define _DRM_BO_FLAG_UNFENCED 0x00000001
1066 #define _DRM_BO_FLAG_EVICTED 0x00000002
1069 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1072 return ((dev->driver->driver_features & feature) ? 1 : 0);
1076 #define drm_get_pci_domain(dev) dev->hose->bus->number
1078 #define drm_get_pci_domain(dev) 0
1082 static inline int drm_core_has_AGP(struct drm_device *dev)
1084 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1087 #define drm_core_has_AGP(dev) (0)
1091 static inline int drm_core_has_MTRR(struct drm_device *dev)
1093 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1096 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
1098 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1101 return mtrr_add(offset, size, flags, 1);
1104 static inline int drm_mtrr_del(int handle, unsigned long offset,
1105 unsigned long size, unsigned int flags)
1107 return mtrr_del(handle, offset, size);
1111 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1117 static inline int drm_mtrr_del(int handle, unsigned long offset,
1118 unsigned long size, unsigned int flags)
1123 #define drm_core_has_MTRR(dev) (0)
1124 #define DRM_MTRR_WC 0
1128 /******************************************************************/
1129 /** \name Internal function definitions */
1132 /* Driver support (drm_drv.h) */
1133 extern int drm_fb_loaded;
1134 extern int drm_init(struct drm_driver *driver,
1135 struct pci_device_id *pciidlist);
1136 extern void drm_exit(struct drm_driver *driver);
1137 extern void drm_cleanup_pci(struct pci_dev *pdev);
1138 extern int drm_ioctl(struct inode *inode, struct file *filp,
1139 unsigned int cmd, unsigned long arg);
1140 extern long drm_compat_ioctl(struct file *filp,
1141 unsigned int cmd, unsigned long arg);
1143 extern int drm_lastclose(drm_device_t * dev);
1145 /* Device support (drm_fops.h) */
1146 extern int drm_open(struct inode *inode, struct file *filp);
1147 extern int drm_stub_open(struct inode *inode, struct file *filp);
1148 extern int drm_fasync(int fd, struct file *filp, int on);
1149 extern int drm_release(struct inode *inode, struct file *filp);
1150 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1152 /* Mapping support (drm_vm.h) */
1153 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1154 extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
1155 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1156 extern pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma);
1158 /* Memory management support (drm_memory.h) */
1159 #include "drm_memory.h"
1160 extern void drm_mem_init(void);
1161 extern int drm_mem_info(char *buf, char **start, off_t offset,
1162 int request, int *eof, void *data);
1163 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1164 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
1165 extern unsigned long drm_alloc_pages(int order, int area);
1166 extern void drm_free_pages(unsigned long address, int order, int area);
1167 extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t *dev, int pages, u32 type);
1168 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
1169 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1170 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1172 extern void drm_free_memctl(size_t size);
1173 extern int drm_alloc_memctl(size_t size);
1174 extern void drm_query_memctl(drm_u64_t *cur_used,
1175 drm_u64_t *low_threshold,
1176 drm_u64_t *high_threshold);
1177 extern void drm_init_memctl(size_t low_threshold,
1178 size_t high_threshold,
1181 /* Misc. IOCTL support (drm_ioctl.h) */
1182 extern int drm_irq_by_busid(struct inode *inode, struct file *filp,
1183 unsigned int cmd, unsigned long arg);
1184 extern int drm_getunique(struct inode *inode, struct file *filp,
1185 unsigned int cmd, unsigned long arg);
1186 extern int drm_setunique(struct inode *inode, struct file *filp,
1187 unsigned int cmd, unsigned long arg);
1188 extern int drm_getmap(struct inode *inode, struct file *filp,
1189 unsigned int cmd, unsigned long arg);
1190 extern int drm_getclient(struct inode *inode, struct file *filp,
1191 unsigned int cmd, unsigned long arg);
1192 extern int drm_getstats(struct inode *inode, struct file *filp,
1193 unsigned int cmd, unsigned long arg);
1194 extern int drm_setversion(struct inode *inode, struct file *filp,
1195 unsigned int cmd, unsigned long arg);
1196 extern int drm_noop(struct inode *inode, struct file *filp,
1197 unsigned int cmd, unsigned long arg);
1199 /* Context IOCTL support (drm_context.h) */
1200 extern int drm_resctx(struct inode *inode, struct file *filp,
1201 unsigned int cmd, unsigned long arg);
1202 extern int drm_addctx(struct inode *inode, struct file *filp,
1203 unsigned int cmd, unsigned long arg);
1204 extern int drm_modctx(struct inode *inode, struct file *filp,
1205 unsigned int cmd, unsigned long arg);
1206 extern int drm_getctx(struct inode *inode, struct file *filp,
1207 unsigned int cmd, unsigned long arg);
1208 extern int drm_switchctx(struct inode *inode, struct file *filp,
1209 unsigned int cmd, unsigned long arg);
1210 extern int drm_newctx(struct inode *inode, struct file *filp,
1211 unsigned int cmd, unsigned long arg);
1212 extern int drm_rmctx(struct inode *inode, struct file *filp,
1213 unsigned int cmd, unsigned long arg);
1215 extern int drm_ctxbitmap_init(drm_device_t * dev);
1216 extern void drm_ctxbitmap_cleanup(drm_device_t * dev);
1217 extern void drm_ctxbitmap_free(drm_device_t * dev, int ctx_handle);
1219 extern int drm_setsareactx(struct inode *inode, struct file *filp,
1220 unsigned int cmd, unsigned long arg);
1221 extern int drm_getsareactx(struct inode *inode, struct file *filp,
1222 unsigned int cmd, unsigned long arg);
1224 /* Drawable IOCTL support (drm_drawable.h) */
1225 extern int drm_adddraw(struct inode *inode, struct file *filp,
1226 unsigned int cmd, unsigned long arg);
1227 extern int drm_rmdraw(struct inode *inode, struct file *filp,
1228 unsigned int cmd, unsigned long arg);
1229 extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
1230 unsigned int cmd, unsigned long arg);
1231 extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
1234 /* Authentication IOCTL support (drm_auth.h) */
1235 extern int drm_getmagic(struct inode *inode, struct file *filp,
1236 unsigned int cmd, unsigned long arg);
1237 extern int drm_authmagic(struct inode *inode, struct file *filp,
1238 unsigned int cmd, unsigned long arg);
1240 /* Locking IOCTL support (drm_lock.h) */
1241 extern int drm_lock(struct inode *inode, struct file *filp,
1242 unsigned int cmd, unsigned long arg);
1243 extern int drm_unlock(struct inode *inode, struct file *filp,
1244 unsigned int cmd, unsigned long arg);
1245 extern int drm_lock_take(__volatile__ unsigned int *lock, unsigned int context);
1246 extern int drm_lock_free(drm_device_t * dev,
1247 __volatile__ unsigned int *lock, unsigned int context);
1249 * These are exported to drivers so that they can implement fencing using
1250 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1253 extern int drm_i_have_hw_lock(struct file *filp);
1254 extern int drm_kernel_take_hw_lock(struct file *filp);
1256 /* Buffer management support (drm_bufs.h) */
1257 extern int drm_addbufs_agp(drm_device_t * dev, drm_buf_desc_t * request);
1258 extern int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request);
1259 extern int drm_addbufs_fb (drm_device_t * dev, drm_buf_desc_t * request);
1260 extern int drm_addmap(drm_device_t * dev, unsigned int offset,
1261 unsigned int size, drm_map_type_t type,
1262 drm_map_flags_t flags, drm_local_map_t ** map_ptr);
1263 extern int drm_addmap_ioctl(struct inode *inode, struct file *filp,
1264 unsigned int cmd, unsigned long arg);
1265 extern int drm_rmmap(drm_device_t *dev, drm_local_map_t *map);
1266 extern int drm_rmmap_locked(drm_device_t *dev, drm_local_map_t *map);
1267 extern int drm_rmmap_ioctl(struct inode *inode, struct file *filp,
1268 unsigned int cmd, unsigned long arg);
1269 extern int drm_addbufs(struct inode *inode, struct file *filp,
1270 unsigned int cmd, unsigned long arg);
1271 extern int drm_infobufs(struct inode *inode, struct file *filp,
1272 unsigned int cmd, unsigned long arg);
1273 extern int drm_markbufs(struct inode *inode, struct file *filp,
1274 unsigned int cmd, unsigned long arg);
1275 extern int drm_freebufs(struct inode *inode, struct file *filp,
1276 unsigned int cmd, unsigned long arg);
1277 extern int drm_mapbufs(struct inode *inode, struct file *filp,
1278 unsigned int cmd, unsigned long arg);
1279 extern int drm_order(unsigned long size);
1280 extern unsigned long drm_get_resource_start(drm_device_t *dev,
1281 unsigned int resource);
1282 extern unsigned long drm_get_resource_len(drm_device_t *dev,
1283 unsigned int resource);
1285 /* DMA support (drm_dma.h) */
1286 extern int drm_dma_setup(drm_device_t * dev);
1287 extern void drm_dma_takedown(drm_device_t * dev);
1288 extern void drm_free_buffer(drm_device_t * dev, drm_buf_t * buf);
1289 extern void drm_core_reclaim_buffers(drm_device_t *dev, struct file *filp);
1291 /* IRQ support (drm_irq.h) */
1292 extern int drm_control(struct inode *inode, struct file *filp,
1293 unsigned int cmd, unsigned long arg);
1294 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1295 extern int drm_irq_uninstall(drm_device_t *dev);
1296 extern void drm_driver_irq_preinstall(drm_device_t * dev);
1297 extern void drm_driver_irq_postinstall(drm_device_t * dev);
1298 extern void drm_driver_irq_uninstall(drm_device_t * dev);
1300 extern int drm_wait_vblank(struct inode *inode, struct file *filp,
1301 unsigned int cmd, unsigned long arg);
1302 extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
1303 extern void drm_vbl_send_signals(drm_device_t * dev);
1304 extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));
1306 /* AGP/GART support (drm_agpsupport.h) */
1307 extern drm_agp_head_t *drm_agp_init(drm_device_t *dev);
1308 extern int drm_agp_acquire(drm_device_t * dev);
1309 extern int drm_agp_acquire_ioctl(struct inode *inode, struct file *filp,
1310 unsigned int cmd, unsigned long arg);
1311 extern int drm_agp_release(drm_device_t *dev);
1312 extern int drm_agp_release_ioctl(struct inode *inode, struct file *filp,
1313 unsigned int cmd, unsigned long arg);
1314 extern int drm_agp_enable(drm_device_t *dev, drm_agp_mode_t mode);
1315 extern int drm_agp_enable_ioctl(struct inode *inode, struct file *filp,
1316 unsigned int cmd, unsigned long arg);
1317 extern int drm_agp_info(drm_device_t * dev, drm_agp_info_t *info);
1318 extern int drm_agp_info_ioctl(struct inode *inode, struct file *filp,
1319 unsigned int cmd, unsigned long arg);
1320 extern int drm_agp_alloc(drm_device_t *dev, drm_agp_buffer_t *request);
1321 extern int drm_agp_alloc_ioctl(struct inode *inode, struct file *filp,
1322 unsigned int cmd, unsigned long arg);
1323 extern int drm_agp_free(drm_device_t *dev, drm_agp_buffer_t *request);
1324 extern int drm_agp_free_ioctl(struct inode *inode, struct file *filp,
1325 unsigned int cmd, unsigned long arg);
1326 extern int drm_agp_unbind(drm_device_t *dev, drm_agp_binding_t *request);
1327 extern int drm_agp_unbind_ioctl(struct inode *inode, struct file *filp,
1328 unsigned int cmd, unsigned long arg);
1329 extern int drm_agp_bind(drm_device_t *dev, drm_agp_binding_t *request);
1330 extern int drm_agp_bind_ioctl(struct inode *inode, struct file *filp,
1331 unsigned int cmd, unsigned long arg);
1332 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
1333 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
1335 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1337 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1338 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1339 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1340 extern drm_ttm_backend_t *drm_agp_init_ttm(struct drm_device *dev,
1341 drm_ttm_backend_t *backend);
1342 /* Stub support (drm_stub.h) */
1343 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1344 struct drm_driver *driver);
1345 extern int drm_put_dev(drm_device_t * dev);
1346 extern int drm_put_head(drm_head_t * head);
1347 extern unsigned int drm_debug; /* 1 to enable debug output */
1348 extern unsigned int drm_cards_limit;
1349 extern drm_head_t **drm_heads;
1350 extern struct drm_sysfs_class *drm_class;
1351 extern struct proc_dir_entry *drm_proc_root;
1353 /* Proc support (drm_proc.h) */
1354 extern int drm_proc_init(drm_device_t * dev,
1356 struct proc_dir_entry *root,
1357 struct proc_dir_entry **dev_root);
1358 extern int drm_proc_cleanup(int minor,
1359 struct proc_dir_entry *root,
1360 struct proc_dir_entry *dev_root);
1362 /* Scatter Gather Support (drm_scatter.h) */
1363 extern void drm_sg_cleanup(drm_sg_mem_t * entry);
1364 extern int drm_sg_alloc(struct inode *inode, struct file *filp,
1365 unsigned int cmd, unsigned long arg);
1366 extern int drm_sg_free(struct inode *inode, struct file *filp,
1367 unsigned int cmd, unsigned long arg);
1369 /* ATI PCIGART support (ati_pcigart.h) */
1370 extern int drm_ati_pcigart_init(drm_device_t * dev, drm_ati_pcigart_info *gart_info);
1371 extern int drm_ati_pcigart_cleanup(drm_device_t * dev, drm_ati_pcigart_info *gart_info);
1373 extern drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size,
1374 size_t align, dma_addr_t maxaddr);
1375 extern void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t *dmah);
1376 extern void drm_pci_free(drm_device_t * dev, drm_dma_handle_t *dmah);
1378 /* sysfs support (drm_sysfs.c) */
1379 struct drm_sysfs_class;
1380 extern struct drm_sysfs_class *drm_sysfs_create(struct module *owner,
1382 extern void drm_sysfs_destroy(struct drm_sysfs_class *cs);
1383 extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
1385 extern void drm_sysfs_device_remove(struct class_device *class_dev);
1388 * Basic memory manager support (drm_mm.c)
1391 extern drm_mm_node_t * drm_mm_get_block(drm_mm_node_t * parent, unsigned long size,
1392 unsigned alignment);
1393 extern void drm_mm_put_block(drm_mm_node_t *cur);
1394 extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size,
1395 unsigned alignment, int best_match);
1396 extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size);
1397 extern void drm_mm_takedown(drm_mm_t *mm);
1398 extern int drm_mm_clean(drm_mm_t *mm);
1399 extern unsigned long drm_mm_tail_space(drm_mm_t *mm);
1400 extern int drm_mm_remove_space_from_tail(drm_mm_t *mm, unsigned long size);
1401 extern int drm_mm_add_space_to_tail(drm_mm_t *mm, unsigned long size);
1403 static inline drm_mm_t *drm_get_mm(drm_mm_node_t *block)
1410 * User space object bookkeeping (drm_object.c)
1414 * Must be called with the struct_mutex held.
1417 extern int drm_add_user_object(drm_file_t *priv, drm_user_object_t *item,
1420 * Must be called with the struct_mutex held.
1423 extern drm_user_object_t *drm_lookup_user_object(drm_file_t *priv, uint32_t key);
1426 * Must be called with the struct_mutex held.
1427 * If "item" has been obtained by a call to drm_lookup_user_object. You may not
1428 * release the struct_mutex before calling drm_remove_ref_object.
1429 * This function may temporarily release the struct_mutex.
1432 extern int drm_remove_user_object(drm_file_t *priv, drm_user_object_t *item);
1435 * Must be called with the struct_mutex held. May temporarily release it.
1438 extern int drm_add_ref_object(drm_file_t *priv, drm_user_object_t *referenced_object,
1439 drm_ref_t ref_action);
1442 * Must be called with the struct_mutex held.
1445 drm_ref_object_t *drm_lookup_ref_object(drm_file_t *priv,
1446 drm_user_object_t *referenced_object,
1447 drm_ref_t ref_action);
1449 * Must be called with the struct_mutex held.
1450 * If "item" has been obtained by a call to drm_lookup_ref_object. You may not
1451 * release the struct_mutex before calling drm_remove_ref_object.
1452 * This function may temporarily release the struct_mutex.
1455 extern void drm_remove_ref_object(drm_file_t *priv, drm_ref_object_t *item);
1456 extern int drm_user_object_ref(drm_file_t *priv, uint32_t user_token, drm_object_type_t type,
1457 drm_user_object_t **object);
1458 extern int drm_user_object_unref(drm_file_t *priv, uint32_t user_token, drm_object_type_t type);
1463 * fence objects (drm_fence.c)
1466 extern void drm_fence_handler(drm_device_t *dev, uint32_t breadcrumb, uint32_t type);
1467 extern void drm_fence_manager_init(drm_device_t *dev);
1468 extern void drm_fence_manager_takedown(drm_device_t *dev);
1469 extern void drm_fence_flush_old(drm_device_t *dev, uint32_t sequence);
1470 extern int drm_fence_object_flush(drm_device_t * dev,
1471 volatile drm_fence_object_t * fence,
1473 extern int drm_fence_object_signaled(volatile drm_fence_object_t * fence,
1475 extern void drm_fence_usage_deref_locked(drm_device_t * dev,
1476 drm_fence_object_t * fence);
1477 extern void drm_fence_usage_deref_unlocked(drm_device_t * dev,
1478 drm_fence_object_t * fence);
1479 extern int drm_fence_object_wait(drm_device_t * dev,
1480 volatile drm_fence_object_t * fence,
1481 int lazy, int ignore_signals, uint32_t mask);
1482 extern int drm_fence_object_create(drm_device_t *dev, uint32_t type,
1483 uint32_t fence_flags,
1484 drm_fence_object_t **c_fence);
1485 extern int drm_fence_add_user_object(drm_file_t *priv,
1486 drm_fence_object_t *fence,
1493 extern int drm_fence_ioctl(DRM_IOCTL_ARGS);
1496 * buffer objects (drm_bo.c)
1499 extern int drm_bo_ioctl(DRM_IOCTL_ARGS);
1500 extern int drm_mm_init_ioctl(DRM_IOCTL_ARGS);
1501 extern int drm_bo_driver_finish(drm_device_t *dev);
1502 extern int drm_bo_driver_init(drm_device_t *dev);
1503 extern int drm_bo_pci_offset(drm_device_t *dev,
1504 drm_bo_mem_reg_t *mem,
1505 unsigned long *bus_base,
1506 unsigned long *bus_offset,
1507 unsigned long *bus_size);
1508 extern int drm_mem_reg_is_pci(drm_device_t *dev, drm_bo_mem_reg_t *mem);
1511 extern void drm_bo_usage_deref_locked(drm_buffer_object_t * bo);
1512 extern int drm_fence_buffer_objects(drm_file_t * priv,
1513 struct list_head *list,
1514 uint32_t fence_flags,
1515 drm_fence_object_t *fence,
1516 drm_fence_object_t **used_fence);
1517 extern void drm_bo_add_to_lru(drm_buffer_object_t * bo);
1518 extern int drm_bo_wait(drm_buffer_object_t * bo, int lazy, int ignore_signals,
1520 extern int drm_bo_mem_space(drm_buffer_object_t *bo,
1521 drm_bo_mem_reg_t *mem,
1526 * Buffer object memory move helpers.
1530 extern int drm_bo_move_ttm(drm_buffer_object_t *bo,
1533 drm_bo_mem_reg_t *new_mem);
1534 extern int drm_bo_move_memcpy(drm_buffer_object_t *bo,
1537 drm_bo_mem_reg_t *new_mem);
1538 extern int drm_bo_move_accel_cleanup(drm_buffer_object_t *bo,
1541 uint32_t fence_type,
1542 uint32_t fence_flags,
1543 drm_bo_mem_reg_t *new_mem);
1545 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1546 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1548 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1551 drm_map_list_t *_entry;
1552 list_for_each_entry(_entry, &dev->maplist->head, head)
1553 if (_entry->user_token == token)
1558 static __inline__ int drm_device_is_agp(drm_device_t *dev)
1560 if ( dev->driver->device_is_agp != NULL ) {
1561 int err = (*dev->driver->device_is_agp)( dev );
1568 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1571 static __inline__ int drm_device_is_pcie(drm_device_t *dev)
1573 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1576 static __inline__ void drm_core_dropmap(struct drm_map *map)
1580 #ifndef DEBUG_MEMORY
1581 /** Wrapper around kmalloc() */
1582 static __inline__ void *drm_alloc(size_t size, int area)
1584 return kmalloc(size, GFP_KERNEL);
1587 /** Wrapper around kfree() */
1588 static __inline__ void drm_free(void *pt, size_t size, int area)
1593 extern void *drm_alloc(size_t size, int area);
1594 extern void drm_free(void *pt, size_t size, int area);
1598 * Accounting variants of standard calls.
1601 static inline void *drm_ctl_alloc(size_t size, int area)
1604 if (drm_alloc_memctl(size))
1606 ret = drm_alloc(size, area);
1608 drm_free_memctl(size);
1612 static inline void *drm_ctl_calloc(size_t nmemb, size_t size, int area)
1616 if (drm_alloc_memctl(nmemb*size))
1618 ret = drm_calloc(nmemb, size, area);
1620 drm_free_memctl(nmemb*size);
1624 static inline void drm_ctl_free(void *pt, size_t size, int area)
1626 drm_free(pt, size, area);
1627 drm_free_memctl(size);
1632 #endif /* __KERNEL__ */