2 * \file drm_os_freebsd.h
3 * OS abstraction macros.
5 * $FreeBSD: head/sys/dev/drm2/drm_os_freebsd.h 254858 2013-08-25 14:27:14Z dumbbell $
8 #define DRM_READ8(map, offset) \
9 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
10 (vm_offset_t)(offset))
11 #define DRM_READ16(map, offset) \
12 le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
13 (vm_offset_t)(offset)))
14 #define DRM_READ32(map, offset) \
15 le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
16 (vm_offset_t)(offset)))
17 #define DRM_READ64(map, offset) \
18 le64toh(*(volatile u_int64_t *)(((vm_offset_t)(map)->handle) + \
19 (vm_offset_t)(offset)))
20 #define DRM_WRITE8(map, offset, val) \
21 *(volatile u_int8_t *)(((vm_offset_t)(map)->handle) + \
22 (vm_offset_t)(offset)) = val
23 #define DRM_WRITE16(map, offset, val) \
24 *(volatile u_int16_t *)(((vm_offset_t)(map)->handle) + \
25 (vm_offset_t)(offset)) = htole16(val)
27 #define DRM_WRITE32(map, offset, val) \
28 *(volatile u_int32_t *)(((vm_offset_t)(map)->handle) + \
29 (vm_offset_t)(offset)) = htole32(val)
31 #define DRM_WRITE64(map, offset, val) \
32 *(volatile u_int64_t *)(((vm_offset_t)(map)->handle) + \
33 (vm_offset_t)(offset)) = htole64(val)
36 #if _BYTE_ORDER == _BIG_ENDIAN
37 #define __BIG_ENDIAN 4321
39 #define __LITTLE_ENDIAN 1234
43 #define BITS_PER_LONG 64
45 #define BITS_PER_LONG 32
48 #define cpu_to_le16(x) htole16(x)
49 #define le16_to_cpu(x) le16toh(x)
50 #define cpu_to_le32(x) htole32(x)
51 #define le32_to_cpu(x) le32toh(x)
53 #define cpu_to_be16(x) htobe16(x)
54 #define be16_to_cpu(x) be16toh(x)
55 #define cpu_to_be32(x) htobe32(x)
56 #define be32_to_cpu(x) be32toh(x)
57 #define be32_to_cpup(x) be32toh(*x)
59 #define unlikely(x) __builtin_expect(!!(x), 0)
60 #define likely(x) __builtin_expect(!!(x), 1)
63 #define DRM_UDELAY(udelay) DELAY(udelay)
64 #define DRM_MDELAY(msecs) do { int loops = (msecs); \
65 while (loops--) DELAY(1000); \
67 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
69 #define lower_32_bits(n) ((u32)(n))
71 #define memset_io(a, b, c) memset((a), (b), (c))
72 #define memcpy_fromio(a, b, c) memcpy((a), (b), (c))
73 #define memcpy_toio(a, b, c) memcpy((a), (b), (c))
75 /* XXXKIB what is the right code for the FreeBSD ? */
76 /* kib@ used ENXIO here -- dumbbell@ */
79 #define KTR_DRM KTR_DEV
80 #define KTR_DRM_REG KTR_SPARE3
82 #define hweight32(i) bitcount32(i)
85 * ror32 - rotate a 32-bit value right
86 * @word: value to rotate
87 * @shift: bits to roll
89 * Source: include/linux/bitops.h
91 static inline uint32_t ror32(uint32_t word, unsigned int shift)
93 return (word >> shift) | (word << (32 - shift));
96 #define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0)
97 #define get_unaligned(ptr) \
98 ({ __typeof__(*(ptr)) __tmp; \
99 memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
101 #if _BYTE_ORDER == _LITTLE_ENDIAN
102 /* Taken from linux/include/linux/unaligned/le_struct.h. */
103 struct __una_u32 { u32 x; } __packed;
105 static inline u32 __get_unaligned_cpu32(const void *p)
107 const struct __una_u32 *ptr = (const struct __una_u32 *)p;
111 static inline u32 get_unaligned_le32(const void *p)
113 return __get_unaligned_cpu32((const u8 *)p);
116 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */
117 static inline u32 __get_unaligned_le32(const u8 *p)
119 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
122 static inline u32 get_unaligned_le32(const void *p)
124 return __get_unaligned_le32((const u8 *)p);
128 #define KIB_NOTYET() \
130 if (drm_debug && drm_notyet_flag) \
131 kprintf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \