Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_IPI_H |
| 2 | #define __ASM_IPI_H |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * the following functions deal with sending IPIs between CPUs. |
| 26 | * |
| 27 | * We use 'broadcast', CPU->CPU IPIs and self-IPIs too. |
| 28 | */ |
| 29 | |
| 30 | static inline unsigned int __prepare_ICR (unsigned int shortcut, int vector, unsigned int dest) |
| 31 | { |
Jan Beulich | 1a426cb | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 32 | unsigned int icr = shortcut | dest; |
| 33 | |
| 34 | switch (vector) { |
| 35 | default: |
| 36 | icr |= APIC_DM_FIXED | vector; |
| 37 | break; |
| 38 | case NMI_VECTOR: |
Jan Beulich | 1a426cb | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 39 | icr |= APIC_DM_NMI; |
| 40 | break; |
| 41 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return icr; |
| 43 | } |
| 44 | |
| 45 | static inline int __prepare_ICR2 (unsigned int mask) |
| 46 | { |
| 47 | return SET_APIC_DEST_FIELD(mask); |
| 48 | } |
| 49 | |
| 50 | static inline void __send_IPI_shortcut(unsigned int shortcut, int vector, unsigned int dest) |
| 51 | { |
| 52 | /* |
| 53 | * Subtle. In the case of the 'never do double writes' workaround |
| 54 | * we have to lock out interrupts to be safe. As we don't care |
| 55 | * of the value read we use an atomic rmw access to avoid costly |
| 56 | * cli/sti. Otherwise we use an even cheaper single atomic write |
| 57 | * to the APIC. |
| 58 | */ |
| 59 | unsigned int cfg; |
| 60 | |
| 61 | /* |
| 62 | * Wait for idle. |
| 63 | */ |
| 64 | apic_wait_icr_idle(); |
| 65 | |
| 66 | /* |
| 67 | * No need to touch the target chip field |
| 68 | */ |
| 69 | cfg = __prepare_ICR(shortcut, vector, dest); |
| 70 | |
| 71 | /* |
| 72 | * Send the IPI. The write to APIC_ICR fires this off. |
| 73 | */ |
Andi Kleen | eddfb4e | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 74 | apic_write(APIC_ICR, cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | static inline void send_IPI_mask_sequence(cpumask_t mask, int vector) |
| 79 | { |
| 80 | unsigned long cfg, flags; |
| 81 | unsigned long query_cpu; |
| 82 | |
| 83 | /* |
| 84 | * Hack. The clustered APIC addressing mode doesn't allow us to send |
| 85 | * to an arbitrary mask, so I do a unicast to each CPU instead. |
| 86 | * - mbligh |
| 87 | */ |
| 88 | local_irq_save(flags); |
| 89 | |
Andi Kleen | 74f0629 | 2005-07-28 21:15:25 -0700 | [diff] [blame] | 90 | for_each_cpu_mask(query_cpu, mask) { |
| 91 | /* |
| 92 | * Wait for idle. |
| 93 | */ |
| 94 | apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Andi Kleen | 74f0629 | 2005-07-28 21:15:25 -0700 | [diff] [blame] | 96 | /* |
| 97 | * prepare target chip field |
| 98 | */ |
| 99 | cfg = __prepare_ICR2(x86_cpu_to_apicid[query_cpu]); |
Andi Kleen | eddfb4e | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 100 | apic_write(APIC_ICR2, cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Andi Kleen | 74f0629 | 2005-07-28 21:15:25 -0700 | [diff] [blame] | 102 | /* |
| 103 | * program the ICR |
| 104 | */ |
| 105 | cfg = __prepare_ICR(0, vector, APIC_DEST_PHYSICAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Andi Kleen | 74f0629 | 2005-07-28 21:15:25 -0700 | [diff] [blame] | 107 | /* |
| 108 | * Send the IPI. The write to APIC_ICR fires this off. |
| 109 | */ |
Andi Kleen | eddfb4e | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 110 | apic_write(APIC_ICR, cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | local_irq_restore(flags); |
| 113 | } |
| 114 | |
| 115 | #endif /* __ASM_IPI_H */ |