• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/arch/ia64/xen/
1/******************************************************************************
2 * arch/ia64/xen/irq_xen.c
3 *
4 * Copyright (c) 2008 Isaku Yamahata <yamahata at valinux co jp>
5 *                    VA Linux Systems Japan K.K.
6 *
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.
11 *
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.
16 *
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
20 *
21 */
22
23#include <linux/cpu.h>
24
25#include <xen/interface/xen.h>
26#include <xen/interface/callback.h>
27#include <xen/events.h>
28
29#include <asm/xen/privop.h>
30
31#include "irq_xen.h"
32
33/***************************************************************************
34 * pv_irq_ops
35 * irq operations
36 */
37
38static int
39xen_assign_irq_vector(int irq)
40{
41	struct physdev_irq irq_op;
42
43	irq_op.irq = irq;
44	if (HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector, &irq_op))
45		return -ENOSPC;
46
47	return irq_op.vector;
48}
49
50static void
51xen_free_irq_vector(int vector)
52{
53	struct physdev_irq irq_op;
54
55	if (vector < IA64_FIRST_DEVICE_VECTOR ||
56	    vector > IA64_LAST_DEVICE_VECTOR)
57		return;
58
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",
62		       __func__, vector);
63}
64
65
66static DEFINE_PER_CPU(int, xen_timer_irq) = -1;
67static DEFINE_PER_CPU(int, xen_ipi_irq) = -1;
68static DEFINE_PER_CPU(int, xen_resched_irq) = -1;
69static DEFINE_PER_CPU(int, xen_cmc_irq) = -1;
70static DEFINE_PER_CPU(int, xen_cmcp_irq) = -1;
71static DEFINE_PER_CPU(int, xen_cpep_irq) = -1;
72#define NAME_SIZE	15
73static DEFINE_PER_CPU(char[NAME_SIZE], xen_timer_name);
74static DEFINE_PER_CPU(char[NAME_SIZE], xen_ipi_name);
75static DEFINE_PER_CPU(char[NAME_SIZE], xen_resched_name);
76static DEFINE_PER_CPU(char[NAME_SIZE], xen_cmc_name);
77static DEFINE_PER_CPU(char[NAME_SIZE], xen_cmcp_name);
78static DEFINE_PER_CPU(char[NAME_SIZE], xen_cpep_name);
79#undef NAME_SIZE
80
81struct saved_irq {
82	unsigned int irq;
83	struct irqaction *action;
84};
85/* 16 should be far optimistic value, since only several percpu irqs
86 * are registered early.
87 */
88#define MAX_LATE_IRQ	16
89static struct saved_irq saved_percpu_irqs[MAX_LATE_IRQ];
90static unsigned short late_irq_cnt;
91static unsigned short saved_irq_cnt;
92static int xen_slab_ready;
93
94#ifdef CONFIG_SMP
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.
98 */
99static irqreturn_t
100xen_dummy_handler(int irq, void *dev_id)
101{
102
103	return IRQ_HANDLED;
104}
105
106static struct irqaction xen_ipi_irqaction = {
107	.handler =	handle_IPI,
108	.flags =	IRQF_DISABLED,
109	.name =		"IPI"
110};
111
112static struct irqaction xen_resched_irqaction = {
113	.handler =	xen_dummy_handler,
114	.flags =	IRQF_DISABLED,
115	.name =		"resched"
116};
117
118static struct irqaction xen_tlb_irqaction = {
119	.handler =	xen_dummy_handler,
120	.flags =	IRQF_DISABLED,
121	.name =		"tlb_flush"
122};
123#endif
124
125static void
126__xen_register_percpu_irq(unsigned int cpu, unsigned int vec,
127			struct irqaction *action, int save)
128{
129	struct irq_desc *desc;
130	int irq = 0;
131
132	if (xen_slab_ready) {
133		switch (vec) {
134		case IA64_TIMER_VECTOR:
135			snprintf(per_cpu(xen_timer_name, cpu),
136				 sizeof(per_cpu(xen_timer_name, cpu)),
137				 "%s%d", action->name, cpu);
138			irq = bind_virq_to_irqhandler(VIRQ_ITC, cpu,
139				action->handler, action->flags,
140				per_cpu(xen_timer_name, cpu), action->dev_id);
141			per_cpu(xen_timer_irq, cpu) = irq;
142			break;
143		case IA64_IPI_RESCHEDULE:
144			snprintf(per_cpu(xen_resched_name, cpu),
145				 sizeof(per_cpu(xen_resched_name, cpu)),
146				 "%s%d", action->name, cpu);
147			irq = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR, cpu,
148				action->handler, action->flags,
149				per_cpu(xen_resched_name, cpu), action->dev_id);
150			per_cpu(xen_resched_irq, cpu) = irq;
151			break;
152		case IA64_IPI_VECTOR:
153			snprintf(per_cpu(xen_ipi_name, cpu),
154				 sizeof(per_cpu(xen_ipi_name, cpu)),
155				 "%s%d", action->name, cpu);
156			irq = bind_ipi_to_irqhandler(XEN_IPI_VECTOR, cpu,
157				action->handler, action->flags,
158				per_cpu(xen_ipi_name, cpu), action->dev_id);
159			per_cpu(xen_ipi_irq, cpu) = irq;
160			break;
161		case IA64_CMC_VECTOR:
162			snprintf(per_cpu(xen_cmc_name, cpu),
163				 sizeof(per_cpu(xen_cmc_name, cpu)),
164				 "%s%d", action->name, cpu);
165			irq = bind_virq_to_irqhandler(VIRQ_MCA_CMC, cpu,
166						action->handler,
167						action->flags,
168						per_cpu(xen_cmc_name, cpu),
169						action->dev_id);
170			per_cpu(xen_cmc_irq, cpu) = irq;
171			break;
172		case IA64_CMCP_VECTOR:
173			snprintf(per_cpu(xen_cmcp_name, cpu),
174				 sizeof(per_cpu(xen_cmcp_name, cpu)),
175				 "%s%d", action->name, cpu);
176			irq = bind_ipi_to_irqhandler(XEN_CMCP_VECTOR, cpu,
177						action->handler,
178						action->flags,
179						per_cpu(xen_cmcp_name, cpu),
180						action->dev_id);
181			per_cpu(xen_cmcp_irq, cpu) = irq;
182			break;
183		case IA64_CPEP_VECTOR:
184			snprintf(per_cpu(xen_cpep_name, cpu),
185				 sizeof(per_cpu(xen_cpep_name, cpu)),
186				 "%s%d", action->name, cpu);
187			irq = bind_ipi_to_irqhandler(XEN_CPEP_VECTOR, cpu,
188						action->handler,
189						action->flags,
190						per_cpu(xen_cpep_name, cpu),
191						action->dev_id);
192			per_cpu(xen_cpep_irq, cpu) = irq;
193			break;
194		case IA64_CPE_VECTOR:
195		case IA64_MCA_RENDEZ_VECTOR:
196		case IA64_PERFMON_VECTOR:
197		case IA64_MCA_WAKEUP_VECTOR:
198		case IA64_SPURIOUS_INT_VECTOR:
199			/* No need to complain, these aren't supported. */
200			break;
201		default:
202			printk(KERN_WARNING "Percpu irq %d is unsupported "
203			       "by xen!\n", vec);
204			break;
205		}
206		BUG_ON(irq < 0);
207
208		if (irq > 0) {
209			/*
210			 * Mark percpu.  Without this, migrate_irqs() will
211			 * mark the interrupt for migrations and trigger it
212			 * on cpu hotplug.
213			 */
214			desc = irq_desc + irq;
215			desc->status |= IRQ_PER_CPU;
216		}
217	}
218
219	/* For BSP, we cache registered percpu irqs, and then re-walk
220	 * them when initializing APs
221	 */
222	if (!cpu && save) {
223		BUG_ON(saved_irq_cnt == MAX_LATE_IRQ);
224		saved_percpu_irqs[saved_irq_cnt].irq = vec;
225		saved_percpu_irqs[saved_irq_cnt].action = action;
226		saved_irq_cnt++;
227		if (!xen_slab_ready)
228			late_irq_cnt++;
229	}
230}
231
232static void
233xen_register_percpu_irq(ia64_vector vec, struct irqaction *action)
234{
235	__xen_register_percpu_irq(smp_processor_id(), vec, action, 1);
236}
237
238static void
239xen_bind_early_percpu_irq(void)
240{
241	int i;
242
243	xen_slab_ready = 1;
244	/* There's no race when accessing this cached array, since only
245	 * BSP will face with such step shortly
246	 */
247	for (i = 0; i < late_irq_cnt; i++)
248		__xen_register_percpu_irq(smp_processor_id(),
249					  saved_percpu_irqs[i].irq,
250					  saved_percpu_irqs[i].action, 0);
251}
252
253
254#ifdef CONFIG_HOTPLUG_CPU
255static int __devinit
256unbind_evtchn_callback(struct notifier_block *nfb,
257		       unsigned long action, void *hcpu)
258{
259	unsigned int cpu = (unsigned long)hcpu;
260
261	if (action == CPU_DEAD) {
262		/* Unregister evtchn.  */
263		if (per_cpu(xen_cpep_irq, cpu) >= 0) {
264			unbind_from_irqhandler(per_cpu(xen_cpep_irq, cpu),
265					       NULL);
266			per_cpu(xen_cpep_irq, cpu) = -1;
267		}
268		if (per_cpu(xen_cmcp_irq, cpu) >= 0) {
269			unbind_from_irqhandler(per_cpu(xen_cmcp_irq, cpu),
270					       NULL);
271			per_cpu(xen_cmcp_irq, cpu) = -1;
272		}
273		if (per_cpu(xen_cmc_irq, cpu) >= 0) {
274			unbind_from_irqhandler(per_cpu(xen_cmc_irq, cpu), NULL);
275			per_cpu(xen_cmc_irq, cpu) = -1;
276		}
277		if (per_cpu(xen_ipi_irq, cpu) >= 0) {
278			unbind_from_irqhandler(per_cpu(xen_ipi_irq, cpu), NULL);
279			per_cpu(xen_ipi_irq, cpu) = -1;
280		}
281		if (per_cpu(xen_resched_irq, cpu) >= 0) {
282			unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu),
283					       NULL);
284			per_cpu(xen_resched_irq, cpu) = -1;
285		}
286		if (per_cpu(xen_timer_irq, cpu) >= 0) {
287			unbind_from_irqhandler(per_cpu(xen_timer_irq, cpu),
288					       NULL);
289			per_cpu(xen_timer_irq, cpu) = -1;
290		}
291	}
292	return NOTIFY_OK;
293}
294
295static struct notifier_block unbind_evtchn_notifier = {
296	.notifier_call = unbind_evtchn_callback,
297	.priority = 0
298};
299#endif
300
301void xen_smp_intr_init_early(unsigned int cpu)
302{
303#ifdef CONFIG_SMP
304	unsigned int i;
305
306	for (i = 0; i < saved_irq_cnt; i++)
307		__xen_register_percpu_irq(cpu, saved_percpu_irqs[i].irq,
308					  saved_percpu_irqs[i].action, 0);
309#endif
310}
311
312void xen_smp_intr_init(void)
313{
314#ifdef CONFIG_SMP
315	unsigned int cpu = smp_processor_id();
316	struct callback_register event = {
317		.type = CALLBACKTYPE_event,
318		.address = { .ip = (unsigned long)&xen_event_callback },
319	};
320
321	if (cpu == 0) {
322		/* Initialization was already done for boot cpu.  */
323#ifdef CONFIG_HOTPLUG_CPU
324		/* Register the notifier only once.  */
325		register_cpu_notifier(&unbind_evtchn_notifier);
326#endif
327		return;
328	}
329
330	/* This should be piggyback when setup vcpu guest context */
331	BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register, &event));
332#endif /* CONFIG_SMP */
333}
334
335void __init
336xen_irq_init(void)
337{
338	struct callback_register event = {
339		.type = CALLBACKTYPE_event,
340		.address = { .ip = (unsigned long)&xen_event_callback },
341	};
342
343	xen_init_IRQ();
344	BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register, &event));
345	late_time_init = xen_bind_early_percpu_irq;
346}
347
348void
349xen_platform_send_ipi(int cpu, int vector, int delivery_mode, int redirect)
350{
351#ifdef CONFIG_SMP
352	/* TODO: we need to call vcpu_up here */
353	if (unlikely(vector == ap_wakeup_vector)) {
354		xen_smp_intr_init_early(cpu);
355
356		xen_send_ipi(cpu, vector);
357		/* vcpu_prepare_and_up(cpu); */
358		return;
359	}
360#endif
361
362	switch (vector) {
363	case IA64_IPI_VECTOR:
364		xen_send_IPI_one(cpu, XEN_IPI_VECTOR);
365		break;
366	case IA64_IPI_RESCHEDULE:
367		xen_send_IPI_one(cpu, XEN_RESCHEDULE_VECTOR);
368		break;
369	case IA64_CMCP_VECTOR:
370		xen_send_IPI_one(cpu, XEN_CMCP_VECTOR);
371		break;
372	case IA64_CPEP_VECTOR:
373		xen_send_IPI_one(cpu, XEN_CPEP_VECTOR);
374		break;
375	case IA64_TIMER_VECTOR: {
376		/* this is used only once by check_sal_cache_flush()
377		   at boot time */
378		static int used = 0;
379		if (!used) {
380			xen_send_ipi(cpu, IA64_TIMER_VECTOR);
381			used = 1;
382			break;
383		}
384		/* fallthrough */
385	}
386	default:
387		printk(KERN_WARNING "Unsupported IPI type 0x%x\n",
388		       vector);
389		notify_remote_via_irq(0); /* defaults to 0 irq */
390		break;
391	}
392}
393
394static void __init
395xen_register_ipi(void)
396{
397#ifdef CONFIG_SMP
398	register_percpu_irq(IA64_IPI_VECTOR, &xen_ipi_irqaction);
399	register_percpu_irq(IA64_IPI_RESCHEDULE, &xen_resched_irqaction);
400	register_percpu_irq(IA64_IPI_LOCAL_TLB_FLUSH, &xen_tlb_irqaction);
401#endif
402}
403
404static void
405xen_resend_irq(unsigned int vector)
406{
407	(void)resend_irq_on_evtchn(vector);
408}
409
410const struct pv_irq_ops xen_irq_ops __initdata = {
411	.register_ipi = xen_register_ipi,
412
413	.assign_irq_vector = xen_assign_irq_vector,
414	.free_irq_vector = xen_free_irq_vector,
415	.register_percpu_irq = xen_register_percpu_irq,
416
417	.resend_irq = xen_resend_irq,
418};
419