smp.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Author: Andy Fleming <afleming@freescale.com>
  3. * Kumar Gala <galak@kernel.crashing.org>
  4. *
  5. * Copyright 2006-2008 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 <asm/machdep.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/page.h>
  21. #include <asm/mpic.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/dbell.h>
  24. #include <sysdev/fsl_soc.h>
  25. #include <sysdev/mpic.h>
  26. extern void __early_start(void);
  27. #define BOOT_ENTRY_ADDR_UPPER 0
  28. #define BOOT_ENTRY_ADDR_LOWER 1
  29. #define BOOT_ENTRY_R3_UPPER 2
  30. #define BOOT_ENTRY_R3_LOWER 3
  31. #define BOOT_ENTRY_RESV 4
  32. #define BOOT_ENTRY_PIR 5
  33. #define BOOT_ENTRY_R6_UPPER 6
  34. #define BOOT_ENTRY_R6_LOWER 7
  35. #define NUM_BOOT_ENTRY 8
  36. #define SIZE_BOOT_ENTRY (NUM_BOOT_ENTRY * sizeof(u32))
  37. static void __init
  38. smp_85xx_kick_cpu(int nr)
  39. {
  40. unsigned long flags;
  41. const u64 *cpu_rel_addr;
  42. __iomem u32 *bptr_vaddr;
  43. struct device_node *np;
  44. int n = 0;
  45. int ioremappable;
  46. WARN_ON (nr < 0 || nr >= NR_CPUS);
  47. pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr);
  48. np = of_get_cpu_node(nr, NULL);
  49. cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL);
  50. if (cpu_rel_addr == NULL) {
  51. printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr);
  52. return;
  53. }
  54. /*
  55. * A secondary core could be in a spinloop in the bootpage
  56. * (0xfffff000), somewhere in highmem, or somewhere in lowmem.
  57. * The bootpage and highmem can be accessed via ioremap(), but
  58. * we need to directly access the spinloop if its in lowmem.
  59. */
  60. ioremappable = *cpu_rel_addr > virt_to_phys(high_memory);
  61. /* Map the spin table */
  62. if (ioremappable)
  63. bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY);
  64. else
  65. bptr_vaddr = phys_to_virt(*cpu_rel_addr);
  66. local_irq_save(flags);
  67. out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr);
  68. out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start));
  69. if (!ioremappable)
  70. flush_dcache_range((ulong)bptr_vaddr,
  71. (ulong)(bptr_vaddr + SIZE_BOOT_ENTRY));
  72. /* Wait a bit for the CPU to ack. */
  73. while ((__secondary_hold_acknowledge != nr) && (++n < 1000))
  74. mdelay(1);
  75. local_irq_restore(flags);
  76. if (ioremappable)
  77. iounmap(bptr_vaddr);
  78. pr_debug("waited %d msecs for CPU #%d.\n", n, nr);
  79. }
  80. static void __init
  81. smp_85xx_setup_cpu(int cpu_nr)
  82. {
  83. mpic_setup_this_cpu();
  84. if (cpu_has_feature(CPU_FTR_DBELL))
  85. doorbell_setup_this_cpu();
  86. }
  87. struct smp_ops_t smp_85xx_ops = {
  88. .kick_cpu = smp_85xx_kick_cpu,
  89. #ifdef CONFIG_KEXEC
  90. .give_timebase = smp_generic_give_timebase,
  91. .take_timebase = smp_generic_take_timebase,
  92. #endif
  93. };
  94. #ifdef CONFIG_KEXEC
  95. static int kexec_down_cpus = 0;
  96. void mpc85xx_smp_kexec_cpu_down(int crash_shutdown, int secondary)
  97. {
  98. mpic_teardown_this_cpu(1);
  99. /* When crashing, this gets called on all CPU's we only
  100. * take down the non-boot cpus */
  101. if (smp_processor_id() != boot_cpuid)
  102. {
  103. local_irq_disable();
  104. kexec_down_cpus++;
  105. while (1);
  106. }
  107. }
  108. static void mpc85xx_smp_kexec_down(void *arg)
  109. {
  110. if (ppc_md.kexec_cpu_down)
  111. ppc_md.kexec_cpu_down(0,1);
  112. }
  113. static void mpc85xx_smp_machine_kexec(struct kimage *image)
  114. {
  115. int timeout = 2000;
  116. int i;
  117. set_cpus_allowed(current, cpumask_of_cpu(boot_cpuid));
  118. smp_call_function(mpc85xx_smp_kexec_down, NULL, 0);
  119. while ( (kexec_down_cpus != (num_online_cpus() - 1)) &&
  120. ( timeout > 0 ) )
  121. {
  122. timeout--;
  123. }
  124. if ( !timeout )
  125. printk(KERN_ERR "Unable to bring down secondary cpu(s)");
  126. for (i = 0; i < num_present_cpus(); i++)
  127. {
  128. if ( i == smp_processor_id() ) continue;
  129. mpic_reset_core(i);
  130. }
  131. default_machine_kexec(image);
  132. }
  133. #endif /* CONFIG_KEXEC */
  134. void __init mpc85xx_smp_init(void)
  135. {
  136. struct device_node *np;
  137. np = of_find_node_by_type(NULL, "open-pic");
  138. if (np) {
  139. smp_85xx_ops.probe = smp_mpic_probe;
  140. smp_85xx_ops.setup_cpu = smp_85xx_setup_cpu;
  141. smp_85xx_ops.message_pass = smp_mpic_message_pass;
  142. }
  143. if (cpu_has_feature(CPU_FTR_DBELL))
  144. smp_85xx_ops.message_pass = doorbell_message_pass;
  145. BUG_ON(!smp_85xx_ops.message_pass);
  146. smp_ops = &smp_85xx_ops;
  147. #ifdef CONFIG_KEXEC
  148. ppc_md.kexec_cpu_down = mpc85xx_smp_kexec_cpu_down;
  149. ppc_md.machine_kexec = mpc85xx_smp_machine_kexec;
  150. #endif
  151. }