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