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>
9 #include <asm/genapic.h>
12 /* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
14 static cpumask_t x2apic_target_cpus(void)
16 return cpumask_of_cpu(0);
19 static cpumask_t x2apic_vector_allocation_domain(int cpu)
21 cpumask_t domain = CPU_MASK_NONE;
26 static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
31 cfg = __prepare_ICR(0, vector, dest);
36 x2apic_icr_write(cfg, apicid);
39 static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
42 unsigned long query_cpu;
44 local_irq_save(flags);
45 for_each_cpu_mask(query_cpu, mask) {
46 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
47 vector, APIC_DEST_PHYSICAL);
49 local_irq_restore(flags);
52 static void x2apic_send_IPI_allbutself(int vector)
54 cpumask_t mask = cpu_online_map;
56 cpu_clear(smp_processor_id(), mask);
58 if (!cpus_empty(mask))
59 x2apic_send_IPI_mask(mask, vector);
62 static void x2apic_send_IPI_all(int vector)
64 x2apic_send_IPI_mask(cpu_online_map, vector);
67 static int x2apic_apic_id_registered(void)
72 static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
77 * We're using fixed IRQ delivery, can only return one phys APIC ID.
78 * May as well be the first.
80 cpu = first_cpu(cpumask);
81 if ((unsigned)cpu < NR_CPUS)
82 return per_cpu(x86_cpu_to_apicid, cpu);
87 static unsigned int get_apic_id(unsigned long x)
95 static unsigned long set_apic_id(unsigned int id)
103 static unsigned int x2apic_read_id(void)
105 return apic_read(APIC_ID);
108 static unsigned int phys_pkg_id(int index_msb)
110 return x2apic_read_id() >> index_msb;
113 void x2apic_send_IPI_self(int vector)
115 apic_write(APIC_SELF_IPI, vector);
118 void init_x2apic_ldr(void)
123 struct genapic apic_x2apic_phys = {
124 .name = "physical x2apic",
125 .int_delivery_mode = dest_Fixed,
126 .int_dest_mode = (APIC_DEST_PHYSICAL != 0),
127 .target_cpus = x2apic_target_cpus,
128 .vector_allocation_domain = x2apic_vector_allocation_domain,
129 .apic_id_registered = x2apic_apic_id_registered,
130 .init_apic_ldr = init_x2apic_ldr,
131 .send_IPI_all = x2apic_send_IPI_all,
132 .send_IPI_allbutself = x2apic_send_IPI_allbutself,
133 .send_IPI_mask = x2apic_send_IPI_mask,
134 .send_IPI_self = x2apic_send_IPI_self,
135 .cpu_mask_to_apicid = x2apic_cpu_mask_to_apicid,
136 .phys_pkg_id = phys_pkg_id,
137 .get_apic_id = get_apic_id,
138 .set_apic_id = set_apic_id,
139 .apic_id_mask = (0xFFFFFFFFu),