Home | History | Annotate | Line # | Download | only in include
cpufunc.h revision 1.85
      1  1.45      matt /*	cpufunc.h,v 1.40.22.4 2007/11/08 10:59:33 matt Exp	*/
      2   1.1   reinoud 
      3   1.1   reinoud /*
      4   1.1   reinoud  * Copyright (c) 1997 Mark Brinicombe.
      5   1.1   reinoud  * Copyright (c) 1997 Causality Limited
      6   1.1   reinoud  * All rights reserved.
      7   1.1   reinoud  *
      8   1.1   reinoud  * Redistribution and use in source and binary forms, with or without
      9   1.1   reinoud  * modification, are permitted provided that the following conditions
     10   1.1   reinoud  * are met:
     11   1.1   reinoud  * 1. Redistributions of source code must retain the above copyright
     12   1.1   reinoud  *    notice, this list of conditions and the following disclaimer.
     13   1.1   reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1   reinoud  *    notice, this list of conditions and the following disclaimer in the
     15   1.1   reinoud  *    documentation and/or other materials provided with the distribution.
     16   1.1   reinoud  * 3. All advertising materials mentioning features or use of this software
     17   1.1   reinoud  *    must display the following acknowledgement:
     18   1.1   reinoud  *	This product includes software developed by Causality Limited.
     19   1.1   reinoud  * 4. The name of Causality Limited may not be used to endorse or promote
     20   1.1   reinoud  *    products derived from this software without specific prior written
     21   1.1   reinoud  *    permission.
     22   1.1   reinoud  *
     23   1.1   reinoud  * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS
     24   1.1   reinoud  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     25   1.1   reinoud  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     26   1.1   reinoud  * DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT,
     27   1.1   reinoud  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28   1.1   reinoud  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29   1.1   reinoud  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1   reinoud  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1   reinoud  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1   reinoud  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1   reinoud  * SUCH DAMAGE.
     34   1.1   reinoud  *
     35   1.1   reinoud  * RiscBSD kernel project
     36   1.1   reinoud  *
     37   1.1   reinoud  * cpufunc.h
     38   1.1   reinoud  *
     39   1.1   reinoud  * Prototypes for cpu, mmu and tlb related functions.
     40   1.1   reinoud  */
     41   1.1   reinoud 
     42  1.65      matt #ifndef _ARM_CPUFUNC_H_
     43  1.65      matt #define _ARM_CPUFUNC_H_
     44   1.1   reinoud 
     45  1.84     skrll #ifdef _ARM_ARCH_7
     46  1.83     skrll /*
     47  1.83     skrll  * Options for DMB and DSB:
     48  1.83     skrll  *	oshld	Outer Shareable, load
     49  1.83     skrll  *	oshst	Outer Shareable, store
     50  1.83     skrll  *	osh	Outer Shareable, all
     51  1.83     skrll  *	nshld	Non-shareable, load
     52  1.83     skrll  *	nshst	Non-shareable, store
     53  1.83     skrll  *	nsh	Non-shareable, all
     54  1.83     skrll  *	ishld	Inner Shareable, load
     55  1.83     skrll  *	ishst	Inner Shareable, store
     56  1.83     skrll  *	ish	Inner Shareable, all
     57  1.83     skrll  *	ld	Full system, load
     58  1.83     skrll  *	st	Full system, store
     59  1.83     skrll  *	sy	Full system, all
     60  1.83     skrll  */
     61  1.83     skrll #define	dsb(opt)	__asm __volatile("dsb " __STRING(opt) : : : "memory")
     62  1.83     skrll #define	dmb(opt)	__asm __volatile("dmb " __STRING(opt) : : : "memory")
     63  1.85     skrll #define	isb()		__asm __volatile("isb" : : : "memory")
     64  1.85     skrll 
     65  1.84     skrll #else
     66  1.84     skrll 
     67  1.84     skrll #define dsb(opt)	\
     68  1.84     skrll 	__asm __volatile("mcr p15, 0, %0, c7, c10, 4" :: "r" (0) : "memory")
     69  1.84     skrll #define dmb(opt)	\
     70  1.84     skrll 	__asm __volatile("mcr p15, 0, %0, c7, c10, 5" :: "r" (0) : "memory")
     71  1.85     skrll #define isb()		\
     72  1.85     skrll 	__asm __volatile("mcr p15, 0, %0, c7, c5, 4" :: "r" (0) : "memory")
     73  1.84     skrll 
     74  1.84     skrll #endif
     75  1.83     skrll 
     76  1.79       ryo #ifdef __arm__
     77  1.79       ryo 
     78  1.21   thorpej #ifdef _KERNEL
     79  1.21   thorpej 
     80   1.1   reinoud #include <sys/types.h>
     81  1.79       ryo 
     82  1.45      matt #include <arm/armreg.h>
     83  1.21   thorpej #include <arm/cpuconf.h>
     84  1.74  christos #include <arm/cpufunc_proto.h>
     85   1.1   reinoud 
     86   1.1   reinoud struct cpu_functions {
     87   1.1   reinoud 
     88   1.1   reinoud 	/* CPU functions */
     89  1.32       uwe 
     90  1.39     bjh21 	u_int	(*cf_id)		(void);
     91  1.39     bjh21 	void	(*cf_cpwait)		(void);
     92   1.1   reinoud 
     93   1.1   reinoud 	/* MMU functions */
     94   1.1   reinoud 
     95  1.39     bjh21 	u_int	(*cf_control)		(u_int, u_int);
     96  1.39     bjh21 	void	(*cf_domains)		(u_int);
     97  1.69      matt #if defined(ARM_MMU_EXTENDED)
     98  1.69      matt 	void	(*cf_setttb)		(u_int, tlb_asid_t);
     99  1.69      matt #else
    100  1.60      matt 	void	(*cf_setttb)		(u_int, bool);
    101  1.69      matt #endif
    102  1.39     bjh21 	u_int	(*cf_faultstatus)	(void);
    103  1.39     bjh21 	u_int	(*cf_faultaddress)	(void);
    104   1.1   reinoud 
    105   1.1   reinoud 	/* TLB functions */
    106   1.1   reinoud 
    107  1.39     bjh21 	void	(*cf_tlb_flushID)	(void);
    108  1.66      matt 	void	(*cf_tlb_flushID_SE)	(vaddr_t);
    109  1.39     bjh21 	void	(*cf_tlb_flushI)	(void);
    110  1.66      matt 	void	(*cf_tlb_flushI_SE)	(vaddr_t);
    111  1.39     bjh21 	void	(*cf_tlb_flushD)	(void);
    112  1.66      matt 	void	(*cf_tlb_flushD_SE)	(vaddr_t);
    113   1.1   reinoud 
    114  1.17   thorpej 	/*
    115  1.17   thorpej 	 * Cache operations:
    116  1.17   thorpej 	 *
    117  1.17   thorpej 	 * We define the following primitives:
    118  1.17   thorpej 	 *
    119  1.17   thorpej 	 *	icache_sync_all		Synchronize I-cache
    120  1.17   thorpej 	 *	icache_sync_range	Synchronize I-cache range
    121  1.17   thorpej 	 *
    122  1.17   thorpej 	 *	dcache_wbinv_all	Write-back and Invalidate D-cache
    123  1.17   thorpej 	 *	dcache_wbinv_range	Write-back and Invalidate D-cache range
    124  1.17   thorpej 	 *	dcache_inv_range	Invalidate D-cache range
    125  1.17   thorpej 	 *	dcache_wb_range		Write-back D-cache range
    126  1.17   thorpej 	 *
    127  1.17   thorpej 	 *	idcache_wbinv_all	Write-back and Invalidate D-cache,
    128  1.17   thorpej 	 *				Invalidate I-cache
    129  1.17   thorpej 	 *	idcache_wbinv_range	Write-back and Invalidate D-cache,
    130  1.17   thorpej 	 *				Invalidate I-cache range
    131  1.17   thorpej 	 *
    132  1.17   thorpej 	 * Note that the ARM term for "write-back" is "clean".  We use
    133  1.17   thorpej 	 * the term "write-back" since it's a more common way to describe
    134  1.17   thorpej 	 * the operation.
    135  1.17   thorpej 	 *
    136  1.17   thorpej 	 * There are some rules that must be followed:
    137  1.17   thorpej 	 *
    138  1.17   thorpej 	 *	I-cache Synch (all or range):
    139  1.17   thorpej 	 *		The goal is to synchronize the instruction stream,
    140  1.17   thorpej 	 *		so you may beed to write-back dirty D-cache blocks
    141  1.17   thorpej 	 *		first.  If a range is requested, and you can't
    142  1.17   thorpej 	 *		synchronize just a range, you have to hit the whole
    143  1.17   thorpej 	 *		thing.
    144  1.17   thorpej 	 *
    145  1.17   thorpej 	 *	D-cache Write-Back and Invalidate range:
    146  1.17   thorpej 	 *		If you can't WB-Inv a range, you must WB-Inv the
    147  1.17   thorpej 	 *		entire D-cache.
    148  1.17   thorpej 	 *
    149  1.17   thorpej 	 *	D-cache Invalidate:
    150  1.17   thorpej 	 *		If you can't Inv the D-cache, you must Write-Back
    151  1.17   thorpej 	 *		and Invalidate.  Code that uses this operation
    152  1.17   thorpej 	 *		MUST NOT assume that the D-cache will not be written
    153  1.17   thorpej 	 *		back to memory.
    154  1.17   thorpej 	 *
    155  1.17   thorpej 	 *	D-cache Write-Back:
    156  1.17   thorpej 	 *		If you can't Write-back without doing an Inv,
    157  1.17   thorpej 	 *		that's fine.  Then treat this as a WB-Inv.
    158  1.17   thorpej 	 *		Skipping the invalidate is merely an optimization.
    159  1.17   thorpej 	 *
    160  1.17   thorpej 	 *	All operations:
    161  1.17   thorpej 	 *		Valid virtual addresses must be passed to each
    162  1.17   thorpej 	 *		cache operation.
    163  1.17   thorpej 	 */
    164  1.39     bjh21 	void	(*cf_icache_sync_all)	(void);
    165  1.39     bjh21 	void	(*cf_icache_sync_range)	(vaddr_t, vsize_t);
    166  1.17   thorpej 
    167  1.39     bjh21 	void	(*cf_dcache_wbinv_all)	(void);
    168  1.39     bjh21 	void	(*cf_dcache_wbinv_range)(vaddr_t, vsize_t);
    169  1.39     bjh21 	void	(*cf_dcache_inv_range)	(vaddr_t, vsize_t);
    170  1.39     bjh21 	void	(*cf_dcache_wb_range)	(vaddr_t, vsize_t);
    171   1.1   reinoud 
    172  1.59      matt 	void	(*cf_sdcache_wbinv_range)(vaddr_t, paddr_t, psize_t);
    173  1.59      matt 	void	(*cf_sdcache_inv_range)	(vaddr_t, paddr_t, psize_t);
    174  1.59      matt 	void	(*cf_sdcache_wb_range)	(vaddr_t, paddr_t, psize_t);
    175  1.59      matt 
    176  1.39     bjh21 	void	(*cf_idcache_wbinv_all)	(void);
    177  1.39     bjh21 	void	(*cf_idcache_wbinv_range)(vaddr_t, vsize_t);
    178   1.1   reinoud 
    179   1.1   reinoud 	/* Other functions */
    180   1.1   reinoud 
    181  1.39     bjh21 	void	(*cf_flush_prefetchbuf)	(void);
    182  1.39     bjh21 	void	(*cf_drain_writebuf)	(void);
    183  1.39     bjh21 	void	(*cf_flush_brnchtgt_C)	(void);
    184  1.39     bjh21 	void	(*cf_flush_brnchtgt_E)	(u_int);
    185   1.1   reinoud 
    186  1.39     bjh21 	void	(*cf_sleep)		(int mode);
    187   1.1   reinoud 
    188   1.1   reinoud 	/* Soft functions */
    189   1.1   reinoud 
    190  1.39     bjh21 	int	(*cf_dataabt_fixup)	(void *);
    191  1.39     bjh21 	int	(*cf_prefetchabt_fixup)	(void *);
    192   1.1   reinoud 
    193  1.69      matt #if defined(ARM_MMU_EXTENDED)
    194  1.69      matt 	void	(*cf_context_switch)	(u_int, tlb_asid_t);
    195  1.69      matt #else
    196  1.41       scw 	void	(*cf_context_switch)	(u_int);
    197  1.69      matt #endif
    198   1.1   reinoud 
    199  1.39     bjh21 	void	(*cf_setup)		(char *);
    200   1.1   reinoud };
    201   1.1   reinoud 
    202   1.1   reinoud extern struct cpu_functions cpufuncs;
    203   1.1   reinoud extern u_int cputype;
    204   1.1   reinoud 
    205  1.76  christos #define cpu_idnum()		cpufuncs.cf_id()
    206   1.1   reinoud 
    207   1.1   reinoud #define cpu_control(c, e)	cpufuncs.cf_control(c, e)
    208   1.1   reinoud #define cpu_domains(d)		cpufuncs.cf_domains(d)
    209  1.60      matt #define cpu_setttb(t, f)	cpufuncs.cf_setttb(t, f)
    210   1.1   reinoud #define cpu_faultstatus()	cpufuncs.cf_faultstatus()
    211   1.1   reinoud #define cpu_faultaddress()	cpufuncs.cf_faultaddress()
    212   1.1   reinoud 
    213   1.1   reinoud #define	cpu_tlb_flushID()	cpufuncs.cf_tlb_flushID()
    214   1.1   reinoud #define	cpu_tlb_flushID_SE(e)	cpufuncs.cf_tlb_flushID_SE(e)
    215   1.1   reinoud #define	cpu_tlb_flushI()	cpufuncs.cf_tlb_flushI()
    216   1.1   reinoud #define	cpu_tlb_flushI_SE(e)	cpufuncs.cf_tlb_flushI_SE(e)
    217   1.1   reinoud #define	cpu_tlb_flushD()	cpufuncs.cf_tlb_flushD()
    218   1.1   reinoud #define	cpu_tlb_flushD_SE(e)	cpufuncs.cf_tlb_flushD_SE(e)
    219   1.1   reinoud 
    220  1.17   thorpej #define	cpu_icache_sync_all()	cpufuncs.cf_icache_sync_all()
    221  1.17   thorpej #define	cpu_icache_sync_range(a, s) cpufuncs.cf_icache_sync_range((a), (s))
    222  1.17   thorpej 
    223  1.17   thorpej #define	cpu_dcache_wbinv_all()	cpufuncs.cf_dcache_wbinv_all()
    224  1.17   thorpej #define	cpu_dcache_wbinv_range(a, s) cpufuncs.cf_dcache_wbinv_range((a), (s))
    225  1.17   thorpej #define	cpu_dcache_inv_range(a, s) cpufuncs.cf_dcache_inv_range((a), (s))
    226  1.17   thorpej #define	cpu_dcache_wb_range(a, s) cpufuncs.cf_dcache_wb_range((a), (s))
    227  1.17   thorpej 
    228  1.59      matt #define	cpu_sdcache_wbinv_range(a, b, s) cpufuncs.cf_sdcache_wbinv_range((a), (b), (s))
    229  1.59      matt #define	cpu_sdcache_inv_range(a, b, s) cpufuncs.cf_sdcache_inv_range((a), (b), (s))
    230  1.59      matt #define	cpu_sdcache_wb_range(a, b, s) cpufuncs.cf_sdcache_wb_range((a), (b), (s))
    231  1.59      matt 
    232  1.17   thorpej #define	cpu_idcache_wbinv_all()	cpufuncs.cf_idcache_wbinv_all()
    233  1.17   thorpej #define	cpu_idcache_wbinv_range(a, s) cpufuncs.cf_idcache_wbinv_range((a), (s))
    234   1.1   reinoud 
    235   1.1   reinoud #define	cpu_flush_prefetchbuf()	cpufuncs.cf_flush_prefetchbuf()
    236   1.1   reinoud #define	cpu_drain_writebuf()	cpufuncs.cf_drain_writebuf()
    237   1.1   reinoud #define	cpu_flush_brnchtgt_C()	cpufuncs.cf_flush_brnchtgt_C()
    238   1.1   reinoud #define	cpu_flush_brnchtgt_E(e)	cpufuncs.cf_flush_brnchtgt_E(e)
    239   1.1   reinoud 
    240   1.1   reinoud #define cpu_sleep(m)		cpufuncs.cf_sleep(m)
    241   1.1   reinoud 
    242   1.1   reinoud #define cpu_dataabt_fixup(a)		cpufuncs.cf_dataabt_fixup(a)
    243   1.1   reinoud #define cpu_prefetchabt_fixup(a)	cpufuncs.cf_prefetchabt_fixup(a)
    244   1.7       wiz #define ABORT_FIXUP_OK		0	/* fixup succeeded */
    245   1.1   reinoud #define ABORT_FIXUP_FAILED	1	/* fixup failed */
    246   1.1   reinoud #define ABORT_FIXUP_RETURN	2	/* abort handler should return */
    247   1.1   reinoud 
    248  1.41       scw #define cpu_context_switch(a)		cpufuncs.cf_context_switch(a)
    249   1.1   reinoud #define cpu_setup(a)			cpufuncs.cf_setup(a)
    250   1.1   reinoud 
    251  1.39     bjh21 int	set_cpufuncs		(void);
    252  1.40     bjh21 int	set_cpufuncs_id		(u_int);
    253   1.1   reinoud #define ARCHITECTURE_NOT_PRESENT	1	/* known but not configured */
    254   1.1   reinoud #define ARCHITECTURE_NOT_SUPPORTED	2	/* not known */
    255   1.1   reinoud 
    256  1.39     bjh21 void	cpufunc_nullop		(void);
    257  1.39     bjh21 int	cpufunc_null_fixup	(void *);
    258  1.39     bjh21 int	early_abort_fixup	(void *);
    259  1.39     bjh21 int	late_abort_fixup	(void *);
    260  1.39     bjh21 u_int	cpufunc_id		(void);
    261  1.39     bjh21 u_int	cpufunc_control		(u_int, u_int);
    262  1.39     bjh21 void	cpufunc_domains		(u_int);
    263  1.39     bjh21 u_int	cpufunc_faultstatus	(void);
    264  1.39     bjh21 u_int	cpufunc_faultaddress	(void);
    265   1.3     bjh21 
    266   1.1   reinoud #define setttb		cpu_setttb
    267   1.1   reinoud #define drain_writebuf	cpu_drain_writebuf
    268   1.1   reinoud 
    269  1.73      matt 
    270  1.73      matt #if defined(CPU_XSCALE)
    271  1.73      matt #define	cpu_cpwait()		cpufuncs.cf_cpwait()
    272  1.73      matt #endif
    273  1.73      matt 
    274  1.43     chris #ifndef cpu_cpwait
    275  1.43     chris #define	cpu_cpwait()
    276  1.43     chris #endif
    277  1.43     chris 
    278   1.1   reinoud /*
    279   1.1   reinoud  * Macros for manipulating CPU interrupts
    280   1.1   reinoud  */
    281  1.62     skrll static __inline uint32_t __set_cpsr_c(uint32_t bic, uint32_t eor) __attribute__((__unused__));
    282  1.62     skrll static __inline uint32_t disable_interrupts(uint32_t mask) __attribute__((__unused__));
    283  1.62     skrll static __inline uint32_t enable_interrupts(uint32_t mask) __attribute__((__unused__));
    284  1.25    briggs 
    285  1.43     chris static __inline uint32_t
    286  1.43     chris __set_cpsr_c(uint32_t bic, uint32_t eor)
    287  1.25    briggs {
    288  1.43     chris 	uint32_t	tmp, ret;
    289  1.25    briggs 
    290  1.36     perry 	__asm volatile(
    291  1.25    briggs 		"mrs     %0, cpsr\n"	/* Get the CPSR */
    292  1.25    briggs 		"bic	 %1, %0, %2\n"	/* Clear bits */
    293  1.25    briggs 		"eor	 %1, %1, %3\n"	/* XOR bits */
    294  1.25    briggs 		"msr     cpsr_c, %1\n"	/* Set the control field of CPSR */
    295  1.25    briggs 	: "=&r" (ret), "=&r" (tmp)
    296  1.31  rearnsha 	: "r" (bic), "r" (eor) : "memory");
    297  1.25    briggs 
    298  1.25    briggs 	return ret;
    299  1.25    briggs }
    300  1.25    briggs 
    301  1.43     chris static __inline uint32_t
    302  1.43     chris disable_interrupts(uint32_t mask)
    303  1.43     chris {
    304  1.43     chris 	uint32_t	tmp, ret;
    305  1.43     chris 	mask &= (I32_bit | F32_bit);
    306  1.43     chris 
    307  1.43     chris 	__asm volatile(
    308  1.43     chris 		"mrs     %0, cpsr\n"	/* Get the CPSR */
    309  1.43     chris 		"orr	 %1, %0, %2\n"	/* set bits */
    310  1.43     chris 		"msr     cpsr_c, %1\n"	/* Set the control field of CPSR */
    311  1.43     chris 	: "=&r" (ret), "=&r" (tmp)
    312  1.43     chris 	: "r" (mask)
    313  1.43     chris 	: "memory");
    314  1.43     chris 
    315  1.43     chris 	return ret;
    316  1.43     chris }
    317  1.43     chris 
    318  1.43     chris static __inline uint32_t
    319  1.43     chris enable_interrupts(uint32_t mask)
    320  1.43     chris {
    321  1.69      matt 	uint32_t	ret;
    322  1.43     chris 	mask &= (I32_bit | F32_bit);
    323  1.43     chris 
    324  1.69      matt 	/* Get the CPSR */
    325  1.69      matt 	__asm __volatile("mrs\t%0, cpsr\n" : "=r"(ret));
    326  1.69      matt #ifdef _ARM_ARCH_6
    327  1.69      matt 	if (__builtin_constant_p(mask)) {
    328  1.69      matt 		switch (mask) {
    329  1.69      matt 		case I32_bit | F32_bit:
    330  1.69      matt 			__asm __volatile("cpsie\tif");
    331  1.69      matt 			break;
    332  1.69      matt 		case I32_bit:
    333  1.69      matt 			__asm __volatile("cpsie\ti");
    334  1.69      matt 			break;
    335  1.69      matt 		case F32_bit:
    336  1.69      matt 			__asm __volatile("cpsie\tf");
    337  1.69      matt 			break;
    338  1.69      matt 		default:
    339  1.69      matt 			break;
    340  1.69      matt 		}
    341  1.69      matt 		return ret;
    342  1.69      matt 	}
    343  1.69      matt #endif /* _ARM_ARCH_6 */
    344  1.69      matt 
    345  1.69      matt 	/* Set the control field of CPSR */
    346  1.69      matt 	__asm volatile("msr\tcpsr_c, %0" :: "r"(ret & ~mask));
    347   1.1   reinoud 
    348  1.43     chris 	return ret;
    349  1.43     chris }
    350   1.1   reinoud 
    351  1.15   thorpej #define restore_interrupts(old_cpsr)					\
    352  1.25    briggs 	(__set_cpsr_c((I32_bit | F32_bit), (old_cpsr) & (I32_bit | F32_bit)))
    353  1.45      matt 
    354  1.45      matt static inline void cpsie(register_t psw) __attribute__((__unused__));
    355  1.45      matt static inline register_t cpsid(register_t psw) __attribute__((__unused__));
    356  1.45      matt 
    357  1.45      matt static inline void
    358  1.45      matt cpsie(register_t psw)
    359  1.45      matt {
    360  1.49      matt #ifdef _ARM_ARCH_6
    361  1.45      matt 	if (!__builtin_constant_p(psw)) {
    362  1.45      matt 		enable_interrupts(psw);
    363  1.45      matt 		return;
    364  1.45      matt 	}
    365  1.45      matt 	switch (psw & (I32_bit|F32_bit)) {
    366  1.45      matt 	case I32_bit:		__asm("cpsie\ti"); break;
    367  1.45      matt 	case F32_bit:		__asm("cpsie\tf"); break;
    368  1.45      matt 	case I32_bit|F32_bit:	__asm("cpsie\tif"); break;
    369  1.45      matt 	}
    370  1.48     cliff #else
    371  1.48     cliff 	enable_interrupts(psw);
    372  1.48     cliff #endif
    373  1.45      matt }
    374  1.45      matt 
    375  1.45      matt static inline register_t
    376  1.45      matt cpsid(register_t psw)
    377  1.45      matt {
    378  1.49      matt #ifdef _ARM_ARCH_6
    379  1.45      matt 	register_t oldpsw;
    380  1.45      matt 	if (!__builtin_constant_p(psw))
    381  1.45      matt 		return disable_interrupts(psw);
    382  1.45      matt 
    383  1.45      matt 	__asm("mrs	%0, cpsr" : "=r"(oldpsw));
    384  1.45      matt 	switch (psw & (I32_bit|F32_bit)) {
    385  1.45      matt 	case I32_bit:		__asm("cpsid\ti"); break;
    386  1.45      matt 	case F32_bit:		__asm("cpsid\tf"); break;
    387  1.45      matt 	case I32_bit|F32_bit:	__asm("cpsid\tif"); break;
    388  1.45      matt 	}
    389  1.45      matt 	return oldpsw;
    390  1.80     skrll #else
    391  1.48     cliff 	return disable_interrupts(psw);
    392  1.48     cliff #endif
    393  1.45      matt }
    394  1.45      matt 
    395  1.15   thorpej 
    396  1.15   thorpej /* Functions to manipulate the CPSR. */
    397  1.32       uwe u_int	SetCPSR(u_int, u_int);
    398  1.15   thorpej u_int	GetCPSR(void);
    399   1.1   reinoud 
    400   1.1   reinoud 
    401   1.1   reinoud /*
    402   1.1   reinoud  * CPU functions from locore.S
    403   1.1   reinoud  */
    404   1.1   reinoud 
    405  1.58      matt void cpu_reset		(void) __dead;
    406  1.14   thorpej 
    407  1.14   thorpej /*
    408  1.14   thorpej  * Cache info variables.
    409  1.14   thorpej  */
    410  1.67      matt #define	CACHE_TYPE_VIVT		0
    411  1.67      matt #define	CACHE_TYPE_xxPT		1
    412  1.67      matt #define	CACHE_TYPE_VIPT		1
    413  1.67      matt #define	CACHE_TYPE_PIxx		2
    414  1.67      matt #define	CACHE_TYPE_PIPT		3
    415  1.14   thorpej 
    416  1.14   thorpej /* PRIMARY CACHE VARIABLES */
    417  1.58      matt struct arm_cache_info {
    418  1.58      matt 	u_int icache_size;
    419  1.58      matt 	u_int icache_line_size;
    420  1.58      matt 	u_int icache_ways;
    421  1.68      matt 	u_int icache_way_size;
    422  1.58      matt 	u_int icache_sets;
    423  1.58      matt 
    424  1.58      matt 	u_int dcache_size;
    425  1.58      matt 	u_int dcache_line_size;
    426  1.58      matt 	u_int dcache_ways;
    427  1.68      matt 	u_int dcache_way_size;
    428  1.58      matt 	u_int dcache_sets;
    429  1.58      matt 
    430  1.69      matt 	uint8_t cache_type;
    431  1.58      matt 	bool cache_unified;
    432  1.67      matt 	uint8_t icache_type;
    433  1.67      matt 	uint8_t dcache_type;
    434  1.58      matt };
    435  1.58      matt 
    436  1.77       mrg #if (ARM_MMU_V6 + ARM_MMU_V7) != 0
    437  1.58      matt extern u_int arm_cache_prefer_mask;
    438  1.77       mrg #endif
    439  1.58      matt extern u_int arm_dcache_align;
    440  1.58      matt extern u_int arm_dcache_align_mask;
    441   1.1   reinoud 
    442  1.58      matt extern struct arm_cache_info arm_pcache;
    443  1.58      matt extern struct arm_cache_info arm_scache;
    444  1.79       ryo 
    445  1.81     skrll extern uint32_t cpu_ttb;
    446  1.81     skrll 
    447   1.1   reinoud #endif	/* _KERNEL */
    448  1.55  christos 
    449  1.55  christos #if defined(_KERNEL) || defined(_KMEMUSER)
    450  1.55  christos /*
    451  1.55  christos  * Miscellany
    452  1.55  christos  */
    453  1.55  christos 
    454  1.55  christos int get_pc_str_offset	(void);
    455  1.55  christos 
    456  1.79       ryo bool cpu_gtmr_exists_p(void);
    457  1.79       ryo u_int cpu_clusterid(void);
    458  1.79       ryo bool cpu_earlydevice_va_p(void);
    459  1.79       ryo 
    460  1.55  christos /*
    461  1.55  christos  * Functions to manipulate cpu r13
    462  1.55  christos  * (in arm/arm32/setstack.S)
    463  1.55  christos  */
    464  1.55  christos 
    465  1.55  christos void set_stackptr	(u_int, u_int);
    466  1.55  christos u_int get_stackptr	(u_int);
    467  1.55  christos 
    468  1.55  christos #endif /* _KERNEL || _KMEMUSER */
    469  1.55  christos 
    470  1.79       ryo #elif defined(__aarch64__)
    471  1.79       ryo 
    472  1.79       ryo #include <aarch64/cpufunc.h>
    473  1.79       ryo 
    474  1.79       ryo #endif /* __arm__/__aarch64__ */
    475  1.79       ryo 
    476  1.65      matt #endif	/* _ARM_CPUFUNC_H_ */
    477   1.1   reinoud 
    478   1.1   reinoud /* End of cpufunc.h */
    479