3 * OS abstraction macros.
6 #include <linux/interrupt.h> /* For task queue support */
7 #include <linux/delay.h>
10 #define DRM_IOCTL_ARGS struct inode *inode, struct drm_file *file_priv, unsigned int cmd, unsigned long data
11 /** Current process ID */
12 #define DRM_CURRENTPID current->pid
13 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
14 #define DRM_UDELAY(d) udelay(d)
15 #if LINUX_VERSION_CODE <= 0x020608 /* KERNEL_VERSION(2,6,8) */
19 /** Read a byte from a MMIO region */
20 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
21 /** Read a word from a MMIO region */
22 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
23 /** Read a dword from a MMIO region */
24 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
25 /** Write a byte into a MMIO region */
26 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
27 /** Write a word into a MMIO region */
28 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
29 /** Write a dword into a MMIO region */
30 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
32 /** Read a byte from a MMIO region */
33 #define DRM_READ8(map, offset) readb((map)->handle + (offset))
34 /** Read a word from a MMIO region */
35 #define DRM_READ16(map, offset) readw((map)->handle + (offset))
36 /** Read a dword from a MMIO region */
37 #define DRM_READ32(map, offset) readl((map)->handle + (offset))
38 /** Write a byte into a MMIO region */
39 #define DRM_WRITE8(map, offset, val) writeb(val, (map)->handle + (offset))
40 /** Write a word into a MMIO region */
41 #define DRM_WRITE16(map, offset, val) writew(val, (map)->handle + (offset))
42 /** Write a dword into a MMIO region */
43 #define DRM_WRITE32(map, offset, val) writel(val, (map)->handle + (offset))
45 /** Read memory barrier */
46 #define DRM_READMEMORYBARRIER() rmb()
47 /** Write memory barrier */
48 #define DRM_WRITEMEMORYBARRIER() wmb()
49 /** Read/write memory barrier */
50 #define DRM_MEMORYBARRIER() mb()
51 /** DRM device local declaration */
52 #define DRM_DEVICE struct drm_device *dev = file_priv->head->dev
54 /** IRQ handler arguments and return type and values */
55 #define DRM_IRQ_ARGS int irq, void *arg
56 /** backwards compatibility with old irq return values */
58 typedef void irqreturn_t;
59 #define IRQ_HANDLED /* nothing */
60 #define IRQ_NONE /* nothing */
65 #define DRM_AGP_MEM struct agp_memory
66 #define DRM_AGP_KERN struct agp_kern_info
68 /* define some dummy types for non AGP supporting kernels */
70 unsigned long aper_base;
71 unsigned long aper_size;
73 #define DRM_AGP_MEM int
74 #define DRM_AGP_KERN struct no_agp_kern
78 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
79 unsigned int type, char increment)
84 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
89 #define MTRR_TYPE_WRCOMB 1
92 /** For data going into the kernel through the ioctl argument */
93 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
94 if ( copy_from_user(&arg1, arg2, arg3) ) \
96 /** For data going from the kernel through the ioctl argument */
97 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
98 if ( copy_to_user(arg1, &arg2, arg3) ) \
100 /** Other copying of data to kernel space */
101 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
102 copy_from_user(arg1, arg2, arg3)
103 /** Other copying of data from kernel space */
104 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
105 copy_to_user(arg1, arg2, arg3)
106 /* Macros for copyfrom user, but checking readability only once */
107 #define DRM_VERIFYAREA_READ( uaddr, size ) \
108 (access_ok( VERIFY_READ, uaddr, size) ? 0 : -EFAULT)
109 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
110 __copy_from_user(arg1, arg2, arg3)
111 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
112 __copy_to_user(arg1, arg2, arg3)
113 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
114 __get_user(val, uaddr)
118 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
120 DECLARE_WAITQUEUE(entry, current); \
121 unsigned long end = jiffies + (timeout); \
122 add_wait_queue(&(queue), &entry); \
125 __set_current_state(TASK_INTERRUPTIBLE); \
128 if (time_after_eq(jiffies, end)) { \
132 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
133 if (signal_pending(current)) { \
138 __set_current_state(TASK_RUNNING); \
139 remove_wait_queue(&(queue), &entry); \
142 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
143 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )