2 * Copyright 2004 James Cleverdon, IBM.
3 * Subject to the GNU Public License, v.2
5 * Flat APIC subarch code.
7 * Hacked for x86-64 by James Cleverdon from i386 architecture code by
8 * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
11 #include <linux/errno.h>
12 #include <linux/threads.h>
13 #include <linux/cpumask.h>
14 #include <linux/string.h>
15 #include <linux/kernel.h>
16 #include <linux/ctype.h>
17 #include <linux/hardirq.h>
18 #include <linux/module.h>
23 #include <linux/acpi.h>
25 static struct apic apic_physflat
;
26 static struct apic apic_flat
;
28 struct apic __read_mostly
*apic
= &apic_flat
;
29 EXPORT_SYMBOL_GPL(apic
);
31 static int flat_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
37 * Set up the logical destination ID.
39 * Intel recommends to set DFR, LDR and TPR before enabling
40 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
41 * document number 292116). So here it goes...
43 void flat_init_apic_ldr(void)
46 unsigned long num
, id
;
48 num
= smp_processor_id();
50 apic_write(APIC_DFR
, APIC_DFR_FLAT
);
51 val
= apic_read(APIC_LDR
) & ~APIC_LDR_MASK
;
52 val
|= SET_APIC_LOGICAL_ID(id
);
53 apic_write(APIC_LDR
, val
);
56 static inline void _flat_send_IPI_mask(unsigned long mask
, int vector
)
60 local_irq_save(flags
);
61 __default_send_IPI_dest_field(mask
, vector
, apic
->dest_logical
);
62 local_irq_restore(flags
);
65 static void flat_send_IPI_mask(const struct cpumask
*cpumask
, int vector
)
67 unsigned long mask
= cpumask_bits(cpumask
)[0];
69 _flat_send_IPI_mask(mask
, vector
);
73 flat_send_IPI_mask_allbutself(const struct cpumask
*cpumask
, int vector
)
75 unsigned long mask
= cpumask_bits(cpumask
)[0];
76 int cpu
= smp_processor_id();
78 if (cpu
< BITS_PER_LONG
)
79 clear_bit(cpu
, &mask
);
81 _flat_send_IPI_mask(mask
, vector
);
84 static void flat_send_IPI_allbutself(int vector
)
86 int cpu
= smp_processor_id();
87 #ifdef CONFIG_HOTPLUG_CPU
92 if (hotplug
|| vector
== NMI_VECTOR
) {
93 if (!cpumask_equal(cpu_online_mask
, cpumask_of(cpu
))) {
94 unsigned long mask
= cpumask_bits(cpu_online_mask
)[0];
96 if (cpu
< BITS_PER_LONG
)
97 clear_bit(cpu
, &mask
);
99 _flat_send_IPI_mask(mask
, vector
);
101 } else if (num_online_cpus() > 1) {
102 __default_send_IPI_shortcut(APIC_DEST_ALLBUT
,
103 vector
, apic
->dest_logical
);
107 static void flat_send_IPI_all(int vector
)
109 if (vector
== NMI_VECTOR
) {
110 flat_send_IPI_mask(cpu_online_mask
, vector
);
112 __default_send_IPI_shortcut(APIC_DEST_ALLINC
,
113 vector
, apic
->dest_logical
);
117 static unsigned int flat_get_apic_id(unsigned long x
)
121 id
= (((x
)>>24) & 0xFFu
);
126 static unsigned long set_apic_id(unsigned int id
)
130 x
= ((id
& 0xFFu
)<<24);
134 static unsigned int read_xapic_id(void)
138 id
= flat_get_apic_id(apic_read(APIC_ID
));
142 static int flat_apic_id_registered(void)
144 return physid_isset(read_xapic_id(), phys_cpu_present_map
);
147 static int flat_phys_pkg_id(int initial_apic_id
, int index_msb
)
149 return initial_apic_id
>> index_msb
;
152 static int flat_probe(void)
157 static struct apic apic_flat
= {
160 .acpi_madt_oem_check
= flat_acpi_madt_oem_check
,
161 .apic_id_valid
= default_apic_id_valid
,
162 .apic_id_registered
= flat_apic_id_registered
,
164 .irq_delivery_mode
= dest_LowestPrio
,
165 .irq_dest_mode
= 1, /* logical */
167 .target_cpus
= online_target_cpus
,
169 .dest_logical
= APIC_DEST_LOGICAL
,
170 .check_apicid_used
= NULL
,
171 .check_apicid_present
= NULL
,
173 .vector_allocation_domain
= flat_vector_allocation_domain
,
174 .init_apic_ldr
= flat_init_apic_ldr
,
176 .ioapic_phys_id_map
= NULL
,
177 .setup_apic_routing
= NULL
,
178 .multi_timer_check
= NULL
,
179 .cpu_present_to_apicid
= default_cpu_present_to_apicid
,
180 .apicid_to_cpu_present
= NULL
,
181 .setup_portio_remap
= NULL
,
182 .check_phys_apicid_present
= default_check_phys_apicid_present
,
183 .enable_apic_mode
= NULL
,
184 .phys_pkg_id
= flat_phys_pkg_id
,
185 .mps_oem_check
= NULL
,
187 .get_apic_id
= flat_get_apic_id
,
188 .set_apic_id
= set_apic_id
,
189 .apic_id_mask
= 0xFFu
<< 24,
191 .cpu_mask_to_apicid_and
= flat_cpu_mask_to_apicid_and
,
193 .send_IPI_mask
= flat_send_IPI_mask
,
194 .send_IPI_mask_allbutself
= flat_send_IPI_mask_allbutself
,
195 .send_IPI_allbutself
= flat_send_IPI_allbutself
,
196 .send_IPI_all
= flat_send_IPI_all
,
197 .send_IPI_self
= apic_send_IPI_self
,
199 .trampoline_phys_low
= DEFAULT_TRAMPOLINE_PHYS_LOW
,
200 .trampoline_phys_high
= DEFAULT_TRAMPOLINE_PHYS_HIGH
,
201 .wait_for_init_deassert
= NULL
,
202 .smp_callin_clear_local_apic
= NULL
,
203 .inquire_remote_apic
= default_inquire_remote_apic
,
205 .read
= native_apic_mem_read
,
206 .write
= native_apic_mem_write
,
207 .eoi_write
= native_apic_mem_write
,
208 .icr_read
= native_apic_icr_read
,
209 .icr_write
= native_apic_icr_write
,
210 .wait_icr_idle
= native_apic_wait_icr_idle
,
211 .safe_wait_icr_idle
= native_safe_apic_wait_icr_idle
,
215 * Physflat mode is used when there are more than 8 CPUs on a system.
216 * We cannot use logical delivery in this case because the mask
217 * overflows, so use physical mode.
219 static int physflat_acpi_madt_oem_check(char *oem_id
, char *oem_table_id
)
223 * Quirk: some x86_64 machines can only use physical APIC mode
224 * regardless of how many processors are present (x86_64 ES7000
227 if (acpi_gbl_FADT
.header
.revision
>= FADT2_REVISION_ID
&&
228 (acpi_gbl_FADT
.flags
& ACPI_FADT_APIC_PHYSICAL
)) {
229 printk(KERN_DEBUG
"system APIC only can use physical flat");
233 if (!strncmp(oem_id
, "IBM", 3) && !strncmp(oem_table_id
, "EXA", 3)) {
234 printk(KERN_DEBUG
"IBM Summit detected, will use apic physical");
242 static void physflat_send_IPI_mask(const struct cpumask
*cpumask
, int vector
)
244 default_send_IPI_mask_sequence_phys(cpumask
, vector
);
247 static void physflat_send_IPI_mask_allbutself(const struct cpumask
*cpumask
,
250 default_send_IPI_mask_allbutself_phys(cpumask
, vector
);
253 static void physflat_send_IPI_allbutself(int vector
)
255 default_send_IPI_mask_allbutself_phys(cpu_online_mask
, vector
);
258 static void physflat_send_IPI_all(int vector
)
260 physflat_send_IPI_mask(cpu_online_mask
, vector
);
263 static int physflat_probe(void)
265 if (apic
== &apic_physflat
|| num_possible_cpus() > 8)
271 static struct apic apic_physflat
= {
273 .name
= "physical flat",
274 .probe
= physflat_probe
,
275 .acpi_madt_oem_check
= physflat_acpi_madt_oem_check
,
276 .apic_id_valid
= default_apic_id_valid
,
277 .apic_id_registered
= flat_apic_id_registered
,
279 .irq_delivery_mode
= dest_Fixed
,
280 .irq_dest_mode
= 0, /* physical */
282 .target_cpus
= online_target_cpus
,
285 .check_apicid_used
= NULL
,
286 .check_apicid_present
= NULL
,
288 .vector_allocation_domain
= default_vector_allocation_domain
,
289 /* not needed, but shouldn't hurt: */
290 .init_apic_ldr
= flat_init_apic_ldr
,
292 .ioapic_phys_id_map
= NULL
,
293 .setup_apic_routing
= NULL
,
294 .multi_timer_check
= NULL
,
295 .cpu_present_to_apicid
= default_cpu_present_to_apicid
,
296 .apicid_to_cpu_present
= NULL
,
297 .setup_portio_remap
= NULL
,
298 .check_phys_apicid_present
= default_check_phys_apicid_present
,
299 .enable_apic_mode
= NULL
,
300 .phys_pkg_id
= flat_phys_pkg_id
,
301 .mps_oem_check
= NULL
,
303 .get_apic_id
= flat_get_apic_id
,
304 .set_apic_id
= set_apic_id
,
305 .apic_id_mask
= 0xFFu
<< 24,
307 .cpu_mask_to_apicid_and
= default_cpu_mask_to_apicid_and
,
309 .send_IPI_mask
= physflat_send_IPI_mask
,
310 .send_IPI_mask_allbutself
= physflat_send_IPI_mask_allbutself
,
311 .send_IPI_allbutself
= physflat_send_IPI_allbutself
,
312 .send_IPI_all
= physflat_send_IPI_all
,
313 .send_IPI_self
= apic_send_IPI_self
,
315 .trampoline_phys_low
= DEFAULT_TRAMPOLINE_PHYS_LOW
,
316 .trampoline_phys_high
= DEFAULT_TRAMPOLINE_PHYS_HIGH
,
317 .wait_for_init_deassert
= NULL
,
318 .smp_callin_clear_local_apic
= NULL
,
319 .inquire_remote_apic
= default_inquire_remote_apic
,
321 .read
= native_apic_mem_read
,
322 .write
= native_apic_mem_write
,
323 .eoi_write
= native_apic_mem_write
,
324 .icr_read
= native_apic_icr_read
,
325 .icr_write
= native_apic_icr_write
,
326 .wait_icr_idle
= native_apic_wait_icr_idle
,
327 .safe_wait_icr_idle
= native_safe_apic_wait_icr_idle
,
331 * We need to check for physflat first, so this order is important.
333 apic_drivers(apic_physflat
, apic_flat
);