ipi.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. 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. apic->cpu_to_logical_apicid(query_cpu), vector,
  65. 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. apic->cpu_to_logical_apicid(query_cpu), vector,
  81. apic->dest_logical);
  82. }
  83. local_irq_restore(flags);
  84. }
  85. #ifdef CONFIG_X86_32
  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. local_irq_save(flags);
  94. WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
  95. __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
  96. local_irq_restore(flags);
  97. }
  98. void default_send_IPI_allbutself(int vector)
  99. {
  100. /*
  101. * if there are no other CPUs in the system then we get an APIC send
  102. * error if we try to broadcast, thus avoid sending IPIs in this case.
  103. */
  104. if (!(num_online_cpus() > 1))
  105. return;
  106. __default_local_send_IPI_allbutself(vector);
  107. }
  108. void default_send_IPI_all(int vector)
  109. {
  110. __default_local_send_IPI_all(vector);
  111. }
  112. void default_send_IPI_self(int vector)
  113. {
  114. __default_send_IPI_shortcut(APIC_DEST_SELF, vector, apic->dest_logical);
  115. }
  116. /* must come after the send_IPI functions above for inlining */
  117. static int convert_apicid_to_cpu(int apic_id)
  118. {
  119. int i;
  120. for_each_possible_cpu(i) {
  121. if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
  122. return i;
  123. }
  124. return -1;
  125. }
  126. int safe_smp_processor_id(void)
  127. {
  128. int apicid, cpuid;
  129. if (!boot_cpu_has(X86_FEATURE_APIC))
  130. return 0;
  131. apicid = hard_smp_processor_id();
  132. if (apicid == BAD_APICID)
  133. return 0;
  134. cpuid = convert_apicid_to_cpu(apicid);
  135. return cpuid >= 0 ? cpuid : 0;
  136. }
  137. #endif