smp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright(c) 2015 EZchip Technologies.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. */
  16. #include <linux/smp.h>
  17. #include <linux/of_fdt.h>
  18. #include <linux/io.h>
  19. #include <linux/irqdomain.h>
  20. #include <asm/irq.h>
  21. #include <plat/ctop.h>
  22. #include <plat/smp.h>
  23. #include <plat/mtm.h>
  24. #define NPS_DEFAULT_MSID 0x34
  25. #define NPS_MTM_CPU_CFG 0x90
  26. static char smp_cpuinfo_buf[128] = {"Extn [EZNPS-SMP]\t: On\n"};
  27. /* Get cpu map from device tree */
  28. static int __init eznps_get_map(const char *name, struct cpumask *cpumask)
  29. {
  30. unsigned long dt_root = of_get_flat_dt_root();
  31. const char *buf;
  32. buf = of_get_flat_dt_prop(dt_root, name, NULL);
  33. if (!buf)
  34. return 1;
  35. cpulist_parse(buf, cpumask);
  36. return 0;
  37. }
  38. /* Update board cpu maps */
  39. static void __init eznps_init_cpumasks(void)
  40. {
  41. struct cpumask cpumask;
  42. if (eznps_get_map("present-cpus", &cpumask)) {
  43. pr_err("Failed to get present-cpus from dtb");
  44. return;
  45. }
  46. init_cpu_present(&cpumask);
  47. if (eznps_get_map("possible-cpus", &cpumask)) {
  48. pr_err("Failed to get possible-cpus from dtb");
  49. return;
  50. }
  51. init_cpu_possible(&cpumask);
  52. }
  53. static void eznps_init_core(unsigned int cpu)
  54. {
  55. u32 sync_value;
  56. struct nps_host_reg_aux_hw_comply hw_comply;
  57. struct nps_host_reg_aux_lpc lpc;
  58. if (NPS_CPU_TO_THREAD_NUM(cpu) != 0)
  59. return;
  60. hw_comply.value = read_aux_reg(CTOP_AUX_HW_COMPLY);
  61. hw_comply.me = 1;
  62. hw_comply.le = 1;
  63. hw_comply.te = 1;
  64. write_aux_reg(CTOP_AUX_HW_COMPLY, hw_comply.value);
  65. /* Enable MMU clock */
  66. lpc.mep = 1;
  67. write_aux_reg(CTOP_AUX_LPC, lpc.value);
  68. /* Boot CPU only */
  69. if (!cpu) {
  70. /* Write to general purpose register in CRG */
  71. sync_value = ioread32be(REG_GEN_PURP_0);
  72. sync_value |= NPS_CRG_SYNC_BIT;
  73. iowrite32be(sync_value, REG_GEN_PURP_0);
  74. }
  75. }
  76. /*
  77. * Master kick starting another CPU
  78. */
  79. static void __init eznps_smp_wakeup_cpu(int cpu, unsigned long pc)
  80. {
  81. struct nps_host_reg_mtm_cpu_cfg cpu_cfg;
  82. if (mtm_enable_thread(cpu) == 0)
  83. return;
  84. /* set PC, dmsid, and start CPU */
  85. cpu_cfg.value = (u32)res_service;
  86. cpu_cfg.dmsid = NPS_DEFAULT_MSID;
  87. cpu_cfg.cs = 1;
  88. iowrite32be(cpu_cfg.value, nps_mtm_reg_addr(cpu, NPS_MTM_CPU_CFG));
  89. }
  90. static void eznps_ipi_send(int cpu)
  91. {
  92. struct global_id gid;
  93. struct {
  94. union {
  95. struct {
  96. u32 num:8, cluster:8, core:8, thread:8;
  97. };
  98. u32 value;
  99. };
  100. } ipi;
  101. gid.value = cpu;
  102. ipi.thread = get_thread(gid);
  103. ipi.core = gid.core;
  104. ipi.cluster = nps_cluster_logic_to_phys(gid.cluster);
  105. ipi.num = NPS_IPI_IRQ;
  106. __asm__ __volatile__(
  107. " mov r3, %0\n"
  108. " .word %1\n"
  109. :
  110. : "r"(ipi.value), "i"(CTOP_INST_ASRI_0_R3)
  111. : "r3");
  112. }
  113. static void eznps_init_per_cpu(int cpu)
  114. {
  115. smp_ipi_irq_setup(cpu, NPS_IPI_IRQ);
  116. eznps_init_core(cpu);
  117. mtm_enable_core(cpu);
  118. }
  119. struct plat_smp_ops plat_smp_ops = {
  120. .info = smp_cpuinfo_buf,
  121. .init_early_smp = eznps_init_cpumasks,
  122. .cpu_kick = eznps_smp_wakeup_cpu,
  123. .ipi_send = eznps_ipi_send,
  124. .init_per_cpu = eznps_init_per_cpu,
  125. };