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