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