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 __init 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 cpumask_t x2apic_target_cpus(void)
34 return cpumask_of_cpu(0);
37 static cpumask_t x2apic_vector_allocation_domain(int cpu)
39 cpumask_t domain = CPU_MASK_NONE;
44 static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
49 cfg = __prepare_ICR(0, vector, dest);
54 x2apic_icr_write(cfg, apicid);
57 static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
60 unsigned long query_cpu;
62 local_irq_save(flags);
63 for_each_cpu_mask(query_cpu, mask) {
64 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
65 vector, APIC_DEST_PHYSICAL);
67 local_irq_restore(flags);
70 static void x2apic_send_IPI_allbutself(int vector)
72 cpumask_t mask = cpu_online_map;
74 cpu_clear(smp_processor_id(), mask);
76 if (!cpus_empty(mask))
77 x2apic_send_IPI_mask(mask, vector);
80 static void x2apic_send_IPI_all(int vector)
82 x2apic_send_IPI_mask(cpu_online_map, vector);
85 static int x2apic_apic_id_registered(void)
90 static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
95 * We're using fixed IRQ delivery, can only return one phys APIC ID.
96 * May as well be the first.
98 cpu = first_cpu(cpumask);
99 if ((unsigned)cpu < NR_CPUS)
100 return per_cpu(x86_cpu_to_apicid, cpu);
105 static unsigned int get_apic_id(unsigned long x)
113 static unsigned long set_apic_id(unsigned int id)
121 static unsigned int x2apic_read_id(void)
123 return apic_read(APIC_ID);
126 static unsigned int phys_pkg_id(int index_msb)
128 return x2apic_read_id() >> index_msb;
131 void x2apic_send_IPI_self(int vector)
133 apic_write(APIC_SELF_IPI, vector);
136 void init_x2apic_ldr(void)
141 struct genapic apic_x2apic_phys = {
142 .name = "physical x2apic",
143 .acpi_madt_oem_check = x2apic_acpi_madt_oem_check,
144 .int_delivery_mode = dest_Fixed,
145 .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
146 .target_cpus = x2apic_target_cpus,
147 .vector_allocation_domain = x2apic_vector_allocation_domain,
148 .apic_id_registered = x2apic_apic_id_registered,
149 .init_apic_ldr = init_x2apic_ldr,
150 .send_IPI_all = x2apic_send_IPI_all,
151 .send_IPI_allbutself = x2apic_send_IPI_allbutself,
152 .send_IPI_mask = x2apic_send_IPI_mask,
153 .send_IPI_self = x2apic_send_IPI_self,
154 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
155 .phys_pkg_id = phys_pkg_id,
156 .get_apic_id = get_apic_id,
157 .set_apic_id = set_apic_id,
158 .apic_id_mask = (0xFFFFFFFFu),