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