cpu.h revision 1.10.6.6 1 1.10.6.6 nathanw /* $NetBSD: cpu.h,v 1.10.6.6 2002/04/01 07:42:03 nathanw Exp $ */
2 1.10.6.2 briggs
3 1.10.6.2 briggs /*
4 1.10.6.2 briggs * Copyright (C) 1999 Wolfgang Solfrank.
5 1.10.6.2 briggs * Copyright (C) 1999 TooLs GmbH.
6 1.10.6.2 briggs * Copyright (C) 1995-1997 Wolfgang Solfrank.
7 1.10.6.2 briggs * Copyright (C) 1995-1997 TooLs GmbH.
8 1.10.6.2 briggs * All rights reserved.
9 1.10.6.2 briggs *
10 1.10.6.2 briggs * Redistribution and use in source and binary forms, with or without
11 1.10.6.2 briggs * modification, are permitted provided that the following conditions
12 1.10.6.2 briggs * are met:
13 1.10.6.2 briggs * 1. Redistributions of source code must retain the above copyright
14 1.10.6.2 briggs * notice, this list of conditions and the following disclaimer.
15 1.10.6.2 briggs * 2. Redistributions in binary form must reproduce the above copyright
16 1.10.6.2 briggs * notice, this list of conditions and the following disclaimer in the
17 1.10.6.2 briggs * documentation and/or other materials provided with the distribution.
18 1.10.6.2 briggs * 3. All advertising materials mentioning features or use of this software
19 1.10.6.2 briggs * must display the following acknowledgement:
20 1.10.6.2 briggs * This product includes software developed by TooLs GmbH.
21 1.10.6.2 briggs * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 1.10.6.2 briggs * derived from this software without specific prior written permission.
23 1.10.6.2 briggs *
24 1.10.6.2 briggs * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 1.10.6.2 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.10.6.2 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.10.6.2 briggs * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 1.10.6.2 briggs * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 1.10.6.2 briggs * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 1.10.6.2 briggs * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 1.10.6.2 briggs * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 1.10.6.2 briggs * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 1.10.6.2 briggs * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.10.6.2 briggs */
35 1.10.6.2 briggs #ifndef _POWERPC_CPU_H_
36 1.10.6.2 briggs #define _POWERPC_CPU_H_
37 1.10.6.2 briggs
38 1.10.6.2 briggs #if defined(_KERNEL_OPT)
39 1.10.6.2 briggs #include "opt_lockdebug.h"
40 1.10.6.2 briggs #include "opt_multiprocessor.h"
41 1.10.6.2 briggs #endif
42 1.10.6.2 briggs
43 1.10.6.2 briggs #include <sys/device.h>
44 1.10.6.2 briggs #include <machine/frame.h>
45 1.10.6.2 briggs #include <machine/psl.h>
46 1.10.6.2 briggs #include <machine/intr.h>
47 1.10.6.2 briggs
48 1.10.6.6 nathanw
49 1.10.6.6 nathanw struct cache_info {
50 1.10.6.6 nathanw int dcache_size;
51 1.10.6.6 nathanw int dcache_line_size;
52 1.10.6.6 nathanw int icache_size;
53 1.10.6.6 nathanw int icache_line_size;
54 1.10.6.6 nathanw };
55 1.10.6.6 nathanw
56 1.10.6.6 nathanw
57 1.10.6.2 briggs #ifdef _KERNEL
58 1.10.6.2 briggs #include <sys/sched.h>
59 1.10.6.6 nathanw #include <dev/sysmon/sysmonvar.h>
60 1.10.6.6 nathanw
61 1.10.6.2 briggs struct cpu_info {
62 1.10.6.2 briggs struct schedstate_percpu ci_schedstate; /* scheduler state */
63 1.10.6.2 briggs #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
64 1.10.6.2 briggs u_long ci_spin_locks; /* # of spin locks held */
65 1.10.6.2 briggs u_long ci_simple_locks; /* # of simple locks held */
66 1.10.6.2 briggs #endif
67 1.10.6.2 briggs struct device *ci_dev; /* device of corresponding cpu */
68 1.10.6.2 briggs struct lwp *ci_curproc; /* current owner of the processor */
69 1.10.6.2 briggs
70 1.10.6.2 briggs struct pcb *ci_curpcb;
71 1.10.6.2 briggs struct pmap *ci_curpm;
72 1.10.6.2 briggs struct lwp *ci_fpuproc;
73 1.10.6.2 briggs struct pcb *ci_idle_pcb; /* PA of our idle pcb */
74 1.10.6.2 briggs int ci_cpuid;
75 1.10.6.2 briggs
76 1.10.6.2 briggs int ci_astpending;
77 1.10.6.2 briggs int ci_want_resched;
78 1.10.6.2 briggs u_long ci_lasttb;
79 1.10.6.2 briggs int ci_tickspending;
80 1.10.6.2 briggs int ci_cpl;
81 1.10.6.2 briggs int ci_ipending;
82 1.10.6.2 briggs int ci_intrdepth;
83 1.10.6.2 briggs char *ci_intstk;
84 1.10.6.2 briggs char *ci_spillstk;
85 1.10.6.2 briggs int ci_tempsave[8];
86 1.10.6.2 briggs int ci_ddbsave[8];
87 1.10.6.2 briggs int ci_ipkdbsave[8];
88 1.10.6.2 briggs int ci_disisave[4];
89 1.10.6.6 nathanw struct cache_info ci_ci;
90 1.10.6.6 nathanw struct sysmon_envsys ci_sysmon;
91 1.10.6.6 nathanw struct envsys_tre_data ci_tau_info;
92 1.10.6.2 briggs struct evcnt ci_ev_traps; /* calls to trap() */
93 1.10.6.2 briggs struct evcnt ci_ev_kdsi; /* kernel DSI traps */
94 1.10.6.2 briggs struct evcnt ci_ev_udsi; /* user DSI traps */
95 1.10.6.2 briggs struct evcnt ci_ev_udsi_fatal; /* user DSI trap failures */
96 1.10.6.2 briggs struct evcnt ci_ev_isi; /* user ISI traps */
97 1.10.6.2 briggs struct evcnt ci_ev_isi_fatal; /* user ISI trap failures */
98 1.10.6.2 briggs struct evcnt ci_ev_pgm; /* user PGM traps */
99 1.10.6.2 briggs struct evcnt ci_ev_fpu; /* FPU traps */
100 1.10.6.2 briggs struct evcnt ci_ev_fpusw; /* FPU context switch */
101 1.10.6.2 briggs struct evcnt ci_ev_ali; /* Alignment traps */
102 1.10.6.2 briggs struct evcnt ci_ev_ali_fatal; /* Alignment fatal trap */
103 1.10.6.2 briggs struct evcnt ci_ev_scalls; /* system call traps */
104 1.10.6.2 briggs struct evcnt ci_ev_vec; /* Altivec traps */
105 1.10.6.2 briggs struct evcnt ci_ev_vecsw; /* Altivec context switches */
106 1.10.6.2 briggs };
107 1.10.6.2 briggs
108 1.10.6.2 briggs #ifdef MULTIPROCESSOR
109 1.10.6.2 briggs static __inline int
110 1.10.6.5 nathanw cpu_number(void)
111 1.10.6.2 briggs {
112 1.10.6.2 briggs int pir;
113 1.10.6.2 briggs
114 1.10.6.2 briggs asm ("mfspr %0,1023" : "=r"(pir));
115 1.10.6.2 briggs return pir;
116 1.10.6.2 briggs }
117 1.10.6.2 briggs
118 1.10.6.2 briggs static __inline struct cpu_info *
119 1.10.6.5 nathanw curcpu(void)
120 1.10.6.2 briggs {
121 1.10.6.2 briggs struct cpu_info *ci;
122 1.10.6.2 briggs
123 1.10.6.2 briggs asm volatile ("mfsprg %0,0" : "=r"(ci));
124 1.10.6.2 briggs return ci;
125 1.10.6.2 briggs }
126 1.10.6.2 briggs
127 1.10.6.5 nathanw void cpu_boot_secondary_processors(void);
128 1.10.6.5 nathanw
129 1.10.6.2 briggs extern struct cpu_info cpu_info[];
130 1.10.6.2 briggs
131 1.10.6.2 briggs #define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0)
132 1.10.6.2 briggs #define curproc curcpu()->ci_curproc
133 1.10.6.2 briggs #define fpuproc curcpu()->ci_fpuproc
134 1.10.6.2 briggs #define curpcb curcpu()->ci_curpcb
135 1.10.6.2 briggs #define curpm curcpu()->ci_curpm
136 1.10.6.2 briggs #define want_resched curcpu()->ci_want_resched
137 1.10.6.2 briggs #define astpending curcpu()->ci_astpending
138 1.10.6.2 briggs #define intr_depth curcpu()->ci_intrdepth
139 1.10.6.2 briggs
140 1.10.6.2 briggs #else
141 1.10.6.2 briggs extern struct cpu_info cpu_info_store;
142 1.10.6.2 briggs extern volatile int want_resched;
143 1.10.6.2 briggs extern volatile int astpending;
144 1.10.6.2 briggs extern volatile int intr_depth;
145 1.10.6.2 briggs
146 1.10.6.2 briggs #define curcpu() (&cpu_info_store)
147 1.10.6.2 briggs #define cpu_number() 0
148 1.10.6.2 briggs
149 1.10.6.2 briggs #endif /* MULTIPROCESSOR */
150 1.10.6.2 briggs
151 1.10.6.2 briggs #define ppc_cpuid(ci) ((ci)->ci_cpuid)
152 1.10.6.2 briggs
153 1.10.6.2 briggs #define CLKF_USERMODE(frame) (((frame)->srr1 & PSL_PR) != 0)
154 1.10.6.2 briggs #define CLKF_BASEPRI(frame) ((frame)->pri == 0)
155 1.10.6.2 briggs #define CLKF_PC(frame) ((frame)->srr0)
156 1.10.6.2 briggs #define CLKF_INTR(frame) ((frame)->depth > 0)
157 1.10.6.2 briggs
158 1.10.6.3 briggs #define LWP_PC(l) (trapframe(l)->srr0)
159 1.10.6.2 briggs
160 1.10.6.2 briggs #define cpu_swapout(p)
161 1.10.6.2 briggs #define cpu_wait(p)
162 1.10.6.4 thorpej #define cpu_proc_fork(p1, p2)
163 1.10.6.2 briggs
164 1.10.6.2 briggs extern int powersave;
165 1.10.6.2 briggs extern int cpu_timebase;
166 1.10.6.2 briggs extern int cpu_printfataltraps;
167 1.10.6.2 briggs
168 1.10.6.2 briggs extern struct cpu_info *cpu_attach_common(struct device *, int);
169 1.10.6.2 briggs extern void cpu_identify(char *, size_t);
170 1.10.6.2 briggs extern void delay (unsigned int);
171 1.10.6.6 nathanw extern void cpu_probe_cache(void);
172 1.10.6.6 nathanw extern void dcache_flush_page(vaddr_t);
173 1.10.6.6 nathanw extern void icache_flush_page(vaddr_t);
174 1.10.6.6 nathanw extern void dcache_flush(vaddr_t, vsize_t);
175 1.10.6.6 nathanw extern void icache_flush(vaddr_t, vsize_t);
176 1.10.6.2 briggs #define DELAY(n) delay(n)
177 1.10.6.2 briggs
178 1.10.6.2 briggs #define need_resched(ci) (want_resched = 1, astpending = 1)
179 1.10.6.2 briggs #define need_proftick(p) ((p)->p_flag |= P_OWEUPC, astpending = 1)
180 1.10.6.2 briggs #define signotify(p) (astpending = 1)
181 1.10.6.2 briggs
182 1.10.6.2 briggs #endif /* _KERNEL */
183 1.10.6.2 briggs
184 1.10.6.2 briggs #if defined(_KERNEL) || defined(_STANDALONE)
185 1.10.6.2 briggs #if !defined(CACHELINESIZE)
186 1.10.6.2 briggs #define CACHELINESIZE 32
187 1.10.6.2 briggs #endif
188 1.10.6.2 briggs #endif
189 1.10.6.2 briggs
190 1.10.6.6 nathanw void __syncicache(void *, size_t);
191 1.10.6.6 nathanw
192 1.10.6.2 briggs
193 1.10.6.2 briggs /*
194 1.10.6.2 briggs * CTL_MACHDEP definitions.
195 1.10.6.2 briggs */
196 1.10.6.2 briggs #define CPU_CACHELINE 1
197 1.10.6.2 briggs #define CPU_TIMEBASE 2
198 1.10.6.2 briggs #define CPU_CPUTEMP 3
199 1.10.6.2 briggs #define CPU_PRINTFATALTRAPS 4
200 1.10.6.6 nathanw #define CPU_CACHEINFO 5
201 1.10.6.6 nathanw #define CPU_MAXID 6
202 1.10.6.2 briggs
203 1.10.6.2 briggs #define CTL_MACHDEP_NAMES { \
204 1.10.6.2 briggs { 0, 0 }, \
205 1.10.6.2 briggs { "cachelinesize", CTLTYPE_INT }, \
206 1.10.6.2 briggs { "timebase", CTLTYPE_INT }, \
207 1.10.6.2 briggs { "cputempature", CTLTYPE_INT }, \
208 1.10.6.2 briggs { "printfataltraps", CTLTYPE_INT }, \
209 1.10.6.6 nathanw { "cacheinfo", CTLTYPE_STRUCT }, \
210 1.10.6.2 briggs }
211 1.10.6.2 briggs
212 1.10.6.2 briggs #endif /* _POWERPC_CPU_H_ */
213