1 /* $OpenBSD: cpu.h,v 1.24 2009/03/26 17:24:33 oga Exp $ */ 2 /* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */ 3 4 /* 5 * Copyright (c) 1994-1996 Mark Brinicombe. 6 * Copyright (c) 1994 Brini. 7 * All rights reserved. 8 * 9 * This code is derived from software written for Brini by Mark Brinicombe 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by Brini. 22 * 4. The name of the company nor the name of the author may be used to 23 * endorse or promote products derived from this software without specific 24 * prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * RiscBSD kernel project 39 * 40 * cpu.h 41 * 42 * CPU specific symbols 43 * 44 * Created : 18/09/94 45 * 46 * Based on kate/katelib/arm6.h 47 */ 48 49 #ifndef _ARM_CPU_H_ 50 #define _ARM_CPU_H_ 51 52 /* 53 * User-visible definitions 54 */ 55 56 /* CTL_MACHDEP definitions. */ 57 #define CPU_DEBUG 1 /* int: misc kernel debug control */ 58 #define CPU_BOOTED_DEVICE 2 /* string: device we booted from */ 59 #define CPU_BOOTED_KERNEL 3 /* string: kernel we booted */ 60 #define CPU_CONSDEV 4 /* struct: dev_t of our console */ 61 #define CPU_POWERSAVE 5 /* int: use CPU powersave mode */ 62 #define CPU_ALLOWAPERTURE 6 /* int: allow mmap of /dev/xf86 */ 63 #define CPU_APMWARN 7 /* APM battery warning percentage */ 64 #define CPU_KBDRESET 8 /* int: console keyboard reset */ 65 /* 9 formerly int: CPU_ZTSRAWMODE */ 66 /* 10 formerly struct: CPU_ZTSSCALE */ 67 #define CPU_MAXSPEED 11 /* int: number of valid machdep ids */ 68 #define CPU_LIDSUSPEND 12 /* int: closing lid causes suspend */ 69 #define CPU_MAXID 13 /* number of valid machdep ids */ 70 71 #define CTL_MACHDEP_NAMES { \ 72 { 0, 0 }, \ 73 { "debug", CTLTYPE_INT }, \ 74 { "booted_device", CTLTYPE_STRING }, \ 75 { "booted_kernel", CTLTYPE_STRING }, \ 76 { "console_device", CTLTYPE_STRUCT }, \ 77 { "powersave", CTLTYPE_INT }, \ 78 { "allowaperture", CTLTYPE_INT }, \ 79 { "apmwarn", CTLTYPE_INT }, \ 80 { "kbdreset", CTLTYPE_INT }, \ 81 { 0, 0 }, \ 82 { 0, 0 }, \ 83 { "maxspeed", CTLTYPE_INT }, \ 84 { "lidsuspend", CTLTYPE_INT } \ 85 } 86 87 #ifdef _KERNEL 88 89 /* 90 * Kernel-only definitions 91 */ 92 93 #include <arm/cpuconf.h> 94 95 #include <machine/intr.h> 96 #ifndef _LOCORE 97 #if 0 98 #include <sys/user.h> 99 #endif 100 #include <machine/frame.h> 101 #include <machine/pcb.h> 102 #endif /* !_LOCORE */ 103 104 #include <arm/armreg.h> 105 106 #ifndef _LOCORE 107 /* 1 == use cpu_sleep(), 0 == don't */ 108 extern int cpu_do_powersave; 109 #endif 110 111 #ifdef __PROG32 112 #ifdef _LOCORE 113 #define IRQdisable \ 114 stmfd sp!, {r0} ; \ 115 mrs r0, cpsr ; \ 116 orr r0, r0, #(I32_bit) ; \ 117 msr cpsr_c, r0 ; \ 118 ldmfd sp!, {r0} 119 120 #define IRQenable \ 121 stmfd sp!, {r0} ; \ 122 mrs r0, cpsr ; \ 123 bic r0, r0, #(I32_bit) ; \ 124 msr cpsr_c, r0 ; \ 125 ldmfd sp!, {r0} 126 127 #else 128 #define IRQdisable __set_cpsr_c(I32_bit, I32_bit); 129 #define IRQenable __set_cpsr_c(I32_bit, 0); 130 #endif /* _LOCORE */ 131 #endif 132 133 #ifndef _LOCORE 134 135 /* All the CLKF_* macros take a struct clockframe * as an argument. */ 136 137 /* 138 * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the 139 * frame came from USR mode or not. 140 */ 141 #ifdef __PROG32 142 #define CLKF_USERMODE(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE) 143 #else 144 #define CLKF_USERMODE(frame) ((frame->if_r15 & R15_MODE) == R15_MODE_USR) 145 #endif 146 147 /* 148 * CLKF_INTR: True if we took the interrupt from inside another 149 * interrupt handler. 150 */ 151 extern int current_intr_depth; 152 #ifdef __PROG32 153 /* Hack to treat FPE time as interrupt time so we can measure it */ 154 #define CLKF_INTR(frame) \ 155 ((current_intr_depth > 1) || \ 156 (frame->if_spsr & PSR_MODE) == PSR_UND32_MODE) 157 #else 158 #define CLKF_INTR(frame) (current_intr_depth > 1) 159 #endif 160 161 /* 162 * CLKF_PC: Extract the program counter from a clockframe 163 */ 164 #ifdef __PROG32 165 #define CLKF_PC(frame) (frame->if_pc) 166 #else 167 #define CLKF_PC(frame) (frame->if_r15 & R15_PC) 168 #endif 169 170 /* 171 * PROC_PC: Find out the program counter for the given process. 172 */ 173 #ifdef __PROG32 174 #define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_pc) 175 #else 176 #define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_r15 & R15_PC) 177 #endif 178 179 /* The address of the vector page. */ 180 extern vaddr_t vector_page; 181 #ifdef __PROG32 182 void arm32_vector_init(vaddr_t, int); 183 184 #define ARM_VEC_RESET (1 << 0) 185 #define ARM_VEC_UNDEFINED (1 << 1) 186 #define ARM_VEC_SWI (1 << 2) 187 #define ARM_VEC_PREFETCH_ABORT (1 << 3) 188 #define ARM_VEC_DATA_ABORT (1 << 4) 189 #define ARM_VEC_ADDRESS_EXCEPTION (1 << 5) 190 #define ARM_VEC_IRQ (1 << 6) 191 #define ARM_VEC_FIQ (1 << 7) 192 193 #define ARM_NVEC 8 194 #define ARM_VEC_ALL 0xffffffff 195 #endif 196 197 /* 198 * Per-CPU information. For now we assume one CPU. 199 */ 200 201 #include <sys/device.h> 202 #include <sys/sched.h> 203 struct cpu_info { 204 struct proc *ci_curproc; 205 206 struct schedstate_percpu ci_schedstate; /* scheduler state */ 207 #if defined(DIAGNOSTIC) || defined(LOCKDEBUG) 208 u_long ci_spin_locks; /* # of spin locks held */ 209 u_long ci_simple_locks; /* # of simple locks held */ 210 #endif 211 struct device *ci_dev; /* Device corresponding to this CPU */ 212 u_int32_t ci_arm_cpuid; /* aggregate CPU id */ 213 u_int32_t ci_arm_cputype; /* CPU type */ 214 u_int32_t ci_arm_cpurev; /* CPU revision */ 215 u_int32_t ci_ctrl; /* The CPU control register */ 216 #ifdef MULTIPROCESSOR 217 MP_CPU_INFO_MEMBERS 218 #endif 219 u_int32_t ci_randseed; 220 }; 221 222 #ifndef MULTIPROCESSOR 223 extern struct cpu_info cpu_info_store; 224 #define curcpu() (&cpu_info_store) 225 #define cpu_number() 0 226 #define CPU_IS_PRIMARY(ci) 1 227 #define CPU_INFO_ITERATOR int 228 #define CPU_INFO_FOREACH(cii, ci) \ 229 for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) 230 #define CPU_INFO_UNIT(ci) 0 231 #define MAXCPUS 1 232 #define cpu_unidle(ci) 233 #endif 234 235 #ifdef __PROG32 236 void cpu_proc_fork(struct proc *, struct proc *); 237 #else 238 #define cpu_proc_fork(p1, p2) 239 #endif 240 241 /* 242 * Scheduling glue 243 */ 244 245 extern int astpending; 246 #define setsoftast() (astpending = 1) 247 248 /* 249 * Notify the current process (p) that it has a signal pending, 250 * process as soon as possible. 251 */ 252 253 #define signotify(p) setsoftast() 254 255 /* 256 * Preempt the current process if in interrupt from user mode, 257 * or after the current trap/syscall if in system mode. 258 */ 259 extern int want_resched; /* resched() was called */ 260 #define need_resched(ci) (want_resched = 1, setsoftast()) 261 #define clear_resched(ci) want_resched = 0 262 263 /* 264 * Give a profiling tick to the current process when the user profiling 265 * buffer pages are invalid. On the i386, request an ast to send us 266 * through trap(), marking the proc as needing a profiling tick. 267 */ 268 #define need_proftick(p) setsoftast() 269 270 #ifndef acorn26 271 /* 272 * cpu device glue (belongs in cpuvar.h) 273 */ 274 275 struct device; 276 void cpu_attach (struct device *); 277 int cpu_alloc_idlepcb (struct cpu_info *); 278 #endif 279 280 281 /* 282 * Random cruft 283 */ 284 285 /* locore.S */ 286 void atomic_set_bit (u_int *address, u_int setmask); 287 void atomic_clear_bit (u_int *address, u_int clearmask); 288 289 /* cpuswitch.S */ 290 struct pcb; 291 void savectx (struct pcb *pcb); 292 293 /* ast.c */ 294 void userret (struct proc *p); 295 296 /* machdep.h */ 297 void bootsync (int); 298 299 /* fault.c */ 300 int badaddr_read (void *, size_t, void *); 301 302 /* syscall.c */ 303 void swi_handler (trapframe_t *); 304 305 /* machine_machdep.c */ 306 void board_startup(void); 307 308 #endif /* !_LOCORE */ 309 310 #endif /* _KERNEL */ 311 312 #endif /* !_ARM_CPU_H_ */ 313 314 /* End of cpu.h */ 315