xref: /netbsd-src/sys/arch/mips/include/cpu.h (revision b757af438b42b93f8c6571f026d8b8ef3eaf5fc9)
1 /*	$NetBSD: cpu.h,v 1.106 2011/09/22 05:08:52 macallan 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 
48 #if defined(_KERNEL_OPT)
49 #include "opt_cputype.h"
50 #include "opt_lockdebug.h"
51 #include "opt_multiprocessor.h"
52 #endif
53 
54 #ifndef _LOCORE
55 #include <sys/cpu_data.h>
56 #include <sys/device_if.h>
57 #include <sys/evcnt.h>
58 
59 typedef struct cpu_watchpoint {
60 	register_t	cw_addr;
61 	register_t	cw_mask;
62 	uint32_t	cw_asid;
63 	uint32_t	cw_mode;
64 } cpu_watchpoint_t;
65 /* (abstract) mode bits */
66 #define CPUWATCH_WRITE	__BIT(0)
67 #define CPUWATCH_READ	__BIT(1)
68 #define CPUWATCH_EXEC	__BIT(2)
69 #define CPUWATCH_MASK	__BIT(3)
70 #define CPUWATCH_ASID	__BIT(4)
71 #define CPUWATCH_RWX	(CPUWATCH_EXEC|CPUWATCH_READ|CPUWATCH_WRITE)
72 
73 #define CPUWATCH_MAX	8	/* max possible number of watchpoints */
74 
75 u_int		  cpuwatch_discover(void);
76 void		  cpuwatch_free(cpu_watchpoint_t *);
77 cpu_watchpoint_t *cpuwatch_alloc(void);
78 void		  cpuwatch_set_all(void);
79 void		  cpuwatch_clr_all(void);
80 void		  cpuwatch_set(cpu_watchpoint_t *);
81 void		  cpuwatch_clr(cpu_watchpoint_t *);
82 
83 struct cpu_info {
84 	struct cpu_data ci_data;	/* MI per-cpu data */
85 	struct cpu_info *ci_next;	/* Next CPU in list */
86 	struct cpu_softc *ci_softc;	/* chip-dependent hook */
87 	device_t ci_dev;		/* owning device */
88 	cpuid_t ci_cpuid;		/* Machine-level identifier */
89 	u_long ci_cctr_freq;		/* cycle counter frequency */
90 	u_long ci_cpu_freq;		/* CPU frequency */
91 	u_long ci_cycles_per_hz;	/* CPU freq / hz */
92 	u_long ci_divisor_delay;	/* for delay/DELAY */
93 	u_long ci_divisor_recip;	/* unused, for obsolete microtime(9) */
94 	struct lwp *ci_curlwp;		/* currently running lwp */
95 	volatile int ci_want_resched;	/* user preemption pending */
96 	int ci_mtx_count;		/* negative count of held mutexes */
97 	int ci_mtx_oldspl;		/* saved SPL value */
98 	int ci_idepth;			/* hardware interrupt depth */
99 	int ci_cpl;			/* current [interrupt] priority level */
100 	uint32_t ci_next_cp0_clk_intr;	/* for hard clock intr scheduling */
101 	struct evcnt ci_ev_count_compare;		/* hard clock intr counter */
102 	struct evcnt ci_ev_count_compare_missed;	/* hard clock miss counter */
103 	struct lwp *ci_softlwps[SOFTINT_COUNT];
104 	volatile u_int ci_softints;
105 	struct evcnt ci_ev_fpu_loads;	/* fpu load counter */
106 	struct evcnt ci_ev_fpu_saves;	/* fpu save counter */
107 	struct evcnt ci_ev_dsp_loads;	/* dsp load counter */
108 	struct evcnt ci_ev_dsp_saves;	/* dsp save counter */
109 	struct evcnt ci_ev_tlbmisses;
110 
111 	/*
112 	 * Per-cpu pmap information
113 	 */
114 	int ci_tlb_slot;		/* reserved tlb entry for cpu_info */
115 	u_int ci_pmap_asid_cur;		/* current ASID */
116 	struct pmap_tlb_info *ci_tlb_info; /* tlb information for this cpu */
117 	union segtab *ci_pmap_seg0tab;
118 #ifdef _LP64
119 	union segtab *ci_pmap_segtab;
120 #else
121 	vaddr_t ci_pmap_srcbase;	/* starting VA of ephemeral src space */
122 	vaddr_t ci_pmap_dstbase;	/* starting VA of ephemeral dst space */
123 #endif
124 
125 	u_int ci_cpuwatch_count;	/* number of watchpoints on this CPU */
126 	cpu_watchpoint_t ci_cpuwatch_tab[CPUWATCH_MAX];
127 
128 #ifdef MULTIPROCESSOR
129 	volatile u_long ci_flags;
130 	volatile uint64_t ci_request_ipis;
131 					/* bitmask of IPIs requested */
132 					/*  use on chips where hw cannot pass tag */
133 	uint64_t ci_active_ipis;	/* bitmask of IPIs being serviced */
134 	uint32_t ci_ksp_tlb_slot;	/* tlb entry for kernel stack */
135 	struct evcnt ci_evcnt_all_ipis;	/* aggregated IPI counter */
136 	struct evcnt ci_evcnt_per_ipi[NIPIS];	/* individual IPI counters*/
137 	struct evcnt ci_evcnt_synci_activate_rqst;
138 	struct evcnt ci_evcnt_synci_onproc_rqst;
139 	struct evcnt ci_evcnt_synci_deferred_rqst;
140 	struct evcnt ci_evcnt_synci_ipi_rqst;
141 
142 #define	CPUF_PRIMARY	0x01		/* CPU is primary CPU */
143 #define	CPUF_PRESENT	0x02		/* CPU is present */
144 #define	CPUF_RUNNING	0x04		/* CPU is running */
145 #define	CPUF_PAUSED	0x08		/* CPU is paused */
146 #define	CPUF_USERPMAP	0x20		/* CPU has a user pmap activated */
147 #endif
148 
149 };
150 
151 #define	CPU_INFO_ITERATOR		int
152 #define	CPU_INFO_FOREACH(cii, ci)	\
153     (void)(cii), ci = &cpu_info_store; ci != NULL; ci = ci->ci_next
154 
155 #endif /* !_LOCORE */
156 #endif /* _KERNEL */
157 
158 /*
159  * CTL_MACHDEP definitions.
160  */
161 #define CPU_CONSDEV		1	/* dev_t: console terminal device */
162 #define CPU_BOOTED_KERNEL	2	/* string: booted kernel name */
163 #define CPU_ROOT_DEVICE		3	/* string: root device name */
164 #define CPU_LLSC		4	/* OS/CPU supports LL/SC instruction */
165 
166 /*
167  * Platform can override, but note this breaks userland compatibility
168  * with other mips platforms.
169  */
170 #ifndef CPU_MAXID
171 #define CPU_MAXID		5	/* number of valid machdep ids */
172 #endif
173 
174 #ifdef _KERNEL
175 #if defined(_MODULAR) || defined(_LKM) || defined(_STANDALONE)
176 /* Assume all CPU architectures are valid for LKM's and standlone progs */
177 #define	MIPS1		1
178 #define	MIPS3		1
179 #define	MIPS4		1
180 #define	MIPS32		1
181 #define	MIPS32R2	1
182 #define	MIPS64		1
183 #define	MIPS64R2	1
184 #endif
185 
186 #if (MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) == 0
187 #error at least one of MIPS1, MIPS3, MIPS4, MIPS32, MIPS32R2, MIPS64, or MIPS64RR2 must be specified
188 #endif
189 
190 /* Shortcut for MIPS3 or above defined */
191 #if defined(MIPS3) || defined(MIPS4) \
192     || defined(MIPS32) || defined(MIPS32R2) \
193     || defined(MIPS64) || defined(MIPS64R2)
194 
195 #define	MIPS3_PLUS	1
196 #define __HAVE_CPU_COUNTER
197 #else
198 #undef MIPS3_PLUS
199 #endif
200 
201 /*
202  * Macros to find the CPU architecture we're on at run-time,
203  * or if possible, at compile-time.
204  */
205 
206 #define	CPU_ARCH_MIPSx		0		/* XXX unknown */
207 #define	CPU_ARCH_MIPS1		(1 << 0)
208 #define	CPU_ARCH_MIPS2		(1 << 1)
209 #define	CPU_ARCH_MIPS3		(1 << 2)
210 #define	CPU_ARCH_MIPS4		(1 << 3)
211 #define	CPU_ARCH_MIPS5		(1 << 4)
212 #define	CPU_ARCH_MIPS32		(1 << 5)
213 #define	CPU_ARCH_MIPS64		(1 << 6)
214 #define	CPU_ARCH_MIPS32R2	(1 << 7)
215 #define	CPU_ARCH_MIPS64R2	(1 << 8)
216 
217 /* Note: must be kept in sync with -ffixed-?? Makefile.mips. */
218 #define MIPS_CURLWP             $24
219 #define MIPS_CURLWP_QUOTED      "$24"
220 #define MIPS_CURLWP_LABEL	_L_T8
221 #define MIPS_CURLWP_REG		_R_T8
222 #define TF_MIPS_CURLWP(x)	TF_REG_T8(x)
223 
224 #ifndef _LOCORE
225 
226 extern struct cpu_info cpu_info_store;
227 register struct lwp *mips_curlwp asm(MIPS_CURLWP_QUOTED);
228 
229 #define	curlwp			mips_curlwp
230 #define	curcpu()		(curlwp->l_cpu)
231 #define	curpcb			((struct pcb *)lwp_getpcb(curlwp))
232 #ifdef MULTIPROCESSOR
233 #define	cpu_number()		(curcpu()->ci_index)
234 #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
235 #else
236 #define	cpu_number()		(0)
237 #define	CPU_IS_PRIMARY(ci)	(true)
238 #endif
239 
240 /* XXX simonb
241  * Should the following be in a cpu_info type structure?
242  * And how many of these are per-cpu vs. per-system?  (Ie,
243  * we can assume that all cpus have the same mmu-type, but
244  * maybe not that all cpus run at the same clock speed.
245  * Some SGI's apparently support R12k and R14k in the same
246  * box.)
247  */
248 struct mips_options {
249 	const struct pridtab *mips_cpu;
250 
251 	u_int mips_cpu_arch;
252 	u_int mips_cpu_mhz; /* CPU speed in MHz, estimated by mc_cpuspeed(). */
253 	u_int mips_cpu_flags;
254 	u_int mips_num_tlb_entries;
255 	mips_prid_t mips_cpu_id;
256 	mips_prid_t mips_fpu_id;
257 	bool mips_has_r4k_mmu;
258 	bool mips_has_llsc;
259 	u_int mips3_pg_shift;
260 	u_int mips3_pg_cached;
261 	u_int mips3_cca_devmem;
262 #ifdef MIPS3_PLUS
263 #ifdef _LP64
264 	uint64_t mips3_xkphys_cached;
265 #endif
266 	uint64_t mips3_tlb_vpn_mask;
267 	uint64_t mips3_tlb_pfn_mask;
268 	uint32_t mips3_tlb_pg_mask;
269 #endif
270 };
271 extern struct mips_options mips_options;
272 
273 #define	CPU_MIPS_R4K_MMU		0x0001
274 #define	CPU_MIPS_NO_LLSC		0x0002
275 #define	CPU_MIPS_CAUSE_IV		0x0004
276 #define	CPU_MIPS_HAVE_SPECIAL_CCA	0x0008	/* Defaults to '3' if not set. */
277 #define	CPU_MIPS_CACHED_CCA_MASK	0x0070
278 #define	CPU_MIPS_CACHED_CCA_SHIFT	 4
279 #define	CPU_MIPS_DOUBLE_COUNT		0x0080	/* 1 cp0 count == 2 clock cycles */
280 #define	CPU_MIPS_USE_WAIT		0x0100	/* Use "wait"-based cpu_idle() */
281 #define	CPU_MIPS_NO_WAIT		0x0200	/* Inverse of previous, for mips32/64 */
282 #define	CPU_MIPS_D_CACHE_COHERENT	0x0400	/* D-cache is fully coherent */
283 #define	CPU_MIPS_I_D_CACHE_COHERENT	0x0800	/* I-cache funcs don't need to flush the D-cache */
284 #define	CPU_MIPS_NO_LLADDR		0x1000
285 #define	CPU_MIPS_HAVE_MxCR		0x2000	/* have mfcr, mtcr insns */
286 #define	CPU_MIPS_LOONGSON2		0x4000
287 #define	MIPS_NOT_SUPP			0x8000
288 #define	CPU_MIPS_HAVE_DSP		0x10000
289 
290 #endif	/* !_LOCORE */
291 
292 #if ((MIPS1 + MIPS3 + MIPS4 + MIPS32 + MIPS32R2 + MIPS64 + MIPS64R2) == 1) || defined(_LOCORE)
293 
294 #if defined(MIPS1)
295 
296 # define CPUISMIPS3		0
297 # define CPUIS64BITS		0
298 # define CPUISMIPS32		0
299 # define CPUISMIPS32R2		0
300 # define CPUISMIPS64		0
301 # define CPUISMIPS64R2		0
302 # define CPUISMIPSNN		0
303 # define MIPS_HAS_R4K_MMU	0
304 # define MIPS_HAS_CLOCK		0
305 # define MIPS_HAS_LLSC		0
306 # define MIPS_HAS_LLADDR	0
307 # define MIPS_HAS_DSP		0
308 
309 #elif defined(MIPS3) || defined(MIPS4)
310 
311 # define CPUISMIPS3		1
312 # define CPUIS64BITS		1
313 # define CPUISMIPS32		0
314 # define CPUISMIPS32R2		0
315 # define CPUISMIPS64		0
316 # define CPUISMIPS64R2		0
317 # define CPUISMIPSNN		0
318 # define MIPS_HAS_R4K_MMU	1
319 # define MIPS_HAS_CLOCK		1
320 # if defined(_LOCORE)
321 #  if !defined(MIPS3_4100)
322 #   define MIPS_HAS_LLSC	1
323 #  else
324 #   define MIPS_HAS_LLSC	0
325 #  endif
326 # else	/* _LOCORE */
327 #  define MIPS_HAS_LLSC		(mips_options.mips_has_llsc)
328 # endif	/* _LOCORE */
329 # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
330 # define MIPS_HAS_DSP		0
331 
332 #elif defined(MIPS32)
333 
334 # define CPUISMIPS3		1
335 # define CPUIS64BITS		0
336 # define CPUISMIPS32		1
337 # define CPUISMIPS32R2		0
338 # define CPUISMIPS64		0
339 # define CPUISMIPS64R2		0
340 # define CPUISMIPSNN		1
341 # define MIPS_HAS_R4K_MMU	1
342 # define MIPS_HAS_CLOCK		1
343 # define MIPS_HAS_LLSC		1
344 # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
345 # define MIPS_HAS_DSP		0
346 
347 #elif defined(MIPS32R2)
348 
349 # define CPUISMIPS3		1
350 # define CPUIS64BITS		0
351 # define CPUISMIPS32		0
352 # define CPUISMIPS32R2		1
353 # define CPUISMIPS64		0
354 # define CPUISMIPS64R2		0
355 # define CPUISMIPSNN		1
356 # define MIPS_HAS_R4K_MMU	1
357 # define MIPS_HAS_CLOCK		1
358 # define MIPS_HAS_LLSC		1
359 # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
360 # define MIPS_HAS_DSP		(mips_options.mips_cpu_flags & CPU_MIPS_HAVE_DSP)
361 
362 #elif defined(MIPS64)
363 
364 # define CPUISMIPS3		1
365 # define CPUIS64BITS		1
366 # define CPUISMIPS32		0
367 # define CPUISMIPS32R2		0
368 # define CPUISMIPS64		1
369 # define CPUISMIPS64R2		0
370 # define CPUISMIPSNN		1
371 # define MIPS_HAS_R4K_MMU	1
372 # define MIPS_HAS_CLOCK		1
373 # define MIPS_HAS_LLSC		1
374 # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
375 # define MIPS_HAS_DSP		0
376 
377 #elif defined(MIPS64R2)
378 
379 # define CPUISMIPS3		1
380 # define CPUIS64BITS		1
381 # define CPUISMIPS32		0
382 # define CPUISMIPS32R2		0
383 # define CPUISMIPS64		0
384 # define CPUISMIPS64R2		1
385 # define CPUISMIPSNN		1
386 # define MIPS_HAS_R4K_MMU	1
387 # define MIPS_HAS_CLOCK		1
388 # define MIPS_HAS_LLSC		1
389 # define MIPS_HAS_LLADDR	((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
390 # define MIPS_HAS_DSP		(mips_options.mips_cpu_flags & CPU_MIPS_HAVE_DSP)
391 
392 #endif
393 
394 #else /* run-time test */
395 
396 #ifndef	_LOCORE
397 
398 #define	MIPS_HAS_R4K_MMU	(mips_options.mips_has_r4k_mmu)
399 #define	MIPS_HAS_LLSC		(mips_options.mips_has_llsc)
400 #define	MIPS_HAS_LLADDR		((mips_options.mips_cpu_flags & CPU_MIPS_NO_LLADDR) == 0)
401 # define MIPS_HAS_DSP		(mips_options.mips_cpu_flags & CPU_MIPS_HAVE_DSP)
402 
403 /* This test is ... rather bogus */
404 #define	CPUISMIPS3	((mips_options.mips_cpu_arch & \
405 	(CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS32 | CPU_ARCH_MIPS64)) != 0)
406 
407 /* And these aren't much better while the previous test exists as is... */
408 #define	CPUISMIPS4	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS4) != 0)
409 #define	CPUISMIPS5	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS5) != 0)
410 #define	CPUISMIPS32	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS32) != 0)
411 #define	CPUISMIPS32R2	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS32R2) != 0)
412 #define	CPUISMIPS64	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS64) != 0)
413 #define	CPUISMIPS64R2	((mips_options.mips_cpu_arch & CPU_ARCH_MIPS64R2) != 0)
414 #define	CPUISMIPSNN	((mips_options.mips_cpu_arch & (CPU_ARCH_MIPS32 | CPU_ARCH_MIPS32R2 | CPU_ARCH_MIPS64 | CPU_ARCH_MIPS64R2)) != 0)
415 #define	CPUIS64BITS	((mips_options.mips_cpu_arch & \
416 	(CPU_ARCH_MIPS3 | CPU_ARCH_MIPS4 | CPU_ARCH_MIPS64 | CPU_ARCH_MIPS64R2)) != 0)
417 
418 #define	MIPS_HAS_CLOCK	(mips_options.mips_cpu_arch >= CPU_ARCH_MIPS3)
419 
420 #else	/* !_LOCORE */
421 
422 #define	MIPS_HAS_LLSC	0
423 
424 #endif	/* !_LOCORE */
425 
426 #endif /* run-time test */
427 
428 #ifndef	_LOCORE
429 
430 /*
431  * definitions of cpu-dependent requirements
432  * referenced in generic code
433  */
434 
435 /*
436  * Send an inter-processor interupt to each other CPU (excludes curcpu())
437  */
438 void cpu_broadcast_ipi(int);
439 
440 /*
441  * Send an inter-processor interupt to CPUs in cpuset (excludes curcpu())
442  */
443 void cpu_multicast_ipi(__cpuset_t, int);
444 
445 /*
446  * Send an inter-processor interupt to another CPU.
447  */
448 int cpu_send_ipi(struct cpu_info *, int);
449 
450 /*
451  * cpu_intr(ppl, pc, status);  (most state needed by clockframe)
452  */
453 void cpu_intr(int, vaddr_t, uint32_t);
454 
455 /*
456  * Arguments to hardclock and gatherstats encapsulate the previous
457  * machine state in an opaque clockframe.
458  */
459 struct clockframe {
460 	vaddr_t		pc;	/* program counter at time of interrupt */
461 	uint32_t	sr;	/* status register at time of interrupt */
462 	bool		intr;	/* interrupted a interrupt */
463 };
464 
465 /*
466  * A port must provde CLKF_USERMODE() for use in machine-independent code.
467  * These differ on r4000 and r3000 systems; provide them in the
468  * port-dependent file that includes this one, using the macros below.
469  */
470 
471 /* mips1 versions */
472 #define	MIPS1_CLKF_USERMODE(framep)	((framep)->sr & MIPS_SR_KU_PREV)
473 
474 /* mips3 versions */
475 #define	MIPS3_CLKF_USERMODE(framep)	((framep)->sr & MIPS_SR_KSU_USER)
476 
477 #define	CLKF_PC(framep)		((framep)->pc)
478 #define	CLKF_INTR(framep)	((framep)->intr)
479 
480 #if defined(MIPS3_PLUS) && !defined(MIPS1)		/* XXX bogus! */
481 #define	CLKF_USERMODE(framep)	MIPS3_CLKF_USERMODE(framep)
482 #endif
483 
484 #if !defined(MIPS3_PLUS) && defined(MIPS1)		/* XXX bogus! */
485 #define	CLKF_USERMODE(framep)	MIPS1_CLKF_USERMODE(framep)
486 #endif
487 
488 #if defined(MIPS3_PLUS) && defined(MIPS1)		/* XXX bogus! */
489 #define CLKF_USERMODE(framep) \
490     ((CPUISMIPS3) ? MIPS3_CLKF_USERMODE(framep):  MIPS1_CLKF_USERMODE(framep))
491 #endif
492 
493 /*
494  * Misc prototypes and variable declarations.
495  */
496 #define	LWP_PC(l)	cpu_lwp_pc(l)
497 
498 struct proc;
499 struct lwp;
500 struct pcb;
501 struct reg;
502 
503 /*
504  * Preempt the current process if in interrupt from user mode,
505  * or after the current trap/syscall if in system mode.
506  */
507 void	cpu_need_resched(struct cpu_info *, int);
508 /*
509  * Notify the current lwp (l) that it has a signal pending,
510  * process as soon as possible.
511  */
512 void	cpu_signotify(struct lwp *);
513 
514 /*
515  * Give a profiling tick to the current process when the user profiling
516  * buffer pages are invalid.  On the MIPS, request an ast to send us
517  * through trap, marking the proc as needing a profiling tick.
518  */
519 void	cpu_need_proftick(struct lwp *);
520 void	cpu_set_curpri(int);
521 
522 extern int mips_poolpage_vmfreelist;	/* freelist to allocate poolpages */
523 
524 struct cpu_info *
525 	cpu_info_alloc(struct pmap_tlb_info *, cpuid_t, cpuid_t, cpuid_t,
526 	    cpuid_t);
527 void	cpu_attach_common(device_t, struct cpu_info *);
528 void	cpu_startup_common(void);
529 #ifdef _LP64
530 void	cpu_vmspace_exec(struct lwp *, vaddr_t, vaddr_t);
531 #endif
532 
533 #ifdef MULTIPROCESSOR
534 void	cpu_hatch(struct cpu_info *ci);
535 void	cpu_trampoline(void);
536 void	cpu_boot_secondary_processors(void);
537 void	cpu_halt(void);
538 void	cpu_halt_others(void);
539 void	cpu_pause(struct reg *);
540 void	cpu_pause_others(void);
541 void	cpu_resume(int);
542 void	cpu_resume_others(void);
543 int	cpu_is_paused(int);
544 void	cpu_debug_dump(void);
545 
546 extern volatile __cpuset_t cpus_running;
547 extern volatile __cpuset_t cpus_hatched;
548 extern volatile __cpuset_t cpus_paused;
549 extern volatile __cpuset_t cpus_resumed;
550 extern volatile __cpuset_t cpus_halted;
551 #endif
552 
553 /* copy.S */
554 int32_t kfetch_32(volatile uint32_t *, uint32_t);
555 int8_t	ufetch_int8(void *);
556 int16_t	ufetch_int16(void *);
557 int32_t ufetch_int32(void *);
558 uint8_t	ufetch_uint8(void *);
559 uint16_t ufetch_uint16(void *);
560 uint32_t ufetch_uint32(void *);
561 int8_t	ufetch_int8_intrsafe(void *);
562 int16_t	ufetch_int16_intrsafe(void *);
563 int32_t ufetch_int32_intrsafe(void *);
564 uint8_t	ufetch_uint8_intrsafe(void *);
565 uint16_t ufetch_uint16_intrsafe(void *);
566 uint32_t ufetch_uint32_intrsafe(void *);
567 #ifdef _LP64
568 int64_t ufetch_int64(void *);
569 uint64_t ufetch_uint64(void *);
570 int64_t ufetch_int64_intrsafe(void *);
571 uint64_t ufetch_uint64_intrsafe(void *);
572 #endif
573 char	ufetch_char(void *);
574 short	ufetch_short(void *);
575 int	ufetch_int(void *);
576 long	ufetch_long(void *);
577 char	ufetch_char_intrsafe(void *);
578 short	ufetch_short_intrsafe(void *);
579 int	ufetch_int_intrsafe(void *);
580 long	ufetch_long_intrsafe(void *);
581 
582 u_char	ufetch_uchar(void *);
583 u_short	ufetch_ushort(void *);
584 u_int	ufetch_uint(void *);
585 u_long	ufetch_ulong(void *);
586 u_char	ufetch_uchar_intrsafe(void *);
587 u_short	ufetch_ushort_intrsafe(void *);
588 u_int	ufetch_uint_intrsafe(void *);
589 u_long	ufetch_ulong_intrsafe(void *);
590 void 	*ufetch_ptr(void *);
591 
592 int	ustore_int8(void *, int8_t);
593 int	ustore_int16(void *, int16_t);
594 int	ustore_int32(void *, int32_t);
595 int	ustore_uint8(void *, uint8_t);
596 int	ustore_uint16(void *, uint16_t);
597 int	ustore_uint32(void *, uint32_t);
598 int	ustore_int8_intrsafe(void *, int8_t);
599 int	ustore_int16_intrsafe(void *, int16_t);
600 int	ustore_int32_intrsafe(void *, int32_t);
601 int	ustore_uint8_intrsafe(void *, uint8_t);
602 int	ustore_uint16_intrsafe(void *, uint16_t);
603 int	ustore_uint32_intrsafe(void *, uint32_t);
604 #ifdef _LP64
605 int	ustore_int64(void *, int64_t);
606 int	ustore_uint64(void *, uint64_t);
607 int	ustore_int64_intrsafe(void *, int64_t);
608 int	ustore_uint64_intrsafe(void *, uint64_t);
609 #endif
610 int	ustore_char(void *, char);
611 int	ustore_char_intrsafe(void *, char);
612 int	ustore_short(void *, short);
613 int	ustore_short_intrsafe(void *, short);
614 int	ustore_int(void *, int);
615 int	ustore_int_intrsafe(void *, int);
616 int	ustore_long(void *, long);
617 int	ustore_long_intrsafe(void *, long);
618 int	ustore_uchar(void *, u_char);
619 int	ustore_uchar_intrsafe(void *, u_char);
620 int	ustore_ushort(void *, u_short);
621 int	ustore_ushort_intrsafe(void *, u_short);
622 int	ustore_uint(void *, u_int);
623 int	ustore_uint_intrsafe(void *, u_int);
624 int	ustore_ulong(void *, u_long);
625 int	ustore_ulong_intrsafe(void *, u_long);
626 int 	ustore_ptr(void *, void *);
627 int	ustore_ptr_intrsafe(void *, void *);
628 
629 int	ustore_uint32_isync(void *, uint32_t);
630 
631 /* trap.c */
632 void	netintr(void);
633 int	kdbpeek(vaddr_t);
634 
635 /* mips_dsp.c */
636 void	dsp_init(void);
637 void	dsp_discard(void);
638 void	dsp_load(void);
639 void	dsp_save(void);
640 bool	dsp_used_p(void);
641 extern const pcu_ops_t mips_dsp_ops;
642 
643 /* mips_fpu.c */
644 void	fpu_init(void);
645 void	fpu_discard(void);
646 void	fpu_load(void);
647 void	fpu_save(void);
648 bool	fpu_used_p(void);
649 extern const pcu_ops_t mips_fpu_ops;
650 
651 /* mips_machdep.c */
652 void	dumpsys(void);
653 int	savectx(struct pcb *);
654 void	cpu_identify(device_t);
655 
656 /* locore*.S */
657 int	badaddr(void *, size_t);
658 int	badaddr64(uint64_t, size_t);
659 
660 /* vm_machdep.c */
661 void *	cpu_uarea_alloc(bool);
662 bool	cpu_uarea_free(void *);
663 void	cpu_proc_fork(struct proc *, struct proc *);
664 vaddr_t	cpu_lwp_pc(struct lwp *);
665 int	ioaccess(vaddr_t, paddr_t, vsize_t);
666 int	iounaccess(vaddr_t, vsize_t);
667 
668 #endif /* ! _LOCORE */
669 #endif /* _KERNEL */
670 #endif /* _CPU_H_ */
671