Commit | Line | Data |
---|---|---|
9b0c5028 | 1 | /* |
7b387253 IM |
2 | * Default generic APIC driver. This handles up to 8 CPUs. |
3 | * | |
9b0c5028 PC |
4 | * Copyright 2003 Andi Kleen, SuSE Labs. |
5 | * Subject to the GNU Public License, v.2 | |
6 | * | |
1da177e4 | 7 | * Generic x86 APIC driver probe layer. |
9b0c5028 | 8 | */ |
1da177e4 LT |
9 | #include <linux/threads.h> |
10 | #include <linux/cpumask.h> | |
7d01d32d | 11 | #include <linux/module.h> |
1da177e4 LT |
12 | #include <linux/string.h> |
13 | #include <linux/kernel.h> | |
14 | #include <linux/ctype.h> | |
15 | #include <linux/init.h> | |
1a3f239d | 16 | #include <linux/errno.h> |
1da177e4 LT |
17 | #include <asm/fixmap.h> |
18 | #include <asm/mpspec.h> | |
19 | #include <asm/apicdef.h> | |
7b6aa335 | 20 | #include <asm/apic.h> |
54ac14a8 | 21 | #include <asm/setup.h> |
1da177e4 | 22 | |
7b387253 | 23 | #include <linux/smp.h> |
7b387253 IM |
24 | #include <asm/ipi.h> |
25 | ||
6bda2c8b IM |
26 | #include <linux/interrupt.h> |
27 | #include <asm/acpi.h> | |
6bda2c8b | 28 | #include <asm/e820.h> |
6bda2c8b | 29 | |
6bda2c8b IM |
30 | #ifdef CONFIG_HOTPLUG_CPU |
31 | #define DEFAULT_SEND_IPI (1) | |
32 | #else | |
33 | #define DEFAULT_SEND_IPI (0) | |
34 | #endif | |
35 | ||
36 | int no_broadcast = DEFAULT_SEND_IPI; | |
37 | ||
9be1b56a IM |
38 | static __init int no_ipi_broadcast(char *str) |
39 | { | |
40 | get_option(&str, &no_broadcast); | |
41 | pr_info("Using %s mode\n", | |
42 | no_broadcast ? "No IPI Broadcast" : "IPI Broadcast"); | |
43 | return 1; | |
44 | } | |
45 | __setup("no_ipi_broadcast=", no_ipi_broadcast); | |
46 | ||
47 | static int __init print_ipi_mode(void) | |
48 | { | |
49 | pr_info("Using IPI %s mode\n", | |
50 | no_broadcast ? "No-Shortcut" : "Shortcut"); | |
51 | return 0; | |
52 | } | |
53 | late_initcall(print_ipi_mode); | |
6bda2c8b | 54 | |
681ee44d SS |
55 | void __init default_setup_apic_routing(void) |
56 | { | |
57 | int version = apic_version[boot_cpu_physical_apicid]; | |
58 | ||
59 | if (num_possible_cpus() > 8) { | |
60 | switch (boot_cpu_data.x86_vendor) { | |
61 | case X86_VENDOR_INTEL: | |
62 | if (!APIC_XAPIC(version)) { | |
63 | def_to_bigsmp = 0; | |
64 | break; | |
65 | } | |
66 | /* If P4 and above fall through */ | |
67 | case X86_VENDOR_AMD: | |
68 | def_to_bigsmp = 1; | |
69 | } | |
70 | } | |
71 | ||
72 | #ifdef CONFIG_X86_BIGSMP | |
73 | generic_bigsmp_probe(); | |
74 | #endif | |
75 | ||
76 | if (apic->setup_apic_routing) | |
77 | apic->setup_apic_routing(); | |
78 | } | |
79 | ||
80 | static void setup_apic_flat_routing(void) | |
28aa29ee IM |
81 | { |
82 | #ifdef CONFIG_X86_IO_APIC | |
83 | printk(KERN_INFO | |
84 | "Enabling APIC mode: Flat. Using %d I/O APICs\n", | |
85 | nr_ioapics); | |
86 | #endif | |
87 | } | |
88 | ||
7b387253 IM |
89 | static void default_vector_allocation_domain(int cpu, struct cpumask *retmask) |
90 | { | |
91 | /* | |
92 | * Careful. Some cpus do not strictly honor the set of cpus | |
93 | * specified in the interrupt destination when using lowest | |
94 | * priority interrupt delivery mode. | |
95 | * | |
96 | * In particular there was a hyperthreading cpu observed to | |
97 | * deliver interrupts to the wrong hyperthread when only one | |
98 | * hyperthread was specified in the interrupt desitination. | |
99 | */ | |
5c6cb5e2 RR |
100 | cpumask_clear(retmask); |
101 | cpumask_bits(retmask)[0] = APIC_ALL_CPUS; | |
7b387253 IM |
102 | } |
103 | ||
104 | /* should be called last. */ | |
105 | static int probe_default(void) | |
106 | { | |
107 | return 1; | |
108 | } | |
109 | ||
be163a15 | 110 | struct apic apic_default = { |
7b387253 IM |
111 | |
112 | .name = "default", | |
113 | .probe = probe_default, | |
114 | .acpi_madt_oem_check = NULL, | |
115 | .apic_id_registered = default_apic_id_registered, | |
116 | ||
117 | .irq_delivery_mode = dest_LowestPrio, | |
118 | /* logical delivery broadcast to all CPUs: */ | |
119 | .irq_dest_mode = 1, | |
120 | ||
121 | .target_cpus = default_target_cpus, | |
122 | .disable_esr = 0, | |
123 | .dest_logical = APIC_DEST_LOGICAL, | |
124 | .check_apicid_used = default_check_apicid_used, | |
125 | .check_apicid_present = default_check_apicid_present, | |
126 | ||
127 | .vector_allocation_domain = default_vector_allocation_domain, | |
128 | .init_apic_ldr = default_init_apic_ldr, | |
129 | ||
130 | .ioapic_phys_id_map = default_ioapic_phys_id_map, | |
681ee44d | 131 | .setup_apic_routing = setup_apic_flat_routing, |
7b387253 IM |
132 | .multi_timer_check = NULL, |
133 | .apicid_to_node = default_apicid_to_node, | |
134 | .cpu_to_logical_apicid = default_cpu_to_logical_apicid, | |
135 | .cpu_present_to_apicid = default_cpu_present_to_apicid, | |
7abc0753 | 136 | .apicid_to_cpu_present = physid_set_mask_of_physid, |
7b387253 IM |
137 | .setup_portio_remap = NULL, |
138 | .check_phys_apicid_present = default_check_phys_apicid_present, | |
139 | .enable_apic_mode = NULL, | |
140 | .phys_pkg_id = default_phys_pkg_id, | |
141 | .mps_oem_check = NULL, | |
142 | ||
143 | .get_apic_id = default_get_apic_id, | |
144 | .set_apic_id = NULL, | |
145 | .apic_id_mask = 0x0F << 24, | |
146 | ||
147 | .cpu_mask_to_apicid = default_cpu_mask_to_apicid, | |
148 | .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and, | |
149 | ||
43f39890 YL |
150 | .send_IPI_mask = default_send_IPI_mask_logical, |
151 | .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical, | |
7b387253 IM |
152 | .send_IPI_allbutself = default_send_IPI_allbutself, |
153 | .send_IPI_all = default_send_IPI_all, | |
6b64ee02 | 154 | .send_IPI_self = default_send_IPI_self, |
7b387253 | 155 | |
7b387253 IM |
156 | .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW, |
157 | .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH, | |
158 | ||
159 | .wait_for_init_deassert = default_wait_for_init_deassert, | |
160 | ||
161 | .smp_callin_clear_local_apic = NULL, | |
7b387253 | 162 | .inquire_remote_apic = default_inquire_remote_apic, |
c1eeb2de YL |
163 | |
164 | .read = native_apic_mem_read, | |
165 | .write = native_apic_mem_write, | |
166 | .icr_read = native_apic_icr_read, | |
167 | .icr_write = native_apic_icr_write, | |
168 | .wait_icr_idle = native_apic_wait_icr_idle, | |
169 | .safe_wait_icr_idle = native_safe_apic_wait_icr_idle, | |
7b387253 IM |
170 | }; |
171 | ||
be163a15 IM |
172 | extern struct apic apic_numaq; |
173 | extern struct apic apic_summit; | |
174 | extern struct apic apic_bigsmp; | |
175 | extern struct apic apic_es7000; | |
2b6163bf | 176 | extern struct apic apic_es7000_cluster; |
1da177e4 | 177 | |
be163a15 | 178 | struct apic *apic = &apic_default; |
7d01d32d | 179 | EXPORT_SYMBOL_GPL(apic); |
1da177e4 | 180 | |
be163a15 | 181 | static struct apic *apic_probe[] __initdata = { |
d49c4288 YL |
182 | #ifdef CONFIG_X86_NUMAQ |
183 | &apic_numaq, | |
184 | #endif | |
185 | #ifdef CONFIG_X86_SUMMIT | |
1da177e4 | 186 | &apic_summit, |
d49c4288 YL |
187 | #endif |
188 | #ifdef CONFIG_X86_BIGSMP | |
9b0c5028 | 189 | &apic_bigsmp, |
d49c4288 YL |
190 | #endif |
191 | #ifdef CONFIG_X86_ES7000 | |
1da177e4 | 192 | &apic_es7000, |
2b6163bf | 193 | &apic_es7000_cluster, |
d49c4288 | 194 | #endif |
1da177e4 LT |
195 | &apic_default, /* must be last */ |
196 | NULL, | |
197 | }; | |
198 | ||
1a3f239d RR |
199 | static int cmdline_apic __initdata; |
200 | static int __init parse_apic(char *arg) | |
201 | { | |
202 | int i; | |
203 | ||
204 | if (!arg) | |
205 | return -EINVAL; | |
206 | ||
207 | for (i = 0; apic_probe[i]; i++) { | |
208 | if (!strcmp(apic_probe[i]->name, arg)) { | |
c8d46cf0 | 209 | apic = apic_probe[i]; |
1a3f239d RR |
210 | cmdline_apic = 1; |
211 | return 0; | |
212 | } | |
213 | } | |
9a8cb626 AK |
214 | |
215 | /* Parsed again by __setup for debug/verbose */ | |
216 | return 0; | |
1a3f239d RR |
217 | } |
218 | early_param("apic", parse_apic); | |
911a62d4 VP |
219 | |
220 | void __init generic_bigsmp_probe(void) | |
221 | { | |
b20d70b7 | 222 | #ifdef CONFIG_X86_BIGSMP |
911a62d4 VP |
223 | /* |
224 | * This routine is used to switch to bigsmp mode when | |
225 | * - There is no apic= option specified by the user | |
27b46d76 | 226 | * - generic_apic_probe() has chosen apic_default as the sub_arch |
911a62d4 VP |
227 | * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support |
228 | */ | |
229 | ||
c8d46cf0 | 230 | if (!cmdline_apic && apic == &apic_default) { |
911a62d4 | 231 | if (apic_bigsmp.probe()) { |
c8d46cf0 | 232 | apic = &apic_bigsmp; |
911a62d4 | 233 | printk(KERN_INFO "Overriding APIC driver with %s\n", |
c8d46cf0 | 234 | apic->name); |
911a62d4 | 235 | } |
87f76065 | 236 | } |
d49c4288 | 237 | #endif |
911a62d4 VP |
238 | } |
239 | ||
1a3f239d | 240 | void __init generic_apic_probe(void) |
9b0c5028 | 241 | { |
1a3f239d RR |
242 | if (!cmdline_apic) { |
243 | int i; | |
244 | for (i = 0; apic_probe[i]; i++) { | |
245 | if (apic_probe[i]->probe()) { | |
c8d46cf0 | 246 | apic = apic_probe[i]; |
1a3f239d | 247 | break; |
1da177e4 LT |
248 | } |
249 | } | |
1a3f239d RR |
250 | /* Not visible without early console */ |
251 | if (!apic_probe[i]) | |
252 | panic("Didn't find an APIC driver"); | |
1da177e4 | 253 | } |
c8d46cf0 | 254 | printk(KERN_INFO "Using APIC driver %s\n", apic->name); |
9b0c5028 | 255 | } |
1da177e4 LT |
256 | |
257 | /* These functions can switch the APIC even after the initial ->probe() */ | |
258 | ||
9c764247 IM |
259 | int __init |
260 | generic_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid) | |
9b0c5028 | 261 | { |
1da177e4 | 262 | int i; |
5f836405 | 263 | |
9b0c5028 | 264 | for (i = 0; apic_probe[i]; ++i) { |
5f836405 IM |
265 | if (!apic_probe[i]->mps_oem_check) |
266 | continue; | |
267 | if (!apic_probe[i]->mps_oem_check(mpc, oem, productid)) | |
268 | continue; | |
269 | ||
270 | if (!cmdline_apic) { | |
271 | apic = apic_probe[i]; | |
5f836405 IM |
272 | printk(KERN_INFO "Switched to APIC driver `%s'.\n", |
273 | apic->name); | |
9b0c5028 | 274 | } |
5f836405 | 275 | return 1; |
9b0c5028 | 276 | } |
1da177e4 | 277 | return 0; |
9b0c5028 | 278 | } |
1da177e4 | 279 | |
306db03b | 280 | int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id) |
1da177e4 LT |
281 | { |
282 | int i; | |
306db03b | 283 | |
9b0c5028 | 284 | for (i = 0; apic_probe[i]; ++i) { |
306db03b IM |
285 | if (!apic_probe[i]->acpi_madt_oem_check) |
286 | continue; | |
287 | if (!apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id)) | |
288 | continue; | |
289 | ||
290 | if (!cmdline_apic) { | |
291 | apic = apic_probe[i]; | |
306db03b IM |
292 | printk(KERN_INFO "Switched to APIC driver `%s'.\n", |
293 | apic->name); | |
9b0c5028 | 294 | } |
306db03b | 295 | return 1; |
9b0c5028 PC |
296 | } |
297 | return 0; | |
1da177e4 | 298 | } |