Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1 | /* |
| 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. |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 19 | * 4. PIRQs - Hardware interrupts. |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 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 Saout | 28e0886 | 2009-01-11 11:46:23 -0800 | [diff] [blame] | 29 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jeremy Fitzhardinge | b21ddbf | 2010-06-07 16:28:49 -0400 | [diff] [blame] | 31 | #include <linux/irqnr.h> |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 32 | |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 33 | #include <asm/desc.h> |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 34 | #include <asm/ptrace.h> |
| 35 | #include <asm/irq.h> |
Jeremy Fitzhardinge | 792dc4f | 2009-02-06 14:09:43 -0800 | [diff] [blame] | 36 | #include <asm/idle.h> |
Konrad Rzeszutek Wilk | 0794bfc | 2010-10-18 10:41:08 -0400 | [diff] [blame] | 37 | #include <asm/io_apic.h> |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 38 | #include <asm/sync_bitops.h> |
| 39 | #include <asm/xen/hypercall.h> |
Adrian Bunk | 8d1b875 | 2007-07-20 00:31:44 -0700 | [diff] [blame] | 40 | #include <asm/xen/hypervisor.h> |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 41 | |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 42 | #include <xen/xen.h> |
| 43 | #include <xen/hvm.h> |
Isaku Yamahata | e04d0d0 | 2008-04-02 10:53:55 -0700 | [diff] [blame] | 44 | #include <xen/xen-ops.h> |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 45 | #include <xen/events.h> |
| 46 | #include <xen/interface/xen.h> |
| 47 | #include <xen/interface/event_channel.h> |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 48 | #include <xen/interface/hvm/hvm_op.h> |
| 49 | #include <xen/interface/hvm/params.h> |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 50 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 51 | /* |
| 52 | * This lock protects updates to the following mapping and reference-count |
| 53 | * arrays. The lock does not need to be acquired to read the mapping tables. |
| 54 | */ |
| 55 | static DEFINE_SPINLOCK(irq_mapping_update_lock); |
| 56 | |
| 57 | /* IRQ <-> VIRQ mapping. */ |
Tejun Heo | 204fba4 | 2009-06-24 15:13:45 +0900 | [diff] [blame] | 58 | static DEFINE_PER_CPU(int [NR_VIRQS], virq_to_irq) = {[0 ... NR_VIRQS-1] = -1}; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 59 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 60 | /* IRQ <-> IPI mapping */ |
Tejun Heo | 204fba4 | 2009-06-24 15:13:45 +0900 | [diff] [blame] | 61 | static DEFINE_PER_CPU(int [XEN_NR_IPIS], ipi_to_irq) = {[0 ... XEN_NR_IPIS-1] = -1}; |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 62 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 63 | /* Interrupt types. */ |
| 64 | enum xen_irq_type { |
Jeremy Fitzhardinge | d77bbd4 | 2009-02-06 14:09:45 -0800 | [diff] [blame] | 65 | IRQT_UNBOUND = 0, |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 66 | IRQT_PIRQ, |
| 67 | IRQT_VIRQ, |
| 68 | IRQT_IPI, |
| 69 | IRQT_EVTCHN |
| 70 | }; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 71 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 72 | /* |
| 73 | * Packed IRQ information: |
| 74 | * type - enum xen_irq_type |
| 75 | * event channel - irq->event channel mapping |
| 76 | * cpu - cpu this event channel is bound to |
| 77 | * index - type-specific information: |
| 78 | * PIRQ - vector, with MSB being "needs EIO" |
| 79 | * VIRQ - virq number |
| 80 | * IPI - IPI vector |
| 81 | * EVTCHN - |
| 82 | */ |
| 83 | struct irq_info |
| 84 | { |
| 85 | enum xen_irq_type type; /* type */ |
| 86 | unsigned short evtchn; /* event channel */ |
| 87 | unsigned short cpu; /* cpu bound */ |
| 88 | |
| 89 | union { |
| 90 | unsigned short virq; |
| 91 | enum ipi_vector ipi; |
| 92 | struct { |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 93 | unsigned short pirq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 94 | unsigned short gsi; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 95 | unsigned char vector; |
| 96 | unsigned char flags; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 97 | } pirq; |
| 98 | } u; |
| 99 | }; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 100 | #define PIRQ_NEEDS_EOI (1 << 0) |
Konrad Rzeszutek Wilk | 15ebbb8 | 2010-10-04 13:43:27 -0400 | [diff] [blame] | 101 | #define PIRQ_SHAREABLE (1 << 1) |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 102 | |
Jeremy Fitzhardinge | b21ddbf | 2010-06-07 16:28:49 -0400 | [diff] [blame] | 103 | static struct irq_info *irq_info; |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 104 | static int *pirq_to_irq; |
Stefano Stabellini | 01557ba | 2010-08-20 14:46:52 +0100 | [diff] [blame^] | 105 | static int nr_pirqs; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 106 | |
Jeremy Fitzhardinge | b21ddbf | 2010-06-07 16:28:49 -0400 | [diff] [blame] | 107 | static int *evtchn_to_irq; |
Mike Travis | c7a3589 | 2009-01-10 21:58:11 -0800 | [diff] [blame] | 108 | struct cpu_evtchn_s { |
| 109 | unsigned long bits[NR_EVENT_CHANNELS/BITS_PER_LONG]; |
| 110 | }; |
Jeremy Fitzhardinge | 3b32f57 | 2009-08-13 12:50:37 -0700 | [diff] [blame] | 111 | |
| 112 | static __initdata struct cpu_evtchn_s init_evtchn_mask = { |
| 113 | .bits[0 ... (NR_EVENT_CHANNELS/BITS_PER_LONG)-1] = ~0ul, |
| 114 | }; |
| 115 | static struct cpu_evtchn_s *cpu_evtchn_mask_p = &init_evtchn_mask; |
| 116 | |
Mike Travis | c7a3589 | 2009-01-10 21:58:11 -0800 | [diff] [blame] | 117 | static inline unsigned long *cpu_evtchn_mask(int cpu) |
| 118 | { |
| 119 | return cpu_evtchn_mask_p[cpu].bits; |
| 120 | } |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 121 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 122 | /* Xen will never allocate port zero for any purpose. */ |
| 123 | #define VALID_EVTCHN(chn) ((chn) != 0) |
| 124 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 125 | static struct irq_chip xen_dynamic_chip; |
Jeremy Fitzhardinge | aaca496 | 2010-08-20 18:57:53 -0700 | [diff] [blame] | 126 | static struct irq_chip xen_percpu_chip; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 127 | static struct irq_chip xen_pirq_chip; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 128 | |
| 129 | /* Constructor for packed IRQ information. */ |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 130 | static struct irq_info mk_unbound_info(void) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 131 | { |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 132 | return (struct irq_info) { .type = IRQT_UNBOUND }; |
| 133 | } |
| 134 | |
| 135 | static struct irq_info mk_evtchn_info(unsigned short evtchn) |
| 136 | { |
Ian Campbell | 90af951 | 2009-02-06 16:55:58 -0800 | [diff] [blame] | 137 | return (struct irq_info) { .type = IRQT_EVTCHN, .evtchn = evtchn, |
| 138 | .cpu = 0 }; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static struct irq_info mk_ipi_info(unsigned short evtchn, enum ipi_vector ipi) |
| 142 | { |
| 143 | return (struct irq_info) { .type = IRQT_IPI, .evtchn = evtchn, |
Ian Campbell | 90af951 | 2009-02-06 16:55:58 -0800 | [diff] [blame] | 144 | .cpu = 0, .u.ipi = ipi }; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static struct irq_info mk_virq_info(unsigned short evtchn, unsigned short virq) |
| 148 | { |
| 149 | return (struct irq_info) { .type = IRQT_VIRQ, .evtchn = evtchn, |
Ian Campbell | 90af951 | 2009-02-06 16:55:58 -0800 | [diff] [blame] | 150 | .cpu = 0, .u.virq = virq }; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 153 | static struct irq_info mk_pirq_info(unsigned short evtchn, unsigned short pirq, |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 154 | unsigned short gsi, unsigned short vector) |
| 155 | { |
| 156 | return (struct irq_info) { .type = IRQT_PIRQ, .evtchn = evtchn, |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 157 | .cpu = 0, |
| 158 | .u.pirq = { .pirq = pirq, .gsi = gsi, .vector = vector } }; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Accessors for packed IRQ information. |
| 163 | */ |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 164 | static struct irq_info *info_for_irq(unsigned irq) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 165 | { |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 166 | return &irq_info[irq]; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 169 | static unsigned int evtchn_from_irq(unsigned irq) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 170 | { |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 171 | return info_for_irq(irq)->evtchn; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Ian Campbell | d4c0453 | 2009-02-06 19:20:31 -0800 | [diff] [blame] | 174 | unsigned irq_from_evtchn(unsigned int evtchn) |
| 175 | { |
| 176 | return evtchn_to_irq[evtchn]; |
| 177 | } |
| 178 | EXPORT_SYMBOL_GPL(irq_from_evtchn); |
| 179 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 180 | static enum ipi_vector ipi_from_irq(unsigned irq) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 181 | { |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 182 | struct irq_info *info = info_for_irq(irq); |
| 183 | |
| 184 | BUG_ON(info == NULL); |
| 185 | BUG_ON(info->type != IRQT_IPI); |
| 186 | |
| 187 | return info->u.ipi; |
| 188 | } |
| 189 | |
| 190 | static unsigned virq_from_irq(unsigned irq) |
| 191 | { |
| 192 | struct irq_info *info = info_for_irq(irq); |
| 193 | |
| 194 | BUG_ON(info == NULL); |
| 195 | BUG_ON(info->type != IRQT_VIRQ); |
| 196 | |
| 197 | return info->u.virq; |
| 198 | } |
| 199 | |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 200 | static unsigned pirq_from_irq(unsigned irq) |
| 201 | { |
| 202 | struct irq_info *info = info_for_irq(irq); |
| 203 | |
| 204 | BUG_ON(info == NULL); |
| 205 | BUG_ON(info->type != IRQT_PIRQ); |
| 206 | |
| 207 | return info->u.pirq.pirq; |
| 208 | } |
| 209 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 210 | static unsigned gsi_from_irq(unsigned irq) |
| 211 | { |
| 212 | struct irq_info *info = info_for_irq(irq); |
| 213 | |
| 214 | BUG_ON(info == NULL); |
| 215 | BUG_ON(info->type != IRQT_PIRQ); |
| 216 | |
| 217 | return info->u.pirq.gsi; |
| 218 | } |
| 219 | |
| 220 | static unsigned vector_from_irq(unsigned irq) |
| 221 | { |
| 222 | struct irq_info *info = info_for_irq(irq); |
| 223 | |
| 224 | BUG_ON(info == NULL); |
| 225 | BUG_ON(info->type != IRQT_PIRQ); |
| 226 | |
| 227 | return info->u.pirq.vector; |
| 228 | } |
| 229 | |
| 230 | static enum xen_irq_type type_from_irq(unsigned irq) |
| 231 | { |
| 232 | return info_for_irq(irq)->type; |
| 233 | } |
| 234 | |
| 235 | static unsigned cpu_from_irq(unsigned irq) |
| 236 | { |
| 237 | return info_for_irq(irq)->cpu; |
| 238 | } |
| 239 | |
| 240 | static unsigned int cpu_from_evtchn(unsigned int evtchn) |
| 241 | { |
| 242 | int irq = evtchn_to_irq[evtchn]; |
| 243 | unsigned ret = 0; |
| 244 | |
| 245 | if (irq != -1) |
| 246 | ret = cpu_from_irq(irq); |
| 247 | |
| 248 | return ret; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 251 | static bool pirq_needs_eoi(unsigned irq) |
| 252 | { |
| 253 | struct irq_info *info = info_for_irq(irq); |
| 254 | |
| 255 | BUG_ON(info->type != IRQT_PIRQ); |
| 256 | |
| 257 | return info->u.pirq.flags & PIRQ_NEEDS_EOI; |
| 258 | } |
| 259 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 260 | static inline unsigned long active_evtchns(unsigned int cpu, |
| 261 | struct shared_info *sh, |
| 262 | unsigned int idx) |
| 263 | { |
| 264 | return (sh->evtchn_pending[idx] & |
Mike Travis | c7a3589 | 2009-01-10 21:58:11 -0800 | [diff] [blame] | 265 | cpu_evtchn_mask(cpu)[idx] & |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 266 | ~sh->evtchn_mask[idx]); |
| 267 | } |
| 268 | |
| 269 | static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu) |
| 270 | { |
| 271 | int irq = evtchn_to_irq[chn]; |
| 272 | |
| 273 | BUG_ON(irq == -1); |
| 274 | #ifdef CONFIG_SMP |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 275 | cpumask_copy(irq_to_desc(irq)->affinity, cpumask_of(cpu)); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 276 | #endif |
| 277 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 278 | __clear_bit(chn, cpu_evtchn_mask(cpu_from_irq(irq))); |
Mike Travis | c7a3589 | 2009-01-10 21:58:11 -0800 | [diff] [blame] | 279 | __set_bit(chn, cpu_evtchn_mask(cpu)); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 280 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 281 | irq_info[irq].cpu = cpu; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void init_evtchn_cpu_bindings(void) |
| 285 | { |
| 286 | #ifdef CONFIG_SMP |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame] | 287 | struct irq_desc *desc; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 288 | int i; |
Thomas Gleixner | 10e5808 | 2008-10-16 14:19:04 +0200 | [diff] [blame] | 289 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 290 | /* By default all event channels notify CPU#0. */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 291 | for_each_irq_desc(i, desc) { |
Mike Travis | 7f7ace0 | 2009-01-10 21:58:08 -0800 | [diff] [blame] | 292 | cpumask_copy(desc->affinity, cpumask_of(0)); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 293 | } |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 294 | #endif |
| 295 | |
Mike Travis | c7a3589 | 2009-01-10 21:58:11 -0800 | [diff] [blame] | 296 | memset(cpu_evtchn_mask(0), ~0, sizeof(cpu_evtchn_mask(0))); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 299 | static inline void clear_evtchn(int port) |
| 300 | { |
| 301 | struct shared_info *s = HYPERVISOR_shared_info; |
| 302 | sync_clear_bit(port, &s->evtchn_pending[0]); |
| 303 | } |
| 304 | |
| 305 | static inline void set_evtchn(int port) |
| 306 | { |
| 307 | struct shared_info *s = HYPERVISOR_shared_info; |
| 308 | sync_set_bit(port, &s->evtchn_pending[0]); |
| 309 | } |
| 310 | |
Jeremy Fitzhardinge | 168d2f4 | 2008-08-20 17:02:18 -0700 | [diff] [blame] | 311 | static inline int test_evtchn(int port) |
| 312 | { |
| 313 | struct shared_info *s = HYPERVISOR_shared_info; |
| 314 | return sync_test_bit(port, &s->evtchn_pending[0]); |
| 315 | } |
| 316 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 317 | |
| 318 | /** |
| 319 | * notify_remote_via_irq - send event to remote end of event channel via irq |
| 320 | * @irq: irq of event channel to send event to |
| 321 | * |
| 322 | * Unlike notify_remote_via_evtchn(), this is safe to use across |
| 323 | * save/restore. Notifications on a broken connection are silently |
| 324 | * dropped. |
| 325 | */ |
| 326 | void notify_remote_via_irq(int irq) |
| 327 | { |
| 328 | int evtchn = evtchn_from_irq(irq); |
| 329 | |
| 330 | if (VALID_EVTCHN(evtchn)) |
| 331 | notify_remote_via_evtchn(evtchn); |
| 332 | } |
| 333 | EXPORT_SYMBOL_GPL(notify_remote_via_irq); |
| 334 | |
| 335 | static void mask_evtchn(int port) |
| 336 | { |
| 337 | struct shared_info *s = HYPERVISOR_shared_info; |
| 338 | sync_set_bit(port, &s->evtchn_mask[0]); |
| 339 | } |
| 340 | |
| 341 | static void unmask_evtchn(int port) |
| 342 | { |
| 343 | struct shared_info *s = HYPERVISOR_shared_info; |
| 344 | unsigned int cpu = get_cpu(); |
| 345 | |
| 346 | BUG_ON(!irqs_disabled()); |
| 347 | |
| 348 | /* Slow path (hypercall) if this is a non-local port. */ |
| 349 | if (unlikely(cpu != cpu_from_evtchn(port))) { |
| 350 | struct evtchn_unmask unmask = { .port = port }; |
| 351 | (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask); |
| 352 | } else { |
| 353 | struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu); |
| 354 | |
| 355 | sync_clear_bit(port, &s->evtchn_mask[0]); |
| 356 | |
| 357 | /* |
| 358 | * The following is basically the equivalent of |
| 359 | * 'hw_resend_irq'. Just like a real IO-APIC we 'lose |
| 360 | * the interrupt edge' if the channel is masked. |
| 361 | */ |
| 362 | if (sync_test_bit(port, &s->evtchn_pending[0]) && |
| 363 | !sync_test_and_set_bit(port / BITS_PER_LONG, |
| 364 | &vcpu_info->evtchn_pending_sel)) |
| 365 | vcpu_info->evtchn_upcall_pending = 1; |
| 366 | } |
| 367 | |
| 368 | put_cpu(); |
| 369 | } |
| 370 | |
Konrad Rzeszutek Wilk | 0794bfc | 2010-10-18 10:41:08 -0400 | [diff] [blame] | 371 | static int get_nr_hw_irqs(void) |
| 372 | { |
| 373 | int ret = 1; |
| 374 | |
| 375 | #ifdef CONFIG_X86_IO_APIC |
| 376 | ret = get_nr_irqs_gsi(); |
| 377 | #endif |
| 378 | |
| 379 | return ret; |
| 380 | } |
| 381 | |
Stefano Stabellini | 01557ba | 2010-08-20 14:46:52 +0100 | [diff] [blame^] | 382 | /* callers of this function should make sure that PHYSDEVOP_get_nr_pirqs |
| 383 | * succeeded otherwise nr_pirqs won't hold the right value */ |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 384 | static int find_unbound_pirq(void) |
| 385 | { |
| 386 | int i; |
Stefano Stabellini | 01557ba | 2010-08-20 14:46:52 +0100 | [diff] [blame^] | 387 | for (i = nr_pirqs-1; i >= 0; i--) { |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 388 | if (pirq_to_irq[i] < 0) |
| 389 | return i; |
| 390 | } |
| 391 | return -1; |
| 392 | } |
| 393 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 394 | static int find_unbound_irq(void) |
| 395 | { |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 396 | struct irq_data *data; |
| 397 | int irq, res; |
Konrad Rzeszutek Wilk | 3a69e91 | 2010-10-18 10:49:10 -0400 | [diff] [blame] | 398 | int start = get_nr_hw_irqs(); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 399 | |
Konrad Rzeszutek Wilk | 3a69e91 | 2010-10-18 10:49:10 -0400 | [diff] [blame] | 400 | if (start == nr_irqs) |
| 401 | goto no_irqs; |
| 402 | |
| 403 | /* nr_irqs is a magic value. Must not use it.*/ |
| 404 | for (irq = nr_irqs-1; irq > start; irq--) { |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 405 | data = irq_get_irq_data(irq); |
Stefano Stabellini | 99ad198 | 2010-05-14 12:41:20 +0100 | [diff] [blame] | 406 | /* only 0->15 have init'd desc; handle irq > 16 */ |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 407 | if (!data) |
Stefano Stabellini | 99ad198 | 2010-05-14 12:41:20 +0100 | [diff] [blame] | 408 | break; |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 409 | if (data->chip == &no_irq_chip) |
Stefano Stabellini | 99ad198 | 2010-05-14 12:41:20 +0100 | [diff] [blame] | 410 | break; |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 411 | if (data->chip != &xen_dynamic_chip) |
Stefano Stabellini | 99ad198 | 2010-05-14 12:41:20 +0100 | [diff] [blame] | 412 | continue; |
Jeremy Fitzhardinge | d77bbd4 | 2009-02-06 14:09:45 -0800 | [diff] [blame] | 413 | if (irq_info[irq].type == IRQT_UNBOUND) |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 414 | return irq; |
Stefano Stabellini | 99ad198 | 2010-05-14 12:41:20 +0100 | [diff] [blame] | 415 | } |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 416 | |
Konrad Rzeszutek Wilk | 3a69e91 | 2010-10-18 10:49:10 -0400 | [diff] [blame] | 417 | if (irq == start) |
| 418 | goto no_irqs; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 419 | |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 420 | res = irq_alloc_desc_at(irq, 0); |
Jeremy Fitzhardinge | 6f8a0ed | 2008-12-17 13:42:29 -0800 | [diff] [blame] | 421 | |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 422 | if (WARN_ON(res != irq)) |
| 423 | return -1; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 424 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 425 | return irq; |
Konrad Rzeszutek Wilk | 3a69e91 | 2010-10-18 10:49:10 -0400 | [diff] [blame] | 426 | |
| 427 | no_irqs: |
| 428 | panic("No available IRQ to bind to: increase nr_irqs!\n"); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 431 | static bool identity_mapped_irq(unsigned irq) |
| 432 | { |
Konrad Rzeszutek Wilk | 0794bfc | 2010-10-18 10:41:08 -0400 | [diff] [blame] | 433 | /* identity map all the hardware irqs */ |
| 434 | return irq < get_nr_hw_irqs(); |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | static void pirq_unmask_notify(int irq) |
| 438 | { |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 439 | struct physdev_eoi eoi = { .irq = pirq_from_irq(irq) }; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 440 | |
| 441 | if (unlikely(pirq_needs_eoi(irq))) { |
| 442 | int rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); |
| 443 | WARN_ON(rc); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | static void pirq_query_unmask(int irq) |
| 448 | { |
| 449 | struct physdev_irq_status_query irq_status; |
| 450 | struct irq_info *info = info_for_irq(irq); |
| 451 | |
| 452 | BUG_ON(info->type != IRQT_PIRQ); |
| 453 | |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 454 | irq_status.irq = pirq_from_irq(irq); |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 455 | if (HYPERVISOR_physdev_op(PHYSDEVOP_irq_status_query, &irq_status)) |
| 456 | irq_status.flags = 0; |
| 457 | |
| 458 | info->u.pirq.flags &= ~PIRQ_NEEDS_EOI; |
| 459 | if (irq_status.flags & XENIRQSTAT_needs_eoi) |
| 460 | info->u.pirq.flags |= PIRQ_NEEDS_EOI; |
| 461 | } |
| 462 | |
| 463 | static bool probing_irq(int irq) |
| 464 | { |
| 465 | struct irq_desc *desc = irq_to_desc(irq); |
| 466 | |
| 467 | return desc && desc->action == NULL; |
| 468 | } |
| 469 | |
| 470 | static unsigned int startup_pirq(unsigned int irq) |
| 471 | { |
| 472 | struct evtchn_bind_pirq bind_pirq; |
| 473 | struct irq_info *info = info_for_irq(irq); |
| 474 | int evtchn = evtchn_from_irq(irq); |
Konrad Rzeszutek Wilk | 15ebbb8 | 2010-10-04 13:43:27 -0400 | [diff] [blame] | 475 | int rc; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 476 | |
| 477 | BUG_ON(info->type != IRQT_PIRQ); |
| 478 | |
| 479 | if (VALID_EVTCHN(evtchn)) |
| 480 | goto out; |
| 481 | |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 482 | bind_pirq.pirq = pirq_from_irq(irq); |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 483 | /* NB. We are happy to share unless we are probing. */ |
Konrad Rzeszutek Wilk | 15ebbb8 | 2010-10-04 13:43:27 -0400 | [diff] [blame] | 484 | bind_pirq.flags = info->u.pirq.flags & PIRQ_SHAREABLE ? |
| 485 | BIND_PIRQ__WILL_SHARE : 0; |
| 486 | rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq); |
| 487 | if (rc != 0) { |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 488 | if (!probing_irq(irq)) |
| 489 | printk(KERN_INFO "Failed to obtain physical IRQ %d\n", |
| 490 | irq); |
| 491 | return 0; |
| 492 | } |
| 493 | evtchn = bind_pirq.port; |
| 494 | |
| 495 | pirq_query_unmask(irq); |
| 496 | |
| 497 | evtchn_to_irq[evtchn] = irq; |
| 498 | bind_evtchn_to_cpu(evtchn, 0); |
| 499 | info->evtchn = evtchn; |
| 500 | |
| 501 | out: |
| 502 | unmask_evtchn(evtchn); |
| 503 | pirq_unmask_notify(irq); |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static void shutdown_pirq(unsigned int irq) |
| 509 | { |
| 510 | struct evtchn_close close; |
| 511 | struct irq_info *info = info_for_irq(irq); |
| 512 | int evtchn = evtchn_from_irq(irq); |
| 513 | |
| 514 | BUG_ON(info->type != IRQT_PIRQ); |
| 515 | |
| 516 | if (!VALID_EVTCHN(evtchn)) |
| 517 | return; |
| 518 | |
| 519 | mask_evtchn(evtchn); |
| 520 | |
| 521 | close.port = evtchn; |
| 522 | if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0) |
| 523 | BUG(); |
| 524 | |
| 525 | bind_evtchn_to_cpu(evtchn, 0); |
| 526 | evtchn_to_irq[evtchn] = -1; |
| 527 | info->evtchn = 0; |
| 528 | } |
| 529 | |
| 530 | static void enable_pirq(unsigned int irq) |
| 531 | { |
| 532 | startup_pirq(irq); |
| 533 | } |
| 534 | |
| 535 | static void disable_pirq(unsigned int irq) |
| 536 | { |
| 537 | } |
| 538 | |
| 539 | static void ack_pirq(unsigned int irq) |
| 540 | { |
| 541 | int evtchn = evtchn_from_irq(irq); |
| 542 | |
| 543 | move_native_irq(irq); |
| 544 | |
| 545 | if (VALID_EVTCHN(evtchn)) { |
| 546 | mask_evtchn(evtchn); |
| 547 | clear_evtchn(evtchn); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static void end_pirq(unsigned int irq) |
| 552 | { |
| 553 | int evtchn = evtchn_from_irq(irq); |
| 554 | struct irq_desc *desc = irq_to_desc(irq); |
| 555 | |
| 556 | if (WARN_ON(!desc)) |
| 557 | return; |
| 558 | |
| 559 | if ((desc->status & (IRQ_DISABLED|IRQ_PENDING)) == |
| 560 | (IRQ_DISABLED|IRQ_PENDING)) { |
| 561 | shutdown_pirq(irq); |
| 562 | } else if (VALID_EVTCHN(evtchn)) { |
| 563 | unmask_evtchn(evtchn); |
| 564 | pirq_unmask_notify(irq); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static int find_irq_by_gsi(unsigned gsi) |
| 569 | { |
| 570 | int irq; |
| 571 | |
Jeremy Fitzhardinge | b21ddbf | 2010-06-07 16:28:49 -0400 | [diff] [blame] | 572 | for (irq = 0; irq < nr_irqs; irq++) { |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 573 | struct irq_info *info = info_for_irq(irq); |
| 574 | |
| 575 | if (info == NULL || info->type != IRQT_PIRQ) |
| 576 | continue; |
| 577 | |
| 578 | if (gsi_from_irq(irq) == gsi) |
| 579 | return irq; |
| 580 | } |
| 581 | |
| 582 | return -1; |
| 583 | } |
| 584 | |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 585 | int xen_allocate_pirq(unsigned gsi, int shareable, char *name) |
| 586 | { |
| 587 | return xen_map_pirq_gsi(gsi, gsi, shareable, name); |
| 588 | } |
| 589 | |
| 590 | /* xen_map_pirq_gsi might allocate irqs from the top down, as a |
Konrad Rzeszutek Wilk | 3a69e91 | 2010-10-18 10:49:10 -0400 | [diff] [blame] | 591 | * consequence don't assume that the irq number returned has a low value |
| 592 | * or can be used as a pirq number unless you know otherwise. |
| 593 | * |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 594 | * One notable exception is when xen_map_pirq_gsi is called passing an |
Konrad Rzeszutek Wilk | 3a69e91 | 2010-10-18 10:49:10 -0400 | [diff] [blame] | 595 | * hardware gsi as argument, in that case the irq number returned |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 596 | * matches the gsi number passed as second argument. |
| 597 | * |
| 598 | * Note: We don't assign an event channel until the irq actually started |
| 599 | * up. Return an existing irq if we've already got one for the gsi. |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 600 | */ |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 601 | int xen_map_pirq_gsi(unsigned pirq, unsigned gsi, int shareable, char *name) |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 602 | { |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 603 | int irq = 0; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 604 | struct physdev_irq irq_op; |
| 605 | |
| 606 | spin_lock(&irq_mapping_update_lock); |
| 607 | |
Stefano Stabellini | 01557ba | 2010-08-20 14:46:52 +0100 | [diff] [blame^] | 608 | if ((pirq > nr_pirqs) || (gsi > nr_irqs)) { |
| 609 | printk(KERN_WARNING "xen_map_pirq_gsi: %s %s is incorrect!\n", |
| 610 | pirq > nr_pirqs ? "nr_pirqs" :"", |
| 611 | gsi > nr_irqs ? "nr_irqs" : ""); |
| 612 | goto out; |
| 613 | } |
| 614 | |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 615 | irq = find_irq_by_gsi(gsi); |
| 616 | if (irq != -1) { |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 617 | printk(KERN_INFO "xen_map_pirq_gsi: returning irq %d for gsi %u\n", |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 618 | irq, gsi); |
| 619 | goto out; /* XXX need refcount? */ |
| 620 | } |
| 621 | |
Alex Nixon | b5401a9 | 2010-03-18 16:31:34 -0400 | [diff] [blame] | 622 | /* If we are a PV guest, we don't have GSIs (no ACPI passed). Therefore |
| 623 | * we are using the !xen_initial_domain() to drop in the function.*/ |
| 624 | if (identity_mapped_irq(gsi) || !xen_initial_domain()) { |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 625 | irq = gsi; |
Konrad Rzeszutek Wilk | 2c52f8d | 2010-10-18 17:11:10 -0400 | [diff] [blame] | 626 | irq_alloc_desc_at(irq, 0); |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 627 | } else |
| 628 | irq = find_unbound_irq(); |
| 629 | |
| 630 | set_irq_chip_and_handler_name(irq, &xen_pirq_chip, |
Gerd Hoffmann | 1a60d05 | 2010-10-04 13:42:27 -0400 | [diff] [blame] | 631 | handle_level_irq, name); |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 632 | |
| 633 | irq_op.irq = irq; |
Alex Nixon | b5401a9 | 2010-03-18 16:31:34 -0400 | [diff] [blame] | 634 | irq_op.vector = 0; |
| 635 | |
| 636 | /* Only the privileged domain can do this. For non-priv, the pcifront |
| 637 | * driver provides a PCI bus that does the call to do exactly |
| 638 | * this in the priv domain. */ |
| 639 | if (xen_initial_domain() && |
| 640 | HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector, &irq_op)) { |
Konrad Rzeszutek Wilk | 2c52f8d | 2010-10-18 17:11:10 -0400 | [diff] [blame] | 641 | irq_free_desc(irq); |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 642 | irq = -ENOSPC; |
| 643 | goto out; |
| 644 | } |
| 645 | |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 646 | irq_info[irq] = mk_pirq_info(0, pirq, gsi, irq_op.vector); |
Konrad Rzeszutek Wilk | 15ebbb8 | 2010-10-04 13:43:27 -0400 | [diff] [blame] | 647 | irq_info[irq].u.pirq.flags |= shareable ? PIRQ_SHAREABLE : 0; |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 648 | pirq_to_irq[pirq] = irq; |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 649 | |
| 650 | out: |
| 651 | spin_unlock(&irq_mapping_update_lock); |
| 652 | |
| 653 | return irq; |
| 654 | } |
| 655 | |
Alex Nixon | b5401a9 | 2010-03-18 16:31:34 -0400 | [diff] [blame] | 656 | int xen_destroy_irq(int irq) |
| 657 | { |
| 658 | struct irq_desc *desc; |
| 659 | int rc = -ENOENT; |
| 660 | |
| 661 | spin_lock(&irq_mapping_update_lock); |
| 662 | |
| 663 | desc = irq_to_desc(irq); |
| 664 | if (!desc) |
| 665 | goto out; |
| 666 | |
| 667 | irq_info[irq] = mk_unbound_info(); |
| 668 | |
Konrad Rzeszutek Wilk | 2c52f8d | 2010-10-18 17:11:10 -0400 | [diff] [blame] | 669 | irq_free_desc(irq); |
Alex Nixon | b5401a9 | 2010-03-18 16:31:34 -0400 | [diff] [blame] | 670 | |
| 671 | out: |
| 672 | spin_unlock(&irq_mapping_update_lock); |
| 673 | return rc; |
| 674 | } |
| 675 | |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 676 | int xen_vector_from_irq(unsigned irq) |
| 677 | { |
| 678 | return vector_from_irq(irq); |
| 679 | } |
| 680 | |
| 681 | int xen_gsi_from_irq(unsigned irq) |
| 682 | { |
| 683 | return gsi_from_irq(irq); |
| 684 | } |
| 685 | |
Jeremy Fitzhardinge | b536b4b | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 686 | int bind_evtchn_to_irq(unsigned int evtchn) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 687 | { |
| 688 | int irq; |
| 689 | |
| 690 | spin_lock(&irq_mapping_update_lock); |
| 691 | |
| 692 | irq = evtchn_to_irq[evtchn]; |
| 693 | |
| 694 | if (irq == -1) { |
| 695 | irq = find_unbound_irq(); |
| 696 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 697 | set_irq_chip_and_handler_name(irq, &xen_dynamic_chip, |
Jeremy Fitzhardinge | dffe2e1 | 2010-08-20 19:10:01 -0700 | [diff] [blame] | 698 | handle_edge_irq, "event"); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 699 | |
| 700 | evtchn_to_irq[evtchn] = irq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 701 | irq_info[irq] = mk_evtchn_info(evtchn); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 704 | spin_unlock(&irq_mapping_update_lock); |
| 705 | |
| 706 | return irq; |
| 707 | } |
Jeremy Fitzhardinge | b536b4b | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 708 | EXPORT_SYMBOL_GPL(bind_evtchn_to_irq); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 709 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 710 | static int bind_ipi_to_irq(unsigned int ipi, unsigned int cpu) |
| 711 | { |
| 712 | struct evtchn_bind_ipi bind_ipi; |
| 713 | int evtchn, irq; |
| 714 | |
| 715 | spin_lock(&irq_mapping_update_lock); |
| 716 | |
| 717 | irq = per_cpu(ipi_to_irq, cpu)[ipi]; |
Ian Campbell | 90af951 | 2009-02-06 16:55:58 -0800 | [diff] [blame] | 718 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 719 | if (irq == -1) { |
| 720 | irq = find_unbound_irq(); |
| 721 | if (irq < 0) |
| 722 | goto out; |
| 723 | |
Jeremy Fitzhardinge | aaca496 | 2010-08-20 18:57:53 -0700 | [diff] [blame] | 724 | set_irq_chip_and_handler_name(irq, &xen_percpu_chip, |
| 725 | handle_percpu_irq, "ipi"); |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 726 | |
| 727 | bind_ipi.vcpu = cpu; |
| 728 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi, |
| 729 | &bind_ipi) != 0) |
| 730 | BUG(); |
| 731 | evtchn = bind_ipi.port; |
| 732 | |
| 733 | evtchn_to_irq[evtchn] = irq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 734 | irq_info[irq] = mk_ipi_info(evtchn, ipi); |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 735 | per_cpu(ipi_to_irq, cpu)[ipi] = irq; |
| 736 | |
| 737 | bind_evtchn_to_cpu(evtchn, cpu); |
| 738 | } |
| 739 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 740 | out: |
| 741 | spin_unlock(&irq_mapping_update_lock); |
| 742 | return irq; |
| 743 | } |
| 744 | |
| 745 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 746 | static int bind_virq_to_irq(unsigned int virq, unsigned int cpu) |
| 747 | { |
| 748 | struct evtchn_bind_virq bind_virq; |
| 749 | int evtchn, irq; |
| 750 | |
| 751 | spin_lock(&irq_mapping_update_lock); |
| 752 | |
| 753 | irq = per_cpu(virq_to_irq, cpu)[virq]; |
| 754 | |
| 755 | if (irq == -1) { |
| 756 | bind_virq.virq = virq; |
| 757 | bind_virq.vcpu = cpu; |
| 758 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, |
| 759 | &bind_virq) != 0) |
| 760 | BUG(); |
| 761 | evtchn = bind_virq.port; |
| 762 | |
| 763 | irq = find_unbound_irq(); |
| 764 | |
Jeremy Fitzhardinge | aaca496 | 2010-08-20 18:57:53 -0700 | [diff] [blame] | 765 | set_irq_chip_and_handler_name(irq, &xen_percpu_chip, |
| 766 | handle_percpu_irq, "virq"); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 767 | |
| 768 | evtchn_to_irq[evtchn] = irq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 769 | irq_info[irq] = mk_virq_info(evtchn, virq); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 770 | |
| 771 | per_cpu(virq_to_irq, cpu)[virq] = irq; |
| 772 | |
| 773 | bind_evtchn_to_cpu(evtchn, cpu); |
| 774 | } |
| 775 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 776 | spin_unlock(&irq_mapping_update_lock); |
| 777 | |
| 778 | return irq; |
| 779 | } |
| 780 | |
| 781 | static void unbind_from_irq(unsigned int irq) |
| 782 | { |
| 783 | struct evtchn_close close; |
| 784 | int evtchn = evtchn_from_irq(irq); |
| 785 | |
| 786 | spin_lock(&irq_mapping_update_lock); |
| 787 | |
Jeremy Fitzhardinge | d77bbd4 | 2009-02-06 14:09:45 -0800 | [diff] [blame] | 788 | if (VALID_EVTCHN(evtchn)) { |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 789 | close.port = evtchn; |
| 790 | if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0) |
| 791 | BUG(); |
| 792 | |
| 793 | switch (type_from_irq(irq)) { |
| 794 | case IRQT_VIRQ: |
| 795 | per_cpu(virq_to_irq, cpu_from_evtchn(evtchn)) |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 796 | [virq_from_irq(irq)] = -1; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 797 | break; |
Alex Nixon | d68d82a | 2008-08-22 11:52:15 +0100 | [diff] [blame] | 798 | case IRQT_IPI: |
| 799 | per_cpu(ipi_to_irq, cpu_from_evtchn(evtchn)) |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 800 | [ipi_from_irq(irq)] = -1; |
Alex Nixon | d68d82a | 2008-08-22 11:52:15 +0100 | [diff] [blame] | 801 | break; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 802 | default: |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | /* Closed ports are implicitly re-bound to VCPU0. */ |
| 807 | bind_evtchn_to_cpu(evtchn, 0); |
| 808 | |
| 809 | evtchn_to_irq[evtchn] = -1; |
Ian Campbell | fed5ea8 | 2009-12-01 16:15:30 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | if (irq_info[irq].type != IRQT_UNBOUND) { |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 813 | irq_info[irq] = mk_unbound_info(); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 814 | |
Thomas Gleixner | 77dff1c | 2010-09-29 17:37:10 +0200 | [diff] [blame] | 815 | irq_free_desc(irq); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | spin_unlock(&irq_mapping_update_lock); |
| 819 | } |
| 820 | |
| 821 | int bind_evtchn_to_irqhandler(unsigned int evtchn, |
Jeff Garzik | 7c23997 | 2007-10-19 03:12:20 -0400 | [diff] [blame] | 822 | irq_handler_t handler, |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 823 | unsigned long irqflags, |
| 824 | const char *devname, void *dev_id) |
| 825 | { |
| 826 | unsigned int irq; |
| 827 | int retval; |
| 828 | |
| 829 | irq = bind_evtchn_to_irq(evtchn); |
| 830 | retval = request_irq(irq, handler, irqflags, devname, dev_id); |
| 831 | if (retval != 0) { |
| 832 | unbind_from_irq(irq); |
| 833 | return retval; |
| 834 | } |
| 835 | |
| 836 | return irq; |
| 837 | } |
| 838 | EXPORT_SYMBOL_GPL(bind_evtchn_to_irqhandler); |
| 839 | |
| 840 | int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, |
Jeff Garzik | 7c23997 | 2007-10-19 03:12:20 -0400 | [diff] [blame] | 841 | irq_handler_t handler, |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 842 | unsigned long irqflags, const char *devname, void *dev_id) |
| 843 | { |
| 844 | unsigned int irq; |
| 845 | int retval; |
| 846 | |
| 847 | irq = bind_virq_to_irq(virq, cpu); |
| 848 | retval = request_irq(irq, handler, irqflags, devname, dev_id); |
| 849 | if (retval != 0) { |
| 850 | unbind_from_irq(irq); |
| 851 | return retval; |
| 852 | } |
| 853 | |
| 854 | return irq; |
| 855 | } |
| 856 | EXPORT_SYMBOL_GPL(bind_virq_to_irqhandler); |
| 857 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 858 | int bind_ipi_to_irqhandler(enum ipi_vector ipi, |
| 859 | unsigned int cpu, |
| 860 | irq_handler_t handler, |
| 861 | unsigned long irqflags, |
| 862 | const char *devname, |
| 863 | void *dev_id) |
| 864 | { |
| 865 | int irq, retval; |
| 866 | |
| 867 | irq = bind_ipi_to_irq(ipi, cpu); |
| 868 | if (irq < 0) |
| 869 | return irq; |
| 870 | |
Ian Campbell | 4877c73 | 2010-07-29 11:16:35 +0100 | [diff] [blame] | 871 | irqflags |= IRQF_NO_SUSPEND; |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 872 | retval = request_irq(irq, handler, irqflags, devname, dev_id); |
| 873 | if (retval != 0) { |
| 874 | unbind_from_irq(irq); |
| 875 | return retval; |
| 876 | } |
| 877 | |
| 878 | return irq; |
| 879 | } |
| 880 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 881 | void unbind_from_irqhandler(unsigned int irq, void *dev_id) |
| 882 | { |
| 883 | free_irq(irq, dev_id); |
| 884 | unbind_from_irq(irq); |
| 885 | } |
| 886 | EXPORT_SYMBOL_GPL(unbind_from_irqhandler); |
| 887 | |
Jeremy Fitzhardinge | f87e4ca | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 888 | void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector) |
| 889 | { |
| 890 | int irq = per_cpu(ipi_to_irq, cpu)[vector]; |
| 891 | BUG_ON(irq < 0); |
| 892 | notify_remote_via_irq(irq); |
| 893 | } |
| 894 | |
Jeremy Fitzhardinge | ee523ca | 2008-03-17 16:37:18 -0700 | [diff] [blame] | 895 | irqreturn_t xen_debug_interrupt(int irq, void *dev_id) |
| 896 | { |
| 897 | struct shared_info *sh = HYPERVISOR_shared_info; |
| 898 | int cpu = smp_processor_id(); |
| 899 | int i; |
| 900 | unsigned long flags; |
| 901 | static DEFINE_SPINLOCK(debug_lock); |
| 902 | |
| 903 | spin_lock_irqsave(&debug_lock, flags); |
| 904 | |
| 905 | printk("vcpu %d\n ", cpu); |
| 906 | |
| 907 | for_each_online_cpu(i) { |
| 908 | struct vcpu_info *v = per_cpu(xen_vcpu, i); |
| 909 | printk("%d: masked=%d pending=%d event_sel %08lx\n ", i, |
Isaku Yamahata | e849c3e | 2008-04-02 10:53:56 -0700 | [diff] [blame] | 910 | (get_irq_regs() && i == cpu) ? xen_irqs_disabled(get_irq_regs()) : v->evtchn_upcall_mask, |
Jeremy Fitzhardinge | ee523ca | 2008-03-17 16:37:18 -0700 | [diff] [blame] | 911 | v->evtchn_upcall_pending, |
| 912 | v->evtchn_pending_sel); |
| 913 | } |
| 914 | printk("pending:\n "); |
| 915 | for(i = ARRAY_SIZE(sh->evtchn_pending)-1; i >= 0; i--) |
| 916 | printk("%08lx%s", sh->evtchn_pending[i], |
| 917 | i % 8 == 0 ? "\n " : " "); |
| 918 | printk("\nmasks:\n "); |
| 919 | for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) |
| 920 | printk("%08lx%s", sh->evtchn_mask[i], |
| 921 | i % 8 == 0 ? "\n " : " "); |
| 922 | |
| 923 | printk("\nunmasked:\n "); |
| 924 | for(i = ARRAY_SIZE(sh->evtchn_mask)-1; i >= 0; i--) |
| 925 | printk("%08lx%s", sh->evtchn_pending[i] & ~sh->evtchn_mask[i], |
| 926 | i % 8 == 0 ? "\n " : " "); |
| 927 | |
| 928 | printk("\npending list:\n"); |
| 929 | for(i = 0; i < NR_EVENT_CHANNELS; i++) { |
| 930 | if (sync_test_bit(i, sh->evtchn_pending)) { |
| 931 | printk(" %d: event %d -> irq %d\n", |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 932 | cpu_from_evtchn(i), i, |
| 933 | evtchn_to_irq[i]); |
Jeremy Fitzhardinge | ee523ca | 2008-03-17 16:37:18 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
| 937 | spin_unlock_irqrestore(&debug_lock, flags); |
| 938 | |
| 939 | return IRQ_HANDLED; |
| 940 | } |
| 941 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 942 | static DEFINE_PER_CPU(unsigned, xed_nesting_count); |
| 943 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 944 | /* |
| 945 | * Search the CPUs pending events bitmasks. For each one found, map |
| 946 | * the event number to an irq, and feed it into do_IRQ() for |
| 947 | * handling. |
| 948 | * |
| 949 | * Xen uses a two-level bitmap to speed searching. The first level is |
| 950 | * a bitset of words which contain pending event bits. The second |
| 951 | * level is a bitset of pending events themselves. |
| 952 | */ |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 953 | static void __xen_evtchn_do_upcall(void) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 954 | { |
| 955 | int cpu = get_cpu(); |
| 956 | struct shared_info *s = HYPERVISOR_shared_info; |
| 957 | struct vcpu_info *vcpu_info = __get_cpu_var(xen_vcpu); |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 958 | unsigned count; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 959 | |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 960 | do { |
| 961 | unsigned long pending_words; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 962 | |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 963 | vcpu_info->evtchn_upcall_pending = 0; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 964 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 965 | if (__get_cpu_var(xed_nesting_count)++) |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 966 | goto out; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 967 | |
Isaku Yamahata | e849c3e | 2008-04-02 10:53:56 -0700 | [diff] [blame] | 968 | #ifndef CONFIG_X86 /* No need for a barrier -- XCHG is a barrier on x86. */ |
| 969 | /* Clear master flag /before/ clearing selector flag. */ |
Isaku Yamahata | 6673cf6 | 2008-06-16 14:58:13 -0700 | [diff] [blame] | 970 | wmb(); |
Isaku Yamahata | e849c3e | 2008-04-02 10:53:56 -0700 | [diff] [blame] | 971 | #endif |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 972 | pending_words = xchg(&vcpu_info->evtchn_pending_sel, 0); |
| 973 | while (pending_words != 0) { |
| 974 | unsigned long pending_bits; |
| 975 | int word_idx = __ffs(pending_words); |
| 976 | pending_words &= ~(1UL << word_idx); |
| 977 | |
| 978 | while ((pending_bits = active_evtchns(cpu, s, word_idx)) != 0) { |
| 979 | int bit_idx = __ffs(pending_bits); |
| 980 | int port = (word_idx * BITS_PER_LONG) + bit_idx; |
| 981 | int irq = evtchn_to_irq[port]; |
Eric W. Biederman | ca4dbc6 | 2010-02-17 18:49:54 -0800 | [diff] [blame] | 982 | struct irq_desc *desc; |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 983 | |
Eric W. Biederman | ca4dbc6 | 2010-02-17 18:49:54 -0800 | [diff] [blame] | 984 | if (irq != -1) { |
| 985 | desc = irq_to_desc(irq); |
| 986 | if (desc) |
| 987 | generic_handle_irq_desc(irq, desc); |
| 988 | } |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 989 | } |
| 990 | } |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 991 | |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 992 | BUG_ON(!irqs_disabled()); |
| 993 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 994 | count = __get_cpu_var(xed_nesting_count); |
| 995 | __get_cpu_var(xed_nesting_count) = 0; |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 996 | } while (count != 1 || vcpu_info->evtchn_upcall_pending); |
Jeremy Fitzhardinge | 229664b | 2008-03-17 16:37:20 -0700 | [diff] [blame] | 997 | |
| 998 | out: |
Jeremy Fitzhardinge | 3445a8f | 2009-02-06 14:09:46 -0800 | [diff] [blame] | 999 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1000 | put_cpu(); |
| 1001 | } |
| 1002 | |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1003 | void xen_evtchn_do_upcall(struct pt_regs *regs) |
| 1004 | { |
| 1005 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 1006 | |
| 1007 | exit_idle(); |
| 1008 | irq_enter(); |
| 1009 | |
| 1010 | __xen_evtchn_do_upcall(); |
| 1011 | |
| 1012 | irq_exit(); |
| 1013 | set_irq_regs(old_regs); |
| 1014 | } |
| 1015 | |
| 1016 | void xen_hvm_evtchn_do_upcall(void) |
| 1017 | { |
| 1018 | __xen_evtchn_do_upcall(); |
| 1019 | } |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 1020 | EXPORT_SYMBOL_GPL(xen_hvm_evtchn_do_upcall); |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1021 | |
Jeremy Fitzhardinge | eb1e305 | 2008-05-26 23:31:23 +0100 | [diff] [blame] | 1022 | /* Rebind a new event channel to an existing irq. */ |
| 1023 | void rebind_evtchn_irq(int evtchn, int irq) |
| 1024 | { |
Jeremy Fitzhardinge | d77bbd4 | 2009-02-06 14:09:45 -0800 | [diff] [blame] | 1025 | struct irq_info *info = info_for_irq(irq); |
| 1026 | |
Jeremy Fitzhardinge | eb1e305 | 2008-05-26 23:31:23 +0100 | [diff] [blame] | 1027 | /* Make sure the irq is masked, since the new event channel |
| 1028 | will also be masked. */ |
| 1029 | disable_irq(irq); |
| 1030 | |
| 1031 | spin_lock(&irq_mapping_update_lock); |
| 1032 | |
| 1033 | /* After resume the irq<->evtchn mappings are all cleared out */ |
| 1034 | BUG_ON(evtchn_to_irq[evtchn] != -1); |
| 1035 | /* Expect irq to have been bound before, |
Jeremy Fitzhardinge | d77bbd4 | 2009-02-06 14:09:45 -0800 | [diff] [blame] | 1036 | so there should be a proper type */ |
| 1037 | BUG_ON(info->type == IRQT_UNBOUND); |
Jeremy Fitzhardinge | eb1e305 | 2008-05-26 23:31:23 +0100 | [diff] [blame] | 1038 | |
| 1039 | evtchn_to_irq[evtchn] = irq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 1040 | irq_info[irq] = mk_evtchn_info(evtchn); |
Jeremy Fitzhardinge | eb1e305 | 2008-05-26 23:31:23 +0100 | [diff] [blame] | 1041 | |
| 1042 | spin_unlock(&irq_mapping_update_lock); |
| 1043 | |
| 1044 | /* new event channels are always bound to cpu 0 */ |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 1045 | irq_set_affinity(irq, cpumask_of(0)); |
Jeremy Fitzhardinge | eb1e305 | 2008-05-26 23:31:23 +0100 | [diff] [blame] | 1046 | |
| 1047 | /* Unmask the event channel. */ |
| 1048 | enable_irq(irq); |
| 1049 | } |
| 1050 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1051 | /* Rebind an evtchn so that it gets delivered to a specific cpu */ |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 1052 | static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1053 | { |
| 1054 | struct evtchn_bind_vcpu bind_vcpu; |
| 1055 | int evtchn = evtchn_from_irq(irq); |
| 1056 | |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 1057 | /* events delivered via platform PCI interrupts are always |
| 1058 | * routed to vcpu 0 */ |
| 1059 | if (!VALID_EVTCHN(evtchn) || |
| 1060 | (xen_hvm_domain() && !xen_have_vector_callback)) |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 1061 | return -1; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1062 | |
| 1063 | /* Send future instances of this interrupt to other vcpu. */ |
| 1064 | bind_vcpu.port = evtchn; |
| 1065 | bind_vcpu.vcpu = tcpu; |
| 1066 | |
| 1067 | /* |
| 1068 | * If this fails, it usually just indicates that we're dealing with a |
| 1069 | * virq or IPI channel, which don't actually need to be rebound. Ignore |
| 1070 | * it, but don't do the xenlinux-level rebind in that case. |
| 1071 | */ |
| 1072 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0) |
| 1073 | bind_evtchn_to_cpu(evtchn, tcpu); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 1074 | |
| 1075 | return 0; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 1078 | static int set_affinity_irq(unsigned irq, const struct cpumask *dest) |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1079 | { |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 1080 | unsigned tcpu = cpumask_first(dest); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 1081 | |
| 1082 | return rebind_irq_to_cpu(irq, tcpu); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
Isaku Yamahata | 642e0c8 | 2008-04-02 10:53:57 -0700 | [diff] [blame] | 1085 | int resend_irq_on_evtchn(unsigned int irq) |
| 1086 | { |
| 1087 | int masked, evtchn = evtchn_from_irq(irq); |
| 1088 | struct shared_info *s = HYPERVISOR_shared_info; |
| 1089 | |
| 1090 | if (!VALID_EVTCHN(evtchn)) |
| 1091 | return 1; |
| 1092 | |
| 1093 | masked = sync_test_and_set_bit(evtchn, s->evtchn_mask); |
| 1094 | sync_set_bit(evtchn, s->evtchn_pending); |
| 1095 | if (!masked) |
| 1096 | unmask_evtchn(evtchn); |
| 1097 | |
| 1098 | return 1; |
| 1099 | } |
| 1100 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1101 | static void enable_dynirq(unsigned int irq) |
| 1102 | { |
| 1103 | int evtchn = evtchn_from_irq(irq); |
| 1104 | |
| 1105 | if (VALID_EVTCHN(evtchn)) |
| 1106 | unmask_evtchn(evtchn); |
| 1107 | } |
| 1108 | |
| 1109 | static void disable_dynirq(unsigned int irq) |
| 1110 | { |
| 1111 | int evtchn = evtchn_from_irq(irq); |
| 1112 | |
| 1113 | if (VALID_EVTCHN(evtchn)) |
| 1114 | mask_evtchn(evtchn); |
| 1115 | } |
| 1116 | |
| 1117 | static void ack_dynirq(unsigned int irq) |
| 1118 | { |
| 1119 | int evtchn = evtchn_from_irq(irq); |
| 1120 | |
| 1121 | move_native_irq(irq); |
| 1122 | |
| 1123 | if (VALID_EVTCHN(evtchn)) |
| 1124 | clear_evtchn(evtchn); |
| 1125 | } |
| 1126 | |
| 1127 | static int retrigger_dynirq(unsigned int irq) |
| 1128 | { |
| 1129 | int evtchn = evtchn_from_irq(irq); |
Jeremy Fitzhardinge | ee8fa1c | 2008-03-17 16:37:19 -0700 | [diff] [blame] | 1130 | struct shared_info *sh = HYPERVISOR_shared_info; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1131 | int ret = 0; |
| 1132 | |
| 1133 | if (VALID_EVTCHN(evtchn)) { |
Jeremy Fitzhardinge | ee8fa1c | 2008-03-17 16:37:19 -0700 | [diff] [blame] | 1134 | int masked; |
| 1135 | |
| 1136 | masked = sync_test_and_set_bit(evtchn, sh->evtchn_mask); |
| 1137 | sync_set_bit(evtchn, sh->evtchn_pending); |
| 1138 | if (!masked) |
| 1139 | unmask_evtchn(evtchn); |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1140 | ret = 1; |
| 1141 | } |
| 1142 | |
| 1143 | return ret; |
| 1144 | } |
| 1145 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1146 | static void restore_cpu_virqs(unsigned int cpu) |
| 1147 | { |
| 1148 | struct evtchn_bind_virq bind_virq; |
| 1149 | int virq, irq, evtchn; |
| 1150 | |
| 1151 | for (virq = 0; virq < NR_VIRQS; virq++) { |
| 1152 | if ((irq = per_cpu(virq_to_irq, cpu)[virq]) == -1) |
| 1153 | continue; |
| 1154 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 1155 | BUG_ON(virq_from_irq(irq) != virq); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1156 | |
| 1157 | /* Get a new binding from Xen. */ |
| 1158 | bind_virq.virq = virq; |
| 1159 | bind_virq.vcpu = cpu; |
| 1160 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, |
| 1161 | &bind_virq) != 0) |
| 1162 | BUG(); |
| 1163 | evtchn = bind_virq.port; |
| 1164 | |
| 1165 | /* Record the new mapping. */ |
| 1166 | evtchn_to_irq[evtchn] = irq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 1167 | irq_info[irq] = mk_virq_info(evtchn, virq); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1168 | bind_evtchn_to_cpu(evtchn, cpu); |
| 1169 | |
| 1170 | /* Ready for use. */ |
| 1171 | unmask_evtchn(evtchn); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | static void restore_cpu_ipis(unsigned int cpu) |
| 1176 | { |
| 1177 | struct evtchn_bind_ipi bind_ipi; |
| 1178 | int ipi, irq, evtchn; |
| 1179 | |
| 1180 | for (ipi = 0; ipi < XEN_NR_IPIS; ipi++) { |
| 1181 | if ((irq = per_cpu(ipi_to_irq, cpu)[ipi]) == -1) |
| 1182 | continue; |
| 1183 | |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 1184 | BUG_ON(ipi_from_irq(irq) != ipi); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1185 | |
| 1186 | /* Get a new binding from Xen. */ |
| 1187 | bind_ipi.vcpu = cpu; |
| 1188 | if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi, |
| 1189 | &bind_ipi) != 0) |
| 1190 | BUG(); |
| 1191 | evtchn = bind_ipi.port; |
| 1192 | |
| 1193 | /* Record the new mapping. */ |
| 1194 | evtchn_to_irq[evtchn] = irq; |
Jeremy Fitzhardinge | ced40d0 | 2009-02-06 14:09:44 -0800 | [diff] [blame] | 1195 | irq_info[irq] = mk_ipi_info(evtchn, ipi); |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1196 | bind_evtchn_to_cpu(evtchn, cpu); |
| 1197 | |
| 1198 | /* Ready for use. */ |
| 1199 | unmask_evtchn(evtchn); |
| 1200 | |
| 1201 | } |
| 1202 | } |
| 1203 | |
Jeremy Fitzhardinge | 2d9e1e2 | 2008-07-07 12:07:53 -0700 | [diff] [blame] | 1204 | /* Clear an irq's pending state, in preparation for polling on it */ |
| 1205 | void xen_clear_irq_pending(int irq) |
| 1206 | { |
| 1207 | int evtchn = evtchn_from_irq(irq); |
| 1208 | |
| 1209 | if (VALID_EVTCHN(evtchn)) |
| 1210 | clear_evtchn(evtchn); |
| 1211 | } |
Konrad Rzeszutek Wilk | d9a8814 | 2009-11-05 16:33:09 -0500 | [diff] [blame] | 1212 | EXPORT_SYMBOL(xen_clear_irq_pending); |
Jeremy Fitzhardinge | 168d2f4 | 2008-08-20 17:02:18 -0700 | [diff] [blame] | 1213 | void xen_set_irq_pending(int irq) |
| 1214 | { |
| 1215 | int evtchn = evtchn_from_irq(irq); |
| 1216 | |
| 1217 | if (VALID_EVTCHN(evtchn)) |
| 1218 | set_evtchn(evtchn); |
| 1219 | } |
| 1220 | |
| 1221 | bool xen_test_irq_pending(int irq) |
| 1222 | { |
| 1223 | int evtchn = evtchn_from_irq(irq); |
| 1224 | bool ret = false; |
| 1225 | |
| 1226 | if (VALID_EVTCHN(evtchn)) |
| 1227 | ret = test_evtchn(evtchn); |
| 1228 | |
| 1229 | return ret; |
| 1230 | } |
| 1231 | |
Konrad Rzeszutek Wilk | d9a8814 | 2009-11-05 16:33:09 -0500 | [diff] [blame] | 1232 | /* Poll waiting for an irq to become pending with timeout. In the usual case, |
| 1233 | * the irq will be disabled so it won't deliver an interrupt. */ |
| 1234 | void xen_poll_irq_timeout(int irq, u64 timeout) |
Jeremy Fitzhardinge | 2d9e1e2 | 2008-07-07 12:07:53 -0700 | [diff] [blame] | 1235 | { |
| 1236 | evtchn_port_t evtchn = evtchn_from_irq(irq); |
| 1237 | |
| 1238 | if (VALID_EVTCHN(evtchn)) { |
| 1239 | struct sched_poll poll; |
| 1240 | |
| 1241 | poll.nr_ports = 1; |
Konrad Rzeszutek Wilk | d9a8814 | 2009-11-05 16:33:09 -0500 | [diff] [blame] | 1242 | poll.timeout = timeout; |
Isaku Yamahata | ff3c536 | 2008-10-14 17:50:44 -0700 | [diff] [blame] | 1243 | set_xen_guest_handle(poll.ports, &evtchn); |
Jeremy Fitzhardinge | 2d9e1e2 | 2008-07-07 12:07:53 -0700 | [diff] [blame] | 1244 | |
| 1245 | if (HYPERVISOR_sched_op(SCHEDOP_poll, &poll) != 0) |
| 1246 | BUG(); |
| 1247 | } |
| 1248 | } |
Konrad Rzeszutek Wilk | d9a8814 | 2009-11-05 16:33:09 -0500 | [diff] [blame] | 1249 | EXPORT_SYMBOL(xen_poll_irq_timeout); |
| 1250 | /* Poll waiting for an irq to become pending. In the usual case, the |
| 1251 | * irq will be disabled so it won't deliver an interrupt. */ |
| 1252 | void xen_poll_irq(int irq) |
| 1253 | { |
| 1254 | xen_poll_irq_timeout(irq, 0 /* no timeout */); |
| 1255 | } |
Jeremy Fitzhardinge | 2d9e1e2 | 2008-07-07 12:07:53 -0700 | [diff] [blame] | 1256 | |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1257 | void xen_irq_resume(void) |
| 1258 | { |
| 1259 | unsigned int cpu, irq, evtchn; |
| 1260 | |
| 1261 | init_evtchn_cpu_bindings(); |
| 1262 | |
| 1263 | /* New event-channel space is not 'live' yet. */ |
| 1264 | for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) |
| 1265 | mask_evtchn(evtchn); |
| 1266 | |
| 1267 | /* No IRQ <-> event-channel mappings. */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1268 | for (irq = 0; irq < nr_irqs; irq++) |
Jeremy Fitzhardinge | 0e91398 | 2008-05-26 23:31:27 +0100 | [diff] [blame] | 1269 | irq_info[irq].evtchn = 0; /* zap event-channel binding */ |
| 1270 | |
| 1271 | for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) |
| 1272 | evtchn_to_irq[evtchn] = -1; |
| 1273 | |
| 1274 | for_each_possible_cpu(cpu) { |
| 1275 | restore_cpu_virqs(cpu); |
| 1276 | restore_cpu_ipis(cpu); |
| 1277 | } |
| 1278 | } |
| 1279 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1280 | static struct irq_chip xen_dynamic_chip __read_mostly = { |
| 1281 | .name = "xen-dyn", |
Jeremy Fitzhardinge | 54a353a | 2009-02-06 14:09:42 -0800 | [diff] [blame] | 1282 | |
| 1283 | .disable = disable_dynirq, |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1284 | .mask = disable_dynirq, |
| 1285 | .unmask = enable_dynirq, |
Jeremy Fitzhardinge | 54a353a | 2009-02-06 14:09:42 -0800 | [diff] [blame] | 1286 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1287 | .ack = ack_dynirq, |
| 1288 | .set_affinity = set_affinity_irq, |
| 1289 | .retrigger = retrigger_dynirq, |
| 1290 | }; |
| 1291 | |
Jeremy Fitzhardinge | d46a78b | 2010-10-01 12:20:09 -0400 | [diff] [blame] | 1292 | static struct irq_chip xen_pirq_chip __read_mostly = { |
| 1293 | .name = "xen-pirq", |
| 1294 | |
| 1295 | .startup = startup_pirq, |
| 1296 | .shutdown = shutdown_pirq, |
| 1297 | |
| 1298 | .enable = enable_pirq, |
| 1299 | .unmask = enable_pirq, |
| 1300 | |
| 1301 | .disable = disable_pirq, |
| 1302 | .mask = disable_pirq, |
| 1303 | |
| 1304 | .ack = ack_pirq, |
| 1305 | .end = end_pirq, |
| 1306 | |
| 1307 | .set_affinity = set_affinity_irq, |
| 1308 | |
| 1309 | .retrigger = retrigger_dynirq, |
| 1310 | }; |
| 1311 | |
Jeremy Fitzhardinge | aaca496 | 2010-08-20 18:57:53 -0700 | [diff] [blame] | 1312 | static struct irq_chip xen_percpu_chip __read_mostly = { |
| 1313 | .name = "xen-percpu", |
| 1314 | |
| 1315 | .disable = disable_dynirq, |
| 1316 | .mask = disable_dynirq, |
| 1317 | .unmask = enable_dynirq, |
| 1318 | |
| 1319 | .ack = ack_dynirq, |
| 1320 | }; |
| 1321 | |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1322 | int xen_set_callback_via(uint64_t via) |
| 1323 | { |
| 1324 | struct xen_hvm_param a; |
| 1325 | a.domid = DOMID_SELF; |
| 1326 | a.index = HVM_PARAM_CALLBACK_IRQ; |
| 1327 | a.value = via; |
| 1328 | return HYPERVISOR_hvm_op(HVMOP_set_param, &a); |
| 1329 | } |
| 1330 | EXPORT_SYMBOL_GPL(xen_set_callback_via); |
| 1331 | |
Stefano Stabellini | ca65f9f | 2010-07-29 14:37:48 +0100 | [diff] [blame] | 1332 | #ifdef CONFIG_XEN_PVHVM |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1333 | /* Vector callbacks are better than PCI interrupts to receive event |
| 1334 | * channel notifications because we can receive vector callbacks on any |
| 1335 | * vcpu and we don't need PCI support or APIC interactions. */ |
| 1336 | void xen_callback_vector(void) |
| 1337 | { |
| 1338 | int rc; |
| 1339 | uint64_t callback_via; |
| 1340 | if (xen_have_vector_callback) { |
| 1341 | callback_via = HVM_CALLBACK_VECTOR(XEN_HVM_EVTCHN_CALLBACK); |
| 1342 | rc = xen_set_callback_via(callback_via); |
| 1343 | if (rc) { |
| 1344 | printk(KERN_ERR "Request for Xen HVM callback vector" |
| 1345 | " failed.\n"); |
| 1346 | xen_have_vector_callback = 0; |
| 1347 | return; |
| 1348 | } |
| 1349 | printk(KERN_INFO "Xen HVM callback vector for event delivery is " |
| 1350 | "enabled\n"); |
| 1351 | /* in the restore case the vector has already been allocated */ |
| 1352 | if (!test_bit(XEN_HVM_EVTCHN_CALLBACK, used_vectors)) |
| 1353 | alloc_intr_gate(XEN_HVM_EVTCHN_CALLBACK, xen_hvm_callback_vector); |
| 1354 | } |
| 1355 | } |
Stefano Stabellini | ca65f9f | 2010-07-29 14:37:48 +0100 | [diff] [blame] | 1356 | #else |
| 1357 | void xen_callback_vector(void) {} |
| 1358 | #endif |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1359 | |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1360 | void __init xen_init_IRQ(void) |
| 1361 | { |
Stefano Stabellini | 01557ba | 2010-08-20 14:46:52 +0100 | [diff] [blame^] | 1362 | int i, rc; |
| 1363 | struct physdev_nr_pirqs op_nr_pirqs; |
Mike Travis | c7a3589 | 2009-01-10 21:58:11 -0800 | [diff] [blame] | 1364 | |
Pekka Enberg | a70c352 | 2009-07-01 11:51:18 +0300 | [diff] [blame] | 1365 | cpu_evtchn_mask_p = kcalloc(nr_cpu_ids, sizeof(struct cpu_evtchn_s), |
| 1366 | GFP_KERNEL); |
Jeremy Fitzhardinge | b21ddbf | 2010-06-07 16:28:49 -0400 | [diff] [blame] | 1367 | irq_info = kcalloc(nr_irqs, sizeof(*irq_info), GFP_KERNEL); |
| 1368 | |
Stefano Stabellini | 01557ba | 2010-08-20 14:46:52 +0100 | [diff] [blame^] | 1369 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_get_nr_pirqs, &op_nr_pirqs); |
| 1370 | if (rc < 0) { |
| 1371 | nr_pirqs = nr_irqs; |
| 1372 | if (rc != -ENOSYS) |
| 1373 | printk(KERN_WARNING "PHYSDEVOP_get_nr_pirqs returned rc=%d\n", rc); |
| 1374 | } else { |
| 1375 | if (xen_pv_domain() && !xen_initial_domain()) |
| 1376 | nr_pirqs = max((int)op_nr_pirqs.nr_pirqs, nr_irqs); |
| 1377 | else |
| 1378 | nr_pirqs = op_nr_pirqs.nr_pirqs; |
| 1379 | } |
| 1380 | pirq_to_irq = kcalloc(nr_pirqs, sizeof(*pirq_to_irq), GFP_KERNEL); |
| 1381 | for (i = 0; i < nr_pirqs; i++) |
Stefano Stabellini | 7a043f1 | 2010-07-01 17:08:14 +0100 | [diff] [blame] | 1382 | pirq_to_irq[i] = -1; |
| 1383 | |
Jeremy Fitzhardinge | b21ddbf | 2010-06-07 16:28:49 -0400 | [diff] [blame] | 1384 | evtchn_to_irq = kcalloc(NR_EVENT_CHANNELS, sizeof(*evtchn_to_irq), |
| 1385 | GFP_KERNEL); |
| 1386 | for (i = 0; i < NR_EVENT_CHANNELS; i++) |
| 1387 | evtchn_to_irq[i] = -1; |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1388 | |
| 1389 | init_evtchn_cpu_bindings(); |
| 1390 | |
| 1391 | /* No event channels are 'live' right now. */ |
| 1392 | for (i = 0; i < NR_EVENT_CHANNELS; i++) |
| 1393 | mask_evtchn(i); |
| 1394 | |
Sheng Yang | 38e20b0 | 2010-05-14 12:40:51 +0100 | [diff] [blame] | 1395 | if (xen_hvm_domain()) { |
| 1396 | xen_callback_vector(); |
| 1397 | native_init_IRQ(); |
| 1398 | } else { |
| 1399 | irq_ctx_init(smp_processor_id()); |
| 1400 | } |
Jeremy Fitzhardinge | e46cdb6 | 2007-07-17 18:37:05 -0700 | [diff] [blame] | 1401 | } |