1 /*      $NetBSD: cpu.h,v 1.108 2023/12/19 00:29:48 kalvisd 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_gprof.h"
33 #include "opt_multiprocessor.h"
34 #include "opt_lockdebug.h"
35 #endif
36 
37 #define   CPU_PRINTFATALTRAPS 1
38 #define   CPU_CONSDEV                   2
39 #define   CPU_BOOTED_DEVICE   3
40 #define   CPU_BOOTED_KERNEL   4
41 
42 #ifdef _KERNEL
43 
44 #include <sys/cdefs.h>
45 #include <sys/queue.h>
46 #include <sys/device_if.h>
47 #include <sys/cpu_data.h>
48 
49 #include <machine/mtpr.h>
50 #include <machine/pcb.h>
51 #include <machine/uvax.h>
52 #include <machine/psl.h>
53 
54 #define enablertclock()
55 
56 /*
57  * All cpu-dependent info is kept in this struct. Pointer to the
58  * struct for the current cpu is set up in locore.c.
59  */
60 struct cpu_info;
61 
62 struct cpu_dep {
63           void      (*cpu_steal_pages)(void); /* pmap init before mm is on */
64           int       (*cpu_mchk)(void *);   /* Machine check handling */
65           void      (*cpu_memerr)(void); /* Memory subsystem errors */
66               /* Autoconfiguration */
67           void      (*cpu_conf)(void);
68           int       (*cpu_gettime)(struct timeval *); /* Read cpu clock time */
69           void      (*cpu_settime)(struct timeval *); /* Write system time to cpu */
70           short     cpu_vups;           /* speed of cpu */
71           short     cpu_scbsz;                    /* (estimated) size of SCB */
72           void      (*cpu_halt)(void);  /* Cpu dependent halt call */
73           void      (*cpu_reboot)(int); /* Cpu dependent reboot call */
74           void      (*cpu_clrf)(void);  /* Clear cold/warm start flags */
75           const char * const *cpu_devs; /* mainbus devices */
76           void      (*cpu_attach_cpu)(device_t);  /* print CPU info */
77           int     cpu_flags;
78           void      (*cpu_badaddr)(void);         /* cpu-specific badaddr() */
79 };
80 
81 #if defined(MULTIPROCESSOR)
82 /*
83  * All cpu-dependent calls for multicpu systems goes here.
84  */
85 struct cpu_mp_dep {
86           void      (*cpu_startslave)(struct cpu_info *);
87           void      (*cpu_send_ipi)(struct cpu_info *);
88           void      (*cpu_cnintr)(void);
89 };
90 /*
91  * NOTE: This is not bit mask, this is bit _number_.
92  */
93 #define   IPI_START_CNTX      1         /* Start console transmitter, proc out */
94 #define   IPI_SEND_CNCHAR     2         /* Write char to console, kernel printf */
95 #define   IPI_RUNNING         3         /* This CPU just started to run */
96 #define   IPI_TBIA  4         /* Flush the TLB */
97 #define   IPI_DDB             5         /* Jump into the DDB loop */
98 #define   IPI_XCALL 6         /* Helper for xcall(9) */
99 #define   IPI_GENERIC         7         /* Generic ipi(9) call */
100 
101 #define   IPI_DEST_MASTER     -1        /* Destination is mastercpu */
102 #define   IPI_DEST_ALL        -2        /* Broadcast */
103 
104 extern const struct cpu_mp_dep *mp_dep_call;
105 #endif /* defined(MULTIPROCESSOR) */
106 
107 #define   CPU_RAISEIPL        1         /* Must raise IPL until intr is handled */
108 
109 extern const struct cpu_dep *dep_call;
110                                         /* Holds pointer to current CPU struct. */
111 
112 struct clockframe {
113         int     pc;
114         int     ps;
115 };
116 
117 struct cpu_info {
118           /*
119            * Public members.
120            */
121           struct cpu_data ci_data;      /* MI per-cpu data */
122           device_t ci_dev;              /* device struct for this cpu */
123           int ci_mtx_oldspl;            /* saved spl */
124           int ci_mtx_count;             /* negative count of mutexes */
125           int ci_cpuid;                           /* h/w specific cpu id */
126           int ci_want_resched;                    /* Should change process */
127 
128           /*
129            * Private members.
130            */
131 #if defined(__HAVE_FAST_SOFTINTS)
132           lwp_t *ci_softlwps[SOFTINT_COUNT];
133 #endif
134           vaddr_t ci_istack;            /* Interrupt stack location */
135           const char *ci_cpustr;
136           int ci_slotid;                          /* cpu slot */
137           struct lwp *ci_onproc;                  /* current user LWP / kthread */
138 #if defined(MULTIPROCESSOR)
139           struct lwp *ci_curlwp;                  /* current lwp (for other cpus) */
140           volatile int ci_flags;                  /* See below */
141           long ci_ipimsgs;              /* Sent IPI bits */
142           struct trapframe *ci_ddb_regs;          /* Used by DDB */
143           SIMPLEQ_ENTRY(cpu_info) ci_next; /* next cpu_info */
144 #endif
145           uintptr_t ci_cas_addr;                  /* current address doing CAS in a RAS */
146 #if defined(GPROF) && defined(MULTIPROCESSOR)
147           struct gmonparam *ci_gmon;    /* MI per-cpu GPROF */
148 #endif
149 };
150 #define   CI_MASTERCPU        1                   /* Set if master CPU */
151 #define   CI_RUNNING          2                   /* Set when a slave CPU is running */
152 #define   CI_STOPPED          4                   /* Stopped (in debugger) */
153 
154 extern int cpu_printfataltraps;
155 
156 #define   curcpu()            (curlwp->l_cpu + 0)
157 #define   curlwp                        ((struct lwp *)mfpr(PR_SSP))
158 #define   cpu_number()                  (curcpu()->ci_cpuid)
159 #define   cpu_need_resched(ci, l, flags)                    \
160           do {                                                                  \
161                     struct pcb *pcb = lwp_getpcb(curlwp);             \
162                     __USE(flags);                                               \
163                     pcb->P0LR = (pcb->P0LR & ~AST_MASK) | AST_ON;     \
164                     mtpr(AST_OK,PR_ASTLVL);                                     \
165           } while (/*CONSTCOND*/ 0)
166 #define   cpu_proc_fork(x, y) do { } while (/*CONSCOND*/0)
167 
168 /*
169  * This allows SIMH to recognize the kernel wants to sleep.
170  */
171 static inline void
cpu_idle(void)172 cpu_idle(void)
173 {
174           int ipl = mfpr(PR_IPL);
175           mtpr(1, PR_IPL);
176           mtpr(ipl, PR_IPL);
177 }
178 
179 static inline bool
cpu_intr_p(void)180 cpu_intr_p(void)
181 {
182           register_t psl;
183           __asm("movpsl %0" : "=g"(psl));
184           return (psl & PSL_IS) != 0;
185 }
186 #if defined(MULTIPROCESSOR)
187 #define   CPU_IS_PRIMARY(ci)  ((ci)->ci_flags & CI_MASTERCPU)
188 
189 #define   CPU_INFO_ITERATOR   int __unused
190 #define   CPU_INFO_FOREACH(cii, ci)     ci = SIMPLEQ_FIRST(&cpus); \
191                                                   ci != NULL; \
192                                                   ci = SIMPLEQ_NEXT(ci, ci_next)
193 
194 extern SIMPLEQ_HEAD(cpu_info_qh, cpu_info) cpus;
195 extern char vax_mp_tramp;
196 #endif
197 
198 /*
199  * Notify the current process (p) that it has a signal pending,
200  * process as soon as possible.
201  */
202 
203 #define cpu_signotify(l)                                              \
204           do {                                                                  \
205                     struct pcb *pcb = lwp_getpcb(l);                  \
206                     pcb->P0LR = (pcb->P0LR & ~AST_MASK) | AST_ON;     \
207                     mtpr(AST_OK,PR_ASTLVL);                                     \
208           } while (/*CONSTCOND*/ 0)
209 
210 
211 /*
212  * Give a profiling tick to the current process when the user profiling
213  * buffer pages are invalid.  On the hp300, request an ast to send us
214  * through trap, marking the proc as needing a profiling tick.
215  */
216 #define cpu_need_proftick(l)                                          \
217           do {                                                                  \
218                     struct pcb *pcb = lwp_getpcb(l);                  \
219                     (l)->l_pflag |= LP_OWEUPC;                        \
220                     pcb->P0LR = (pcb->P0LR & ~AST_MASK) | AST_ON;     \
221                     mtpr(AST_OK,PR_ASTLVL);                                     \
222           } while (/*CONSTCOND*/ 0)
223 
224 /*
225  * This defines the I/O device register space size in pages.
226  */
227 #define   IOSPSZ    ((64*1024) / VAX_NBPG)        /* 64k == 128 pages */
228 
229 #define   LWP_PC(l) cpu_lwp_pc(l)
230 
231 struct buf;
232 struct pte;
233 
234 #include <sys/lwp.h>
235 
236 /* Some low-level prototypes */
237 #if defined(MULTIPROCESSOR)
238 void      cpu_slavesetup(device_t, int);
239 void      cpu_boot_secondary_processors(void);
240 void      cpu_send_ipi(int, int);
241 void      cpu_handle_ipi(void);
242 #endif
243 vaddr_t   cpu_lwp_pc(struct lwp *);
244 int       badaddr(volatile void *, int);
245 void      dumpsys(void);
246 void      swapconf(void);
247 void      disk_printtype(int, int);
248 void      disk_reallymapin(struct buf *, struct pte *, int, int);
249 vaddr_t   vax_map_physmem(paddr_t, size_t);
250 void      vax_unmap_physmem(vaddr_t, size_t);
251 void      ioaccess(vaddr_t, paddr_t, size_t);
252 void      iounaccess(vaddr_t, size_t);
253 void      findcpu(void);
254 #ifdef DDB
255 int       kdbrint(int);
256 #endif
257 #endif /* _KERNEL */
258 #ifdef _STANDALONE
259 void      findcpu(void);
260 #endif
261 #endif /* _VAX_CPU_H_ */
262