]> git.proxmox.com Git - mirror_zfs.git/blob - include/os/linux/spl/sys/sysmacros.h
module/*.ko: prune .data, global .rodata
[mirror_zfs.git] / include / os / linux / spl / sys / sysmacros.h
1 /*
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 *
10 * The SPL is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 * The SPL is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _SPL_SYSMACROS_H
25 #define _SPL_SYSMACROS_H
26
27 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/sched/rt.h>
30 #include <linux/cpumask.h>
31 #include <sys/debug.h>
32 #include <sys/zone.h>
33 #include <sys/signal.h>
34 #include <asm/page.h>
35
36
37 #ifndef _KERNEL
38 #define _KERNEL __KERNEL__
39 #endif
40
41 #define FALSE 0
42 #define TRUE 1
43
44 #define INT8_MAX (127)
45 #define INT8_MIN (-128)
46 #define UINT8_MAX (255)
47 #define UINT8_MIN (0)
48
49 #define INT16_MAX (32767)
50 #define INT16_MIN (-32768)
51 #define UINT16_MAX (65535)
52 #define UINT16_MIN (0)
53
54 #define INT32_MAX INT_MAX
55 #define INT32_MIN INT_MIN
56 #define UINT32_MAX UINT_MAX
57 #define UINT32_MIN UINT_MIN
58
59 #define INT64_MAX LLONG_MAX
60 #define INT64_MIN LLONG_MIN
61 #define UINT64_MAX ULLONG_MAX
62 #define UINT64_MIN ULLONG_MIN
63
64 #define NBBY 8
65
66 #define MAXMSGLEN 256
67 #define MAXNAMELEN 256
68 #define MAXPATHLEN 4096
69 #define MAXOFFSET_T LLONG_MAX
70 #define MAXBSIZE 8192
71 #define DEV_BSIZE 512
72 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
73
74 #define proc_pageout NULL
75 #define curproc current
76 #define max_ncpus num_possible_cpus()
77 #define boot_ncpus num_online_cpus()
78 #define CPU_SEQID smp_processor_id()
79 #define CPU_SEQID_UNSTABLE raw_smp_processor_id()
80 #define is_system_labeled() 0
81
82 #ifndef RLIM64_INFINITY
83 #define RLIM64_INFINITY (~0ULL)
84 #endif
85
86 /*
87 * 0..MAX_PRIO-1: Process priority
88 * 0..MAX_RT_PRIO-1: RT priority tasks
89 * MAX_RT_PRIO..MAX_PRIO-1: SCHED_NORMAL tasks
90 *
91 * Treat shim tasks as SCHED_NORMAL tasks
92 */
93 #define minclsyspri (MAX_PRIO-1)
94 #define maxclsyspri (MAX_RT_PRIO)
95 #define defclsyspri (DEFAULT_PRIO)
96
97 #ifndef NICE_TO_PRIO
98 #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)
99 #endif
100 #ifndef PRIO_TO_NICE
101 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
102 #endif
103
104 /*
105 * Missing macros
106 */
107 #ifndef PAGESIZE
108 #define PAGESIZE PAGE_SIZE
109 #endif
110
111 #ifndef PAGESHIFT
112 #define PAGESHIFT PAGE_SHIFT
113 #endif
114
115 /* Missing globals */
116 extern unsigned long spl_hostid;
117
118 /* Missing misc functions */
119 extern uint32_t zone_get_hostid(void *zone);
120 extern void spl_setup(void);
121 extern void spl_cleanup(void);
122
123 #define highbit(x) __fls(x)
124 #define lowbit(x) __ffs(x)
125
126 #define highbit64(x) fls64(x)
127 #define makedevice(maj, min) makedev(maj, min)
128
129 /* common macros */
130 #ifndef MIN
131 #define MIN(a, b) ((a) < (b) ? (a) : (b))
132 #endif
133 #ifndef MAX
134 #define MAX(a, b) ((a) < (b) ? (b) : (a))
135 #endif
136 #ifndef ABS
137 #define ABS(a) ((a) < 0 ? -(a) : (a))
138 #endif
139 #ifndef DIV_ROUND_UP
140 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
141 #endif
142 #ifndef roundup
143 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
144 #endif
145 #ifndef howmany
146 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
147 #endif
148
149 /*
150 * Compatibility macros/typedefs needed for Solaris -> Linux port
151 */
152 #define P2ALIGN(x, align) ((x) & -(align))
153 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
154 #define P2ROUNDUP(x, align) ((((x) - 1) | ((align) - 1)) + 1)
155 #define P2PHASE(x, align) ((x) & ((align) - 1))
156 #define P2NPHASE(x, align) (-(x) & ((align) - 1))
157 #define ISP2(x) (((x) & ((x) - 1)) == 0)
158 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
159 #define P2BOUNDARY(off, len, align) \
160 (((off) ^ ((off) + (len) - 1)) > (align) - 1)
161
162 /*
163 * Typed version of the P2* macros. These macros should be used to ensure
164 * that the result is correctly calculated based on the data type of (x),
165 * which is passed in as the last argument, regardless of the data
166 * type of the alignment. For example, if (x) is of type uint64_t,
167 * and we want to round it up to a page boundary using "PAGESIZE" as
168 * the alignment, we can do either
169 *
170 * P2ROUNDUP(x, (uint64_t)PAGESIZE)
171 * or
172 * P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
173 */
174 #define P2ALIGN_TYPED(x, align, type) \
175 ((type)(x) & -(type)(align))
176 #define P2PHASE_TYPED(x, align, type) \
177 ((type)(x) & ((type)(align) - 1))
178 #define P2NPHASE_TYPED(x, align, type) \
179 (-(type)(x) & ((type)(align) - 1))
180 #define P2ROUNDUP_TYPED(x, align, type) \
181 ((((type)(x) - 1) | ((type)(align) - 1)) + 1)
182 #define P2END_TYPED(x, align, type) \
183 (-(~(type)(x) & -(type)(align)))
184 #define P2PHASEUP_TYPED(x, align, phase, type) \
185 ((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
186 #define P2CROSS_TYPED(x, y, align, type) \
187 (((type)(x) ^ (type)(y)) > (type)(align) - 1)
188 #define P2SAMEHIGHBIT_TYPED(x, y, type) \
189 (((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
190
191 #define SET_ERROR(err) \
192 (__set_error(__FILE__, __func__, __LINE__, err), err)
193
194 #include <linux/sort.h>
195 #define qsort(base, num, size, cmp) \
196 sort(base, num, size, cmp, NULL)
197
198 #if !defined(_KMEMUSER) && !defined(offsetof)
199
200 /* avoid any possibility of clashing with <stddef.h> version */
201
202 #define offsetof(s, m) ((size_t)(&(((s *)0)->m)))
203 #endif
204
205 #endif /* _SPL_SYSMACROS_H */