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 ii2Nop(void);
52 static int ii2Safe
; // Safe I/O address for delay routine
54 static int iiDelayed
; // Set when the iiResetDelay function is
55 // called. Cleared when ANY board is reset.
56 static rwlock_t Dl_spinlock
;
62 //=======================================================
63 // Initialization Routines
69 //=======================================================
71 //******************************************************************************
72 // Function: iiEllisInit()
79 // This routine performs any required initialization of the iiEllis subsystem.
81 //******************************************************************************
85 LOCK_INIT(&Dl_spinlock
);
88 //******************************************************************************
89 // Function: iiEllisCleanup()
96 // This routine performs any required cleanup of the iiEllis subsystem.
98 //******************************************************************************
104 //******************************************************************************
105 // Function: iiSetAddress(pB, address, delay)
106 // Parameters: pB - pointer to the board structure
107 // address - the purported I/O address of the board
108 // delay - pointer to the 1-ms delay function to use
109 // in this and any future operations to this board
111 // Returns: True if everything appears copacetic.
112 // False if there is any error: the pB->i2eError field has the error
116 // This routine (roughly) checks for address validity, sets the i2eValid OK and
117 // sets the state to II_STATE_COLD which means that we haven't even sent a reset
120 //******************************************************************************
122 iiSetAddress( i2eBordStrPtr pB
, int address
, delayFunc_t delay
)
124 // Should any failure occur before init is finished...
125 pB
->i2eValid
= I2E_INCOMPLETE
;
127 // Cannot check upper limit except extremely: Might be microchannel
128 // Address must be on an 8-byte boundary
130 if ((unsigned int)address
<= 0x100
131 || (unsigned int)address
>= 0xfff8
135 COMPLETE(pB
,I2EE_BADADDR
);
138 // Initialize accelerators
139 pB
->i2eBase
= address
;
140 pB
->i2eData
= address
+ FIFO_DATA
;
141 pB
->i2eStatus
= address
+ FIFO_STATUS
;
142 pB
->i2ePointer
= address
+ FIFO_PTR
;
143 pB
->i2eXMail
= address
+ FIFO_MAIL
;
144 pB
->i2eXMask
= address
+ FIFO_MASK
;
146 // Initialize i/o address for ii2DelayIO
147 ii2Safe
= address
+ FIFO_NOP
;
149 // Initialize the delay routine
150 pB
->i2eDelay
= ((delay
!= (delayFunc_t
)NULL
) ? delay
: (delayFunc_t
)ii2Nop
);
152 pB
->i2eValid
= I2E_MAGIC
;
153 pB
->i2eState
= II_STATE_COLD
;
155 COMPLETE(pB
, I2EE_GOOD
);
158 //******************************************************************************
159 // Function: iiReset(pB)
160 // Parameters: pB - pointer to the board structure
162 // Returns: True if everything appears copacetic.
163 // False if there is any error: the pB->i2eError field has the error
167 // Attempts to reset the board (see also i2hw.h). Normally, we would use this to
168 // reset a board immediately after iiSetAddress(), but it is valid to reset a
169 // board from any state, say, in order to change or re-load loadware. (Under
170 // such circumstances, no reason to re-run iiSetAddress(), which is why it is a
171 // separate routine and not included in this routine.
173 //******************************************************************************
175 iiReset(i2eBordStrPtr pB
)
177 // Magic number should be set, else even the address is suspect
178 if (pB
->i2eValid
!= I2E_MAGIC
)
180 COMPLETE(pB
, I2EE_BADMAGIC
);
183 OUTB(pB
->i2eBase
+ FIFO_RESET
, 0); // Any data will do
184 iiDelay(pB
, 50); // Pause between resets
185 OUTB(pB
->i2eBase
+ FIFO_RESET
, 0); // Second reset
187 // We must wait before even attempting to read anything from the FIFO: the
188 // board's P.O.S.T may actually attempt to read and write its end of the
189 // FIFO in order to check flags, loop back (where supported), etc. On
190 // completion of this testing it would reset the FIFO, and on completion
191 // of all // P.O.S.T., write the message. We must not mistake data which
192 // might have been sent for testing as part of the reset message. To
193 // better utilize time, say, when resetting several boards, we allow the
194 // delay to be performed externally; in this way the caller can reset
195 // several boards, delay a single time, then call the initialization
198 pB
->i2eState
= II_STATE_RESET
;
200 iiDelayed
= 0; // i.e., the delay routine hasn't been called since the most
203 // Ensure anything which would have been of use to standard loadware is
204 // blanked out, since board has now forgotten everything!.
206 pB
->i2eUsingIrq
= IRQ_UNDEFINED
; // Not set up to use an interrupt yet
207 pB
->i2eWaitingForEmptyFifo
= 0;
208 pB
->i2eOutMailWaiting
= 0;
209 pB
->i2eChannelPtr
= NULL
;
210 pB
->i2eChannelCnt
= 0;
212 pB
->i2eLeadoffWord
[0] = 0;
213 pB
->i2eFifoInInts
= 0;
214 pB
->i2eFifoOutInts
= 0;
215 pB
->i2eFatalTrap
= NULL
;
218 COMPLETE(pB
, I2EE_GOOD
);
221 //******************************************************************************
222 // Function: iiResetDelay(pB)
223 // Parameters: pB - pointer to the board structure
225 // Returns: True if everything appears copacetic.
226 // False if there is any error: the pB->i2eError field has the error
230 // Using the delay defined in board structure, waits two seconds (for board to
233 //******************************************************************************
235 iiResetDelay(i2eBordStrPtr pB
)
237 if (pB
->i2eValid
!= I2E_MAGIC
) {
238 COMPLETE(pB
, I2EE_BADMAGIC
);
240 if (pB
->i2eState
!= II_STATE_RESET
) {
241 COMPLETE(pB
, I2EE_BADSTATE
);
243 iiDelay(pB
,2000); /* Now we wait for two seconds. */
244 iiDelayed
= 1; /* Delay has been called: ok to initialize */
245 COMPLETE(pB
, I2EE_GOOD
);
248 //******************************************************************************
249 // Function: iiInitialize(pB)
250 // Parameters: pB - pointer to the board structure
252 // Returns: True if everything appears copacetic.
253 // False if there is any error: the pB->i2eError field has the error
257 // Attempts to read the Power-on reset message. Initializes any remaining fields
258 // in the pB structure.
260 // This should be called as the third step of a process beginning with
261 // iiReset(), then iiResetDelay(). This routine checks to see that the structure
262 // is "valid" and in the reset state, also confirms that the delay routine has
263 // been called since the latest reset (to any board! overly strong!).
265 //******************************************************************************
267 iiInitialize(i2eBordStrPtr pB
)
271 unsigned short utemp
;
274 if (pB
->i2eValid
!= I2E_MAGIC
)
276 COMPLETE(pB
, I2EE_BADMAGIC
);
279 if (pB
->i2eState
!= II_STATE_RESET
|| !iiDelayed
)
281 COMPLETE(pB
, I2EE_BADSTATE
);
284 // In case there is a failure short of our completely reading the power-up
286 pB
->i2eValid
= I2E_INCOMPLETE
;
289 // Now attempt to read the message.
291 for (itemp
= 0; itemp
< sizeof(porStr
); itemp
++)
293 // We expect the entire message is ready.
294 if (HAS_NO_INPUT(pB
))
296 pB
->i2ePomSize
= itemp
;
297 COMPLETE(pB
, I2EE_PORM_SHORT
);
300 pB
->i2ePom
.c
[itemp
] = c
= BYTE_FROM(pB
);
302 // We check the magic numbers as soon as they are supposed to be read
303 // (rather than after) to minimize effect of reading something we
304 // already suspect can't be "us".
305 if ( (itemp
== POR_1_INDEX
&& c
!= POR_MAGIC_1
) ||
306 (itemp
== POR_2_INDEX
&& c
!= POR_MAGIC_2
))
308 pB
->i2ePomSize
= itemp
+1;
309 COMPLETE(pB
, I2EE_BADMAGIC
);
313 pB
->i2ePomSize
= itemp
;
315 // Ensure that this was all the data...
317 COMPLETE(pB
, I2EE_PORM_LONG
);
319 // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
320 // Implying we will not be able to download any code either: That's ok: the
321 // condition is pretty explicit.
322 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_MAPPER
)
324 COMPLETE(pB
, I2EE_POSTERR
);
327 // Determine anything which must be done differently depending on the family
329 switch (pB
->i2ePom
.e
.porID
& POR_ID_FAMILY
)
331 case POR_ID_FII
: // IntelliPort-II
333 pB
->i2eFifoStyle
= FIFO_II
;
334 pB
->i2eFifoSize
= 512; // 512 bytes, always
335 pB
->i2eDataWidth16
= NO
;
337 pB
->i2eMaxIrq
= 15; // Because board cannot tell us it is in an 8-bit
338 // slot, we do allow it to be done (documentation!)
343 pB
->i2eChannelMap
[1] =
344 pB
->i2eChannelMap
[2] =
345 pB
->i2eChannelMap
[3] = 0;
347 switch (pB
->i2ePom
.e
.porID
& POR_ID_SIZE
)
351 pB
->i2eChannelMap
[0] = 0x0f; // four-port
353 // Since porPorts1 is based on the Hardware ID register, the numbers
354 // should always be consistent for IntelliPort-II. Ditto below...
355 if (pB
->i2ePom
.e
.porPorts1
!= 4)
357 COMPLETE(pB
, I2EE_INCONSIST
);
364 pB
->i2eChannelMap
[0] = 0xff; // Eight port
365 if (pB
->i2ePom
.e
.porPorts1
!= 8)
367 COMPLETE(pB
, I2EE_INCONSIST
);
373 pB
->i2eChannelMap
[0] = 0x3f; // Six Port
374 if (pB
->i2ePom
.e
.porPorts1
!= 6)
376 COMPLETE(pB
, I2EE_INCONSIST
);
381 // Fix up the "good channel list based on any errors reported.
382 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART1
)
384 pB
->i2eGoodMap
[0] &= ~0x0f;
387 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART2
)
389 pB
->i2eGoodMap
[0] &= ~0xf0;
392 break; // POR_ID_FII case
394 case POR_ID_FIIEX
: // IntelliPort-IIEX
396 pB
->i2eFifoStyle
= FIFO_IIEX
;
398 itemp
= pB
->i2ePom
.e
.porFifoSize
;
400 // Implicit assumption that fifo would not grow beyond 32k,
401 // nor would ever be less than 256.
403 if (itemp
< 8 || itemp
> 15)
405 COMPLETE(pB
, I2EE_INCONSIST
);
407 pB
->i2eFifoSize
= (1 << itemp
);
409 // These are based on what P.O.S.T thinks should be there, based on
411 ilimit
= pB
->i2ePom
.e
.porNumBoxes
;
412 if (ilimit
> ABS_MAX_BOXES
)
414 ilimit
= ABS_MAX_BOXES
;
417 // For as many boxes as EXIST, gives the type of box.
418 // Added 8/6/93: check for the ISA-4 (asic) which looks like an
419 // expandable but for whom "8 or 16?" is not the right question.
421 utemp
= pB
->i2ePom
.e
.porFlags
;
422 if (utemp
& POR_CEX4
)
424 pB
->i2eChannelMap
[0] = 0x000f;
427 for (itemp
= 0; itemp
< ilimit
; itemp
++)
429 pB
->i2eChannelMap
[itemp
] =
430 ((utemp
& POR_BOX_16
) ? 0xffff : 0x00ff);
435 // These are based on what P.O.S.T actually found.
437 utemp
= (pB
->i2ePom
.e
.porPorts2
<< 8) + pB
->i2ePom
.e
.porPorts1
;
439 for (itemp
= 0; itemp
< ilimit
; itemp
++)
441 pB
->i2eGoodMap
[itemp
] = 0;
442 if (utemp
& 1) pB
->i2eGoodMap
[itemp
] |= 0x000f;
443 if (utemp
& 2) pB
->i2eGoodMap
[itemp
] |= 0x00f0;
444 if (utemp
& 4) pB
->i2eGoodMap
[itemp
] |= 0x0f00;
445 if (utemp
& 8) pB
->i2eGoodMap
[itemp
] |= 0xf000;
449 // Now determine whether we should transfer in 8 or 16-bit mode.
450 switch (pB
->i2ePom
.e
.porBus
& (POR_BUS_SLOT16
| POR_BUS_DIP16
) )
452 case POR_BUS_SLOT16
| POR_BUS_DIP16
:
453 pB
->i2eDataWidth16
= YES
;
458 pB
->i2eDataWidth16
= NO
;
463 case POR_BUS_DIP16
: // In an 8-bit slot, DIP switch don't care.
465 pB
->i2eDataWidth16
= NO
;
469 break; // POR_ID_FIIEX case
471 default: // Unknown type of board
472 COMPLETE(pB
, I2EE_BAD_FAMILY
);
474 } // End the switch based on family
476 // Temporarily, claim there is no room in the outbound fifo.
477 // We will maintain this whenever we check for an empty outbound FIFO.
478 pB
->i2eFifoRemains
= 0;
480 // Now, based on the bus type, should we expect to be able to re-configure
481 // interrupts (say, for testing purposes).
482 switch (pB
->i2ePom
.e
.porBus
& POR_BUS_TYPE
)
485 case POR_BUS_T_UNK
: // If the type of bus is undeclared, assume ok.
486 pB
->i2eChangeIrq
= YES
;
490 pB
->i2eChangeIrq
= NO
;
493 COMPLETE(pB
, I2EE_BADBUS
);
496 if (pB
->i2eDataWidth16
== YES
)
498 pB
->i2eWriteBuf
= iiWriteBuf16
;
499 pB
->i2eReadBuf
= iiReadBuf16
;
500 pB
->i2eWriteWord
= iiWriteWord16
;
501 pB
->i2eReadWord
= iiReadWord16
;
503 pB
->i2eWriteBuf
= iiWriteBuf8
;
504 pB
->i2eReadBuf
= iiReadBuf8
;
505 pB
->i2eWriteWord
= iiWriteWord8
;
506 pB
->i2eReadWord
= iiReadWord8
;
509 switch(pB
->i2eFifoStyle
)
512 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyII
;
513 pB
->i2eTxMailEmpty
= iiTxMailEmptyII
;
514 pB
->i2eTrySendMail
= iiTrySendMailII
;
515 pB
->i2eGetMail
= iiGetMailII
;
516 pB
->i2eEnableMailIrq
= iiEnableMailIrqII
;
517 pB
->i2eWriteMask
= iiWriteMaskII
;
522 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyIIEX
;
523 pB
->i2eTxMailEmpty
= iiTxMailEmptyIIEX
;
524 pB
->i2eTrySendMail
= iiTrySendMailIIEX
;
525 pB
->i2eGetMail
= iiGetMailIIEX
;
526 pB
->i2eEnableMailIrq
= iiEnableMailIrqIIEX
;
527 pB
->i2eWriteMask
= iiWriteMaskIIEX
;
532 COMPLETE(pB
, I2EE_INCONSIST
);
535 // Initialize state information.
536 pB
->i2eState
= II_STATE_READY
; // Ready to load loadware.
538 // Some Final cleanup:
539 // For some boards, the bootstrap firmware may perform some sort of test
540 // resulting in a stray character pending in the incoming mailbox. If one is
541 // there, it should be read and discarded, especially since for the standard
542 // firmware, it's the mailbox that interrupts the host.
544 pB
->i2eStartMail
= iiGetMail(pB
);
546 // Throw it away and clear the mailbox structure element
547 pB
->i2eStartMail
= NO_MAIL_HERE
;
549 // Everything is ok now, return with good status/
551 pB
->i2eValid
= I2E_MAGIC
;
552 COMPLETE(pB
, I2EE_GOOD
);
555 //******************************************************************************
556 // Function: ii2DelayTimer(mseconds)
557 // Parameters: mseconds - number of milliseconds to delay
563 // This routine delays for approximately mseconds milliseconds and is intended
564 // to be called indirectly through i2Delay field in i2eBordStr. It uses the
565 // Linux timer_list mechanism.
567 // The Linux timers use a unit called "jiffies" which are 10mS in the Intel
568 // architecture. This function rounds the delay period up to the next "jiffy".
569 // In the Alpha architecture the "jiffy" is 1mS, but this driver is not intended
570 // for Alpha platforms at this time.
572 //******************************************************************************
574 ii2DelayTimer(unsigned int mseconds
)
576 msleep_interruptible(mseconds
);
580 //static void ii2DelayIO(unsigned int);
581 //******************************************************************************
582 // !!! Not Used, this is DOS crap, some of you young folks may be interested in
583 // in how things were done in the stone age of caculating machines !!!
584 // Function: ii2DelayIO(mseconds)
585 // Parameters: mseconds - number of milliseconds to delay
591 // This routine delays for approximately mseconds milliseconds and is intended
592 // to be called indirectly through i2Delay field in i2eBordStr. It is intended
593 // for use where a clock-based function is impossible: for example, DOS drivers.
595 // This function uses the IN instruction to place bounds on the timing and
596 // assumes that ii2Safe has been set. This is because I/O instructions are not
597 // subject to caching and will therefore take a certain minimum time. To ensure
598 // the delay is at least long enough on fast machines, it is based on some
599 // fastest-case calculations. On slower machines this may cause VERY long
600 // delays. (3 x fastest case). In the fastest case, everything is cached except
601 // the I/O instruction itself.
603 // Timing calculations:
604 // The fastest bus speed for I/O operations is likely to be 10 MHz. The I/O
605 // operation in question is a byte operation to an odd address. For 8-bit
606 // operations, the architecture generally enforces two wait states. At 10 MHz, a
607 // single cycle time is 100nS. A read operation at two wait states takes 6
608 // cycles for a total time of 600nS. Therefore approximately 1666 iterations
609 // would be required to generate a single millisecond delay. The worst
610 // (reasonable) case would be an 8MHz system with no cacheing. In this case, the
611 // I/O instruction would take 125nS x 6 cyles = 750 nS. More importantly, code
612 // fetch of other instructions in the loop would take time (zero wait states,
613 // however) and would be hard to estimate. This is minimized by using in-line
614 // assembler for the in inner loop of IN instructions. This consists of just a
615 // few bytes. So we'll guess about four code fetches per loop. Each code fetch
616 // should take four cycles, so we have 125nS * 8 = 1000nS. Worst case then is
617 // that what should have taken 1 mS takes instead 1666 * (1750) = 2.9 mS.
619 // So much for theoretical timings: results using 1666 value on some actual
621 // IBM 286 6MHz 3.15 mS
622 // Zenith 386 33MHz 2.45 mS
623 // (brandX) 386 33MHz 1.90 mS (has cache)
624 // (brandY) 486 33MHz 2.35 mS
625 // NCR 486 ?? 1.65 mS (microchannel)
627 // For most machines, it is probably safe to scale this number back (remember,
628 // for robust operation use an actual timed delay if possible), so we are using
629 // a value of 1190. This yields 1.17 mS for the fastest machine in our sample,
630 // 1.75 mS for typical 386 machines, and 2.25 mS the absolute slowest machine.
633 // The above timings are too slow. Actual cycle times might be faster. ISA cycle
634 // times could approach 500 nS, and ...
635 // The IBM model 77 being microchannel has no wait states for 8-bit reads and
636 // seems to be accessing the I/O at 440 nS per access (from start of one to
637 // start of next). This would imply we need 1000/.440 = 2272 iterations to
638 // guarantee we are fast enough. In actual testing, we see that 2 * 1190 are in
639 // fact enough. For diagnostics, we keep the level at 1190, but developers note
640 // this needs tuning.
642 // Safe assumption: 2270 i/o reads = 1 millisecond
644 //******************************************************************************
647 static int ii2DelValue
= 1190; // See timing calculations below
648 // 1666 for fastest theoretical machine
649 // 1190 safe for most fast 386 machines
650 // 1000 for fastest machine tested here
651 // 540 (sic) for AT286/6Mhz
653 ii2DelayIO(unsigned int mseconds
)
656 return; /* Do nothing if this variable uninitialized */
667 //******************************************************************************
668 // Function: ii2Nop()
675 // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
676 // saves checking for a NULL pointer at every call.
677 //******************************************************************************
681 return; // no mystery here
684 //=======================================================
685 // Routines which are available in 8/16-bit versions, or
686 // in different fifo styles. These are ALL called
687 // indirectly through the board structure.
688 //=======================================================
690 //******************************************************************************
691 // Function: iiWriteBuf16(pB, address, count)
692 // Parameters: pB - pointer to board structure
693 // address - address of data to write
694 // count - number of data bytes to write
696 // Returns: True if everything appears copacetic.
697 // False if there is any error: the pB->i2eError field has the error
701 // Writes 'count' bytes from 'address' to the data fifo specified by the board
702 // structure pointer pB. Should count happen to be odd, an extra pad byte is
703 // sent (identity unknown...). Uses 16-bit (word) operations. Is called
704 // indirectly through pB->i2eWriteBuf.
706 //******************************************************************************
708 iiWriteBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
710 // Rudimentary sanity checking here.
711 if (pB
->i2eValid
!= I2E_MAGIC
)
712 COMPLETE(pB
, I2EE_INVALID
);
714 OUTSW ( pB
->i2eData
, address
, count
);
716 COMPLETE(pB
, I2EE_GOOD
);
719 //******************************************************************************
720 // Function: iiWriteBuf8(pB, address, count)
721 // Parameters: pB - pointer to board structure
722 // address - address of data to write
723 // count - number of data bytes to write
725 // Returns: True if everything appears copacetic.
726 // False if there is any error: the pB->i2eError field has the error
730 // Writes 'count' bytes from 'address' to the data fifo specified by the board
731 // structure pointer pB. Should count happen to be odd, an extra pad byte is
732 // sent (identity unknown...). This is to be consistent with the 16-bit version.
733 // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
735 //******************************************************************************
737 iiWriteBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
739 /* Rudimentary sanity checking here */
740 if (pB
->i2eValid
!= I2E_MAGIC
)
741 COMPLETE(pB
, I2EE_INVALID
);
743 OUTSB ( pB
->i2eData
, address
, count
);
745 COMPLETE(pB
, I2EE_GOOD
);
748 //******************************************************************************
749 // Function: iiReadBuf16(pB, address, count)
750 // Parameters: pB - pointer to board structure
751 // address - address to put data read
752 // count - number of data bytes to read
754 // Returns: True if everything appears copacetic.
755 // False if there is any error: the pB->i2eError field has the error
759 // Reads 'count' bytes into 'address' from the data fifo specified by the board
760 // structure pointer pB. Should count happen to be odd, an extra pad byte is
761 // received (identity unknown...). Uses 16-bit (word) operations. Is called
762 // indirectly through pB->i2eReadBuf.
764 //******************************************************************************
766 iiReadBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
768 // Rudimentary sanity checking here.
769 if (pB
->i2eValid
!= I2E_MAGIC
)
770 COMPLETE(pB
, I2EE_INVALID
);
772 INSW ( pB
->i2eData
, address
, count
);
774 COMPLETE(pB
, I2EE_GOOD
);
777 //******************************************************************************
778 // Function: iiReadBuf8(pB, address, count)
779 // Parameters: pB - pointer to board structure
780 // address - address to put data read
781 // count - number of data bytes to read
783 // Returns: True if everything appears copacetic.
784 // False if there is any error: the pB->i2eError field has the error
788 // Reads 'count' bytes into 'address' from the data fifo specified by the board
789 // structure pointer pB. Should count happen to be odd, an extra pad byte is
790 // received (identity unknown...). This to match the 16-bit behaviour. Uses
791 // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
793 //******************************************************************************
795 iiReadBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
797 // Rudimentary sanity checking here.
798 if (pB
->i2eValid
!= I2E_MAGIC
)
799 COMPLETE(pB
, I2EE_INVALID
);
801 INSB ( pB
->i2eData
, address
, count
);
803 COMPLETE(pB
, I2EE_GOOD
);
806 //******************************************************************************
807 // Function: iiReadWord16(pB)
808 // Parameters: pB - pointer to board structure
810 // Returns: True if everything appears copacetic.
811 // False if there is any error: the pB->i2eError field has the error
815 // Returns the word read from the data fifo specified by the board-structure
816 // pointer pB. Uses a 16-bit operation. Is called indirectly through
819 //******************************************************************************
820 static unsigned short
821 iiReadWord16(i2eBordStrPtr pB
)
823 return (unsigned short)( INW(pB
->i2eData
) );
826 //******************************************************************************
827 // Function: iiReadWord8(pB)
828 // Parameters: pB - pointer to board structure
830 // Returns: True if everything appears copacetic.
831 // False if there is any error: the pB->i2eError field has the error
835 // Returns the word read from the data fifo specified by the board-structure
836 // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
837 // called indirectly through pB->i2eReadWord.
839 //******************************************************************************
840 static unsigned short
841 iiReadWord8(i2eBordStrPtr pB
)
845 urs
= INB ( pB
->i2eData
);
847 return ( ( INB ( pB
->i2eData
) << 8 ) | urs
);
850 //******************************************************************************
851 // Function: iiWriteWord16(pB, value)
852 // Parameters: pB - pointer to board structure
853 // value - data to write
855 // Returns: True if everything appears copacetic.
856 // False if there is any error: the pB->i2eError field has the error
860 // Writes the word 'value' to the data fifo specified by the board-structure
861 // pointer pB. Uses 16-bit operation. Is called indirectly through
864 //******************************************************************************
866 iiWriteWord16(i2eBordStrPtr pB
, unsigned short value
)
868 WORD_TO(pB
, (int)value
);
871 //******************************************************************************
872 // Function: iiWriteWord8(pB, value)
873 // Parameters: pB - pointer to board structure
874 // value - data to write
876 // Returns: True if everything appears copacetic.
877 // False if there is any error: the pB->i2eError field has the error
881 // Writes the word 'value' to the data fifo specified by the board-structure
882 // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
883 // indirectly through pB->i2eWriteWord.
885 //******************************************************************************
887 iiWriteWord8(i2eBordStrPtr pB
, unsigned short value
)
889 BYTE_TO(pB
, (char)value
);
890 BYTE_TO(pB
, (char)(value
>> 8) );
893 //******************************************************************************
894 // Function: iiWaitForTxEmptyII(pB, mSdelay)
895 // Parameters: pB - pointer to board structure
896 // mSdelay - period to wait before returning
898 // Returns: True if the FIFO is empty.
899 // False if it not empty in the required time: the pB->i2eError
900 // field has the error.
904 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
905 // not empty by the required time, returns false and error in pB->i2eError,
906 // otherwise returns true.
908 // mSdelay == 0 is taken to mean must be empty on the first test.
910 // This version operates on IntelliPort-II - style FIFO's
912 // Note this routine is organized so that if status is ok there is no delay at
913 // all called either before or after the test. Is called indirectly through
914 // pB->i2eWaitForTxEmpty.
916 //******************************************************************************
918 iiWaitForTxEmptyII(i2eBordStrPtr pB
, int mSdelay
)
925 // This routine hinges on being able to see the "other" status register
926 // (as seen by the local processor). His incoming fifo is our outgoing
929 // By the nature of this routine, you would be using this as part of a
930 // larger atomic context: i.e., you would use this routine to ensure the
931 // fifo empty, then act on this information. Between these two halves,
932 // you will generally not want to service interrupts or in any way
933 // disrupt the assumptions implicit in the larger context.
935 // Even worse, however, this routine "shifts" the status register to
936 // point to the local status register which is not the usual situation.
937 // Therefore for extra safety, we force the critical section to be
938 // completely atomic, and pick up after ourselves before allowing any
939 // interrupts of any kind.
942 WRITE_LOCK_IRQSAVE(&Dl_spinlock
,flags
)
943 OUTB(pB
->i2ePointer
, SEL_COMMAND
);
944 OUTB(pB
->i2ePointer
, SEL_CMD_SH
);
946 itemp
= INB(pB
->i2eStatus
);
948 OUTB(pB
->i2ePointer
, SEL_COMMAND
);
949 OUTB(pB
->i2ePointer
, SEL_CMD_UNSH
);
951 if (itemp
& ST_IN_EMPTY
)
953 UPDATE_FIFO_ROOM(pB
);
954 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
955 COMPLETE(pB
, I2EE_GOOD
);
958 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
963 iiDelay(pB
, 1); /* 1 mS granularity on checking condition */
965 COMPLETE(pB
, I2EE_TXE_TIME
);
968 //******************************************************************************
969 // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
970 // Parameters: pB - pointer to board structure
971 // mSdelay - period to wait before returning
973 // Returns: True if the FIFO is empty.
974 // False if it not empty in the required time: the pB->i2eError
975 // field has the error.
979 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
980 // not empty by the required time, returns false and error in pB->i2eError,
981 // otherwise returns true.
983 // mSdelay == 0 is taken to mean must be empty on the first test.
985 // This version operates on IntelliPort-IIEX - style FIFO's
987 // Note this routine is organized so that if status is ok there is no delay at
988 // all called either before or after the test. Is called indirectly through
989 // pB->i2eWaitForTxEmpty.
991 //******************************************************************************
993 iiWaitForTxEmptyIIEX(i2eBordStrPtr pB
, int mSdelay
)
999 // By the nature of this routine, you would be using this as part of a
1000 // larger atomic context: i.e., you would use this routine to ensure the
1001 // fifo empty, then act on this information. Between these two halves,
1002 // you will generally not want to service interrupts or in any way
1003 // disrupt the assumptions implicit in the larger context.
1005 WRITE_LOCK_IRQSAVE(&Dl_spinlock
,flags
)
1007 if (INB(pB
->i2eStatus
) & STE_OUT_MT
) {
1008 UPDATE_FIFO_ROOM(pB
);
1009 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
1010 COMPLETE(pB
, I2EE_GOOD
);
1012 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock
,flags
)
1017 iiDelay(pB
, 1); // 1 mS granularity on checking condition
1019 COMPLETE(pB
, I2EE_TXE_TIME
);
1022 //******************************************************************************
1023 // Function: iiTxMailEmptyII(pB)
1024 // Parameters: pB - pointer to board structure
1026 // Returns: True if the transmit mailbox is empty.
1027 // False if it not empty.
1031 // Returns true or false according to whether the transmit mailbox is empty (and
1032 // therefore able to accept more mail)
1034 // This version operates on IntelliPort-II - style FIFO's
1036 //******************************************************************************
1038 iiTxMailEmptyII(i2eBordStrPtr pB
)
1040 int port
= pB
->i2ePointer
;
1041 OUTB ( port
, SEL_OUTMAIL
);
1042 return ( INB(port
) == 0 );
1045 //******************************************************************************
1046 // Function: iiTxMailEmptyIIEX(pB)
1047 // Parameters: pB - pointer to board structure
1049 // Returns: True if the transmit mailbox is empty.
1050 // False if it not empty.
1054 // Returns true or false according to whether the transmit mailbox is empty (and
1055 // therefore able to accept more mail)
1057 // This version operates on IntelliPort-IIEX - style FIFO's
1059 //******************************************************************************
1061 iiTxMailEmptyIIEX(i2eBordStrPtr pB
)
1063 return !(INB(pB
->i2eStatus
) & STE_OUT_MAIL
);
1066 //******************************************************************************
1067 // Function: iiTrySendMailII(pB,mail)
1068 // Parameters: pB - pointer to board structure
1069 // mail - value to write to mailbox
1071 // Returns: True if the transmit mailbox is empty, and mail is sent.
1072 // False if it not empty.
1076 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1077 // mailbox is not empty, returns false.
1079 // This version operates on IntelliPort-II - style FIFO's
1081 //******************************************************************************
1083 iiTrySendMailII(i2eBordStrPtr pB
, unsigned char mail
)
1085 int port
= pB
->i2ePointer
;
1087 OUTB(port
, SEL_OUTMAIL
);
1088 if (INB(port
) == 0) {
1089 OUTB(port
, SEL_OUTMAIL
);
1096 //******************************************************************************
1097 // Function: iiTrySendMailIIEX(pB,mail)
1098 // Parameters: pB - pointer to board structure
1099 // mail - value to write to mailbox
1101 // Returns: True if the transmit mailbox is empty, and mail is sent.
1102 // False if it not empty.
1106 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1107 // mailbox is not empty, returns false.
1109 // This version operates on IntelliPort-IIEX - style FIFO's
1111 //******************************************************************************
1113 iiTrySendMailIIEX(i2eBordStrPtr pB
, unsigned char mail
)
1115 if(INB(pB
->i2eStatus
) & STE_OUT_MAIL
) {
1118 OUTB(pB
->i2eXMail
, mail
);
1122 //******************************************************************************
1123 // Function: iiGetMailII(pB,mail)
1124 // Parameters: pB - pointer to board structure
1126 // Returns: Mailbox data or NO_MAIL_HERE.
1130 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1131 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1133 // This version operates on IntelliPort-II - style FIFO's
1135 //******************************************************************************
1136 static unsigned short
1137 iiGetMailII(i2eBordStrPtr pB
)
1140 OUTB(pB
->i2ePointer
, SEL_INMAIL
);
1141 return INB(pB
->i2ePointer
);
1143 return NO_MAIL_HERE
;
1147 //******************************************************************************
1148 // Function: iiGetMailIIEX(pB,mail)
1149 // Parameters: pB - pointer to board structure
1151 // Returns: Mailbox data or NO_MAIL_HERE.
1155 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1156 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1158 // This version operates on IntelliPort-IIEX - style FIFO's
1160 //******************************************************************************
1161 static unsigned short
1162 iiGetMailIIEX(i2eBordStrPtr pB
)
1165 return INB(pB
->i2eXMail
);
1167 return NO_MAIL_HERE
;
1171 //******************************************************************************
1172 // Function: iiEnableMailIrqII(pB)
1173 // Parameters: pB - pointer to board structure
1179 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1181 // This version operates on IntelliPort-II - style FIFO's
1183 //******************************************************************************
1185 iiEnableMailIrqII(i2eBordStrPtr pB
)
1187 OUTB(pB
->i2ePointer
, SEL_MASK
);
1188 OUTB(pB
->i2ePointer
, ST_IN_MAIL
);
1191 //******************************************************************************
1192 // Function: iiEnableMailIrqIIEX(pB)
1193 // Parameters: pB - pointer to board structure
1199 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1201 // This version operates on IntelliPort-IIEX - style FIFO's
1203 //******************************************************************************
1205 iiEnableMailIrqIIEX(i2eBordStrPtr pB
)
1207 OUTB(pB
->i2eXMask
, MX_IN_MAIL
);
1210 //******************************************************************************
1211 // Function: iiWriteMaskII(pB)
1212 // Parameters: pB - pointer to board structure
1218 // Writes arbitrary value to the mask register.
1220 // This version operates on IntelliPort-II - style FIFO's
1222 //******************************************************************************
1224 iiWriteMaskII(i2eBordStrPtr pB
, unsigned char value
)
1226 OUTB(pB
->i2ePointer
, SEL_MASK
);
1227 OUTB(pB
->i2ePointer
, value
);
1230 //******************************************************************************
1231 // Function: iiWriteMaskIIEX(pB)
1232 // Parameters: pB - pointer to board structure
1238 // Writes arbitrary value to the mask register.
1240 // This version operates on IntelliPort-IIEX - style FIFO's
1242 //******************************************************************************
1244 iiWriteMaskIIEX(i2eBordStrPtr pB
, unsigned char value
)
1246 OUTB(pB
->i2eXMask
, value
);
1249 //******************************************************************************
1250 // Function: iiDownloadBlock(pB, pSource, isStandard)
1251 // Parameters: pB - pointer to board structure
1252 // pSource - loadware block to download
1253 // isStandard - True if "standard" loadware, else false.
1255 // Returns: Success or Failure
1259 // Downloads a single block (at pSource)to the board referenced by pB. Caller
1260 // sets isStandard to true/false according to whether the "standard" loadware is
1261 // what's being loaded. The normal process, then, is to perform an iiInitialize
1262 // to the board, then perform some number of iiDownloadBlocks using the returned
1263 // state to determine when download is complete.
1265 // Possible return values: (see I2ELLIS.H)
1268 // II_DOWN_CONTINUING
1274 // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
1275 // determine whether this is the first block, whether to check for magic
1276 // numbers, how many blocks there are to go...
1278 //******************************************************************************
1280 iiDownloadBlock ( i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
)
1285 if (pB
->i2eValid
!= I2E_MAGIC
) return II_DOWN_BADVALID
;
1287 switch(pB
->i2eState
)
1289 case II_STATE_READY
:
1291 // Loading the first block after reset. Must check the magic number of the
1292 // loadfile, store the number of blocks we expect to load.
1293 if (pSource
->e
.loadMagic
!= MAGIC_LOADFILE
)
1295 return II_DOWN_BADFILE
;
1298 // Next we store the total number of blocks to load, including this one.
1299 pB
->i2eToLoad
= 1 + pSource
->e
.loadBlocksMore
;
1301 // Set the state, store the version numbers. ('Cause this may have come
1302 // from a file - we might want to report these versions and revisions in
1303 // case of an error!
1304 pB
->i2eState
= II_STATE_LOADING
;
1305 pB
->i2eLVersion
= pSource
->e
.loadVersion
;
1306 pB
->i2eLRevision
= pSource
->e
.loadRevision
;
1307 pB
->i2eLSub
= pSource
->e
.loadSubRevision
;
1309 // The time and date of compilation is also available but don't bother
1310 // storing it for normal purposes.
1314 case II_STATE_LOADING
:
1319 return II_DOWN_BADSTATE
;
1322 // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
1323 // must be positive still, because otherwise we would have cleaned up last
1324 // time and set the state to II_STATE_LOADED.
1325 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1326 return II_DOWN_TIMEOUT
;
1329 if (!iiWriteBuf(pB
, pSource
->c
, LOADWARE_BLOCK_SIZE
)) {
1330 return II_DOWN_BADVALID
;
1333 // If we just loaded the first block, wait for the fifo to empty an extra
1334 // long time to allow for any special startup code in the firmware, like
1335 // sending status messages to the LCD's.
1338 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_START_TIME
)) {
1339 return II_DOWN_TIMEOUT
;
1343 // Determine whether this was our last block!
1344 if (--(pB
->i2eToLoad
)) {
1345 return II_DOWN_CONTINUING
; // more to come...
1348 // It WAS our last block: Clean up operations...
1349 // ...Wait for last buffer to drain from the board...
1350 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1351 return II_DOWN_TIMEOUT
;
1353 // If there were only a single block written, this would come back
1354 // immediately and be harmless, though not strictly necessary.
1355 itemp
= MAX_DLOAD_ACK_TIME
/10;
1357 if (HAS_INPUT(pB
)) {
1358 switch(BYTE_FROM(pB
))
1362 isStandard
? II_STATE_STDLOADED
:II_STATE_LOADED
;
1364 // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
1365 // will, // if there is a debug port attached, require some
1366 // time to send information to the debug port now. It will do
1367 // this before // executing any of the code we just downloaded.
1368 // It may take up to 700 milliseconds.
1369 if (pB
->i2ePom
.e
.porDiag2
& POR_DEBUG_PORT
) {
1373 return II_DOWN_GOOD
;
1381 iiDelay(pB
, 10); // 10 mS granularity on checking condition
1384 // Drop-through --> timed out waiting for firmware confirmation
1386 pB
->i2eState
= II_STATE_BADLOAD
;
1387 return II_DOWN_TIMEOUT
;
1390 //******************************************************************************
1391 // Function: iiDownloadAll(pB, pSource, isStandard, size)
1392 // Parameters: pB - pointer to board structure
1393 // pSource - loadware block to download
1394 // isStandard - True if "standard" loadware, else false.
1395 // size - size of data to download (in bytes)
1397 // Returns: Success or Failure
1401 // Given a pointer to a board structure, a pointer to the beginning of some
1402 // loadware, whether it is considered the "standard loadware", and the size of
1403 // the array in bytes loads the entire array to the board as loadware.
1405 // Assumes the board has been freshly reset and the power-up reset message read.
1406 // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
1407 // too much or too little data to load, or if iiDownloadBlock complains.
1408 //******************************************************************************
1410 iiDownloadAll(i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
, int size
)
1414 // We know (from context) board should be ready for the first block of
1415 // download. Complain if not.
1416 if (pB
->i2eState
!= II_STATE_READY
) return II_DOWN_BADSTATE
;
1419 size
-= LOADWARE_BLOCK_SIZE
; // How much data should there be left to
1420 // load after the following operation ?
1422 // Note we just bump pSource by "one", because its size is actually that
1423 // of an entire block, same as LOADWARE_BLOCK_SIZE.
1424 status
= iiDownloadBlock(pB
, pSource
++, isStandard
);
1429 return ( (size
> 0) ? II_DOWN_OVER
: II_DOWN_GOOD
);
1431 case II_DOWN_CONTINUING
:
1439 // We shouldn't drop out: it means "while" caught us with nothing left to
1440 // download, yet the previous DownloadBlock did not return complete. Ergo,
1441 // not enough data to match the size byte in the header.
1442 return II_DOWN_UNDER
;