Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /** |
| 3 | * \file drm_os_linux.h |
| 4 | * OS abstraction macros. |
| 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/interrupt.h> /* For task queue support */ |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 8 | #include <linux/sched/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/delay.h> |
Corentin Labbe | 71ae3df | 2017-06-02 13:25:10 +0200 | [diff] [blame] | 10 | #include <linux/io-64-nonatomic-lo-hi.h> |
Dave Airlie | 87f0da5 | 2009-02-26 10:12:10 +1000 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | /** Current process ID */ |
Pavel Emelyanov | ba25f9d | 2007-10-18 23:40:40 -0700 | [diff] [blame] | 13 | #define DRM_CURRENTPID task_pid_nr(current) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)) |
Dave Airlie | 87f0da5 | 2009-02-26 10:12:10 +1000 | [diff] [blame] | 27 | |
| 28 | /** Read a qword from a MMIO region - be careful using these unless you really understand them */ |
| 29 | #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset)) |
| 30 | /** Write a qword into a MMIO region */ |
| 31 | #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset)) |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ |
| 34 | do { \ |
| 35 | DECLARE_WAITQUEUE(entry, current); \ |
| 36 | unsigned long end = jiffies + (timeout); \ |
| 37 | add_wait_queue(&(queue), &entry); \ |
| 38 | \ |
| 39 | for (;;) { \ |
| 40 | __set_current_state(TASK_INTERRUPTIBLE); \ |
| 41 | if (condition) \ |
| 42 | break; \ |
| 43 | if (time_after_eq(jiffies, end)) { \ |
| 44 | ret = -EBUSY; \ |
| 45 | break; \ |
| 46 | } \ |
| 47 | schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \ |
| 48 | if (signal_pending(current)) { \ |
| 49 | ret = -EINTR; \ |
| 50 | break; \ |
| 51 | } \ |
| 52 | } \ |
| 53 | __set_current_state(TASK_RUNNING); \ |
| 54 | remove_wait_queue(&(queue), &entry); \ |
| 55 | } while (0) |