1 /******************************************************************************
2 * arch/ia64/xen/irq_xen.c
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 * VA Linux Systems Japan K.K.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/cpu.h>
25 #include <xen/interface/xen.h>
26 #include <xen/interface/callback.h>
27 #include <xen/events.h>
29 #include <asm/xen/privop.h>
33 /***************************************************************************
39 xen_assign_irq_vector(int irq
)
41 struct physdev_irq irq_op
;
44 if (HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector
, &irq_op
))
51 xen_free_irq_vector(int vector
)
53 struct physdev_irq irq_op
;
55 if (vector
< IA64_FIRST_DEVICE_VECTOR
||
56 vector
> IA64_LAST_DEVICE_VECTOR
)
59 irq_op
.vector
= vector
;
60 if (HYPERVISOR_physdev_op(PHYSDEVOP_free_irq_vector
, &irq_op
))
61 printk(KERN_WARNING
"%s: xen_free_irq_vecotr fail vector=%d\n",
66 static DEFINE_PER_CPU(int, xen_timer_irq
) = -1;
67 static DEFINE_PER_CPU(int, xen_ipi_irq
) = -1;
68 static DEFINE_PER_CPU(int, xen_resched_irq
) = -1;
69 static DEFINE_PER_CPU(int, xen_cmc_irq
) = -1;
70 static DEFINE_PER_CPU(int, xen_cmcp_irq
) = -1;
71 static DEFINE_PER_CPU(int, xen_cpep_irq
) = -1;
73 static DEFINE_PER_CPU(char[NAME_SIZE
], xen_timer_name
);
74 static DEFINE_PER_CPU(char[NAME_SIZE
], xen_ipi_name
);
75 static DEFINE_PER_CPU(char[NAME_SIZE
], xen_resched_name
);
76 static DEFINE_PER_CPU(char[NAME_SIZE
], xen_cmc_name
);
77 static DEFINE_PER_CPU(char[NAME_SIZE
], xen_cmcp_name
);
78 static DEFINE_PER_CPU(char[NAME_SIZE
], xen_cpep_name
);
83 struct irqaction
*action
;
85 /* 16 should be far optimistic value, since only several percpu irqs
86 * are registered early.
88 #define MAX_LATE_IRQ 16
89 static struct saved_irq saved_percpu_irqs
[MAX_LATE_IRQ
];
90 static unsigned short late_irq_cnt
;
91 static unsigned short saved_irq_cnt
;
92 static int xen_slab_ready
;
95 /* Dummy stub. Though we may check XEN_RESCHEDULE_VECTOR before __do_IRQ,
96 * it ends up to issue several memory accesses upon percpu data and
97 * thus adds unnecessary traffic to other paths.
100 xen_dummy_handler(int irq
, void *dev_id
)
106 static struct irqaction xen_ipi_irqaction
= {
107 .handler
= handle_IPI
,
108 .flags
= IRQF_DISABLED
,
112 static struct irqaction xen_resched_irqaction
= {
113 .handler
= xen_dummy_handler
,
114 .flags
= IRQF_DISABLED
,
118 static struct irqaction xen_tlb_irqaction
= {
119 .handler
= xen_dummy_handler
,
120 .flags
= IRQF_DISABLED
,
126 * This is xen version percpu irq registration, which needs bind
127 * to xen specific evtchn sub-system. One trick here is that xen
128 * evtchn binding interface depends on kmalloc because related
129 * port needs to be freed at device/cpu down. So we cache the
130 * registration on BSP before slab is ready and then deal them
131 * at later point. For rest instances happening after slab ready,
132 * we hook them to xen evtchn immediately.
134 * FIXME: MCA is not supported by far, and thus "nomca" boot param is
138 __xen_register_percpu_irq(unsigned int cpu
, unsigned int vec
,
139 struct irqaction
*action
, int save
)
143 if (xen_slab_ready
) {
145 case IA64_TIMER_VECTOR
:
146 snprintf(per_cpu(xen_timer_name
, cpu
),
147 sizeof(per_cpu(xen_timer_name
, cpu
)),
148 "%s%d", action
->name
, cpu
);
149 irq
= bind_virq_to_irqhandler(VIRQ_ITC
, cpu
,
150 action
->handler
, action
->flags
,
151 per_cpu(xen_timer_name
, cpu
), action
->dev_id
);
152 per_cpu(xen_timer_irq
, cpu
) = irq
;
154 case IA64_IPI_RESCHEDULE
:
155 snprintf(per_cpu(xen_resched_name
, cpu
),
156 sizeof(per_cpu(xen_resched_name
, cpu
)),
157 "%s%d", action
->name
, cpu
);
158 irq
= bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR
, cpu
,
159 action
->handler
, action
->flags
,
160 per_cpu(xen_resched_name
, cpu
), action
->dev_id
);
161 per_cpu(xen_resched_irq
, cpu
) = irq
;
163 case IA64_IPI_VECTOR
:
164 snprintf(per_cpu(xen_ipi_name
, cpu
),
165 sizeof(per_cpu(xen_ipi_name
, cpu
)),
166 "%s%d", action
->name
, cpu
);
167 irq
= bind_ipi_to_irqhandler(XEN_IPI_VECTOR
, cpu
,
168 action
->handler
, action
->flags
,
169 per_cpu(xen_ipi_name
, cpu
), action
->dev_id
);
170 per_cpu(xen_ipi_irq
, cpu
) = irq
;
172 case IA64_CMC_VECTOR
:
173 snprintf(per_cpu(xen_cmc_name
, cpu
),
174 sizeof(per_cpu(xen_cmc_name
, cpu
)),
175 "%s%d", action
->name
, cpu
);
176 irq
= bind_virq_to_irqhandler(VIRQ_MCA_CMC
, cpu
,
179 per_cpu(xen_cmc_name
, cpu
),
181 per_cpu(xen_cmc_irq
, cpu
) = irq
;
183 case IA64_CMCP_VECTOR
:
184 snprintf(per_cpu(xen_cmcp_name
, cpu
),
185 sizeof(per_cpu(xen_cmcp_name
, cpu
)),
186 "%s%d", action
->name
, cpu
);
187 irq
= bind_ipi_to_irqhandler(XEN_CMCP_VECTOR
, cpu
,
190 per_cpu(xen_cmcp_name
, cpu
),
192 per_cpu(xen_cmcp_irq
, cpu
) = irq
;
194 case IA64_CPEP_VECTOR
:
195 snprintf(per_cpu(xen_cpep_name
, cpu
),
196 sizeof(per_cpu(xen_cpep_name
, cpu
)),
197 "%s%d", action
->name
, cpu
);
198 irq
= bind_ipi_to_irqhandler(XEN_CPEP_VECTOR
, cpu
,
201 per_cpu(xen_cpep_name
, cpu
),
203 per_cpu(xen_cpep_irq
, cpu
) = irq
;
205 case IA64_CPE_VECTOR
:
206 case IA64_MCA_RENDEZ_VECTOR
:
207 case IA64_PERFMON_VECTOR
:
208 case IA64_MCA_WAKEUP_VECTOR
:
209 case IA64_SPURIOUS_INT_VECTOR
:
210 /* No need to complain, these aren't supported. */
213 printk(KERN_WARNING
"Percpu irq %d is unsupported "
221 * Mark percpu. Without this, migrate_irqs() will
222 * mark the interrupt for migrations and trigger it
225 irq_set_status_flags(irq
, IRQ_PER_CPU
);
229 /* For BSP, we cache registered percpu irqs, and then re-walk
230 * them when initializing APs
233 BUG_ON(saved_irq_cnt
== MAX_LATE_IRQ
);
234 saved_percpu_irqs
[saved_irq_cnt
].irq
= vec
;
235 saved_percpu_irqs
[saved_irq_cnt
].action
= action
;
243 xen_register_percpu_irq(ia64_vector vec
, struct irqaction
*action
)
245 __xen_register_percpu_irq(smp_processor_id(), vec
, action
, 1);
249 xen_bind_early_percpu_irq(void)
254 /* There's no race when accessing this cached array, since only
255 * BSP will face with such step shortly
257 for (i
= 0; i
< late_irq_cnt
; i
++)
258 __xen_register_percpu_irq(smp_processor_id(),
259 saved_percpu_irqs
[i
].irq
,
260 saved_percpu_irqs
[i
].action
, 0);
263 /* FIXME: There's no obvious point to check whether slab is ready. So
264 * a hack is used here by utilizing a late time hook.
267 #ifdef CONFIG_HOTPLUG_CPU
269 unbind_evtchn_callback(struct notifier_block
*nfb
,
270 unsigned long action
, void *hcpu
)
272 unsigned int cpu
= (unsigned long)hcpu
;
274 if (action
== CPU_DEAD
) {
275 /* Unregister evtchn. */
276 if (per_cpu(xen_cpep_irq
, cpu
) >= 0) {
277 unbind_from_irqhandler(per_cpu(xen_cpep_irq
, cpu
),
279 per_cpu(xen_cpep_irq
, cpu
) = -1;
281 if (per_cpu(xen_cmcp_irq
, cpu
) >= 0) {
282 unbind_from_irqhandler(per_cpu(xen_cmcp_irq
, cpu
),
284 per_cpu(xen_cmcp_irq
, cpu
) = -1;
286 if (per_cpu(xen_cmc_irq
, cpu
) >= 0) {
287 unbind_from_irqhandler(per_cpu(xen_cmc_irq
, cpu
), NULL
);
288 per_cpu(xen_cmc_irq
, cpu
) = -1;
290 if (per_cpu(xen_ipi_irq
, cpu
) >= 0) {
291 unbind_from_irqhandler(per_cpu(xen_ipi_irq
, cpu
), NULL
);
292 per_cpu(xen_ipi_irq
, cpu
) = -1;
294 if (per_cpu(xen_resched_irq
, cpu
) >= 0) {
295 unbind_from_irqhandler(per_cpu(xen_resched_irq
, cpu
),
297 per_cpu(xen_resched_irq
, cpu
) = -1;
299 if (per_cpu(xen_timer_irq
, cpu
) >= 0) {
300 unbind_from_irqhandler(per_cpu(xen_timer_irq
, cpu
),
302 per_cpu(xen_timer_irq
, cpu
) = -1;
308 static struct notifier_block unbind_evtchn_notifier
= {
309 .notifier_call
= unbind_evtchn_callback
,
314 void xen_smp_intr_init_early(unsigned int cpu
)
319 for (i
= 0; i
< saved_irq_cnt
; i
++)
320 __xen_register_percpu_irq(cpu
, saved_percpu_irqs
[i
].irq
,
321 saved_percpu_irqs
[i
].action
, 0);
325 void xen_smp_intr_init(void)
328 unsigned int cpu
= smp_processor_id();
329 struct callback_register event
= {
330 .type
= CALLBACKTYPE_event
,
331 .address
= { .ip
= (unsigned long)&xen_event_callback
},
335 /* Initialization was already done for boot cpu. */
336 #ifdef CONFIG_HOTPLUG_CPU
337 /* Register the notifier only once. */
338 register_cpu_notifier(&unbind_evtchn_notifier
);
343 /* This should be piggyback when setup vcpu guest context */
344 BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register
, &event
));
345 #endif /* CONFIG_SMP */
351 struct callback_register event
= {
352 .type
= CALLBACKTYPE_event
,
353 .address
= { .ip
= (unsigned long)&xen_event_callback
},
357 BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register
, &event
));
358 late_time_init
= xen_bind_early_percpu_irq
;
362 xen_platform_send_ipi(int cpu
, int vector
, int delivery_mode
, int redirect
)
365 /* TODO: we need to call vcpu_up here */
366 if (unlikely(vector
== ap_wakeup_vector
)) {
368 * This should be in __cpu_up(cpu) in ia64 smpboot.c
369 * like x86. But don't want to modify it,
372 xen_smp_intr_init_early(cpu
);
374 xen_send_ipi(cpu
, vector
);
375 /* vcpu_prepare_and_up(cpu); */
381 case IA64_IPI_VECTOR
:
382 xen_send_IPI_one(cpu
, XEN_IPI_VECTOR
);
384 case IA64_IPI_RESCHEDULE
:
385 xen_send_IPI_one(cpu
, XEN_RESCHEDULE_VECTOR
);
387 case IA64_CMCP_VECTOR
:
388 xen_send_IPI_one(cpu
, XEN_CMCP_VECTOR
);
390 case IA64_CPEP_VECTOR
:
391 xen_send_IPI_one(cpu
, XEN_CPEP_VECTOR
);
393 case IA64_TIMER_VECTOR
: {
394 /* this is used only once by check_sal_cache_flush()
398 xen_send_ipi(cpu
, IA64_TIMER_VECTOR
);
405 printk(KERN_WARNING
"Unsupported IPI type 0x%x\n",
407 notify_remote_via_irq(0); /* defaults to 0 irq */
413 xen_register_ipi(void)
416 register_percpu_irq(IA64_IPI_VECTOR
, &xen_ipi_irqaction
);
417 register_percpu_irq(IA64_IPI_RESCHEDULE
, &xen_resched_irqaction
);
418 register_percpu_irq(IA64_IPI_LOCAL_TLB_FLUSH
, &xen_tlb_irqaction
);
423 xen_resend_irq(unsigned int vector
)
425 (void)resend_irq_on_evtchn(vector
);
428 const struct pv_irq_ops xen_irq_ops __initdata
= {
429 .register_ipi
= xen_register_ipi
,
431 .assign_irq_vector
= xen_assign_irq_vector
,
432 .free_irq_vector
= xen_free_irq_vector
,
433 .register_percpu_irq
= xen_register_percpu_irq
,
435 .resend_irq
= xen_resend_irq
,