3 * OS abstraction macros.
6 #include <linux/interrupt.h> /* For task queue support */
7 #include <linux/delay.h>
9 /** Current process ID */
10 #define DRM_CURRENTPID current->pid
11 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
12 #define DRM_UDELAY(d) udelay(d)
13 #if LINUX_VERSION_CODE <= 0x020608 /* KERNEL_VERSION(2,6,8) */
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))
30 /** Read a byte from a MMIO region */
31 #define DRM_READ8(map, offset) readb((map)->handle + (offset))
32 /** Read a word from a MMIO region */
33 #define DRM_READ16(map, offset) readw((map)->handle + (offset))
34 /** Read a dword from a MMIO region */
35 #define DRM_READ32(map, offset) readl((map)->handle + (offset))
36 /** Write a byte into a MMIO region */
37 #define DRM_WRITE8(map, offset, val) writeb(val, (map)->handle + (offset))
38 /** Write a word into a MMIO region */
39 #define DRM_WRITE16(map, offset, val) writew(val, (map)->handle + (offset))
40 /** Write a dword into a MMIO region */
41 #define DRM_WRITE32(map, offset, val) writel(val, (map)->handle + (offset))
43 /** Read memory barrier */
44 #define DRM_READMEMORYBARRIER() rmb()
45 /** Write memory barrier */
46 #define DRM_WRITEMEMORYBARRIER() wmb()
47 /** Read/write memory barrier */
48 #define DRM_MEMORYBARRIER() mb()
50 /** IRQ handler arguments and return type and values */
51 #define DRM_IRQ_ARGS int irq, void *arg
52 /** backwards compatibility with old irq return values */
54 typedef void irqreturn_t;
55 #define IRQ_HANDLED /* nothing */
56 #define IRQ_NONE /* nothing */
61 #define DRM_AGP_MEM struct agp_memory
62 #define DRM_AGP_KERN struct agp_kern_info
64 /* define some dummy types for non AGP supporting kernels */
66 unsigned long aper_base;
67 unsigned long aper_size;
69 #define DRM_AGP_MEM int
70 #define DRM_AGP_KERN struct no_agp_kern
74 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
75 unsigned int type, char increment)
80 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
85 #define MTRR_TYPE_WRCOMB 1
88 /** Other copying of data to kernel space */
89 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
90 copy_from_user(arg1, arg2, arg3)
91 /** Other copying of data from kernel space */
92 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
93 copy_to_user(arg1, arg2, arg3)
94 /* Macros for copyfrom user, but checking readability only once */
95 #define DRM_VERIFYAREA_READ( uaddr, size ) \
96 (access_ok( VERIFY_READ, uaddr, size) ? 0 : -EFAULT)
97 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
98 __copy_from_user(arg1, arg2, arg3)
99 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
100 __copy_to_user(arg1, arg2, arg3)
101 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
102 __get_user(val, uaddr)
106 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
108 DECLARE_WAITQUEUE(entry, current); \
109 unsigned long end = jiffies + (timeout); \
110 add_wait_queue(&(queue), &entry); \
113 __set_current_state(TASK_INTERRUPTIBLE); \
116 if (time_after_eq(jiffies, end)) { \
120 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
121 if (signal_pending(current)) { \
126 __set_current_state(TASK_RUNNING); \
127 remove_wait_queue(&(queue), &entry); \
130 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
131 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )