platsmp.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_fdt.h>
  16. #include <linux/vexpress.h>
  17. #include <asm/smp_scu.h>
  18. #include <asm/hardware/gic.h>
  19. #include <asm/mach/map.h>
  20. #include <mach/motherboard.h>
  21. #include <plat/platsmp.h>
  22. #include "core.h"
  23. #if defined(CONFIG_OF)
  24. static enum {
  25. GENERIC_SCU,
  26. CORTEX_A9_SCU,
  27. } vexpress_dt_scu __initdata = GENERIC_SCU;
  28. static struct map_desc vexpress_dt_cortex_a9_scu_map __initdata = {
  29. .virtual = V2T_PERIPH,
  30. /* .pfn set in vexpress_dt_init_cortex_a9_scu() */
  31. .length = SZ_128,
  32. .type = MT_DEVICE,
  33. };
  34. static void *vexpress_dt_cortex_a9_scu_base __initdata;
  35. const static char *vexpress_dt_cortex_a9_match[] __initconst = {
  36. "arm,cortex-a5-scu",
  37. "arm,cortex-a9-scu",
  38. NULL
  39. };
  40. static int __init vexpress_dt_find_scu(unsigned long node,
  41. const char *uname, int depth, void *data)
  42. {
  43. if (of_flat_dt_match(node, vexpress_dt_cortex_a9_match)) {
  44. phys_addr_t phys_addr;
  45. __be32 *reg = of_get_flat_dt_prop(node, "reg", NULL);
  46. if (WARN_ON(!reg))
  47. return -EINVAL;
  48. phys_addr = be32_to_cpup(reg);
  49. vexpress_dt_scu = CORTEX_A9_SCU;
  50. vexpress_dt_cortex_a9_scu_map.pfn = __phys_to_pfn(phys_addr);
  51. iotable_init(&vexpress_dt_cortex_a9_scu_map, 1);
  52. vexpress_dt_cortex_a9_scu_base = ioremap(phys_addr, SZ_256);
  53. if (WARN_ON(!vexpress_dt_cortex_a9_scu_base))
  54. return -EFAULT;
  55. }
  56. return 0;
  57. }
  58. void __init vexpress_dt_smp_map_io(void)
  59. {
  60. if (initial_boot_params)
  61. WARN_ON(of_scan_flat_dt(vexpress_dt_find_scu, NULL));
  62. }
  63. static int __init vexpress_dt_cpus_num(unsigned long node, const char *uname,
  64. int depth, void *data)
  65. {
  66. static int prev_depth = -1;
  67. static int nr_cpus = -1;
  68. if (prev_depth > depth && nr_cpus > 0)
  69. return nr_cpus;
  70. if (nr_cpus < 0 && strcmp(uname, "cpus") == 0)
  71. nr_cpus = 0;
  72. if (nr_cpus >= 0) {
  73. const char *device_type = of_get_flat_dt_prop(node,
  74. "device_type", NULL);
  75. if (device_type && strcmp(device_type, "cpu") == 0)
  76. nr_cpus++;
  77. }
  78. prev_depth = depth;
  79. return 0;
  80. }
  81. static void __init vexpress_dt_smp_init_cpus(void)
  82. {
  83. int ncores = 0, i;
  84. switch (vexpress_dt_scu) {
  85. case GENERIC_SCU:
  86. ncores = of_scan_flat_dt(vexpress_dt_cpus_num, NULL);
  87. break;
  88. case CORTEX_A9_SCU:
  89. ncores = scu_get_core_count(vexpress_dt_cortex_a9_scu_base);
  90. break;
  91. default:
  92. WARN_ON(1);
  93. break;
  94. }
  95. if (ncores < 2)
  96. return;
  97. if (ncores > nr_cpu_ids) {
  98. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  99. ncores, nr_cpu_ids);
  100. ncores = nr_cpu_ids;
  101. }
  102. for (i = 0; i < ncores; ++i)
  103. set_cpu_possible(i, true);
  104. set_smp_cross_call(gic_raise_softirq);
  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. };