x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / tile / kernel / smp.c
blob01e8ab29f43a8bac34f3d0f98ea6e8c2b69cd2df
1 /*
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
12 * more details.
14 * TILE SMP support routines.
17 #include <linux/smp.h>
18 #include <linux/interrupt.h>
19 #include <linux/io.h>
20 #include <linux/irq.h>
21 #include <linux/module.h>
22 #include <asm/cacheflush.h>
23 #include <asm/homecache.h>
26 * We write to width and height with a single store in head_NN.S,
27 * so make the variable aligned to "long".
29 HV_Topology smp_topology __write_once __aligned(sizeof(long));
30 EXPORT_SYMBOL(smp_topology);
32 #if CHIP_HAS_IPI()
33 static unsigned long __iomem *ipi_mappings[NR_CPUS];
34 #endif
38 * Top-level send_IPI*() functions to send messages to other cpus.
41 /* Set by smp_send_stop() to avoid recursive panics. */
42 static int stopping_cpus;
44 static void __send_IPI_many(HV_Recipient *recip, int nrecip, int tag)
46 int sent = 0;
47 while (sent < nrecip) {
48 int rc = hv_send_message(recip, nrecip,
49 (HV_VirtAddr)&tag, sizeof(tag));
50 if (rc < 0) {
51 if (!stopping_cpus) /* avoid recursive panic */
52 panic("hv_send_message returned %d", rc);
53 break;
55 WARN_ONCE(rc == 0, "hv_send_message() returned zero\n");
56 sent += rc;
60 void send_IPI_single(int cpu, int tag)
62 HV_Recipient recip = {
63 .y = cpu / smp_width,
64 .x = cpu % smp_width,
65 .state = HV_TO_BE_SENT
67 __send_IPI_many(&recip, 1, tag);
70 void send_IPI_many(const struct cpumask *mask, int tag)
72 HV_Recipient recip[NR_CPUS];
73 int cpu;
74 int nrecip = 0;
75 int my_cpu = smp_processor_id();
76 for_each_cpu(cpu, mask) {
77 HV_Recipient *r;
78 BUG_ON(cpu == my_cpu);
79 r = &recip[nrecip++];
80 r->y = cpu / smp_width;
81 r->x = cpu % smp_width;
82 r->state = HV_TO_BE_SENT;
84 __send_IPI_many(recip, nrecip, tag);
87 void send_IPI_allbutself(int tag)
89 struct cpumask mask;
90 cpumask_copy(&mask, cpu_online_mask);
91 cpumask_clear_cpu(smp_processor_id(), &mask);
92 send_IPI_many(&mask, tag);
96 * Functions related to starting/stopping cpus.
99 /* Handler to start the current cpu. */
100 static void smp_start_cpu_interrupt(void)
102 get_irq_regs()->pc = start_cpu_function_addr;
105 /* Handler to stop the current cpu. */
106 static void smp_stop_cpu_interrupt(void)
108 arch_local_irq_disable_all();
109 set_cpu_online(smp_processor_id(), 0);
110 for (;;)
111 asm("nap; nop");
114 /* This function calls the 'stop' function on all other CPUs in the system. */
115 void smp_send_stop(void)
117 stopping_cpus = 1;
118 send_IPI_allbutself(MSG_TAG_STOP_CPU);
121 /* On panic, just wait; we may get an smp_send_stop() later on. */
122 void panic_smp_self_stop(void)
124 while (1)
125 asm("nap; nop");
129 * Dispatch code called from hv_message_intr() for HV_MSG_TILE hv messages.
131 void evaluate_message(int tag)
133 switch (tag) {
134 case MSG_TAG_START_CPU: /* Start up a cpu */
135 smp_start_cpu_interrupt();
136 break;
138 case MSG_TAG_STOP_CPU: /* Sent to shut down slave CPU's */
139 smp_stop_cpu_interrupt();
140 break;
142 case MSG_TAG_CALL_FUNCTION_MANY: /* Call function on cpumask */
143 generic_smp_call_function_interrupt();
144 break;
146 case MSG_TAG_CALL_FUNCTION_SINGLE: /* Call function on one other CPU */
147 generic_smp_call_function_single_interrupt();
148 break;
150 default:
151 panic("Unknown IPI message tag %d", tag);
152 break;
158 * flush_icache_range() code uses smp_call_function().
161 struct ipi_flush {
162 unsigned long start;
163 unsigned long end;
166 static void ipi_flush_icache_range(void *info)
168 struct ipi_flush *flush = (struct ipi_flush *) info;
169 __flush_icache_range(flush->start, flush->end);
172 void flush_icache_range(unsigned long start, unsigned long end)
174 struct ipi_flush flush = { start, end };
176 /* If invoked with irqs disabled, we can not issue IPIs. */
177 if (irqs_disabled())
178 flush_remote(0, HV_FLUSH_EVICT_L1I, NULL, 0, 0, 0,
179 NULL, NULL, 0);
180 else {
181 preempt_disable();
182 on_each_cpu(ipi_flush_icache_range, &flush, 1);
183 preempt_enable();
188 /* Called when smp_send_reschedule() triggers IRQ_RESCHEDULE. */
189 static irqreturn_t handle_reschedule_ipi(int irq, void *token)
191 __get_cpu_var(irq_stat).irq_resched_count++;
192 scheduler_ipi();
194 return IRQ_HANDLED;
197 static struct irqaction resched_action = {
198 .handler = handle_reschedule_ipi,
199 .name = "resched",
200 .dev_id = handle_reschedule_ipi /* unique token */,
203 void __init ipi_init(void)
205 #if CHIP_HAS_IPI()
206 int cpu;
207 /* Map IPI trigger MMIO addresses. */
208 for_each_possible_cpu(cpu) {
209 HV_Coord tile;
210 HV_PTE pte;
211 unsigned long offset;
213 tile.x = cpu_x(cpu);
214 tile.y = cpu_y(cpu);
215 if (hv_get_ipi_pte(tile, KERNEL_PL, &pte) != 0)
216 panic("Failed to initialize IPI for cpu %d\n", cpu);
218 offset = PFN_PHYS(pte_pfn(pte));
219 ipi_mappings[cpu] = ioremap_prot(offset, PAGE_SIZE, pte);
221 #endif
223 /* Bind handle_reschedule_ipi() to IRQ_RESCHEDULE. */
224 tile_irq_activate(IRQ_RESCHEDULE, TILE_IRQ_PERCPU);
225 BUG_ON(setup_irq(IRQ_RESCHEDULE, &resched_action));
228 #if CHIP_HAS_IPI()
230 void smp_send_reschedule(int cpu)
232 WARN_ON(cpu_is_offline(cpu));
235 * We just want to do an MMIO store. The traditional writeq()
236 * functions aren't really correct here, since they're always
237 * directed at the PCI shim. For now, just do a raw store,
238 * casting away the __iomem attribute.
240 ((unsigned long __force *)ipi_mappings[cpu])[IRQ_RESCHEDULE] = 0;
243 #else
245 void smp_send_reschedule(int cpu)
247 HV_Coord coord;
249 WARN_ON(cpu_is_offline(cpu));
251 coord.y = cpu_y(cpu);
252 coord.x = cpu_x(cpu);
253 hv_trigger_ipi(coord, IRQ_RESCHEDULE);
256 #endif /* CHIP_HAS_IPI() */