2 * \file drm_os_freebsd.h
3 * OS abstraction macros.
9 #if _BYTE_ORDER == _BIG_ENDIAN
10 #define __BIG_ENDIAN 4321
12 #define __LITTLE_ENDIAN 1234
15 #define cpu_to_le16(x) htole16(x)
16 #define le16_to_cpu(x) le16toh(x)
17 #define cpu_to_le32(x) htole32(x)
18 #define le32_to_cpu(x) le32toh(x)
20 #define cpu_to_be16(x) htobe16(x)
21 #define be16_to_cpu(x) be16toh(x)
22 #define cpu_to_be32(x) htobe32(x)
23 #define be32_to_cpu(x) be32toh(x)
24 #define be32_to_cpup(x) be32toh(*x)
26 typedef vm_paddr_t dma_addr_t;
35 typedef int32_t __be32;
37 #define unlikely(x) __builtin_expect(!!(x), 0)
38 #define likely(x) __builtin_expect(!!(x), 1)
39 #define container_of(ptr, type, member) ({ \
40 __typeof( ((type *)0)->member ) *__mptr = (ptr); \
41 (type *)( (char *)__mptr - offsetof(type,member) );})
44 #define DRM_UDELAY(udelay) DELAY(udelay)
45 #define DRM_MDELAY(msecs) do { int loops = (msecs); \
46 while (loops--) DELAY(1000); \
48 #define DRM_MSLEEP(msecs) drm_msleep((msecs), "drm_msleep")
49 #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */
51 #define do_div(a, b) ((a) /= (b))
52 #define lower_32_bits(n) ((u32)(n))
54 #define min_t(type, x, y) ({ \
57 __min1 < __min2 ? __min1 : __min2; })
59 #define max_t(type, x, y) ({ \
62 __max1 > __max2 ? __max1 : __max2; })
64 #define memset_io(a, b, c) memset((a), (b), (c))
65 #define memcpy_fromio(a, b, c) memcpy((a), (b), (c))
66 #define memcpy_toio(a, b, c) memcpy((a), (b), (c))
68 /* XXXKIB what is the right code for the FreeBSD ? */
69 /* kib@ used ENXIO here -- dumbbell@ */
71 #define ERESTARTSYS ERESTART
73 #define KTR_DRM KTR_DEV
74 #define KTR_DRM_REG KTR_SPARE3
76 #define PCI_VENDOR_ID_APPLE 0x106b
77 #define PCI_VENDOR_ID_ASUSTEK 0x1043
78 #define PCI_VENDOR_ID_ATI 0x1002
79 #define PCI_VENDOR_ID_DELL 0x1028
80 #define PCI_VENDOR_ID_HP 0x103c
81 #define PCI_VENDOR_ID_IBM 0x1014
82 #define PCI_VENDOR_ID_INTEL 0x8086
83 #define PCI_VENDOR_ID_SERVERWORKS 0x1166
84 #define PCI_VENDOR_ID_SONY 0x104d
85 #define PCI_VENDOR_ID_VIA 0x1106
87 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
88 #define hweight32(i) bitcount32(i)
90 static inline unsigned long
91 roundup_pow_of_two(unsigned long x)
93 return (1UL << flsl(x - 1));
97 * ror32 - rotate a 32-bit value right
98 * @word: value to rotate
99 * @shift: bits to roll
101 * Source: include/linux/bitops.h
103 static inline uint32_t ror32(uint32_t word, unsigned int shift)
105 return (word >> shift) | (word << (32 - shift));
108 #define IS_ALIGNED(x, y) (((x) & ((y) - 1)) == 0)
109 #define get_unaligned(ptr) \
110 ({ __typeof__(*(ptr)) __tmp; \
111 memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
113 #if _BYTE_ORDER == _LITTLE_ENDIAN
114 /* Taken from linux/include/linux/unaligned/le_struct.h. */
115 struct __una_u32 { u32 x; } __packed;
117 static inline u32 __get_unaligned_cpu32(const void *p)
119 const struct __una_u32 *ptr = (const struct __una_u32 *)p;
123 static inline u32 get_unaligned_le32(const void *p)
125 return __get_unaligned_cpu32((const u8 *)p);
128 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */
129 static inline u32 __get_unaligned_le32(const u8 *p)
131 return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
134 static inline u32 get_unaligned_le32(const void *p)
136 return __get_unaligned_le32((const u8 *)p);
140 #define KIB_NOTYET() \
142 if (drm_debug_flag && drm_notyet_flag) \
143 printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \