3 #include <linux/slab.h>
4 #include <linux/cpumask.h>
5 #include <linux/percpu.h>
7 #include <xen/events.h>
9 #include <xen/hvc-console.h>
13 static DEFINE_PER_CPU(struct xen_common_irq, xen_resched_irq) = { .irq = -1 };
14 static DEFINE_PER_CPU(struct xen_common_irq, xen_callfunc_irq) = { .irq = -1 };
15 static DEFINE_PER_CPU(struct xen_common_irq, xen_callfuncsingle_irq) = { .irq = -1 };
16 static DEFINE_PER_CPU(struct xen_common_irq, xen_debug_irq) = { .irq = -1 };
18 static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id);
19 static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id);
22 * Reschedule call back.
24 static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
26 inc_irq_stat(irq_resched_count);
32 void xen_smp_intr_free(unsigned int cpu)
34 if (per_cpu(xen_resched_irq, cpu).irq >= 0) {
35 unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu).irq, NULL);
36 per_cpu(xen_resched_irq, cpu).irq = -1;
37 kfree(per_cpu(xen_resched_irq, cpu).name);
38 per_cpu(xen_resched_irq, cpu).name = NULL;
40 if (per_cpu(xen_callfunc_irq, cpu).irq >= 0) {
41 unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu).irq, NULL);
42 per_cpu(xen_callfunc_irq, cpu).irq = -1;
43 kfree(per_cpu(xen_callfunc_irq, cpu).name);
44 per_cpu(xen_callfunc_irq, cpu).name = NULL;
46 if (per_cpu(xen_debug_irq, cpu).irq >= 0) {
47 unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu).irq, NULL);
48 per_cpu(xen_debug_irq, cpu).irq = -1;
49 kfree(per_cpu(xen_debug_irq, cpu).name);
50 per_cpu(xen_debug_irq, cpu).name = NULL;
52 if (per_cpu(xen_callfuncsingle_irq, cpu).irq >= 0) {
53 unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu).irq,
55 per_cpu(xen_callfuncsingle_irq, cpu).irq = -1;
56 kfree(per_cpu(xen_callfuncsingle_irq, cpu).name);
57 per_cpu(xen_callfuncsingle_irq, cpu).name = NULL;
61 int xen_smp_intr_init(unsigned int cpu)
64 char *resched_name, *callfunc_name, *debug_name;
66 resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu);
67 rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR,
69 xen_reschedule_interrupt,
70 IRQF_PERCPU|IRQF_NOBALANCING,
75 per_cpu(xen_resched_irq, cpu).irq = rc;
76 per_cpu(xen_resched_irq, cpu).name = resched_name;
78 callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu);
79 rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR,
81 xen_call_function_interrupt,
82 IRQF_PERCPU|IRQF_NOBALANCING,
87 per_cpu(xen_callfunc_irq, cpu).irq = rc;
88 per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
90 debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
91 rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, xen_debug_interrupt,
92 IRQF_PERCPU | IRQF_NOBALANCING,
96 per_cpu(xen_debug_irq, cpu).irq = rc;
97 per_cpu(xen_debug_irq, cpu).name = debug_name;
99 callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
100 rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
102 xen_call_function_single_interrupt,
103 IRQF_PERCPU|IRQF_NOBALANCING,
108 per_cpu(xen_callfuncsingle_irq, cpu).irq = rc;
109 per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name;
114 xen_smp_intr_free(cpu);
118 void __init xen_smp_cpus_done(unsigned int max_cpus)
120 int cpu, rc, count = 0;
122 if (xen_hvm_domain())
123 native_smp_cpus_done(max_cpus);
125 if (xen_have_vcpu_info_placement)
128 for_each_online_cpu(cpu) {
129 if (xen_vcpu_nr(cpu) < MAX_VIRT_CPUS)
136 * Reset vcpu_info so this cpu cannot be onlined again.
138 xen_vcpu_info_reset(cpu);
141 pr_warn("%s: failed to bring CPU %d down, error %d\n",
145 WARN(count, "%s: brought %d CPUs offline\n", __func__, count);
148 void xen_smp_send_reschedule(int cpu)
150 xen_send_IPI_one(cpu, XEN_RESCHEDULE_VECTOR);
153 static void __xen_send_IPI_mask(const struct cpumask *mask,
158 for_each_cpu_and(cpu, mask, cpu_online_mask)
159 xen_send_IPI_one(cpu, vector);
162 void xen_smp_send_call_function_ipi(const struct cpumask *mask)
166 __xen_send_IPI_mask(mask, XEN_CALL_FUNCTION_VECTOR);
168 /* Make sure other vcpus get a chance to run if they need to. */
169 for_each_cpu(cpu, mask) {
170 if (xen_vcpu_stolen(cpu)) {
171 HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
177 void xen_smp_send_call_function_single_ipi(int cpu)
179 __xen_send_IPI_mask(cpumask_of(cpu),
180 XEN_CALL_FUNCTION_SINGLE_VECTOR);
183 static inline int xen_map_vector(int vector)
188 case RESCHEDULE_VECTOR:
189 xen_vector = XEN_RESCHEDULE_VECTOR;
191 case CALL_FUNCTION_VECTOR:
192 xen_vector = XEN_CALL_FUNCTION_VECTOR;
194 case CALL_FUNCTION_SINGLE_VECTOR:
195 xen_vector = XEN_CALL_FUNCTION_SINGLE_VECTOR;
197 case IRQ_WORK_VECTOR:
198 xen_vector = XEN_IRQ_WORK_VECTOR;
202 case APIC_DM_NMI: /* Some use that instead of NMI_VECTOR */
203 xen_vector = XEN_NMI_VECTOR;
208 printk(KERN_ERR "xen: vector 0x%x is not implemented\n",
215 void xen_send_IPI_mask(const struct cpumask *mask,
218 int xen_vector = xen_map_vector(vector);
221 __xen_send_IPI_mask(mask, xen_vector);
224 void xen_send_IPI_all(int vector)
226 int xen_vector = xen_map_vector(vector);
229 __xen_send_IPI_mask(cpu_online_mask, xen_vector);
232 void xen_send_IPI_self(int vector)
234 int xen_vector = xen_map_vector(vector);
237 xen_send_IPI_one(smp_processor_id(), xen_vector);
240 void xen_send_IPI_mask_allbutself(const struct cpumask *mask,
244 unsigned int this_cpu = smp_processor_id();
245 int xen_vector = xen_map_vector(vector);
247 if (!(num_online_cpus() > 1) || (xen_vector < 0))
250 for_each_cpu_and(cpu, mask, cpu_online_mask) {
254 xen_send_IPI_one(cpu, xen_vector);
258 void xen_send_IPI_allbutself(int vector)
260 xen_send_IPI_mask_allbutself(cpu_online_mask, vector);
263 static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id)
266 generic_smp_call_function_interrupt();
267 inc_irq_stat(irq_call_count);
273 static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id)
276 generic_smp_call_function_single_interrupt();
277 inc_irq_stat(irq_call_count);