2 #include <linux/slab.h>
3 #include <linux/cpumask.h>
4 #include <linux/percpu.h>
6 #include <xen/events.h>
8 #include <xen/hvc-console.h>
12 static DEFINE_PER_CPU(struct xen_common_irq, xen_resched_irq) = { .irq = -1 };
13 static DEFINE_PER_CPU(struct xen_common_irq, xen_callfunc_irq) = { .irq = -1 };
14 static DEFINE_PER_CPU(struct xen_common_irq, xen_callfuncsingle_irq) = { .irq = -1 };
15 static DEFINE_PER_CPU(struct xen_common_irq, xen_debug_irq) = { .irq = -1 };
17 static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id);
18 static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id);
21 * Reschedule call back.
23 static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
25 inc_irq_stat(irq_resched_count);
31 void xen_smp_intr_free(unsigned int cpu)
33 if (per_cpu(xen_resched_irq, cpu).irq >= 0) {
34 unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu).irq, NULL);
35 per_cpu(xen_resched_irq, cpu).irq = -1;
36 kfree(per_cpu(xen_resched_irq, cpu).name);
37 per_cpu(xen_resched_irq, cpu).name = NULL;
39 if (per_cpu(xen_callfunc_irq, cpu).irq >= 0) {
40 unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu).irq, NULL);
41 per_cpu(xen_callfunc_irq, cpu).irq = -1;
42 kfree(per_cpu(xen_callfunc_irq, cpu).name);
43 per_cpu(xen_callfunc_irq, cpu).name = NULL;
45 if (per_cpu(xen_debug_irq, cpu).irq >= 0) {
46 unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu).irq, NULL);
47 per_cpu(xen_debug_irq, cpu).irq = -1;
48 kfree(per_cpu(xen_debug_irq, cpu).name);
49 per_cpu(xen_debug_irq, cpu).name = NULL;
51 if (per_cpu(xen_callfuncsingle_irq, cpu).irq >= 0) {
52 unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu).irq,
54 per_cpu(xen_callfuncsingle_irq, cpu).irq = -1;
55 kfree(per_cpu(xen_callfuncsingle_irq, cpu).name);
56 per_cpu(xen_callfuncsingle_irq, cpu).name = NULL;
60 int xen_smp_intr_init(unsigned int cpu)
63 char *resched_name, *callfunc_name, *debug_name;
65 resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu);
66 rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR,
68 xen_reschedule_interrupt,
69 IRQF_PERCPU|IRQF_NOBALANCING,
74 per_cpu(xen_resched_irq, cpu).irq = rc;
75 per_cpu(xen_resched_irq, cpu).name = resched_name;
77 callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu);
78 rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR,
80 xen_call_function_interrupt,
81 IRQF_PERCPU|IRQF_NOBALANCING,
86 per_cpu(xen_callfunc_irq, cpu).irq = rc;
87 per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
89 debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
90 rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, xen_debug_interrupt,
91 IRQF_PERCPU | IRQF_NOBALANCING,
95 per_cpu(xen_debug_irq, cpu).irq = rc;
96 per_cpu(xen_debug_irq, cpu).name = debug_name;
98 callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
99 rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
101 xen_call_function_single_interrupt,
102 IRQF_PERCPU|IRQF_NOBALANCING,
107 per_cpu(xen_callfuncsingle_irq, cpu).irq = rc;
108 per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name;
113 xen_smp_intr_free(cpu);
117 void xen_smp_send_reschedule(int cpu)
119 xen_send_IPI_one(cpu, XEN_RESCHEDULE_VECTOR);
122 static void __xen_send_IPI_mask(const struct cpumask *mask,
127 for_each_cpu_and(cpu, mask, cpu_online_mask)
128 xen_send_IPI_one(cpu, vector);
131 void xen_smp_send_call_function_ipi(const struct cpumask *mask)
135 __xen_send_IPI_mask(mask, XEN_CALL_FUNCTION_VECTOR);
137 /* Make sure other vcpus get a chance to run if they need to. */
138 for_each_cpu(cpu, mask) {
139 if (xen_vcpu_stolen(cpu)) {
140 HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
146 void xen_smp_send_call_function_single_ipi(int cpu)
148 __xen_send_IPI_mask(cpumask_of(cpu),
149 XEN_CALL_FUNCTION_SINGLE_VECTOR);
152 static inline int xen_map_vector(int vector)
157 case RESCHEDULE_VECTOR:
158 xen_vector = XEN_RESCHEDULE_VECTOR;
160 case CALL_FUNCTION_VECTOR:
161 xen_vector = XEN_CALL_FUNCTION_VECTOR;
163 case CALL_FUNCTION_SINGLE_VECTOR:
164 xen_vector = XEN_CALL_FUNCTION_SINGLE_VECTOR;
166 case IRQ_WORK_VECTOR:
167 xen_vector = XEN_IRQ_WORK_VECTOR;
171 case APIC_DM_NMI: /* Some use that instead of NMI_VECTOR */
172 xen_vector = XEN_NMI_VECTOR;
177 printk(KERN_ERR "xen: vector 0x%x is not implemented\n",
184 void xen_send_IPI_mask(const struct cpumask *mask,
187 int xen_vector = xen_map_vector(vector);
190 __xen_send_IPI_mask(mask, xen_vector);
193 void xen_send_IPI_all(int vector)
195 int xen_vector = xen_map_vector(vector);
198 __xen_send_IPI_mask(cpu_online_mask, xen_vector);
201 void xen_send_IPI_self(int vector)
203 int xen_vector = xen_map_vector(vector);
206 xen_send_IPI_one(smp_processor_id(), xen_vector);
209 void xen_send_IPI_mask_allbutself(const struct cpumask *mask,
213 unsigned int this_cpu = smp_processor_id();
214 int xen_vector = xen_map_vector(vector);
216 if (!(num_online_cpus() > 1) || (xen_vector < 0))
219 for_each_cpu_and(cpu, mask, cpu_online_mask) {
223 xen_send_IPI_one(cpu, xen_vector);
227 void xen_send_IPI_allbutself(int vector)
229 xen_send_IPI_mask_allbutself(cpu_online_mask, vector);
232 static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id)
235 generic_smp_call_function_interrupt();
236 inc_irq_stat(irq_call_count);
242 static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id)
245 generic_smp_call_function_single_interrupt();
246 inc_irq_stat(irq_call_count);