Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.104
      1  1.104       ryo /* $NetBSD: cpu.h,v 1.104 2021/08/14 17:51:18 ryo 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  *
     20   1.32   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21   1.32   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.32   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.32   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24   1.32   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.32   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.32   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.32   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.32   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.32   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.32   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31   1.32   thorpej  */
     32    1.1       cgd 
     33    1.1       cgd /*
     34   1.76     rmind  * Copyright (c) 1988 University of Utah.
     35    1.1       cgd  * Copyright (c) 1982, 1990, 1993
     36    1.1       cgd  *	The Regents of the University of California.  All rights reserved.
     37   1.61       agc  *
     38   1.61       agc  * This code is derived from software contributed to Berkeley by
     39   1.61       agc  * the Systems Programming Group of the University of Utah Computer
     40   1.61       agc  * Science Department.
     41   1.61       agc  *
     42   1.61       agc  * Redistribution and use in source and binary forms, with or without
     43   1.61       agc  * modification, are permitted provided that the following conditions
     44   1.61       agc  * are met:
     45   1.61       agc  * 1. Redistributions of source code must retain the above copyright
     46   1.61       agc  *    notice, this list of conditions and the following disclaimer.
     47   1.61       agc  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.61       agc  *    notice, this list of conditions and the following disclaimer in the
     49   1.61       agc  *    documentation and/or other materials provided with the distribution.
     50   1.61       agc  * 3. Neither the name of the University nor the names of its contributors
     51   1.61       agc  *    may be used to endorse or promote products derived from this software
     52   1.61       agc  *    without specific prior written permission.
     53   1.61       agc  *
     54   1.61       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55   1.61       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56   1.61       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57   1.61       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58   1.61       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59   1.61       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60   1.61       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61   1.61       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62   1.61       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63   1.61       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64   1.61       agc  * SUCH DAMAGE.
     65   1.61       agc  *
     66   1.61       agc  * from: Utah $Hdr: cpu.h 1.16 91/03/25$
     67   1.61       agc  *
     68   1.61       agc  *	@(#)cpu.h	8.4 (Berkeley) 1/5/94
     69   1.61       agc  */
     70    1.1       cgd 
     71    1.1       cgd #ifndef _ALPHA_CPU_H_
     72    1.1       cgd #define _ALPHA_CPU_H_
     73    1.1       cgd 
     74   1.58       mrg #if defined(_KERNEL_OPT)
     75  1.104       ryo #include "opt_gprof.h"
     76   1.32   thorpej #include "opt_multiprocessor.h"
     77   1.39   thorpej #include "opt_lockdebug.h"
     78   1.32   thorpej #endif
     79   1.32   thorpej 
     80    1.1       cgd /*
     81    1.1       cgd  * Exported definitions unique to Alpha cpu support.
     82    1.1       cgd  */
     83   1.34   thorpej 
     84   1.34   thorpej #include <machine/alpha_cpu.h>
     85    1.1       cgd 
     86   1.75        he #if defined(_KERNEL) || defined(_KMEMUSER)
     87   1.63      yamt #include <sys/cpu_data.h>
     88   1.71   tsutsui #include <sys/cctr.h>
     89   1.96   thorpej #include <sys/intr.h>
     90    1.1       cgd #include <machine/frame.h>
     91   1.32   thorpej 
     92   1.37   thorpej /*
     93   1.37   thorpej  * Machine check information.
     94   1.37   thorpej  */
     95   1.37   thorpej struct mchkinfo {
     96   1.65     perry 	volatile int mc_expected;	/* machine check is expected */
     97   1.65     perry 	volatile int mc_received;	/* machine check was received */
     98   1.37   thorpej };
     99   1.37   thorpej 
    100   1.92   thorpej /*
    101   1.92   thorpej  * Per-cpu information.  Data accessed by MI code is marked [MI].
    102   1.92   thorpej  */
    103   1.32   thorpej struct cpu_info {
    104   1.94   thorpej 	struct cpu_data ci_data;	/* [MI] general per-cpu data */
    105   1.92   thorpej 	struct lwp *ci_curlwp;		/* [MI] current owner of the cpu */
    106   1.92   thorpej 	struct lwp *ci_onproc;		/* [MI] current user LWP / kthread */
    107   1.92   thorpej 	struct cctr_state ci_cc;	/* [MI] cycle counter state */
    108   1.92   thorpej 
    109   1.92   thorpej 	volatile int ci_mtx_count;	/* [MI] neg count of spin mutexes */
    110   1.92   thorpej 	volatile int ci_mtx_oldspl;	/* [MI] for spin mutex splx() */
    111   1.39   thorpej 
    112   1.92   thorpej 	u_long ci_intrdepth;		/* interrupt trap depth */
    113   1.95   thorpej 	volatile u_long ci_ssir;	/* simulated software interrupt reg */
    114   1.96   thorpej 					/* LWPs for soft intr dispatch */
    115   1.96   thorpej 	struct lwp *ci_silwps[SOFTINT_COUNT];
    116   1.43   thorpej 	struct cpu_softc *ci_softc;	/* pointer to our device */
    117   1.56   thorpej 
    118   1.87   thorpej 	struct pmap *ci_pmap;		/* currently-activated pmap */
    119   1.89   thorpej 	u_int ci_next_asn;		/* next ASN to assign */
    120   1.89   thorpej 	u_long ci_asn_gen;		/* current ASN generation */
    121   1.87   thorpej 
    122   1.92   thorpej 	struct mchkinfo ci_mcinfo;	/* machine check info */
    123   1.92   thorpej 
    124   1.92   thorpej 	/*
    125   1.92   thorpej 	 * The following must be in their own cache line, as they are
    126   1.92   thorpej 	 * stored to regularly by remote CPUs.
    127   1.92   thorpej 	 */
    128   1.92   thorpej 	volatile u_long ci_ipis		/* interprocessor interrupts pending */
    129   1.92   thorpej 			__aligned(64);
    130   1.92   thorpej 	u_int	ci_want_resched;	/* [MI] preempt current process */
    131   1.92   thorpej 
    132   1.92   thorpej 	/*
    133   1.92   thorpej 	 * These are largely static, and will frequently be fetched
    134   1.92   thorpej 	 * by other CPUs.  For that reason, they get their own cache
    135   1.92   thorpej 	 * line, too.
    136   1.92   thorpej 	 */
    137   1.92   thorpej 	struct cpu_info *ci_next	/* next cpu_info structure */
    138   1.92   thorpej 			__aligned(64);
    139   1.92   thorpej 	cpuid_t ci_cpuid;		/* [MI] our CPU ID */
    140   1.65     perry 	volatile u_long ci_flags;	/* flags; see below */
    141   1.92   thorpej 	uint64_t ci_pcc_freq;		/* cpu cycles/second */
    142   1.92   thorpej 	struct trapframe *ci_db_regs;	/* registers for debuggers */
    143   1.97   thorpej 	u_int	ci_nintrhand;		/* # of interrupt handlers */
    144  1.104       ryo #if defined(GPROF) && defined(MULTIPROCESSOR)
    145  1.104       ryo 	struct gmonparam *ci_gmon;	/* [MI] per-cpu GPROF */
    146  1.104       ryo #endif
    147   1.32   thorpej };
    148   1.32   thorpej 
    149   1.95   thorpej /* Ensure some cpu_info fields are within the signed 16-bit displacement. */
    150   1.92   thorpej __CTASSERT(offsetof(struct cpu_info, ci_curlwp) <= 0x7ff0);
    151   1.95   thorpej __CTASSERT(offsetof(struct cpu_info, ci_ssir) <= 0x7ff0);
    152   1.92   thorpej 
    153   1.75        he #endif /* _KERNEL || _KMEMUSER */
    154   1.75        he 
    155   1.75        he #if defined(_KERNEL)
    156   1.75        he 
    157   1.32   thorpej #define	CPUF_PRIMARY	0x01		/* CPU is primary CPU */
    158   1.32   thorpej #define	CPUF_PRESENT	0x02		/* CPU is present */
    159   1.32   thorpej #define	CPUF_RUNNING	0x04		/* CPU is running */
    160   1.48   thorpej #define	CPUF_PAUSED	0x08		/* CPU is paused */
    161   1.32   thorpej 
    162   1.54   thorpej extern	struct cpu_info cpu_info_primary;
    163   1.54   thorpej extern	struct cpu_info *cpu_info_list;
    164   1.54   thorpej 
    165   1.80  christos #define	CPU_INFO_ITERATOR		int __unused
    166   1.80  christos #define	CPU_INFO_FOREACH(cii, ci)	ci = cpu_info_list; \
    167   1.54   thorpej 					ci != NULL; ci = ci->ci_next
    168   1.54   thorpej 
    169   1.40   thorpej #if defined(MULTIPROCESSOR)
    170   1.65     perry extern	volatile u_long cpus_running;
    171   1.65     perry extern	volatile u_long cpus_paused;
    172   1.54   thorpej extern	struct cpu_info *cpu_info[];
    173   1.32   thorpej 
    174   1.93   thorpej #define	curlwp			((struct lwp *)alpha_pal_rdval())
    175   1.93   thorpej #define	curcpu()		curlwp->l_cpu
    176   1.41   thorpej #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
    177   1.32   thorpej 
    178   1.44   thorpej void	cpu_boot_secondary_processors(void);
    179   1.45   thorpej 
    180   1.45   thorpej void	cpu_pause_resume(unsigned long, int);
    181   1.45   thorpej void	cpu_pause_resume_all(int);
    182   1.39   thorpej #else /* ! MULTIPROCESSOR */
    183   1.54   thorpej #define	curcpu()	(&cpu_info_primary)
    184   1.93   thorpej #define	curlwp		curcpu()->ci_curlwp
    185   1.32   thorpej #endif /* MULTIPROCESSOR */
    186   1.38   thorpej 
    187   1.40   thorpej 
    188    1.1       cgd /*
    189    1.1       cgd  * definitions of cpu-dependent requirements
    190    1.1       cgd  * referenced in generic code
    191    1.1       cgd  */
    192   1.31   thorpej #define	cpu_number()		alpha_pal_whami()
    193   1.59   thorpej #define	cpu_proc_fork(p1, p2)	/* nothing */
    194    1.1       cgd 
    195    1.1       cgd /*
    196    1.1       cgd  * Arguments to hardclock and gatherstats encapsulate the previous
    197   1.83      flxd  * machine state in an opaque clockframe.  On the alpha, we use
    198    1.1       cgd  * what we push on an interrupt (a trapframe).
    199    1.1       cgd  */
    200    1.1       cgd struct clockframe {
    201    1.1       cgd 	struct trapframe	cf_tf;
    202    1.1       cgd };
    203    1.9       cgd #define	CLKF_USERMODE(framep)						\
    204   1.11       cgd 	(((framep)->cf_tf.tf_regs[FRAME_PS] & ALPHA_PSL_USERMODE) != 0)
    205   1.11       cgd #define	CLKF_PC(framep)		((framep)->cf_tf.tf_regs[FRAME_PC])
    206   1.42   thorpej 
    207    1.1       cgd /*
    208   1.42   thorpej  * This isn't perfect; if the clock interrupt comes in before the
    209   1.42   thorpej  * r/m/w cycle is complete, we won't be counted... but it's not
    210  1.102     skrll  * like this statistic has to be extremely accurate.
    211    1.1       cgd  */
    212  1.100       rin #define	CLKF_INTR(framep)						\
    213  1.101   thorpej 	((curcpu()->ci_intrdepth & 0xf) != 0)	/* see interrupt() */
    214   1.49   mycroft 
    215   1.49   mycroft /*
    216   1.49   mycroft  * This is used during profiling to integrate system time.  It can safely
    217   1.49   mycroft  * assume that the process is resident.
    218   1.49   mycroft  */
    219   1.59   thorpej #define	LWP_PC(p)		((l)->l_md.md_tf->tf_regs[FRAME_PC])
    220    1.1       cgd 
    221   1.88   thorpej void	cpu_need_proftick(struct lwp *);
    222   1.88   thorpej void	cpu_signotify(struct lwp *);
    223    1.1       cgd 
    224   1.88   thorpej #define	aston(l)		((l)->l_md.md_astpending = 1)
    225   1.33   thorpej #endif /* _KERNEL */
    226    1.1       cgd 
    227    1.1       cgd /*
    228    1.1       cgd  * CTL_MACHDEP definitions.
    229    1.1       cgd  */
    230    1.1       cgd #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
    231    1.8       cgd #define	CPU_ROOT_DEVICE		2	/* string: root device name */
    232   1.12       cgd #define	CPU_UNALIGNED_PRINT	3	/* int: print unaligned accesses */
    233   1.12       cgd #define	CPU_UNALIGNED_FIX	4	/* int: fix unaligned accesses */
    234   1.12       cgd #define	CPU_UNALIGNED_SIGBUS	5	/* int: SIGBUS unaligned accesses */
    235   1.14       cgd #define	CPU_BOOTED_KERNEL	6	/* string: booted kernel name */
    236   1.55      ross #define	CPU_FP_SYNC_COMPLETE	7	/* int: always fixup sync fp traps */
    237   1.99   thorpej #define	CPU_CCTR		8	/* int: using CC timecounter */
    238   1.99   thorpej #define	CPU_IS_QEMU		9	/* int: running under Qemu */
    239  1.103   thorpej #define	CPU_FP_COMPLETE_DEBUG	10	/* int: enable FP completion debug */
    240   1.99   thorpej 
    241    1.1       cgd 
    242   1.13       cgd #ifdef _KERNEL
    243   1.13       cgd 
    244   1.13       cgd struct pcb;
    245   1.13       cgd struct proc;
    246   1.13       cgd struct reg;
    247   1.13       cgd struct rpb;
    248   1.13       cgd struct trapframe;
    249   1.57  sommerfe 
    250   1.44   thorpej int	badaddr(void *, size_t);
    251   1.77      matt void *	cpu_uarea_alloc(bool);
    252   1.78      matt bool	cpu_uarea_free(void *);
    253   1.13       cgd 
    254   1.98   thorpej void	cpu_idle_wtint(void);
    255   1.98   thorpej extern	void (*cpu_idle_fn)(void);
    256   1.98   thorpej #define	cpu_idle()	(*cpu_idle_fn)()
    257   1.98   thorpej 
    258   1.98   thorpej void	cpu_initclocks_secondary(void);
    259   1.68      yamt 
    260   1.13       cgd #endif /* _KERNEL */
    261    1.1       cgd #endif /* _ALPHA_CPU_H_ */
    262