]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Written by: Garry Forsgren, Unisys Corporation | |
3 | * Natalie Protasevich, Unisys Corporation | |
7da18ed9 | 4 | * |
1da177e4 LT |
5 | * This file contains the code to configure and interface |
6 | * with Unisys ES7000 series hardware system manager. | |
7 | * | |
7da18ed9 IM |
8 | * Copyright (c) 2003 Unisys Corporation. |
9 | * Copyright (C) 2009, Red Hat, Inc., Ingo Molnar | |
10 | * | |
11 | * All Rights Reserved. | |
1da177e4 LT |
12 | * |
13 | * This program is free software; you can redistribute it and/or modify it | |
14 | * under the terms of version 2 of the GNU General Public License as | |
15 | * published by the Free Software Foundation. | |
16 | * | |
17 | * This program is distributed in the hope that it would be useful, but | |
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
22 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
23 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
24 | * | |
25 | * Contact information: Unisys Corporation, Township Line & Union Meeting | |
26 | * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or: | |
27 | * | |
28 | * http://www.unisys.com | |
29 | */ | |
2c4ce18c IM |
30 | #include <linux/notifier.h> |
31 | #include <linux/spinlock.h> | |
32 | #include <linux/cpumask.h> | |
33 | #include <linux/threads.h> | |
1da177e4 | 34 | #include <linux/kernel.h> |
2c4ce18c IM |
35 | #include <linux/module.h> |
36 | #include <linux/reboot.h> | |
1da177e4 | 37 | #include <linux/string.h> |
2c4ce18c | 38 | #include <linux/types.h> |
1da177e4 | 39 | #include <linux/errno.h> |
1da177e4 | 40 | #include <linux/acpi.h> |
2c4ce18c | 41 | #include <linux/init.h> |
7da18ed9 | 42 | #include <linux/nmi.h> |
2c4ce18c | 43 | #include <linux/smp.h> |
7da18ed9 | 44 | #include <linux/io.h> |
2c4ce18c | 45 | |
1da177e4 | 46 | #include <asm/apicdef.h> |
2c4ce18c IM |
47 | #include <asm/atomic.h> |
48 | #include <asm/fixmap.h> | |
49 | #include <asm/mpspec.h> | |
569712b2 | 50 | #include <asm/setup.h> |
2c4ce18c IM |
51 | #include <asm/apic.h> |
52 | #include <asm/ipi.h> | |
1da177e4 | 53 | |
1625324d YL |
54 | /* |
55 | * ES7000 chipsets | |
56 | */ | |
57 | ||
2c4ce18c IM |
58 | #define NON_UNISYS 0 |
59 | #define ES7000_CLASSIC 1 | |
60 | #define ES7000_ZORRO 2 | |
1625324d | 61 | |
2c4ce18c IM |
62 | #define MIP_REG 1 |
63 | #define MIP_PSAI_REG 4 | |
1625324d | 64 | |
2c4ce18c IM |
65 | #define MIP_BUSY 1 |
66 | #define MIP_SPIN 0xf0000 | |
67 | #define MIP_VALID 0x0100000000000000ULL | |
352887d1 | 68 | #define MIP_SW_APIC 0x1020b |
1625324d | 69 | |
2c4ce18c | 70 | #define MIP_PORT(val) ((val >> 32) & 0xffff) |
1625324d | 71 | |
2c4ce18c | 72 | #define MIP_RD_LO(val) (val & 0xffffffff) |
1625324d | 73 | |
352887d1 IM |
74 | struct mip_reg { |
75 | unsigned long long off_0x00; | |
76 | unsigned long long off_0x08; | |
77 | unsigned long long off_0x10; | |
78 | unsigned long long off_0x18; | |
79 | unsigned long long off_0x20; | |
80 | unsigned long long off_0x28; | |
81 | unsigned long long off_0x30; | |
82 | unsigned long long off_0x38; | |
83 | }; | |
84 | ||
1625324d | 85 | struct mip_reg_info { |
2c4ce18c IM |
86 | unsigned long long mip_info; |
87 | unsigned long long delivery_info; | |
88 | unsigned long long host_reg; | |
89 | unsigned long long mip_reg; | |
1625324d YL |
90 | }; |
91 | ||
1625324d | 92 | struct psai { |
2c4ce18c IM |
93 | unsigned long long entry_type; |
94 | unsigned long long addr; | |
95 | unsigned long long bep_addr; | |
1625324d YL |
96 | }; |
97 | ||
1625324d | 98 | #ifdef CONFIG_ACPI |
7da18ed9 | 99 | |
352887d1 | 100 | struct es7000_oem_table { |
2c4ce18c IM |
101 | struct acpi_table_header Header; |
102 | u32 OEMTableAddr; | |
103 | u32 OEMTableSize; | |
1625324d | 104 | }; |
7da18ed9 IM |
105 | |
106 | static unsigned long oem_addrX; | |
107 | static unsigned long oem_size; | |
108 | ||
1625324d YL |
109 | #endif |
110 | ||
1da177e4 LT |
111 | /* |
112 | * ES7000 Globals | |
113 | */ | |
114 | ||
7da18ed9 | 115 | static volatile unsigned long *psai; |
2c4ce18c IM |
116 | static struct mip_reg *mip_reg; |
117 | static struct mip_reg *host_reg; | |
118 | static int mip_port; | |
7da18ed9 IM |
119 | static unsigned long mip_addr; |
120 | static unsigned long host_addr; | |
1da177e4 | 121 | |
2c4ce18c | 122 | int es7000_plat; |
32c50612 | 123 | |
1da177e4 LT |
124 | /* |
125 | * GSI override for ES7000 platforms. | |
126 | */ | |
127 | ||
2c4ce18c | 128 | static unsigned int base; |
1da177e4 LT |
129 | |
130 | static int | |
131 | es7000_rename_gsi(int ioapic, int gsi) | |
132 | { | |
9338316c NP |
133 | if (es7000_plat == ES7000_ZORRO) |
134 | return gsi; | |
135 | ||
1da177e4 LT |
136 | if (!base) { |
137 | int i; | |
138 | for (i = 0; i < nr_ioapics; i++) | |
139 | base += nr_ioapic_registers[i]; | |
140 | } | |
141 | ||
c7e7964c | 142 | if (!ioapic && (gsi < 16)) |
1da177e4 | 143 | gsi += base; |
2c4ce18c | 144 | |
1da177e4 LT |
145 | return gsi; |
146 | } | |
147 | ||
569712b2 YL |
148 | static int wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip) |
149 | { | |
150 | unsigned long vect = 0, psaival = 0; | |
151 | ||
152 | if (psai == NULL) | |
153 | return -1; | |
154 | ||
155 | vect = ((unsigned long)__pa(eip)/0x1000) << 16; | |
156 | psaival = (0x1000000 | vect | cpu); | |
157 | ||
158 | while (*psai & 0x1000000) | |
159 | ; | |
160 | ||
161 | *psai = psaival; | |
162 | ||
163 | return 0; | |
164 | } | |
54ac14a8 | 165 | |
2b6163bf | 166 | static int __init es7000_apic_is_cluster(void) |
54ac14a8 | 167 | { |
b5fe363b YL |
168 | /* MPENTIUMIII */ |
169 | if (boot_cpu_data.x86 == 6 && | |
2b6163bf YL |
170 | (boot_cpu_data.x86_model >= 7 || boot_cpu_data.x86_model <= 11)) |
171 | return 1; | |
b5fe363b | 172 | |
54ac14a8 YL |
173 | return 0; |
174 | } | |
569712b2 | 175 | |
d3185b37 | 176 | static void __init setup_unisys(void) |
56f1d5d5 NP |
177 | { |
178 | /* | |
179 | * Determine the generation of the ES7000 currently running. | |
180 | * | |
181 | * es7000_plat = 1 if the machine is a 5xx ES7000 box | |
182 | * es7000_plat = 2 if the machine is a x86_64 ES7000 box | |
183 | * | |
184 | */ | |
185 | if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2)) | |
9338316c | 186 | es7000_plat = ES7000_ZORRO; |
56f1d5d5 | 187 | else |
9338316c | 188 | es7000_plat = ES7000_CLASSIC; |
56f1d5d5 NP |
189 | ioapic_renumber_irq = es7000_rename_gsi; |
190 | } | |
191 | ||
1da177e4 | 192 | /* |
d3185b37 | 193 | * Parse the OEM Table: |
1da177e4 | 194 | */ |
352887d1 | 195 | static int __init parse_unisys_oem(char *oemptr) |
1da177e4 | 196 | { |
352887d1 | 197 | int i; |
1da177e4 | 198 | int success = 0; |
352887d1 IM |
199 | unsigned char type, size; |
200 | unsigned long val; | |
201 | char *tp = NULL; | |
202 | struct psai *psaip = NULL; | |
1da177e4 LT |
203 | struct mip_reg_info *mi; |
204 | struct mip_reg *host, *mip; | |
205 | ||
206 | tp = oemptr; | |
207 | ||
208 | tp += 8; | |
209 | ||
352887d1 | 210 | for (i = 0; i <= 6; i++) { |
1da177e4 LT |
211 | type = *tp++; |
212 | size = *tp++; | |
213 | tp -= 2; | |
214 | switch (type) { | |
215 | case MIP_REG: | |
216 | mi = (struct mip_reg_info *)tp; | |
217 | val = MIP_RD_LO(mi->host_reg); | |
218 | host_addr = val; | |
219 | host = (struct mip_reg *)val; | |
220 | host_reg = __va(host); | |
221 | val = MIP_RD_LO(mi->mip_reg); | |
222 | mip_port = MIP_PORT(mi->mip_info); | |
223 | mip_addr = val; | |
224 | mip = (struct mip_reg *)val; | |
225 | mip_reg = __va(mip); | |
5171c304 TG |
226 | pr_debug("es7000_mipcfg: host_reg = 0x%lx \n", |
227 | (unsigned long)host_reg); | |
228 | pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n", | |
229 | (unsigned long)mip_reg); | |
1da177e4 LT |
230 | success++; |
231 | break; | |
232 | case MIP_PSAI_REG: | |
233 | psaip = (struct psai *)tp; | |
234 | if (tp != NULL) { | |
235 | if (psaip->addr) | |
236 | psai = __va(psaip->addr); | |
237 | else | |
238 | psai = NULL; | |
239 | success++; | |
240 | } | |
241 | break; | |
242 | default: | |
243 | break; | |
244 | } | |
1da177e4 LT |
245 | tp += size; |
246 | } | |
247 | ||
d3185b37 | 248 | if (success < 2) |
9338316c | 249 | es7000_plat = NON_UNISYS; |
d3185b37 | 250 | else |
56f1d5d5 | 251 | setup_unisys(); |
2c4ce18c | 252 | |
1da177e4 LT |
253 | return es7000_plat; |
254 | } | |
255 | ||
e5428ede | 256 | #ifdef CONFIG_ACPI |
d3185b37 | 257 | static int __init find_unisys_acpi_oem_table(unsigned long *oem_addr) |
1da177e4 | 258 | { |
ceb6c468 | 259 | struct acpi_table_header *header = NULL; |
7da18ed9 | 260 | struct es7000_oem_table *table; |
b825e6cc | 261 | acpi_size tbl_size; |
7da18ed9 IM |
262 | acpi_status ret; |
263 | int i = 0; | |
a73aaedd | 264 | |
7da18ed9 IM |
265 | for (;;) { |
266 | ret = acpi_get_table_with_size("OEM1", i++, &header, &tbl_size); | |
267 | if (!ACPI_SUCCESS(ret)) | |
268 | return -1; | |
a73aaedd | 269 | |
7da18ed9 IM |
270 | if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) |
271 | break; | |
a73aaedd | 272 | |
b825e6cc | 273 | early_acpi_os_unmap_memory(header, tbl_size); |
1da177e4 | 274 | } |
7da18ed9 IM |
275 | |
276 | table = (void *)header; | |
277 | ||
278 | oem_addrX = table->OEMTableAddr; | |
279 | oem_size = table->OEMTableSize; | |
280 | ||
281 | early_acpi_os_unmap_memory(header, tbl_size); | |
282 | ||
283 | *oem_addr = (unsigned long)__acpi_map_table(oem_addrX, oem_size); | |
284 | ||
285 | return 0; | |
1da177e4 | 286 | } |
a73aaedd | 287 | |
d3185b37 | 288 | static void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr) |
a73aaedd | 289 | { |
b825e6cc YL |
290 | if (!oem_addr) |
291 | return; | |
292 | ||
293 | __acpi_unmap_table((char *)oem_addr, oem_size); | |
a73aaedd | 294 | } |
7da18ed9 IM |
295 | |
296 | static int es7000_check_dsdt(void) | |
297 | { | |
298 | struct acpi_table_header header; | |
299 | ||
300 | if (ACPI_SUCCESS(acpi_get_table_header(ACPI_SIG_DSDT, 0, &header)) && | |
301 | !strncmp(header.oem_id, "UNISYS", 6)) | |
302 | return 1; | |
303 | return 0; | |
304 | } | |
305 | ||
2b6163bf YL |
306 | static int __initdata es7000_acpi_ret; |
307 | ||
7da18ed9 IM |
308 | /* Hook from generic ACPI tables.c */ |
309 | static int __init es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id) | |
310 | { | |
311 | unsigned long oem_addr = 0; | |
312 | int check_dsdt; | |
313 | int ret = 0; | |
314 | ||
315 | /* check dsdt at first to avoid clear fix_map for oem_addr */ | |
316 | check_dsdt = es7000_check_dsdt(); | |
317 | ||
318 | if (!find_unisys_acpi_oem_table(&oem_addr)) { | |
319 | if (check_dsdt) { | |
320 | ret = parse_unisys_oem((char *)oem_addr); | |
321 | } else { | |
322 | setup_unisys(); | |
323 | ret = 1; | |
324 | } | |
325 | /* | |
326 | * we need to unmap it | |
327 | */ | |
328 | unmap_unisys_acpi_oem_table(oem_addr); | |
329 | } | |
2b6163bf YL |
330 | |
331 | es7000_acpi_ret = ret; | |
332 | ||
333 | return ret && !es7000_apic_is_cluster(); | |
7da18ed9 | 334 | } |
3b900d44 IM |
335 | |
336 | static int __init | |
337 | es7000_acpi_madt_oem_check_cluster(char *oem_id, char *oem_table_id) | |
2b6163bf YL |
338 | { |
339 | int ret = es7000_acpi_ret; | |
340 | ||
341 | return ret && es7000_apic_is_cluster(); | |
342 | } | |
343 | ||
7da18ed9 IM |
344 | #else /* !CONFIG_ACPI: */ |
345 | static int __init es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id) | |
346 | { | |
347 | return 0; | |
348 | } | |
3b900d44 IM |
349 | |
350 | static int __init | |
351 | es7000_acpi_madt_oem_check_cluster(char *oem_id, char *oem_table_id) | |
352 | { | |
353 | return 0; | |
354 | } | |
7da18ed9 | 355 | #endif /* !CONFIG_ACPI */ |
1da177e4 | 356 | |
2c4ce18c | 357 | static void es7000_spin(int n) |
1da177e4 LT |
358 | { |
359 | int i = 0; | |
360 | ||
361 | while (i++ < n) | |
362 | rep_nop(); | |
363 | } | |
364 | ||
365 | static int __init | |
366 | es7000_mip_write(struct mip_reg *mip_reg) | |
367 | { | |
2c4ce18c IM |
368 | int status = 0; |
369 | int spin; | |
1da177e4 LT |
370 | |
371 | spin = MIP_SPIN; | |
2c4ce18c IM |
372 | while ((host_reg->off_0x38 & MIP_VALID) != 0) { |
373 | if (--spin <= 0) { | |
7da18ed9 | 374 | WARN(1, "Timeout waiting for Host Valid Flag\n"); |
2c4ce18c IM |
375 | return -1; |
376 | } | |
1da177e4 LT |
377 | es7000_spin(MIP_SPIN); |
378 | } | |
379 | ||
380 | memcpy(host_reg, mip_reg, sizeof(struct mip_reg)); | |
381 | outb(1, mip_port); | |
382 | ||
383 | spin = MIP_SPIN; | |
384 | ||
2c4ce18c | 385 | while ((mip_reg->off_0x38 & MIP_VALID) == 0) { |
1da177e4 | 386 | if (--spin <= 0) { |
7da18ed9 | 387 | WARN(1, "Timeout waiting for MIP Valid Flag\n"); |
1da177e4 LT |
388 | return -1; |
389 | } | |
390 | es7000_spin(MIP_SPIN); | |
391 | } | |
392 | ||
2c4ce18c IM |
393 | status = (mip_reg->off_0x00 & 0xffff0000000000ULL) >> 48; |
394 | mip_reg->off_0x38 &= ~MIP_VALID; | |
395 | ||
1da177e4 LT |
396 | return status; |
397 | } | |
398 | ||
d3185b37 | 399 | static void __init es7000_enable_apic_mode(void) |
1da177e4 | 400 | { |
b0b20e5a IM |
401 | struct mip_reg es7000_mip_reg; |
402 | int mip_status; | |
403 | ||
404 | if (!es7000_plat) | |
1da177e4 | 405 | return; |
b0b20e5a | 406 | |
7da18ed9 | 407 | printk(KERN_INFO "ES7000: Enabling APIC mode.\n"); |
352887d1 IM |
408 | memset(&es7000_mip_reg, 0, sizeof(struct mip_reg)); |
409 | es7000_mip_reg.off_0x00 = MIP_SW_APIC; | |
410 | es7000_mip_reg.off_0x38 = MIP_VALID; | |
b0b20e5a | 411 | |
7da18ed9 IM |
412 | while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0) |
413 | WARN(1, "Command failed, status = %x\n", mip_status); | |
1da177e4 | 414 | } |
2e096df8 | 415 | |
2e096df8 IM |
416 | static void es7000_vector_allocation_domain(int cpu, cpumask_t *retmask) |
417 | { | |
418 | /* Careful. Some cpus do not strictly honor the set of cpus | |
419 | * specified in the interrupt destination when using lowest | |
420 | * priority interrupt delivery mode. | |
421 | * | |
422 | * In particular there was a hyperthreading cpu observed to | |
423 | * deliver interrupts to the wrong hyperthread when only one | |
424 | * hyperthread was specified in the interrupt desitination. | |
425 | */ | |
426 | *retmask = (cpumask_t){ { [0] = APIC_ALL_CPUS, } }; | |
427 | } | |
428 | ||
429 | ||
430 | static void es7000_wait_for_init_deassert(atomic_t *deassert) | |
431 | { | |
2e096df8 IM |
432 | while (!atomic_read(deassert)) |
433 | cpu_relax(); | |
2e096df8 IM |
434 | } |
435 | ||
436 | static unsigned int es7000_get_apic_id(unsigned long x) | |
437 | { | |
438 | return (x >> 24) & 0xFF; | |
439 | } | |
440 | ||
2e096df8 IM |
441 | static void es7000_send_IPI_mask(const struct cpumask *mask, int vector) |
442 | { | |
43f39890 | 443 | default_send_IPI_mask_sequence_phys(mask, vector); |
2e096df8 IM |
444 | } |
445 | ||
446 | static void es7000_send_IPI_allbutself(int vector) | |
447 | { | |
43f39890 | 448 | default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector); |
2e096df8 IM |
449 | } |
450 | ||
451 | static void es7000_send_IPI_all(int vector) | |
452 | { | |
453 | es7000_send_IPI_mask(cpu_online_mask, vector); | |
454 | } | |
455 | ||
456 | static int es7000_apic_id_registered(void) | |
457 | { | |
352887d1 | 458 | return 1; |
2e096df8 IM |
459 | } |
460 | ||
461 | static const cpumask_t *target_cpus_cluster(void) | |
462 | { | |
463 | return &CPU_MASK_ALL; | |
464 | } | |
465 | ||
466 | static const cpumask_t *es7000_target_cpus(void) | |
467 | { | |
468 | return &cpumask_of_cpu(smp_processor_id()); | |
469 | } | |
470 | ||
471 | static unsigned long | |
472 | es7000_check_apicid_used(physid_mask_t bitmap, int apicid) | |
473 | { | |
474 | return 0; | |
475 | } | |
476 | static unsigned long es7000_check_apicid_present(int bit) | |
477 | { | |
478 | return physid_isset(bit, phys_cpu_present_map); | |
479 | } | |
480 | ||
481 | static unsigned long calculate_ldr(int cpu) | |
482 | { | |
2c4ce18c | 483 | unsigned long id = per_cpu(x86_bios_cpu_apicid, cpu); |
2e096df8 | 484 | |
2c4ce18c | 485 | return SET_APIC_LOGICAL_ID(id); |
2e096df8 IM |
486 | } |
487 | ||
488 | /* | |
489 | * Set up the logical destination ID. | |
490 | * | |
491 | * Intel recommends to set DFR, LdR and TPR before enabling | |
492 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel | |
493 | * document number 292116). So here it goes... | |
494 | */ | |
495 | static void es7000_init_apic_ldr_cluster(void) | |
496 | { | |
497 | unsigned long val; | |
498 | int cpu = smp_processor_id(); | |
499 | ||
352887d1 | 500 | apic_write(APIC_DFR, APIC_DFR_CLUSTER); |
2e096df8 IM |
501 | val = calculate_ldr(cpu); |
502 | apic_write(APIC_LDR, val); | |
503 | } | |
504 | ||
505 | static void es7000_init_apic_ldr(void) | |
506 | { | |
507 | unsigned long val; | |
508 | int cpu = smp_processor_id(); | |
509 | ||
352887d1 | 510 | apic_write(APIC_DFR, APIC_DFR_FLAT); |
2e096df8 IM |
511 | val = calculate_ldr(cpu); |
512 | apic_write(APIC_LDR, val); | |
513 | } | |
514 | ||
515 | static void es7000_setup_apic_routing(void) | |
516 | { | |
517 | int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id()); | |
7da18ed9 IM |
518 | |
519 | printk(KERN_INFO | |
520 | "Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n", | |
2e096df8 IM |
521 | (apic_version[apic] == 0x14) ? |
522 | "Physical Cluster" : "Logical Cluster", | |
7da18ed9 | 523 | nr_ioapics, cpus_addr(*es7000_target_cpus())[0]); |
2e096df8 IM |
524 | } |
525 | ||
526 | static int es7000_apicid_to_node(int logical_apicid) | |
527 | { | |
528 | return 0; | |
529 | } | |
530 | ||
531 | ||
532 | static int es7000_cpu_present_to_apicid(int mps_cpu) | |
533 | { | |
534 | if (!mps_cpu) | |
535 | return boot_cpu_physical_apicid; | |
536 | else if (mps_cpu < nr_cpu_ids) | |
2c4ce18c | 537 | return per_cpu(x86_bios_cpu_apicid, mps_cpu); |
2e096df8 IM |
538 | else |
539 | return BAD_APICID; | |
540 | } | |
541 | ||
7da18ed9 IM |
542 | static int cpu_id; |
543 | ||
2e096df8 IM |
544 | static physid_mask_t es7000_apicid_to_cpu_present(int phys_apicid) |
545 | { | |
2e096df8 IM |
546 | physid_mask_t mask; |
547 | ||
7da18ed9 IM |
548 | mask = physid_mask_of_physid(cpu_id); |
549 | ++cpu_id; | |
2e096df8 IM |
550 | |
551 | return mask; | |
552 | } | |
553 | ||
554 | /* Mapping from cpu number to logical apicid */ | |
555 | static int es7000_cpu_to_logical_apicid(int cpu) | |
556 | { | |
557 | #ifdef CONFIG_SMP | |
558 | if (cpu >= nr_cpu_ids) | |
559 | return BAD_APICID; | |
2f205bc4 | 560 | return cpu_2_logical_apicid[cpu]; |
2e096df8 IM |
561 | #else |
562 | return logical_smp_processor_id(); | |
563 | #endif | |
564 | } | |
565 | ||
566 | static physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map) | |
567 | { | |
568 | /* For clustered we don't have a good way to do this yet - hack */ | |
569 | return physids_promote(0xff); | |
570 | } | |
571 | ||
572 | static int es7000_check_phys_apicid_present(int cpu_physical_apicid) | |
573 | { | |
574 | boot_cpu_physical_apicid = read_apic_id(); | |
2c4ce18c | 575 | return 1; |
2e096df8 IM |
576 | } |
577 | ||
578 | static unsigned int | |
579 | es7000_cpu_mask_to_apicid_cluster(const struct cpumask *cpumask) | |
580 | { | |
581 | int cpus_found = 0; | |
582 | int num_bits_set; | |
583 | int apicid; | |
584 | int cpu; | |
585 | ||
586 | num_bits_set = cpumask_weight(cpumask); | |
587 | /* Return id to all */ | |
588 | if (num_bits_set == nr_cpu_ids) | |
589 | return 0xFF; | |
590 | /* | |
591 | * The cpus in the mask must all be on the apic cluster. If are not | |
592 | * on the same apicid cluster return default value of target_cpus(): | |
593 | */ | |
594 | cpu = cpumask_first(cpumask); | |
595 | apicid = es7000_cpu_to_logical_apicid(cpu); | |
596 | ||
597 | while (cpus_found < num_bits_set) { | |
598 | if (cpumask_test_cpu(cpu, cpumask)) { | |
599 | int new_apicid = es7000_cpu_to_logical_apicid(cpu); | |
600 | ||
b9e0d1aa | 601 | if (APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) { |
7da18ed9 | 602 | WARN(1, "Not a valid mask!"); |
2e096df8 IM |
603 | |
604 | return 0xFF; | |
605 | } | |
606 | apicid = new_apicid; | |
607 | cpus_found++; | |
608 | } | |
609 | cpu++; | |
610 | } | |
611 | return apicid; | |
612 | } | |
613 | ||
614 | static unsigned int es7000_cpu_mask_to_apicid(const cpumask_t *cpumask) | |
615 | { | |
616 | int cpus_found = 0; | |
617 | int num_bits_set; | |
618 | int apicid; | |
619 | int cpu; | |
620 | ||
621 | num_bits_set = cpus_weight(*cpumask); | |
622 | /* Return id to all */ | |
623 | if (num_bits_set == nr_cpu_ids) | |
624 | return es7000_cpu_to_logical_apicid(0); | |
625 | /* | |
626 | * The cpus in the mask must all be on the apic cluster. If are not | |
627 | * on the same apicid cluster return default value of target_cpus(): | |
628 | */ | |
629 | cpu = first_cpu(*cpumask); | |
630 | apicid = es7000_cpu_to_logical_apicid(cpu); | |
631 | while (cpus_found < num_bits_set) { | |
632 | if (cpu_isset(cpu, *cpumask)) { | |
633 | int new_apicid = es7000_cpu_to_logical_apicid(cpu); | |
634 | ||
b9e0d1aa | 635 | if (APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) { |
352887d1 | 636 | printk("%s: Not a valid mask!\n", __func__); |
2e096df8 IM |
637 | |
638 | return es7000_cpu_to_logical_apicid(0); | |
639 | } | |
640 | apicid = new_apicid; | |
641 | cpus_found++; | |
642 | } | |
643 | cpu++; | |
644 | } | |
645 | return apicid; | |
646 | } | |
647 | ||
648 | static unsigned int | |
649 | es7000_cpu_mask_to_apicid_and(const struct cpumask *inmask, | |
650 | const struct cpumask *andmask) | |
651 | { | |
652 | int apicid = es7000_cpu_to_logical_apicid(0); | |
653 | cpumask_var_t cpumask; | |
654 | ||
655 | if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC)) | |
656 | return apicid; | |
657 | ||
658 | cpumask_and(cpumask, inmask, andmask); | |
659 | cpumask_and(cpumask, cpumask, cpu_online_mask); | |
660 | apicid = es7000_cpu_mask_to_apicid(cpumask); | |
661 | ||
662 | free_cpumask_var(cpumask); | |
663 | ||
664 | return apicid; | |
665 | } | |
666 | ||
667 | static int es7000_phys_pkg_id(int cpuid_apic, int index_msb) | |
668 | { | |
669 | return cpuid_apic >> index_msb; | |
670 | } | |
671 | ||
2e096df8 IM |
672 | static int probe_es7000(void) |
673 | { | |
674 | /* probed later in mptable/ACPI hooks */ | |
675 | return 0; | |
676 | } | |
677 | ||
2b6163bf | 678 | static int __initdata es7000_mps_ret; |
2e096df8 IM |
679 | static __init int |
680 | es7000_mps_oem_check(struct mpc_table *mpc, char *oem, char *productid) | |
681 | { | |
2b6163bf YL |
682 | int ret = 0; |
683 | ||
2e096df8 IM |
684 | if (mpc->oemptr) { |
685 | struct mpc_oemtable *oem_table = | |
686 | (struct mpc_oemtable *)mpc->oemptr; | |
687 | ||
688 | if (!strncmp(oem, "UNISYS", 6)) | |
2b6163bf | 689 | ret = parse_unisys_oem((char *)oem_table); |
2e096df8 | 690 | } |
2b6163bf YL |
691 | |
692 | es7000_mps_ret = ret; | |
693 | ||
694 | return ret && !es7000_apic_is_cluster(); | |
695 | } | |
696 | ||
697 | static __init int | |
698 | es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem, char *productid) | |
699 | { | |
700 | int ret = es7000_mps_ret; | |
701 | ||
702 | return ret && es7000_apic_is_cluster(); | |
2e096df8 IM |
703 | } |
704 | ||
2b6163bf YL |
705 | struct apic apic_es7000_cluster = { |
706 | ||
707 | .name = "es7000", | |
708 | .probe = probe_es7000, | |
709 | .acpi_madt_oem_check = es7000_acpi_madt_oem_check_cluster, | |
710 | .apic_id_registered = es7000_apic_id_registered, | |
711 | ||
712 | .irq_delivery_mode = dest_LowestPrio, | |
713 | /* logical delivery broadcast to all procs: */ | |
714 | .irq_dest_mode = 1, | |
715 | ||
716 | .target_cpus = target_cpus_cluster, | |
717 | .disable_esr = 1, | |
718 | .dest_logical = 0, | |
719 | .check_apicid_used = es7000_check_apicid_used, | |
720 | .check_apicid_present = es7000_check_apicid_present, | |
721 | ||
722 | .vector_allocation_domain = es7000_vector_allocation_domain, | |
723 | .init_apic_ldr = es7000_init_apic_ldr_cluster, | |
724 | ||
725 | .ioapic_phys_id_map = es7000_ioapic_phys_id_map, | |
726 | .setup_apic_routing = es7000_setup_apic_routing, | |
727 | .multi_timer_check = NULL, | |
728 | .apicid_to_node = es7000_apicid_to_node, | |
729 | .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid, | |
730 | .cpu_present_to_apicid = es7000_cpu_present_to_apicid, | |
731 | .apicid_to_cpu_present = es7000_apicid_to_cpu_present, | |
732 | .setup_portio_remap = NULL, | |
733 | .check_phys_apicid_present = es7000_check_phys_apicid_present, | |
734 | .enable_apic_mode = es7000_enable_apic_mode, | |
735 | .phys_pkg_id = es7000_phys_pkg_id, | |
736 | .mps_oem_check = es7000_mps_oem_check_cluster, | |
737 | ||
738 | .get_apic_id = es7000_get_apic_id, | |
739 | .set_apic_id = NULL, | |
740 | .apic_id_mask = 0xFF << 24, | |
741 | ||
742 | .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid_cluster, | |
743 | .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and, | |
744 | ||
745 | .send_IPI_mask = es7000_send_IPI_mask, | |
746 | .send_IPI_mask_allbutself = NULL, | |
747 | .send_IPI_allbutself = es7000_send_IPI_allbutself, | |
748 | .send_IPI_all = es7000_send_IPI_all, | |
749 | .send_IPI_self = default_send_IPI_self, | |
750 | ||
1f5bcabf | 751 | .wakeup_secondary_cpu = wakeup_secondary_cpu_via_mip, |
2b6163bf YL |
752 | |
753 | .trampoline_phys_low = 0x467, | |
754 | .trampoline_phys_high = 0x469, | |
755 | ||
756 | .wait_for_init_deassert = NULL, | |
757 | ||
758 | /* Nothing to do for most platforms, since cleared by the INIT cycle: */ | |
759 | .smp_callin_clear_local_apic = NULL, | |
760 | .inquire_remote_apic = default_inquire_remote_apic, | |
761 | ||
762 | .read = native_apic_mem_read, | |
763 | .write = native_apic_mem_write, | |
764 | .icr_read = native_apic_icr_read, | |
765 | .icr_write = native_apic_icr_write, | |
766 | .wait_icr_idle = native_apic_wait_icr_idle, | |
767 | .safe_wait_icr_idle = native_safe_apic_wait_icr_idle, | |
768 | }; | |
2e096df8 | 769 | |
be163a15 | 770 | struct apic apic_es7000 = { |
2e096df8 IM |
771 | |
772 | .name = "es7000", | |
773 | .probe = probe_es7000, | |
774 | .acpi_madt_oem_check = es7000_acpi_madt_oem_check, | |
775 | .apic_id_registered = es7000_apic_id_registered, | |
776 | ||
777 | .irq_delivery_mode = dest_Fixed, | |
778 | /* phys delivery to target CPUs: */ | |
779 | .irq_dest_mode = 0, | |
780 | ||
781 | .target_cpus = es7000_target_cpus, | |
782 | .disable_esr = 1, | |
783 | .dest_logical = 0, | |
784 | .check_apicid_used = es7000_check_apicid_used, | |
785 | .check_apicid_present = es7000_check_apicid_present, | |
786 | ||
787 | .vector_allocation_domain = es7000_vector_allocation_domain, | |
788 | .init_apic_ldr = es7000_init_apic_ldr, | |
789 | ||
790 | .ioapic_phys_id_map = es7000_ioapic_phys_id_map, | |
791 | .setup_apic_routing = es7000_setup_apic_routing, | |
792 | .multi_timer_check = NULL, | |
793 | .apicid_to_node = es7000_apicid_to_node, | |
794 | .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid, | |
795 | .cpu_present_to_apicid = es7000_cpu_present_to_apicid, | |
796 | .apicid_to_cpu_present = es7000_apicid_to_cpu_present, | |
797 | .setup_portio_remap = NULL, | |
798 | .check_phys_apicid_present = es7000_check_phys_apicid_present, | |
799 | .enable_apic_mode = es7000_enable_apic_mode, | |
800 | .phys_pkg_id = es7000_phys_pkg_id, | |
801 | .mps_oem_check = es7000_mps_oem_check, | |
802 | ||
803 | .get_apic_id = es7000_get_apic_id, | |
804 | .set_apic_id = NULL, | |
805 | .apic_id_mask = 0xFF << 24, | |
806 | ||
807 | .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid, | |
808 | .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and, | |
809 | ||
810 | .send_IPI_mask = es7000_send_IPI_mask, | |
811 | .send_IPI_mask_allbutself = NULL, | |
812 | .send_IPI_allbutself = es7000_send_IPI_allbutself, | |
813 | .send_IPI_all = es7000_send_IPI_all, | |
6b64ee02 | 814 | .send_IPI_self = default_send_IPI_self, |
2e096df8 | 815 | |
2e096df8 IM |
816 | .trampoline_phys_low = 0x467, |
817 | .trampoline_phys_high = 0x469, | |
818 | ||
819 | .wait_for_init_deassert = es7000_wait_for_init_deassert, | |
820 | ||
821 | /* Nothing to do for most platforms, since cleared by the INIT cycle: */ | |
822 | .smp_callin_clear_local_apic = NULL, | |
2e096df8 | 823 | .inquire_remote_apic = default_inquire_remote_apic, |
c1eeb2de YL |
824 | |
825 | .read = native_apic_mem_read, | |
826 | .write = native_apic_mem_write, | |
827 | .icr_read = native_apic_icr_read, | |
828 | .icr_write = native_apic_icr_write, | |
829 | .wait_icr_idle = native_apic_wait_icr_idle, | |
830 | .safe_wait_icr_idle = native_safe_apic_wait_icr_idle, | |
2e096df8 | 831 | }; |