blob: 9d0386c7e798540fe49557f33fd61604d61a8a07 [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 Travise7986732008-12-16 17:33:52 -080032static const cpumask_t *x2apic_target_cpus(void)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070033{
Mike Travise7986732008-12-16 17:33:52 -080034 return &cpumask_of_cpu(0);
Suresh Siddha2d9579a2008-07-10 11:16:59 -070035}
36
Mike Travise7986732008-12-16 17:33:52 -080037static void x2apic_vector_allocation_domain(int cpu, cpumask_t *retmask)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070038{
Mike Travise7986732008-12-16 17:33:52 -080039 cpus_clear(*retmask);
40 cpu_set(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 Travise7986732008-12-16 17:33:52 -080056static void x2apic_send_IPI_mask(const cpumask_t *mask, int vector)
Suresh Siddha2d9579a2008-07-10 11:16:59 -070057{
58 unsigned long flags;
59 unsigned long query_cpu;
60
61 local_irq_save(flags);
Mike Travise7986732008-12-16 17:33:52 -080062 for_each_cpu_mask_nr(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
Mike Travise7986732008-12-16 17:33:52 -080069static void x2apic_send_IPI_mask_allbutself(const cpumask_t *mask, int vector)
70{
71 unsigned long flags;
72 unsigned long query_cpu;
73 unsigned long this_cpu = smp_processor_id();
74
75 local_irq_save(flags);
76 for_each_cpu_mask_nr(query_cpu, *mask) {
77 if (query_cpu != this_cpu)
78 __x2apic_send_IPI_dest(
79 per_cpu(x86_cpu_to_apicid, query_cpu),
80 vector, APIC_DEST_PHYSICAL);
81 }
82 local_irq_restore(flags);
83}
84
Suresh Siddha2d9579a2008-07-10 11:16:59 -070085static void x2apic_send_IPI_allbutself(int vector)
86{
Mike Travise7986732008-12-16 17:33:52 -080087 unsigned long flags;
88 unsigned long query_cpu;
89 unsigned long this_cpu = smp_processor_id();
Suresh Siddha2d9579a2008-07-10 11:16:59 -070090
Mike Travise7986732008-12-16 17:33:52 -080091 local_irq_save(flags);
92 for_each_online_cpu(query_cpu)
93 if (query_cpu != this_cpu)
94 __x2apic_send_IPI_dest(
95 per_cpu(x86_cpu_to_apicid, query_cpu),
96 vector, APIC_DEST_PHYSICAL);
97 local_irq_restore(flags);
Suresh Siddha2d9579a2008-07-10 11:16:59 -070098}
99
100static void x2apic_send_IPI_all(int vector)
101{
Mike Travise7986732008-12-16 17:33:52 -0800102 x2apic_send_IPI_mask(&cpu_online_map, vector);
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700103}
104
105static int x2apic_apic_id_registered(void)
106{
107 return 1;
108}
109
Mike Travise7986732008-12-16 17:33:52 -0800110static unsigned int x2apic_cpu_mask_to_apicid(const cpumask_t *cpumask)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700111{
112 int cpu;
113
114 /*
115 * We're using fixed IRQ delivery, can only return one phys APIC ID.
116 * May as well be the first.
117 */
Mike Travise7986732008-12-16 17:33:52 -0800118 cpu = first_cpu(*cpumask);
119 if ((unsigned)cpu < nr_cpu_ids)
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700120 return per_cpu(x86_cpu_to_apicid, cpu);
121 else
122 return BAD_APICID;
123}
124
Mike Travis6eeb7c52008-12-16 17:33:55 -0800125static unsigned int x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
126 const struct cpumask *andmask)
Mike Travis95d313c2008-12-16 17:33:54 -0800127{
128 int cpu;
129
130 /*
131 * We're using fixed IRQ delivery, can only return one phys APIC ID.
132 * May as well be the first.
133 */
Mike Travis6eeb7c52008-12-16 17:33:55 -0800134 cpu = cpumask_any_and(cpumask, andmask);
135 if (cpu < nr_cpu_ids)
136 return per_cpu(x86_cpu_to_apicid, cpu);
Mike Travis95d313c2008-12-16 17:33:54 -0800137 return BAD_APICID;
138}
139
Yinghai Luf910a9d2008-07-12 01:01:20 -0700140static unsigned int get_apic_id(unsigned long x)
141{
142 unsigned int id;
143
144 id = x;
145 return id;
146}
147
148static unsigned long set_apic_id(unsigned int id)
149{
150 unsigned long x;
151
152 x = id;
153 return x;
154}
155
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700156static unsigned int phys_pkg_id(int index_msb)
157{
Suresh Siddhae17941b2008-08-23 17:47:11 +0200158 return current_cpu_data.initial_apicid >> index_msb;
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700159}
160
161void x2apic_send_IPI_self(int vector)
162{
163 apic_write(APIC_SELF_IPI, vector);
164}
165
166void init_x2apic_ldr(void)
167{
168 return;
169}
170
171struct genapic apic_x2apic_phys = {
172 .name = "physical x2apic",
Yinghai Lu1b9b89e2008-07-21 22:08:21 -0700173 .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700174 .int_delivery_mode = dest_Fixed,
175 .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
176 .target_cpus = x2apic_target_cpus,
177 .vector_allocation_domain = x2apic_vector_allocation_domain,
178 .apic_id_registered = x2apic_apic_id_registered,
179 .init_apic_ldr = init_x2apic_ldr,
180 .send_IPI_all = x2apic_send_IPI_all,
181 .send_IPI_allbutself = x2apic_send_IPI_allbutself,
182 .send_IPI_mask = x2apic_send_IPI_mask,
Mike Travise7986732008-12-16 17:33:52 -0800183 .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700184 .send_IPI_self = x2apic_send_IPI_self,
185 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
Mike Travis95d313c2008-12-16 17:33:54 -0800186 .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and,
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700187 .phys_pkg_id = phys_pkg_id,
Yinghai Luf910a9d2008-07-12 01:01:20 -0700188 .get_apic_id = get_apic_id,
189 .set_apic_id = set_apic_id,
190 .apic_id_mask = (0xFFFFFFFFu),
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700191};