blob: 65fa3a23ea5e9fb2f022c80dd29c423970d5122e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/linkage.h>
2#include <linux/sched.h>
3
4#include <asm/pmon.h>
5#include <asm/titan_dep.h>
6
7extern unsigned int (*mips_hpt_read)(void);
8extern void (*mips_hpt_init)(unsigned int);
9
10#define LAUNCHSTACK_SIZE 256
11
Ralf Baechle2f69ddc2005-10-03 13:41:19 +010012static __initdata DEFINE_SPINLOCK(launch_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14static unsigned long secondary_sp __initdata;
15static unsigned long secondary_gp __initdata;
16
17static unsigned char launchstack[LAUNCHSTACK_SIZE] __initdata
18 __attribute__((aligned(2 * sizeof(long))));
19
20static void __init prom_smp_bootstrap(void)
21{
22 local_irq_disable();
23
24 while (spin_is_locked(&launch_lock));
25
26 __asm__ __volatile__(
27 " move $sp, %0 \n"
28 " move $gp, %1 \n"
29 " j smp_bootstrap \n"
30 :
31 : "r" (secondary_sp), "r" (secondary_gp));
32}
33
34/*
35 * PMON is a fragile beast. It'll blow up once the mappings it's littering
36 * right into the middle of KSEG3 are blown away so we have to grab the slave
37 * core early and keep it in a waiting loop.
38 */
39void __init prom_grab_secondary(void)
40{
41 spin_lock(&launch_lock);
42
43 pmon_cpustart(1, &prom_smp_bootstrap,
44 launchstack + LAUNCHSTACK_SIZE, 0);
45}
46
47/*
48 * Detect available CPUs, populate phys_cpu_present_map before smp_init
49 *
50 * We don't want to start the secondary CPU yet nor do we have a nice probing
51 * feature in PMON so we just assume presence of the secondary core.
52 */
Ralf Baechle9b6695a2006-02-23 12:23:27 +000053void __init plat_smp_setup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Ralf Baechle9b6695a2006-02-23 12:23:27 +000055 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 cpus_clear(phys_cpu_present_map);
58
59 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 cpu_set(i, phys_cpu_present_map);
61 __cpu_number_map[i] = i;
62 __cpu_logical_map[i] = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
Ralf Baechle9b6695a2006-02-23 12:23:27 +000064}
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Ralf Baechle9b6695a2006-02-23 12:23:27 +000066void __init plat_prepare_cpus(unsigned int max_cpus)
67{
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 /*
69 * Be paranoid. Enable the IPI only if we're really about to go SMP.
70 */
Ralf Baechle9b6695a2006-02-23 12:23:27 +000071 if (cpus_weight(cpu_possible_map))
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 set_c0_status(STATUSF_IP5);
73}
74
75/*
76 * Firmware CPU startup hook
77 * Complicated by PMON's weird interface which tries to minimic the UNIX fork.
78 * It launches the next * available CPU and copies some information on the
79 * stack so the first thing we do is throw away that stuff and load useful
80 * values into the registers ...
81 */
82void prom_boot_secondary(int cpu, struct task_struct *idle)
83{
Al Virodc8f6022006-01-12 01:06:07 -080084 unsigned long gp = (unsigned long) task_thread_info(idle);
Ralf Baechle1e93e702006-02-21 00:17:50 +000085 unsigned long sp = __KSTK_TOS(idle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 secondary_sp = sp;
88 secondary_gp = gp;
89
90 spin_unlock(&launch_lock);
91}
92
93/* Hook for after all CPUs are online */
94void prom_cpus_done(void)
95{
96}
97
98/*
99 * After we've done initial boot, this function is called to allow the
100 * board code to clean up state, if needed
101 */
102void prom_init_secondary(void)
103{
104 mips_hpt_init(mips_hpt_read());
105
106 set_c0_status(ST0_CO | ST0_IE | ST0_IM);
107}
108
109void prom_smp_finish(void)
110{
111}
112
Ralf Baechle937a8012006-10-07 19:44:33 +0100113asmlinkage void titan_mailbox_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 int cpu = smp_processor_id();
116 unsigned long status;
117
118 if (cpu == 0) {
119 status = OCD_READ(RM9000x2_OCD_INTP0STATUS3);
120 OCD_WRITE(RM9000x2_OCD_INTP0CLEAR3, status);
121 }
122
123 if (cpu == 1) {
124 status = OCD_READ(RM9000x2_OCD_INTP1STATUS3);
125 OCD_WRITE(RM9000x2_OCD_INTP1CLEAR3, status);
126 }
127
128 if (status & 0x2)
129 smp_call_function_interrupt();
130}
131
132/*
133 * Send inter-processor interrupt
134 */
135void core_send_ipi(int cpu, unsigned int action)
136{
137 /*
138 * Generate an INTMSG so that it can be sent over to the
139 * destination CPU. The INTMSG will put the STATUS bits
140 * based on the action desired. An alternative strategy
141 * is to write to the Interrupt Set register, read the
142 * Interrupt Status register and clear the Interrupt
143 * Clear register. The latter is preffered.
144 */
145 switch (action) {
146 case SMP_RESCHEDULE_YOURSELF:
147 if (cpu == 1)
148 OCD_WRITE(RM9000x2_OCD_INTP1SET3, 4);
149 else
150 OCD_WRITE(RM9000x2_OCD_INTP0SET3, 4);
151 break;
152
153 case SMP_CALL_FUNCTION:
154 if (cpu == 1)
155 OCD_WRITE(RM9000x2_OCD_INTP1SET3, 2);
156 else
157 OCD_WRITE(RM9000x2_OCD_INTP0SET3, 2);
158 break;
159 }
160}