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