blob: 89174f847b49effb88961e01c6e526f3809ae690 [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/notifier.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010031#include <linux/spinlock.h>
32#include <linux/cpumask.h>
33#include <linux/threads.h>
34#include <linux/kernel.h>
35#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/reboot.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010037#include <linux/string.h>
38#include <linux/types.h>
39#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/acpi.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010041#include <linux/init.h>
Ingo Molnar7da18ed2009-02-17 15:29:30 +010042#include <linux/nmi.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010043#include <linux/smp.h>
Ingo Molnar7da18ed2009-02-17 15:29:30 +010044#include <linux/io.h>
Ingo Molnar2c4ce182009-02-17 14:57:16 +010045
46#include <asm/apicdef.h>
47#include <asm/atomic.h>
48#include <asm/fixmap.h>
49#include <asm/mpspec.h>
50#include <asm/setup.h>
51#include <asm/apic.h>
52#include <asm/ipi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*
Yinghai Lu16253242008-08-27 23:01:16 -070055 * ES7000 chipsets
56 */
57
Ingo Molnar2c4ce182009-02-17 14:57:16 +010058#define NON_UNISYS 0
59#define ES7000_CLASSIC 1
60#define ES7000_ZORRO 2
Yinghai Lu16253242008-08-27 23:01:16 -070061
Ingo Molnar2c4ce182009-02-17 14:57:16 +010062#define MIP_REG 1
63#define MIP_PSAI_REG 4
Yinghai Lu16253242008-08-27 23:01:16 -070064
Ingo Molnar2c4ce182009-02-17 14:57:16 +010065#define MIP_BUSY 1
66#define MIP_SPIN 0xf0000
67#define MIP_VALID 0x0100000000000000ULL
Ingo Molnar352887d2009-02-17 15:17:55 +010068#define MIP_SW_APIC 0x1020b
Yinghai Lu16253242008-08-27 23:01:16 -070069
Ingo Molnar2c4ce182009-02-17 14:57:16 +010070#define MIP_PORT(val) ((val >> 32) & 0xffff)
Yinghai Lu16253242008-08-27 23:01:16 -070071
Ingo Molnar2c4ce182009-02-17 14:57:16 +010072#define MIP_RD_LO(val) (val & 0xffffffff)
Yinghai Lu16253242008-08-27 23:01:16 -070073
Yinghai Lu16253242008-08-27 23:01:16 -070074struct mip_reg {
Ingo Molnar2c4ce182009-02-17 14:57:16 +010075 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;
Yinghai Lu16253242008-08-27 23:01:16 -070083};
84
Ingo Molnar352887d2009-02-17 15:17:55 +010085struct mip_reg_info {
86 unsigned long long mip_info;
87 unsigned long long delivery_info;
88 unsigned long long host_reg;
89 unsigned long long mip_reg;
90};
Ingo Molnar2c4ce182009-02-17 14:57:16 +010091
Ingo Molnar352887d2009-02-17 15:17:55 +010092struct psai {
93 unsigned long long entry_type;
94 unsigned long long addr;
95 unsigned long long bep_addr;
96};
Ingo Molnar2c4ce182009-02-17 14:57:16 +010097
Ingo Molnar352887d2009-02-17 15:17:55 +010098#ifdef CONFIG_ACPI
Ingo Molnar7da18ed2009-02-17 15:29:30 +010099
Ingo Molnar352887d2009-02-17 15:17:55 +0100100struct es7000_oem_table {
101 struct acpi_table_header Header;
102 u32 OEMTableAddr;
103 u32 OEMTableSize;
104};
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100105
106static unsigned long oem_addrX;
107static unsigned long oem_size;
108
Ingo Molnar352887d2009-02-17 15:17:55 +0100109#endif
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100110
Yinghai Lu16253242008-08-27 23:01:16 -0700111/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * ES7000 Globals
113 */
114
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100115static volatile unsigned long *psai;
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100116static struct mip_reg *mip_reg;
117static struct mip_reg *host_reg;
118static int mip_port;
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100119static unsigned long mip_addr;
120static unsigned long host_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100122int es7000_plat;
Alexey Starikovskiy32c50612008-05-14 19:02:51 +0400123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/*
125 * GSI override for ES7000 platforms.
126 */
127
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100128static unsigned int base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130static int
131es7000_rename_gsi(int ioapic, int gsi)
132{
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800133 if (es7000_plat == ES7000_ZORRO)
134 return gsi;
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (!base) {
137 int i;
138 for (i = 0; i < nr_ioapics; i++)
139 base += nr_ioapic_registers[i];
140 }
141
Yinghai Luc7e79642008-07-25 02:17:33 -0700142 if (!ioapic && (gsi < 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 gsi += base;
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return gsi;
146}
147
Cyrill Gorcunov667c5292009-04-19 11:43:11 +0400148static int __cpuinit wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
Yinghai Lu569712b2008-11-16 03:12:49 -0800149{
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}
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800165
Jiri Slaby871d78c2009-03-02 11:34:27 +0100166static int es7000_apic_is_cluster(void)
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800167{
Yinghai Lub5fe3632008-11-18 08:14:14 -0800168 /* MPENTIUMIII */
169 if (boot_cpu_data.x86 == 6 &&
Roel Kluin005155b2009-08-25 15:35:12 +0200170 (boot_cpu_data.x86_model >= 7 && boot_cpu_data.x86_model <= 11))
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800171 return 1;
Yinghai Lub5fe3632008-11-18 08:14:14 -0800172
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800173 return 0;
174}
Yinghai Lu569712b2008-11-16 03:12:49 -0800175
Jiri Slaby871d78c2009-03-02 11:34:27 +0100176static void setup_unisys(void)
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700177{
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))
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800186 es7000_plat = ES7000_ZORRO;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700187 else
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800188 es7000_plat = ES7000_CLASSIC;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700189 ioapic_renumber_irq = es7000_rename_gsi;
190}
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192/*
Ingo Molnard3185b32009-02-17 15:13:05 +0100193 * Parse the OEM Table:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 */
Jiri Slaby871d78c2009-03-02 11:34:27 +0100195static int parse_unisys_oem(char *oemptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Ingo Molnar352887d2009-02-17 15:17:55 +0100197 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 int success = 0;
Ingo Molnar352887d2009-02-17 15:17:55 +0100199 unsigned char type, size;
200 unsigned long val;
201 char *tp = NULL;
202 struct psai *psaip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 struct mip_reg_info *mi;
204 struct mip_reg *host, *mip;
205
206 tp = oemptr;
207
208 tp += 8;
209
Ingo Molnar352887d2009-02-17 15:17:55 +0100210 for (i = 0; i <= 6; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 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);
Thomas Gleixner5171c302008-07-21 21:58:34 +0200226 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 tp += size;
246 }
247
Ingo Molnard3185b32009-02-17 15:13:05 +0100248 if (success < 2)
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800249 es7000_plat = NON_UNISYS;
Ingo Molnard3185b32009-02-17 15:13:05 +0100250 else
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700251 setup_unisys();
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return es7000_plat;
254}
255
Natalie.Protasevich@unisys.come5428ed2006-03-23 02:59:36 -0800256#ifdef CONFIG_ACPI
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600257static int __init find_unisys_acpi_oem_table(unsigned long *oem_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300259 struct acpi_table_header *header = NULL;
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100260 struct es7000_oem_table *table;
Yinghai Lub825e6c2009-02-07 15:39:41 -0800261 acpi_size tbl_size;
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100262 acpi_status ret;
263 int i = 0;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700264
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100265 for (;;) {
266 ret = acpi_get_table_with_size("OEM1", i++, &header, &tbl_size);
267 if (!ACPI_SUCCESS(ret))
268 return -1;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700269
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100270 if (!memcmp((char *) &header->oem_id, "UNISYS", 6))
271 break;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700272
Yinghai Lub825e6c2009-02-07 15:39:41 -0800273 early_acpi_os_unmap_memory(header, tbl_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100275
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
Yinghai Lua73aaed2008-09-14 02:33:14 -0700287
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600288static void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr)
Yinghai Lua73aaed2008-09-14 02:33:14 -0700289{
Yinghai Lub825e6c2009-02-07 15:39:41 -0800290 if (!oem_addr)
291 return;
292
293 __acpi_unmap_table((char *)oem_addr, oem_size);
Yinghai Lua73aaed2008-09-14 02:33:14 -0700294}
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100295
296static 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
Jiri Slaby871d78c2009-03-02 11:34:27 +0100306static int es7000_acpi_ret;
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800307
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100308/* Hook from generic ACPI tables.c */
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600309static int __init es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100310{
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 }
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800330
331 es7000_acpi_ret = ret;
332
333 return ret && !es7000_apic_is_cluster();
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100334}
Ingo Molnar3b900d42009-02-26 14:34:08 +0100335
Jiri Slaby871d78c2009-03-02 11:34:27 +0100336static int es7000_acpi_madt_oem_check_cluster(char *oem_id, char *oem_table_id)
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800337{
338 int ret = es7000_acpi_ret;
339
340 return ret && es7000_apic_is_cluster();
341}
342
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100343#else /* !CONFIG_ACPI: */
Jiri Slaby871d78c2009-03-02 11:34:27 +0100344static int es7000_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100345{
346 return 0;
347}
Ingo Molnar3b900d42009-02-26 14:34:08 +0100348
Jiri Slaby871d78c2009-03-02 11:34:27 +0100349static int es7000_acpi_madt_oem_check_cluster(char *oem_id, char *oem_table_id)
Ingo Molnar3b900d42009-02-26 14:34:08 +0100350{
351 return 0;
352}
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100353#endif /* !CONFIG_ACPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100355static void es7000_spin(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 int i = 0;
358
359 while (i++ < n)
360 rep_nop();
361}
362
Jiri Slaby871d78c2009-03-02 11:34:27 +0100363static int es7000_mip_write(struct mip_reg *mip_reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100365 int status = 0;
366 int spin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 spin = MIP_SPIN;
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100369 while ((host_reg->off_0x38 & MIP_VALID) != 0) {
370 if (--spin <= 0) {
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100371 WARN(1, "Timeout waiting for Host Valid Flag\n");
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100372 return -1;
373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 es7000_spin(MIP_SPIN);
375 }
376
377 memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
378 outb(1, mip_port);
379
380 spin = MIP_SPIN;
381
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100382 while ((mip_reg->off_0x38 & MIP_VALID) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (--spin <= 0) {
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100384 WARN(1, "Timeout waiting for MIP Valid Flag\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return -1;
386 }
387 es7000_spin(MIP_SPIN);
388 }
389
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100390 status = (mip_reg->off_0x00 & 0xffff0000000000ULL) >> 48;
391 mip_reg->off_0x38 &= ~MIP_VALID;
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return status;
394}
395
Jiri Slaby871d78c2009-03-02 11:34:27 +0100396static void es7000_enable_apic_mode(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100398 struct mip_reg es7000_mip_reg;
399 int mip_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100401 if (!es7000_plat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return;
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100403
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100404 printk(KERN_INFO "ES7000: Enabling APIC mode.\n");
Ingo Molnar352887d2009-02-17 15:17:55 +0100405 memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
406 es7000_mip_reg.off_0x00 = MIP_SW_APIC;
407 es7000_mip_reg.off_0x38 = MIP_VALID;
Ingo Molnarb0b20e52009-01-28 13:15:06 +0100408
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100409 while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
410 WARN(1, "Command failed, status = %x\n", mip_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
Ingo Molnar2e096df2009-01-28 19:01:05 +0100412
Rusty Russell73e907d2009-03-13 14:49:57 +1030413static void es7000_vector_allocation_domain(int cpu, struct cpumask *retmask)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100414{
415 /* Careful. Some cpus do not strictly honor the set of cpus
416 * specified in the interrupt destination when using lowest
417 * priority interrupt delivery mode.
418 *
419 * In particular there was a hyperthreading cpu observed to
420 * deliver interrupts to the wrong hyperthread when only one
421 * hyperthread was specified in the interrupt desitination.
422 */
Rusty Russell5c6cb5e2009-03-13 14:49:56 +1030423 cpumask_clear(retmask);
424 cpumask_bits(retmask)[0] = APIC_ALL_CPUS;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100425}
426
427
428static void es7000_wait_for_init_deassert(atomic_t *deassert)
429{
Ingo Molnar2e096df2009-01-28 19:01:05 +0100430 while (!atomic_read(deassert))
431 cpu_relax();
Ingo Molnar2e096df2009-01-28 19:01:05 +0100432}
433
434static unsigned int es7000_get_apic_id(unsigned long x)
435{
436 return (x >> 24) & 0xFF;
437}
438
Ingo Molnar2e096df2009-01-28 19:01:05 +0100439static void es7000_send_IPI_mask(const struct cpumask *mask, int vector)
440{
Yinghai Lu43f39892009-01-29 19:31:49 -0800441 default_send_IPI_mask_sequence_phys(mask, vector);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100442}
443
444static void es7000_send_IPI_allbutself(int vector)
445{
Yinghai Lu43f39892009-01-29 19:31:49 -0800446 default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100447}
448
449static void es7000_send_IPI_all(int vector)
450{
451 es7000_send_IPI_mask(cpu_online_mask, vector);
452}
453
454static int es7000_apic_id_registered(void)
455{
Ingo Molnar352887d2009-02-17 15:17:55 +0100456 return 1;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100457}
458
Rusty Russell73e907d2009-03-13 14:49:57 +1030459static const struct cpumask *target_cpus_cluster(void)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100460{
Rusty Russell101aaca2009-03-13 14:49:47 +1030461 return cpu_all_mask;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100462}
463
Rusty Russell4f062892009-03-13 14:49:54 +1030464static const struct cpumask *es7000_target_cpus(void)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100465{
Rusty Russell4f062892009-03-13 14:49:54 +1030466 return cpumask_of(smp_processor_id());
Ingo Molnar2e096df2009-01-28 19:01:05 +0100467}
468
469static unsigned long
470es7000_check_apicid_used(physid_mask_t bitmap, int apicid)
471{
472 return 0;
473}
474static unsigned long es7000_check_apicid_present(int bit)
475{
476 return physid_isset(bit, phys_cpu_present_map);
477}
478
479static unsigned long calculate_ldr(int cpu)
480{
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100481 unsigned long id = per_cpu(x86_bios_cpu_apicid, cpu);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100482
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100483 return SET_APIC_LOGICAL_ID(id);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100484}
485
486/*
487 * Set up the logical destination ID.
488 *
489 * Intel recommends to set DFR, LdR and TPR before enabling
490 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
491 * document number 292116). So here it goes...
492 */
493static void es7000_init_apic_ldr_cluster(void)
494{
495 unsigned long val;
496 int cpu = smp_processor_id();
497
Ingo Molnar352887d2009-02-17 15:17:55 +0100498 apic_write(APIC_DFR, APIC_DFR_CLUSTER);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100499 val = calculate_ldr(cpu);
500 apic_write(APIC_LDR, val);
501}
502
503static void es7000_init_apic_ldr(void)
504{
505 unsigned long val;
506 int cpu = smp_processor_id();
507
Ingo Molnar352887d2009-02-17 15:17:55 +0100508 apic_write(APIC_DFR, APIC_DFR_FLAT);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100509 val = calculate_ldr(cpu);
510 apic_write(APIC_LDR, val);
511}
512
513static void es7000_setup_apic_routing(void)
514{
515 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100516
517 printk(KERN_INFO
518 "Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
Ingo Molnar2e096df2009-01-28 19:01:05 +0100519 (apic_version[apic] == 0x14) ?
520 "Physical Cluster" : "Logical Cluster",
Rusty Russell4f062892009-03-13 14:49:54 +1030521 nr_ioapics, cpumask_bits(es7000_target_cpus())[0]);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100522}
523
524static int es7000_apicid_to_node(int logical_apicid)
525{
526 return 0;
527}
528
529
530static int es7000_cpu_present_to_apicid(int mps_cpu)
531{
532 if (!mps_cpu)
533 return boot_cpu_physical_apicid;
534 else if (mps_cpu < nr_cpu_ids)
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100535 return per_cpu(x86_bios_cpu_apicid, mps_cpu);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100536 else
537 return BAD_APICID;
538}
539
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100540static int cpu_id;
541
Ingo Molnar2e096df2009-01-28 19:01:05 +0100542static physid_mask_t es7000_apicid_to_cpu_present(int phys_apicid)
543{
Ingo Molnar2e096df2009-01-28 19:01:05 +0100544 physid_mask_t mask;
545
Ingo Molnar7da18ed2009-02-17 15:29:30 +0100546 mask = physid_mask_of_physid(cpu_id);
547 ++cpu_id;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100548
549 return mask;
550}
551
552/* Mapping from cpu number to logical apicid */
553static int es7000_cpu_to_logical_apicid(int cpu)
554{
555#ifdef CONFIG_SMP
556 if (cpu >= nr_cpu_ids)
557 return BAD_APICID;
Ingo Molnar2f205bc2009-02-17 14:45:30 +0100558 return cpu_2_logical_apicid[cpu];
Ingo Molnar2e096df2009-01-28 19:01:05 +0100559#else
560 return logical_smp_processor_id();
561#endif
562}
563
564static physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map)
565{
566 /* For clustered we don't have a good way to do this yet - hack */
567 return physids_promote(0xff);
568}
569
570static int es7000_check_phys_apicid_present(int cpu_physical_apicid)
571{
572 boot_cpu_physical_apicid = read_apic_id();
Ingo Molnar2c4ce182009-02-17 14:57:16 +0100573 return 1;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100574}
575
Rusty Russell73e907d2009-03-13 14:49:57 +1030576static unsigned int es7000_cpu_mask_to_apicid(const struct cpumask *cpumask)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100577{
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100578 unsigned int round = 0;
579 int cpu, uninitialized_var(apicid);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100580
Ingo Molnar2e096df2009-01-28 19:01:05 +0100581 /*
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100582 * The cpus in the mask must all be on the apic cluster.
Ingo Molnar2e096df2009-01-28 19:01:05 +0100583 */
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100584 for_each_cpu(cpu, cpumask) {
585 int new_apicid = es7000_cpu_to_logical_apicid(cpu);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100586
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100587 if (round && APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) {
588 WARN(1, "Not a valid mask!");
Ingo Molnar2e096df2009-01-28 19:01:05 +0100589
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100590 return BAD_APICID;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100591 }
Jiri Slaby0edc0b32009-03-02 10:53:57 +0100592 apicid = new_apicid;
593 round++;
Ingo Molnar2e096df2009-01-28 19:01:05 +0100594 }
595 return apicid;
596}
597
598static unsigned int
599es7000_cpu_mask_to_apicid_and(const struct cpumask *inmask,
600 const struct cpumask *andmask)
601{
602 int apicid = es7000_cpu_to_logical_apicid(0);
603 cpumask_var_t cpumask;
604
605 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
606 return apicid;
607
608 cpumask_and(cpumask, inmask, andmask);
609 cpumask_and(cpumask, cpumask, cpu_online_mask);
610 apicid = es7000_cpu_mask_to_apicid(cpumask);
611
612 free_cpumask_var(cpumask);
613
614 return apicid;
615}
616
617static int es7000_phys_pkg_id(int cpuid_apic, int index_msb)
618{
619 return cpuid_apic >> index_msb;
620}
621
Ingo Molnar2e096df2009-01-28 19:01:05 +0100622static int probe_es7000(void)
623{
624 /* probed later in mptable/ACPI hooks */
625 return 0;
626}
627
Jiri Slaby871d78c2009-03-02 11:34:27 +0100628static int es7000_mps_ret;
629static int es7000_mps_oem_check(struct mpc_table *mpc, char *oem,
630 char *productid)
Ingo Molnar2e096df2009-01-28 19:01:05 +0100631{
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800632 int ret = 0;
633
Ingo Molnar2e096df2009-01-28 19:01:05 +0100634 if (mpc->oemptr) {
635 struct mpc_oemtable *oem_table =
636 (struct mpc_oemtable *)mpc->oemptr;
637
638 if (!strncmp(oem, "UNISYS", 6))
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800639 ret = parse_unisys_oem((char *)oem_table);
Ingo Molnar2e096df2009-01-28 19:01:05 +0100640 }
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800641
642 es7000_mps_ret = ret;
643
644 return ret && !es7000_apic_is_cluster();
Ingo Molnar2e096df2009-01-28 19:01:05 +0100645}
646
Jiri Slaby871d78c2009-03-02 11:34:27 +0100647static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
648 char *productid)
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800649{
650 int ret = es7000_mps_ret;
651
652 return ret && es7000_apic_is_cluster();
653}
654
Rakib Mullick151586d2009-07-12 17:04:12 +0600655/* We've been warned by a false positive warning.Use __refdata to keep calm. */
656struct apic __refdata apic_es7000_cluster = {
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800657
658 .name = "es7000",
659 .probe = probe_es7000,
660 .acpi_madt_oem_check = es7000_acpi_madt_oem_check_cluster,
661 .apic_id_registered = es7000_apic_id_registered,
662
663 .irq_delivery_mode = dest_LowestPrio,
664 /* logical delivery broadcast to all procs: */
665 .irq_dest_mode = 1,
666
667 .target_cpus = target_cpus_cluster,
668 .disable_esr = 1,
669 .dest_logical = 0,
670 .check_apicid_used = es7000_check_apicid_used,
671 .check_apicid_present = es7000_check_apicid_present,
672
673 .vector_allocation_domain = es7000_vector_allocation_domain,
674 .init_apic_ldr = es7000_init_apic_ldr_cluster,
675
676 .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
677 .setup_apic_routing = es7000_setup_apic_routing,
678 .multi_timer_check = NULL,
679 .apicid_to_node = es7000_apicid_to_node,
680 .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid,
681 .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
682 .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
683 .setup_portio_remap = NULL,
684 .check_phys_apicid_present = es7000_check_phys_apicid_present,
685 .enable_apic_mode = es7000_enable_apic_mode,
686 .phys_pkg_id = es7000_phys_pkg_id,
687 .mps_oem_check = es7000_mps_oem_check_cluster,
688
689 .get_apic_id = es7000_get_apic_id,
690 .set_apic_id = NULL,
691 .apic_id_mask = 0xFF << 24,
692
Jiri Slabyc2b20cb2009-03-02 10:53:56 +0100693 .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid,
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800694 .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
695
696 .send_IPI_mask = es7000_send_IPI_mask,
697 .send_IPI_mask_allbutself = NULL,
698 .send_IPI_allbutself = es7000_send_IPI_allbutself,
699 .send_IPI_all = es7000_send_IPI_all,
700 .send_IPI_self = default_send_IPI_self,
701
Ingo Molnar1f5bcab2009-02-26 13:51:40 +0100702 .wakeup_secondary_cpu = wakeup_secondary_cpu_via_mip,
Yinghai Lu2b6163b2009-02-25 20:50:49 -0800703
704 .trampoline_phys_low = 0x467,
705 .trampoline_phys_high = 0x469,
706
707 .wait_for_init_deassert = NULL,
708
709 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
710 .smp_callin_clear_local_apic = NULL,
711 .inquire_remote_apic = default_inquire_remote_apic,
712
713 .read = native_apic_mem_read,
714 .write = native_apic_mem_write,
715 .icr_read = native_apic_icr_read,
716 .icr_write = native_apic_icr_write,
717 .wait_icr_idle = native_apic_wait_icr_idle,
718 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
719};
Ingo Molnar2e096df2009-01-28 19:01:05 +0100720
Sam Ravnborgb74d4462009-05-09 15:35:10 +0600721struct apic __refdata apic_es7000 = {
Ingo Molnar2e096df2009-01-28 19:01:05 +0100722
723 .name = "es7000",
724 .probe = probe_es7000,
725 .acpi_madt_oem_check = es7000_acpi_madt_oem_check,
726 .apic_id_registered = es7000_apic_id_registered,
727
728 .irq_delivery_mode = dest_Fixed,
729 /* phys delivery to target CPUs: */
730 .irq_dest_mode = 0,
731
732 .target_cpus = es7000_target_cpus,
733 .disable_esr = 1,
734 .dest_logical = 0,
735 .check_apicid_used = es7000_check_apicid_used,
736 .check_apicid_present = es7000_check_apicid_present,
737
738 .vector_allocation_domain = es7000_vector_allocation_domain,
739 .init_apic_ldr = es7000_init_apic_ldr,
740
741 .ioapic_phys_id_map = es7000_ioapic_phys_id_map,
742 .setup_apic_routing = es7000_setup_apic_routing,
743 .multi_timer_check = NULL,
744 .apicid_to_node = es7000_apicid_to_node,
745 .cpu_to_logical_apicid = es7000_cpu_to_logical_apicid,
746 .cpu_present_to_apicid = es7000_cpu_present_to_apicid,
747 .apicid_to_cpu_present = es7000_apicid_to_cpu_present,
748 .setup_portio_remap = NULL,
749 .check_phys_apicid_present = es7000_check_phys_apicid_present,
750 .enable_apic_mode = es7000_enable_apic_mode,
751 .phys_pkg_id = es7000_phys_pkg_id,
752 .mps_oem_check = es7000_mps_oem_check,
753
754 .get_apic_id = es7000_get_apic_id,
755 .set_apic_id = NULL,
756 .apic_id_mask = 0xFF << 24,
757
758 .cpu_mask_to_apicid = es7000_cpu_mask_to_apicid,
759 .cpu_mask_to_apicid_and = es7000_cpu_mask_to_apicid_and,
760
761 .send_IPI_mask = es7000_send_IPI_mask,
762 .send_IPI_mask_allbutself = NULL,
763 .send_IPI_allbutself = es7000_send_IPI_allbutself,
764 .send_IPI_all = es7000_send_IPI_all,
Ingo Molnar6b64ee02009-01-30 23:42:18 +0100765 .send_IPI_self = default_send_IPI_self,
Ingo Molnar2e096df2009-01-28 19:01:05 +0100766
Ingo Molnar2e096df2009-01-28 19:01:05 +0100767 .trampoline_phys_low = 0x467,
768 .trampoline_phys_high = 0x469,
769
770 .wait_for_init_deassert = es7000_wait_for_init_deassert,
771
772 /* Nothing to do for most platforms, since cleared by the INIT cycle: */
773 .smp_callin_clear_local_apic = NULL,
Ingo Molnar2e096df2009-01-28 19:01:05 +0100774 .inquire_remote_apic = default_inquire_remote_apic,
Yinghai Luc1eeb2d2009-02-16 23:02:14 -0800775
776 .read = native_apic_mem_read,
777 .write = native_apic_mem_write,
778 .icr_read = native_apic_icr_read,
779 .icr_write = native_apic_icr_write,
780 .wait_icr_idle = native_apic_wait_icr_idle,
781 .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
Ingo Molnar2e096df2009-01-28 19:01:05 +0100782};