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