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