cpufunc.h revision 1.25
1/* $OpenBSD: cpufunc.h,v 1.25 2016/04/03 13:55:23 jsg Exp $ */ 2/* $NetBSD: cpufunc.h,v 1.29 2003/09/06 09:08:35 rearnsha Exp $ */ 3 4/* 5 * Copyright (c) 1997 Mark Brinicombe. 6 * Copyright (c) 1997 Causality Limited 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * 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 promote 21 * products derived from this software without specific prior written 22 * permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``AS IS'' AND ANY EXPRESS 25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 * DISCLAIMED. IN NO EVENT SHALL CAUSALITY LIMITED BE LIABLE FOR ANY DIRECT, 28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * RiscBSD kernel project 37 * 38 * cpufunc.h 39 * 40 * Prototypes for cpu, mmu and tlb related functions. 41 */ 42 43#ifndef _ARM_CPUFUNC_H_ 44#define _ARM_CPUFUNC_H_ 45 46#ifdef _KERNEL 47 48#include <sys/types.h> 49#include <arm/cpuconf.h> 50 51struct cpu_functions { 52 53 /* CPU functions */ 54 55 u_int (*cf_id) (void); 56 void (*cf_cpwait) (void); 57 58 /* MMU functions */ 59 60 u_int (*cf_control) (u_int clear, u_int set); 61 u_int (*cf_auxcontrol) (u_int clear, u_int set); 62 void (*cf_domains) (u_int domains); 63 void (*cf_setttb) (u_int ttb); 64 u_int (*cf_dfsr) (void); 65 u_int (*cf_dfar) (void); 66 u_int (*cf_ifsr) (void); 67 u_int (*cf_ifar) (void); 68 69 /* TLB functions */ 70 71 void (*cf_tlb_flushID) (void); 72 void (*cf_tlb_flushID_SE) (u_int va); 73 void (*cf_tlb_flushI) (void); 74 void (*cf_tlb_flushI_SE) (u_int va); 75 void (*cf_tlb_flushD) (void); 76 void (*cf_tlb_flushD_SE) (u_int va); 77 78 /* 79 * Cache operations: 80 * 81 * We define the following primitives: 82 * 83 * icache_sync_all Synchronize I-cache 84 * icache_sync_range Synchronize I-cache range 85 * 86 * dcache_wbinv_all Write-back and Invalidate D-cache 87 * dcache_wbinv_range Write-back and Invalidate D-cache range 88 * dcache_inv_range Invalidate D-cache range 89 * dcache_wb_range Write-back D-cache range 90 * 91 * idcache_wbinv_all Write-back and Invalidate D-cache, 92 * Invalidate I-cache 93 * idcache_wbinv_range Write-back and Invalidate D-cache, 94 * Invalidate I-cache range 95 * 96 * Note that the ARM term for "write-back" is "clean". We use 97 * the term "write-back" since it's a more common way to describe 98 * the operation. 99 * 100 * There are some rules that must be followed: 101 * 102 * I-cache Synch (all or range): 103 * The goal is to synchronize the instruction stream, 104 * so you may beed to write-back dirty D-cache blocks 105 * first. If a range is requested, and you can't 106 * synchronize just a range, you have to hit the whole 107 * thing. 108 * 109 * D-cache Write-Back and Invalidate range: 110 * If you can't WB-Inv a range, you must WB-Inv the 111 * entire D-cache. 112 * 113 * D-cache Invalidate: 114 * If you can't Inv the D-cache, you must Write-Back 115 * and Invalidate. Code that uses this operation 116 * MUST NOT assume that the D-cache will not be written 117 * back to memory. 118 * 119 * D-cache Write-Back: 120 * If you can't Write-back without doing an Inv, 121 * that's fine. Then treat this as a WB-Inv. 122 * Skipping the invalidate is merely an optimization. 123 * 124 * All operations: 125 * Valid virtual addresses must be passed to each 126 * cache operation. 127 */ 128 void (*cf_icache_sync_all) (void); 129 void (*cf_icache_sync_range) (vaddr_t, vsize_t); 130 131 void (*cf_dcache_wbinv_all) (void); 132 void (*cf_dcache_wbinv_range) (vaddr_t, vsize_t); 133 void (*cf_dcache_inv_range) (vaddr_t, vsize_t); 134 void (*cf_dcache_wb_range) (vaddr_t, vsize_t); 135 136 void (*cf_idcache_wbinv_all) (void); 137 void (*cf_idcache_wbinv_range) (vaddr_t, vsize_t); 138 139 void (*cf_sdcache_wbinv_all) (void); 140 void (*cf_sdcache_wbinv_range) (vaddr_t, paddr_t, vsize_t); 141 void (*cf_sdcache_inv_range) (vaddr_t, paddr_t, vsize_t); 142 void (*cf_sdcache_wb_range) (vaddr_t, paddr_t, vsize_t); 143 144 /* Other functions */ 145 146 void (*cf_flush_prefetchbuf) (void); 147 void (*cf_drain_writebuf) (void); 148 149 void (*cf_sleep) (int mode); 150 151 /* Soft functions */ 152 void (*cf_context_switch) (u_int); 153 void (*cf_setup) (void); 154}; 155 156extern struct cpu_functions cpufuncs; 157extern u_int cputype; 158 159#define cpu_id() cpufuncs.cf_id() 160#define cpu_cpwait() cpufuncs.cf_cpwait() 161 162#define cpu_control(c, s) cpufuncs.cf_control(c, s) 163#define cpu_auxcontrol(c, s) cpufuncs.cf_auxcontrol(c, s) 164#define cpu_domains(d) cpufuncs.cf_domains(d) 165#define cpu_setttb(t) cpufuncs.cf_setttb(t) 166#define cpu_dfsr() cpufuncs.cf_dfsr() 167#define cpu_dfar() cpufuncs.cf_dfar() 168#define cpu_ifsr() cpufuncs.cf_ifsr() 169#define cpu_ifar() cpufuncs.cf_ifar() 170 171#define cpu_tlb_flushID() cpufuncs.cf_tlb_flushID() 172#define cpu_tlb_flushID_SE(e) cpufuncs.cf_tlb_flushID_SE(e) 173#define cpu_tlb_flushI() cpufuncs.cf_tlb_flushI() 174#define cpu_tlb_flushI_SE(e) cpufuncs.cf_tlb_flushI_SE(e) 175#define cpu_tlb_flushD() cpufuncs.cf_tlb_flushD() 176#define cpu_tlb_flushD_SE(e) cpufuncs.cf_tlb_flushD_SE(e) 177 178#define cpu_icache_sync_all() cpufuncs.cf_icache_sync_all() 179#define cpu_icache_sync_range(a, s) cpufuncs.cf_icache_sync_range((a), (s)) 180 181#define cpu_dcache_wbinv_all() cpufuncs.cf_dcache_wbinv_all() 182#define cpu_dcache_wbinv_range(a, s) cpufuncs.cf_dcache_wbinv_range((a), (s)) 183#define cpu_dcache_inv_range(a, s) cpufuncs.cf_dcache_inv_range((a), (s)) 184#define cpu_dcache_wb_range(a, s) cpufuncs.cf_dcache_wb_range((a), (s)) 185 186#define cpu_idcache_wbinv_all() cpufuncs.cf_idcache_wbinv_all() 187#define cpu_idcache_wbinv_range(a, s) cpufuncs.cf_idcache_wbinv_range((a), (s)) 188 189#define cpu_sdcache_enabled() (cpufuncs.cf_sdcache_wbinv_all != cpufunc_nullop) 190#define cpu_sdcache_wbinv_all() cpufuncs.cf_sdcache_wbinv_all() 191#define cpu_sdcache_wbinv_range(va, pa, s) cpufuncs.cf_sdcache_wbinv_range((va), (pa), (s)) 192#define cpu_sdcache_inv_range(va, pa, s) cpufuncs.cf_sdcache_inv_range((va), (pa), (s)) 193#define cpu_sdcache_wb_range(va, pa, s) cpufuncs.cf_sdcache_wb_range((va), (pa), (s)) 194 195#define cpu_flush_prefetchbuf() cpufuncs.cf_flush_prefetchbuf() 196#define cpu_drain_writebuf() cpufuncs.cf_drain_writebuf() 197 198#define cpu_sleep(m) cpufuncs.cf_sleep(m) 199 200#define cpu_context_switch(a) cpufuncs.cf_context_switch(a) 201#define cpu_setup(a) cpufuncs.cf_setup(a) 202 203int set_cpufuncs (void); 204#define ARCHITECTURE_NOT_PRESENT 1 /* known but not configured */ 205#define ARCHITECTURE_NOT_SUPPORTED 2 /* not known */ 206 207void cpufunc_nullop (void); 208int early_abort_fixup (void *); 209int late_abort_fixup (void *); 210u_int cpufunc_id (void); 211u_int cpufunc_control (u_int clear, u_int set); 212u_int cpufunc_auxcontrol (u_int clear, u_int set); 213void cpufunc_domains (u_int domains); 214u_int cpufunc_dfsr (void); 215u_int cpufunc_dfar (void); 216u_int cpufunc_ifsr (void); 217u_int cpufunc_ifar (void); 218 219#ifdef CPU_ARMv7 220void armv7_setttb (u_int); 221 222void armv7_tlb_flushID_SE (u_int); 223void armv7_tlb_flushI_SE (u_int); 224 225void armv7_context_switch (u_int); 226 227void armv7_setup (void); 228void armv7_tlb_flushID (void); 229void armv7_tlb_flushI (void); 230void armv7_tlb_flushD (void); 231void armv7_tlb_flushD_SE (u_int va); 232 233void armv7_drain_writebuf (void); 234void armv7_cpu_sleep (int mode); 235 236u_int armv7_periphbase (void); 237 238void armv7_icache_sync_all (void); 239void armv7_icache_sync_range (vaddr_t, vsize_t); 240 241void armv7_dcache_wbinv_all (void); 242void armv7_dcache_wbinv_range (vaddr_t, vsize_t); 243void armv7_dcache_inv_range (vaddr_t, vsize_t); 244void armv7_dcache_wb_range (vaddr_t, vsize_t); 245 246void armv7_idcache_wbinv_all (void); 247void armv7_idcache_wbinv_range (vaddr_t, vsize_t); 248 249extern unsigned armv7_dcache_sets_max; 250extern unsigned armv7_dcache_sets_inc; 251extern unsigned armv7_dcache_index_max; 252extern unsigned armv7_dcache_index_inc; 253#endif 254 255 256#if defined(CPU_XSCALE_80321) || defined(CPU_XSCALE_PXA2X0) 257void armv4_tlb_flushID (void); 258void armv4_tlb_flushI (void); 259void armv4_tlb_flushD (void); 260void armv4_tlb_flushD_SE (u_int va); 261 262void armv4_drain_writebuf (void); 263#endif 264 265#if defined(CPU_XSCALE_80321) || \ 266 defined(CPU_XSCALE_PXA2X0) || (ARM_MMU_XSCALE == 1) 267void xscale_cpwait (void); 268 269void xscale_cpu_sleep (int mode); 270 271u_int xscale_control (u_int clear, u_int bic); 272 273void xscale_setttb (u_int ttb); 274 275void xscale_tlb_flushID_SE (u_int va); 276 277void xscale_cache_flushID (void); 278void xscale_cache_flushI (void); 279void xscale_cache_flushD (void); 280void xscale_cache_flushD_SE (u_int entry); 281 282void xscale_cache_cleanID (void); 283void xscale_cache_cleanD (void); 284void xscale_cache_cleanD_E (u_int entry); 285 286void xscale_cache_clean_minidata (void); 287 288void xscale_cache_purgeID (void); 289void xscale_cache_purgeID_E (u_int entry); 290void xscale_cache_purgeD (void); 291void xscale_cache_purgeD_E (u_int entry); 292 293void xscale_cache_syncI (void); 294void xscale_cache_cleanID_rng (vaddr_t start, vsize_t end); 295void xscale_cache_cleanD_rng (vaddr_t start, vsize_t end); 296void xscale_cache_purgeID_rng (vaddr_t start, vsize_t end); 297void xscale_cache_purgeD_rng (vaddr_t start, vsize_t end); 298void xscale_cache_syncI_rng (vaddr_t start, vsize_t end); 299void xscale_cache_flushD_rng (vaddr_t start, vsize_t end); 300 301void xscale_context_switch (u_int); 302 303void xscale_setup (void); 304#endif /* CPU_XSCALE_80321 || CPU_XSCALE_PXA2X0 */ 305 306#define tlb_flush cpu_tlb_flushID 307#define setttb cpu_setttb 308#define drain_writebuf cpu_drain_writebuf 309 310/* 311 * Macros for manipulating CPU interrupts 312 */ 313/* Functions to manipulate the CPSR. */ 314static __inline u_int32_t __set_cpsr_c(u_int bic, u_int eor); 315static __inline u_int32_t __get_cpsr(void); 316 317static __inline u_int32_t 318__set_cpsr_c(u_int bic, u_int eor) 319{ 320 u_int32_t tmp, ret; 321 322 __asm volatile( 323 "mrs %0, cpsr\n\t" /* Get the CPSR */ 324 "bic %1, %0, %2\n\t" /* Clear bits */ 325 "eor %1, %1, %3\n\t" /* XOR bits */ 326 "msr cpsr_c, %1" /* Set CPSR control field */ 327 : "=&r" (ret), "=&r" (tmp) 328 : "r" (bic), "r" (eor)); 329 330 return ret; 331} 332 333static __inline u_int32_t 334__get_cpsr() 335{ 336 u_int32_t ret; 337 338 __asm volatile("mrs %0, cpsr" : "=&r" (ret)); 339 340 return ret; 341} 342 343#define disable_interrupts(mask) \ 344 (__set_cpsr_c((mask) & (PSR_I | PSR_F), \ 345 (mask) & (PSR_I | PSR_F))) 346 347#define enable_interrupts(mask) \ 348 (__set_cpsr_c((mask) & (PSR_I | PSR_F), 0)) 349 350#define restore_interrupts(old_cpsr) \ 351 (__set_cpsr_c((PSR_I | PSR_F), (old_cpsr) & (PSR_I | PSR_F))) 352 353/* 354 * Functions to manipulate cpu r13 355 * (in arm/arm/setstack.S) 356 */ 357 358void set_stackptr (u_int mode, u_int address); 359u_int get_stackptr (u_int mode); 360 361/* 362 * Miscellany 363 */ 364 365int get_pc_str_offset (void); 366 367/* 368 * CPU functions from locore.S 369 */ 370 371void cpu_reset (void) __attribute__((__noreturn__)); 372 373/* 374 * Cache info variables. 375 */ 376 377/* PRIMARY CACHE VARIABLES */ 378extern int arm_picache_size; 379extern int arm_picache_line_size; 380extern int arm_picache_ways; 381 382extern int arm_pdcache_size; /* and unified */ 383extern int arm_pdcache_line_size; 384extern int arm_pdcache_ways; 385 386extern int arm_pcache_type; 387extern int arm_pcache_unified; 388 389extern int arm_dcache_align; 390extern int arm_dcache_align_mask; 391 392#endif /* _KERNEL */ 393#endif /* _ARM_CPUFUNC_H_ */ 394 395/* End of cpufunc.h */ 396