blob: 10122353b74482da3bcccb654ca00fc7dc006632 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * \file drm_os_linux.h
3 * OS abstraction macros.
4 */
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/interrupt.h> /* For task queue support */
Ingo Molnar174cd4b2017-02-02 19:15:33 +01007#include <linux/sched/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/delay.h>
Corentin Labbe71ae3df2017-06-02 13:25:10 +02009#include <linux/io-64-nonatomic-lo-hi.h>
Dave Airlie87f0da52009-02-26 10:12:10 +100010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011/** Current process ID */
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -070012#define DRM_CURRENTPID task_pid_nr(current)
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#define DRM_UDELAY(d) udelay(d)
14/** Read a byte from a MMIO region */
15#define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
16/** Read a word from a MMIO region */
17#define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
18/** Read a dword from a MMIO region */
19#define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
20/** Write a byte into a MMIO region */
21#define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
22/** Write a word into a MMIO region */
23#define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
24/** Write a dword into a MMIO region */
25#define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
Dave Airlie87f0da52009-02-26 10:12:10 +100026
27/** Read a qword from a MMIO region - be careful using these unless you really understand them */
28#define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset))
29/** Write a qword into a MMIO region */
30#define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset))
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define DRM_WAIT_ON( ret, queue, timeout, condition ) \
33do { \
34 DECLARE_WAITQUEUE(entry, current); \
35 unsigned long end = jiffies + (timeout); \
36 add_wait_queue(&(queue), &entry); \
37 \
38 for (;;) { \
39 __set_current_state(TASK_INTERRUPTIBLE); \
40 if (condition) \
41 break; \
42 if (time_after_eq(jiffies, end)) { \
43 ret = -EBUSY; \
44 break; \
45 } \
46 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
47 if (signal_pending(current)) { \
48 ret = -EINTR; \
49 break; \
50 } \
51 } \
52 __set_current_state(TASK_RUNNING); \
53 remove_wait_queue(&(queue), &entry); \
54} while (0)