]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/sparc64/include/smp.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / sparc64 / include / smp.h
1 /*-
2  * Copyright (c) 2001 Jake Burkholder.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _MACHINE_SMP_H_
30 #define _MACHINE_SMP_H_
31
32 #ifdef SMP
33
34 #define CPU_TICKSYNC            1
35 #define CPU_STICKSYNC           2
36 #define CPU_INIT                3
37 #define CPU_BOOTSTRAP           4
38
39 #ifndef LOCORE
40
41 #include <machine/intr_machdep.h>
42 #include <machine/pcb.h>
43 #include <machine/tte.h>
44
45 #define IDR_BUSY                        0x0000000000000001ULL
46 #define IDR_NACK                        0x0000000000000002ULL
47 #define IDR_CHEETAH_ALL_BUSY            0x5555555555555555ULL
48 #define IDR_CHEETAH_ALL_NACK            (~IDR_CHEETAH_ALL_BUSY)
49 #define IDR_CHEETAH_MAX_BN_PAIRS        32
50 #define IDR_JALAPENO_MAX_BN_PAIRS       4
51
52 #define IDC_ITID_SHIFT                  14
53 #define IDC_BN_SHIFT                    24
54
55 #define IPI_AST         PIL_AST
56 #define IPI_RENDEZVOUS  PIL_RENDEZVOUS
57 #define IPI_PREEMPT     PIL_PREEMPT
58 #define IPI_STOP        PIL_STOP
59
60 #define IPI_RETRIES     5000
61
62 struct cpu_start_args {
63         u_int   csa_count;
64         u_int   csa_mid;
65         u_int   csa_state;
66         vm_offset_t csa_pcpu;
67         u_long  csa_tick;
68         u_long  csa_stick;
69         u_long  csa_ver;
70         struct  tte csa_ttes[PCPU_PAGES];
71 };
72
73 struct ipi_cache_args {
74         u_int   ica_mask;
75         vm_paddr_t ica_pa;
76 };
77
78 struct ipi_tlb_args {
79         u_int   ita_mask;
80         struct  pmap *ita_pmap;
81         u_long  ita_start;
82         u_long  ita_end;
83 };
84 #define ita_va  ita_start
85
86 struct pcpu;
87
88 extern struct pcb stoppcbs[];
89
90 void    cpu_mp_bootstrap(struct pcpu *pc);
91 void    cpu_mp_shutdown(void);
92
93 typedef void cpu_ipi_selected_t(u_int, u_long, u_long, u_long);
94 extern  cpu_ipi_selected_t *cpu_ipi_selected;
95
96 void    mp_init(void);
97
98 extern  struct mtx ipi_mtx;
99 extern  struct ipi_cache_args ipi_cache_args;
100 extern  struct ipi_tlb_args ipi_tlb_args;
101
102 extern  char *mp_tramp_code;
103 extern  u_long mp_tramp_code_len;
104 extern  u_long mp_tramp_tlb_slots;
105 extern  u_long mp_tramp_func;
106
107 extern  void mp_startup(void);
108
109 extern  char tl_ipi_cheetah_dcache_page_inval[];
110 extern  char tl_ipi_spitfire_dcache_page_inval[];
111 extern  char tl_ipi_spitfire_icache_page_inval[];
112
113 extern  char tl_ipi_level[];
114 extern  char tl_ipi_tlb_context_demap[];
115 extern  char tl_ipi_tlb_page_demap[];
116 extern  char tl_ipi_tlb_range_demap[];
117
118 static __inline void
119 ipi_all_but_self(u_int ipi)
120 {
121
122         cpu_ipi_selected(PCPU_GET(other_cpus), 0, (u_long)tl_ipi_level, ipi);
123 }
124
125 static __inline void
126 ipi_selected(u_int cpus, u_int ipi)
127 {
128
129         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_level, ipi);
130 }
131
132 #if defined(_MACHINE_PMAP_H_) && defined(_SYS_MUTEX_H_)
133
134 static __inline void *
135 ipi_dcache_page_inval(void *func, vm_paddr_t pa)
136 {
137         struct ipi_cache_args *ica;
138
139         if (smp_cpus == 1)
140                 return (NULL);
141         ica = &ipi_cache_args;
142         mtx_lock_spin(&ipi_mtx);
143         ica->ica_mask = all_cpus;
144         ica->ica_pa = pa;
145         cpu_ipi_selected(PCPU_GET(other_cpus), 0, (u_long)func, (u_long)ica);
146         return (&ica->ica_mask);
147 }
148
149 static __inline void *
150 ipi_icache_page_inval(void *func, vm_paddr_t pa)
151 {
152         struct ipi_cache_args *ica;
153
154         if (smp_cpus == 1)
155                 return (NULL);
156         ica = &ipi_cache_args;
157         mtx_lock_spin(&ipi_mtx);
158         ica->ica_mask = all_cpus;
159         ica->ica_pa = pa;
160         cpu_ipi_selected(PCPU_GET(other_cpus), 0, (u_long)func, (u_long)ica);
161         return (&ica->ica_mask);
162 }
163
164 static __inline void *
165 ipi_tlb_context_demap(struct pmap *pm)
166 {
167         struct ipi_tlb_args *ita;
168         u_int cpus;
169
170         if (smp_cpus == 1)
171                 return (NULL);
172         if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0)
173                 return (NULL);
174         ita = &ipi_tlb_args;
175         mtx_lock_spin(&ipi_mtx);
176         ita->ita_mask = cpus | PCPU_GET(cpumask);
177         ita->ita_pmap = pm;
178         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_context_demap,
179             (u_long)ita);
180         return (&ita->ita_mask);
181 }
182
183 static __inline void *
184 ipi_tlb_page_demap(struct pmap *pm, vm_offset_t va)
185 {
186         struct ipi_tlb_args *ita;
187         u_int cpus;
188
189         if (smp_cpus == 1)
190                 return (NULL);
191         if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0)
192                 return (NULL);
193         ita = &ipi_tlb_args;
194         mtx_lock_spin(&ipi_mtx);
195         ita->ita_mask = cpus | PCPU_GET(cpumask);
196         ita->ita_pmap = pm;
197         ita->ita_va = va;
198         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_page_demap, (u_long)ita);
199         return (&ita->ita_mask);
200 }
201
202 static __inline void *
203 ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
204 {
205         struct ipi_tlb_args *ita;
206         u_int cpus;
207
208         if (smp_cpus == 1)
209                 return (NULL);
210         if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0)
211                 return (NULL);
212         ita = &ipi_tlb_args;
213         mtx_lock_spin(&ipi_mtx);
214         ita->ita_mask = cpus | PCPU_GET(cpumask);
215         ita->ita_pmap = pm;
216         ita->ita_start = start;
217         ita->ita_end = end;
218         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_range_demap, (u_long)ita);
219         return (&ita->ita_mask);
220 }
221
222 static __inline void
223 ipi_wait(void *cookie)
224 {
225         volatile u_int *mask;
226
227         if ((mask = cookie) != NULL) {
228                 atomic_clear_int(mask, PCPU_GET(cpumask));
229                 while (*mask != 0)
230                         ;
231                 mtx_unlock_spin(&ipi_mtx);
232         }
233 }
234
235 #endif /* _MACHINE_PMAP_H_ && _SYS_MUTEX_H_ */
236
237 #endif /* !LOCORE */
238
239 #else
240
241 #ifndef LOCORE
242
243 static __inline void *
244 ipi_dcache_page_inval(void *func, vm_paddr_t pa)
245 {
246
247         return (NULL);
248 }
249
250 static __inline void *
251 ipi_icache_page_inval(void *func, vm_paddr_t pa)
252 {
253
254         return (NULL);
255 }
256
257 static __inline void *
258 ipi_tlb_context_demap(struct pmap *pm)
259 {
260
261         return (NULL);
262 }
263
264 static __inline void *
265 ipi_tlb_page_demap(struct pmap *pm, vm_offset_t va)
266 {
267
268         return (NULL);
269 }
270
271 static __inline void *
272 ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
273 {
274
275         return (NULL);
276 }
277
278 static __inline void
279 ipi_wait(void *cookie)
280 {
281
282 }
283
284 static __inline void
285 tl_ipi_cheetah_dcache_page_inval(void)
286 {
287
288 }
289
290 static __inline void
291 tl_ipi_spitfire_dcache_page_inval(void)
292 {
293
294 }
295
296 static __inline void
297 tl_ipi_spitfire_icache_page_inval(void)
298 {
299
300 }
301
302 #endif /* !LOCORE */
303
304 #endif /* SMP */
305
306 #endif /* !_MACHINE_SMP_H_ */