| H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_IPI_H | 
|  | 2 | #define _ASM_X86_IPI_H | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 |  | 
| Ingo Molnar | d53e2f2 | 2009-01-28 19:14:52 +0100 | [diff] [blame] | 4 | #ifdef CONFIG_X86_LOCAL_APIC | 
|  | 5 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | /* | 
|  | 7 | * Copyright 2004 James Cleverdon, IBM. | 
|  | 8 | * Subject to the GNU Public License, v.2 | 
|  | 9 | * | 
|  | 10 | * Generic APIC InterProcessor Interrupt code. | 
|  | 11 | * | 
|  | 12 | * Moved to include file by James Cleverdon from | 
|  | 13 | * arch/x86-64/kernel/smp.c | 
|  | 14 | * | 
|  | 15 | * Copyrights from kernel/smp.c: | 
|  | 16 | * | 
|  | 17 | * (c) 1995 Alan Cox, Building #3 <alan@redhat.com> | 
|  | 18 | * (c) 1998-99, 2000 Ingo Molnar <mingo@redhat.com> | 
|  | 19 | * (c) 2002,2003 Andi Kleen, SuSE Labs. | 
|  | 20 | * Subject to the GNU Public License, v.2 | 
|  | 21 | */ | 
|  | 22 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/hw_irq.h> | 
| Jan Beulich | 00f1ea6 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 24 | #include <asm/apic.h> | 
| Paul Jackson | e3f8ba8 | 2008-05-14 08:15:04 -0700 | [diff] [blame] | 25 | #include <asm/smp.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 |  | 
|  | 27 | /* | 
|  | 28 | * the following functions deal with sending IPIs between CPUs. | 
|  | 29 | * | 
|  | 30 | * We use 'broadcast', CPU->CPU IPIs and self-IPIs too. | 
|  | 31 | */ | 
|  | 32 |  | 
| Joe Perches | 061b3d9 | 2008-03-23 01:02:27 -0700 | [diff] [blame] | 33 | static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector, | 
|  | 34 | unsigned int dest) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { | 
| Jan Beulich | 1a426cb | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 36 | unsigned int icr = shortcut | dest; | 
|  | 37 |  | 
|  | 38 | switch (vector) { | 
|  | 39 | default: | 
|  | 40 | icr |= APIC_DM_FIXED | vector; | 
|  | 41 | break; | 
|  | 42 | case NMI_VECTOR: | 
| Jan Beulich | 1a426cb | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 43 | icr |= APIC_DM_NMI; | 
|  | 44 | break; | 
|  | 45 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | return icr; | 
|  | 47 | } | 
|  | 48 |  | 
| Joe Perches | 061b3d9 | 2008-03-23 01:02:27 -0700 | [diff] [blame] | 49 | static inline int __prepare_ICR2(unsigned int mask) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { | 
|  | 51 | return SET_APIC_DEST_FIELD(mask); | 
|  | 52 | } | 
|  | 53 |  | 
| Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 54 | static inline void __xapic_wait_icr_idle(void) | 
|  | 55 | { | 
|  | 56 | while (native_apic_mem_read(APIC_ICR) & APIC_ICR_BUSY) | 
|  | 57 | cpu_relax(); | 
|  | 58 | } | 
|  | 59 |  | 
| Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 60 | static inline void | 
| Ingo Molnar | d53e2f2 | 2009-01-28 19:14:52 +0100 | [diff] [blame] | 61 | __default_send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int dest) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { | 
|  | 63 | /* | 
|  | 64 | * Subtle. In the case of the 'never do double writes' workaround | 
|  | 65 | * we have to lock out interrupts to be safe.  As we don't care | 
|  | 66 | * of the value read we use an atomic rmw access to avoid costly | 
|  | 67 | * cli/sti.  Otherwise we use an even cheaper single atomic write | 
|  | 68 | * to the APIC. | 
|  | 69 | */ | 
|  | 70 | unsigned int cfg; | 
|  | 71 |  | 
|  | 72 | /* | 
|  | 73 | * Wait for idle. | 
|  | 74 | */ | 
| Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 75 | __xapic_wait_icr_idle(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 |  | 
|  | 77 | /* | 
|  | 78 | * No need to touch the target chip field | 
|  | 79 | */ | 
|  | 80 | cfg = __prepare_ICR(shortcut, vector, dest); | 
|  | 81 |  | 
|  | 82 | /* | 
|  | 83 | * Send the IPI. The write to APIC_ICR fires this off. | 
|  | 84 | */ | 
| Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 85 | native_apic_mem_write(APIC_ICR, cfg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Fernando Luis [** ISO-8859-1 charset **] VázquezCao | 9062d88 | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 88 | /* | 
|  | 89 | * This is used to send an IPI with no shorthand notation (the destination is | 
|  | 90 | * specified in bits 56 to 63 of the ICR). | 
|  | 91 | */ | 
| Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 92 | static inline void | 
|  | 93 | __default_send_IPI_dest_field(unsigned int mask, int vector, unsigned int dest) | 
| Fernando Luis [** ISO-8859-1 charset **] VázquezCao | 9062d88 | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 94 | { | 
|  | 95 | unsigned long cfg; | 
|  | 96 |  | 
|  | 97 | /* | 
|  | 98 | * Wait for idle. | 
|  | 99 | */ | 
| Fernando Luis [** ISO-8859-1 charset **] VázquezCao | 70ae77f | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 100 | if (unlikely(vector == NMI_VECTOR)) | 
|  | 101 | safe_apic_wait_icr_idle(); | 
|  | 102 | else | 
| Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 103 | __xapic_wait_icr_idle(); | 
| Fernando Luis [** ISO-8859-1 charset **] VázquezCao | 9062d88 | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 104 |  | 
|  | 105 | /* | 
|  | 106 | * prepare target chip field | 
|  | 107 | */ | 
|  | 108 | cfg = __prepare_ICR2(mask); | 
| Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 109 | native_apic_mem_write(APIC_ICR2, cfg); | 
| Fernando Luis [** ISO-8859-1 charset **] VázquezCao | 9062d88 | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 110 |  | 
|  | 111 | /* | 
|  | 112 | * program the ICR | 
|  | 113 | */ | 
|  | 114 | cfg = __prepare_ICR(0, vector, dest); | 
|  | 115 |  | 
|  | 116 | /* | 
|  | 117 | * Send the IPI. The write to APIC_ICR fires this off. | 
|  | 118 | */ | 
| Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 119 | native_apic_mem_write(APIC_ICR, cfg); | 
| Fernando Luis [** ISO-8859-1 charset **] VázquezCao | 9062d88 | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 120 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 |  | 
| Yinghai Lu | c5e9548 | 2009-01-30 17:29:27 -0800 | [diff] [blame] | 122 | extern void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, | 
|  | 123 | int vector); | 
|  | 124 | extern void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask, | 
|  | 125 | int vector); | 
| Ingo Molnar | d53e2f2 | 2009-01-28 19:14:52 +0100 | [diff] [blame] | 126 |  | 
|  | 127 | /* Avoid include hell */ | 
|  | 128 | #define NMI_VECTOR 0x02 | 
|  | 129 |  | 
| Ingo Molnar | d53e2f2 | 2009-01-28 19:14:52 +0100 | [diff] [blame] | 130 | extern int no_broadcast; | 
|  | 131 |  | 
| Ingo Molnar | d53e2f2 | 2009-01-28 19:14:52 +0100 | [diff] [blame] | 132 | static inline void __default_local_send_IPI_allbutself(int vector) | 
|  | 133 | { | 
|  | 134 | if (no_broadcast || vector == NMI_VECTOR) | 
|  | 135 | apic->send_IPI_mask_allbutself(cpu_online_mask, vector); | 
|  | 136 | else | 
|  | 137 | __default_send_IPI_shortcut(APIC_DEST_ALLBUT, vector, apic->dest_logical); | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | static inline void __default_local_send_IPI_all(int vector) | 
|  | 141 | { | 
|  | 142 | if (no_broadcast || vector == NMI_VECTOR) | 
|  | 143 | apic->send_IPI_mask(cpu_online_mask, vector); | 
|  | 144 | else | 
|  | 145 | __default_send_IPI_shortcut(APIC_DEST_ALLINC, vector, apic->dest_logical); | 
|  | 146 | } | 
|  | 147 |  | 
|  | 148 | #ifdef CONFIG_X86_32 | 
| Tejun Heo | 1245e16 | 2011-01-23 14:37:29 +0100 | [diff] [blame] | 149 | extern void default_send_IPI_mask_sequence_logical(const struct cpumask *mask, | 
|  | 150 | int vector); | 
|  | 151 | extern void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask, | 
|  | 152 | int vector); | 
| Yinghai Lu | c5e9548 | 2009-01-30 17:29:27 -0800 | [diff] [blame] | 153 | extern void default_send_IPI_mask_logical(const struct cpumask *mask, | 
|  | 154 | int vector); | 
|  | 155 | extern void default_send_IPI_allbutself(int vector); | 
|  | 156 | extern void default_send_IPI_all(int vector); | 
|  | 157 | extern void default_send_IPI_self(int vector); | 
| Ingo Molnar | d53e2f2 | 2009-01-28 19:14:52 +0100 | [diff] [blame] | 158 | #endif | 
|  | 159 |  | 
|  | 160 | #endif | 
|  | 161 |  | 
| H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 162 | #endif /* _ASM_X86_IPI_H */ |