1 #include <linux/cpumask.h>
2 #include <linux/interrupt.h>
5 #include <linux/delay.h>
6 #include <linux/spinlock.h>
7 #include <linux/kernel_stat.h>
8 #include <linux/mc146818rtc.h>
9 #include <linux/cache.h>
10 #include <linux/cpu.h>
11 #include <linux/module.h>
15 #include <asm/tlbflush.h>
16 #include <asm/mmu_context.h>
18 #include <asm/proto.h>
21 void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector)
23 unsigned long query_cpu;
27 * Hack. The clustered APIC addressing mode doesn't allow us to send
28 * to an arbitrary mask, so I do a unicast to each CPU instead.
31 local_irq_save(flags);
32 for_each_cpu(query_cpu, mask) {
33 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
34 query_cpu), vector, APIC_DEST_PHYSICAL);
36 local_irq_restore(flags);
39 void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask,
42 unsigned int this_cpu = smp_processor_id();
43 unsigned int query_cpu;
46 /* See Hack comment above */
48 local_irq_save(flags);
49 for_each_cpu(query_cpu, mask) {
50 if (query_cpu == this_cpu)
52 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
53 query_cpu), vector, APIC_DEST_PHYSICAL);
55 local_irq_restore(flags);
60 void default_send_IPI_mask_sequence_logical(const struct cpumask *mask,
64 unsigned int query_cpu;
67 * Hack. The clustered APIC addressing mode doesn't allow us to send
68 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
69 * should be modified to do 1 message per cluster ID - mbligh
72 local_irq_save(flags);
73 for_each_cpu(query_cpu, mask)
74 __default_send_IPI_dest_field(
75 early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
76 vector, apic->dest_logical);
77 local_irq_restore(flags);
80 void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask,
84 unsigned int query_cpu;
85 unsigned int this_cpu = smp_processor_id();
87 /* See Hack comment above */
89 local_irq_save(flags);
90 for_each_cpu(query_cpu, mask) {
91 if (query_cpu == this_cpu)
93 __default_send_IPI_dest_field(
94 early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
95 vector, apic->dest_logical);
97 local_irq_restore(flags);
101 * This is only used on smaller machines.
103 void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector)
105 unsigned long mask = cpumask_bits(cpumask)[0];
111 local_irq_save(flags);
112 WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
113 __default_send_IPI_dest_field(mask, vector, apic->dest_logical);
114 local_irq_restore(flags);
117 void default_send_IPI_allbutself(int vector)
120 * if there are no other CPUs in the system then we get an APIC send
121 * error if we try to broadcast, thus avoid sending IPIs in this case.
123 if (!(num_online_cpus() > 1))
126 __default_local_send_IPI_allbutself(vector);
129 void default_send_IPI_all(int vector)
131 __default_local_send_IPI_all(vector);
134 void default_send_IPI_self(int vector)
136 __default_send_IPI_shortcut(APIC_DEST_SELF, vector, apic->dest_logical);
139 /* must come after the send_IPI functions above for inlining */
140 static int convert_apicid_to_cpu(int apic_id)
144 for_each_possible_cpu(i) {
145 if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
151 int safe_smp_processor_id(void)
158 apicid = hard_smp_processor_id();
159 if (apicid == BAD_APICID)
162 cpuid = convert_apicid_to_cpu(apicid);
164 return cpuid >= 0 ? cpuid : 0;