]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/sun4v/include/smp.h
Copy head to stable/8 as part of 8.0 Release cycle.
[FreeBSD/stable/8.git] / sys / sun4v / 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 #define CPU_CLKSYNC             1
33 #define CPU_INIT                2
34 #define CPU_BOOTSTRAP           3
35
36 #ifndef LOCORE
37
38 #include <machine/intr_machdep.h>
39 #include <machine/tte.h>
40
41 #define IDR_BUSY        (1<<0)
42 #define IDR_NACK        (1<<1)
43
44 #define IPI_AST         PIL_AST
45 #define IPI_RENDEZVOUS  PIL_RENDEZVOUS
46 #define IPI_STOP        PIL_STOP
47 #define IPI_PREEMPT     PIL_PREEMPT
48
49
50 #define IPI_RETRIES     5000
51
52 struct cpu_start_args {
53         u_int   csa_count;
54         u_int   csa_state;
55         vm_offset_t csa_pcpu;
56         u_int csa_cpuid;
57 };
58
59 struct ipi_cache_args {
60         u_int   ica_mask;
61         vm_paddr_t ica_pa;
62 };
63
64 struct ipi_tlb_args {
65         u_int   ita_mask;
66         struct  pmap *ita_pmap;
67         u_long  ita_start;
68         u_long  ita_end;
69 };
70 #define ita_va  ita_start
71
72 struct pcpu;
73
74 void    cpu_mp_bootstrap(struct pcpu *pc);
75 void    cpu_mp_shutdown(void);
76
77 void    cpu_ipi_selected(int cpus, uint16_t *cpulist, u_long d0, u_long d1, u_long d2, uint64_t *ackmask);
78 void    cpu_ipi_send(u_int mid, u_long d0, u_long d1, u_long d2);
79
80 void cpu_ipi_ast(struct trapframe *tf);
81 void cpu_ipi_stop(struct trapframe *tf);
82 void cpu_ipi_preempt(struct trapframe *tf);
83
84 void    ipi_selected(u_int cpus, u_int ipi);
85 void    ipi_all_but_self(u_int ipi);
86
87 vm_offset_t mp_tramp_alloc(void);
88 void        mp_set_tsb_desc_ra(vm_paddr_t);
89 void        mp_add_nucleus_mapping(vm_offset_t, uint64_t);
90 extern  struct mtx ipi_mtx;
91 extern  struct ipi_cache_args ipi_cache_args;
92 extern  struct ipi_tlb_args ipi_tlb_args;
93
94 extern  vm_offset_t mp_tramp;
95 extern  char *mp_tramp_code;
96 extern  u_long mp_tramp_code_len;
97 extern  u_long mp_tramp_tte_slots;
98 extern  u_long mp_tramp_tsb_desc_ra;
99 extern  u_long mp_tramp_func;
100
101 extern  void mp_startup(void);
102
103 extern  char tl_ipi_level[];
104 extern  char tl_invltlb[];
105 extern  char tl_invlctx[];
106 extern  char tl_invlpg[];
107 extern  char tl_invlrng[];
108 extern  char tl_tsbupdate[];
109 extern  char tl_ttehashupdate[];
110
111 #ifdef SMP
112
113 #if defined(_MACHINE_PMAP_H_) && defined(_SYS_MUTEX_H_)
114 #if 0
115 static __inline void *
116 ipi_dcache_page_inval(void *func, vm_paddr_t pa)
117 {
118         struct ipi_cache_args *ica;
119
120         if (smp_cpus == 1)
121                 return (NULL);
122         ica = &ipi_cache_args;
123         mtx_lock_spin(&ipi_mtx);
124         ica->ica_mask = all_cpus;
125         ica->ica_pa = pa;
126         cpu_ipi_selected(PCPU_GET(other_cpus), 0, (u_long)func, (u_long)ica);
127         return (&ica->ica_mask);
128 }
129
130 static __inline void *
131 ipi_icache_page_inval(void *func, vm_paddr_t pa)
132 {
133         struct ipi_cache_args *ica;
134
135         if (smp_cpus == 1)
136                 return (NULL);
137         ica = &ipi_cache_args;
138         mtx_lock_spin(&ipi_mtx);
139         ica->ica_mask = all_cpus;
140         ica->ica_pa = pa;
141         cpu_ipi_selected(PCPU_GET(other_cpus), 0, (u_long)func, (u_long)ica);
142         return (&ica->ica_mask);
143 }
144
145 static __inline void *
146 ipi_tlb_context_demap(struct pmap *pm)
147 {
148         struct ipi_tlb_args *ita;
149         u_int cpus;
150
151         if (smp_cpus == 1)
152                 return (NULL);
153         if ((cpus = (pm->pm_active & PCPU_GET(other_cpus))) == 0)
154                 return (NULL);
155         ita = &ipi_tlb_args;
156         mtx_lock_spin(&ipi_mtx);
157         ita->ita_mask = cpus | PCPU_GET(cpumask);
158         ita->ita_pmap = pm;
159         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_context_demap,
160             (u_long)ita);
161         return (&ita->ita_mask);
162 }
163
164 static __inline void *
165 ipi_tlb_page_demap(struct pmap *pm, vm_offset_t va)
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         ita->ita_va = va;
179         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_page_demap, (u_long)ita);
180         return (&ita->ita_mask);
181 }
182
183 static __inline void *
184 ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
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_start = start;
198         ita->ita_end = end;
199         cpu_ipi_selected(cpus, 0, (u_long)tl_ipi_tlb_range_demap, (u_long)ita);
200         return (&ita->ita_mask);
201 }
202 #endif
203 static __inline void
204 ipi_wait(void *cookie)
205 {
206         volatile u_int *mask;
207
208         if ((mask = cookie) != NULL) {
209                 atomic_clear_int(mask, PCPU_GET(cpumask));
210                 while (*mask != 0)
211                         ;
212                 mtx_unlock_spin(&ipi_mtx);
213         }
214 }
215
216 #endif /* _MACHINE_PMAP_H_ && _SYS_MUTEX_H_ */
217
218 #else
219
220 static __inline void *
221 ipi_dcache_page_inval(void *func, vm_paddr_t pa)
222 {
223         return (NULL);
224 }
225
226 static __inline void *
227 ipi_icache_page_inval(void *func, vm_paddr_t pa)
228 {
229         return (NULL);
230 }
231
232 static __inline void *
233 ipi_tlb_context_demap(struct pmap *pm)
234 {
235         return (NULL);
236 }
237
238 static __inline void *
239 ipi_tlb_page_demap(struct pmap *pm, vm_offset_t va)
240 {
241         return (NULL);
242 }
243
244 static __inline void *
245 ipi_tlb_range_demap(struct pmap *pm, vm_offset_t start, vm_offset_t end)
246 {
247         return (NULL);
248 }
249
250 static __inline void
251 ipi_wait(void *cookie)
252 {
253 }
254
255 #endif /* SMP */
256
257 #endif /* !LOCORE */
258
259 #endif /* !_MACHINE_SMP_H_ */