blob: 72f91bff29c7d836d86844c224225e1353c76648 [file] [log] [blame]
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -07001/*
2 * Xen event channels
3 *
4 * Xen models interrupts with abstract event channels. Because each
5 * domain gets 1024 event channels, but NR_IRQ is not that large, we
6 * must dynamically map irqs<->event channels. The event channels
7 * interface with the rest of the kernel by defining a xen interrupt
8 * chip. When an event is recieved, it is mapped to an irq and sent
9 * through the normal interrupt processing path.
10 *
11 * There are four kinds of events which can be mapped to an event
12 * channel:
13 *
14 * 1. Inter-domain notifications. This includes all the virtual
15 * device events, since they're driven by front-ends in another domain
16 * (typically dom0).
17 * 2. VIRQs, typically used for timers. These are per-cpu events.
18 * 3. IPIs.
19 * 4. Hardware interrupts. Not supported at present.
20 *
21 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
22 */
23
24#include <linux/linkage.h>
25#include <linux/interrupt.h>
26#include <linux/irq.h>
27#include <linux/module.h>
28#include <linux/string.h>
Christophe Saout28e08862009-01-11 11:46:23 -080029#include <linux/bootmem.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070031
Sheng Yang38e20b02010-05-14 12:40:51 +010032#include <asm/desc.h>
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070033#include <asm/ptrace.h>
34#include <asm/irq.h>
Jeremy Fitzhardinge792dc4f2009-02-06 14:09:43 -080035#include <asm/idle.h>
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070036#include <asm/sync_bitops.h>
37#include <asm/xen/hypercall.h>
Adrian Bunk8d1b8752007-07-20 00:31:44 -070038#include <asm/xen/hypervisor.h>
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070039
Sheng Yang38e20b02010-05-14 12:40:51 +010040#include <xen/xen.h>
41#include <xen/hvm.h>
Isaku Yamahatae04d0d02008-04-02 10:53:55 -070042#include <xen/xen-ops.h>
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070043#include <xen/events.h>
44#include <xen/interface/xen.h>
45#include <xen/interface/event_channel.h>
Sheng Yang38e20b02010-05-14 12:40:51 +010046#include <xen/interface/hvm/hvm_op.h>
47#include <xen/interface/hvm/params.h>
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070048
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070049/*
50 * This lock protects updates to the following mapping and reference-count
51 * arrays. The lock does not need to be acquired to read the mapping tables.
52 */
53static DEFINE_SPINLOCK(irq_mapping_update_lock);
54
55/* IRQ <-> VIRQ mapping. */
Tejun Heo204fba42009-06-24 15:13:45 +090056static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1};
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070057
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -070058/* IRQ <-> IPI mapping */
Tejun Heo204fba42009-06-24 15:13:45 +090059static DEFINE_PER_CPU(int [XEN_NR_IPIS], ipi_to_irq) = {[0 ... XEN_NR_IPIS-1] = -1};
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -070060
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -080061/* Interrupt types. */
62enum xen_irq_type {
Jeremy Fitzhardinged77bbd42009-02-06 14:09:45 -080063 IRQT_UNBOUND = 0,
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -070064 IRQT_PIRQ,
65 IRQT_VIRQ,
66 IRQT_IPI,
67 IRQT_EVTCHN
68};
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070069
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -080070/*
71 * Packed IRQ information:
72 * type - enum xen_irq_type
73 * event channel - irq->event channel mapping
74 * cpu - cpu this event channel is bound to
75 * index - type-specific information:
76 * PIRQ - vector, with MSB being "needs EIO"
77 * VIRQ - virq number
78 * IPI - IPI vector
79 * EVTCHN -
80 */
81struct irq_info
82{
83 enum xen_irq_type type; /* type */
84 unsigned short evtchn; /* event channel */
85 unsigned short cpu; /* cpu bound */
86
87 union {
88 unsigned short virq;
89 enum ipi_vector ipi;
90 struct {
91 unsigned short gsi;
92 unsigned short vector;
93 } pirq;
94 } u;
95};
96
97static struct irq_info irq_info[NR_IRQS];
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -070098
99static int evtchn_to_irq[NR_EVENT_CHANNELS] = {
100 [0 ... NR_EVENT_CHANNELS-1] = -1
101};
Mike Travisc7a35892009-01-10 21:58:11 -0800102struct cpu_evtchn_s {
103 unsigned long bits[NR_EVENT_CHANNELS/BITS_PER_LONG];
104};
105static struct cpu_evtchn_s *cpu_evtchn_mask_p;
106static inline unsigned long *cpu_evtchn_mask(int cpu)
107{
108 return cpu_evtchn_mask_p[cpu].bits;
109}
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700110
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700111/* Xen will never allocate port zero for any purpose. */
112#define VALID_EVTCHN(chn) ((chn) != 0)
113
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700114static struct irq_chip xen_dynamic_chip;
115
116/* Constructor for packed IRQ information. */
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800117static struct irq_info mk_unbound_info(void)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700118{
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800119 return (struct irq_info) { .type = IRQT_UNBOUND };
120}
121
122static struct irq_info mk_evtchn_info(unsigned short evtchn)
123{
Ian Campbell90af9512009-02-06 16:55:58 -0800124 return (struct irq_info) { .type = IRQT_EVTCHN, .evtchn = evtchn,
125 .cpu = 0 };
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800126}
127
128static struct irq_info mk_ipi_info(unsigned short evtchn, enum ipi_vector ipi)
129{
130 return (struct irq_info) { .type = IRQT_IPI, .evtchn = evtchn,
Ian Campbell90af9512009-02-06 16:55:58 -0800131 .cpu = 0, .u.ipi = ipi };
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800132}
133
134static struct irq_info mk_virq_info(unsigned short evtchn, unsigned short virq)
135{
136 return (struct irq_info) { .type = IRQT_VIRQ, .evtchn = evtchn,
Ian Campbell90af9512009-02-06 16:55:58 -0800137 .cpu = 0, .u.virq = virq };
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800138}
139
140static struct irq_info mk_pirq_info(unsigned short evtchn,
141 unsigned short gsi, unsigned short vector)
142{
143 return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn,
Ian Campbell90af9512009-02-06 16:55:58 -0800144 .cpu = 0, .u.pirq = { .gsi = gsi, .vector = vector } };
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700145}
146
147/*
148 * Accessors for packed IRQ information.
149 */
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800150static struct irq_info *info_for_irq(unsigned irq)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700151{
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800152 return &irq_info[irq];
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700153}
154
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800155static unsigned int evtchn_from_irq(unsigned irq)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700156{
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800157 return info_for_irq(irq)->evtchn;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700158}
159
Ian Campbelld4c04532009-02-06 19:20:31 -0800160unsigned irq_from_evtchn(unsigned int evtchn)
161{
162 return evtchn_to_irq[evtchn];
163}
164EXPORT_SYMBOL_GPL(irq_from_evtchn);
165
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800166static enum ipi_vector ipi_from_irq(unsigned irq)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700167{
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800168 struct irq_info *info = info_for_irq(irq);
169
170 BUG_ON(info == NULL);
171 BUG_ON(info->type != IRQT_IPI);
172
173 return info->u.ipi;
174}
175
176static unsigned virq_from_irq(unsigned irq)
177{
178 struct irq_info *info = info_for_irq(irq);
179
180 BUG_ON(info == NULL);
181 BUG_ON(info->type != IRQT_VIRQ);
182
183 return info->u.virq;
184}
185
186static unsigned gsi_from_irq(unsigned irq)
187{
188 struct irq_info *info = info_for_irq(irq);
189
190 BUG_ON(info == NULL);
191 BUG_ON(info->type != IRQT_PIRQ);
192
193 return info->u.pirq.gsi;
194}
195
196static unsigned vector_from_irq(unsigned irq)
197{
198 struct irq_info *info = info_for_irq(irq);
199
200 BUG_ON(info == NULL);
201 BUG_ON(info->type != IRQT_PIRQ);
202
203 return info->u.pirq.vector;
204}
205
206static enum xen_irq_type type_from_irq(unsigned irq)
207{
208 return info_for_irq(irq)->type;
209}
210
211static unsigned cpu_from_irq(unsigned irq)
212{
213 return info_for_irq(irq)->cpu;
214}
215
216static unsigned int cpu_from_evtchn(unsigned int evtchn)
217{
218 int irq = evtchn_to_irq[evtchn];
219 unsigned ret = 0;
220
221 if (irq != -1)
222 ret = cpu_from_irq(irq);
223
224 return ret;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700225}
226
227static inline unsigned long active_evtchns(unsigned int cpu,
228 struct shared_info *sh,
229 unsigned int idx)
230{
231 return (sh->evtchn_pending[idx] &
Mike Travisc7a35892009-01-10 21:58:11 -0800232 cpu_evtchn_mask(cpu)[idx] &
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700233 ~sh->evtchn_mask[idx]);
234}
235
236static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
237{
238 int irq = evtchn_to_irq[chn];
239
240 BUG_ON(irq == -1);
241#ifdef CONFIG_SMP
Mike Travis7f7ace02009-01-10 21:58:08 -0800242 cpumask_copy(irq_to_desc(irq)->affinity, cpumask_of(cpu));
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700243#endif
244
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800245 __clear_bit(chn, cpu_evtchn_mask(cpu_from_irq(irq)));
Mike Travisc7a35892009-01-10 21:58:11 -0800246 __set_bit(chn, cpu_evtchn_mask(cpu));
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700247
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800248 irq_info[irq].cpu = cpu;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700249}
250
251static void init_evtchn_cpu_bindings(void)
252{
253#ifdef CONFIG_SMP
Thomas Gleixner10e58082008-10-16 14:19:04 +0200254 struct irq_desc *desc;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700255 int i;
Thomas Gleixner10e58082008-10-16 14:19:04 +0200256
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700257 /* By default all event channels notify CPU#0. */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800258 for_each_irq_desc(i, desc) {
Mike Travis7f7ace02009-01-10 21:58:08 -0800259 cpumask_copy(desc->affinity, cpumask_of(0));
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800260 }
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700261#endif
262
Mike Travisc7a35892009-01-10 21:58:11 -0800263 memset(cpu_evtchn_mask(0), ~0, sizeof(cpu_evtchn_mask(0)));
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700264}
265
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700266static inline void clear_evtchn(int port)
267{
268 struct shared_info *s = HYPERVISOR_shared_info;
269 sync_clear_bit(port, &s->evtchn_pending[0]);
270}
271
272static inline void set_evtchn(int port)
273{
274 struct shared_info *s = HYPERVISOR_shared_info;
275 sync_set_bit(port, &s->evtchn_pending[0]);
276}
277
Jeremy Fitzhardinge168d2f42008-08-20 17:02:18 -0700278static inline int test_evtchn(int port)
279{
280 struct shared_info *s = HYPERVISOR_shared_info;
281 return sync_test_bit(port, &s->evtchn_pending[0]);
282}
283
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700284
285/**
286 * notify_remote_via_irq - send event to remote end of event channel via irq
287 * @irq: irq of event channel to send event to
288 *
289 * Unlike notify_remote_via_evtchn(), this is safe to use across
290 * save/restore. Notifications on a broken connection are silently
291 * dropped.
292 */
293void notify_remote_via_irq(int irq)
294{
295 int evtchn = evtchn_from_irq(irq);
296
297 if (VALID_EVTCHN(evtchn))
298 notify_remote_via_evtchn(evtchn);
299}
300EXPORT_SYMBOL_GPL(notify_remote_via_irq);
301
302static void mask_evtchn(int port)
303{
304 struct shared_info *s = HYPERVISOR_shared_info;
305 sync_set_bit(port, &s->evtchn_mask[0]);
306}
307
308static void unmask_evtchn(int port)
309{
310 struct shared_info *s = HYPERVISOR_shared_info;
311 unsigned int cpu = get_cpu();
312
313 BUG_ON(!irqs_disabled());
314
315 /* Slow path (hypercall) if this is a non-local port. */
316 if (unlikely(cpu != cpu_from_evtchn(port))) {
317 struct evtchn_unmask unmask = { .port = port };
318 (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask);
319 } else {
320 struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu);
321
322 sync_clear_bit(port, &s->evtchn_mask[0]);
323
324 /*
325 * The following is basically the equivalent of
326 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
327 * the interrupt edge' if the channel is masked.
328 */
329 if (sync_test_bit(port, &s->evtchn_pending[0]) &&
330 !sync_test_and_set_bit(port / BITS_PER_LONG,
331 &vcpu_info->evtchn_pending_sel))
332 vcpu_info->evtchn_upcall_pending = 1;
333 }
334
335 put_cpu();
336}
337
338static int find_unbound_irq(void)
339{
340 int irq;
Jeremy Fitzhardinge6f8a0ed2008-12-17 13:42:29 -0800341 struct irq_desc *desc;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700342
Stefano Stabellini99ad1982010-05-14 12:41:20 +0100343 for (irq = 0; irq < nr_irqs; irq++) {
344 desc = irq_to_desc(irq);
345 /* only 0->15 have init'd desc; handle irq > 16 */
346 if (desc == NULL)
347 break;
348 if (desc->chip == &no_irq_chip)
349 break;
350 if (desc->chip != &xen_dynamic_chip)
351 continue;
Jeremy Fitzhardinged77bbd42009-02-06 14:09:45 -0800352 if (irq_info[irq].type == IRQT_UNBOUND)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700353 break;
Stefano Stabellini99ad1982010-05-14 12:41:20 +0100354 }
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700355
Yinghai Lu5a15d7e2008-08-19 20:49:57 -0700356 if (irq == nr_irqs)
357 panic("No available IRQ to bind to: increase nr_irqs!\n");
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700358
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700359 desc = irq_to_desc_alloc_node(irq, 0);
Jeremy Fitzhardinge6f8a0ed2008-12-17 13:42:29 -0800360 if (WARN_ON(desc == NULL))
361 return -1;
362
Stefano Stabellini99ad1982010-05-14 12:41:20 +0100363 dynamic_irq_init_keep_chip_data(irq);
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800364
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700365 return irq;
366}
367
Jeremy Fitzhardingeb536b4b2007-07-17 18:37:06 -0700368int bind_evtchn_to_irq(unsigned int evtchn)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700369{
370 int irq;
371
372 spin_lock(&irq_mapping_update_lock);
373
374 irq = evtchn_to_irq[evtchn];
375
376 if (irq == -1) {
377 irq = find_unbound_irq();
378
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700379 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
380 handle_level_irq, "event");
381
382 evtchn_to_irq[evtchn] = irq;
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800383 irq_info[irq] = mk_evtchn_info(evtchn);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700384 }
385
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700386 spin_unlock(&irq_mapping_update_lock);
387
388 return irq;
389}
Jeremy Fitzhardingeb536b4b2007-07-17 18:37:06 -0700390EXPORT_SYMBOL_GPL(bind_evtchn_to_irq);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700391
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700392static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu)
393{
394 struct evtchn_bind_ipi bind_ipi;
395 int evtchn, irq;
396
397 spin_lock(&irq_mapping_update_lock);
398
399 irq = per_cpu(ipi_to_irq, cpu)[ipi];
Ian Campbell90af9512009-02-06 16:55:58 -0800400
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700401 if (irq == -1) {
402 irq = find_unbound_irq();
403 if (irq < 0)
404 goto out;
405
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700406 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
407 handle_level_irq, "ipi");
408
409 bind_ipi.vcpu = cpu;
410 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi,
411 &bind_ipi) != 0)
412 BUG();
413 evtchn = bind_ipi.port;
414
415 evtchn_to_irq[evtchn] = irq;
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800416 irq_info[irq] = mk_ipi_info(evtchn, ipi);
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700417 per_cpu(ipi_to_irq, cpu)[ipi] = irq;
418
419 bind_evtchn_to_cpu(evtchn, cpu);
420 }
421
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700422 out:
423 spin_unlock(&irq_mapping_update_lock);
424 return irq;
425}
426
427
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700428static int bind_virq_to_irq(unsigned int virq, unsigned int cpu)
429{
430 struct evtchn_bind_virq bind_virq;
431 int evtchn, irq;
432
433 spin_lock(&irq_mapping_update_lock);
434
435 irq = per_cpu(virq_to_irq, cpu)[virq];
436
437 if (irq == -1) {
438 bind_virq.virq = virq;
439 bind_virq.vcpu = cpu;
440 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
441 &bind_virq) != 0)
442 BUG();
443 evtchn = bind_virq.port;
444
445 irq = find_unbound_irq();
446
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700447 set_irq_chip_and_handler_name(irq, &xen_dynamic_chip,
448 handle_level_irq, "virq");
449
450 evtchn_to_irq[evtchn] = irq;
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800451 irq_info[irq] = mk_virq_info(evtchn, virq);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700452
453 per_cpu(virq_to_irq, cpu)[virq] = irq;
454
455 bind_evtchn_to_cpu(evtchn, cpu);
456 }
457
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700458 spin_unlock(&irq_mapping_update_lock);
459
460 return irq;
461}
462
463static void unbind_from_irq(unsigned int irq)
464{
465 struct evtchn_close close;
466 int evtchn = evtchn_from_irq(irq);
467
468 spin_lock(&irq_mapping_update_lock);
469
Jeremy Fitzhardinged77bbd42009-02-06 14:09:45 -0800470 if (VALID_EVTCHN(evtchn)) {
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700471 close.port = evtchn;
472 if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
473 BUG();
474
475 switch (type_from_irq(irq)) {
476 case IRQT_VIRQ:
477 per_cpu(virq_to_irq, cpu_from_evtchn(evtchn))
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800478 [virq_from_irq(irq)] = -1;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700479 break;
Alex Nixond68d82a2008-08-22 11:52:15 +0100480 case IRQT_IPI:
481 per_cpu(ipi_to_irq, cpu_from_evtchn(evtchn))
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800482 [ipi_from_irq(irq)] = -1;
Alex Nixond68d82a2008-08-22 11:52:15 +0100483 break;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700484 default:
485 break;
486 }
487
488 /* Closed ports are implicitly re-bound to VCPU0. */
489 bind_evtchn_to_cpu(evtchn, 0);
490
491 evtchn_to_irq[evtchn] = -1;
Ian Campbellfed5ea82009-12-01 16:15:30 +0000492 }
493
494 if (irq_info[irq].type != IRQT_UNBOUND) {
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800495 irq_info[irq] = mk_unbound_info();
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700496
Jeremy Fitzhardinge0f2287a2008-05-26 23:31:24 +0100497 dynamic_irq_cleanup(irq);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700498 }
499
500 spin_unlock(&irq_mapping_update_lock);
501}
502
503int bind_evtchn_to_irqhandler(unsigned int evtchn,
Jeff Garzik7c239972007-10-19 03:12:20 -0400504 irq_handler_t handler,
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700505 unsigned long irqflags,
506 const char *devname, void *dev_id)
507{
508 unsigned int irq;
509 int retval;
510
511 irq = bind_evtchn_to_irq(evtchn);
512 retval = request_irq(irq, handler, irqflags, devname, dev_id);
513 if (retval != 0) {
514 unbind_from_irq(irq);
515 return retval;
516 }
517
518 return irq;
519}
520EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler);
521
522int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu,
Jeff Garzik7c239972007-10-19 03:12:20 -0400523 irq_handler_t handler,
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700524 unsigned long irqflags, const char *devname, void *dev_id)
525{
526 unsigned int irq;
527 int retval;
528
529 irq = bind_virq_to_irq(virq, cpu);
530 retval = request_irq(irq, handler, irqflags, devname, dev_id);
531 if (retval != 0) {
532 unbind_from_irq(irq);
533 return retval;
534 }
535
536 return irq;
537}
538EXPORT_SYMBOL_GPL(bind_virq_to_irqhandler);
539
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700540int bind_ipi_to_irqhandler(enum ipi_vector ipi,
541 unsigned int cpu,
542 irq_handler_t handler,
543 unsigned long irqflags,
544 const char *devname,
545 void *dev_id)
546{
547 int irq, retval;
548
549 irq = bind_ipi_to_irq(ipi, cpu);
550 if (irq < 0)
551 return irq;
552
Ian Campbell4877c732010-07-29 11:16:35 +0100553 irqflags |= IRQF_NO_SUSPEND;
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700554 retval = request_irq(irq, handler, irqflags, devname, dev_id);
555 if (retval != 0) {
556 unbind_from_irq(irq);
557 return retval;
558 }
559
560 return irq;
561}
562
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700563void unbind_from_irqhandler(unsigned int irq, void *dev_id)
564{
565 free_irq(irq, dev_id);
566 unbind_from_irq(irq);
567}
568EXPORT_SYMBOL_GPL(unbind_from_irqhandler);
569
Jeremy Fitzhardingef87e4ca2007-07-17 18:37:06 -0700570void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)
571{
572 int irq = per_cpu(ipi_to_irq, cpu)[vector];
573 BUG_ON(irq < 0);
574 notify_remote_via_irq(irq);
575}
576
Jeremy Fitzhardingeee523ca2008-03-17 16:37:18 -0700577irqreturn_t xen_debug_interrupt(int irq, void *dev_id)
578{
579 struct shared_info *sh = HYPERVISOR_shared_info;
580 int cpu = smp_processor_id();
581 int i;
582 unsigned long flags;
583 static DEFINE_SPINLOCK(debug_lock);
584
585 spin_lock_irqsave(&debug_lock, flags);
586
587 printk("vcpu %d\n ", cpu);
588
589 for_each_online_cpu(i) {
590 struct vcpu_info *v = per_cpu(xen_vcpu, i);
591 printk("%d: masked=%d pending=%d event_sel %08lx\n ", i,
Isaku Yamahatae849c3e2008-04-02 10:53:56 -0700592 (get_irq_regs() && i == cpu) ? xen_irqs_disabled(get_irq_regs()) : v->evtchn_upcall_mask,
Jeremy Fitzhardingeee523ca2008-03-17 16:37:18 -0700593 v->evtchn_upcall_pending,
594 v->evtchn_pending_sel);
595 }
596 printk("pending:\n ");
597 for(i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--)
598 printk("%08lx%s", sh->evtchn_pending[i],
599 i % 8 == 0 ? "\n " : " ");
600 printk("\nmasks:\n ");
601 for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
602 printk("%08lx%s", sh->evtchn_mask[i],
603 i % 8 == 0 ? "\n " : " ");
604
605 printk("\nunmasked:\n ");
606 for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--)
607 printk("%08lx%s", sh->evtchn_pending[i] & ~sh->evtchn_mask[i],
608 i % 8 == 0 ? "\n " : " ");
609
610 printk("\npending list:\n");
611 for(i = 0; i < NR_EVENT_CHANNELS; i++) {
612 if (sync_test_bit(i, sh->evtchn_pending)) {
613 printk(" %d: event %d -> irq %d\n",
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800614 cpu_from_evtchn(i), i,
615 evtchn_to_irq[i]);
Jeremy Fitzhardingeee523ca2008-03-17 16:37:18 -0700616 }
617 }
618
619 spin_unlock_irqrestore(&debug_lock, flags);
620
621 return IRQ_HANDLED;
622}
623
Tejun Heo245b2e72009-06-24 15:13:48 +0900624static DEFINE_PER_CPU(unsigned, xed_nesting_count);
625
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700626/*
627 * Search the CPUs pending events bitmasks. For each one found, map
628 * the event number to an irq, and feed it into do_IRQ() for
629 * handling.
630 *
631 * Xen uses a two-level bitmap to speed searching. The first level is
632 * a bitset of words which contain pending event bits. The second
633 * level is a bitset of pending events themselves.
634 */
Sheng Yang38e20b02010-05-14 12:40:51 +0100635static void __xen_evtchn_do_upcall(void)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700636{
637 int cpu = get_cpu();
638 struct shared_info *s = HYPERVISOR_shared_info;
639 struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu);
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700640 unsigned count;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700641
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700642 do {
643 unsigned long pending_words;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700644
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700645 vcpu_info->evtchn_upcall_pending = 0;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700646
Tejun Heo245b2e72009-06-24 15:13:48 +0900647 if (__get_cpu_var(xed_nesting_count)++)
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700648 goto out;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700649
Isaku Yamahatae849c3e2008-04-02 10:53:56 -0700650#ifndef CONFIG_X86 /* No need for a barrier -- XCHG is a barrier on x86. */
651 /* Clear master flag /before/ clearing selector flag. */
Isaku Yamahata6673cf62008-06-16 14:58:13 -0700652 wmb();
Isaku Yamahatae849c3e2008-04-02 10:53:56 -0700653#endif
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700654 pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0);
655 while (pending_words != 0) {
656 unsigned long pending_bits;
657 int word_idx = __ffs(pending_words);
658 pending_words &= ~(1UL << word_idx);
659
660 while ((pending_bits = active_evtchns(cpu, s, word_idx)) != 0) {
661 int bit_idx = __ffs(pending_bits);
662 int port = (word_idx * BITS_PER_LONG) + bit_idx;
663 int irq = evtchn_to_irq[port];
Eric W. Biedermanca4dbc62010-02-17 18:49:54 -0800664 struct irq_desc *desc;
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700665
Eric W. Biedermanca4dbc62010-02-17 18:49:54 -0800666 if (irq != -1) {
667 desc = irq_to_desc(irq);
668 if (desc)
669 generic_handle_irq_desc(irq, desc);
670 }
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700671 }
672 }
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700673
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700674 BUG_ON(!irqs_disabled());
675
Tejun Heo245b2e72009-06-24 15:13:48 +0900676 count = __get_cpu_var(xed_nesting_count);
677 __get_cpu_var(xed_nesting_count) = 0;
Stefano Stabellini183d03c2010-05-17 17:08:21 +0100678 } while (count != 1 || vcpu_info->evtchn_upcall_pending);
Jeremy Fitzhardinge229664b2008-03-17 16:37:20 -0700679
680out:
Jeremy Fitzhardinge3445a8f2009-02-06 14:09:46 -0800681
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700682 put_cpu();
683}
684
Sheng Yang38e20b02010-05-14 12:40:51 +0100685void xen_evtchn_do_upcall(struct pt_regs *regs)
686{
687 struct pt_regs *old_regs = set_irq_regs(regs);
688
689 exit_idle();
690 irq_enter();
691
692 __xen_evtchn_do_upcall();
693
694 irq_exit();
695 set_irq_regs(old_regs);
696}
697
698void xen_hvm_evtchn_do_upcall(void)
699{
700 __xen_evtchn_do_upcall();
701}
Stefano Stabellini183d03c2010-05-17 17:08:21 +0100702EXPORT_SYMBOL_GPL(xen_hvm_evtchn_do_upcall);
Sheng Yang38e20b02010-05-14 12:40:51 +0100703
Jeremy Fitzhardingeeb1e3052008-05-26 23:31:23 +0100704/* Rebind a new event channel to an existing irq. */
705void rebind_evtchn_irq(int evtchn, int irq)
706{
Jeremy Fitzhardinged77bbd42009-02-06 14:09:45 -0800707 struct irq_info *info = info_for_irq(irq);
708
Jeremy Fitzhardingeeb1e3052008-05-26 23:31:23 +0100709 /* Make sure the irq is masked, since the new event channel
710 will also be masked. */
711 disable_irq(irq);
712
713 spin_lock(&irq_mapping_update_lock);
714
715 /* After resume the irq<->evtchn mappings are all cleared out */
716 BUG_ON(evtchn_to_irq[evtchn] != -1);
717 /* Expect irq to have been bound before,
Jeremy Fitzhardinged77bbd42009-02-06 14:09:45 -0800718 so there should be a proper type */
719 BUG_ON(info->type == IRQT_UNBOUND);
Jeremy Fitzhardingeeb1e3052008-05-26 23:31:23 +0100720
721 evtchn_to_irq[evtchn] = irq;
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800722 irq_info[irq] = mk_evtchn_info(evtchn);
Jeremy Fitzhardingeeb1e3052008-05-26 23:31:23 +0100723
724 spin_unlock(&irq_mapping_update_lock);
725
726 /* new event channels are always bound to cpu 0 */
Rusty Russell0de26522008-12-13 21:20:26 +1030727 irq_set_affinity(irq, cpumask_of(0));
Jeremy Fitzhardingeeb1e3052008-05-26 23:31:23 +0100728
729 /* Unmask the event channel. */
730 enable_irq(irq);
731}
732
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700733/* Rebind an evtchn so that it gets delivered to a specific cpu */
Yinghai Lud5dedd42009-04-27 17:59:21 -0700734static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700735{
736 struct evtchn_bind_vcpu bind_vcpu;
737 int evtchn = evtchn_from_irq(irq);
738
Stefano Stabellini183d03c2010-05-17 17:08:21 +0100739 /* events delivered via platform PCI interrupts are always
740 * routed to vcpu 0 */
741 if (!VALID_EVTCHN(evtchn) ||
742 (xen_hvm_domain() && !xen_have_vector_callback))
Yinghai Lud5dedd42009-04-27 17:59:21 -0700743 return -1;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700744
745 /* Send future instances of this interrupt to other vcpu. */
746 bind_vcpu.port = evtchn;
747 bind_vcpu.vcpu = tcpu;
748
749 /*
750 * If this fails, it usually just indicates that we're dealing with a
751 * virq or IPI channel, which don't actually need to be rebound. Ignore
752 * it, but don't do the xenlinux-level rebind in that case.
753 */
754 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0)
755 bind_evtchn_to_cpu(evtchn, tcpu);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700756
757 return 0;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700758}
759
Yinghai Lud5dedd42009-04-27 17:59:21 -0700760static int set_affinity_irq(unsigned irq, const struct cpumask *dest)
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700761{
Rusty Russell0de26522008-12-13 21:20:26 +1030762 unsigned tcpu = cpumask_first(dest);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700763
764 return rebind_irq_to_cpu(irq, tcpu);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700765}
766
Isaku Yamahata642e0c82008-04-02 10:53:57 -0700767int resend_irq_on_evtchn(unsigned int irq)
768{
769 int masked, evtchn = evtchn_from_irq(irq);
770 struct shared_info *s = HYPERVISOR_shared_info;
771
772 if (!VALID_EVTCHN(evtchn))
773 return 1;
774
775 masked = sync_test_and_set_bit(evtchn, s->evtchn_mask);
776 sync_set_bit(evtchn, s->evtchn_pending);
777 if (!masked)
778 unmask_evtchn(evtchn);
779
780 return 1;
781}
782
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700783static void enable_dynirq(unsigned int irq)
784{
785 int evtchn = evtchn_from_irq(irq);
786
787 if (VALID_EVTCHN(evtchn))
788 unmask_evtchn(evtchn);
789}
790
791static void disable_dynirq(unsigned int irq)
792{
793 int evtchn = evtchn_from_irq(irq);
794
795 if (VALID_EVTCHN(evtchn))
796 mask_evtchn(evtchn);
797}
798
799static void ack_dynirq(unsigned int irq)
800{
801 int evtchn = evtchn_from_irq(irq);
802
803 move_native_irq(irq);
804
805 if (VALID_EVTCHN(evtchn))
806 clear_evtchn(evtchn);
807}
808
809static int retrigger_dynirq(unsigned int irq)
810{
811 int evtchn = evtchn_from_irq(irq);
Jeremy Fitzhardingeee8fa1c2008-03-17 16:37:19 -0700812 struct shared_info *sh = HYPERVISOR_shared_info;
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700813 int ret = 0;
814
815 if (VALID_EVTCHN(evtchn)) {
Jeremy Fitzhardingeee8fa1c2008-03-17 16:37:19 -0700816 int masked;
817
818 masked = sync_test_and_set_bit(evtchn, sh->evtchn_mask);
819 sync_set_bit(evtchn, sh->evtchn_pending);
820 if (!masked)
821 unmask_evtchn(evtchn);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700822 ret = 1;
823 }
824
825 return ret;
826}
827
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100828static void restore_cpu_virqs(unsigned int cpu)
829{
830 struct evtchn_bind_virq bind_virq;
831 int virq, irq, evtchn;
832
833 for (virq = 0; virq < NR_VIRQS; virq++) {
834 if ((irq = per_cpu(virq_to_irq, cpu)[virq]) == -1)
835 continue;
836
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800837 BUG_ON(virq_from_irq(irq) != virq);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100838
839 /* Get a new binding from Xen. */
840 bind_virq.virq = virq;
841 bind_virq.vcpu = cpu;
842 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq,
843 &bind_virq) != 0)
844 BUG();
845 evtchn = bind_virq.port;
846
847 /* Record the new mapping. */
848 evtchn_to_irq[evtchn] = irq;
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800849 irq_info[irq] = mk_virq_info(evtchn, virq);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100850 bind_evtchn_to_cpu(evtchn, cpu);
851
852 /* Ready for use. */
853 unmask_evtchn(evtchn);
854 }
855}
856
857static void restore_cpu_ipis(unsigned int cpu)
858{
859 struct evtchn_bind_ipi bind_ipi;
860 int ipi, irq, evtchn;
861
862 for (ipi = 0; ipi < XEN_NR_IPIS; ipi++) {
863 if ((irq = per_cpu(ipi_to_irq, cpu)[ipi]) == -1)
864 continue;
865
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800866 BUG_ON(ipi_from_irq(irq) != ipi);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100867
868 /* Get a new binding from Xen. */
869 bind_ipi.vcpu = cpu;
870 if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi,
871 &bind_ipi) != 0)
872 BUG();
873 evtchn = bind_ipi.port;
874
875 /* Record the new mapping. */
876 evtchn_to_irq[evtchn] = irq;
Jeremy Fitzhardingeced40d02009-02-06 14:09:44 -0800877 irq_info[irq] = mk_ipi_info(evtchn, ipi);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100878 bind_evtchn_to_cpu(evtchn, cpu);
879
880 /* Ready for use. */
881 unmask_evtchn(evtchn);
882
883 }
884}
885
Jeremy Fitzhardinge2d9e1e22008-07-07 12:07:53 -0700886/* Clear an irq's pending state, in preparation for polling on it */
887void xen_clear_irq_pending(int irq)
888{
889 int evtchn = evtchn_from_irq(irq);
890
891 if (VALID_EVTCHN(evtchn))
892 clear_evtchn(evtchn);
893}
894
Jeremy Fitzhardinge168d2f42008-08-20 17:02:18 -0700895void xen_set_irq_pending(int irq)
896{
897 int evtchn = evtchn_from_irq(irq);
898
899 if (VALID_EVTCHN(evtchn))
900 set_evtchn(evtchn);
901}
902
903bool xen_test_irq_pending(int irq)
904{
905 int evtchn = evtchn_from_irq(irq);
906 bool ret = false;
907
908 if (VALID_EVTCHN(evtchn))
909 ret = test_evtchn(evtchn);
910
911 return ret;
912}
913
Jeremy Fitzhardinge2d9e1e22008-07-07 12:07:53 -0700914/* Poll waiting for an irq to become pending. In the usual case, the
915 irq will be disabled so it won't deliver an interrupt. */
916void xen_poll_irq(int irq)
917{
918 evtchn_port_t evtchn = evtchn_from_irq(irq);
919
920 if (VALID_EVTCHN(evtchn)) {
921 struct sched_poll poll;
922
923 poll.nr_ports = 1;
924 poll.timeout = 0;
Isaku Yamahataff3c5362008-10-14 17:50:44 -0700925 set_xen_guest_handle(poll.ports, &evtchn);
Jeremy Fitzhardinge2d9e1e22008-07-07 12:07:53 -0700926
927 if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0)
928 BUG();
929 }
930}
931
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100932void xen_irq_resume(void)
933{
934 unsigned int cpu, irq, evtchn;
935
936 init_evtchn_cpu_bindings();
937
938 /* New event-channel space is not 'live' yet. */
939 for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
940 mask_evtchn(evtchn);
941
942 /* No IRQ <-> event-channel mappings. */
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800943 for (irq = 0; irq < nr_irqs; irq++)
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +0100944 irq_info[irq].evtchn = 0; /* zap event-channel binding */
945
946 for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++)
947 evtchn_to_irq[evtchn] = -1;
948
949 for_each_possible_cpu(cpu) {
950 restore_cpu_virqs(cpu);
951 restore_cpu_ipis(cpu);
952 }
953}
954
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700955static struct irq_chip xen_dynamic_chip __read_mostly = {
956 .name = "xen-dyn",
Jeremy Fitzhardinge54a353a2009-02-06 14:09:42 -0800957
958 .disable = disable_dynirq,
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700959 .mask = disable_dynirq,
960 .unmask = enable_dynirq,
Jeremy Fitzhardinge54a353a2009-02-06 14:09:42 -0800961
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -0700962 .ack = ack_dynirq,
963 .set_affinity = set_affinity_irq,
964 .retrigger = retrigger_dynirq,
965};
966
Sheng Yang38e20b02010-05-14 12:40:51 +0100967int xen_set_callback_via(uint64_t via)
968{
969 struct xen_hvm_param a;
970 a.domid = DOMID_SELF;
971 a.index = HVM_PARAM_CALLBACK_IRQ;
972 a.value = via;
973 return HYPERVISOR_hvm_op(HVMOP_set_param, &a);
974}
975EXPORT_SYMBOL_GPL(xen_set_callback_via);
976
Stefano Stabellinica65f9f2010-07-29 14:37:48 +0100977#ifdef CONFIG_XEN_PVHVM
Sheng Yang38e20b02010-05-14 12:40:51 +0100978/* Vector callbacks are better than PCI interrupts to receive event
979 * channel notifications because we can receive vector callbacks on any
980 * vcpu and we don't need PCI support or APIC interactions. */
981void xen_callback_vector(void)
982{
983 int rc;
984 uint64_t callback_via;
985 if (xen_have_vector_callback) {
986 callback_via = HVM_CALLBACK_VECTOR(XEN_HVM_EVTCHN_CALLBACK);
987 rc = xen_set_callback_via(callback_via);
988 if (rc) {
989 printk(KERN_ERR "Request for Xen HVM callback vector"
990 " failed.\n");
991 xen_have_vector_callback = 0;
992 return;
993 }
994 printk(KERN_INFO "Xen HVM callback vector for event delivery is "
995 "enabled\n");
996 /* in the restore case the vector has already been allocated */
997 if (!test_bit(XEN_HVM_EVTCHN_CALLBACK, used_vectors))
998 alloc_intr_gate(XEN_HVM_EVTCHN_CALLBACK, xen_hvm_callback_vector);
999 }
1000}
Stefano Stabellinica65f9f2010-07-29 14:37:48 +01001001#else
1002void xen_callback_vector(void) {}
1003#endif
Sheng Yang38e20b02010-05-14 12:40:51 +01001004
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -07001005void __init xen_init_IRQ(void)
1006{
1007 int i;
Mike Travisc7a35892009-01-10 21:58:11 -08001008
Pekka Enberga70c3522009-07-01 11:51:18 +03001009 cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s),
1010 GFP_KERNEL);
Christophe Saout28e08862009-01-11 11:46:23 -08001011 BUG_ON(cpu_evtchn_mask_p == NULL);
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -07001012
1013 init_evtchn_cpu_bindings();
1014
1015 /* No event channels are 'live' right now. */
1016 for (i = 0; i < NR_EVENT_CHANNELS; i++)
1017 mask_evtchn(i);
1018
Sheng Yang38e20b02010-05-14 12:40:51 +01001019 if (xen_hvm_domain()) {
1020 xen_callback_vector();
1021 native_init_IRQ();
1022 } else {
1023 irq_ctx_init(smp_processor_id());
1024 }
Jeremy Fitzhardingee46cdb62007-07-17 18:37:05 -07001025}