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/swap.h>
58 #include <linux/kref.h>
59 #include <linux/pagemap.h>
60 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
61 #include <linux/mutex.h>
63 #if defined(__alpha__) || defined(__powerpc__)
64 #include <asm/pgtable.h> /* For pte_wrprotect */
68 #include <asm/uaccess.h>
73 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
74 #include <linux/types.h>
75 #include <linux/agp_backend.h>
77 #include <linux/workqueue.h>
78 #include <linux/poll.h>
79 #include <asm/pgalloc.h>
81 #include <linux/slab.h>
82 #include <linux/idr.h>
84 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
85 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
87 #include "drm_os_linux.h"
88 #include "drm_hashtab.h"
89 #include "drm_internal.h"
94 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
95 typedef unsigned long uintptr_t;
98 /* If you want the memory alloc debug functionality, change define below */
99 /* #define DEBUG_MEMORY */
101 /***********************************************************************/
102 /** \name DRM template customization defaults */
105 /* driver capabilities and requirements mask */
106 #define DRIVER_USE_AGP 0x1
107 #define DRIVER_REQUIRE_AGP 0x2
108 #define DRIVER_USE_MTRR 0x4
109 #define DRIVER_PCI_DMA 0x8
110 #define DRIVER_SG 0x10
111 #define DRIVER_HAVE_DMA 0x20
112 #define DRIVER_HAVE_IRQ 0x40
113 #define DRIVER_IRQ_SHARED 0x80
114 #define DRIVER_DMA_QUEUE 0x100
115 #define DRIVER_FB_DMA 0x200
116 #define DRIVER_MODESET 0x400
117 #define DRIVER_GEM 0x800
121 /***********************************************************************/
122 /** \name Begin the DRM... */
125 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
126 also include looping detection. */
128 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
129 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
130 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
131 #define DRM_LOOPING_LIMIT 5000000
132 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
133 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
135 #define DRM_FLAG_DEBUG 0x01
137 #define DRM_MEM_DMA 0
138 #define DRM_MEM_SAREA 1
139 #define DRM_MEM_DRIVER 2
140 #define DRM_MEM_MAGIC 3
141 #define DRM_MEM_IOCTLS 4
142 #define DRM_MEM_MAPS 5
143 #define DRM_MEM_VMAS 6
144 #define DRM_MEM_BUFS 7
145 #define DRM_MEM_SEGS 8
146 #define DRM_MEM_PAGES 9
147 #define DRM_MEM_FILES 10
148 #define DRM_MEM_QUEUES 11
149 #define DRM_MEM_CMDS 12
150 #define DRM_MEM_MAPPINGS 13
151 #define DRM_MEM_BUFLISTS 14
152 #define DRM_MEM_AGPLISTS 15
153 #define DRM_MEM_TOTALAGP 16
154 #define DRM_MEM_BOUNDAGP 17
155 #define DRM_MEM_CTXBITMAP 18
156 #define DRM_MEM_STUB 19
157 #define DRM_MEM_SGLISTS 20
158 #define DRM_MEM_CTXLIST 21
159 #define DRM_MEM_MM 22
160 #define DRM_MEM_HASHTAB 23
161 #define DRM_MEM_OBJECTS 24
162 #define DRM_MEM_FENCE 25
163 #define DRM_MEM_TTM 26
164 #define DRM_MEM_BUFOBJ 27
166 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
167 #define DRM_MAP_HASH_OFFSET 0x10000000
168 #define DRM_MAP_HASH_ORDER 12
169 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
170 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
172 * This should be small enough to allow the use of kmalloc for hash tables
173 * instead of vmalloc.
176 #define DRM_FILE_HASH_ORDER 8
177 #define DRM_MM_INIT_MAX_PAGES 256
181 #include "drm_compat.h"
183 /***********************************************************************/
184 /** \name Macros to make printk easier */
190 * \param fmt printf() like format string.
191 * \param arg arguments
193 #define DRM_ERROR(fmt, arg...) \
194 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg)
197 * Memory error output.
199 * \param area memory area where the error occurred.
200 * \param fmt printf() like format string.
201 * \param arg arguments
203 #define DRM_MEM_ERROR(area, fmt, arg...) \
204 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \
205 drm_mem_stats[area].name , ##arg)
206 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
211 * \param fmt printf() like format string.
212 * \param arg arguments
215 #define DRM_DEBUG(fmt, arg...) \
219 "[" DRM_NAME ":%s] " fmt , \
220 __FUNCTION__ , ##arg); \
223 #define DRM_DEBUG(fmt, arg...) do { } while (0)
226 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
228 #define DRM_PROC_PRINT(fmt, arg...) \
229 len += sprintf(&buf[len], fmt , ##arg); \
230 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
232 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
233 len += sprintf(&buf[len], fmt , ##arg); \
234 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
238 /***********************************************************************/
239 /** \name Internal types and structures */
242 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
243 #define DRM_MIN(a,b) min(a,b)
244 #define DRM_MAX(a,b) max(a,b)
246 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
247 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
248 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
250 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
252 * Get the private SAREA mapping.
254 * \param _dev DRM device.
255 * \param _ctx context number.
256 * \param _map output mapping.
258 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
259 (_map) = (_dev)->context_sareas[_ctx]; \
263 * Test that the hardware lock is held by the caller, returning otherwise.
265 * \param dev DRM device.
266 * \param file_priv DRM file private pointer of the caller.
268 #define LOCK_TEST_WITH_RETURN( dev, file_priv ) \
270 if ( !_DRM_LOCK_IS_HELD( file_priv->master->lock.hw_lock->lock ) || \
271 file_priv->master->lock.file_priv != file_priv ) { \
272 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
273 __FUNCTION__, _DRM_LOCK_IS_HELD( file_priv->master->lock.hw_lock->lock ),\
274 file_priv->master->lock.file_priv, file_priv ); \
280 * Copy and IOCTL return string to user space
282 #define DRM_COPY( name, value ) \
283 len = strlen( value ); \
284 if ( len > name##_len ) len = name##_len; \
285 name##_len = strlen( value ); \
286 if ( len && name ) { \
287 if ( copy_to_user( name, value, len ) ) \
292 * Ioctl function type.
294 * \param dev DRM device structure
295 * \param data pointer to kernel-space stored data, copied in and out according
296 * to ioctl description.
297 * \param file_priv DRM file private pointer.
299 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
300 struct drm_file *file_priv);
302 typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
306 #define DRM_MASTER 0x2
307 #define DRM_ROOT_ONLY 0x4
308 #define DRM_CONTROL_ALLOW 0x8 // allow ioctl to operate on control node
310 struct drm_ioctl_desc {
316 * Creates a driver or general drm_ioctl_desc array entry for the given
317 * ioctl, for use by drm_ioctl().
319 #define DRM_IOCTL_DEF(ioctl, func, flags) \
320 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
322 struct drm_magic_entry {
323 struct list_head head;
324 struct drm_hash_item hash_item;
325 struct drm_file *priv;
328 struct drm_vma_entry {
329 struct list_head head;
330 struct vm_area_struct *vma;
338 int idx; /**< Index into master buflist */
339 int total; /**< Buffer size */
340 int order; /**< log-base-2(total) */
341 int used; /**< Amount of buffer in use (for DMA) */
342 unsigned long offset; /**< Byte offset (used internally) */
343 void *address; /**< Address of buffer */
344 unsigned long bus_address; /**< Bus address of buffer */
345 struct drm_buf *next; /**< Kernel-only: used for free list */
346 __volatile__ int waiting; /**< On kernel DMA queue */
347 __volatile__ int pending; /**< On hardware DMA queue */
348 wait_queue_head_t dma_wait; /**< Processes waiting */
349 struct drm_file *file_priv; /**< Private of holding file descr */
350 int context; /**< Kernel queue for this buffer */
351 int while_locked; /**< Dispatch this buffer while locked */
359 } list; /**< Which list we're on */
361 int dev_priv_size; /**< Size of buffer private storage */
362 void *dev_private; /**< Per-buffer private storage */
365 /** bufs is one longer than it has to be */
366 struct drm_waitlist {
367 int count; /**< Number of possible buffers */
368 struct drm_buf **bufs; /**< List of pointers to buffers */
369 struct drm_buf **rp; /**< Read pointer */
370 struct drm_buf **wp; /**< Write pointer */
371 struct drm_buf **end; /**< End pointer */
372 spinlock_t read_lock;
373 spinlock_t write_lock;
376 struct drm_freelist {
377 int initialized; /**< Freelist in use */
378 atomic_t count; /**< Number of free buffers */
379 struct drm_buf *next; /**< End pointer */
381 wait_queue_head_t waiting; /**< Processes waiting on free bufs */
382 int low_mark; /**< Low water mark */
383 int high_mark; /**< High water mark */
384 atomic_t wfh; /**< If waiting for high mark */
388 typedef struct drm_dma_handle {
395 * Buffer entry. There is one of this for each buffer size order.
397 struct drm_buf_entry {
398 int buf_size; /**< size */
399 int buf_count; /**< number of buffers */
400 struct drm_buf *buflist; /**< buffer list */
403 struct drm_dma_handle **seglist;
404 struct drm_freelist freelist;
407 /** File private data */
413 unsigned long ioctl_count;
414 struct list_head lhead;
415 struct drm_minor *minor;
416 unsigned long lock_count;
418 /** Mapping of mm object handles to object pointers. */
419 struct idr object_idr;
420 /** Lock for synchronization of access to object_idr. */
421 spinlock_t table_lock;
426 int is_master; /* this file private is a master for a minor */
427 struct drm_master *master; /* master this node is currently associated with
428 N.B. not always minor->master */
429 struct list_head fbs;
434 atomic_t use_count; /**< Outstanding uses (+1) */
435 atomic_t finalization; /**< Finalization in progress */
436 atomic_t block_count; /**< Count of processes waiting */
437 atomic_t block_read; /**< Queue blocked for reads */
438 wait_queue_head_t read_queue; /**< Processes waiting on block_read */
439 atomic_t block_write; /**< Queue blocked for writes */
440 wait_queue_head_t write_queue; /**< Processes waiting on block_write */
442 atomic_t total_queued; /**< Total queued statistic */
443 atomic_t total_flushed; /**< Total flushes statistic */
444 atomic_t total_locks; /**< Total locks statistics */
446 enum drm_ctx_flags flags; /**< Context preserving and 2D-only */
447 struct drm_waitlist waitlist; /**< Pending buffers */
448 wait_queue_head_t flush_queue; /**< Processes waiting until flush */
454 struct drm_lock_data {
455 struct drm_hw_lock *hw_lock; /**< Hardware lock */
456 /** Private of lock holder's file (NULL=kernel) */
457 struct drm_file *file_priv;
458 wait_queue_head_t lock_queue; /**< Queue of blocked processes */
459 unsigned long lock_time; /**< Time of last lock in jiffies */
461 uint32_t kernel_waiters;
462 uint32_t user_waiters;
469 struct drm_device_dma {
471 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
472 int buf_count; /**< total number of buffers */
473 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
475 int page_count; /**< number of pages */
476 unsigned long *pagelist; /**< page list */
477 unsigned long byte_count;
479 _DRM_DMA_USE_AGP = 0x01,
480 _DRM_DMA_USE_SG = 0x02,
481 _DRM_DMA_USE_FB = 0x04,
482 _DRM_DMA_USE_PCI_RO = 0x08
488 * AGP memory entry. Stored as a doubly linked list.
491 unsigned long handle; /**< handle */
493 unsigned long bound; /**< address */
495 struct list_head head;
501 * \sa drm_agp_init() and drm_device::agp.
503 struct drm_agp_head {
504 DRM_AGP_KERN agp_info; /**< AGP device information */
505 struct list_head memory;
506 unsigned long mode; /**< AGP mode */
507 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
508 struct agp_bridge_data *bridge;
510 int enabled; /**< whether the AGP bus as been enabled */
511 int acquired; /**< whether the AGP device has been acquired */
514 int cant_use_aperture;
515 unsigned long page_mask;
519 * Scatter-gather memory.
522 unsigned long handle;
525 struct page **pagelist;
531 struct drm_hw_lock *lock;
536 * Generic memory manager structs
540 struct list_head fl_entry;
541 struct list_head ml_entry;
550 struct list_head fl_entry;
551 struct list_head ml_entry;
558 struct drm_map_list {
559 struct list_head head; /**< list head */
560 struct drm_hash_item hash;
561 struct drm_map *map; /**< mapping */
563 struct drm_master *master; /** if this map is associated with a specific
565 struct drm_mm_node *file_offset_node;
568 typedef struct drm_map drm_local_map_t;
571 * Context handle list
573 struct drm_ctx_list {
574 struct list_head head; /**< list head */
575 drm_context_t handle; /**< context handle */
576 struct drm_file *tag; /**< associated fd private data */
580 struct list_head head;
581 unsigned int sequence;
583 struct task_struct *task;
586 struct drm_hotplug_sig {
587 struct list_head head;
588 unsigned int counter;
590 struct task_struct *task;
593 /* location of GART table */
594 #define DRM_ATI_GART_MAIN 1
595 #define DRM_ATI_GART_FB 2
597 #define DRM_ATI_GART_PCI 1
598 #define DRM_ATI_GART_PCIE 2
599 #define DRM_ATI_GART_IGP 3
601 struct drm_ati_pcigart_info {
602 int gart_table_location;
606 dma_addr_t table_mask;
607 dma_addr_t member_mask;
608 struct drm_dma_handle *table_handle;
609 drm_local_map_t mapping;
614 * This structure defines the drm_mm memory object, which will be used by the
615 * DRM for its buffer objects.
617 struct drm_gem_object {
618 /** Reference count of this object */
619 struct kref refcount;
621 /** Handle count of this object. Each handle also holds a reference */
622 struct kref handlecount;
624 /** Related drm device */
625 struct drm_device *dev;
627 /** File representing the shmem storage */
631 * Size of the object, in bytes. Immutable over the object's
637 * Global name for this object, starts at 1. 0 means unnamed.
638 * Access is covered by the object_name_lock in the related drm_device
643 * Memory domains. These monitor which caches contain read/write data
644 * related to the object. When transitioning from one set of domains
645 * to another, the driver is called to ensure that caches are suitably
646 * flushed and invalidated
648 uint32_t read_domains;
649 uint32_t write_domain;
652 * While validating an exec operation, the
653 * new read/write domain values are computed here.
654 * They will be transferred to the above values
655 * at the point that any cache flushing occurs
657 uint32_t pending_read_domains;
658 uint32_t pending_write_domain;
660 void *driver_private;
663 #include "drm_objects.h"
664 #include "drm_crtc.h"
666 /* per-master structure */
669 struct kref refcount; /* refcount for this master */
671 struct list_head head; /**< each minor contains a list of masters */
672 struct drm_minor *minor; /**< link back to minor we are a master for */
674 char *unique; /**< Unique identifier: e.g., busid */
675 int unique_len; /**< Length of unique field */
677 int blocked; /**< Blocked due to VC switch? */
679 /** \name Authentication */
681 struct drm_open_hash magiclist;
682 struct list_head magicfree;
685 struct drm_lock_data lock; /**< Information on hardware lock */
687 void *driver_priv; /**< Private structure for driver to use */
691 * DRM driver structure. This structure represent the common code for
692 * a family of cards. There will one drm_device for each card present
697 int (*load) (struct drm_device *, unsigned long flags);
698 int (*firstopen) (struct drm_device *);
699 int (*open) (struct drm_device *, struct drm_file *);
700 void (*preclose) (struct drm_device *, struct drm_file *file_priv);
701 void (*postclose) (struct drm_device *, struct drm_file *);
702 void (*lastclose) (struct drm_device *);
703 int (*unload) (struct drm_device *);
704 int (*suspend) (struct drm_device *, pm_message_t state);
705 int (*resume) (struct drm_device *);
706 int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
707 void (*dma_ready) (struct drm_device *);
708 int (*dma_quiescent) (struct drm_device *);
709 int (*context_ctor) (struct drm_device *dev, int context);
710 int (*context_dtor) (struct drm_device *dev, int context);
711 int (*kernel_context_switch) (struct drm_device *dev, int old,
713 void (*kernel_context_switch_unlock) (struct drm_device * dev);
715 * get_vblank_counter - get raw hardware vblank counter
717 * @crtc: counter to fetch
719 * Driver callback for fetching a raw hardware vblank counter
720 * for @crtc. If a device doesn't have a hardware counter, the
721 * driver can simply return the value of drm_vblank_count and
722 * make the enable_vblank() and disable_vblank() hooks into no-ops,
723 * leaving interrupts enabled at all times.
725 * Wraparound handling and loss of events due to modesetting is dealt
726 * with in the DRM core code.
729 * Raw vblank counter value.
731 u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);
734 * enable_vblank - enable vblank interrupt events
736 * @crtc: which irq to enable
738 * Enable vblank interrupts for @crtc. If the device doesn't have
739 * a hardware vblank counter, this routine should be a no-op, since
740 * interrupts will have to stay on to keep the count accurate.
743 * Zero on success, appropriate errno if the given @crtc's vblank
744 * interrupt cannot be enabled.
746 int (*enable_vblank) (struct drm_device *dev, int crtc);
749 * disable_vblank - disable vblank interrupt events
751 * @crtc: which irq to enable
753 * Disable vblank interrupts for @crtc. If the device doesn't have
754 * a hardware vblank counter, this routine should be a no-op, since
755 * interrupts will have to stay on to keep the count accurate.
757 void (*disable_vblank) (struct drm_device *dev, int crtc);
758 int (*dri_library_name) (struct drm_device *dev, char * buf);
761 * Called by \c drm_device_is_agp. Typically used to determine if a
762 * card is really attached to AGP or not.
764 * \param dev DRM device handle
767 * One of three values is returned depending on whether or not the
768 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
769 * (return of 1), or may or may not be AGP (return of 2).
771 int (*device_is_agp) (struct drm_device *dev);
773 /* these have to be filled in */
774 irqreturn_t(*irq_handler) (DRM_IRQ_ARGS);
775 void (*irq_preinstall) (struct drm_device *dev);
776 int (*irq_postinstall) (struct drm_device *dev);
777 void (*irq_uninstall) (struct drm_device *dev);
778 void (*reclaim_buffers) (struct drm_device *dev,
779 struct drm_file *file_priv);
780 void (*reclaim_buffers_locked) (struct drm_device *dev,
781 struct drm_file *file_priv);
782 void (*reclaim_buffers_idlelocked) (struct drm_device *dev,
783 struct drm_file *file_priv);
784 unsigned long (*get_map_ofs) (struct drm_map *map);
785 unsigned long (*get_reg_ofs) (struct drm_device *dev);
786 void (*set_version) (struct drm_device *dev,
787 struct drm_set_version *sv);
789 /* Master routines */
790 int (*master_create)(struct drm_device *dev, struct drm_master *master);
791 void (*master_destroy)(struct drm_device *dev, struct drm_master *master);
793 int (*proc_init)(struct drm_minor *minor);
794 void (*proc_cleanup)(struct drm_minor *minor);
797 * Driver-specific constructor for drm_gem_objects, to set up
798 * obj->driver_private.
800 * Returns 0 on success.
802 int (*gem_init_object) (struct drm_gem_object *obj);
803 void (*gem_free_object) (struct drm_gem_object *obj);
805 struct drm_fence_driver *fence_driver;
806 struct drm_bo_driver *bo_driver;
818 struct drm_ioctl_desc *ioctls;
820 struct file_operations fops;
821 struct pci_driver pci_driver;
824 #define DRM_MINOR_UNASSIGNED 0
825 #define DRM_MINOR_LEGACY 1
826 #define DRM_MINOR_CONTROL 2
827 #define DRM_MINOR_RENDER 3
830 * DRM minor structure. This structure represents a drm minor number.
833 int index; /**< Minor device number */
834 int type; /**< Control or render */
835 dev_t device; /**< Device number for mknod */
836 struct device kdev; /**< Linux device */
837 struct drm_device *dev;
838 /* for render nodes */
839 struct proc_dir_entry *dev_root; /**< proc directory entry */
840 struct class_device *dev_class;
842 /* for control nodes - a pointer to the current master for this control node */
843 struct drm_master *master; /* currently active master for this node */
844 struct list_head master_list;
846 struct drm_mode_group mode_group;
851 * DRM device structure. This structure represent a complete card that
852 * may contain multiple heads.
855 char *devname; /**< For /proc/interrupts */
856 int if_version; /**< Highest interface version set */
860 spinlock_t count_lock; /**< For inuse, drm_device::open_count, drm_device::buf_use */
861 struct mutex struct_mutex; /**< For others */
864 /** \name Usage Counters */
866 int open_count; /**< Outstanding files open */
867 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
868 atomic_t vma_count; /**< Outstanding vma areas open */
869 int buf_use; /**< Buffers in use -- cannot alloc */
870 atomic_t buf_alloc; /**< Buffer allocation in progress */
873 /** \name Performance counters */
875 unsigned long counters;
876 enum drm_stat_type types[15];
881 /** \name Memory management */
883 struct list_head maplist; /**< Linked list of regions */
884 int map_count; /**< Number of mappable regions */
885 struct drm_open_hash map_hash; /**< User token hash table for maps */
886 struct drm_mm offset_manager; /**< User token manager */
887 struct address_space *dev_mapping; /**< For unmap_mapping_range() */
888 struct page *ttm_dummy_page;
890 /** \name Context handle management */
892 struct list_head ctxlist; /**< Linked list of context handles */
893 int ctx_count; /**< Number of context handles */
894 struct mutex ctxlist_mutex; /**< For ctxlist */
898 struct list_head vmalist; /**< List of vmas (for debugging) */
900 struct list_head filelist;
904 /** \name DMA queues (contexts) */
906 int queue_count; /**< Number of active DMA queues */
907 int queue_reserved; /**< Number of reserved DMA queues */
908 int queue_slots; /**< Actual length of queuelist */
909 struct drm_queue **queuelist; /**< Vector of pointers to DMA queues */
910 struct drm_device_dma *dma; /**< Optional pointer for DMA support */
914 /** \name Context support */
916 int irq; /**< Interrupt used by board */
917 int irq_enabled; /**< True if irq handler is enabled */
918 __volatile__ long context_flag; /**< Context swapping flag */
919 __volatile__ long interrupt_flag; /**< Interruption handler flag */
920 __volatile__ long dma_flag; /**< DMA dispatch flag */
921 struct timer_list timer; /**< Timer for delaying ctx switch */
922 wait_queue_head_t context_wait; /**< Processes waiting on ctx switch */
923 int last_checked; /**< Last context checked for DMA */
924 int last_context; /**< Last current context */
925 unsigned long last_switch; /**< jiffies at last context switch */
928 struct work_struct work;
930 /** \name HOTPLUG IRQ support */
932 wait_queue_head_t hotplug_queue; /**< HOTPLUG wait queue */
933 spinlock_t hotplug_lock;
934 struct list_head *hotplug_sigs; /**< signal list to send on HOTPLUG */
935 atomic_t hotplug_signal_pending; /* number of signals pending on all crtcs*/
939 /** \name VBLANK IRQ support */
943 * At load time, disabling the vblank interrupt won't be allowed since
944 * old clients may not call the modeset ioctl and therefore misbehave.
945 * Once the modeset ioctl *has* been called though, we can safely
946 * disable them when unused.
948 int vblank_disable_allowed;
950 wait_queue_head_t *vbl_queue; /**< VBLANK wait queue */
951 atomic_t *_vblank_count; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
953 struct list_head *vbl_sigs; /**< signal list to send on VBLANK */
954 atomic_t vbl_signal_pending; /* number of signals pending on all crtcs*/
955 atomic_t *vblank_refcount; /* number of users of vblank interrupts per crtc */
956 u32 *last_vblank; /* protected by dev->vbl_lock, used */
957 /* for wraparound handling */
958 int *vblank_enabled; /* so we don't call enable more than
960 int *vblank_inmodeset; /* Display driver is setting mode */
961 struct timer_list vblank_disable_timer;
963 u32 max_vblank_count; /**< size of vblank counter register */
964 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
965 void (*locked_tasklet_func)(struct drm_device *dev);
971 struct fasync_struct *buf_async;/**< Processes waiting for SIGIO */
972 wait_queue_head_t buf_readers; /**< Processes waiting to read */
973 wait_queue_head_t buf_writers; /**< Processes waiting to ctx switch */
975 struct drm_agp_head *agp; /**< AGP data */
977 struct pci_dev *pdev; /**< PCI device structure */
978 int pci_vendor; /**< PCI vendor id */
979 int pci_device; /**< PCI device id */
981 struct pci_controller *hose;
983 int num_crtcs; /**< Number of CRTCs on this device */
984 struct drm_sg_mem *sg; /**< Scatter gather memory */
985 void *dev_private; /**< device private data */
986 struct drm_sigdata sigdata; /**< For block_all_signals */
989 struct drm_driver *driver;
990 drm_local_map_t *agp_buffer_map;
991 unsigned int agp_buffer_token;
993 /* minor number for control node */
994 struct drm_minor *control;
995 struct drm_minor *primary; /**< render type primary screen head */
997 struct drm_fence_manager fm;
998 struct drm_buffer_manager bm;
1000 /** \name Drawable information */
1002 spinlock_t drw_lock;
1006 /* DRM mode setting */
1007 struct drm_mode_config mode_config;
1009 /** \name GEM information */
1011 spinlock_t object_name_lock;
1012 struct idr object_name_idr;
1013 atomic_t object_count;
1014 atomic_t object_memory;
1016 atomic_t pin_memory;
1018 atomic_t gtt_memory;
1020 uint32_t invalidate_domains; /* domains pending invalidation */
1021 uint32_t flush_domains; /* domains pending flush */
1026 struct drm_agp_ttm_backend {
1027 struct drm_ttm_backend backend;
1029 struct agp_bridge_data *bridge;
1033 struct ati_pcigart_ttm_backend {
1034 struct drm_ttm_backend backend;
1036 void (*gart_flush_fn)(struct drm_device *dev);
1037 struct drm_ati_pcigart_info *gart_info;
1038 unsigned long offset;
1039 struct page **pages;
1042 struct drm_device *dev;
1044 extern struct drm_ttm_backend *ati_pcigart_init_ttm(struct drm_device *dev, struct drm_ati_pcigart_info *info, void (*gart_flush_fn)(struct drm_device *dev));
1046 static __inline__ int drm_core_check_feature(struct drm_device *dev,
1049 return ((dev->driver->driver_features & feature) ? 1 : 0);
1053 #define drm_get_pci_domain(dev) dev->hose->index
1055 #define drm_get_pci_domain(dev) 0
1059 static inline int drm_core_has_AGP(struct drm_device *dev)
1061 return drm_core_check_feature(dev, DRIVER_USE_AGP);
1064 #define drm_core_has_AGP(dev) (0)
1068 static inline int drm_core_has_MTRR(struct drm_device *dev)
1070 return drm_core_check_feature(dev, DRIVER_USE_MTRR);
1073 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
1075 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1078 return mtrr_add(offset, size, flags, 1);
1081 static inline int drm_mtrr_del(int handle, unsigned long offset,
1082 unsigned long size, unsigned int flags)
1084 return mtrr_del(handle, offset, size);
1088 static inline int drm_mtrr_add(unsigned long offset, unsigned long size,
1094 static inline int drm_mtrr_del(int handle, unsigned long offset,
1095 unsigned long size, unsigned int flags)
1100 #define drm_core_has_MTRR(dev) (0)
1101 #define DRM_MTRR_WC 0
1105 /******************************************************************/
1106 /** \name Internal function definitions */
1109 /* Driver support (drm_drv.h) */
1110 extern int drm_fb_loaded;
1111 extern int drm_init(struct drm_driver *driver,
1112 struct pci_device_id *pciidlist);
1113 extern void drm_exit(struct drm_driver *driver);
1114 extern void drm_cleanup_pci(struct pci_dev *pdev);
1115 extern int drm_ioctl(struct inode *inode, struct file *filp,
1116 unsigned int cmd, unsigned long arg);
1117 extern long drm_unlocked_ioctl(struct file *filp,
1118 unsigned int cmd, unsigned long arg);
1119 extern long drm_compat_ioctl(struct file *filp,
1120 unsigned int cmd, unsigned long arg);
1122 extern int drm_lastclose(struct drm_device *dev);
1124 /* Device support (drm_fops.h) */
1125 extern int drm_open(struct inode *inode, struct file *filp);
1126 extern int drm_stub_open(struct inode *inode, struct file *filp);
1127 extern int drm_fasync(int fd, struct file *filp, int on);
1128 extern int drm_release(struct inode *inode, struct file *filp);
1129 unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
1131 /* Mapping support (drm_vm.h) */
1132 extern int drm_mmap(struct file *filp, struct vm_area_struct *vma);
1133 extern unsigned long drm_core_get_map_ofs(struct drm_map * map);
1134 extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1135 extern pgprot_t drm_io_prot(uint32_t map_type, struct vm_area_struct *vma);
1137 /* Memory management support (drm_memory.h) */
1138 #include "drm_memory.h"
1139 extern void drm_mem_init(void);
1140 extern int drm_mem_info(char *buf, char **start, off_t offset,
1141 int request, int *eof, void *data);
1142 extern void *drm_calloc(size_t nmemb, size_t size, int area);
1143 extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
1144 extern unsigned long drm_alloc_pages(int order, int area);
1145 extern void drm_free_pages(unsigned long address, int order, int area);
1146 extern DRM_AGP_MEM *drm_alloc_agp(struct drm_device *dev, int pages, u32 type);
1147 extern int drm_free_agp(DRM_AGP_MEM * handle, int pages);
1148 extern int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start);
1149 extern DRM_AGP_MEM *drm_agp_bind_pages(struct drm_device *dev,
1150 struct page **pages,
1151 unsigned long num_pages,
1152 uint32_t gtt_offset);
1153 extern int drm_unbind_agp(DRM_AGP_MEM * handle);
1155 extern void drm_free_memctl(size_t size);
1156 extern int drm_alloc_memctl(size_t size);
1157 extern void drm_query_memctl(uint64_t *cur_used,
1158 uint64_t *emer_used,
1159 uint64_t *low_threshold,
1160 uint64_t *high_threshold,
1161 uint64_t *emer_threshold);
1162 extern void drm_init_memctl(size_t low_threshold,
1163 size_t high_threshold,
1166 /* Misc. IOCTL support (drm_ioctl.h) */
1167 extern int drm_irq_by_busid(struct drm_device *dev, void *data,
1168 struct drm_file *file_priv);
1169 extern int drm_getunique(struct drm_device *dev, void *data,
1170 struct drm_file *file_priv);
1171 extern int drm_setunique(struct drm_device *dev, void *data,
1172 struct drm_file *file_priv);
1173 extern int drm_getmap(struct drm_device *dev, void *data,
1174 struct drm_file *file_priv);
1175 extern int drm_getclient(struct drm_device *dev, void *data,
1176 struct drm_file *file_priv);
1177 extern int drm_getstats(struct drm_device *dev, void *data,
1178 struct drm_file *file_priv);
1179 extern int drm_setversion(struct drm_device *dev, void *data,
1180 struct drm_file *file_priv);
1181 extern int drm_noop(struct drm_device *dev, void *data,
1182 struct drm_file *file_priv);
1184 /* Context IOCTL support (drm_context.h) */
1185 extern int drm_resctx(struct drm_device *dev, void *data,
1186 struct drm_file *file_priv);
1187 extern int drm_addctx(struct drm_device *dev, void *data,
1188 struct drm_file *file_priv);
1189 extern int drm_modctx(struct drm_device *dev, void *data,
1190 struct drm_file *file_priv);
1191 extern int drm_getctx(struct drm_device *dev, void *data,
1192 struct drm_file *file_priv);
1193 extern int drm_switchctx(struct drm_device *dev, void *data,
1194 struct drm_file *file_priv);
1195 extern int drm_newctx(struct drm_device *dev, void *data,
1196 struct drm_file *file_priv);
1197 extern int drm_rmctx(struct drm_device *dev, void *data,
1198 struct drm_file *file_priv);
1200 extern int drm_ctxbitmap_init(struct drm_device *dev);
1201 extern void drm_ctxbitmap_cleanup(struct drm_device *dev);
1202 extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
1204 extern int drm_setsareactx(struct drm_device *dev, void *data,
1205 struct drm_file *file_priv);
1206 extern int drm_getsareactx(struct drm_device *dev, void *data,
1207 struct drm_file *file_priv);
1209 /* Drawable IOCTL support (drm_drawable.h) */
1210 extern int drm_adddraw(struct drm_device *dev, void *data,
1211 struct drm_file *file_priv);
1212 extern int drm_rmdraw(struct drm_device *dev, void *data,
1213 struct drm_file *file_priv);
1214 extern int drm_update_drawable_info(struct drm_device *dev, void *data,
1215 struct drm_file *file_priv);
1216 extern struct drm_drawable_info *drm_get_drawable_info(struct drm_device *dev,
1218 extern void drm_drawable_free_all(struct drm_device *dev);
1220 /* Authentication IOCTL support (drm_auth.h) */
1221 extern int drm_getmagic(struct drm_device *dev, void *data,
1222 struct drm_file *file_priv);
1223 extern int drm_authmagic(struct drm_device *dev, void *data,
1224 struct drm_file *file_priv);
1226 /* Locking IOCTL support (drm_lock.h) */
1227 extern int drm_lock(struct drm_device *dev, void *data,
1228 struct drm_file *file_priv);
1229 extern int drm_unlock(struct drm_device *dev, void *data,
1230 struct drm_file *file_priv);
1231 extern int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
1232 extern int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context);
1233 extern void drm_idlelock_take(struct drm_lock_data *lock_data);
1234 extern void drm_idlelock_release(struct drm_lock_data *lock_data);
1237 * These are exported to drivers so that they can implement fencing using
1238 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
1241 extern int drm_i_have_hw_lock(struct drm_device *dev,
1242 struct drm_file *file_priv);
1244 /* Buffer management support (drm_bufs.h) */
1245 extern int drm_addbufs_agp(struct drm_device *dev, struct drm_buf_desc * request);
1246 extern int drm_addbufs_pci(struct drm_device *dev, struct drm_buf_desc * request);
1247 extern int drm_addbufs_fb (struct drm_device *dev, struct drm_buf_desc * request);
1248 extern int drm_addmap(struct drm_device *dev, unsigned int offset,
1249 unsigned int size, enum drm_map_type type,
1250 enum drm_map_flags flags, drm_local_map_t ** map_ptr);
1251 extern int drm_addmap_ioctl(struct drm_device *dev, void *data,
1252 struct drm_file *file_priv);
1253 extern int drm_rmmap(struct drm_device *dev, drm_local_map_t *map);
1254 extern int drm_rmmap_locked(struct drm_device *dev, drm_local_map_t *map);
1255 extern int drm_rmmap_ioctl(struct drm_device *dev, void *data,
1256 struct drm_file *file_priv);
1257 extern int drm_addbufs(struct drm_device *dev, void *data,
1258 struct drm_file *file_priv);
1259 extern int drm_infobufs(struct drm_device *dev, void *data,
1260 struct drm_file *file_priv);
1261 extern int drm_markbufs(struct drm_device *dev, void *data,
1262 struct drm_file *file_priv);
1263 extern int drm_freebufs(struct drm_device *dev, void *data,
1264 struct drm_file *file_priv);
1265 extern int drm_mapbufs(struct drm_device *dev, void *data,
1266 struct drm_file *file_priv);
1267 extern int drm_order(unsigned long size);
1268 extern unsigned long drm_get_resource_start(struct drm_device *dev,
1269 unsigned int resource);
1270 extern unsigned long drm_get_resource_len(struct drm_device *dev,
1271 unsigned int resource);
1272 extern struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
1273 drm_local_map_t *map);
1276 /* DMA support (drm_dma.h) */
1277 extern int drm_dma_setup(struct drm_device *dev);
1278 extern void drm_dma_takedown(struct drm_device *dev);
1279 extern void drm_free_buffer(struct drm_device *dev, struct drm_buf * buf);
1280 extern void drm_core_reclaim_buffers(struct drm_device *dev,
1281 struct drm_file *filp);
1283 /* IRQ support (drm_irq.h) */
1284 extern int drm_control(struct drm_device *dev, void *data,
1285 struct drm_file *file_priv);
1286 extern irqreturn_t drm_irq_handler(DRM_IRQ_ARGS);
1287 extern int drm_irq_install(struct drm_device *dev);
1288 extern int drm_irq_uninstall(struct drm_device *dev);
1289 extern void drm_driver_irq_preinstall(struct drm_device *dev);
1290 extern void drm_driver_irq_postinstall(struct drm_device *dev);
1291 extern void drm_driver_irq_uninstall(struct drm_device *dev);
1293 extern int drm_hotplug_init(struct drm_device *dev);
1294 extern int drm_wait_hotplug(struct drm_device *dev, void *data, struct drm_file *filp);
1295 extern int drm_vblank_init(struct drm_device *dev, int num_crtcs);
1296 extern int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *filp);
1297 extern int drm_wait_hotplug(struct drm_device *dev, void *data, struct drm_file *filp);
1298 extern int drm_vblank_wait(struct drm_device * dev, unsigned int *vbl_seq);
1299 extern void drm_locked_tasklet(struct drm_device *dev, void(*func)(struct drm_device*));
1300 extern u32 drm_vblank_count(struct drm_device *dev, int crtc);
1301 extern void drm_handle_vblank(struct drm_device *dev, int crtc);
1302 extern void drm_handle_hotplug(struct drm_device *dev);
1303 extern int drm_vblank_get(struct drm_device *dev, int crtc);
1304 extern void drm_vblank_put(struct drm_device *dev, int crtc);
1306 /* Modesetting support */
1307 extern int drm_modeset_ctl(struct drm_device *dev, void *data,
1308 struct drm_file *file_priv);
1310 /* AGP/GART support (drm_agpsupport.h) */
1311 extern struct drm_agp_head *drm_agp_init(struct drm_device *dev);
1312 extern int drm_agp_acquire(struct drm_device *dev);
1313 extern int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
1314 struct drm_file *file_priv);
1315 extern int drm_agp_release(struct drm_device *dev);
1316 extern int drm_agp_release_ioctl(struct drm_device *dev, void *data,
1317 struct drm_file *file_priv);
1318 extern int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
1319 extern int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
1320 struct drm_file *file_priv);
1321 extern int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
1322 extern int drm_agp_info_ioctl(struct drm_device *dev, void *data,
1323 struct drm_file *file_priv);
1324 extern int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
1325 extern int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
1326 struct drm_file *file_priv);
1327 extern int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
1328 extern int drm_agp_free_ioctl(struct drm_device *dev, void *data,
1329 struct drm_file *file_priv);
1330 extern int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
1331 extern int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
1332 struct drm_file *file_priv);
1333 extern int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
1334 extern int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
1335 struct drm_file *file_priv);
1336 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,11)
1337 extern DRM_AGP_MEM *drm_agp_allocate_memory(size_t pages, u32 type);
1339 extern DRM_AGP_MEM *drm_agp_allocate_memory(struct agp_bridge_data *bridge, size_t pages, u32 type);
1341 extern int drm_agp_free_memory(DRM_AGP_MEM * handle);
1342 extern int drm_agp_bind_memory(DRM_AGP_MEM * handle, off_t start);
1343 extern int drm_agp_unbind_memory(DRM_AGP_MEM * handle);
1344 extern struct drm_ttm_backend *drm_agp_init_ttm(struct drm_device *dev);
1345 extern void drm_agp_chipset_flush(struct drm_device *dev);
1346 /* Stub support (drm_stub.h) */
1347 extern int drm_setmaster_ioctl(struct drm_device *dev, void *data,
1348 struct drm_file *file_priv);
1349 extern int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
1350 struct drm_file *file_priv);
1351 struct drm_master *drm_master_create(struct drm_minor *minor);
1352 extern struct drm_master *drm_master_get(struct drm_master *master);
1353 extern void drm_master_put(struct drm_master **master);
1354 extern int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
1355 struct drm_driver *driver);
1356 extern int drm_put_dev(struct drm_device *dev);
1357 extern int drm_put_minor(struct drm_minor **minor_p);
1358 extern unsigned int drm_debug; /* 1 to enable debug output */
1360 extern struct class *drm_class;
1361 extern struct proc_dir_entry *drm_proc_root;
1363 extern struct idr drm_minors_idr;
1365 extern drm_local_map_t *drm_getsarea(struct drm_device *dev);
1367 /* Proc support (drm_proc.h) */
1368 int drm_proc_init(struct drm_minor *minor, int minor_id,
1369 struct proc_dir_entry *root);
1370 int drm_proc_cleanup(struct drm_minor *minor, struct proc_dir_entry *root);
1372 /* Scatter Gather Support (drm_scatter.h) */
1373 extern void drm_sg_cleanup(struct drm_sg_mem * entry);
1374 extern int drm_sg_alloc_ioctl(struct drm_device *dev, void *data,
1375 struct drm_file *file_priv);
1376 extern int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request);
1377 extern int drm_sg_free(struct drm_device *dev, void *data,
1378 struct drm_file *file_priv);
1380 /* ATI PCIGART support (ati_pcigart.h) */
1381 extern int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1382 extern int drm_ati_pcigart_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info);
1383 extern int drm_ati_alloc_pcigart_table(struct drm_device *dev,
1384 struct drm_ati_pcigart_info *gart_info);
1386 extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1387 size_t align, dma_addr_t maxaddr);
1388 extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1389 extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
1391 /* sysfs support (drm_sysfs.c) */
1392 struct drm_sysfs_class;
1393 extern struct class *drm_sysfs_create(struct module *owner, char *name);
1394 extern void drm_sysfs_destroy(void);
1395 extern int drm_sysfs_device_add(struct drm_minor *minor);
1396 extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1397 extern void drm_sysfs_device_remove(struct drm_minor *minor);
1398 extern char *drm_get_connector_status_name(enum drm_connector_status status);
1399 extern int drm_sysfs_connector_add(struct drm_connector *connector);
1400 extern void drm_sysfs_connector_remove(struct drm_connector *connector);
1403 * Basic memory manager support (drm_mm.c)
1406 extern struct drm_mm_node * drm_mm_get_block(struct drm_mm_node * parent, unsigned long size,
1407 unsigned alignment);
1408 extern void drm_mm_put_block(struct drm_mm_node *cur);
1409 extern struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, unsigned long size,
1410 unsigned alignment, int best_match);
1411 extern int drm_mm_init(struct drm_mm *mm, unsigned long start, unsigned long size);
1412 extern void drm_mm_takedown(struct drm_mm *mm);
1413 extern int drm_mm_clean(struct drm_mm *mm);
1414 extern unsigned long drm_mm_tail_space(struct drm_mm *mm);
1415 extern int drm_mm_remove_space_from_tail(struct drm_mm *mm, unsigned long size);
1416 extern int drm_mm_add_space_to_tail(struct drm_mm *mm, unsigned long size);
1418 static inline struct drm_mm *drm_get_mm(struct drm_mm_node *block)
1423 /* Graphics Execution Manager library functions (drm_gem.c) */
1425 drm_gem_init (struct drm_device *dev);
1428 drm_gem_object_free (struct kref *kref);
1430 struct drm_gem_object *
1431 drm_gem_object_alloc(struct drm_device *dev, size_t size);
1434 drm_gem_object_handle_free (struct kref *kref);
1436 static inline void drm_gem_object_reference(struct drm_gem_object *obj)
1438 kref_get(&obj->refcount);
1441 static inline void drm_gem_object_unreference(struct drm_gem_object *obj)
1446 kref_put (&obj->refcount, drm_gem_object_free);
1450 drm_gem_handle_create(struct drm_file *file_priv,
1451 struct drm_gem_object *obj,
1454 static inline void drm_gem_object_handle_reference (struct drm_gem_object *obj)
1456 drm_gem_object_reference (obj);
1457 kref_get(&obj->handlecount);
1460 static inline void drm_gem_object_handle_unreference (struct drm_gem_object *obj)
1466 * Must bump handle count first as this may be the last
1467 * ref, in which case the object would disappear before we
1468 * checked for a name
1470 kref_put (&obj->handlecount, drm_gem_object_handle_free);
1471 drm_gem_object_unreference (obj);
1474 struct drm_gem_object *
1475 drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp,
1477 int drm_gem_close_ioctl(struct drm_device *dev, void *data,
1478 struct drm_file *file_priv);
1479 int drm_gem_flink_ioctl(struct drm_device *dev, void *data,
1480 struct drm_file *file_priv);
1481 int drm_gem_open_ioctl(struct drm_device *dev, void *data,
1482 struct drm_file *file_priv);
1484 void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
1485 void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
1487 extern void drm_core_ioremap(struct drm_map *map, struct drm_device *dev);
1488 extern void drm_core_ioremap_wc(struct drm_map *map, struct drm_device *dev);
1489 extern void drm_core_ioremapfree(struct drm_map *map, struct drm_device *dev);
1491 static __inline__ struct drm_map *drm_core_findmap(struct drm_device *dev,
1494 struct drm_map_list *_entry;
1495 list_for_each_entry(_entry, &dev->maplist, head)
1496 if (_entry->user_token == token)
1501 static __inline__ int drm_device_is_agp(struct drm_device *dev)
1503 if ( dev->driver->device_is_agp != NULL ) {
1504 int err = (*dev->driver->device_is_agp)(dev);
1511 return pci_find_capability(dev->pdev, PCI_CAP_ID_AGP);
1514 static __inline__ int drm_device_is_pcie(struct drm_device *dev)
1516 return pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
1519 static __inline__ void drm_core_dropmap(struct drm_map *map)
1523 #ifndef DEBUG_MEMORY
1524 /** Wrapper around kmalloc() */
1525 static __inline__ void *drm_alloc(size_t size, int area)
1527 return kmalloc(size, GFP_KERNEL);
1530 /** Wrapper around kfree() */
1531 static __inline__ void drm_free(void *pt, size_t size, int area)
1536 extern void *drm_alloc(size_t size, int area);
1537 extern void drm_free(void *pt, size_t size, int area);
1541 * Accounting variants of standard calls.
1544 static inline void *drm_ctl_alloc(size_t size, int area)
1547 if (drm_alloc_memctl(size))
1549 ret = drm_alloc(size, area);
1551 drm_free_memctl(size);
1555 static inline void *drm_ctl_calloc(size_t nmemb, size_t size, int area)
1559 if (drm_alloc_memctl(nmemb*size))
1561 ret = drm_calloc(nmemb, size, area);
1563 drm_free_memctl(nmemb*size);
1567 static inline void drm_ctl_free(void *pt, size_t size, int area)
1569 drm_free(pt, size, area);
1570 drm_free_memctl(size);
1575 #endif /* __KERNEL__ */