blob: f35a3bf3a9e56210878f13dfda18c7cfd81dc1cd [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 -070013DEFINE_PER_CPU(int, x2apic_extra_bits);
14
15static int x2apic_phys;
16
17static int set_x2apic_phys_mode(char *arg)
18{
19 x2apic_phys = 1;
20 return 0;
21}
22early_param("x2apic_phys", set_x2apic_phys_mode);
23
24static int __init x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
25{
26 if (cpu_has_x2apic && intr_remapping_enabled && x2apic_phys)
27 return 1;
28
29 return 0;
30}
Suresh Siddha2d9579a2008-07-10 11:16:59 -070031
32/* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
33
34static cpumask_t x2apic_target_cpus(void)
35{
36 return cpumask_of_cpu(0);
37}
38
39static cpumask_t x2apic_vector_allocation_domain(int cpu)
40{
41 cpumask_t domain = CPU_MASK_NONE;
42 cpu_set(cpu, domain);
43 return domain;
44}
45
46static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
47 unsigned int dest)
48{
49 unsigned long cfg;
50
51 cfg = __prepare_ICR(0, vector, dest);
52
53 /*
54 * send the IPI.
55 */
56 x2apic_icr_write(cfg, apicid);
57}
58
59static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
60{
61 unsigned long flags;
62 unsigned long query_cpu;
63
64 local_irq_save(flags);
65 for_each_cpu_mask(query_cpu, mask) {
66 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
67 vector, APIC_DEST_PHYSICAL);
68 }
69 local_irq_restore(flags);
70}
71
72static void x2apic_send_IPI_allbutself(int vector)
73{
74 cpumask_t mask = cpu_online_map;
75
76 cpu_clear(smp_processor_id(), mask);
77
78 if (!cpus_empty(mask))
79 x2apic_send_IPI_mask(mask, vector);
80}
81
82static void x2apic_send_IPI_all(int vector)
83{
84 x2apic_send_IPI_mask(cpu_online_map, vector);
85}
86
87static int x2apic_apic_id_registered(void)
88{
89 return 1;
90}
91
92static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
93{
94 int cpu;
95
96 /*
97 * We're using fixed IRQ delivery, can only return one phys APIC ID.
98 * May as well be the first.
99 */
100 cpu = first_cpu(cpumask);
101 if ((unsigned)cpu < NR_CPUS)
102 return per_cpu(x86_cpu_to_apicid, cpu);
103 else
104 return BAD_APICID;
105}
106
Yinghai Luf910a9d2008-07-12 01:01:20 -0700107static unsigned int get_apic_id(unsigned long x)
108{
109 unsigned int id;
110
111 id = x;
112 return id;
113}
114
115static unsigned long set_apic_id(unsigned int id)
116{
117 unsigned long x;
118
119 x = id;
120 return x;
121}
122
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700123static unsigned int x2apic_read_id(void)
124{
125 return apic_read(APIC_ID);
126}
127
128static unsigned int phys_pkg_id(int index_msb)
129{
130 return x2apic_read_id() >> index_msb;
131}
132
133void x2apic_send_IPI_self(int vector)
134{
135 apic_write(APIC_SELF_IPI, vector);
136}
137
138void init_x2apic_ldr(void)
139{
140 return;
141}
142
143struct genapic apic_x2apic_phys = {
144 .name = "physical x2apic",
Yinghai Lu1b9b89e2008-07-21 22:08:21 -0700145 .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700146 .int_delivery_mode = dest_Fixed,
147 .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
148 .target_cpus = x2apic_target_cpus,
149 .vector_allocation_domain = x2apic_vector_allocation_domain,
150 .apic_id_registered = x2apic_apic_id_registered,
151 .init_apic_ldr = init_x2apic_ldr,
152 .send_IPI_all = x2apic_send_IPI_all,
153 .send_IPI_allbutself = x2apic_send_IPI_allbutself,
154 .send_IPI_mask = x2apic_send_IPI_mask,
155 .send_IPI_self = x2apic_send_IPI_self,
156 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
157 .phys_pkg_id = phys_pkg_id,
Yinghai Luf910a9d2008-07-12 01:01:20 -0700158 .get_apic_id = get_apic_id,
159 .set_apic_id = set_apic_id,
160 .apic_id_mask = (0xFFFFFFFFu),
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700161};