Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 1 | /* |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 5 | * |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 6 | * Copyright (C) 2007 MIPS Technologies, Inc. All rights reserved. |
| 7 | * Copyright (C) 2013 Imagination Technologies Ltd. |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 8 | * |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 9 | * Arbitrary Monitor Interface |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 10 | */ |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 11 | #include <linux/kernel.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 12 | #include <linux/smp.h> |
| 13 | |
David Daney | 9e86786 | 2008-09-20 10:16:36 -0700 | [diff] [blame] | 14 | #include <asm/addrspace.h> |
David Daney | 9e86786 | 2008-09-20 10:16:36 -0700 | [diff] [blame] | 15 | #include <asm/mipsmtregs.h> |
Steven J. Hill | 5792bf6 | 2014-01-01 16:35:32 +0100 | [diff] [blame] | 16 | #include <asm/mips-boards/launch.h> |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 17 | #include <asm/vpe.h> |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 18 | |
| 19 | int amon_cpu_avail(int cpu) |
| 20 | { |
Thomas Bogendoerfer | 938b2b1 | 2008-05-29 22:05:07 +0200 | [diff] [blame] | 21 | struct cpulaunch *launch = (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 22 | |
| 23 | if (cpu < 0 || cpu >= NCPULAUNCH) { |
| 24 | pr_debug("avail: cpu%d is out of range\n", cpu); |
| 25 | return 0; |
| 26 | } |
| 27 | |
| 28 | launch += cpu; |
| 29 | if (!(launch->flags & LAUNCH_FREADY)) { |
| 30 | pr_debug("avail: cpu%d is not ready\n", cpu); |
| 31 | return 0; |
| 32 | } |
| 33 | if (launch->flags & (LAUNCH_FGO|LAUNCH_FGONE)) { |
| 34 | pr_debug("avail: too late.. cpu%d is already gone\n", cpu); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | return 1; |
| 39 | } |
| 40 | |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 41 | int amon_cpu_start(int cpu, |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 42 | unsigned long pc, unsigned long sp, |
| 43 | unsigned long gp, unsigned long a0) |
| 44 | { |
| 45 | volatile struct cpulaunch *launch = |
Thomas Bogendoerfer | 938b2b1 | 2008-05-29 22:05:07 +0200 | [diff] [blame] | 46 | (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH); |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 47 | |
| 48 | if (!amon_cpu_avail(cpu)) |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 49 | return -1; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 50 | if (cpu == smp_processor_id()) { |
| 51 | pr_debug("launch: I am cpu%d!\n", cpu); |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 52 | return -1; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 53 | } |
| 54 | launch += cpu; |
| 55 | |
| 56 | pr_debug("launch: starting cpu%d\n", cpu); |
| 57 | |
| 58 | launch->pc = pc; |
| 59 | launch->gp = gp; |
| 60 | launch->sp = sp; |
| 61 | launch->a0 = a0; |
| 62 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 63 | smp_wmb(); /* Target must see parameters before go */ |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 64 | launch->flags |= LAUNCH_FGO; |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 65 | smp_wmb(); /* Target must see go before we poll */ |
Chris Dearman | 2ee0a42 | 2009-07-10 02:06:38 -0700 | [diff] [blame] | 66 | |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 67 | while ((launch->flags & LAUNCH_FGONE) == 0) |
| 68 | ; |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 69 | smp_rmb(); /* Target will be updating flags soon */ |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 70 | pr_debug("launch: cpu%d gone!\n", cpu); |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 71 | |
| 72 | return 0; |
Ralf Baechle | 39b8d52 | 2008-04-28 17:14:26 +0100 | [diff] [blame] | 73 | } |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 74 | |
Deng-Cheng Zhu | 031365b | 2014-02-28 10:23:03 -0800 | [diff] [blame] | 75 | #ifdef CONFIG_MIPS_VPE_LOADER_CMP |
Deng-Cheng Zhu | 1336113 | 2013-10-30 15:52:10 -0500 | [diff] [blame] | 76 | int vpe_run(struct vpe *v) |
| 77 | { |
| 78 | struct vpe_notifications *n; |
| 79 | |
| 80 | if (amon_cpu_start(aprp_cpu_index(), v->__start, 0, 0, 0) < 0) |
| 81 | return -1; |
| 82 | |
| 83 | list_for_each_entry(n, &v->notify, list) |
| 84 | n->start(VPE_MODULE_MINOR); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | #endif |