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