blob: 5cbae8aa0408886a874bfa5e7263e720abb7b1e2 [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>
10#include <asm/ipi.h>
11#include <asm/genapic.h>
12
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070013static int x2apic_phys;
14
15static int set_x2apic_phys_mode(char *arg)
16{
17 x2apic_phys = 1;
18 return 0;
19}
20early_param("x2apic_phys", set_x2apic_phys_mode);
21
Marcin Slusarz3cfba082008-10-12 11:46:23 +020022static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070023{
Yinghai Lud25ae382008-07-25 19:39:03 -070024 if (cpu_has_x2apic && x2apic_phys)
Yinghai Lu1b9b89e2008-07-21 22:08:21 -070025 return 1;
26
27 return 0;
28}
Suresh Siddha2d9579a2008-07-10 11:16:59 -070029
30/* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
31
Mike Travisbcda0162008-12-16 17:33:59 -080032static const struct cpumask *x2apic_target_cpus(void)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070033{
Mike Travisbcda0162008-12-16 17:33:59 -080034 return cpumask_of(0);
Suresh Siddha2d9579a2008-07-10 11:16:59 -070035}
36
Mike Travisbcda0162008-12-16 17:33:59 -080037static void x2apic_vector_allocation_domain(int cpu, struct cpumask *retmask)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070038{
Mike Travisbcda0162008-12-16 17:33:59 -080039 cpumask_clear(retmask);
40 cpumask_set_cpu(cpu, retmask);
Suresh Siddha2d9579a2008-07-10 11:16:59 -070041}
42
43static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
44 unsigned int dest)
45{
46 unsigned long cfg;
47
48 cfg = __prepare_ICR(0, vector, dest);
49
50 /*
51 * send the IPI.
52 */
53 x2apic_icr_write(cfg, apicid);
54}
55
Mike Travisbcda0162008-12-16 17:33:59 -080056static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070057{
Suresh Siddha2d9579a2008-07-10 11:16:59 -070058 unsigned long query_cpu;
Ingo Molnardac5f412009-01-28 15:42:24 +010059 unsigned long flags;
Suresh Siddha2d9579a2008-07-10 11:16:59 -070060
61 local_irq_save(flags);
Mike Travisbcda0162008-12-16 17:33:59 -080062 for_each_cpu(query_cpu, mask) {
Suresh Siddha2d9579a2008-07-10 11:16:59 -070063 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
64 vector, APIC_DEST_PHYSICAL);
65 }
66 local_irq_restore(flags);
67}
68
Ingo Molnardac5f412009-01-28 15:42:24 +010069static void
70 x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
Mike Travise7986732008-12-16 17:33:52 -080071{
Mike Travise7986732008-12-16 17:33:52 -080072 unsigned long this_cpu = smp_processor_id();
Ingo Molnardac5f412009-01-28 15:42:24 +010073 unsigned long query_cpu;
74 unsigned long flags;
Mike Travise7986732008-12-16 17:33:52 -080075
76 local_irq_save(flags);
Mike Travisbcda0162008-12-16 17:33:59 -080077 for_each_cpu(query_cpu, mask) {
Mike Travise7986732008-12-16 17:33:52 -080078 if (query_cpu != this_cpu)
79 __x2apic_send_IPI_dest(
80 per_cpu(x86_cpu_to_apicid, query_cpu),
81 vector, APIC_DEST_PHYSICAL);
82 }
83 local_irq_restore(flags);
84}
85
Suresh Siddha2d9579a2008-07-10 11:16:59 -070086static void x2apic_send_IPI_allbutself(int vector)
87{
Mike Travise7986732008-12-16 17:33:52 -080088 unsigned long this_cpu = smp_processor_id();
Ingo Molnardac5f412009-01-28 15:42:24 +010089 unsigned long query_cpu;
90 unsigned long flags;
Suresh Siddha2d9579a2008-07-10 11:16:59 -070091
Mike Travise7986732008-12-16 17:33:52 -080092 local_irq_save(flags);
Ingo Molnardac5f412009-01-28 15:42:24 +010093 for_each_online_cpu(query_cpu) {
94 if (query_cpu == this_cpu)
95 continue;
96 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
97 vector, APIC_DEST_PHYSICAL);
98 }
Mike Travise7986732008-12-16 17:33:52 -080099 local_irq_restore(flags);
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700100}
101
102static void x2apic_send_IPI_all(int vector)
103{
Mike Travisbcda0162008-12-16 17:33:59 -0800104 x2apic_send_IPI_mask(cpu_online_mask, vector);
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700105}
106
107static int x2apic_apic_id_registered(void)
108{
109 return 1;
110}
111
Mike Travisbcda0162008-12-16 17:33:59 -0800112static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700113{
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700114 /*
115 * We're using fixed IRQ delivery, can only return one phys APIC ID.
116 * May as well be the first.
117 */
Ingo Molnardebccb32009-01-28 15:20:18 +0100118 int cpu = cpumask_first(cpumask);
119
Mike Travise7986732008-12-16 17:33:52 -0800120 if ((unsigned)cpu < nr_cpu_ids)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700121 return per_cpu(x86_cpu_to_apicid, cpu);
122 else
123 return BAD_APICID;
124}
125
Ingo Molnardebccb32009-01-28 15:20:18 +0100126static unsigned int
127x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
128 const struct cpumask *andmask)
Mike Travis95d313c2008-12-16 17:33:54 -0800129{
130 int cpu;
131
132 /*
133 * We're using fixed IRQ delivery, can only return one phys APIC ID.
134 * May as well be the first.
135 */
Ingo Molnardebccb32009-01-28 15:20:18 +0100136 for_each_cpu_and(cpu, cpumask, andmask) {
Mike Travisa775a382008-12-17 15:21:39 -0800137 if (cpumask_test_cpu(cpu, cpu_online_mask))
138 break;
Ingo Molnardebccb32009-01-28 15:20:18 +0100139 }
140
Mike Travis6eeb7c52008-12-16 17:33:55 -0800141 if (cpu < nr_cpu_ids)
142 return per_cpu(x86_cpu_to_apicid, cpu);
Ingo Molnardebccb32009-01-28 15:20:18 +0100143
Mike Travis95d313c2008-12-16 17:33:54 -0800144 return BAD_APICID;
145}
146
Ingo Molnarca6c8ed2009-01-28 14:08:38 +0100147static unsigned int x2apic_phys_get_apic_id(unsigned long x)
Yinghai Luf910a9d2008-07-12 01:01:20 -0700148{
Ingo Molnardac5f412009-01-28 15:42:24 +0100149 return x;
Yinghai Luf910a9d2008-07-12 01:01:20 -0700150}
151
152static unsigned long set_apic_id(unsigned int id)
153{
Ingo Molnardac5f412009-01-28 15:42:24 +0100154 return id;
Yinghai Luf910a9d2008-07-12 01:01:20 -0700155}
156
Ingo Molnard4c9a9f2009-01-28 13:31:22 +0100157static int x2apic_phys_pkg_id(int initial_apicid, int index_msb)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700158{
Suresh Siddhae17941b2008-08-23 17:47:11 +0200159 return current_cpu_data.initial_apicid >> index_msb;
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700160}
161
Jaswinder Singh Rajput4d08d972008-12-29 22:11:40 +0530162static void x2apic_send_IPI_self(int vector)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700163{
164 apic_write(APIC_SELF_IPI, vector);
165}
166
Jaswinder Singh Rajput4d08d972008-12-29 22:11:40 +0530167static void init_x2apic_ldr(void)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700168{
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700169}
170
171struct genapic apic_x2apic_phys = {
Ingo Molnar05c155c2009-01-28 02:37:01 +0100172
173 .name = "physical x2apic",
174 .probe = NULL,
175 .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
176 .apic_id_registered = x2apic_apic_id_registered,
177
Ingo Molnarf8987a12009-01-28 04:02:31 +0100178 .irq_delivery_mode = dest_Fixed,
Ingo Molnar0b06e732009-01-28 05:13:04 +0100179 .irq_dest_mode = 0, /* physical */
Ingo Molnar05c155c2009-01-28 02:37:01 +0100180
181 .target_cpus = x2apic_target_cpus,
Ingo Molnar08125d32009-01-28 05:08:44 +0100182 .disable_esr = 0,
Ingo Molnarbdb1a9b2009-01-28 05:29:25 +0100183 .dest_logical = 0,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100184 .check_apicid_used = NULL,
185 .check_apicid_present = NULL,
186
Ingo Molnar05c155c2009-01-28 02:37:01 +0100187 .vector_allocation_domain = x2apic_vector_allocation_domain,
188 .init_apic_ldr = init_x2apic_ldr,
189
190 .ioapic_phys_id_map = NULL,
191 .setup_apic_routing = NULL,
192 .multi_timer_check = NULL,
193 .apicid_to_node = NULL,
194 .cpu_to_logical_apicid = NULL,
Ingo Molnara21769a42009-01-28 06:50:47 +0100195 .cpu_present_to_apicid = default_cpu_present_to_apicid,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100196 .apicid_to_cpu_present = NULL,
197 .setup_portio_remap = NULL,
Ingo Molnara27a6212009-01-28 12:43:18 +0100198 .check_phys_apicid_present = default_check_phys_apicid_present,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100199 .enable_apic_mode = NULL,
Ingo Molnard4c9a9f2009-01-28 13:31:22 +0100200 .phys_pkg_id = x2apic_phys_pkg_id,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100201 .mps_oem_check = NULL,
202
Ingo Molnarca6c8ed2009-01-28 14:08:38 +0100203 .get_apic_id = x2apic_phys_get_apic_id,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100204 .set_apic_id = set_apic_id,
205 .apic_id_mask = 0xFFFFFFFFu,
206
207 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
208 .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and,
209
210 .send_IPI_mask = x2apic_send_IPI_mask,
211 .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
212 .send_IPI_allbutself = x2apic_send_IPI_allbutself,
213 .send_IPI_all = x2apic_send_IPI_all,
214 .send_IPI_self = x2apic_send_IPI_self,
215
216 .wakeup_cpu = NULL,
Ingo Molnarabfa5842009-01-28 16:15:16 +0100217 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
218 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100219 .wait_for_init_deassert = NULL,
220 .smp_callin_clear_local_apic = NULL,
221 .store_NMI_vector = NULL,
Ingo Molnar05c155c2009-01-28 02:37:01 +0100222 .inquire_remote_apic = NULL,
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700223};