Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.103
      1 /*      $NetBSD: cpu.h,v 1.103 2019/11/23 19:40:37 ad Exp $      */
      2 
      3 /*
      4  * Copyright (c) 1994 Ludd, University of Lule}, Sweden
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef _VAX_CPU_H_
     29 #define _VAX_CPU_H_
     30 
     31 #if defined(_KERNEL_OPT)
     32 #include "opt_multiprocessor.h"
     33 #include "opt_lockdebug.h"
     34 #endif
     35 
     36 #define	CPU_PRINTFATALTRAPS	1
     37 #define	CPU_CONSDEV		2
     38 #define	CPU_BOOTED_DEVICE	3
     39 #define	CPU_BOOTED_KERNEL	4
     40 
     41 #ifdef _KERNEL
     42 
     43 #include <sys/cdefs.h>
     44 #include <sys/queue.h>
     45 #include <sys/device_if.h>
     46 #include <sys/cpu_data.h>
     47 
     48 #include <machine/mtpr.h>
     49 #include <machine/pcb.h>
     50 #include <machine/uvax.h>
     51 #include <machine/psl.h>
     52 
     53 #define enablertclock()
     54 
     55 /*
     56  * All cpu-dependent info is kept in this struct. Pointer to the
     57  * struct for the current cpu is set up in locore.c.
     58  */
     59 struct cpu_info;
     60 
     61 struct cpu_dep {
     62 	void	(*cpu_steal_pages)(void); /* pmap init before mm is on */
     63 	int	(*cpu_mchk)(void *);   /* Machine check handling */
     64 	void	(*cpu_memerr)(void); /* Memory subsystem errors */
     65 	    /* Autoconfiguration */
     66 	void	(*cpu_conf)(void);
     67 	int	(*cpu_gettime)(struct timeval *); /* Read cpu clock time */
     68 	void	(*cpu_settime)(struct timeval *); /* Write system time to cpu */
     69 	short	cpu_vups;		/* speed of cpu */
     70 	short	cpu_scbsz;		/* (estimated) size of SCB */
     71 	void	(*cpu_halt)(void);	/* Cpu dependent halt call */
     72 	void	(*cpu_reboot)(int);	/* Cpu dependent reboot call */
     73 	void	(*cpu_clrf)(void);	/* Clear cold/warm start flags */
     74 	const char * const *cpu_devs;	/* mainbus devices */
     75 	void	(*cpu_attach_cpu)(device_t);	/* print CPU info */
     76 	int     cpu_flags;
     77 	void	(*cpu_badaddr)(void);	/* cpu-specific badaddr() */
     78 };
     79 
     80 #if defined(MULTIPROCESSOR)
     81 /*
     82  * All cpu-dependent calls for multicpu systems goes here.
     83  */
     84 struct cpu_mp_dep {
     85 	void	(*cpu_startslave)(struct cpu_info *);
     86 	void	(*cpu_send_ipi)(struct cpu_info *);
     87 	void	(*cpu_cnintr)(void);
     88 };
     89 /*
     90  * NOTE: This is not bit mask, this is bit _number_.
     91  */
     92 #define	IPI_START_CNTX	1	/* Start console transmitter, proc out */
     93 #define	IPI_SEND_CNCHAR	2	/* Write char to console, kernel printf */
     94 #define	IPI_RUNNING	3	/* This CPU just started to run */
     95 #define	IPI_TBIA	4	/* Flush the TLB */
     96 #define	IPI_DDB		5	/* Jump into the DDB loop */
     97 #define	IPI_XCALL	6	/* Helper for xcall(9) */
     98 #define	IPI_GENERIC	7	/* Generic ipi(9) call */
     99 
    100 #define	IPI_DEST_MASTER	-1	/* Destination is mastercpu */
    101 #define	IPI_DEST_ALL	-2	/* Broadcast */
    102 
    103 extern const struct cpu_mp_dep *mp_dep_call;
    104 #endif /* defined(MULTIPROCESSOR) */
    105 
    106 #define	CPU_RAISEIPL	1	/* Must raise IPL until intr is handled */
    107 
    108 extern const struct cpu_dep *dep_call;
    109 				/* Holds pointer to current CPU struct. */
    110 
    111 struct clockframe {
    112         int     pc;
    113         int     ps;
    114 };
    115 
    116 struct cpu_info {
    117 	/*
    118 	 * Public members.
    119 	 */
    120 	struct cpu_data ci_data;	/* MI per-cpu data */
    121 	device_t ci_dev;		/* device struct for this cpu */
    122 	int ci_mtx_oldspl;		/* saved spl */
    123 	int ci_mtx_count;		/* negative count of mutexes */
    124 	int ci_cpuid;			/* h/w specific cpu id */
    125 	int ci_want_resched;		/* Should change process */
    126 
    127 	/*
    128 	 * Private members.
    129 	 */
    130 #if defined(__HAVE_FAST_SOFTINTS)
    131 	lwp_t *ci_softlwps[SOFTINT_COUNT];
    132 #endif
    133 	vaddr_t ci_istack;		/* Interrupt stack location */
    134 	const char *ci_cpustr;
    135 	int ci_slotid;			/* cpu slot */
    136 #if defined(MULTIPROCESSOR)
    137 	struct lwp *ci_curlwp;		/* current lwp (for other cpus) */
    138 	volatile int ci_flags;		/* See below */
    139 	long ci_ipimsgs;		/* Sent IPI bits */
    140 	struct trapframe *ci_ddb_regs;	/* Used by DDB */
    141 	SIMPLEQ_ENTRY(cpu_info) ci_next; /* next cpu_info */
    142 #endif
    143 	uintptr_t ci_cas_addr;		/* current address doing CAS in a RAS */
    144 };
    145 #define	CI_MASTERCPU	1		/* Set if master CPU */
    146 #define	CI_RUNNING	2		/* Set when a slave CPU is running */
    147 #define	CI_STOPPED	4		/* Stopped (in debugger) */
    148 
    149 extern int cpu_printfataltraps;
    150 
    151 #define	curcpu()		(curlwp->l_cpu + 0)
    152 #define	curlwp			((struct lwp *)mfpr(PR_SSP))
    153 #define	cpu_number()		(curcpu()->ci_cpuid)
    154 #define	cpu_need_resched(ci, l, flags)		\
    155 	do {					\
    156 		__USE(flags);			\
    157 		mtpr(AST_OK,PR_ASTLVL);		\
    158 	} while (/*CONSTCOND*/ 0)
    159 #define	cpu_proc_fork(x, y)	do { } while (/*CONSCOND*/0)
    160 
    161 /*
    162  * This allows SIMH to recognize the kernel wants to sleep.
    163  */
    164 static inline void
    165 cpu_idle(void)
    166 {
    167 	int ipl = mfpr(PR_IPL);
    168 	mtpr(1, PR_IPL);
    169 	mtpr(ipl, PR_IPL);
    170 }
    171 
    172 static inline bool
    173 cpu_intr_p(void)
    174 {
    175 	register_t psl;
    176 	__asm("movpsl %0" : "=g"(psl));
    177 	return (psl & PSL_IS) != 0;
    178 }
    179 #if defined(MULTIPROCESSOR)
    180 #define	CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CI_MASTERCPU)
    181 
    182 #define	CPU_INFO_ITERATOR	int __unused
    183 #define	CPU_INFO_FOREACH(cii, ci)	ci = SIMPLEQ_FIRST(&cpus); \
    184 					ci != NULL; \
    185 					ci = SIMPLEQ_NEXT(ci, ci_next)
    186 
    187 extern SIMPLEQ_HEAD(cpu_info_qh, cpu_info) cpus;
    188 extern char vax_mp_tramp;
    189 #endif
    190 
    191 /*
    192  * Notify the current process (p) that it has a signal pending,
    193  * process as soon as possible.
    194  */
    195 
    196 #define cpu_signotify(l)     mtpr(AST_OK,PR_ASTLVL)
    197 
    198 
    199 /*
    200  * Give a profiling tick to the current process when the user profiling
    201  * buffer pages are invalid.  On the hp300, request an ast to send us
    202  * through trap, marking the proc as needing a profiling tick.
    203  */
    204 #define cpu_need_proftick(l) do { (l)->l_pflag |= LP_OWEUPC; mtpr(AST_OK,PR_ASTLVL); } while (/*CONSTCOND*/ 0)
    205 
    206 /*
    207  * This defines the I/O device register space size in pages.
    208  */
    209 #define	IOSPSZ	((64*1024) / VAX_NBPG)	/* 64k == 128 pages */
    210 
    211 #define	LWP_PC(l)	cpu_lwp_pc(l)
    212 
    213 struct buf;
    214 struct pte;
    215 
    216 #include <sys/lwp.h>
    217 
    218 /* Some low-level prototypes */
    219 #if defined(MULTIPROCESSOR)
    220 void	cpu_slavesetup(device_t, int);
    221 void	cpu_boot_secondary_processors(void);
    222 void	cpu_send_ipi(int, int);
    223 void	cpu_handle_ipi(void);
    224 #endif
    225 vaddr_t	cpu_lwp_pc(struct lwp *);
    226 int	badaddr(volatile void *, int);
    227 void	dumpsys(void);
    228 void	swapconf(void);
    229 void	disk_printtype(int, int);
    230 void	disk_reallymapin(struct buf *, struct pte *, int, int);
    231 vaddr_t	vax_map_physmem(paddr_t, size_t);
    232 void	vax_unmap_physmem(vaddr_t, size_t);
    233 void	ioaccess(vaddr_t, paddr_t, size_t);
    234 void	iounaccess(vaddr_t, size_t);
    235 void	findcpu(void);
    236 #ifdef DDB
    237 int	kdbrint(int);
    238 #endif
    239 #endif /* _KERNEL */
    240 #ifdef _STANDALONE
    241 void	findcpu(void);
    242 #endif
    243 #endif /* _VAX_CPU_H_ */
    244