File: /usr/src/linux/drivers/char/rio/rioboot.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		: rioboot.c
24     **	SID		: 1.3
25     **	Last Modified	: 11/6/98 10:33:36
26     **	Retrieved	: 11/6/98 10:33:48
27     **
28     **  ident @(#)rioboot.c	1.3
29     **
30     ** -----------------------------------------------------------------------------
31     */
32     
33     #ifdef SCCS_LABELS
34     static char *_rioboot_c_sccs_ = "@(#)rioboot.c	1.3";
35     #endif
36     
37     #define __NO_VERSION__
38     #include <linux/module.h>
39     #include <linux/slab.h>
40     #include <linux/errno.h>
41     #include <linux/interrupt.h>
42     #include <asm/io.h>
43     #include <asm/system.h>
44     #include <asm/string.h>
45     #include <asm/semaphore.h>
46     
47     
48     #include <linux/termios.h>
49     #include <linux/serial.h>
50     
51     #include <linux/compatmac.h>
52     #include <linux/generic_serial.h>
53     
54     
55     
56     #include "linux_compat.h"
57     #include "rio_linux.h"
58     #include "typdef.h"
59     #include "pkt.h"
60     #include "daemon.h"
61     #include "rio.h"
62     #include "riospace.h"
63     #include "top.h"
64     #include "cmdpkt.h"
65     #include "map.h"
66     #include "riotypes.h"
67     #include "rup.h"
68     #include "port.h"
69     #include "riodrvr.h"
70     #include "rioinfo.h"
71     #include "func.h"
72     #include "errors.h"
73     #include "pci.h"
74     
75     #include "parmmap.h"
76     #include "unixrup.h"
77     #include "board.h"
78     #include "host.h"
79     #include "error.h"
80     #include "phb.h"
81     #include "link.h"
82     #include "cmdblk.h"
83     #include "route.h"
84     
85     static uchar
86     RIOAtVec2Ctrl[] =
87     {
88     	/* 0 */  INTERRUPT_DISABLE,
89     	/* 1 */  INTERRUPT_DISABLE,
90     	/* 2 */  INTERRUPT_DISABLE,
91     	/* 3 */  INTERRUPT_DISABLE,
92     	/* 4 */  INTERRUPT_DISABLE,
93     	/* 5 */  INTERRUPT_DISABLE,
94     	/* 6 */  INTERRUPT_DISABLE,
95     	/* 7 */  INTERRUPT_DISABLE,
96     	/* 8 */  INTERRUPT_DISABLE,
97     	/* 9 */  IRQ_9|INTERRUPT_ENABLE,
98     	/* 10 */ INTERRUPT_DISABLE,
99     	/* 11 */ IRQ_11|INTERRUPT_ENABLE,
100     	/* 12 */ IRQ_12|INTERRUPT_ENABLE,
101     	/* 13 */ INTERRUPT_DISABLE,
102     	/* 14 */ INTERRUPT_DISABLE,
103     	/* 15 */ IRQ_15|INTERRUPT_ENABLE
104     };
105     
106     /*
107     ** Load in the RTA boot code.
108     */
109     int
110     RIOBootCodeRTA(p, rbp)
111     struct rio_info *	p;
112     struct DownLoad *	rbp; 
113     {
114     	int offset;
115     
116     	func_enter ();
117     
118     	/* Linux doesn't allow you to disable interrupts during a
119     	   "copyin". (Crash when a pagefault occurs). */
120     	/* disable(oldspl); */
121     	
122     	rio_dprintk (RIO_DEBUG_BOOT, "Data at user address 0x%x\n",(int)rbp->DataP);
123     
124     	/*
125     	** Check that we have set asside enough memory for this
126     	*/
127     	if ( rbp->Count > SIXTY_FOUR_K ) {
128     		rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot Code Too Large!\n");
129     		p->RIOError.Error = HOST_FILE_TOO_LARGE;
130     		/* restore(oldspl); */
131     		func_exit ();
132     		return ENOMEM;
133     	}
134     
135     	if ( p->RIOBooting ) {
136     		rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot Code : BUSY BUSY BUSY!\n");
137     		p->RIOError.Error = BOOT_IN_PROGRESS;
138     		/* restore(oldspl); */
139     		func_exit ();
140     		return EBUSY;
141     	}
142     
143     	/*
144     	** The data we load in must end on a (RTA_BOOT_DATA_SIZE) byte boundary,
145     	** so calculate how far we have to move the data up the buffer
146     	** to achieve this.
147     	*/
148     	offset = (RTA_BOOT_DATA_SIZE - (rbp->Count % RTA_BOOT_DATA_SIZE)) % 
149     							RTA_BOOT_DATA_SIZE;
150     
151     	/*
152     	** Be clean, and clear the 'unused' portion of the boot buffer,
153     	** because it will (eventually) be part of the Rta run time environment
154     	** and so should be zeroed.
155     	*/
156     	bzero( (caddr_t)p->RIOBootPackets, offset );
157     
158     	/*
159     	** Copy the data from user space.
160     	*/
161     
162     	if ( copyin((int)rbp->DataP,((caddr_t)(p->RIOBootPackets))+offset,
163     				rbp->Count) ==COPYFAIL ) {
164     		rio_dprintk (RIO_DEBUG_BOOT, "Bad data copy from user space\n");
165     		p->RIOError.Error = COPYIN_FAILED;
166     		/* restore(oldspl); */
167     		func_exit ();
168     		return EFAULT;
169     	}
170     
171     	/*
172     	** Make sure that our copy of the size includes that offset we discussed
173     	** earlier.
174     	*/
175     	p->RIONumBootPkts = (rbp->Count+offset)/RTA_BOOT_DATA_SIZE;
176     	p->RIOBootCount   = rbp->Count;
177     
178     	/* restore(oldspl); */
179     	func_exit();
180     	return 0;
181     }
182     
183     void rio_start_card_running (struct Host * HostP)
184     {
185     	func_enter ();
186     
187     	switch ( HostP->Type ) {
188     	case RIO_AT:
189     		rio_dprintk (RIO_DEBUG_BOOT, "Start ISA card running\n");
190     		WBYTE(HostP->Control, 
191     		      BOOT_FROM_RAM | EXTERNAL_BUS_ON
192     		      | HostP->Mode
193     		      | RIOAtVec2Ctrl[HostP->Ivec & 0xF] );
194     		break;
195     		
196     #ifdef FUTURE_RELEASE
197     	case RIO_MCA:
198     				/*
199     				** MCA handles IRQ vectors differently, so we don't write 
200     				** them to this register.
201     				*/
202     		rio_dprintk (RIO_DEBUG_BOOT, "Start MCA card running\n");
203     		WBYTE(HostP->Control, McaTpBootFromRam | McaTpBusEnable | HostP->Mode);
204     		break;
205     
206     	case RIO_EISA:
207     				/*
208     				** EISA is totally different and expects OUTBZs to turn it on.
209     				*/
210     		rio_dprintk (RIO_DEBUG_BOOT, "Start EISA card running\n");
211     		OUTBZ( HostP->Slot, EISA_CONTROL_PORT, HostP->Mode | RIOEisaVec2Ctrl[HostP->Ivec] | EISA_TP_RUN | EISA_TP_BUS_ENABLE | EISA_TP_BOOT_FROM_RAM );
212     		break;
213     #endif
214     
215     	case RIO_PCI:
216     				/*
217     				** PCI is much the same as MCA. Everything is once again memory
218     				** mapped, so we are writing to memory registers instead of io
219     				** ports.
220     				*/
221     		rio_dprintk (RIO_DEBUG_BOOT, "Start PCI card running\n");
222     		WBYTE(HostP->Control, PCITpBootFromRam | PCITpBusEnable | HostP->Mode);
223     		break;
224     	default:
225     		rio_dprintk (RIO_DEBUG_BOOT, "Unknown host type %d\n", HostP->Type);
226     		break;
227     	}
228     /* 
229     	printk (KERN_INFO "Done with starting the card\n");
230     	func_exit ();
231     */
232     	return;
233     }
234     
235     /*
236     ** Load in the host boot code - load it directly onto all halted hosts
237     ** of the correct type.
238     **
239     ** Put your rubber pants on before messing with this code - even the magic
240     ** numbers have trouble understanding what they are doing here.
241     */
242     int
243     RIOBootCodeHOST(p, rbp)
244     struct rio_info *	p;
245     register struct DownLoad *rbp;
246     {
247     	register struct Host *HostP;
248     	register caddr_t Cad;
249     	register PARM_MAP *ParmMapP;
250     	register int RupN;
251     	int PortN;
252     	uint host;
253     	caddr_t StartP;
254     	BYTE *DestP;
255     	int wait_count;
256     	ushort OldParmMap;
257     	ushort offset;	/* It is very important that this is a ushort */
258     	/* uint byte; */
259     	caddr_t DownCode = NULL;
260     	unsigned long flags;
261     
262     	HostP = NULL; /* Assure the compiler we've initialized it */
263     	for ( host=0; host<p->RIONumHosts; host++ ) {
264     		rio_dprintk (RIO_DEBUG_BOOT, "Attempt to boot host %d\n",host);
265     		HostP = &p->RIOHosts[host];
266     		
267     		rio_dprintk (RIO_DEBUG_BOOT,  "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n",
268     		    HostP->Type, HostP->Mode, HostP->Ivec);
269     
270     
271     		if ( (HostP->Flags & RUN_STATE) != RC_WAITING ) {
272     			rio_dprintk (RIO_DEBUG_BOOT, "%s %d already running\n","Host",host);
273     			continue;
274     		}
275     
276     		/*
277     		** Grab a 32 bit pointer to the card.
278     		*/
279     		Cad = HostP->Caddr;
280     
281     		/*
282     		** We are going to (try) and load in rbp->Count bytes.
283     		** The last byte will reside at p->RIOConf.HostLoadBase-1;
284     		** Therefore, we need to start copying at address
285     		** (caddr+p->RIOConf.HostLoadBase-rbp->Count)
286     		*/
287     		StartP = (caddr_t)&Cad[p->RIOConf.HostLoadBase-rbp->Count];
288     
289     		rio_dprintk (RIO_DEBUG_BOOT, "kernel virtual address for host is 0x%x\n", (int)Cad );
290     		rio_dprintk (RIO_DEBUG_BOOT, "kernel virtual address for download is 0x%x\n", (int)StartP);
291     		rio_dprintk (RIO_DEBUG_BOOT, "host loadbase is 0x%x\n",p->RIOConf.HostLoadBase);
292     		rio_dprintk (RIO_DEBUG_BOOT, "size of download is 0x%x\n", rbp->Count);
293     
294     		if ( p->RIOConf.HostLoadBase < rbp->Count ) {
295     			rio_dprintk (RIO_DEBUG_BOOT, "Bin too large\n");
296     			p->RIOError.Error = HOST_FILE_TOO_LARGE;
297     			func_exit ();
298     			return EFBIG;
299     		}
300     		/*
301     		** Ensure that the host really is stopped.
302     		** Disable it's external bus & twang its reset line.
303     		*/
304     		RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
305     
306     		/*
307     		** Copy the data directly from user space to the SRAM.
308     		** This ain't going to be none too clever if the download
309     		** code is bigger than this segment.
310     		*/
311     		rio_dprintk (RIO_DEBUG_BOOT, "Copy in code\n");
312     
313     		/*
314     		** PCI hostcard can't cope with 32 bit accesses and so need to copy 
315     		** data to a local buffer, and then dripfeed the card.
316     		*/
317     		if ( HostP->Type == RIO_PCI ) {
318     		  /* int offset; */
319     
320     			DownCode = sysbrk(rbp->Count);
321     			if ( !DownCode ) {
322     				rio_dprintk (RIO_DEBUG_BOOT, "No system memory available\n");
323     				p->RIOError.Error = NOT_ENOUGH_CORE_FOR_PCI_COPY;
324     				func_exit ();
325     				return ENOMEM;
326     			}
327     			bzero(DownCode, rbp->Count);
328     
329     			if ( copyin((int)rbp->DataP,DownCode,rbp->Count)==COPYFAIL ) {
330     				rio_dprintk (RIO_DEBUG_BOOT, "Bad copyin of host data\n");
331     				p->RIOError.Error = COPYIN_FAILED;
332     				func_exit ();
333     				return EFAULT;
334     			}
335     
336     			HostP->Copy( DownCode, StartP, rbp->Count );
337     
338     			sysfree( DownCode, rbp->Count );
339     		}
340     		else if ( copyin((int)rbp->DataP,StartP,rbp->Count)==COPYFAIL ) {
341     			rio_dprintk (RIO_DEBUG_BOOT, "Bad copyin of host data\n");
342     			p->RIOError.Error = COPYIN_FAILED;
343     			func_exit ();
344     			return EFAULT;
345     		}
346     
347     		rio_dprintk (RIO_DEBUG_BOOT, "Copy completed\n");
348     
349     		/*
350     		**			S T O P !
351     		**
352     		** Upto this point the code has been fairly rational, and possibly
353     		** even straight forward. What follows is a pile of crud that will
354     		** magically turn into six bytes of transputer assembler. Normally
355     		** you would expect an array or something, but, being me, I have
356     		** chosen [been told] to use a technique whereby the startup code
357     		** will be correct if we change the loadbase for the code. Which
358     		** brings us onto another issue - the loadbase is the *end* of the
359     		** code, not the start.
360     		**
361     		** If I were you I wouldn't start from here.
362     		*/
363     
364     		/*
365     		** We now need to insert a short boot section into
366     		** the memory at the end of Sram2. This is normally (de)composed
367     		** of the last eight bytes of the download code. The
368     		** download has been assembled/compiled to expect to be
369     		** loaded from 0x7FFF downwards. We have loaded it
370     		** at some other address. The startup code goes into the small
371     		** ram window at Sram2, in the last 8 bytes, which are really
372     		** at addresses 0x7FF8-0x7FFF.
373     		**
374     		** If the loadbase is, say, 0x7C00, then we need to branch to
375     		** address 0x7BFE to run the host.bin startup code. We assemble
376     		** this jump manually.
377     		**
378     		** The two byte sequence 60 08 is loaded into memory at address
379     		** 0x7FFE,F. This is a local branch to location 0x7FF8 (60 is nfix 0,
380     		** which adds '0' to the .O register, complements .O, and then shifts
381     		** it left by 4 bit positions, 08 is a jump .O+8 instruction. This will
382     		** add 8 to .O (which was 0xFFF0), and will branch RELATIVE to the new
383     		** location. Now, the branch starts from the value of .PC (or .IP or
384     		** whatever the bloody register is called on this chip), and the .PC
385     		** will be pointing to the location AFTER the branch, in this case
386     		** .PC == 0x8000, so the branch will be to 0x8000+0xFFF8 = 0x7FF8.
387     		**
388     		** A long branch is coded at 0x7FF8. This consists of loading a four
389     		** byte offset into .O using nfix (as above) and pfix operators. The
390     		** pfix operates in exactly the same way as the nfix operator, but
391     		** without the complement operation. The offset, of course, must be
392     		** relative to the address of the byte AFTER the branch instruction,
393     		** which will be (urm) 0x7FFC, so, our final destination of the branch
394     		** (loadbase-2), has to be reached from here. Imagine that the loadbase
395     		** is 0x7C00 (which it is), then we will need to branch to 0x7BFE (which
396     		** is the first byte of the initial two byte short local branch of the
397     		** download code).
398     		**
399     		** To code a jump from 0x7FFC (which is where the branch will start
400     		** from) to 0x7BFE, we will need to branch 0xFC02 bytes (0x7FFC+0xFC02)=
401     		** 0x7BFE.
402     		** This will be coded as four bytes:
403     		** 60 2C 20 02
404     		** being nfix .O+0
405     		**	   pfix .O+C
406     		**	   pfix .O+0
407     		**	   jump .O+2
408     		**
409     		** The nfix operator is used, so that the startup code will be
410     		** compatible with the whole Tp family. (lies, damn lies, it'll never
411     		** work in a month of Sundays).
412     		**
413     		** The nfix nyble is the 1s compliment of the nyble value you
414     		** want to load - in this case we wanted 'F' so we nfix loaded '0'.
415     		*/
416     
417     
418     		/*
419     		** Dest points to the top 8 bytes of Sram2. The Tp jumps
420     		** to 0x7FFE at reset time, and starts executing. This is
421     		** a short branch to 0x7FF8, where a long branch is coded.
422     		*/
423     
424     		DestP = (BYTE *)&Cad[0x7FF8];	/* <<<---- READ THE ABOVE COMMENTS */
425     
426     #define	NFIX(N)	(0x60 | (N))	/* .O  = (~(.O + N))<<4 */
427     #define	PFIX(N)	(0x20 | (N))	/* .O  =   (.O + N)<<4  */
428     #define	JUMP(N)	(0x00 | (N))	/* .PC =   .PC + .O	 */
429     
430     		/*
431     		** 0x7FFC is the address of the location following the last byte of
432     		** the four byte jump instruction.
433     		** READ THE ABOVE COMMENTS
434     		**
435     		** offset is (TO-FROM) % MEMSIZE, but with compound buggering about.
436     		** Memsize is 64K for this range of Tp, so offset is a short (unsigned,
437     		** cos I don't understand 2's complement).
438     		*/
439     		offset = (p->RIOConf.HostLoadBase-2)-0x7FFC;
440     		WBYTE( DestP[0] , NFIX(((ushort)(~offset) >> (ushort)12) & 0xF) );
441     		WBYTE( DestP[1] , PFIX(( offset >> 8) & 0xF) );
442     		WBYTE( DestP[2] , PFIX(( offset >> 4) & 0xF) );
443     		WBYTE( DestP[3] , JUMP( offset & 0xF) );
444     
445     		WBYTE( DestP[6] , NFIX(0) );
446     		WBYTE( DestP[7] , JUMP(8) );
447     
448     		rio_dprintk (RIO_DEBUG_BOOT, "host loadbase is 0x%x\n",p->RIOConf.HostLoadBase);
449     		rio_dprintk (RIO_DEBUG_BOOT, "startup offset is 0x%x\n",offset);
450     
451     		/*
452     		** Flag what is going on
453     		*/
454     		HostP->Flags &= ~RUN_STATE;
455     		HostP->Flags |= RC_STARTUP;
456     
457     		/*
458     		** Grab a copy of the current ParmMap pointer, so we
459     		** can tell when it has changed.
460     		*/
461     		OldParmMap = RWORD(HostP->__ParmMapR);
462     
463     		rio_dprintk (RIO_DEBUG_BOOT, "Original parmmap is 0x%x\n",OldParmMap);
464     
465     		/*
466     		** And start it running (I hope).
467     		** As there is nothing dodgy or obscure about the
468     		** above code, this is guaranteed to work every time.
469     		*/
470     		rio_dprintk (RIO_DEBUG_BOOT,  "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n",
471     		    HostP->Type, HostP->Mode, HostP->Ivec);
472     
473     		rio_start_card_running(HostP);
474     
475     		rio_dprintk (RIO_DEBUG_BOOT, "Set control port\n");
476     
477     		/*
478     		** Now, wait for upto five seconds for the Tp to setup the parmmap
479     		** pointer:
480     		*/
481     		for ( wait_count=0; (wait_count<p->RIOConf.StartupTime)&&
482     			(RWORD(HostP->__ParmMapR)==OldParmMap); wait_count++ ) {
483     			rio_dprintk (RIO_DEBUG_BOOT, "Checkout %d, 0x%x\n",wait_count,RWORD(HostP->__ParmMapR));
484     			delay(HostP, HUNDRED_MS);
485     
486     		}
487     
488     		/*
489     		** If the parmmap pointer is unchanged, then the host code
490     		** has crashed & burned in a really spectacular way
491     		*/
492     		if ( RWORD(HostP->__ParmMapR) == OldParmMap ) {
493     			rio_dprintk (RIO_DEBUG_BOOT, "parmmap 0x%x\n", RWORD(HostP->__ParmMapR));
494     			rio_dprintk (RIO_DEBUG_BOOT, "RIO Mesg Run Fail\n");
495     
496     #define	HOST_DISABLE \
497     		HostP->Flags &= ~RUN_STATE; \
498     		HostP->Flags |= RC_STUFFED; \
499     		RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );\
500     		continue
501     
502     			HOST_DISABLE;
503     		}
504     
505     		rio_dprintk (RIO_DEBUG_BOOT, "Running 0x%x\n", RWORD(HostP->__ParmMapR));
506     
507     		/*
508     		** Well, the board thought it was OK, and setup its parmmap
509     		** pointer. For the time being, we will pretend that this
510     		** board is running, and check out what the error flag says.
511     		*/
512     
513     		/*
514     		** Grab a 32 bit pointer to the parmmap structure
515     		*/
516     		ParmMapP = (PARM_MAP *)RIO_PTR(Cad,RWORD(HostP->__ParmMapR));
517     		rio_dprintk (RIO_DEBUG_BOOT, "ParmMapP : %x\n", (int)ParmMapP);
518     		ParmMapP = (PARM_MAP *)((unsigned long)Cad + 
519     						(unsigned long)((RWORD((HostP->__ParmMapR))) & 0xFFFF)); 
520     		rio_dprintk (RIO_DEBUG_BOOT, "ParmMapP : %x\n", (int)ParmMapP);
521     
522     		/*
523     		** The links entry should be 0xFFFF; we set it up
524     		** with a mask to say how many PHBs to use, and 
525     		** which links to use.
526     		*/
527     		if ( (RWORD(ParmMapP->links) & 0xFFFF) != 0xFFFF ) {
528     			rio_dprintk (RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name);
529     			rio_dprintk (RIO_DEBUG_BOOT, "Links = 0x%x\n",RWORD(ParmMapP->links));
530     			HOST_DISABLE;
531     		}
532     
533     		WWORD(ParmMapP->links , RIO_LINK_ENABLE);
534     
535     		/*
536     		** now wait for the card to set all the parmmap->XXX stuff
537     		** this is a wait of upto two seconds....
538     		*/
539     		rio_dprintk (RIO_DEBUG_BOOT, "Looking for init_done - %d ticks\n",p->RIOConf.StartupTime);
540     		HostP->timeout_id = 0;
541     		for ( wait_count=0; (wait_count<p->RIOConf.StartupTime) && 
542     						!RWORD(ParmMapP->init_done); wait_count++ ) {
543     			rio_dprintk (RIO_DEBUG_BOOT, "Waiting for init_done\n");
544     			delay(HostP, HUNDRED_MS);
545     		}
546     		rio_dprintk (RIO_DEBUG_BOOT, "OK! init_done!\n");
547     
548     		if (RWORD(ParmMapP->error) != E_NO_ERROR || 
549     							!RWORD(ParmMapP->init_done) ) {
550     			rio_dprintk (RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name);
551     			rio_dprintk (RIO_DEBUG_BOOT, "Timedout waiting for init_done\n");
552     			HOST_DISABLE;
553     		}
554     
555     		rio_dprintk (RIO_DEBUG_BOOT, "Got init_done\n");
556     
557     		/*
558     		** It runs! It runs!
559     		*/
560     		rio_dprintk (RIO_DEBUG_BOOT, "Host ID %x Running\n",HostP->UniqueNum);
561     
562     		/*
563     		** set the time period between interrupts.
564     		*/
565     		WWORD(ParmMapP->timer, (short)p->RIOConf.Timer );
566     
567     		/*
568     		** Translate all the 16 bit pointers in the __ParmMapR into
569     		** 32 bit pointers for the driver.
570     		*/
571     		HostP->ParmMapP	 =	ParmMapP;
572     		HostP->PhbP		 =	(PHB*)RIO_PTR(Cad,RWORD(ParmMapP->phb_ptr));
573     		HostP->RupP		 =	(RUP*)RIO_PTR(Cad,RWORD(ParmMapP->rups));
574     		HostP->PhbNumP	  = (ushort*)RIO_PTR(Cad,RWORD(ParmMapP->phb_num_ptr));
575     		HostP->LinkStrP	 =	(LPB*)RIO_PTR(Cad,RWORD(ParmMapP->link_str_ptr));
576     
577     		/*
578     		** point the UnixRups at the real Rups
579     		*/
580     		for ( RupN = 0; RupN<MAX_RUP; RupN++ ) {
581     			HostP->UnixRups[RupN].RupP		= &HostP->RupP[RupN];
582     			HostP->UnixRups[RupN].Id		  = RupN+1;
583     			HostP->UnixRups[RupN].BaseSysPort = NO_PORT;
584     			HostP->UnixRups[RupN].RupLock = SPIN_LOCK_UNLOCKED;
585     		}
586     
587     		for ( RupN = 0; RupN<LINKS_PER_UNIT; RupN++ ) {
588     			HostP->UnixRups[RupN+MAX_RUP].RupP	= &HostP->LinkStrP[RupN].rup;
589     			HostP->UnixRups[RupN+MAX_RUP].Id  = 0;
590     			HostP->UnixRups[RupN+MAX_RUP].BaseSysPort = NO_PORT;
591     			HostP->UnixRups[RupN+MAX_RUP].RupLock = SPIN_LOCK_UNLOCKED;
592     		}
593     
594     		/*
595     		** point the PortP->Phbs at the real Phbs
596     		*/
597     		for ( PortN=p->RIOFirstPortsMapped; 
598     				PortN<p->RIOLastPortsMapped+PORTS_PER_RTA; PortN++ ) {
599     			if ( p->RIOPortp[PortN]->HostP == HostP ) {
600     				struct Port *PortP = p->RIOPortp[PortN];
601     				struct PHB *PhbP;
602     				/* int oldspl; */
603     
604     				if ( !PortP->Mapped )
605     					continue;
606     
607     				PhbP = &HostP->PhbP[PortP->HostPort];
608     				rio_spin_lock_irqsave(&PortP->portSem, flags);
609     
610     				PortP->PhbP = PhbP;
611     
612     				PortP->TxAdd	= (WORD *)RIO_PTR(Cad,RWORD(PhbP->tx_add));
613     				PortP->TxStart  = (WORD *)RIO_PTR(Cad,RWORD(PhbP->tx_start));
614     				PortP->TxEnd	= (WORD *)RIO_PTR(Cad,RWORD(PhbP->tx_end));
615     				PortP->RxRemove = (WORD *)RIO_PTR(Cad,RWORD(PhbP->rx_remove));
616     				PortP->RxStart  = (WORD *)RIO_PTR(Cad,RWORD(PhbP->rx_start));
617     				PortP->RxEnd	= (WORD *)RIO_PTR(Cad,RWORD(PhbP->rx_end));
618     
619     				rio_spin_unlock_irqrestore(&PortP->portSem, flags);
620     				/*
621     				** point the UnixRup at the base SysPort
622     				*/
623     				if ( !(PortN % PORTS_PER_RTA) )
624     					HostP->UnixRups[PortP->RupNum].BaseSysPort = PortN;
625     			}
626     		}
627     
628     		rio_dprintk (RIO_DEBUG_BOOT, "Set the card running... \n");
629     		/*
630     		** last thing - show the world that everything is in place
631     		*/
632     		HostP->Flags &= ~RUN_STATE;
633     		HostP->Flags |= RC_RUNNING;
634     	}
635     	/*
636     	** MPX always uses a poller. This is actually patched into the system
637     	** configuration and called directly from each clock tick.
638     	**
639     	*/
640     	p->RIOPolling = 1;
641     
642     	p->RIOSystemUp++;
643     	
644     	rio_dprintk (RIO_DEBUG_BOOT, "Done everything %x\n", HostP->Ivec);
645     	func_exit ();
646     	return 0;
647     }
648     
649     
650     
651     /*
652     ** Boot an RTA. If we have successfully processed this boot, then
653     ** return 1. If we havent, then return 0.
654     */
655     int
656     RIOBootRup( p, Rup, HostP, PacketP)
657     struct rio_info *	p;
658     uint Rup;
659     struct Host *HostP;
660     struct PKT *PacketP; 
661     {
662     	struct PktCmd *PktCmdP = (struct PktCmd *)PacketP->data;
663     	struct PktCmd_M *PktReplyP;
664     	struct CmdBlk *CmdBlkP;
665     	uint sequence;
666     
667     #ifdef CHECK
668     	CheckHost(Host);
669     	CheckRup(Rup);
670     	CheckHostP(HostP);
671     	CheckPacketP(PacketP);
672     #endif
673     
674     	/*
675     	** If we haven't been told what to boot, we can't boot it.
676     	*/
677     	if ( p->RIONumBootPkts == 0 ) {
678     		rio_dprintk (RIO_DEBUG_BOOT, "No RTA code to download yet\n");
679     		return 0;
680     	}
681     
682     	/* rio_dprint(RIO_DEBUG_BOOT, NULL,DBG_BOOT,"Incoming command packet\n"); */
683     	/* ShowPacket( DBG_BOOT, PacketP ); */
684     
685     	/*
686     	** Special case of boot completed - if we get one of these then we
687     	** don't need a command block. For all other cases we do, so handle
688     	** this first and then get a command block, then handle every other
689     	** case, relinquishing the command block if disaster strikes!
690     	*/
691     	if ( (RBYTE(PacketP->len) & PKT_CMD_BIT) && 
692     			(RBYTE(PktCmdP->Command)==BOOT_COMPLETED) )
693     		return RIOBootComplete(p, HostP, Rup, PktCmdP );
694     
695     	/*
696     	** try to unhook a command block from the command free list.
697     	*/
698     	if ( !(CmdBlkP = RIOGetCmdBlk()) ) {
699     		rio_dprintk (RIO_DEBUG_BOOT, "No command blocks to boot RTA! come back later.\n");
700     		return 0;
701     	}
702     
703     	/*
704     	** Fill in the default info on the command block
705     	*/
706     	CmdBlkP->Packet.dest_unit = Rup < (ushort)MAX_RUP ? Rup : 0;
707     	CmdBlkP->Packet.dest_port = BOOT_RUP;
708     	CmdBlkP->Packet.src_unit  = 0;
709     	CmdBlkP->Packet.src_port  = BOOT_RUP;
710     
711     	CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
712     	PktReplyP = (struct PktCmd_M *)CmdBlkP->Packet.data;
713     
714     	/*
715     	** process COMMANDS on the boot rup!
716     	*/
717     	if ( RBYTE(PacketP->len) & PKT_CMD_BIT ) {
718     		/*
719     		** We only expect one type of command - a BOOT_REQUEST!
720     		*/
721     		if ( RBYTE(PktCmdP->Command) != BOOT_REQUEST ) {
722     			rio_dprintk (RIO_DEBUG_BOOT, "Unexpected command %d on BOOT RUP %d of host %d\n", 
723     						PktCmdP->Command,Rup,HostP-p->RIOHosts);
724     			ShowPacket( DBG_BOOT, PacketP );
725     			RIOFreeCmdBlk( CmdBlkP );
726     			return 1;
727     		}
728     
729     		/*
730     		** Build a Boot Sequence command block
731     		**
732     		** 02.03.1999 ARG - ESIL 0820 fix
733     		** We no longer need to use "Boot Mode", we'll always allow
734     		** boot requests - the boot will not complete if the device
735     		** appears in the bindings table.
736     		** So, this conditional is not required ...
737     		**
738     		if (p->RIOBootMode == RC_BOOT_NONE)
739     			**
740     			** If the system is in slave mode, and a boot request is
741     			** received, set command to BOOT_ABORT so that the boot
742     			** will not complete.
743     			**
744     			PktReplyP->Command			 = BOOT_ABORT;
745     		else
746     		**
747     		** We'll just (always) set the command field in packet reply
748     		** to allow an attempted boot sequence :
749     		*/
750     		PktReplyP->Command = BOOT_SEQUENCE;
751     
752     		PktReplyP->BootSequence.NumPackets = p->RIONumBootPkts;
753     		PktReplyP->BootSequence.LoadBase   = p->RIOConf.RtaLoadBase;
754     		PktReplyP->BootSequence.CodeSize   = p->RIOBootCount;
755     
756     		CmdBlkP->Packet.len				= BOOT_SEQUENCE_LEN | PKT_CMD_BIT;
757     
758     		bcopy("BOOT",(void *)&CmdBlkP->Packet.data[BOOT_SEQUENCE_LEN],4);
759     
760     		rio_dprintk (RIO_DEBUG_BOOT, "Boot RTA on Host %d Rup %d - %d (0x%x) packets to 0x%x\n",
761     			HostP-p->RIOHosts, Rup, p->RIONumBootPkts, p->RIONumBootPkts, 
762     								p->RIOConf.RtaLoadBase);
763     
764     		/*
765     		** If this host is in slave mode, send the RTA an invalid boot
766     		** sequence command block to force it to kill the boot. We wait
767     		** for half a second before sending this packet to prevent the RTA
768     		** attempting to boot too often. The master host should then grab
769     		** the RTA and make it its own.
770     		*/
771     		p->RIOBooting++;
772     		RIOQueueCmdBlk( HostP, Rup, CmdBlkP );
773     		return 1;
774     	}
775     
776     	/*
777     	** It is a request for boot data.
778     	*/
779     	sequence = RWORD(PktCmdP->Sequence);
780     
781     	rio_dprintk (RIO_DEBUG_BOOT, "Boot block %d on Host %d Rup%d\n",sequence,HostP-p->RIOHosts,Rup);
782     
783     	if ( sequence >= p->RIONumBootPkts ) {
784     		rio_dprintk (RIO_DEBUG_BOOT, "Got a request for packet %d, max is %d\n", sequence, 
785     					p->RIONumBootPkts);
786     		ShowPacket( DBG_BOOT, PacketP );
787     	}
788     
789     	PktReplyP->Sequence = sequence;
790     
791     	bcopy( p->RIOBootPackets[ p->RIONumBootPkts - sequence - 1 ], 
792     				PktReplyP->BootData, RTA_BOOT_DATA_SIZE );
793     
794     	CmdBlkP->Packet.len = PKT_MAX_DATA_LEN;
795     	ShowPacket( DBG_BOOT, &CmdBlkP->Packet );
796     	RIOQueueCmdBlk( HostP, Rup, CmdBlkP );
797     	return 1;
798     }
799     
800     /*
801     ** This function is called when an RTA been booted.
802     ** If booted by a host, HostP->HostUniqueNum is the booting host.
803     ** If booted by an RTA, HostP->Mapping[Rup].RtaUniqueNum is the booting RTA.
804     ** RtaUniq is the booted RTA.
805     */
806     int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, struct PktCmd *PktCmdP )
807     {
808     	struct Map	*MapP = NULL;
809     	struct Map	*MapP2 = NULL;
810     	int	Flag;
811     	int	found;
812     	int	host, rta;
813     	int	EmptySlot = -1;
814     	int	entry, entry2;
815     	char	*MyType, *MyName;
816     	uint	MyLink;
817     	ushort	RtaType;
818     	uint	RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) +
819     			  (RBYTE(PktCmdP->UniqNum[1]) << 8) +
820     			  (RBYTE(PktCmdP->UniqNum[2]) << 16) +
821     			  (RBYTE(PktCmdP->UniqNum[3]) << 24);
822     
823     	/* Was RIOBooting-- . That's bad. If an RTA sends two of them, the
824     	   driver will never think that the RTA has booted... -- REW */
825     	p->RIOBooting = 0;
826     
827     	rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot completed - BootInProgress now %d\n", p->RIOBooting);
828     
829     	/*
830     	** Determine type of unit (16/8 port RTA).
831     	*/
832     	RtaType = GetUnitType(RtaUniq);
833             if ( Rup >= (ushort)MAX_RUP ) {
834     	    rio_dprintk (RIO_DEBUG_BOOT, "RIO: Host %s has booted an RTA(%d) on link %c\n",
835     	     HostP->Name, 8 * RtaType, RBYTE(PktCmdP->LinkNum)+'A');
836     	} else {
837     	    rio_dprintk (RIO_DEBUG_BOOT, "RIO: RTA %s has booted an RTA(%d) on link %c\n",
838     	     HostP->Mapping[Rup].Name, 8 * RtaType,
839     	     RBYTE(PktCmdP->LinkNum)+'A');
840     	}
841     
842     	rio_dprintk (RIO_DEBUG_BOOT, "UniqNum is 0x%x\n",RtaUniq);
843     
844             if ( ( RtaUniq == 0x00000000 ) || ( RtaUniq == 0xffffffff ) )
845     	{
846     	    rio_dprintk (RIO_DEBUG_BOOT, "Illegal RTA Uniq Number\n");
847     	    return TRUE;
848     	}
849     
850     	/*
851     	** If this RTA has just booted an RTA which doesn't belong to this
852     	** system, or the system is in slave mode, do not attempt to create
853     	** a new table entry for it.
854     	*/
855     	if (!RIOBootOk(p, HostP, RtaUniq))
856     	{
857     	    MyLink = RBYTE(PktCmdP->LinkNum);
858     	    if (Rup < (ushort) MAX_RUP)
859     	    {
860     		/*
861     		** RtaUniq was clone booted (by this RTA). Instruct this RTA
862     		** to hold off further attempts to boot on this link for 30
863     		** seconds.
864     		*/
865     		if (RIOSuspendBootRta(HostP, HostP->Mapping[Rup].ID, MyLink))
866     		{
867     		    rio_dprintk (RIO_DEBUG_BOOT, "RTA failed to suspend booting on link %c\n",
868     		     'A' + MyLink);
869     		}
870     	    }
871     	    else
872     	    {
873     		/*
874     		** RtaUniq was booted by this host. Set the booting link
875     		** to hold off for 30 seconds to give another unit a
876     		** chance to boot it.
877     		*/
878     		WWORD(HostP->LinkStrP[MyLink].WaitNoBoot, 30);
879     	    }
880     	    rio_dprintk (RIO_DEBUG_BOOT, "RTA %x not owned - suspend booting down link %c on unit %x\n",
881     	      RtaUniq, 'A' + MyLink, HostP->Mapping[Rup].RtaUniqueNum);
882     	    return TRUE;
883     	}
884     
885     	/*
886     	** Check for a SLOT_IN_USE entry for this RTA attached to the
887     	** current host card in the driver table.
888     	**
889     	** If it exists, make a note that we have booted it. Other parts of
890     	** the driver are interested in this information at a later date,
891     	** in particular when the booting RTA asks for an ID for this unit,
892     	** we must have set the BOOTED flag, and the NEWBOOT flag is used
893     	** to force an open on any ports that where previously open on this
894     	** unit.
895     	*/
896             for ( entry=0; entry<MAX_RUP; entry++ )
897     	{
898     	    uint sysport;
899     
900     	    if ((HostP->Mapping[entry].Flags & SLOT_IN_USE) && 
901     	       (HostP->Mapping[entry].RtaUniqueNum==RtaUniq))
902     	    {
903     	        HostP->Mapping[entry].Flags |= RTA_BOOTED|RTA_NEWBOOT;
904     #if NEED_TO_FIX
905     		RIO_SV_BROADCAST(HostP->svFlags[entry]);
906     #endif
907     		if ( (sysport=HostP->Mapping[entry].SysPort) != NO_PORT )
908     		{
909     		   if ( sysport < p->RIOFirstPortsBooted )
910     			p->RIOFirstPortsBooted = sysport;
911     		   if ( sysport > p->RIOLastPortsBooted )
912     			p->RIOLastPortsBooted = sysport;
913     		   /*
914     		   ** For a 16 port RTA, check the second bank of 8 ports
915     		   */
916     		   if (RtaType == TYPE_RTA16)
917     		   {
918     			entry2 = HostP->Mapping[entry].ID2 - 1;
919     			HostP->Mapping[entry2].Flags |= RTA_BOOTED|RTA_NEWBOOT;
920     #if NEED_TO_FIX
921     			RIO_SV_BROADCAST(HostP->svFlags[entry2]);
922     #endif
923     			sysport = HostP->Mapping[entry2].SysPort;
924     			if ( sysport < p->RIOFirstPortsBooted )
925     			    p->RIOFirstPortsBooted = sysport;
926     			if ( sysport > p->RIOLastPortsBooted )
927     			    p->RIOLastPortsBooted = sysport;
928     		   }
929     		}
930     		if (RtaType == TYPE_RTA16) {
931     		   rio_dprintk (RIO_DEBUG_BOOT, "RTA will be given IDs %d+%d\n",
932     		    entry+1, entry2+1);
933     		} else {
934     		   rio_dprintk (RIO_DEBUG_BOOT, "RTA will be given ID %d\n",entry+1);
935     		}
936     		return TRUE;
937     	    }
938     	}
939     
940     	rio_dprintk (RIO_DEBUG_BOOT, "RTA not configured for this host\n");
941     
942     	if ( Rup >= (ushort)MAX_RUP )
943     	{
944     	    /*
945     	    ** It was a host that did the booting
946     	    */
947     	    MyType = "Host";
948     	    MyName = HostP->Name;
949     	}
950     	else
951     	{
952     	    /*
953     	    ** It was an RTA that did the booting
954     	    */
955     	    MyType = "RTA";
956     	    MyName = HostP->Mapping[Rup].Name;
957     	}
958     #ifdef CHECK
959     	CheckString(MyType);
960     	CheckString(MyName);
961     #endif
962     
963     	MyLink = RBYTE(PktCmdP->LinkNum);
964     
965     	/*
966     	** There is no SLOT_IN_USE entry for this RTA attached to the current
967     	** host card in the driver table.
968     	**
969     	** Check for a SLOT_TENTATIVE entry for this RTA attached to the
970     	** current host card in the driver table.
971     	**
972     	** If we find one, then we re-use that slot.
973     	*/
974     	for ( entry=0; entry<MAX_RUP; entry++ )
975     	{
976     	    if ( (HostP->Mapping[entry].Flags & SLOT_TENTATIVE) &&
977     		 (HostP->Mapping[entry].RtaUniqueNum == RtaUniq) )
978     	    {
979     		if (RtaType == TYPE_RTA16)
980     		{
981     		    entry2 = HostP->Mapping[entry].ID2 - 1;
982     		    if ( (HostP->Mapping[entry2].Flags & SLOT_TENTATIVE) &&
983     			 (HostP->Mapping[entry2].RtaUniqueNum == RtaUniq) )
984     			rio_dprintk (RIO_DEBUG_BOOT, "Found previous tentative slots (%d+%d)\n",
985     			 entry, entry2);
986     		    else
987     			continue;
988     		}
989     		else
990     			rio_dprintk (RIO_DEBUG_BOOT, "Found previous tentative slot (%d)\n",entry);
991     		if (! p->RIONoMessage)
992     		    cprintf("RTA connected to %s '%s' (%c) not configured.\n",MyType,MyName,MyLink+'A');
993     		return TRUE;
994     	    }
995     	}
996     
997     	/*
998     	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
999     	** attached to the current host card in the driver table.
1000     	**
1001     	** Check if there is a SLOT_IN_USE or SLOT_TENTATIVE entry on another
1002     	** host for this RTA in the driver table.
1003     	**
1004     	** For a SLOT_IN_USE entry on another host, we need to delete the RTA
1005     	** entry from the other host and add it to this host (using some of
1006     	** the functions from table.c which do this).
1007     	** For a SLOT_TENTATIVE entry on another host, we must cope with the
1008     	** following scenario:
1009     	**
1010     	** + Plug 8 port RTA into host A. (This creates SLOT_TENTATIVE entry
1011     	**   in table)
1012     	** + Unplug RTA and plug into host B. (We now have 2 SLOT_TENTATIVE
1013     	**   entries)
1014     	** + Configure RTA on host B. (This slot now becomes SLOT_IN_USE)
1015     	** + Unplug RTA and plug back into host A.
1016     	** + Configure RTA on host A. We now have the same RTA configured
1017     	**   with different ports on two different hosts.
1018     	*/
1019     	rio_dprintk (RIO_DEBUG_BOOT, "Have we seen RTA %x before?\n", RtaUniq );
1020     	found = 0;
1021     	Flag = 0; /* Convince the compiler this variable is initialized */
1022     	for ( host = 0; !found && (host < p->RIONumHosts); host++ )
1023     	{
1024     	    for ( rta=0; rta<MAX_RUP; rta++ )
1025     	    {
1026     		if ((p->RIOHosts[host].Mapping[rta].Flags &
1027     		 (SLOT_IN_USE | SLOT_TENTATIVE)) &&
1028     		 (p->RIOHosts[host].Mapping[rta].RtaUniqueNum==RtaUniq))
1029     		{
1030     		    Flag = p->RIOHosts[host].Mapping[rta].Flags;
1031     		    MapP = &p->RIOHosts[host].Mapping[rta];
1032     		    if (RtaType == TYPE_RTA16)
1033     		    {
1034     			MapP2 = &p->RIOHosts[host].Mapping[MapP->ID2 - 1];
1035     			rio_dprintk (RIO_DEBUG_BOOT, "This RTA is units %d+%d from host %s\n",
1036     			 rta+1, MapP->ID2, p->RIOHosts[host].Name);
1037     		    }
1038     		    else
1039     			rio_dprintk (RIO_DEBUG_BOOT, "This RTA is unit %d from host %s\n",
1040     			 rta+1, p->RIOHosts[host].Name);
1041     		    found = 1;
1042     		    break;
1043     		}
1044     	    }
1045     	}
1046     
1047     	/*
1048     	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
1049     	** attached to the current host card in the driver table.
1050     	**
1051     	** If we have not found a SLOT_IN_USE or SLOT_TENTATIVE entry on
1052     	** another host for this RTA in the driver table...
1053     	**
1054     	** Check for a SLOT_IN_USE entry for this RTA in the config table.
1055     	*/
1056     	if ( !MapP )
1057     	{
1058     	    rio_dprintk (RIO_DEBUG_BOOT, "Look for RTA %x in RIOSavedTable\n",RtaUniq);
1059     	    for ( rta=0; rta < TOTAL_MAP_ENTRIES; rta++ )
1060     	    {
1061     		rio_dprintk (RIO_DEBUG_BOOT, "Check table entry %d (%x)",
1062     		      rta,
1063     		      p->RIOSavedTable[rta].RtaUniqueNum);
1064     
1065     		if ( (p->RIOSavedTable[rta].Flags & SLOT_IN_USE) &&
1066     		 (p->RIOSavedTable[rta].RtaUniqueNum == RtaUniq) )
1067     		{
1068     		    MapP = &p->RIOSavedTable[rta];
1069     		    Flag = p->RIOSavedTable[rta].Flags;
1070     		    if (RtaType == TYPE_RTA16)
1071     		    {
1072                             for (entry2 = rta + 1; entry2 < TOTAL_MAP_ENTRIES;
1073                              entry2++)
1074                             {
1075                                 if (p->RIOSavedTable[entry2].RtaUniqueNum == RtaUniq)
1076                                     break;
1077                             }
1078                             MapP2 = &p->RIOSavedTable[entry2];
1079                             rio_dprintk (RIO_DEBUG_BOOT, "This RTA is from table entries %d+%d\n",
1080                                   rta, entry2);
1081     		    }
1082     		    else
1083     			rio_dprintk (RIO_DEBUG_BOOT, "This RTA is from table entry %d\n", rta);
1084     		    break;
1085     		}
1086     	    }
1087     	}
1088     
1089     	/*
1090     	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
1091     	** attached to the current host card in the driver table.
1092     	**
1093     	** We may have found a SLOT_IN_USE entry on another host for this
1094     	** RTA in the config table, or a SLOT_IN_USE or SLOT_TENTATIVE entry
1095     	** on another host for this RTA in the driver table.
1096     	**
1097     	** Check the driver table for room to fit this newly discovered RTA.
1098     	** RIOFindFreeID() first looks for free slots and if it does not
1099     	** find any free slots it will then attempt to oust any
1100     	** tentative entry in the table.
1101     	*/
1102     	EmptySlot = 1;
1103     	if (RtaType == TYPE_RTA16)
1104     	{
1105     	    if (RIOFindFreeID(p, HostP, &entry, &entry2) == 0)
1106     	    {
1107     		RIODefaultName(p, HostP, entry);
1108     		FillSlot(entry, entry2, RtaUniq, HostP);
1109     		EmptySlot = 0;
1110     	    }
1111     	}
1112     	else
1113     	{
1114     	    if (RIOFindFreeID(p, HostP, &entry, NULL) == 0)
1115     	    {
1116     		RIODefaultName(p, HostP, entry);
1117     		FillSlot(entry, 0, RtaUniq, HostP);
1118     		EmptySlot = 0;
1119     	    }
1120     	}
1121     
1122     	/*
1123     	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
1124     	** attached to the current host card in the driver table.
1125     	**
1126     	** If we found a SLOT_IN_USE entry on another host for this
1127     	** RTA in the config or driver table, and there are enough free
1128     	** slots in the driver table, then we need to move it over and
1129     	** delete it from the other host.
1130     	** If we found a SLOT_TENTATIVE entry on another host for this
1131     	** RTA in the driver table, just delete the other host entry.
1132     	*/
1133     	if (EmptySlot == 0)
1134     	{
1135     	    if ( MapP )
1136     	    {
1137     		if (Flag & SLOT_IN_USE)
1138     		{
1139     		    rio_dprintk (RIO_DEBUG_BOOT, 
1140         "This RTA configured on another host - move entry to current host (1)\n");
1141     		    HostP->Mapping[entry].SysPort = MapP->SysPort;
1142     		    CCOPY( MapP->Name, HostP->Mapping[entry].Name, MAX_NAME_LEN );
1143     		    HostP->Mapping[entry].Flags =
1144     		     SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT;
1145     #if NEED_TO_FIX
1146     		    RIO_SV_BROADCAST(HostP->svFlags[entry]);
1147     #endif
1148     		    RIOReMapPorts( p, HostP, &HostP->Mapping[entry] );
1149     		    if ( HostP->Mapping[entry].SysPort < p->RIOFirstPortsBooted )
1150     			p->RIOFirstPortsBooted = HostP->Mapping[entry].SysPort;
1151     		    if ( HostP->Mapping[entry].SysPort > p->RIOLastPortsBooted )
1152     			p->RIOLastPortsBooted = HostP->Mapping[entry].SysPort;
1153     		    rio_dprintk (RIO_DEBUG_BOOT, "SysPort %d, Name %s\n",(int)MapP->SysPort,MapP->Name);
1154     		}
1155     		else
1156     		{
1157     		    rio_dprintk (RIO_DEBUG_BOOT, 
1158        "This RTA has a tentative entry on another host - delete that entry (1)\n");
1159     		    HostP->Mapping[entry].Flags =
1160     		     SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT;
1161     #if NEED_TO_FIX
1162     		    RIO_SV_BROADCAST(HostP->svFlags[entry]);
1163     #endif
1164     		}
1165     		if (RtaType == TYPE_RTA16)
1166     		{
1167     		    if (Flag & SLOT_IN_USE)
1168     		    {
1169     			HostP->Mapping[entry2].Flags = SLOT_IN_USE |
1170     			 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1171     #if NEED_TO_FIX
1172     			RIO_SV_BROADCAST(HostP->svFlags[entry2]);
1173     #endif
1174     			HostP->Mapping[entry2].SysPort = MapP2->SysPort;
1175     			/*
1176     			** Map second block of ttys for 16 port RTA
1177     			*/
1178     			RIOReMapPorts( p, HostP, &HostP->Mapping[entry2] );
1179     		       if (HostP->Mapping[entry2].SysPort < p->RIOFirstPortsBooted)
1180     			 p->RIOFirstPortsBooted = HostP->Mapping[entry2].SysPort;
1181     		       if (HostP->Mapping[entry2].SysPort > p->RIOLastPortsBooted)
1182     			 p->RIOLastPortsBooted = HostP->Mapping[entry2].SysPort;
1183     			rio_dprintk (RIO_DEBUG_BOOT, "SysPort %d, Name %s\n",
1184     			       (int)HostP->Mapping[entry2].SysPort,
1185     			       HostP->Mapping[entry].Name);
1186     		    }
1187     		    else
1188     			HostP->Mapping[entry2].Flags = SLOT_TENTATIVE |
1189     			 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1190     #if NEED_TO_FIX
1191     			RIO_SV_BROADCAST(HostP->svFlags[entry2]);
1192     #endif
1193     		    bzero( (caddr_t)MapP2, sizeof(struct Map) );
1194     		}
1195     		bzero( (caddr_t)MapP, sizeof(struct Map) );
1196     		if (! p->RIONoMessage)
1197     		    cprintf("An orphaned RTA has been adopted by %s '%s' (%c).\n",MyType,MyName,MyLink+'A');
1198     	    }
1199     	    else if (! p->RIONoMessage)
1200     		cprintf("RTA connected to %s '%s' (%c) not configured.\n",MyType,MyName,MyLink+'A');
1201     	    RIOSetChange(p);
1202     	    return TRUE;
1203     	}
1204     
1205     	/*
1206     	** There is no room in the driver table to make an entry for the
1207     	** booted RTA. Keep a note of its Uniq Num in the overflow table,
1208     	** so we can ignore it's ID requests.
1209     	*/
1210     	if (! p->RIONoMessage)
1211     	    cprintf("The RTA connected to %s '%s' (%c) cannot be configured.  You cannot configure more than 128 ports to one host card.\n",MyType,MyName,MyLink+'A');
1212     	for ( entry=0; entry<HostP->NumExtraBooted; entry++ )
1213     	{
1214     	    if ( HostP->ExtraUnits[entry] == RtaUniq )
1215     	    {
1216     		/*
1217     		** already got it!
1218     		*/
1219     		return TRUE;
1220     	    }
1221     	}
1222     	/*
1223     	** If there is room, add the unit to the list of extras
1224     	*/
1225     	if ( HostP->NumExtraBooted < MAX_EXTRA_UNITS )
1226     	    HostP->ExtraUnits[HostP->NumExtraBooted++] = RtaUniq;
1227     	return TRUE;
1228     }
1229     
1230     
1231     /*
1232     ** If the RTA or its host appears in the RIOBindTab[] structure then
1233     ** we mustn't boot the RTA and should return FALSE.
1234     ** This operation is slightly different from the other drivers for RIO
1235     ** in that this is designed to work with the new utilities
1236     ** not config.rio and is FAR SIMPLER.
1237     ** We no longer support the RIOBootMode variable. It is all done from the
1238     ** "boot/noboot" field in the rio.cf file.
1239     */
1240     int
1241     RIOBootOk(p, HostP, RtaUniq)
1242     struct rio_info *	p;
1243     struct Host *		HostP;
1244     ulong RtaUniq;
1245     {
1246         int		Entry;
1247         uint HostUniq = HostP->UniqueNum;
1248     
1249     	/*
1250     	** Search bindings table for RTA or its parent.
1251     	** If it exists, return 0, else 1.
1252     	*/
1253     	for (Entry = 0;
1254     	    ( Entry < MAX_RTA_BINDINGS ) && ( p->RIOBindTab[Entry] != 0 );
1255     	    Entry++)
1256     	{
1257     		if ( (p->RIOBindTab[Entry] == HostUniq) ||
1258     		     (p->RIOBindTab[Entry] == RtaUniq) )
1259     			return 0;
1260     	}
1261     	return 1;
1262     }
1263     
1264     /*
1265     ** Make an empty slot tentative. If this is a 16 port RTA, make both
1266     ** slots tentative, and the second one RTA_SECOND_SLOT as well.
1267     */
1268     
1269     void
1270     FillSlot(entry, entry2, RtaUniq, HostP)
1271     int entry;
1272     int entry2;
1273     uint RtaUniq;
1274     struct Host *HostP;
1275     {
1276     	int		link;
1277     
1278     	rio_dprintk (RIO_DEBUG_BOOT, "FillSlot(%d, %d, 0x%x...)\n", entry, entry2, RtaUniq);
1279     
1280     	HostP->Mapping[entry].Flags = (RTA_BOOTED | RTA_NEWBOOT | SLOT_TENTATIVE);
1281     	HostP->Mapping[entry].SysPort = NO_PORT;
1282     	HostP->Mapping[entry].RtaUniqueNum = RtaUniq;
1283     	HostP->Mapping[entry].HostUniqueNum = HostP->UniqueNum;
1284     	HostP->Mapping[entry].ID = entry + 1;
1285     	HostP->Mapping[entry].ID2 = 0;
1286     	if (entry2) {
1287     		HostP->Mapping[entry2].Flags = (RTA_BOOTED | RTA_NEWBOOT | 
1288     								SLOT_TENTATIVE | RTA16_SECOND_SLOT);
1289     		HostP->Mapping[entry2].SysPort = NO_PORT;
1290     		HostP->Mapping[entry2].RtaUniqueNum = RtaUniq;
1291     		HostP->Mapping[entry2].HostUniqueNum = HostP->UniqueNum;
1292     		HostP->Mapping[entry2].Name[0] = '\0';
1293     		HostP->Mapping[entry2].ID = entry2 + 1;
1294     		HostP->Mapping[entry2].ID2 = entry + 1;
1295     		HostP->Mapping[entry].ID2 = entry2 + 1;
1296     	}
1297     	/*
1298     	** Must set these up, so that utilities show
1299     	** topology of 16 port RTAs correctly
1300     	*/
1301     	for ( link=0; link<LINKS_PER_UNIT; link++ ) {
1302     		HostP->Mapping[entry].Topology[link].Unit = ROUTE_DISCONNECT;
1303     		HostP->Mapping[entry].Topology[link].Link = NO_LINK;
1304     		if (entry2) {
1305     			HostP->Mapping[entry2].Topology[link].Unit = ROUTE_DISCONNECT;
1306     			HostP->Mapping[entry2].Topology[link].Link = NO_LINK;
1307     		}
1308     	}
1309     }
1310     
1311     #if 0
1312     /*
1313     	Function:	This function is to disable the disk interrupt 
1314         Returns :   Nothing
1315     */
1316     void
1317     disable_interrupt(vector)
1318     int	vector;
1319     {
1320     	int	ps;
1321     	int	val;
1322     
1323     	disable(ps);
1324     	if (vector > 40)  {
1325     		val = 1 << (vector - 40);
1326     		__outb(S8259+1, __inb(S8259+1) | val);
1327     	}
1328     	else {
1329     		val = 1 << (vector - 32);
1330     		__outb(M8259+1, __inb(M8259+1) | val);
1331     	}
1332     	restore(ps);
1333     }
1334     
1335     /*
1336     	Function:	This function is to enable the disk interrupt 
1337         Returns :   Nothing
1338     */
1339     void
1340     enable_interrupt(vector)
1341     int	vector;
1342     {
1343     	int	ps;
1344     	int	val;
1345     
1346     	disable(ps);
1347     	if (vector > 40)  {
1348     		val = 1 << (vector - 40);
1349     		val = ~val;
1350     		__outb(S8259+1, __inb(S8259+1) & val);
1351     	}
1352     	else {
1353     		val = 1 << (vector - 32);
1354     		val = ~val;
1355     		__outb(M8259+1, __inb(M8259+1) & val);
1356     	}
1357     	restore(ps);
1358     }
1359     #endif
1360