1 #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>
7 #include <linux/dmar.h>
11 #include <asm/genapic.h>
13 static int x2apic_phys;
15 static int set_x2apic_phys_mode(char *arg)
20 early_param("x2apic_phys", set_x2apic_phys_mode);
22 static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
24 if (cpu_has_x2apic && x2apic_phys)
30 /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
32 static const cpumask_t *x2apic_target_cpus(void)
34 return &cpumask_of_cpu(0);
37 static void x2apic_vector_allocation_domain(int cpu, cpumask_t *retmask)
40 cpu_set(cpu, *retmask);
43 static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
48 cfg = __prepare_ICR(0, vector, dest);
53 x2apic_icr_write(cfg, apicid);
56 static void x2apic_send_IPI_mask(const cpumask_t *mask, int vector)
59 unsigned long query_cpu;
61 local_irq_save(flags);
62 for_each_cpu_mask_nr(query_cpu, *mask) {
63 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
64 vector, APIC_DEST_PHYSICAL);
66 local_irq_restore(flags);
69 static void x2apic_send_IPI_mask_allbutself(const cpumask_t *mask, int vector)
72 unsigned long query_cpu;
73 unsigned long this_cpu = smp_processor_id();
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);
82 local_irq_restore(flags);
85 static void x2apic_send_IPI_allbutself(int vector)
88 unsigned long query_cpu;
89 unsigned long this_cpu = smp_processor_id();
91 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);
100 static void x2apic_send_IPI_all(int vector)
102 x2apic_send_IPI_mask(&cpu_online_map, vector);
105 static int x2apic_apic_id_registered(void)
110 static unsigned int x2apic_cpu_mask_to_apicid(const cpumask_t *cpumask)
115 * We're using fixed IRQ delivery, can only return one phys APIC ID.
116 * May as well be the first.
118 cpu = first_cpu(*cpumask);
119 if ((unsigned)cpu < nr_cpu_ids)
120 return per_cpu(x86_cpu_to_apicid, cpu);
125 static unsigned int x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
126 const struct cpumask *andmask)
131 * We're using fixed IRQ delivery, can only return one phys APIC ID.
132 * May as well be the first.
134 cpu = cpumask_any_and(cpumask, andmask);
135 if (cpu < nr_cpu_ids)
136 return per_cpu(x86_cpu_to_apicid, cpu);
140 static unsigned int get_apic_id(unsigned long x)
148 static unsigned long set_apic_id(unsigned int id)
156 static unsigned int phys_pkg_id(int index_msb)
158 return current_cpu_data.initial_apicid >> index_msb;
161 void x2apic_send_IPI_self(int vector)
163 apic_write(APIC_SELF_IPI, vector);
166 void init_x2apic_ldr(void)
171 struct genapic apic_x2apic_phys = {
172 .name = "physical x2apic",
173 .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
174 .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,
183 .send_IPI_mask_allbutself = x2apic_send_IPI_mask_allbutself,
184 .send_IPI_self = x2apic_send_IPI_self,
185 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
186 .cpu_mask_to_apicid_and = x2apic_cpu_mask_to_apicid_and,
187 .phys_pkg_id = phys_pkg_id,
188 .get_apic_id = get_apic_id,
189 .set_apic_id = set_apic_id,
190 .apic_id_mask = (0xFFFFFFFFu),