xref: /netbsd-src/sys/arch/alpha/include/cpu.h (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /* $NetBSD: cpu.h,v 1.75 2010/12/26 18:00:41 he Exp $ */
2 
3 /*-
4  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center, and by Charles M. Hannum.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * Copyright (c) 1982, 1990, 1993
35  *	The Regents of the University of California.  All rights reserved.
36  *
37  * This code is derived from software contributed to Berkeley by
38  * the Systems Programming Group of the University of Utah Computer
39  * Science Department.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  *    notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in the
48  *    documentation and/or other materials provided with the distribution.
49  * 3. Neither the name of the University nor the names of its contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  *
65  * from: Utah $Hdr: cpu.h 1.16 91/03/25$
66  *
67  *	@(#)cpu.h	8.4 (Berkeley) 1/5/94
68  */
69 /*
70  * Copyright (c) 1988 University of Utah.
71  *
72  * This code is derived from software contributed to Berkeley by
73  * the Systems Programming Group of the University of Utah Computer
74  * Science Department.
75  *
76  * Redistribution and use in source and binary forms, with or without
77  * modification, are permitted provided that the following conditions
78  * are met:
79  * 1. Redistributions of source code must retain the above copyright
80  *    notice, this list of conditions and the following disclaimer.
81  * 2. Redistributions in binary form must reproduce the above copyright
82  *    notice, this list of conditions and the following disclaimer in the
83  *    documentation and/or other materials provided with the distribution.
84  * 3. All advertising materials mentioning features or use of this software
85  *    must display the following acknowledgement:
86  *	This product includes software developed by the University of
87  *	California, Berkeley and its contributors.
88  * 4. Neither the name of the University nor the names of its contributors
89  *    may be used to endorse or promote products derived from this software
90  *    without specific prior written permission.
91  *
92  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
93  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
95  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
96  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
97  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
98  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
100  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
101  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
102  * SUCH DAMAGE.
103  *
104  * from: Utah $Hdr: cpu.h 1.16 91/03/25$
105  *
106  *	@(#)cpu.h	8.4 (Berkeley) 1/5/94
107  */
108 
109 #ifndef _ALPHA_CPU_H_
110 #define _ALPHA_CPU_H_
111 
112 #if defined(_KERNEL_OPT)
113 #include "opt_multiprocessor.h"
114 #include "opt_lockdebug.h"
115 #endif
116 
117 /*
118  * Exported definitions unique to Alpha cpu support.
119  */
120 
121 #include <machine/alpha_cpu.h>
122 
123 #if defined(_KERNEL) || defined(_KMEMUSER)
124 #include <sys/cpu_data.h>
125 #ifndef _KMEMUSER
126 #include <sys/cctr.h>
127 #include <machine/frame.h>
128 #endif
129 
130 /*
131  * Machine check information.
132  */
133 struct mchkinfo {
134 	volatile int mc_expected;	/* machine check is expected */
135 	volatile int mc_received;	/* machine check was received */
136 };
137 
138 struct cpu_info {
139 	/*
140 	 * Private members accessed in assembly with 8 bit offsets.
141 	 */
142 	struct lwp *ci_fpcurlwp;	/* current owner of the FPU */
143 	paddr_t ci_curpcb;		/* PA of current HW PCB */
144 
145 	/*
146 	 * Public members.
147 	 */
148 	struct lwp *ci_curlwp;		/* current owner of the processor */
149 	struct cpu_data ci_data;	/* MI per-cpu data */
150 #ifndef _KMEMUSER
151 	struct cctr_state ci_cc;	/* cycle counter state */
152 	struct cpu_info *ci_next;	/* next cpu_info structure */
153 	int ci_mtx_count;
154 	int ci_mtx_oldspl;
155 
156 	/*
157 	 * Private members.
158 	 */
159 	struct mchkinfo ci_mcinfo;	/* machine check info */
160 	cpuid_t ci_cpuid;		/* our CPU ID */
161 	struct cpu_softc *ci_softc;	/* pointer to our device */
162 	u_long ci_want_resched;		/* preempt current process */
163 	u_long ci_intrdepth;		/* interrupt trap depth */
164 	struct trapframe *ci_db_regs;	/* registers for debuggers */
165 	uint64_t ci_pcc_freq;		/* cpu cycles/second */
166 
167 #if defined(MULTIPROCESSOR)
168 	volatile u_long ci_flags;	/* flags; see below */
169 	volatile u_long ci_ipis;	/* interprocessor interrupts pending */
170 #endif
171 #endif /* _KMEMUSER */
172 };
173 
174 #endif /* _KERNEL || _KMEMUSER */
175 
176 #if defined(_KERNEL)
177 
178 #define	CPUF_PRIMARY	0x01		/* CPU is primary CPU */
179 #define	CPUF_PRESENT	0x02		/* CPU is present */
180 #define	CPUF_RUNNING	0x04		/* CPU is running */
181 #define	CPUF_PAUSED	0x08		/* CPU is paused */
182 #define	CPUF_FPUSAVE	0x10		/* CPU is currently in fpusave_cpu() */
183 
184 extern	struct cpu_info cpu_info_primary;
185 extern	struct cpu_info *cpu_info_list;
186 
187 #define	CPU_INFO_ITERATOR		int
188 #define	CPU_INFO_FOREACH(cii, ci)	cii = 0, ci = cpu_info_list; \
189 					ci != NULL; ci = ci->ci_next
190 
191 #if defined(MULTIPROCESSOR)
192 extern	volatile u_long cpus_running;
193 extern	volatile u_long cpus_paused;
194 extern	struct cpu_info *cpu_info[];
195 
196 #define	curcpu()		((struct cpu_info *)alpha_pal_rdval())
197 #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
198 
199 void	cpu_boot_secondary_processors(void);
200 
201 void	cpu_pause_resume(unsigned long, int);
202 void	cpu_pause_resume_all(int);
203 #else /* ! MULTIPROCESSOR */
204 #define	curcpu()	(&cpu_info_primary)
205 #endif /* MULTIPROCESSOR */
206 
207 #define	curlwp		curcpu()->ci_curlwp
208 #define	fpcurlwp	curcpu()->ci_fpcurlwp
209 #define	curpcb		curcpu()->ci_curpcb
210 
211 /*
212  * definitions of cpu-dependent requirements
213  * referenced in generic code
214  */
215 #define	cpu_number()		alpha_pal_whami()
216 #define	cpu_proc_fork(p1, p2)	/* nothing */
217 
218 /*
219  * Arguments to hardclock and gatherstats encapsulate the previous
220  * machine state in an opaque clockframe.  One the Alpha, we use
221  * what we push on an interrupt (a trapframe).
222  */
223 struct clockframe {
224 	struct trapframe	cf_tf;
225 };
226 #define	CLKF_USERMODE(framep)						\
227 	(((framep)->cf_tf.tf_regs[FRAME_PS] & ALPHA_PSL_USERMODE) != 0)
228 #define	CLKF_PC(framep)		((framep)->cf_tf.tf_regs[FRAME_PC])
229 
230 /*
231  * This isn't perfect; if the clock interrupt comes in before the
232  * r/m/w cycle is complete, we won't be counted... but it's not
233  * like this stastic has to be extremely accurate.
234  */
235 #define	CLKF_INTR(framep)	(curcpu()->ci_intrdepth)
236 
237 /*
238  * This is used during profiling to integrate system time.  It can safely
239  * assume that the process is resident.
240  */
241 #define	LWP_PC(p)		((l)->l_md.md_tf->tf_regs[FRAME_PC])
242 
243 /*
244  * Give a profiling tick to the current process when the user profiling
245  * buffer pages are invalid.  On the Alpha, request an AST to send us
246  * through trap, marking the proc as needing a profiling tick.
247  */
248 #define	cpu_need_proftick(l)						\
249 do {									\
250 	(l)->l_pflag |= LP_OWEUPC;					\
251 	aston(l);							\
252 } while (/*CONSTCOND*/0)
253 
254 /*
255  * Notify the current process (p) that it has a signal pending,
256  * process as soon as possible.
257  */
258 #define	cpu_signotify(l)	aston(l)
259 
260 /*
261  * XXXSMP
262  * Should we send an AST IPI?  Or just let it handle it next time
263  * it sees a normal kernel entry?  I guess letting it happen later
264  * follows the `asynchronous' part of the name...
265  */
266 #define	aston(l)	((l)->l_md.md_astpending = 1)
267 #endif /* _KERNEL */
268 
269 /*
270  * CTL_MACHDEP definitions.
271  */
272 #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
273 #define	CPU_ROOT_DEVICE		2	/* string: root device name */
274 #define	CPU_UNALIGNED_PRINT	3	/* int: print unaligned accesses */
275 #define	CPU_UNALIGNED_FIX	4	/* int: fix unaligned accesses */
276 #define	CPU_UNALIGNED_SIGBUS	5	/* int: SIGBUS unaligned accesses */
277 #define	CPU_BOOTED_KERNEL	6	/* string: booted kernel name */
278 #define	CPU_FP_SYNC_COMPLETE	7	/* int: always fixup sync fp traps */
279 #define	CPU_MAXID		8	/* 7 valid machdep IDs */
280 
281 #ifdef _KERNEL
282 
283 struct pcb;
284 struct proc;
285 struct reg;
286 struct rpb;
287 struct trapframe;
288 
289 int	badaddr(void *, size_t);
290 
291 #define	cpu_idle()	/* nothing */
292 
293 #endif /* _KERNEL */
294 #endif /* _ALPHA_CPU_H_ */
295