2 ** -----------------------------------------------------------------------------
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
25 ** Last Modified : 11/6/98 10:33:43
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)rioinit.c 1.3
30 ** -----------------------------------------------------------------------------
33 static char *_rioinit_c_sccs_
= "@(#)rioinit.c 1.3";
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>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
53 #include "linux_compat.h"
83 #include "rio_linux.h"
86 #define bcopy rio_pcicopy
88 int RIOPCIinit(struct rio_info
*p
, int Mode
);
90 static int RIOScrub(int, BYTE
*, int);
96 ** Fill out the fields in the p->RIOHosts structure now we know we know
97 ** we have a board present.
99 ** bits < 0 indicates 8 bit operation requested,
100 ** bits > 0 indicates 16 bit operation.
103 RIOAssignAT(p
, Base
, virtAddr
, mode
)
110 struct DpRam
*cardp
= (struct DpRam
*)virtAddr
;
112 if ((Base
< ONE_MEG
) || (mode
& BYTE_ACCESS_MODE
))
113 bits
= BYTE_OPERATION
;
115 bits
= WORD_OPERATION
;
118 ** Board has passed its scrub test. Fill in all the
121 p
->RIOHosts
[p
->RIONumHosts
].Caddr
= virtAddr
;
122 p
->RIOHosts
[p
->RIONumHosts
].CardP
= (struct DpRam
*)virtAddr
;
125 ** Revision 01 AT host cards don't support WORD operations,
127 if ( RBYTE(cardp
->DpRevision
) == 01 )
128 bits
= BYTE_OPERATION
;
130 p
->RIOHosts
[p
->RIONumHosts
].Type
= RIO_AT
;
131 p
->RIOHosts
[p
->RIONumHosts
].Copy
= bcopy
;
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
|
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
|
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
);
153 rio_dprintk (RIO_DEBUG_INIT
, "RIO-init: Tests Passed at 0x%x\n", Base
);
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,
164 #define TEST_END sizeof(val)
168 ** Nothing too complicated, just enough to check it out.
171 RIOBoardTest(paddr
, caddr
, type
, slot
)
177 struct DpRam
*DpRam
= (struct DpRam
*)caddr
;
183 rio_dprintk (RIO_DEBUG_INIT
, "RIO-init: Reset host type=%d, DpRam=0x%x, slot=%d\n",
184 type
,(int)DpRam
, slot
);
186 RIOHostReset(type
, DpRam
, slot
);
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
196 rio_dprintk (RIO_DEBUG_INIT
, "RIO-init: Setup ram/size arrays\n");
198 size
[0] = DP_SRAM1_SIZE
;
199 size
[1] = DP_SRAM2_SIZE
;
200 size
[2] = DP_SRAM3_SIZE
;
201 size
[3] = DP_SCRATCH_SIZE
;
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;
208 ram
[3] = (char *)&DpRam
->DpScratch
[0];
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]);
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],
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.
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",
235 rio_dprintk (RIO_DEBUG_INIT
, "Test completed\n");
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.
252 RIOScrub(op
, ram
, size
)
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
;
268 oldword
= oldbyte
| (oldbyte
<<8);
270 oldbyte
= oldword
= 0; /* Tell the compiler we've initilalized them. */
272 newword
= newbyte
| (newbyte
<<8);
274 invword
= invbyte
| (invbyte
<<8);
277 ** Check that the RAM contains the value that should have been left there
278 ** by the previous test (not applicable for pass zero)
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
]));
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]));
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.
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
]));
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
]));
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
320 ** This is the WORD operation test.
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]));
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]));
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.
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
]));
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]));
358 ** time to check out byte swapping errors
360 swapword
= invbyte
| (newbyte
<< 8);
362 for (off
=0; off
<size
; off
+=2) {
363 WBYTE(ram
[off
],invbyte
);
364 WBYTE(ram
[off
+1],newbyte
);
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]));
373 *((ushort
*)&ram
[off
]) = ~swapword
;
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
]));
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]));
385 *((ushort
*)&ram
[off
]) = newword
;
392 RIODefaultName(p
, HostP
, UnitId
)
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);
404 HostP
->Mapping
[UnitId
].Name
[14]='1'+UnitId
;
405 HostP
->Mapping
[UnitId
].Name
[15]=0;
410 #define RIO_RELEASE "Linux"
411 #define RELEASE_ID "1.0"
413 static struct rioVersion stVersion
;
418 strlcpy(stVersion
.version
, "RIO driver for linux V1.0",
419 sizeof(stVersion
.version
));
420 strlcpy(stVersion
.buildDate
, __DATE__
,
421 sizeof(stVersion
.buildDate
));
427 RIOHostReset(Type
, DpRamP
, Slot
)
429 volatile struct DpRam
*DpRamP
;
435 rio_dprintk (RIO_DEBUG_INIT
, "RIOHostReset: type 0x%x", Type
);
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);
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);
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;
458 /* for (i=0; i<6000; i++); */
462 rio_dprintk (RIO_DEBUG_INIT
, " (UNKNOWN)\n");