2 * Copyright (C) 2007, 2011 MIPS Technologies, Inc.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * Arbitrary Monitor interface
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/smp.h>
25 #include <asm/addrspace.h>
26 #include <asm/mips-boards/launch.h>
27 #include <asm/mipsmtregs.h>
29 int amon_cpu_avail(int cpu
)
31 struct cpulaunch
*launch
= (struct cpulaunch
*)CKSEG0ADDR(CPULAUNCH
);
33 if (cpu
< 0 || cpu
>= NCPULAUNCH
) {
34 pr_debug("avail: cpu%d is out of range\n", cpu
);
39 if (!(launch
->flags
& LAUNCH_FREADY
)) {
40 pr_debug("avail: cpu%d is not ready\n", cpu
);
43 if (launch
->flags
& (LAUNCH_FGO
|LAUNCH_FGONE
)) {
44 pr_debug("avail: too late.. cpu%d is already gone\n", cpu
);
51 void amon_cpu_start(int cpu
,
52 unsigned long pc
, unsigned long sp
,
53 unsigned long gp
, unsigned long a0
)
55 volatile struct cpulaunch
*launch
=
56 (struct cpulaunch
*)CKSEG0ADDR(CPULAUNCH
);
58 if (!amon_cpu_avail(cpu
))
60 if (cpu
== smp_processor_id()) {
61 pr_debug("launch: I am cpu%d!\n", cpu
);
66 pr_debug("launch: starting cpu%d\n", cpu
);
73 smp_wmb(); /* Target must see parameters before go */
74 launch
->flags
|= LAUNCH_FGO
;
75 smp_wmb(); /* Target must see go before we poll */
76 while ((launch
->flags
& LAUNCH_FGONE
) == 0)
78 smp_rmb(); /* Target will be updating flags soon */
79 pr_debug("launch: cpu%d gone!\n", cpu
);
83 * Restart the CPU ready for amon_cpu_start again
84 * A bit of a hack... it duplicates the CPU startup code that
85 * lives somewhere in the boot monitor.
87 void amon_cpu_dead(void)
89 struct cpulaunch
*launch
;
93 launch
= (struct cpulaunch
*)CKSEG0ADDR(CPULAUNCH
);
94 launch
+= smp_processor_id();
100 launch
->flags
= LAUNCH_FREADY
;
104 __asm__
__volatile__ (
106 " .set noreorder\n\t"
108 " lw %[r0],%[LAUNCH_FLAGS](%[launch])\n\t"
109 " andi %[r0],%[FGO]\n\t"
112 " mfc0 %[r0],$9\n\t" /* Read Count */
113 " addu %[r0],%[waitperiod]\n\t"
114 " mtc0 %[r0],$11\n\t" /* Write Compare */
118 "1: lw $ra,%[LAUNCH_PC](%[launch])\n\t"
119 " lw $gp,%[LAUNCH_GP](%[launch])\n\t"
120 " lw $sp,%[LAUNCH_SP](%[launch])\n\t"
121 " lw $a0,%[LAUNCH_A0](%[launch])\n\t"
122 " move $a1,$zero\n\t"
123 " move $a2,$zero\n\t"
124 " move $a3,$zero\n\t"
125 " lw %[r0],%[LAUNCH_FLAGS](%[launch])\n\t"
126 " ori %[r0],%[FGONE]\n\t"
128 " sw %[r0],%[LAUNCH_FLAGS](%[launch])\n\t"
131 : [launch
] "r" (launch
),
132 [FGONE
] "i" (LAUNCH_FGONE
),
133 [FGO
] "i" (LAUNCH_FGO
),
134 [LAUNCH_PC
] "i" (offsetof(struct cpulaunch
, pc
)),
135 [LAUNCH_GP
] "i" (offsetof(struct cpulaunch
, gp
)),
136 [LAUNCH_SP
] "i" (offsetof(struct cpulaunch
, sp
)),
137 [LAUNCH_A0
] "i" (offsetof(struct cpulaunch
, a0
)),
138 [LAUNCH_FLAGS
] "i" (offsetof(struct cpulaunch
, flags
)),
139 [waitperiod
] "i" ((cpufreq
/ 2) / 100) /* delay of ~10ms */
140 : "ra","a0","a1","a2","a3","sp" /* ,"gp" */