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: iiSetAddress(pB, address, delay)
73 // Parameters: pB - pointer to the board structure
74 // address - the purported I/O address of the board
75 // delay - pointer to the 1-ms delay function to use
76 // in this and any future operations to this board
78 // Returns: True if everything appears copacetic.
79 // False if there is any error: the pB->i2eError field has the error
83 // This routine (roughly) checks for address validity, sets the i2eValid OK and
84 // sets the state to II_STATE_COLD which means that we haven't even sent a reset
87 //******************************************************************************
89 iiSetAddress( i2eBordStrPtr pB
, int address
, delayFunc_t delay
)
91 // Should any failure occur before init is finished...
92 pB
->i2eValid
= I2E_INCOMPLETE
;
94 // Cannot check upper limit except extremely: Might be microchannel
95 // Address must be on an 8-byte boundary
97 if ((unsigned int)address
<= 0x100
98 || (unsigned int)address
>= 0xfff8
102 I2_COMPLETE(pB
, I2EE_BADADDR
);
105 // Initialize accelerators
106 pB
->i2eBase
= address
;
107 pB
->i2eData
= address
+ FIFO_DATA
;
108 pB
->i2eStatus
= address
+ FIFO_STATUS
;
109 pB
->i2ePointer
= address
+ FIFO_PTR
;
110 pB
->i2eXMail
= address
+ FIFO_MAIL
;
111 pB
->i2eXMask
= address
+ FIFO_MASK
;
113 // Initialize i/o address for ii2DelayIO
114 ii2Safe
= address
+ FIFO_NOP
;
116 // Initialize the delay routine
117 pB
->i2eDelay
= ((delay
!= (delayFunc_t
)NULL
) ? delay
: (delayFunc_t
)ii2Nop
);
119 pB
->i2eValid
= I2E_MAGIC
;
120 pB
->i2eState
= II_STATE_COLD
;
122 I2_COMPLETE(pB
, I2EE_GOOD
);
125 //******************************************************************************
126 // Function: iiReset(pB)
127 // Parameters: pB - pointer to the board structure
129 // Returns: True if everything appears copacetic.
130 // False if there is any error: the pB->i2eError field has the error
134 // Attempts to reset the board (see also i2hw.h). Normally, we would use this to
135 // reset a board immediately after iiSetAddress(), but it is valid to reset a
136 // board from any state, say, in order to change or re-load loadware. (Under
137 // such circumstances, no reason to re-run iiSetAddress(), which is why it is a
138 // separate routine and not included in this routine.
140 //******************************************************************************
142 iiReset(i2eBordStrPtr pB
)
144 // Magic number should be set, else even the address is suspect
145 if (pB
->i2eValid
!= I2E_MAGIC
)
147 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
150 outb(0, pB
->i2eBase
+ FIFO_RESET
); /* Any data will do */
151 iiDelay(pB
, 50); // Pause between resets
152 outb(0, pB
->i2eBase
+ FIFO_RESET
); /* Second reset */
154 // We must wait before even attempting to read anything from the FIFO: the
155 // board's P.O.S.T may actually attempt to read and write its end of the
156 // FIFO in order to check flags, loop back (where supported), etc. On
157 // completion of this testing it would reset the FIFO, and on completion
158 // of all // P.O.S.T., write the message. We must not mistake data which
159 // might have been sent for testing as part of the reset message. To
160 // better utilize time, say, when resetting several boards, we allow the
161 // delay to be performed externally; in this way the caller can reset
162 // several boards, delay a single time, then call the initialization
165 pB
->i2eState
= II_STATE_RESET
;
167 iiDelayed
= 0; // i.e., the delay routine hasn't been called since the most
170 // Ensure anything which would have been of use to standard loadware is
171 // blanked out, since board has now forgotten everything!.
173 pB
->i2eUsingIrq
= I2_IRQ_UNDEFINED
; /* to not use an interrupt so far */
174 pB
->i2eWaitingForEmptyFifo
= 0;
175 pB
->i2eOutMailWaiting
= 0;
176 pB
->i2eChannelPtr
= NULL
;
177 pB
->i2eChannelCnt
= 0;
179 pB
->i2eLeadoffWord
[0] = 0;
180 pB
->i2eFifoInInts
= 0;
181 pB
->i2eFifoOutInts
= 0;
182 pB
->i2eFatalTrap
= NULL
;
185 I2_COMPLETE(pB
, I2EE_GOOD
);
188 //******************************************************************************
189 // Function: iiResetDelay(pB)
190 // Parameters: pB - pointer to the board structure
192 // Returns: True if everything appears copacetic.
193 // False if there is any error: the pB->i2eError field has the error
197 // Using the delay defined in board structure, waits two seconds (for board to
200 //******************************************************************************
202 iiResetDelay(i2eBordStrPtr pB
)
204 if (pB
->i2eValid
!= I2E_MAGIC
) {
205 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
207 if (pB
->i2eState
!= II_STATE_RESET
) {
208 I2_COMPLETE(pB
, I2EE_BADSTATE
);
210 iiDelay(pB
,2000); /* Now we wait for two seconds. */
211 iiDelayed
= 1; /* Delay has been called: ok to initialize */
212 I2_COMPLETE(pB
, I2EE_GOOD
);
215 //******************************************************************************
216 // Function: iiInitialize(pB)
217 // Parameters: pB - pointer to the board structure
219 // Returns: True if everything appears copacetic.
220 // False if there is any error: the pB->i2eError field has the error
224 // Attempts to read the Power-on reset message. Initializes any remaining fields
225 // in the pB structure.
227 // This should be called as the third step of a process beginning with
228 // iiReset(), then iiResetDelay(). This routine checks to see that the structure
229 // is "valid" and in the reset state, also confirms that the delay routine has
230 // been called since the latest reset (to any board! overly strong!).
232 //******************************************************************************
234 iiInitialize(i2eBordStrPtr pB
)
238 unsigned short utemp
;
241 if (pB
->i2eValid
!= I2E_MAGIC
)
243 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
246 if (pB
->i2eState
!= II_STATE_RESET
|| !iiDelayed
)
248 I2_COMPLETE(pB
, I2EE_BADSTATE
);
251 // In case there is a failure short of our completely reading the power-up
253 pB
->i2eValid
= I2E_INCOMPLETE
;
256 // Now attempt to read the message.
258 for (itemp
= 0; itemp
< sizeof(porStr
); itemp
++)
260 // We expect the entire message is ready.
261 if (!I2_HAS_INPUT(pB
)) {
262 pB
->i2ePomSize
= itemp
;
263 I2_COMPLETE(pB
, I2EE_PORM_SHORT
);
266 pB
->i2ePom
.c
[itemp
] = c
= inb(pB
->i2eData
);
268 // We check the magic numbers as soon as they are supposed to be read
269 // (rather than after) to minimize effect of reading something we
270 // already suspect can't be "us".
271 if ( (itemp
== POR_1_INDEX
&& c
!= POR_MAGIC_1
) ||
272 (itemp
== POR_2_INDEX
&& c
!= POR_MAGIC_2
))
274 pB
->i2ePomSize
= itemp
+1;
275 I2_COMPLETE(pB
, I2EE_BADMAGIC
);
279 pB
->i2ePomSize
= itemp
;
281 // Ensure that this was all the data...
282 if (I2_HAS_INPUT(pB
))
283 I2_COMPLETE(pB
, I2EE_PORM_LONG
);
285 // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
286 // Implying we will not be able to download any code either: That's ok: the
287 // condition is pretty explicit.
288 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_MAPPER
)
290 I2_COMPLETE(pB
, I2EE_POSTERR
);
293 // Determine anything which must be done differently depending on the family
295 switch (pB
->i2ePom
.e
.porID
& POR_ID_FAMILY
)
297 case POR_ID_FII
: // IntelliPort-II
299 pB
->i2eFifoStyle
= FIFO_II
;
300 pB
->i2eFifoSize
= 512; // 512 bytes, always
301 pB
->i2eDataWidth16
= false;
303 pB
->i2eMaxIrq
= 15; // Because board cannot tell us it is in an 8-bit
304 // slot, we do allow it to be done (documentation!)
309 pB
->i2eChannelMap
[1] =
310 pB
->i2eChannelMap
[2] =
311 pB
->i2eChannelMap
[3] = 0;
313 switch (pB
->i2ePom
.e
.porID
& POR_ID_SIZE
)
317 pB
->i2eChannelMap
[0] = 0x0f; // four-port
319 // Since porPorts1 is based on the Hardware ID register, the numbers
320 // should always be consistent for IntelliPort-II. Ditto below...
321 if (pB
->i2ePom
.e
.porPorts1
!= 4)
323 I2_COMPLETE(pB
, I2EE_INCONSIST
);
330 pB
->i2eChannelMap
[0] = 0xff; // Eight port
331 if (pB
->i2ePom
.e
.porPorts1
!= 8)
333 I2_COMPLETE(pB
, I2EE_INCONSIST
);
339 pB
->i2eChannelMap
[0] = 0x3f; // Six Port
340 if (pB
->i2ePom
.e
.porPorts1
!= 6)
342 I2_COMPLETE(pB
, I2EE_INCONSIST
);
347 // Fix up the "good channel list based on any errors reported.
348 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART1
)
350 pB
->i2eGoodMap
[0] &= ~0x0f;
353 if (pB
->i2ePom
.e
.porDiag1
& POR_BAD_UART2
)
355 pB
->i2eGoodMap
[0] &= ~0xf0;
358 break; // POR_ID_FII case
360 case POR_ID_FIIEX
: // IntelliPort-IIEX
362 pB
->i2eFifoStyle
= FIFO_IIEX
;
364 itemp
= pB
->i2ePom
.e
.porFifoSize
;
366 // Implicit assumption that fifo would not grow beyond 32k,
367 // nor would ever be less than 256.
369 if (itemp
< 8 || itemp
> 15)
371 I2_COMPLETE(pB
, I2EE_INCONSIST
);
373 pB
->i2eFifoSize
= (1 << itemp
);
375 // These are based on what P.O.S.T thinks should be there, based on
377 ilimit
= pB
->i2ePom
.e
.porNumBoxes
;
378 if (ilimit
> ABS_MAX_BOXES
)
380 ilimit
= ABS_MAX_BOXES
;
383 // For as many boxes as EXIST, gives the type of box.
384 // Added 8/6/93: check for the ISA-4 (asic) which looks like an
385 // expandable but for whom "8 or 16?" is not the right question.
387 utemp
= pB
->i2ePom
.e
.porFlags
;
388 if (utemp
& POR_CEX4
)
390 pB
->i2eChannelMap
[0] = 0x000f;
393 for (itemp
= 0; itemp
< ilimit
; itemp
++)
395 pB
->i2eChannelMap
[itemp
] =
396 ((utemp
& POR_BOX_16
) ? 0xffff : 0x00ff);
401 // These are based on what P.O.S.T actually found.
403 utemp
= (pB
->i2ePom
.e
.porPorts2
<< 8) + pB
->i2ePom
.e
.porPorts1
;
405 for (itemp
= 0; itemp
< ilimit
; itemp
++)
407 pB
->i2eGoodMap
[itemp
] = 0;
408 if (utemp
& 1) pB
->i2eGoodMap
[itemp
] |= 0x000f;
409 if (utemp
& 2) pB
->i2eGoodMap
[itemp
] |= 0x00f0;
410 if (utemp
& 4) pB
->i2eGoodMap
[itemp
] |= 0x0f00;
411 if (utemp
& 8) pB
->i2eGoodMap
[itemp
] |= 0xf000;
415 // Now determine whether we should transfer in 8 or 16-bit mode.
416 switch (pB
->i2ePom
.e
.porBus
& (POR_BUS_SLOT16
| POR_BUS_DIP16
) )
418 case POR_BUS_SLOT16
| POR_BUS_DIP16
:
419 pB
->i2eDataWidth16
= true;
424 pB
->i2eDataWidth16
= false;
429 case POR_BUS_DIP16
: // In an 8-bit slot, DIP switch don't care.
431 pB
->i2eDataWidth16
= false;
435 break; // POR_ID_FIIEX case
437 default: // Unknown type of board
438 I2_COMPLETE(pB
, I2EE_BAD_FAMILY
);
440 } // End the switch based on family
442 // Temporarily, claim there is no room in the outbound fifo.
443 // We will maintain this whenever we check for an empty outbound FIFO.
444 pB
->i2eFifoRemains
= 0;
446 // Now, based on the bus type, should we expect to be able to re-configure
447 // interrupts (say, for testing purposes).
448 switch (pB
->i2ePom
.e
.porBus
& POR_BUS_TYPE
)
451 case POR_BUS_T_UNK
: // If the type of bus is undeclared, assume ok.
456 I2_COMPLETE(pB
, I2EE_BADBUS
);
459 if (pB
->i2eDataWidth16
)
461 pB
->i2eWriteBuf
= iiWriteBuf16
;
462 pB
->i2eReadBuf
= iiReadBuf16
;
463 pB
->i2eWriteWord
= iiWriteWord16
;
464 pB
->i2eReadWord
= iiReadWord16
;
466 pB
->i2eWriteBuf
= iiWriteBuf8
;
467 pB
->i2eReadBuf
= iiReadBuf8
;
468 pB
->i2eWriteWord
= iiWriteWord8
;
469 pB
->i2eReadWord
= iiReadWord8
;
472 switch(pB
->i2eFifoStyle
)
475 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyII
;
476 pB
->i2eTxMailEmpty
= iiTxMailEmptyII
;
477 pB
->i2eTrySendMail
= iiTrySendMailII
;
478 pB
->i2eGetMail
= iiGetMailII
;
479 pB
->i2eEnableMailIrq
= iiEnableMailIrqII
;
480 pB
->i2eWriteMask
= iiWriteMaskII
;
485 pB
->i2eWaitForTxEmpty
= iiWaitForTxEmptyIIEX
;
486 pB
->i2eTxMailEmpty
= iiTxMailEmptyIIEX
;
487 pB
->i2eTrySendMail
= iiTrySendMailIIEX
;
488 pB
->i2eGetMail
= iiGetMailIIEX
;
489 pB
->i2eEnableMailIrq
= iiEnableMailIrqIIEX
;
490 pB
->i2eWriteMask
= iiWriteMaskIIEX
;
495 I2_COMPLETE(pB
, I2EE_INCONSIST
);
498 // Initialize state information.
499 pB
->i2eState
= II_STATE_READY
; // Ready to load loadware.
501 // Some Final cleanup:
502 // For some boards, the bootstrap firmware may perform some sort of test
503 // resulting in a stray character pending in the incoming mailbox. If one is
504 // there, it should be read and discarded, especially since for the standard
505 // firmware, it's the mailbox that interrupts the host.
507 pB
->i2eStartMail
= iiGetMail(pB
);
509 // Throw it away and clear the mailbox structure element
510 pB
->i2eStartMail
= NO_MAIL_HERE
;
512 // Everything is ok now, return with good status/
514 pB
->i2eValid
= I2E_MAGIC
;
515 I2_COMPLETE(pB
, I2EE_GOOD
);
518 //******************************************************************************
519 // Function: ii2DelayTimer(mseconds)
520 // Parameters: mseconds - number of milliseconds to delay
526 // This routine delays for approximately mseconds milliseconds and is intended
527 // to be called indirectly through i2Delay field in i2eBordStr. It uses the
528 // Linux timer_list mechanism.
530 // The Linux timers use a unit called "jiffies" which are 10mS in the Intel
531 // architecture. This function rounds the delay period up to the next "jiffy".
532 // In the Alpha architecture the "jiffy" is 1mS, but this driver is not intended
533 // for Alpha platforms at this time.
535 //******************************************************************************
537 ii2DelayTimer(unsigned int mseconds
)
539 msleep_interruptible(mseconds
);
543 //static void ii2DelayIO(unsigned int);
544 //******************************************************************************
545 // !!! Not Used, this is DOS crap, some of you young folks may be interested in
546 // in how things were done in the stone age of caculating machines !!!
547 // Function: ii2DelayIO(mseconds)
548 // Parameters: mseconds - number of milliseconds to delay
554 // This routine delays for approximately mseconds milliseconds and is intended
555 // to be called indirectly through i2Delay field in i2eBordStr. It is intended
556 // for use where a clock-based function is impossible: for example, DOS drivers.
558 // This function uses the IN instruction to place bounds on the timing and
559 // assumes that ii2Safe has been set. This is because I/O instructions are not
560 // subject to caching and will therefore take a certain minimum time. To ensure
561 // the delay is at least long enough on fast machines, it is based on some
562 // fastest-case calculations. On slower machines this may cause VERY long
563 // delays. (3 x fastest case). In the fastest case, everything is cached except
564 // the I/O instruction itself.
566 // Timing calculations:
567 // The fastest bus speed for I/O operations is likely to be 10 MHz. The I/O
568 // operation in question is a byte operation to an odd address. For 8-bit
569 // operations, the architecture generally enforces two wait states. At 10 MHz, a
570 // single cycle time is 100nS. A read operation at two wait states takes 6
571 // cycles for a total time of 600nS. Therefore approximately 1666 iterations
572 // would be required to generate a single millisecond delay. The worst
573 // (reasonable) case would be an 8MHz system with no cacheing. In this case, the
574 // I/O instruction would take 125nS x 6 cyles = 750 nS. More importantly, code
575 // fetch of other instructions in the loop would take time (zero wait states,
576 // however) and would be hard to estimate. This is minimized by using in-line
577 // assembler for the in inner loop of IN instructions. This consists of just a
578 // few bytes. So we'll guess about four code fetches per loop. Each code fetch
579 // should take four cycles, so we have 125nS * 8 = 1000nS. Worst case then is
580 // that what should have taken 1 mS takes instead 1666 * (1750) = 2.9 mS.
582 // So much for theoretical timings: results using 1666 value on some actual
584 // IBM 286 6MHz 3.15 mS
585 // Zenith 386 33MHz 2.45 mS
586 // (brandX) 386 33MHz 1.90 mS (has cache)
587 // (brandY) 486 33MHz 2.35 mS
588 // NCR 486 ?? 1.65 mS (microchannel)
590 // For most machines, it is probably safe to scale this number back (remember,
591 // for robust operation use an actual timed delay if possible), so we are using
592 // a value of 1190. This yields 1.17 mS for the fastest machine in our sample,
593 // 1.75 mS for typical 386 machines, and 2.25 mS the absolute slowest machine.
596 // The above timings are too slow. Actual cycle times might be faster. ISA cycle
597 // times could approach 500 nS, and ...
598 // The IBM model 77 being microchannel has no wait states for 8-bit reads and
599 // seems to be accessing the I/O at 440 nS per access (from start of one to
600 // start of next). This would imply we need 1000/.440 = 2272 iterations to
601 // guarantee we are fast enough. In actual testing, we see that 2 * 1190 are in
602 // fact enough. For diagnostics, we keep the level at 1190, but developers note
603 // this needs tuning.
605 // Safe assumption: 2270 i/o reads = 1 millisecond
607 //******************************************************************************
610 static int ii2DelValue
= 1190; // See timing calculations below
611 // 1666 for fastest theoretical machine
612 // 1190 safe for most fast 386 machines
613 // 1000 for fastest machine tested here
614 // 540 (sic) for AT286/6Mhz
616 ii2DelayIO(unsigned int mseconds
)
619 return; /* Do nothing if this variable uninitialized */
630 //******************************************************************************
631 // Function: ii2Nop()
638 // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
639 // saves checking for a NULL pointer at every call.
640 //******************************************************************************
644 return; // no mystery here
647 //=======================================================
648 // Routines which are available in 8/16-bit versions, or
649 // in different fifo styles. These are ALL called
650 // indirectly through the board structure.
651 //=======================================================
653 //******************************************************************************
654 // Function: iiWriteBuf16(pB, address, count)
655 // Parameters: pB - pointer to board structure
656 // address - address of data to write
657 // count - number of data bytes to write
659 // Returns: True if everything appears copacetic.
660 // False if there is any error: the pB->i2eError field has the error
664 // Writes 'count' bytes from 'address' to the data fifo specified by the board
665 // structure pointer pB. Should count happen to be odd, an extra pad byte is
666 // sent (identity unknown...). Uses 16-bit (word) operations. Is called
667 // indirectly through pB->i2eWriteBuf.
669 //******************************************************************************
671 iiWriteBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
673 // Rudimentary sanity checking here.
674 if (pB
->i2eValid
!= I2E_MAGIC
)
675 I2_COMPLETE(pB
, I2EE_INVALID
);
677 I2_OUTSW(pB
->i2eData
, address
, count
);
679 I2_COMPLETE(pB
, I2EE_GOOD
);
682 //******************************************************************************
683 // Function: iiWriteBuf8(pB, address, count)
684 // Parameters: pB - pointer to board structure
685 // address - address of data to write
686 // count - number of data bytes to write
688 // Returns: True if everything appears copacetic.
689 // False if there is any error: the pB->i2eError field has the error
693 // Writes 'count' bytes from 'address' to the data fifo specified by the board
694 // structure pointer pB. Should count happen to be odd, an extra pad byte is
695 // sent (identity unknown...). This is to be consistent with the 16-bit version.
696 // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
698 //******************************************************************************
700 iiWriteBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
702 /* Rudimentary sanity checking here */
703 if (pB
->i2eValid
!= I2E_MAGIC
)
704 I2_COMPLETE(pB
, I2EE_INVALID
);
706 I2_OUTSB(pB
->i2eData
, address
, count
);
708 I2_COMPLETE(pB
, I2EE_GOOD
);
711 //******************************************************************************
712 // Function: iiReadBuf16(pB, address, count)
713 // Parameters: pB - pointer to board structure
714 // address - address to put data read
715 // count - number of data bytes to read
717 // Returns: True if everything appears copacetic.
718 // False if there is any error: the pB->i2eError field has the error
722 // Reads 'count' bytes into 'address' from the data fifo specified by the board
723 // structure pointer pB. Should count happen to be odd, an extra pad byte is
724 // received (identity unknown...). Uses 16-bit (word) operations. Is called
725 // indirectly through pB->i2eReadBuf.
727 //******************************************************************************
729 iiReadBuf16(i2eBordStrPtr pB
, unsigned char *address
, int count
)
731 // Rudimentary sanity checking here.
732 if (pB
->i2eValid
!= I2E_MAGIC
)
733 I2_COMPLETE(pB
, I2EE_INVALID
);
735 I2_INSW(pB
->i2eData
, address
, count
);
737 I2_COMPLETE(pB
, I2EE_GOOD
);
740 //******************************************************************************
741 // Function: iiReadBuf8(pB, address, count)
742 // Parameters: pB - pointer to board structure
743 // address - address to put data read
744 // count - number of data bytes to read
746 // Returns: True if everything appears copacetic.
747 // False if there is any error: the pB->i2eError field has the error
751 // Reads 'count' bytes into 'address' from the data fifo specified by the board
752 // structure pointer pB. Should count happen to be odd, an extra pad byte is
753 // received (identity unknown...). This to match the 16-bit behaviour. Uses
754 // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
756 //******************************************************************************
758 iiReadBuf8(i2eBordStrPtr pB
, unsigned char *address
, int count
)
760 // Rudimentary sanity checking here.
761 if (pB
->i2eValid
!= I2E_MAGIC
)
762 I2_COMPLETE(pB
, I2EE_INVALID
);
764 I2_INSB(pB
->i2eData
, address
, count
);
766 I2_COMPLETE(pB
, I2EE_GOOD
);
769 //******************************************************************************
770 // Function: iiReadWord16(pB)
771 // Parameters: pB - pointer to board structure
773 // Returns: True if everything appears copacetic.
774 // False if there is any error: the pB->i2eError field has the error
778 // Returns the word read from the data fifo specified by the board-structure
779 // pointer pB. Uses a 16-bit operation. Is called indirectly through
782 //******************************************************************************
783 static unsigned short
784 iiReadWord16(i2eBordStrPtr pB
)
786 return inw(pB
->i2eData
);
789 //******************************************************************************
790 // Function: iiReadWord8(pB)
791 // Parameters: pB - pointer to board structure
793 // Returns: True if everything appears copacetic.
794 // False if there is any error: the pB->i2eError field has the error
798 // Returns the word read from the data fifo specified by the board-structure
799 // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
800 // called indirectly through pB->i2eReadWord.
802 //******************************************************************************
803 static unsigned short
804 iiReadWord8(i2eBordStrPtr pB
)
808 urs
= inb(pB
->i2eData
);
810 return (inb(pB
->i2eData
) << 8) | urs
;
813 //******************************************************************************
814 // Function: iiWriteWord16(pB, value)
815 // Parameters: pB - pointer to board structure
816 // value - data to write
818 // Returns: True if everything appears copacetic.
819 // False if there is any error: the pB->i2eError field has the error
823 // Writes the word 'value' to the data fifo specified by the board-structure
824 // pointer pB. Uses 16-bit operation. Is called indirectly through
827 //******************************************************************************
829 iiWriteWord16(i2eBordStrPtr pB
, unsigned short value
)
831 outw((int)value
, pB
->i2eData
);
834 //******************************************************************************
835 // Function: iiWriteWord8(pB, value)
836 // Parameters: pB - pointer to board structure
837 // value - data to write
839 // Returns: True if everything appears copacetic.
840 // False if there is any error: the pB->i2eError field has the error
844 // Writes the word 'value' to the data fifo specified by the board-structure
845 // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
846 // indirectly through pB->i2eWriteWord.
848 //******************************************************************************
850 iiWriteWord8(i2eBordStrPtr pB
, unsigned short value
)
852 outb((char)value
, pB
->i2eData
);
853 outb((char)(value
>> 8), pB
->i2eData
);
856 //******************************************************************************
857 // Function: iiWaitForTxEmptyII(pB, mSdelay)
858 // Parameters: pB - pointer to board structure
859 // mSdelay - period to wait before returning
861 // Returns: True if the FIFO is empty.
862 // False if it not empty in the required time: the pB->i2eError
863 // field has the error.
867 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
868 // not empty by the required time, returns false and error in pB->i2eError,
869 // otherwise returns true.
871 // mSdelay == 0 is taken to mean must be empty on the first test.
873 // This version operates on IntelliPort-II - style FIFO's
875 // Note this routine is organized so that if status is ok there is no delay at
876 // all called either before or after the test. Is called indirectly through
877 // pB->i2eWaitForTxEmpty.
879 //******************************************************************************
881 iiWaitForTxEmptyII(i2eBordStrPtr pB
, int mSdelay
)
888 // This routine hinges on being able to see the "other" status register
889 // (as seen by the local processor). His incoming fifo is our outgoing
892 // By the nature of this routine, you would be using this as part of a
893 // larger atomic context: i.e., you would use this routine to ensure the
894 // fifo empty, then act on this information. Between these two halves,
895 // you will generally not want to service interrupts or in any way
896 // disrupt the assumptions implicit in the larger context.
898 // Even worse, however, this routine "shifts" the status register to
899 // point to the local status register which is not the usual situation.
900 // Therefore for extra safety, we force the critical section to be
901 // completely atomic, and pick up after ourselves before allowing any
902 // interrupts of any kind.
905 write_lock_irqsave(&Dl_spinlock
, flags
);
906 outb(SEL_COMMAND
, pB
->i2ePointer
);
907 outb(SEL_CMD_SH
, pB
->i2ePointer
);
909 itemp
= inb(pB
->i2eStatus
);
911 outb(SEL_COMMAND
, pB
->i2ePointer
);
912 outb(SEL_CMD_UNSH
, pB
->i2ePointer
);
914 if (itemp
& ST_IN_EMPTY
)
916 I2_UPDATE_FIFO_ROOM(pB
);
917 write_unlock_irqrestore(&Dl_spinlock
, flags
);
918 I2_COMPLETE(pB
, I2EE_GOOD
);
921 write_unlock_irqrestore(&Dl_spinlock
, flags
);
926 iiDelay(pB
, 1); /* 1 mS granularity on checking condition */
928 I2_COMPLETE(pB
, I2EE_TXE_TIME
);
931 //******************************************************************************
932 // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
933 // Parameters: pB - pointer to board structure
934 // mSdelay - period to wait before returning
936 // Returns: True if the FIFO is empty.
937 // False if it not empty in the required time: the pB->i2eError
938 // field has the error.
942 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
943 // not empty by the required time, returns false and error in pB->i2eError,
944 // otherwise returns true.
946 // mSdelay == 0 is taken to mean must be empty on the first test.
948 // This version operates on IntelliPort-IIEX - style FIFO's
950 // Note this routine is organized so that if status is ok there is no delay at
951 // all called either before or after the test. Is called indirectly through
952 // pB->i2eWaitForTxEmpty.
954 //******************************************************************************
956 iiWaitForTxEmptyIIEX(i2eBordStrPtr pB
, int mSdelay
)
962 // By the nature of this routine, you would be using this as part of a
963 // larger atomic context: i.e., you would use this routine to ensure the
964 // fifo empty, then act on this information. Between these two halves,
965 // you will generally not want to service interrupts or in any way
966 // disrupt the assumptions implicit in the larger context.
968 write_lock_irqsave(&Dl_spinlock
, flags
);
970 if (inb(pB
->i2eStatus
) & STE_OUT_MT
) {
971 I2_UPDATE_FIFO_ROOM(pB
);
972 write_unlock_irqrestore(&Dl_spinlock
, flags
);
973 I2_COMPLETE(pB
, I2EE_GOOD
);
975 write_unlock_irqrestore(&Dl_spinlock
, flags
);
980 iiDelay(pB
, 1); // 1 mS granularity on checking condition
982 I2_COMPLETE(pB
, I2EE_TXE_TIME
);
985 //******************************************************************************
986 // Function: iiTxMailEmptyII(pB)
987 // Parameters: pB - pointer to board structure
989 // Returns: True if the transmit mailbox is empty.
990 // False if it not empty.
994 // Returns true or false according to whether the transmit mailbox is empty (and
995 // therefore able to accept more mail)
997 // This version operates on IntelliPort-II - style FIFO's
999 //******************************************************************************
1001 iiTxMailEmptyII(i2eBordStrPtr pB
)
1003 int port
= pB
->i2ePointer
;
1004 outb(SEL_OUTMAIL
, port
);
1005 return inb(port
) == 0;
1008 //******************************************************************************
1009 // Function: iiTxMailEmptyIIEX(pB)
1010 // Parameters: pB - pointer to board structure
1012 // Returns: True if the transmit mailbox is empty.
1013 // False if it not empty.
1017 // Returns true or false according to whether the transmit mailbox is empty (and
1018 // therefore able to accept more mail)
1020 // This version operates on IntelliPort-IIEX - style FIFO's
1022 //******************************************************************************
1024 iiTxMailEmptyIIEX(i2eBordStrPtr pB
)
1026 return !(inb(pB
->i2eStatus
) & STE_OUT_MAIL
);
1029 //******************************************************************************
1030 // Function: iiTrySendMailII(pB,mail)
1031 // Parameters: pB - pointer to board structure
1032 // mail - value to write to mailbox
1034 // Returns: True if the transmit mailbox is empty, and mail is sent.
1035 // False if it not empty.
1039 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1040 // mailbox is not empty, returns false.
1042 // This version operates on IntelliPort-II - style FIFO's
1044 //******************************************************************************
1046 iiTrySendMailII(i2eBordStrPtr pB
, unsigned char mail
)
1048 int port
= pB
->i2ePointer
;
1050 outb(SEL_OUTMAIL
, port
);
1051 if (inb(port
) == 0) {
1052 outb(SEL_OUTMAIL
, port
);
1059 //******************************************************************************
1060 // Function: iiTrySendMailIIEX(pB,mail)
1061 // Parameters: pB - pointer to board structure
1062 // mail - value to write to mailbox
1064 // Returns: True if the transmit mailbox is empty, and mail is sent.
1065 // False if it not empty.
1069 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
1070 // mailbox is not empty, returns false.
1072 // This version operates on IntelliPort-IIEX - style FIFO's
1074 //******************************************************************************
1076 iiTrySendMailIIEX(i2eBordStrPtr pB
, unsigned char mail
)
1078 if (inb(pB
->i2eStatus
) & STE_OUT_MAIL
)
1080 outb(mail
, pB
->i2eXMail
);
1084 //******************************************************************************
1085 // Function: iiGetMailII(pB,mail)
1086 // Parameters: pB - pointer to board structure
1088 // Returns: Mailbox data or NO_MAIL_HERE.
1092 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1093 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1095 // This version operates on IntelliPort-II - style FIFO's
1097 //******************************************************************************
1098 static unsigned short
1099 iiGetMailII(i2eBordStrPtr pB
)
1101 if (I2_HAS_MAIL(pB
)) {
1102 outb(SEL_INMAIL
, pB
->i2ePointer
);
1103 return inb(pB
->i2ePointer
);
1105 return NO_MAIL_HERE
;
1109 //******************************************************************************
1110 // Function: iiGetMailIIEX(pB,mail)
1111 // Parameters: pB - pointer to board structure
1113 // Returns: Mailbox data or NO_MAIL_HERE.
1117 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1118 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1120 // This version operates on IntelliPort-IIEX - style FIFO's
1122 //******************************************************************************
1123 static unsigned short
1124 iiGetMailIIEX(i2eBordStrPtr pB
)
1126 if (I2_HAS_MAIL(pB
))
1127 return inb(pB
->i2eXMail
);
1129 return NO_MAIL_HERE
;
1132 //******************************************************************************
1133 // Function: iiEnableMailIrqII(pB)
1134 // Parameters: pB - pointer to board structure
1140 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1142 // This version operates on IntelliPort-II - style FIFO's
1144 //******************************************************************************
1146 iiEnableMailIrqII(i2eBordStrPtr pB
)
1148 outb(SEL_MASK
, pB
->i2ePointer
);
1149 outb(ST_IN_MAIL
, pB
->i2ePointer
);
1152 //******************************************************************************
1153 // Function: iiEnableMailIrqIIEX(pB)
1154 // Parameters: pB - pointer to board structure
1160 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1162 // This version operates on IntelliPort-IIEX - style FIFO's
1164 //******************************************************************************
1166 iiEnableMailIrqIIEX(i2eBordStrPtr pB
)
1168 outb(MX_IN_MAIL
, pB
->i2eXMask
);
1171 //******************************************************************************
1172 // Function: iiWriteMaskII(pB)
1173 // Parameters: pB - pointer to board structure
1179 // Writes arbitrary value to the mask register.
1181 // This version operates on IntelliPort-II - style FIFO's
1183 //******************************************************************************
1185 iiWriteMaskII(i2eBordStrPtr pB
, unsigned char value
)
1187 outb(SEL_MASK
, pB
->i2ePointer
);
1188 outb(value
, pB
->i2ePointer
);
1191 //******************************************************************************
1192 // Function: iiWriteMaskIIEX(pB)
1193 // Parameters: pB - pointer to board structure
1199 // Writes arbitrary value to the mask register.
1201 // This version operates on IntelliPort-IIEX - style FIFO's
1203 //******************************************************************************
1205 iiWriteMaskIIEX(i2eBordStrPtr pB
, unsigned char value
)
1207 outb(value
, pB
->i2eXMask
);
1210 //******************************************************************************
1211 // Function: iiDownloadBlock(pB, pSource, isStandard)
1212 // Parameters: pB - pointer to board structure
1213 // pSource - loadware block to download
1214 // isStandard - True if "standard" loadware, else false.
1216 // Returns: Success or Failure
1220 // Downloads a single block (at pSource)to the board referenced by pB. Caller
1221 // sets isStandard to true/false according to whether the "standard" loadware is
1222 // what's being loaded. The normal process, then, is to perform an iiInitialize
1223 // to the board, then perform some number of iiDownloadBlocks using the returned
1224 // state to determine when download is complete.
1226 // Possible return values: (see I2ELLIS.H)
1229 // II_DOWN_CONTINUING
1235 // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
1236 // determine whether this is the first block, whether to check for magic
1237 // numbers, how many blocks there are to go...
1239 //******************************************************************************
1241 iiDownloadBlock ( i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
)
1246 if (pB
->i2eValid
!= I2E_MAGIC
) return II_DOWN_BADVALID
;
1248 switch(pB
->i2eState
)
1250 case II_STATE_READY
:
1252 // Loading the first block after reset. Must check the magic number of the
1253 // loadfile, store the number of blocks we expect to load.
1254 if (pSource
->e
.loadMagic
!= MAGIC_LOADFILE
)
1256 return II_DOWN_BADFILE
;
1259 // Next we store the total number of blocks to load, including this one.
1260 pB
->i2eToLoad
= 1 + pSource
->e
.loadBlocksMore
;
1262 // Set the state, store the version numbers. ('Cause this may have come
1263 // from a file - we might want to report these versions and revisions in
1264 // case of an error!
1265 pB
->i2eState
= II_STATE_LOADING
;
1266 pB
->i2eLVersion
= pSource
->e
.loadVersion
;
1267 pB
->i2eLRevision
= pSource
->e
.loadRevision
;
1268 pB
->i2eLSub
= pSource
->e
.loadSubRevision
;
1270 // The time and date of compilation is also available but don't bother
1271 // storing it for normal purposes.
1275 case II_STATE_LOADING
:
1280 return II_DOWN_BADSTATE
;
1283 // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
1284 // must be positive still, because otherwise we would have cleaned up last
1285 // time and set the state to II_STATE_LOADED.
1286 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1287 return II_DOWN_TIMEOUT
;
1290 if (!iiWriteBuf(pB
, pSource
->c
, LOADWARE_BLOCK_SIZE
)) {
1291 return II_DOWN_BADVALID
;
1294 // If we just loaded the first block, wait for the fifo to empty an extra
1295 // long time to allow for any special startup code in the firmware, like
1296 // sending status messages to the LCD's.
1299 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_START_TIME
)) {
1300 return II_DOWN_TIMEOUT
;
1304 // Determine whether this was our last block!
1305 if (--(pB
->i2eToLoad
)) {
1306 return II_DOWN_CONTINUING
; // more to come...
1309 // It WAS our last block: Clean up operations...
1310 // ...Wait for last buffer to drain from the board...
1311 if (!iiWaitForTxEmpty(pB
, MAX_DLOAD_READ_TIME
)) {
1312 return II_DOWN_TIMEOUT
;
1314 // If there were only a single block written, this would come back
1315 // immediately and be harmless, though not strictly necessary.
1316 itemp
= MAX_DLOAD_ACK_TIME
/10;
1318 if (I2_HAS_INPUT(pB
)) {
1319 switch (inb(pB
->i2eData
)) {
1322 isStandard
? II_STATE_STDLOADED
:II_STATE_LOADED
;
1324 // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
1325 // will, // if there is a debug port attached, require some
1326 // time to send information to the debug port now. It will do
1327 // this before // executing any of the code we just downloaded.
1328 // It may take up to 700 milliseconds.
1329 if (pB
->i2ePom
.e
.porDiag2
& POR_DEBUG_PORT
) {
1333 return II_DOWN_GOOD
;
1341 iiDelay(pB
, 10); // 10 mS granularity on checking condition
1344 // Drop-through --> timed out waiting for firmware confirmation
1346 pB
->i2eState
= II_STATE_BADLOAD
;
1347 return II_DOWN_TIMEOUT
;
1350 //******************************************************************************
1351 // Function: iiDownloadAll(pB, pSource, isStandard, size)
1352 // Parameters: pB - pointer to board structure
1353 // pSource - loadware block to download
1354 // isStandard - True if "standard" loadware, else false.
1355 // size - size of data to download (in bytes)
1357 // Returns: Success or Failure
1361 // Given a pointer to a board structure, a pointer to the beginning of some
1362 // loadware, whether it is considered the "standard loadware", and the size of
1363 // the array in bytes loads the entire array to the board as loadware.
1365 // Assumes the board has been freshly reset and the power-up reset message read.
1366 // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
1367 // too much or too little data to load, or if iiDownloadBlock complains.
1368 //******************************************************************************
1370 iiDownloadAll(i2eBordStrPtr pB
, loadHdrStrPtr pSource
, int isStandard
, int size
)
1374 // We know (from context) board should be ready for the first block of
1375 // download. Complain if not.
1376 if (pB
->i2eState
!= II_STATE_READY
) return II_DOWN_BADSTATE
;
1379 size
-= LOADWARE_BLOCK_SIZE
; // How much data should there be left to
1380 // load after the following operation ?
1382 // Note we just bump pSource by "one", because its size is actually that
1383 // of an entire block, same as LOADWARE_BLOCK_SIZE.
1384 status
= iiDownloadBlock(pB
, pSource
++, isStandard
);
1389 return ( (size
> 0) ? II_DOWN_OVER
: II_DOWN_GOOD
);
1391 case II_DOWN_CONTINUING
:
1399 // We shouldn't drop out: it means "while" caught us with nothing left to
1400 // download, yet the previous DownloadBlock did not return complete. Ergo,
1401 // not enough data to match the size byte in the header.
1402 return II_DOWN_UNDER
;