xref: /freebsd/sys/contrib/openzfs/include/os/linux/spl/sys/isa_defs.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
4  *  Copyright (C) 2007 The Regents of the University of California.
5  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6  *  Written by Brian Behlendorf <behlendorf1@llnl.gov>.
7  *  UCRL-CODE-235197
8  *
9  *  This file is part of the SPL, Solaris Porting Layer.
10  *
11  *  The SPL is free software; you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License as published by the
13  *  Free Software Foundation; either version 2 of the License, or (at your
14  *  option) any later version.
15  *
16  *  The SPL is distributed in the hope that it will be useful, but WITHOUT
17  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19  *  for more details.
20  *
21  *  You should have received a copy of the GNU General Public License along
22  *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef	_SPL_ISA_DEFS_H
26 #define	_SPL_ISA_DEFS_H
27 
28 /* x86_64 arch specific defines */
29 #if defined(__x86_64) || defined(__x86_64__)
30 
31 #if !defined(__x86_64)
32 #define	__x86_64
33 #endif
34 
35 #if !defined(__amd64)
36 #define	__amd64
37 #endif
38 
39 #if !defined(__x86)
40 #define	__x86
41 #endif
42 
43 #if defined(_ILP32)
44 /* x32-specific defines; careful to *not* define _LP64 here */
45 #else
46 #if !defined(_LP64)
47 #define	_LP64
48 #endif
49 #endif
50 
51 /* i386 arch specific defines */
52 #elif defined(__i386) || defined(__i386__)
53 
54 #if !defined(__i386)
55 #define	__i386
56 #endif
57 
58 #if !defined(__x86)
59 #define	__x86
60 #endif
61 
62 #if !defined(_ILP32)
63 #define	_ILP32
64 #endif
65 
66 /* powerpc (ppc64) arch specific defines */
67 #elif defined(__powerpc) || defined(__powerpc__) || defined(__powerpc64__)
68 
69 #if !defined(__powerpc)
70 #define	__powerpc
71 #endif
72 
73 #if !defined(__powerpc__)
74 #define	__powerpc__
75 #endif
76 
77 #if defined(__powerpc64__)
78 #if !defined(_LP64)
79 #define	_LP64
80 #endif
81 #else
82 #if !defined(_ILP32)
83 #define	_ILP32
84 #endif
85 #endif
86 
87 /* arm arch specific defines */
88 #elif defined(__arm) || defined(__arm__)
89 
90 #if !defined(__arm)
91 #define	__arm
92 #endif
93 
94 #if !defined(__arm__)
95 #define	__arm__
96 #endif
97 
98 #if !defined(_ILP32)
99 #define	_ILP32
100 #endif
101 
102 #if defined(__ARMEL__)
103 #define	_ZFS_LITTLE_ENDIAN
104 #else
105 #define	_ZFS_BIG_ENDIAN
106 #endif
107 
108 /* aarch64 arch specific defines */
109 #elif defined(__aarch64__)
110 
111 #if !defined(_LP64)
112 #define	_LP64
113 #endif
114 
115 #if defined(__AARCH64EL__)
116 #define	_ZFS_LITTLE_ENDIAN
117 #else
118 #define	_ZFS_BIG_ENDIAN
119 #endif
120 
121 /* sparc arch specific defines */
122 #elif defined(__sparc) || defined(__sparc__)
123 
124 #if !defined(__sparc)
125 #define	__sparc
126 #endif
127 
128 #if !defined(__sparc__)
129 #define	__sparc__
130 #endif
131 
132 #if defined(__arch64__)
133 #if !defined(_LP64)
134 #define	_LP64
135 #endif
136 #else
137 #if !defined(_ILP32)
138 #define	_ILP32
139 #endif
140 #endif
141 
142 #define	_ZFS_BIG_ENDIAN
143 #define	_SUNOS_VTOC_16
144 
145 /* s390 arch specific defines */
146 #elif defined(__s390__)
147 #if defined(__s390x__)
148 #if !defined(_LP64)
149 #define	_LP64
150 #endif
151 #else
152 #if !defined(_ILP32)
153 #define	_ILP32
154 #endif
155 #endif
156 
157 #define	_ZFS_BIG_ENDIAN
158 
159 /* MIPS arch specific defines */
160 #elif defined(__mips__)
161 
162 #if defined(__MIPSEB__)
163 #define	_ZFS_BIG_ENDIAN
164 #elif defined(__MIPSEL__)
165 #define	_ZFS_LITTLE_ENDIAN
166 #else
167 #error MIPS no endian specified
168 #endif
169 
170 #ifndef _LP64
171 #define	_ILP32
172 #endif
173 
174 #define	_SUNOS_VTOC_16
175 
176 /*
177  * RISC-V arch specific defines
178  * only RV64G (including atomic) LP64 is supported yet
179  */
180 #elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 && \
181 	defined(__riscv_atomic) && __riscv_atomic
182 
183 #if !defined(_LP64)
184 #define	_LP64 1
185 #endif
186 
187 #ifndef	__riscv__
188 #define	__riscv__
189 #endif
190 
191 #ifndef	__rv64g__
192 #define	__rv64g__
193 #endif
194 
195 #define	_ZFS_LITTLE_ENDIAN
196 
197 #define	_SUNOS_VTOC_16
198 
199 /*
200  * LoongArch arch specific defines
201  * only LoongArch64 is supported yet
202  */
203 #elif defined(__loongarch__) && defined(__loongarch_lp64)
204 
205 #if !defined(_LP64)
206 #define	_LP64
207 #endif
208 
209 #define	_ZFS_LITTLE_ENDIAN
210 #define	_SUNOS_VTOC_16
211 
212 /* not all LoongArch cores support unaligned accesses in hardware */
213 #define	_ALIGNMENT_REQUIRED	1
214 
215 #else
216 /*
217  * Currently supported:
218  * x86_64, x32, i386, arm, powerpc, s390, sparc, mips, RV64G, and LoongArch64
219  */
220 #error "Unsupported ISA type"
221 #endif
222 
223 #if defined(_ILP32) && defined(_LP64)
224 #error "Both _ILP32 and _LP64 are defined"
225 #endif
226 
227 #if !defined(_ILP32) && !defined(_LP64)
228 #error "Neither _ILP32 or _LP64 are defined"
229 #endif
230 
231 #include <sys/byteorder.h>
232 
233 /*
234  * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS will be defined by the Linux
235  * kernel for architectures which support efficient unaligned access.
236  */
237 #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
238 #define	HAVE_EFFICIENT_UNALIGNED_ACCESS
239 #endif
240 
241 #if defined(_ZFS_LITTLE_ENDIAN) && defined(_ZFS_BIG_ENDIAN)
242 #error "Both _ZFS_LITTLE_ENDIAN and _ZFS_BIG_ENDIAN are defined"
243 #endif
244 
245 #if !defined(_ZFS_LITTLE_ENDIAN) && !defined(_ZFS_BIG_ENDIAN)
246 #error "Neither _ZFS_LITTLE_ENDIAN or _ZFS_BIG_ENDIAN are defined"
247 #endif
248 
249 #endif	/* _SPL_ISA_DEFS_H */
250