platsmp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 <asm/smp_scu.h>
  17. #include <asm/hardware/gic.h>
  18. #include <asm/mach/map.h>
  19. #include <mach/motherboard.h>
  20. #include "core.h"
  21. extern void versatile_secondary_startup(void);
  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. set_smp_cross_call(gic_raise_softirq);
  104. }
  105. static void __init vexpress_dt_smp_prepare_cpus(unsigned int max_cpus)
  106. {
  107. int i;
  108. switch (vexpress_dt_scu) {
  109. case GENERIC_SCU:
  110. for (i = 0; i < max_cpus; i++)
  111. set_cpu_present(i, true);
  112. break;
  113. case CORTEX_A9_SCU:
  114. scu_enable(vexpress_dt_cortex_a9_scu_base);
  115. break;
  116. default:
  117. WARN_ON(1);
  118. break;
  119. }
  120. }
  121. #else
  122. static void __init vexpress_dt_smp_init_cpus(void)
  123. {
  124. WARN_ON(1);
  125. }
  126. void __init vexpress_dt_smp_prepare_cpus(unsigned int max_cpus)
  127. {
  128. WARN_ON(1);
  129. }
  130. #endif
  131. /*
  132. * Initialise the CPU possible map early - this describes the CPUs
  133. * which may be present or become present in the system.
  134. */
  135. void __init smp_init_cpus(void)
  136. {
  137. if (ct_desc)
  138. ct_desc->init_cpu_map();
  139. else
  140. vexpress_dt_smp_init_cpus();
  141. }
  142. void __init platform_smp_prepare_cpus(unsigned int max_cpus)
  143. {
  144. /*
  145. * Initialise the present map, which describes the set of CPUs
  146. * actually populated at the present time.
  147. */
  148. if (ct_desc)
  149. ct_desc->smp_enable(max_cpus);
  150. else
  151. vexpress_dt_smp_prepare_cpus(max_cpus);
  152. /*
  153. * Write the address of secondary startup into the
  154. * system-wide flags register. The boot monitor waits
  155. * until it receives a soft interrupt, and then the
  156. * secondary CPU branches to this address.
  157. */
  158. v2m_flags_set(virt_to_phys(versatile_secondary_startup));
  159. }