16fc729afSOlivier Houchard /* $NetBSD: cpufunc.h,v 1.29 2003/09/06 09:08:35 rearnsha Exp $ */ 26fc729afSOlivier Houchard 3d8315c79SWarner Losh /*- 4af3dc4a7SPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 5af3dc4a7SPedro F. Giffuni * 66fc729afSOlivier Houchard * Copyright (c) 1997 Mark Brinicombe. 76fc729afSOlivier Houchard * Copyright (c) 1997 Causality Limited 86fc729afSOlivier Houchard * All rights reserved. 96fc729afSOlivier Houchard * 106fc729afSOlivier Houchard * Redistribution and use in source and binary forms, with or without 116fc729afSOlivier Houchard * modification, are permitted provided that the following conditions 126fc729afSOlivier Houchard * are met: 136fc729afSOlivier Houchard * 1. Redistributions of source code must retain the above copyright 146fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer. 156fc729afSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright 166fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer in the 176fc729afSOlivier Houchard * documentation and/or other materials provided with the distribution. 186fc729afSOlivier Houchard * 3. All advertising materials mentioning features or use of this software 196fc729afSOlivier Houchard * must display the following acknowledgement: 206fc729afSOlivier Houchard * This product includes software developed by Causality Limited. 216fc729afSOlivier Houchard * 4. The name of Causality Limited may not be used to endorse or promote 226fc729afSOlivier Houchard * products derived from this software without specific prior written 236fc729afSOlivier Houchard * permission. 246fc729afSOlivier Houchard * 256fc729afSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS 266fc729afSOlivier Houchard * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 276fc729afSOlivier Houchard * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 286fc729afSOlivier Houchard * DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT, 296fc729afSOlivier Houchard * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 306fc729afSOlivier Houchard * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 316fc729afSOlivier Houchard * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 326fc729afSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 336fc729afSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 346fc729afSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 356fc729afSOlivier Houchard * SUCH DAMAGE. 366fc729afSOlivier Houchard * 376fc729afSOlivier Houchard * RiscBSD kernel project 386fc729afSOlivier Houchard * 396fc729afSOlivier Houchard * cpufunc.h 406fc729afSOlivier Houchard * 416fc729afSOlivier Houchard * Prototypes for cpu, mmu and tlb related functions. 426fc729afSOlivier Houchard */ 436fc729afSOlivier Houchard 446fc729afSOlivier Houchard #ifndef _MACHINE_CPUFUNC_H_ 456fc729afSOlivier Houchard #define _MACHINE_CPUFUNC_H_ 466fc729afSOlivier Houchard 476fc729afSOlivier Houchard #ifdef _KERNEL 486fc729afSOlivier Houchard 496fc729afSOlivier Houchard #include <sys/types.h> 505fcbe89aSMichal Meloun #include <machine/armreg.h> 516fc729afSOlivier Houchard 524628245bSOlivier Houchard static __inline void 534628245bSOlivier Houchard breakpoint(void) 544628245bSOlivier Houchard { 55a9c91abdSJohn Baldwin __asm("udf 0xffff"); 564628245bSOlivier Houchard } 57be687a0dSOlivier Houchard 586fc729afSOlivier Houchard struct cpu_functions { 596fc729afSOlivier Houchard /* CPU functions */ 60425b5be3SOlivier Houchard void (*cf_l2cache_wbinv_all) (void); 61425b5be3SOlivier Houchard void (*cf_l2cache_wbinv_range) (vm_offset_t, vm_size_t); 62425b5be3SOlivier Houchard void (*cf_l2cache_inv_range) (vm_offset_t, vm_size_t); 63425b5be3SOlivier Houchard void (*cf_l2cache_wb_range) (vm_offset_t, vm_size_t); 64b07d0cbcSIan Lepore void (*cf_l2cache_drain_writebuf) (void); 656fc729afSOlivier Houchard 666fc729afSOlivier Houchard /* Other functions */ 676fc729afSOlivier Houchard 686fc729afSOlivier Houchard void (*cf_sleep) (int mode); 696fc729afSOlivier Houchard 709a25f3e8SAndrew Turner void (*cf_setup) (void); 716fc729afSOlivier Houchard }; 726fc729afSOlivier Houchard 736fc729afSOlivier Houchard extern struct cpu_functions cpufuncs; 746fc729afSOlivier Houchard extern u_int cputype; 756fc729afSOlivier Houchard 76425b5be3SOlivier Houchard #define cpu_l2cache_wbinv_all() cpufuncs.cf_l2cache_wbinv_all() 77425b5be3SOlivier Houchard #define cpu_l2cache_wb_range(a, s) cpufuncs.cf_l2cache_wb_range((a), (s)) 78425b5be3SOlivier Houchard #define cpu_l2cache_inv_range(a, s) cpufuncs.cf_l2cache_inv_range((a), (s)) 79425b5be3SOlivier Houchard #define cpu_l2cache_wbinv_range(a, s) cpufuncs.cf_l2cache_wbinv_range((a), (s)) 80b07d0cbcSIan Lepore #define cpu_l2cache_drain_writebuf() cpufuncs.cf_l2cache_drain_writebuf() 816fc729afSOlivier Houchard 826fc729afSOlivier Houchard #define cpu_sleep(m) cpufuncs.cf_sleep(m) 836fc729afSOlivier Houchard 849a25f3e8SAndrew Turner #define cpu_setup() cpufuncs.cf_setup() 856fc729afSOlivier Houchard 866fc729afSOlivier Houchard int set_cpufuncs (void); 876fc729afSOlivier Houchard #define ARCHITECTURE_NOT_PRESENT 1 /* known but not configured */ 886fc729afSOlivier Houchard 896fc729afSOlivier Houchard void cpufunc_nullop (void); 906fc729afSOlivier Houchard u_int cpufunc_control (u_int clear, u_int bic); 916fc729afSOlivier Houchard 926fc729afSOlivier Houchard 9393a065e7SMichal Meloun #if defined(CPU_CORTEXA) || defined(CPU_MV_PJ4B) || defined(CPU_KRAIT) 94cf1a573fSOleksandr Tymoshenko void armv7_cpu_sleep (int); 9563b25978SWarner Losh #endif 9637b25ee6SAndrew Turner #if defined(CPU_MV_PJ4B) 9737b25ee6SAndrew Turner void pj4b_config (void); 9837b25ee6SAndrew Turner #endif 9963b25978SWarner Losh 100c5f8f894SOleksandr Tymoshenko 1016fc729afSOlivier Houchard 1026fc729afSOlivier Houchard /* 1036fc729afSOlivier Houchard * Macros for manipulating CPU interrupts 1046fc729afSOlivier Houchard */ 1055fcbe89aSMichal Meloun #define __ARM_INTR_BITS (PSR_I | PSR_F | PSR_A) 1066fc729afSOlivier Houchard 1075fcbe89aSMichal Meloun static __inline uint32_t 1085fcbe89aSMichal Meloun __set_cpsr(uint32_t bic, uint32_t eor) 1096fc729afSOlivier Houchard { 1105fcbe89aSMichal Meloun uint32_t tmp, ret; 1116fc729afSOlivier Houchard 1126fc729afSOlivier Houchard __asm __volatile( 1136fc729afSOlivier Houchard "mrs %0, cpsr\n" /* Get the CPSR */ 1146fc729afSOlivier Houchard "bic %1, %0, %2\n" /* Clear bits */ 1156fc729afSOlivier Houchard "eor %1, %1, %3\n" /* XOR bits */ 1165fcbe89aSMichal Meloun "msr cpsr_xc, %1\n" /* Set the CPSR */ 1176fc729afSOlivier Houchard : "=&r" (ret), "=&r" (tmp) 11824e01b0cSOlivier Houchard : "r" (bic), "r" (eor) : "memory"); 1196fc729afSOlivier Houchard 1206fc729afSOlivier Houchard return ret; 1216fc729afSOlivier Houchard } 1226fc729afSOlivier Houchard 1235fcbe89aSMichal Meloun static __inline uint32_t 1245fcbe89aSMichal Meloun disable_interrupts(uint32_t mask) 1255fcbe89aSMichal Meloun { 126dfad9244SMarcel Moolenaar 1275fcbe89aSMichal Meloun return (__set_cpsr(mask & __ARM_INTR_BITS, mask & __ARM_INTR_BITS)); 1285fcbe89aSMichal Meloun } 1296fc729afSOlivier Houchard 1305fcbe89aSMichal Meloun static __inline uint32_t 1315fcbe89aSMichal Meloun enable_interrupts(uint32_t mask) 1325fcbe89aSMichal Meloun { 1336fc729afSOlivier Houchard 1345fcbe89aSMichal Meloun return (__set_cpsr(mask & __ARM_INTR_BITS, 0)); 1355fcbe89aSMichal Meloun } 1365fcbe89aSMichal Meloun 1375fcbe89aSMichal Meloun static __inline uint32_t 1385fcbe89aSMichal Meloun restore_interrupts(uint32_t old_cpsr) 1395fcbe89aSMichal Meloun { 1405fcbe89aSMichal Meloun 1415fcbe89aSMichal Meloun return (__set_cpsr(__ARM_INTR_BITS, old_cpsr & __ARM_INTR_BITS)); 1425fcbe89aSMichal Meloun } 1436fc729afSOlivier Houchard 144dfad9244SMarcel Moolenaar static __inline register_t 145dfad9244SMarcel Moolenaar intr_disable(void) 146dfad9244SMarcel Moolenaar { 147dfad9244SMarcel Moolenaar 1485fcbe89aSMichal Meloun return (disable_interrupts(PSR_I | PSR_F)); 149dfad9244SMarcel Moolenaar } 150dfad9244SMarcel Moolenaar 151dfad9244SMarcel Moolenaar static __inline void 152dfad9244SMarcel Moolenaar intr_restore(register_t s) 153dfad9244SMarcel Moolenaar { 154dfad9244SMarcel Moolenaar 155dfad9244SMarcel Moolenaar restore_interrupts(s); 156dfad9244SMarcel Moolenaar } 1575fcbe89aSMichal Meloun #undef __ARM_INTR_BITS 1586fc729afSOlivier Houchard 1596fc729afSOlivier Houchard /* 1606fc729afSOlivier Houchard * Functions to manipulate cpu r13 1616fc729afSOlivier Houchard * (in arm/arm32/setstack.S) 1626fc729afSOlivier Houchard */ 1636fc729afSOlivier Houchard 1644eaa43e6SKevin Lo void set_stackptr (u_int mode, u_int address); 1654eaa43e6SKevin Lo u_int get_stackptr (u_int mode); 1666fc729afSOlivier Houchard 1676fc729afSOlivier Houchard /* 1686fc729afSOlivier Houchard * CPU functions from locore.S 1696fc729afSOlivier Houchard */ 1706fc729afSOlivier Houchard 1714eaa43e6SKevin Lo void cpu_reset (void) __attribute__((__noreturn__)); 1726fc729afSOlivier Houchard 1736fc729afSOlivier Houchard /* 1746fc729afSOlivier Houchard * Cache info variables. 1756fc729afSOlivier Houchard */ 1766fc729afSOlivier Houchard 1776fc729afSOlivier Houchard /* PRIMARY CACHE VARIABLES */ 178*185aa8c9SMark Johnston extern unsigned int arm_dcache_align; 179*185aa8c9SMark Johnston extern unsigned int arm_dcache_align_mask; 1806fc729afSOlivier Houchard 181a9c91abdSJohn Baldwin #else /* !_KERNEL */ 182a9c91abdSJohn Baldwin 183a9c91abdSJohn Baldwin static __inline void 184a9c91abdSJohn Baldwin breakpoint(void) 185a9c91abdSJohn Baldwin { 186a9c91abdSJohn Baldwin 187a9c91abdSJohn Baldwin /* 188a9c91abdSJohn Baldwin * This matches the instruction used by GDB for software 189a9c91abdSJohn Baldwin * breakpoints. 190a9c91abdSJohn Baldwin */ 191a9c91abdSJohn Baldwin __asm("udf 0xfdee"); 192a9c91abdSJohn Baldwin } 193a9c91abdSJohn Baldwin 1946fc729afSOlivier Houchard #endif /* _KERNEL */ 1956fc729afSOlivier Houchard #endif /* _MACHINE_CPUFUNC_H_ */ 1966fc729afSOlivier Houchard 1976fc729afSOlivier Houchard /* End of cpufunc.h */ 198