blob: 3d8d6a6c1f8e5f8435db4e6be54b0608d0872ace [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/hw_irq.h>
Jan Beulich00f1ea62007-05-02 19:27:04 +020022#include <asm/apic.h>
Paul Jacksone3f8ba82008-05-14 08:15:04 -070023#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
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 Perches061b3d92008-03-23 01:02:27 -070031static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector,
32 unsigned int dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Jan Beulich1a426cb2005-09-12 18:49:24 +020034 unsigned int icr = shortcut | dest;
35
36 switch (vector) {
37 default:
38 icr |= APIC_DM_FIXED | vector;
39 break;
40 case NMI_VECTOR:
Jan Beulich1a426cb2005-09-12 18:49:24 +020041 icr |= APIC_DM_NMI;
42 break;
43 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 return icr;
45}
46
Joe Perches061b3d92008-03-23 01:02:27 -070047static inline int __prepare_ICR2(unsigned int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
49 return SET_APIC_DEST_FIELD(mask);
50}
51
Suresh Siddha1b374e42008-07-10 11:16:49 -070052static inline void __xapic_wait_icr_idle(void)
53{
54 while (native_apic_mem_read(APIC_ICR) & APIC_ICR_BUSY)
55 cpu_relax();
56}
57
Joe Perches061b3d92008-03-23 01:02:27 -070058static inline void __send_IPI_shortcut(unsigned int shortcut, int vector,
59 unsigned int dest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 /*
62 * Subtle. In the case of the 'never do double writes' workaround
63 * we have to lock out interrupts to be safe. As we don't care
64 * of the value read we use an atomic rmw access to avoid costly
65 * cli/sti. Otherwise we use an even cheaper single atomic write
66 * to the APIC.
67 */
68 unsigned int cfg;
69
70 /*
71 * Wait for idle.
72 */
Suresh Siddha1b374e42008-07-10 11:16:49 -070073 __xapic_wait_icr_idle();
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 /*
76 * No need to touch the target chip field
77 */
78 cfg = __prepare_ICR(shortcut, vector, dest);
79
80 /*
81 * Send the IPI. The write to APIC_ICR fires this off.
82 */
Suresh Siddha1b374e42008-07-10 11:16:49 -070083 native_apic_mem_write(APIC_ICR, cfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +020086/*
87 * This is used to send an IPI with no shorthand notation (the destination is
88 * specified in bits 56 to 63 of the ICR).
89 */
Joe Perches061b3d92008-03-23 01:02:27 -070090static inline void __send_IPI_dest_field(unsigned int mask, int vector,
91 unsigned int dest)
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +020092{
93 unsigned long cfg;
94
95 /*
96 * Wait for idle.
97 */
Fernando Luis [** ISO-8859-1 charset **] VázquezCao70ae77f2007-05-02 19:27:18 +020098 if (unlikely(vector == NMI_VECTOR))
99 safe_apic_wait_icr_idle();
100 else
Suresh Siddha1b374e42008-07-10 11:16:49 -0700101 __xapic_wait_icr_idle();
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200102
103 /*
104 * prepare target chip field
105 */
106 cfg = __prepare_ICR2(mask);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700107 native_apic_mem_write(APIC_ICR2, cfg);
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200108
109 /*
110 * program the ICR
111 */
112 cfg = __prepare_ICR(0, vector, dest);
113
114 /*
115 * Send the IPI. The write to APIC_ICR fires this off.
116 */
Suresh Siddha1b374e42008-07-10 11:16:49 -0700117 native_apic_mem_write(APIC_ICR, cfg);
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120static inline void send_IPI_mask_sequence(cpumask_t mask, int vector)
121{
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200122 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 unsigned long query_cpu;
124
125 /*
126 * Hack. The clustered APIC addressing mode doesn't allow us to send
127 * to an arbitrary mask, so I do a unicast to each CPU instead.
128 * - mbligh
129 */
130 local_irq_save(flags);
Andi Kleen74f06292005-07-28 21:15:25 -0700131 for_each_cpu_mask(query_cpu, mask) {
Mike Travis71fff5e2007-10-19 20:35:03 +0200132 __send_IPI_dest_field(per_cpu(x86_cpu_to_apicid, query_cpu),
Fernando Luis [** ISO-8859-1 charset **] VázquezCao9062d882007-05-02 19:27:18 +0200133 vector, APIC_DEST_PHYSICAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135 local_irq_restore(flags);
136}
137
138#endif /* __ASM_IPI_H */