smp.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Author: Andy Fleming <afleming@freescale.com>
  3. * Kumar Gala <galak@kernel.crashing.org>
  4. *
  5. * Copyright 2006-2008, 2011 Freescale Semiconductor Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/of.h>
  17. #include <linux/kexec.h>
  18. #include <linux/highmem.h>
  19. #include <asm/machdep.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/page.h>
  22. #include <asm/mpic.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/dbell.h>
  25. #include <sysdev/fsl_soc.h>
  26. #include <sysdev/mpic.h>
  27. #include "smp.h"
  28. extern void __early_start(void);
  29. #define BOOT_ENTRY_ADDR_UPPER 0
  30. #define BOOT_ENTRY_ADDR_LOWER 1
  31. #define BOOT_ENTRY_R3_UPPER 2
  32. #define BOOT_ENTRY_R3_LOWER 3
  33. #define BOOT_ENTRY_RESV 4
  34. #define BOOT_ENTRY_PIR 5
  35. #define BOOT_ENTRY_R6_UPPER 6
  36. #define BOOT_ENTRY_R6_LOWER 7
  37. #define NUM_BOOT_ENTRY 8
  38. #define SIZE_BOOT_ENTRY (NUM_BOOT_ENTRY * sizeof(u32))
  39. static int __init
  40. smp_85xx_kick_cpu(int nr)
  41. {
  42. unsigned long flags;
  43. const u64 *cpu_rel_addr;
  44. __iomem u32 *bptr_vaddr;
  45. struct device_node *np;
  46. int n = 0, hw_cpu = get_hard_smp_processor_id(nr);
  47. int ioremappable;
  48. WARN_ON(nr < 0 || nr >= NR_CPUS);
  49. WARN_ON(hw_cpu < 0 || hw_cpu >= NR_CPUS);
  50. pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr);
  51. np = of_get_cpu_node(nr, NULL);
  52. cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL);
  53. if (cpu_rel_addr == NULL) {
  54. printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr);
  55. return -ENOENT;
  56. }
  57. /*
  58. * A secondary core could be in a spinloop in the bootpage
  59. * (0xfffff000), somewhere in highmem, or somewhere in lowmem.
  60. * The bootpage and highmem can be accessed via ioremap(), but
  61. * we need to directly access the spinloop if its in lowmem.
  62. */
  63. ioremappable = *cpu_rel_addr > virt_to_phys(high_memory);
  64. /* Map the spin table */
  65. if (ioremappable)
  66. bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY);
  67. else
  68. bptr_vaddr = phys_to_virt(*cpu_rel_addr);
  69. local_irq_save(flags);
  70. out_be32(bptr_vaddr + BOOT_ENTRY_PIR, hw_cpu);
  71. #ifdef CONFIG_PPC32
  72. out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start));
  73. if (!ioremappable)
  74. flush_dcache_range((ulong)bptr_vaddr,
  75. (ulong)(bptr_vaddr + SIZE_BOOT_ENTRY));
  76. /* Wait a bit for the CPU to ack. */
  77. while ((__secondary_hold_acknowledge != hw_cpu) && (++n < 1000))
  78. mdelay(1);
  79. #else
  80. smp_generic_kick_cpu(nr);
  81. out_be64((u64 *)(bptr_vaddr + BOOT_ENTRY_ADDR_UPPER),
  82. __pa((u64)*((unsigned long long *) generic_secondary_smp_init)));
  83. if (!ioremappable)
  84. flush_dcache_range((ulong)bptr_vaddr,
  85. (ulong)(bptr_vaddr + SIZE_BOOT_ENTRY));
  86. #endif
  87. local_irq_restore(flags);
  88. if (ioremappable)
  89. iounmap(bptr_vaddr);
  90. pr_debug("waited %d msecs for CPU #%d.\n", n, nr);
  91. return 0;
  92. }
  93. struct smp_ops_t smp_85xx_ops = {
  94. .kick_cpu = smp_85xx_kick_cpu,
  95. #ifdef CONFIG_KEXEC
  96. .give_timebase = smp_generic_give_timebase,
  97. .take_timebase = smp_generic_take_timebase,
  98. #endif
  99. };
  100. #ifdef CONFIG_KEXEC
  101. atomic_t kexec_down_cpus = ATOMIC_INIT(0);
  102. void mpc85xx_smp_kexec_cpu_down(int crash_shutdown, int secondary)
  103. {
  104. local_irq_disable();
  105. if (secondary) {
  106. atomic_inc(&kexec_down_cpus);
  107. /* loop forever */
  108. while (1);
  109. }
  110. }
  111. static void mpc85xx_smp_kexec_down(void *arg)
  112. {
  113. if (ppc_md.kexec_cpu_down)
  114. ppc_md.kexec_cpu_down(0,1);
  115. }
  116. static void map_and_flush(unsigned long paddr)
  117. {
  118. struct page *page = pfn_to_page(paddr >> PAGE_SHIFT);
  119. unsigned long kaddr = (unsigned long)kmap(page);
  120. flush_dcache_range(kaddr, kaddr + PAGE_SIZE);
  121. kunmap(page);
  122. }
  123. /**
  124. * Before we reset the other cores, we need to flush relevant cache
  125. * out to memory so we don't get anything corrupted, some of these flushes
  126. * are performed out of an overabundance of caution as interrupts are not
  127. * disabled yet and we can switch cores
  128. */
  129. static void mpc85xx_smp_flush_dcache_kexec(struct kimage *image)
  130. {
  131. kimage_entry_t *ptr, entry;
  132. unsigned long paddr;
  133. int i;
  134. if (image->type == KEXEC_TYPE_DEFAULT) {
  135. /* normal kexec images are stored in temporary pages */
  136. for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
  137. ptr = (entry & IND_INDIRECTION) ?
  138. phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
  139. if (!(entry & IND_DESTINATION)) {
  140. map_and_flush(entry);
  141. }
  142. }
  143. /* flush out last IND_DONE page */
  144. map_and_flush(entry);
  145. } else {
  146. /* crash type kexec images are copied to the crash region */
  147. for (i = 0; i < image->nr_segments; i++) {
  148. struct kexec_segment *seg = &image->segment[i];
  149. for (paddr = seg->mem; paddr < seg->mem + seg->memsz;
  150. paddr += PAGE_SIZE) {
  151. map_and_flush(paddr);
  152. }
  153. }
  154. }
  155. /* also flush the kimage struct to be passed in as well */
  156. flush_dcache_range((unsigned long)image,
  157. (unsigned long)image + sizeof(*image));
  158. }
  159. static void mpc85xx_smp_machine_kexec(struct kimage *image)
  160. {
  161. int timeout = INT_MAX;
  162. int i, num_cpus = num_present_cpus();
  163. mpc85xx_smp_flush_dcache_kexec(image);
  164. if (image->type == KEXEC_TYPE_DEFAULT)
  165. smp_call_function(mpc85xx_smp_kexec_down, NULL, 0);
  166. while ( (atomic_read(&kexec_down_cpus) != (num_cpus - 1)) &&
  167. ( timeout > 0 ) )
  168. {
  169. timeout--;
  170. }
  171. if ( !timeout )
  172. printk(KERN_ERR "Unable to bring down secondary cpu(s)");
  173. for_each_online_cpu(i)
  174. {
  175. if ( i == smp_processor_id() ) continue;
  176. mpic_reset_core(i);
  177. }
  178. default_machine_kexec(image);
  179. }
  180. #endif /* CONFIG_KEXEC */
  181. static void __init
  182. smp_85xx_setup_cpu(int cpu_nr)
  183. {
  184. if (smp_85xx_ops.probe == smp_mpic_probe)
  185. mpic_setup_this_cpu();
  186. if (cpu_has_feature(CPU_FTR_DBELL))
  187. doorbell_setup_this_cpu();
  188. }
  189. void __init mpc85xx_smp_init(void)
  190. {
  191. struct device_node *np;
  192. smp_85xx_ops.setup_cpu = smp_85xx_setup_cpu;
  193. np = of_find_node_by_type(NULL, "open-pic");
  194. if (np) {
  195. smp_85xx_ops.probe = smp_mpic_probe;
  196. smp_85xx_ops.message_pass = smp_mpic_message_pass;
  197. }
  198. if (cpu_has_feature(CPU_FTR_DBELL)) {
  199. /*
  200. * If left NULL, .message_pass defaults to
  201. * smp_muxed_ipi_message_pass
  202. */
  203. smp_85xx_ops.message_pass = NULL;
  204. smp_85xx_ops.cause_ipi = doorbell_cause_ipi;
  205. }
  206. smp_ops = &smp_85xx_ops;
  207. #ifdef CONFIG_KEXEC
  208. ppc_md.kexec_cpu_down = mpc85xx_smp_kexec_cpu_down;
  209. ppc_md.machine_kexec = mpc85xx_smp_machine_kexec;
  210. #endif
  211. }