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 #define DRM_ERR(d) -(d)
14 /** Current process ID */
15 #define DRM_CURRENTPID current->pid
16 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
17 #define DRM_UDELAY(d) udelay(d)
18 #if LINUX_VERSION_CODE <= 0x020608 /* KERNEL_VERSION(2,6,8) */
22 /** Read a byte from a MMIO region */
23 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
24 /** Read a word from a MMIO region */
25 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
26 /** Read a dword from a MMIO region */
27 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
28 /** Write a byte into a MMIO region */
29 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
30 /** Write a word into a MMIO region */
31 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
32 /** Write a dword into a MMIO region */
33 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
35 /** Read a byte from a MMIO region */
36 #define DRM_READ8(map, offset) readb((map)->handle + (offset))
37 /** Read a word from a MMIO region */
38 #define DRM_READ16(map, offset) readw((map)->handle + (offset))
39 /** Read a dword from a MMIO region */
40 #define DRM_READ32(map, offset) readl((map)->handle + (offset))
41 /** Write a byte into a MMIO region */
42 #define DRM_WRITE8(map, offset, val) writeb(val, (map)->handle + (offset))
43 /** Write a word into a MMIO region */
44 #define DRM_WRITE16(map, offset, val) writew(val, (map)->handle + (offset))
45 /** Write a dword into a MMIO region */
46 #define DRM_WRITE32(map, offset, val) writel(val, (map)->handle + (offset))
48 /** Read memory barrier */
49 #define DRM_READMEMORYBARRIER() rmb()
50 /** Write memory barrier */
51 #define DRM_WRITEMEMORYBARRIER() wmb()
52 /** Read/write memory barrier */
53 #define DRM_MEMORYBARRIER() mb()
54 /** DRM device local declaration */
55 #define DRM_DEVICE drm_file_t *priv = filp->private_data; \
56 drm_device_t *dev = priv->head->dev
58 /** IRQ handler arguments and return type and values */
59 #define DRM_IRQ_ARGS int irq, void *arg
60 /** backwards compatibility with old irq return values */
62 typedef void irqreturn_t;
63 #define IRQ_HANDLED /* nothing */
64 #define IRQ_NONE /* nothing */
69 #define DRM_AGP_MEM struct agp_memory
70 #define DRM_AGP_KERN struct agp_kern_info
72 /* define some dummy types for non AGP supporting kernels */
74 unsigned long aper_base;
75 unsigned long aper_size;
77 #define DRM_AGP_MEM int
78 #define DRM_AGP_KERN struct no_agp_kern
82 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
83 unsigned int type, char increment)
88 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
93 #define MTRR_TYPE_WRCOMB 1
96 /** For data going into the kernel through the ioctl argument */
97 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
98 if ( copy_from_user(&arg1, arg2, arg3) ) \
100 /** For data going from the kernel through the ioctl argument */
101 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
102 if ( copy_to_user(arg1, &arg2, arg3) ) \
104 /** Other copying of data to kernel space */
105 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
106 copy_from_user(arg1, arg2, arg3)
107 /** Other copying of data from kernel space */
108 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
109 copy_to_user(arg1, arg2, arg3)
110 /* Macros for copyfrom user, but checking readability only once */
111 #define DRM_VERIFYAREA_READ( uaddr, size ) \
112 (access_ok( VERIFY_READ, uaddr, size) ? 0 : -EFAULT)
113 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
114 __copy_from_user(arg1, arg2, arg3)
115 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
116 __copy_to_user(arg1, arg2, arg3)
117 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
118 __get_user(val, uaddr)
120 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
124 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
126 DECLARE_WAITQUEUE(entry, current); \
127 unsigned long end = jiffies + (timeout); \
128 add_wait_queue(&(queue), &entry); \
131 __set_current_state(TASK_INTERRUPTIBLE); \
134 if (time_after_eq(jiffies, end)) { \
138 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
139 if (signal_pending(current)) { \
144 __set_current_state(TASK_RUNNING); \
145 remove_wait_queue(&(queue), &entry); \
148 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
149 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )