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, struct pt_regs *regs
60 /** backwards compatibility with old irq return values */
62 typedef void irqreturn_t;
63 #define IRQ_HANDLED /* nothing */
64 #define IRQ_NONE /* nothing */
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,70)
70 #define DRM_AGP_MEM agp_memory
71 #define DRM_AGP_KERN agp_kern_info
73 #define DRM_AGP_MEM struct agp_memory
74 #define DRM_AGP_KERN struct agp_kern_info
77 /* define some dummy types for non AGP supporting kernels */
79 unsigned long aper_base;
80 unsigned long aper_size;
82 #define DRM_AGP_MEM int
83 #define DRM_AGP_KERN struct no_agp_kern
87 static __inline__ int mtrr_add(unsigned long base, unsigned long size,
88 unsigned int type, char increment)
93 static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
98 #define MTRR_TYPE_WRCOMB 1
101 /** Task queue handler arguments */
102 #define DRM_TASKQUEUE_ARGS void *arg
104 /** For data going into the kernel through the ioctl argument */
105 #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
106 if ( copy_from_user(&arg1, arg2, arg3) ) \
108 /** For data going from the kernel through the ioctl argument */
109 #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
110 if ( copy_to_user(arg1, &arg2, arg3) ) \
112 /** Other copying of data to kernel space */
113 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
114 copy_from_user(arg1, arg2, arg3)
115 /** Other copying of data from kernel space */
116 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
117 copy_to_user(arg1, arg2, arg3)
118 /* Macros for copyfrom user, but checking readability only once */
119 #define DRM_VERIFYAREA_READ( uaddr, size ) \
120 (access_ok( VERIFY_READ, uaddr, size) ? 0 : -EFAULT)
121 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
122 __copy_from_user(arg1, arg2, arg3)
123 #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
124 __copy_to_user(arg1, arg2, arg3)
125 #define DRM_GET_USER_UNCHECKED(val, uaddr) \
126 __get_user(val, uaddr)
128 #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
131 * Get the pointer to the SAREA.
133 * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
135 #define DRM_GETSAREA() \
137 drm_map_list_t *entry; \
138 list_for_each_entry( entry, &dev->maplist->head, head ) { \
140 entry->map->type == _DRM_SHM && \
141 (entry->map->flags & _DRM_CONTAINS_LOCK) ) { \
142 dev_priv->sarea = entry->map; \
150 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
152 DECLARE_WAITQUEUE(entry, current); \
153 unsigned long end = jiffies + (timeout); \
154 add_wait_queue(&(queue), &entry); \
157 __set_current_state(TASK_INTERRUPTIBLE); \
160 if (time_after_eq(jiffies, end)) { \
164 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
165 if (signal_pending(current)) { \
170 __set_current_state(TASK_RUNNING); \
171 remove_wait_queue(&(queue), &entry); \
174 #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
175 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )