1 /*******************************************************************************
3 * (c) 1998 by Computone Corporation
5 ********************************************************************************
8 * PACKAGE: Linux tty Device Driver for IntelliPort family of multiport
9 * serial I/O controllers.
11 * DESCRIPTION: Low-level interface code for the device driver
12 * (This is included source code, not a separate compilation
15 *******************************************************************************/
16 //---------------------------------------------
17 // Function declarations private to this module
18 //---------------------------------------------
19 // Functions called only indirectly through i2eBordStr entries.
21 static int iiWriteBuf16(i2eBordStrPtr
, unsigned char *, int);
22 static int iiWriteBuf8(i2eBordStrPtr
, unsigned char *, int);
23 static int iiReadBuf16(i2eBordStrPtr
, unsigned char *, int);
24 static int iiReadBuf8(i2eBordStrPtr
, unsigned char *, int);
26 static unsigned short iiReadWord16(i2eBordStrPtr
);
27 static unsigned short iiReadWord8(i2eBordStrPtr
);
28 static void iiWriteWord16(i2eBordStrPtr
, unsigned short);
29 static void iiWriteWord8(i2eBordStrPtr
, unsigned short);
31 static int iiWaitForTxEmptyII(i2eBordStrPtr
, int);
32 static int iiWaitForTxEmptyIIEX(i2eBordStrPtr
, int);
33 static int iiTxMailEmptyII(i2eBordStrPtr
);
34 static int iiTxMailEmptyIIEX(i2eBordStrPtr
);
35 static int iiTrySendMailII(i2eBordStrPtr
, unsigned char);
36 static int iiTrySendMailIIEX(i2eBordStrPtr
, unsigned char);
38 static unsigned short iiGetMailII(i2eBordStrPtr
);
39 static unsigned short iiGetMailIIEX(i2eBordStrPtr
);
41 static void iiEnableMailIrqII(i2eBordStrPtr
);
42 static void iiEnableMailIrqIIEX(i2eBordStrPtr
);
43 static void iiWriteMaskII(i2eBordStrPtr
, unsigned char);
44 static void iiWriteMaskIIEX(i2eBordStrPtr
, unsigned char);
46 static void ii2DelayTimer(unsigned int);
47 static void ii2DelayWakeup(unsigned long id
);
48 static void ii2Nop(void);
54 static int ii2Safe
; // Safe I/O address for delay routine
56 static int iiDelayed
; // Set when the iiResetDelay function is
57 // called. Cleared when ANY board is reset.
58 static struct timer_list
* pDelayTimer
; // Used by iiDelayTimer
59 static wait_queue_head_t pDelayWait
; // Used by iiDelayTimer
60 static rwlock_t Dl_spinlock
;
66 //=======================================================
67 // Initialization Routines
73 //=======================================================
75 //******************************************************************************
76 // Function: iiEllisInit()
83 // This routine performs any required initialization of the iiEllis subsystem.
85 //******************************************************************************
89 pDelayTimer
= kmalloc ( sizeof (struct timer_list
), GFP_KERNEL
);
90 init_timer(pDelayTimer
);
91 init_waitqueue_head(&pDelayWait
);
92 LOCK_INIT(&Dl_spinlock
);
95 //******************************************************************************
96 // Function: iiEllisCleanup()
103 // This routine performs any required cleanup of the iiEllis subsystem.
105 //******************************************************************************
112 //******************************************************************************
113 // Function: iiSetAddress(pB, address, delay)
114 // Parameters: pB - pointer to the board structure
115 // address - the purported I/O address of the board
116 // delay - pointer to the 1-ms delay function to use
117 // in this and any future operations to this board
119 // Returns: True if everything appears copacetic.
120 // False if there is any error: the pB->i2eError field has the error
124 // This routine (roughly) checks for address validity, sets the i2eValid OK and
125 // sets the state to II_STATE_COLD which means that we haven't even sent a reset
128 //******************************************************************************
130 iiSetAddress( i2eBordStrPtr pB
, int address
, delayFunc_t delay
)
132 // Should any failure occur before init is finished...
133 pB
->i2eValid
= I2E_INCOMPLETE
;
135 // Cannot check upper limit except extremely: Might be microchannel
136 // Address must be on an 8-byte boundary
138 if ((unsigned int)address
<= 0x100
139 || (unsigned int)address
>= 0xfff8
143 COMPLETE(pB
,I2EE_BADADDR
);
146 // Initialize accelerators
147 pB
->i2eBase
= address
;
148 pB
->i2eData
= address
+ FIFO_DATA
;
149 pB
->i2eStatus
= address
+ FIFO_STATUS
;
150 pB
->i2ePointer
= address
+ FIFO_PTR
;
151 pB
->i2eXMail
= address
+ FIFO_MAIL
;
152 pB
->i2eXMask
= address
+ FIFO_MASK
;
154 // Initialize i/o address for ii2DelayIO
155 ii2Safe
= address
+ FIFO_NOP
;
157 // Initialize the delay routine
158 pB
->i2eDelay
= ((delay
!= (delayFunc_t
)NULL
) ? delay
: (delayFunc_t
)ii2Nop
);
160 pB
->i2eValid
= I2E_MAGIC
;
161 pB
->i2eState
= II_STATE_COLD
;
163 COMPLETE(pB
, I2EE_GOOD
);
166 //******************************************************************************
167 // Function: iiReset(pB)
168 // Parameters: pB - pointer to the board structure
170 // Returns: True if everything appears copacetic.
171 // False if there is any error: the pB->i2eError field has the error
175 // Attempts to reset the board (see also i2hw.h). Normally, we would use this to
176 // reset a board immediately after iiSetAddress(), but it is valid to reset a
177 // board from any state, say, in order to change or re-load loadware. (Under
178 // such circumstances, no reason to re-run iiSetAddress(), which is why it is a
179 // separate routine and not included in this routine.
181 //******************************************************************************
183 iiReset(i2eBordStrPtr pB
)
185 // Magic number should be set, else even the address is suspect
186 if (pB
->i2eValid
!= I2E_MAGIC
)
188 COMPLETE(pB
, I2EE_BADMAGIC
);
191 OUTB(pB
->i2eBase
+ FIFO_RESET
, 0); // Any data will do
192 iiDelay(pB
, 50); // Pause between resets
193 OUTB(pB
->i2eBase
+ FIFO_RESET
, 0); // Second reset
195 // We must wait before even attempting to read anything from the FIFO: the
196 // board's P.O.S.T may actually attempt to read and write its end of the
197 // FIFO in order to check flags, loop back (where supported), etc. On
198 // completion of this testing it would reset the FIFO, and on completion
199 // of all // P.O.S.T., write the message. We must not mistake data which
200 // might have been sent for testing as part of the reset message. To
201 // better utilize time, say, when resetting several boards, we allow the
202 // delay to be performed externally; in this way the caller can reset
203 // several boards, delay a single time, then call the initialization
206 pB
->i2eState
= II_STATE_RESET
;
208 iiDelayed
= 0; // i.e., the delay routine hasn't been called since the most
211 // Ensure anything which would have been of use to standard loadware is
212 // blanked out, since board has now forgotten everything!.
214 pB
->i2eUsingIrq
= IRQ_UNDEFINED
; // Not set up to use an interrupt yet
215 pB
->i2eWaitingForEmptyFifo
= 0;
216 pB
->i2eOutMailWaiting
= 0;
217 pB
->i2eChannelPtr
= NULL
;
218 pB
->i2eChannelCnt
= 0;
220 pB
->i2eLeadoffWord
[0] = 0;
221 pB
->i2eFifoInInts
= 0;
222 pB
->i2eFifoOutInts
= 0;
223 pB
->i2eFatalTrap
= NULL
;
226 COMPLETE(pB
, I2EE_GOOD
);
229 //******************************************************************************
230 // Function: iiResetDelay(pB)
231 // Parameters: pB - pointer to the board structure
233 // Returns: True if everything appears copacetic.
234 // False if there is any error: the pB->i2eError field has the error
238 // Using the delay defined in board structure, waits two seconds (for board to
241 //******************************************************************************
243 iiResetDelay(i2eBordStrPtr pB
)
245 if (pB
->i2eValid
!= I2E_MAGIC
) {
246 COMPLETE(pB
, I2EE_BADMAGIC
);
248 if (pB
->i2eState
!= II_STATE_RESET
) {
249 COMPLETE(pB
, I2EE_BADSTATE
);
251 iiDelay(pB
,2000); /* Now we wait for two seconds. */
252 iiDelayed
= 1; /* Delay has been called: ok to initialize */
253 COMPLETE(pB
, I2EE_GOOD
);
256 //******************************************************************************
257 // Function: iiInitialize(pB)
258 // Parameters: pB - pointer to the board structure
260 // Returns: True if everything appears copacetic.
261 // False if there is any error: the pB->i2eError field has the error
265 // Attempts to read the Power-on reset message. Initializes any remaining fields
266 // in the pB structure.
268 // This should be called as the third step of a process beginning with
269 // iiReset(), then iiResetDelay(). This routine checks to see that the structure
270 // is "valid" and in the reset state, also confirms that the delay routine has
271 // been called since the latest reset (to any board! overly strong!).
273 //******************************************************************************
275 iiInitialize(i2eBordStrPtr pB
)
279 unsigned short utemp
;
282 if (pB
->i2eValid
!= I2E_MAGIC
)
284 COMPLETE(pB
, I2EE_BADMAGIC
);
287 if (pB
->i2eState
!= II_STATE_RESET
|| !iiDelayed
)
289 COMPLETE(pB
, I2EE_BADSTATE
);
292 // In case there is a failure short of our completely reading the power-up
294 pB
->i2eValid
= I2E_INCOMPLETE
;
297 // Now attempt to read the message.
299 for (itemp
= 0; itemp
< sizeof(porStr
); itemp
++)
301 // We expect the entire message is ready.
302 if (HAS_NO_INPUT(pB
))
304 pB
->i2ePomSize
= itemp
;
305 COMPLETE(pB
, I2EE_PORM_SHORT
);
308 pB
->i2ePom
.c
[itemp
] = c
= BYTE_FROM(pB
);
310 // We check the magic numbers as soon as they are supposed to be read
311 // (rather than after) to minimize effect of reading something we
312 // already suspect can't be "us".
313 if ( (itemp
== POR_1_INDEX
&& c
!= POR_MAGIC_1
) ||
314 (itemp
== POR_2_INDEX
&& c
!= POR_MAGIC_2
))
316 pB
->i2ePomSize
= itemp
+1;
317 COMPLETE(pB
, I2EE_BADMAGIC
);
321 pB
->i2ePomSize
= itemp
;
323 // Ensure that this was all the data...
325 COMPLETE(pB
, I2EE_PORM_LONG
);
327 // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
328 // Implying we will not be able to download any code either: That's ok: the
329 // condition is pretty explicit.
330 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_MAPPER
)
332 COMPLETE(pB
, I2EE_POSTERR
);
335 // Determine anything which must be done differently depending on the family
337 switch (pB
->i2ePom
.e
.porID
& POR_ID_FAMILY
)
339 case POR_ID_FII
: // IntelliPort-II
341 pB
->i2eFifoStyle
= FIFO_II
;
342 pB
->i2eFifoSize
= 512; // 512 bytes, always
343 pB
->i2eDataWidth16
= NO
;
345 pB
->i2eMaxIrq
= 15; // Because board cannot tell us it is in an 8-bit
346 // slot, we do allow it to be done (documentation!)
351 pB
->i2eChannelMap
[1] =
352 pB
->i2eChannelMap
[2] =
353 pB
->i2eChannelMap
[3] = 0;
355 switch (pB
->i2ePom
.e
.porID
& POR_ID_SIZE
)
359 pB
->i2eChannelMap
[0] = 0x0f; // four-port
361 // Since porPorts1 is based on the Hardware ID register, the numbers
362 // should always be consistent for IntelliPort-II. Ditto below...
363 if (pB
->i2ePom
.e
.porPorts1
!= 4)
365 COMPLETE(pB
, I2EE_INCONSIST
);
372 pB
->i2eChannelMap
[0] = 0xff; // Eight port
373 if (pB
->i2ePom
.e
.porPorts1
!= 8)
375 COMPLETE(pB
, I2EE_INCONSIST
);
381 pB
->i2eChannelMap
[0] = 0x3f; // Six Port
382 if (pB
->i2ePom
.e
.porPorts1
!= 6)
384 COMPLETE(pB
, I2EE_INCONSIST
);
389 // Fix up the "good channel list based on any errors reported.
390 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART1
)
392 pB
->i2eGoodMap
[0] &= ~0x0f;
395 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART2
)
397 pB
->i2eGoodMap
[0] &= ~0xf0;
400 break; // POR_ID_FII case
402 case POR_ID_FIIEX
: // IntelliPort-IIEX
404 pB
->i2eFifoStyle
= FIFO_IIEX
;
406 itemp
= pB
->i2ePom
.e
.porFifoSize
;
408 // Implicit assumption that fifo would not grow beyond 32k,
409 // nor would ever be less than 256.
411 if (itemp
< 8 || itemp
> 15)
413 COMPLETE(pB
, I2EE_INCONSIST
);
415 pB
->i2eFifoSize
= (1 << itemp
);
417 // These are based on what P.O.S.T thinks should be there, based on
419 ilimit
= pB
->i2ePom
.e
.porNumBoxes
;
420 if (ilimit
> ABS_MAX_BOXES
)
422 ilimit
= ABS_MAX_BOXES
;
425 // For as many boxes as EXIST, gives the type of box.
426 // Added 8/6/93: check for the ISA-4 (asic) which looks like an
427 // expandable but for whom "8 or 16?" is not the right question.
429 utemp
= pB
->i2ePom
.e
.porFlags
;
430 if (utemp
& POR_CEX4
)
432 pB
->i2eChannelMap
[0] = 0x000f;
435 for (itemp
= 0; itemp
< ilimit
; itemp
++)
437 pB
->i2eChannelMap
[itemp
] =
438 ((utemp
& POR_BOX_16
) ? 0xffff : 0x00ff);
443 // These are based on what P.O.S.T actually found.
445 utemp
= (pB
->i2ePom
.e
.porPorts2
<< 8) + pB
->i2ePom
.e
.porPorts1
;
447 for (itemp
= 0; itemp
< ilimit
; itemp
++)
449 pB
->i2eGoodMap
[itemp
] = 0;
450 if (utemp
& 1) pB
->i2eGoodMap
[itemp
] |= 0x000f;
451 if (utemp
& 2) pB
->i2eGoodMap
[itemp
] |= 0x00f0;
452 if (utemp
& 4) pB
->i2eGoodMap
[itemp
] |= 0x0f00;
453 if (utemp
& 8) pB
->i2eGoodMap
[itemp
] |= 0xf000;
457 // Now determine whether we should transfer in 8 or 16-bit mode.
458 switch (pB
->i2ePom
.e
.porBus
& (POR_BUS_SLOT16
| POR_BUS_DIP16
) )
460 case POR_BUS_SLOT16
| POR_BUS_DIP16
:
461 pB
->i2eDataWidth16
= YES
;
466 pB
->i2eDataWidth16
= NO
;
471 case POR_BUS_DIP16
: // In an 8-bit slot, DIP switch don't care.
473 pB
->i2eDataWidth16
= NO
;
477 break; // POR_ID_FIIEX case
479 default: // Unknown type of board
480 COMPLETE(pB
, I2EE_BAD_FAMILY
);
482 } // End the switch based on family
484 // Temporarily, claim there is no room in the outbound fifo.
485 // We will maintain this whenever we check for an empty outbound FIFO.
486 pB
->i2eFifoRemains
= 0;
488 // Now, based on the bus type, should we expect to be able to re-configure
489 // interrupts (say, for testing purposes).
490 switch (pB
->i2ePom
.e
.porBus
& POR_BUS_TYPE
)
493 case POR_BUS_T_UNK
: // If the type of bus is undeclared, assume ok.
494 pB
->i2eChangeIrq
= YES
;
498 pB
->i2eChangeIrq
= NO
;
501 COMPLETE(pB
, I2EE_BADBUS
);
504 if (pB
->i2eDataWidth16
== YES
)
506 pB
->i2eWriteBuf
= iiWriteBuf16
;
507 pB
->i2eReadBuf
= iiReadBuf16
;
508 pB
->i2eWriteWord
= iiWriteWord16
;
509 pB
->i2eReadWord
= iiReadWord16
;
511 pB
->i2eWriteBuf
= iiWriteBuf8
;
512 pB
->i2eReadBuf
= iiReadBuf8
;
513 pB
->i2eWriteWord
= iiWriteWord8
;
514 pB
->i2eReadWord
= iiReadWord8
;
517 switch(pB
->i2eFifoStyle
)
520 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyII
;
521 pB
->i2eTxMailEmpty
= iiTxMailEmptyII
;
522 pB
->i2eTrySendMail
= iiTrySendMailII
;
523 pB
->i2eGetMail
= iiGetMailII
;
524 pB
->i2eEnableMailIrq
= iiEnableMailIrqII
;
525 pB
->i2eWriteMask
= iiWriteMaskII
;
530 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyIIEX
;
531 pB
->i2eTxMailEmpty
= iiTxMailEmptyIIEX
;
532 pB
->i2eTrySendMail
= iiTrySendMailIIEX
;
533 pB
->i2eGetMail
= iiGetMailIIEX
;
534 pB
->i2eEnableMailIrq
= iiEnableMailIrqIIEX
;
535 pB
->i2eWriteMask
= iiWriteMaskIIEX
;
540 COMPLETE(pB
, I2EE_INCONSIST
);
543 // Initialize state information.
544 pB
->i2eState
= II_STATE_READY
; // Ready to load loadware.
546 // Some Final cleanup:
547 // For some boards, the bootstrap firmware may perform some sort of test
548 // resulting in a stray character pending in the incoming mailbox. If one is
549 // there, it should be read and discarded, especially since for the standard
550 // firmware, it's the mailbox that interrupts the host.
552 pB
->i2eStartMail
= iiGetMail(pB
);
554 // Throw it away and clear the mailbox structure element
555 pB
->i2eStartMail
= NO_MAIL_HERE
;
557 // Everything is ok now, return with good status/
559 pB
->i2eValid
= I2E_MAGIC
;
560 COMPLETE(pB
, I2EE_GOOD
);
563 //=======================================================
568 //=======================================================
571 ii2DelayWakeup(unsigned long id
)
573 wake_up_interruptible ( &pDelayWait
);
576 //******************************************************************************
577 // Function: ii2DelayTimer(mseconds)
578 // Parameters: mseconds - number of milliseconds to delay
584 // This routine delays for approximately mseconds milliseconds and is intended
585 // to be called indirectly through i2Delay field in i2eBordStr. It uses the
586 // Linux timer_list mechanism.
588 // The Linux timers use a unit called "jiffies" which are 10mS in the Intel
589 // architecture. This function rounds the delay period up to the next "jiffy".
590 // In the Alpha architecture the "jiffy" is 1mS, but this driver is not intended
591 // for Alpha platforms at this time.
593 //******************************************************************************
595 ii2DelayTimer(unsigned int mseconds
)
599 init_waitqueue_entry(&wait
, current
);
601 init_timer ( pDelayTimer
);
603 add_wait_queue(&pDelayWait
, &wait
);
605 set_current_state( TASK_INTERRUPTIBLE
);
607 pDelayTimer
->expires
= jiffies
+ ( mseconds
+ 9 ) / 10;
608 pDelayTimer
->function
= ii2DelayWakeup
;
609 pDelayTimer
->data
= 0;
611 add_timer ( pDelayTimer
);
615 set_current_state( TASK_RUNNING
);
616 remove_wait_queue(&pDelayWait
, &wait
);
618 del_timer ( pDelayTimer
);
622 //static void ii2DelayIO(unsigned int);
623 //******************************************************************************
624 // !!! Not Used, this is DOS crap, some of you young folks may be interested in
625 // in how things were done in the stone age of caculating machines !!!
626 // Function: ii2DelayIO(mseconds)
627 // Parameters: mseconds - number of milliseconds to delay
633 // This routine delays for approximately mseconds milliseconds and is intended
634 // to be called indirectly through i2Delay field in i2eBordStr. It is intended
635 // for use where a clock-based function is impossible: for example, DOS drivers.
637 // This function uses the IN instruction to place bounds on the timing and
638 // assumes that ii2Safe has been set. This is because I/O instructions are not
639 // subject to caching and will therefore take a certain minimum time. To ensure
640 // the delay is at least long enough on fast machines, it is based on some
641 // fastest-case calculations. On slower machines this may cause VERY long
642 // delays. (3 x fastest case). In the fastest case, everything is cached except
643 // the I/O instruction itself.
645 // Timing calculations:
646 // The fastest bus speed for I/O operations is likely to be 10 MHz. The I/O
647 // operation in question is a byte operation to an odd address. For 8-bit
648 // operations, the architecture generally enforces two wait states. At 10 MHz, a
649 // single cycle time is 100nS. A read operation at two wait states takes 6
650 // cycles for a total time of 600nS. Therefore approximately 1666 iterations
651 // would be required to generate a single millisecond delay. The worst
652 // (reasonable) case would be an 8MHz system with no cacheing. In this case, the
653 // I/O instruction would take 125nS x 6 cyles = 750 nS. More importantly, code
654 // fetch of other instructions in the loop would take time (zero wait states,
655 // however) and would be hard to estimate. This is minimized by using in-line
656 // assembler for the in inner loop of IN instructions. This consists of just a
657 // few bytes. So we'll guess about four code fetches per loop. Each code fetch
658 // should take four cycles, so we have 125nS * 8 = 1000nS. Worst case then is
659 // that what should have taken 1 mS takes instead 1666 * (1750) = 2.9 mS.
661 // So much for theoretical timings: results using 1666 value on some actual
663 // IBM 286 6MHz 3.15 mS
664 // Zenith 386 33MHz 2.45 mS
665 // (brandX) 386 33MHz 1.90 mS (has cache)
666 // (brandY) 486 33MHz 2.35 mS
667 // NCR 486 ?? 1.65 mS (microchannel)
669 // For most machines, it is probably safe to scale this number back (remember,
670 // for robust operation use an actual timed delay if possible), so we are using
671 // a value of 1190. This yields 1.17 mS for the fastest machine in our sample,
672 // 1.75 mS for typical 386 machines, and 2.25 mS the absolute slowest machine.
675 // The above timings are too slow. Actual cycle times might be faster. ISA cycle
676 // times could approach 500 nS, and ...
677 // The IBM model 77 being microchannel has no wait states for 8-bit reads and
678 // seems to be accessing the I/O at 440 nS per access (from start of one to
679 // start of next). This would imply we need 1000/.440 = 2272 iterations to
680 // guarantee we are fast enough. In actual testing, we see that 2 * 1190 are in
681 // fact enough. For diagnostics, we keep the level at 1190, but developers note
682 // this needs tuning.
684 // Safe assumption: 2270 i/o reads = 1 millisecond
686 //******************************************************************************
689 static int ii2DelValue
= 1190; // See timing calculations below
690 // 1666 for fastest theoretical machine
691 // 1190 safe for most fast 386 machines
692 // 1000 for fastest machine tested here
693 // 540 (sic) for AT286/6Mhz
695 ii2DelayIO(unsigned int mseconds
)
698 return; /* Do nothing if this variable uninitialized */
709 //******************************************************************************
710 // Function: ii2Nop()
717 // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
718 // saves checking for a NULL pointer at every call.
719 //******************************************************************************
723 return; // no mystery here
726 //=======================================================
727 // Routines which are available in 8/16-bit versions, or
728 // in different fifo styles. These are ALL called
729 // indirectly through the board structure.
730 //=======================================================
732 //******************************************************************************
733 // Function: iiWriteBuf16(pB, address, count)
734 // Parameters: pB - pointer to board structure
735 // address - address of data to write
736 // count - number of data bytes to write
738 // Returns: True if everything appears copacetic.
739 // False if there is any error: the pB->i2eError field has the error
743 // Writes 'count' bytes from 'address' to the data fifo specified by the board
744 // structure pointer pB. Should count happen to be odd, an extra pad byte is
745 // sent (identity unknown...). Uses 16-bit (word) operations. Is called
746 // indirectly through pB->i2eWriteBuf.
748 //******************************************************************************
750 iiWriteBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
752 // Rudimentary sanity checking here.
753 if (pB
->i2eValid
!= I2E_MAGIC
)
754 COMPLETE(pB
, I2EE_INVALID
);
756 OUTSW ( pB
->i2eData
, address
, count
);
758 COMPLETE(pB
, I2EE_GOOD
);
761 //******************************************************************************
762 // Function: iiWriteBuf8(pB, address, count)
763 // Parameters: pB - pointer to board structure
764 // address - address of data to write
765 // count - number of data bytes to write
767 // Returns: True if everything appears copacetic.
768 // False if there is any error: the pB->i2eError field has the error
772 // Writes 'count' bytes from 'address' to the data fifo specified by the board
773 // structure pointer pB. Should count happen to be odd, an extra pad byte is
774 // sent (identity unknown...). This is to be consistent with the 16-bit version.
775 // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
777 //******************************************************************************
779 iiWriteBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
781 /* Rudimentary sanity checking here */
782 if (pB
->i2eValid
!= I2E_MAGIC
)
783 COMPLETE(pB
, I2EE_INVALID
);
785 OUTSB ( pB
->i2eData
, address
, count
);
787 COMPLETE(pB
, I2EE_GOOD
);
790 //******************************************************************************
791 // Function: iiReadBuf16(pB, address, count)
792 // Parameters: pB - pointer to board structure
793 // address - address to put data read
794 // count - number of data bytes to read
796 // Returns: True if everything appears copacetic.
797 // False if there is any error: the pB->i2eError field has the error
801 // Reads 'count' bytes into 'address' from the data fifo specified by the board
802 // structure pointer pB. Should count happen to be odd, an extra pad byte is
803 // received (identity unknown...). Uses 16-bit (word) operations. Is called
804 // indirectly through pB->i2eReadBuf.
806 //******************************************************************************
808 iiReadBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
810 // Rudimentary sanity checking here.
811 if (pB
->i2eValid
!= I2E_MAGIC
)
812 COMPLETE(pB
, I2EE_INVALID
);
814 INSW ( pB
->i2eData
, address
, count
);
816 COMPLETE(pB
, I2EE_GOOD
);
819 //******************************************************************************
820 // Function: iiReadBuf8(pB, address, count)
821 // Parameters: pB - pointer to board structure
822 // address - address to put data read
823 // count - number of data bytes to read
825 // Returns: True if everything appears copacetic.
826 // False if there is any error: the pB->i2eError field has the error
830 // Reads 'count' bytes into 'address' from the data fifo specified by the board
831 // structure pointer pB. Should count happen to be odd, an extra pad byte is
832 // received (identity unknown...). This to match the 16-bit behaviour. Uses
833 // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
835 //******************************************************************************
837 iiReadBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
839 // Rudimentary sanity checking here.
840 if (pB
->i2eValid
!= I2E_MAGIC
)
841 COMPLETE(pB
, I2EE_INVALID
);
843 INSB ( pB
->i2eData
, address
, count
);
845 COMPLETE(pB
, I2EE_GOOD
);
848 //******************************************************************************
849 // Function: iiReadWord16(pB)
850 // Parameters: pB - pointer to board structure
852 // Returns: True if everything appears copacetic.
853 // False if there is any error: the pB->i2eError field has the error
857 // Returns the word read from the data fifo specified by the board-structure
858 // pointer pB. Uses a 16-bit operation. Is called indirectly through
861 //******************************************************************************
862 static unsigned short
863 iiReadWord16(i2eBordStrPtr pB
)
865 return (unsigned short)( INW(pB
->i2eData
) );
868 //******************************************************************************
869 // Function: iiReadWord8(pB)
870 // Parameters: pB - pointer to board structure
872 // Returns: True if everything appears copacetic.
873 // False if there is any error: the pB->i2eError field has the error
877 // Returns the word read from the data fifo specified by the board-structure
878 // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
879 // called indirectly through pB->i2eReadWord.
881 //******************************************************************************
882 static unsigned short
883 iiReadWord8(i2eBordStrPtr pB
)
887 urs
= INB ( pB
->i2eData
);
889 return ( ( INB ( pB
->i2eData
) << 8 ) | urs
);
892 //******************************************************************************
893 // Function: iiWriteWord16(pB, value)
894 // Parameters: pB - pointer to board structure
895 // value - data to write
897 // Returns: True if everything appears copacetic.
898 // False if there is any error: the pB->i2eError field has the error
902 // Writes the word 'value' to the data fifo specified by the board-structure
903 // pointer pB. Uses 16-bit operation. Is called indirectly through
906 //******************************************************************************
908 iiWriteWord16(i2eBordStrPtr pB
, unsigned short value
)
910 WORD_TO(pB
, (int)value
);
913 //******************************************************************************
914 // Function: iiWriteWord8(pB, value)
915 // Parameters: pB - pointer to board structure
916 // value - data to write
918 // Returns: True if everything appears copacetic.
919 // False if there is any error: the pB->i2eError field has the error
923 // Writes the word 'value' to the data fifo specified by the board-structure
924 // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
925 // indirectly through pB->i2eWriteWord.
927 //******************************************************************************
929 iiWriteWord8(i2eBordStrPtr pB
, unsigned short value
)
931 BYTE_TO(pB
, (char)value
);
932 BYTE_TO(pB
, (char)(value
>> 8) );
935 //******************************************************************************
936 // Function: iiWaitForTxEmptyII(pB, mSdelay)
937 // Parameters: pB - pointer to board structure
938 // mSdelay - period to wait before returning
940 // Returns: True if the FIFO is empty.
941 // False if it not empty in the required time: the pB->i2eError
942 // field has the error.
946 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
947 // not empty by the required time, returns false and error in pB->i2eError,
948 // otherwise returns true.
950 // mSdelay == 0 is taken to mean must be empty on the first test.
952 // This version operates on IntelliPort-II - style FIFO's
954 // Note this routine is organized so that if status is ok there is no delay at
955 // all called either before or after the test. Is called indirectly through
956 // pB->i2eWaitForTxEmpty.
958 //******************************************************************************
960 iiWaitForTxEmptyII(i2eBordStrPtr pB
, int mSdelay
)
967 // This routine hinges on being able to see the "other" status register
968 // (as seen by the local processor). His incoming fifo is our outgoing
971 // By the nature of this routine, you would be using this as part of a
972 // larger atomic context: i.e., you would use this routine to ensure the
973 // fifo empty, then act on this information. Between these two halves,
974 // you will generally not want to service interrupts or in any way
975 // disrupt the assumptions implicit in the larger context.
977 // Even worse, however, this routine "shifts" the status register to
978 // point to the local status register which is not the usual situation.
979 // Therefore for extra safety, we force the critical section to be
980 // completely atomic, and pick up after ourselves before allowing any
981 // interrupts of any kind.
984 WRITE_LOCK_IRQSAVE(&Dl_spinlock
,flags
)
985 OUTB(pB
->i2ePointer
, SEL_COMMAND
);
986 OUTB(pB
->i2ePointer
, SEL_CMD_SH
);
988 itemp
= INB(pB
->i2eStatus
);
990 OUTB(pB
->i2ePointer
, SEL_COMMAND
);
991 OUTB(pB
->i2ePointer
, SEL_CMD_UNSH
);
993 if (itemp
& ST_IN_EMPTY
)
995 UPDATE_FIFO_ROOM(pB
);
996 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
997 COMPLETE(pB
, I2EE_GOOD
);
1000 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
1005 iiDelay(pB
, 1); /* 1 mS granularity on checking condition */
1007 COMPLETE(pB
, I2EE_TXE_TIME
);
1010 //******************************************************************************
1011 // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
1012 // Parameters: pB - pointer to board structure
1013 // mSdelay - period to wait before returning
1015 // Returns: True if the FIFO is empty.
1016 // False if it not empty in the required time: the pB->i2eError
1017 // field has the error.
1021 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
1022 // not empty by the required time, returns false and error in pB->i2eError,
1023 // otherwise returns true.
1025 // mSdelay == 0 is taken to mean must be empty on the first test.
1027 // This version operates on IntelliPort-IIEX - style FIFO's
1029 // Note this routine is organized so that if status is ok there is no delay at
1030 // all called either before or after the test. Is called indirectly through
1031 // pB->i2eWaitForTxEmpty.
1033 //******************************************************************************
1035 iiWaitForTxEmptyIIEX(i2eBordStrPtr pB
, int mSdelay
)
1037 unsigned long flags
;
1041 // By the nature of this routine, you would be using this as part of a
1042 // larger atomic context: i.e., you would use this routine to ensure the
1043 // fifo empty, then act on this information. Between these two halves,
1044 // you will generally not want to service interrupts or in any way
1045 // disrupt the assumptions implicit in the larger context.
1047 WRITE_LOCK_IRQSAVE(&Dl_spinlock
,flags
)
1049 if (INB(pB
->i2eStatus
) & STE_OUT_MT
) {
1050 UPDATE_FIFO_ROOM(pB
);
1051 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
1052 COMPLETE(pB
, I2EE_GOOD
);
1054 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
1059 iiDelay(pB
, 1); // 1 mS granularity on checking condition
1061 COMPLETE(pB
, I2EE_TXE_TIME
);
1064 //******************************************************************************
1065 // Function: iiTxMailEmptyII(pB)
1066 // Parameters: pB - pointer to board structure
1068 // Returns: True if the transmit mailbox is empty.
1069 // False if it not empty.
1073 // Returns true or false according to whether the transmit mailbox is empty (and
1074 // therefore able to accept more mail)
1076 // This version operates on IntelliPort-II - style FIFO's
1078 //******************************************************************************
1080 iiTxMailEmptyII(i2eBordStrPtr pB
)
1082 int port
= pB
->i2ePointer
;
1083 OUTB ( port
, SEL_OUTMAIL
);
1084 return ( INB(port
) == 0 );
1087 //******************************************************************************
1088 // Function: iiTxMailEmptyIIEX(pB)
1089 // Parameters: pB - pointer to board structure
1091 // Returns: True if the transmit mailbox is empty.
1092 // False if it not empty.
1096 // Returns true or false according to whether the transmit mailbox is empty (and
1097 // therefore able to accept more mail)
1099 // This version operates on IntelliPort-IIEX - style FIFO's
1101 //******************************************************************************
1103 iiTxMailEmptyIIEX(i2eBordStrPtr pB
)
1105 return !(INB(pB
->i2eStatus
) & STE_OUT_MAIL
);
1108 //******************************************************************************
1109 // Function: iiTrySendMailII(pB,mail)
1110 // Parameters: pB - pointer to board structure
1111 // mail - value to write to mailbox
1113 // Returns: True if the transmit mailbox is empty, and mail is sent.
1114 // False if it not empty.
1118 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1119 // mailbox is not empty, returns false.
1121 // This version operates on IntelliPort-II - style FIFO's
1123 //******************************************************************************
1125 iiTrySendMailII(i2eBordStrPtr pB
, unsigned char mail
)
1127 int port
= pB
->i2ePointer
;
1129 OUTB(port
, SEL_OUTMAIL
);
1130 if (INB(port
) == 0) {
1131 OUTB(port
, SEL_OUTMAIL
);
1138 //******************************************************************************
1139 // Function: iiTrySendMailIIEX(pB,mail)
1140 // Parameters: pB - pointer to board structure
1141 // mail - value to write to mailbox
1143 // Returns: True if the transmit mailbox is empty, and mail is sent.
1144 // False if it not empty.
1148 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1149 // mailbox is not empty, returns false.
1151 // This version operates on IntelliPort-IIEX - style FIFO's
1153 //******************************************************************************
1155 iiTrySendMailIIEX(i2eBordStrPtr pB
, unsigned char mail
)
1157 if(INB(pB
->i2eStatus
) & STE_OUT_MAIL
) {
1160 OUTB(pB
->i2eXMail
, mail
);
1164 //******************************************************************************
1165 // Function: iiGetMailII(pB,mail)
1166 // Parameters: pB - pointer to board structure
1168 // Returns: Mailbox data or NO_MAIL_HERE.
1172 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1173 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1175 // This version operates on IntelliPort-II - style FIFO's
1177 //******************************************************************************
1178 static unsigned short
1179 iiGetMailII(i2eBordStrPtr pB
)
1182 OUTB(pB
->i2ePointer
, SEL_INMAIL
);
1183 return INB(pB
->i2ePointer
);
1185 return NO_MAIL_HERE
;
1189 //******************************************************************************
1190 // Function: iiGetMailIIEX(pB,mail)
1191 // Parameters: pB - pointer to board structure
1193 // Returns: Mailbox data or NO_MAIL_HERE.
1197 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1198 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1200 // This version operates on IntelliPort-IIEX - style FIFO's
1202 //******************************************************************************
1203 static unsigned short
1204 iiGetMailIIEX(i2eBordStrPtr pB
)
1207 return INB(pB
->i2eXMail
);
1209 return NO_MAIL_HERE
;
1213 //******************************************************************************
1214 // Function: iiEnableMailIrqII(pB)
1215 // Parameters: pB - pointer to board structure
1221 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1223 // This version operates on IntelliPort-II - style FIFO's
1225 //******************************************************************************
1227 iiEnableMailIrqII(i2eBordStrPtr pB
)
1229 OUTB(pB
->i2ePointer
, SEL_MASK
);
1230 OUTB(pB
->i2ePointer
, ST_IN_MAIL
);
1233 //******************************************************************************
1234 // Function: iiEnableMailIrqIIEX(pB)
1235 // Parameters: pB - pointer to board structure
1241 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1243 // This version operates on IntelliPort-IIEX - style FIFO's
1245 //******************************************************************************
1247 iiEnableMailIrqIIEX(i2eBordStrPtr pB
)
1249 OUTB(pB
->i2eXMask
, MX_IN_MAIL
);
1252 //******************************************************************************
1253 // Function: iiWriteMaskII(pB)
1254 // Parameters: pB - pointer to board structure
1260 // Writes arbitrary value to the mask register.
1262 // This version operates on IntelliPort-II - style FIFO's
1264 //******************************************************************************
1266 iiWriteMaskII(i2eBordStrPtr pB
, unsigned char value
)
1268 OUTB(pB
->i2ePointer
, SEL_MASK
);
1269 OUTB(pB
->i2ePointer
, value
);
1272 //******************************************************************************
1273 // Function: iiWriteMaskIIEX(pB)
1274 // Parameters: pB - pointer to board structure
1280 // Writes arbitrary value to the mask register.
1282 // This version operates on IntelliPort-IIEX - style FIFO's
1284 //******************************************************************************
1286 iiWriteMaskIIEX(i2eBordStrPtr pB
, unsigned char value
)
1288 OUTB(pB
->i2eXMask
, value
);
1291 //******************************************************************************
1292 // Function: iiDownloadBlock(pB, pSource, isStandard)
1293 // Parameters: pB - pointer to board structure
1294 // pSource - loadware block to download
1295 // isStandard - True if "standard" loadware, else false.
1297 // Returns: Success or Failure
1301 // Downloads a single block (at pSource)to the board referenced by pB. Caller
1302 // sets isStandard to true/false according to whether the "standard" loadware is
1303 // what's being loaded. The normal process, then, is to perform an iiInitialize
1304 // to the board, then perform some number of iiDownloadBlocks using the returned
1305 // state to determine when download is complete.
1307 // Possible return values: (see I2ELLIS.H)
1310 // II_DOWN_CONTINUING
1316 // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
1317 // determine whether this is the first block, whether to check for magic
1318 // numbers, how many blocks there are to go...
1320 //******************************************************************************
1322 iiDownloadBlock ( i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
)
1327 if (pB
->i2eValid
!= I2E_MAGIC
) return II_DOWN_BADVALID
;
1329 switch(pB
->i2eState
)
1331 case II_STATE_READY
:
1333 // Loading the first block after reset. Must check the magic number of the
1334 // loadfile, store the number of blocks we expect to load.
1335 if (pSource
->e
.loadMagic
!= MAGIC_LOADFILE
)
1337 return II_DOWN_BADFILE
;
1340 // Next we store the total number of blocks to load, including this one.
1341 pB
->i2eToLoad
= 1 + pSource
->e
.loadBlocksMore
;
1343 // Set the state, store the version numbers. ('Cause this may have come
1344 // from a file - we might want to report these versions and revisions in
1345 // case of an error!
1346 pB
->i2eState
= II_STATE_LOADING
;
1347 pB
->i2eLVersion
= pSource
->e
.loadVersion
;
1348 pB
->i2eLRevision
= pSource
->e
.loadRevision
;
1349 pB
->i2eLSub
= pSource
->e
.loadSubRevision
;
1351 // The time and date of compilation is also available but don't bother
1352 // storing it for normal purposes.
1356 case II_STATE_LOADING
:
1361 return II_DOWN_BADSTATE
;
1364 // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
1365 // must be positive still, because otherwise we would have cleaned up last
1366 // time and set the state to II_STATE_LOADED.
1367 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1368 return II_DOWN_TIMEOUT
;
1371 if (!iiWriteBuf(pB
, pSource
->c
, LOADWARE_BLOCK_SIZE
)) {
1372 return II_DOWN_BADVALID
;
1375 // If we just loaded the first block, wait for the fifo to empty an extra
1376 // long time to allow for any special startup code in the firmware, like
1377 // sending status messages to the LCD's.
1380 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_START_TIME
)) {
1381 return II_DOWN_TIMEOUT
;
1385 // Determine whether this was our last block!
1386 if (--(pB
->i2eToLoad
)) {
1387 return II_DOWN_CONTINUING
; // more to come...
1390 // It WAS our last block: Clean up operations...
1391 // ...Wait for last buffer to drain from the board...
1392 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1393 return II_DOWN_TIMEOUT
;
1395 // If there were only a single block written, this would come back
1396 // immediately and be harmless, though not strictly necessary.
1397 itemp
= MAX_DLOAD_ACK_TIME
/10;
1399 if (HAS_INPUT(pB
)) {
1400 switch(BYTE_FROM(pB
))
1404 isStandard
? II_STATE_STDLOADED
:II_STATE_LOADED
;
1406 // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
1407 // will, // if there is a debug port attached, require some
1408 // time to send information to the debug port now. It will do
1409 // this before // executing any of the code we just downloaded.
1410 // It may take up to 700 milliseconds.
1411 if (pB
->i2ePom
.e
.porDiag2
& POR_DEBUG_PORT
) {
1415 return II_DOWN_GOOD
;
1423 iiDelay(pB
, 10); // 10 mS granularity on checking condition
1426 // Drop-through --> timed out waiting for firmware confirmation
1428 pB
->i2eState
= II_STATE_BADLOAD
;
1429 return II_DOWN_TIMEOUT
;
1432 //******************************************************************************
1433 // Function: iiDownloadAll(pB, pSource, isStandard, size)
1434 // Parameters: pB - pointer to board structure
1435 // pSource - loadware block to download
1436 // isStandard - True if "standard" loadware, else false.
1437 // size - size of data to download (in bytes)
1439 // Returns: Success or Failure
1443 // Given a pointer to a board structure, a pointer to the beginning of some
1444 // loadware, whether it is considered the "standard loadware", and the size of
1445 // the array in bytes loads the entire array to the board as loadware.
1447 // Assumes the board has been freshly reset and the power-up reset message read.
1448 // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
1449 // too much or too little data to load, or if iiDownloadBlock complains.
1450 //******************************************************************************
1452 iiDownloadAll(i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
, int size
)
1456 // We know (from context) board should be ready for the first block of
1457 // download. Complain if not.
1458 if (pB
->i2eState
!= II_STATE_READY
) return II_DOWN_BADSTATE
;
1461 size
-= LOADWARE_BLOCK_SIZE
; // How much data should there be left to
1462 // load after the following operation ?
1464 // Note we just bump pSource by "one", because its size is actually that
1465 // of an entire block, same as LOADWARE_BLOCK_SIZE.
1466 status
= iiDownloadBlock(pB
, pSource
++, isStandard
);
1471 return ( (size
> 0) ? II_DOWN_OVER
: II_DOWN_GOOD
);
1473 case II_DOWN_CONTINUING
:
1481 // We shouldn't drop out: it means "while" caught us with nothing left to
1482 // download, yet the previous DownloadBlock did not return complete. Ergo,
1483 // not enough data to match the size byte in the header.
1484 return II_DOWN_UNDER
;