1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2001, 2002, 2003 Broadcom Corporation
6 #include <linux/init.h>
7 #include <linux/delay.h>
8 #include <linux/interrupt.h>
10 #include <linux/kernel_stat.h>
11 #include <linux/sched/task_stack.h>
13 #include <asm/mmu_context.h>
15 #include <asm/fw/cfe/cfe_api.h>
16 #include <asm/sibyte/sb1250.h>
17 #include <asm/sibyte/sb1250_regs.h>
18 #include <asm/sibyte/sb1250_int.h>
20 static void *mailbox_set_regs
[] = {
21 IOADDR(A_IMR_CPU0_BASE
+ R_IMR_MAILBOX_SET_CPU
),
22 IOADDR(A_IMR_CPU1_BASE
+ R_IMR_MAILBOX_SET_CPU
)
25 static void *mailbox_clear_regs
[] = {
26 IOADDR(A_IMR_CPU0_BASE
+ R_IMR_MAILBOX_CLR_CPU
),
27 IOADDR(A_IMR_CPU1_BASE
+ R_IMR_MAILBOX_CLR_CPU
)
30 static void *mailbox_regs
[] = {
31 IOADDR(A_IMR_CPU0_BASE
+ R_IMR_MAILBOX_CPU
),
32 IOADDR(A_IMR_CPU1_BASE
+ R_IMR_MAILBOX_CPU
)
36 * SMP init and finish on secondary CPUs
38 void sb1250_smp_init(void)
40 unsigned int imask
= STATUSF_IP4
| STATUSF_IP3
| STATUSF_IP2
|
41 STATUSF_IP1
| STATUSF_IP0
;
43 /* Set interrupt mask, but don't enable */
44 change_c0_status(ST0_IM
, imask
);
48 * These are routines for dealing with the sb1250 smp capabilities
49 * independent of board/firmware
53 * Simple enough; everything is set up, so just poke the appropriate mailbox
54 * register, and we should be set
56 static void sb1250_send_ipi_single(int cpu
, unsigned int action
)
58 __raw_writeq((((u64
)action
) << 48), mailbox_set_regs
[cpu
]);
61 static inline void sb1250_send_ipi_mask(const struct cpumask
*mask
,
67 sb1250_send_ipi_single(i
, action
);
71 * Code to run on secondary just after probing the CPU
73 static void sb1250_init_secondary(void)
75 extern void sb1250_smp_init(void);
81 * Do any tidying up before marking online and running the idle
84 static void sb1250_smp_finish(void)
86 extern void sb1250_clockevent_init(void);
88 sb1250_clockevent_init();
93 * Setup the PC, SP, and GP of a secondary processor and start it
96 static int sb1250_boot_secondary(int cpu
, struct task_struct
*idle
)
100 retval
= cfe_cpu_start(cpu_logical_map(cpu
), &smp_bootstrap
,
102 (unsigned long)task_thread_info(idle
), 0);
104 printk("cfe_start_cpu(%i) returned %i\n" , cpu
, retval
);
109 * Use CFE to find out how many CPUs are available, setting up
110 * cpu_possible_mask and the logical/physical mappings.
111 * XXXKW will the boot CPU ever not be physical 0?
113 * Common setup before any secondaries are started
115 static void __init
sb1250_smp_setup(void)
119 init_cpu_possible(cpumask_of(0));
120 __cpu_number_map
[0] = 0;
121 __cpu_logical_map
[0] = 0;
123 for (i
= 1, num
= 0; i
< NR_CPUS
; i
++) {
124 if (cfe_cpu_stop(i
) == 0) {
125 set_cpu_possible(i
, true);
126 __cpu_number_map
[i
] = ++num
;
127 __cpu_logical_map
[num
] = i
;
130 printk(KERN_INFO
"Detected %i available secondary CPU(s)\n", num
);
133 static void __init
sb1250_prepare_cpus(unsigned int max_cpus
)
137 const struct plat_smp_ops sb_smp_ops
= {
138 .send_ipi_single
= sb1250_send_ipi_single
,
139 .send_ipi_mask
= sb1250_send_ipi_mask
,
140 .init_secondary
= sb1250_init_secondary
,
141 .smp_finish
= sb1250_smp_finish
,
142 .boot_secondary
= sb1250_boot_secondary
,
143 .smp_setup
= sb1250_smp_setup
,
144 .prepare_cpus
= sb1250_prepare_cpus
,
147 void sb1250_mailbox_interrupt(void)
149 int cpu
= smp_processor_id();
150 int irq
= K_INT_MBOX_0
;
153 kstat_incr_irq_this_cpu(irq
);
154 /* Load the mailbox register to figure out what we're supposed to do */
155 action
= (____raw_readq(mailbox_regs
[cpu
]) >> 48) & 0xffff;
157 /* Clear the mailbox to clear the interrupt */
158 ____raw_writeq(((u64
)action
) << 48, mailbox_clear_regs
[cpu
]);
160 if (action
& SMP_RESCHEDULE_YOURSELF
)
163 if (action
& SMP_CALL_FUNCTION
) {
165 generic_smp_call_function_interrupt();