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 /** Read a byte from a MMIO region */
16 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
17 /** Read a word from a MMIO region */
18 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
19 /** Read a dword from a MMIO region */
20 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
21 /** Write a byte into a MMIO region */
22 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
23 /** Write a word into a MMIO region */
24 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
25 /** Write a dword into a MMIO region */
26 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
27 /** Read memory barrier */
28 #define DRM_READMEMORYBARRIER() rmb()
29 /** Write memory barrier */
30 #define DRM_WRITEMEMORYBARRIER() wmb()
31 /** Read/write memory barrier */
32 #define DRM_MEMORYBARRIER() mb()
33 /** DRM device local declaration */
34 #define DRM_DEVICE struct drm_device *dev = file_priv->head->dev
36 /** IRQ handler arguments and return type and values */
37 #define DRM_IRQ_ARGS int irq, void *arg
41 #define DRM_AGP_MEM struct agp_memory
42 #define DRM_AGP_KERN struct agp_kern_info
44 /* define some dummy types for non AGP supporting kernels */
46 unsigned long aper_base;
47 unsigned long aper_size;
49 #define DRM_AGP_MEM int
50 #define DRM_AGP_KERN struct no_agp_kern
54 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
55 unsigned int type, char increment)
60 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
65 #define MTRR_TYPE_WRCOMB 1
69 /** For data going into the kernel through the ioctl argument */
70 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
71 if ( copy_from_user(&arg1, arg2, arg3) ) \
73 /** For data going from the kernel through the ioctl argument */
74 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
75 if ( copy_to_user(arg1, &arg2, arg3) ) \
77 /** Other copying of data to kernel space */
78 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
79 copy_from_user(arg1, arg2, arg3)
80 /** Other copying of data from kernel space */
81 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
82 copy_to_user(arg1, arg2, arg3)
83 /* Macros for copyfrom user, but checking readability only once */
84 #define DRM_VERIFYAREA_READ( uaddr, size ) \
85 (access_ok( VERIFY_READ, uaddr, size ) ? 0 : -EFAULT)
86 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
87 __copy_from_user(arg1, arg2, arg3)
88 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
89 __copy_to_user(arg1, arg2, arg3)
90 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
91 __get_user(val, uaddr)
95 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
97 DECLARE_WAITQUEUE(entry, current); \
98 unsigned long end = jiffies + (timeout); \
99 add_wait_queue(&(queue), &entry); \
102 __set_current_state(TASK_INTERRUPTIBLE); \
105 if (time_after_eq(jiffies, end)) { \
109 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
110 if (signal_pending(current)) { \
115 __set_current_state(TASK_RUNNING); \
116 remove_wait_queue(&(queue), &entry); \
119 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
120 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )