3 * OS abstraction macros.
6 #include <linux/interrupt.h> /* For task queue support */
7 #include <linux/delay.h>
10 static inline u64 readq(void __iomem *reg)
12 return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32);
15 static inline void writeq(u64 val, void __iomem *reg)
17 writel(val & 0xffffffff, reg);
18 writel(val >> 32, reg + 0x4UL);
22 /** Current process ID */
23 #define DRM_CURRENTPID task_pid_nr(current)
24 #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
25 #define DRM_UDELAY(d) udelay(d)
26 /** Read a byte from a MMIO region */
27 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
28 /** Read a word from a MMIO region */
29 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
30 /** Read a dword from a MMIO region */
31 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
32 /** Write a byte into a MMIO region */
33 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
34 /** Write a word into a MMIO region */
35 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
36 /** Write a dword into a MMIO region */
37 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
38 /** Read memory barrier */
40 /** Read a qword from a MMIO region - be careful using these unless you really understand them */
41 #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset))
42 /** Write a qword into a MMIO region */
43 #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset))
45 #define DRM_READMEMORYBARRIER() rmb()
46 /** Write memory barrier */
47 #define DRM_WRITEMEMORYBARRIER() wmb()
48 /** Read/write memory barrier */
49 #define DRM_MEMORYBARRIER() mb()
51 /** IRQ handler arguments and return type and values */
52 #define DRM_IRQ_ARGS int irq, void *arg
54 /** Other copying of data to kernel space */
55 #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
56 copy_from_user(arg1, arg2, arg3)
57 /** Other copying of data from kernel space */
58 #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
59 copy_to_user(arg1, arg2, arg3)
63 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
65 DECLARE_WAITQUEUE(entry, current); \
66 unsigned long end = jiffies + (timeout); \
67 add_wait_queue(&(queue), &entry); \
70 __set_current_state(TASK_INTERRUPTIBLE); \
73 if (time_after_eq(jiffies, end)) { \
77 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
78 if (signal_pending(current)) { \
83 __set_current_state(TASK_RUNNING); \
84 remove_wait_queue(&(queue), &entry); \
87 #define DRM_WAKEUP( queue ) wake_up( queue )
88 #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )