malta-amon.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2007 MIPS Technologies, Inc.
  3. * All rights reserved.
  4. * This program is free software; you can distribute it and/or modify it
  5. * under the terms of the GNU General Public License (Version 2) as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. * for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  16. *
  17. * Arbitrary Monitor interface
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/smp.h>
  22. #include <asm/addrspace.h>
  23. #include <asm/mips-boards/launch.h>
  24. #include <asm/mipsmtregs.h>
  25. int amon_cpu_avail(int cpu)
  26. {
  27. struct cpulaunch *launch = (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH);
  28. if (cpu < 0 || cpu >= NCPULAUNCH) {
  29. pr_debug("avail: cpu%d is out of range\n", cpu);
  30. return 0;
  31. }
  32. launch += cpu;
  33. if (!(launch->flags & LAUNCH_FREADY)) {
  34. pr_debug("avail: cpu%d is not ready\n", cpu);
  35. return 0;
  36. }
  37. if (launch->flags & (LAUNCH_FGO|LAUNCH_FGONE)) {
  38. pr_debug("avail: too late.. cpu%d is already gone\n", cpu);
  39. return 0;
  40. }
  41. return 1;
  42. }
  43. void amon_cpu_start(int cpu,
  44. unsigned long pc, unsigned long sp,
  45. unsigned long gp, unsigned long a0)
  46. {
  47. volatile struct cpulaunch *launch =
  48. (struct cpulaunch *)CKSEG0ADDR(CPULAUNCH);
  49. if (!amon_cpu_avail(cpu))
  50. return;
  51. if (cpu == smp_processor_id()) {
  52. pr_debug("launch: I am cpu%d!\n", cpu);
  53. return;
  54. }
  55. launch += cpu;
  56. pr_debug("launch: starting cpu%d\n", cpu);
  57. launch->pc = pc;
  58. launch->gp = gp;
  59. launch->sp = sp;
  60. launch->a0 = a0;
  61. smp_wmb(); /* Target must see parameters before go */
  62. launch->flags |= LAUNCH_FGO;
  63. smp_wmb(); /* Target must see go before we poll */
  64. while ((launch->flags & LAUNCH_FGONE) == 0)
  65. ;
  66. smp_rmb(); /* Target will be updating flags soon */
  67. pr_debug("launch: cpu%d gone!\n", cpu);
  68. }