ia64/xen-unstable

view unmodified_drivers/linux-2.6/platform-pci/evtchn.c @ 12460:22e58b2b0b45

[IA64] warning fix

These are pulled in through the ACPI header now

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author awilliam@xenbuild.aw
date Sun Oct 29 09:27:26 2006 -0700 (2006-10-29)
parents 206e20b7b54e
children 79a40acadb41
line source
1 /******************************************************************************
2 * evtchn.c
3 *
4 * A simplified event channel for para-drivers in unmodified linux
5 *
6 * Copyright (c) 2002-2005, K A Fraser
7 * Copyright (c) 2005, Intel Corporation <xiaofeng.ling@intel.com>
8 *
9 * This file may be distributed separately from the Linux kernel, or
10 * incorporated into other software packages, subject to the following license:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this source file (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use, copy, modify,
15 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16 * and to permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
31 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
34 #include <xen/evtchn.h>
35 #include <xen/interface/hvm/ioreq.h>
36 #include <xen/features.h>
37 #include "platform-pci.h"
39 #ifdef HAVE_XEN_PLATFORM_COMPAT_H
40 #include <xen/platform-compat.h>
41 #endif
43 void *shared_info_area;
45 #define MAX_EVTCHN 256
46 static struct
47 {
48 irqreturn_t(*handler) (int, void *, struct pt_regs *);
49 void *dev_id;
50 } evtchns[MAX_EVTCHN];
52 void mask_evtchn(int port)
53 {
54 shared_info_t *s = shared_info_area;
55 synch_set_bit(port, &s->evtchn_mask[0]);
56 }
57 EXPORT_SYMBOL(mask_evtchn);
59 void unmask_evtchn(int port)
60 {
61 unsigned int cpu;
62 shared_info_t *s = shared_info_area;
63 vcpu_info_t *vcpu_info;
65 preempt_disable();
66 cpu = smp_processor_id();
67 vcpu_info = &s->vcpu_info[cpu];
69 /* Slow path (hypercall) if this is a non-local port. We only
70 ever bind event channels to vcpu 0 in HVM guests. */
71 if (unlikely(cpu != 0)) {
72 evtchn_unmask_t op = { .port = port };
73 (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask,
74 &op);
75 preempt_enable();
76 return;
77 }
79 synch_clear_bit(port, &s->evtchn_mask[0]);
81 /*
82 * The following is basically the equivalent of
83 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose the
84 * interrupt edge' if the channel is masked.
85 */
86 if (synch_test_bit(port, &s->evtchn_pending[0]) &&
87 !synch_test_and_set_bit(port / BITS_PER_LONG,
88 &vcpu_info->evtchn_pending_sel)) {
89 vcpu_info->evtchn_upcall_pending = 1;
90 if (!vcpu_info->evtchn_upcall_mask)
91 force_evtchn_callback();
92 }
93 preempt_enable();
94 }
95 EXPORT_SYMBOL(unmask_evtchn);
97 int
98 bind_evtchn_to_irqhandler(unsigned int evtchn,
99 irqreturn_t(*handler) (int, void *,
100 struct pt_regs *),
101 unsigned long irqflags, const char *devname,
102 void *dev_id)
103 {
104 if (evtchn >= MAX_EVTCHN)
105 return -EINVAL;
106 evtchns[evtchn].handler = handler;
107 evtchns[evtchn].dev_id = dev_id;
108 unmask_evtchn(evtchn);
109 return evtchn;
110 }
112 EXPORT_SYMBOL(bind_evtchn_to_irqhandler);
114 void unbind_from_irqhandler(unsigned int evtchn, void *dev_id)
115 {
116 if (evtchn >= MAX_EVTCHN)
117 return;
119 mask_evtchn(evtchn);
120 evtchns[evtchn].handler = NULL;
121 }
123 EXPORT_SYMBOL(unbind_from_irqhandler);
125 void notify_remote_via_irq(int irq)
126 {
127 int evtchn = irq;
128 notify_remote_via_evtchn(evtchn);
129 }
131 EXPORT_SYMBOL(notify_remote_via_irq);
133 irqreturn_t evtchn_interrupt(int irq, void *dev_id, struct pt_regs *regs)
134 {
135 unsigned int l1i, l2i, port;
136 int cpu = smp_processor_id();
137 irqreturn_t(*handler) (int, void *, struct pt_regs *);
138 shared_info_t *s = shared_info_area;
139 vcpu_info_t *v = &s->vcpu_info[cpu];
140 unsigned long l1, l2;
142 v->evtchn_upcall_pending = 0;
143 /* NB. No need for a barrier here -- XCHG is a barrier
144 * on x86. */
145 l1 = xchg(&v->evtchn_pending_sel, 0);
146 while (l1 != 0)
147 {
148 l1i = __ffs(l1);
149 l1 &= ~(1 << l1i);
151 l2 = s->evtchn_pending[l1i] & ~s->evtchn_mask[l1i];
152 while (l2 != 0)
153 {
154 l2i = __ffs(l2);
156 port = (l1i * BITS_PER_LONG) + l2i;
157 synch_clear_bit(port, &s->evtchn_pending[0]);
158 if ((handler = evtchns[port].handler) != NULL)
159 {
160 handler(port, evtchns[port].dev_id,
161 regs);
162 }
163 else
164 {
165 printk(KERN_WARNING "unexpected event channel upcall on port %d!\n", port);
166 }
167 l2 = s->evtchn_pending[l1i] & ~s->evtchn_mask[l1i];
168 }
169 }
170 return IRQ_HANDLED;
171 }
173 void force_evtchn_callback(void)
174 {
175 evtchn_interrupt(0, NULL, NULL);
176 }
177 EXPORT_SYMBOL(force_evtchn_callback);