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