Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /** |
| 2 | * \file drm_os_linux.h |
| 3 | * OS abstraction macros. |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/interrupt.h> /* For task queue support */ |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 7 | #include <linux/sched/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/delay.h> |
| 9 | |
Dave Airlie | 87f0da5 | 2009-02-26 10:12:10 +1000 | [diff] [blame] | 10 | #ifndef readq |
Dave Airlie | 522b5cc | 2009-03-31 15:14:39 +1100 | [diff] [blame] | 11 | static inline u64 readq(void __iomem *reg) |
Dave Airlie | 87f0da5 | 2009-02-26 10:12:10 +1000 | [diff] [blame] | 12 | { |
| 13 | return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32); |
| 14 | } |
| 15 | |
Dave Airlie | 522b5cc | 2009-03-31 15:14:39 +1100 | [diff] [blame] | 16 | static inline void writeq(u64 val, void __iomem *reg) |
Dave Airlie | 87f0da5 | 2009-02-26 10:12:10 +1000 | [diff] [blame] | 17 | { |
| 18 | writel(val & 0xffffffff, reg); |
| 19 | writel(val >> 32, reg + 0x4UL); |
| 20 | } |
| 21 | #endif |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /** Current process ID */ |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 24 | #define DRM_CURRENTPID task_pid_nr(current) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)) |
Dave Airlie | 87f0da5 | 2009-02-26 10:12:10 +1000 | [diff] [blame] | 38 | |
| 39 | /** Read a qword from a MMIO region - be careful using these unless you really understand them */ |
| 40 | #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset)) |
| 41 | /** Write a qword into a MMIO region */ |
| 42 | #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset)) |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ |
| 45 | do { \ |
| 46 | DECLARE_WAITQUEUE(entry, current); \ |
| 47 | unsigned long end = jiffies + (timeout); \ |
| 48 | add_wait_queue(&(queue), &entry); \ |
| 49 | \ |
| 50 | for (;;) { \ |
| 51 | __set_current_state(TASK_INTERRUPTIBLE); \ |
| 52 | if (condition) \ |
| 53 | break; \ |
| 54 | if (time_after_eq(jiffies, end)) { \ |
| 55 | ret = -EBUSY; \ |
| 56 | break; \ |
| 57 | } \ |
| 58 | schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \ |
| 59 | if (signal_pending(current)) { \ |
| 60 | ret = -EINTR; \ |
| 61 | break; \ |
| 62 | } \ |
| 63 | } \ |
| 64 | __set_current_state(TASK_RUNNING); \ |
| 65 | remove_wait_queue(&(queue), &entry); \ |
| 66 | } while (0) |