platsmp.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 u32 boot_inst;
  21. static void __iomem *cpu_ctrl;
  22. static inline void berlin_perform_reset_cpu(unsigned int cpu)
  23. {
  24. u32 val;
  25. val = readl(cpu_ctrl + CPU_RESET);
  26. val |= BIT(cpu_logical_map(cpu));
  27. writel(val, cpu_ctrl + CPU_RESET);
  28. }
  29. static int berlin_boot_secondary(unsigned int cpu, struct task_struct *idle)
  30. {
  31. if (!cpu_ctrl)
  32. return -EFAULT;
  33. /*
  34. * Reset the CPU, making it to execute the instruction in the reset
  35. * exception vector.
  36. */
  37. berlin_perform_reset_cpu(cpu);
  38. return 0;
  39. }
  40. static void __init berlin_smp_prepare_cpus(unsigned int max_cpus)
  41. {
  42. struct device_node *np;
  43. void __iomem *scu_base;
  44. void __iomem *vectors_base;
  45. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  46. scu_base = of_iomap(np, 0);
  47. of_node_put(np);
  48. if (!scu_base)
  49. return;
  50. np = of_find_compatible_node(NULL, NULL, "marvell,berlin-cpu-ctrl");
  51. cpu_ctrl = of_iomap(np, 0);
  52. of_node_put(np);
  53. if (!cpu_ctrl)
  54. goto unmap_scu;
  55. vectors_base = ioremap(CONFIG_VECTORS_BASE, SZ_32K);
  56. if (!vectors_base)
  57. goto unmap_scu;
  58. scu_enable(scu_base);
  59. flush_cache_all();
  60. /*
  61. * Write the first instruction the CPU will execute after being reset
  62. * in the reset exception vector.
  63. */
  64. writel(boot_inst, vectors_base + RESET_VECT);
  65. /*
  66. * Write the secondary startup address into the SW reset address
  67. * vector. This is used by boot_inst.
  68. */
  69. writel(virt_to_phys(secondary_startup), vectors_base + SW_RESET_ADDR);
  70. iounmap(vectors_base);
  71. unmap_scu:
  72. iounmap(scu_base);
  73. }
  74. static struct smp_operations berlin_smp_ops __initdata = {
  75. .smp_prepare_cpus = berlin_smp_prepare_cpus,
  76. .smp_boot_secondary = berlin_boot_secondary,
  77. };
  78. CPU_METHOD_OF_DECLARE(berlin_smp, "marvell,berlin-smp", &berlin_smp_ops);