x86: Implement the default x86_32_early_logical_apicid()
[linux-2.6/btrfs-unstable.git] / arch / x86 / kernel / apic / probe_32.c
blob0f9a9ab49e79da07de16659294c90ae7143405d6
1 /*
2 * Default generic APIC driver. This handles up to 8 CPUs.
4 * Copyright 2003 Andi Kleen, SuSE Labs.
5 * Subject to the GNU Public License, v.2
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>
23 #include <linux/smp.h>
24 #include <asm/ipi.h>
26 #include <linux/interrupt.h>
27 #include <asm/acpi.h>
28 #include <asm/e820.h>
30 #ifdef CONFIG_HOTPLUG_CPU
31 #define DEFAULT_SEND_IPI (1)
32 #else
33 #define DEFAULT_SEND_IPI (0)
34 #endif
36 int no_broadcast = DEFAULT_SEND_IPI;
38 static __init int no_ipi_broadcast(char *str)
40 get_option(&str, &no_broadcast);
41 pr_info("Using %s mode\n",
42 no_broadcast ? "No IPI Broadcast" : "IPI Broadcast");
43 return 1;
45 __setup("no_ipi_broadcast=", no_ipi_broadcast);
47 static int __init print_ipi_mode(void)
49 pr_info("Using IPI %s mode\n",
50 no_broadcast ? "No-Shortcut" : "Shortcut");
51 return 0;
53 late_initcall(print_ipi_mode);
55 void __init default_setup_apic_routing(void)
57 int version = apic_version[boot_cpu_physical_apicid];
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;
66 /* If P4 and above fall through */
67 case X86_VENDOR_AMD:
68 def_to_bigsmp = 1;
72 #ifdef CONFIG_X86_BIGSMP
73 generic_bigsmp_probe();
74 #endif
76 if (apic->setup_apic_routing)
77 apic->setup_apic_routing();
80 static int default_x86_32_early_logical_apicid(int cpu)
82 return 1 << cpu;
85 static void setup_apic_flat_routing(void)
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
94 static void default_vector_allocation_domain(int cpu, struct cpumask *retmask)
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.
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.
105 cpumask_clear(retmask);
106 cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
109 /* should be called last. */
110 static int probe_default(void)
112 return 1;
115 struct apic apic_default = {
117 .name = "default",
118 .probe = probe_default,
119 .acpi_madt_oem_check = NULL,
120 .apic_id_registered = default_apic_id_registered,
122 .irq_delivery_mode = dest_LowestPrio,
123 /* logical delivery broadcast to all CPUs: */
124 .irq_dest_mode = 1,
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,
132 .vector_allocation_domain = default_vector_allocation_domain,
133 .init_apic_ldr = default_init_apic_ldr,
135 .ioapic_phys_id_map = default_ioapic_phys_id_map,
136 .setup_apic_routing = setup_apic_flat_routing,
137 .multi_timer_check = NULL,
138 .apicid_to_node = default_apicid_to_node,
139 .cpu_present_to_apicid = default_cpu_present_to_apicid,
140 .apicid_to_cpu_present = physid_set_mask_of_physid,
141 .setup_portio_remap = NULL,
142 .check_phys_apicid_present = default_check_phys_apicid_present,
143 .enable_apic_mode = NULL,
144 .phys_pkg_id = default_phys_pkg_id,
145 .mps_oem_check = NULL,
147 .get_apic_id = default_get_apic_id,
148 .set_apic_id = NULL,
149 .apic_id_mask = 0x0F << 24,
151 .cpu_mask_to_apicid = default_cpu_mask_to_apicid,
152 .cpu_mask_to_apicid_and = default_cpu_mask_to_apicid_and,
154 .send_IPI_mask = default_send_IPI_mask_logical,
155 .send_IPI_mask_allbutself = default_send_IPI_mask_allbutself_logical,
156 .send_IPI_allbutself = default_send_IPI_allbutself,
157 .send_IPI_all = default_send_IPI_all,
158 .send_IPI_self = default_send_IPI_self,
160 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
161 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
163 .wait_for_init_deassert = default_wait_for_init_deassert,
165 .smp_callin_clear_local_apic = NULL,
166 .inquire_remote_apic = default_inquire_remote_apic,
168 .read = native_apic_mem_read,
169 .write = native_apic_mem_write,
170 .icr_read = native_apic_icr_read,
171 .icr_write = native_apic_icr_write,
172 .wait_icr_idle = native_apic_wait_icr_idle,
173 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
175 .x86_32_early_logical_apicid = default_x86_32_early_logical_apicid,
178 extern struct apic apic_numaq;
179 extern struct apic apic_summit;
180 extern struct apic apic_bigsmp;
181 extern struct apic apic_es7000;
182 extern struct apic apic_es7000_cluster;
184 struct apic *apic = &apic_default;
185 EXPORT_SYMBOL_GPL(apic);
187 static struct apic *apic_probe[] __initdata = {
188 #ifdef CONFIG_X86_NUMAQ
189 &apic_numaq,
190 #endif
191 #ifdef CONFIG_X86_SUMMIT
192 &apic_summit,
193 #endif
194 #ifdef CONFIG_X86_BIGSMP
195 &apic_bigsmp,
196 #endif
197 #ifdef CONFIG_X86_ES7000
198 &apic_es7000,
199 &apic_es7000_cluster,
200 #endif
201 &apic_default, /* must be last */
202 NULL,
205 static int cmdline_apic __initdata;
206 static int __init parse_apic(char *arg)
208 int i;
210 if (!arg)
211 return -EINVAL;
213 for (i = 0; apic_probe[i]; i++) {
214 if (!strcmp(apic_probe[i]->name, arg)) {
215 apic = apic_probe[i];
216 cmdline_apic = 1;
217 return 0;
221 /* Parsed again by __setup for debug/verbose */
222 return 0;
224 early_param("apic", parse_apic);
226 void __init generic_bigsmp_probe(void)
228 #ifdef CONFIG_X86_BIGSMP
230 * This routine is used to switch to bigsmp mode when
231 * - There is no apic= option specified by the user
232 * - generic_apic_probe() has chosen apic_default as the sub_arch
233 * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
236 if (!cmdline_apic && apic == &apic_default) {
237 if (apic_bigsmp.probe()) {
238 apic = &apic_bigsmp;
239 printk(KERN_INFO "Overriding APIC driver with %s\n",
240 apic->name);
243 #endif
246 void __init generic_apic_probe(void)
248 if (!cmdline_apic) {
249 int i;
250 for (i = 0; apic_probe[i]; i++) {
251 if (apic_probe[i]->probe()) {
252 apic = apic_probe[i];
253 break;
256 /* Not visible without early console */
257 if (!apic_probe[i])
258 panic("Didn't find an APIC driver");
260 printk(KERN_INFO "Using APIC driver %s\n", apic->name);
263 /* These functions can switch the APIC even after the initial ->probe() */
265 int __init
266 generic_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid)
268 int i;
270 for (i = 0; apic_probe[i]; ++i) {
271 if (!apic_probe[i]->mps_oem_check)
272 continue;
273 if (!apic_probe[i]->mps_oem_check(mpc, oem, productid))
274 continue;
276 if (!cmdline_apic) {
277 apic = apic_probe[i];
278 printk(KERN_INFO "Switched to APIC driver `%s'.\n",
279 apic->name);
281 return 1;
283 return 0;
286 int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
288 int i;
290 for (i = 0; apic_probe[i]; ++i) {
291 if (!apic_probe[i]->acpi_madt_oem_check)
292 continue;
293 if (!apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id))
294 continue;
296 if (!cmdline_apic) {
297 apic = apic_probe[i];
298 printk(KERN_INFO "Switched to APIC driver `%s'.\n",
299 apic->name);
301 return 1;
303 return 0;