1 // SPDX-License-Identifier: GPL-2.0-only
3 * SMP support for Hexagon
5 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/interrupt.h>
13 #include <linux/module.h>
14 #include <linux/percpu.h>
15 #include <linux/sched/mm.h>
16 #include <linux/smp.h>
17 #include <linux/spinlock.h>
18 #include <linux/cpu.h>
19 #include <linux/mm_types.h>
21 #include <asm/time.h> /* timer_interrupt */
22 #include <asm/hexagon_vm.h>
24 #define BASE_IPI_IRQ 26
27 * cpu_possible_mask needs to be filled out prior to setup_per_cpu_areas
28 * (which is prior to any of our smp_prepare_cpu crap), in order to set
29 * up the... per_cpu areas.
36 static DEFINE_PER_CPU(struct ipi_data
, ipi_data
);
38 static inline void __handle_ipi(unsigned long *ops
, struct ipi_data
*ipi
,
41 unsigned long msg
= 0;
43 msg
= find_next_bit(ops
, BITS_PER_LONG
, msg
+1);
52 generic_smp_call_function_interrupt();
66 } while (msg
< BITS_PER_LONG
);
69 /* Used for IPI call from other CPU's to unmask int */
70 void smp_vm_unmask_irq(void *info
)
72 __vmintop_locen((long) info
);
77 * This is based on Alpha's IPI stuff.
78 * Supposed to take (int, void*) as args now.
79 * Specifically, first arg is irq, second is the irq_desc.
82 irqreturn_t
handle_ipi(int irq
, void *desc
)
84 int cpu
= smp_processor_id();
85 struct ipi_data
*ipi
= &per_cpu(ipi_data
, cpu
);
88 while ((ops
= xchg(&ipi
->bits
, 0)) != 0)
89 __handle_ipi(&ops
, ipi
, cpu
);
93 void send_ipi(const struct cpumask
*cpumask
, enum ipi_message_type msg
)
99 local_irq_save(flags
);
101 for_each_cpu(cpu
, cpumask
) {
102 struct ipi_data
*ipi
= &per_cpu(ipi_data
, cpu
);
104 set_bit(msg
, &ipi
->bits
);
105 /* Possible barrier here */
106 retval
= __vmintop_post(BASE_IPI_IRQ
+cpu
);
109 printk(KERN_ERR
"interrupt %ld not configured?\n",
114 local_irq_restore(flags
);
117 void __init
smp_prepare_boot_cpu(void)
122 * interrupts should already be disabled from the VM
123 * SP should already be correct; need to set THREADINFO_REG
124 * to point to current thread info
127 void start_secondary(void)
129 unsigned long thread_ptr
;
130 unsigned int cpu
, irq
;
132 /* Calculate thread_info pointer from stack pointer */
133 __asm__
__volatile__(
138 thread_ptr
= thread_ptr
& ~(THREAD_SIZE
-1);
140 __asm__
__volatile__(
141 QUOTED_THREADINFO_REG
" = %0;\n"
146 /* Set the memory struct */
148 current
->active_mm
= &init_mm
;
150 cpu
= smp_processor_id();
152 irq
= BASE_IPI_IRQ
+ cpu
;
153 if (request_irq(irq
, handle_ipi
, IRQF_TRIGGER_RISING
, "ipi_handler",
155 pr_err("Failed to request irq %u (ipi_handler)\n", irq
);
157 /* Register the clock_event dummy */
158 setup_percpu_clockdev();
160 printk(KERN_INFO
"%s cpu %d\n", __func__
, current_thread_info()->cpu
);
162 notify_cpu_starting(cpu
);
164 set_cpu_online(cpu
, true);
168 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE
);
173 * called once for each present cpu
174 * apparently starts up the CPU and then
175 * maintains control until "cpu_online(cpu)" is set.
178 int __cpu_up(unsigned int cpu
, struct task_struct
*idle
)
180 struct thread_info
*thread
= (struct thread_info
*)idle
->stack
;
185 /* Boot to the head. */
186 stack_start
= ((void *) thread
) + THREAD_SIZE
;
187 __vmstart(start_secondary
, stack_start
);
189 while (!cpu_online(cpu
))
195 void __init
smp_cpus_done(unsigned int max_cpus
)
199 void __init
smp_prepare_cpus(unsigned int max_cpus
)
201 int i
, irq
= BASE_IPI_IRQ
;
204 * should eventually have some sort of machine
205 * descriptor that has this stuff
208 /* Right now, let's just fake it. */
209 for (i
= 0; i
< max_cpus
; i
++)
210 set_cpu_present(i
, true);
212 /* Also need to register the interrupts for IPI */
214 if (request_irq(irq
, handle_ipi
, IRQF_TRIGGER_RISING
,
215 "ipi_handler", NULL
))
216 pr_err("Failed to request irq %d (ipi_handler)\n", irq
);
220 void smp_send_reschedule(int cpu
)
222 send_ipi(cpumask_of(cpu
), IPI_RESCHEDULE
);
225 void smp_send_stop(void)
227 struct cpumask targets
;
228 cpumask_copy(&targets
, cpu_online_mask
);
229 cpumask_clear_cpu(smp_processor_id(), &targets
);
230 send_ipi(&targets
, IPI_CPU_STOP
);
233 void arch_send_call_function_single_ipi(int cpu
)
235 send_ipi(cpumask_of(cpu
), IPI_CALL_FUNC
);
238 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
240 send_ipi(mask
, IPI_CALL_FUNC
);
243 int setup_profiling_timer(unsigned int multiplier
)
248 void smp_start_cpus(void)
252 for (i
= 0; i
< NR_CPUS
; i
++)
253 set_cpu_possible(i
, true);