platsmp.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * linux/arch/arm/mach-vexpress/platsmp.c
  3. *
  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/init.h>
  12. #include <linux/errno.h>
  13. #include <linux/smp.h>
  14. #include <linux/io.h>
  15. #include <linux/of.h>
  16. #include <linux/of_fdt.h>
  17. #include <linux/vexpress.h>
  18. #include <asm/mcpm.h>
  19. #include <asm/smp_scu.h>
  20. #include <asm/mach/map.h>
  21. #include <mach/motherboard.h>
  22. #include <plat/platsmp.h>
  23. #include "core.h"
  24. #if defined(CONFIG_OF)
  25. static enum {
  26. GENERIC_SCU,
  27. CORTEX_A9_SCU,
  28. } vexpress_dt_scu __initdata = GENERIC_SCU;
  29. static struct map_desc vexpress_dt_cortex_a9_scu_map __initdata = {
  30. .virtual = V2T_PERIPH,
  31. /* .pfn set in vexpress_dt_init_cortex_a9_scu() */
  32. .length = SZ_128,
  33. .type = MT_DEVICE,
  34. };
  35. static void *vexpress_dt_cortex_a9_scu_base __initdata;
  36. const static char *vexpress_dt_cortex_a9_match[] __initconst = {
  37. "arm,cortex-a5-scu",
  38. "arm,cortex-a9-scu",
  39. NULL
  40. };
  41. static int __init vexpress_dt_find_scu(unsigned long node,
  42. const char *uname, int depth, void *data)
  43. {
  44. if (of_flat_dt_match(node, vexpress_dt_cortex_a9_match)) {
  45. phys_addr_t phys_addr;
  46. __be32 *reg = of_get_flat_dt_prop(node, "reg", NULL);
  47. if (WARN_ON(!reg))
  48. return -EINVAL;
  49. phys_addr = be32_to_cpup(reg);
  50. vexpress_dt_scu = CORTEX_A9_SCU;
  51. vexpress_dt_cortex_a9_scu_map.pfn = __phys_to_pfn(phys_addr);
  52. iotable_init(&vexpress_dt_cortex_a9_scu_map, 1);
  53. vexpress_dt_cortex_a9_scu_base = ioremap(phys_addr, SZ_256);
  54. if (WARN_ON(!vexpress_dt_cortex_a9_scu_base))
  55. return -EFAULT;
  56. }
  57. return 0;
  58. }
  59. void __init vexpress_dt_smp_map_io(void)
  60. {
  61. if (initial_boot_params)
  62. WARN_ON(of_scan_flat_dt(vexpress_dt_find_scu, NULL));
  63. }
  64. static int __init vexpress_dt_cpus_num(unsigned long node, const char *uname,
  65. int depth, void *data)
  66. {
  67. static int prev_depth = -1;
  68. static int nr_cpus = -1;
  69. if (prev_depth > depth && nr_cpus > 0)
  70. return nr_cpus;
  71. if (nr_cpus < 0 && strcmp(uname, "cpus") == 0)
  72. nr_cpus = 0;
  73. if (nr_cpus >= 0) {
  74. const char *device_type = of_get_flat_dt_prop(node,
  75. "device_type", NULL);
  76. if (device_type && strcmp(device_type, "cpu") == 0)
  77. nr_cpus++;
  78. }
  79. prev_depth = depth;
  80. return 0;
  81. }
  82. static void __init vexpress_dt_smp_init_cpus(void)
  83. {
  84. int ncores = 0, i;
  85. switch (vexpress_dt_scu) {
  86. case GENERIC_SCU:
  87. ncores = of_scan_flat_dt(vexpress_dt_cpus_num, NULL);
  88. break;
  89. case CORTEX_A9_SCU:
  90. ncores = scu_get_core_count(vexpress_dt_cortex_a9_scu_base);
  91. break;
  92. default:
  93. WARN_ON(1);
  94. break;
  95. }
  96. if (ncores < 2)
  97. return;
  98. if (ncores > nr_cpu_ids) {
  99. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  100. ncores, nr_cpu_ids);
  101. ncores = nr_cpu_ids;
  102. }
  103. for (i = 0; i < ncores; ++i)
  104. set_cpu_possible(i, true);
  105. }
  106. static void __init vexpress_dt_smp_prepare_cpus(unsigned int max_cpus)
  107. {
  108. int i;
  109. switch (vexpress_dt_scu) {
  110. case GENERIC_SCU:
  111. for (i = 0; i < max_cpus; i++)
  112. set_cpu_present(i, true);
  113. break;
  114. case CORTEX_A9_SCU:
  115. scu_enable(vexpress_dt_cortex_a9_scu_base);
  116. break;
  117. default:
  118. WARN_ON(1);
  119. break;
  120. }
  121. }
  122. #else
  123. static void __init vexpress_dt_smp_init_cpus(void)
  124. {
  125. WARN_ON(1);
  126. }
  127. void __init vexpress_dt_smp_prepare_cpus(unsigned int max_cpus)
  128. {
  129. WARN_ON(1);
  130. }
  131. #endif
  132. /*
  133. * Initialise the CPU possible map early - this describes the CPUs
  134. * which may be present or become present in the system.
  135. */
  136. static void __init vexpress_smp_init_cpus(void)
  137. {
  138. if (ct_desc)
  139. ct_desc->init_cpu_map();
  140. else
  141. vexpress_dt_smp_init_cpus();
  142. }
  143. static void __init vexpress_smp_prepare_cpus(unsigned int max_cpus)
  144. {
  145. /*
  146. * Initialise the present map, which describes the set of CPUs
  147. * actually populated at the present time.
  148. */
  149. if (ct_desc)
  150. ct_desc->smp_enable(max_cpus);
  151. else
  152. vexpress_dt_smp_prepare_cpus(max_cpus);
  153. /*
  154. * Write the address of secondary startup into the
  155. * system-wide flags register. The boot monitor waits
  156. * until it receives a soft interrupt, and then the
  157. * secondary CPU branches to this address.
  158. */
  159. vexpress_flags_set(virt_to_phys(versatile_secondary_startup));
  160. }
  161. struct smp_operations __initdata vexpress_smp_ops = {
  162. .smp_init_cpus = vexpress_smp_init_cpus,
  163. .smp_prepare_cpus = vexpress_smp_prepare_cpus,
  164. .smp_secondary_init = versatile_secondary_init,
  165. .smp_boot_secondary = versatile_boot_secondary,
  166. #ifdef CONFIG_HOTPLUG_CPU
  167. .cpu_die = vexpress_cpu_die,
  168. #endif
  169. };
  170. bool __init vexpress_smp_init_ops(void)
  171. {
  172. #ifdef CONFIG_MCPM
  173. /*
  174. * The best way to detect a multi-cluster configuration at the moment
  175. * is to look for the presence of a CCI in the system.
  176. * Override the default vexpress_smp_ops if so.
  177. */
  178. struct device_node *node;
  179. node = of_find_compatible_node(NULL, NULL, "arm,cci-400");
  180. if (node && of_device_is_available(node)) {
  181. mcpm_smp_set_ops();
  182. return true;
  183. }
  184. #endif
  185. return false;
  186. }