xen_intr.c revision 1.7 1 1.7 bouyer /* $NetBSD: xen_intr.c,v 1.7 2008/05/25 16:09:30 bouyer 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.7 bouyer __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.7 2008/05/25 16:09:30 bouyer 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.7 bouyer KASSERT(psl == 0);
74 1.2 bouyer Xspllower(nlevel);
75 1.2 bouyer /* Xspllower does enable_intr() */
76 1.2 bouyer } else {
77 1.2 bouyer ci->ci_ilevel = nlevel;
78 1.2 bouyer x86_write_psl(psl);
79 1.2 bouyer }
80 1.2 bouyer }
81 1.2 bouyer
82 1.2 bouyer void
83 1.2 bouyer x86_disable_intr(void)
84 1.2 bouyer {
85 1.2 bouyer __cli();
86 1.2 bouyer }
87 1.2 bouyer
88 1.2 bouyer void
89 1.2 bouyer x86_enable_intr(void)
90 1.2 bouyer {
91 1.2 bouyer __sti();
92 1.2 bouyer }
93 1.2 bouyer
94 1.2 bouyer u_long
95 1.2 bouyer x86_read_psl(void)
96 1.2 bouyer {
97 1.2 bouyer
98 1.4 cegger return (curcpu()->ci_vcpu->evtchn_upcall_mask);
99 1.2 bouyer }
100 1.2 bouyer
101 1.2 bouyer void
102 1.2 bouyer x86_write_psl(u_long psl)
103 1.2 bouyer {
104 1.4 cegger struct cpu_info *ci = curcpu();
105 1.2 bouyer
106 1.4 cegger ci->ci_vcpu->evtchn_upcall_mask = psl;
107 1.2 bouyer x86_lfence();
108 1.4 cegger if (ci->ci_vcpu->evtchn_upcall_pending && psl == 0) {
109 1.2 bouyer hypervisor_force_callback();
110 1.2 bouyer }
111 1.2 bouyer }
112