Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 James Cleverdon, IBM. |
| 3 | * Subject to the GNU Public License, v.2 |
| 4 | * |
| 5 | * Generic APIC sub-arch probe layer. |
| 6 | * |
| 7 | * Hacked for x86-64 by James Cleverdon from i386 architecture code by |
| 8 | * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and |
| 9 | * James Cleverdon. |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/threads.h> |
| 12 | #include <linux/cpumask.h> |
| 13 | #include <linux/string.h> |
Ingo Molnar | 07c7c47 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 14 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/ctype.h> |
| 17 | #include <linux/init.h> |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 18 | #include <linux/hardirq.h> |
Yinghai Lu | d25ae38 | 2008-07-25 19:39:03 -0700 | [diff] [blame] | 19 | #include <linux/dmar.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/smp.h> |
Ingo Molnar | 7b6aa33 | 2009-02-17 13:58:15 +0100 | [diff] [blame] | 22 | #include <asm/apic.h> |
Yinghai Lu | c1eeb2d | 2009-02-16 23:02:14 -0800 | [diff] [blame] | 23 | #include <asm/ipi.h> |
Yinghai Lu | 54ac14a | 2008-11-17 15:19:53 -0800 | [diff] [blame] | 24 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Ingo Molnar | be163a1 | 2009-02-17 16:28:46 +0100 | [diff] [blame] | 26 | extern struct apic apic_flat; |
| 27 | extern struct apic apic_physflat; |
| 28 | extern struct apic apic_x2xpic_uv_x; |
| 29 | extern struct apic apic_x2apic_phys; |
| 30 | extern struct apic apic_x2apic_cluster; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Ingo Molnar | be163a1 | 2009-02-17 16:28:46 +0100 | [diff] [blame] | 32 | struct apic __read_mostly *apic = &apic_flat; |
Ingo Molnar | 7d01d32 | 2009-02-17 12:33:20 +0100 | [diff] [blame] | 33 | EXPORT_SYMBOL_GPL(apic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Ingo Molnar | be163a1 | 2009-02-17 16:28:46 +0100 | [diff] [blame] | 35 | static struct apic *apic_probe[] __initdata = { |
Nick Piggin | 03b4863 | 2009-01-20 04:36:04 +0100 | [diff] [blame] | 36 | #ifdef CONFIG_X86_UV |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 37 | &apic_x2apic_uv_x, |
Nick Piggin | 03b4863 | 2009-01-20 04:36:04 +0100 | [diff] [blame] | 38 | #endif |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_X86_X2APIC |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 40 | &apic_x2apic_phys, |
| 41 | &apic_x2apic_cluster, |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 42 | #endif |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 43 | &apic_physflat, |
| 44 | NULL, |
| 45 | }; |
Jack Steiner | ae26186 | 2008-03-28 14:12:06 -0500 | [diff] [blame] | 46 | |
Yinghai Lu | 295594e | 2009-08-25 13:44:44 -0700 | [diff] [blame] | 47 | static int apicid_phys_pkg_id(int initial_apic_id, int index_msb) |
| 48 | { |
| 49 | return hard_smp_processor_id() >> index_msb; |
| 50 | } |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode. |
| 54 | */ |
Ingo Molnar | 72ce016 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 55 | void __init default_setup_apic_routing(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 57 | #ifdef CONFIG_X86_X2APIC |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 58 | if (x2apic_mode |
Suresh Siddha | ef1f87a | 2009-02-21 14:23:21 -0800 | [diff] [blame] | 59 | #ifdef CONFIG_X86_UV |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 60 | && apic != &apic_x2apic_uv_x |
Suresh Siddha | ef1f87a | 2009-02-21 14:23:21 -0800 | [diff] [blame] | 61 | #endif |
Gleb Natapov | ce69a78 | 2009-07-20 15:24:17 +0300 | [diff] [blame] | 62 | ) { |
Suresh Siddha | ef1f87a | 2009-02-21 14:23:21 -0800 | [diff] [blame] | 63 | if (x2apic_phys) |
| 64 | apic = &apic_x2apic_phys; |
| 65 | else |
| 66 | apic = &apic_x2apic_cluster; |
| 67 | printk(KERN_INFO "Setting APIC routing to %s\n", apic->name); |
Yinghai Lu | d25ae38 | 2008-07-25 19:39:03 -0700 | [diff] [blame] | 68 | } |
Yinghai Lu | 06cd9a7 | 2009-02-16 17:29:58 -0800 | [diff] [blame] | 69 | #endif |
Yinghai Lu | d25ae38 | 2008-07-25 19:39:03 -0700 | [diff] [blame] | 70 | |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 71 | if (apic == &apic_flat) { |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 72 | if (max_physical_apicid >= 8) |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 73 | apic = &apic_physflat; |
| 74 | printk(KERN_INFO "Setting APIC routing to %s\n", apic->name); |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 75 | } |
Suresh Siddha | 9d783ba | 2009-03-16 17:04:55 -0700 | [diff] [blame] | 76 | |
Yinghai Lu | 295594e | 2009-08-25 13:44:44 -0700 | [diff] [blame] | 77 | if (is_vsmp_box()) { |
| 78 | /* need to update phys_pkg_id */ |
| 79 | apic->phys_pkg_id = apicid_phys_pkg_id; |
| 80 | } |
| 81 | |
Suresh Siddha | 9d783ba | 2009-03-16 17:04:55 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Now that apic routing model is selected, configure the |
| 84 | * fault handling for intr remapping. |
| 85 | */ |
| 86 | if (intr_remapping_enabled) |
| 87 | enable_drhd_fault_handling(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Ingo Molnar | 07c7c47 | 2007-05-02 19:27:04 +0200 | [diff] [blame] | 90 | /* Same for both flat and physical. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Suresh Siddha | cff73a6 | 2008-07-10 11:16:53 -0700 | [diff] [blame] | 92 | void apic_send_IPI_self(int vector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Ingo Molnar | dac5f41 | 2009-01-28 15:42:24 +0100 | [diff] [blame] | 94 | __default_send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
Jack Steiner | ae26186 | 2008-03-28 14:12:06 -0500 | [diff] [blame] | 96 | |
Ingo Molnar | 306db03 | 2009-01-28 03:43:47 +0100 | [diff] [blame] | 97 | int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id) |
Jack Steiner | ae26186 | 2008-03-28 14:12:06 -0500 | [diff] [blame] | 98 | { |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 99 | int i; |
| 100 | |
| 101 | for (i = 0; apic_probe[i]; ++i) { |
| 102 | if (apic_probe[i]->acpi_madt_oem_check(oem_id, oem_table_id)) { |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 103 | apic = apic_probe[i]; |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 104 | printk(KERN_INFO "Setting APIC routing to %s.\n", |
Ingo Molnar | c8d46cf | 2009-01-28 00:14:11 +0100 | [diff] [blame] | 105 | apic->name); |
Yinghai Lu | 1b9b89e | 2008-07-21 22:08:21 -0700 | [diff] [blame] | 106 | return 1; |
| 107 | } |
Jack Steiner | ae26186 | 2008-03-28 14:12:06 -0500 | [diff] [blame] | 108 | } |
| 109 | return 0; |
| 110 | } |