blob: c5ae751b994a317c32f086d59c2cf33f120b402e [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>
18
19extern struct genapic apic_summit;
20extern struct genapic apic_bigsmp;
21extern struct genapic apic_es7000;
22extern struct genapic apic_default;
23
24struct genapic *genapic = &apic_default;
25
Adrian Bunk96d553582007-10-17 18:04:36 +020026static struct genapic *apic_probe[] __initdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 &apic_summit,
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010028 &apic_bigsmp,
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 &apic_es7000,
30 &apic_default, /* must be last */
31 NULL,
32};
33
Rusty Russell1a3f2392006-09-26 10:52:32 +020034static int cmdline_apic __initdata;
35static int __init parse_apic(char *arg)
36{
37 int i;
38
39 if (!arg)
40 return -EINVAL;
41
42 for (i = 0; apic_probe[i]; i++) {
43 if (!strcmp(apic_probe[i]->name, arg)) {
44 genapic = apic_probe[i];
45 cmdline_apic = 1;
46 return 0;
47 }
48 }
Andi Kleen9a8cb622006-12-07 02:14:11 +010049
50 /* Parsed again by __setup for debug/verbose */
51 return 0;
Rusty Russell1a3f2392006-09-26 10:52:32 +020052}
53early_param("apic", parse_apic);
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070054
55void __init generic_bigsmp_probe(void)
56{
57 /*
58 * This routine is used to switch to bigsmp mode when
59 * - There is no apic= option specified by the user
Simon Arlott27b46d72007-10-20 01:13:56 +020060 * - generic_apic_probe() has chosen apic_default as the sub_arch
Venkatesh Pallipadi911a62d2005-09-03 15:56:31 -070061 * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support
62 */
63
64 if (!cmdline_apic && genapic == &apic_default)
65 if (apic_bigsmp.probe()) {
66 genapic = &apic_bigsmp;
67 printk(KERN_INFO "Overriding APIC driver with %s\n",
68 genapic->name);
69 }
70}
71
Rusty Russell1a3f2392006-09-26 10:52:32 +020072void __init generic_apic_probe(void)
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010073{
Rusty Russell1a3f2392006-09-26 10:52:32 +020074 if (!cmdline_apic) {
75 int i;
76 for (i = 0; apic_probe[i]; i++) {
77 if (apic_probe[i]->probe()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 genapic = apic_probe[i];
Rusty Russell1a3f2392006-09-26 10:52:32 +020079 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
81 }
Rusty Russell1a3f2392006-09-26 10:52:32 +020082 /* Not visible without early console */
83 if (!apic_probe[i])
84 panic("Didn't find an APIC driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 printk(KERN_INFO "Using APIC driver %s\n", genapic->name);
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010087}
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89/* These functions can switch the APIC even after the initial ->probe() */
90
91int __init mps_oem_check(struct mp_config_table *mpc, char *oem, char *productid)
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010092{
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 int i;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +010094 for (i = 0; apic_probe[i]; ++i) {
95 if (apic_probe[i]->mps_oem_check(mpc, oem, productid)) {
Jan Beulich2ba567c2006-05-30 22:47:51 +020096 if (!cmdline_apic) {
97 genapic = apic_probe[i];
98 printk(KERN_INFO "Switched to APIC driver `%s'.\n",
99 genapic->name);
100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return 1;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100102 }
103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return 0;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100105}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
108{
109 int i;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100110 for (i = 0; apic_probe[i]; ++i) {
111 if (apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id)) {
Jan Beulich2ba567c2006-05-30 22:47:51 +0200112 if (!cmdline_apic) {
113 genapic = apic_probe[i];
114 printk(KERN_INFO "Switched to APIC driver `%s'.\n",
115 genapic->name);
116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return 1;
Paolo Ciarrocchi9b0c5022008-02-19 23:57:17 +0100118 }
119 }
120 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
123int hard_smp_processor_id(void)
124{
125 return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
126}