1 /* $NetBSD: cpu.h,v 1.104 2019/12/01 15:34:46 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 struct lwp *ci_onproc; /* current user LWP / kthread */ 137 #if defined(MULTIPROCESSOR) 138 struct lwp *ci_curlwp; /* current lwp (for other cpus) */ 139 volatile int ci_flags; /* See below */ 140 long ci_ipimsgs; /* Sent IPI bits */ 141 struct trapframe *ci_ddb_regs; /* Used by DDB */ 142 SIMPLEQ_ENTRY(cpu_info) ci_next; /* next cpu_info */ 143 #endif 144 uintptr_t ci_cas_addr; /* current address doing CAS in a RAS */ 145 }; 146 #define CI_MASTERCPU 1 /* Set if master CPU */ 147 #define CI_RUNNING 2 /* Set when a slave CPU is running */ 148 #define CI_STOPPED 4 /* Stopped (in debugger) */ 149 150 extern int cpu_printfataltraps; 151 152 #define curcpu() (curlwp->l_cpu + 0) 153 #define curlwp ((struct lwp *)mfpr(PR_SSP)) 154 #define cpu_number() (curcpu()->ci_cpuid) 155 #define cpu_need_resched(ci, l, flags) \ 156 do { \ 157 __USE(flags); \ 158 mtpr(AST_OK,PR_ASTLVL); \ 159 } while (/*CONSTCOND*/ 0) 160 #define cpu_proc_fork(x, y) do { } while (/*CONSCOND*/0) 161 162 /* 163 * This allows SIMH to recognize the kernel wants to sleep. 164 */ 165 static inline void 166 cpu_idle(void) 167 { 168 int ipl = mfpr(PR_IPL); 169 mtpr(1, PR_IPL); 170 mtpr(ipl, PR_IPL); 171 } 172 173 static inline bool 174 cpu_intr_p(void) 175 { 176 register_t psl; 177 __asm("movpsl %0" : "=g"(psl)); 178 return (psl & PSL_IS) != 0; 179 } 180 #if defined(MULTIPROCESSOR) 181 #define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CI_MASTERCPU) 182 183 #define CPU_INFO_ITERATOR int __unused 184 #define CPU_INFO_FOREACH(cii, ci) ci = SIMPLEQ_FIRST(&cpus); \ 185 ci != NULL; \ 186 ci = SIMPLEQ_NEXT(ci, ci_next) 187 188 extern SIMPLEQ_HEAD(cpu_info_qh, cpu_info) cpus; 189 extern char vax_mp_tramp; 190 #endif 191 192 /* 193 * Notify the current process (p) that it has a signal pending, 194 * process as soon as possible. 195 */ 196 197 #define cpu_signotify(l) mtpr(AST_OK,PR_ASTLVL) 198 199 200 /* 201 * Give a profiling tick to the current process when the user profiling 202 * buffer pages are invalid. On the hp300, request an ast to send us 203 * through trap, marking the proc as needing a profiling tick. 204 */ 205 #define cpu_need_proftick(l) do { (l)->l_pflag |= LP_OWEUPC; mtpr(AST_OK,PR_ASTLVL); } while (/*CONSTCOND*/ 0) 206 207 /* 208 * This defines the I/O device register space size in pages. 209 */ 210 #define IOSPSZ ((64*1024) / VAX_NBPG) /* 64k == 128 pages */ 211 212 #define LWP_PC(l) cpu_lwp_pc(l) 213 214 struct buf; 215 struct pte; 216 217 #include <sys/lwp.h> 218 219 /* Some low-level prototypes */ 220 #if defined(MULTIPROCESSOR) 221 void cpu_slavesetup(device_t, int); 222 void cpu_boot_secondary_processors(void); 223 void cpu_send_ipi(int, int); 224 void cpu_handle_ipi(void); 225 #endif 226 vaddr_t cpu_lwp_pc(struct lwp *); 227 int badaddr(volatile void *, int); 228 void dumpsys(void); 229 void swapconf(void); 230 void disk_printtype(int, int); 231 void disk_reallymapin(struct buf *, struct pte *, int, int); 232 vaddr_t vax_map_physmem(paddr_t, size_t); 233 void vax_unmap_physmem(vaddr_t, size_t); 234 void ioaccess(vaddr_t, paddr_t, size_t); 235 void iounaccess(vaddr_t, size_t); 236 void findcpu(void); 237 #ifdef DDB 238 int kdbrint(int); 239 #endif 240 #endif /* _KERNEL */ 241 #ifdef _STANDALONE 242 void findcpu(void); 243 #endif 244 #endif /* _VAX_CPU_H_ */ 245