xen_intr.c revision 1.3.2.1 1 1.3.2.1 yamt /* $NetBSD: xen_intr.c,v 1.3.2.1 2008/05/18 12:33:08 yamt Exp $ */
2 1.2 bouyer
3 1.2 bouyer /*-
4 1.2 bouyer * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 1.2 bouyer * All rights reserved.
6 1.2 bouyer *
7 1.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.2 bouyer * by Charles M. Hannum, and by Jason R. Thorpe.
9 1.2 bouyer *
10 1.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2 bouyer * modification, are permitted provided that the following conditions
12 1.2 bouyer * are met:
13 1.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2 bouyer *
19 1.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
30 1.2 bouyer */
31 1.2 bouyer
32 1.2 bouyer #include <sys/cdefs.h>
33 1.3.2.1 yamt __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.3.2.1 2008/05/18 12:33:08 yamt Exp $");
34 1.2 bouyer
35 1.2 bouyer #include <sys/param.h>
36 1.2 bouyer
37 1.2 bouyer #include <machine/cpu.h>
38 1.2 bouyer #include <machine/intr.h>
39 1.2 bouyer
40 1.2 bouyer /*
41 1.2 bouyer * Add a mask to cpl, and return the old value of cpl.
42 1.2 bouyer */
43 1.2 bouyer int
44 1.2 bouyer splraise(int nlevel)
45 1.2 bouyer {
46 1.2 bouyer int olevel;
47 1.2 bouyer struct cpu_info *ci = curcpu();
48 1.2 bouyer
49 1.2 bouyer olevel = ci->ci_ilevel;
50 1.2 bouyer if (nlevel > olevel)
51 1.2 bouyer ci->ci_ilevel = nlevel;
52 1.2 bouyer __insn_barrier();
53 1.2 bouyer return (olevel);
54 1.2 bouyer }
55 1.2 bouyer
56 1.2 bouyer /*
57 1.2 bouyer * Restore a value to cpl (unmasking interrupts). If any unmasked
58 1.2 bouyer * interrupts are pending, call Xspllower() to process them.
59 1.2 bouyer */
60 1.2 bouyer void
61 1.2 bouyer spllower(int nlevel)
62 1.2 bouyer {
63 1.2 bouyer struct cpu_info *ci = curcpu();
64 1.3 cegger uint32_t imask;
65 1.2 bouyer u_long psl;
66 1.2 bouyer
67 1.2 bouyer __insn_barrier();
68 1.2 bouyer
69 1.2 bouyer imask = IUNMASK(ci, nlevel);
70 1.2 bouyer psl = x86_read_psl();
71 1.2 bouyer x86_disable_intr();
72 1.2 bouyer if (ci->ci_ipending & imask) {
73 1.2 bouyer Xspllower(nlevel);
74 1.2 bouyer /* Xspllower does enable_intr() */
75 1.2 bouyer } else {
76 1.2 bouyer ci->ci_ilevel = nlevel;
77 1.2 bouyer x86_write_psl(psl);
78 1.2 bouyer }
79 1.2 bouyer }
80 1.2 bouyer
81 1.2 bouyer #ifndef __x86_64__
82 1.2 bouyer
83 1.2 bouyer /*
84 1.2 bouyer * Software interrupt registration
85 1.2 bouyer *
86 1.2 bouyer * We hand-code this to ensure that it's atomic.
87 1.2 bouyer *
88 1.2 bouyer * XXX always scheduled on the current CPU.
89 1.2 bouyer */
90 1.2 bouyer void
91 1.2 bouyer softintr(int sir)
92 1.2 bouyer {
93 1.2 bouyer struct cpu_info *ci = curcpu();
94 1.2 bouyer
95 1.2 bouyer __asm volatile("orl %1, %0" : "=m"(ci->ci_ipending) : "ir" (1 << sir));
96 1.2 bouyer }
97 1.2 bouyer #endif
98 1.2 bouyer
99 1.2 bouyer void
100 1.2 bouyer x86_disable_intr(void)
101 1.2 bouyer {
102 1.2 bouyer __cli();
103 1.2 bouyer }
104 1.2 bouyer
105 1.2 bouyer void
106 1.2 bouyer x86_enable_intr(void)
107 1.2 bouyer {
108 1.2 bouyer __sti();
109 1.2 bouyer }
110 1.2 bouyer
111 1.2 bouyer u_long
112 1.2 bouyer x86_read_psl(void)
113 1.2 bouyer {
114 1.2 bouyer
115 1.3.2.1 yamt return (curcpu()->ci_vcpu->evtchn_upcall_mask);
116 1.2 bouyer }
117 1.2 bouyer
118 1.2 bouyer void
119 1.2 bouyer x86_write_psl(u_long psl)
120 1.2 bouyer {
121 1.3.2.1 yamt struct cpu_info *ci = curcpu();
122 1.2 bouyer
123 1.3.2.1 yamt ci->ci_vcpu->evtchn_upcall_mask = psl;
124 1.2 bouyer x86_lfence();
125 1.3.2.1 yamt if (ci->ci_vcpu->evtchn_upcall_pending && psl == 0) {
126 1.2 bouyer hypervisor_force_callback();
127 1.2 bouyer }
128 1.2 bouyer }
129