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 10 /* Handle the DRM options from kernel config. */ 11 #ifdef __DragonFly__ 12 #include "opt_drm.h" 13 #ifdef DRM_DEBUG 14 # if DRM_DEBUG>1 15 # define DRM_DEBUG_DEFAULT_ON 2 16 # else 17 # define DRM_DEBUG_DEFAULT_ON 1 18 # endif 19 #undef DRM_DEBUG 20 #else /* !DRM_DEBUG */ 21 # define DRM_DEBUG_DEFAULT_ON 0 22 #endif /* DRM_DEBUG */ 23 #endif /* __DragonFly__ */ 24 25 #ifndef readq 26 static inline u64 readq(void __iomem *reg) 27 { 28 return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32); 29 } 30 31 static inline void writeq(u64 val, void __iomem *reg) 32 { 33 writel(val & 0xffffffff, reg); 34 writel(val >> 32, reg + 0x4UL); 35 } 36 #endif 37 38 /** Current process ID */ 39 #define DRM_CURRENTPID (curproc != NULL ? curproc->p_pid : -1) 40 #define DRM_UDELAY(d) DELAY(d) 41 /** Read a byte from a MMIO region */ 42 #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset)) 43 /** Read a word from a MMIO region */ 44 #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset)) 45 /** Read a dword from a MMIO region */ 46 #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset)) 47 /** Write a byte into a MMIO region */ 48 #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset)) 49 /** Write a word into a MMIO region */ 50 #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset)) 51 /** Write a dword into a MMIO region */ 52 #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset)) 53 54 /** Read a qword from a MMIO region - be careful using these unless you really understand them */ 55 #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset)) 56 /** Write a qword into a MMIO region */ 57 #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset)) 58 59 #define DRM_WAIT_ON( ret, queue, timeout, condition ) \ 60 do { \ 61 wait_queue_t entry = { \ 62 .private = current, \ 63 .func = default_wake_function, \ 64 }; \ 65 unsigned long end = jiffies + (timeout); \ 66 add_wait_queue(&(queue), &entry); \ 67 \ 68 for (;;) { \ 69 __set_current_state(TASK_INTERRUPTIBLE); \ 70 if (condition) \ 71 break; \ 72 if (time_after_eq(jiffies, end)) { \ 73 ret = -EBUSY; \ 74 break; \ 75 } \ 76 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \ 77 if (signal_pending(current)) { \ 78 ret = -EINTR; \ 79 break; \ 80 } \ 81 } \ 82 __set_current_state(TASK_RUNNING); \ 83 remove_wait_queue(&(queue), &entry); \ 84 } while (0) 85