]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - sys/dev/drm2/drm_os_freebsd.h
MFC 219886, 226100, 226111, 226341, 242529, 259015, 259016, 259019, 259049,
[FreeBSD/stable/9.git] / sys / dev / drm2 / drm_os_freebsd.h
1 /**
2  * \file drm_os_freebsd.h
3  * OS abstraction macros.
4  */
5
6 #include <sys/cdefs.h>
7 __FBSDID("$FreeBSD$");
8
9 #include <sys/fbio.h>
10
11 #if _BYTE_ORDER == _BIG_ENDIAN
12 #define __BIG_ENDIAN 4321
13 #else
14 #define __LITTLE_ENDIAN 1234
15 #endif
16
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)
21
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)
27
28 typedef vm_paddr_t dma_addr_t;
29 typedef uint64_t u64;
30 typedef uint32_t u32;
31 typedef uint16_t u16;
32 typedef uint8_t u8;
33 typedef int64_t s64;
34 typedef int32_t s32;
35 typedef int16_t s16;
36 typedef int8_t s8;
37 typedef int32_t __be32;
38
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) );})
44
45 #define DRM_HZ                  hz
46 #define DRM_UDELAY(udelay)      DELAY(udelay)
47 #define DRM_MDELAY(msecs)       do { int loops = (msecs);               \
48                                   while (loops--) DELAY(1000);          \
49                                 } while (0)
50 #define DRM_MSLEEP(msecs)       drm_msleep((msecs), "drm_msleep")
51 #define DRM_TIME_SLICE          (hz/20)  /* Time slice for GLXContexts    */
52
53 #define do_div(a, b)            ((a) /= (b))
54 #define lower_32_bits(n)        ((u32)(n))
55
56 #define min_t(type, x, y) ({                    \
57         type __min1 = (x);                      \
58         type __min2 = (y);                      \
59         __min1 < __min2 ? __min1 : __min2; })
60
61 #define max_t(type, x, y) ({                    \
62         type __max1 = (x);                      \
63         type __max2 = (y);                      \
64         __max1 > __max2 ? __max1 : __max2; })
65
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))
69
70 /* XXXKIB what is the right code for the FreeBSD ? */
71 /* kib@ used ENXIO here -- dumbbell@ */
72 #define EREMOTEIO       EIO
73 #define ERESTARTSYS     ERESTART
74
75 #define KTR_DRM         KTR_DEV
76 #define KTR_DRM_REG     KTR_SPARE3
77
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
88
89 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
90 #define hweight32(i)    bitcount32(i)
91
92 static inline unsigned long
93 roundup_pow_of_two(unsigned long x)
94 {
95         return (1UL << flsl(x - 1));
96 }
97
98 /**
99  * ror32 - rotate a 32-bit value right
100  * @word: value to rotate
101  * @shift: bits to roll
102  *
103  * Source: include/linux/bitops.h
104  */
105 static inline uint32_t ror32(uint32_t word, unsigned int shift)
106 {
107         return (word >> shift) | (word << (32 - shift));
108 }
109
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; })
114
115 #if _BYTE_ORDER == _LITTLE_ENDIAN
116 /* Taken from linux/include/linux/unaligned/le_struct.h. */
117 struct __una_u32 { u32 x; } __packed;
118
119 static inline u32 __get_unaligned_cpu32(const void *p)
120 {
121         const struct __una_u32 *ptr = (const struct __una_u32 *)p;
122         return ptr->x;
123 }
124
125 static inline u32 get_unaligned_le32(const void *p)
126 {
127         return __get_unaligned_cpu32((const u8 *)p);
128 }
129 #else
130 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */
131 static inline u32 __get_unaligned_le32(const u8 *p)
132 {
133         return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
134 }
135
136 static inline u32 get_unaligned_le32(const void *p)
137 {
138         return __get_unaligned_le32((const u8 *)p);
139 }
140 #endif
141
142 #define KIB_NOTYET()                                                    \
143 do {                                                                    \
144         if (drm_debug_flag && drm_notyet_flag)                          \
145                 printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
146 } while (0)