Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.106.12.3
      1  1.106.12.1       tls /*	$NetBSD: cpu.h,v 1.106.12.3 2017/12/03 11:36:27 jdolecek Exp $	*/
      2         1.8       cgd 
      3         1.1   deraadt /*-
      4         1.5     glass  * Copyright (c) 1992, 1993
      5         1.5     glass  *	The Regents of the University of California.  All rights reserved.
      6         1.1   deraadt  *
      7         1.1   deraadt  * This code is derived from software contributed to Berkeley by
      8         1.1   deraadt  * Ralph Campbell and Rick Macklem.
      9         1.1   deraadt  *
     10         1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     11         1.1   deraadt  * modification, are permitted provided that the following conditions
     12         1.1   deraadt  * are met:
     13         1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     14         1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     15         1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     16         1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     17         1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     18        1.71       agc  * 3. Neither the name of the University nor the names of its contributors
     19         1.1   deraadt  *    may be used to endorse or promote products derived from this software
     20         1.1   deraadt  *    without specific prior written permission.
     21         1.1   deraadt  *
     22         1.1   deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23         1.1   deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24         1.1   deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25         1.1   deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26         1.1   deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27         1.1   deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28         1.1   deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29         1.1   deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30         1.1   deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31         1.1   deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32         1.1   deraadt  * SUCH DAMAGE.
     33         1.1   deraadt  *
     34         1.8       cgd  *	@(#)cpu.h	8.4 (Berkeley) 1/4/94
     35         1.1   deraadt  */
     36         1.1   deraadt 
     37         1.1   deraadt #ifndef _CPU_H_
     38         1.1   deraadt #define _CPU_H_
     39         1.1   deraadt 
     40         1.1   deraadt /*
     41        1.13  jonathan  * Exported definitions unique to NetBSD/mips cpu support.
     42         1.1   deraadt  */
     43        1.36     soren 
     44  1.106.12.3  jdolecek #ifdef _LOCORE
     45  1.106.12.3  jdolecek #error Use assym.h to get definitions from <mips/cpu.h>
     46  1.106.12.3  jdolecek #endif
     47  1.106.12.3  jdolecek 
     48        1.68    simonb #ifdef _KERNEL
     49        1.55    simonb 
     50        1.53    simonb #if defined(_KERNEL_OPT)
     51        1.98      matt #include "opt_cputype.h"
     52        1.53    simonb #include "opt_lockdebug.h"
     53        1.98      matt #include "opt_multiprocessor.h"
     54        1.53    simonb #endif
     55        1.53    simonb 
     56        1.98      matt #include <sys/cpu_data.h>
     57        1.98      matt #include <sys/device_if.h>
     58        1.98      matt #include <sys/evcnt.h>
     59  1.106.12.3  jdolecek #include <sys/kcpuset.h>
     60        1.94      matt 
     61       1.101     cliff typedef struct cpu_watchpoint {
     62       1.101     cliff 	register_t	cw_addr;
     63       1.101     cliff 	register_t	cw_mask;
     64       1.101     cliff 	uint32_t	cw_asid;
     65       1.101     cliff 	uint32_t	cw_mode;
     66       1.101     cliff } cpu_watchpoint_t;
     67  1.106.12.3  jdolecek 
     68       1.101     cliff /* (abstract) mode bits */
     69       1.101     cliff #define CPUWATCH_WRITE	__BIT(0)
     70       1.101     cliff #define CPUWATCH_READ	__BIT(1)
     71       1.101     cliff #define CPUWATCH_EXEC	__BIT(2)
     72       1.101     cliff #define CPUWATCH_MASK	__BIT(3)
     73       1.101     cliff #define CPUWATCH_ASID	__BIT(4)
     74       1.101     cliff #define CPUWATCH_RWX	(CPUWATCH_EXEC|CPUWATCH_READ|CPUWATCH_WRITE)
     75       1.101     cliff 
     76       1.101     cliff #define CPUWATCH_MAX	8	/* max possible number of watchpoints */
     77       1.101     cliff 
     78       1.101     cliff u_int		  cpuwatch_discover(void);
     79       1.101     cliff void		  cpuwatch_free(cpu_watchpoint_t *);
     80       1.101     cliff cpu_watchpoint_t *cpuwatch_alloc(void);
     81       1.101     cliff void		  cpuwatch_set_all(void);
     82       1.101     cliff void		  cpuwatch_clr_all(void);
     83       1.101     cliff void		  cpuwatch_set(cpu_watchpoint_t *);
     84       1.101     cliff void		  cpuwatch_clr(cpu_watchpoint_t *);
     85       1.101     cliff 
     86        1.53    simonb struct cpu_info {
     87        1.73      yamt 	struct cpu_data ci_data;	/* MI per-cpu data */
     88  1.106.12.3  jdolecek 	void *ci_nmi_stack;		/* NMI exception stack */
     89        1.98      matt 	struct cpu_softc *ci_softc;	/* chip-dependent hook */
     90        1.98      matt 	device_t ci_dev;		/* owning device */
     91        1.85        ad 	cpuid_t ci_cpuid;		/* Machine-level identifier */
     92        1.98      matt 	u_long ci_cctr_freq;		/* cycle counter frequency */
     93        1.58    simonb 	u_long ci_cpu_freq;		/* CPU frequency */
     94        1.58    simonb 	u_long ci_cycles_per_hz;	/* CPU freq / hz */
     95        1.58    simonb 	u_long ci_divisor_delay;	/* for delay/DELAY */
     96        1.90   tsutsui 	u_long ci_divisor_recip;	/* unused, for obsolete microtime(9) */
     97        1.82      yamt 	struct lwp *ci_curlwp;		/* currently running lwp */
     98        1.98      matt 	volatile int ci_want_resched;	/* user preemption pending */
     99        1.78        ad 	int ci_mtx_count;		/* negative count of held mutexes */
    100        1.78        ad 	int ci_mtx_oldspl;		/* saved SPL value */
    101        1.86        ad 	int ci_idepth;			/* hardware interrupt depth */
    102        1.98      matt 	int ci_cpl;			/* current [interrupt] priority level */
    103        1.98      matt 	uint32_t ci_next_cp0_clk_intr;	/* for hard clock intr scheduling */
    104        1.98      matt 	struct evcnt ci_ev_count_compare;		/* hard clock intr counter */
    105        1.98      matt 	struct evcnt ci_ev_count_compare_missed;	/* hard clock miss counter */
    106        1.98      matt 	struct lwp *ci_softlwps[SOFTINT_COUNT];
    107        1.98      matt 	volatile u_int ci_softints;
    108        1.98      matt 	struct evcnt ci_ev_fpu_loads;	/* fpu load counter */
    109        1.98      matt 	struct evcnt ci_ev_fpu_saves;	/* fpu save counter */
    110       1.105      matt 	struct evcnt ci_ev_dsp_loads;	/* dsp load counter */
    111       1.105      matt 	struct evcnt ci_ev_dsp_saves;	/* dsp save counter */
    112        1.98      matt 	struct evcnt ci_ev_tlbmisses;
    113        1.98      matt 
    114        1.98      matt 	/*
    115        1.98      matt 	 * Per-cpu pmap information
    116        1.98      matt 	 */
    117        1.98      matt 	int ci_tlb_slot;		/* reserved tlb entry for cpu_info */
    118        1.98      matt 	u_int ci_pmap_asid_cur;		/* current ASID */
    119        1.98      matt 	struct pmap_tlb_info *ci_tlb_info; /* tlb information for this cpu */
    120  1.106.12.3  jdolecek 	union pmap_segtab *ci_pmap_segtabs[2];
    121  1.106.12.3  jdolecek #define ci_pmap_user_segtab	ci_pmap_segtabs[0]
    122  1.106.12.3  jdolecek #define ci_pmap_kern_segtab	ci_pmap_segtabs[1]
    123        1.98      matt #ifdef _LP64
    124  1.106.12.3  jdolecek 	union pmap_segtab *ci_pmap_seg0tabs[2];
    125  1.106.12.3  jdolecek #define ci_pmap_user_seg0tab	ci_pmap_seg0tabs[0]
    126  1.106.12.3  jdolecek #define ci_pmap_kern_seg0tab	ci_pmap_seg0tabs[1]
    127  1.106.12.3  jdolecek #endif
    128        1.98      matt 	vaddr_t ci_pmap_srcbase;	/* starting VA of ephemeral src space */
    129        1.98      matt 	vaddr_t ci_pmap_dstbase;	/* starting VA of ephemeral dst space */
    130        1.98      matt 
    131       1.101     cliff 	u_int ci_cpuwatch_count;	/* number of watchpoints on this CPU */
    132       1.101     cliff 	cpu_watchpoint_t ci_cpuwatch_tab[CPUWATCH_MAX];
    133        1.98      matt 
    134        1.98      matt #ifdef MULTIPROCESSOR
    135        1.98      matt 	volatile u_long ci_flags;
    136        1.98      matt 	volatile uint64_t ci_request_ipis;
    137        1.98      matt 					/* bitmask of IPIs requested */
    138        1.98      matt 					/*  use on chips where hw cannot pass tag */
    139        1.98      matt 	uint64_t ci_active_ipis;	/* bitmask of IPIs being serviced */
    140        1.98      matt 	uint32_t ci_ksp_tlb_slot;	/* tlb entry for kernel stack */
    141        1.98      matt 	struct evcnt ci_evcnt_all_ipis;	/* aggregated IPI counter */
    142        1.98      matt 	struct evcnt ci_evcnt_per_ipi[NIPIS];	/* individual IPI counters*/
    143        1.98      matt 	struct evcnt ci_evcnt_synci_activate_rqst;
    144        1.98      matt 	struct evcnt ci_evcnt_synci_onproc_rqst;
    145        1.98      matt 	struct evcnt ci_evcnt_synci_deferred_rqst;
    146        1.98      matt 	struct evcnt ci_evcnt_synci_ipi_rqst;
    147        1.98      matt 
    148        1.98      matt #define	CPUF_PRIMARY	0x01		/* CPU is primary CPU */
    149        1.98      matt #define	CPUF_PRESENT	0x02		/* CPU is present */
    150        1.98      matt #define	CPUF_RUNNING	0x04		/* CPU is running */
    151        1.98      matt #define	CPUF_PAUSED	0x08		/* CPU is paused */
    152        1.98      matt #define	CPUF_USERPMAP	0x20		/* CPU has a user pmap activated */
    153  1.106.12.3  jdolecek 	kcpuset_t *ci_multicastcpus;
    154  1.106.12.3  jdolecek 	kcpuset_t *ci_watchcpus;
    155  1.106.12.3  jdolecek 	kcpuset_t *ci_ddbcpus;
    156        1.98      matt #endif
    157        1.98      matt 
    158        1.53    simonb };
    159        1.68    simonb 
    160  1.106.12.3  jdolecek #ifdef MULTIPROCESSOR
    161  1.106.12.3  jdolecek #define	CPU_INFO_ITERATOR		int
    162        1.85        ad #define	CPU_INFO_FOREACH(cii, ci)	\
    163  1.106.12.3  jdolecek     cii = 0, ci = cpu_infos[0]; cii < ncpu && (ci = cpu_infos[cii]) != NULL; cii++
    164        1.77   tsutsui #else
    165  1.106.12.3  jdolecek #define	CPU_INFO_ITERATOR		int __unused
    166  1.106.12.3  jdolecek #define	CPU_INFO_FOREACH(cii, ci)	\
    167  1.106.12.3  jdolecek     ci = &cpu_info_store; ci != NULL; ci = NULL
    168        1.77   tsutsui #endif
    169        1.33    simonb 
    170        1.82      yamt /* Note: must be kept in sync with -ffixed-?? Makefile.mips. */
    171  1.106.12.3  jdolecek //	MIPS_CURLWP moved to <mips/regdef.h>
    172  1.106.12.3  jdolecek #define MIPS_CURLWP_QUOTED	"$24"
    173        1.98      matt #define MIPS_CURLWP_LABEL	_L_T8
    174        1.98      matt #define MIPS_CURLWP_REG		_R_T8
    175        1.82      yamt 
    176        1.77   tsutsui extern struct cpu_info cpu_info_store;
    177  1.106.12.3  jdolecek #ifdef MULTIPROCESSOR
    178  1.106.12.3  jdolecek extern struct cpu_info *cpuid_infos[];
    179  1.106.12.3  jdolecek #endif
    180        1.82      yamt register struct lwp *mips_curlwp asm(MIPS_CURLWP_QUOTED);
    181        1.77   tsutsui 
    182        1.82      yamt #define	curlwp			mips_curlwp
    183  1.106.12.3  jdolecek #define	curcpu()		lwp_getcpu(curlwp)
    184        1.92     rmind #define	curpcb			((struct pcb *)lwp_getpcb(curlwp))
    185        1.98      matt #ifdef MULTIPROCESSOR
    186        1.98      matt #define	cpu_number()		(curcpu()->ci_index)
    187        1.98      matt #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
    188        1.98      matt #else
    189        1.82      yamt #define	cpu_number()		(0)
    190        1.98      matt #define	CPU_IS_PRIMARY(ci)	(true)
    191        1.98      matt #endif
    192        1.77   tsutsui 
    193        1.21  jonathan /*
    194         1.1   deraadt  * definitions of cpu-dependent requirements
    195         1.1   deraadt  * referenced in generic code
    196         1.1   deraadt  */
    197        1.42     jeffs 
    198        1.98      matt /*
    199        1.98      matt  * Send an inter-processor interupt to each other CPU (excludes curcpu())
    200        1.98      matt  */
    201        1.98      matt void cpu_broadcast_ipi(int);
    202        1.98      matt 
    203        1.98      matt /*
    204  1.106.12.3  jdolecek  * Send an inter-processor interupt to CPUs in kcpuset (excludes curcpu())
    205        1.98      matt  */
    206  1.106.12.3  jdolecek void cpu_multicast_ipi(const kcpuset_t *, int);
    207        1.98      matt 
    208        1.98      matt /*
    209        1.98      matt  * Send an inter-processor interupt to another CPU.
    210        1.98      matt  */
    211        1.98      matt int cpu_send_ipi(struct cpu_info *, int);
    212        1.98      matt 
    213        1.98      matt /*
    214        1.98      matt  * cpu_intr(ppl, pc, status);  (most state needed by clockframe)
    215        1.98      matt  */
    216        1.98      matt void cpu_intr(int, vaddr_t, uint32_t);
    217         1.1   deraadt 
    218         1.1   deraadt /*
    219         1.1   deraadt  * Arguments to hardclock and gatherstats encapsulate the previous
    220         1.1   deraadt  * machine state in an opaque clockframe.
    221         1.1   deraadt  */
    222         1.5     glass struct clockframe {
    223        1.98      matt 	vaddr_t		pc;	/* program counter at time of interrupt */
    224        1.94      matt 	uint32_t	sr;	/* status register at time of interrupt */
    225        1.98      matt 	bool		intr;	/* interrupted a interrupt */
    226         1.5     glass };
    227         1.1   deraadt 
    228        1.14  jonathan /*
    229        1.79        ad  * A port must provde CLKF_USERMODE() for use in machine-independent code.
    230        1.79        ad  * These differ on r4000 and r3000 systems; provide them in the
    231        1.79        ad  * port-dependent file that includes this one, using the macros below.
    232        1.14  jonathan  */
    233  1.106.12.3  jdolecek uint32_t cpu_clkf_usermode_mask(void);
    234        1.14  jonathan 
    235  1.106.12.3  jdolecek #define	CLKF_USERMODE(framep)	((framep)->sr & cpu_clkf_usermode_mask())
    236  1.106.12.3  jdolecek #define	CLKF_PC(framep)		((framep)->pc + 0)
    237  1.106.12.3  jdolecek #define	CLKF_INTR(framep)	((framep)->intr + 0)
    238        1.18  jonathan 
    239        1.47   thorpej /*
    240        1.98      matt  * Misc prototypes and variable declarations.
    241        1.47   thorpej  */
    242        1.98      matt #define	LWP_PC(l)	cpu_lwp_pc(l)
    243        1.98      matt 
    244        1.98      matt struct proc;
    245        1.98      matt struct lwp;
    246        1.98      matt struct pcb;
    247        1.98      matt struct reg;
    248         1.1   deraadt 
    249         1.1   deraadt /*
    250         1.1   deraadt  * Preempt the current process if in interrupt from user mode,
    251         1.1   deraadt  * or after the current trap/syscall if in system mode.
    252         1.1   deraadt  */
    253        1.82      yamt void	cpu_need_resched(struct cpu_info *, int);
    254        1.98      matt /*
    255        1.98      matt  * Notify the current lwp (l) that it has a signal pending,
    256        1.98      matt  * process as soon as possible.
    257        1.98      matt  */
    258        1.98      matt void	cpu_signotify(struct lwp *);
    259         1.1   deraadt 
    260         1.1   deraadt /*
    261         1.1   deraadt  * Give a profiling tick to the current process when the user profiling
    262        1.13  jonathan  * buffer pages are invalid.  On the MIPS, request an ast to send us
    263         1.1   deraadt  * through trap, marking the proc as needing a profiling tick.
    264         1.1   deraadt  */
    265        1.98      matt void	cpu_need_proftick(struct lwp *);
    266        1.98      matt void	cpu_set_curpri(int);
    267         1.1   deraadt 
    268  1.106.12.3  jdolecek /* VM related hooks */
    269        1.98      matt void	cpu_boot_secondary_processors(void);
    270        1.98      matt void *	cpu_uarea_alloc(bool);
    271        1.98      matt bool	cpu_uarea_free(void *);
    272        1.98      matt void	cpu_proc_fork(struct proc *, struct proc *);
    273        1.98      matt vaddr_t	cpu_lwp_pc(struct lwp *);
    274  1.106.12.3  jdolecek #ifdef _LP64
    275  1.106.12.3  jdolecek void	cpu_vmspace_exec(struct lwp *, vaddr_t, vaddr_t);
    276  1.106.12.3  jdolecek #endif
    277        1.27   thorpej 
    278        1.28    castor #endif /* _KERNEL */
    279  1.106.12.3  jdolecek 
    280  1.106.12.3  jdolecek /*
    281  1.106.12.3  jdolecek  * CTL_MACHDEP definitions.
    282  1.106.12.3  jdolecek  */
    283  1.106.12.3  jdolecek #define CPU_CONSDEV		1	/* dev_t: console terminal device */
    284  1.106.12.3  jdolecek #define CPU_BOOTED_KERNEL	2	/* string: booted kernel name */
    285  1.106.12.3  jdolecek #define CPU_ROOT_DEVICE		3	/* string: root device name */
    286  1.106.12.3  jdolecek #define CPU_LLSC		4	/* OS/CPU supports LL/SC instruction */
    287  1.106.12.3  jdolecek #define CPU_LMMI		5	/* Loongson multimedia instructions */
    288  1.106.12.3  jdolecek 
    289  1.106.12.3  jdolecek /*
    290  1.106.12.3  jdolecek  * Platform can override, but note this breaks userland compatibility
    291  1.106.12.3  jdolecek  * with other mips platforms.
    292  1.106.12.3  jdolecek  */
    293  1.106.12.3  jdolecek #ifndef CPU_MAXID
    294  1.106.12.3  jdolecek #define CPU_MAXID		5	/* number of valid machdep ids */
    295  1.106.12.3  jdolecek #endif
    296  1.106.12.3  jdolecek 
    297         1.1   deraadt #endif /* _CPU_H_ */
    298