x86: move es7000_plat out of mpparse.c
[linux-2.6] / arch / x86 / mach-es7000 / es7000plat.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 "es7000.h"
43 #include <mach_mpparse.h>
44
45 /*
46  * ES7000 Globals
47  */
48
49 static volatile unsigned long   *psai = NULL;
50 static struct mip_reg           *mip_reg;
51 static struct mip_reg           *host_reg;
52 static int                      mip_port;
53 static unsigned long            mip_addr, host_addr;
54
55 int es7000_plat;
56
57 /*
58  * GSI override for ES7000 platforms.
59  */
60
61 static unsigned int base;
62
63 static int
64 es7000_rename_gsi(int ioapic, int gsi)
65 {
66         if (es7000_plat == ES7000_ZORRO)
67                 return gsi;
68
69         if (!base) {
70                 int i;
71                 for (i = 0; i < nr_ioapics; i++)
72                         base += nr_ioapic_registers[i];
73         }
74
75         if (!ioapic && (gsi < 16)) 
76                 gsi += base;
77         return gsi;
78 }
79
80 void __init
81 setup_unisys(void)
82 {
83         /*
84          * Determine the generation of the ES7000 currently running.
85          *
86          * es7000_plat = 1 if the machine is a 5xx ES7000 box
87          * es7000_plat = 2 if the machine is a x86_64 ES7000 box
88          *
89          */
90         if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
91                 es7000_plat = ES7000_ZORRO;
92         else
93                 es7000_plat = ES7000_CLASSIC;
94         ioapic_renumber_irq = es7000_rename_gsi;
95 }
96
97 /*
98  * Parse the OEM Table
99  */
100
101 int __init
102 parse_unisys_oem (char *oemptr)
103 {
104         int                     i;
105         int                     success = 0;
106         unsigned char           type, size;
107         unsigned long           val;
108         char                    *tp = NULL;
109         struct psai             *psaip = NULL;
110         struct mip_reg_info     *mi;
111         struct mip_reg          *host, *mip;
112
113         tp = oemptr;
114
115         tp += 8;
116
117         for (i=0; i <= 6; i++) {
118                 type = *tp++;
119                 size = *tp++;
120                 tp -= 2;
121                 switch (type) {
122                 case MIP_REG:
123                         mi = (struct mip_reg_info *)tp;
124                         val = MIP_RD_LO(mi->host_reg);
125                         host_addr = val;
126                         host = (struct mip_reg *)val;
127                         host_reg = __va(host);
128                         val = MIP_RD_LO(mi->mip_reg);
129                         mip_port = MIP_PORT(mi->mip_info);
130                         mip_addr = val;
131                         mip = (struct mip_reg *)val;
132                         mip_reg = __va(mip);
133                         Dprintk("es7000_mipcfg: host_reg = 0x%lx \n",
134                                 (unsigned long)host_reg);
135                         Dprintk("es7000_mipcfg: mip_reg = 0x%lx \n",
136                                 (unsigned long)mip_reg);
137                         success++;
138                         break;
139                 case MIP_PSAI_REG:
140                         psaip = (struct psai *)tp;
141                         if (tp != NULL) {
142                                 if (psaip->addr)
143                                         psai = __va(psaip->addr);
144                                 else
145                                         psai = NULL;
146                                 success++;
147                         }
148                         break;
149                 default:
150                         break;
151                 }
152                 tp += size;
153         }
154
155         if (success < 2) {
156                 es7000_plat = NON_UNISYS;
157         } else
158                 setup_unisys();
159         return es7000_plat;
160 }
161
162 #ifdef CONFIG_ACPI
163 int __init
164 find_unisys_acpi_oem_table(unsigned long *oem_addr)
165 {
166         struct acpi_table_header *header = NULL;
167         int i = 0;
168         while (ACPI_SUCCESS(acpi_get_table("OEM1", i++, &header))) {
169                 if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
170                         struct oem_table *t = (struct oem_table *)header;
171                         *oem_addr = (unsigned long)__acpi_map_table(t->OEMTableAddr,
172                                                                     t->OEMTableSize);
173                         return 0;
174                 }
175         }
176         return -1;
177 }
178 #endif
179
180 /*
181  * This file also gets compiled if CONFIG_X86_GENERICARCH is set. Generic
182  * arch already has got following function definitions (asm-generic/es7000.c)
183  * hence no need to define these for that case.
184  */
185 #ifndef CONFIG_X86_GENERICARCH
186 void es7000_sw_apic(void);
187 void __init enable_apic_mode(void)
188 {
189         es7000_sw_apic();
190         return;
191 }
192
193 __init int mps_oem_check(struct mp_config_table *mpc, char *oem,
194                 char *productid)
195 {
196         if (mpc->mpc_oemptr) {
197                 struct mp_config_oemtable *oem_table =
198                         (struct mp_config_oemtable *)mpc->mpc_oemptr;
199                 if (!strncmp(oem, "UNISYS", 6))
200                         return parse_unisys_oem((char *)oem_table);
201         }
202         return 0;
203 }
204 #ifdef CONFIG_ACPI
205 /* Hook from generic ACPI tables.c */
206 int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
207 {
208         unsigned long oem_addr;
209         if (!find_unisys_acpi_oem_table(&oem_addr)) {
210                 if (es7000_check_dsdt())
211                         return parse_unisys_oem((char *)oem_addr);
212                 else {
213                         setup_unisys();
214                         return 1;
215                 }
216         }
217         return 0;
218 }
219 #else
220 int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
221 {
222         return 0;
223 }
224 #endif
225 #endif /* COFIG_X86_GENERICARCH */
226
227 static void
228 es7000_spin(int n)
229 {
230         int i = 0;
231
232         while (i++ < n)
233                 rep_nop();
234 }
235
236 static int __init
237 es7000_mip_write(struct mip_reg *mip_reg)
238 {
239         int                     status = 0;
240         int                     spin;
241
242         spin = MIP_SPIN;
243         while (((unsigned long long)host_reg->off_38 &
244                 (unsigned long long)MIP_VALID) != 0) {
245                         if (--spin <= 0) {
246                                 printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
247                                 return -1;
248                         }
249                 es7000_spin(MIP_SPIN);
250         }
251
252         memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
253         outb(1, mip_port);
254
255         spin = MIP_SPIN;
256
257         while (((unsigned long long)mip_reg->off_38 &
258                 (unsigned long long)MIP_VALID) == 0) {
259                 if (--spin <= 0) {
260                         printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
261                         return -1;
262                 }
263                 es7000_spin(MIP_SPIN);
264         }
265
266         status = ((unsigned long long)mip_reg->off_0 &
267                 (unsigned long long)0xffff0000000000ULL) >> 48;
268         mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
269                 (unsigned long long)~MIP_VALID);
270         return status;
271 }
272
273 int
274 es7000_start_cpu(int cpu, unsigned long eip)
275 {
276         unsigned long vect = 0, psaival = 0;
277
278         if (psai == NULL)
279                 return -1;
280
281         vect = ((unsigned long)__pa(eip)/0x1000) << 16;
282         psaival = (0x1000000 | vect | cpu);
283
284         while (*psai & 0x1000000)
285                 ;
286
287         *psai = psaival;
288
289         return 0;
290
291 }
292
293 void __init
294 es7000_sw_apic(void)
295 {
296         if (es7000_plat) {
297                 int mip_status;
298                 struct mip_reg es7000_mip_reg;
299
300                 printk("ES7000: Enabling APIC mode.\n");
301                 memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
302                 es7000_mip_reg.off_0 = MIP_SW_APIC;
303                 es7000_mip_reg.off_38 = (MIP_VALID);
304                 while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
305                         printk("es7000_sw_apic: command failed, status = %x\n",
306                                 mip_status);
307                 return;
308         }
309 }