ipi.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef __ASM_IPI_H
  2. #define __ASM_IPI_H
  3. /*
  4. * Copyright 2004 James Cleverdon, IBM.
  5. * Subject to the GNU Public License, v.2
  6. *
  7. * Generic APIC InterProcessor Interrupt code.
  8. *
  9. * Moved to include file by James Cleverdon from
  10. * arch/x86-64/kernel/smp.c
  11. *
  12. * Copyrights from kernel/smp.c:
  13. *
  14. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  15. * (c) 1998-99, 2000 Ingo Molnar <mingo@redhat.com>
  16. * (c) 2002,2003 Andi Kleen, SuSE Labs.
  17. * Subject to the GNU Public License, v.2
  18. */
  19. #include <asm/hw_irq.h>
  20. #include <asm/apic.h>
  21. /*
  22. * the following functions deal with sending IPIs between CPUs.
  23. *
  24. * We use 'broadcast', CPU->CPU IPIs and self-IPIs too.
  25. */
  26. static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector,
  27. unsigned int dest)
  28. {
  29. unsigned int icr = shortcut | dest;
  30. switch (vector) {
  31. default:
  32. icr |= APIC_DM_FIXED | vector;
  33. break;
  34. case NMI_VECTOR:
  35. icr |= APIC_DM_NMI;
  36. break;
  37. }
  38. return icr;
  39. }
  40. static inline int __prepare_ICR2(unsigned int mask)
  41. {
  42. return SET_APIC_DEST_FIELD(mask);
  43. }
  44. static inline void __send_IPI_shortcut(unsigned int shortcut, int vector,
  45. unsigned int dest)
  46. {
  47. /*
  48. * Subtle. In the case of the 'never do double writes' workaround
  49. * we have to lock out interrupts to be safe. As we don't care
  50. * of the value read we use an atomic rmw access to avoid costly
  51. * cli/sti. Otherwise we use an even cheaper single atomic write
  52. * to the APIC.
  53. */
  54. unsigned int cfg;
  55. /*
  56. * Wait for idle.
  57. */
  58. apic_wait_icr_idle();
  59. /*
  60. * No need to touch the target chip field
  61. */
  62. cfg = __prepare_ICR(shortcut, vector, dest);
  63. /*
  64. * Send the IPI. The write to APIC_ICR fires this off.
  65. */
  66. apic_write(APIC_ICR, cfg);
  67. }
  68. /*
  69. * This is used to send an IPI with no shorthand notation (the destination is
  70. * specified in bits 56 to 63 of the ICR).
  71. */
  72. static inline void __send_IPI_dest_field(unsigned int mask, int vector,
  73. unsigned int dest)
  74. {
  75. unsigned long cfg;
  76. /*
  77. * Wait for idle.
  78. */
  79. if (unlikely(vector == NMI_VECTOR))
  80. safe_apic_wait_icr_idle();
  81. else
  82. apic_wait_icr_idle();
  83. /*
  84. * prepare target chip field
  85. */
  86. cfg = __prepare_ICR2(mask);
  87. apic_write(APIC_ICR2, cfg);
  88. /*
  89. * program the ICR
  90. */
  91. cfg = __prepare_ICR(0, vector, dest);
  92. /*
  93. * Send the IPI. The write to APIC_ICR fires this off.
  94. */
  95. apic_write(APIC_ICR, cfg);
  96. }
  97. static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
  98. {
  99. unsigned long flags;
  100. unsigned long query_cpu;
  101. /*
  102. * Hack. The clustered APIC addressing mode doesn't allow us to send
  103. * to an arbitrary mask, so I do a unicast to each CPU instead.
  104. * - mbligh
  105. */
  106. local_irq_save(flags);
  107. for_each_cpu_mask(query_cpu, mask) {
  108. __send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, query_cpu),
  109. vector, APIC_DEST_PHYSICAL);
  110. }
  111. local_irq_restore(flags);
  112. }
  113. #endif /* __ASM_IPI_H */