xref: /openbsd-src/sys/arch/mips64/include/cpu.h (revision bffdb31288634c80f42ab5f5773f1455e7b69f61)
1*bffdb312Smpi /*	$OpenBSD: cpu.h,v 1.150 2024/10/23 07:40:20 mpi Exp $	*/
2f58c7388Spefo 
3f58c7388Spefo /*-
4f58c7388Spefo  * Copyright (c) 1992, 1993
5f58c7388Spefo  *	The Regents of the University of California.  All rights reserved.
6f58c7388Spefo  *
7f58c7388Spefo  * This code is derived from software contributed to Berkeley by
8f58c7388Spefo  * Ralph Campbell and Rick Macklem.
9f58c7388Spefo  *
10f58c7388Spefo  * Redistribution and use in source and binary forms, with or without
11f58c7388Spefo  * modification, are permitted provided that the following conditions
12f58c7388Spefo  * are met:
13f58c7388Spefo  * 1. Redistributions of source code must retain the above copyright
14f58c7388Spefo  *    notice, this list of conditions and the following disclaimer.
15f58c7388Spefo  * 2. Redistributions in binary form must reproduce the above copyright
16f58c7388Spefo  *    notice, this list of conditions and the following disclaimer in the
17f58c7388Spefo  *    documentation and/or other materials provided with the distribution.
1853aa784aSmiod  * 3. Neither the name of the University nor the names of its contributors
19f58c7388Spefo  *    may be used to endorse or promote products derived from this software
20f58c7388Spefo  *    without specific prior written permission.
21f58c7388Spefo  *
22f58c7388Spefo  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23f58c7388Spefo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24f58c7388Spefo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25f58c7388Spefo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26f58c7388Spefo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27f58c7388Spefo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28f58c7388Spefo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29f58c7388Spefo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30f58c7388Spefo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31f58c7388Spefo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32f58c7388Spefo  * SUCH DAMAGE.
33f58c7388Spefo  *
34f58c7388Spefo  *	Copyright (C) 1989 Digital Equipment Corporation.
35f58c7388Spefo  *	Permission to use, copy, modify, and distribute this software and
36f58c7388Spefo  *	its documentation for any purpose and without fee is hereby granted,
37f58c7388Spefo  *	provided that the above copyright notice appears in all copies.
38f58c7388Spefo  *	Digital Equipment Corporation makes no representations about the
39f58c7388Spefo  *	suitability of this software for any purpose.  It is provided "as is"
40f58c7388Spefo  *	without express or implied warranty.
41f58c7388Spefo  *
42f58c7388Spefo  *	from: @(#)cpu.h	8.4 (Berkeley) 1/4/94
43f58c7388Spefo  */
44f58c7388Spefo 
452fa72412Spirofti #ifndef _MIPS64_CPU_H_
462fa72412Spirofti #define	_MIPS64_CPU_H_
47f58c7388Spefo 
4871b9f840Smiod #ifndef _LOCORE
4971b9f840Smiod 
50abf66238Smiod /*
51abf66238Smiod  * MIPS32-style segment definitions.
52abf66238Smiod  * They only cover the first 512MB of physical addresses.
53abf66238Smiod  */
5471b9f840Smiod #define	CKSEG0_BASE		0xffffffff80000000UL
5571b9f840Smiod #define	CKSEG1_BASE		0xffffffffa0000000UL
5671b9f840Smiod #define	CKSSEG_BASE		0xffffffffc0000000UL
5771b9f840Smiod #define	CKSEG3_BASE		0xffffffffe0000000UL
5871b9f840Smiod #define	CKSEG_SIZE		0x0000000020000000UL
59f58c7388Spefo 
6071b9f840Smiod #define	CKSEG0_TO_PHYS(x)	((u_long)(x) & (CKSEG_SIZE - 1))
6171b9f840Smiod #define	CKSEG1_TO_PHYS(x)	((u_long)(x) & (CKSEG_SIZE - 1))
6271b9f840Smiod #define	PHYS_TO_CKSEG0(x)	((u_long)(x) | CKSEG0_BASE)
6371b9f840Smiod #define	PHYS_TO_CKSEG1(x)	((u_long)(x) | CKSEG1_BASE)
64f58c7388Spefo 
65edb45030Smiod /*
66abf66238Smiod  * MIPS64-style segment definitions.
67abf66238Smiod  * These allow for 36 bits of addressable physical memory, thus 64GB.
68edb45030Smiod  */
69abf66238Smiod 
70abf66238Smiod /*
71abf66238Smiod  * Cache Coherency Attributes.
72abf66238Smiod  */
73abf66238Smiod /* r8k only */
74abf66238Smiod #define	CCA_NC_COPROCESSOR	0UL	/* uncached, coprocessor ordered */
75abf66238Smiod /* common to r4, r5k, r8k and r1xk */
76edb45030Smiod #define	CCA_NC			2UL	/* uncached, write-around */
77edb45030Smiod #define	CCA_NONCOHERENT		3UL	/* cached, non-coherent, write-back */
78abf66238Smiod /* r8k, r1xk only */
79abf66238Smiod #define	CCA_COHERENT_EXCL	4UL	/* cached, coherent, exclusive */
80abf66238Smiod #define	CCA_COHERENT_EXCLWRITE	5UL	/* cached, coherent, exclusive write */
81abf66238Smiod /* r4k only */
82abf66238Smiod #define	CCA_COHERENT_UPDWRITE	6UL	/* cached, coherent, update on write */
83547c5d1dSmiod /* r1xk only */
84547c5d1dSmiod #define	CCA_NC_ACCELERATED	7UL	/* uncached accelerated */
85abf66238Smiod 
86abf66238Smiod #ifdef TGT_COHERENT
87abf66238Smiod #define	CCA_CACHED		CCA_COHERENT_EXCLWRITE
88abf66238Smiod #else
89abf66238Smiod #define	CCA_CACHED		CCA_NONCOHERENT
90052d47d4Smiod #endif
91edb45030Smiod 
9271b9f840Smiod #define	XKSSSEG_BASE		0x4000000000000000UL
93edb45030Smiod #define	XKPHYS_BASE		0x8000000000000000UL
9471b9f840Smiod #define	XKSSEG_BASE		0xc000000000000000UL
9571b9f840Smiod 
96edb45030Smiod #define	XKPHYS_TO_PHYS(x)	((paddr_t)(x) & 0x0000000fffffffffUL)
97abf66238Smiod #define	PHYS_TO_XKPHYS(x,c)	((paddr_t)(x) | XKPHYS_BASE | ((c) << 59))
98edb45030Smiod #define	IS_XKPHYS(va)		(((va) >> 62) == 2)
995951a7daSmiod #define	XKPHYS_TO_CCA(x)	(((x) >> 59) & 0x07)
100edb45030Smiod 
10171b9f840Smiod #endif	/* _LOCORE */
10271b9f840Smiod 
103f58c7388Spefo /*
104f58c7388Spefo  * Exported definitions unique to mips cpu support.
105f58c7388Spefo  */
106f58c7388Spefo 
1078382e3ccSmiod #if defined(_KERNEL) && !defined(_LOCORE)
1080b8ac74bSkettenis 
109f124c57cScheloha #include <sys/clockintr.h>
1109117996aSsyuu #include <sys/device.h>
1119117996aSsyuu #include <machine/intr.h>
112056c6503Smiod #include <sys/sched.h>
1131a1181a9Sjsg #include <sys/srp.h>
114cea0d947Smiod #include <uvm/uvm_percpu.h>
1159117996aSsyuu 
116c301e791Smiod struct cpu_hwinfo {
117c301e791Smiod 	uint32_t	c0prid;
118c301e791Smiod 	uint32_t	c1prid;
119c301e791Smiod 	uint32_t	clock;	/* Hz */
120c301e791Smiod 	uint32_t	tlbsize;
121c301e791Smiod 	uint		type;
12269307465Smiod 	uint32_t	l2size;
123c301e791Smiod };
124c301e791Smiod 
125d6930de2Smiod /*
126d6930de2Smiod  * Cache memory configuration. One struct per cache.
127d6930de2Smiod  */
128d6930de2Smiod struct cache_info {
129d6930de2Smiod 	uint		size;		/* total cache size */
130d6930de2Smiod 	uint		linesize;	/* line size */
131d6930de2Smiod 	uint		setsize;	/* set size */
132d6930de2Smiod 	uint		sets;		/* number of sets */
133d6930de2Smiod };
134d6930de2Smiod 
1350b8ac74bSkettenis struct cpu_info {
13692c3bdc8Ssyuu 	struct device	*ci_dev;	/* our device */
1379117996aSsyuu 	struct cpu_info	*ci_self;	/* pointer to this structure */
1389117996aSsyuu 	struct cpu_info	*ci_next;	/* next cpu */
1390b8ac74bSkettenis 	struct proc	*ci_curproc;
1401b9cca20Ssyuu 	struct user	*ci_curprocpaddr;
1415d65c980Ssyuu 	struct proc	*ci_fpuproc;	/* pointer to last proc to use FP */
1421c8c6138Smiod 	uint32_t	 ci_delayconst;
143c301e791Smiod 	struct cpu_hwinfo
144c301e791Smiod 			ci_hw;
145c1805af1Smiod 
14652776b7dSdlg #if defined(MULTIPROCESSOR)
14752776b7dSdlg 	struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM];
148cea0d947Smiod #define __HAVE_UVM_PERCPU
149cea0d947Smiod 	struct uvm_pmr_cache	ci_uvm;
15052776b7dSdlg #endif
15152776b7dSdlg 
15280941abeSmiod 	/* cache information and pending flush state */
153c1805af1Smiod 	uint		ci_cacheconfiguration;
15480941abeSmiod 	uint64_t	ci_cachepending_l1i;
155d6930de2Smiod 	struct cache_info
156d6930de2Smiod 			ci_l1inst,
157d6930de2Smiod 			ci_l1data,
158d6930de2Smiod 			ci_l2,
159d6930de2Smiod 			ci_l3;
160c1805af1Smiod 
16187543086Smiod 	/* function pointers for the cache handling routines */
16287543086Smiod 	void		(*ci_SyncCache)(struct cpu_info *);
16387543086Smiod 	void		(*ci_InvalidateICache)(struct cpu_info *, vaddr_t,
16487543086Smiod 			    size_t);
16580941abeSmiod 	void		(*ci_InvalidateICachePage)(struct cpu_info *, vaddr_t);
16680941abeSmiod 	void		(*ci_SyncICache)(struct cpu_info *);
16787543086Smiod 	void		(*ci_SyncDCachePage)(struct cpu_info *, vaddr_t,
16887543086Smiod 			    paddr_t);
1691a4be959Svisa 	void		(*ci_HitSyncDCachePage)(struct cpu_info *, vaddr_t,
1701a4be959Svisa 			    paddr_t);
17187543086Smiod 	void		(*ci_HitSyncDCache)(struct cpu_info *, vaddr_t, size_t);
17287543086Smiod 	void		(*ci_HitInvalidateDCache)(struct cpu_info *, vaddr_t,
17387543086Smiod 			    size_t);
17487543086Smiod 	void		(*ci_IOSyncDCache)(struct cpu_info *, vaddr_t, size_t,
17587543086Smiod 			    int);
17687543086Smiod 
177a2bf8699Smiod 	struct schedstate_percpu
178a2bf8699Smiod 			ci_schedstate;
179a2bf8699Smiod 	int		ci_want_resched;	/* need_resched() invoked */
1809117996aSsyuu 	cpuid_t		ci_cpuid;		/* our CPU ID */
18116a9d6c0Smiod 	uint32_t	ci_randseed;		/* per cpu random seed */
182cb5217fbSvisa 	volatile int	ci_ipl;			/* software IPL */
183648adb54Smiod 	uint32_t	ci_softpending;		/* pending soft interrupts */
18425879624Ssyuu 	int		ci_clock_started;
18585caa4b9Scheloha 	volatile int	ci_clock_deferred;	/* clock interrupt postponed */
186c737cf90Scheloha 	struct clockqueue
187f124c57cScheloha 			ci_queue;
1887e891e3bSmiod 
1899bda246cSsyuu 	struct pmap	*ci_curpmap;
190*bffdb312Smpi 	uint		ci_idepth;		/* interrupt depth */
1919117996aSsyuu #ifdef MULTIPROCESSOR
192e8c48788Smiod 	volatile u_long	ci_flags;		/* flags; see below */
1939117996aSsyuu #endif
1943edbacd7Ssyuu 	volatile int    ci_ddb;
1953edbacd7Ssyuu #define	CI_DDB_RUNNING		0
1963edbacd7Ssyuu #define	CI_DDB_SHOULDSTOP	1
1973edbacd7Ssyuu #define	CI_DDB_STOPPED		2
1983edbacd7Ssyuu #define	CI_DDB_ENTERDDB		3
1993edbacd7Ssyuu #define	CI_DDB_INDDB		4
200ac5996fcSmiod 
201ac5996fcSmiod #ifdef DIAGNOSTIC
202ac5996fcSmiod 	int		ci_mutex_level;
203ac5996fcSmiod #endif
2046377c2eaSmpi #ifdef GPROF
2056377c2eaSmpi 	struct gmonparam *ci_gmon;
2061d970828Scheloha 	struct clockintr ci_gmonclock;
2076377c2eaSmpi #endif
2081a4a9ab2Scheloha 	char		ci_panicbuf[512];
2090b8ac74bSkettenis };
2100b8ac74bSkettenis 
2119117996aSsyuu #define	CPUF_PRIMARY	0x01		/* CPU is primary CPU */
2129117996aSsyuu #define	CPUF_PRESENT	0x02		/* CPU is present */
2139117996aSsyuu #define	CPUF_RUNNING	0x04		/* CPU is running */
2149117996aSsyuu 
2150b8ac74bSkettenis extern struct cpu_info cpu_info_primary;
2169117996aSsyuu extern struct cpu_info *cpu_info_list;
2170b8ac74bSkettenis #define CPU_INFO_ITERATOR		int
2189117996aSsyuu #define	CPU_INFO_FOREACH(cii, ci)	for (cii = 0, ci = cpu_info_list; \
2199117996aSsyuu 					    ci != NULL; ci = ci->ci_next)
2200b8ac74bSkettenis 
22192c3bdc8Ssyuu #define CPU_INFO_UNIT(ci)               ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0)
2229117996aSsyuu 
22396b227e7Sguenther #define	cpu_idle_enter()	do { /* nothing */ } while (0)
22496b227e7Sguenther #define	cpu_idle_leave()	do { /* nothing */ } while (0)
225e79d7867Svisa extern void (*cpu_idle_cycle_func)(void);
226e79d7867Svisa #define cpu_idle_cycle()		(*cpu_idle_cycle_func)()
227e79d7867Svisa 
2289117996aSsyuu #ifdef MULTIPROCESSOR
2291d6e3571Ssyuu #define getcurcpu()			hw_getcurcpu()
2301d6e3571Ssyuu #define setcurcpu(ci)			hw_setcurcpu(ci)
231afdabf13Ssyuu extern struct cpu_info *get_cpu_info(int);
232afdabf13Ssyuu #define curcpu() getcurcpu()
2339117996aSsyuu #define	CPU_IS_PRIMARY(ci)		((ci)->ci_flags & CPUF_PRIMARY)
234d73de46fSkettenis #define	CPU_IS_RUNNING(ci)		((ci)->ci_flags & CPUF_RUNNING)
235afdabf13Ssyuu #define cpu_number()			(curcpu()->ci_cpuid)
2369117996aSsyuu 
2379117996aSsyuu void cpu_unidle(struct cpu_info *);
2389117996aSsyuu void cpu_boot_secondary_processors(void);
239d52140c2Ssyuu #define cpu_boot_secondary(ci)          hw_cpu_boot_secondary(ci)
240d52140c2Ssyuu #define cpu_hatch(ci)                   hw_cpu_hatch(ci)
2419117996aSsyuu 
242afdabf13Ssyuu vaddr_t alloc_contiguous_pages(size_t);
24392c3bdc8Ssyuu 
244fc9490a2Ssyuu #define MIPS64_IPI_NOP		0x00000001
2457d157f4aSsyuu #define MIPS64_IPI_RENDEZVOUS	0x00000002
2463edbacd7Ssyuu #define MIPS64_IPI_DDB		0x00000004
2473edbacd7Ssyuu #define MIPS64_NIPIS		3	/* must not exceed 32 */
248fc9490a2Ssyuu 
249fc9490a2Ssyuu void	mips64_ipi_init(void);
250fc9490a2Ssyuu void	mips64_send_ipi(unsigned int, unsigned int);
2517d157f4aSsyuu void	smp_rendezvous_cpus(unsigned long, void (*)(void *), void *arg);
252fc9490a2Ssyuu 
2539117996aSsyuu #include <sys/mplock.h>
2549117996aSsyuu #else
2559117996aSsyuu #define MAXCPUS				1
2569117996aSsyuu #define curcpu()			(&cpu_info_primary)
2579117996aSsyuu #define	CPU_IS_PRIMARY(ci)		1
258d73de46fSkettenis #define	CPU_IS_RUNNING(ci)		1
259282d9ab5Sderaadt #define cpu_number()			0UL
2609117996aSsyuu #define cpu_unidle(ci)
2613edbacd7Ssyuu #define get_cpu_info(i)			(&cpu_info_primary)
2629117996aSsyuu #endif
2630b8ac74bSkettenis 
264b43d7c27Sjca #define CPU_BUSY_CYCLE()	__asm volatile ("" ::: "memory")
26565f535b7Suebayasi 
26611d1f9b2Scheloha extern void (*md_initclock)(void);
26719fc6073Smiod extern void (*md_startclock)(struct cpu_info *);
26885caa4b9Scheloha extern void (*md_triggerclock)(void);
26919fc6073Smiod void	cp0_calibrate(struct cpu_info *);
27025879624Ssyuu 
27101802d2cSdlg unsigned int cpu_rnd_messybits(void);
27201802d2cSdlg 
273f58c7388Spefo #include <machine/frame.h>
2745dac4f4fSmiod 
275f58c7388Spefo /*
27604b4a84fSmiod  * Arguments to hardclock encapsulate the previous machine state in
27704b4a84fSmiod  * an opaque clockframe.
278f58c7388Spefo  */
279b43ebd13Smpi #define	clockframe trapframe	/* Use normal trap frame */
280f58c7388Spefo 
2817b6ae6a5Smiod #define	SR_KSU_USER		0x00000010
282f58c7388Spefo #define	CLKF_USERMODE(framep)	((framep)->sr & SR_KSU_USER)
283f58c7388Spefo #define	CLKF_PC(framep)		((framep)->pc)
284*bffdb312Smpi #define	CLKF_INTR(framep)	(curcpu()->ci_idepth > 1)	/* XXX */
285f58c7388Spefo 
286f58c7388Spefo /*
2874516c5b4Smiod  * This is used during profiling to integrate system time.
2884516c5b4Smiod  */
2894516c5b4Smiod #define	PROC_PC(p)	((p)->p_md.md_regs->pc)
2901eaa59e7Sguenther #define	PROC_STACK(p)	((p)->p_md.md_regs->sp)
2914516c5b4Smiod 
2924516c5b4Smiod /*
293f58c7388Spefo  * Preempt the current process if in interrupt from user mode,
294f58c7388Spefo  * or after the current trap/syscall if in system mode.
295f58c7388Spefo  */
29600c79297Svisa void	need_resched(struct cpu_info *);
297a2bf8699Smiod #define	clear_resched(ci) 	(ci)->ci_want_resched = 0
298f58c7388Spefo 
299f58c7388Spefo /*
300f58c7388Spefo  * Give a profiling tick to the current process when the user profiling
301014dc27dSmiod  * buffer pages are invalid.  On MIPS designs, request an ast to send us
302f58c7388Spefo  * through trap, marking the proc as needing a profiling tick.
303f58c7388Spefo  */
304a2bf8699Smiod #define	need_proftick(p)	aston(p)
305f58c7388Spefo 
306f58c7388Spefo /*
307f58c7388Spefo  * Notify the current process (p) that it has a signal pending,
308f58c7388Spefo  * process as soon as possible.
309f58c7388Spefo  */
31000c79297Svisa void	signotify(struct proc *);
311f58c7388Spefo 
3123870118eSmmcc #define	aston(p)		((p)->p_md.md_astpending = 1)
313f58c7388Spefo 
3142df76cc2Sguenther #define	mips_sync()		__asm__ volatile ("sync" ::: "memory")
315c40b02a1Smiod 
3168382e3ccSmiod #endif /* _KERNEL && !_LOCORE */
317f58c7388Spefo 
3187b6ae6a5Smiod #ifdef _KERNEL
3197b6ae6a5Smiod /*
3207b6ae6a5Smiod  * Values for the code field in a break instruction.
3217b6ae6a5Smiod  */
3227b6ae6a5Smiod #define	BREAK_INSTR		0x0000000d
3237b6ae6a5Smiod #define	BREAK_VAL_MASK		0x03ff0000
3247b6ae6a5Smiod #define	BREAK_VAL_SHIFT		16
3257b6ae6a5Smiod #define	BREAK_KDB_VAL		512
3267b6ae6a5Smiod #define	BREAK_SSTEP_VAL		513
3277b6ae6a5Smiod #define	BREAK_BRKPT_VAL		514
3287b6ae6a5Smiod #define	BREAK_SOVER_VAL		515
3297b6ae6a5Smiod #define	BREAK_DDB_VAL		516
3307b6ae6a5Smiod #define	BREAK_FPUEMUL_VAL	517
3317b6ae6a5Smiod #define	BREAK_KDB	(BREAK_INSTR | (BREAK_KDB_VAL << BREAK_VAL_SHIFT))
3327b6ae6a5Smiod #define	BREAK_SSTEP	(BREAK_INSTR | (BREAK_SSTEP_VAL << BREAK_VAL_SHIFT))
3337b6ae6a5Smiod #define	BREAK_BRKPT	(BREAK_INSTR | (BREAK_BRKPT_VAL << BREAK_VAL_SHIFT))
3347b6ae6a5Smiod #define	BREAK_SOVER	(BREAK_INSTR | (BREAK_SOVER_VAL << BREAK_VAL_SHIFT))
3357b6ae6a5Smiod #define	BREAK_DDB	(BREAK_INSTR | (BREAK_DDB_VAL << BREAK_VAL_SHIFT))
3367b6ae6a5Smiod #define	BREAK_FPUEMUL	(BREAK_INSTR | (BREAK_FPUEMUL_VAL << BREAK_VAL_SHIFT))
3377b6ae6a5Smiod 
3387b6ae6a5Smiod #endif /* _KERNEL */
3397b6ae6a5Smiod 
340f58c7388Spefo /*
341f58c7388Spefo  * CTL_MACHDEP definitions.
342f58c7388Spefo  */
343f58c7388Spefo #define	CPU_ALLOWAPERTURE	1	/* allow mmap of /dev/xf86 */
344b2e0f490Snaddy 		/*		2	   formerly: keyboard reset */
34539325887Snatano 		/*		3	   formerly: CPU_LIDSUSPEND */
3462d357aedSnatano #define CPU_LIDACTION		4	/* action caused by lid close */
3472d357aedSnatano #define	CPU_MAXID		5	/* number of valid machdep ids */
348f58c7388Spefo 
349f58c7388Spefo #define	CTL_MACHDEP_NAMES {			\
350f58c7388Spefo 	{ 0, 0 },				\
351f58c7388Spefo 	{ "allowaperture", CTLTYPE_INT },	\
352b2e0f490Snaddy 	{ 0, 0 },				\
35339325887Snatano 	{ 0, 0 },				\
3542d357aedSnatano 	{ "lidaction", CTLTYPE_INT },		\
355f58c7388Spefo }
356f58c7388Spefo 
357f58c7388Spefo /*
358f58c7388Spefo  * MIPS CPU types (cp_imp).
359f58c7388Spefo  */
360f58c7388Spefo #define	MIPS_R2000	0x01	/* MIPS R2000 CPU		ISA I   */
361f58c7388Spefo #define	MIPS_R3000	0x02	/* MIPS R3000 CPU		ISA I   */
362f58c7388Spefo #define	MIPS_R6000	0x03	/* MIPS R6000 CPU		ISA II	*/
363f58c7388Spefo #define	MIPS_R4000	0x04	/* MIPS R4000/4400 CPU		ISA III	*/
364f58c7388Spefo #define	MIPS_R3LSI	0x05	/* LSI Logic R3000 derivate	ISA I	*/
365f58c7388Spefo #define	MIPS_R6000A	0x06	/* MIPS R6000A CPU		ISA II	*/
36654b315e0Svisa #define	MIPS_CN50XX	0x06	/* Cavium OCTEON CN50xx		MIPS64R2*/
367f58c7388Spefo #define	MIPS_R3IDT	0x07	/* IDT R3000 derivate		ISA I	*/
368f58c7388Spefo #define	MIPS_R10000	0x09	/* MIPS R10000/T5 CPU		ISA IV  */
369f58c7388Spefo #define	MIPS_R4200	0x0a	/* MIPS R4200 CPU (ICE)		ISA III */
370f58c7388Spefo #define	MIPS_R4300	0x0b	/* NEC VR4300 CPU		ISA III */
371f58c7388Spefo #define	MIPS_R4100	0x0c	/* NEC VR41xx CPU MIPS-16	ISA III */
37252aecc03Spefo #define	MIPS_R12000	0x0e	/* MIPS R12000			ISA IV  */
37352aecc03Spefo #define	MIPS_R14000	0x0f	/* MIPS R14000			ISA IV  */
374f58c7388Spefo #define	MIPS_R8000	0x10	/* MIPS R8000 Blackbird/TFP	ISA IV  */
375f58c7388Spefo #define	MIPS_R4600	0x20	/* PMCS R4600 Orion		ISA III */
376f58c7388Spefo #define	MIPS_R4700	0x21	/* PMCS R4700 Orion		ISA III */
377f58c7388Spefo #define	MIPS_R3TOSH	0x22	/* Toshiba R3000 based CPU	ISA I	*/
378f58c7388Spefo #define	MIPS_R5000	0x23	/* MIPS R5000 CPU		ISA IV  */
379f58c7388Spefo #define	MIPS_RM7000	0x27	/* PMCS RM7000 CPU		ISA IV  */
380f58c7388Spefo #define	MIPS_RM52X0	0x28	/* PMCS RM52X0 CPU		ISA IV  */
381f58c7388Spefo #define	MIPS_RM9000	0x34	/* PMCS RM9000 CPU		ISA IV  */
38213382d84Smiod #define	MIPS_LOONGSON	0x42	/* STC LoongSon CPU		ISA III */
383f58c7388Spefo #define	MIPS_VR5400	0x54	/* NEC Vr5400 CPU		ISA IV+ */
3844e0b48a5Smiod #define	MIPS_LOONGSON2	0x63	/* STC LoongSon2/3 CPU		ISA III+ */
3855f3b292cSvisa #define	MIPS_CN63XX	0x90	/* Cavium OCTEON II CN6[23]xx	MIPS64R2 */
3865f3b292cSvisa #define	MIPS_CN68XX	0x91	/* Cavium OCTEON II CN68xx	MIPS64R2 */
3875f3b292cSvisa #define	MIPS_CN66XX	0x92	/* Cavium OCTEON II CN66xx	MIPS64R2 */
38854b315e0Svisa #define	MIPS_CN61XX	0x93	/* Cavium OCTEON II CN6[01]xx	MIPS64R2 */
3895f3b292cSvisa #define	MIPS_CN78XX	0x95	/* Cavium OCTEON III CN7[678]xx	MIPS64R2 */
39054b315e0Svisa #define	MIPS_CN71XX	0x96	/* Cavium OCTEON III CN7[01]xx	MIPS64R2 */
391183c606cSvisa #define	MIPS_CN73XX	0x97	/* Cavium OCTEON III CN7[23]xx	MIPS64R2 */
392f58c7388Spefo 
393f58c7388Spefo /*
3947b9c60e5Sjmc  * MIPS FPU types. Only soft, rest is the same as cpu type.
395f58c7388Spefo  */
396f58c7388Spefo #define	MIPS_SOFT	0x00	/* Software emulation		ISA I   */
39752aecc03Spefo 
398f58c7388Spefo 
399f58c7388Spefo #if defined(_KERNEL) && !defined(_LOCORE)
400f58c7388Spefo 
40189bd20d4Smiod extern register_t protosr;
4029e8849fbSvisa extern int cpu_has_synced_cp0_count;
4032fef4a92Svisa extern int cpu_has_userlocal;
40489bd20d4Smiod 
4056d1676f7Svisa #ifdef FPUEMUL
4066d1676f7Svisa #define	CPU_HAS_FPU(ci)	((ci)->ci_hw.c1prid != 0)
4076d1676f7Svisa #else
4086d1676f7Svisa #define	CPU_HAS_FPU(ci)	1
4096d1676f7Svisa #endif
4106d1676f7Svisa 
4110f3849f4Smiod struct exec_package;
412f58c7388Spefo struct user;
413f58c7388Spefo 
414caeb30e1Smiod void	tlb_asid_wrap(struct cpu_info *);
415f58c7388Spefo void	tlb_flush(int);
416f58c7388Spefo void	tlb_flush_addr(vaddr_t);
417caeb30e1Smiod void	tlb_init(unsigned int);
418caeb30e1Smiod void	tlb_set_page_mask(uint32_t);
419caeb30e1Smiod void	tlb_set_pid(u_int);
420caeb30e1Smiod void	tlb_set_wired(uint32_t);
421caeb30e1Smiod int	tlb_update(vaddr_t, register_t);
422f58c7388Spefo 
423e8371444Smiod void	build_trampoline(vaddr_t, vaddr_t);
42487543086Smiod void	cpu_switchto_asm(struct proc *, struct proc *);
4250f3849f4Smiod int	exec_md_map(struct proc *, struct exec_package *);
426f58c7388Spefo void	savectx(struct user *, int);
4275d65c980Ssyuu 
42816e66f46Svisa int	copyinsn(struct proc *, vaddr_t, uint32_t *);
4295d65c980Ssyuu void	enable_fpu(struct proc *);
4305d65c980Ssyuu void	save_fpu(void);
431b43ebd13Smpi int	fpe_branch_emulate(struct proc *, struct trapframe *, uint32_t,
4320f3849f4Smiod 	    vaddr_t);
43387543086Smiod void	MipsSaveCurFPState(struct proc *);
43487543086Smiod void	MipsSaveCurFPState16(struct proc *);
435b43ebd13Smpi void	MipsSwitchFPState(struct proc *, struct trapframe *);
436b43ebd13Smpi void	MipsSwitchFPState16(struct proc *, struct trapframe *);
437f58c7388Spefo 
438b43ebd13Smpi void	MipsFPTrap(struct trapframe *);
439b43ebd13Smpi register_t MipsEmulateBranch(struct trapframe *, vaddr_t, uint32_t, uint32_t);
440f58c7388Spefo 
44123fa11dcSmiod int	classify_insn(uint32_t);
44223fa11dcSmiod #define	INSNCLASS_NEUTRAL	0
44323fa11dcSmiod #define	INSNCLASS_CALL		1
44423fa11dcSmiod #define	INSNCLASS_BRANCH	2
44523fa11dcSmiod 
446f58c7388Spefo /*
447f58c7388Spefo  * Low level access routines to CPU registers
448f58c7388Spefo  */
449f58c7388Spefo 
450f58c7388Spefo void	setsoftintr0(void);
451f58c7388Spefo void	clearsoftintr0(void);
452f58c7388Spefo void	setsoftintr1(void);
453f58c7388Spefo void	clearsoftintr1(void);
454a6ba7b46Smiod register_t enableintr(void);
455a6ba7b46Smiod register_t disableintr(void);
456a6ba7b46Smiod register_t getsr(void);
457a6ba7b46Smiod register_t setsr(register_t);
458a6ba7b46Smiod 
45985caa4b9Scheloha uint32_t cp0_get_cause(void);
460a6ba7b46Smiod u_int	cp0_get_count(void);
461a6ba7b46Smiod register_t cp0_get_config(void);
462a6ba7b46Smiod uint32_t cp0_get_config_1(void);
463a6ba7b46Smiod uint32_t cp0_get_config_2(void);
464a6ba7b46Smiod uint32_t cp0_get_config_3(void);
465cb79e5ceSvisa uint32_t cp0_get_config_4(void);
4668f99340cSvisa uint32_t cp0_get_pagegrain(void);
467a6ba7b46Smiod register_t cp0_get_prid(void);
468a6ba7b46Smiod void	cp0_reset_cause(register_t);
469a6ba7b46Smiod void	cp0_set_compare(u_int);
470a6ba7b46Smiod void	cp0_set_config(register_t);
4718f99340cSvisa void	cp0_set_pagegrain(uint32_t);
472a6ba7b46Smiod void	cp0_set_trapbase(register_t);
473a6ba7b46Smiod u_int	cp1_get_prid(void);
474f58c7388Spefo 
4752fef4a92Svisa static inline uint32_t
4762fef4a92Svisa cp0_get_hwrena(void)
4772fef4a92Svisa {
4782fef4a92Svisa 	uint32_t value;
4792fef4a92Svisa 	__asm__ volatile ("mfc0 %0, $7" : "=r" (value));
4802fef4a92Svisa 	return value;
4812fef4a92Svisa }
4822fef4a92Svisa 
4832fef4a92Svisa static inline void
4842fef4a92Svisa cp0_set_hwrena(uint32_t value)
4852fef4a92Svisa {
4862fef4a92Svisa 	__asm__ volatile ("mtc0 %0, $7" : : "r" (value));
4872fef4a92Svisa }
4882fef4a92Svisa 
4892fef4a92Svisa static inline void
4902fef4a92Svisa cp0_set_userlocal(void *value)
4912fef4a92Svisa {
4922fef4a92Svisa 	__asm__ volatile (
4932fef4a92Svisa 	"	.set	push\n"
4942fef4a92Svisa 	"	.set	mips64r2\n"
4952fef4a92Svisa 	"	dmtc0	%0, $4, 2\n"
4962fef4a92Svisa 	"	.set	pop\n"
4972fef4a92Svisa 	: : "r" (value));
4982fef4a92Svisa }
4992fef4a92Svisa 
5009390f385Svisa static inline u_long
5019390f385Svisa intr_disable(void)
5029390f385Svisa {
5039390f385Svisa 	return disableintr();
5049390f385Svisa }
5059390f385Svisa 
5069390f385Svisa static inline void
5079390f385Svisa intr_restore(u_long sr)
5089390f385Svisa {
5099390f385Svisa 	setsr(sr);
5109390f385Svisa }
5119390f385Svisa 
51287543086Smiod /*
513be7b688eStobias  * Cache routines (may be overridden)
51487543086Smiod  */
51587543086Smiod 
51687543086Smiod #ifndef	Mips_SyncCache
51787543086Smiod #define	Mips_SyncCache(ci) \
51887543086Smiod 	((ci)->ci_SyncCache)(ci)
51987543086Smiod #endif
52087543086Smiod #ifndef	Mips_InvalidateICache
52187543086Smiod #define	Mips_InvalidateICache(ci, va, l) \
52287543086Smiod 	((ci)->ci_InvalidateICache)(ci, va, l)
52387543086Smiod #endif
52480941abeSmiod #ifndef	Mips_InvalidateICachePage
52580941abeSmiod #define	Mips_InvalidateICachePage(ci, va) \
52680941abeSmiod 	((ci)->ci_InvalidateICachePage)(ci, va)
52780941abeSmiod #endif
52880941abeSmiod #ifndef	Mips_SyncICache
52980941abeSmiod #define	Mips_SyncICache(ci) \
53080941abeSmiod 	((ci)->ci_SyncICache)(ci)
53180941abeSmiod #endif
53287543086Smiod #ifndef	Mips_SyncDCachePage
53387543086Smiod #define	Mips_SyncDCachePage(ci, va, pa) \
53487543086Smiod 	((ci)->ci_SyncDCachePage)(ci, va, pa)
53587543086Smiod #endif
5361a4be959Svisa #ifndef	Mips_HitSyncDCachePage
5371a4be959Svisa #define	Mips_HitSyncDCachePage(ci, va, pa) \
5381a4be959Svisa 	((ci)->ci_HitSyncDCachePage)(ci, va, pa)
5391a4be959Svisa #endif
54087543086Smiod #ifndef	Mips_HitSyncDCache
54187543086Smiod #define	Mips_HitSyncDCache(ci, va, l) \
54287543086Smiod 	((ci)->ci_HitSyncDCache)(ci, va, l)
54387543086Smiod #endif
54487543086Smiod #ifndef	Mips_HitInvalidateDCache
54587543086Smiod #define	Mips_HitInvalidateDCache(ci, va, l) \
54687543086Smiod 	((ci)->ci_HitInvalidateDCache)(ci, va, l)
54787543086Smiod #endif
54887543086Smiod #ifndef	Mips_IOSyncDCache
54987543086Smiod #define	Mips_IOSyncDCache(ci, va, l, h) \
55087543086Smiod 	((ci)->ci_IOSyncDCache)(ci, va, l, h)
55187543086Smiod #endif
55287543086Smiod 
5538382e3ccSmiod #endif /* _KERNEL && !_LOCORE */
5542fa72412Spirofti #endif /* !_MIPS64_CPU_H_ */
555