Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003 Andi Kleen, SuSE Labs. |
| 3 | * Subject to the GNU Public License, v.2 |
| 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Generic x86 APIC driver probe layer. |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #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 Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 13 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <asm/fixmap.h> |
| 15 | #include <asm/mpspec.h> |
| 16 | #include <asm/apicdef.h> |
| 17 | #include <asm/genapic.h> |
Yinghai Lu | 54ac14a | 2008-11-17 15:19:53 -0800 | [diff] [blame] | 18 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 20 | extern struct genapic apic_numaq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | extern struct genapic apic_summit; |
| 22 | extern struct genapic apic_bigsmp; |
| 23 | extern struct genapic apic_es7000; |
| 24 | extern struct genapic apic_default; |
| 25 | |
| 26 | struct genapic *genapic = &apic_default; |
| 27 | |
Adrian Bunk | 96d55358 | 2007-10-17 18:04:36 +0200 | [diff] [blame] | 28 | static struct genapic *apic_probe[] __initdata = { |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 29 | #ifdef CONFIG_X86_NUMAQ |
| 30 | &apic_numaq, |
| 31 | #endif |
| 32 | #ifdef CONFIG_X86_SUMMIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | &apic_summit, |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 34 | #endif |
| 35 | #ifdef CONFIG_X86_BIGSMP |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 36 | &apic_bigsmp, |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 37 | #endif |
| 38 | #ifdef CONFIG_X86_ES7000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | &apic_es7000, |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 40 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | &apic_default, /* must be last */ |
| 42 | NULL, |
| 43 | }; |
| 44 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 45 | static int cmdline_apic __initdata; |
| 46 | static 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 Kleen | 9a8cb62 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 60 | |
Yinghai Lu | 54ac14a | 2008-11-17 15:19:53 -0800 | [diff] [blame] | 61 | if (x86_quirks->update_genapic) |
| 62 | x86_quirks->update_genapic(); |
| 63 | |
Andi Kleen | 9a8cb62 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 64 | /* Parsed again by __setup for debug/verbose */ |
| 65 | return 0; |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 66 | } |
| 67 | early_param("apic", parse_apic); |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 68 | |
| 69 | void __init generic_bigsmp_probe(void) |
| 70 | { |
Yinghai Lu | b20d70b | 2008-06-09 17:00:15 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_X86_BIGSMP |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 72 | /* |
| 73 | * This routine is used to switch to bigsmp mode when |
| 74 | * - There is no apic= option specified by the user |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 75 | * - generic_apic_probe() has chosen apic_default as the sub_arch |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 76 | * - we find more than 8 CPUs in acpi LAPIC listing with xAPIC support |
| 77 | */ |
| 78 | |
Yinghai Lu | 87f7606 | 2008-11-19 20:50:53 -0800 | [diff] [blame^] | 79 | if (!cmdline_apic && genapic == &apic_default) { |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 80 | if (apic_bigsmp.probe()) { |
| 81 | genapic = &apic_bigsmp; |
Yinghai Lu | 87f7606 | 2008-11-19 20:50:53 -0800 | [diff] [blame^] | 82 | if (x86_quirks->update_genapic) |
| 83 | x86_quirks->update_genapic(); |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 84 | printk(KERN_INFO "Overriding APIC driver with %s\n", |
| 85 | genapic->name); |
| 86 | } |
Yinghai Lu | 87f7606 | 2008-11-19 20:50:53 -0800 | [diff] [blame^] | 87 | } |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 88 | #endif |
Venkatesh Pallipadi | 911a62d | 2005-09-03 15:56:31 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 91 | void __init generic_apic_probe(void) |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 92 | { |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 93 | if (!cmdline_apic) { |
| 94 | int i; |
| 95 | for (i = 0; apic_probe[i]; i++) { |
| 96 | if (apic_probe[i]->probe()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | genapic = apic_probe[i]; |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 98 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 101 | /* Not visible without early console */ |
| 102 | if (!apic_probe[i]) |
| 103 | panic("Didn't find an APIC driver"); |
Yinghai Lu | 87f7606 | 2008-11-19 20:50:53 -0800 | [diff] [blame^] | 104 | |
| 105 | if (x86_quirks->update_genapic) |
| 106 | x86_quirks->update_genapic(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | printk(KERN_INFO "Using APIC driver %s\n", genapic->name); |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* These functions can switch the APIC even after the initial ->probe() */ |
| 112 | |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 113 | int __init mps_oem_check(struct mp_config_table *mpc, char *oem, |
| 114 | char *productid) |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 115 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | int i; |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 117 | for (i = 0; apic_probe[i]; ++i) { |
| 118 | if (apic_probe[i]->mps_oem_check(mpc, oem, productid)) { |
Jan Beulich | 2ba567c | 2006-05-30 22:47:51 +0200 | [diff] [blame] | 119 | if (!cmdline_apic) { |
| 120 | genapic = apic_probe[i]; |
Yinghai Lu | 87f7606 | 2008-11-19 20:50:53 -0800 | [diff] [blame^] | 121 | if (x86_quirks->update_genapic) |
| 122 | x86_quirks->update_genapic(); |
Jan Beulich | 2ba567c | 2006-05-30 22:47:51 +0200 | [diff] [blame] | 123 | printk(KERN_INFO "Switched to APIC driver `%s'.\n", |
| 124 | genapic->name); |
| 125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | return 1; |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 127 | } |
| 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return 0; |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id) |
| 133 | { |
| 134 | int i; |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 135 | for (i = 0; apic_probe[i]; ++i) { |
| 136 | if (apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id)) { |
Jan Beulich | 2ba567c | 2006-05-30 22:47:51 +0200 | [diff] [blame] | 137 | if (!cmdline_apic) { |
| 138 | genapic = apic_probe[i]; |
Yinghai Lu | 87f7606 | 2008-11-19 20:50:53 -0800 | [diff] [blame^] | 139 | if (x86_quirks->update_genapic) |
| 140 | x86_quirks->update_genapic(); |
Jan Beulich | 2ba567c | 2006-05-30 22:47:51 +0200 | [diff] [blame] | 141 | printk(KERN_INFO "Switched to APIC driver `%s'.\n", |
| 142 | genapic->name); |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return 1; |
Paolo Ciarrocchi | 9b0c502 | 2008-02-19 23:57:17 +0100 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | int hard_smp_processor_id(void) |
| 151 | { |
| 152 | return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID)); |
| 153 | } |