2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
14 * TILE SMP support routines.
17 #include <linux/smp.h>
18 #include <linux/irq.h>
19 #include <asm/cacheflush.h>
21 HV_Topology smp_topology __write_once;
25 * Top-level send_IPI*() functions to send messages to other cpus.
28 /* Set by smp_send_stop() to avoid recursive panics. */
29 static int stopping_cpus;
31 void send_IPI_single(int cpu, int tag)
33 HV_Recipient recip = {
36 .state = HV_TO_BE_SENT
38 int rc = hv_send_message(&recip, 1, (HV_VirtAddr)&tag, sizeof(tag));
42 void send_IPI_many(const struct cpumask *mask, int tag)
44 HV_Recipient recip[NR_CPUS];
47 int my_cpu = smp_processor_id();
48 for_each_cpu(cpu, mask) {
50 BUG_ON(cpu == my_cpu);
52 r->y = cpu / smp_width;
53 r->x = cpu % smp_width;
54 r->state = HV_TO_BE_SENT;
57 while (sent < nrecip) {
58 int rc = hv_send_message(recip, nrecip,
59 (HV_VirtAddr)&tag, sizeof(tag));
61 if (!stopping_cpus) /* avoid recursive panic */
62 panic("hv_send_message returned %d", rc);
69 void send_IPI_allbutself(int tag)
72 cpumask_copy(&mask, cpu_online_mask);
73 cpumask_clear_cpu(smp_processor_id(), &mask);
74 send_IPI_many(&mask, tag);
79 * Provide smp_call_function_mask, but also run function locally
80 * if specified in the mask.
82 void on_each_cpu_mask(const struct cpumask *mask, void (*func)(void *),
83 void *info, bool wait)
86 smp_call_function_many(mask, func, info, wait);
87 if (cpumask_test_cpu(cpu, mask)) {
97 * Functions related to starting/stopping cpus.
100 /* Handler to start the current cpu. */
101 static void smp_start_cpu_interrupt(void)
103 extern unsigned long start_cpu_function_addr;
104 get_irq_regs()->pc = start_cpu_function_addr;
107 /* Handler to stop the current cpu. */
108 static void smp_stop_cpu_interrupt(void)
110 set_cpu_online(smp_processor_id(), 0);
111 raw_local_irq_disable_all();
116 /* This function calls the 'stop' function on all other CPUs in the system. */
117 void smp_send_stop(void)
120 send_IPI_allbutself(MSG_TAG_STOP_CPU);
125 * Dispatch code called from hv_message_intr() for HV_MSG_TILE hv messages.
127 void evaluate_message(int tag)
130 case MSG_TAG_START_CPU: /* Start up a cpu */
131 smp_start_cpu_interrupt();
134 case MSG_TAG_STOP_CPU: /* Sent to shut down slave CPU's */
135 smp_stop_cpu_interrupt();
138 case MSG_TAG_CALL_FUNCTION_MANY: /* Call function on cpumask */
139 generic_smp_call_function_interrupt();
142 case MSG_TAG_CALL_FUNCTION_SINGLE: /* Call function on one other CPU */
143 generic_smp_call_function_single_interrupt();
147 panic("Unknown IPI message tag %d", tag);
154 * flush_icache_range() code uses smp_call_function().
162 static void ipi_flush_icache_range(void *info)
164 struct ipi_flush *flush = (struct ipi_flush *) info;
165 __flush_icache_range(flush->start, flush->end);
168 void flush_icache_range(unsigned long start, unsigned long end)
170 struct ipi_flush flush = { start, end };
172 on_each_cpu(ipi_flush_icache_range, &flush, 1);
178 * The smp_send_reschedule() path does not use the hv_message_intr()
179 * path but instead the faster tile_dev_intr() path for interrupts.
182 irqreturn_t handle_reschedule_ipi(int irq, void *token)
185 * Nothing to do here; when we return from interrupt, the
186 * rescheduling will occur there. But do bump the interrupt
187 * profiler count in the meantime.
189 __get_cpu_var(irq_stat).irq_resched_count++;
194 void smp_send_reschedule(int cpu)
198 WARN_ON(cpu_is_offline(cpu));
199 coord.y = cpu / smp_width;
200 coord.x = cpu % smp_width;
201 hv_trigger_ipi(coord, IRQ_RESCHEDULE);