xen_intr.c revision 1.2.22.2 1 1.2 bouyer /* $NetBSD: xen_intr.c,v 1.2.22.2 2008/07/02 19:08:19 mjf 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.2 bouyer __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.2.22.2 2008/07/02 19:08:19 mjf 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.2.22.1 mjf uint32_t imask;
65 1.2 bouyer u_long psl;
66 1.2 bouyer
67 1.2.22.2 mjf if (ci->ci_ilevel <= nlevel)
68 1.2.22.2 mjf return;
69 1.2.22.2 mjf
70 1.2 bouyer __insn_barrier();
71 1.2 bouyer
72 1.2 bouyer imask = IUNMASK(ci, nlevel);
73 1.2 bouyer psl = x86_read_psl();
74 1.2 bouyer x86_disable_intr();
75 1.2 bouyer if (ci->ci_ipending & imask) {
76 1.2.22.1 mjf KASSERT(psl == 0);
77 1.2 bouyer Xspllower(nlevel);
78 1.2 bouyer /* Xspllower does enable_intr() */
79 1.2 bouyer } else {
80 1.2 bouyer ci->ci_ilevel = nlevel;
81 1.2 bouyer x86_write_psl(psl);
82 1.2 bouyer }
83 1.2 bouyer }
84 1.2 bouyer
85 1.2 bouyer void
86 1.2 bouyer x86_disable_intr(void)
87 1.2 bouyer {
88 1.2 bouyer __cli();
89 1.2 bouyer }
90 1.2 bouyer
91 1.2 bouyer void
92 1.2 bouyer x86_enable_intr(void)
93 1.2 bouyer {
94 1.2 bouyer __sti();
95 1.2 bouyer }
96 1.2 bouyer
97 1.2 bouyer u_long
98 1.2 bouyer x86_read_psl(void)
99 1.2 bouyer {
100 1.2 bouyer
101 1.2.22.1 mjf return (curcpu()->ci_vcpu->evtchn_upcall_mask);
102 1.2 bouyer }
103 1.2 bouyer
104 1.2 bouyer void
105 1.2 bouyer x86_write_psl(u_long psl)
106 1.2 bouyer {
107 1.2.22.1 mjf struct cpu_info *ci = curcpu();
108 1.2 bouyer
109 1.2.22.1 mjf ci->ci_vcpu->evtchn_upcall_mask = psl;
110 1.2 bouyer x86_lfence();
111 1.2.22.1 mjf if (ci->ci_vcpu->evtchn_upcall_pending && psl == 0) {
112 1.2 bouyer hypervisor_force_callback();
113 1.2 bouyer }
114 1.2 bouyer }
115