platsmp.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2014 Marvell Technology Group Ltd.
  3. *
  4. * Antoine Ténart <antoine.tenart@free-electrons.com>
  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/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/smp_plat.h>
  16. #include <asm/smp_scu.h>
  17. #define CPU_RESET 0x00
  18. #define RESET_VECT 0x00
  19. #define SW_RESET_ADDR 0x94
  20. extern void berlin_secondary_startup(void);
  21. extern u32 boot_inst;
  22. static void __iomem *cpu_ctrl;
  23. static inline void berlin_perform_reset_cpu(unsigned int cpu)
  24. {
  25. u32 val;
  26. val = readl(cpu_ctrl + CPU_RESET);
  27. val |= BIT(cpu_logical_map(cpu));
  28. writel(val, cpu_ctrl + CPU_RESET);
  29. }
  30. static int berlin_boot_secondary(unsigned int cpu, struct task_struct *idle)
  31. {
  32. if (!cpu_ctrl)
  33. return -EFAULT;
  34. /*
  35. * Reset the CPU, making it to execute the instruction in the reset
  36. * exception vector.
  37. */
  38. berlin_perform_reset_cpu(cpu);
  39. return 0;
  40. }
  41. static void __init berlin_smp_prepare_cpus(unsigned int max_cpus)
  42. {
  43. struct device_node *np;
  44. void __iomem *scu_base;
  45. void __iomem *vectors_base;
  46. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  47. scu_base = of_iomap(np, 0);
  48. of_node_put(np);
  49. if (!scu_base)
  50. return;
  51. np = of_find_compatible_node(NULL, NULL, "marvell,berlin-cpu-ctrl");
  52. cpu_ctrl = of_iomap(np, 0);
  53. of_node_put(np);
  54. if (!cpu_ctrl)
  55. goto unmap_scu;
  56. vectors_base = ioremap(CONFIG_VECTORS_BASE, SZ_32K);
  57. if (!vectors_base)
  58. goto unmap_scu;
  59. scu_enable(scu_base);
  60. flush_cache_all();
  61. /*
  62. * Write the first instruction the CPU will execute after being reset
  63. * in the reset exception vector.
  64. */
  65. writel(boot_inst, vectors_base + RESET_VECT);
  66. /*
  67. * Write the secondary startup address into the SW reset address
  68. * vector. This is used by boot_inst.
  69. */
  70. writel(virt_to_phys(berlin_secondary_startup), vectors_base + SW_RESET_ADDR);
  71. iounmap(vectors_base);
  72. unmap_scu:
  73. iounmap(scu_base);
  74. }
  75. static struct smp_operations berlin_smp_ops __initdata = {
  76. .smp_prepare_cpus = berlin_smp_prepare_cpus,
  77. .smp_boot_secondary = berlin_boot_secondary,
  78. };
  79. CPU_METHOD_OF_DECLARE(berlin_smp, "marvell,berlin-smp", &berlin_smp_ops);