blob: 65edc180fc8297be82347bec05e3cd62d155a86d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/threads.h>
12#include <linux/cpumask.h>
13#include <linux/string.h>
Ingo Molnar07c7c472007-05-02 19:27:04 +020014#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/kernel.h>
16#include <linux/ctype.h>
17#include <linux/init.h>
Jack Steinerac23d4e2008-03-28 14:12:16 -050018#include <linux/hardirq.h>
Yinghai Lud25ae382008-07-25 19:39:03 -070019#include <linux/dmar.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/smp.h>
Ingo Molnar7b6aa332009-02-17 13:58:15 +010022#include <asm/apic.h>
Yinghai Luc1eeb2d2009-02-16 23:02:14 -080023#include <asm/ipi.h>
Yinghai Lu54ac14a2008-11-17 15:19:53 -080024#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Ingo Molnarbe163a12009-02-17 16:28:46 +010026extern struct apic apic_flat;
27extern struct apic apic_physflat;
28extern struct apic apic_x2xpic_uv_x;
29extern struct apic apic_x2apic_phys;
30extern struct apic apic_x2apic_cluster;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ingo Molnarbe163a12009-02-17 16:28:46 +010032struct apic __read_mostly *apic = &apic_flat;
Ingo Molnar7d01d322009-02-17 12:33:20 +010033EXPORT_SYMBOL_GPL(apic);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Ingo Molnarbe163a12009-02-17 16:28:46 +010035static struct apic *apic_probe[] __initdata = {
Nick Piggin03b48632009-01-20 04:36:04 +010036#ifdef CONFIG_X86_UV
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070037 &apic_x2apic_uv_x,
Nick Piggin03b48632009-01-20 04:36:04 +010038#endif
Yinghai Lu06cd9a72009-02-16 17:29:58 -080039#ifdef CONFIG_X86_X2APIC
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070040 &apic_x2apic_phys,
41 &apic_x2apic_cluster,
Yinghai Lu06cd9a72009-02-16 17:29:58 -080042#endif
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070043 &apic_physflat,
44 NULL,
45};
Jack Steinerae261862008-03-28 14:12:06 -050046
Yinghai Lu295594e2009-08-25 13:44:44 -070047static int apicid_phys_pkg_id(int initial_apic_id, int index_msb)
48{
49 return hard_smp_processor_id() >> index_msb;
50}
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/*
53 * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
54 */
Ingo Molnar72ce0162009-01-28 06:50:47 +010055void __init default_setup_apic_routing(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Yinghai Lu06cd9a72009-02-16 17:29:58 -080057#ifdef CONFIG_X86_X2APIC
Gleb Natapovce69a782009-07-20 15:24:17 +030058 if (x2apic_mode
Suresh Siddhaef1f87a2009-02-21 14:23:21 -080059#ifdef CONFIG_X86_UV
Gleb Natapovce69a782009-07-20 15:24:17 +030060 && apic != &apic_x2apic_uv_x
Suresh Siddhaef1f87a2009-02-21 14:23:21 -080061#endif
Gleb Natapovce69a782009-07-20 15:24:17 +030062 ) {
Suresh Siddhaef1f87a2009-02-21 14:23:21 -080063 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 Lud25ae382008-07-25 19:39:03 -070068 }
Yinghai Lu06cd9a72009-02-16 17:29:58 -080069#endif
Yinghai Lud25ae382008-07-25 19:39:03 -070070
Ingo Molnarc8d46cf2009-01-28 00:14:11 +010071 if (apic == &apic_flat) {
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070072 if (max_physical_apicid >= 8)
Ingo Molnarc8d46cf2009-01-28 00:14:11 +010073 apic = &apic_physflat;
74 printk(KERN_INFO "Setting APIC routing to %s\n", apic->name);
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070075 }
Suresh Siddha9d783ba2009-03-16 17:04:55 -070076
Yinghai Lu295594e2009-08-25 13:44:44 -070077 if (is_vsmp_box()) {
78 /* need to update phys_pkg_id */
79 apic->phys_pkg_id = apicid_phys_pkg_id;
80 }
81
Suresh Siddha9d783ba2009-03-16 17:04:55 -070082 /*
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 Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Ingo Molnar07c7c472007-05-02 19:27:04 +020090/* Same for both flat and physical. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Suresh Siddhacff73a62008-07-10 11:16:53 -070092void apic_send_IPI_self(int vector)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Ingo Molnardac5f412009-01-28 15:42:24 +010094 __default_send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
Jack Steinerae261862008-03-28 14:12:06 -050096
Ingo Molnar306db032009-01-28 03:43:47 +010097int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Jack Steinerae261862008-03-28 14:12:06 -050098{
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070099 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 Molnarc8d46cf2009-01-28 00:14:11 +0100103 apic = apic_probe[i];
Yinghai Lu1b9b89e2008-07-21 22:08:21 -0700104 printk(KERN_INFO "Setting APIC routing to %s.\n",
Ingo Molnarc8d46cf2009-01-28 00:14:11 +0100105 apic->name);
Yinghai Lu1b9b89e2008-07-21 22:08:21 -0700106 return 1;
107 }
Jack Steinerae261862008-03-28 14:12:06 -0500108 }
109 return 0;
110}