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