blob: c346d9d0226f313129917b091e4a4e94bcde6105 [file] [log] [blame]
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +01001/*
2 * Copyright 2003 Andi Kleen, SuSE Labs.
3 * Subject to the GNU Public License, v.2
4 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Generic x86 APIC driver probe layer.
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +01006 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/threads.h>
8#include <linux/cpumask.h>
9#include <linux/string.h>
10#include <linux/kernel.h>
11#include <linux/ctype.h>
12#include <linux/init.h>
Rusty Russell1a3f2392006-09-26 10:52:32 +020013#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/fixmap.h>
15#include <asm/mpspec.h>
16#include <asm/apicdef.h>
17#include <asm/genapic.h>
Yinghai Lu54ac14a2008-11-17 15:19:53 -080018#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Yinghai Lud49c4282008-06-08 18:31:54 -070020extern struct genapic apic_numaq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021extern struct genapic apic_summit;
22extern struct genapic apic_bigsmp;
23extern struct genapic apic_es7000;
24extern struct genapic apic_default;
25
26struct genapic *genapic = &apic_default;
27
Adrian Bunk96d553582007-10-17 18:04:36 +020028static struct genapic *apic_probe[] __initdata = {
Yinghai Lud49c4282008-06-08 18:31:54 -070029#ifdef CONFIG_X86_NUMAQ
30 &apic_numaq,
31#endif
32#ifdef CONFIG_X86_SUMMIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 &apic_summit,
Yinghai Lud49c4282008-06-08 18:31:54 -070034#endif
35#ifdef CONFIG_X86_BIGSMP
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010036 &apic_bigsmp,
Yinghai Lud49c4282008-06-08 18:31:54 -070037#endif
38#ifdef CONFIG_X86_ES7000
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 &apic_es7000,
Yinghai Lud49c4282008-06-08 18:31:54 -070040#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 &apic_default, /* must be last */
42 NULL,
43};
44
Rusty Russell1a3f2392006-09-26 10:52:32 +020045static int cmdline_apic __initdata;
46static int __init parse_apic(char *arg)
47{
48 int i;
49
50 if (!arg)
51 return -EINVAL;
52
53 for (i = 0; apic_probe[i]; i++) {
54 if (!strcmp(apic_probe[i]->name, arg)) {
55 genapic = apic_probe[i];
56 cmdline_apic = 1;
57 return 0;
58 }
59 }
Andi Kleen9a8cb622006-12-07 02:14:11 +010060
Yinghai Lu54ac14a2008-11-17 15:19:53 -080061 if (x86_quirks->update_genapic)
62 x86_quirks->update_genapic();
63
Andi Kleen9a8cb622006-12-07 02:14:11 +010064 /* Parsed again by __setup for debug/verbose */
65 return 0;
Rusty Russell1a3f2392006-09-26 10:52:32 +020066}
67early_param("apic", parse_apic);
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070068
69void __init generic_bigsmp_probe(void)
70{
Yinghai Lub20d70b2008-06-09 17:00:15 -070071#ifdef CONFIG_X86_BIGSMP
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070072 /*
73 * This routine is used to switch to bigsmp mode when
74 * - There is no apic= option specified by the user
Simon Arlott27b46d72007-10-20 01:13:56 +020075 * - generic_apic_probe() has chosen apic_default as the sub_arch
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070076 * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
77 */
78
Yinghai Lu87f76062008-11-19 20:50:53 -080079 if (!cmdline_apic && genapic == &apic_default) {
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070080 if (apic_bigsmp.probe()) {
81 genapic = &apic_bigsmp;
Yinghai Lu87f76062008-11-19 20:50:53 -080082 if (x86_quirks->update_genapic)
83 x86_quirks->update_genapic();
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070084 printk(KERN_INFO "Overriding APIC driver with %s\n",
85 genapic->name);
86 }
Yinghai Lu87f76062008-11-19 20:50:53 -080087 }
Yinghai Lud49c4282008-06-08 18:31:54 -070088#endif
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070089}
90
Rusty Russell1a3f2392006-09-26 10:52:32 +020091void __init generic_apic_probe(void)
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010092{
Rusty Russell1a3f2392006-09-26 10:52:32 +020093 if (!cmdline_apic) {
94 int i;
95 for (i = 0; apic_probe[i]; i++) {
96 if (apic_probe[i]->probe()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 genapic = apic_probe[i];
Rusty Russell1a3f2392006-09-26 10:52:32 +020098 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
100 }
Rusty Russell1a3f2392006-09-26 10:52:32 +0200101 /* Not visible without early console */
102 if (!apic_probe[i])
103 panic("Didn't find an APIC driver");
Yinghai Lu87f76062008-11-19 20:50:53 -0800104
105 if (x86_quirks->update_genapic)
106 x86_quirks->update_genapic();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 printk(KERN_INFO "Using APIC driver %s\n", genapic->name);
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100109}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/* These functions can switch the APIC even after the initial ->probe() */
112
Yinghai Lud49c4282008-06-08 18:31:54 -0700113int __init mps_oem_check(struct mp_config_table *mpc, char *oem,
114 char *productid)
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100115{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 int i;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100117 for (i = 0; apic_probe[i]; ++i) {
118 if (apic_probe[i]->mps_oem_check(mpc, oem, productid)) {
Jan Beulich2ba567c2006-05-30 22:47:51 +0200119 if (!cmdline_apic) {
120 genapic = apic_probe[i];
Yinghai Lu87f76062008-11-19 20:50:53 -0800121 if (x86_quirks->update_genapic)
122 x86_quirks->update_genapic();
Jan Beulich2ba567c2006-05-30 22:47:51 +0200123 printk(KERN_INFO "Switched to APIC driver `%s'.\n",
124 genapic->name);
125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return 1;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100127 }
128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100130}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
133{
134 int i;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100135 for (i = 0; apic_probe[i]; ++i) {
136 if (apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id)) {
Jan Beulich2ba567c2006-05-30 22:47:51 +0200137 if (!cmdline_apic) {
138 genapic = apic_probe[i];
Yinghai Lu87f76062008-11-19 20:50:53 -0800139 if (x86_quirks->update_genapic)
140 x86_quirks->update_genapic();
Jan Beulich2ba567c2006-05-30 22:47:51 +0200141 printk(KERN_INFO "Switched to APIC driver `%s'.\n",
142 genapic->name);
143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return 1;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100145 }
146 }
147 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
150int hard_smp_processor_id(void)
151{
152 return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
153}