3 * OS abstraction macros.
6 #include <linux/interrupt.h> /* For task queue support */
7 #include <linux/delay.h>
9 /** File pointer type */
10 #define DRMFILE struct file *
11 /** Ioctl arguments */
12 #define DRM_IOCTL_ARGS struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data
13 /** Current process ID */
14 #define DRM_CURRENTPID current->pid
15 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
16 #define DRM_UDELAY(d) udelay(d)
17 /** Read a byte from a MMIO region */
18 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
19 /** Read a word from a MMIO region */
20 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
21 /** Read a dword from a MMIO region */
22 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
23 /** Write a byte into a MMIO region */
24 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
25 /** Write a word into a MMIO region */
26 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
27 /** Write a dword into a MMIO region */
28 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
29 /** Read memory barrier */
30 #define DRM_READMEMORYBARRIER() rmb()
31 /** Write memory barrier */
32 #define DRM_WRITEMEMORYBARRIER() wmb()
33 /** Read/write memory barrier */
34 #define DRM_MEMORYBARRIER() mb()
35 /** DRM device local declaration */
36 #define DRM_DEVICE struct drm_file *priv = filp->private_data; \
37 struct drm_device *dev = priv->head->dev
39 /** IRQ handler arguments and return type and values */
40 #define DRM_IRQ_ARGS int irq, void *arg
44 #define DRM_AGP_MEM struct agp_memory
45 #define DRM_AGP_KERN struct agp_kern_info
47 /* define some dummy types for non AGP supporting kernels */
49 unsigned long aper_base;
50 unsigned long aper_size;
52 #define DRM_AGP_MEM int
53 #define DRM_AGP_KERN struct no_agp_kern
57 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
58 unsigned int type, char increment)
63 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
68 #define MTRR_TYPE_WRCOMB 1
72 /** For data going into the kernel through the ioctl argument */
73 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
74 if ( copy_from_user(&arg1, arg2, arg3) ) \
76 /** For data going from the kernel through the ioctl argument */
77 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
78 if ( copy_to_user(arg1, &arg2, arg3) ) \
80 /** Other copying of data to kernel space */
81 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
82 copy_from_user(arg1, arg2, arg3)
83 /** Other copying of data from kernel space */
84 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
85 copy_to_user(arg1, arg2, arg3)
86 /* Macros for copyfrom user, but checking readability only once */
87 #define DRM_VERIFYAREA_READ( uaddr, size ) \
88 (access_ok( VERIFY_READ, uaddr, size ) ? 0 : -EFAULT)
89 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
90 __copy_from_user(arg1, arg2, arg3)
91 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
92 __copy_to_user(arg1, arg2, arg3)
93 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
94 __get_user(val, uaddr)
96 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
100 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
102 DECLARE_WAITQUEUE(entry, current); \
103 unsigned long end = jiffies + (timeout); \
104 add_wait_queue(&(queue), &entry); \
107 __set_current_state(TASK_INTERRUPTIBLE); \
110 if (time_after_eq(jiffies, end)) { \
114 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
115 if (signal_pending(current)) { \
120 __set_current_state(TASK_RUNNING); \
121 remove_wait_queue(&(queue), &entry); \
124 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
125 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )