cpu.h revision 1.90.16.2 1 /* $NetBSD: cpu.h,v 1.90.16.2 2009/09/08 07:54:52 matt 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)cpu.h 8.4 (Berkeley) 1/4/94
35 */
36
37 #ifndef _CPU_H_
38 #define _CPU_H_
39
40 #include <mips/cpuregs.h>
41
42 /*
43 * Exported definitions unique to NetBSD/mips cpu support.
44 */
45
46 #ifdef _KERNEL
47 #ifndef _LOCORE
48 #include <sys/cpu_data.h>
49
50 #if defined(_KERNEL_OPT)
51 #include "opt_lockdebug.h"
52 #endif
53
54 struct cpu_info {
55 struct cpu_data ci_data; /* MI per-cpu data */
56 struct cpu_info *ci_next; /* Next CPU in list */
57 cpuid_t ci_cpuid; /* Machine-level identifier */
58 u_long ci_cpu_freq; /* CPU frequency */
59 u_long ci_cycles_per_hz; /* CPU freq / hz */
60 u_long ci_divisor_delay; /* for delay/DELAY */
61 u_long ci_divisor_recip; /* unused, for obsolete microtime(9) */
62 struct lwp *ci_curlwp; /* currently running lwp */
63 struct lwp *ci_fpcurlwp; /* the current FPU owner */
64 int ci_want_resched; /* user preemption pending */
65 int ci_mtx_count; /* negative count of held mutexes */
66 int ci_mtx_oldspl; /* saved SPL value */
67 int ci_idepth; /* hardware interrupt depth */
68 };
69
70 #define CPU_INFO_ITERATOR int
71 #define CPU_INFO_FOREACH(cii, ci) \
72 (void)(cii), ci = &cpu_info_store; ci != NULL; ci = ci->ci_next
73
74 #endif /* !_LOCORE */
75 #endif /* _KERNEL */
76
77 /*
78 * CTL_MACHDEP definitions.
79 */
80 #define CPU_CONSDEV 1 /* dev_t: console terminal device */
81 #define CPU_BOOTED_KERNEL 2 /* string: booted kernel name */
82 #define CPU_ROOT_DEVICE 3 /* string: root device name */
83 #define CPU_LLSC 4 /* OS/CPU supports LL/SC instruction */
84
85 /*
86 * Platform can override, but note this breaks userland compatibility
87 * with other mips platforms.
88 */
89 #ifndef CPU_MAXID
90 #define CPU_MAXID 5 /* number of valid machdep ids */
91
92 #endif
93
94 #ifdef _KERNEL
95 #if defined(_LKM) || defined(_STANDALONE)
96 /* Assume all CPU architectures are valid for LKM's and standlone progs */
97 #define MIPS1 1
98 #define MIPS3 1
99 #define MIPS4 1
100 #define MIPS32 1
101 #define MIPS64 1
102 #endif
103
104 #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 0
105 #error at least one of MIPS1, MIPS3, MIPS4, MIPS32 or MIPS64 must be specified
106 #endif
107
108 /* Shortcut for MIPS3 or above defined */
109 #if defined(MIPS3) || defined(MIPS4) || defined(MIPS32) || defined(MIPS64)
110 #define MIPS3_PLUS 1
111 #else
112 #undef MIPS3_PLUS
113 #endif
114
115 /*
116 * Macros to find the CPU architecture we're on at run-time,
117 * or if possible, at compile-time.
118 */
119
120 #define CPU_ARCH_MIPSx 0 /* XXX unknown */
121 #define CPU_ARCH_MIPS1 (1 << 0)
122 #define CPU_ARCH_MIPS2 (1 << 1)
123 #define CPU_ARCH_MIPS3 (1 << 2)
124 #define CPU_ARCH_MIPS4 (1 << 3)
125 #define CPU_ARCH_MIPS5 (1 << 4)
126 #define CPU_ARCH_MIPS32 (1 << 5)
127 #define CPU_ARCH_MIPS64 (1 << 6)
128
129 /* Note: must be kept in sync with -ffixed-?? Makefile.mips. */
130 #define MIPS_CURLWP $23
131 #define MIPS_CURLWP_QUOTED "$23"
132 #define MIPS_CURLWP_CARD 23
133 #define MIPS_CURLWP_FRAME(x) FRAME_S7(x)
134
135 #ifndef _LOCORE
136
137 extern struct cpu_info cpu_info_store;
138 register struct lwp *mips_curlwp asm(MIPS_CURLWP_QUOTED);
139
140 #define curlwp mips_curlwp
141 #define curcpu() (curlwp->l_cpu)
142 #define curpcb ((struct pcb *)curlwp->l_addr)
143 #define fpcurlwp (curcpu()->ci_fpcurlwp)
144 #define cpu_number() (0)
145 #define cpu_proc_fork(p1, p2) ((void)((p2)->p_md.md_abi = (p1)->p_md.md_abi))
146
147 /* XXX simonb
148 * Should the following be in a cpu_info type structure?
149 * And how many of these are per-cpu vs. per-system? (Ie,
150 * we can assume that all cpus have the same mmu-type, but
151 * maybe not that all cpus run at the same clock speed.
152 * Some SGI's apparently support R12k and R14k in the same
153 * box.)
154 */
155 extern int cpu_arch;
156 extern int mips_cpu_flags;
157 extern int mips_has_r4k_mmu;
158 extern int mips_has_llsc;
159 extern int mips3_pg_cached;
160 #ifdef _LP64
161 extern uint64_t mips3_xkphys_cached;
162 #endif
163 extern u_int mips3_pg_shift;
164
165 #define CPU_MIPS_R4K_MMU 0x0001
166 #define CPU_MIPS_NO_LLSC 0x0002
167 #define CPU_MIPS_CAUSE_IV 0x0004
168 #define CPU_MIPS_HAVE_SPECIAL_CCA 0x0008 /* Defaults to '3' if not set. */
169 #define CPU_MIPS_CACHED_CCA_MASK 0x0070
170 #define CPU_MIPS_CACHED_CCA_SHIFT 4
171 #define CPU_MIPS_DOUBLE_COUNT 0x0080 /* 1 cp0 count == 2 clock cycles */
172 #define CPU_MIPS_USE_WAIT 0x0100 /* Use "wait"-based cpu_idle() */
173 #define CPU_MIPS_NO_WAIT 0x0200 /* Inverse of previous, for mips32/64 */
174 #define CPU_MIPS_D_CACHE_COHERENT 0x0400 /* D-cache is fully coherent */
175 #define CPU_MIPS_I_D_CACHE_COHERENT 0x0800 /* I-cache funcs don't need to flush the D-cache */
176 #define MIPS_NOT_SUPP 0x8000
177
178 #endif /* !_LOCORE */
179
180 #if ((MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS64) == 1) || defined(_LOCORE)
181
182 #if defined(MIPS1)
183
184 # define CPUISMIPS3 0
185 # define CPUIS64BITS 0
186 # define CPUISMIPS32 0
187 # define CPUISMIPS64 0
188 # define CPUISMIPSNN 0
189 # define MIPS_HAS_R4K_MMU 0
190 # define MIPS_HAS_CLOCK 0
191 # define MIPS_HAS_LLSC 0
192
193 #elif defined(MIPS3) || defined(MIPS4)
194
195 # define CPUISMIPS3 1
196 # define CPUIS64BITS 1
197 # define CPUISMIPS32 0
198 # define CPUISMIPS64 0
199 # define CPUISMIPSNN 0
200 # define MIPS_HAS_R4K_MMU 1
201 # define MIPS_HAS_CLOCK 1
202 # if defined(_LOCORE)
203 # if !defined(MIPS3_5900) && !defined(MIPS3_4100)
204 # define MIPS_HAS_LLSC 1
205 # else
206 # define MIPS_HAS_LLSC 0
207 # endif
208 # else /* _LOCORE */
209 # define MIPS_HAS_LLSC (mips_has_llsc)
210 # endif /* _LOCORE */
211
212 #elif defined(MIPS32)
213
214 # define CPUISMIPS3 1
215 # define CPUIS64BITS 0
216 # define CPUISMIPS32 1
217 # define CPUISMIPS64 0
218 # define CPUISMIPSNN 1
219 # define MIPS_HAS_R4K_MMU 1
220 # define MIPS_HAS_CLOCK 1
221 # define MIPS_HAS_LLSC 1
222
223 #elif defined(MIPS64)
224
225 # define CPUISMIPS3 1
226 # define CPUIS64BITS 1
227 # define CPUISMIPS32 0
228 # define CPUISMIPS64 1
229 # define CPUISMIPSNN 1
230 # define MIPS_HAS_R4K_MMU 1
231 # define MIPS_HAS_CLOCK 1
232 # define MIPS_HAS_LLSC 1
233
234 #endif
235
236 #else /* run-time test */
237
238 #ifndef _LOCORE
239
240 #define MIPS_HAS_R4K_MMU (mips_has_r4k_mmu)
241 #define MIPS_HAS_LLSC (mips_has_llsc)
242
243 /* This test is ... rather bogus */
244 #define CPUISMIPS3 ((cpu_arch & \
245 (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
246
247 /* And these aren't much better while the previous test exists as is... */
248 #define CPUISMIPS32 ((cpu_arch & CPU_ARCH_MIPS32) != 0)
249 #define CPUISMIPS64 ((cpu_arch & CPU_ARCH_MIPS64) != 0)
250 #define CPUISMIPSNN ((cpu_arch & (CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
251 #define CPUIS64BITS ((cpu_arch & \
252 (CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS64)) != 0)
253
254 #define MIPS_HAS_CLOCK (cpu_arch >= CPU_ARCH_MIPS3)
255
256 #else /* !_LOCORE */
257
258 #define MIPS_HAS_LLSC 0
259
260 #endif /* !_LOCORE */
261
262 #endif /* run-time test */
263
264 #ifndef _LOCORE
265
266 /*
267 * definitions of cpu-dependent requirements
268 * referenced in generic code
269 */
270 #define cpu_swapout(p) panic("cpu_swapout: can't get here");
271
272 void cpu_intr(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
273
274 /*
275 * Arguments to hardclock and gatherstats encapsulate the previous
276 * machine state in an opaque clockframe.
277 */
278 struct clockframe {
279 int pc; /* program counter at time of interrupt */
280 int sr; /* status register at time of interrupt */
281 int ppl; /* previous priority level at time of interrupt */
282 };
283
284 /*
285 * A port must provde CLKF_USERMODE() for use in machine-independent code.
286 * These differ on r4000 and r3000 systems; provide them in the
287 * port-dependent file that includes this one, using the macros below.
288 */
289
290 /* mips1 versions */
291 #define MIPS1_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KU_PREV)
292
293 /* mips3 versions */
294 #define MIPS3_CLKF_USERMODE(framep) ((framep)->sr & MIPS_SR_KSU_USER)
295
296 #define CLKF_PC(framep) ((framep)->pc)
297 #define CLKF_INTR(framep) (0)
298
299 #if defined(MIPS3_PLUS) && !defined(MIPS1) /* XXX bogus! */
300 #define CLKF_USERMODE(framep) MIPS3_CLKF_USERMODE(framep)
301 #endif
302
303 #if !defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
304 #define CLKF_USERMODE(framep) MIPS1_CLKF_USERMODE(framep)
305 #endif
306
307 #if defined(MIPS3_PLUS) && defined(MIPS1) /* XXX bogus! */
308 #define CLKF_USERMODE(framep) \
309 ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep): MIPS1_CLKF_USERMODE(framep))
310 #endif
311
312 /*
313 * This is used during profiling to integrate system time. It can safely
314 * assume that the process is resident.
315 */
316 #define PROC_PC(p) \
317 (((struct frame *)(p)->p_md.md_regs)->f_regs[37]) /* XXX PC */
318
319 /*
320 * Preempt the current process if in interrupt from user mode,
321 * or after the current trap/syscall if in system mode.
322 */
323 void cpu_need_resched(struct cpu_info *, int);
324
325 /*
326 * Give a profiling tick to the current process when the user profiling
327 * buffer pages are invalid. On the MIPS, request an ast to send us
328 * through trap, marking the proc as needing a profiling tick.
329 */
330 #define cpu_need_proftick(l) \
331 do { \
332 (l)->l_pflag |= LP_OWEUPC; \
333 aston(l); \
334 } while (/*CONSTCOND*/0)
335
336 /*
337 * Notify the current lwp (l) that it has a signal pending,
338 * process as soon as possible.
339 */
340 #define cpu_signotify(l) aston(l)
341
342 #define aston(l) ((l)->l_md.md_astpending = 1)
343
344 /*
345 * Misc prototypes and variable declarations.
346 */
347 struct lwp;
348 struct user;
349
350 extern struct segtab *segbase; /* current segtab base */
351
352 /* trap.c */
353 void netintr(void);
354 int kdbpeek(vaddr_t);
355
356 /* mips_machdep.c */
357 void dumpsys(void);
358 int savectx(struct user *);
359 void mips_init_msgbuf(void);
360 void savefpregs(struct lwp *);
361 void loadfpregs(struct lwp *);
362
363 /* locore*.S */
364 int badaddr(void *, size_t);
365 int badaddr64(uint64_t, size_t);
366
367 /* mips_machdep.c */
368 void cpu_identify(void);
369 void mips_vector_init(void);
370
371 #endif /* ! _LOCORE */
372 #endif /* _KERNEL */
373 #endif /* _CPU_H_ */
374