ipi.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/fixmap.h>
  20. #include <asm/hw_irq.h>
  21. #include <asm/apicdef.h>
  22. #include <asm/genapic.h>
  23. /*
  24. * the following functions deal with sending IPIs between CPUs.
  25. *
  26. * We use 'broadcast', CPU->CPU IPIs and self-IPIs too.
  27. */
  28. static inline unsigned int __prepare_ICR (unsigned int shortcut, int vector, unsigned int dest)
  29. {
  30. unsigned int icr = APIC_DM_FIXED | shortcut | vector | dest;
  31. if (vector == KDB_VECTOR)
  32. icr = (icr & (~APIC_VECTOR_MASK)) | APIC_DM_NMI;
  33. return icr;
  34. }
  35. static inline int __prepare_ICR2 (unsigned int mask)
  36. {
  37. return SET_APIC_DEST_FIELD(mask);
  38. }
  39. static inline void __send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int dest)
  40. {
  41. /*
  42. * Subtle. In the case of the 'never do double writes' workaround
  43. * we have to lock out interrupts to be safe. As we don't care
  44. * of the value read we use an atomic rmw access to avoid costly
  45. * cli/sti. Otherwise we use an even cheaper single atomic write
  46. * to the APIC.
  47. */
  48. unsigned int cfg;
  49. /*
  50. * Wait for idle.
  51. */
  52. apic_wait_icr_idle();
  53. /*
  54. * No need to touch the target chip field
  55. */
  56. cfg = __prepare_ICR(shortcut, vector, dest);
  57. /*
  58. * Send the IPI. The write to APIC_ICR fires this off.
  59. */
  60. apic_write_around(APIC_ICR, cfg);
  61. }
  62. static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
  63. {
  64. unsigned long cfg, flags;
  65. unsigned long query_cpu;
  66. /*
  67. * Hack. The clustered APIC addressing mode doesn't allow us to send
  68. * to an arbitrary mask, so I do a unicast to each CPU instead.
  69. * - mbligh
  70. */
  71. local_irq_save(flags);
  72. for_each_cpu_mask(query_cpu, mask) {
  73. /*
  74. * Wait for idle.
  75. */
  76. apic_wait_icr_idle();
  77. /*
  78. * prepare target chip field
  79. */
  80. cfg = __prepare_ICR2(x86_cpu_to_apicid[query_cpu]);
  81. apic_write_around(APIC_ICR2, cfg);
  82. /*
  83. * program the ICR
  84. */
  85. cfg = __prepare_ICR(0, vector, APIC_DEST_PHYSICAL);
  86. /*
  87. * Send the IPI. The write to APIC_ICR fires this off.
  88. */
  89. apic_write_around(APIC_ICR, cfg);
  90. }
  91. local_irq_restore(flags);
  92. }
  93. #endif /* __ASM_IPI_H */