xen_intr.c revision 1.2.4.2 1 1.2.4.2 ad /* $NetBSD: xen_intr.c,v 1.2.4.2 2007/12/03 19:04:44 ad Exp $ */
2 1.2.4.2 ad
3 1.2.4.2 ad /*-
4 1.2.4.2 ad * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 1.2.4.2 ad * All rights reserved.
6 1.2.4.2 ad *
7 1.2.4.2 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 ad * by Charles M. Hannum, and by Jason R. Thorpe.
9 1.2.4.2 ad *
10 1.2.4.2 ad * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 ad * modification, are permitted provided that the following conditions
12 1.2.4.2 ad * are met:
13 1.2.4.2 ad * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 ad * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 ad * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 ad * documentation and/or other materials provided with the distribution.
18 1.2.4.2 ad * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 ad * must display the following acknowledgement:
20 1.2.4.2 ad * This product includes software developed by the NetBSD
21 1.2.4.2 ad * Foundation, Inc. and its contributors.
22 1.2.4.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 ad * contributors may be used to endorse or promote products derived
24 1.2.4.2 ad * from this software without specific prior written permission.
25 1.2.4.2 ad *
26 1.2.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 ad */
38 1.2.4.2 ad
39 1.2.4.2 ad #include <sys/cdefs.h>
40 1.2.4.2 ad __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.2.4.2 2007/12/03 19:04:44 ad Exp $");
41 1.2.4.2 ad
42 1.2.4.2 ad #include <sys/param.h>
43 1.2.4.2 ad
44 1.2.4.2 ad #include <machine/cpu.h>
45 1.2.4.2 ad #include <machine/intr.h>
46 1.2.4.2 ad
47 1.2.4.2 ad /*
48 1.2.4.2 ad * Add a mask to cpl, and return the old value of cpl.
49 1.2.4.2 ad */
50 1.2.4.2 ad int
51 1.2.4.2 ad splraise(int nlevel)
52 1.2.4.2 ad {
53 1.2.4.2 ad int olevel;
54 1.2.4.2 ad struct cpu_info *ci = curcpu();
55 1.2.4.2 ad
56 1.2.4.2 ad olevel = ci->ci_ilevel;
57 1.2.4.2 ad if (nlevel > olevel)
58 1.2.4.2 ad ci->ci_ilevel = nlevel;
59 1.2.4.2 ad __insn_barrier();
60 1.2.4.2 ad return (olevel);
61 1.2.4.2 ad }
62 1.2.4.2 ad
63 1.2.4.2 ad /*
64 1.2.4.2 ad * Restore a value to cpl (unmasking interrupts). If any unmasked
65 1.2.4.2 ad * interrupts are pending, call Xspllower() to process them.
66 1.2.4.2 ad */
67 1.2.4.2 ad void
68 1.2.4.2 ad spllower(int nlevel)
69 1.2.4.2 ad {
70 1.2.4.2 ad struct cpu_info *ci = curcpu();
71 1.2.4.2 ad u_int32_t imask;
72 1.2.4.2 ad u_long psl;
73 1.2.4.2 ad
74 1.2.4.2 ad __insn_barrier();
75 1.2.4.2 ad
76 1.2.4.2 ad imask = IUNMASK(ci, nlevel);
77 1.2.4.2 ad psl = x86_read_psl();
78 1.2.4.2 ad x86_disable_intr();
79 1.2.4.2 ad if (ci->ci_ipending & imask) {
80 1.2.4.2 ad Xspllower(nlevel);
81 1.2.4.2 ad /* Xspllower does enable_intr() */
82 1.2.4.2 ad } else {
83 1.2.4.2 ad ci->ci_ilevel = nlevel;
84 1.2.4.2 ad x86_write_psl(psl);
85 1.2.4.2 ad }
86 1.2.4.2 ad }
87 1.2.4.2 ad
88 1.2.4.2 ad #ifndef __x86_64__
89 1.2.4.2 ad
90 1.2.4.2 ad /*
91 1.2.4.2 ad * Software interrupt registration
92 1.2.4.2 ad *
93 1.2.4.2 ad * We hand-code this to ensure that it's atomic.
94 1.2.4.2 ad *
95 1.2.4.2 ad * XXX always scheduled on the current CPU.
96 1.2.4.2 ad */
97 1.2.4.2 ad void
98 1.2.4.2 ad softintr(int sir)
99 1.2.4.2 ad {
100 1.2.4.2 ad struct cpu_info *ci = curcpu();
101 1.2.4.2 ad
102 1.2.4.2 ad __asm volatile("orl %1, %0" : "=m"(ci->ci_ipending) : "ir" (1 << sir));
103 1.2.4.2 ad }
104 1.2.4.2 ad #endif
105 1.2.4.2 ad
106 1.2.4.2 ad void
107 1.2.4.2 ad x86_disable_intr(void)
108 1.2.4.2 ad {
109 1.2.4.2 ad __cli();
110 1.2.4.2 ad }
111 1.2.4.2 ad
112 1.2.4.2 ad void
113 1.2.4.2 ad x86_enable_intr(void)
114 1.2.4.2 ad {
115 1.2.4.2 ad __sti();
116 1.2.4.2 ad }
117 1.2.4.2 ad
118 1.2.4.2 ad u_long
119 1.2.4.2 ad x86_read_psl(void)
120 1.2.4.2 ad {
121 1.2.4.2 ad
122 1.2.4.2 ad return (HYPERVISOR_shared_info->vcpu_info[0].evtchn_upcall_mask);
123 1.2.4.2 ad }
124 1.2.4.2 ad
125 1.2.4.2 ad void
126 1.2.4.2 ad x86_write_psl(u_long psl)
127 1.2.4.2 ad {
128 1.2.4.2 ad
129 1.2.4.2 ad HYPERVISOR_shared_info->vcpu_info[0].evtchn_upcall_mask = psl;
130 1.2.4.2 ad x86_lfence();
131 1.2.4.2 ad if (HYPERVISOR_shared_info->vcpu_info[0].evtchn_upcall_pending &&
132 1.2.4.2 ad psl == 0) {
133 1.2.4.2 ad hypervisor_force_callback();
134 1.2.4.2 ad }
135 1.2.4.2 ad }
136 1.2.4.2 ad /* $NetBSD: xen_intr.c,v 1.2.4.2 2007/12/03 19:04:44 ad Exp $ */
137 1.2.4.2 ad
138 1.2.4.2 ad /*-
139 1.2.4.2 ad * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
140 1.2.4.2 ad * All rights reserved.
141 1.2.4.2 ad *
142 1.2.4.2 ad * This code is derived from software contributed to The NetBSD Foundation
143 1.2.4.2 ad * by Charles M. Hannum, and by Jason R. Thorpe.
144 1.2.4.2 ad *
145 1.2.4.2 ad * Redistribution and use in source and binary forms, with or without
146 1.2.4.2 ad * modification, are permitted provided that the following conditions
147 1.2.4.2 ad * are met:
148 1.2.4.2 ad * 1. Redistributions of source code must retain the above copyright
149 1.2.4.2 ad * notice, this list of conditions and the following disclaimer.
150 1.2.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
151 1.2.4.2 ad * notice, this list of conditions and the following disclaimer in the
152 1.2.4.2 ad * documentation and/or other materials provided with the distribution.
153 1.2.4.2 ad * 3. All advertising materials mentioning features or use of this software
154 1.2.4.2 ad * must display the following acknowledgement:
155 1.2.4.2 ad * This product includes software developed by the NetBSD
156 1.2.4.2 ad * Foundation, Inc. and its contributors.
157 1.2.4.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
158 1.2.4.2 ad * contributors may be used to endorse or promote products derived
159 1.2.4.2 ad * from this software without specific prior written permission.
160 1.2.4.2 ad *
161 1.2.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
162 1.2.4.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
163 1.2.4.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
164 1.2.4.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
165 1.2.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
166 1.2.4.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
167 1.2.4.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
168 1.2.4.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
169 1.2.4.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
170 1.2.4.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
171 1.2.4.2 ad * POSSIBILITY OF SUCH DAMAGE.
172 1.2.4.2 ad */
173 1.2.4.2 ad
174 1.2.4.2 ad #include <sys/cdefs.h>
175 1.2.4.2 ad __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.2.4.2 2007/12/03 19:04:44 ad Exp $");
176 1.2.4.2 ad
177 1.2.4.2 ad #include <sys/param.h>
178 1.2.4.2 ad
179 1.2.4.2 ad #include <machine/cpu.h>
180 1.2.4.2 ad #include <machine/intr.h>
181 1.2.4.2 ad
182 1.2.4.2 ad /*
183 1.2.4.2 ad * Add a mask to cpl, and return the old value of cpl.
184 1.2.4.2 ad */
185 1.2.4.2 ad int
186 1.2.4.2 ad splraise(int nlevel)
187 1.2.4.2 ad {
188 1.2.4.2 ad int olevel;
189 1.2.4.2 ad struct cpu_info *ci = curcpu();
190 1.2.4.2 ad
191 1.2.4.2 ad olevel = ci->ci_ilevel;
192 1.2.4.2 ad if (nlevel > olevel)
193 1.2.4.2 ad ci->ci_ilevel = nlevel;
194 1.2.4.2 ad __insn_barrier();
195 1.2.4.2 ad return (olevel);
196 1.2.4.2 ad }
197 1.2.4.2 ad
198 1.2.4.2 ad /*
199 1.2.4.2 ad * Restore a value to cpl (unmasking interrupts). If any unmasked
200 1.2.4.2 ad * interrupts are pending, call Xspllower() to process them.
201 1.2.4.2 ad */
202 1.2.4.2 ad void
203 1.2.4.2 ad spllower(int nlevel)
204 1.2.4.2 ad {
205 1.2.4.2 ad struct cpu_info *ci = curcpu();
206 1.2.4.2 ad u_int32_t imask;
207 1.2.4.2 ad u_long psl;
208 1.2.4.2 ad
209 1.2.4.2 ad __insn_barrier();
210 1.2.4.2 ad
211 1.2.4.2 ad imask = IUNMASK(ci, nlevel);
212 1.2.4.2 ad psl = x86_read_psl();
213 1.2.4.2 ad x86_disable_intr();
214 1.2.4.2 ad if (ci->ci_ipending & imask) {
215 1.2.4.2 ad Xspllower(nlevel);
216 1.2.4.2 ad /* Xspllower does enable_intr() */
217 1.2.4.2 ad } else {
218 1.2.4.2 ad ci->ci_ilevel = nlevel;
219 1.2.4.2 ad x86_write_psl(psl);
220 1.2.4.2 ad }
221 1.2.4.2 ad }
222 1.2.4.2 ad
223 1.2.4.2 ad #ifndef __x86_64__
224 1.2.4.2 ad
225 1.2.4.2 ad /*
226 1.2.4.2 ad * Software interrupt registration
227 1.2.4.2 ad *
228 1.2.4.2 ad * We hand-code this to ensure that it's atomic.
229 1.2.4.2 ad *
230 1.2.4.2 ad * XXX always scheduled on the current CPU.
231 1.2.4.2 ad */
232 1.2.4.2 ad void
233 1.2.4.2 ad softintr(int sir)
234 1.2.4.2 ad {
235 1.2.4.2 ad struct cpu_info *ci = curcpu();
236 1.2.4.2 ad
237 1.2.4.2 ad __asm volatile("orl %1, %0" : "=m"(ci->ci_ipending) : "ir" (1 << sir));
238 1.2.4.2 ad }
239 1.2.4.2 ad #endif
240 1.2.4.2 ad
241 1.2.4.2 ad void
242 1.2.4.2 ad x86_disable_intr(void)
243 1.2.4.2 ad {
244 1.2.4.2 ad __cli();
245 1.2.4.2 ad }
246 1.2.4.2 ad
247 1.2.4.2 ad void
248 1.2.4.2 ad x86_enable_intr(void)
249 1.2.4.2 ad {
250 1.2.4.2 ad __sti();
251 1.2.4.2 ad }
252 1.2.4.2 ad
253 1.2.4.2 ad u_long
254 1.2.4.2 ad x86_read_psl(void)
255 1.2.4.2 ad {
256 1.2.4.2 ad
257 1.2.4.2 ad return (HYPERVISOR_shared_info->vcpu_info[0].evtchn_upcall_mask);
258 1.2.4.2 ad }
259 1.2.4.2 ad
260 1.2.4.2 ad void
261 1.2.4.2 ad x86_write_psl(u_long psl)
262 1.2.4.2 ad {
263 1.2.4.2 ad
264 1.2.4.2 ad HYPERVISOR_shared_info->vcpu_info[0].evtchn_upcall_mask = psl;
265 1.2.4.2 ad x86_lfence();
266 1.2.4.2 ad if (HYPERVISOR_shared_info->vcpu_info[0].evtchn_upcall_pending &&
267 1.2.4.2 ad psl == 0) {
268 1.2.4.2 ad hypervisor_force_callback();
269 1.2.4.2 ad }
270 1.2.4.2 ad }
271