blob: fb3bfe66fbe291b98aeb6f2032afd3a83cbbccbb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Written by: Garry Forsgren, Unisys Corporation
3 * Natalie Protasevich, Unisys Corporation
4 * This file contains the code to configure and interface
5 * with Unisys ES7000 series hardware system manager.
6 *
7 * Copyright (c) 2003 Unisys Corporation. All Rights Reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it would be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
20 *
21 * Contact information: Unisys Corporation, Township Line & Union Meeting
22 * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or:
23 *
24 * http://www.unisys.com
25 */
26
27#include <linux/module.h>
28#include <linux/types.h>
29#include <linux/kernel.h>
30#include <linux/smp.h>
31#include <linux/string.h>
32#include <linux/spinlock.h>
33#include <linux/errno.h>
34#include <linux/notifier.h>
35#include <linux/reboot.h>
36#include <linux/init.h>
37#include <linux/acpi.h>
38#include <asm/io.h>
39#include <asm/nmi.h>
40#include <asm/smp.h>
41#include <asm/apicdef.h>
Vivek Goyal071922c2007-07-06 02:39:55 -070042#include <mach_mpparse.h>
Yinghai Lu54ac14a2008-11-17 15:19:53 -080043#include <asm/genapic.h>
Yinghai Lu569712b2008-11-16 03:12:49 -080044#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46/*
Yinghai Lu16253242008-08-27 23:01:16 -070047 * ES7000 chipsets
48 */
49
50#define NON_UNISYS 0
51#define ES7000_CLASSIC 1
52#define ES7000_ZORRO 2
53
54
55#define MIP_REG 1
56#define MIP_PSAI_REG 4
57
58#define MIP_BUSY 1
59#define MIP_SPIN 0xf0000
60#define MIP_VALID 0x0100000000000000ULL
61#define MIP_PORT(VALUE) ((VALUE >> 32) & 0xffff)
62
63#define MIP_RD_LO(VALUE) (VALUE & 0xffffffff)
64
65struct mip_reg_info {
66 unsigned long long mip_info;
67 unsigned long long delivery_info;
68 unsigned long long host_reg;
69 unsigned long long mip_reg;
70};
71
72struct part_info {
73 unsigned char type;
74 unsigned char length;
75 unsigned char part_id;
76 unsigned char apic_mode;
77 unsigned long snum;
78 char ptype[16];
79 char sname[64];
80 char pname[64];
81};
82
83struct psai {
84 unsigned long long entry_type;
85 unsigned long long addr;
86 unsigned long long bep_addr;
87};
88
89struct es7000_mem_info {
90 unsigned char type;
91 unsigned char length;
92 unsigned char resv[6];
93 unsigned long long start;
94 unsigned long long size;
95};
96
97struct es7000_oem_table {
98 unsigned long long hdr;
99 struct mip_reg_info mip;
100 struct part_info pif;
101 struct es7000_mem_info shm;
102 struct psai psai;
103};
104
105#ifdef CONFIG_ACPI
106
107struct oem_table {
108 struct acpi_table_header Header;
109 u32 OEMTableAddr;
110 u32 OEMTableSize;
111};
112
113extern int find_unisys_acpi_oem_table(unsigned long *oem_addr);
Yinghai Lua73aaed2008-09-14 02:33:14 -0700114extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr);
Yinghai Lu16253242008-08-27 23:01:16 -0700115#endif
116
117struct mip_reg {
118 unsigned long long off_0;
119 unsigned long long off_8;
120 unsigned long long off_10;
121 unsigned long long off_18;
122 unsigned long long off_20;
123 unsigned long long off_28;
124 unsigned long long off_30;
125 unsigned long long off_38;
126};
127
128#define MIP_SW_APIC 0x1020b
129#define MIP_FUNC(VALUE) (VALUE & 0xff)
130
131/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 * ES7000 Globals
133 */
134
Adrian Bunkfb7ae262007-10-17 18:04:37 +0200135static volatile unsigned long *psai = NULL;
136static struct mip_reg *mip_reg;
137static struct mip_reg *host_reg;
138static int mip_port;
139static unsigned long mip_addr, host_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Alexey Starikovskiy32c50612008-05-14 19:02:51 +0400141int es7000_plat;
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/*
144 * GSI override for ES7000 platforms.
145 */
146
147static unsigned int base;
148
149static int
150es7000_rename_gsi(int ioapic, int gsi)
151{
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800152 if (es7000_plat == ES7000_ZORRO)
153 return gsi;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 if (!base) {
156 int i;
157 for (i = 0; i < nr_ioapics; i++)
158 base += nr_ioapic_registers[i];
159 }
160
Yinghai Luc7e79642008-07-25 02:17:33 -0700161 if (!ioapic && (gsi < 16))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 gsi += base;
163 return gsi;
164}
165
Yinghai Lu569712b2008-11-16 03:12:49 -0800166#ifdef CONFIG_ES7000_CLUSTERED_APIC
167static int wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
168{
169 unsigned long vect = 0, psaival = 0;
170
171 if (psai == NULL)
172 return -1;
173
174 vect = ((unsigned long)__pa(eip)/0x1000) << 16;
175 psaival = (0x1000000 | vect | cpu);
176
177 while (*psai & 0x1000000)
178 ;
179
180 *psai = psaival;
181
182 return 0;
183}
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800184
185static int __init es7000_update_genapic(void)
186{
187 genapic->wakeup_cpu = wakeup_secondary_cpu_via_mip;
188
189 return 0;
190}
Yinghai Lu569712b2008-11-16 03:12:49 -0800191#endif
192
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700193void __init
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800194setup_unisys(void)
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700195{
196 /*
197 * Determine the generation of the ES7000 currently running.
198 *
199 * es7000_plat = 1 if the machine is a 5xx ES7000 box
200 * es7000_plat = 2 if the machine is a x86_64 ES7000 box
201 *
202 */
203 if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800204 es7000_plat = ES7000_ZORRO;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700205 else
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800206 es7000_plat = ES7000_CLASSIC;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700207 ioapic_renumber_irq = es7000_rename_gsi;
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800208
Yinghai Lu569712b2008-11-16 03:12:49 -0800209#ifdef CONFIG_ES7000_CLUSTERED_APIC
Yinghai Lu54ac14a2008-11-17 15:19:53 -0800210 x86_quirks->update_genapic = es7000_update_genapic;
Yinghai Lu569712b2008-11-16 03:12:49 -0800211#endif
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700212}
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214/*
215 * Parse the OEM Table
216 */
217
218int __init
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700219parse_unisys_oem (char *oemptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 int i;
222 int success = 0;
223 unsigned char type, size;
224 unsigned long val;
225 char *tp = NULL;
226 struct psai *psaip = NULL;
227 struct mip_reg_info *mi;
228 struct mip_reg *host, *mip;
229
230 tp = oemptr;
231
232 tp += 8;
233
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700234 for (i=0; i <= 6; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 type = *tp++;
236 size = *tp++;
237 tp -= 2;
238 switch (type) {
239 case MIP_REG:
240 mi = (struct mip_reg_info *)tp;
241 val = MIP_RD_LO(mi->host_reg);
242 host_addr = val;
243 host = (struct mip_reg *)val;
244 host_reg = __va(host);
245 val = MIP_RD_LO(mi->mip_reg);
246 mip_port = MIP_PORT(mi->mip_info);
247 mip_addr = val;
248 mip = (struct mip_reg *)val;
249 mip_reg = __va(mip);
Thomas Gleixner5171c302008-07-21 21:58:34 +0200250 pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
251 (unsigned long)host_reg);
252 pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
253 (unsigned long)mip_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 success++;
255 break;
256 case MIP_PSAI_REG:
257 psaip = (struct psai *)tp;
258 if (tp != NULL) {
259 if (psaip->addr)
260 psai = __va(psaip->addr);
261 else
262 psai = NULL;
263 success++;
264 }
265 break;
266 default:
267 break;
268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 tp += size;
270 }
271
272 if (success < 2) {
Natalie.Protasevich@unisys.com93383162005-10-30 14:59:38 -0800273 es7000_plat = NON_UNISYS;
Natalie.Protasevich@unisys.com56f1d5d2005-09-03 15:56:34 -0700274 } else
275 setup_unisys();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return es7000_plat;
277}
278
Natalie.Protasevich@unisys.come5428ed2006-03-23 02:59:36 -0800279#ifdef CONFIG_ACPI
Yinghai Lua73aaed2008-09-14 02:33:14 -0700280static unsigned long oem_addrX;
281static unsigned long oem_size;
282int __init find_unisys_acpi_oem_table(unsigned long *oem_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300284 struct acpi_table_header *header = NULL;
285 int i = 0;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700286 acpi_size tbl_size;
287
288 while (ACPI_SUCCESS(acpi_get_table_with_size("OEM1", i++, &header, &tbl_size))) {
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300289 if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
290 struct oem_table *t = (struct oem_table *)header;
Yinghai Lua73aaed2008-09-14 02:33:14 -0700291
292 oem_addrX = t->OEMTableAddr;
293 oem_size = t->OEMTableSize;
294 early_acpi_os_unmap_memory(header, tbl_size);
295
296 *oem_addr = (unsigned long)__acpi_map_table(oem_addrX,
297 oem_size);
Alexey Starikovskiyceb6c462007-02-02 19:48:22 +0300298 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
Yinghai Lua73aaed2008-09-14 02:33:14 -0700300 early_acpi_os_unmap_memory(header, tbl_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 return -1;
303}
Yinghai Lua73aaed2008-09-14 02:33:14 -0700304
305void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr)
306{
307 if (!oem_addr)
308 return;
309
310 __acpi_unmap_table((char *)oem_addr, oem_size);
311}
Natalie.Protasevich@unisys.come5428ed2006-03-23 02:59:36 -0800312#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314static void
315es7000_spin(int n)
316{
317 int i = 0;
318
319 while (i++ < n)
320 rep_nop();
321}
322
323static int __init
324es7000_mip_write(struct mip_reg *mip_reg)
325{
326 int status = 0;
327 int spin;
328
329 spin = MIP_SPIN;
330 while (((unsigned long long)host_reg->off_38 &
331 (unsigned long long)MIP_VALID) != 0) {
332 if (--spin <= 0) {
333 printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
334 return -1;
335 }
336 es7000_spin(MIP_SPIN);
337 }
338
339 memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
340 outb(1, mip_port);
341
342 spin = MIP_SPIN;
343
344 while (((unsigned long long)mip_reg->off_38 &
345 (unsigned long long)MIP_VALID) == 0) {
346 if (--spin <= 0) {
347 printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
348 return -1;
349 }
350 es7000_spin(MIP_SPIN);
351 }
352
353 status = ((unsigned long long)mip_reg->off_0 &
354 (unsigned long long)0xffff0000000000ULL) >> 48;
355 mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
356 (unsigned long long)~MIP_VALID);
357 return status;
358}
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360void __init
Adrian Bunkfb7ae262007-10-17 18:04:37 +0200361es7000_sw_apic(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 if (es7000_plat) {
364 int mip_status;
365 struct mip_reg es7000_mip_reg;
366
367 printk("ES7000: Enabling APIC mode.\n");
368 memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
369 es7000_mip_reg.off_0 = MIP_SW_APIC;
370 es7000_mip_reg.off_38 = (MIP_VALID);
371 while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
372 printk("es7000_sw_apic: command failed, status = %x\n",
373 mip_status);
374 return;
375 }
376}