xref: /openbsd/sys/arch/m88k/include/cpu.h (revision 8932bfb7)
1 /*	$OpenBSD: cpu.h,v 1.53 2011/03/23 16:54:35 pirofti 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 	/*
100 	 * Function pointers used within mplock to ensure
101 	 * non-interruptability.
102 	 */
103 	uint32_t	(*ci_mp_atomic_begin)
104 			    (__cpu_simple_lock_t *lock, uint *csr);
105 	void		(*ci_mp_atomic_end)
106 			    (uint32_t psr, __cpu_simple_lock_t *lock, uint csr);
107 
108 	/*
109 	 * Other processor-dependent routines
110 	 */
111 	void		(*ci_zeropage)(vaddr_t);
112 	void		(*ci_copypage)(vaddr_t, vaddr_t);
113 
114 	/*
115 	 * The following fields are used differently depending on
116 	 * the processor type.  Think of them as an anonymous union
117 	 * of two anonymous structs.
118 	 */
119 	u_int		 ci_cpudep0;
120 	u_int		 ci_cpudep1;
121 	u_int		 ci_cpudep2;
122 	u_int		 ci_cpudep3;
123 	u_int		 ci_cpudep4;
124 	u_int		 ci_cpudep5;
125 	u_int		 ci_cpudep6;
126 	u_int		 ci_cpudep7;
127 
128 	/* 88100 fields */
129 #define	ci_pfsr_i0	 ci_cpudep0		/* instruction... */
130 #define	ci_pfsr_i1	 ci_cpudep1
131 #define	ci_pfsr_d0	 ci_cpudep2		/* ...and data CMMU PFSRs */
132 #define	ci_pfsr_d1	 ci_cpudep3
133 
134 	/* 88110 fields */
135 #define	ci_ipi_arg1	 ci_cpudep0		/* Complex IPI arguments */
136 #define	ci_ipi_arg2	 ci_cpudep1
137 #define	ci_h_sxip	 ci_cpudep2		/* trapframe values */
138 #define	ci_h_epsr	 ci_cpudep3		/* for hardclock */
139 #define	ci_s_sxip	 ci_cpudep4		/* and softclock */
140 #define	ci_s_epsr	 ci_cpudep5
141 #define	ci_pmap_ipi	 ci_cpudep6		/* delayed pmap tlb ipi */
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 	u_long		 ci_spin_locks;		/* spin locks counter */
150 
151 	int		 ci_ddb_state;		/* ddb status */
152 #define	CI_DDB_RUNNING	0
153 #define	CI_DDB_ENTERDDB	1
154 #define	CI_DDB_INDDB	2
155 #define	CI_DDB_PAUSE	3
156 
157 	u_int32_t	 ci_randseed;		/* per-cpu random seed */
158 
159 	int		 ci_ipi;		/* pending ipis */
160 #define	CI_IPI_NOTIFY		0x00000001
161 #define	CI_IPI_HARDCLOCK	0x00000002
162 #define	CI_IPI_STATCLOCK	0x00000004
163 #define	CI_IPI_DDB		0x00000008
164 /* 88110 simple ipi */
165 #define	CI_IPI_TLB_FLUSH_KERNEL	0x00000010
166 #define	CI_IPI_TLB_FLUSH_USER	0x00000020
167 /* 88110 complex ipi */
168 #define	CI_IPI_CACHE_FLUSH	0x00000040
169 #define	CI_IPI_ICACHE_FLUSH	0x00000080
170 #define	CI_IPI_DMA_CACHECTL	0x00000100
171 	void		(*ci_softipi_cb)(void);	/* 88110 softipi callback */
172 
173 #ifdef DIAGNOSTIC
174 	int	ci_mutex_level;
175 #endif
176 };
177 
178 extern cpuid_t master_cpu;
179 extern struct cpu_info m88k_cpus[MAX_CPUS];
180 
181 #define	CPU_INFO_ITERATOR	cpuid_t
182 #define	CPU_INFO_FOREACH(cii, ci) \
183 	for ((cii) = 0; (cii) < MAX_CPUS; (cii)++) \
184 		if (((ci) = &m88k_cpus[cii])->ci_flags & CIF_ALIVE)
185 #define	CPU_INFO_UNIT(ci)	((ci)->ci_cpuid)
186 #define MAXCPUS	MAX_CPUS
187 
188 #if defined(MULTIPROCESSOR)
189 
190 static __inline__ struct cpu_info *
191 curcpu(void)
192 {
193 	struct cpu_info *cpuptr;
194 
195 	__asm__ __volatile__ ("ldcr %0, cr17" : "=r" (cpuptr));
196 	return cpuptr;
197 }
198 
199 #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CIF_PRIMARY)
200 
201 void	cpu_boot_secondary_processors(void);
202 __dead void cpu_emergency_disable(void);
203 void	cpu_unidle(struct cpu_info *);
204 void	m88k_send_ipi(int, cpuid_t);
205 void	m88k_broadcast_ipi(int);
206 
207 #else	/* MULTIPROCESSOR */
208 
209 #define	curcpu()	(&m88k_cpus[0])
210 #define	cpu_unidle(ci)	do { /* nothing */ } while (0)
211 #define	CPU_IS_PRIMARY(ci)	1
212 
213 #endif	/* MULTIPROCESSOR */
214 
215 void	set_cpu_number(cpuid_t);
216 
217 /*
218  * The md code may hardcode this in some very specific situations.
219  */
220 #if !defined(cpu_number)
221 #define	cpu_number()		curcpu()->ci_cpuid
222 #endif
223 
224 #define	curpcb			curcpu()->ci_curpcb
225 
226 #endif /* _LOCORE */
227 
228 /*
229  * definitions of cpu-dependent requirements
230  * referenced in generic code
231  */
232 #define	cpu_exec(p)		do { /* nothing */ } while (0)
233 
234 #define	cpu_idle_enter()	do { /* nothing */ } while (0)
235 #define	cpu_idle_cycle()	do { /* nothing */ } while (0)
236 #define	cpu_idle_leave()	do { /* nothing */ } while (0)
237 
238 #if defined(MULTIPROCESSOR)
239 #include <sys/lock.h>
240 #include <sys/mplock.h>
241 #endif
242 
243 /*
244  * Arguments to hardclock and gatherstats encapsulate the previous
245  * machine state in an opaque clockframe. CLKF_INTR is only valid
246  * if the process is in kernel mode. Clockframe is really trapframe,
247  * so pointer to clockframe can be safely cast into a pointer to
248  * trapframe.
249  */
250 struct clockframe {
251 	struct trapframe tf;
252 };
253 
254 #define	CLKF_USERMODE(framep)	(((framep)->tf.tf_epsr & PSR_MODE) == 0)
255 #define	CLKF_PC(framep)		((framep)->tf.tf_sxip & XIP_ADDR)
256 #define	CLKF_INTR(framep) \
257 	(((struct cpu_info *)(framep)->tf.tf_cpu)->ci_intrdepth > 1)
258 
259 #define	aston(p)		((p)->p_md.md_astpending = 1)
260 
261 /*
262  * This is used during profiling to integrate system time.
263  */
264 #define	PC_REGS(regs)							\
265 	(CPU_IS88110 ? ((regs)->exip & XIP_ADDR) :			\
266 	 ((regs)->sxip & XIP_V ? (regs)->sxip & XIP_ADDR :		\
267 	  ((regs)->snip & NIP_V ? (regs)->snip & NIP_ADDR :		\
268 				   (regs)->sfip & FIP_ADDR)))
269 #define	PROC_PC(p)	PC_REGS((struct reg *)((p)->p_md.md_tf))
270 
271 #define clear_resched(ci) 	(ci)->ci_want_resched = 0
272 
273 /*
274  * Give a profiling tick to the current process when the user profiling
275  * buffer pages are invalid.  On the m88k, request an ast to send us
276  * through trap(), marking the proc as needing a profiling tick.
277  */
278 #define	need_proftick(p)	aston(p)
279 
280 void	need_resched(struct cpu_info *);
281 void	signotify(struct proc *);
282 void	softipi(void);
283 
284 int	badaddr(vaddr_t addr, int size);
285 void	set_vbr(register_t);
286 extern register_t kernel_vbr;
287 
288 #endif /* _KERNEL */
289 #endif /* _M88K_CPU_H_ */
290