Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.39
      1 /*	$NetBSD: cpu.h,v 1.39 2003/11/20 08:04:04 petrov Exp $ */
      2 
      3 /*
      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  *	@(#)cpu.h	8.4 (Berkeley) 1/5/94
     41  */
     42 
     43 #ifndef _CPU_H_
     44 #define _CPU_H_
     45 
     46 /*
     47  * CTL_MACHDEP definitions.
     48  */
     49 #define	CPU_BOOTED_KERNEL	1	/* string: booted kernel name */
     50 #define	CPU_BOOTED_DEVICE	2	/* string: device booted from */
     51 #define	CPU_BOOT_ARGS		3	/* string: args booted with */
     52 #define	CPU_ARCH		4	/* integer: cpu architecture version */
     53 #define	CPU_MAXID		5	/* number of valid machdep ids */
     54 
     55 #define	CTL_MACHDEP_NAMES {			\
     56 	{ 0, 0 },				\
     57 	{ "booted_kernel", CTLTYPE_STRING },	\
     58 	{ "booted_device", CTLTYPE_STRING },	\
     59 	{ "boot_args", CTLTYPE_STRING },	\
     60 	{ "cpu_arch", CTLTYPE_INT },		\
     61 }
     62 
     63 #ifdef _KERNEL
     64 /*
     65  * Exported definitions unique to SPARC cpu support.
     66  */
     67 
     68 #if defined(_KERNEL_OPT)
     69 #include "opt_multiprocessor.h"
     70 #include "opt_lockdebug.h"
     71 #endif
     72 
     73 #include <machine/psl.h>
     74 #include <machine/reg.h>
     75 #include <machine/intr.h>
     76 #include <sparc64/sparc64/intreg.h>
     77 
     78 #include <sys/sched.h>
     79 /*
     80  * The cpu_info structure is part of a 64KB structure mapped both the kernel
     81  * pmap and a single locked TTE a CPUINFO_VA for that particular processor.
     82  * Each processor's cpu_info is accessible at CPUINFO_VA only for that
     83  * processor.  Other processors can access that through an additional mapping
     84  * in the kernel pmap.
     85  *
     86  * The 64KB page contains:
     87  *
     88  * cpu_info
     89  * interrupt stack (all remaining space)
     90  * idle PCB
     91  * idle stack (STACKSPACE - sizeof(PCB))
     92  * 32KB TSB
     93  */
     94 
     95 struct cpu_info {
     96 	/* Most important fields first */
     97 	struct lwp		*ci_curlwp;
     98 	struct pcb		*ci_cpcb;
     99 	struct cpu_info		*ci_next;
    100 
    101 	struct lwp		*ci_fplwp;
    102 	int			ci_number;
    103 	int			ci_upaid;
    104 	int			ci_cpuid;
    105 	struct schedstate_percpu ci_schedstate;
    106 
    107 	/*
    108 	 * Variables used by cc_microtime().
    109 	 */
    110 	struct timeval ci_cc_time;
    111 	int64_t ci_cc_cc;
    112 	int64_t ci_cc_ms_delta;
    113 	int64_t ci_cc_denom;
    114 
    115 	/* DEBUG/DIAGNOSTIC stuff */
    116 	u_long			ci_spin_locks;
    117 	u_long			ci_simple_locks;
    118 
    119 	/* Spinning up the CPU */
    120 	void			(*ci_spinup) __P((void));
    121 	void			*ci_initstack;
    122 	paddr_t			ci_paddr;
    123 };
    124 
    125 extern struct cpu_info *cpus;
    126 extern struct cpu_info cpu_info_store;
    127 
    128 #if defined(MULTIPROCESSOR)
    129 #define	curcpu()	((struct cpu_info *)CPUINFO_VA)
    130 #else
    131 #define	curcpu()	(&cpu_info_store)
    132 #endif
    133 
    134 /*
    135  * definitions of cpu-dependent requirements
    136  * referenced in generic code
    137  */
    138 #define	cpu_swapin(p)	/* nothing */
    139 #define	cpu_swapout(p)	/* nothing */
    140 #define	cpu_wait(p)	/* nothing */
    141 #if 1
    142 #define cpu_number()	0
    143 #else
    144 #define	cpu_number()	(curcpu()->ci_number)
    145 #endif
    146 
    147 /* This really should be somewhere else. */
    148 #define	cpu_proc_fork(p1, p2)	/* nothing */
    149 
    150 #if defined(MULTIPROCESSOR)
    151 void	cpu_boot_secondary_processors __P((void));
    152 #define	CPU_IS_PRIMARY(ci)	(1) /* XXX */
    153 #else
    154 #define	CPU_IS_PRIMARY(ci)	(1)
    155 #endif
    156 
    157 /*
    158  * definitions for MI microtime().
    159  */
    160 extern struct timeval cc_microset_time;
    161 #define microtime(tv)	cc_microtime(tv)
    162 void	cc_microtime __P((struct timeval *));
    163 void	cc_microset __P((struct cpu_info *));
    164 
    165 extern uint64_t cpu_clockrate[];
    166 
    167 /*
    168  * Arguments to hardclock, softclock and gatherstats encapsulate the
    169  * previous machine state in an opaque clockframe.  The ipl is here
    170  * as well for strayintr (see locore.s:interrupt and intr.c:strayintr).
    171  * Note that CLKF_INTR is valid only if CLKF_USERMODE is false.
    172  */
    173 extern int intstack[];
    174 extern int eintstack[];
    175 struct clockframe {
    176 	struct trapframe64 t;
    177 };
    178 
    179 #define	CLKF_USERMODE(framep)	(((framep)->t.tf_tstate & TSTATE_PRIV) == 0)
    180 /*
    181  * XXX Disable CLKF_BASEPRI() for now.  If we use a counter-timer for
    182  * the clock, the interrupt remains blocked until the interrupt handler
    183  * returns and we write to the clear interrupt register.  If we use
    184  * %tick for the clock, we could get multiple interrupts, but the
    185  * currently enabled INTR_INTERLOCK will prevent the interrupt from being
    186  * posted twice anyway.
    187  *
    188  * Switching to %tick for all machines and disabling INTR_INTERLOCK
    189  * in locore.s would allow us to take advantage of CLKF_BASEPRI().
    190  */
    191 #if 0
    192 #define	CLKF_BASEPRI(framep)	(((framep)->t.tf_oldpil) == 0)
    193 #else
    194 #define	CLKF_BASEPRI(framep)	(0)
    195 #endif
    196 #define	CLKF_PC(framep)		((framep)->t.tf_pc)
    197 /* Since some files in sys/kern do not know BIAS, I'm using 0x7ff here */
    198 #define	CLKF_INTR(framep)						\
    199 	((!CLKF_USERMODE(framep))&&					\
    200 		(((framep)->t.tf_out[6] & 1 ) ?				\
    201 			(((vaddr_t)(framep)->t.tf_out[6] <		\
    202 				(vaddr_t)EINTSTACK-0x7ff) &&		\
    203 			((vaddr_t)(framep)->t.tf_out[6] >		\
    204 				(vaddr_t)INTSTACK-0x7ff)) :		\
    205 			(((vaddr_t)(framep)->t.tf_out[6] <		\
    206 				(vaddr_t)EINTSTACK) &&			\
    207 			((vaddr_t)(framep)->t.tf_out[6] >		\
    208 				(vaddr_t)INTSTACK))))
    209 
    210 /*
    211  * Software interrupt request `register'.
    212  */
    213 #ifdef DEPRECATED
    214 union sir {
    215 	int	sir_any;
    216 	char	sir_which[4];
    217 } sir;
    218 
    219 #define SIR_NET		0
    220 #define SIR_CLOCK	1
    221 #endif
    222 
    223 extern struct intrhand soft01intr, soft01net, soft01clock;
    224 
    225 #if 0
    226 #define setsoftint()	send_softint(-1, IPL_SOFTINT, &soft01intr)
    227 #define setsoftnet()	send_softint(-1, IPL_SOFTNET, &soft01net)
    228 #else
    229 void setsoftint __P((void));
    230 void setsoftnet __P((void));
    231 #endif
    232 
    233 int	want_ast;
    234 
    235 /*
    236  * Preempt the current process if in interrupt from user mode,
    237  * or after the current trap/syscall if in system mode.
    238  */
    239 int	want_resched;		/* resched() was called */
    240 #define	need_resched(ci)	(want_resched = 1, want_ast = 1)
    241 
    242 /*
    243  * Give a profiling tick to the current process when the user profiling
    244  * buffer pages are invalid.  On the sparc, request an ast to send us
    245  * through trap(), marking the proc as needing a profiling tick.
    246  */
    247 #define	need_proftick(p)	((p)->p_flag |= P_OWEUPC, want_ast = 1)
    248 
    249 /*
    250  * Notify the current process (p) that it has a signal pending,
    251  * process as soon as possible.
    252  */
    253 #define	signotify(p)		(want_ast = 1)
    254 
    255 /*
    256  * Only one process may own the FPU state.
    257  *
    258  * XXX this must be per-cpu (eventually)
    259  */
    260 struct	lwp *fplwp;		/* FPU owner */
    261 
    262 /*
    263  * Interrupt handler chains.  Interrupt handlers should return 0 for
    264  * ``not me'' or 1 (``I took care of it'').  intr_establish() inserts a
    265  * handler into the list.  The handler is called with its (single)
    266  * argument, or with a pointer to a clockframe if ih_arg is NULL.
    267  */
    268 struct intrhand {
    269 	int			(*ih_fun) __P((void *));
    270 	void			*ih_arg;
    271 	short			ih_number;	/* interrupt number */
    272 						/* the H/W provides */
    273 	char			ih_pil;		/* interrupt priority */
    274 	struct intrhand		*ih_next;	/* global list */
    275 	struct intrhand		*ih_pending;	/* interrupt queued */
    276 	volatile u_int64_t	*ih_map;	/* Interrupt map reg */
    277 	volatile u_int64_t	*ih_clr;	/* clear interrupt reg */
    278 };
    279 extern struct intrhand *intrhand[];
    280 extern struct intrhand *intrlev[MAXINTNUM];
    281 
    282 void	intr_establish __P((int level, struct intrhand *));
    283 
    284 /* cpu.c */
    285 paddr_t cpu_alloc __P((void));
    286 u_int64_t cpu_init __P((paddr_t, int));
    287 /* disksubr.c */
    288 struct dkbad;
    289 int isbad __P((struct dkbad *bt, int, int, int));
    290 /* machdep.c */
    291 int	ldcontrolb __P((caddr_t));
    292 void	dumpconf __P((void));
    293 caddr_t	reserve_dumppages __P((caddr_t));
    294 /* clock.c */
    295 struct timeval;
    296 int	tickintr __P((void *)); /* level 10 (tick) interrupt code */
    297 int	clockintr __P((void *));/* level 10 (clock) interrupt code */
    298 int	statintr __P((void *));	/* level 14 (statclock) interrupt code */
    299 /* locore.s */
    300 struct fpstate64;
    301 void	savefpstate __P((struct fpstate64 *));
    302 void	loadfpstate __P((struct fpstate64 *));
    303 u_int64_t	probeget __P((paddr_t, int, int));
    304 int	probeset __P((paddr_t, int, int, u_int64_t));
    305 #if 0
    306 void	write_all_windows __P((void));
    307 void	write_user_windows __P((void));
    308 #else
    309 #define	 write_all_windows() __asm __volatile("flushw" : : )
    310 #define	 write_user_windows() __asm __volatile("flushw" : : )
    311 #endif
    312 void 	proc_trampoline __P((void));
    313 struct pcb;
    314 void	snapshot __P((struct pcb *));
    315 struct frame *getfp __P((void));
    316 int	xldcontrolb __P((caddr_t, struct pcb *));
    317 void	copywords __P((const void *, void *, size_t));
    318 void	qcopy __P((const void *, void *, size_t));
    319 void	qzero __P((void *, size_t));
    320 void	switchtoctx __P((int));
    321 /* locore2.c */
    322 void	remrq __P((struct proc *));
    323 /* trap.c */
    324 void	kill_user_windows __P((struct lwp *));
    325 int	rwindow_save __P((struct lwp *));
    326 /* amd7930intr.s */
    327 void	amd7930_trap __P((void));
    328 /* cons.c */
    329 int	cnrom __P((void));
    330 /* zs.c */
    331 void zsconsole __P((struct tty *, int, int, void (**)(struct tty *, int)));
    332 #ifdef KGDB
    333 void zs_kgdb_init __P((void));
    334 #endif
    335 /* fb.c */
    336 void	fb_unblank __P((void));
    337 /* kgdb_stub.c */
    338 #ifdef KGDB
    339 void kgdb_attach __P((int (*)(void *), void (*)(void *, int), void *));
    340 void kgdb_connect __P((int));
    341 void kgdb_panic __P((void));
    342 #endif
    343 /* emul.c */
    344 int	fixalign __P((struct lwp *, struct trapframe64 *));
    345 int	emulinstr __P((vaddr_t, struct trapframe64 *));
    346 
    347 /*
    348  *
    349  * The SPARC has a Trap Base Register (TBR) which holds the upper 20 bits
    350  * of the trap vector table.  The next eight bits are supplied by the
    351  * hardware when the trap occurs, and the bottom four bits are always
    352  * zero (so that we can shove up to 16 bytes of executable code---exactly
    353  * four instructions---into each trap vector).
    354  *
    355  * The hardware allocates half the trap vectors to hardware and half to
    356  * software.
    357  *
    358  * Traps have priorities assigned (lower number => higher priority).
    359  */
    360 
    361 struct trapvec {
    362 	int	tv_instr[8];		/* the eight instructions */
    363 };
    364 extern struct trapvec *trapbase;	/* the 256 vectors */
    365 
    366 extern void wzero __P((void *, u_int));
    367 extern void wcopy __P((const void *, void *, u_int));
    368 
    369 #endif /* _KERNEL */
    370 #endif /* _CPU_H_ */
    371