smp.c 6.1 KB

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