This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / i386 / mach-es7000 / es7000.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  * Parse the OEM Table
56  */
57
58 void __init
59 parse_unisys_oem (char *oemptr, int oem_entries)
60 {
61         int                     i;
62         int                     success = 0;
63         unsigned char           type, size;
64         unsigned long           val;
65         char                    *tp = NULL;  
66         struct psai             *psaip = NULL;
67         struct mip_reg_info     *mi;
68         struct mip_reg          *host, *mip;
69
70         tp = oemptr;
71
72         tp += 8;
73
74         for (i=0; i <= oem_entries; i++) {
75                 type = *tp++;
76                 size = *tp++;
77                 tp -= 2;
78                 switch (type) {
79                 case MIP_REG:
80                         mi = (struct mip_reg_info *)tp;
81                         val = MIP_RD_LO(mi->host_reg);
82                         host_addr = val;
83                         host = (struct mip_reg *)val;
84                         host_reg = __va(host);
85                         val = MIP_RD_LO(mi->mip_reg);
86                         mip_addr = val;
87                         mip = (struct mip_reg *)val;
88                         mip_reg = __va(mip);
89                         Dprintk("es7000_mipcfg: host_reg = 0x%lx \n", 
90                                 (unsigned long)host_reg);
91                         Dprintk("es7000_mipcfg: mip_reg = 0x%lx \n", 
92                                 (unsigned long)mip_reg);
93                         success++;
94                         break;
95                 case MIP_PSAI_REG:
96                         psaip = (struct psai *)tp;
97                         if (tp != NULL) {
98                                 if (psaip->addr)
99                                         psai = __va(psaip->addr);
100                                 else
101                                         psai = NULL;
102                                 success++;
103                         }
104                         break;
105                 default:
106                         break;
107                 }
108                 if (i == 6) break;
109                 tp += size;
110         }
111
112         if (success < 2) {
113                 printk("\nNo ES7000 found.\n");
114                 es7000_plat = 0;
115         } else {
116                 printk("\nEnabling ES7000 specific features...\n");
117                 es7000_plat = 1;
118         }
119         return;
120 }
121
122 int __init 
123 find_unisys_acpi_oem_table(unsigned long *oem_addr, int *length) 
124 {
125         struct acpi_table_rsdp          *rsdp = NULL;
126         unsigned long                   rsdp_phys = 0;
127         struct acpi_table_header        *header = NULL;
128         int                             i;
129         struct acpi_table_sdt           sdt;
130
131         rsdp_phys = acpi_find_rsdp();
132         rsdp = __va(rsdp_phys);
133         if (rsdp->rsdt_address) {
134                 struct acpi_table_rsdt  *mapped_rsdt = NULL;
135                 sdt.pa = rsdp->rsdt_address;
136
137                 header = (struct acpi_table_header *)
138                         __acpi_map_table(sdt.pa, sizeof(struct acpi_table_header));
139                 if (!header)
140                         return -ENODEV;
141
142                 sdt.count = (header->length - sizeof(struct acpi_table_header)) >> 3;
143                 mapped_rsdt = (struct acpi_table_rsdt *)
144                         __acpi_map_table(sdt.pa, header->length);
145                 if (!mapped_rsdt)
146                         return -ENODEV;
147
148                 header = &mapped_rsdt->header;
149
150                 for (i = 0; i < sdt.count; i++)
151                         sdt.entry[i].pa = (unsigned long) mapped_rsdt->entry[i];
152         };
153         for (i = 0; i < sdt.count; i++) {
154
155                 header = (struct acpi_table_header *)
156                         __acpi_map_table(sdt.entry[i].pa,
157                                 sizeof(struct acpi_table_header));
158                 if (!header)
159                         continue;
160                 if (!strncmp((char *) &header->signature, "OEM1", 4)) {
161                         if (!strncmp((char *) &header->oem_id, "UNISYS", 6)) {
162                                 void *addr;
163                                 struct oem_table *t;
164                                 acpi_table_print(header, sdt.entry[i].pa);
165                                 t = (struct oem_table *) __acpi_map_table(sdt.entry[i].pa, header->length);
166                                 addr = (void *) __acpi_map_table(t->OEMTableAddr, t->OEMTableSize);
167                                 *length = header->length;
168                                 *oem_addr = (unsigned long) addr;
169                                 return 0;
170                         }
171                 }
172         }
173         printk("ES7000: did not find Unisys ACPI OEM table!\n");
174         return -1;
175 }
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)0xffff0000000000) >> 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 }