Merge branch 'x86/cpu' into x86/core
[safe/jmp/linux-2.6] / arch / x86 / kernel / es7000_32.c
1 /*
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>
42 #include <mach_mpparse.h>
43
44 /*
45  * ES7000 chipsets
46  */
47
48 #define NON_UNISYS              0
49 #define ES7000_CLASSIC          1
50 #define ES7000_ZORRO            2
51
52
53 #define MIP_REG                 1
54 #define MIP_PSAI_REG            4
55
56 #define MIP_BUSY                1
57 #define MIP_SPIN                0xf0000
58 #define MIP_VALID               0x0100000000000000ULL
59 #define MIP_PORT(VALUE) ((VALUE >> 32) & 0xffff)
60
61 #define MIP_RD_LO(VALUE)        (VALUE & 0xffffffff)
62
63 struct mip_reg_info {
64         unsigned long long mip_info;
65         unsigned long long delivery_info;
66         unsigned long long host_reg;
67         unsigned long long mip_reg;
68 };
69
70 struct part_info {
71         unsigned char type;
72         unsigned char length;
73         unsigned char part_id;
74         unsigned char apic_mode;
75         unsigned long snum;
76         char ptype[16];
77         char sname[64];
78         char pname[64];
79 };
80
81 struct psai {
82         unsigned long long entry_type;
83         unsigned long long addr;
84         unsigned long long bep_addr;
85 };
86
87 struct es7000_mem_info {
88         unsigned char type;
89         unsigned char length;
90         unsigned char resv[6];
91         unsigned long long  start;
92         unsigned long long  size;
93 };
94
95 struct es7000_oem_table {
96         unsigned long long hdr;
97         struct mip_reg_info mip;
98         struct part_info pif;
99         struct es7000_mem_info shm;
100         struct psai psai;
101 };
102
103 #ifdef CONFIG_ACPI
104
105 struct oem_table {
106         struct acpi_table_header Header;
107         u32 OEMTableAddr;
108         u32 OEMTableSize;
109 };
110
111 extern int find_unisys_acpi_oem_table(unsigned long *oem_addr);
112 #endif
113
114 struct mip_reg {
115         unsigned long long off_0;
116         unsigned long long off_8;
117         unsigned long long off_10;
118         unsigned long long off_18;
119         unsigned long long off_20;
120         unsigned long long off_28;
121         unsigned long long off_30;
122         unsigned long long off_38;
123 };
124
125 #define MIP_SW_APIC             0x1020b
126 #define MIP_FUNC(VALUE)         (VALUE & 0xff)
127
128 /*
129  * ES7000 Globals
130  */
131
132 static volatile unsigned long   *psai = NULL;
133 static struct mip_reg           *mip_reg;
134 static struct mip_reg           *host_reg;
135 static int                      mip_port;
136 static unsigned long            mip_addr, host_addr;
137
138 int es7000_plat;
139
140 /*
141  * GSI override for ES7000 platforms.
142  */
143
144 static unsigned int base;
145
146 static int
147 es7000_rename_gsi(int ioapic, int gsi)
148 {
149         if (es7000_plat == ES7000_ZORRO)
150                 return gsi;
151
152         if (!base) {
153                 int i;
154                 for (i = 0; i < nr_ioapics; i++)
155                         base += nr_ioapic_registers[i];
156         }
157
158         if (!ioapic && (gsi < 16))
159                 gsi += base;
160         return gsi;
161 }
162
163 void __init
164 setup_unisys(void)
165 {
166         /*
167          * Determine the generation of the ES7000 currently running.
168          *
169          * es7000_plat = 1 if the machine is a 5xx ES7000 box
170          * es7000_plat = 2 if the machine is a x86_64 ES7000 box
171          *
172          */
173         if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
174                 es7000_plat = ES7000_ZORRO;
175         else
176                 es7000_plat = ES7000_CLASSIC;
177         ioapic_renumber_irq = es7000_rename_gsi;
178 }
179
180 /*
181  * Parse the OEM Table
182  */
183
184 int __init
185 parse_unisys_oem (char *oemptr)
186 {
187         int                     i;
188         int                     success = 0;
189         unsigned char           type, size;
190         unsigned long           val;
191         char                    *tp = NULL;
192         struct psai             *psaip = NULL;
193         struct mip_reg_info     *mi;
194         struct mip_reg          *host, *mip;
195
196         tp = oemptr;
197
198         tp += 8;
199
200         for (i=0; i <= 6; i++) {
201                 type = *tp++;
202                 size = *tp++;
203                 tp -= 2;
204                 switch (type) {
205                 case MIP_REG:
206                         mi = (struct mip_reg_info *)tp;
207                         val = MIP_RD_LO(mi->host_reg);
208                         host_addr = val;
209                         host = (struct mip_reg *)val;
210                         host_reg = __va(host);
211                         val = MIP_RD_LO(mi->mip_reg);
212                         mip_port = MIP_PORT(mi->mip_info);
213                         mip_addr = val;
214                         mip = (struct mip_reg *)val;
215                         mip_reg = __va(mip);
216                         pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
217                                  (unsigned long)host_reg);
218                         pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
219                                  (unsigned long)mip_reg);
220                         success++;
221                         break;
222                 case MIP_PSAI_REG:
223                         psaip = (struct psai *)tp;
224                         if (tp != NULL) {
225                                 if (psaip->addr)
226                                         psai = __va(psaip->addr);
227                                 else
228                                         psai = NULL;
229                                 success++;
230                         }
231                         break;
232                 default:
233                         break;
234                 }
235                 tp += size;
236         }
237
238         if (success < 2) {
239                 es7000_plat = NON_UNISYS;
240         } else
241                 setup_unisys();
242         return es7000_plat;
243 }
244
245 #ifdef CONFIG_ACPI
246 int __init
247 find_unisys_acpi_oem_table(unsigned long *oem_addr)
248 {
249         struct acpi_table_header *header = NULL;
250         int i = 0;
251         while (ACPI_SUCCESS(acpi_get_table("OEM1", i++, &header))) {
252                 if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
253                         struct oem_table *t = (struct oem_table *)header;
254                         *oem_addr = (unsigned long)__acpi_map_table(t->OEMTableAddr,
255                                                                     t->OEMTableSize);
256                         return 0;
257                 }
258         }
259         return -1;
260 }
261 #endif
262
263 static void
264 es7000_spin(int n)
265 {
266         int i = 0;
267
268         while (i++ < n)
269                 rep_nop();
270 }
271
272 static int __init
273 es7000_mip_write(struct mip_reg *mip_reg)
274 {
275         int                     status = 0;
276         int                     spin;
277
278         spin = MIP_SPIN;
279         while (((unsigned long long)host_reg->off_38 &
280                 (unsigned long long)MIP_VALID) != 0) {
281                         if (--spin <= 0) {
282                                 printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
283                                 return -1;
284                         }
285                 es7000_spin(MIP_SPIN);
286         }
287
288         memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
289         outb(1, mip_port);
290
291         spin = MIP_SPIN;
292
293         while (((unsigned long long)mip_reg->off_38 &
294                 (unsigned long long)MIP_VALID) == 0) {
295                 if (--spin <= 0) {
296                         printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
297                         return -1;
298                 }
299                 es7000_spin(MIP_SPIN);
300         }
301
302         status = ((unsigned long long)mip_reg->off_0 &
303                 (unsigned long long)0xffff0000000000ULL) >> 48;
304         mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
305                 (unsigned long long)~MIP_VALID);
306         return status;
307 }
308
309 int
310 es7000_start_cpu(int cpu, unsigned long eip)
311 {
312         unsigned long vect = 0, psaival = 0;
313
314         if (psai == NULL)
315                 return -1;
316
317         vect = ((unsigned long)__pa(eip)/0x1000) << 16;
318         psaival = (0x1000000 | vect | cpu);
319
320         while (*psai & 0x1000000)
321                 ;
322
323         *psai = psaival;
324
325         return 0;
326
327 }
328
329 void __init
330 es7000_sw_apic(void)
331 {
332         if (es7000_plat) {
333                 int mip_status;
334                 struct mip_reg es7000_mip_reg;
335
336                 printk("ES7000: Enabling APIC mode.\n");
337                 memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
338                 es7000_mip_reg.off_0 = MIP_SW_APIC;
339                 es7000_mip_reg.off_38 = (MIP_VALID);
340                 while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
341                         printk("es7000_sw_apic: command failed, status = %x\n",
342                                 mip_status);
343                 return;
344         }
345 }