ipi.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include <linux/cpumask.h>
  2. #include <linux/interrupt.h>
  3. #include <linux/init.h>
  4. #include <linux/mm.h>
  5. #include <linux/delay.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/kernel_stat.h>
  8. #include <linux/mc146818rtc.h>
  9. #include <linux/cache.h>
  10. #include <linux/cpu.h>
  11. #include <linux/module.h>
  12. #include <asm/smp.h>
  13. #include <asm/mtrr.h>
  14. #include <asm/tlbflush.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/apic.h>
  17. #include <asm/proto.h>
  18. #include <asm/ipi.h>
  19. void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector)
  20. {
  21. unsigned long query_cpu;
  22. unsigned long flags;
  23. /*
  24. * Hack. The clustered APIC addressing mode doesn't allow us to send
  25. * to an arbitrary mask, so I do a unicast to each CPU instead.
  26. * - mbligh
  27. */
  28. local_irq_save(flags);
  29. for_each_cpu(query_cpu, mask) {
  30. __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
  31. query_cpu), vector, APIC_DEST_PHYSICAL);
  32. }
  33. local_irq_restore(flags);
  34. }
  35. void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask,
  36. int vector)
  37. {
  38. unsigned int this_cpu = smp_processor_id();
  39. unsigned int query_cpu;
  40. unsigned long flags;
  41. /* See Hack comment above */
  42. local_irq_save(flags);
  43. for_each_cpu(query_cpu, mask) {
  44. if (query_cpu == this_cpu)
  45. continue;
  46. __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
  47. query_cpu), vector, APIC_DEST_PHYSICAL);
  48. }
  49. local_irq_restore(flags);
  50. }
  51. #ifdef CONFIG_X86_32
  52. void default_send_IPI_mask_sequence_logical(const struct cpumask *mask,
  53. int vector)
  54. {
  55. unsigned long flags;
  56. unsigned int query_cpu;
  57. /*
  58. * Hack. The clustered APIC addressing mode doesn't allow us to send
  59. * to an arbitrary mask, so I do a unicasts to each CPU instead. This
  60. * should be modified to do 1 message per cluster ID - mbligh
  61. */
  62. local_irq_save(flags);
  63. for_each_cpu(query_cpu, mask)
  64. __default_send_IPI_dest_field(
  65. early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
  66. vector, apic->dest_logical);
  67. local_irq_restore(flags);
  68. }
  69. void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask,
  70. int vector)
  71. {
  72. unsigned long flags;
  73. unsigned int query_cpu;
  74. unsigned int this_cpu = smp_processor_id();
  75. /* See Hack comment above */
  76. local_irq_save(flags);
  77. for_each_cpu(query_cpu, mask) {
  78. if (query_cpu == this_cpu)
  79. continue;
  80. __default_send_IPI_dest_field(
  81. early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
  82. vector, apic->dest_logical);
  83. }
  84. local_irq_restore(flags);
  85. }
  86. /*
  87. * This is only used on smaller machines.
  88. */
  89. void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector)
  90. {
  91. unsigned long mask = cpumask_bits(cpumask)[0];
  92. unsigned long flags;
  93. if (WARN_ONCE(!mask, "empty IPI mask"))
  94. return;
  95. local_irq_save(flags);
  96. WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
  97. __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
  98. local_irq_restore(flags);
  99. }
  100. void default_send_IPI_allbutself(int vector)
  101. {
  102. /*
  103. * if there are no other CPUs in the system then we get an APIC send
  104. * error if we try to broadcast, thus avoid sending IPIs in this case.
  105. */
  106. if (!(num_online_cpus() > 1))
  107. return;
  108. __default_local_send_IPI_allbutself(vector);
  109. }
  110. void default_send_IPI_all(int vector)
  111. {
  112. __default_local_send_IPI_all(vector);
  113. }
  114. void default_send_IPI_self(int vector)
  115. {
  116. __default_send_IPI_shortcut(APIC_DEST_SELF, vector, apic->dest_logical);
  117. }
  118. /* must come after the send_IPI functions above for inlining */
  119. static int convert_apicid_to_cpu(int apic_id)
  120. {
  121. int i;
  122. for_each_possible_cpu(i) {
  123. if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
  124. return i;
  125. }
  126. return -1;
  127. }
  128. int safe_smp_processor_id(void)
  129. {
  130. int apicid, cpuid;
  131. if (!cpu_has_apic)
  132. return 0;
  133. apicid = hard_smp_processor_id();
  134. if (apicid == BAD_APICID)
  135. return 0;
  136. cpuid = convert_apicid_to_cpu(apicid);
  137. return cpuid >= 0 ? cpuid : 0;
  138. }
  139. #endif