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 #if _BYTE_ORDER == _BIG_ENDIAN
9 #define __BIG_ENDIAN 4321
11 #define __LITTLE_ENDIAN 1234
15 #define BITS_PER_LONG 64
17 #define BITS_PER_LONG 32
20 #define cpu_to_le16(x) htole16(x)
21 #define le16_to_cpu(x) le16toh(x)
22 #define cpu_to_le32(x) htole32(x)
23 #define le32_to_cpu(x) le32toh(x)
25 #define cpu_to_be16(x) htobe16(x)
26 #define be16_to_cpu(x) be16toh(x)
27 #define cpu_to_be32(x) htobe32(x)
28 #define be32_to_cpu(x) be32toh(x)
29 #define be32_to_cpup(x) be32toh(*x)
31 #define unlikely(x) __builtin_expect(!!(x), 0)
32 #define likely(x) __builtin_expect(!!(x), 1)
35 #define DRM_UDELAY(udelay) DELAY(udelay)
36 #define DRM_MDELAY(msecs) do { int loops = (msecs); \
37 while (loops--) DELAY(1000); \
39 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
41 #define do_div(a, b) ((a) /= (b))
42 #define lower_32_bits(n) ((u32)(n))
44 #define memset_io(a, b, c) memset((a), (b), (c))
45 #define memcpy_fromio(a, b, c) memcpy((a), (b), (c))
46 #define memcpy_toio(a, b, c) memcpy((a), (b), (c))
48 /* XXXKIB what is the right code for the FreeBSD ? */
49 /* kib@ used ENXIO here -- dumbbell@ */
51 #define ERESTARTSYS ERESTART
53 #define KTR_DRM KTR_DEV
54 #define KTR_DRM_REG KTR_SPARE3
56 #define PCI_VENDOR_ID_APPLE 0x106b
57 #define PCI_VENDOR_ID_ASUSTEK 0x1043
58 #define PCI_VENDOR_ID_ATI 0x1002
59 #define PCI_VENDOR_ID_DELL 0x1028
60 #define PCI_VENDOR_ID_HP 0x103c
61 #define PCI_VENDOR_ID_IBM 0x1014
62 #define PCI_VENDOR_ID_INTEL 0x8086
63 #define PCI_VENDOR_ID_SERVERWORKS 0x1166
64 #define PCI_VENDOR_ID_SONY 0x104d
65 #define PCI_VENDOR_ID_VIA 0x1106
67 #define hweight32(i) bitcount32(i)
69 static inline unsigned long
70 roundup_pow_of_two(unsigned long x)
72 return (1UL << flsl(x - 1));
76 * ror32 - rotate a 32-bit value right
77 * @word: value to rotate
78 * @shift: bits to roll
80 * Source: include/linux/bitops.h
82 static inline uint32_t ror32(uint32_t word, unsigned int shift)
84 return (word >> shift) | (word << (32 - shift));
87 #define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0)
88 #define get_unaligned(ptr) \
89 ({ __typeof__(*(ptr)) __tmp; \
90 memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
92 #if _BYTE_ORDER == _LITTLE_ENDIAN
93 /* Taken from linux/include/linux/unaligned/le_struct.h. */
94 struct __una_u32 { u32 x; } __packed;
96 static inline u32 __get_unaligned_cpu32(const void *p)
98 const struct __una_u32 *ptr = (const struct __una_u32 *)p;
102 static inline u32 get_unaligned_le32(const void *p)
104 return __get_unaligned_cpu32((const u8 *)p);
107 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */
108 static inline u32 __get_unaligned_le32(const u8 *p)
110 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
113 static inline u32 get_unaligned_le32(const void *p)
115 return __get_unaligned_le32((const u8 *)p);
119 #define KIB_NOTYET() \
121 if (drm_debug && drm_notyet_flag) \
122 kprintf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \