blob: 03ba1b895f5ec69cdadde8509e6bf887b046ef21 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Written by: Garry Forsgren, Unisys Corporation
3 * Natalie Protasevich, Unisys Corporation
Ingo Molnar7da18ed2009-02-17 15:29:30 +01004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * This file contains the code to configure and interface
6 * with Unisys ES7000 series hardware system manager.
7 *
Ingo Molnar7da18ed2009-02-17 15:29:30 +01008 * Copyright (c) 2003 Unisys Corporation.
9 * Copyright (C) 2009, Red Hat, Inc., Ingo Molnar
10 *
11 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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 */
Joe Perches5cd476e2009-12-09 10:45:33 -080030
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/notifier.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010034#include <linux/spinlock.h>
35#include <linux/cpumask.h>
36#include <linux/threads.h>
37#include <linux/kernel.h>
38#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/reboot.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010040#include <linux/string.h>
41#include <linux/types.h>
42#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/acpi.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010044#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090045#include <linux/gfp.h>
Ingo Molnar7da18ed2009-02-17 15:29:30 +010046#include <linux/nmi.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010047#include <linux/smp.h>
Ingo Molnar7da18ed2009-02-17 15:29:30 +010048#include <linux/io.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010049
50#include <asm/apicdef.h>
51#include <asm/atomic.h>
52#include <asm/fixmap.h>
53#include <asm/mpspec.h>
54#include <asm/setup.h>
55#include <asm/apic.h>
56#include <asm/ipi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58/*
Yinghai Lu16253242008-08-27 23:01:16 -070059 * ES7000 chipsets
60 */
61
Ingo Molnar2c4ce182009-02-17 14:57:16 +010062#define NON_UNISYS 0
63#define ES7000_CLASSIC 1
64#define ES7000_ZORRO 2
Yinghai Lu16253242008-08-27 23:01:16 -070065
Ingo Molnar2c4ce182009-02-17 14:57:16 +010066#define MIP_REG 1
67#define MIP_PSAI_REG 4
Yinghai Lu16253242008-08-27 23:01:16 -070068
Ingo Molnar2c4ce182009-02-17 14:57:16 +010069#define MIP_BUSY 1
70#define MIP_SPIN 0xf0000
71#define MIP_VALID 0x0100000000000000ULL
Ingo Molnar352887d2009-02-17 15:17:55 +010072#define MIP_SW_APIC 0x1020b
Yinghai Lu16253242008-08-27 23:01:16 -070073
Ingo Molnar2c4ce182009-02-17 14:57:16 +010074#define MIP_PORT(val) ((val >> 32) & 0xffff)
Yinghai Lu16253242008-08-27 23:01:16 -070075
Ingo Molnar2c4ce182009-02-17 14:57:16 +010076#define MIP_RD_LO(val) (val & 0xffffffff)
Yinghai Lu16253242008-08-27 23:01:16 -070077
Yinghai Lu16253242008-08-27 23:01:16 -070078struct mip_reg {
Ingo Molnar2c4ce182009-02-17 14:57:16 +010079 unsigned long long off_0x00;
80 unsigned long long off_0x08;
81 unsigned long long off_0x10;
82 unsigned long long off_0x18;
83 unsigned long long off_0x20;
84 unsigned long long off_0x28;
85 unsigned long long off_0x30;
86 unsigned long long off_0x38;
Yinghai Lu16253242008-08-27 23:01:16 -070087};
88
Ingo Molnar352887d2009-02-17 15:17:55 +010089struct mip_reg_info {
90 unsigned long long mip_info;
91 unsigned long long delivery_info;
92 unsigned long long host_reg;
93 unsigned long long mip_reg;
94};
Ingo Molnar2c4ce182009-02-17 14:57:16 +010095
Ingo Molnar352887d2009-02-17 15:17:55 +010096struct psai {
97 unsigned long long entry_type;
98 unsigned long long addr;
99 unsigned long long bep_addr;
100};
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100101
Ingo Molnar352887d2009-02-17 15:17:55 +0100102#ifdef CONFIG_ACPI
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100103
Ingo Molnar352887d2009-02-17 15:17:55 +0100104struct es7000_oem_table {
105 struct acpi_table_header Header;
106 u32 OEMTableAddr;
107 u32 OEMTableSize;
108};
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100109
110static unsigned long oem_addrX;
111static unsigned long oem_size;
112
Ingo Molnar352887d2009-02-17 15:17:55 +0100113#endif
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100114
Yinghai Lu16253242008-08-27 23:01:16 -0700115/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * ES7000 Globals
117 */
118
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100119static volatile unsigned long *psai;
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100120static struct mip_reg *mip_reg;
121static struct mip_reg *host_reg;
122static int mip_port;
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100123static unsigned long mip_addr;
124static unsigned long host_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100126int es7000_plat;
Alexey Starikovskiy32c50612008-05-14 19:02:51 +0400127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/*
129 * GSI override for ES7000 platforms.
130 */
131
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100132static unsigned int base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134static int
135es7000_rename_gsi(int ioapic, int gsi)
136{
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800137 if (es7000_plat == ES7000_ZORRO)
138 return gsi;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (!base) {
141 int i;
142 for (i = 0; i < nr_ioapics; i++)
143 base += nr_ioapic_registers[i];
144 }
145
Yinghai Luc7e79642008-07-25 02:17:33 -0700146 if (!ioapic && (gsi < 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 gsi += base;
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 return gsi;
150}
151
Cyrill Gorcunov667c5292009-04-19 11:43:11 +0400152static int __cpuinit wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
Yinghai Lu569712b2008-11-16 03:12:49 -0800153{
154 unsigned long vect = 0, psaival = 0;
155
156 if (psai == NULL)
157 return -1;
158
159 vect = ((unsigned long)__pa(eip)/0x1000) << 16;
160 psaival = (0x1000000 | vect | cpu);
161
162 while (*psai & 0x1000000)
163 ;
164
165 *psai = psaival;
166
167 return 0;
168}
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800169
Jiri Slaby871d78c2009-03-02 11:34:27 +0100170static int es7000_apic_is_cluster(void)
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800171{
Yinghai Lub5fe3632008-11-18 08:14:14 -0800172 /* MPENTIUMIII */
173 if (boot_cpu_data.x86 == 6 &&
Roel Kluin005155b2009-08-25 15:35:12 +0200174 (boot_cpu_data.x86_model >= 7 && boot_cpu_data.x86_model <= 11))
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800175 return 1;
Yinghai Lub5fe3632008-11-18 08:14:14 -0800176
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800177 return 0;
178}
Yinghai Lu569712b2008-11-16 03:12:49 -0800179
Jiri Slaby871d78c2009-03-02 11:34:27 +0100180static void setup_unisys(void)
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700181{
182 /*
183 * Determine the generation of the ES7000 currently running.
184 *
185 * es7000_plat = 1 if the machine is a 5xx ES7000 box
186 * es7000_plat = 2 if the machine is a x86_64 ES7000 box
187 *
188 */
189 if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800190 es7000_plat = ES7000_ZORRO;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700191 else
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800192 es7000_plat = ES7000_CLASSIC;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700193 ioapic_renumber_irq = es7000_rename_gsi;
194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/*
Ingo Molnard3185b32009-02-17 15:13:05 +0100197 * Parse the OEM Table:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 */
Jiri Slaby871d78c2009-03-02 11:34:27 +0100199static int parse_unisys_oem(char *oemptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
Ingo Molnar352887d2009-02-17 15:17:55 +0100201 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 int success = 0;
Ingo Molnar352887d2009-02-17 15:17:55 +0100203 unsigned char type, size;
204 unsigned long val;
205 char *tp = NULL;
206 struct psai *psaip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 struct mip_reg_info *mi;
208 struct mip_reg *host, *mip;
209
210 tp = oemptr;
211
212 tp += 8;
213
Ingo Molnar352887d2009-02-17 15:17:55 +0100214 for (i = 0; i <= 6; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 type = *tp++;
216 size = *tp++;
217 tp -= 2;
218 switch (type) {
219 case MIP_REG:
220 mi = (struct mip_reg_info *)tp;
221 val = MIP_RD_LO(mi->host_reg);
222 host_addr = val;
223 host = (struct mip_reg *)val;
224 host_reg = __va(host);
225 val = MIP_RD_LO(mi->mip_reg);
226 mip_port = MIP_PORT(mi->mip_info);
227 mip_addr = val;
228 mip = (struct mip_reg *)val;
229 mip_reg = __va(mip);
Joe Perches5cd476e2009-12-09 10:45:33 -0800230 pr_debug("host_reg = 0x%lx\n",
Thomas Gleixner5171c302008-07-21 21:58:34 +0200231 (unsigned long)host_reg);
Joe Perches5cd476e2009-12-09 10:45:33 -0800232 pr_debug("mip_reg = 0x%lx\n",
Thomas Gleixner5171c302008-07-21 21:58:34 +0200233 (unsigned long)mip_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 success++;
235 break;
236 case MIP_PSAI_REG:
237 psaip = (struct psai *)tp;
238 if (tp != NULL) {
239 if (psaip->addr)
240 psai = __va(psaip->addr);
241 else
242 psai = NULL;
243 success++;
244 }
245 break;
246 default:
247 break;
248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 tp += size;
250 }
251
Ingo Molnard3185b32009-02-17 15:13:05 +0100252 if (success < 2)
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800253 es7000_plat = NON_UNISYS;
Ingo Molnard3185b32009-02-17 15:13:05 +0100254 else
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700255 setup_unisys();
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return es7000_plat;
258}
259
Natalie.Protasevich@unisys.come5428ed2006-03-23 02:59:36 -0800260#ifdef CONFIG_ACPI
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600261static int __init find_unisys_acpi_oem_table(unsigned long *oem_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300263 struct acpi_table_header *header = NULL;
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100264 struct es7000_oem_table *table;
Yinghai Lub825e6c2009-02-07 15:39:41 -0800265 acpi_size tbl_size;
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100266 acpi_status ret;
267 int i = 0;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700268
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100269 for (;;) {
270 ret = acpi_get_table_with_size("OEM1", i++, &header, &tbl_size);
271 if (!ACPI_SUCCESS(ret))
272 return -1;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700273
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100274 if (!memcmp((char *) &header->oem_id, "UNISYS", 6))
275 break;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700276
Yinghai Lub825e6c2009-02-07 15:39:41 -0800277 early_acpi_os_unmap_memory(header, tbl_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100279
280 table = (void *)header;
281
282 oem_addrX = table->OEMTableAddr;
283 oem_size = table->OEMTableSize;
284
285 early_acpi_os_unmap_memory(header, tbl_size);
286
287 *oem_addr = (unsigned long)__acpi_map_table(oem_addrX, oem_size);
288
289 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
Yinghai Lua73aaed2008-09-14 02:33:14 -0700291
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600292static void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr)
Yinghai Lua73aaed2008-09-14 02:33:14 -0700293{
Yinghai Lub825e6c2009-02-07 15:39:41 -0800294 if (!oem_addr)
295 return;
296
297 __acpi_unmap_table((char *)oem_addr, oem_size);
Yinghai Lua73aaed2008-09-14 02:33:14 -0700298}
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100299
300static int es7000_check_dsdt(void)
301{
302 struct acpi_table_header header;
303
304 if (ACPI_SUCCESS(acpi_get_table_header(ACPI_SIG_DSDT, 0, &header)) &&
305 !strncmp(header.oem_id, "UNISYS", 6))
306 return 1;
307 return 0;
308}
309
Jiri Slaby871d78c2009-03-02 11:34:27 +0100310static int es7000_acpi_ret;
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800311
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100312/* Hook from generic ACPI tables.c */
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600313static int __init es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100314{
315 unsigned long oem_addr = 0;
316 int check_dsdt;
317 int ret = 0;
318
319 /* check dsdt at first to avoid clear fix_map for oem_addr */
320 check_dsdt = es7000_check_dsdt();
321
322 if (!find_unisys_acpi_oem_table(&oem_addr)) {
323 if (check_dsdt) {
324 ret = parse_unisys_oem((char *)oem_addr);
325 } else {
326 setup_unisys();
327 ret = 1;
328 }
329 /*
330 * we need to unmap it
331 */
332 unmap_unisys_acpi_oem_table(oem_addr);
333 }
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800334
335 es7000_acpi_ret = ret;
336
337 return ret && !es7000_apic_is_cluster();
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100338}
Ingo Molnar3b900d42009-02-26 14:34:08 +0100339
Jiri Slaby871d78c2009-03-02 11:34:27 +0100340static int es7000_acpi_madt_oem_check_cluster(char *oem_id, char *oem_table_id)
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800341{
342 int ret = es7000_acpi_ret;
343
344 return ret && es7000_apic_is_cluster();
345}
346
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100347#else /* !CONFIG_ACPI: */
Jiri Slaby871d78c2009-03-02 11:34:27 +0100348static int es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100349{
350 return 0;
351}
Ingo Molnar3b900d42009-02-26 14:34:08 +0100352
Jiri Slaby871d78c2009-03-02 11:34:27 +0100353static int es7000_acpi_madt_oem_check_cluster(char *oem_id, char *oem_table_id)
Ingo Molnar3b900d42009-02-26 14:34:08 +0100354{
355 return 0;
356}
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100357#endif /* !CONFIG_ACPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100359static void es7000_spin(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 int i = 0;
362
363 while (i++ < n)
364 rep_nop();
365}
366
Jiri Slaby871d78c2009-03-02 11:34:27 +0100367static int es7000_mip_write(struct mip_reg *mip_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100369 int status = 0;
370 int spin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 spin = MIP_SPIN;
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100373 while ((host_reg->off_0x38 & MIP_VALID) != 0) {
374 if (--spin <= 0) {
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100375 WARN(1, "Timeout waiting for Host Valid Flag\n");
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100376 return -1;
377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 es7000_spin(MIP_SPIN);
379 }
380
381 memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
382 outb(1, mip_port);
383
384 spin = MIP_SPIN;
385
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100386 while ((mip_reg->off_0x38 & MIP_VALID) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (--spin <= 0) {
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100388 WARN(1, "Timeout waiting for MIP Valid Flag\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 return -1;
390 }
391 es7000_spin(MIP_SPIN);
392 }
393
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100394 status = (mip_reg->off_0x00 & 0xffff0000000000ULL) >> 48;
395 mip_reg->off_0x38 &= ~MIP_VALID;
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return status;
398}
399
Jiri Slaby871d78c2009-03-02 11:34:27 +0100400static void es7000_enable_apic_mode(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100402 struct mip_reg es7000_mip_reg;
403 int mip_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100405 if (!es7000_plat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return;
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100407
Joe Perches5cd476e2009-12-09 10:45:33 -0800408 pr_info("Enabling APIC mode.\n");
Ingo Molnar352887d2009-02-17 15:17:55 +0100409 memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
410 es7000_mip_reg.off_0x00 = MIP_SW_APIC;
411 es7000_mip_reg.off_0x38 = MIP_VALID;
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100412
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100413 while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
414 WARN(1, "Command failed, status = %x\n", mip_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
Ingo Molnar2e096df2009-01-28 19:01:05 +0100416
Rusty Russell73e907d2009-03-13 14:49:57 +1030417static void es7000_vector_allocation_domain(int cpu, struct cpumask *retmask)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100418{
419 /* Careful. Some cpus do not strictly honor the set of cpus
420 * specified in the interrupt destination when using lowest
421 * priority interrupt delivery mode.
422 *
423 * In particular there was a hyperthreading cpu observed to
424 * deliver interrupts to the wrong hyperthread when only one
425 * hyperthread was specified in the interrupt desitination.
426 */
Rusty Russell5c6cb5e2009-03-13 14:49:56 +1030427 cpumask_clear(retmask);
428 cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100429}
430
431
432static void es7000_wait_for_init_deassert(atomic_t *deassert)
433{
Ingo Molnar2e096df2009-01-28 19:01:05 +0100434 while (!atomic_read(deassert))
435 cpu_relax();
Ingo Molnar2e096df2009-01-28 19:01:05 +0100436}
437
438static unsigned int es7000_get_apic_id(unsigned long x)
439{
440 return (x >> 24) & 0xFF;
441}
442
Ingo Molnar2e096df2009-01-28 19:01:05 +0100443static void es7000_send_IPI_mask(const struct cpumask *mask, int vector)
444{
Yinghai Lu43f39892009-01-29 19:31:49 -0800445 default_send_IPI_mask_sequence_phys(mask, vector);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100446}
447
448static void es7000_send_IPI_allbutself(int vector)
449{
Yinghai Lu43f39892009-01-29 19:31:49 -0800450 default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100451}
452
453static void es7000_send_IPI_all(int vector)
454{
455 es7000_send_IPI_mask(cpu_online_mask, vector);
456}
457
458static int es7000_apic_id_registered(void)
459{
Ingo Molnar352887d2009-02-17 15:17:55 +0100460 return 1;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100461}
462
Rusty Russell73e907d2009-03-13 14:49:57 +1030463static const struct cpumask *target_cpus_cluster(void)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100464{
Rusty Russell101aaca2009-03-13 14:49:47 +1030465 return cpu_all_mask;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100466}
467
Rusty Russell4f062892009-03-13 14:49:54 +1030468static const struct cpumask *es7000_target_cpus(void)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100469{
Rusty Russell4f062892009-03-13 14:49:54 +1030470 return cpumask_of(smp_processor_id());
Ingo Molnar2e096df2009-01-28 19:01:05 +0100471}
472
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300473static unsigned long es7000_check_apicid_used(physid_mask_t *map, int apicid)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100474{
475 return 0;
476}
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300477
Ingo Molnar2e096df2009-01-28 19:01:05 +0100478static unsigned long es7000_check_apicid_present(int bit)
479{
480 return physid_isset(bit, phys_cpu_present_map);
481}
482
483static unsigned long calculate_ldr(int cpu)
484{
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100485 unsigned long id = per_cpu(x86_bios_cpu_apicid, cpu);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100486
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100487 return SET_APIC_LOGICAL_ID(id);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100488}
489
490/*
491 * Set up the logical destination ID.
492 *
493 * Intel recommends to set DFR, LdR and TPR before enabling
494 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
495 * document number 292116). So here it goes...
496 */
497static void es7000_init_apic_ldr_cluster(void)
498{
499 unsigned long val;
500 int cpu = smp_processor_id();
501
Ingo Molnar352887d2009-02-17 15:17:55 +0100502 apic_write(APIC_DFR, APIC_DFR_CLUSTER);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100503 val = calculate_ldr(cpu);
504 apic_write(APIC_LDR, val);
505}
506
507static void es7000_init_apic_ldr(void)
508{
509 unsigned long val;
510 int cpu = smp_processor_id();
511
Ingo Molnar352887d2009-02-17 15:17:55 +0100512 apic_write(APIC_DFR, APIC_DFR_FLAT);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100513 val = calculate_ldr(cpu);
514 apic_write(APIC_LDR, val);
515}
516
517static void es7000_setup_apic_routing(void)
518{
519 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100520
Joe Perches5cd476e2009-12-09 10:45:33 -0800521 pr_info("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
Ingo Molnar2e096df2009-01-28 19:01:05 +0100522 (apic_version[apic] == 0x14) ?
523 "Physical Cluster" : "Logical Cluster",
Rusty Russell4f062892009-03-13 14:49:54 +1030524 nr_ioapics, cpumask_bits(es7000_target_cpus())[0]);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100525}
526
527static int es7000_apicid_to_node(int logical_apicid)
528{
529 return 0;
530}
531
532
533static int es7000_cpu_present_to_apicid(int mps_cpu)
534{
535 if (!mps_cpu)
536 return boot_cpu_physical_apicid;
537 else if (mps_cpu < nr_cpu_ids)
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100538 return per_cpu(x86_bios_cpu_apicid, mps_cpu);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100539 else
540 return BAD_APICID;
541}
542
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100543static int cpu_id;
544
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300545static void es7000_apicid_to_cpu_present(int phys_apicid, physid_mask_t *retmap)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100546{
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300547 physid_set_mask_of_physid(cpu_id, retmap);
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100548 ++cpu_id;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100549}
550
551/* Mapping from cpu number to logical apicid */
552static int es7000_cpu_to_logical_apicid(int cpu)
553{
554#ifdef CONFIG_SMP
555 if (cpu >= nr_cpu_ids)
556 return BAD_APICID;
Ingo Molnar2f205bc2009-02-17 14:45:30 +0100557 return cpu_2_logical_apicid[cpu];
Ingo Molnar2e096df2009-01-28 19:01:05 +0100558#else
559 return logical_smp_processor_id();
560#endif
561}
562
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300563static void es7000_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100564{
565 /* For clustered we don't have a good way to do this yet - hack */
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +0300566 physids_promote(0xFFL, retmap);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100567}
568
569static int es7000_check_phys_apicid_present(int cpu_physical_apicid)
570{
571 boot_cpu_physical_apicid = read_apic_id();
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100572 return 1;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100573}
574
Rusty Russell73e907d2009-03-13 14:49:57 +1030575static unsigned int es7000_cpu_mask_to_apicid(const struct cpumask *cpumask)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100576{
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100577 unsigned int round = 0;
578 int cpu, uninitialized_var(apicid);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100579
Ingo Molnar2e096df2009-01-28 19:01:05 +0100580 /*
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100581 * The cpus in the mask must all be on the apic cluster.
Ingo Molnar2e096df2009-01-28 19:01:05 +0100582 */
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100583 for_each_cpu(cpu, cpumask) {
584 int new_apicid = es7000_cpu_to_logical_apicid(cpu);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100585
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100586 if (round && APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) {
587 WARN(1, "Not a valid mask!");
Ingo Molnar2e096df2009-01-28 19:01:05 +0100588
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100589 return BAD_APICID;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100590 }
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100591 apicid = new_apicid;
592 round++;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100593 }
594 return apicid;
595}
596
597static unsigned int
598es7000_cpu_mask_to_apicid_and(const struct cpumask *inmask,
599 const struct cpumask *andmask)
600{
601 int apicid = es7000_cpu_to_logical_apicid(0);
602 cpumask_var_t cpumask;
603
604 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
605 return apicid;
606
607 cpumask_and(cpumask, inmask, andmask);
608 cpumask_and(cpumask, cpumask, cpu_online_mask);
609 apicid = es7000_cpu_mask_to_apicid(cpumask);
610
611 free_cpumask_var(cpumask);
612
613 return apicid;
614}
615
616static int es7000_phys_pkg_id(int cpuid_apic, int index_msb)
617{
618 return cpuid_apic >> index_msb;
619}
620
Ingo Molnar2e096df2009-01-28 19:01:05 +0100621static int probe_es7000(void)
622{
623 /* probed later in mptable/ACPI hooks */
624 return 0;
625}
626
Jiri Slaby871d78c2009-03-02 11:34:27 +0100627static int es7000_mps_ret;
628static int es7000_mps_oem_check(struct mpc_table *mpc, char *oem,
629 char *productid)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100630{
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800631 int ret = 0;
632
Ingo Molnar2e096df2009-01-28 19:01:05 +0100633 if (mpc->oemptr) {
634 struct mpc_oemtable *oem_table =
635 (struct mpc_oemtable *)mpc->oemptr;
636
637 if (!strncmp(oem, "UNISYS", 6))
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800638 ret = parse_unisys_oem((char *)oem_table);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100639 }
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800640
641 es7000_mps_ret = ret;
642
643 return ret && !es7000_apic_is_cluster();
Ingo Molnar2e096df2009-01-28 19:01:05 +0100644}
645
Jiri Slaby871d78c2009-03-02 11:34:27 +0100646static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
647 char *productid)
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800648{
649 int ret = es7000_mps_ret;
650
651 return ret && es7000_apic_is_cluster();
652}
653
Rakib Mullick151586d2009-07-12 17:04:12 +0600654/* We've been warned by a false positive warning.Use __refdata to keep calm. */
655struct apic __refdata apic_es7000_cluster = {
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800656
657 .name = "es7000",
658 .probe = probe_es7000,
659 .acpi_madt_oem_check = es7000_acpi_madt_oem_check_cluster,
660 .apic_id_registered = es7000_apic_id_registered,
661
662 .irq_delivery_mode = dest_LowestPrio,
663 /* logical delivery broadcast to all procs: */
664 .irq_dest_mode = 1,
665
666 .target_cpus = target_cpus_cluster,
667 .disable_esr = 1,
668 .dest_logical = 0,
669 .check_apicid_used = es7000_check_apicid_used,
670 .check_apicid_present = es7000_check_apicid_present,
671
672 .vector_allocation_domain = es7000_vector_allocation_domain,
673 .init_apic_ldr = es7000_init_apic_ldr_cluster,
674
675 .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
676 .setup_apic_routing = es7000_setup_apic_routing,
677 .multi_timer_check = NULL,
678 .apicid_to_node = es7000_apicid_to_node,
679 .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid,
680 .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
681 .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
682 .setup_portio_remap = NULL,
683 .check_phys_apicid_present = es7000_check_phys_apicid_present,
684 .enable_apic_mode = es7000_enable_apic_mode,
685 .phys_pkg_id = es7000_phys_pkg_id,
686 .mps_oem_check = es7000_mps_oem_check_cluster,
687
688 .get_apic_id = es7000_get_apic_id,
689 .set_apic_id = NULL,
690 .apic_id_mask = 0xFF << 24,
691
Jiri Slabyc2b20cb2009-03-02 10:53:56 +0100692 .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid,
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800693 .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
694
695 .send_IPI_mask = es7000_send_IPI_mask,
696 .send_IPI_mask_allbutself = NULL,
697 .send_IPI_allbutself = es7000_send_IPI_allbutself,
698 .send_IPI_all = es7000_send_IPI_all,
699 .send_IPI_self = default_send_IPI_self,
700
Ingo Molnar1f5bcab2009-02-26 13:51:40 +0100701 .wakeup_secondary_cpu = wakeup_secondary_cpu_via_mip,
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800702
703 .trampoline_phys_low = 0x467,
704 .trampoline_phys_high = 0x469,
705
706 .wait_for_init_deassert = NULL,
707
708 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
709 .smp_callin_clear_local_apic = NULL,
710 .inquire_remote_apic = default_inquire_remote_apic,
711
712 .read = native_apic_mem_read,
713 .write = native_apic_mem_write,
714 .icr_read = native_apic_icr_read,
715 .icr_write = native_apic_icr_write,
716 .wait_icr_idle = native_apic_wait_icr_idle,
717 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
718};
Ingo Molnar2e096df2009-01-28 19:01:05 +0100719
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600720struct apic __refdata apic_es7000 = {
Ingo Molnar2e096df2009-01-28 19:01:05 +0100721
722 .name = "es7000",
723 .probe = probe_es7000,
724 .acpi_madt_oem_check = es7000_acpi_madt_oem_check,
725 .apic_id_registered = es7000_apic_id_registered,
726
727 .irq_delivery_mode = dest_Fixed,
728 /* phys delivery to target CPUs: */
729 .irq_dest_mode = 0,
730
731 .target_cpus = es7000_target_cpus,
732 .disable_esr = 1,
733 .dest_logical = 0,
734 .check_apicid_used = es7000_check_apicid_used,
735 .check_apicid_present = es7000_check_apicid_present,
736
737 .vector_allocation_domain = es7000_vector_allocation_domain,
738 .init_apic_ldr = es7000_init_apic_ldr,
739
740 .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
741 .setup_apic_routing = es7000_setup_apic_routing,
742 .multi_timer_check = NULL,
743 .apicid_to_node = es7000_apicid_to_node,
744 .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid,
745 .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
746 .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
747 .setup_portio_remap = NULL,
748 .check_phys_apicid_present = es7000_check_phys_apicid_present,
749 .enable_apic_mode = es7000_enable_apic_mode,
750 .phys_pkg_id = es7000_phys_pkg_id,
751 .mps_oem_check = es7000_mps_oem_check,
752
753 .get_apic_id = es7000_get_apic_id,
754 .set_apic_id = NULL,
755 .apic_id_mask = 0xFF << 24,
756
757 .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid,
758 .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
759
760 .send_IPI_mask = es7000_send_IPI_mask,
761 .send_IPI_mask_allbutself = NULL,
762 .send_IPI_allbutself = es7000_send_IPI_allbutself,
763 .send_IPI_all = es7000_send_IPI_all,
Ingo Molnar6b64ee02009-01-30 23:42:18 +0100764 .send_IPI_self = default_send_IPI_self,
Ingo Molnar2e096df2009-01-28 19:01:05 +0100765
Ingo Molnar2e096df2009-01-28 19:01:05 +0100766 .trampoline_phys_low = 0x467,
767 .trampoline_phys_high = 0x469,
768
769 .wait_for_init_deassert = es7000_wait_for_init_deassert,
770
771 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
772 .smp_callin_clear_local_apic = NULL,
Ingo Molnar2e096df2009-01-28 19:01:05 +0100773 .inquire_remote_apic = default_inquire_remote_apic,
Yinghai Luc1eeb2d2009-02-16 23:02:14 -0800774
775 .read = native_apic_mem_read,
776 .write = native_apic_mem_write,
777 .icr_read = native_apic_icr_read,
778 .icr_write = native_apic_icr_write,
779 .wait_icr_idle = native_apic_wait_icr_idle,
780 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
Ingo Molnar2e096df2009-01-28 19:01:05 +0100781};