xref: /openbsd/sys/arch/alpha/include/cpu.h (revision 264ca280)
1 /* $OpenBSD: cpu.h,v 1.57 2016/03/30 15:39:46 afresh1 Exp $ */
2 /* $NetBSD: cpu.h,v 1.45 2000/08/21 02:03:12 thorpej Exp $ */
3 
4 /*-
5  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10  * NASA Ames Research Center.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Copyright (c) 1988 University of Utah.
36  * Copyright (c) 1982, 1990, 1993
37  *	The Regents of the University of California.  All rights reserved.
38  *
39  * This code is derived from software contributed to Berkeley by
40  * the Systems Programming Group of the University of Utah Computer
41  * Science Department.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. Neither the name of the University nor the names of its contributors
52  *    may be used to endorse or promote products derived from this software
53  *    without specific prior written permission.
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65  * SUCH DAMAGE.
66  *
67  * from: Utah $Hdr: cpu.h 1.16 91/03/25$
68  *
69  *	@(#)cpu.h	8.4 (Berkeley) 1/5/94
70  */
71 
72 #ifndef _MACHINE_CPU_H_
73 #define _MACHINE_CPU_H_
74 
75 #ifndef NO_IEEE
76 typedef union alpha_s_float {
77 	u_int32_t i;
78 	u_int32_t frac: 23,
79 		exp:   8,
80 		sign:  1;
81 } s_float;
82 
83 typedef union alpha_t_float {
84 	u_int64_t i;
85 	u_int64_t frac: 52,
86 		exp:  11,
87 		sign:  1;
88 } t_float;
89 #endif
90 
91 /*
92  * Exported definitions unique to Alpha cpu support.
93  */
94 
95 #ifdef _KERNEL
96 
97 #include <machine/alpha_cpu.h>
98 #include <machine/frame.h>
99 #include <machine/bus.h>
100 #include <machine/intr.h>
101 #include <sys/cdefs.h>
102 #include <sys/device.h>
103 #include <sys/sched.h>
104 
105 struct pcb;
106 struct proc;
107 struct reg;
108 struct rpb;
109 struct trapframe;
110 
111 extern u_long cpu_implver;		/* from IMPLVER instruction */
112 extern u_long cpu_amask;		/* from AMASK instruction */
113 extern int bootdev_debug;
114 extern int alpha_fp_sync_complete;
115 extern int alpha_unaligned_print, alpha_unaligned_fix, alpha_unaligned_sigbus;
116 
117 void	XentArith(u_int64_t, u_int64_t, u_int64_t);		/* MAGIC */
118 void	XentIF(u_int64_t, u_int64_t, u_int64_t);		/* MAGIC */
119 void	XentInt(u_int64_t, u_int64_t, u_int64_t);		/* MAGIC */
120 void	XentMM(u_int64_t, u_int64_t, u_int64_t);		/* MAGIC */
121 void	XentRestart(void);					/* MAGIC */
122 void	XentSys(u_int64_t, u_int64_t, u_int64_t);		/* MAGIC */
123 void	XentUna(u_int64_t, u_int64_t, u_int64_t);		/* MAGIC */
124 void	alpha_init(u_long, u_long, u_long, u_long, u_long);
125 int	alpha_pa_access(u_long);
126 void	ast(struct trapframe *);
127 int	badaddr(void *, size_t);
128 int	badaddr_read(void *, size_t, void *);
129 u_int64_t console_restart(struct trapframe *);
130 void	do_sir(void);
131 void	dumpconf(void);
132 void	exception_return(void);					/* MAGIC */
133 void	frametoreg(struct trapframe *, struct reg *);
134 long	fswintrberr(void);					/* MAGIC */
135 void	init_bootstrap_console(void);
136 void	init_prom_interface(struct rpb *);
137 void	interrupt(unsigned long, unsigned long, unsigned long,
138 	    struct trapframe *);
139 void	machine_check(unsigned long, struct trapframe *, unsigned long,
140 	    unsigned long);
141 u_int64_t hwrpb_checksum(void);
142 void	hwrpb_restart_setup(void);
143 void	regdump(struct trapframe *);
144 void	regtoframe(struct reg *, struct trapframe *);
145 void	savectx(struct pcb *);
146 void    switch_exit(struct proc *);				/* MAGIC */
147 void	switch_trampoline(void);				/* MAGIC */
148 void	syscall(u_int64_t, struct trapframe *);
149 void	trap(unsigned long, unsigned long, unsigned long, unsigned long,
150 	    struct trapframe *);
151 void	trap_init(void);
152 void	enable_nsio_ide(bus_space_tag_t);
153 
154 /* Multiprocessor glue; cpu.c */
155 struct cpu_info;
156 int	cpu_iccb_send(cpuid_t, const char *);
157 void	cpu_iccb_receive(void);
158 void	cpu_hatch(struct cpu_info *);
159 __dead
160 void	cpu_halt(void);
161 void	cpu_halt_secondary(unsigned long);
162 void	cpu_spinup_trampoline(void);				/* MAGIC */
163 void	cpu_pause(unsigned long);
164 void	cpu_resume(unsigned long);
165 
166 /*
167  * Machine check information.
168  */
169 struct mchkinfo {
170 	volatile int mc_expected;	/* machine check is expected */
171 	volatile int mc_received;	/* machine check was received */
172 };
173 
174 struct cpu_info {
175 	/*
176 	 * Private members accessed in assembly with 8 bit offsets.
177 	 */
178 	struct proc *ci_curproc;	/* current owner of the processor */
179 	paddr_t ci_curpcb;		/* PA of current HW PCB */
180 
181 	/*
182 	 * Public members.
183 	 */
184 	struct schedstate_percpu ci_schedstate;	/* scheduler state */
185 #ifdef DIAGNOSTIC
186 	int	ci_mutex_level;
187 #endif
188 	cpuid_t ci_cpuid;		/* our CPU ID */
189 	struct cpu_info *ci_next;
190 	u_int32_t ci_randseed;
191 
192 #if defined(MULTIPROCESSOR)
193 	struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM];
194 #endif
195 
196 	/*
197 	 * Private members.
198 	 */
199 	struct mchkinfo ci_mcinfo;	/* machine check info */
200 	struct proc *ci_fpcurproc;	/* current owner of the FPU */
201 	struct pcb *ci_idle_pcb;	/* our idle PCB */
202 	paddr_t ci_idle_pcb_paddr;	/* PA of idle PCB */
203 	struct device *ci_dev;		/* pointer to our device */
204 	u_long ci_want_resched;		/* preempt current process */
205 	u_long ci_intrdepth;		/* interrupt trap depth */
206 	struct trapframe *ci_db_regs;	/* registers for debuggers */
207 
208 #if defined(MULTIPROCESSOR)
209 	volatile u_long ci_flags;	/* flags; see below */
210 	volatile u_long ci_ipis;	/* interprocessor interrupts pending */
211 #endif
212 #ifdef GPROF
213 	struct gmonparam *ci_gmon;
214 #endif
215 };
216 
217 #define	CPUF_PRIMARY	0x01		/* CPU is primary CPU */
218 #define	CPUF_RUNNING	0x02		/* CPU is running */
219 #define	CPUF_PAUSED	0x04		/* CPU is paused */
220 #define	CPUF_FPUSAVE	0x08		/* CPU is currently in fpusave_cpu() */
221 
222 void	fpusave_cpu(struct cpu_info *, int);
223 void	fpusave_proc(struct proc *, int);
224 
225 extern	struct cpu_info cpu_info_primary;
226 extern	struct cpu_info *cpu_info_list;
227 
228 #define	CPU_INFO_UNIT(ci)	((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0)
229 #define	CPU_INFO_ITERATOR		int
230 #define	CPU_INFO_FOREACH(cii, ci)	for (cii = 0, ci = cpu_info_list; \
231 					    ci != NULL; ci = ci->ci_next)
232 
233 #define MAXCPUS	ALPHA_MAXPROCS
234 
235 #if defined(MULTIPROCESSOR)
236 extern	volatile u_long cpus_running;
237 extern	volatile u_long cpus_paused;
238 extern	struct cpu_info *cpu_info[];
239 
240 #define	curcpu()			((struct cpu_info *)alpha_pal_rdval())
241 #define	CPU_IS_PRIMARY(ci)		((ci)->ci_flags & CPUF_PRIMARY)
242 
243 void	cpu_boot_secondary_processors(void);
244 
245 void	cpu_pause_resume(unsigned long, int);
246 void	cpu_pause_resume_all(int);
247 void	cpu_unidle(struct cpu_info *);
248 
249 #else /* ! MULTIPROCESSOR */
250 
251 #define	curcpu()			(&cpu_info_primary)
252 #define	CPU_IS_PRIMARY(ci)		1
253 #define cpu_unidle(ci)			do { /* nothing */ } while (0)
254 
255 #endif /* MULTIPROCESSOR */
256 
257 #define CPU_BUSY_CYCLE()	do {} while (0)
258 
259 #define	curproc		curcpu()->ci_curproc
260 #define	fpcurproc	curcpu()->ci_fpcurproc
261 #define	curpcb		curcpu()->ci_curpcb
262 
263 /*
264  * definitions of cpu-dependent requirements
265  * referenced in generic code
266  */
267 #define	cpu_number()		alpha_pal_whami()
268 
269 /*
270  * Arguments to hardclock and gatherstats encapsulate the previous
271  * machine state in an opaque clockframe.  On the Alpha, we use
272  * what we push on an interrupt (a trapframe).
273  */
274 struct clockframe {
275 	struct trapframe	cf_tf;
276 };
277 #define	CLKF_USERMODE(framep)						\
278 	(((framep)->cf_tf.tf_regs[FRAME_PS] & ALPHA_PSL_USERMODE) != 0)
279 #define	CLKF_PC(framep)		((framep)->cf_tf.tf_regs[FRAME_PC])
280 
281 /*
282  * This isn't perfect; if the clock interrupt comes in before the
283  * r/m/w cycle is complete, we won't be counted... but it's not
284  * like this statistic has to be extremely accurate.
285  */
286 #define	CLKF_INTR(framep)	(curcpu()->ci_intrdepth)
287 
288 /*
289  * This is used during profiling to integrate system time.
290  */
291 #define	PROC_PC(p)	((p)->p_md.md_tf->tf_regs[FRAME_PC])
292 #define	PROC_STACK(p)	(alpha_pal_rdusp())	/*XXX only works for curproc */
293 
294 /*
295  * Preempt the current process if in interrupt from user mode,
296  * or after the current trap/syscall if in system mode.
297  */
298 #define	need_resched(ci)						\
299 do {									\
300 	(ci)->ci_want_resched = 1;					\
301 	if ((ci)->ci_curproc != NULL)					\
302 		aston((ci)->ci_curproc);				\
303 } while (/*CONSTCOND*/0)
304 #define clear_resched(ci) (ci)->ci_want_resched = 0
305 
306 /*
307  * Give a profiling tick to the current process when the user profiling
308  * buffer pages are invalid.  On the Alpha, request an AST to send us
309  * through trap, marking the proc as needing a profiling tick.
310  */
311 #define	need_proftick(p)	aston(p)
312 
313 /*
314  * Notify the current process (p) that it has a signal pending,
315  * process as soon as possible.
316  */
317 #ifdef MULTIPROCESSOR
318 #define	signotify(p)	do { aston(p); cpu_unidle((p)->p_cpu); } while (0)
319 #else
320 #define signotify(p)	aston(p)
321 #endif
322 
323 #define	aston(p)	((p)->p_md.md_astpending = 1)
324 #endif /* _KERNEL */
325 
326 /*
327  * CTL_MACHDEP definitions.
328  */
329 #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
330 #define	CPU_UNALIGNED_PRINT	3	/* int: print unaligned accesses */
331 #define	CPU_UNALIGNED_FIX	4	/* int: fix unaligned accesses */
332 #define	CPU_UNALIGNED_SIGBUS	5	/* int: SIGBUS unaligned accesses */
333 #define	CPU_BOOTED_KERNEL	6	/* string: booted kernel name */
334 #define	CPU_FP_SYNC_COMPLETE	7	/* int: always fixup sync fp traps */
335 #define CPU_CHIPSET		8	/* chipset information */
336 #define CPU_ALLOWAPERTURE	9
337 #define	CPU_LED_BLINK		10	/* int: blink leds on DEC 3000 */
338 
339 #define	CPU_MAXID		11	/* valid machdep IDs */
340 
341 #define CPU_CHIPSET_MEM		1	/* PCI memory address */
342 #define CPU_CHIPSET_BWX		2	/* PCI supports BWX */
343 #define CPU_CHIPSET_TYPE	3	/* PCI chipset name */
344 #define CPU_CHIPSET_DENSE	4	/* PCI chipset dense memory addr */
345 #define CPU_CHIPSET_PORTS	5	/* PCI port address */
346 #define CPU_CHIPSET_HAE_MASK	6	/* PCI chipset mask for HAE register */
347 #define CPU_CHIPSET_MAXID	7
348 
349 #define	CTL_MACHDEP_NAMES { \
350 	{ 0, 0 }, \
351 	{ "console_device", CTLTYPE_STRUCT }, \
352 	{ 0, 0 }, \
353 	{ "unaligned_print", CTLTYPE_INT }, \
354 	{ "unaligned_fix", CTLTYPE_INT }, \
355 	{ "unaligned_sigbus", CTLTYPE_INT }, \
356 	{ "booted_kernel", CTLTYPE_STRING }, \
357 	{ "fp_sync_complete", CTLTYPE_INT }, \
358 	{ "chipset", CTLTYPE_NODE }, \
359 	{ "allowaperture", CTLTYPE_INT }, \
360 	{ "led_blink", CTLTYPE_INT } \
361 }
362 
363 #define CTL_CHIPSET_NAMES { \
364 	{ 0, 0 }, \
365 	{ "memory", CTLTYPE_QUAD }, \
366 	{ "bwx", CTLTYPE_INT }, \
367 	{ "type", CTLTYPE_STRING }, \
368 	{ "dense_base", CTLTYPE_QUAD }, \
369 	{ "ports_base", CTLTYPE_QUAD }, \
370 	{ "hae_mask", CTLTYPE_QUAD }, \
371 }
372 
373 #ifdef _KERNEL
374 
375 struct pcb;
376 struct proc;
377 struct reg;
378 struct rpb;
379 struct trapframe;
380 
381 /* IEEE and VAX FP completion */
382 
383 #ifndef NO_IEEE
384 void alpha_sts(int, s_float *);					/* MAGIC */
385 void alpha_stt(int, t_float *);					/* MAGIC */
386 void alpha_lds(int, s_float *);					/* MAGIC */
387 void alpha_ldt(int, t_float *);					/* MAGIC */
388 
389 uint64_t alpha_read_fpcr(void);					/* MAGIC */
390 void alpha_write_fpcr(u_int64_t);				/* MAGIC */
391 
392 u_int64_t alpha_read_fp_c(struct proc *);
393 void alpha_write_fp_c(struct proc *, u_int64_t);
394 
395 int alpha_fp_complete(u_long, u_long, struct proc *, u_int64_t *);
396 int alpha_fp_complete_at(u_long, struct proc *, u_int64_t *);
397 #endif
398 
399 void alpha_enable_fp(struct proc *, int);
400 
401 #ifdef MULTIPROCESSOR
402 #include <sys/mplock.h>
403 #endif
404 
405 #endif /* _KERNEL */
406 #endif /* _MACHINE_CPU_H_ */
407