3 * OS abstraction macros.
7 #include <linux/interrupt.h> /* For task queue support */
8 #include <linux/delay.h>
10 /** File pointer type */
11 #define DRMFILE struct file *
12 /** Ioctl arguments */
13 #define DRM_IOCTL_ARGS struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data
14 #define DRM_ERR(d) -(d)
15 /** Current process ID */
16 #define DRM_CURRENTPID current->pid
17 #define DRM_UDELAY(d) udelay(d)
18 /** Read a byte from a MMIO region */
19 #define DRM_READ8(map, offset) readb(((unsigned long)(map)->handle) + (offset))
20 /** Read a dword from a MMIO region */
21 #define DRM_READ32(map, offset) readl(((unsigned long)(map)->handle) + (offset))
22 /** Write a byte into a MMIO region */
23 #define DRM_WRITE8(map, offset, val) writeb(val, ((unsigned long)(map)->handle) + (offset))
24 /** Write a dword into a MMIO region */
25 #define DRM_WRITE32(map, offset, val) writel(val, ((unsigned long)(map)->handle) + (offset))
26 /** Read memory barrier */
27 #define DRM_READMEMORYBARRIER() rmb()
28 /** Write memory barrier */
29 #define DRM_WRITEMEMORYBARRIER() wmb()
30 /** Read/write memory barrier */
31 #define DRM_MEMORYBARRIER() mb()
32 /** DRM device local declaration */
33 #define DRM_DEVICE drm_file_t *priv = filp->private_data; \
34 drm_device_t *dev = priv->dev
36 /** IRQ handler arguments and return type and values */
37 #define DRM_IRQ_ARGS int irq, void *arg, struct pt_regs *regs
40 #define DRM_AGP_MEM struct agp_memory
41 #define DRM_AGP_KERN struct agp_kern_info
43 /** Task queue handler arguments */
44 #define DRM_TASKQUEUE_ARGS void *arg
46 /** For data going into the kernel through the ioctl argument */
47 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
48 if ( copy_from_user(&arg1, arg2, arg3) ) \
50 /** For data going from the kernel through the ioctl argument */
51 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
52 if ( copy_to_user(arg1, &arg2, arg3) ) \
54 /** Other copying of data to kernel space */
55 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
56 copy_from_user(arg1, arg2, arg3)
57 /** Other copying of data from kernel space */
58 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
59 copy_to_user(arg1, arg2, arg3)
60 /* Macros for copyfrom user, but checking readability only once */
61 #define DRM_VERIFYAREA_READ( uaddr, size ) \
62 verify_area( VERIFY_READ, uaddr, size )
63 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
64 __copy_from_user(arg1, arg2, arg3)
65 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
66 __get_user(val, uaddr)
69 /** 'malloc' without the overhead of DRM(alloc)() */
70 #define DRM_MALLOC(x) kmalloc(x, GFP_KERNEL)
71 /** 'free' without the overhead of DRM(free)() */
72 #define DRM_FREE(x,size) kfree(x)
75 * Get the pointer to the SAREA.
77 * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
79 #define DRM_GETSAREA() \
81 drm_map_list_t *entry; \
82 list_for_each_entry( entry, &dev->maplist->head, head ) { \
84 entry->map->type == _DRM_SHM && \
85 (entry->map->flags & _DRM_CONTAINS_LOCK) ) { \
86 dev_priv->sarea = entry->map; \
94 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
96 DECLARE_WAITQUEUE(entry, current); \
97 unsigned long end = jiffies + (timeout); \
98 add_wait_queue(&(queue), &entry); \
101 current->state = TASK_INTERRUPTIBLE; \
104 if (time_after_eq(jiffies, end)) { \
108 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
109 if (signal_pending(current)) { \
114 current->state = TASK_RUNNING; \
115 remove_wait_queue(&(queue), &entry); \
119 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
120 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )