cpu.h revision 1.61 1 /* $NetBSD: cpu.h,v 1.61 2002/04/03 03:48:33 simonb Exp $ */
2
3 /*-
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell and Rick Macklem.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR 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 * @(#)cpu.h 8.4 (Berkeley) 1/4/94
39 */
40
41 #ifndef _CPU_H_
42 #define _CPU_H_
43
44 #include <mips/cpuregs.h>
45
46 /*
47 * Exported definitions unique to NetBSD/mips cpu support.
48 */
49
50 #ifndef _LOCORE
51 #include <sys/sched.h>
52
53 #if defined(_KERNEL_OPT)
54 #include "opt_lockdebug.h"
55 #endif
56
57 struct cpu_info {
58 struct schedstate_percpu ci_schedstate; /* scheduler state */
59 u_long ci_cpu_freq; /* CPU frequency */
60 u_long ci_cycles_per_hz; /* CPU freq / hz */
61 u_long ci_divisor_delay; /* for delay/DELAY */
62 u_long ci_divisor_recip; /* scaled reciprocal of previous */
63 #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
64 u_long ci_spin_locks; /* # of spin locks held */
65 u_long ci_simple_locks; /* # of simple locks held */
66 #endif
67 };
68 #endif /* !defined(_LOCORE) */
69
70 /*
71 * CTL_MACHDEP definitions.
72 */
73 #define CPU_CONSDEV 1 /* dev_t: console terminal device */
74 #define CPU_BOOTED_KERNEL 2 /* string: booted kernel name */
75 #define CPU_ROOT_DEVICE 3 /* string: root device name */
76
77 /*
78 * Platform can override, but note this breaks userland compatibility
79 * with other mips platforms.
80 */
81 #ifndef CPU_MAXID
82 #define CPU_MAXID 4 /* number of valid machdep ids */
83
84 #define CTL_MACHDEP_NAMES { \
85 { 0, 0 }, \
86 { "console_device", CTLTYPE_STRUCT }, \
87 { "booted_kernel", CTLTYPE_STRING }, \
88 { "root_device", CTLTYPE_STRING }, \
89 }
90 #endif
91
92 #ifdef _KERNEL
93 #ifndef _LOCORE
94 extern struct cpu_info cpu_info_store;
95
96 #define curcpu() (&cpu_info_store)
97 #define cpu_number() (0)
98 #endif /* !_LOCORE */
99
100 /*
101 * Macros to find the CPU architecture we're on at run-time,
102 * or if possible, at compile-time.
103 */
104
105 #define CPU_ARCH_MIPSx 0 /* XXX unknown */
106 #define CPU_ARCH_MIPS1 (1 << 0)
107 #define CPU_ARCH_MIPS2 (1 << 1)
108 #define CPU_ARCH_MIPS3 (1 << 2)
109 #define CPU_ARCH_MIPS4 (1 << 3)
110 #define CPU_ARCH_MIPS5 (1 << 4)
111 #define CPU_ARCH_MIPS32 (1 << 5)
112 #define CPU_ARCH_MIPS64 (1 << 6)
113
114 #ifndef _LOCORE
115 /* XXX simonb
116 * Should the following be in a cpu_info type structure?
117 * And how many of these are per-cpu vs. per-system? (Ie,
118 * we can assume that all cpus have the same mmu-type, but
119 * maybe not that all cpus run at the same clock speed.
120 * Some SGI's apparently support R12k and R14k in the same
121 * box.)
122 */
123 extern int cpu_arch;
124 extern int mips_cpu_flags;
125 extern int mips_has_r4k_mmu;
126 extern int mips_has_llsc;
127 extern int mips3_pg_cached;
128
129 #define CPU_MIPS_R4K_MMU 0x0001
130 #define CPU_MIPS_NO_LLSC 0x0002
131 #define CPU_MIPS_CAUSE_IV 0x0004
132 #define CPU_MIPS_HAVE_SPECIAL_CCA 0x0008 /* Defaults to '3' if not set. */
133 #define CPU_MIPS_CACHED_CCA_MASK 0x0070
134 #define CPU_MIPS_CACHED_CCA_SHIFT 4
135 #define MIPS_NOT_SUPP 0x8000
136
137 #ifdef _LKM
138 /* Assume all CPU architectures are valid for LKM's */
139 #define MIPS1 1
140 #define MIPS3 1
141 #define MIPS4 1
142 #define MIPS32 1
143 #define MIPS64 1
144 #endif
145
146 #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 0
147 #error at least one of MIPS1, MIPS3, MIPS4, MIPS32 or MIPS64 must be specified
148 #endif
149
150 #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 1
151 #ifdef MIPS1
152 # define CPUISMIPS3 0
153 # define CPUIS64BITS 0
154 # define CPUISMIPS32 0
155 # define CPUISMIPS64 0
156 # define CPUISMIPSNN 0
157 # define MIPS_HAS_R4K_MMU 0
158 # define MIPS_HAS_CLOCK 0
159 # define MIPS_HAS_LLSC 0
160 #endif /* MIPS1 */
161
162 #if defined(MIPS3) || defined(MIPS4)
163 # define CPUISMIPS3 1
164 # define CPUIS64BITS 1
165 # define CPUISMIPS32 0
166 # define CPUISMIPS64 0
167 # define CPUISMIPSNN 0
168 # define MIPS_HAS_R4K_MMU 1
169 # define MIPS_HAS_CLOCK 1
170 # define MIPS_HAS_LLSC (mips_has_llsc)
171 #endif /* MIPS3 || MIPS4 */
172
173 #ifdef MIPS32
174 # define CPUISMIPS3 1
175 # define CPUIS64BITS 0
176 # define CPUISMIPS32 1
177 # define CPUISMIPS64 0
178 # define CPUISMIPSNN 1
179 # define MIPS_HAS_R4K_MMU 1
180 # define MIPS_HAS_CLOCK 1
181 # define MIPS_HAS_LLSC 1
182 #endif /* MIPS32 */
183
184 #ifdef MIPS64
185 # define CPUISMIPS3 1
186 # define CPUIS64BITS 1
187 # define CPUISMIPS32 0
188 # define CPUISMIPS64 1
189 # define CPUISMIPSNN 1
190 # define MIPS_HAS_R4K_MMU 1
191 # define MIPS_HAS_CLOCK 1
192 # define MIPS_HAS_LLSC 1
193 #endif /* MIPS32 */
194
195 #else /* run-time test */
196
197 #define MIPS_HAS_R4K_MMU (mips_has_r4k_mmu)
198 #define MIPS_HAS_LLSC (mips_has_llsc)
199
200 /* This test is ... rather bogus */
201 #define CPUISMIPS3 ((cpu_arch & \
202 (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
203
204 /* And these aren't much better while the previous test exists as is... */
205 #define CPUISMIPS32 ((cpu_arch & CPU_ARCH_MIPS32) != 0)
206 #define CPUISMIPS64 ((cpu_arch & CPU_ARCH_MIPS64) != 0)
207 #define CPUISMIPSNN ((cpu_arch & (CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
208 #define CPUIS64BITS ((cpu_arch & \
209 (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS64)) != 0)
210
211 #define MIPS_HAS_CLOCK (cpu_arch >= CPU_ARCH_MIPS3)
212 #endif /* run-time test */
213
214 /* Shortcut for MIPS3 or above defined */
215 #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
216 #define MIPS3_PLUS 1
217 #else
218 #undef MIPS3_PLUS
219 #endif
220
221
222 /*
223 * definitions of cpu-dependent requirements
224 * referenced in generic code
225 */
226 #define cpu_wait(p) /* nothing */
227 #define cpu_swapout(p) panic("cpu_swapout: can't get here");
228
229 void cpu_intr(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
230
231 /*
232 * Arguments to hardclock and gatherstats encapsulate the previous
233 * machine state in an opaque clockframe.
234 */
235 struct clockframe {
236 int pc; /* program counter at time of interrupt */
237 int sr; /* status register at time of interrupt */
238 int ppl; /* previous priority level at time of interrupt */
239 };
240
241 /*
242 * A port must provde CLKF_USERMODE() and CLKF_BASEPRI() for use
243 * in machine-independent code. These differ on r4000 and r3000 systems;
244 * provide them in the port-dependent file that includes this one, using
245 * the macros below.
246 */
247
248 /* mips1 versions */
249 #define MIPS1_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KU_PREV)
250 #define MIPS1_CLKF_BASEPRI(framep) \
251 ((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_ENA_PREV)) == 0)
252
253 /* mips3 versions */
254 #define MIPS3_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KSU_USER)
255 #define MIPS3_CLKF_BASEPRI(framep) \
256 ((~(framep)->sr & (MIPS_INT_MASK | MIPS_SR_INT_IE)) == 0)
257
258 #ifdef IPL_ICU_MASK
259 #define ICU_CLKF_BASEPRI(framep) ((framep)->ppl == 0)
260 #endif
261
262 #define CLKF_PC(framep) ((framep)->pc)
263 #define CLKF_INTR(framep) (0)
264
265 #if defined(MIPS3_PLUS) && !defined(MIPS1) /* XXX bogus! */
266 #define CLKF_USERMODE(framep) MIPS3_CLKF_USERMODE(framep)
267 #define CLKF_BASEPRI(framep) MIPS3_CLKF_BASEPRI(framep)
268 #endif
269
270 #if !defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
271 #define CLKF_USERMODE(framep) MIPS1_CLKF_USERMODE(framep)
272 #define CLKF_BASEPRI(framep) MIPS1_CLKF_BASEPRI(framep)
273 #endif
274
275 #ifdef IPL_ICU_MASK
276 #undef CLKF_BASEPRI
277 #define CLKF_BASEPRI(framep) ICU_CLKF_BASEPRI(framep)
278 #endif
279
280 #if defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
281 #define CLKF_USERMODE(framep) \
282 ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep): MIPS1_CLKF_USERMODE(framep))
283 #define CLKF_BASEPRI(framep) \
284 ((CPUISMIPS3) ? MIPS3_CLKF_BASEPRI(framep): MIPS1_CLKF_BASEPRI(framep))
285 #endif
286
287 /*
288 * This is used during profiling to integrate system time. It can safely
289 * assume that the process is resident.
290 */
291 #define PROC_PC(p) \
292 (((struct frame *)(p)->p_md.md_regs)->f_regs[37]) /* XXX PC */
293
294 /*
295 * Preempt the current process if in interrupt from user mode,
296 * or after the current trap/syscall if in system mode.
297 */
298 #define need_resched(ci) \
299 do { \
300 want_resched = 1; \
301 if (curproc != NULL) \
302 aston(curproc); \
303 } while (/*CONSTCOND*/0)
304
305 /*
306 * Give a profiling tick to the current process when the user profiling
307 * buffer pages are invalid. On the MIPS, request an ast to send us
308 * through trap, marking the proc as needing a profiling tick.
309 */
310 #define need_proftick(p) \
311 do { \
312 (p)->p_flag |= P_OWEUPC; \
313 aston(p); \
314 } while (/*CONSTCOND*/0)
315
316 /*
317 * Notify the current process (p) that it has a signal pending,
318 * process as soon as possible.
319 */
320 #define signotify(p) aston(p)
321
322 #define aston(p) ((p)->p_md.md_astpending = 1)
323
324 extern int want_resched; /* resched() was called */
325
326 /*
327 * Misc prototypes and variable declarations.
328 */
329 struct proc;
330 struct user;
331
332 extern struct proc *fpcurproc;
333
334 /* trap.c */
335 void netintr(void);
336 int kdbpeek(vaddr_t);
337
338 /* mips_machdep.c */
339 void dumpsys(void);
340 int savectx(struct user *);
341 void mips_init_msgbuf(void);
342 void savefpregs(struct proc *);
343 void loadfpregs(struct proc *);
344
345 /* locore*.S */
346 int badaddr(void *, size_t);
347 int badaddr64(uint64_t, size_t);
348
349 /* mips_machdep.c */
350 void cpu_identify(void);
351 void mips_vector_init(void);
352
353 #endif /* ! _LOCORE */
354 #endif /* _KERNEL */
355 #endif /* _CPU_H_ */
356