1825088edSmatt /* cpufunc.h,v 1.40.22.4 2007/11/08 10:59:33 matt Exp */
2c1f753f9Sreinoud
3c1f753f9Sreinoud /*
4c1f753f9Sreinoud * Copyright (c) 1997 Mark Brinicombe.
5c1f753f9Sreinoud * Copyright (c) 1997 Causality Limited
6c1f753f9Sreinoud * All rights reserved.
7c1f753f9Sreinoud *
8c1f753f9Sreinoud * Redistribution and use in source and binary forms, with or without
9c1f753f9Sreinoud * modification, are permitted provided that the following conditions
10c1f753f9Sreinoud * are met:
11c1f753f9Sreinoud * 1. Redistributions of source code must retain the above copyright
12c1f753f9Sreinoud * notice, this list of conditions and the following disclaimer.
13c1f753f9Sreinoud * 2. Redistributions in binary form must reproduce the above copyright
14c1f753f9Sreinoud * notice, this list of conditions and the following disclaimer in the
15c1f753f9Sreinoud * documentation and/or other materials provided with the distribution.
16c1f753f9Sreinoud * 3. All advertising materials mentioning features or use of this software
17c1f753f9Sreinoud * must display the following acknowledgement:
18c1f753f9Sreinoud * This product includes software developed by Causality Limited.
19c1f753f9Sreinoud * 4. The name of Causality Limited may not be used to endorse or promote
20c1f753f9Sreinoud * products derived from this software without specific prior written
21c1f753f9Sreinoud * permission.
22c1f753f9Sreinoud *
23c1f753f9Sreinoud * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS
24c1f753f9Sreinoud * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25c1f753f9Sreinoud * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26c1f753f9Sreinoud * DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT,
27c1f753f9Sreinoud * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28c1f753f9Sreinoud * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29c1f753f9Sreinoud * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30c1f753f9Sreinoud * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31c1f753f9Sreinoud * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32c1f753f9Sreinoud * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33c1f753f9Sreinoud * SUCH DAMAGE.
34c1f753f9Sreinoud *
35c1f753f9Sreinoud * RiscBSD kernel project
36c1f753f9Sreinoud *
37c1f753f9Sreinoud * cpufunc.h
38c1f753f9Sreinoud *
39c1f753f9Sreinoud * Prototypes for cpu, mmu and tlb related functions.
40c1f753f9Sreinoud */
41c1f753f9Sreinoud
422e13731dSmatt #ifndef _ARM_CPUFUNC_H_
432e13731dSmatt #define _ARM_CPUFUNC_H_
44c1f753f9Sreinoud
457c77f45cSskrll #ifdef _ARM_ARCH_7
46767a8892Sskrll /*
47767a8892Sskrll * Options for DMB and DSB:
48767a8892Sskrll * oshld Outer Shareable, load
49767a8892Sskrll * oshst Outer Shareable, store
50767a8892Sskrll * osh Outer Shareable, all
51767a8892Sskrll * nshld Non-shareable, load
52767a8892Sskrll * nshst Non-shareable, store
53767a8892Sskrll * nsh Non-shareable, all
54767a8892Sskrll * ishld Inner Shareable, load
55767a8892Sskrll * ishst Inner Shareable, store
56767a8892Sskrll * ish Inner Shareable, all
57767a8892Sskrll * ld Full system, load
58767a8892Sskrll * st Full system, store
59767a8892Sskrll * sy Full system, all
60767a8892Sskrll */
61767a8892Sskrll #define dsb(opt) __asm __volatile("dsb " __STRING(opt) : : : "memory")
62767a8892Sskrll #define dmb(opt) __asm __volatile("dmb " __STRING(opt) : : : "memory")
63428cf2f3Sskrll #define isb() __asm __volatile("isb" : : : "memory")
6469120ac1Sskrll #define sev() __asm __volatile("sev" : : : "memory")
65428cf2f3Sskrll
667c77f45cSskrll #else
677c77f45cSskrll
687c77f45cSskrll #define dsb(opt) \
697c77f45cSskrll __asm __volatile("mcr p15, 0, %0, c7, c10, 4" :: "r" (0) : "memory")
707c77f45cSskrll #define dmb(opt) \
717c77f45cSskrll __asm __volatile("mcr p15, 0, %0, c7, c10, 5" :: "r" (0) : "memory")
72428cf2f3Sskrll #define isb() \
73428cf2f3Sskrll __asm __volatile("mcr p15, 0, %0, c7, c5, 4" :: "r" (0) : "memory")
7469120ac1Sskrll #define sev() __nothing
757c77f45cSskrll
767c77f45cSskrll #endif
77767a8892Sskrll
78fe33aa27Sryo #ifdef __arm__
79fe33aa27Sryo
80c1f753f9Sreinoud #ifdef _KERNEL
8132a08607Sthorpej
8232a08607Sthorpej #include <sys/types.h>
83fe33aa27Sryo
84825088edSmatt #include <arm/armreg.h>
8532a08607Sthorpej #include <arm/cpuconf.h>
8637052397Schristos #include <arm/cpufunc_proto.h>
87c1f753f9Sreinoud
88c1f753f9Sreinoud struct cpu_functions {
89c1f753f9Sreinoud
90c1f753f9Sreinoud /* CPU functions */
91c1f753f9Sreinoud
92d4eec840Sbjh21 u_int (*cf_id) (void);
93d4eec840Sbjh21 void (*cf_cpwait) (void);
94c1f753f9Sreinoud
95c1f753f9Sreinoud /* MMU functions */
96c1f753f9Sreinoud
97d4eec840Sbjh21 u_int (*cf_control) (u_int, u_int);
98d4eec840Sbjh21 void (*cf_domains) (u_int);
9979d29d46Smatt #if defined(ARM_MMU_EXTENDED)
10079d29d46Smatt void (*cf_setttb) (u_int, tlb_asid_t);
10179d29d46Smatt #else
102ee6cde04Smatt void (*cf_setttb) (u_int, bool);
10379d29d46Smatt #endif
104d4eec840Sbjh21 u_int (*cf_faultstatus) (void);
105d4eec840Sbjh21 u_int (*cf_faultaddress) (void);
106c1f753f9Sreinoud
107c1f753f9Sreinoud /* TLB functions */
108c1f753f9Sreinoud
109d4eec840Sbjh21 void (*cf_tlb_flushID) (void);
110d841a68aSmatt void (*cf_tlb_flushID_SE) (vaddr_t);
111d4eec840Sbjh21 void (*cf_tlb_flushI) (void);
112d841a68aSmatt void (*cf_tlb_flushI_SE) (vaddr_t);
113d4eec840Sbjh21 void (*cf_tlb_flushD) (void);
114d841a68aSmatt void (*cf_tlb_flushD_SE) (vaddr_t);
115c1f753f9Sreinoud
1164e990d9cSthorpej /*
1174e990d9cSthorpej * Cache operations:
1184e990d9cSthorpej *
1194e990d9cSthorpej * We define the following primitives:
1204e990d9cSthorpej *
1214e990d9cSthorpej * icache_sync_all Synchronize I-cache
1224e990d9cSthorpej * icache_sync_range Synchronize I-cache range
1234e990d9cSthorpej *
1244e990d9cSthorpej * dcache_wbinv_all Write-back and Invalidate D-cache
1254e990d9cSthorpej * dcache_wbinv_range Write-back and Invalidate D-cache range
1264e990d9cSthorpej * dcache_inv_range Invalidate D-cache range
1274e990d9cSthorpej * dcache_wb_range Write-back D-cache range
1284e990d9cSthorpej *
1294e990d9cSthorpej * idcache_wbinv_all Write-back and Invalidate D-cache,
1304e990d9cSthorpej * Invalidate I-cache
1314e990d9cSthorpej * idcache_wbinv_range Write-back and Invalidate D-cache,
1324e990d9cSthorpej * Invalidate I-cache range
1334e990d9cSthorpej *
1344e990d9cSthorpej * Note that the ARM term for "write-back" is "clean". We use
1354e990d9cSthorpej * the term "write-back" since it's a more common way to describe
1364e990d9cSthorpej * the operation.
1374e990d9cSthorpej *
1384e990d9cSthorpej * There are some rules that must be followed:
1394e990d9cSthorpej *
1404e990d9cSthorpej * I-cache Synch (all or range):
1414e990d9cSthorpej * The goal is to synchronize the instruction stream,
1424e990d9cSthorpej * so you may beed to write-back dirty D-cache blocks
1434e990d9cSthorpej * first. If a range is requested, and you can't
1444e990d9cSthorpej * synchronize just a range, you have to hit the whole
1454e990d9cSthorpej * thing.
1464e990d9cSthorpej *
1474e990d9cSthorpej * D-cache Write-Back and Invalidate range:
1484e990d9cSthorpej * If you can't WB-Inv a range, you must WB-Inv the
1494e990d9cSthorpej * entire D-cache.
1504e990d9cSthorpej *
1514e990d9cSthorpej * D-cache Invalidate:
1524e990d9cSthorpej * If you can't Inv the D-cache, you must Write-Back
1534e990d9cSthorpej * and Invalidate. Code that uses this operation
1544e990d9cSthorpej * MUST NOT assume that the D-cache will not be written
1554e990d9cSthorpej * back to memory.
1564e990d9cSthorpej *
1574e990d9cSthorpej * D-cache Write-Back:
1584e990d9cSthorpej * If you can't Write-back without doing an Inv,
1594e990d9cSthorpej * that's fine. Then treat this as a WB-Inv.
1604e990d9cSthorpej * Skipping the invalidate is merely an optimization.
1614e990d9cSthorpej *
1624e990d9cSthorpej * All operations:
1634e990d9cSthorpej * Valid virtual addresses must be passed to each
1644e990d9cSthorpej * cache operation.
1654e990d9cSthorpej */
166d4eec840Sbjh21 void (*cf_icache_sync_all) (void);
167d4eec840Sbjh21 void (*cf_icache_sync_range) (vaddr_t, vsize_t);
168c1f753f9Sreinoud
169d4eec840Sbjh21 void (*cf_dcache_wbinv_all) (void);
170d4eec840Sbjh21 void (*cf_dcache_wbinv_range)(vaddr_t, vsize_t);
171d4eec840Sbjh21 void (*cf_dcache_inv_range) (vaddr_t, vsize_t);
172d4eec840Sbjh21 void (*cf_dcache_wb_range) (vaddr_t, vsize_t);
173c1f753f9Sreinoud
174653e56c7Smatt void (*cf_sdcache_wbinv_range)(vaddr_t, paddr_t, psize_t);
175653e56c7Smatt void (*cf_sdcache_inv_range) (vaddr_t, paddr_t, psize_t);
176653e56c7Smatt void (*cf_sdcache_wb_range) (vaddr_t, paddr_t, psize_t);
177653e56c7Smatt
178d4eec840Sbjh21 void (*cf_idcache_wbinv_all) (void);
179d4eec840Sbjh21 void (*cf_idcache_wbinv_range)(vaddr_t, vsize_t);
180c1f753f9Sreinoud
181c1f753f9Sreinoud /* Other functions */
182c1f753f9Sreinoud
183d4eec840Sbjh21 void (*cf_flush_prefetchbuf) (void);
184d4eec840Sbjh21 void (*cf_drain_writebuf) (void);
185d4eec840Sbjh21 void (*cf_flush_brnchtgt_C) (void);
186d4eec840Sbjh21 void (*cf_flush_brnchtgt_E) (u_int);
187c1f753f9Sreinoud
188d4eec840Sbjh21 void (*cf_sleep) (int mode);
189c1f753f9Sreinoud
190c1f753f9Sreinoud /* Soft functions */
191c1f753f9Sreinoud
192d4eec840Sbjh21 int (*cf_dataabt_fixup) (void *);
193d4eec840Sbjh21 int (*cf_prefetchabt_fixup) (void *);
194c1f753f9Sreinoud
19579d29d46Smatt #if defined(ARM_MMU_EXTENDED)
19679d29d46Smatt void (*cf_context_switch) (u_int, tlb_asid_t);
19779d29d46Smatt #else
198e73cf3caSscw void (*cf_context_switch) (u_int);
19979d29d46Smatt #endif
200c1f753f9Sreinoud
201d4eec840Sbjh21 void (*cf_setup) (char *);
202c1f753f9Sreinoud };
203c1f753f9Sreinoud
204c1f753f9Sreinoud extern struct cpu_functions cpufuncs;
205c1f753f9Sreinoud extern u_int cputype;
206c1f753f9Sreinoud
2078cd0a7d1Schristos #define cpu_idnum() cpufuncs.cf_id()
208c1f753f9Sreinoud
209c1f753f9Sreinoud #define cpu_control(c, e) cpufuncs.cf_control(c, e)
210c1f753f9Sreinoud #define cpu_domains(d) cpufuncs.cf_domains(d)
211ee6cde04Smatt #define cpu_setttb(t, f) cpufuncs.cf_setttb(t, f)
212c1f753f9Sreinoud #define cpu_faultstatus() cpufuncs.cf_faultstatus()
213c1f753f9Sreinoud #define cpu_faultaddress() cpufuncs.cf_faultaddress()
214c1f753f9Sreinoud
215c1f753f9Sreinoud #define cpu_tlb_flushID() cpufuncs.cf_tlb_flushID()
216c1f753f9Sreinoud #define cpu_tlb_flushID_SE(e) cpufuncs.cf_tlb_flushID_SE(e)
217c1f753f9Sreinoud #define cpu_tlb_flushI() cpufuncs.cf_tlb_flushI()
218c1f753f9Sreinoud #define cpu_tlb_flushI_SE(e) cpufuncs.cf_tlb_flushI_SE(e)
219c1f753f9Sreinoud #define cpu_tlb_flushD() cpufuncs.cf_tlb_flushD()
220c1f753f9Sreinoud #define cpu_tlb_flushD_SE(e) cpufuncs.cf_tlb_flushD_SE(e)
221c1f753f9Sreinoud
2224e990d9cSthorpej #define cpu_icache_sync_all() cpufuncs.cf_icache_sync_all()
2234e990d9cSthorpej #define cpu_icache_sync_range(a, s) cpufuncs.cf_icache_sync_range((a), (s))
2244e990d9cSthorpej
2254e990d9cSthorpej #define cpu_dcache_wbinv_all() cpufuncs.cf_dcache_wbinv_all()
2264e990d9cSthorpej #define cpu_dcache_wbinv_range(a, s) cpufuncs.cf_dcache_wbinv_range((a), (s))
2274e990d9cSthorpej #define cpu_dcache_inv_range(a, s) cpufuncs.cf_dcache_inv_range((a), (s))
2284e990d9cSthorpej #define cpu_dcache_wb_range(a, s) cpufuncs.cf_dcache_wb_range((a), (s))
2294e990d9cSthorpej
230653e56c7Smatt #define cpu_sdcache_wbinv_range(a, b, s) cpufuncs.cf_sdcache_wbinv_range((a), (b), (s))
231653e56c7Smatt #define cpu_sdcache_inv_range(a, b, s) cpufuncs.cf_sdcache_inv_range((a), (b), (s))
232653e56c7Smatt #define cpu_sdcache_wb_range(a, b, s) cpufuncs.cf_sdcache_wb_range((a), (b), (s))
233653e56c7Smatt
2344e990d9cSthorpej #define cpu_idcache_wbinv_all() cpufuncs.cf_idcache_wbinv_all()
2354e990d9cSthorpej #define cpu_idcache_wbinv_range(a, s) cpufuncs.cf_idcache_wbinv_range((a), (s))
236c1f753f9Sreinoud
237c1f753f9Sreinoud #define cpu_flush_prefetchbuf() cpufuncs.cf_flush_prefetchbuf()
238c1f753f9Sreinoud #define cpu_drain_writebuf() cpufuncs.cf_drain_writebuf()
239c1f753f9Sreinoud #define cpu_flush_brnchtgt_C() cpufuncs.cf_flush_brnchtgt_C()
240c1f753f9Sreinoud #define cpu_flush_brnchtgt_E(e) cpufuncs.cf_flush_brnchtgt_E(e)
241c1f753f9Sreinoud
242c1f753f9Sreinoud #define cpu_sleep(m) cpufuncs.cf_sleep(m)
243c1f753f9Sreinoud
244c1f753f9Sreinoud #define cpu_dataabt_fixup(a) cpufuncs.cf_dataabt_fixup(a)
245c1f753f9Sreinoud #define cpu_prefetchabt_fixup(a) cpufuncs.cf_prefetchabt_fixup(a)
246d3755353Swiz #define ABORT_FIXUP_OK 0 /* fixup succeeded */
247c1f753f9Sreinoud #define ABORT_FIXUP_FAILED 1 /* fixup failed */
248c1f753f9Sreinoud #define ABORT_FIXUP_RETURN 2 /* abort handler should return */
249c1f753f9Sreinoud
250e73cf3caSscw #define cpu_context_switch(a) cpufuncs.cf_context_switch(a)
251c1f753f9Sreinoud #define cpu_setup(a) cpufuncs.cf_setup(a)
252c1f753f9Sreinoud
253d4eec840Sbjh21 int set_cpufuncs (void);
2545dbe04b4Sbjh21 int set_cpufuncs_id (u_int);
255c1f753f9Sreinoud #define ARCHITECTURE_NOT_PRESENT 1 /* known but not configured */
256c1f753f9Sreinoud #define ARCHITECTURE_NOT_SUPPORTED 2 /* not known */
257c1f753f9Sreinoud
258d4eec840Sbjh21 void cpufunc_nullop (void);
259d4eec840Sbjh21 int cpufunc_null_fixup (void *);
260d4eec840Sbjh21 int early_abort_fixup (void *);
261d4eec840Sbjh21 int late_abort_fixup (void *);
262d4eec840Sbjh21 u_int cpufunc_id (void);
263d4eec840Sbjh21 u_int cpufunc_control (u_int, u_int);
264d4eec840Sbjh21 void cpufunc_domains (u_int);
265d4eec840Sbjh21 u_int cpufunc_faultstatus (void);
266d4eec840Sbjh21 u_int cpufunc_faultaddress (void);
267c1f753f9Sreinoud
26820e97df7Smatt #if defined(CPU_XSCALE)
26920e97df7Smatt #define cpu_cpwait() cpufuncs.cf_cpwait()
27020e97df7Smatt #endif
27120e97df7Smatt
272cf20f24bSchris #ifndef cpu_cpwait
273cf20f24bSchris #define cpu_cpwait()
274cf20f24bSchris #endif
275cf20f24bSchris
276c1f753f9Sreinoud /*
277c1f753f9Sreinoud * Macros for manipulating CPU interrupts
278c1f753f9Sreinoud */
27908a4aba7Sskrll static __inline uint32_t __set_cpsr_c(uint32_t bic, uint32_t eor) __attribute__((__unused__));
28008a4aba7Sskrll static __inline uint32_t disable_interrupts(uint32_t mask) __attribute__((__unused__));
28108a4aba7Sskrll static __inline uint32_t enable_interrupts(uint32_t mask) __attribute__((__unused__));
2824bb5ae3dSbriggs
283cf20f24bSchris static __inline uint32_t
__set_cpsr_c(uint32_t bic,uint32_t eor)284cf20f24bSchris __set_cpsr_c(uint32_t bic, uint32_t eor)
2854bb5ae3dSbriggs {
286cf20f24bSchris uint32_t tmp, ret;
2874bb5ae3dSbriggs
2885f1c88d7Sperry __asm volatile(
2894bb5ae3dSbriggs "mrs %0, cpsr\n" /* Get the CPSR */
2904bb5ae3dSbriggs "bic %1, %0, %2\n" /* Clear bits */
2914bb5ae3dSbriggs "eor %1, %1, %3\n" /* XOR bits */
2924bb5ae3dSbriggs "msr cpsr_c, %1\n" /* Set the control field of CPSR */
2934bb5ae3dSbriggs : "=&r" (ret), "=&r" (tmp)
2949264ede4Srearnsha : "r" (bic), "r" (eor) : "memory");
2954bb5ae3dSbriggs
2964bb5ae3dSbriggs return ret;
2974bb5ae3dSbriggs }
2984bb5ae3dSbriggs
299cf20f24bSchris static __inline uint32_t
disable_interrupts(uint32_t mask)300cf20f24bSchris disable_interrupts(uint32_t mask)
301cf20f24bSchris {
302cf20f24bSchris uint32_t tmp, ret;
303cf20f24bSchris mask &= (I32_bit | F32_bit);
304c1f753f9Sreinoud
305cf20f24bSchris __asm volatile(
306cf20f24bSchris "mrs %0, cpsr\n" /* Get the CPSR */
307cf20f24bSchris "orr %1, %0, %2\n" /* set bits */
308cf20f24bSchris "msr cpsr_c, %1\n" /* Set the control field of CPSR */
309cf20f24bSchris : "=&r" (ret), "=&r" (tmp)
310cf20f24bSchris : "r" (mask)
311cf20f24bSchris : "memory");
312cf20f24bSchris
313cf20f24bSchris return ret;
314cf20f24bSchris }
315cf20f24bSchris
316cf20f24bSchris static __inline uint32_t
enable_interrupts(uint32_t mask)317cf20f24bSchris enable_interrupts(uint32_t mask)
318cf20f24bSchris {
31979d29d46Smatt uint32_t ret;
320cf20f24bSchris mask &= (I32_bit | F32_bit);
321cf20f24bSchris
32279d29d46Smatt /* Get the CPSR */
32379d29d46Smatt __asm __volatile("mrs\t%0, cpsr\n" : "=r"(ret));
32479d29d46Smatt #ifdef _ARM_ARCH_6
32579d29d46Smatt if (__builtin_constant_p(mask)) {
32679d29d46Smatt switch (mask) {
32779d29d46Smatt case I32_bit | F32_bit:
32879d29d46Smatt __asm __volatile("cpsie\tif");
32979d29d46Smatt break;
33079d29d46Smatt case I32_bit:
33179d29d46Smatt __asm __volatile("cpsie\ti");
33279d29d46Smatt break;
33379d29d46Smatt case F32_bit:
33479d29d46Smatt __asm __volatile("cpsie\tf");
33579d29d46Smatt break;
33679d29d46Smatt default:
33779d29d46Smatt break;
33879d29d46Smatt }
33979d29d46Smatt return ret;
34079d29d46Smatt }
34179d29d46Smatt #endif /* _ARM_ARCH_6 */
34279d29d46Smatt
34379d29d46Smatt /* Set the control field of CPSR */
34479d29d46Smatt __asm volatile("msr\tcpsr_c, %0" :: "r"(ret & ~mask));
345cf20f24bSchris
346cf20f24bSchris return ret;
347cf20f24bSchris }
348c1f753f9Sreinoud
349c1f753f9Sreinoud #define restore_interrupts(old_cpsr) \
3504bb5ae3dSbriggs (__set_cpsr_c((I32_bit | F32_bit), (old_cpsr) & (I32_bit | F32_bit)))
351825088edSmatt
352f0c0b047Sjmcneill #define ENABLE_INTERRUPT() cpsie(I32_bit)
353f0c0b047Sjmcneill #define DISABLE_INTERRUPT() cpsid(I32_bit)
354*9feefd4bSjmcneill #define DISABLE_INTERRUPT_SAVE() cpsid(I32_bit)
355f0c0b047Sjmcneill
356825088edSmatt static inline void cpsie(register_t psw) __attribute__((__unused__));
357825088edSmatt static inline register_t cpsid(register_t psw) __attribute__((__unused__));
358825088edSmatt
359825088edSmatt static inline void
cpsie(register_t psw)360825088edSmatt cpsie(register_t psw)
361825088edSmatt {
36231ebcdb4Smatt #ifdef _ARM_ARCH_6
363825088edSmatt if (!__builtin_constant_p(psw)) {
364825088edSmatt enable_interrupts(psw);
365825088edSmatt return;
366825088edSmatt }
367825088edSmatt switch (psw & (I32_bit|F32_bit)) {
368825088edSmatt case I32_bit: __asm("cpsie\ti"); break;
369825088edSmatt case F32_bit: __asm("cpsie\tf"); break;
370825088edSmatt case I32_bit|F32_bit: __asm("cpsie\tif"); break;
371825088edSmatt }
372c73ebb00Scliff #else
373c73ebb00Scliff enable_interrupts(psw);
374c73ebb00Scliff #endif
375825088edSmatt }
376825088edSmatt
377825088edSmatt static inline register_t
cpsid(register_t psw)378825088edSmatt cpsid(register_t psw)
379825088edSmatt {
38031ebcdb4Smatt #ifdef _ARM_ARCH_6
381825088edSmatt register_t oldpsw;
382825088edSmatt if (!__builtin_constant_p(psw))
383825088edSmatt return disable_interrupts(psw);
384825088edSmatt
385825088edSmatt __asm("mrs %0, cpsr" : "=r"(oldpsw));
386825088edSmatt switch (psw & (I32_bit|F32_bit)) {
387825088edSmatt case I32_bit: __asm("cpsid\ti"); break;
388825088edSmatt case F32_bit: __asm("cpsid\tf"); break;
389825088edSmatt case I32_bit|F32_bit: __asm("cpsid\tif"); break;
390825088edSmatt }
391825088edSmatt return oldpsw;
392c73ebb00Scliff #else
393c73ebb00Scliff return disable_interrupts(psw);
394c73ebb00Scliff #endif
395825088edSmatt }
396825088edSmatt
397c1f753f9Sreinoud
39801415786Sthorpej /* Functions to manipulate the CPSR. */
3997f3b59beSuwe u_int SetCPSR(u_int, u_int);
40001415786Sthorpej u_int GetCPSR(void);
401c1f753f9Sreinoud
402261bd8f8Sbjh21
403261bd8f8Sbjh21 /*
404c1f753f9Sreinoud * CPU functions from locore.S
405c1f753f9Sreinoud */
406c1f753f9Sreinoud
407ce2db8d3Smatt void cpu_reset (void) __dead;
408c1f753f9Sreinoud
4095dc817e3Smrg #if (ARM_MMU_V6 + ARM_MMU_V7) != 0
410ce2db8d3Smatt extern u_int arm_cache_prefer_mask;
4115dc817e3Smrg #endif
412ce2db8d3Smatt extern u_int arm_dcache_align;
413ce2db8d3Smatt extern u_int arm_dcache_align_mask;
414959181a8Sthorpej
415ce2db8d3Smatt extern struct arm_cache_info arm_pcache;
416ce2db8d3Smatt extern struct arm_cache_info arm_scache;
417fe33aa27Sryo
418b206c0dbSskrll extern uint32_t cpu_ttb;
419b206c0dbSskrll
420c1f753f9Sreinoud #endif /* _KERNEL */
421529515a4Schristos
422529515a4Schristos #if defined(_KERNEL) || defined(_KMEMUSER)
423529515a4Schristos /*
424529515a4Schristos * Miscellany
425529515a4Schristos */
426529515a4Schristos
427529515a4Schristos int get_pc_str_offset (void);
428529515a4Schristos
429fe33aa27Sryo bool cpu_gtmr_exists_p(void);
430fe33aa27Sryo u_int cpu_clusterid(void);
431fe33aa27Sryo bool cpu_earlydevice_va_p(void);
432fe33aa27Sryo
433529515a4Schristos /*
434529515a4Schristos * Functions to manipulate cpu r13
435529515a4Schristos * (in arm/arm32/setstack.S)
436529515a4Schristos */
437529515a4Schristos
438529515a4Schristos void set_stackptr (u_int, u_int);
439529515a4Schristos u_int get_stackptr (u_int);
440529515a4Schristos
441529515a4Schristos #endif /* _KERNEL || _KMEMUSER */
442529515a4Schristos
443fe33aa27Sryo #elif defined(__aarch64__)
444fe33aa27Sryo
445fe33aa27Sryo #include <aarch64/cpufunc.h>
446fe33aa27Sryo
447fe33aa27Sryo #endif /* __arm__/__aarch64__ */
448fe33aa27Sryo
4492e13731dSmatt #endif /* _ARM_CPUFUNC_H_ */
450c1f753f9Sreinoud
451c1f753f9Sreinoud /* End of cpufunc.h */
452