xref: /dragonfly/sys/dev/drm/include/drm/drm_os_linux.h (revision d9d67b59)
1 /**
2  * \file drm_os_dragonfly.h
3  * OS abstraction macros.
4  */
5 
6 #include <sys/param.h>
7 #include <sys/endian.h>
8 #include <sys/systm.h>
9 #include <sys/serialize.h>
10 #include <linux/interrupt.h>	/* For task queue support */
11 #include <linux/delay.h>
12 
13 /* Handle the DRM options from kernel config. */
14 #ifdef __DragonFly__
15 #include "opt_drm.h"
16 #ifdef DRM_DEBUG
17 #  if DRM_DEBUG>1
18 #    define DRM_DEBUG_DEFAULT_ON 2
19 #  else
20 #    define DRM_DEBUG_DEFAULT_ON 1
21 #  endif
22 #undef DRM_DEBUG
23 #endif /* DRM_DEBUG */
24 #endif /* DragonFly */
25 
26 #ifndef readq
27 static inline u64 readq(void __iomem *reg)
28 {
29 	return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32);
30 }
31 
32 static inline void writeq(u64 val, void __iomem *reg)
33 {
34 	writel(val & 0xffffffff, reg);
35 	writel(val >> 32, reg + 0x4UL);
36 }
37 #endif
38 
39 /** Current process ID */
40 #define DRM_CURRENTPID			(curproc != NULL ? curproc->p_pid : -1)
41 #define DRM_UDELAY(d)			DELAY(d)
42 /** Read a byte from a MMIO region */
43 #define DRM_READ8(map, offset)		readb(((void __iomem *)(map)->handle) + (offset))
44 /** Read a word from a MMIO region */
45 #define DRM_READ16(map, offset)         readw(((void __iomem *)(map)->handle) + (offset))
46 /** Read a dword from a MMIO region */
47 #define DRM_READ32(map, offset)		readl(((void __iomem *)(map)->handle) + (offset))
48 /** Write a byte into a MMIO region */
49 #define DRM_WRITE8(map, offset, val)	writeb(val, ((void __iomem *)(map)->handle) + (offset))
50 /** Write a word into a MMIO region */
51 #define DRM_WRITE16(map, offset, val)   writew(val, ((void __iomem *)(map)->handle) + (offset))
52 /** Write a dword into a MMIO region */
53 #define DRM_WRITE32(map, offset, val)					\
54 	*(volatile u_int32_t *)(((vm_offset_t)(map)->handle) +		\
55 	    (vm_offset_t)(offset)) = htole32(val)
56 
57 /** Read a qword from a MMIO region - be careful using these unless you really understand them */
58 #define DRM_READ64(map, offset)		readq(((void __iomem *)(map)->handle) + (offset))
59 /** Write a qword into a MMIO region */
60 #define DRM_WRITE64(map, offset, val)	writeq(val, ((void __iomem *)(map)->handle) + (offset))
61 
62 #define DRM_WAIT_ON( ret, queue, timeout, condition )		\
63 for ( ret = 0 ; !ret && !(condition) ; ) {			\
64 	lwkt_serialize_enter(&dev->irq_lock);			\
65 	if (!(condition)) {					\
66 		tsleep_interlock(&(queue), PCATCH);		\
67 		lwkt_serialize_exit(&dev->irq_lock);		\
68 		ret = -tsleep(&(queue), PCATCH | PINTERLOCKED,	\
69 			  "drmwtq", (timeout));			\
70 	} else {						\
71 		lwkt_serialize_exit(&dev->irq_lock);		\
72 	}							\
73 }
74 
75 /* include code to override EDID blocks from external firmware modules */
76 #define CONFIG_DRM_LOAD_EDID_FIRMWARE
77