Merge branches 'x86/acpi', 'x86/asm', 'x86/cpudetect', 'x86/crashdump', 'x86/debug...
[safe/jmp/linux-2.6] / arch / x86 / kernel / bigsmp_32.c
1 /*
2  * APIC driver for "bigsmp" XAPIC machines with more than 8 virtual CPUs.
3  * Drives the local APIC in "clustered mode".
4  */
5 #define APIC_DEFINITION 1
6 #include <linux/threads.h>
7 #include <linux/cpumask.h>
8 #include <asm/mpspec.h>
9 #include <asm/genapic.h>
10 #include <asm/fixmap.h>
11 #include <asm/apicdef.h>
12 #include <asm/ipi.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/dmi.h>
16 #include <linux/smp.h>
17
18
19 static inline unsigned bigsmp_get_apic_id(unsigned long x)
20 {
21         return (x >> 24) & 0xFF;
22 }
23
24 #define xapic_phys_to_log_apicid(cpu) (per_cpu(x86_bios_cpu_apicid, cpu))
25
26 static inline int bigsmp_apic_id_registered(void)
27 {
28         return 1;
29 }
30
31 static inline const cpumask_t *bigsmp_target_cpus(void)
32 {
33 #ifdef CONFIG_SMP
34         return &cpu_online_map;
35 #else
36         return &cpumask_of_cpu(0);
37 #endif
38 }
39
40 #define APIC_DFR_VALUE          (APIC_DFR_FLAT)
41
42 static inline unsigned long
43 bigsmp_check_apicid_used(physid_mask_t bitmap, int apicid)
44 {
45         return 0;
46 }
47
48 static inline unsigned long bigsmp_check_apicid_present(int bit)
49 {
50         return 1;
51 }
52
53 static inline unsigned long calculate_ldr(int cpu)
54 {
55         unsigned long val, id;
56         val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
57         id = xapic_phys_to_log_apicid(cpu);
58         val |= SET_APIC_LOGICAL_ID(id);
59         return val;
60 }
61
62 /*
63  * Set up the logical destination ID.
64  *
65  * Intel recommends to set DFR, LDR and TPR before enabling
66  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
67  * document number 292116).  So here it goes...
68  */
69 static inline void bigsmp_init_apic_ldr(void)
70 {
71         unsigned long val;
72         int cpu = smp_processor_id();
73
74         apic_write(APIC_DFR, APIC_DFR_VALUE);
75         val = calculate_ldr(cpu);
76         apic_write(APIC_LDR, val);
77 }
78
79 static inline void bigsmp_setup_apic_routing(void)
80 {
81         printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
82                 "Physflat", nr_ioapics);
83 }
84
85 static inline int bigsmp_apicid_to_node(int logical_apicid)
86 {
87         return apicid_2_node[hard_smp_processor_id()];
88 }
89
90 static inline int bigsmp_cpu_present_to_apicid(int mps_cpu)
91 {
92         if (mps_cpu < nr_cpu_ids)
93                 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
94
95         return BAD_APICID;
96 }
97
98 static inline physid_mask_t bigsmp_apicid_to_cpu_present(int phys_apicid)
99 {
100         return physid_mask_of_physid(phys_apicid);
101 }
102
103 extern u8 cpu_2_logical_apicid[];
104 /* Mapping from cpu number to logical apicid */
105 static inline int bigsmp_cpu_to_logical_apicid(int cpu)
106 {
107         if (cpu >= nr_cpu_ids)
108                 return BAD_APICID;
109         return cpu_physical_id(cpu);
110 }
111
112 static inline physid_mask_t bigsmp_ioapic_phys_id_map(physid_mask_t phys_map)
113 {
114         /* For clustered we don't have a good way to do this yet - hack */
115         return physids_promote(0xFFL);
116 }
117
118 static inline void bigsmp_setup_portio_remap(void)
119 {
120 }
121
122 static inline int bigsmp_check_phys_apicid_present(int boot_cpu_physical_apicid)
123 {
124         return 1;
125 }
126
127 /* As we are using single CPU as destination, pick only one CPU here */
128 static inline unsigned int bigsmp_cpu_mask_to_apicid(const cpumask_t *cpumask)
129 {
130         return bigsmp_cpu_to_logical_apicid(first_cpu(*cpumask));
131 }
132
133 static inline unsigned int
134 bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
135                               const struct cpumask *andmask)
136 {
137         int cpu;
138
139         /*
140          * We're using fixed IRQ delivery, can only return one phys APIC ID.
141          * May as well be the first.
142          */
143         for_each_cpu_and(cpu, cpumask, andmask) {
144                 if (cpumask_test_cpu(cpu, cpu_online_mask))
145                         break;
146         }
147         if (cpu < nr_cpu_ids)
148                 return bigsmp_cpu_to_logical_apicid(cpu);
149
150         return BAD_APICID;
151 }
152
153 static inline int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
154 {
155         return cpuid_apic >> index_msb;
156 }
157
158 static inline void bigsmp_send_IPI_mask(const struct cpumask *mask, int vector)
159 {
160         default_send_IPI_mask_sequence_phys(mask, vector);
161 }
162
163 static inline void bigsmp_send_IPI_allbutself(int vector)
164 {
165         default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
166 }
167
168 static inline void bigsmp_send_IPI_all(int vector)
169 {
170         bigsmp_send_IPI_mask(cpu_online_mask, vector);
171 }
172
173 static int dmi_bigsmp; /* can be set by dmi scanners */
174
175 static int hp_ht_bigsmp(const struct dmi_system_id *d)
176 {
177         printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
178         dmi_bigsmp = 1;
179         return 0;
180 }
181
182
183 static const struct dmi_system_id bigsmp_dmi_table[] = {
184         { hp_ht_bigsmp, "HP ProLiant DL760 G2",
185         { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
186         DMI_MATCH(DMI_BIOS_VERSION, "P44-"),}
187         },
188
189         { hp_ht_bigsmp, "HP ProLiant DL740",
190         { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
191         DMI_MATCH(DMI_BIOS_VERSION, "P47-"),}
192         },
193          { }
194 };
195
196 static void bigsmp_vector_allocation_domain(int cpu, cpumask_t *retmask)
197 {
198         cpus_clear(*retmask);
199         cpu_set(cpu, *retmask);
200 }
201
202 static int probe_bigsmp(void)
203 {
204         if (def_to_bigsmp)
205                 dmi_bigsmp = 1;
206         else
207                 dmi_check_system(bigsmp_dmi_table);
208         return dmi_bigsmp;
209 }
210
211 struct genapic apic_bigsmp = {
212
213         .name                           = "bigsmp",
214         .probe                          = probe_bigsmp,
215         .acpi_madt_oem_check            = NULL,
216         .apic_id_registered             = bigsmp_apic_id_registered,
217
218         .irq_delivery_mode              = dest_Fixed,
219         /* phys delivery to target CPU: */
220         .irq_dest_mode                  = 0,
221
222         .target_cpus                    = bigsmp_target_cpus,
223         .disable_esr                    = 1,
224         .dest_logical                   = 0,
225         .check_apicid_used              = bigsmp_check_apicid_used,
226         .check_apicid_present           = bigsmp_check_apicid_present,
227
228         .vector_allocation_domain       = bigsmp_vector_allocation_domain,
229         .init_apic_ldr                  = bigsmp_init_apic_ldr,
230
231         .ioapic_phys_id_map             = bigsmp_ioapic_phys_id_map,
232         .setup_apic_routing             = bigsmp_setup_apic_routing,
233         .multi_timer_check              = NULL,
234         .apicid_to_node                 = bigsmp_apicid_to_node,
235         .cpu_to_logical_apicid          = bigsmp_cpu_to_logical_apicid,
236         .cpu_present_to_apicid          = bigsmp_cpu_present_to_apicid,
237         .apicid_to_cpu_present          = bigsmp_apicid_to_cpu_present,
238         .setup_portio_remap             = NULL,
239         .check_phys_apicid_present      = bigsmp_check_phys_apicid_present,
240         .enable_apic_mode               = NULL,
241         .phys_pkg_id                    = bigsmp_phys_pkg_id,
242         .mps_oem_check                  = NULL,
243
244         .get_apic_id                    = bigsmp_get_apic_id,
245         .set_apic_id                    = NULL,
246         .apic_id_mask                   = 0xFF << 24,
247
248         .cpu_mask_to_apicid             = bigsmp_cpu_mask_to_apicid,
249         .cpu_mask_to_apicid_and         = bigsmp_cpu_mask_to_apicid_and,
250
251         .send_IPI_mask                  = bigsmp_send_IPI_mask,
252         .send_IPI_mask_allbutself       = NULL,
253         .send_IPI_allbutself            = bigsmp_send_IPI_allbutself,
254         .send_IPI_all                   = bigsmp_send_IPI_all,
255         .send_IPI_self                  = default_send_IPI_self,
256
257         .wakeup_cpu                     = NULL,
258         .trampoline_phys_low            = DEFAULT_TRAMPOLINE_PHYS_LOW,
259         .trampoline_phys_high           = DEFAULT_TRAMPOLINE_PHYS_HIGH,
260
261         .wait_for_init_deassert         = default_wait_for_init_deassert,
262
263         .smp_callin_clear_local_apic    = NULL,
264         .store_NMI_vector               = NULL,
265         .inquire_remote_apic            = default_inquire_remote_apic,
266 };