platsmp.c 4.4 KB

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