blob: f7ba21cb3e25649a775229171a226d82a9aa3849 [file] [log] [blame]
Suresh Siddha2d9579a2008-07-10 11:16:59 -07001#include <linux/threads.h>
2#include <linux/cpumask.h>
3#include <linux/string.h>
4#include <linux/kernel.h>
5#include <linux/ctype.h>
6#include <linux/init.h>
Yinghai Lu1b9b89e2008-07-21 22:08:21 -07007#include <linux/dmar.h>
8
Suresh Siddha2d9579a2008-07-10 11:16:59 -07009#include <asm/smp.h>
Cyrill Gorcunov79deb8e2011-05-19 16:45:50 -070010#include <asm/x2apic.h>
Suresh Siddha2d9579a2008-07-10 11:16:59 -070011
Suresh Siddhaef1f87a2009-02-21 14:23:21 -080012int x2apic_phys;
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070013
14static int set_x2apic_phys_mode(char *arg)
15{
16 x2apic_phys = 1;
17 return 0;
18}
19early_param("x2apic_phys", set_x2apic_phys_mode);
20
Marcin Slusarz3cfba082008-10-12 11:46:23 +020021static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070022{
Suresh Siddhaef1f87a2009-02-21 14:23:21 -080023 if (x2apic_phys)
24 return x2apic_enabled();
25 else
26 return 0;
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070027}
Suresh Siddha2d9579a2008-07-10 11:16:59 -070028
Ingo Molnardac5f412009-01-28 15:42:24 +010029static void
Suresh Siddhaa27d0b52011-05-19 16:45:47 -070030__x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
Mike Travise7986732008-12-16 17:33:52 -080031{
Ingo Molnardac5f412009-01-28 15:42:24 +010032 unsigned long query_cpu;
Suresh Siddhaa27d0b52011-05-19 16:45:47 -070033 unsigned long this_cpu;
Ingo Molnardac5f412009-01-28 15:42:24 +010034 unsigned long flags;
Mike Travise7986732008-12-16 17:33:52 -080035
Suresh Siddhace4e2402009-03-17 10:16:54 -080036 x2apic_wrmsr_fence();
37
Mike Travise7986732008-12-16 17:33:52 -080038 local_irq_save(flags);
Suresh Siddhaa27d0b52011-05-19 16:45:47 -070039
40 this_cpu = smp_processor_id();
Mike Travisbcda0162008-12-16 17:33:59 -080041 for_each_cpu(query_cpu, mask) {
Suresh Siddhaa27d0b52011-05-19 16:45:47 -070042 if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
Ingo Molnardac5f412009-01-28 15:42:24 +010043 continue;
44 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
45 vector, APIC_DEST_PHYSICAL);
46 }
Mike Travise7986732008-12-16 17:33:52 -080047 local_irq_restore(flags);
Suresh Siddha2d9579a2008-07-10 11:16:59 -070048}
49
Suresh Siddhaa27d0b52011-05-19 16:45:47 -070050static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
51{
52 __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
53}
54
55static void
56 x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
57{
58 __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
59}
60
61static void x2apic_send_IPI_allbutself(int vector)
62{
63 __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT);
64}
65
Suresh Siddha2d9579a2008-07-10 11:16:59 -070066static void x2apic_send_IPI_all(int vector)
67{
Suresh Siddhaa27d0b52011-05-19 16:45:47 -070068 __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC);
Suresh Siddha2d9579a2008-07-10 11:16:59 -070069}
70
Mike Travisbcda0162008-12-16 17:33:59 -080071static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070072{
Suresh Siddha2d9579a2008-07-10 11:16:59 -070073 /*
74 * We're using fixed IRQ delivery, can only return one phys APIC ID.
75 * May as well be the first.
76 */
Ingo Molnardebccb32009-01-28 15:20:18 +010077 int cpu = cpumask_first(cpumask);
78
Mike Travise7986732008-12-16 17:33:52 -080079 if ((unsigned)cpu < nr_cpu_ids)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070080 return per_cpu(x86_cpu_to_apicid, cpu);
81 else
82 return BAD_APICID;
83}
84
Ingo Molnardebccb32009-01-28 15:20:18 +010085static unsigned int
86x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
87 const struct cpumask *andmask)
Mike Travis95d313c2008-12-16 17:33:54 -080088{
89 int cpu;
90
91 /*
92 * We're using fixed IRQ delivery, can only return one phys APIC ID.
93 * May as well be the first.
94 */
Ingo Molnardebccb32009-01-28 15:20:18 +010095 for_each_cpu_and(cpu, cpumask, andmask) {
Mike Travisa775a382008-12-17 15:21:39 -080096 if (cpumask_test_cpu(cpu, cpu_online_mask))
97 break;
Ingo Molnardebccb32009-01-28 15:20:18 +010098 }
99
Suresh Siddha18374d82009-12-17 18:29:46 -0800100 return per_cpu(x86_cpu_to_apicid, cpu);
Mike Travis95d313c2008-12-16 17:33:54 -0800101}
102
Jaswinder Singh Rajput4d08d972008-12-29 22:11:40 +0530103static void init_x2apic_ldr(void)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700104{
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700105}
106
Suresh Siddha9ebd6802011-05-19 16:45:46 -0700107static int x2apic_phys_probe(void)
108{
109 if (x2apic_mode && x2apic_phys)
110 return 1;
111
112 return apic == &apic_x2apic_phys;
113}
114
Ingo Molnarbe163a12009-02-17 16:28:46 +0100115struct apic apic_x2apic_phys = {
Ingo Molnar05c155c2009-01-28 02:37:01 +0100116
117 .name = "physical x2apic",
Suresh Siddha9ebd6802011-05-19 16:45:46 -0700118 .probe = x2apic_phys_probe,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100119 .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
120 .apic_id_registered = x2apic_apic_id_registered,
121
Ingo Molnarf8987a12009-01-28 04:02:31 +0100122 .irq_delivery_mode = dest_Fixed,
Ingo Molnar0b06e732009-01-28 05:13:04 +0100123 .irq_dest_mode = 0, /* physical */
Ingo Molnar05c155c2009-01-28 02:37:01 +0100124
125 .target_cpus = x2apic_target_cpus,
Ingo Molnar08125d32009-01-28 05:08:44 +0100126 .disable_esr = 0,
Ingo Molnarbdb1a9b2009-01-28 05:29:25 +0100127 .dest_logical = 0,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100128 .check_apicid_used = NULL,
129 .check_apicid_present = NULL,
130
Ingo Molnar05c155c2009-01-28 02:37:01 +0100131 .vector_allocation_domain = x2apic_vector_allocation_domain,
132 .init_apic_ldr = init_x2apic_ldr,
133
134 .ioapic_phys_id_map = NULL,
135 .setup_apic_routing = NULL,
136 .multi_timer_check = NULL,
Ingo Molnara21769a42009-01-28 06:50:47 +0100137 .cpu_present_to_apicid = default_cpu_present_to_apicid,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100138 .apicid_to_cpu_present = NULL,
139 .setup_portio_remap = NULL,
Ingo Molnara27a6212009-01-28 12:43:18 +0100140 .check_phys_apicid_present = default_check_phys_apicid_present,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100141 .enable_apic_mode = NULL,
Ingo Molnard4c9a9f2009-01-28 13:31:22 +0100142 .phys_pkg_id = x2apic_phys_pkg_id,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100143 .mps_oem_check = NULL,
144
Cyrill Gorcunov79deb8e2011-05-19 16:45:50 -0700145 .get_apic_id = x2apic_get_apic_id,
146 .set_apic_id = x2apic_set_apic_id,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100147 .apic_id_mask = 0xFFFFFFFFu,
148
149 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
150 .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and,
151
152 .send_IPI_mask = x2apic_send_IPI_mask,
153 .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
154 .send_IPI_allbutself = x2apic_send_IPI_allbutself,
155 .send_IPI_all = x2apic_send_IPI_all,
156 .send_IPI_self = x2apic_send_IPI_self,
157
Ingo Molnarabfa5842009-01-28 16:15:16 +0100158 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
159 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100160 .wait_for_init_deassert = NULL,
161 .smp_callin_clear_local_apic = NULL,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100162 .inquire_remote_apic = NULL,
Yinghai Luc1eeb2d2009-02-16 23:02:14 -0800163
164 .read = native_apic_msr_read,
165 .write = native_apic_msr_write,
166 .icr_read = native_x2apic_icr_read,
167 .icr_write = native_x2apic_icr_write,
168 .wait_icr_idle = native_x2apic_wait_icr_idle,
169 .safe_wait_icr_idle = native_safe_x2apic_wait_icr_idle,
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700170};
Suresh Siddha107e0e02011-05-20 17:51:17 -0700171
172apic_driver(apic_x2apic_phys);