iSeries_smp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * SMP support for iSeries machines.
  3. *
  4. * Dave Engebretsen, Peter Bergner, and
  5. * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
  6. *
  7. * Plus various changes from other IBM teams...
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #undef DEBUG
  15. #include <linux/config.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/sched.h>
  19. #include <linux/smp.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/kernel_stat.h>
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/cache.h>
  27. #include <linux/err.h>
  28. #include <linux/sysdev.h>
  29. #include <linux/cpu.h>
  30. #include <asm/ptrace.h>
  31. #include <asm/atomic.h>
  32. #include <asm/irq.h>
  33. #include <asm/page.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/io.h>
  36. #include <asm/smp.h>
  37. #include <asm/paca.h>
  38. #include <asm/iSeries/HvCall.h>
  39. #include <asm/time.h>
  40. #include <asm/ppcdebug.h>
  41. #include <asm/machdep.h>
  42. #include <asm/cputable.h>
  43. #include <asm/system.h>
  44. static unsigned long iSeries_smp_message[NR_CPUS];
  45. void iSeries_smp_message_recv( struct pt_regs * regs )
  46. {
  47. int cpu = smp_processor_id();
  48. int msg;
  49. if ( num_online_cpus() < 2 )
  50. return;
  51. for ( msg = 0; msg < 4; ++msg )
  52. if ( test_and_clear_bit( msg, &iSeries_smp_message[cpu] ) )
  53. smp_message_recv( msg, regs );
  54. }
  55. static inline void smp_iSeries_do_message(int cpu, int msg)
  56. {
  57. set_bit(msg, &iSeries_smp_message[cpu]);
  58. HvCall_sendIPI(&(paca[cpu]));
  59. }
  60. static void smp_iSeries_message_pass(int target, int msg)
  61. {
  62. int i;
  63. if (target < NR_CPUS)
  64. smp_iSeries_do_message(target, msg);
  65. else {
  66. for_each_online_cpu(i) {
  67. if (target == MSG_ALL_BUT_SELF
  68. && i == smp_processor_id())
  69. continue;
  70. smp_iSeries_do_message(i, msg);
  71. }
  72. }
  73. }
  74. static int smp_iSeries_numProcs(void)
  75. {
  76. unsigned np, i;
  77. np = 0;
  78. for (i=0; i < NR_CPUS; ++i) {
  79. if (paca[i].lppaca.dyn_proc_status < 2) {
  80. cpu_set(i, cpu_possible_map);
  81. cpu_set(i, cpu_present_map);
  82. cpu_set(i, cpu_sibling_map[i]);
  83. ++np;
  84. }
  85. }
  86. return np;
  87. }
  88. static int smp_iSeries_probe(void)
  89. {
  90. unsigned i;
  91. unsigned np = 0;
  92. for (i=0; i < NR_CPUS; ++i) {
  93. if (paca[i].lppaca.dyn_proc_status < 2) {
  94. /*paca[i].active = 1;*/
  95. ++np;
  96. }
  97. }
  98. return np;
  99. }
  100. static void smp_iSeries_kick_cpu(int nr)
  101. {
  102. BUG_ON(nr < 0 || nr >= NR_CPUS);
  103. /* Verify that our partition has a processor nr */
  104. if (paca[nr].lppaca.dyn_proc_status >= 2)
  105. return;
  106. /* The processor is currently spinning, waiting
  107. * for the cpu_start field to become non-zero
  108. * After we set cpu_start, the processor will
  109. * continue on to secondary_start in iSeries_head.S
  110. */
  111. paca[nr].cpu_start = 1;
  112. }
  113. static void __devinit smp_iSeries_setup_cpu(int nr)
  114. {
  115. }
  116. static struct smp_ops_t iSeries_smp_ops = {
  117. .message_pass = smp_iSeries_message_pass,
  118. .probe = smp_iSeries_probe,
  119. .kick_cpu = smp_iSeries_kick_cpu,
  120. .setup_cpu = smp_iSeries_setup_cpu,
  121. };
  122. /* This is called very early. */
  123. void __init smp_init_iSeries(void)
  124. {
  125. smp_ops = &iSeries_smp_ops;
  126. systemcfg->processorCount = smp_iSeries_numProcs();
  127. }