/* $NetBSD: cpufunc.h,v 1.29 2003/09/06 09:08:35 rearnsha Exp $ */12/*-3* SPDX-License-Identifier: BSD-4-Clause4*5* Copyright (c) 1997 Mark Brinicombe.6* Copyright (c) 1997 Causality Limited7* All rights reserved.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17* 3. All advertising materials mentioning features or use of this software18* must display the following acknowledgement:19* This product includes software developed by Causality Limited.20* 4. The name of Causality Limited may not be used to endorse or promote21* products derived from this software without specific prior written22* permission.23*24* THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS25* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED26* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE27* DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT,28* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES29* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR30* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)31* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT32* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY33* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF34* SUCH DAMAGE.35*36* RiscBSD kernel project37*38* cpufunc.h39*40* Prototypes for cpu, mmu and tlb related functions.41*/4243#ifndef _MACHINE_CPUFUNC_H_44#define _MACHINE_CPUFUNC_H_4546#ifdef _KERNEL4748#include <sys/types.h>49#include <machine/armreg.h>5051static __inline void52breakpoint(void)53{54__asm("udf 0xffff");55}5657struct cpu_functions {58/* CPU functions */59void (*cf_l2cache_wbinv_all) (void);60void (*cf_l2cache_wbinv_range) (vm_offset_t, vm_size_t);61void (*cf_l2cache_inv_range) (vm_offset_t, vm_size_t);62void (*cf_l2cache_wb_range) (vm_offset_t, vm_size_t);63void (*cf_l2cache_drain_writebuf) (void);6465/* Other functions */6667void (*cf_sleep) (int mode);6869void (*cf_setup) (void);70};7172extern struct cpu_functions cpufuncs;73extern u_int cputype;7475#define cpu_l2cache_wbinv_all() cpufuncs.cf_l2cache_wbinv_all()76#define cpu_l2cache_wb_range(a, s) cpufuncs.cf_l2cache_wb_range((a), (s))77#define cpu_l2cache_inv_range(a, s) cpufuncs.cf_l2cache_inv_range((a), (s))78#define cpu_l2cache_wbinv_range(a, s) cpufuncs.cf_l2cache_wbinv_range((a), (s))79#define cpu_l2cache_drain_writebuf() cpufuncs.cf_l2cache_drain_writebuf()8081#define cpu_sleep(m) cpufuncs.cf_sleep(m)8283#define cpu_setup() cpufuncs.cf_setup()8485int set_cpufuncs (void);86#define ARCHITECTURE_NOT_PRESENT 1 /* known but not configured */8788void cpufunc_nullop (void);89u_int cpufunc_control (u_int clear, u_int bic);909192#if defined(CPU_CORTEXA) || defined(CPU_MV_PJ4B) || defined(CPU_KRAIT)93void armv7_cpu_sleep (int);94#endif95#if defined(CPU_MV_PJ4B)96void pj4b_config (void);97#endif9899100101/*102* Macros for manipulating CPU interrupts103*/104#define __ARM_INTR_BITS (PSR_I | PSR_F | PSR_A)105106static __inline uint32_t107__set_cpsr(uint32_t bic, uint32_t eor)108{109uint32_t tmp, ret;110111__asm __volatile(112"mrs %0, cpsr\n" /* Get the CPSR */113"bic %1, %0, %2\n" /* Clear bits */114"eor %1, %1, %3\n" /* XOR bits */115"msr cpsr_xc, %1\n" /* Set the CPSR */116: "=&r" (ret), "=&r" (tmp)117: "r" (bic), "r" (eor) : "memory");118119return ret;120}121122static __inline uint32_t123disable_interrupts(uint32_t mask)124{125126return (__set_cpsr(mask & __ARM_INTR_BITS, mask & __ARM_INTR_BITS));127}128129static __inline uint32_t130enable_interrupts(uint32_t mask)131{132133return (__set_cpsr(mask & __ARM_INTR_BITS, 0));134}135136static __inline uint32_t137restore_interrupts(uint32_t old_cpsr)138{139140return (__set_cpsr(__ARM_INTR_BITS, old_cpsr & __ARM_INTR_BITS));141}142143static __inline register_t144intr_disable(void)145{146147return (disable_interrupts(PSR_I | PSR_F));148}149150static __inline void151intr_restore(register_t s)152{153154restore_interrupts(s);155}156#undef __ARM_INTR_BITS157158/*159* Functions to manipulate cpu r13160* (in arm/arm32/setstack.S)161*/162163void set_stackptr (u_int mode, u_int address);164u_int get_stackptr (u_int mode);165166/*167* CPU functions from locore.S168*/169170void cpu_reset (void) __attribute__((__noreturn__));171172/*173* Cache info variables.174*/175176/* PRIMARY CACHE VARIABLES */177extern unsigned int arm_dcache_align;178extern unsigned int arm_dcache_align_mask;179180#else /* !_KERNEL */181182static __inline void183breakpoint(void)184{185186/*187* This matches the instruction used by GDB for software188* breakpoints.189*/190__asm("udf 0xfdee");191}192193#endif /* _KERNEL */194#endif /* _MACHINE_CPUFUNC_H_ */195196/* End of cpufunc.h */197198199