xref: /openbsd/sys/arch/m88k/include/cpu.h (revision 00ee6dc4)
1 /*	$OpenBSD: cpu.h,v 1.76 2024/02/25 19:15:50 cheloha 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/clockintr.h>
64 #include <sys/queue.h>
65 #include <sys/sched.h>
66 #include <sys/srp.h>
67 
68 #if defined(MULTIPROCESSOR)
69 #if !defined(MAX_CPUS) || MAX_CPUS > 4
70 #undef	MAX_CPUS
71 #define	MAX_CPUS	4
72 #endif
73 #else
74 #if !defined(MAX_CPUS)
75 #undef	MAX_CPUS
76 #define	MAX_CPUS	1
77 #endif
78 #endif
79 
80 #ifndef _LOCORE
81 
82 #include <machine/lock.h>
83 
84 /*
85  * Per-CPU data structure
86  */
87 
88 struct pmap;
89 
90 struct cpu_info {
91 	u_int		 ci_flags;
92 #define	CIF_ALIVE		0x01		/* cpu initialized */
93 #define	CIF_PRIMARY		0x02		/* primary cpu */
94 
95 	struct proc	*ci_curproc;		/* current process... */
96 	struct pcb	*ci_curpcb;		/* ...its pcb... */
97 	struct pmap	*ci_curpmap;		/* ...and its pmap */
98 
99 	u_int		 ci_cpuid;		/* cpu number */
100 
101 	/*
102 	 * Function pointers used within mplock to ensure
103 	 * non-interruptability.
104 	 */
105 	uint32_t	(*ci_mp_atomic_begin)
106 			    (__cpu_simple_lock_t *lock, uint *csr);
107 	void		(*ci_mp_atomic_end)
108 			    (uint32_t psr, __cpu_simple_lock_t *lock, uint csr);
109 
110 	/*
111 	 * Other processor-dependent routines
112 	 */
113 	void		(*ci_zeropage)(vaddr_t);
114 	void		(*ci_copypage)(vaddr_t, vaddr_t);
115 
116 	/*
117 	 * The following fields are used differently depending on
118 	 * the processor type.  Think of them as an anonymous union
119 	 * of two anonymous structs.
120 	 */
121 	u_int		 ci_cpudep0;
122 	u_int		 ci_cpudep1;
123 	u_int		 ci_cpudep2;
124 	u_int		 ci_cpudep3;
125 	u_int		 ci_cpudep4;
126 	u_int		 ci_cpudep5;
127 	u_int		 ci_cpudep6;
128 	u_int		 ci_cpudep7;
129 
130 	/* 88100 fields */
131 #define	ci_pfsr_i0	 ci_cpudep0		/* instruction... */
132 #define	ci_pfsr_i1	 ci_cpudep1
133 #define	ci_pfsr_d0	 ci_cpudep2		/* ...and data CMMU PFSRs */
134 #define	ci_pfsr_d1	 ci_cpudep3
135 
136 	/* 88110 fields */
137 #define	ci_ipi_arg1	 ci_cpudep0		/* Complex IPI arguments */
138 #define	ci_ipi_arg2	 ci_cpudep1
139 #define	ci_h_sxip	 ci_cpudep2		/* trapframe values */
140 #define	ci_h_epsr	 ci_cpudep3		/* for hardclock */
141 #define	ci_s_sxip	 ci_cpudep4		/* and softclock */
142 #define	ci_s_epsr	 ci_cpudep5
143 
144 	struct schedstate_percpu
145 			 ci_schedstate;		/* scheduling state */
146 	int		 ci_want_resched;	/* need_resched() invoked */
147 
148 	u_int		 ci_intrdepth;		/* interrupt depth */
149 
150 	int		 ci_ddb_state;		/* ddb status */
151 #define	CI_DDB_RUNNING	0
152 #define	CI_DDB_ENTERDDB	1
153 #define	CI_DDB_INDDB	2
154 #define	CI_DDB_PAUSE	3
155 
156 	u_int32_t	 ci_randseed;		/* per-cpu random seed */
157 
158 	int		 ci_ipi;		/* pending ipis */
159 #define	CI_IPI_NOTIFY		0x00000001
160 #define	CI_IPI_HARDCLOCK	0x00000002
161 #define	CI_IPI_STATCLOCK	0x00000004
162 #define	CI_IPI_DDB		0x00000008
163 /* 88110 simple ipi */
164 #define	CI_IPI_TLB_FLUSH_KERNEL	0x00000010
165 #define	CI_IPI_TLB_FLUSH_USER	0x00000020
166 /* 88110 complex ipi */
167 #define	CI_IPI_CACHE_FLUSH	0x00000040
168 #define	CI_IPI_ICACHE_FLUSH	0x00000080
169 #define	CI_IPI_DMA_CACHECTL	0x00000100
170 	void		(*ci_softipi_cb)(void);	/* 88110 softipi callback */
171 
172 #if defined(MULTIPROCESSOR)
173 	struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM];
174 #endif
175 #ifdef DIAGNOSTIC
176 	int	ci_mutex_level;
177 #endif
178 #ifdef GPROF
179 	struct gmonparam *ci_gmon;
180 	struct clockintr ci_gmonclock;
181 #endif
182 	struct clockqueue ci_queue;
183 	char		 ci_panicbuf[512];
184 };
185 
186 extern cpuid_t master_cpu;
187 extern struct cpu_info m88k_cpus[MAX_CPUS];
188 
189 #define	CPU_INFO_ITERATOR	cpuid_t
190 #define	CPU_INFO_FOREACH(cii, ci) \
191 	for ((cii) = 0; (cii) < MAX_CPUS; (cii)++) \
192 		if (((ci) = &m88k_cpus[cii])->ci_flags & CIF_ALIVE)
193 #define	CPU_INFO_UNIT(ci)	((ci)->ci_cpuid)
194 #define MAXCPUS	MAX_CPUS
195 
196 #if defined(MULTIPROCESSOR)
197 
198 static __inline__ struct cpu_info *
199 curcpu(void)
200 {
201 	struct cpu_info *cpuptr;
202 
203 	__asm__ volatile ("ldcr %0, %%cr17" : "=r" (cpuptr));
204 	return cpuptr;
205 }
206 
207 #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CIF_PRIMARY)
208 #define	CPU_IS_RUNNING(ci)	((ci)->ci_flags & CIF_ALIVE)
209 
210 void	cpu_boot_secondary_processors(void);
211 __dead void cpu_emergency_disable(void);
212 void	cpu_unidle(struct cpu_info *);
213 void	m88k_send_ipi(int, cpuid_t);
214 void	m88k_broadcast_ipi(int);
215 
216 #else	/* MULTIPROCESSOR */
217 
218 #define	curcpu()	(&m88k_cpus[0])
219 #define	cpu_unidle(ci)	do { /* nothing */ } while (0)
220 #define	CPU_IS_PRIMARY(ci)	1
221 #define	CPU_IS_RUNNING(ci)	1
222 
223 #endif	/* MULTIPROCESSOR */
224 
225 #define CPU_BUSY_CYCLE()	do {} while (0)
226 
227 struct cpu_info *set_cpu_number(cpuid_t);
228 
229 /*
230  * The md code may hardcode this in some very specific situations.
231  */
232 #if !defined(cpu_number)
233 #define	cpu_number()		curcpu()->ci_cpuid
234 #endif
235 
236 #define	curpcb			curcpu()->ci_curpcb
237 
238 unsigned int cpu_rnd_messybits(void);
239 
240 #endif /* _LOCORE */
241 
242 /*
243  * definitions of cpu-dependent requirements
244  * referenced in generic code
245  */
246 
247 #define	cpu_idle_enter()	do { /* nothing */ } while (0)
248 #define	cpu_idle_cycle()	do { /* nothing */ } while (0)
249 #define	cpu_idle_leave()	do { /* nothing */ } while (0)
250 
251 #if defined(MULTIPROCESSOR)
252 #include <sys/mplock.h>
253 #endif
254 
255 /*
256  * Arguments to hardclock and gatherstats encapsulate the previous
257  * machine state in an opaque clockframe. CLKF_INTR is only valid
258  * if the process is in kernel mode. Clockframe is really trapframe,
259  * so pointer to clockframe can be safely cast into a pointer to
260  * trapframe.
261  */
262 struct clockframe {
263 	struct trapframe tf;
264 };
265 
266 #define	CLKF_USERMODE(framep)	(((framep)->tf.tf_epsr & PSR_MODE) == 0)
267 #define	CLKF_PC(framep)		((framep)->tf.tf_sxip & XIP_ADDR)
268 #define	CLKF_INTR(framep) \
269 	(((struct cpu_info *)(framep)->tf.tf_cpu)->ci_intrdepth > 1)
270 
271 #define	aston(p)		((p)->p_md.md_astpending = 1)
272 
273 /*
274  * This is used during profiling to integrate system time.
275  */
276 #define	PC_REGS(regs)							\
277 	(CPU_IS88110 ? ((regs)->exip & XIP_ADDR) :			\
278 	 ((regs)->sxip & XIP_V ? (regs)->sxip & XIP_ADDR :		\
279 	  ((regs)->snip & NIP_V ? (regs)->snip & NIP_ADDR :		\
280 				   (regs)->sfip & FIP_ADDR)))
281 #define	PROC_PC(p)	PC_REGS((struct reg *)((p)->p_md.md_tf))
282 #define	PROC_STACK(p)	((p)->p_md.md_tf->tf_sp)
283 
284 #define clear_resched(ci) 	(ci)->ci_want_resched = 0
285 
286 /*
287  * Give a profiling tick to the current process when the user profiling
288  * buffer pages are invalid.  On the m88k, request an ast to send us
289  * through trap(), marking the proc as needing a profiling tick.
290  */
291 #define	need_proftick(p)	aston(p)
292 
293 void	need_resched(struct cpu_info *);
294 void	signotify(struct proc *);
295 void	softipi(void);
296 
297 int	badaddr(vaddr_t addr, int size);
298 void	set_vbr(register_t);
299 extern register_t kernel_vbr;
300 
301 #define copyinsn(p, v, ip) copyin32((v), (ip))
302 
303 #endif /* _KERNEL */
304 #endif /* _M88K_CPU_H_ */
305