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 */
55 #include <linux/dma-mapping.h>
57 #include <linux/kref.h>
58 #include <linux/pagemap.h>
59 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
60 #include <linux/mutex.h>
62 #if defined(__alpha__) || defined(__powerpc__)
63 #include <asm/pgtable.h> /* For pte_wrprotect */
67 #include <asm/uaccess.h>
72 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
73 #include <linux/types.h>
74 #include <linux/agp_backend.h>
76 #include <linux/workqueue.h>
77 #include <linux/poll.h>
78 #include <asm/pgalloc.h>
80 #include <linux/slab.h>
81 #include <linux/idr.h>
83 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
84 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
86 #include "drm_os_linux.h"
87 #include "drm_hashtab.h"
88 #include "drm_internal.h"
93 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
94 typedef unsigned long uintptr_t;
97 /* If you want the memory alloc debug functionality, change define below */
98 /* #define DEBUG_MEMORY */
100 /***********************************************************************/
101 /** \name DRM template customization defaults */
104 /* driver capabilities and requirements mask */
105 #define DRIVER_USE_AGP 0x1
106 #define DRIVER_REQUIRE_AGP 0x2
107 #define DRIVER_USE_MTRR 0x4
108 #define DRIVER_PCI_DMA 0x8
109 #define DRIVER_SG 0x10
110 #define DRIVER_HAVE_DMA 0x20
111 #define DRIVER_HAVE_IRQ 0x40
112 #define DRIVER_IRQ_SHARED 0x80
113 #define DRIVER_DMA_QUEUE 0x100
114 #define DRIVER_FB_DMA 0x200
115 #define DRIVER_GEM 0x400
119 /***********************************************************************/
120 /** \name Begin the DRM... */
123 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
124 also include looping detection. */
126 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
127 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
128 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
129 #define DRM_LOOPING_LIMIT 5000000
130 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
131 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
133 #define DRM_FLAG_DEBUG 0x01
135 #define DRM_MEM_DMA 0
136 #define DRM_MEM_SAREA 1
137 #define DRM_MEM_DRIVER 2
138 #define DRM_MEM_MAGIC 3
139 #define DRM_MEM_IOCTLS 4
140 #define DRM_MEM_MAPS 5
141 #define DRM_MEM_VMAS 6
142 #define DRM_MEM_BUFS 7
143 #define DRM_MEM_SEGS 8
144 #define DRM_MEM_PAGES 9
145 #define DRM_MEM_FILES 10
146 #define DRM_MEM_QUEUES 11
147 #define DRM_MEM_CMDS 12
148 #define DRM_MEM_MAPPINGS 13
149 #define DRM_MEM_BUFLISTS 14
150 #define DRM_MEM_AGPLISTS 15
151 #define DRM_MEM_TOTALAGP 16
152 #define DRM_MEM_BOUNDAGP 17
153 #define DRM_MEM_CTXBITMAP 18
154 #define DRM_MEM_STUB 19
155 #define DRM_MEM_SGLISTS 20
156 #define DRM_MEM_CTXLIST 21
157 #define DRM_MEM_MM 22
158 #define DRM_MEM_HASHTAB 23
159 #define DRM_MEM_OBJECTS 24
160 #define DRM_MEM_FENCE 25
161 #define DRM_MEM_TTM 26
162 #define DRM_MEM_BUFOBJ 27
164 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
165 #define DRM_MAP_HASH_OFFSET 0x10000000
166 #define DRM_MAP_HASH_ORDER 12
167 #define DRM_OBJECT_HASH_ORDER 12
168 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
169 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
171 * This should be small enough to allow the use of kmalloc for hash tables
172 * instead of vmalloc.
175 #define DRM_FILE_HASH_ORDER 8
176 #define DRM_MM_INIT_MAX_PAGES 256
180 #include "drm_compat.h"
182 /***********************************************************************/
183 /** \name Macros to make printk easier */
189 * \param fmt printf() like format string.
190 * \param arg arguments
192 #define DRM_ERROR(fmt, arg...) \
193 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
196 * Memory error output.
198 * \param area memory area where the error occurred.
199 * \param fmt printf() like format string.
200 * \param arg arguments
202 #define DRM_MEM_ERROR(area, fmt, arg...) \
203 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
204 drm_mem_stats[area].name , ##arg)
205 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
210 * \param fmt printf() like format string.
211 * \param arg arguments
214 #define DRM_DEBUG(fmt, arg...) \
218 "[" DRM_NAME ":%s] " fmt , \
219 __FUNCTION__ , ##arg); \
222 #define DRM_DEBUG(fmt, arg...) do { } while (0)
225 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
227 #define DRM_PROC_PRINT(fmt, arg...) \
228 len += sprintf(&buf[len], fmt , ##arg); \
229 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
231 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
232 len += sprintf(&buf[len], fmt , ##arg); \
233 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
237 /***********************************************************************/
238 /** \name Internal types and structures */
241 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
242 #define DRM_MIN(a,b) min(a,b)
243 #define DRM_MAX(a,b) max(a,b)
245 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
246 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
247 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
249 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
251 * Get the private SAREA mapping.
253 * \param _dev DRM device.
254 * \param _ctx context number.
255 * \param _map output mapping.
257 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
258 (_map) = (_dev)->context_sareas[_ctx]; \
262 * Test that the hardware lock is held by the caller, returning otherwise.
264 * \param dev DRM device.
265 * \param file_priv DRM file private pointer of the caller.
267 #define LOCK_TEST_WITH_RETURN( dev, file_priv ) \
269 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
270 dev->lock.file_priv != file_priv ) { \
271 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
272 __FUNCTION__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
273 dev->lock.file_priv, file_priv ); \
279 * Copy and IOCTL return string to user space
281 #define DRM_COPY( name, value ) \
282 len = strlen( value ); \
283 if ( len > name##_len ) len = name##_len; \
284 name##_len = strlen( value ); \
285 if ( len && name ) { \
286 if ( copy_to_user( name, value, len ) ) \
291 * Ioctl function type.
293 * \param dev DRM device structure
294 * \param data pointer to kernel-space stored data, copied in and out according
295 * to ioctl description.
296 * \param file_priv DRM file private pointer.
298 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
299 struct drm_file *file_priv);
301 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
305 #define DRM_MASTER 0x2
306 #define DRM_ROOT_ONLY 0x4
308 struct drm_ioctl_desc {
314 * Creates a driver or general drm_ioctl_desc array entry for the given
315 * ioctl, for use by drm_ioctl().
317 #define DRM_IOCTL_DEF(ioctl, func, flags) \
318 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
320 struct drm_magic_entry {
321 struct list_head head;
322 struct drm_hash_item hash_item;
323 struct drm_file *priv;
326 struct drm_vma_entry {
327 struct list_head head;
328 struct vm_area_struct *vma;
336 int idx; /**< Index into master buflist */
337 int total; /**< Buffer size */
338 int order; /**< log-base-2(total) */
339 int used; /**< Amount of buffer in use (for DMA) */
340 unsigned long offset; /**< Byte offset (used internally) */
341 void *address; /**< Address of buffer */
342 unsigned long bus_address; /**< Bus address of buffer */
343 struct drm_buf *next; /**< Kernel-only: used for free list */
344 __volatile__ int waiting; /**< On kernel DMA queue */
345 __volatile__ int pending; /**< On hardware DMA queue */
346 wait_queue_head_t dma_wait; /**< Processes waiting */
347 struct drm_file *file_priv; /**< Private of holding file descr */
348 int context; /**< Kernel queue for this buffer */
349 int while_locked; /**< Dispatch this buffer while locked */
357 } list; /**< Which list we're on */
359 int dev_priv_size; /**< Size of buffer private storage */
360 void *dev_private; /**< Per-buffer private storage */
363 /** bufs is one longer than it has to be */
364 struct drm_waitlist {
365 int count; /**< Number of possible buffers */
366 struct drm_buf **bufs; /**< List of pointers to buffers */
367 struct drm_buf **rp; /**< Read pointer */
368 struct drm_buf **wp; /**< Write pointer */
369 struct drm_buf **end; /**< End pointer */
370 spinlock_t read_lock;
371 spinlock_t write_lock;
374 struct drm_freelist {
375 int initialized; /**< Freelist in use */
376 atomic_t count; /**< Number of free buffers */
377 struct drm_buf *next; /**< End pointer */
379 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
380 int low_mark; /**< Low water mark */
381 int high_mark; /**< High water mark */
382 atomic_t wfh; /**< If waiting for high mark */
386 typedef struct drm_dma_handle {
393 * Buffer entry. There is one of this for each buffer size order.
395 struct drm_buf_entry {
396 int buf_size; /**< size */
397 int buf_count; /**< number of buffers */
398 struct drm_buf *buflist; /**< buffer list */
401 struct drm_dma_handle **seglist;
402 struct drm_freelist freelist;
413 /** File private data */
420 unsigned long ioctl_count;
421 struct list_head lhead;
422 struct drm_minor *minor;
423 int remove_auth_on_close;
424 unsigned long lock_count;
427 * The user object hash table is global and resides in the
428 * drm_device structure. We protect the lists and hash tables with the
429 * device struct_mutex. A bit coarse-grained but probably the best
433 struct list_head refd_objects;
435 /** Mapping of mm object handles to object pointers. */
436 struct idr object_idr;
437 /** Lock for synchronization of access to object_idr. */
438 spinlock_t table_lock;
440 struct drm_open_hash refd_object_hash[_DRM_NO_REF_TYPES];
447 atomic_t use_count; /**< Outstanding uses (+1) */
448 atomic_t finalization; /**< Finalization in progress */
449 atomic_t block_count; /**< Count of processes waiting */
450 atomic_t block_read; /**< Queue blocked for reads */
451 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
452 atomic_t block_write; /**< Queue blocked for writes */
453 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
455 atomic_t total_queued; /**< Total queued statistic */
456 atomic_t total_flushed; /**< Total flushes statistic */
457 atomic_t total_locks; /**< Total locks statistics */
459 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
460 struct drm_waitlist waitlist; /**< Pending buffers */
461 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
467 struct drm_lock_data {
468 struct drm_hw_lock *hw_lock; /**< Hardware lock */
469 /** Private of lock holder's file (NULL=kernel) */
470 struct drm_file *file_priv;
471 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
472 unsigned long lock_time; /**< Time of last lock in jiffies */
474 uint32_t kernel_waiters;
475 uint32_t user_waiters;
478 * Boolean signaling that the lock is held on behalf of the
479 * file_priv client by the kernel in an ioctl handler.
487 struct drm_device_dma {
489 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
490 int buf_count; /**< total number of buffers */
491 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
493 int page_count; /**< number of pages */
494 unsigned long *pagelist; /**< page list */
495 unsigned long byte_count;
497 _DRM_DMA_USE_AGP = 0x01,
498 _DRM_DMA_USE_SG = 0x02,
499 _DRM_DMA_USE_FB = 0x04,
500 _DRM_DMA_USE_PCI_RO = 0x08
506 * AGP memory entry. Stored as a doubly linked list.
509 unsigned long handle; /**< handle */
511 unsigned long bound; /**< address */
513 struct list_head head;
519 * \sa drm_agp_init() and drm_device::agp.
521 struct drm_agp_head {
522 DRM_AGP_KERN agp_info; /**< AGP device information */
523 struct list_head memory;
524 unsigned long mode; /**< AGP mode */
525 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
526 struct agp_bridge_data *bridge;
528 int enabled; /**< whether the AGP bus as been enabled */
529 int acquired; /**< whether the AGP device has been acquired */
532 int cant_use_aperture;
533 unsigned long page_mask;
537 * Scatter-gather memory.
540 unsigned long handle;
543 struct page **pagelist;
549 struct drm_hw_lock *lock;
554 * Generic memory manager structs
557 struct drm_memrange_node {
558 struct list_head fl_entry;
559 struct list_head ml_entry;
563 struct drm_memrange *mm;
567 struct drm_memrange {
568 struct list_head fl_entry;
569 struct list_head ml_entry;
576 struct drm_map_list {
577 struct list_head head; /**< list head */
578 struct drm_hash_item hash;
579 struct drm_map *map; /**< mapping */
581 struct drm_memrange_node *file_offset_node;
584 typedef struct drm_map drm_local_map_t;
587 * Context handle list
589 struct drm_ctx_list {
590 struct list_head head; /**< list head */
591 drm_context_t handle; /**< context handle */
592 struct drm_file *tag; /**< associated fd private data */
596 struct list_head head;
597 unsigned int sequence;
599 struct task_struct *task;
602 /* location of GART table */
603 #define DRM_ATI_GART_MAIN 1
604 #define DRM_ATI_GART_FB 2
606 #define DRM_ATI_GART_PCI 1
607 #define DRM_ATI_GART_PCIE 2
608 #define DRM_ATI_GART_IGP 3
610 struct drm_ati_pcigart_info {
611 int gart_table_location;
615 dma_addr_t table_mask;
616 dma_addr_t member_mask;
617 struct drm_dma_handle *table_handle;
618 drm_local_map_t mapping;
623 * This structure defines the drm_mm memory object, which will be used by the
624 * DRM for its buffer objects.
626 struct drm_gem_object {
627 /** Reference count of this object */
628 struct kref refcount;
630 /** Handle count of this object. Each handle also holds a reference */
631 struct kref handlecount;
633 /** Related drm device */
634 struct drm_device *dev;
636 /** File representing the shmem storage */
640 * Size of the object, in bytes. Immutable over the object's
646 * Global name for this object, starts at 1. 0 means unnamed.
647 * Access is covered by the object_name_lock in the related drm_device
652 * Memory domains. These monitor which caches contain read/write data
653 * related to the object. When transitioning from one set of domains
654 * to another, the driver is called to ensure that caches are suitably
655 * flushed and invalidated
657 uint32_t read_domains;
658 uint32_t write_domain;
661 * While validating an exec operation, the
662 * new read/write domain values are computed here.
663 * They will be transferred to the above values
664 * at the point that any cache flushing occurs
666 uint32_t pending_read_domains;
667 uint32_t pending_write_domain;
669 void *driver_private;
672 #include "drm_objects.h"
675 * DRM driver structure. This structure represent the common code for
676 * a family of cards. There will one drm_device for each card present
681 int (*load) (struct drm_device *, unsigned long flags);
682 int (*firstopen) (struct drm_device *);
683 int (*open) (struct drm_device *, struct drm_file *);
684 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
685 void (*postclose) (struct drm_device *, struct drm_file *);
686 void (*lastclose) (struct drm_device *);
687 int (*unload) (struct drm_device *);
688 int (*suspend) (struct drm_device *, pm_message_t state);
689 int (*resume) (struct drm_device *);
690 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
691 void (*dma_ready) (struct drm_device *);
692 int (*dma_quiescent) (struct drm_device *);
693 int (*context_ctor) (struct drm_device *dev, int context);
694 int (*context_dtor) (struct drm_device *dev, int context);
695 int (*kernel_context_switch) (struct drm_device *dev, int old,
697 void (*kernel_context_switch_unlock) (struct drm_device * dev);
699 * get_vblank_counter - get raw hardware vblank counter
701 * @crtc: counter to fetch
703 * Driver callback for fetching a raw hardware vblank counter
704 * for @crtc. If a device doesn't have a hardware counter, the
705 * driver can simply return the value of drm_vblank_count and
706 * make the enable_vblank() and disable_vblank() hooks into no-ops,
707 * leaving interrupts enabled at all times.
709 * Wraparound handling and loss of events due to modesetting is dealt
710 * with in the DRM core code.
713 * Raw vblank counter value.
715 u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
718 * enable_vblank - enable vblank interrupt events
720 * @crtc: which irq to enable
722 * Enable vblank interrupts for @crtc. If the device doesn't have
723 * a hardware vblank counter, this routine should be a no-op, since
724 * interrupts will have to stay on to keep the count accurate.
727 * Zero on success, appropriate errno if the given @crtc's vblank
728 * interrupt cannot be enabled.
730 int (*enable_vblank) (struct drm_device *dev, int crtc);
733 * disable_vblank - disable vblank interrupt events
735 * @crtc: which irq to enable
737 * Disable vblank interrupts for @crtc. If the device doesn't have
738 * a hardware vblank counter, this routine should be a no-op, since
739 * interrupts will have to stay on to keep the count accurate.
741 void (*disable_vblank) (struct drm_device *dev, int crtc);
742 int (*dri_library_name) (struct drm_device *dev, char * buf);
745 * Called by \c drm_device_is_agp. Typically used to determine if a
746 * card is really attached to AGP or not.
748 * \param dev DRM device handle
751 * One of three values is returned depending on whether or not the
752 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
753 * (return of 1), or may or may not be AGP (return of 2).
755 int (*device_is_agp) (struct drm_device *dev);
757 /* these have to be filled in */
758 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
759 void (*irq_preinstall) (struct drm_device *dev);
760 int (*irq_postinstall) (struct drm_device *dev);
761 void (*irq_uninstall) (struct drm_device *dev);
762 void (*reclaim_buffers) (struct drm_device *dev,
763 struct drm_file *file_priv);
764 void (*reclaim_buffers_locked) (struct drm_device *dev,
765 struct drm_file *file_priv);
766 void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
767 struct drm_file *file_priv);
768 unsigned long (*get_map_ofs) (struct drm_map *map);
769 unsigned long (*get_reg_ofs) (struct drm_device *dev);
770 void (*set_version) (struct drm_device *dev,
771 struct drm_set_version *sv);
774 * Driver-specific constructor for drm_gem_objects, to set up
775 * obj->driver_private.
777 * Returns 0 on success.
779 int (*gem_init_object) (struct drm_gem_object *obj);
780 void (*gem_free_object) (struct drm_gem_object *obj);
782 struct drm_fence_driver *fence_driver;
783 struct drm_bo_driver *bo_driver;
795 struct drm_ioctl_desc *ioctls;
797 struct file_operations fops;
798 struct pci_driver pci_driver;
801 #define DRM_MINOR_UNASSIGNED 0
802 #define DRM_MINOR_LEGACY 1
805 * DRM minor structure. This structure represents a drm minor number.
808 int index; /**< Minor device number */
809 int type; /**< Control or render */
810 dev_t device; /**< Device number for mknod */
811 struct device kdev; /**< Linux device */
812 struct drm_device *dev;
813 struct proc_dir_entry *dev_root; /**< proc directory entry */
814 struct class_device *dev_class;
819 * DRM device structure. This structure represent a complete card that
820 * may contain multiple heads.
823 char *unique; /**< Unique identifier: e.g., busid */
824 int unique_len; /**< Length of unique field */
825 char *devname; /**< For /proc/interrupts */
826 int if_version; /**< Highest interface version set */
828 int blocked; /**< Blocked due to VC switch? */
832 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
833 struct mutex struct_mutex; /**< For others */
836 /** \name Usage Counters */
838 int open_count; /**< Outstanding files open */
839 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
840 atomic_t vma_count; /**< Outstanding vma areas open */
841 int buf_use; /**< Buffers in use -- cannot alloc */
842 atomic_t buf_alloc; /**< Buffer allocation in progress */
845 /** \name Performance counters */
847 unsigned long counters;
848 enum drm_stat_type types[15];
852 /** \name Authentication */
854 struct list_head filelist;
855 struct drm_open_hash magiclist;
856 struct list_head magicfree;
859 /** \name Memory management */
861 struct list_head maplist; /**< Linked list of regions */
862 int map_count; /**< Number of mappable regions */
863 struct drm_open_hash map_hash; /**< User token hash table for maps */
864 struct drm_memrange offset_manager; /**< User token manager */
865 struct drm_open_hash object_hash; /**< User token hash table for objects */
866 struct address_space *dev_mapping; /**< For unmap_mapping_range() */
867 struct page *ttm_dummy_page;
869 /** \name Context handle management */
871 struct list_head ctxlist; /**< Linked list of context handles */
872 int ctx_count; /**< Number of context handles */
873 struct mutex ctxlist_mutex; /**< For ctxlist */
877 struct list_head vmalist; /**< List of vmas (for debugging) */
878 struct drm_lock_data lock; /**< Information on hardware lock */
881 /** \name DMA queues (contexts) */
883 int queue_count; /**< Number of active DMA queues */
884 int queue_reserved; /**< Number of reserved DMA queues */
885 int queue_slots; /**< Actual length of queuelist */
886 struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */
887 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
890 /** \name Context support */
892 int irq; /**< Interrupt used by board */
893 int irq_enabled; /**< True if irq handler is enabled */
894 __volatile__ long context_flag; /**< Context swapping flag */
895 __volatile__ long interrupt_flag; /**< Interruption handler flag */
896 __volatile__ long dma_flag; /**< DMA dispatch flag */
897 struct timer_list timer; /**< Timer for delaying ctx switch */
898 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
899 int last_checked; /**< Last context checked for DMA */
900 int last_context; /**< Last current context */
901 unsigned long last_switch; /**< jiffies at last context switch */
904 struct work_struct work;
906 /** \name VBLANK IRQ support */
909 wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */
910 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
912 struct list_head *vbl_sigs; /**< signal list to send on VBLANK */
913 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs*/
914 atomic_t *vblank_refcount; /* number of users of vblank interrupts per crtc */
915 u32 *last_vblank; /* protected by dev->vbl_lock, used */
916 /* for wraparound handling */
917 u32 *vblank_offset; /* used to track how many vblanks */
918 int *vblank_enabled; /* so we don't call enable more than
920 u32 *vblank_premodeset; /* were lost during modeset */
921 struct timer_list vblank_disable_timer;
923 unsigned long max_vblank_count; /**< size of vblank counter register */
924 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
925 void (*locked_tasklet_func)(struct drm_device *dev);
931 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
932 wait_queue_head_t buf_readers; /**< Processes waiting to read */
933 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
935 struct drm_agp_head *agp; /**< AGP data */
937 struct pci_dev *pdev; /**< PCI device structure */
938 int pci_vendor; /**< PCI vendor id */
939 int pci_device; /**< PCI device id */
941 struct pci_controller *hose;
943 int num_crtcs; /**< Number of CRTCs on this device */
944 struct drm_sg_mem *sg; /**< Scatter gather memory */
945 void *dev_private; /**< device private data */
946 struct drm_sigdata sigdata; /**< For block_all_signals */
949 struct drm_driver *driver;
950 drm_local_map_t *agp_buffer_map;
951 unsigned int agp_buffer_token;
952 struct drm_minor *primary; /**< render type primary screen head */
954 struct drm_fence_manager fm;
955 struct drm_buffer_manager bm;
957 /** \name Drawable information */
963 /** \name GEM information */
965 spinlock_t object_name_lock;
966 struct idr object_name_idr;
967 atomic_t object_count;
968 atomic_t object_memory;
974 uint32_t invalidate_domains; /* domains pending invalidation */
975 uint32_t flush_domains; /* domains pending flush */
980 struct drm_agp_ttm_backend {
981 struct drm_ttm_backend backend;
983 struct agp_bridge_data *bridge;
989 static __inline__ int drm_core_check_feature(struct drm_device *dev,
992 return ((dev->driver->driver_features & feature) ? 1 : 0);
996 #define drm_get_pci_domain(dev) dev->hose->index
998 #define drm_get_pci_domain(dev) 0
1002 static inline int drm_core_has_AGP(struct drm_device *dev)
1004 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1007 #define drm_core_has_AGP(dev) (0)
1011 static inline int drm_core_has_MTRR(struct drm_device *dev)
1013 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1016 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
1018 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1021 return mtrr_add(offset, size, flags, 1);
1024 static inline int drm_mtrr_del(int handle, unsigned long offset,
1025 unsigned long size, unsigned int flags)
1027 return mtrr_del(handle, offset, size);
1031 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1037 static inline int drm_mtrr_del(int handle, unsigned long offset,
1038 unsigned long size, unsigned int flags)
1043 #define drm_core_has_MTRR(dev) (0)
1044 #define DRM_MTRR_WC 0
1048 /******************************************************************/
1049 /** \name Internal function definitions */
1052 /* Driver support (drm_drv.h) */
1053 extern int drm_fb_loaded;
1054 extern int drm_init(struct drm_driver *driver,
1055 struct pci_device_id *pciidlist);
1056 extern void drm_exit(struct drm_driver *driver);
1057 extern void drm_cleanup_pci(struct pci_dev *pdev);
1058 extern int drm_ioctl(struct inode *inode, struct file *filp,
1059 unsigned int cmd, unsigned long arg);
1060 extern long drm_unlocked_ioctl(struct file *filp,
1061 unsigned int cmd, unsigned long arg);
1062 extern long drm_compat_ioctl(struct file *filp,
1063 unsigned int cmd, unsigned long arg);
1065 extern int drm_lastclose(struct drm_device *dev);
1067 /* Device support (drm_fops.h) */
1068 extern int drm_open(struct inode *inode, struct file *filp);
1069 extern int drm_stub_open(struct inode *inode, struct file *filp);
1070 extern int drm_fasync(int fd, struct file *filp, int on);
1071 extern int drm_release(struct inode *inode, struct file *filp);
1072 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1074 /* Mapping support (drm_vm.h) */
1075 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1076 extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
1077 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1078 extern pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma);
1080 /* Memory management support (drm_memory.h) */
1081 #include "drm_memory.h"
1082 extern void drm_mem_init(void);
1083 extern int drm_mem_info(char *buf, char **start, off_t offset,
1084 int request, int *eof, void *data);
1085 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1086 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
1087 extern unsigned long drm_alloc_pages(int order, int area);
1088 extern void drm_free_pages(unsigned long address, int order, int area);
1089 extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
1090 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
1091 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1092 extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1093 struct page **pages,
1094 unsigned long num_pages,
1095 uint32_t gtt_offset);
1096 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1098 extern void drm_free_memctl(size_t size);
1099 extern int drm_alloc_memctl(size_t size);
1100 extern void drm_query_memctl(uint64_t *cur_used,
1101 uint64_t *emer_used,
1102 uint64_t *low_threshold,
1103 uint64_t *high_threshold,
1104 uint64_t *emer_threshold);
1105 extern void drm_init_memctl(size_t low_threshold,
1106 size_t high_threshold,
1109 /* Misc. IOCTL support (drm_ioctl.h) */
1110 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1111 struct drm_file *file_priv);
1112 extern int drm_getunique(struct drm_device *dev, void *data,
1113 struct drm_file *file_priv);
1114 extern int drm_setunique(struct drm_device *dev, void *data,
1115 struct drm_file *file_priv);
1116 extern int drm_getmap(struct drm_device *dev, void *data,
1117 struct drm_file *file_priv);
1118 extern int drm_getclient(struct drm_device *dev, void *data,
1119 struct drm_file *file_priv);
1120 extern int drm_getstats(struct drm_device *dev, void *data,
1121 struct drm_file *file_priv);
1122 extern int drm_setversion(struct drm_device *dev, void *data,
1123 struct drm_file *file_priv);
1124 extern int drm_noop(struct drm_device *dev, void *data,
1125 struct drm_file *file_priv);
1127 /* Context IOCTL support (drm_context.h) */
1128 extern int drm_resctx(struct drm_device *dev, void *data,
1129 struct drm_file *file_priv);
1130 extern int drm_addctx(struct drm_device *dev, void *data,
1131 struct drm_file *file_priv);
1132 extern int drm_modctx(struct drm_device *dev, void *data,
1133 struct drm_file *file_priv);
1134 extern int drm_getctx(struct drm_device *dev, void *data,
1135 struct drm_file *file_priv);
1136 extern int drm_switchctx(struct drm_device *dev, void *data,
1137 struct drm_file *file_priv);
1138 extern int drm_newctx(struct drm_device *dev, void *data,
1139 struct drm_file *file_priv);
1140 extern int drm_rmctx(struct drm_device *dev, void *data,
1141 struct drm_file *file_priv);
1143 extern int drm_ctxbitmap_init(struct drm_device *dev);
1144 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1145 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1147 extern int drm_setsareactx(struct drm_device *dev, void *data,
1148 struct drm_file *file_priv);
1149 extern int drm_getsareactx(struct drm_device *dev, void *data,
1150 struct drm_file *file_priv);
1152 /* Drawable IOCTL support (drm_drawable.h) */
1153 extern int drm_adddraw(struct drm_device *dev, void *data,
1154 struct drm_file *file_priv);
1155 extern int drm_rmdraw(struct drm_device *dev, void *data,
1156 struct drm_file *file_priv);
1157 extern int drm_update_drawable_info(struct drm_device *dev, void *data,
1158 struct drm_file *file_priv);
1159 extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1161 extern void drm_drawable_free_all(struct drm_device *dev);
1163 /* Authentication IOCTL support (drm_auth.h) */
1164 extern int drm_getmagic(struct drm_device *dev, void *data,
1165 struct drm_file *file_priv);
1166 extern int drm_authmagic(struct drm_device *dev, void *data,
1167 struct drm_file *file_priv);
1169 /* Locking IOCTL support (drm_lock.h) */
1170 extern int drm_lock(struct drm_device *dev, void *data,
1171 struct drm_file *file_priv);
1172 extern int drm_unlock(struct drm_device *dev, void *data,
1173 struct drm_file *file_priv);
1174 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1175 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1176 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1177 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1180 * These are exported to drivers so that they can implement fencing using
1181 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1184 extern int drm_i_have_hw_lock(struct drm_device *dev,
1185 struct drm_file *file_priv);
1187 /* Buffer management support (drm_bufs.h) */
1188 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1189 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1190 extern int drm_addbufs_fb (struct drm_device *dev, struct drm_buf_desc * request);
1191 extern int drm_addmap(struct drm_device *dev, unsigned int offset,
1192 unsigned int size, enum drm_map_type type,
1193 enum drm_map_flags flags, drm_local_map_t ** map_ptr);
1194 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1195 struct drm_file *file_priv);
1196 extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1197 extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
1198 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1199 struct drm_file *file_priv);
1200 extern int drm_addbufs(struct drm_device *dev, void *data,
1201 struct drm_file *file_priv);
1202 extern int drm_infobufs(struct drm_device *dev, void *data,
1203 struct drm_file *file_priv);
1204 extern int drm_markbufs(struct drm_device *dev, void *data,
1205 struct drm_file *file_priv);
1206 extern int drm_freebufs(struct drm_device *dev, void *data,
1207 struct drm_file *file_priv);
1208 extern int drm_mapbufs(struct drm_device *dev, void *data,
1209 struct drm_file *file_priv);
1210 extern int drm_order(unsigned long size);
1211 extern unsigned long drm_get_resource_start(struct drm_device *dev,
1212 unsigned int resource);
1213 extern unsigned long drm_get_resource_len(struct drm_device *dev,
1214 unsigned int resource);
1215 extern struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
1216 drm_local_map_t *map);
1219 /* DMA support (drm_dma.h) */
1220 extern int drm_dma_setup(struct drm_device *dev);
1221 extern void drm_dma_takedown(struct drm_device *dev);
1222 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1223 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1224 struct drm_file *filp);
1226 /* IRQ support (drm_irq.h) */
1227 extern int drm_control(struct drm_device *dev, void *data,
1228 struct drm_file *file_priv);
1229 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1230 extern int drm_irq_install(struct drm_device *dev);
1231 extern int drm_irq_uninstall(struct drm_device *dev);
1232 extern void drm_driver_irq_preinstall(struct drm_device *dev);
1233 extern void drm_driver_irq_postinstall(struct drm_device *dev);
1234 extern void drm_driver_irq_uninstall(struct drm_device *dev);
1236 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1237 extern int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *filp);
1238 extern int drm_vblank_wait(struct drm_device * dev, unsigned int *vbl_seq);
1239 extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
1240 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1241 extern void drm_update_vblank_count(struct drm_device *dev, int crtc);
1242 extern void drm_handle_vblank(struct drm_device *dev, int crtc);
1243 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1244 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1246 /* Modesetting support */
1247 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1248 struct drm_file *file_priv);
1250 /* AGP/GART support (drm_agpsupport.h) */
1251 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1252 extern int drm_agp_acquire(struct drm_device *dev);
1253 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1254 struct drm_file *file_priv);
1255 extern int drm_agp_release(struct drm_device *dev);
1256 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1257 struct drm_file *file_priv);
1258 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1259 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1260 struct drm_file *file_priv);
1261 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1262 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1263 struct drm_file *file_priv);
1264 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1265 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1266 struct drm_file *file_priv);
1267 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1268 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1269 struct drm_file *file_priv);
1270 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1271 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1272 struct drm_file *file_priv);
1273 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1274 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1275 struct drm_file *file_priv);
1276 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
1277 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
1279 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1281 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1282 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1283 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1284 extern struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev);
1285 extern void drm_agp_chipset_flush(struct drm_device *dev);
1286 /* Stub support (drm_stub.h) */
1287 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1288 struct drm_driver *driver);
1289 extern int drm_put_dev(struct drm_device *dev);
1290 extern int drm_put_minor(struct drm_minor **minor);
1291 extern unsigned int drm_debug; /* 1 to enable debug output */
1293 extern struct class *drm_class;
1294 extern struct proc_dir_entry *drm_proc_root;
1296 extern struct idr drm_minors_idr;
1298 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1300 /* Proc support (drm_proc.h) */
1301 int drm_proc_init(struct drm_minor *minor, int minor_id,
1302 struct proc_dir_entry *root);
1303 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1305 /* Scatter Gather Support (drm_scatter.h) */
1306 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1307 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1308 struct drm_file *file_priv);
1309 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1310 extern int drm_sg_free(struct drm_device *dev, void *data,
1311 struct drm_file *file_priv);
1313 /* ATI PCIGART support (ati_pcigart.h) */
1314 extern int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1315 extern int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1317 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1318 size_t align, dma_addr_t maxaddr);
1319 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1320 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1322 /* sysfs support (drm_sysfs.c) */
1323 struct drm_sysfs_class;
1324 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1325 extern void drm_sysfs_destroy(void);
1326 extern int drm_sysfs_device_add(struct drm_minor *minor);
1327 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1330 * Basic memory manager support (drm_memrange.c)
1333 extern struct drm_memrange_node *drm_memrange_get_block(struct drm_memrange_node * parent,
1335 unsigned alignment);
1336 extern void drm_memrange_put_block(struct drm_memrange_node *cur);
1337 extern struct drm_memrange_node *drm_memrange_search_free(const struct drm_memrange *mm,
1339 unsigned alignment, int best_match);
1340 extern int drm_memrange_init(struct drm_memrange *mm,
1341 unsigned long start, unsigned long size);
1342 extern void drm_memrange_takedown(struct drm_memrange *mm);
1343 extern int drm_memrange_clean(struct drm_memrange *mm);
1344 extern unsigned long drm_memrange_tail_space(struct drm_memrange *mm);
1345 extern int drm_memrange_remove_space_from_tail(struct drm_memrange *mm,
1346 unsigned long size);
1347 extern int drm_memrange_add_space_to_tail(struct drm_memrange *mm,
1348 unsigned long size);
1350 static inline struct drm_memrange *drm_get_mm(struct drm_memrange_node *block)
1355 /* Graphics Execution Manager library functions (drm_gem.c) */
1357 drm_gem_init (struct drm_device *dev);
1360 drm_gem_object_free (struct kref *kref);
1362 struct drm_gem_object *
1363 drm_gem_object_alloc(struct drm_device *dev, size_t size);
1366 drm_gem_object_handle_free (struct kref *kref);
1368 static inline void drm_gem_object_reference(struct drm_gem_object *obj)
1370 kref_get(&obj->refcount);
1373 static inline void drm_gem_object_unreference(struct drm_gem_object *obj)
1378 kref_put (&obj->refcount, drm_gem_object_free);
1382 drm_gem_handle_create(struct drm_file *file_priv,
1383 struct drm_gem_object *obj,
1386 static inline void drm_gem_object_handle_reference (struct drm_gem_object *obj)
1388 drm_gem_object_reference (obj);
1389 kref_get(&obj->handlecount);
1392 static inline void drm_gem_object_handle_unreference (struct drm_gem_object *obj)
1398 * Must bump handle count first as this may be the last
1399 * ref, in which case the object would disappear before we
1400 * checked for a name
1402 kref_put (&obj->handlecount, drm_gem_object_handle_free);
1403 drm_gem_object_unreference (obj);
1406 struct drm_gem_object *
1407 drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp,
1409 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1410 struct drm_file *file_priv);
1411 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1412 struct drm_file *file_priv);
1413 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1414 struct drm_file *file_priv);
1416 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1417 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1419 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1420 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1422 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1425 struct drm_map_list *_entry;
1426 list_for_each_entry(_entry, &dev->maplist, head)
1427 if (_entry->user_token == token)
1432 static __inline__ int drm_device_is_agp(struct drm_device *dev)
1434 if ( dev->driver->device_is_agp != NULL ) {
1435 int err = (*dev->driver->device_is_agp)(dev);
1442 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1445 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1447 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1450 static __inline__ void drm_core_dropmap(struct drm_map *map)
1454 #ifndef DEBUG_MEMORY
1455 /** Wrapper around kmalloc() */
1456 static __inline__ void *drm_alloc(size_t size, int area)
1458 return kmalloc(size, GFP_KERNEL);
1461 /** Wrapper around kfree() */
1462 static __inline__ void drm_free(void *pt, size_t size, int area)
1467 extern void *drm_alloc(size_t size, int area);
1468 extern void drm_free(void *pt, size_t size, int area);
1472 * Accounting variants of standard calls.
1475 static inline void *drm_ctl_alloc(size_t size, int area)
1478 if (drm_alloc_memctl(size))
1480 ret = drm_alloc(size, area);
1482 drm_free_memctl(size);
1486 static inline void *drm_ctl_calloc(size_t nmemb, size_t size, int area)
1490 if (drm_alloc_memctl(nmemb*size))
1492 ret = drm_calloc(nmemb, size, area);
1494 drm_free_memctl(nmemb*size);
1498 static inline void drm_ctl_free(void *pt, size_t size, int area)
1500 drm_free(pt, size, area);
1501 drm_free_memctl(size);
1506 #endif /* __KERNEL__ */