ipi.c 3.7 KB

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