xref: /openbsd-src/sys/arch/m88k/include/cpu.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: cpu.h,v 1.64 2015/07/02 01:33:59 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 
66 #if defined(MULTIPROCESSOR)
67 #if !defined(MAX_CPUS) || MAX_CPUS > 4
68 #undef	MAX_CPUS
69 #define	MAX_CPUS	4
70 #endif
71 #else
72 #if !defined(MAX_CPUS)
73 #undef	MAX_CPUS
74 #define	MAX_CPUS	1
75 #endif
76 #endif
77 
78 #ifndef _LOCORE
79 
80 #include <machine/lock.h>
81 
82 /*
83  * Per-CPU data structure
84  */
85 
86 struct pmap;
87 
88 struct cpu_info {
89 	u_int		 ci_flags;
90 #define	CIF_ALIVE		0x01		/* cpu initialized */
91 #define	CIF_PRIMARY		0x02		/* primary cpu */
92 
93 	struct proc	*ci_curproc;		/* current process... */
94 	struct pcb	*ci_curpcb;		/* ...its pcb... */
95 	struct pmap	*ci_curpmap;		/* ...and its pmap */
96 
97 	u_int		 ci_cpuid;		/* cpu number */
98 
99 #if defined(MULTIPROCESSOR)
100 	struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM];
101 #endif
102 
103 	/*
104 	 * Function pointers used within mplock to ensure
105 	 * non-interruptability.
106 	 */
107 	uint32_t	(*ci_mp_atomic_begin)
108 			    (__cpu_simple_lock_t *lock, uint *csr);
109 	void		(*ci_mp_atomic_end)
110 			    (uint32_t psr, __cpu_simple_lock_t *lock, uint csr);
111 
112 	/*
113 	 * Other processor-dependent routines
114 	 */
115 	void		(*ci_zeropage)(vaddr_t);
116 	void		(*ci_copypage)(vaddr_t, vaddr_t);
117 
118 	/*
119 	 * The following fields are used differently depending on
120 	 * the processor type.  Think of them as an anonymous union
121 	 * of two anonymous structs.
122 	 */
123 	u_int		 ci_cpudep0;
124 	u_int		 ci_cpudep1;
125 	u_int		 ci_cpudep2;
126 	u_int		 ci_cpudep3;
127 	u_int		 ci_cpudep4;
128 	u_int		 ci_cpudep5;
129 	u_int		 ci_cpudep6;
130 	u_int		 ci_cpudep7;
131 
132 	/* 88100 fields */
133 #define	ci_pfsr_i0	 ci_cpudep0		/* instruction... */
134 #define	ci_pfsr_i1	 ci_cpudep1
135 #define	ci_pfsr_d0	 ci_cpudep2		/* ...and data CMMU PFSRs */
136 #define	ci_pfsr_d1	 ci_cpudep3
137 
138 	/* 88110 fields */
139 #define	ci_ipi_arg1	 ci_cpudep0		/* Complex IPI arguments */
140 #define	ci_ipi_arg2	 ci_cpudep1
141 #define	ci_h_sxip	 ci_cpudep2		/* trapframe values */
142 #define	ci_h_epsr	 ci_cpudep3		/* for hardclock */
143 #define	ci_s_sxip	 ci_cpudep4		/* and softclock */
144 #define	ci_s_epsr	 ci_cpudep5
145 
146 	struct schedstate_percpu
147 			 ci_schedstate;		/* scheduling state */
148 	int		 ci_want_resched;	/* need_resched() invoked */
149 
150 	u_int		 ci_intrdepth;		/* interrupt depth */
151 
152 	int		 ci_ddb_state;		/* ddb status */
153 #define	CI_DDB_RUNNING	0
154 #define	CI_DDB_ENTERDDB	1
155 #define	CI_DDB_INDDB	2
156 #define	CI_DDB_PAUSE	3
157 
158 	u_int32_t	 ci_randseed;		/* per-cpu random seed */
159 
160 	int		 ci_ipi;		/* pending ipis */
161 #define	CI_IPI_NOTIFY		0x00000001
162 #define	CI_IPI_HARDCLOCK	0x00000002
163 #define	CI_IPI_STATCLOCK	0x00000004
164 #define	CI_IPI_DDB		0x00000008
165 /* 88110 simple ipi */
166 #define	CI_IPI_TLB_FLUSH_KERNEL	0x00000010
167 #define	CI_IPI_TLB_FLUSH_USER	0x00000020
168 /* 88110 complex ipi */
169 #define	CI_IPI_CACHE_FLUSH	0x00000040
170 #define	CI_IPI_ICACHE_FLUSH	0x00000080
171 #define	CI_IPI_DMA_CACHECTL	0x00000100
172 	void		(*ci_softipi_cb)(void);	/* 88110 softipi callback */
173 
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 void	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 #endif /* _LOCORE */
233 
234 /*
235  * definitions of cpu-dependent requirements
236  * referenced in generic code
237  */
238 #define	cpu_exec(p)		do { /* nothing */ } while (0)
239 
240 #define	cpu_idle_enter()	do { /* nothing */ } while (0)
241 #define	cpu_idle_cycle()	do { /* nothing */ } while (0)
242 #define	cpu_idle_leave()	do { /* nothing */ } while (0)
243 
244 #if defined(MULTIPROCESSOR)
245 #include <sys/mplock.h>
246 #endif
247 
248 /*
249  * Arguments to hardclock and gatherstats encapsulate the previous
250  * machine state in an opaque clockframe. CLKF_INTR is only valid
251  * if the process is in kernel mode. Clockframe is really trapframe,
252  * so pointer to clockframe can be safely cast into a pointer to
253  * trapframe.
254  */
255 struct clockframe {
256 	struct trapframe tf;
257 };
258 
259 #define	CLKF_USERMODE(framep)	(((framep)->tf.tf_epsr & PSR_MODE) == 0)
260 #define	CLKF_PC(framep)		((framep)->tf.tf_sxip & XIP_ADDR)
261 #define	CLKF_INTR(framep) \
262 	(((struct cpu_info *)(framep)->tf.tf_cpu)->ci_intrdepth > 1)
263 
264 #define	aston(p)		((p)->p_md.md_astpending = 1)
265 
266 /*
267  * This is used during profiling to integrate system time.
268  */
269 #define	PC_REGS(regs)							\
270 	(CPU_IS88110 ? ((regs)->exip & XIP_ADDR) :			\
271 	 ((regs)->sxip & XIP_V ? (regs)->sxip & XIP_ADDR :		\
272 	  ((regs)->snip & NIP_V ? (regs)->snip & NIP_ADDR :		\
273 				   (regs)->sfip & FIP_ADDR)))
274 #define	PROC_PC(p)	PC_REGS((struct reg *)((p)->p_md.md_tf))
275 #define	PROC_STACK(p)	((p)->p_md.md_tf->tf_sp)
276 
277 #define clear_resched(ci) 	(ci)->ci_want_resched = 0
278 
279 /*
280  * Give a profiling tick to the current process when the user profiling
281  * buffer pages are invalid.  On the m88k, request an ast to send us
282  * through trap(), marking the proc as needing a profiling tick.
283  */
284 #define	need_proftick(p)	aston(p)
285 
286 void	need_resched(struct cpu_info *);
287 void	signotify(struct proc *);
288 void	softipi(void);
289 
290 int	badaddr(vaddr_t addr, int size);
291 void	set_vbr(register_t);
292 extern register_t kernel_vbr;
293 
294 #endif /* _KERNEL */
295 #endif /* _M88K_CPU_H_ */
296