x86, apic: Introduce .apicdrivers section to find the list of apic drivers
[linux-2.6-block.git] / arch / x86 / kernel / apic / x2apic_phys.c
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>
8
9 #include <asm/smp.h>
10 #include <asm/x2apic.h>
11
12 int x2apic_phys;
13
14 static int set_x2apic_phys_mode(char *arg)
15 {
16         x2apic_phys = 1;
17         return 0;
18 }
19 early_param("x2apic_phys", set_x2apic_phys_mode);
20
21 static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
22 {
23         if (x2apic_phys)
24                 return x2apic_enabled();
25         else
26                 return 0;
27 }
28
29 static void
30 __x2apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
31 {
32         unsigned long query_cpu;
33         unsigned long this_cpu;
34         unsigned long flags;
35
36         x2apic_wrmsr_fence();
37
38         local_irq_save(flags);
39
40         this_cpu = smp_processor_id();
41         for_each_cpu(query_cpu, mask) {
42                 if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
43                         continue;
44                 __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
45                                        vector, APIC_DEST_PHYSICAL);
46         }
47         local_irq_restore(flags);
48 }
49
50 static void x2apic_send_IPI_mask(const struct cpumask *mask, int vector)
51 {
52         __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
53 }
54
55 static void
56  x2apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
57 {
58         __x2apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
59 }
60
61 static void x2apic_send_IPI_allbutself(int vector)
62 {
63         __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT);
64 }
65
66 static void x2apic_send_IPI_all(int vector)
67 {
68         __x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC);
69 }
70
71 static unsigned int x2apic_cpu_mask_to_apicid(const struct cpumask *cpumask)
72 {
73         /*
74          * We're using fixed IRQ delivery, can only return one phys APIC ID.
75          * May as well be the first.
76          */
77         int cpu = cpumask_first(cpumask);
78
79         if ((unsigned)cpu < nr_cpu_ids)
80                 return per_cpu(x86_cpu_to_apicid, cpu);
81         else
82                 return BAD_APICID;
83 }
84
85 static unsigned int
86 x2apic_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
87                               const struct cpumask *andmask)
88 {
89         int cpu;
90
91         /*
92          * We're using fixed IRQ delivery, can only return one phys APIC ID.
93          * May as well be the first.
94          */
95         for_each_cpu_and(cpu, cpumask, andmask) {
96                 if (cpumask_test_cpu(cpu, cpu_online_mask))
97                         break;
98         }
99
100         return per_cpu(x86_cpu_to_apicid, cpu);
101 }
102
103 static void init_x2apic_ldr(void)
104 {
105 }
106
107 static int x2apic_phys_probe(void)
108 {
109         if (x2apic_mode && x2apic_phys)
110                 return 1;
111
112         return apic == &apic_x2apic_phys;
113 }
114
115 struct apic apic_x2apic_phys = {
116
117         .name                           = "physical x2apic",
118         .probe                          = x2apic_phys_probe,
119         .acpi_madt_oem_check            = x2apic_acpi_madt_oem_check,
120         .apic_id_registered             = x2apic_apic_id_registered,
121
122         .irq_delivery_mode              = dest_Fixed,
123         .irq_dest_mode                  = 0, /* physical */
124
125         .target_cpus                    = x2apic_target_cpus,
126         .disable_esr                    = 0,
127         .dest_logical                   = 0,
128         .check_apicid_used              = NULL,
129         .check_apicid_present           = NULL,
130
131         .vector_allocation_domain       = x2apic_vector_allocation_domain,
132         .init_apic_ldr                  = init_x2apic_ldr,
133
134         .ioapic_phys_id_map             = NULL,
135         .setup_apic_routing             = NULL,
136         .multi_timer_check              = NULL,
137         .cpu_present_to_apicid          = default_cpu_present_to_apicid,
138         .apicid_to_cpu_present          = NULL,
139         .setup_portio_remap             = NULL,
140         .check_phys_apicid_present      = default_check_phys_apicid_present,
141         .enable_apic_mode               = NULL,
142         .phys_pkg_id                    = x2apic_phys_pkg_id,
143         .mps_oem_check                  = NULL,
144
145         .get_apic_id                    = x2apic_get_apic_id,
146         .set_apic_id                    = x2apic_set_apic_id,
147         .apic_id_mask                   = 0xFFFFFFFFu,
148
149         .cpu_mask_to_apicid             = x2apic_cpu_mask_to_apicid,
150         .cpu_mask_to_apicid_and         = x2apic_cpu_mask_to_apicid_and,
151
152         .send_IPI_mask                  = x2apic_send_IPI_mask,
153         .send_IPI_mask_allbutself       = x2apic_send_IPI_mask_allbutself,
154         .send_IPI_allbutself            = x2apic_send_IPI_allbutself,
155         .send_IPI_all                   = x2apic_send_IPI_all,
156         .send_IPI_self                  = x2apic_send_IPI_self,
157
158         .trampoline_phys_low            = DEFAULT_TRAMPOLINE_PHYS_LOW,
159         .trampoline_phys_high           = DEFAULT_TRAMPOLINE_PHYS_HIGH,
160         .wait_for_init_deassert         = NULL,
161         .smp_callin_clear_local_apic    = NULL,
162         .inquire_remote_apic            = NULL,
163
164         .read                           = native_apic_msr_read,
165         .write                          = native_apic_msr_write,
166         .icr_read                       = native_x2apic_icr_read,
167         .icr_write                      = native_x2apic_icr_write,
168         .wait_icr_idle                  = native_x2apic_wait_icr_idle,
169         .safe_wait_icr_idle             = native_safe_x2apic_wait_icr_idle,
170 };
171
172 apic_driver(apic_x2apic_phys);