platsmp-scu.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SMP support for SoCs with SCU covered by mach-shmobile
  3. *
  4. * Copyright (C) 2013 Magnus Damm
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/smp.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/smp_plat.h>
  16. #include <asm/smp_scu.h>
  17. #include <mach/common.h>
  18. void __init shmobile_smp_scu_prepare_cpus(unsigned int max_cpus)
  19. {
  20. shmobile_boot_fn = virt_to_phys(shmobile_boot_scu);
  21. shmobile_boot_arg = (unsigned long)shmobile_scu_base;
  22. /* enable SCU and cache coherency on booting CPU */
  23. scu_enable(shmobile_scu_base);
  24. scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
  25. }
  26. int shmobile_smp_scu_boot_secondary(unsigned int cpu, struct task_struct *idle)
  27. {
  28. /* do nothing for now */
  29. return 0;
  30. }
  31. #ifdef CONFIG_HOTPLUG_CPU
  32. void shmobile_smp_scu_cpu_die(unsigned int cpu)
  33. {
  34. dsb();
  35. flush_cache_all();
  36. /* disable cache coherency */
  37. scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
  38. /* Endless loop until reset */
  39. while (1)
  40. cpu_do_idle();
  41. }
  42. static int shmobile_smp_scu_psr_core_disabled(int cpu)
  43. {
  44. unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
  45. if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
  46. return 1;
  47. return 0;
  48. }
  49. int shmobile_smp_scu_cpu_kill(unsigned int cpu)
  50. {
  51. int k;
  52. /* this function is running on another CPU than the offline target,
  53. * here we need wait for shutdown code in platform_cpu_die() to
  54. * finish before asking SoC-specific code to power off the CPU core.
  55. */
  56. for (k = 0; k < 1000; k++) {
  57. if (shmobile_smp_scu_psr_core_disabled(cpu))
  58. return 1;
  59. mdelay(1);
  60. }
  61. return 0;
  62. }
  63. #endif