]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/sysmacros.h
Update SPL to use new debug infrastructure. This means:
[mirror_spl.git] / include / sys / sysmacros.h
1 #ifndef _SPL_SYSMACROS_H
2 #define _SPL_SYSMACROS_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <linux/module.h>
9 #include <sys/debug.h>
10 #include <sys/varargs.h>
11 #include <sys/zone.h>
12 #include <sys/signal.h>
13
14 #ifndef _KERNEL
15 #define _KERNEL __KERNEL__
16 #endif
17
18 /* Missing defines.
19 */
20 #define FALSE 0
21 #define TRUE 1
22
23 #define INT32_MAX INT_MAX
24 #define INT32_MIN INT_MIN
25 #define UINT32_MAX UINT_MAX
26 #define UINT32_MIN UINT_MIN
27 #define INT64_MAX LLONG_MAX
28 #define INT64_MIN LLONG_MIN
29 #define UINT64_MAX ULLONG_MAX
30 #define UINT64_MIN ULLONG_MIN
31
32 #define NBBY 8
33 #define ENOTSUP ENOTSUPP
34
35 #define MAXMSGLEN 256
36 #define MAXNAMELEN 256
37 #define MAXPATHLEN PATH_MAX
38 #define MAXOFFSET_T 0x7fffffffffffffffl
39
40 #define MAXBSIZE 8192
41 #define DEV_BSIZE 512
42 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
43
44 #define max_ncpus 64
45 #define CPU_SEQID smp_processor_id() /* I think... */
46 #define _NOTE(x)
47
48 #define RLIM64_INFINITY RLIM_INFINITY
49
50 /* 0..MAX_PRIO-1: Process priority
51 * 0..MAX_RT_PRIO-1: RT priority tasks
52 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
53 *
54 * Treat shim tasks as SCHED_NORMAL tasks
55 */
56 #define minclsyspri (MAX_RT_PRIO)
57 #define maxclsyspri (MAX_PRIO-1)
58
59 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
60 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
61
62 /* Missing macros
63 */
64 #define PAGESIZE PAGE_SIZE
65
66 /* from Solaris sys/byteorder.h */
67 #define BSWAP_8(x) ((x) & 0xff)
68 #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
69 #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
70 #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
71
72 /* Map some simple functions.
73 */
74 #define bzero(ptr,size) memset(ptr,0,size)
75 #define bcopy(src,dest,size) memcpy(dest,src,size)
76 #define bcmp(src,dest,size) memcmp((src), (dest), (size_t)(size))
77
78 /* Dtrace probes do not exist in the linux kernel */
79
80 #ifdef DTRACE_PROBE1
81 #undef DTRACE_PROBE1
82 #endif /* DTRACE_PROBE1 */
83 #define DTRACE_PROBE1(a, b, c) ((void)0)
84
85 #ifdef DTRACE_PROBE2
86 #undef DTRACE_PROBE2
87 #endif /* DTRACE_PROBE2 */
88 #define DTRACE_PROBE2(a, b, c, d, e) ((void)0)
89
90 #ifdef DTRACE_PROBE3
91 #undef DTRACE_PROBE3
92 #endif /* DTRACE_PROBE3 */
93 #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0)
94
95 #ifdef DTRACE_PROBE4
96 #undef DTRACE_PROBE4
97 #endif /* DTRACE_PROBE4 */
98 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0)
99
100 /* Missing globals */
101 extern long spl_hostid;
102 extern char hw_serial[11];
103 extern int p0;
104
105 /* Missing misc functions */
106 extern int highbit(unsigned long i);
107 extern int ddi_strtoul(const char *str, char **nptr,
108 int base, unsigned long *result);
109
110 #define makedevice(maj,min) makedev(maj,min)
111
112 /* common macros */
113 #ifndef MIN
114 #define MIN(a, b) ((a) < (b) ? (a) : (b))
115 #endif
116 #ifndef MAX
117 #define MAX(a, b) ((a) < (b) ? (b) : (a))
118 #endif
119 #ifndef ABS
120 #define ABS(a) ((a) < 0 ? -(a) : (a))
121 #endif
122
123 /*
124 * Compatibility macros/typedefs needed for Solaris -> Linux port
125 */
126 #define P2ALIGN(x, align) ((x) & -(align))
127 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
128 #define P2ROUNDUP(x, align) (-(-(x) & -(align)))
129 #define P2ROUNDUP_TYPED(x, align, type) \
130 (-(-(type)(x) & -(type)(align)))
131 #define P2PHASE(x, align) ((x) & ((align) - 1))
132 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
133 #define P2NPHASE_TYPED(x, align, type) \
134 (-(type)(x) & ((type)(align) - 1))
135 #define ISP2(x) (((x) & ((x) - 1)) == 0)
136 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
137
138 /*
139 * Typed version of the P2* macros. These macros should be used to ensure
140 * that the result is correctly calculated based on the data type of (x),
141 * which is passed in as the last argument, regardless of the data
142 * type of the alignment. For example, if (x) is of type uint64_t,
143 * and we want to round it up to a page boundary using "PAGESIZE" as
144 * the alignment, we can do either
145 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
146 * or
147 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
148 */
149 #define P2ALIGN_TYPED(x, align, type) \
150 ((type)(x) & -(type)(align))
151 #define P2PHASE_TYPED(x, align, type) \
152 ((type)(x) & ((type)(align) - 1))
153 #define P2NPHASE_TYPED(x, align, type) \
154 (-(type)(x) & ((type)(align) - 1))
155 #define P2ROUNDUP_TYPED(x, align, type) \
156 (-(-(type)(x) & -(type)(align)))
157 #define P2END_TYPED(x, align, type) \
158 (-(~(type)(x) & -(type)(align)))
159 #define P2PHASEUP_TYPED(x, align, phase, type) \
160 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
161 #define P2CROSS_TYPED(x, y, align, type) \
162 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
163 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
164 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
165
166 #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
167
168 /* avoid any possibility of clashing with <stddef.h> version */
169
170 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
171 #endif
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif /* _SPL_SYSMACROS_H */