2 * Copyright (c) 2001 Jake Burkholder.
3 * Copyright (c) 2007 - 2011 Marius Strobl <marius@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
30 #ifndef _MACHINE_SMP_H_
31 #define _MACHINE_SMP_H_
35 #define CPU_TICKSYNC 1
36 #define CPU_STICKSYNC 2
38 #define CPU_BOOTSTRAP 4
43 #include <sys/sched.h>
46 #include <machine/intr_machdep.h>
47 #include <machine/pcb.h>
48 #include <machine/tte.h>
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
57 #define IDC_ITID_SHIFT 14
58 #define IDC_BN_SHIFT 24
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
66 #define IPI_RETRIES 5000
68 struct cpu_start_args {
76 struct tte csa_ttes[PCPU_PAGES];
79 struct ipi_cache_args {
91 struct pmap *ita_pmap;
95 #define ita_va ita_start
99 extern struct pcb stoppcbs[];
101 void cpu_mp_bootstrap(struct pcpu *pc);
102 void cpu_mp_shutdown(void);
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;
109 void mp_init(u_int cpu_impl);
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;
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;
120 extern void mp_startup(void);
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[];
126 extern char tl_ipi_level[];
128 extern char tl_ipi_stick_rd[];
129 extern char tl_ipi_tick_rd[];
131 extern char tl_ipi_tlb_context_demap[];
132 extern char tl_ipi_tlb_page_demap[];
133 extern char tl_ipi_tlb_range_demap[];
136 ipi_all_but_self(u_int ipi)
139 cpu_ipi_selected(PCPU_GET(other_cpus), 0, (u_long)tl_ipi_level, ipi);
143 ipi_selected(u_int cpus, u_int ipi)
146 cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_level, ipi);
150 ipi_cpu(int cpu, u_int ipi)
153 cpu_ipi_single(cpu, 0, (u_long)tl_ipi_level, ipi);
156 #if defined(_MACHINE_PMAP_H_) && defined(_SYS_MUTEX_H_)
158 static __inline void *
159 ipi_dcache_page_inval(void *func, vm_paddr_t pa)
161 struct ipi_cache_args *ica;
166 ica = &ipi_cache_args;
167 mtx_lock_spin(&smp_ipi_mtx);
168 ica->ica_mask = PCPU_GET(other_cpus);
170 cpu_ipi_selected(ica->ica_mask, 0, (u_long)func, (u_long)ica);
171 return (&ica->ica_mask);
174 static __inline void *
175 ipi_icache_page_inval(void *func, vm_paddr_t pa)
177 struct ipi_cache_args *ica;
182 ica = &ipi_cache_args;
183 mtx_lock_spin(&smp_ipi_mtx);
184 ica->ica_mask = PCPU_GET(other_cpus);
186 cpu_ipi_selected(ica->ica_mask, 0, (u_long)func, (u_long)ica);
187 return (&ica->ica_mask);
190 static __inline void *
191 ipi_rd(u_int cpu, void *func, u_long *val)
193 struct ipi_rd_args *ira;
199 mtx_lock_spin(&smp_ipi_mtx);
200 ira->ira_mask = 1 << cpu;
202 cpu_ipi_single(cpu, 0, (u_long)func, (u_long)ira);
203 return (&ira->ira_mask);
206 static __inline void *
207 ipi_tlb_context_demap(struct pmap *pm)
209 struct ipi_tlb_args *ita;
215 if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0) {
220 mtx_lock_spin(&smp_ipi_mtx);
221 ita->ita_mask = cpus;
223 cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_context_demap,
225 return (&ita->ita_mask);
228 static __inline void *
229 ipi_tlb_page_demap(struct pmap *pm, vm_offset_t va)
231 struct ipi_tlb_args *ita;
237 if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0) {
242 mtx_lock_spin(&smp_ipi_mtx);
243 ita->ita_mask = cpus;
246 cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_page_demap, (u_long)ita);
247 return (&ita->ita_mask);
250 static __inline void *
251 ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
253 struct ipi_tlb_args *ita;
259 if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0) {
264 mtx_lock_spin(&smp_ipi_mtx);
265 ita->ita_mask = cpus;
267 ita->ita_start = start;
269 cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_range_demap,
271 return (&ita->ita_mask);
275 ipi_wait(void *cookie)
277 volatile cpumask_t *mask;
279 if ((mask = cookie) != NULL) {
282 mtx_unlock_spin(&smp_ipi_mtx);
287 #endif /* _MACHINE_PMAP_H_ && _SYS_MUTEX_H_ */
295 static __inline void *
296 ipi_dcache_page_inval(void *func __unused, vm_paddr_t pa __unused)
302 static __inline void *
303 ipi_icache_page_inval(void *func __unused, vm_paddr_t pa __unused)
309 static __inline void *
310 ipi_rd(u_int cpu __unused, void *func __unused, u_long *val __unused)
316 static __inline void *
317 ipi_tlb_context_demap(struct pmap *pm __unused)
323 static __inline void *
324 ipi_tlb_page_demap(struct pmap *pm __unused, vm_offset_t va __unused)
330 static __inline void *
331 ipi_tlb_range_demap(struct pmap *pm __unused, vm_offset_t start __unused,
332 __unused vm_offset_t end)
339 ipi_wait(void *cookie __unused)
345 tl_ipi_cheetah_dcache_page_inval(void)
351 tl_ipi_spitfire_dcache_page_inval(void)
357 tl_ipi_spitfire_icache_page_inval(void)
366 #endif /* !_MACHINE_SMP_H_ */