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 DEFINE_RWLOCK(Dl_spinlock
);
62 //=======================================================
63 // Initialization Routines
69 //=======================================================
71 //******************************************************************************
72 // Function: iiEllisInit()
79 // This routine performs any required initialization of the iiEllis subsystem.
81 //******************************************************************************
87 //******************************************************************************
88 // Function: iiEllisCleanup()
95 // This routine performs any required cleanup of the iiEllis subsystem.
97 //******************************************************************************
103 //******************************************************************************
104 // Function: iiSetAddress(pB, address, delay)
105 // Parameters: pB - pointer to the board structure
106 // address - the purported I/O address of the board
107 // delay - pointer to the 1-ms delay function to use
108 // in this and any future operations to this board
110 // Returns: True if everything appears copacetic.
111 // False if there is any error: the pB->i2eError field has the error
115 // This routine (roughly) checks for address validity, sets the i2eValid OK and
116 // sets the state to II_STATE_COLD which means that we haven't even sent a reset
119 //******************************************************************************
121 iiSetAddress( i2eBordStrPtr pB
, int address
, delayFunc_t delay
)
123 // Should any failure occur before init is finished...
124 pB
->i2eValid
= I2E_INCOMPLETE
;
126 // Cannot check upper limit except extremely: Might be microchannel
127 // Address must be on an 8-byte boundary
129 if ((unsigned int)address
<= 0x100
130 || (unsigned int)address
>= 0xfff8
134 I2_COMPLETE(pB
, I2EE_BADADDR
);
137 // Initialize accelerators
138 pB
->i2eBase
= address
;
139 pB
->i2eData
= address
+ FIFO_DATA
;
140 pB
->i2eStatus
= address
+ FIFO_STATUS
;
141 pB
->i2ePointer
= address
+ FIFO_PTR
;
142 pB
->i2eXMail
= address
+ FIFO_MAIL
;
143 pB
->i2eXMask
= address
+ FIFO_MASK
;
145 // Initialize i/o address for ii2DelayIO
146 ii2Safe
= address
+ FIFO_NOP
;
148 // Initialize the delay routine
149 pB
->i2eDelay
= ((delay
!= (delayFunc_t
)NULL
) ? delay
: (delayFunc_t
)ii2Nop
);
151 pB
->i2eValid
= I2E_MAGIC
;
152 pB
->i2eState
= II_STATE_COLD
;
154 I2_COMPLETE(pB
, I2EE_GOOD
);
157 //******************************************************************************
158 // Function: iiReset(pB)
159 // Parameters: pB - pointer to the board structure
161 // Returns: True if everything appears copacetic.
162 // False if there is any error: the pB->i2eError field has the error
166 // Attempts to reset the board (see also i2hw.h). Normally, we would use this to
167 // reset a board immediately after iiSetAddress(), but it is valid to reset a
168 // board from any state, say, in order to change or re-load loadware. (Under
169 // such circumstances, no reason to re-run iiSetAddress(), which is why it is a
170 // separate routine and not included in this routine.
172 //******************************************************************************
174 iiReset(i2eBordStrPtr pB
)
176 // Magic number should be set, else even the address is suspect
177 if (pB
->i2eValid
!= I2E_MAGIC
)
179 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
182 outb(0, pB
->i2eBase
+ FIFO_RESET
); /* Any data will do */
183 iiDelay(pB
, 50); // Pause between resets
184 outb(0, pB
->i2eBase
+ FIFO_RESET
); /* Second reset */
186 // We must wait before even attempting to read anything from the FIFO: the
187 // board's P.O.S.T may actually attempt to read and write its end of the
188 // FIFO in order to check flags, loop back (where supported), etc. On
189 // completion of this testing it would reset the FIFO, and on completion
190 // of all // P.O.S.T., write the message. We must not mistake data which
191 // might have been sent for testing as part of the reset message. To
192 // better utilize time, say, when resetting several boards, we allow the
193 // delay to be performed externally; in this way the caller can reset
194 // several boards, delay a single time, then call the initialization
197 pB
->i2eState
= II_STATE_RESET
;
199 iiDelayed
= 0; // i.e., the delay routine hasn't been called since the most
202 // Ensure anything which would have been of use to standard loadware is
203 // blanked out, since board has now forgotten everything!.
205 pB
->i2eUsingIrq
= I2_IRQ_UNDEFINED
; /* to not use an interrupt so far */
206 pB
->i2eWaitingForEmptyFifo
= 0;
207 pB
->i2eOutMailWaiting
= 0;
208 pB
->i2eChannelPtr
= NULL
;
209 pB
->i2eChannelCnt
= 0;
211 pB
->i2eLeadoffWord
[0] = 0;
212 pB
->i2eFifoInInts
= 0;
213 pB
->i2eFifoOutInts
= 0;
214 pB
->i2eFatalTrap
= NULL
;
217 I2_COMPLETE(pB
, I2EE_GOOD
);
220 //******************************************************************************
221 // Function: iiResetDelay(pB)
222 // Parameters: pB - pointer to the board structure
224 // Returns: True if everything appears copacetic.
225 // False if there is any error: the pB->i2eError field has the error
229 // Using the delay defined in board structure, waits two seconds (for board to
232 //******************************************************************************
234 iiResetDelay(i2eBordStrPtr pB
)
236 if (pB
->i2eValid
!= I2E_MAGIC
) {
237 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
239 if (pB
->i2eState
!= II_STATE_RESET
) {
240 I2_COMPLETE(pB
, I2EE_BADSTATE
);
242 iiDelay(pB
,2000); /* Now we wait for two seconds. */
243 iiDelayed
= 1; /* Delay has been called: ok to initialize */
244 I2_COMPLETE(pB
, I2EE_GOOD
);
247 //******************************************************************************
248 // Function: iiInitialize(pB)
249 // Parameters: pB - pointer to the board structure
251 // Returns: True if everything appears copacetic.
252 // False if there is any error: the pB->i2eError field has the error
256 // Attempts to read the Power-on reset message. Initializes any remaining fields
257 // in the pB structure.
259 // This should be called as the third step of a process beginning with
260 // iiReset(), then iiResetDelay(). This routine checks to see that the structure
261 // is "valid" and in the reset state, also confirms that the delay routine has
262 // been called since the latest reset (to any board! overly strong!).
264 //******************************************************************************
266 iiInitialize(i2eBordStrPtr pB
)
270 unsigned short utemp
;
273 if (pB
->i2eValid
!= I2E_MAGIC
)
275 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
278 if (pB
->i2eState
!= II_STATE_RESET
|| !iiDelayed
)
280 I2_COMPLETE(pB
, I2EE_BADSTATE
);
283 // In case there is a failure short of our completely reading the power-up
285 pB
->i2eValid
= I2E_INCOMPLETE
;
288 // Now attempt to read the message.
290 for (itemp
= 0; itemp
< sizeof(porStr
); itemp
++)
292 // We expect the entire message is ready.
293 if (!I2_HAS_INPUT(pB
)) {
294 pB
->i2ePomSize
= itemp
;
295 I2_COMPLETE(pB
, I2EE_PORM_SHORT
);
298 pB
->i2ePom
.c
[itemp
] = c
= inb(pB
->i2eData
);
300 // We check the magic numbers as soon as they are supposed to be read
301 // (rather than after) to minimize effect of reading something we
302 // already suspect can't be "us".
303 if ( (itemp
== POR_1_INDEX
&& c
!= POR_MAGIC_1
) ||
304 (itemp
== POR_2_INDEX
&& c
!= POR_MAGIC_2
))
306 pB
->i2ePomSize
= itemp
+1;
307 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
311 pB
->i2ePomSize
= itemp
;
313 // Ensure that this was all the data...
314 if (I2_HAS_INPUT(pB
))
315 I2_COMPLETE(pB
, I2EE_PORM_LONG
);
317 // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
318 // Implying we will not be able to download any code either: That's ok: the
319 // condition is pretty explicit.
320 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_MAPPER
)
322 I2_COMPLETE(pB
, I2EE_POSTERR
);
325 // Determine anything which must be done differently depending on the family
327 switch (pB
->i2ePom
.e
.porID
& POR_ID_FAMILY
)
329 case POR_ID_FII
: // IntelliPort-II
331 pB
->i2eFifoStyle
= FIFO_II
;
332 pB
->i2eFifoSize
= 512; // 512 bytes, always
333 pB
->i2eDataWidth16
= false;
335 pB
->i2eMaxIrq
= 15; // Because board cannot tell us it is in an 8-bit
336 // slot, we do allow it to be done (documentation!)
341 pB
->i2eChannelMap
[1] =
342 pB
->i2eChannelMap
[2] =
343 pB
->i2eChannelMap
[3] = 0;
345 switch (pB
->i2ePom
.e
.porID
& POR_ID_SIZE
)
349 pB
->i2eChannelMap
[0] = 0x0f; // four-port
351 // Since porPorts1 is based on the Hardware ID register, the numbers
352 // should always be consistent for IntelliPort-II. Ditto below...
353 if (pB
->i2ePom
.e
.porPorts1
!= 4)
355 I2_COMPLETE(pB
, I2EE_INCONSIST
);
362 pB
->i2eChannelMap
[0] = 0xff; // Eight port
363 if (pB
->i2ePom
.e
.porPorts1
!= 8)
365 I2_COMPLETE(pB
, I2EE_INCONSIST
);
371 pB
->i2eChannelMap
[0] = 0x3f; // Six Port
372 if (pB
->i2ePom
.e
.porPorts1
!= 6)
374 I2_COMPLETE(pB
, I2EE_INCONSIST
);
379 // Fix up the "good channel list based on any errors reported.
380 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART1
)
382 pB
->i2eGoodMap
[0] &= ~0x0f;
385 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART2
)
387 pB
->i2eGoodMap
[0] &= ~0xf0;
390 break; // POR_ID_FII case
392 case POR_ID_FIIEX
: // IntelliPort-IIEX
394 pB
->i2eFifoStyle
= FIFO_IIEX
;
396 itemp
= pB
->i2ePom
.e
.porFifoSize
;
398 // Implicit assumption that fifo would not grow beyond 32k,
399 // nor would ever be less than 256.
401 if (itemp
< 8 || itemp
> 15)
403 I2_COMPLETE(pB
, I2EE_INCONSIST
);
405 pB
->i2eFifoSize
= (1 << itemp
);
407 // These are based on what P.O.S.T thinks should be there, based on
409 ilimit
= pB
->i2ePom
.e
.porNumBoxes
;
410 if (ilimit
> ABS_MAX_BOXES
)
412 ilimit
= ABS_MAX_BOXES
;
415 // For as many boxes as EXIST, gives the type of box.
416 // Added 8/6/93: check for the ISA-4 (asic) which looks like an
417 // expandable but for whom "8 or 16?" is not the right question.
419 utemp
= pB
->i2ePom
.e
.porFlags
;
420 if (utemp
& POR_CEX4
)
422 pB
->i2eChannelMap
[0] = 0x000f;
425 for (itemp
= 0; itemp
< ilimit
; itemp
++)
427 pB
->i2eChannelMap
[itemp
] =
428 ((utemp
& POR_BOX_16
) ? 0xffff : 0x00ff);
433 // These are based on what P.O.S.T actually found.
435 utemp
= (pB
->i2ePom
.e
.porPorts2
<< 8) + pB
->i2ePom
.e
.porPorts1
;
437 for (itemp
= 0; itemp
< ilimit
; itemp
++)
439 pB
->i2eGoodMap
[itemp
] = 0;
440 if (utemp
& 1) pB
->i2eGoodMap
[itemp
] |= 0x000f;
441 if (utemp
& 2) pB
->i2eGoodMap
[itemp
] |= 0x00f0;
442 if (utemp
& 4) pB
->i2eGoodMap
[itemp
] |= 0x0f00;
443 if (utemp
& 8) pB
->i2eGoodMap
[itemp
] |= 0xf000;
447 // Now determine whether we should transfer in 8 or 16-bit mode.
448 switch (pB
->i2ePom
.e
.porBus
& (POR_BUS_SLOT16
| POR_BUS_DIP16
) )
450 case POR_BUS_SLOT16
| POR_BUS_DIP16
:
451 pB
->i2eDataWidth16
= true;
456 pB
->i2eDataWidth16
= false;
461 case POR_BUS_DIP16
: // In an 8-bit slot, DIP switch don't care.
463 pB
->i2eDataWidth16
= false;
467 break; // POR_ID_FIIEX case
469 default: // Unknown type of board
470 I2_COMPLETE(pB
, I2EE_BAD_FAMILY
);
472 } // End the switch based on family
474 // Temporarily, claim there is no room in the outbound fifo.
475 // We will maintain this whenever we check for an empty outbound FIFO.
476 pB
->i2eFifoRemains
= 0;
478 // Now, based on the bus type, should we expect to be able to re-configure
479 // interrupts (say, for testing purposes).
480 switch (pB
->i2ePom
.e
.porBus
& POR_BUS_TYPE
)
483 case POR_BUS_T_UNK
: // If the type of bus is undeclared, assume ok.
488 I2_COMPLETE(pB
, I2EE_BADBUS
);
491 if (pB
->i2eDataWidth16
)
493 pB
->i2eWriteBuf
= iiWriteBuf16
;
494 pB
->i2eReadBuf
= iiReadBuf16
;
495 pB
->i2eWriteWord
= iiWriteWord16
;
496 pB
->i2eReadWord
= iiReadWord16
;
498 pB
->i2eWriteBuf
= iiWriteBuf8
;
499 pB
->i2eReadBuf
= iiReadBuf8
;
500 pB
->i2eWriteWord
= iiWriteWord8
;
501 pB
->i2eReadWord
= iiReadWord8
;
504 switch(pB
->i2eFifoStyle
)
507 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyII
;
508 pB
->i2eTxMailEmpty
= iiTxMailEmptyII
;
509 pB
->i2eTrySendMail
= iiTrySendMailII
;
510 pB
->i2eGetMail
= iiGetMailII
;
511 pB
->i2eEnableMailIrq
= iiEnableMailIrqII
;
512 pB
->i2eWriteMask
= iiWriteMaskII
;
517 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyIIEX
;
518 pB
->i2eTxMailEmpty
= iiTxMailEmptyIIEX
;
519 pB
->i2eTrySendMail
= iiTrySendMailIIEX
;
520 pB
->i2eGetMail
= iiGetMailIIEX
;
521 pB
->i2eEnableMailIrq
= iiEnableMailIrqIIEX
;
522 pB
->i2eWriteMask
= iiWriteMaskIIEX
;
527 I2_COMPLETE(pB
, I2EE_INCONSIST
);
530 // Initialize state information.
531 pB
->i2eState
= II_STATE_READY
; // Ready to load loadware.
533 // Some Final cleanup:
534 // For some boards, the bootstrap firmware may perform some sort of test
535 // resulting in a stray character pending in the incoming mailbox. If one is
536 // there, it should be read and discarded, especially since for the standard
537 // firmware, it's the mailbox that interrupts the host.
539 pB
->i2eStartMail
= iiGetMail(pB
);
541 // Throw it away and clear the mailbox structure element
542 pB
->i2eStartMail
= NO_MAIL_HERE
;
544 // Everything is ok now, return with good status/
546 pB
->i2eValid
= I2E_MAGIC
;
547 I2_COMPLETE(pB
, I2EE_GOOD
);
550 //******************************************************************************
551 // Function: ii2DelayTimer(mseconds)
552 // Parameters: mseconds - number of milliseconds to delay
558 // This routine delays for approximately mseconds milliseconds and is intended
559 // to be called indirectly through i2Delay field in i2eBordStr. It uses the
560 // Linux timer_list mechanism.
562 // The Linux timers use a unit called "jiffies" which are 10mS in the Intel
563 // architecture. This function rounds the delay period up to the next "jiffy".
564 // In the Alpha architecture the "jiffy" is 1mS, but this driver is not intended
565 // for Alpha platforms at this time.
567 //******************************************************************************
569 ii2DelayTimer(unsigned int mseconds
)
571 msleep_interruptible(mseconds
);
575 //static void ii2DelayIO(unsigned int);
576 //******************************************************************************
577 // !!! Not Used, this is DOS crap, some of you young folks may be interested in
578 // in how things were done in the stone age of caculating machines !!!
579 // Function: ii2DelayIO(mseconds)
580 // Parameters: mseconds - number of milliseconds to delay
586 // This routine delays for approximately mseconds milliseconds and is intended
587 // to be called indirectly through i2Delay field in i2eBordStr. It is intended
588 // for use where a clock-based function is impossible: for example, DOS drivers.
590 // This function uses the IN instruction to place bounds on the timing and
591 // assumes that ii2Safe has been set. This is because I/O instructions are not
592 // subject to caching and will therefore take a certain minimum time. To ensure
593 // the delay is at least long enough on fast machines, it is based on some
594 // fastest-case calculations. On slower machines this may cause VERY long
595 // delays. (3 x fastest case). In the fastest case, everything is cached except
596 // the I/O instruction itself.
598 // Timing calculations:
599 // The fastest bus speed for I/O operations is likely to be 10 MHz. The I/O
600 // operation in question is a byte operation to an odd address. For 8-bit
601 // operations, the architecture generally enforces two wait states. At 10 MHz, a
602 // single cycle time is 100nS. A read operation at two wait states takes 6
603 // cycles for a total time of 600nS. Therefore approximately 1666 iterations
604 // would be required to generate a single millisecond delay. The worst
605 // (reasonable) case would be an 8MHz system with no cacheing. In this case, the
606 // I/O instruction would take 125nS x 6 cyles = 750 nS. More importantly, code
607 // fetch of other instructions in the loop would take time (zero wait states,
608 // however) and would be hard to estimate. This is minimized by using in-line
609 // assembler for the in inner loop of IN instructions. This consists of just a
610 // few bytes. So we'll guess about four code fetches per loop. Each code fetch
611 // should take four cycles, so we have 125nS * 8 = 1000nS. Worst case then is
612 // that what should have taken 1 mS takes instead 1666 * (1750) = 2.9 mS.
614 // So much for theoretical timings: results using 1666 value on some actual
616 // IBM 286 6MHz 3.15 mS
617 // Zenith 386 33MHz 2.45 mS
618 // (brandX) 386 33MHz 1.90 mS (has cache)
619 // (brandY) 486 33MHz 2.35 mS
620 // NCR 486 ?? 1.65 mS (microchannel)
622 // For most machines, it is probably safe to scale this number back (remember,
623 // for robust operation use an actual timed delay if possible), so we are using
624 // a value of 1190. This yields 1.17 mS for the fastest machine in our sample,
625 // 1.75 mS for typical 386 machines, and 2.25 mS the absolute slowest machine.
628 // The above timings are too slow. Actual cycle times might be faster. ISA cycle
629 // times could approach 500 nS, and ...
630 // The IBM model 77 being microchannel has no wait states for 8-bit reads and
631 // seems to be accessing the I/O at 440 nS per access (from start of one to
632 // start of next). This would imply we need 1000/.440 = 2272 iterations to
633 // guarantee we are fast enough. In actual testing, we see that 2 * 1190 are in
634 // fact enough. For diagnostics, we keep the level at 1190, but developers note
635 // this needs tuning.
637 // Safe assumption: 2270 i/o reads = 1 millisecond
639 //******************************************************************************
642 static int ii2DelValue
= 1190; // See timing calculations below
643 // 1666 for fastest theoretical machine
644 // 1190 safe for most fast 386 machines
645 // 1000 for fastest machine tested here
646 // 540 (sic) for AT286/6Mhz
648 ii2DelayIO(unsigned int mseconds
)
651 return; /* Do nothing if this variable uninitialized */
662 //******************************************************************************
663 // Function: ii2Nop()
670 // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
671 // saves checking for a NULL pointer at every call.
672 //******************************************************************************
676 return; // no mystery here
679 //=======================================================
680 // Routines which are available in 8/16-bit versions, or
681 // in different fifo styles. These are ALL called
682 // indirectly through the board structure.
683 //=======================================================
685 //******************************************************************************
686 // Function: iiWriteBuf16(pB, address, count)
687 // Parameters: pB - pointer to board structure
688 // address - address of data to write
689 // count - number of data bytes to write
691 // Returns: True if everything appears copacetic.
692 // False if there is any error: the pB->i2eError field has the error
696 // Writes 'count' bytes from 'address' to the data fifo specified by the board
697 // structure pointer pB. Should count happen to be odd, an extra pad byte is
698 // sent (identity unknown...). Uses 16-bit (word) operations. Is called
699 // indirectly through pB->i2eWriteBuf.
701 //******************************************************************************
703 iiWriteBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
705 // Rudimentary sanity checking here.
706 if (pB
->i2eValid
!= I2E_MAGIC
)
707 I2_COMPLETE(pB
, I2EE_INVALID
);
709 I2_OUTSW(pB
->i2eData
, address
, count
);
711 I2_COMPLETE(pB
, I2EE_GOOD
);
714 //******************************************************************************
715 // Function: iiWriteBuf8(pB, address, count)
716 // Parameters: pB - pointer to board structure
717 // address - address of data to write
718 // count - number of data bytes to write
720 // Returns: True if everything appears copacetic.
721 // False if there is any error: the pB->i2eError field has the error
725 // Writes 'count' bytes from 'address' to the data fifo specified by the board
726 // structure pointer pB. Should count happen to be odd, an extra pad byte is
727 // sent (identity unknown...). This is to be consistent with the 16-bit version.
728 // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
730 //******************************************************************************
732 iiWriteBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
734 /* Rudimentary sanity checking here */
735 if (pB
->i2eValid
!= I2E_MAGIC
)
736 I2_COMPLETE(pB
, I2EE_INVALID
);
738 I2_OUTSB(pB
->i2eData
, address
, count
);
740 I2_COMPLETE(pB
, I2EE_GOOD
);
743 //******************************************************************************
744 // Function: iiReadBuf16(pB, address, count)
745 // Parameters: pB - pointer to board structure
746 // address - address to put data read
747 // count - number of data bytes to read
749 // Returns: True if everything appears copacetic.
750 // False if there is any error: the pB->i2eError field has the error
754 // Reads 'count' bytes into 'address' from the data fifo specified by the board
755 // structure pointer pB. Should count happen to be odd, an extra pad byte is
756 // received (identity unknown...). Uses 16-bit (word) operations. Is called
757 // indirectly through pB->i2eReadBuf.
759 //******************************************************************************
761 iiReadBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
763 // Rudimentary sanity checking here.
764 if (pB
->i2eValid
!= I2E_MAGIC
)
765 I2_COMPLETE(pB
, I2EE_INVALID
);
767 I2_INSW(pB
->i2eData
, address
, count
);
769 I2_COMPLETE(pB
, I2EE_GOOD
);
772 //******************************************************************************
773 // Function: iiReadBuf8(pB, address, count)
774 // Parameters: pB - pointer to board structure
775 // address - address to put data read
776 // count - number of data bytes to read
778 // Returns: True if everything appears copacetic.
779 // False if there is any error: the pB->i2eError field has the error
783 // Reads 'count' bytes into 'address' from the data fifo specified by the board
784 // structure pointer pB. Should count happen to be odd, an extra pad byte is
785 // received (identity unknown...). This to match the 16-bit behaviour. Uses
786 // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
788 //******************************************************************************
790 iiReadBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
792 // Rudimentary sanity checking here.
793 if (pB
->i2eValid
!= I2E_MAGIC
)
794 I2_COMPLETE(pB
, I2EE_INVALID
);
796 I2_INSB(pB
->i2eData
, address
, count
);
798 I2_COMPLETE(pB
, I2EE_GOOD
);
801 //******************************************************************************
802 // Function: iiReadWord16(pB)
803 // Parameters: pB - pointer to board structure
805 // Returns: True if everything appears copacetic.
806 // False if there is any error: the pB->i2eError field has the error
810 // Returns the word read from the data fifo specified by the board-structure
811 // pointer pB. Uses a 16-bit operation. Is called indirectly through
814 //******************************************************************************
815 static unsigned short
816 iiReadWord16(i2eBordStrPtr pB
)
818 return inw(pB
->i2eData
);
821 //******************************************************************************
822 // Function: iiReadWord8(pB)
823 // Parameters: pB - pointer to board structure
825 // Returns: True if everything appears copacetic.
826 // False if there is any error: the pB->i2eError field has the error
830 // Returns the word read from the data fifo specified by the board-structure
831 // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
832 // called indirectly through pB->i2eReadWord.
834 //******************************************************************************
835 static unsigned short
836 iiReadWord8(i2eBordStrPtr pB
)
840 urs
= inb(pB
->i2eData
);
842 return (inb(pB
->i2eData
) << 8) | urs
;
845 //******************************************************************************
846 // Function: iiWriteWord16(pB, value)
847 // Parameters: pB - pointer to board structure
848 // value - data to write
850 // Returns: True if everything appears copacetic.
851 // False if there is any error: the pB->i2eError field has the error
855 // Writes the word 'value' to the data fifo specified by the board-structure
856 // pointer pB. Uses 16-bit operation. Is called indirectly through
859 //******************************************************************************
861 iiWriteWord16(i2eBordStrPtr pB
, unsigned short value
)
863 outw((int)value
, pB
->i2eData
);
866 //******************************************************************************
867 // Function: iiWriteWord8(pB, value)
868 // Parameters: pB - pointer to board structure
869 // value - data to write
871 // Returns: True if everything appears copacetic.
872 // False if there is any error: the pB->i2eError field has the error
876 // Writes the word 'value' to the data fifo specified by the board-structure
877 // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
878 // indirectly through pB->i2eWriteWord.
880 //******************************************************************************
882 iiWriteWord8(i2eBordStrPtr pB
, unsigned short value
)
884 outb((char)value
, pB
->i2eData
);
885 outb((char)(value
>> 8), pB
->i2eData
);
888 //******************************************************************************
889 // Function: iiWaitForTxEmptyII(pB, mSdelay)
890 // Parameters: pB - pointer to board structure
891 // mSdelay - period to wait before returning
893 // Returns: True if the FIFO is empty.
894 // False if it not empty in the required time: the pB->i2eError
895 // field has the error.
899 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
900 // not empty by the required time, returns false and error in pB->i2eError,
901 // otherwise returns true.
903 // mSdelay == 0 is taken to mean must be empty on the first test.
905 // This version operates on IntelliPort-II - style FIFO's
907 // Note this routine is organized so that if status is ok there is no delay at
908 // all called either before or after the test. Is called indirectly through
909 // pB->i2eWaitForTxEmpty.
911 //******************************************************************************
913 iiWaitForTxEmptyII(i2eBordStrPtr pB
, int mSdelay
)
920 // This routine hinges on being able to see the "other" status register
921 // (as seen by the local processor). His incoming fifo is our outgoing
924 // By the nature of this routine, you would be using this as part of a
925 // larger atomic context: i.e., you would use this routine to ensure the
926 // fifo empty, then act on this information. Between these two halves,
927 // you will generally not want to service interrupts or in any way
928 // disrupt the assumptions implicit in the larger context.
930 // Even worse, however, this routine "shifts" the status register to
931 // point to the local status register which is not the usual situation.
932 // Therefore for extra safety, we force the critical section to be
933 // completely atomic, and pick up after ourselves before allowing any
934 // interrupts of any kind.
937 write_lock_irqsave(&Dl_spinlock
, flags
);
938 outb(SEL_COMMAND
, pB
->i2ePointer
);
939 outb(SEL_CMD_SH
, pB
->i2ePointer
);
941 itemp
= inb(pB
->i2eStatus
);
943 outb(SEL_COMMAND
, pB
->i2ePointer
);
944 outb(SEL_CMD_UNSH
, pB
->i2ePointer
);
946 if (itemp
& ST_IN_EMPTY
)
948 I2_UPDATE_FIFO_ROOM(pB
);
949 write_unlock_irqrestore(&Dl_spinlock
, flags
);
950 I2_COMPLETE(pB
, I2EE_GOOD
);
953 write_unlock_irqrestore(&Dl_spinlock
, flags
);
958 iiDelay(pB
, 1); /* 1 mS granularity on checking condition */
960 I2_COMPLETE(pB
, I2EE_TXE_TIME
);
963 //******************************************************************************
964 // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
965 // Parameters: pB - pointer to board structure
966 // mSdelay - period to wait before returning
968 // Returns: True if the FIFO is empty.
969 // False if it not empty in the required time: the pB->i2eError
970 // field has the error.
974 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
975 // not empty by the required time, returns false and error in pB->i2eError,
976 // otherwise returns true.
978 // mSdelay == 0 is taken to mean must be empty on the first test.
980 // This version operates on IntelliPort-IIEX - style FIFO's
982 // Note this routine is organized so that if status is ok there is no delay at
983 // all called either before or after the test. Is called indirectly through
984 // pB->i2eWaitForTxEmpty.
986 //******************************************************************************
988 iiWaitForTxEmptyIIEX(i2eBordStrPtr pB
, int mSdelay
)
994 // By the nature of this routine, you would be using this as part of a
995 // larger atomic context: i.e., you would use this routine to ensure the
996 // fifo empty, then act on this information. Between these two halves,
997 // you will generally not want to service interrupts or in any way
998 // disrupt the assumptions implicit in the larger context.
1000 write_lock_irqsave(&Dl_spinlock
, flags
);
1002 if (inb(pB
->i2eStatus
) & STE_OUT_MT
) {
1003 I2_UPDATE_FIFO_ROOM(pB
);
1004 write_unlock_irqrestore(&Dl_spinlock
, flags
);
1005 I2_COMPLETE(pB
, I2EE_GOOD
);
1007 write_unlock_irqrestore(&Dl_spinlock
, flags
);
1012 iiDelay(pB
, 1); // 1 mS granularity on checking condition
1014 I2_COMPLETE(pB
, I2EE_TXE_TIME
);
1017 //******************************************************************************
1018 // Function: iiTxMailEmptyII(pB)
1019 // Parameters: pB - pointer to board structure
1021 // Returns: True if the transmit mailbox is empty.
1022 // False if it not empty.
1026 // Returns true or false according to whether the transmit mailbox is empty (and
1027 // therefore able to accept more mail)
1029 // This version operates on IntelliPort-II - style FIFO's
1031 //******************************************************************************
1033 iiTxMailEmptyII(i2eBordStrPtr pB
)
1035 int port
= pB
->i2ePointer
;
1036 outb(SEL_OUTMAIL
, port
);
1037 return inb(port
) == 0;
1040 //******************************************************************************
1041 // Function: iiTxMailEmptyIIEX(pB)
1042 // Parameters: pB - pointer to board structure
1044 // Returns: True if the transmit mailbox is empty.
1045 // False if it not empty.
1049 // Returns true or false according to whether the transmit mailbox is empty (and
1050 // therefore able to accept more mail)
1052 // This version operates on IntelliPort-IIEX - style FIFO's
1054 //******************************************************************************
1056 iiTxMailEmptyIIEX(i2eBordStrPtr pB
)
1058 return !(inb(pB
->i2eStatus
) & STE_OUT_MAIL
);
1061 //******************************************************************************
1062 // Function: iiTrySendMailII(pB,mail)
1063 // Parameters: pB - pointer to board structure
1064 // mail - value to write to mailbox
1066 // Returns: True if the transmit mailbox is empty, and mail is sent.
1067 // False if it not empty.
1071 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1072 // mailbox is not empty, returns false.
1074 // This version operates on IntelliPort-II - style FIFO's
1076 //******************************************************************************
1078 iiTrySendMailII(i2eBordStrPtr pB
, unsigned char mail
)
1080 int port
= pB
->i2ePointer
;
1082 outb(SEL_OUTMAIL
, port
);
1083 if (inb(port
) == 0) {
1084 outb(SEL_OUTMAIL
, port
);
1091 //******************************************************************************
1092 // Function: iiTrySendMailIIEX(pB,mail)
1093 // Parameters: pB - pointer to board structure
1094 // mail - value to write to mailbox
1096 // Returns: True if the transmit mailbox is empty, and mail is sent.
1097 // False if it not empty.
1101 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1102 // mailbox is not empty, returns false.
1104 // This version operates on IntelliPort-IIEX - style FIFO's
1106 //******************************************************************************
1108 iiTrySendMailIIEX(i2eBordStrPtr pB
, unsigned char mail
)
1110 if (inb(pB
->i2eStatus
) & STE_OUT_MAIL
)
1112 outb(mail
, pB
->i2eXMail
);
1116 //******************************************************************************
1117 // Function: iiGetMailII(pB,mail)
1118 // Parameters: pB - pointer to board structure
1120 // Returns: Mailbox data or NO_MAIL_HERE.
1124 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1125 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1127 // This version operates on IntelliPort-II - style FIFO's
1129 //******************************************************************************
1130 static unsigned short
1131 iiGetMailII(i2eBordStrPtr pB
)
1133 if (I2_HAS_MAIL(pB
)) {
1134 outb(SEL_INMAIL
, pB
->i2ePointer
);
1135 return inb(pB
->i2ePointer
);
1137 return NO_MAIL_HERE
;
1141 //******************************************************************************
1142 // Function: iiGetMailIIEX(pB,mail)
1143 // Parameters: pB - pointer to board structure
1145 // Returns: Mailbox data or NO_MAIL_HERE.
1149 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1150 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1152 // This version operates on IntelliPort-IIEX - style FIFO's
1154 //******************************************************************************
1155 static unsigned short
1156 iiGetMailIIEX(i2eBordStrPtr pB
)
1158 if (I2_HAS_MAIL(pB
))
1159 return inb(pB
->i2eXMail
);
1161 return NO_MAIL_HERE
;
1164 //******************************************************************************
1165 // Function: iiEnableMailIrqII(pB)
1166 // Parameters: pB - pointer to board structure
1172 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1174 // This version operates on IntelliPort-II - style FIFO's
1176 //******************************************************************************
1178 iiEnableMailIrqII(i2eBordStrPtr pB
)
1180 outb(SEL_MASK
, pB
->i2ePointer
);
1181 outb(ST_IN_MAIL
, pB
->i2ePointer
);
1184 //******************************************************************************
1185 // Function: iiEnableMailIrqIIEX(pB)
1186 // Parameters: pB - pointer to board structure
1192 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1194 // This version operates on IntelliPort-IIEX - style FIFO's
1196 //******************************************************************************
1198 iiEnableMailIrqIIEX(i2eBordStrPtr pB
)
1200 outb(MX_IN_MAIL
, pB
->i2eXMask
);
1203 //******************************************************************************
1204 // Function: iiWriteMaskII(pB)
1205 // Parameters: pB - pointer to board structure
1211 // Writes arbitrary value to the mask register.
1213 // This version operates on IntelliPort-II - style FIFO's
1215 //******************************************************************************
1217 iiWriteMaskII(i2eBordStrPtr pB
, unsigned char value
)
1219 outb(SEL_MASK
, pB
->i2ePointer
);
1220 outb(value
, pB
->i2ePointer
);
1223 //******************************************************************************
1224 // Function: iiWriteMaskIIEX(pB)
1225 // Parameters: pB - pointer to board structure
1231 // Writes arbitrary value to the mask register.
1233 // This version operates on IntelliPort-IIEX - style FIFO's
1235 //******************************************************************************
1237 iiWriteMaskIIEX(i2eBordStrPtr pB
, unsigned char value
)
1239 outb(value
, pB
->i2eXMask
);
1242 //******************************************************************************
1243 // Function: iiDownloadBlock(pB, pSource, isStandard)
1244 // Parameters: pB - pointer to board structure
1245 // pSource - loadware block to download
1246 // isStandard - True if "standard" loadware, else false.
1248 // Returns: Success or Failure
1252 // Downloads a single block (at pSource)to the board referenced by pB. Caller
1253 // sets isStandard to true/false according to whether the "standard" loadware is
1254 // what's being loaded. The normal process, then, is to perform an iiInitialize
1255 // to the board, then perform some number of iiDownloadBlocks using the returned
1256 // state to determine when download is complete.
1258 // Possible return values: (see I2ELLIS.H)
1261 // II_DOWN_CONTINUING
1267 // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
1268 // determine whether this is the first block, whether to check for magic
1269 // numbers, how many blocks there are to go...
1271 //******************************************************************************
1273 iiDownloadBlock ( i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
)
1278 if (pB
->i2eValid
!= I2E_MAGIC
) return II_DOWN_BADVALID
;
1280 switch(pB
->i2eState
)
1282 case II_STATE_READY
:
1284 // Loading the first block after reset. Must check the magic number of the
1285 // loadfile, store the number of blocks we expect to load.
1286 if (pSource
->e
.loadMagic
!= MAGIC_LOADFILE
)
1288 return II_DOWN_BADFILE
;
1291 // Next we store the total number of blocks to load, including this one.
1292 pB
->i2eToLoad
= 1 + pSource
->e
.loadBlocksMore
;
1294 // Set the state, store the version numbers. ('Cause this may have come
1295 // from a file - we might want to report these versions and revisions in
1296 // case of an error!
1297 pB
->i2eState
= II_STATE_LOADING
;
1298 pB
->i2eLVersion
= pSource
->e
.loadVersion
;
1299 pB
->i2eLRevision
= pSource
->e
.loadRevision
;
1300 pB
->i2eLSub
= pSource
->e
.loadSubRevision
;
1302 // The time and date of compilation is also available but don't bother
1303 // storing it for normal purposes.
1307 case II_STATE_LOADING
:
1312 return II_DOWN_BADSTATE
;
1315 // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
1316 // must be positive still, because otherwise we would have cleaned up last
1317 // time and set the state to II_STATE_LOADED.
1318 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1319 return II_DOWN_TIMEOUT
;
1322 if (!iiWriteBuf(pB
, pSource
->c
, LOADWARE_BLOCK_SIZE
)) {
1323 return II_DOWN_BADVALID
;
1326 // If we just loaded the first block, wait for the fifo to empty an extra
1327 // long time to allow for any special startup code in the firmware, like
1328 // sending status messages to the LCD's.
1331 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_START_TIME
)) {
1332 return II_DOWN_TIMEOUT
;
1336 // Determine whether this was our last block!
1337 if (--(pB
->i2eToLoad
)) {
1338 return II_DOWN_CONTINUING
; // more to come...
1341 // It WAS our last block: Clean up operations...
1342 // ...Wait for last buffer to drain from the board...
1343 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1344 return II_DOWN_TIMEOUT
;
1346 // If there were only a single block written, this would come back
1347 // immediately and be harmless, though not strictly necessary.
1348 itemp
= MAX_DLOAD_ACK_TIME
/10;
1350 if (I2_HAS_INPUT(pB
)) {
1351 switch (inb(pB
->i2eData
)) {
1354 isStandard
? II_STATE_STDLOADED
:II_STATE_LOADED
;
1356 // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
1357 // will, // if there is a debug port attached, require some
1358 // time to send information to the debug port now. It will do
1359 // this before // executing any of the code we just downloaded.
1360 // It may take up to 700 milliseconds.
1361 if (pB
->i2ePom
.e
.porDiag2
& POR_DEBUG_PORT
) {
1365 return II_DOWN_GOOD
;
1373 iiDelay(pB
, 10); // 10 mS granularity on checking condition
1376 // Drop-through --> timed out waiting for firmware confirmation
1378 pB
->i2eState
= II_STATE_BADLOAD
;
1379 return II_DOWN_TIMEOUT
;
1382 //******************************************************************************
1383 // Function: iiDownloadAll(pB, pSource, isStandard, size)
1384 // Parameters: pB - pointer to board structure
1385 // pSource - loadware block to download
1386 // isStandard - True if "standard" loadware, else false.
1387 // size - size of data to download (in bytes)
1389 // Returns: Success or Failure
1393 // Given a pointer to a board structure, a pointer to the beginning of some
1394 // loadware, whether it is considered the "standard loadware", and the size of
1395 // the array in bytes loads the entire array to the board as loadware.
1397 // Assumes the board has been freshly reset and the power-up reset message read.
1398 // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
1399 // too much or too little data to load, or if iiDownloadBlock complains.
1400 //******************************************************************************
1402 iiDownloadAll(i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
, int size
)
1406 // We know (from context) board should be ready for the first block of
1407 // download. Complain if not.
1408 if (pB
->i2eState
!= II_STATE_READY
) return II_DOWN_BADSTATE
;
1411 size
-= LOADWARE_BLOCK_SIZE
; // How much data should there be left to
1412 // load after the following operation ?
1414 // Note we just bump pSource by "one", because its size is actually that
1415 // of an entire block, same as LOADWARE_BLOCK_SIZE.
1416 status
= iiDownloadBlock(pB
, pSource
++, isStandard
);
1421 return ( (size
> 0) ? II_DOWN_OVER
: II_DOWN_GOOD
);
1423 case II_DOWN_CONTINUING
:
1431 // We shouldn't drop out: it means "while" caught us with nothing left to
1432 // download, yet the previous DownloadBlock did not return complete. Ergo,
1433 // not enough data to match the size byte in the header.
1434 return II_DOWN_UNDER
;