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_single_phys(int cpu
, int vector
)
25 local_irq_save(flags
);
26 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid
, cpu
),
27 vector
, APIC_DEST_PHYSICAL
);
28 local_irq_restore(flags
);
31 void default_send_IPI_mask_sequence_phys(const struct cpumask
*mask
, int vector
)
33 unsigned long query_cpu
;
37 * Hack. The clustered APIC addressing mode doesn't allow us to send
38 * to an arbitrary mask, so I do a unicast to each CPU instead.
41 local_irq_save(flags
);
42 for_each_cpu(query_cpu
, mask
) {
43 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid
,
44 query_cpu
), vector
, APIC_DEST_PHYSICAL
);
46 local_irq_restore(flags
);
49 void default_send_IPI_mask_allbutself_phys(const struct cpumask
*mask
,
52 unsigned int this_cpu
= smp_processor_id();
53 unsigned int query_cpu
;
56 /* See Hack comment above */
58 local_irq_save(flags
);
59 for_each_cpu(query_cpu
, mask
) {
60 if (query_cpu
== this_cpu
)
62 __default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid
,
63 query_cpu
), vector
, APIC_DEST_PHYSICAL
);
65 local_irq_restore(flags
);
69 * Helper function for APICs which insist on cpumasks
71 void default_send_IPI_single(int cpu
, int vector
)
73 apic
->send_IPI_mask(cpumask_of(cpu
), vector
);
78 void default_send_IPI_mask_sequence_logical(const struct cpumask
*mask
,
82 unsigned int query_cpu
;
85 * Hack. The clustered APIC addressing mode doesn't allow us to send
86 * to an arbitrary mask, so I do a unicasts to each CPU instead. This
87 * should be modified to do 1 message per cluster ID - mbligh
90 local_irq_save(flags
);
91 for_each_cpu(query_cpu
, mask
)
92 __default_send_IPI_dest_field(
93 early_per_cpu(x86_cpu_to_logical_apicid
, query_cpu
),
94 vector
, apic
->dest_logical
);
95 local_irq_restore(flags
);
98 void default_send_IPI_mask_allbutself_logical(const struct cpumask
*mask
,
102 unsigned int query_cpu
;
103 unsigned int this_cpu
= smp_processor_id();
105 /* See Hack comment above */
107 local_irq_save(flags
);
108 for_each_cpu(query_cpu
, mask
) {
109 if (query_cpu
== this_cpu
)
111 __default_send_IPI_dest_field(
112 early_per_cpu(x86_cpu_to_logical_apicid
, query_cpu
),
113 vector
, apic
->dest_logical
);
115 local_irq_restore(flags
);
119 * This is only used on smaller machines.
121 void default_send_IPI_mask_logical(const struct cpumask
*cpumask
, int vector
)
123 unsigned long mask
= cpumask_bits(cpumask
)[0];
129 local_irq_save(flags
);
130 WARN_ON(mask
& ~cpumask_bits(cpu_online_mask
)[0]);
131 __default_send_IPI_dest_field(mask
, vector
, apic
->dest_logical
);
132 local_irq_restore(flags
);
135 void default_send_IPI_allbutself(int vector
)
138 * if there are no other CPUs in the system then we get an APIC send
139 * error if we try to broadcast, thus avoid sending IPIs in this case.
141 if (!(num_online_cpus() > 1))
144 __default_local_send_IPI_allbutself(vector
);
147 void default_send_IPI_all(int vector
)
149 __default_local_send_IPI_all(vector
);
152 void default_send_IPI_self(int vector
)
154 __default_send_IPI_shortcut(APIC_DEST_SELF
, vector
, apic
->dest_logical
);
157 /* must come after the send_IPI functions above for inlining */
158 static int convert_apicid_to_cpu(int apic_id
)
162 for_each_possible_cpu(i
) {
163 if (per_cpu(x86_cpu_to_apicid
, i
) == apic_id
)
169 int safe_smp_processor_id(void)
176 apicid
= hard_smp_processor_id();
177 if (apicid
== BAD_APICID
)
180 cpuid
= convert_apicid_to_cpu(apicid
);
182 return cpuid
>= 0 ? cpuid
: 0;