1 /** 2 * \file drm_os_freebsd.h 3 * OS abstraction macros. 4 * 5 * $FreeBSD: head/sys/dev/drm2/drm_os_freebsd.h 254858 2013-08-25 14:27:14Z dumbbell $ 6 */ 7 8 #define DRM_READ8(map, offset) \ 9 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \ 10 (vm_offset_t)(offset)) 11 #define DRM_READ16(map, offset) \ 12 le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \ 13 (vm_offset_t)(offset))) 14 #define DRM_READ32(map, offset) \ 15 le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \ 16 (vm_offset_t)(offset))) 17 #define DRM_READ64(map, offset) \ 18 le64toh(*(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \ 19 (vm_offset_t)(offset))) 20 #define DRM_WRITE8(map, offset, val) \ 21 *(volatile u_int8_t *)(((vm_offset_t)(map)->virtual) + \ 22 (vm_offset_t)(offset)) = val 23 #define DRM_WRITE16(map, offset, val) \ 24 *(volatile u_int16_t *)(((vm_offset_t)(map)->virtual) + \ 25 (vm_offset_t)(offset)) = htole16(val) 26 #define DRM_WRITE32(map, offset, val) \ 27 *(volatile u_int32_t *)(((vm_offset_t)(map)->virtual) + \ 28 (vm_offset_t)(offset)) = htole32(val) 29 #define DRM_WRITE64(map, offset, val) \ 30 *(volatile u_int64_t *)(((vm_offset_t)(map)->virtual) + \ 31 (vm_offset_t)(offset)) = htole64(val) 32 33 34 #if _BYTE_ORDER == _BIG_ENDIAN 35 #define __BIG_ENDIAN 4321 36 #else 37 #define __LITTLE_ENDIAN 1234 38 #endif 39 40 #ifdef __LP64__ 41 #define BITS_PER_LONG 64 42 #else 43 #define BITS_PER_LONG 32 44 #endif 45 46 #define cpu_to_le16(x) htole16(x) 47 #define le16_to_cpu(x) le16toh(x) 48 #define cpu_to_le32(x) htole32(x) 49 #define le32_to_cpu(x) le32toh(x) 50 51 #define cpu_to_be16(x) htobe16(x) 52 #define be16_to_cpu(x) be16toh(x) 53 #define cpu_to_be32(x) htobe32(x) 54 #define be32_to_cpu(x) be32toh(x) 55 #define be32_to_cpup(x) be32toh(*x) 56 57 #define unlikely(x) __builtin_expect(!!(x), 0) 58 #define likely(x) __builtin_expect(!!(x), 1) 59 60 #define DRM_HZ hz 61 #define DRM_UDELAY(udelay) DELAY(udelay) 62 #define DRM_MDELAY(msecs) do { int loops = (msecs); \ 63 while (loops--) DELAY(1000); \ 64 } while (0) 65 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ 66 67 #define do_div(a, b) ((a) /= (b)) 68 #define lower_32_bits(n) ((u32)(n)) 69 70 #define memset_io(a, b, c) memset((a), (b), (c)) 71 #define memcpy_fromio(a, b, c) memcpy((a), (b), (c)) 72 #define memcpy_toio(a, b, c) memcpy((a), (b), (c)) 73 74 /* XXXKIB what is the right code for the FreeBSD ? */ 75 /* kib@ used ENXIO here -- dumbbell@ */ 76 #define EREMOTEIO EIO 77 #define ERESTARTSYS ERESTART 78 79 #define KTR_DRM KTR_DEV 80 #define KTR_DRM_REG KTR_SPARE3 81 82 #define hweight32(i) bitcount32(i) 83 84 static inline unsigned long 85 roundup_pow_of_two(unsigned long x) 86 { 87 return (1UL << flsl(x - 1)); 88 } 89 90 /** 91 * ror32 - rotate a 32-bit value right 92 * @word: value to rotate 93 * @shift: bits to roll 94 * 95 * Source: include/linux/bitops.h 96 */ 97 static inline uint32_t ror32(uint32_t word, unsigned int shift) 98 { 99 return (word >> shift) | (word << (32 - shift)); 100 } 101 102 #define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0) 103 #define get_unaligned(ptr) \ 104 ({ __typeof__(*(ptr)) __tmp; \ 105 memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; }) 106 107 #if _BYTE_ORDER == _LITTLE_ENDIAN 108 /* Taken from linux/include/linux/unaligned/le_struct.h. */ 109 struct __una_u32 { u32 x; } __packed; 110 111 static inline u32 __get_unaligned_cpu32(const void *p) 112 { 113 const struct __una_u32 *ptr = (const struct __una_u32 *)p; 114 return ptr->x; 115 } 116 117 static inline u32 get_unaligned_le32(const void *p) 118 { 119 return __get_unaligned_cpu32((const u8 *)p); 120 } 121 #else 122 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */ 123 static inline u32 __get_unaligned_le32(const u8 *p) 124 { 125 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; 126 } 127 128 static inline u32 get_unaligned_le32(const void *p) 129 { 130 return __get_unaligned_le32((const u8 *)p); 131 } 132 #endif 133 134 #define KIB_NOTYET() \ 135 do { \ 136 if (drm_debug && drm_notyet_flag) \ 137 kprintf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \ 138 } while (0) 139