blob: 2f3c6ca19de9951aec562216ce53a7022a6b8beb [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>
7#include <asm/smp.h>
8#include <asm/ipi.h>
9#include <asm/genapic.h>
10
11
12/* Start with all IRQs pointing to boot CPU. IRQ balancing will shift them. */
13
14static cpumask_t x2apic_target_cpus(void)
15{
16 return cpumask_of_cpu(0);
17}
18
19static cpumask_t x2apic_vector_allocation_domain(int cpu)
20{
21 cpumask_t domain = CPU_MASK_NONE;
22 cpu_set(cpu, domain);
23 return domain;
24}
25
26static void __x2apic_send_IPI_dest(unsigned int apicid, int vector,
27 unsigned int dest)
28{
29 unsigned long cfg;
30
31 cfg = __prepare_ICR(0, vector, dest);
32
33 /*
34 * send the IPI.
35 */
36 x2apic_icr_write(cfg, apicid);
37}
38
39static void x2apic_send_IPI_mask(cpumask_t mask, int vector)
40{
41 unsigned long flags;
42 unsigned long query_cpu;
43
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);
48 }
49 local_irq_restore(flags);
50}
51
52static void x2apic_send_IPI_allbutself(int vector)
53{
54 cpumask_t mask = cpu_online_map;
55
56 cpu_clear(smp_processor_id(), mask);
57
58 if (!cpus_empty(mask))
59 x2apic_send_IPI_mask(mask, vector);
60}
61
62static void x2apic_send_IPI_all(int vector)
63{
64 x2apic_send_IPI_mask(cpu_online_map, vector);
65}
66
67static int x2apic_apic_id_registered(void)
68{
69 return 1;
70}
71
72static unsigned int x2apic_cpu_mask_to_apicid(cpumask_t cpumask)
73{
74 int cpu;
75
76 /*
77 * We're using fixed IRQ delivery, can only return one phys APIC ID.
78 * May as well be the first.
79 */
80 cpu = first_cpu(cpumask);
81 if ((unsigned)cpu < NR_CPUS)
82 return per_cpu(x86_cpu_to_apicid, cpu);
83 else
84 return BAD_APICID;
85}
86
Yinghai Luf910a9d2008-07-12 01:01:20 -070087static unsigned int get_apic_id(unsigned long x)
88{
89 unsigned int id;
90
91 id = x;
92 return id;
93}
94
95static unsigned long set_apic_id(unsigned int id)
96{
97 unsigned long x;
98
99 x = id;
100 return x;
101}
102
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700103static unsigned int x2apic_read_id(void)
104{
105 return apic_read(APIC_ID);
106}
107
108static unsigned int phys_pkg_id(int index_msb)
109{
110 return x2apic_read_id() >> index_msb;
111}
112
113void x2apic_send_IPI_self(int vector)
114{
115 apic_write(APIC_SELF_IPI, vector);
116}
117
118void init_x2apic_ldr(void)
119{
120 return;
121}
122
123struct 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,
Yinghai Luf910a9d2008-07-12 01:01:20 -0700137 .get_apic_id = get_apic_id,
138 .set_apic_id = set_apic_id,
139 .apic_id_mask = (0xFFFFFFFFu),
Suresh Siddha2d9579a2008-07-10 11:16:59 -0700140};