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