1 #include <linux/types.h>
4 #include <hwregs/intr_vect.h>
5 #include <hwregs/intr_vect_defs.h>
6 #include <asm/tlbflush.h>
7 #include <asm/mmu_context.h>
8 #include <hwregs/asm/mmu_defs_asm.h>
9 #include <hwregs/supp_reg.h>
10 #include <asm/atomic.h>
12 #include <linux/err.h>
13 #include <linux/init.h>
14 #include <linux/timex.h>
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/cpumask.h>
18 #include <linux/interrupt.h>
19 #include <linux/module.h>
21 #define IPI_SCHEDULE 1
23 #define IPI_FLUSH_TLB 4
26 #define FLUSH_ALL (void*)0xffffffff
28 /* Vector of locks used for various atomic operations */
29 spinlock_t cris_atomic_locks[] = { [0 ... LOCK_COUNT - 1] = SPIN_LOCK_UNLOCKED};
32 cpumask_t cpu_online_map = CPU_MASK_NONE;
33 EXPORT_SYMBOL(cpu_online_map);
34 cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
35 cpumask_t cpu_possible_map;
36 EXPORT_SYMBOL(cpu_possible_map);
37 EXPORT_SYMBOL(phys_cpu_present_map);
39 /* Variables used during SMP boot */
40 volatile int cpu_now_booting = 0;
41 volatile struct thread_info *smp_init_current_idle_thread;
43 /* Variables used during IPI */
44 static DEFINE_SPINLOCK(call_lock);
45 static DEFINE_SPINLOCK(tlbstate_lock);
47 struct call_data_struct {
48 void (*func) (void *info);
53 static struct call_data_struct * call_data;
55 static struct mm_struct* flush_mm;
56 static struct vm_area_struct* flush_vma;
57 static unsigned long flush_addr;
59 extern int setup_irq(int, struct irqaction *);
62 static unsigned long irq_regs[NR_CPUS] = {
67 static irqreturn_t crisv32_ipi_interrupt(int irq, void *dev_id);
68 static int send_ipi(int vector, int wait, cpumask_t cpu_mask);
69 static struct irqaction irq_ipi = {
70 .handler = crisv32_ipi_interrupt,
71 .flags = IRQF_DISABLED,
72 .mask = CPU_MASK_NONE,
76 extern void cris_mmu_init(void);
77 extern void cris_timer_init(void);
79 /* SMP initialization */
80 void __init smp_prepare_cpus(unsigned int max_cpus)
84 /* From now on we can expect IPIs so set them up */
85 setup_irq(IPI_INTR_VECT, &irq_ipi);
87 /* Mark all possible CPUs as present */
88 for (i = 0; i < max_cpus; i++)
89 cpu_set(i, phys_cpu_present_map);
92 void __devinit smp_prepare_boot_cpu(void)
94 /* PGD pointer has moved after per_cpu initialization so
98 pgd = (pgd_t**)&per_cpu(current_pgd, smp_processor_id());
101 SUPP_REG_WR(RW_MM_TLB_PGD, pgd);
103 SUPP_REG_WR(RW_MM_TLB_PGD, pgd);
105 cpu_set(0, cpu_online_map);
106 cpu_set(0, phys_cpu_present_map);
107 cpu_set(0, cpu_possible_map);
110 void __init smp_cpus_done(unsigned int max_cpus)
114 /* Bring one cpu online.*/
116 smp_boot_one_cpu(int cpuid)
119 struct task_struct *idle;
120 cpumask_t cpu_mask = CPU_MASK_NONE;
122 idle = fork_idle(cpuid);
124 panic("SMP: fork failed for CPU:%d", cpuid);
126 task_thread_info(idle)->cpu = cpuid;
128 /* Information to the CPU that is about to boot */
129 smp_init_current_idle_thread = task_thread_info(idle);
130 cpu_now_booting = cpuid;
133 cpu_set(cpuid, cpu_online_map);
134 cpu_set(cpuid, cpu_mask);
135 send_ipi(IPI_BOOT, 0, cpu_mask);
136 cpu_clear(cpuid, cpu_online_map);
138 /* Wait for CPU to come online */
139 for (timeout = 0; timeout < 10000; timeout++) {
140 if(cpu_online(cpuid)) {
142 smp_init_current_idle_thread = NULL;
143 return 0; /* CPU online */
149 put_task_struct(idle);
152 printk(KERN_CRIT "SMP: CPU:%d is stuck.\n", cpuid);
156 /* Secondary CPUs starts using C here. Here we need to setup CPU
157 * specific stuff such as the local timer and the MMU. */
158 void __init smp_callin(void)
160 extern void cpu_idle(void);
162 int cpu = cpu_now_booting;
163 reg_intr_vect_rw_mask vect_mask = {0};
165 /* Initialise the idle task for this CPU */
166 atomic_inc(&init_mm.mm_count);
167 current->active_mm = &init_mm;
173 /* Setup local timer. */
176 /* Enable IRQ and idle */
177 REG_WR(intr_vect, irq_regs[cpu], rw_mask, vect_mask);
178 unmask_irq(IPI_INTR_VECT);
179 unmask_irq(TIMER0_INTR_VECT);
181 notify_cpu_starting(cpu);
184 cpu_set(cpu, cpu_online_map);
188 /* Stop execution on this CPU.*/
189 void stop_this_cpu(void* dummy)
192 asm volatile("halt");
196 void smp_send_stop(void)
198 smp_call_function(stop_this_cpu, NULL, 0);
201 int setup_profiling_timer(unsigned int multiplier)
207 /* cache_decay_ticks is used by the scheduler to decide if a process
208 * is "hot" on one CPU. A higher value means a higher penalty to move
209 * a process to another CPU. Our cache is rather small so we report
212 unsigned long cache_decay_ticks = 1;
214 int __cpuinit __cpu_up(unsigned int cpu)
216 smp_boot_one_cpu(cpu);
217 return cpu_online(cpu) ? 0 : -ENOSYS;
220 void smp_send_reschedule(int cpu)
222 cpumask_t cpu_mask = CPU_MASK_NONE;
223 cpu_set(cpu, cpu_mask);
224 send_ipi(IPI_SCHEDULE, 0, cpu_mask);
229 * Flush needs to be done on the local CPU and on any other CPU that
230 * may have the same mapping. The mm->cpu_vm_mask is used to keep track
231 * of which CPUs that a specific process has been executed on.
233 void flush_tlb_common(struct mm_struct* mm, struct vm_area_struct* vma, unsigned long addr)
238 spin_lock_irqsave(&tlbstate_lock, flags);
239 cpu_mask = (mm == FLUSH_ALL ? CPU_MASK_ALL : mm->cpu_vm_mask);
240 cpu_clear(smp_processor_id(), cpu_mask);
244 send_ipi(IPI_FLUSH_TLB, 1, cpu_mask);
245 spin_unlock_irqrestore(&tlbstate_lock, flags);
248 void flush_tlb_all(void)
251 flush_tlb_common(FLUSH_ALL, FLUSH_ALL, 0);
254 void flush_tlb_mm(struct mm_struct *mm)
257 flush_tlb_common(mm, FLUSH_ALL, 0);
258 /* No more mappings in other CPUs */
259 cpus_clear(mm->cpu_vm_mask);
260 cpu_set(smp_processor_id(), mm->cpu_vm_mask);
263 void flush_tlb_page(struct vm_area_struct *vma,
266 __flush_tlb_page(vma, addr);
267 flush_tlb_common(vma->vm_mm, vma, addr);
270 /* Inter processor interrupts
272 * The IPIs are used for:
273 * * Force a schedule on a CPU
274 * * FLush TLB on other CPUs
275 * * Call a function on other CPUs
278 int send_ipi(int vector, int wait, cpumask_t cpu_mask)
281 reg_intr_vect_rw_ipi ipi = REG_RD(intr_vect, irq_regs[i], rw_ipi);
284 /* Calculate CPUs to send to. */
285 cpus_and(cpu_mask, cpu_mask, cpu_online_map);
288 for_each_cpu_mask(i, cpu_mask)
290 ipi.vector |= vector;
291 REG_WR(intr_vect, irq_regs[i], rw_ipi, ipi);
294 /* Wait for IPI to finish on other CPUS */
296 for_each_cpu_mask(i, cpu_mask) {
298 for (j = 0 ; j < 1000; j++) {
299 ipi = REG_RD(intr_vect, irq_regs[i], rw_ipi);
307 printk("SMP call timeout from %d to %d\n", smp_processor_id(), i);
317 * You must not call this function with disabled interrupts or from a
318 * hardware interrupt handler or from a bottom half handler.
320 int smp_call_function(void (*func)(void *info), void *info, int wait)
322 cpumask_t cpu_mask = CPU_MASK_ALL;
323 struct call_data_struct data;
326 cpu_clear(smp_processor_id(), cpu_mask);
328 WARN_ON(irqs_disabled());
334 spin_lock(&call_lock);
336 ret = send_ipi(IPI_CALL, wait, cpu_mask);
337 spin_unlock(&call_lock);
342 irqreturn_t crisv32_ipi_interrupt(int irq, void *dev_id)
344 void (*func) (void *info) = call_data->func;
345 void *info = call_data->info;
346 reg_intr_vect_rw_ipi ipi;
348 ipi = REG_RD(intr_vect, irq_regs[smp_processor_id()], rw_ipi);
350 if (ipi.vector & IPI_CALL) {
353 if (ipi.vector & IPI_FLUSH_TLB) {
354 if (flush_mm == FLUSH_ALL)
356 else if (flush_vma == FLUSH_ALL)
357 __flush_tlb_mm(flush_mm);
359 __flush_tlb_page(flush_vma, flush_addr);
363 REG_WR(intr_vect, irq_regs[smp_processor_id()], rw_ipi, ipi);