[PATCH] Remove unused code from rioboot
[safe/jmp/linux-2.6] / drivers / char / rio / rioinit.c
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 **  Perle Specialix driver for Linux
5 **  Ported from existing RIO Driver for SCO sources.
6  *
7  *  (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8  *
9  *      This program is free software; you can redistribute it and/or modify
10  *      it under the terms of the GNU General Public License as published by
11  *      the Free Software Foundation; either version 2 of the License, or
12  *      (at your option) any later version.
13  *
14  *      This program is distributed in the hope that it will be useful,
15  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *      GNU General Public License for more details.
18  *
19  *      You should have received a copy of the GNU General Public License
20  *      along with this program; if not, write to the Free Software
21  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 **
23 **      Module          : rioinit.c
24 **      SID             : 1.3
25 **      Last Modified   : 11/6/98 10:33:43
26 **      Retrieved       : 11/6/98 10:33:49
27 **
28 **  ident @(#)rioinit.c 1.3
29 **
30 ** -----------------------------------------------------------------------------
31 */
32 #ifdef SCCS_LABELS
33 static char *_rioinit_c_sccs_ = "@(#)rioinit.c  1.3";
34 #endif
35
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <linux/delay.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
46
47 #include <linux/termios.h>
48 #include <linux/serial.h>
49
50 #include <linux/generic_serial.h>
51
52
53 #include "linux_compat.h"
54 #include "typdef.h"
55 #include "pkt.h"
56 #include "daemon.h"
57 #include "rio.h"
58 #include "riospace.h"
59 #include "top.h"
60 #include "cmdpkt.h"
61 #include "map.h"
62 #include "riotypes.h"
63 #include "rup.h"
64 #include "port.h"
65 #include "riodrvr.h"
66 #include "rioinfo.h"
67 #include "func.h"
68 #include "errors.h"
69 #include "pci.h"
70
71 #include "parmmap.h"
72 #include "unixrup.h"
73 #include "board.h"
74 #include "host.h"
75 #include "error.h"
76 #include "phb.h"
77 #include "link.h"
78 #include "cmdblk.h"
79 #include "route.h"
80 #include "control.h"
81 #include "cirrus.h"
82 #include "rioioctl.h"
83 #include "rio_linux.h"
84
85 #undef bcopy
86 #define bcopy rio_pcicopy
87
88 int RIOPCIinit(struct rio_info *p, int Mode);
89
90 static int RIOScrub(int, BYTE *, int);
91
92
93 /**
94 ** RIOAssignAT :
95 **
96 ** Fill out the fields in the p->RIOHosts structure now we know we know
97 ** we have a board present.
98 **
99 ** bits < 0 indicates 8 bit operation requested,
100 ** bits > 0 indicates 16 bit operation.
101 */
102 int
103 RIOAssignAT(p, Base, virtAddr, mode)
104 struct rio_info *       p;
105 int             Base;
106 caddr_t virtAddr;
107 int             mode;
108 {
109         int             bits;
110         struct DpRam *cardp = (struct DpRam *)virtAddr;
111
112         if ((Base < ONE_MEG) || (mode & BYTE_ACCESS_MODE))
113                 bits = BYTE_OPERATION;
114         else
115                 bits = WORD_OPERATION;
116
117         /*
118         ** Board has passed its scrub test. Fill in all the
119         ** transient stuff.
120         */
121         p->RIOHosts[p->RIONumHosts].Caddr       = virtAddr;
122         p->RIOHosts[p->RIONumHosts].CardP       = (struct DpRam *)virtAddr;
123
124         /*
125         ** Revision 01 AT host cards don't support WORD operations,
126         */
127         if ( RBYTE(cardp->DpRevision) == 01 )
128                 bits = BYTE_OPERATION;
129
130         p->RIOHosts[p->RIONumHosts].Type = RIO_AT;
131         p->RIOHosts[p->RIONumHosts].Copy = bcopy;
132                                                                                         /* set this later */
133         p->RIOHosts[p->RIONumHosts].Slot = -1;
134         p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits;
135         WBYTE(p->RIOHosts[p->RIONumHosts].Control, 
136                         BOOT_FROM_RAM | EXTERNAL_BUS_OFF | 
137                         p->RIOHosts[p->RIONumHosts].Mode | 
138                         INTERRUPT_DISABLE );
139         WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
140         WBYTE(p->RIOHosts[p->RIONumHosts].Control,
141                         BOOT_FROM_RAM | EXTERNAL_BUS_OFF | 
142                         p->RIOHosts[p->RIONumHosts].Mode |
143                         INTERRUPT_DISABLE );
144         WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
145         p->RIOHosts[p->RIONumHosts].UniqueNum =
146                 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
147                 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
148                 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
149                 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
150         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum);
151
152         p->RIONumHosts++;
153         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Tests Passed at 0x%x\n", Base);
154         return(1);
155 }
156
157 static  uchar   val[] = {
158 #ifdef VERY_LONG_TEST
159           0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
160           0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36, 
161 #endif
162           0xff, 0x00, 0x00 };
163
164 #define TEST_END sizeof(val)
165
166 /*
167 ** RAM test a board. 
168 ** Nothing too complicated, just enough to check it out.
169 */
170 int
171 RIOBoardTest(paddr, caddr, type, slot)
172 paddr_t paddr;
173 caddr_t caddr;
174 uchar   type;
175 int             slot;
176 {
177         struct DpRam *DpRam = (struct DpRam *)caddr;
178         char *ram[4];
179         int  size[4];
180         int  op, bank;
181         int  nbanks;
182
183         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=0x%x, slot=%d\n",
184                         type,(int)DpRam, slot);
185
186         RIOHostReset(type, DpRam, slot);
187
188         /*
189         ** Scrub the memory. This comes in several banks:
190         ** DPsram1      - 7000h bytes
191         ** DPsram2      - 200h  bytes
192         ** DPsram3      - 7000h bytes
193         ** scratch      - 1000h bytes
194         */
195
196         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Setup ram/size arrays\n");
197
198         size[0] = DP_SRAM1_SIZE;
199         size[1] = DP_SRAM2_SIZE;
200         size[2] = DP_SRAM3_SIZE;
201         size[3] = DP_SCRATCH_SIZE;
202
203         ram[0] = (char *)&DpRam->DpSram1[0];
204         ram[1] = (char *)&DpRam->DpSram2[0];
205         ram[2] = (char *)&DpRam->DpSram3[0];
206         nbanks = (type == RIO_PCI) ? 3 : 4;
207         if (nbanks == 4)
208                 ram[3] = (char *)&DpRam->DpScratch[0];
209
210
211         if (nbanks == 3) {
212                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
213                                 (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2]);
214         } else {
215                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
216                         (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2], (int)ram[3], 
217                                         size[3]);
218         }
219
220         /*
221         ** This scrub operation will test for crosstalk between
222         ** banks. TEST_END is a magic number, and relates to the offset
223         ** within the 'val' array used by Scrub.
224         */
225         for (op=0; op<TEST_END; op++) {
226                 for (bank=0; bank<nbanks; bank++) {
227                         if (RIOScrub(op, (BYTE *)ram[bank], size[bank]) == RIO_FAIL) {
228                                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n", 
229                                                         bank, op);
230                                 return RIO_FAIL;
231                         }
232                 }
233         }
234
235         rio_dprintk (RIO_DEBUG_INIT, "Test completed\n");
236         return RIO_SUCCESS;
237 }
238
239
240 /*
241 ** Scrub an area of RAM.
242 ** Define PRETEST and POSTTEST for a more thorough checking of the
243 ** state of the memory.
244 ** Call with op set to an index into the above 'val' array to determine
245 ** which value will be written into memory.
246 ** Call with op set to zero means that the RAM will not be read and checked
247 ** before it is written.
248 ** Call with op not zero, and the RAM will be read and compated with val[op-1]
249 ** to check that the data from the previous phase was retained.
250 */
251 static int
252 RIOScrub(op, ram, size)
253 int             op;
254 BYTE *  ram;
255 int             size; 
256 {
257         int                             off;
258         unsigned char   oldbyte;
259         unsigned char   newbyte;
260         unsigned char   invbyte;
261         unsigned short  oldword;
262         unsigned short  newword;
263         unsigned short  invword;
264         unsigned short  swapword;
265
266         if (op) {
267                 oldbyte = val[op-1];
268                 oldword = oldbyte | (oldbyte<<8);
269         } else
270           oldbyte = oldword = 0; /* Tell the compiler we've initilalized them. */
271         newbyte = val[op];
272         newword = newbyte | (newbyte<<8);
273         invbyte = ~newbyte;
274         invword = invbyte | (invbyte<<8);
275
276         /*
277         ** Check that the RAM contains the value that should have been left there
278         ** by the previous test (not applicable for pass zero)
279         */
280         if (op) {
281                 for (off=0; off<size; off++) {
282                         if (RBYTE(ram[off]) != oldbyte) {
283                                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 1: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off]));
284                                 return RIO_FAIL;
285                         }
286                 }
287                 for (off=0; off<size; off+=2) {
288                         if (*(ushort *)&ram[off] != oldword) {
289                                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: WORD at offset 0x%x should have been=%x, was=%x\n",off,oldword,*(ushort *)&ram[off]);
290                                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
291                                 return RIO_FAIL;
292                         }
293                 }
294         }
295
296         /*
297         ** Now write the INVERSE of the test data into every location, using
298         ** BYTE write operations, first checking before each byte is written
299         ** that the location contains the old value still, and checking after
300         ** the write that the location contains the data specified - this is
301         ** the BYTE read/write test.
302         */
303         for (off=0; off<size; off++) {
304                 if (op && (RBYTE(ram[off]) != oldbyte)) {
305                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off]));
306                         return RIO_FAIL;
307                 }
308                 WBYTE(ram[off],invbyte);
309                 if (RBYTE(ram[off]) != invbyte) {
310                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Inv Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, invbyte, RBYTE(ram[off]));
311                         return RIO_FAIL;
312                 }
313         }
314
315         /*
316         ** now, use WORD operations to write the test value into every location,
317         ** check as before that the location contains the previous test value
318         ** before overwriting, and that it contains the data value written
319         ** afterwards.
320         ** This is the WORD operation test.
321         */
322         for (off=0; off<size; off+=2) {
323                 if (*(ushort *)&ram[off] != invword) {
324                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: WORD at offset 0x%x should have been=%x, was=%x\n", off, invword, *(ushort *)&ram[off]);
325                 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
326                         return RIO_FAIL;
327                 }
328
329                 *(ushort *)&ram[off] = newword;
330                 if ( *(ushort *)&ram[off] != newword ) {
331                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]);
332                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
333                         return RIO_FAIL;
334                 }
335         }
336
337         /*
338         ** now run through the block of memory again, first in byte mode
339         ** then in word mode, and check that all the locations contain the
340         ** required test data.
341         */
342         for (off=0; off<size; off++) {
343                 if (RBYTE(ram[off]) != newbyte) {
344                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Byte Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off]));
345                         return RIO_FAIL;
346                 }
347         }
348
349         for (off=0; off<size; off+=2) {
350                 if ( *(ushort *)&ram[off] != newword ) {
351                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]);
352                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
353                         return RIO_FAIL;
354                 }
355         }
356
357         /*
358         ** time to check out byte swapping errors
359         */
360         swapword = invbyte | (newbyte << 8);
361
362         for (off=0; off<size; off+=2) {
363                 WBYTE(ram[off],invbyte);
364                 WBYTE(ram[off+1],newbyte);
365         }
366
367         for ( off=0; off<size; off+=2 ) {
368                 if (*(ushort *)&ram[off] != swapword) {
369                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, swapword, *((ushort *)&ram[off]));
370                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
371                         return RIO_FAIL;
372                 }
373                 *((ushort *)&ram[off]) = ~swapword;
374         }
375
376         for (off=0; off<size; off+=2) {
377                 if (RBYTE(ram[off]) != newbyte) {
378                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off]));
379                         return RIO_FAIL;
380                 }
381                 if (RBYTE(ram[off+1]) != invbyte) {
382                         rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off+1, invbyte, RBYTE(ram[off+1]));
383                         return RIO_FAIL;
384                 }
385                 *((ushort *)&ram[off]) = newword;
386         }
387         return RIO_SUCCESS;
388 }
389
390
391 int
392 RIODefaultName(p, HostP, UnitId)
393 struct rio_info *       p;
394 struct Host *   HostP;
395 uint                    UnitId;
396 {
397         bcopy("UNKNOWN RTA X-XX",HostP->Mapping[UnitId].Name,17);
398         HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts);
399         if ((UnitId+1) > 9) {
400                 HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10);
401                 HostP->Mapping[UnitId].Name[15]='0'+((UnitId+1)%10);
402         }
403         else {
404                 HostP->Mapping[UnitId].Name[14]='1'+UnitId;
405                 HostP->Mapping[UnitId].Name[15]=0;
406         }
407         return 0;
408 }
409
410 #define RIO_RELEASE     "Linux"
411 #define RELEASE_ID      "1.0"
412
413 static struct rioVersion        stVersion;
414
415 struct rioVersion *
416 RIOVersid(void)
417 {
418     strlcpy(stVersion.version, "RIO driver for linux V1.0",
419             sizeof(stVersion.version));
420     strlcpy(stVersion.buildDate, __DATE__,
421             sizeof(stVersion.buildDate));
422
423     return &stVersion;
424 }
425
426 void
427 RIOHostReset(Type, DpRamP, Slot)
428 uint Type;
429 volatile struct DpRam *DpRamP;
430 uint Slot; 
431 {
432         /*
433         ** Reset the Tpu
434         */
435         rio_dprintk (RIO_DEBUG_INIT,  "RIOHostReset: type 0x%x", Type);
436         switch ( Type ) {
437                 case RIO_AT:
438                         rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n");
439                         WBYTE(DpRamP->DpControl,  BOOT_FROM_RAM | EXTERNAL_BUS_OFF | 
440                                           INTERRUPT_DISABLE | BYTE_OPERATION |
441                                           SLOW_LINKS | SLOW_AT_BUS);
442                         WBYTE(DpRamP->DpResetTpu, 0xFF);
443                         udelay(3);
444
445                         rio_dprintk (RIO_DEBUG_INIT,  "RIOHostReset: Don't know if it worked. Try reset again\n");
446                         WBYTE(DpRamP->DpControl,  BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
447                                           INTERRUPT_DISABLE | BYTE_OPERATION |
448                                           SLOW_LINKS | SLOW_AT_BUS);
449                         WBYTE(DpRamP->DpResetTpu, 0xFF);
450                         udelay(3);
451                         break;
452         case RIO_PCI:
453                 rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n");
454                 DpRamP->DpControl  = RIO_PCI_BOOT_FROM_RAM;
455                 DpRamP->DpResetInt = 0xFF;
456                 DpRamP->DpResetTpu = 0xFF;
457                 udelay(100);
458                 /* for (i=0; i<6000; i++);  */
459                 /* suspend( 3 ); */
460                 break;
461         default:
462                 rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n");
463                 break;
464         }
465         return;
466 }