drm/i915: New IRQ management code from Linux
[dragonfly.git] / sys / dev / drm / include / drm / drm_os_freebsd.h
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 #if _BYTE_ORDER == _BIG_ENDIAN
9 #define __BIG_ENDIAN 4321
10 #else
11 #define __LITTLE_ENDIAN 1234
12 #endif
13
14 #ifdef __LP64__
15 #define BITS_PER_LONG   64
16 #else
17 #define BITS_PER_LONG   32
18 #endif
19
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)
24
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)
30
31 #define unlikely(x)            __builtin_expect(!!(x), 0)
32 #define likely(x)              __builtin_expect(!!(x), 1)
33
34 #define DRM_HZ                  hz
35 #define DRM_UDELAY(udelay)      DELAY(udelay)
36 #define DRM_MDELAY(msecs)       do { int loops = (msecs);               \
37                                   while (loops--) DELAY(1000);          \
38                                 } while (0)
39 #define DRM_TIME_SLICE          (hz/20)  /* Time slice for GLXContexts    */
40
41 #define do_div(a, b)            ((a) /= (b))
42 #define lower_32_bits(n)        ((u32)(n))
43
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))
47
48 /* XXXKIB what is the right code for the FreeBSD ? */
49 /* kib@ used ENXIO here -- dumbbell@ */
50 #define EREMOTEIO       EIO
51 #define ERESTARTSYS     ERESTART
52
53 #define KTR_DRM         KTR_DEV
54 #define KTR_DRM_REG     KTR_SPARE3
55
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
66
67 #define hweight32(i)    bitcount32(i)
68
69 static inline unsigned long
70 roundup_pow_of_two(unsigned long x)
71 {
72         return (1UL << flsl(x - 1));
73 }
74
75 /**
76  * ror32 - rotate a 32-bit value right
77  * @word: value to rotate
78  * @shift: bits to roll
79  *
80  * Source: include/linux/bitops.h
81  */
82 static inline uint32_t ror32(uint32_t word, unsigned int shift)
83 {
84         return (word >> shift) | (word << (32 - shift));
85 }
86
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; })
91
92 #if _BYTE_ORDER == _LITTLE_ENDIAN
93 /* Taken from linux/include/linux/unaligned/le_struct.h. */
94 struct __una_u32 { u32 x; } __packed;
95
96 static inline u32 __get_unaligned_cpu32(const void *p)
97 {
98         const struct __una_u32 *ptr = (const struct __una_u32 *)p;
99         return ptr->x;
100 }
101
102 static inline u32 get_unaligned_le32(const void *p)
103 {
104         return __get_unaligned_cpu32((const u8 *)p);
105 }
106 #else
107 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */
108 static inline u32 __get_unaligned_le32(const u8 *p)
109 {
110         return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
111 }
112
113 static inline u32 get_unaligned_le32(const void *p)
114 {
115         return __get_unaligned_le32((const u8 *)p);
116 }
117 #endif
118
119 #define KIB_NOTYET()                                                    \
120 do {                                                                    \
121         if (drm_debug && drm_notyet_flag)                               \
122                 kprintf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
123 } while (0)