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