platsmp-scu.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/cpu.h>
  11. #include <linux/delay.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/smp.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/smp_plat.h>
  17. #include <asm/smp_scu.h>
  18. #include "common.h"
  19. static phys_addr_t shmobile_scu_base_phys;
  20. static void __iomem *shmobile_scu_base;
  21. static int shmobile_scu_cpu_prepare(unsigned int cpu)
  22. {
  23. /* For this particular CPU register SCU SMP boot vector */
  24. shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu),
  25. shmobile_scu_base_phys);
  26. return 0;
  27. }
  28. void __init shmobile_smp_scu_prepare_cpus(phys_addr_t scu_base_phys,
  29. unsigned int max_cpus)
  30. {
  31. /* install boot code shared by all CPUs */
  32. shmobile_boot_fn = virt_to_phys(shmobile_smp_boot);
  33. /* enable SCU and cache coherency on booting CPU */
  34. shmobile_scu_base_phys = scu_base_phys;
  35. shmobile_scu_base = ioremap(scu_base_phys, PAGE_SIZE);
  36. scu_enable(shmobile_scu_base);
  37. scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
  38. /* Use CPU notifier for reset vector control */
  39. cpuhp_setup_state_nocalls(CPUHP_ARM_SHMOBILE_SCU_PREPARE,
  40. "arm/shmobile-scu:prepare",
  41. shmobile_scu_cpu_prepare, NULL);
  42. }
  43. #ifdef CONFIG_HOTPLUG_CPU
  44. void shmobile_smp_scu_cpu_die(unsigned int cpu)
  45. {
  46. /* For this particular CPU deregister boot vector */
  47. shmobile_smp_hook(cpu, 0, 0);
  48. dsb();
  49. flush_cache_all();
  50. /* disable cache coherency */
  51. scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
  52. /* jump to shared mach-shmobile sleep / reset code */
  53. shmobile_smp_sleep();
  54. }
  55. static int shmobile_smp_scu_psr_core_disabled(int cpu)
  56. {
  57. unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
  58. if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
  59. return 1;
  60. return 0;
  61. }
  62. int shmobile_smp_scu_cpu_kill(unsigned int cpu)
  63. {
  64. int k;
  65. /* this function is running on another CPU than the offline target,
  66. * here we need wait for shutdown code in platform_cpu_die() to
  67. * finish before asking SoC-specific code to power off the CPU core.
  68. */
  69. for (k = 0; k < 1000; k++) {
  70. if (shmobile_smp_scu_psr_core_disabled(cpu))
  71. return 1;
  72. mdelay(1);
  73. }
  74. return 0;
  75. }
  76. #endif