xref: /openbsd/sys/arch/m88k/include/cpu.h (revision 09467b48)
1 /*	$OpenBSD: cpu.h,v 1.68 2020/05/31 06:23:57 dlg Exp $ */
2 /*
3  * Copyright (c) 1996 Nivas Madhur
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  */
40 
41 #ifndef _M88K_CPU_H_
42 #define _M88K_CPU_H_
43 
44 /*
45  * CTL_MACHDEP definitions.
46  */
47 #define	CPU_CONSDEV	1	/* dev_t: console terminal device */
48 #define	CPU_CPUTYPE	2	/* int: cpu type */
49 #define	CPU_MAXID	3	/* number of valid machdep ids */
50 
51 #define	CTL_MACHDEP_NAMES { \
52 	{ 0, 0 }, \
53 	{ "console_device", CTLTYPE_STRUCT }, \
54 	{ "cputype", CTLTYPE_INT }, \
55 }
56 
57 #ifdef _KERNEL
58 
59 #include <machine/atomic.h>
60 #include <machine/pcb.h>
61 #include <machine/psl.h>
62 #include <machine/intr.h>
63 #include <sys/queue.h>
64 #include <sys/sched.h>
65 #include <sys/srp.h>
66 
67 #if defined(MULTIPROCESSOR)
68 #if !defined(MAX_CPUS) || MAX_CPUS > 4
69 #undef	MAX_CPUS
70 #define	MAX_CPUS	4
71 #endif
72 #else
73 #if !defined(MAX_CPUS)
74 #undef	MAX_CPUS
75 #define	MAX_CPUS	1
76 #endif
77 #endif
78 
79 #ifndef _LOCORE
80 
81 #include <machine/lock.h>
82 
83 /*
84  * Per-CPU data structure
85  */
86 
87 struct pmap;
88 
89 struct cpu_info {
90 	u_int		 ci_flags;
91 #define	CIF_ALIVE		0x01		/* cpu initialized */
92 #define	CIF_PRIMARY		0x02		/* primary cpu */
93 
94 	struct proc	*ci_curproc;		/* current process... */
95 	struct pcb	*ci_curpcb;		/* ...its pcb... */
96 	struct pmap	*ci_curpmap;		/* ...and its pmap */
97 
98 	u_int		 ci_cpuid;		/* cpu number */
99 
100 	/*
101 	 * Function pointers used within mplock to ensure
102 	 * non-interruptability.
103 	 */
104 	uint32_t	(*ci_mp_atomic_begin)
105 			    (__cpu_simple_lock_t *lock, uint *csr);
106 	void		(*ci_mp_atomic_end)
107 			    (uint32_t psr, __cpu_simple_lock_t *lock, uint csr);
108 
109 	/*
110 	 * Other processor-dependent routines
111 	 */
112 	void		(*ci_zeropage)(vaddr_t);
113 	void		(*ci_copypage)(vaddr_t, vaddr_t);
114 
115 	/*
116 	 * The following fields are used differently depending on
117 	 * the processor type.  Think of them as an anonymous union
118 	 * of two anonymous structs.
119 	 */
120 	u_int		 ci_cpudep0;
121 	u_int		 ci_cpudep1;
122 	u_int		 ci_cpudep2;
123 	u_int		 ci_cpudep3;
124 	u_int		 ci_cpudep4;
125 	u_int		 ci_cpudep5;
126 	u_int		 ci_cpudep6;
127 	u_int		 ci_cpudep7;
128 
129 	/* 88100 fields */
130 #define	ci_pfsr_i0	 ci_cpudep0		/* instruction... */
131 #define	ci_pfsr_i1	 ci_cpudep1
132 #define	ci_pfsr_d0	 ci_cpudep2		/* ...and data CMMU PFSRs */
133 #define	ci_pfsr_d1	 ci_cpudep3
134 
135 	/* 88110 fields */
136 #define	ci_ipi_arg1	 ci_cpudep0		/* Complex IPI arguments */
137 #define	ci_ipi_arg2	 ci_cpudep1
138 #define	ci_h_sxip	 ci_cpudep2		/* trapframe values */
139 #define	ci_h_epsr	 ci_cpudep3		/* for hardclock */
140 #define	ci_s_sxip	 ci_cpudep4		/* and softclock */
141 #define	ci_s_epsr	 ci_cpudep5
142 
143 	struct schedstate_percpu
144 			 ci_schedstate;		/* scheduling state */
145 	int		 ci_want_resched;	/* need_resched() invoked */
146 
147 	u_int		 ci_intrdepth;		/* interrupt depth */
148 
149 	int		 ci_ddb_state;		/* ddb status */
150 #define	CI_DDB_RUNNING	0
151 #define	CI_DDB_ENTERDDB	1
152 #define	CI_DDB_INDDB	2
153 #define	CI_DDB_PAUSE	3
154 
155 	u_int32_t	 ci_randseed;		/* per-cpu random seed */
156 
157 	int		 ci_ipi;		/* pending ipis */
158 #define	CI_IPI_NOTIFY		0x00000001
159 #define	CI_IPI_HARDCLOCK	0x00000002
160 #define	CI_IPI_STATCLOCK	0x00000004
161 #define	CI_IPI_DDB		0x00000008
162 /* 88110 simple ipi */
163 #define	CI_IPI_TLB_FLUSH_KERNEL	0x00000010
164 #define	CI_IPI_TLB_FLUSH_USER	0x00000020
165 /* 88110 complex ipi */
166 #define	CI_IPI_CACHE_FLUSH	0x00000040
167 #define	CI_IPI_ICACHE_FLUSH	0x00000080
168 #define	CI_IPI_DMA_CACHECTL	0x00000100
169 	void		(*ci_softipi_cb)(void);	/* 88110 softipi callback */
170 
171 #if defined(MULTIPROCESSOR)
172 	struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM];
173 #endif
174 #ifdef DIAGNOSTIC
175 	int	ci_mutex_level;
176 #endif
177 #ifdef GPROF
178 	struct gmonparam *ci_gmon;
179 #endif
180 };
181 
182 extern cpuid_t master_cpu;
183 extern struct cpu_info m88k_cpus[MAX_CPUS];
184 
185 #define	CPU_INFO_ITERATOR	cpuid_t
186 #define	CPU_INFO_FOREACH(cii, ci) \
187 	for ((cii) = 0; (cii) < MAX_CPUS; (cii)++) \
188 		if (((ci) = &m88k_cpus[cii])->ci_flags & CIF_ALIVE)
189 #define	CPU_INFO_UNIT(ci)	((ci)->ci_cpuid)
190 #define MAXCPUS	MAX_CPUS
191 
192 #if defined(MULTIPROCESSOR)
193 
194 static __inline__ struct cpu_info *
195 curcpu(void)
196 {
197 	struct cpu_info *cpuptr;
198 
199 	__asm__ volatile ("ldcr %0, %%cr17" : "=r" (cpuptr));
200 	return cpuptr;
201 }
202 
203 #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CIF_PRIMARY)
204 
205 void	cpu_boot_secondary_processors(void);
206 __dead void cpu_emergency_disable(void);
207 void	cpu_unidle(struct cpu_info *);
208 void	m88k_send_ipi(int, cpuid_t);
209 void	m88k_broadcast_ipi(int);
210 
211 #else	/* MULTIPROCESSOR */
212 
213 #define	curcpu()	(&m88k_cpus[0])
214 #define	cpu_unidle(ci)	do { /* nothing */ } while (0)
215 #define	CPU_IS_PRIMARY(ci)	1
216 
217 #endif	/* MULTIPROCESSOR */
218 
219 #define CPU_BUSY_CYCLE()	do {} while (0)
220 
221 struct cpu_info *set_cpu_number(cpuid_t);
222 
223 /*
224  * The md code may hardcode this in some very specific situations.
225  */
226 #if !defined(cpu_number)
227 #define	cpu_number()		curcpu()->ci_cpuid
228 #endif
229 
230 #define	curpcb			curcpu()->ci_curpcb
231 
232 unsigned int cpu_rnd_messybits(void);
233 
234 #endif /* _LOCORE */
235 
236 /*
237  * definitions of cpu-dependent requirements
238  * referenced in generic code
239  */
240 #define	cpu_exec(p)		do { /* nothing */ } while (0)
241 
242 #define	cpu_idle_enter()	do { /* nothing */ } while (0)
243 #define	cpu_idle_cycle()	do { /* nothing */ } while (0)
244 #define	cpu_idle_leave()	do { /* nothing */ } while (0)
245 
246 #if defined(MULTIPROCESSOR)
247 #include <sys/mplock.h>
248 #endif
249 
250 /*
251  * Arguments to hardclock and gatherstats encapsulate the previous
252  * machine state in an opaque clockframe. CLKF_INTR is only valid
253  * if the process is in kernel mode. Clockframe is really trapframe,
254  * so pointer to clockframe can be safely cast into a pointer to
255  * trapframe.
256  */
257 struct clockframe {
258 	struct trapframe tf;
259 };
260 
261 #define	CLKF_USERMODE(framep)	(((framep)->tf.tf_epsr & PSR_MODE) == 0)
262 #define	CLKF_PC(framep)		((framep)->tf.tf_sxip & XIP_ADDR)
263 #define	CLKF_INTR(framep) \
264 	(((struct cpu_info *)(framep)->tf.tf_cpu)->ci_intrdepth > 1)
265 
266 #define	aston(p)		((p)->p_md.md_astpending = 1)
267 
268 /*
269  * This is used during profiling to integrate system time.
270  */
271 #define	PC_REGS(regs)							\
272 	(CPU_IS88110 ? ((regs)->exip & XIP_ADDR) :			\
273 	 ((regs)->sxip & XIP_V ? (regs)->sxip & XIP_ADDR :		\
274 	  ((regs)->snip & NIP_V ? (regs)->snip & NIP_ADDR :		\
275 				   (regs)->sfip & FIP_ADDR)))
276 #define	PROC_PC(p)	PC_REGS((struct reg *)((p)->p_md.md_tf))
277 #define	PROC_STACK(p)	((p)->p_md.md_tf->tf_sp)
278 
279 #define clear_resched(ci) 	(ci)->ci_want_resched = 0
280 
281 /*
282  * Give a profiling tick to the current process when the user profiling
283  * buffer pages are invalid.  On the m88k, request an ast to send us
284  * through trap(), marking the proc as needing a profiling tick.
285  */
286 #define	need_proftick(p)	aston(p)
287 
288 void	need_resched(struct cpu_info *);
289 void	signotify(struct proc *);
290 void	softipi(void);
291 
292 int	badaddr(vaddr_t addr, int size);
293 void	set_vbr(register_t);
294 extern register_t kernel_vbr;
295 
296 #endif /* _KERNEL */
297 #endif /* _M88K_CPU_H_ */
298