cpu.h revision 1.59 1 1.59 garbled /* $NetBSD: cpu.h,v 1.59 2007/10/17 19:56:40 garbled Exp $ */
2 1.1 ws
3 1.1 ws /*
4 1.5 ws * Copyright (C) 1999 Wolfgang Solfrank.
5 1.5 ws * Copyright (C) 1999 TooLs GmbH.
6 1.9 matt * Copyright (C) 1995-1997 Wolfgang Solfrank.
7 1.9 matt * Copyright (C) 1995-1997 TooLs GmbH.
8 1.1 ws * All rights reserved.
9 1.1 ws *
10 1.1 ws * Redistribution and use in source and binary forms, with or without
11 1.1 ws * modification, are permitted provided that the following conditions
12 1.1 ws * are met:
13 1.1 ws * 1. Redistributions of source code must retain the above copyright
14 1.1 ws * notice, this list of conditions and the following disclaimer.
15 1.1 ws * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ws * notice, this list of conditions and the following disclaimer in the
17 1.1 ws * documentation and/or other materials provided with the distribution.
18 1.1 ws * 3. All advertising materials mentioning features or use of this software
19 1.1 ws * must display the following acknowledgement:
20 1.1 ws * This product includes software developed by TooLs GmbH.
21 1.1 ws * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 1.1 ws * derived from this software without specific prior written permission.
23 1.1 ws *
24 1.1 ws * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 1.1 ws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.1 ws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.1 ws * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 1.1 ws * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 1.1 ws * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 1.1 ws * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 1.1 ws * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 1.1 ws * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 1.1 ws * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 ws */
35 1.5 ws #ifndef _POWERPC_CPU_H_
36 1.5 ws #define _POWERPC_CPU_H_
37 1.1 ws
38 1.27 matt struct cache_info {
39 1.27 matt int dcache_size;
40 1.27 matt int dcache_line_size;
41 1.27 matt int icache_size;
42 1.27 matt int icache_line_size;
43 1.27 matt };
44 1.27 matt
45 1.27 matt #ifdef _KERNEL
46 1.9 matt #if defined(_KERNEL_OPT)
47 1.9 matt #include "opt_lockdebug.h"
48 1.9 matt #include "opt_multiprocessor.h"
49 1.16 matt #include "opt_ppcarch.h"
50 1.9 matt #endif
51 1.9 matt
52 1.9 matt #include <machine/frame.h>
53 1.9 matt #include <machine/psl.h>
54 1.9 matt #include <machine/intr.h>
55 1.20 matt #include <sys/device.h>
56 1.9 matt
57 1.42 yamt #include <sys/cpu_data.h>
58 1.14 eeh
59 1.9 matt struct cpu_info {
60 1.42 yamt struct cpu_data ci_data; /* MI per-cpu data */
61 1.9 matt struct device *ci_dev; /* device of corresponding cpu */
62 1.23 thorpej struct lwp *ci_curlwp; /* current owner of the processor */
63 1.9 matt
64 1.9 matt struct pcb *ci_curpcb;
65 1.38 matt struct pmap *ci_curpm;
66 1.23 thorpej struct lwp *ci_fpulwp;
67 1.23 thorpej struct lwp *ci_veclwp;
68 1.9 matt int ci_cpuid;
69 1.9 matt
70 1.28 matt volatile int ci_astpending;
71 1.57 rjs int ci_want_resched;
72 1.28 matt volatile u_long ci_lasttb;
73 1.28 matt volatile int ci_tickspending;
74 1.50 freza volatile int ci_cpl;
75 1.50 freza volatile int ci_iactive;
76 1.50 freza volatile int ci_ipending;
77 1.9 matt int ci_intrdepth;
78 1.53 ad int ci_mtx_oldspl;
79 1.53 ad int ci_mtx_count;
80 1.9 matt char *ci_intstk;
81 1.32 matt #define CPUSAVE_LEN 8
82 1.32 matt register_t ci_tempsave[CPUSAVE_LEN];
83 1.32 matt register_t ci_ddbsave[CPUSAVE_LEN];
84 1.32 matt register_t ci_ipkdbsave[CPUSAVE_LEN];
85 1.32 matt #define CPUSAVE_R28 0 /* where r28 gets saved */
86 1.32 matt #define CPUSAVE_R29 1 /* where r29 gets saved */
87 1.32 matt #define CPUSAVE_R30 2 /* where r30 gets saved */
88 1.32 matt #define CPUSAVE_R31 3 /* where r31 gets saved */
89 1.32 matt #define CPUSAVE_DAR 4 /* where SPR_DAR gets saved */
90 1.32 matt #define CPUSAVE_DSISR 5 /* where SPR_DSISR gets saved */
91 1.32 matt #define CPUSAVE_SRR0 6 /* where SRR0 gets saved */
92 1.32 matt #define CPUSAVE_SRR1 7 /* where SRR1 gets saved */
93 1.32 matt #define DISISAVE_LEN 4
94 1.32 matt register_t ci_disisave[DISISAVE_LEN];
95 1.14 eeh struct cache_info ci_ci;
96 1.40 matt void *ci_sysmon_cookie;
97 1.43 matt void (*ci_idlespin)(void);
98 1.44 briggs uint32_t ci_khz;
99 1.25 matt struct evcnt ci_ev_clock; /* clock intrs */
100 1.50 freza struct evcnt ci_ev_statclock; /* stat clock */
101 1.25 matt struct evcnt ci_ev_softclock; /* softclock intrs */
102 1.25 matt struct evcnt ci_ev_softnet; /* softnet intrs */
103 1.25 matt struct evcnt ci_ev_softserial; /* softserial intrs */
104 1.9 matt struct evcnt ci_ev_traps; /* calls to trap() */
105 1.9 matt struct evcnt ci_ev_kdsi; /* kernel DSI traps */
106 1.9 matt struct evcnt ci_ev_udsi; /* user DSI traps */
107 1.9 matt struct evcnt ci_ev_udsi_fatal; /* user DSI trap failures */
108 1.33 matt struct evcnt ci_ev_kisi; /* kernel ISI traps */
109 1.9 matt struct evcnt ci_ev_isi; /* user ISI traps */
110 1.9 matt struct evcnt ci_ev_isi_fatal; /* user ISI trap failures */
111 1.9 matt struct evcnt ci_ev_pgm; /* user PGM traps */
112 1.9 matt struct evcnt ci_ev_fpu; /* FPU traps */
113 1.9 matt struct evcnt ci_ev_fpusw; /* FPU context switch */
114 1.9 matt struct evcnt ci_ev_ali; /* Alignment traps */
115 1.9 matt struct evcnt ci_ev_ali_fatal; /* Alignment fatal trap */
116 1.9 matt struct evcnt ci_ev_scalls; /* system call traps */
117 1.9 matt struct evcnt ci_ev_vec; /* Altivec traps */
118 1.9 matt struct evcnt ci_ev_vecsw; /* Altivec context switches */
119 1.16 matt struct evcnt ci_ev_umchk; /* user MCHK events */
120 1.59 garbled struct evcnt ci_ev_ipi; /* IPIs received */
121 1.9 matt };
122 1.9 matt
123 1.9 matt #ifdef MULTIPROCESSOR
124 1.59 garbled
125 1.59 garbled struct cpu_hatch_data {
126 1.59 garbled struct device *self;
127 1.59 garbled struct cpu_info *ci;
128 1.59 garbled int running;
129 1.59 garbled int pir;
130 1.59 garbled int hid0;
131 1.59 garbled int sdr1;
132 1.59 garbled int sr[16];
133 1.59 garbled int batu[4], batl[4];
134 1.59 garbled int tbu, tbl;
135 1.59 garbled };
136 1.59 garbled
137 1.47 perry static __inline int
138 1.11 chs cpu_number(void)
139 1.9 matt {
140 1.9 matt int pir;
141 1.9 matt
142 1.30 matt __asm ("mfspr %0,1023" : "=r"(pir));
143 1.9 matt return pir;
144 1.9 matt }
145 1.9 matt
146 1.11 chs void cpu_boot_secondary_processors(void);
147 1.9 matt
148 1.9 matt
149 1.9 matt #define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0)
150 1.18 chs #define CPU_INFO_ITERATOR int
151 1.18 chs #define CPU_INFO_FOREACH(cii, ci) \
152 1.18 chs cii = 0, ci = &cpu_info[0]; cii < CPU_MAXNUM; cii++, ci++
153 1.18 chs
154 1.9 matt #else
155 1.9 matt
156 1.9 matt #define cpu_number() 0
157 1.9 matt
158 1.18 chs #define CPU_INFO_ITERATOR int
159 1.18 chs #define CPU_INFO_FOREACH(cii, ci) \
160 1.18 chs cii = 0, ci = curcpu(); ci != NULL; ci = NULL
161 1.18 chs
162 1.9 matt #endif /* MULTIPROCESSOR */
163 1.9 matt
164 1.25 matt extern struct cpu_info cpu_info[];
165 1.25 matt
166 1.47 perry static __inline struct cpu_info *
167 1.25 matt curcpu(void)
168 1.25 matt {
169 1.25 matt struct cpu_info *ci;
170 1.25 matt
171 1.46 perry __asm volatile ("mfsprg %0,0" : "=r"(ci));
172 1.25 matt return ci;
173 1.25 matt }
174 1.25 matt
175 1.25 matt #define curlwp (curcpu()->ci_curlwp)
176 1.25 matt #define curpcb (curcpu()->ci_curpcb)
177 1.38 matt #define curpm (curcpu()->ci_curpm)
178 1.25 matt
179 1.47 perry static __inline register_t
180 1.18 chs mfmsr(void)
181 1.18 chs {
182 1.20 matt register_t msr;
183 1.18 chs
184 1.46 perry __asm volatile ("mfmsr %0" : "=r"(msr));
185 1.18 chs return msr;
186 1.18 chs }
187 1.18 chs
188 1.47 perry static __inline void
189 1.20 matt mtmsr(register_t msr)
190 1.18 chs {
191 1.18 chs
192 1.46 perry __asm volatile ("mtmsr %0" : : "r"(msr));
193 1.19 chs }
194 1.19 chs
195 1.47 perry static __inline uint32_t
196 1.19 chs mftbl(void)
197 1.19 chs {
198 1.19 chs uint32_t tbl;
199 1.19 chs
200 1.46 perry __asm volatile (
201 1.29 hannken #ifdef PPC_IBM403
202 1.29 hannken " mftblo %0 \n"
203 1.29 hannken #else
204 1.29 hannken " mftbl %0 \n"
205 1.29 hannken #endif
206 1.29 hannken : "=r" (tbl));
207 1.29 hannken
208 1.19 chs return tbl;
209 1.19 chs }
210 1.19 chs
211 1.47 perry static __inline uint64_t
212 1.19 chs mftb(void)
213 1.19 chs {
214 1.19 chs uint64_t tb;
215 1.32 matt
216 1.32 matt #ifdef _LP64
217 1.46 perry __asm volatile ("mftb %0" : "=r"(tb));
218 1.32 matt #else
219 1.19 chs int tmp;
220 1.19 chs
221 1.46 perry __asm volatile (
222 1.29 hannken #ifdef PPC_IBM403
223 1.29 hannken "1: mftbhi %0 \n"
224 1.29 hannken " mftblo %0+1 \n"
225 1.29 hannken " mftbhi %1 \n"
226 1.29 hannken #else
227 1.22 thorpej "1: mftbu %0 \n"
228 1.22 thorpej " mftb %0+1 \n"
229 1.22 thorpej " mftbu %1 \n"
230 1.29 hannken #endif
231 1.22 thorpej " cmplw %0,%1 \n"
232 1.29 hannken " bne- 1b \n"
233 1.29 hannken : "=r" (tb), "=r"(tmp) :: "cr0");
234 1.32 matt #endif
235 1.29 hannken
236 1.19 chs return tb;
237 1.24 kleink }
238 1.24 kleink
239 1.47 perry static __inline uint32_t
240 1.24 kleink mfrtcl(void)
241 1.24 kleink {
242 1.24 kleink uint32_t rtcl;
243 1.24 kleink
244 1.46 perry __asm volatile ("mfrtcl %0" : "=r"(rtcl));
245 1.24 kleink return rtcl;
246 1.24 kleink }
247 1.24 kleink
248 1.47 perry static __inline void
249 1.24 kleink mfrtc(uint32_t *rtcp)
250 1.24 kleink {
251 1.24 kleink uint32_t tmp;
252 1.24 kleink
253 1.46 perry __asm volatile (
254 1.24 kleink "1: mfrtcu %0 \n"
255 1.24 kleink " mfrtcl %1 \n"
256 1.24 kleink " mfrtcu %2 \n"
257 1.24 kleink " cmplw %0,%2 \n"
258 1.24 kleink " bne- 1b"
259 1.41 kleink : "=r"(*rtcp), "=r"(*(rtcp + 1)), "=r"(tmp) :: "cr0");
260 1.19 chs }
261 1.19 chs
262 1.47 perry static __inline uint32_t
263 1.19 chs mfpvr(void)
264 1.19 chs {
265 1.19 chs uint32_t pvr;
266 1.19 chs
267 1.46 perry __asm volatile ("mfpvr %0" : "=r"(pvr));
268 1.19 chs return (pvr);
269 1.18 chs }
270 1.18 chs
271 1.49 freza static __inline int
272 1.49 freza cntlzw(uint32_t val)
273 1.49 freza {
274 1.49 freza int cnt;
275 1.49 freza
276 1.49 freza __asm volatile ("cntlzw %0,%1" : "=r"(cnt) : "r"(val));
277 1.49 freza return (cnt);
278 1.49 freza }
279 1.49 freza
280 1.48 freza #if defined(PPC_IBM4XX) || defined(PPC_IBM403)
281 1.48 freza /*
282 1.48 freza * DCR (Device Control Register) access. These have to be
283 1.48 freza * macros because register address is encoded as immediate
284 1.48 freza * operand.
285 1.48 freza */
286 1.48 freza #define mtdcr(reg, val) \
287 1.48 freza __asm volatile("mtdcr %0,%1" : : "K"(reg), "r"(val))
288 1.48 freza
289 1.48 freza #define mfdcr(reg) \
290 1.48 freza ({ \
291 1.48 freza uint32_t __val; \
292 1.48 freza \
293 1.48 freza __asm volatile("mfdcr %0,%1" : "=r"(__val) : "K"(reg)); \
294 1.48 freza __val; \
295 1.48 freza })
296 1.48 freza #endif /* PPC_IBM4XX || PPC_IBM403 */
297 1.48 freza
298 1.9 matt #define CLKF_USERMODE(frame) (((frame)->srr1 & PSL_PR) != 0)
299 1.9 matt #define CLKF_PC(frame) ((frame)->srr0)
300 1.9 matt #define CLKF_INTR(frame) ((frame)->depth > 0)
301 1.9 matt
302 1.23 thorpej #define LWP_PC(l) (trapframe(l)->srr0)
303 1.9 matt
304 1.56 yamt #define cpu_swapin(p)
305 1.9 matt #define cpu_swapout(p)
306 1.23 thorpej #define cpu_proc_fork(p1, p2)
307 1.56 yamt #define cpu_idle() (curcpu()->ci_idlespin())
308 1.56 yamt #define cpu_lwp_free2(l)
309 1.9 matt
310 1.9 matt extern int powersave;
311 1.9 matt extern int cpu_timebase;
312 1.9 matt extern int cpu_printfataltraps;
313 1.16 matt extern char cpu_model[];
314 1.16 matt
315 1.16 matt struct cpu_info *cpu_attach_common(struct device *, int);
316 1.18 chs void cpu_setup(struct device *, struct cpu_info *);
317 1.16 matt void cpu_identify(char *, size_t);
318 1.16 matt void delay (unsigned int);
319 1.16 matt void cpu_probe_cache(void);
320 1.16 matt void dcache_flush_page(vaddr_t);
321 1.16 matt void icache_flush_page(vaddr_t);
322 1.16 matt void dcache_flush(vaddr_t, vsize_t);
323 1.16 matt void icache_flush(vaddr_t, vsize_t);
324 1.31 scw void *mapiodev(paddr_t, psize_t);
325 1.52 matt void unmapiodev(vaddr_t, vsize_t);
326 1.9 matt
327 1.59 garbled #ifdef MULTIPROCESSOR
328 1.59 garbled int md_setup_trampoline(volatile struct cpu_hatch_data *, struct cpu_info *);
329 1.59 garbled void md_presync_timebase(volatile struct cpu_hatch_data *);
330 1.59 garbled void md_start_timebase(volatile struct cpu_hatch_data *);
331 1.59 garbled void md_sync_timebase(volatile struct cpu_hatch_data *);
332 1.59 garbled void md_setup_interrupts(void);
333 1.59 garbled int cpu_spinup(struct device *, struct cpu_info *);
334 1.59 garbled void cpu_hatch(void);
335 1.59 garbled void cpu_spinup_trampoline(void);
336 1.59 garbled #endif
337 1.59 garbled
338 1.9 matt #define DELAY(n) delay(n)
339 1.9 matt
340 1.57 rjs #define cpu_need_resched(ci, v) (ci->ci_want_resched = ci->ci_astpending = 1)
341 1.57 rjs #define cpu_did_resched() ((void)(curcpu()->ci_want_resched = 0))
342 1.56 yamt #define cpu_need_proftick(l) ((l)->l_pflag |= LP_OWEUPC, curcpu()->ci_astpending = 1)
343 1.53 ad #define cpu_signotify(l) (curcpu()->ci_astpending = 1) /* XXXSMP */
344 1.9 matt
345 1.51 sanjayl #if defined(PPC_OEA) || defined(PPC_OEA64) || defined (PPC_OEA64_BRIDGE)
346 1.26 matt void oea_init(void (*)(void));
347 1.26 matt void oea_startup(const char *);
348 1.26 matt void oea_dumpsys(void);
349 1.26 matt void oea_install_extint(void (*)(void));
350 1.55 christos paddr_t kvtop(void *);
351 1.16 matt void softnet(int);
352 1.16 matt
353 1.16 matt extern paddr_t msgbuf_paddr;
354 1.16 matt extern int cpu_altivec;
355 1.16 matt #endif
356 1.16 matt
357 1.9 matt #endif /* _KERNEL */
358 1.9 matt
359 1.9 matt #if defined(_KERNEL) || defined(_STANDALONE)
360 1.9 matt #if !defined(CACHELINESIZE)
361 1.29 hannken #ifdef PPC_IBM403
362 1.29 hannken #define CACHELINESIZE 16
363 1.29 hannken #else
364 1.51 sanjayl #if defined (PPC_OEA64_BRIDGE)
365 1.51 sanjayl #define CACHELINESIZE 128
366 1.51 sanjayl #else
367 1.9 matt #define CACHELINESIZE 32
368 1.51 sanjayl #endif /* PPC_OEA64_BRIDGE */
369 1.29 hannken #endif
370 1.9 matt #endif
371 1.10 matt #endif
372 1.10 matt
373 1.15 matt void __syncicache(void *, size_t);
374 1.14 eeh
375 1.5 ws /*
376 1.5 ws * CTL_MACHDEP definitions.
377 1.5 ws */
378 1.9 matt #define CPU_CACHELINE 1
379 1.9 matt #define CPU_TIMEBASE 2
380 1.9 matt #define CPU_CPUTEMP 3
381 1.9 matt #define CPU_PRINTFATALTRAPS 4
382 1.14 eeh #define CPU_CACHEINFO 5
383 1.16 matt #define CPU_ALTIVEC 6
384 1.16 matt #define CPU_MODEL 7
385 1.58 nisimura #define CPU_POWERSAVE 8 /* int: use CPU powersave mode */
386 1.58 nisimura #define CPU_BOOTED_DEVICE 9 /* string: device we booted from */
387 1.58 nisimura #define CPU_BOOTED_KERNEL 10 /* string: kernel we booted */
388 1.58 nisimura #define CPU_MAXID 11 /* number of valid machdep ids */
389 1.1 ws
390 1.5 ws #define CTL_MACHDEP_NAMES { \
391 1.5 ws { 0, 0 }, \
392 1.5 ws { "cachelinesize", CTLTYPE_INT }, \
393 1.7 matt { "timebase", CTLTYPE_INT }, \
394 1.7 matt { "cputempature", CTLTYPE_INT }, \
395 1.9 matt { "printfataltraps", CTLTYPE_INT }, \
396 1.14 eeh { "cacheinfo", CTLTYPE_STRUCT }, \
397 1.16 matt { "altivec", CTLTYPE_INT }, \
398 1.16 matt { "model", CTLTYPE_STRING }, \
399 1.17 matt { "powersave", CTLTYPE_INT }, \
400 1.1 ws }
401 1.1 ws
402 1.5 ws #endif /* _POWERPC_CPU_H_ */
403