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.
37 /* If you want the memory alloc debug functionality, change define below */
38 /* #define DEBUG_MEMORY */
42 /* add include of current.h so that "current" is defined
43 * before static inline funcs in wait.h. Doing this so we
44 * can build the DRM (part of PI DRI). 4/21/2000 S + B */
45 #include <asm/current.h>
46 #endif /* __alpha__ */
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/miscdevice.h>
51 #include <linux/proc_fs.h>
52 #include <linux/init.h>
53 #include <linux/file.h>
54 #include <linux/pci.h>
55 #include <linux/jiffies.h>
56 #include <linux/smp_lock.h> /* For (un)lock_kernel */
57 #include <linux/dma-mapping.h>
59 #include <linux/cdev.h>
60 #include <linux/mutex.h>
61 #if defined(__alpha__) || defined(__powerpc__)
62 #include <asm/pgtable.h> /* For pte_wrprotect */
66 #include <asm/uaccess.h>
70 #if defined(CONFIG_AGP) || defined(CONFIG_AGP_MODULE)
71 #include <linux/types.h>
72 #include <linux/agp_backend.h>
74 #include <linux/workqueue.h>
75 #include <linux/poll.h>
76 #include <asm/pgalloc.h>
79 #include <linux/idr.h>
81 #define __OS_HAS_AGP (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
82 #define __OS_HAS_MTRR (defined(CONFIG_MTRR))
87 #include "drm_os_linux.h"
88 #include "drm_hashtab.h"
90 /***********************************************************************/
91 /** \name DRM template customization defaults */
94 /* driver capabilities and requirements mask */
95 #define DRIVER_USE_AGP 0x1
96 #define DRIVER_REQUIRE_AGP 0x2
97 #define DRIVER_USE_MTRR 0x4
98 #define DRIVER_PCI_DMA 0x8
99 #define DRIVER_SG 0x10
100 #define DRIVER_HAVE_DMA 0x20
101 #define DRIVER_HAVE_IRQ 0x40
102 #define DRIVER_IRQ_SHARED 0x80
103 #define DRIVER_DMA_QUEUE 0x200
104 #define DRIVER_FB_DMA 0x400
106 /***********************************************************************/
107 /** \name Begin the DRM... */
110 #define DRM_DEBUG_CODE 2 /**< Include debugging code if > 1, then
111 also include looping detection. */
113 #define DRM_MAGIC_HASH_ORDER 4 /**< Size of key hash table. Must be power of 2. */
114 #define DRM_KERNEL_CONTEXT 0 /**< Change drm_resctx if changed */
115 #define DRM_RESERVED_CONTEXTS 1 /**< Change drm_resctx if changed */
116 #define DRM_LOOPING_LIMIT 5000000
117 #define DRM_TIME_SLICE (HZ/20) /**< Time slice for GLXContexts */
118 #define DRM_LOCK_SLICE 1 /**< Time slice for lock, in jiffies */
120 #define DRM_FLAG_DEBUG 0x01
122 #define DRM_MEM_DMA 0
123 #define DRM_MEM_SAREA 1
124 #define DRM_MEM_DRIVER 2
125 #define DRM_MEM_MAGIC 3
126 #define DRM_MEM_IOCTLS 4
127 #define DRM_MEM_MAPS 5
128 #define DRM_MEM_VMAS 6
129 #define DRM_MEM_BUFS 7
130 #define DRM_MEM_SEGS 8
131 #define DRM_MEM_PAGES 9
132 #define DRM_MEM_FILES 10
133 #define DRM_MEM_QUEUES 11
134 #define DRM_MEM_CMDS 12
135 #define DRM_MEM_MAPPINGS 13
136 #define DRM_MEM_BUFLISTS 14
137 #define DRM_MEM_AGPLISTS 15
138 #define DRM_MEM_TOTALAGP 16
139 #define DRM_MEM_BOUNDAGP 17
140 #define DRM_MEM_CTXBITMAP 18
141 #define DRM_MEM_STUB 19
142 #define DRM_MEM_SGLISTS 20
143 #define DRM_MEM_CTXLIST 21
144 #define DRM_MEM_MM 22
145 #define DRM_MEM_HASHTAB 23
147 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
148 #define DRM_MAP_HASH_OFFSET 0x10000000
152 /***********************************************************************/
153 /** \name Macros to make printk easier */
159 * \param fmt printf() like format string.
160 * \param arg arguments
162 #define DRM_ERROR(fmt, arg...) \
163 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
166 * Memory error output.
168 * \param area memory area where the error occurred.
169 * \param fmt printf() like format string.
170 * \param arg arguments
172 #define DRM_MEM_ERROR(area, fmt, arg...) \
173 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
174 drm_mem_stats[area].name , ##arg)
176 #define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
181 * \param fmt printf() like format string.
182 * \param arg arguments
185 #define DRM_DEBUG(fmt, arg...) \
189 "[" DRM_NAME ":%s] " fmt , \
193 #define DRM_DEBUG(fmt, arg...) do { } while (0)
196 #define DRM_PROC_LIMIT (PAGE_SIZE-80)
198 #define DRM_PROC_PRINT(fmt, arg...) \
199 len += sprintf(&buf[len], fmt , ##arg); \
200 if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; }
202 #define DRM_PROC_PRINT_RET(ret, fmt, arg...) \
203 len += sprintf(&buf[len], fmt , ##arg); \
204 if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; }
208 /***********************************************************************/
209 /** \name Internal types and structures */
212 #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x)
214 #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1))
215 #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x))
216 #define DRM_WAITCOUNT(dev,idx) DRM_BUFCOUNT(&dev->queuelist[idx]->waitlist)
218 #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
220 * Get the private SAREA mapping.
222 * \param _dev DRM device.
223 * \param _ctx context number.
224 * \param _map output mapping.
226 #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \
227 (_map) = (_dev)->context_sareas[_ctx]; \
231 * Test that the hardware lock is held by the caller, returning otherwise.
233 * \param dev DRM device.
234 * \param filp file pointer of the caller.
236 #define LOCK_TEST_WITH_RETURN( dev, file_priv ) \
238 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
239 dev->lock.file_priv != file_priv ) { \
240 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
241 __func__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
242 dev->lock.file_priv, file_priv ); \
248 * Copy and IOCTL return string to user space
250 #define DRM_COPY( name, value ) \
251 len = strlen( value ); \
252 if ( len > name##_len ) len = name##_len; \
253 name##_len = strlen( value ); \
254 if ( len && name ) { \
255 if ( copy_to_user( name, value, len ) ) \
260 * Ioctl function type.
262 * \param inode device inode.
263 * \param file_priv DRM file private pointer.
264 * \param cmd command.
265 * \param arg argument.
267 typedef int drm_ioctl_t(struct drm_device
*dev
, void *data
,
268 struct drm_file
*file_priv
);
270 typedef int drm_ioctl_compat_t(struct file
*filp
, unsigned int cmd
,
274 #define DRM_MASTER 0x2
275 #define DRM_ROOT_ONLY 0x4
277 struct drm_ioctl_desc
{
284 * Creates a driver or general drm_ioctl_desc array entry for the given
285 * ioctl, for use by drm_ioctl().
287 #define DRM_IOCTL_DEF(ioctl, func, flags) \
288 [DRM_IOCTL_NR(ioctl)] = {ioctl, func, flags}
290 struct drm_magic_entry
{
291 struct list_head head
;
292 struct drm_hash_item hash_item
;
293 struct drm_file
*priv
;
296 struct drm_vma_entry
{
297 struct list_head head
;
298 struct vm_area_struct
*vma
;
306 int idx
; /**< Index into master buflist */
307 int total
; /**< Buffer size */
308 int order
; /**< log-base-2(total) */
309 int used
; /**< Amount of buffer in use (for DMA) */
310 unsigned long offset
; /**< Byte offset (used internally) */
311 void *address
; /**< Address of buffer */
312 unsigned long bus_address
; /**< Bus address of buffer */
313 struct drm_buf
*next
; /**< Kernel-only: used for free list */
314 __volatile__
int waiting
; /**< On kernel DMA queue */
315 __volatile__
int pending
; /**< On hardware DMA queue */
316 wait_queue_head_t dma_wait
; /**< Processes waiting */
317 struct drm_file
*file_priv
; /**< Private of holding file descr */
318 int context
; /**< Kernel queue for this buffer */
319 int while_locked
; /**< Dispatch this buffer while locked */
327 } list
; /**< Which list we're on */
329 int dev_priv_size
; /**< Size of buffer private storage */
330 void *dev_private
; /**< Per-buffer private storage */
333 /** bufs is one longer than it has to be */
334 struct drm_waitlist
{
335 int count
; /**< Number of possible buffers */
336 struct drm_buf
**bufs
; /**< List of pointers to buffers */
337 struct drm_buf
**rp
; /**< Read pointer */
338 struct drm_buf
**wp
; /**< Write pointer */
339 struct drm_buf
**end
; /**< End pointer */
340 spinlock_t read_lock
;
341 spinlock_t write_lock
;
344 struct drm_freelist
{
345 int initialized
; /**< Freelist in use */
346 atomic_t count
; /**< Number of free buffers */
347 struct drm_buf
*next
; /**< End pointer */
349 wait_queue_head_t waiting
; /**< Processes waiting on free bufs */
350 int low_mark
; /**< Low water mark */
351 int high_mark
; /**< High water mark */
352 atomic_t wfh
; /**< If waiting for high mark */
356 typedef struct drm_dma_handle
{
363 * Buffer entry. There is one of this for each buffer size order.
365 struct drm_buf_entry
{
366 int buf_size
; /**< size */
367 int buf_count
; /**< number of buffers */
368 struct drm_buf
*buflist
; /**< buffer list */
371 struct drm_dma_handle
**seglist
;
373 struct drm_freelist freelist
;
376 /** File private data */
383 unsigned long ioctl_count
;
384 struct list_head lhead
;
385 struct drm_minor
*minor
;
386 int remove_auth_on_close
;
387 unsigned long lock_count
;
394 atomic_t use_count
; /**< Outstanding uses (+1) */
395 atomic_t finalization
; /**< Finalization in progress */
396 atomic_t block_count
; /**< Count of processes waiting */
397 atomic_t block_read
; /**< Queue blocked for reads */
398 wait_queue_head_t read_queue
; /**< Processes waiting on block_read */
399 atomic_t block_write
; /**< Queue blocked for writes */
400 wait_queue_head_t write_queue
; /**< Processes waiting on block_write */
401 atomic_t total_queued
; /**< Total queued statistic */
402 atomic_t total_flushed
; /**< Total flushes statistic */
403 atomic_t total_locks
; /**< Total locks statistics */
404 enum drm_ctx_flags flags
; /**< Context preserving and 2D-only */
405 struct drm_waitlist waitlist
; /**< Pending buffers */
406 wait_queue_head_t flush_queue
; /**< Processes waiting until flush */
412 struct drm_lock_data
{
413 struct drm_hw_lock
*hw_lock
; /**< Hardware lock */
414 /** Private of lock holder's file (NULL=kernel) */
415 struct drm_file
*file_priv
;
416 wait_queue_head_t lock_queue
; /**< Queue of blocked processes */
417 unsigned long lock_time
; /**< Time of last lock in jiffies */
419 uint32_t kernel_waiters
;
420 uint32_t user_waiters
;
427 struct drm_device_dma
{
429 struct drm_buf_entry bufs
[DRM_MAX_ORDER
+ 1]; /**< buffers, grouped by their size order */
430 int buf_count
; /**< total number of buffers */
431 struct drm_buf
**buflist
; /**< Vector of pointers into drm_device_dma::bufs */
433 int page_count
; /**< number of pages */
434 unsigned long *pagelist
; /**< page list */
435 unsigned long byte_count
;
437 _DRM_DMA_USE_AGP
= 0x01,
438 _DRM_DMA_USE_SG
= 0x02,
439 _DRM_DMA_USE_FB
= 0x04,
440 _DRM_DMA_USE_PCI_RO
= 0x08
446 * AGP memory entry. Stored as a doubly linked list.
449 unsigned long handle
; /**< handle */
451 unsigned long bound
; /**< address */
453 struct list_head head
;
459 * \sa drm_agp_init() and drm_device::agp.
461 struct drm_agp_head
{
462 DRM_AGP_KERN agp_info
; /**< AGP device information */
463 struct list_head memory
;
464 unsigned long mode
; /**< AGP mode */
465 struct agp_bridge_data
*bridge
;
466 int enabled
; /**< whether the AGP bus as been enabled */
467 int acquired
; /**< whether the AGP device has been acquired */
470 int cant_use_aperture
;
471 unsigned long page_mask
;
475 * Scatter-gather memory.
478 unsigned long handle
;
481 struct page
**pagelist
;
487 struct drm_hw_lock
*lock
;
492 * Generic memory manager structs
496 struct list_head fl_entry
;
497 struct list_head ml_entry
;
506 struct list_head fl_entry
;
507 struct list_head ml_entry
;
514 struct drm_map_list
{
515 struct list_head head
; /**< list head */
516 struct drm_hash_item hash
;
517 struct drm_map
*map
; /**< mapping */
521 typedef struct drm_map drm_local_map_t
;
524 * Context handle list
526 struct drm_ctx_list
{
527 struct list_head head
; /**< list head */
528 drm_context_t handle
; /**< context handle */
529 struct drm_file
*tag
; /**< associated fd private data */
533 struct list_head head
;
534 unsigned int sequence
;
536 struct task_struct
*task
;
539 /* location of GART table */
540 #define DRM_ATI_GART_MAIN 1
541 #define DRM_ATI_GART_FB 2
543 #define DRM_ATI_GART_PCI 1
544 #define DRM_ATI_GART_PCIE 2
545 #define DRM_ATI_GART_IGP 3
547 struct drm_ati_pcigart_info
{
548 int gart_table_location
;
552 dma_addr_t table_mask
;
553 struct drm_dma_handle
*table_handle
;
554 drm_local_map_t mapping
;
559 * DRM driver structure. This structure represent the common code for
560 * a family of cards. There will one drm_device for each card present
564 int (*load
) (struct drm_device
*, unsigned long flags
);
565 int (*firstopen
) (struct drm_device
*);
566 int (*open
) (struct drm_device
*, struct drm_file
*);
567 void (*preclose
) (struct drm_device
*, struct drm_file
*file_priv
);
568 void (*postclose
) (struct drm_device
*, struct drm_file
*);
569 void (*lastclose
) (struct drm_device
*);
570 int (*unload
) (struct drm_device
*);
571 int (*suspend
) (struct drm_device
*, pm_message_t state
);
572 int (*resume
) (struct drm_device
*);
573 int (*dma_ioctl
) (struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
574 void (*dma_ready
) (struct drm_device
*);
575 int (*dma_quiescent
) (struct drm_device
*);
576 int (*context_ctor
) (struct drm_device
*dev
, int context
);
577 int (*context_dtor
) (struct drm_device
*dev
, int context
);
578 int (*kernel_context_switch
) (struct drm_device
*dev
, int old
,
580 void (*kernel_context_switch_unlock
) (struct drm_device
* dev
);
582 * get_vblank_counter - get raw hardware vblank counter
584 * @crtc: counter to fetch
586 * Driver callback for fetching a raw hardware vblank counter
587 * for @crtc. If a device doesn't have a hardware counter, the
588 * driver can simply return the value of drm_vblank_count and
589 * make the enable_vblank() and disable_vblank() hooks into no-ops,
590 * leaving interrupts enabled at all times.
592 * Wraparound handling and loss of events due to modesetting is dealt
593 * with in the DRM core code.
596 * Raw vblank counter value.
598 u32 (*get_vblank_counter
) (struct drm_device
*dev
, int crtc
);
601 * enable_vblank - enable vblank interrupt events
603 * @crtc: which irq to enable
605 * Enable vblank interrupts for @crtc. If the device doesn't have
606 * a hardware vblank counter, this routine should be a no-op, since
607 * interrupts will have to stay on to keep the count accurate.
610 * Zero on success, appropriate errno if the given @crtc's vblank
611 * interrupt cannot be enabled.
613 int (*enable_vblank
) (struct drm_device
*dev
, int crtc
);
616 * disable_vblank - disable vblank interrupt events
618 * @crtc: which irq to enable
620 * Disable vblank interrupts for @crtc. If the device doesn't have
621 * a hardware vblank counter, this routine should be a no-op, since
622 * interrupts will have to stay on to keep the count accurate.
624 void (*disable_vblank
) (struct drm_device
*dev
, int crtc
);
625 int (*dri_library_name
) (struct drm_device
*dev
, char * buf
);
628 * Called by \c drm_device_is_agp. Typically used to determine if a
629 * card is really attached to AGP or not.
631 * \param dev DRM device handle
634 * One of three values is returned depending on whether or not the
635 * card is absolutely \b not AGP (return of 0), absolutely \b is AGP
636 * (return of 1), or may or may not be AGP (return of 2).
638 int (*device_is_agp
) (struct drm_device
*dev
);
640 /* these have to be filled in */
642 irqreturn_t(*irq_handler
) (DRM_IRQ_ARGS
);
643 void (*irq_preinstall
) (struct drm_device
*dev
);
644 int (*irq_postinstall
) (struct drm_device
*dev
);
645 void (*irq_uninstall
) (struct drm_device
*dev
);
646 void (*reclaim_buffers
) (struct drm_device
*dev
,
647 struct drm_file
* file_priv
);
648 void (*reclaim_buffers_locked
) (struct drm_device
*dev
,
649 struct drm_file
*file_priv
);
650 void (*reclaim_buffers_idlelocked
) (struct drm_device
*dev
,
651 struct drm_file
*file_priv
);
652 unsigned long (*get_map_ofs
) (struct drm_map
* map
);
653 unsigned long (*get_reg_ofs
) (struct drm_device
*dev
);
654 void (*set_version
) (struct drm_device
*dev
,
655 struct drm_set_version
*sv
);
666 struct drm_ioctl_desc
*ioctls
;
668 struct file_operations fops
;
669 struct pci_driver pci_driver
;
672 #define DRM_MINOR_UNASSIGNED 0
673 #define DRM_MINOR_LEGACY 1
676 * DRM minor structure. This structure represents a drm minor number.
679 int index
; /**< Minor device number */
680 int type
; /**< Control or render */
681 dev_t device
; /**< Device number for mknod */
682 struct device kdev
; /**< Linux device */
683 struct drm_device
*dev
;
684 struct proc_dir_entry
*dev_root
; /**< proc directory entry */
688 * DRM device structure. This structure represent a complete card that
689 * may contain multiple heads.
692 char *unique
; /**< Unique identifier: e.g., busid */
693 int unique_len
; /**< Length of unique field */
694 char *devname
; /**< For /proc/interrupts */
695 int if_version
; /**< Highest interface version set */
697 int blocked
; /**< Blocked due to VC switch? */
701 spinlock_t count_lock
; /**< For inuse, drm_device::open_count, drm_device::buf_use */
702 struct mutex struct_mutex
; /**< For others */
705 /** \name Usage Counters */
707 int open_count
; /**< Outstanding files open */
708 atomic_t ioctl_count
; /**< Outstanding IOCTLs pending */
709 atomic_t vma_count
; /**< Outstanding vma areas open */
710 int buf_use
; /**< Buffers in use -- cannot alloc */
711 atomic_t buf_alloc
; /**< Buffer allocation in progress */
714 /** \name Performance counters */
716 unsigned long counters
;
717 enum drm_stat_type types
[15];
721 /** \name Authentication */
723 struct list_head filelist
;
724 struct drm_open_hash magiclist
; /**< magic hash table */
725 struct list_head magicfree
;
728 /** \name Memory management */
730 struct list_head maplist
; /**< Linked list of regions */
731 int map_count
; /**< Number of mappable regions */
732 struct drm_open_hash map_hash
; /**< User token hash table for maps */
734 /** \name Context handle management */
736 struct list_head ctxlist
; /**< Linked list of context handles */
737 int ctx_count
; /**< Number of context handles */
738 struct mutex ctxlist_mutex
; /**< For ctxlist */
742 struct list_head vmalist
; /**< List of vmas (for debugging) */
743 struct drm_lock_data lock
; /**< Information on hardware lock */
746 /** \name DMA queues (contexts) */
748 int queue_count
; /**< Number of active DMA queues */
749 int queue_reserved
; /**< Number of reserved DMA queues */
750 int queue_slots
; /**< Actual length of queuelist */
751 struct drm_queue
**queuelist
; /**< Vector of pointers to DMA queues */
752 struct drm_device_dma
*dma
; /**< Optional pointer for DMA support */
755 /** \name Context support */
757 int irq
; /**< Interrupt used by board */
758 int irq_enabled
; /**< True if irq handler is enabled */
759 __volatile__
long context_flag
; /**< Context swapping flag */
760 __volatile__
long interrupt_flag
; /**< Interruption handler flag */
761 __volatile__
long dma_flag
; /**< DMA dispatch flag */
762 struct timer_list timer
; /**< Timer for delaying ctx switch */
763 wait_queue_head_t context_wait
; /**< Processes waiting on ctx switch */
764 int last_checked
; /**< Last context checked for DMA */
765 int last_context
; /**< Last current context */
766 unsigned long last_switch
; /**< jiffies at last context switch */
769 struct work_struct work
;
770 /** \name VBLANK IRQ support */
773 wait_queue_head_t
*vbl_queue
; /**< VBLANK wait queue */
774 atomic_t
*_vblank_count
; /**< number of VBLANK interrupts (driver must alloc the right number of counters) */
776 struct list_head
*vbl_sigs
; /**< signal list to send on VBLANK */
777 atomic_t vbl_signal_pending
; /* number of signals pending on all crtcs*/
778 atomic_t
*vblank_refcount
; /* number of users of vblank interrupts per crtc */
779 u32
*last_vblank
; /* protected by dev->vbl_lock, used */
780 /* for wraparound handling */
781 u32
*vblank_offset
; /* used to track how many vblanks */
782 int *vblank_enabled
; /* so we don't call enable more than
784 u32
*vblank_premodeset
; /* were lost during modeset */
785 struct timer_list vblank_disable_timer
;
787 unsigned long max_vblank_count
; /**< size of vblank counter register */
788 spinlock_t tasklet_lock
; /**< For drm_locked_tasklet */
789 void (*locked_tasklet_func
)(struct drm_device
*dev
);
795 struct fasync_struct
*buf_async
;/**< Processes waiting for SIGIO */
796 wait_queue_head_t buf_readers
; /**< Processes waiting to read */
797 wait_queue_head_t buf_writers
; /**< Processes waiting to ctx switch */
799 struct drm_agp_head
*agp
; /**< AGP data */
801 struct pci_dev
*pdev
; /**< PCI device structure */
802 int pci_vendor
; /**< PCI vendor id */
803 int pci_device
; /**< PCI device id */
805 struct pci_controller
*hose
;
807 int num_crtcs
; /**< Number of CRTCs on this device */
808 struct drm_sg_mem
*sg
; /**< Scatter gather memory */
809 void *dev_private
; /**< device private data */
810 struct drm_sigdata sigdata
; /**< For block_all_signals */
813 struct drm_driver
*driver
;
814 drm_local_map_t
*agp_buffer_map
;
815 unsigned int agp_buffer_token
;
816 struct drm_minor
*primary
; /**< render type primary screen head */
818 /** \name Drawable information */
825 static __inline__
int drm_core_check_feature(struct drm_device
*dev
,
828 return ((dev
->driver
->driver_features
& feature
) ? 1 : 0);
832 #define drm_get_pci_domain(dev) dev->hose->index
834 #define drm_get_pci_domain(dev) 0
838 static inline int drm_core_has_AGP(struct drm_device
*dev
)
840 return drm_core_check_feature(dev
, DRIVER_USE_AGP
);
843 #define drm_core_has_AGP(dev) (0)
847 static inline int drm_core_has_MTRR(struct drm_device
*dev
)
849 return drm_core_check_feature(dev
, DRIVER_USE_MTRR
);
852 #define DRM_MTRR_WC MTRR_TYPE_WRCOMB
854 static inline int drm_mtrr_add(unsigned long offset
, unsigned long size
,
857 return mtrr_add(offset
, size
, flags
, 1);
860 static inline int drm_mtrr_del(int handle
, unsigned long offset
,
861 unsigned long size
, unsigned int flags
)
863 return mtrr_del(handle
, offset
, size
);
867 #define drm_core_has_MTRR(dev) (0)
869 #define DRM_MTRR_WC 0
871 static inline int drm_mtrr_add(unsigned long offset
, unsigned long size
,
877 static inline int drm_mtrr_del(int handle
, unsigned long offset
,
878 unsigned long size
, unsigned int flags
)
884 /******************************************************************/
885 /** \name Internal function definitions */
888 /* Driver support (drm_drv.h) */
889 extern int drm_init(struct drm_driver
*driver
);
890 extern void drm_exit(struct drm_driver
*driver
);
891 extern int drm_ioctl(struct inode
*inode
, struct file
*filp
,
892 unsigned int cmd
, unsigned long arg
);
893 extern long drm_compat_ioctl(struct file
*filp
,
894 unsigned int cmd
, unsigned long arg
);
895 extern int drm_lastclose(struct drm_device
*dev
);
897 /* Device support (drm_fops.h) */
898 extern int drm_open(struct inode
*inode
, struct file
*filp
);
899 extern int drm_stub_open(struct inode
*inode
, struct file
*filp
);
900 extern int drm_fasync(int fd
, struct file
*filp
, int on
);
901 extern int drm_release(struct inode
*inode
, struct file
*filp
);
903 /* Mapping support (drm_vm.h) */
904 extern int drm_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
905 extern unsigned long drm_core_get_map_ofs(struct drm_map
* map
);
906 extern unsigned long drm_core_get_reg_ofs(struct drm_device
*dev
);
907 extern unsigned int drm_poll(struct file
*filp
, struct poll_table_struct
*wait
);
909 /* Memory management support (drm_memory.h) */
910 #include "drm_memory.h"
911 extern void drm_mem_init(void);
912 extern int drm_mem_info(char *buf
, char **start
, off_t offset
,
913 int request
, int *eof
, void *data
);
914 extern void *drm_realloc(void *oldpt
, size_t oldsize
, size_t size
, int area
);
916 extern DRM_AGP_MEM
*drm_alloc_agp(struct drm_device
*dev
, int pages
, u32 type
);
917 extern int drm_free_agp(DRM_AGP_MEM
* handle
, int pages
);
918 extern int drm_bind_agp(DRM_AGP_MEM
* handle
, unsigned int start
);
919 extern int drm_unbind_agp(DRM_AGP_MEM
* handle
);
921 /* Misc. IOCTL support (drm_ioctl.h) */
922 extern int drm_irq_by_busid(struct drm_device
*dev
, void *data
,
923 struct drm_file
*file_priv
);
924 extern int drm_getunique(struct drm_device
*dev
, void *data
,
925 struct drm_file
*file_priv
);
926 extern int drm_setunique(struct drm_device
*dev
, void *data
,
927 struct drm_file
*file_priv
);
928 extern int drm_getmap(struct drm_device
*dev
, void *data
,
929 struct drm_file
*file_priv
);
930 extern int drm_getclient(struct drm_device
*dev
, void *data
,
931 struct drm_file
*file_priv
);
932 extern int drm_getstats(struct drm_device
*dev
, void *data
,
933 struct drm_file
*file_priv
);
934 extern int drm_setversion(struct drm_device
*dev
, void *data
,
935 struct drm_file
*file_priv
);
936 extern int drm_noop(struct drm_device
*dev
, void *data
,
937 struct drm_file
*file_priv
);
939 /* Context IOCTL support (drm_context.h) */
940 extern int drm_resctx(struct drm_device
*dev
, void *data
,
941 struct drm_file
*file_priv
);
942 extern int drm_addctx(struct drm_device
*dev
, void *data
,
943 struct drm_file
*file_priv
);
944 extern int drm_modctx(struct drm_device
*dev
, void *data
,
945 struct drm_file
*file_priv
);
946 extern int drm_getctx(struct drm_device
*dev
, void *data
,
947 struct drm_file
*file_priv
);
948 extern int drm_switchctx(struct drm_device
*dev
, void *data
,
949 struct drm_file
*file_priv
);
950 extern int drm_newctx(struct drm_device
*dev
, void *data
,
951 struct drm_file
*file_priv
);
952 extern int drm_rmctx(struct drm_device
*dev
, void *data
,
953 struct drm_file
*file_priv
);
955 extern int drm_ctxbitmap_init(struct drm_device
*dev
);
956 extern void drm_ctxbitmap_cleanup(struct drm_device
*dev
);
957 extern void drm_ctxbitmap_free(struct drm_device
*dev
, int ctx_handle
);
959 extern int drm_setsareactx(struct drm_device
*dev
, void *data
,
960 struct drm_file
*file_priv
);
961 extern int drm_getsareactx(struct drm_device
*dev
, void *data
,
962 struct drm_file
*file_priv
);
964 /* Drawable IOCTL support (drm_drawable.h) */
965 extern int drm_adddraw(struct drm_device
*dev
, void *data
,
966 struct drm_file
*file_priv
);
967 extern int drm_rmdraw(struct drm_device
*dev
, void *data
,
968 struct drm_file
*file_priv
);
969 extern int drm_update_drawable_info(struct drm_device
*dev
, void *data
,
970 struct drm_file
*file_priv
);
971 extern struct drm_drawable_info
*drm_get_drawable_info(struct drm_device
*dev
,
973 extern void drm_drawable_free_all(struct drm_device
*dev
);
975 /* Authentication IOCTL support (drm_auth.h) */
976 extern int drm_getmagic(struct drm_device
*dev
, void *data
,
977 struct drm_file
*file_priv
);
978 extern int drm_authmagic(struct drm_device
*dev
, void *data
,
979 struct drm_file
*file_priv
);
981 /* Locking IOCTL support (drm_lock.h) */
982 extern int drm_lock(struct drm_device
*dev
, void *data
,
983 struct drm_file
*file_priv
);
984 extern int drm_unlock(struct drm_device
*dev
, void *data
,
985 struct drm_file
*file_priv
);
986 extern int drm_lock_take(struct drm_lock_data
*lock_data
, unsigned int context
);
987 extern int drm_lock_free(struct drm_lock_data
*lock_data
, unsigned int context
);
988 extern void drm_idlelock_take(struct drm_lock_data
*lock_data
);
989 extern void drm_idlelock_release(struct drm_lock_data
*lock_data
);
992 * These are exported to drivers so that they can implement fencing using
993 * DMA quiscent + idle. DMA quiescent usually requires the hardware lock.
996 extern int drm_i_have_hw_lock(struct drm_device
*dev
, struct drm_file
*file_priv
);
998 /* Buffer management support (drm_bufs.h) */
999 extern int drm_addbufs_agp(struct drm_device
*dev
, struct drm_buf_desc
* request
);
1000 extern int drm_addbufs_pci(struct drm_device
*dev
, struct drm_buf_desc
* request
);
1001 extern int drm_addmap(struct drm_device
*dev
, unsigned int offset
,
1002 unsigned int size
, enum drm_map_type type
,
1003 enum drm_map_flags flags
, drm_local_map_t
** map_ptr
);
1004 extern int drm_addmap_ioctl(struct drm_device
*dev
, void *data
,
1005 struct drm_file
*file_priv
);
1006 extern int drm_rmmap(struct drm_device
*dev
, drm_local_map_t
*map
);
1007 extern int drm_rmmap_locked(struct drm_device
*dev
, drm_local_map_t
*map
);
1008 extern int drm_rmmap_ioctl(struct drm_device
*dev
, void *data
,
1009 struct drm_file
*file_priv
);
1010 extern int drm_addbufs(struct drm_device
*dev
, void *data
,
1011 struct drm_file
*file_priv
);
1012 extern int drm_infobufs(struct drm_device
*dev
, void *data
,
1013 struct drm_file
*file_priv
);
1014 extern int drm_markbufs(struct drm_device
*dev
, void *data
,
1015 struct drm_file
*file_priv
);
1016 extern int drm_freebufs(struct drm_device
*dev
, void *data
,
1017 struct drm_file
*file_priv
);
1018 extern int drm_mapbufs(struct drm_device
*dev
, void *data
,
1019 struct drm_file
*file_priv
);
1020 extern int drm_order(unsigned long size
);
1021 extern unsigned long drm_get_resource_start(struct drm_device
*dev
,
1022 unsigned int resource
);
1023 extern unsigned long drm_get_resource_len(struct drm_device
*dev
,
1024 unsigned int resource
);
1026 /* DMA support (drm_dma.h) */
1027 extern int drm_dma_setup(struct drm_device
*dev
);
1028 extern void drm_dma_takedown(struct drm_device
*dev
);
1029 extern void drm_free_buffer(struct drm_device
*dev
, struct drm_buf
* buf
);
1030 extern void drm_core_reclaim_buffers(struct drm_device
*dev
,
1031 struct drm_file
*filp
);
1033 /* IRQ support (drm_irq.h) */
1034 extern int drm_control(struct drm_device
*dev
, void *data
,
1035 struct drm_file
*file_priv
);
1036 extern irqreturn_t
drm_irq_handler(DRM_IRQ_ARGS
);
1037 extern int drm_irq_uninstall(struct drm_device
*dev
);
1038 extern void drm_driver_irq_preinstall(struct drm_device
*dev
);
1039 extern void drm_driver_irq_postinstall(struct drm_device
*dev
);
1040 extern void drm_driver_irq_uninstall(struct drm_device
*dev
);
1042 extern int drm_vblank_init(struct drm_device
*dev
, int num_crtcs
);
1043 extern int drm_wait_vblank(struct drm_device
*dev
, void *data
, struct drm_file
*filp
);
1044 extern int drm_vblank_wait(struct drm_device
* dev
, unsigned int *vbl_seq
);
1045 extern void drm_locked_tasklet(struct drm_device
*dev
, void(*func
)(struct drm_device
*));
1046 extern u32
drm_vblank_count(struct drm_device
*dev
, int crtc
);
1047 extern void drm_update_vblank_count(struct drm_device
*dev
, int crtc
);
1048 extern void drm_handle_vblank(struct drm_device
*dev
, int crtc
);
1049 extern int drm_vblank_get(struct drm_device
*dev
, int crtc
);
1050 extern void drm_vblank_put(struct drm_device
*dev
, int crtc
);
1052 /* Modesetting support */
1053 extern int drm_modeset_ctl(struct drm_device
*dev
, void *data
,
1054 struct drm_file
*file_priv
);
1056 /* AGP/GART support (drm_agpsupport.h) */
1057 extern struct drm_agp_head
*drm_agp_init(struct drm_device
*dev
);
1058 extern int drm_agp_acquire(struct drm_device
*dev
);
1059 extern int drm_agp_acquire_ioctl(struct drm_device
*dev
, void *data
,
1060 struct drm_file
*file_priv
);
1061 extern int drm_agp_release(struct drm_device
*dev
);
1062 extern int drm_agp_release_ioctl(struct drm_device
*dev
, void *data
,
1063 struct drm_file
*file_priv
);
1064 extern int drm_agp_enable(struct drm_device
*dev
, struct drm_agp_mode mode
);
1065 extern int drm_agp_enable_ioctl(struct drm_device
*dev
, void *data
,
1066 struct drm_file
*file_priv
);
1067 extern int drm_agp_info(struct drm_device
*dev
, struct drm_agp_info
*info
);
1068 extern int drm_agp_info_ioctl(struct drm_device
*dev
, void *data
,
1069 struct drm_file
*file_priv
);
1070 extern int drm_agp_alloc(struct drm_device
*dev
, struct drm_agp_buffer
*request
);
1071 extern int drm_agp_alloc_ioctl(struct drm_device
*dev
, void *data
,
1072 struct drm_file
*file_priv
);
1073 extern int drm_agp_free(struct drm_device
*dev
, struct drm_agp_buffer
*request
);
1074 extern int drm_agp_free_ioctl(struct drm_device
*dev
, void *data
,
1075 struct drm_file
*file_priv
);
1076 extern int drm_agp_unbind(struct drm_device
*dev
, struct drm_agp_binding
*request
);
1077 extern int drm_agp_unbind_ioctl(struct drm_device
*dev
, void *data
,
1078 struct drm_file
*file_priv
);
1079 extern int drm_agp_bind(struct drm_device
*dev
, struct drm_agp_binding
*request
);
1080 extern int drm_agp_bind_ioctl(struct drm_device
*dev
, void *data
,
1081 struct drm_file
*file_priv
);
1082 extern DRM_AGP_MEM
*drm_agp_allocate_memory(struct agp_bridge_data
*bridge
, size_t pages
, u32 type
);
1083 extern int drm_agp_free_memory(DRM_AGP_MEM
* handle
);
1084 extern int drm_agp_bind_memory(DRM_AGP_MEM
* handle
, off_t start
);
1085 extern int drm_agp_unbind_memory(DRM_AGP_MEM
* handle
);
1087 /* Stub support (drm_stub.h) */
1088 extern int drm_get_dev(struct pci_dev
*pdev
, const struct pci_device_id
*ent
,
1089 struct drm_driver
*driver
);
1090 extern int drm_put_dev(struct drm_device
*dev
);
1091 extern int drm_put_minor(struct drm_minor
**minor
);
1092 extern unsigned int drm_debug
;
1094 extern struct class *drm_class
;
1095 extern struct proc_dir_entry
*drm_proc_root
;
1097 extern struct idr drm_minors_idr
;
1099 extern drm_local_map_t
*drm_getsarea(struct drm_device
*dev
);
1101 /* Proc support (drm_proc.h) */
1102 extern int drm_proc_init(struct drm_minor
*minor
, int minor_id
,
1103 struct proc_dir_entry
*root
);
1104 extern int drm_proc_cleanup(struct drm_minor
*minor
, struct proc_dir_entry
*root
);
1106 /* Scatter Gather Support (drm_scatter.h) */
1107 extern void drm_sg_cleanup(struct drm_sg_mem
* entry
);
1108 extern int drm_sg_alloc_ioctl(struct drm_device
*dev
, void *data
,
1109 struct drm_file
*file_priv
);
1110 extern int drm_sg_alloc(struct drm_device
*dev
, struct drm_scatter_gather
* request
);
1111 extern int drm_sg_free(struct drm_device
*dev
, void *data
,
1112 struct drm_file
*file_priv
);
1114 /* ATI PCIGART support (ati_pcigart.h) */
1115 extern int drm_ati_pcigart_init(struct drm_device
*dev
,
1116 struct drm_ati_pcigart_info
* gart_info
);
1117 extern int drm_ati_pcigart_cleanup(struct drm_device
*dev
,
1118 struct drm_ati_pcigart_info
* gart_info
);
1120 extern drm_dma_handle_t
*drm_pci_alloc(struct drm_device
*dev
, size_t size
,
1121 size_t align
, dma_addr_t maxaddr
);
1122 extern void __drm_pci_free(struct drm_device
*dev
, drm_dma_handle_t
* dmah
);
1123 extern void drm_pci_free(struct drm_device
*dev
, drm_dma_handle_t
* dmah
);
1125 /* sysfs support (drm_sysfs.c) */
1126 struct drm_sysfs_class
;
1127 extern struct class *drm_sysfs_create(struct module
*owner
, char *name
);
1128 extern void drm_sysfs_destroy(void);
1129 extern int drm_sysfs_device_add(struct drm_minor
*minor
);
1130 extern void drm_sysfs_device_remove(struct drm_minor
*minor
);
1133 * Basic memory manager support (drm_mm.c)
1135 extern struct drm_mm_node
*drm_mm_get_block(struct drm_mm_node
* parent
,
1137 unsigned alignment
);
1138 extern void drm_mm_put_block(struct drm_mm_node
* cur
);
1139 extern struct drm_mm_node
*drm_mm_search_free(const struct drm_mm
*mm
, unsigned long size
,
1140 unsigned alignment
, int best_match
);
1141 extern int drm_mm_init(struct drm_mm
*mm
, unsigned long start
, unsigned long size
);
1142 extern void drm_mm_takedown(struct drm_mm
*mm
);
1143 extern int drm_mm_clean(struct drm_mm
*mm
);
1144 extern unsigned long drm_mm_tail_space(struct drm_mm
*mm
);
1145 extern int drm_mm_remove_space_from_tail(struct drm_mm
*mm
, unsigned long size
);
1146 extern int drm_mm_add_space_to_tail(struct drm_mm
*mm
, unsigned long size
);
1148 extern void drm_core_ioremap(struct drm_map
*map
, struct drm_device
*dev
);
1149 extern void drm_core_ioremapfree(struct drm_map
*map
, struct drm_device
*dev
);
1151 static __inline__
struct drm_map
*drm_core_findmap(struct drm_device
*dev
,
1154 struct drm_map_list
*_entry
;
1155 list_for_each_entry(_entry
, &dev
->maplist
, head
)
1156 if (_entry
->user_token
== token
)
1161 static __inline__
int drm_device_is_agp(struct drm_device
*dev
)
1163 if (dev
->driver
->device_is_agp
!= NULL
) {
1164 int err
= (*dev
->driver
->device_is_agp
) (dev
);
1171 return pci_find_capability(dev
->pdev
, PCI_CAP_ID_AGP
);
1174 static __inline__
int drm_device_is_pcie(struct drm_device
*dev
)
1176 return pci_find_capability(dev
->pdev
, PCI_CAP_ID_EXP
);
1179 static __inline__
void drm_core_dropmap(struct drm_map
*map
)
1183 #ifndef DEBUG_MEMORY
1184 /** Wrapper around kmalloc() */
1185 static __inline__
void *drm_alloc(size_t size
, int area
)
1187 return kmalloc(size
, GFP_KERNEL
);
1190 /** Wrapper around kfree() */
1191 static __inline__
void drm_free(void *pt
, size_t size
, int area
)
1196 /** Wrapper around kcalloc() */
1197 static __inline__
void *drm_calloc(size_t nmemb
, size_t size
, int area
)
1199 return kcalloc(nmemb
, size
, GFP_KERNEL
);
1202 extern void *drm_alloc(size_t size
, int area
);
1203 extern void drm_free(void *pt
, size_t size
, int area
);
1204 extern void *drm_calloc(size_t nmemb
, size_t size
, int area
);
1209 #endif /* __KERNEL__ */