2 * Copyright (c) 2014 Andrew Turner
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef _MACHINE_CPUFUNC_H_
30 #define _MACHINE_CPUFUNC_H_
41 #define HAVE_INLINE_FFS
43 static __inline __pure2 int
47 return (__builtin_ffs(mask));
50 #define HAVE_INLINE_FFSL
52 static __inline __pure2 int
56 return (__builtin_ffsl(mask));
59 #define HAVE_INLINE_FFSLL
61 static __inline __pure2 int
65 return (__builtin_ffsll(mask));
68 #define HAVE_INLINE_FLS
70 static __inline __pure2 int
74 return (mask == 0 ? 0 :
75 8 * sizeof(mask) - __builtin_clz((u_int)mask));
78 #define HAVE_INLINE_FLSL
80 static __inline __pure2 int
84 return (mask == 0 ? 0 :
85 8 * sizeof(mask) - __builtin_clzl((u_long)mask));
88 #define HAVE_INLINE_FLSLL
90 static __inline __pure2 int
94 return (mask == 0 ? 0 :
95 8 * sizeof(mask) - __builtin_clzll((unsigned long long)mask));
98 #include <machine/armreg.h>
100 void pan_enable(void);
102 static __inline register_t
109 "msr daifset, #(" __XSTRING(DAIF_D) ") \n"
119 __asm __volatile("msr daifclr, #(" __XSTRING(DAIF_D) ")");
122 static __inline register_t
125 /* DAIF is a 32-bit register */
130 "msr daifset, #(" __XSTRING(DAIF_INTR) ") \n"
137 intr_restore(register_t s)
140 WRITE_SPECIALREG(daif, s);
147 __asm __volatile("msr daifclr, #(" __XSTRING(DAIF_INTR) ")");
154 __asm __volatile("msr daifclr, #(" __XSTRING(DAIF_A) ")");
157 static __inline register_t
162 midr = READ_SPECIALREG(midr_el1);
167 static __inline register_t
172 mpidr = READ_SPECIALREG(mpidr_el1);
182 * Ensure compiler barrier, otherwise the monitor clear might
183 * occur too late for us ?
185 __asm __volatile("clrex" : : : "memory");
189 set_ttbr0(uint64_t ttbr0)
193 "msr ttbr0_el1, %0 \n"
200 invalidate_icache(void)
210 invalidate_local_icache(void)
219 extern bool icache_aliasing;
220 extern bool icache_vmid;
222 extern int64_t dcache_line_size;
223 extern int64_t icache_line_size;
224 extern int64_t idcache_line_size;
225 extern int64_t dczva_line_size;
227 #define cpu_nullop() arm64_nullop()
228 #define cpufunc_nullop() arm64_nullop()
230 #define cpu_tlb_flushID() arm64_tlb_flushID()
232 #define cpu_dcache_wbinv_range(a, s) arm64_dcache_wbinv_range((a), (s))
233 #define cpu_dcache_inv_range(a, s) arm64_dcache_inv_range((a), (s))
234 #define cpu_dcache_wb_range(a, s) arm64_dcache_wb_range((a), (s))
236 extern void (*arm64_icache_sync_range)(vm_offset_t, vm_size_t);
238 #define cpu_icache_sync_range(a, s) arm64_icache_sync_range((a), (s))
239 #define cpu_icache_sync_range_checked(a, s) arm64_icache_sync_range_checked((a), (s))
241 void arm64_nullop(void);
242 void arm64_tlb_flushID(void);
243 void arm64_dic_idc_icache_sync_range(vm_offset_t, vm_size_t);
244 void arm64_aliasing_icache_sync_range(vm_offset_t, vm_size_t);
245 int arm64_icache_sync_range_checked(vm_offset_t, vm_size_t);
246 void arm64_dcache_wbinv_range(vm_offset_t, vm_size_t);
247 void arm64_dcache_inv_range(vm_offset_t, vm_size_t);
248 void arm64_dcache_wb_range(vm_offset_t, vm_size_t);
249 bool arm64_get_writable_addr(vm_offset_t, vm_offset_t *);
252 #endif /* _MACHINE_CPUFUNC_H_ */