1 /** 2 * \file drm_os_linux.h 3 * OS abstraction macros. 4 */ 5 6 #include <linux/interrupt.h> /* For task queue support */ 7 #include <linux/sched/signal.h> 8 #include <linux/delay.h> 9 #include <linux/io-64-nonatomic-lo-hi.h> 10 11 /* Handle the DRM options from kernel config. */ 12 #ifdef __DragonFly__ 13 #include "opt_drm.h" 14 #ifdef DRM_DEBUG 15 # if DRM_DEBUG>1 16 # define DRM_DEBUG_DEFAULT_ON 2 17 # else 18 # define DRM_DEBUG_DEFAULT_ON 1 19 # endif 20 #undef DRM_DEBUG 21 #else /* !DRM_DEBUG */ 22 # define DRM_DEBUG_DEFAULT_ON 0 23 #endif /* DRM_DEBUG */ 24 #endif /* __DragonFly__ */ 25 26 /** Current process ID */ 27 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1) 28 #define DRM_UDELAY(d) DELAY(d) 29 /** Read a byte from a MMIO region */ 30 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset)) 31 /** Read a word from a MMIO region */ 32 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset)) 33 /** Read a dword from a MMIO region */ 34 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset)) 35 /** Write a byte into a MMIO region */ 36 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset)) 37 /** Write a word into a MMIO region */ 38 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset)) 39 /** Write a dword into a MMIO region */ 40 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset)) 41 42 /** Read a qword from a MMIO region - be careful using these unless you really understand them */ 43 #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset)) 44 /** Write a qword into a MMIO region */ 45 #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset)) 46 47 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 48 do { \ 49 wait_queue_entry_t entry = { \ 50 .private = current, \ 51 .func = default_wake_function, \ 52 }; \ 53 unsigned long end = jiffies + (timeout); \ 54 add_wait_queue(&(queue), &entry); \ 55 \ 56 for (;;) { \ 57 __set_current_state(TASK_INTERRUPTIBLE); \ 58 if (condition) \ 59 break; \ 60 if (time_after_eq(jiffies, end)) { \ 61 ret = -EBUSY; \ 62 break; \ 63 } \ 64 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \ 65 if (signal_pending(current)) { \ 66 ret = -EINTR; \ 67 break; \ 68 } \ 69 } \ 70 __set_current_state(TASK_RUNNING); \ 71 remove_wait_queue(&(queue), &entry); \ 72 } while (0) 73