platsmp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2016 Neil Armstrong <narmstrong@baylibre.com>
  3. * Copyright (C) 2013 Ma Haijun <mahaijuns@gmail.com>
  4. * Copyright (C) 2002 ARM Ltd.
  5. * All Rights Reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/io.h>
  12. #include <linux/delay.h>
  13. #include <linux/of.h>
  14. #include <linux/of_address.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/cp15.h>
  17. #include <asm/smp_plat.h>
  18. #include <asm/smp_scu.h>
  19. extern void ox820_secondary_startup(void);
  20. extern void ox820_cpu_die(unsigned int cpu);
  21. static void __iomem *cpu_ctrl;
  22. static void __iomem *gic_cpu_ctrl;
  23. #define HOLDINGPEN_CPU_OFFSET 0xc8
  24. #define HOLDINGPEN_LOCATION_OFFSET 0xc4
  25. #define GIC_NCPU_OFFSET(cpu) (0x100 + (cpu)*0x100)
  26. #define GIC_CPU_CTRL 0x00
  27. #define GIC_CPU_CTRL_ENABLE 1
  28. int __init ox820_boot_secondary(unsigned int cpu, struct task_struct *idle)
  29. {
  30. /*
  31. * Write the address of secondary startup into the
  32. * system-wide flags register. The BootMonitor waits
  33. * until it receives a soft interrupt, and then the
  34. * secondary CPU branches to this address.
  35. */
  36. writel(virt_to_phys(ox820_secondary_startup),
  37. cpu_ctrl + HOLDINGPEN_LOCATION_OFFSET);
  38. writel(cpu, cpu_ctrl + HOLDINGPEN_CPU_OFFSET);
  39. /*
  40. * Enable GIC cpu interface in CPU Interface Control Register
  41. */
  42. writel(GIC_CPU_CTRL_ENABLE,
  43. gic_cpu_ctrl + GIC_NCPU_OFFSET(cpu) + GIC_CPU_CTRL);
  44. /*
  45. * Send the secondary CPU a soft interrupt, thereby causing
  46. * the boot monitor to read the system wide flags register,
  47. * and branch to the address found there.
  48. */
  49. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  50. return 0;
  51. }
  52. static void __init ox820_smp_prepare_cpus(unsigned int max_cpus)
  53. {
  54. struct device_node *np;
  55. void __iomem *scu_base;
  56. np = of_find_compatible_node(NULL, NULL, "arm,arm11mp-scu");
  57. scu_base = of_iomap(np, 0);
  58. of_node_put(np);
  59. if (!scu_base)
  60. return;
  61. /* Remap CPU Interrupt Interface Registers */
  62. np = of_find_compatible_node(NULL, NULL, "arm,arm11mp-gic");
  63. gic_cpu_ctrl = of_iomap(np, 1);
  64. of_node_put(np);
  65. if (!gic_cpu_ctrl)
  66. goto unmap_scu;
  67. np = of_find_compatible_node(NULL, NULL, "oxsemi,ox820-sys-ctrl");
  68. cpu_ctrl = of_iomap(np, 0);
  69. of_node_put(np);
  70. if (!cpu_ctrl)
  71. goto unmap_scu;
  72. scu_enable(scu_base);
  73. flush_cache_all();
  74. unmap_scu:
  75. iounmap(scu_base);
  76. }
  77. static const struct smp_operations ox820_smp_ops __initconst = {
  78. .smp_prepare_cpus = ox820_smp_prepare_cpus,
  79. .smp_boot_secondary = ox820_boot_secondary,
  80. #ifdef CONFIG_HOTPLUG_CPU
  81. .cpu_die = ox820_cpu_die,
  82. #endif
  83. };
  84. CPU_METHOD_OF_DECLARE(ox820_smp, "oxsemi,ox820-smp", &ox820_smp_ops);