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