GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / char / ip2 / i2ellis.c
blob6d91e40e2a58af19b5f1ce0c4142702c2a0d2645
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
13 * module.)
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);
48 //***************
49 //* Static Data *
50 //***************
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);
58 //********
59 //* Code *
60 //********
62 //=======================================================
63 // Initialization Routines
65 // iiSetAddress
66 // iiReset
67 // iiResetDelay
68 // iiInitialize
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
81 // Description:
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
85 // yet.
87 //******************************************************************************
88 static int
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
99 || (address & 0x7)
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
132 // Description:
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 //******************************************************************************
141 static int
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
163 // routine for all.
165 pB->i2eState = II_STATE_RESET;
167 iiDelayed = 0; // i.e., the delay routine hasn't been called since the most
168 // recent reset.
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;
183 pB->i2eFatal = 0;
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
195 // Description:
197 // Using the delay defined in board structure, waits two seconds (for board to
198 // reset).
200 //******************************************************************************
201 static int
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
222 // Description:
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 //******************************************************************************
233 static int
234 iiInitialize(i2eBordStrPtr pB)
236 int itemp;
237 unsigned char c;
238 unsigned short utemp;
239 unsigned int ilimit;
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
252 // message.
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
294 // of boards!
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!)
306 pB->i2eGoodMap[1] =
307 pB->i2eGoodMap[2] =
308 pB->i2eGoodMap[3] =
309 pB->i2eChannelMap[1] =
310 pB->i2eChannelMap[2] =
311 pB->i2eChannelMap[3] = 0;
313 switch (pB->i2ePom.e.porID & POR_ID_SIZE)
315 case POR_ID_II_4:
316 pB->i2eGoodMap[0] =
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);
325 break;
327 case POR_ID_II_8:
328 case POR_ID_II_8R:
329 pB->i2eGoodMap[0] =
330 pB->i2eChannelMap[0] = 0xff; // Eight port
331 if (pB->i2ePom.e.porPorts1 != 8)
333 I2_COMPLETE(pB, I2EE_INCONSIST);
335 break;
337 case POR_ID_II_6:
338 pB->i2eGoodMap[0] =
339 pB->i2eChannelMap[0] = 0x3f; // Six Port
340 if (pB->i2ePom.e.porPorts1 != 6)
342 I2_COMPLETE(pB, I2EE_INCONSIST);
344 break;
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
376 // box ID registers
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;
391 } else {
392 utemp &= POR_BOXES;
393 for (itemp = 0; itemp < ilimit; itemp++)
395 pB->i2eChannelMap[itemp] =
396 ((utemp & POR_BOX_16) ? 0xffff : 0x00ff);
397 utemp >>= 1;
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;
412 utemp >>= 4;
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;
420 pB->i2eMaxIrq = 15;
421 break;
423 case POR_BUS_SLOT16:
424 pB->i2eDataWidth16 = false;
425 pB->i2eMaxIrq = 15;
426 break;
428 case 0:
429 case POR_BUS_DIP16: // In an 8-bit slot, DIP switch don't care.
430 default:
431 pB->i2eDataWidth16 = false;
432 pB->i2eMaxIrq = 7;
433 break;
435 break; // POR_ID_FIIEX case
437 default: // Unknown type of board
438 I2_COMPLETE(pB, I2EE_BAD_FAMILY);
439 break;
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)
450 case POR_BUS_T_ISA:
451 case POR_BUS_T_UNK: // If the type of bus is undeclared, assume ok.
452 case POR_BUS_T_MCA:
453 case POR_BUS_T_EISA:
454 break;
455 default:
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;
465 } else {
466 pB->i2eWriteBuf = iiWriteBuf8;
467 pB->i2eReadBuf = iiReadBuf8;
468 pB->i2eWriteWord = iiWriteWord8;
469 pB->i2eReadWord = iiReadWord8;
472 switch(pB->i2eFifoStyle)
474 case FIFO_II:
475 pB->i2eWaitForTxEmpty = iiWaitForTxEmptyII;
476 pB->i2eTxMailEmpty = iiTxMailEmptyII;
477 pB->i2eTrySendMail = iiTrySendMailII;
478 pB->i2eGetMail = iiGetMailII;
479 pB->i2eEnableMailIrq = iiEnableMailIrqII;
480 pB->i2eWriteMask = iiWriteMaskII;
482 break;
484 case FIFO_IIEX:
485 pB->i2eWaitForTxEmpty = iiWaitForTxEmptyIIEX;
486 pB->i2eTxMailEmpty = iiTxMailEmptyIIEX;
487 pB->i2eTrySendMail = iiTrySendMailIIEX;
488 pB->i2eGetMail = iiGetMailIIEX;
489 pB->i2eEnableMailIrq = iiEnableMailIrqIIEX;
490 pB->i2eWriteMask = iiWriteMaskIIEX;
492 break;
494 default:
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
522 // Returns: Nothing
524 // Description:
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 //******************************************************************************
536 static void
537 ii2DelayTimer(unsigned int mseconds)
539 msleep_interruptible(mseconds);
543 //******************************************************************************
544 // Function: ii2Nop()
545 // Parameters: None
547 // Returns: Nothing
549 // Description:
551 // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
552 // saves checking for a NULL pointer at every call.
553 //******************************************************************************
554 static void
555 ii2Nop(void)
557 return; // no mystery here
560 //=======================================================
561 // Routines which are available in 8/16-bit versions, or
562 // in different fifo styles. These are ALL called
563 // indirectly through the board structure.
564 //=======================================================
566 //******************************************************************************
567 // Function: iiWriteBuf16(pB, address, count)
568 // Parameters: pB - pointer to board structure
569 // address - address of data to write
570 // count - number of data bytes to write
572 // Returns: True if everything appears copacetic.
573 // False if there is any error: the pB->i2eError field has the error
575 // Description:
577 // Writes 'count' bytes from 'address' to the data fifo specified by the board
578 // structure pointer pB. Should count happen to be odd, an extra pad byte is
579 // sent (identity unknown...). Uses 16-bit (word) operations. Is called
580 // indirectly through pB->i2eWriteBuf.
582 //******************************************************************************
583 static int
584 iiWriteBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
586 // Rudimentary sanity checking here.
587 if (pB->i2eValid != I2E_MAGIC)
588 I2_COMPLETE(pB, I2EE_INVALID);
590 I2_OUTSW(pB->i2eData, address, count);
592 I2_COMPLETE(pB, I2EE_GOOD);
595 //******************************************************************************
596 // Function: iiWriteBuf8(pB, address, count)
597 // Parameters: pB - pointer to board structure
598 // address - address of data to write
599 // count - number of data bytes to write
601 // Returns: True if everything appears copacetic.
602 // False if there is any error: the pB->i2eError field has the error
604 // Description:
606 // Writes 'count' bytes from 'address' to the data fifo specified by the board
607 // structure pointer pB. Should count happen to be odd, an extra pad byte is
608 // sent (identity unknown...). This is to be consistent with the 16-bit version.
609 // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
611 //******************************************************************************
612 static int
613 iiWriteBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
615 /* Rudimentary sanity checking here */
616 if (pB->i2eValid != I2E_MAGIC)
617 I2_COMPLETE(pB, I2EE_INVALID);
619 I2_OUTSB(pB->i2eData, address, count);
621 I2_COMPLETE(pB, I2EE_GOOD);
624 //******************************************************************************
625 // Function: iiReadBuf16(pB, address, count)
626 // Parameters: pB - pointer to board structure
627 // address - address to put data read
628 // count - number of data bytes to read
630 // Returns: True if everything appears copacetic.
631 // False if there is any error: the pB->i2eError field has the error
633 // Description:
635 // Reads 'count' bytes into 'address' from the data fifo specified by the board
636 // structure pointer pB. Should count happen to be odd, an extra pad byte is
637 // received (identity unknown...). Uses 16-bit (word) operations. Is called
638 // indirectly through pB->i2eReadBuf.
640 //******************************************************************************
641 static int
642 iiReadBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
644 // Rudimentary sanity checking here.
645 if (pB->i2eValid != I2E_MAGIC)
646 I2_COMPLETE(pB, I2EE_INVALID);
648 I2_INSW(pB->i2eData, address, count);
650 I2_COMPLETE(pB, I2EE_GOOD);
653 //******************************************************************************
654 // Function: iiReadBuf8(pB, address, count)
655 // Parameters: pB - pointer to board structure
656 // address - address to put data read
657 // count - number of data bytes to read
659 // Returns: True if everything appears copacetic.
660 // False if there is any error: the pB->i2eError field has the error
662 // Description:
664 // Reads 'count' bytes into 'address' from the data fifo specified by the board
665 // structure pointer pB. Should count happen to be odd, an extra pad byte is
666 // received (identity unknown...). This to match the 16-bit behaviour. Uses
667 // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
669 //******************************************************************************
670 static int
671 iiReadBuf8(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_INSB(pB->i2eData, address, count);
679 I2_COMPLETE(pB, I2EE_GOOD);
682 //******************************************************************************
683 // Function: iiReadWord16(pB)
684 // Parameters: pB - pointer to board structure
686 // Returns: True if everything appears copacetic.
687 // False if there is any error: the pB->i2eError field has the error
689 // Description:
691 // Returns the word read from the data fifo specified by the board-structure
692 // pointer pB. Uses a 16-bit operation. Is called indirectly through
693 // pB->i2eReadWord.
695 //******************************************************************************
696 static unsigned short
697 iiReadWord16(i2eBordStrPtr pB)
699 return inw(pB->i2eData);
702 //******************************************************************************
703 // Function: iiReadWord8(pB)
704 // Parameters: pB - pointer to board structure
706 // Returns: True if everything appears copacetic.
707 // False if there is any error: the pB->i2eError field has the error
709 // Description:
711 // Returns the word read from the data fifo specified by the board-structure
712 // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
713 // called indirectly through pB->i2eReadWord.
715 //******************************************************************************
716 static unsigned short
717 iiReadWord8(i2eBordStrPtr pB)
719 unsigned short urs;
721 urs = inb(pB->i2eData);
723 return (inb(pB->i2eData) << 8) | urs;
726 //******************************************************************************
727 // Function: iiWriteWord16(pB, value)
728 // Parameters: pB - pointer to board structure
729 // value - data to write
731 // Returns: True if everything appears copacetic.
732 // False if there is any error: the pB->i2eError field has the error
734 // Description:
736 // Writes the word 'value' to the data fifo specified by the board-structure
737 // pointer pB. Uses 16-bit operation. Is called indirectly through
738 // pB->i2eWriteWord.
740 //******************************************************************************
741 static void
742 iiWriteWord16(i2eBordStrPtr pB, unsigned short value)
744 outw((int)value, pB->i2eData);
747 //******************************************************************************
748 // Function: iiWriteWord8(pB, value)
749 // Parameters: pB - pointer to board structure
750 // value - data to write
752 // Returns: True if everything appears copacetic.
753 // False if there is any error: the pB->i2eError field has the error
755 // Description:
757 // Writes the word 'value' to the data fifo specified by the board-structure
758 // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
759 // indirectly through pB->i2eWriteWord.
761 //******************************************************************************
762 static void
763 iiWriteWord8(i2eBordStrPtr pB, unsigned short value)
765 outb((char)value, pB->i2eData);
766 outb((char)(value >> 8), pB->i2eData);
769 //******************************************************************************
770 // Function: iiWaitForTxEmptyII(pB, mSdelay)
771 // Parameters: pB - pointer to board structure
772 // mSdelay - period to wait before returning
774 // Returns: True if the FIFO is empty.
775 // False if it not empty in the required time: the pB->i2eError
776 // field has the error.
778 // Description:
780 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
781 // not empty by the required time, returns false and error in pB->i2eError,
782 // otherwise returns true.
784 // mSdelay == 0 is taken to mean must be empty on the first test.
786 // This version operates on IntelliPort-II - style FIFO's
788 // Note this routine is organized so that if status is ok there is no delay at
789 // all called either before or after the test. Is called indirectly through
790 // pB->i2eWaitForTxEmpty.
792 //******************************************************************************
793 static int
794 iiWaitForTxEmptyII(i2eBordStrPtr pB, int mSdelay)
796 unsigned long flags;
797 int itemp;
799 for (;;)
801 // This routine hinges on being able to see the "other" status register
802 // (as seen by the local processor). His incoming fifo is our outgoing
803 // FIFO.
805 // By the nature of this routine, you would be using this as part of a
806 // larger atomic context: i.e., you would use this routine to ensure the
807 // fifo empty, then act on this information. Between these two halves,
808 // you will generally not want to service interrupts or in any way
809 // disrupt the assumptions implicit in the larger context.
811 // Even worse, however, this routine "shifts" the status register to
812 // point to the local status register which is not the usual situation.
813 // Therefore for extra safety, we force the critical section to be
814 // completely atomic, and pick up after ourselves before allowing any
815 // interrupts of any kind.
818 write_lock_irqsave(&Dl_spinlock, flags);
819 outb(SEL_COMMAND, pB->i2ePointer);
820 outb(SEL_CMD_SH, pB->i2ePointer);
822 itemp = inb(pB->i2eStatus);
824 outb(SEL_COMMAND, pB->i2ePointer);
825 outb(SEL_CMD_UNSH, pB->i2ePointer);
827 if (itemp & ST_IN_EMPTY)
829 I2_UPDATE_FIFO_ROOM(pB);
830 write_unlock_irqrestore(&Dl_spinlock, flags);
831 I2_COMPLETE(pB, I2EE_GOOD);
834 write_unlock_irqrestore(&Dl_spinlock, flags);
836 if (mSdelay-- == 0)
837 break;
839 iiDelay(pB, 1); /* 1 mS granularity on checking condition */
841 I2_COMPLETE(pB, I2EE_TXE_TIME);
844 //******************************************************************************
845 // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
846 // Parameters: pB - pointer to board structure
847 // mSdelay - period to wait before returning
849 // Returns: True if the FIFO is empty.
850 // False if it not empty in the required time: the pB->i2eError
851 // field has the error.
853 // Description:
855 // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
856 // not empty by the required time, returns false and error in pB->i2eError,
857 // otherwise returns true.
859 // mSdelay == 0 is taken to mean must be empty on the first test.
861 // This version operates on IntelliPort-IIEX - style FIFO's
863 // Note this routine is organized so that if status is ok there is no delay at
864 // all called either before or after the test. Is called indirectly through
865 // pB->i2eWaitForTxEmpty.
867 //******************************************************************************
868 static int
869 iiWaitForTxEmptyIIEX(i2eBordStrPtr pB, int mSdelay)
871 unsigned long flags;
873 for (;;)
875 // By the nature of this routine, you would be using this as part of a
876 // larger atomic context: i.e., you would use this routine to ensure the
877 // fifo empty, then act on this information. Between these two halves,
878 // you will generally not want to service interrupts or in any way
879 // disrupt the assumptions implicit in the larger context.
881 write_lock_irqsave(&Dl_spinlock, flags);
883 if (inb(pB->i2eStatus) & STE_OUT_MT) {
884 I2_UPDATE_FIFO_ROOM(pB);
885 write_unlock_irqrestore(&Dl_spinlock, flags);
886 I2_COMPLETE(pB, I2EE_GOOD);
888 write_unlock_irqrestore(&Dl_spinlock, flags);
890 if (mSdelay-- == 0)
891 break;
893 iiDelay(pB, 1); // 1 mS granularity on checking condition
895 I2_COMPLETE(pB, I2EE_TXE_TIME);
898 //******************************************************************************
899 // Function: iiTxMailEmptyII(pB)
900 // Parameters: pB - pointer to board structure
902 // Returns: True if the transmit mailbox is empty.
903 // False if it not empty.
905 // Description:
907 // Returns true or false according to whether the transmit mailbox is empty (and
908 // therefore able to accept more mail)
910 // This version operates on IntelliPort-II - style FIFO's
912 //******************************************************************************
913 static int
914 iiTxMailEmptyII(i2eBordStrPtr pB)
916 int port = pB->i2ePointer;
917 outb(SEL_OUTMAIL, port);
918 return inb(port) == 0;
921 //******************************************************************************
922 // Function: iiTxMailEmptyIIEX(pB)
923 // Parameters: pB - pointer to board structure
925 // Returns: True if the transmit mailbox is empty.
926 // False if it not empty.
928 // Description:
930 // Returns true or false according to whether the transmit mailbox is empty (and
931 // therefore able to accept more mail)
933 // This version operates on IntelliPort-IIEX - style FIFO's
935 //******************************************************************************
936 static int
937 iiTxMailEmptyIIEX(i2eBordStrPtr pB)
939 return !(inb(pB->i2eStatus) & STE_OUT_MAIL);
942 //******************************************************************************
943 // Function: iiTrySendMailII(pB,mail)
944 // Parameters: pB - pointer to board structure
945 // mail - value to write to mailbox
947 // Returns: True if the transmit mailbox is empty, and mail is sent.
948 // False if it not empty.
950 // Description:
952 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
953 // mailbox is not empty, returns false.
955 // This version operates on IntelliPort-II - style FIFO's
957 //******************************************************************************
958 static int
959 iiTrySendMailII(i2eBordStrPtr pB, unsigned char mail)
961 int port = pB->i2ePointer;
963 outb(SEL_OUTMAIL, port);
964 if (inb(port) == 0) {
965 outb(SEL_OUTMAIL, port);
966 outb(mail, port);
967 return 1;
969 return 0;
972 //******************************************************************************
973 // Function: iiTrySendMailIIEX(pB,mail)
974 // Parameters: pB - pointer to board structure
975 // mail - value to write to mailbox
977 // Returns: True if the transmit mailbox is empty, and mail is sent.
978 // False if it not empty.
980 // Description:
982 // If outgoing mailbox is empty, sends mail and returns true. If outgoing
983 // mailbox is not empty, returns false.
985 // This version operates on IntelliPort-IIEX - style FIFO's
987 //******************************************************************************
988 static int
989 iiTrySendMailIIEX(i2eBordStrPtr pB, unsigned char mail)
991 if (inb(pB->i2eStatus) & STE_OUT_MAIL)
992 return 0;
993 outb(mail, pB->i2eXMail);
994 return 1;
997 //******************************************************************************
998 // Function: iiGetMailII(pB,mail)
999 // Parameters: pB - pointer to board structure
1001 // Returns: Mailbox data or NO_MAIL_HERE.
1003 // Description:
1005 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1006 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1008 // This version operates on IntelliPort-II - style FIFO's
1010 //******************************************************************************
1011 static unsigned short
1012 iiGetMailII(i2eBordStrPtr pB)
1014 if (I2_HAS_MAIL(pB)) {
1015 outb(SEL_INMAIL, pB->i2ePointer);
1016 return inb(pB->i2ePointer);
1017 } else {
1018 return NO_MAIL_HERE;
1022 //******************************************************************************
1023 // Function: iiGetMailIIEX(pB,mail)
1024 // Parameters: pB - pointer to board structure
1026 // Returns: Mailbox data or NO_MAIL_HERE.
1028 // Description:
1030 // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
1031 // the mailbox, which is guaranteed != NO_MAIL_HERE.
1033 // This version operates on IntelliPort-IIEX - style FIFO's
1035 //******************************************************************************
1036 static unsigned short
1037 iiGetMailIIEX(i2eBordStrPtr pB)
1039 if (I2_HAS_MAIL(pB))
1040 return inb(pB->i2eXMail);
1041 else
1042 return NO_MAIL_HERE;
1045 //******************************************************************************
1046 // Function: iiEnableMailIrqII(pB)
1047 // Parameters: pB - pointer to board structure
1049 // Returns: Nothing
1051 // Description:
1053 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1055 // This version operates on IntelliPort-II - style FIFO's
1057 //******************************************************************************
1058 static void
1059 iiEnableMailIrqII(i2eBordStrPtr pB)
1061 outb(SEL_MASK, pB->i2ePointer);
1062 outb(ST_IN_MAIL, pB->i2ePointer);
1065 //******************************************************************************
1066 // Function: iiEnableMailIrqIIEX(pB)
1067 // Parameters: pB - pointer to board structure
1069 // Returns: Nothing
1071 // Description:
1073 // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
1075 // This version operates on IntelliPort-IIEX - style FIFO's
1077 //******************************************************************************
1078 static void
1079 iiEnableMailIrqIIEX(i2eBordStrPtr pB)
1081 outb(MX_IN_MAIL, pB->i2eXMask);
1084 //******************************************************************************
1085 // Function: iiWriteMaskII(pB)
1086 // Parameters: pB - pointer to board structure
1088 // Returns: Nothing
1090 // Description:
1092 // Writes arbitrary value to the mask register.
1094 // This version operates on IntelliPort-II - style FIFO's
1096 //******************************************************************************
1097 static void
1098 iiWriteMaskII(i2eBordStrPtr pB, unsigned char value)
1100 outb(SEL_MASK, pB->i2ePointer);
1101 outb(value, pB->i2ePointer);
1104 //******************************************************************************
1105 // Function: iiWriteMaskIIEX(pB)
1106 // Parameters: pB - pointer to board structure
1108 // Returns: Nothing
1110 // Description:
1112 // Writes arbitrary value to the mask register.
1114 // This version operates on IntelliPort-IIEX - style FIFO's
1116 //******************************************************************************
1117 static void
1118 iiWriteMaskIIEX(i2eBordStrPtr pB, unsigned char value)
1120 outb(value, pB->i2eXMask);
1123 //******************************************************************************
1124 // Function: iiDownloadBlock(pB, pSource, isStandard)
1125 // Parameters: pB - pointer to board structure
1126 // pSource - loadware block to download
1127 // isStandard - True if "standard" loadware, else false.
1129 // Returns: Success or Failure
1131 // Description:
1133 // Downloads a single block (at pSource)to the board referenced by pB. Caller
1134 // sets isStandard to true/false according to whether the "standard" loadware is
1135 // what's being loaded. The normal process, then, is to perform an iiInitialize
1136 // to the board, then perform some number of iiDownloadBlocks using the returned
1137 // state to determine when download is complete.
1139 // Possible return values: (see I2ELLIS.H)
1140 // II_DOWN_BADVALID
1141 // II_DOWN_BADFILE
1142 // II_DOWN_CONTINUING
1143 // II_DOWN_GOOD
1144 // II_DOWN_BAD
1145 // II_DOWN_BADSTATE
1146 // II_DOWN_TIMEOUT
1148 // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
1149 // determine whether this is the first block, whether to check for magic
1150 // numbers, how many blocks there are to go...
1152 //******************************************************************************
1153 static int
1154 iiDownloadBlock ( i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard)
1156 int itemp;
1157 int loadedFirst;
1159 if (pB->i2eValid != I2E_MAGIC) return II_DOWN_BADVALID;
1161 switch(pB->i2eState)
1163 case II_STATE_READY:
1165 // Loading the first block after reset. Must check the magic number of the
1166 // loadfile, store the number of blocks we expect to load.
1167 if (pSource->e.loadMagic != MAGIC_LOADFILE)
1169 return II_DOWN_BADFILE;
1172 // Next we store the total number of blocks to load, including this one.
1173 pB->i2eToLoad = 1 + pSource->e.loadBlocksMore;
1175 // Set the state, store the version numbers. ('Cause this may have come
1176 // from a file - we might want to report these versions and revisions in
1177 // case of an error!
1178 pB->i2eState = II_STATE_LOADING;
1179 pB->i2eLVersion = pSource->e.loadVersion;
1180 pB->i2eLRevision = pSource->e.loadRevision;
1181 pB->i2eLSub = pSource->e.loadSubRevision;
1183 // The time and date of compilation is also available but don't bother
1184 // storing it for normal purposes.
1185 loadedFirst = 1;
1186 break;
1188 case II_STATE_LOADING:
1189 loadedFirst = 0;
1190 break;
1192 default:
1193 return II_DOWN_BADSTATE;
1196 // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
1197 // must be positive still, because otherwise we would have cleaned up last
1198 // time and set the state to II_STATE_LOADED.
1199 if (!iiWaitForTxEmpty(pB, MAX_DLOAD_READ_TIME)) {
1200 return II_DOWN_TIMEOUT;
1203 if (!iiWriteBuf(pB, pSource->c, LOADWARE_BLOCK_SIZE)) {
1204 return II_DOWN_BADVALID;
1207 // If we just loaded the first block, wait for the fifo to empty an extra
1208 // long time to allow for any special startup code in the firmware, like
1209 // sending status messages to the LCD's.
1211 if (loadedFirst) {
1212 if (!iiWaitForTxEmpty(pB, MAX_DLOAD_START_TIME)) {
1213 return II_DOWN_TIMEOUT;
1217 // Determine whether this was our last block!
1218 if (--(pB->i2eToLoad)) {
1219 return II_DOWN_CONTINUING; // more to come...
1222 // It WAS our last block: Clean up operations...
1223 // ...Wait for last buffer to drain from the board...
1224 if (!iiWaitForTxEmpty(pB, MAX_DLOAD_READ_TIME)) {
1225 return II_DOWN_TIMEOUT;
1227 // If there were only a single block written, this would come back
1228 // immediately and be harmless, though not strictly necessary.
1229 itemp = MAX_DLOAD_ACK_TIME/10;
1230 while (--itemp) {
1231 if (I2_HAS_INPUT(pB)) {
1232 switch (inb(pB->i2eData)) {
1233 case LOADWARE_OK:
1234 pB->i2eState =
1235 isStandard ? II_STATE_STDLOADED :II_STATE_LOADED;
1237 // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
1238 // will, // if there is a debug port attached, require some
1239 // time to send information to the debug port now. It will do
1240 // this before // executing any of the code we just downloaded.
1241 // It may take up to 700 milliseconds.
1242 if (pB->i2ePom.e.porDiag2 & POR_DEBUG_PORT) {
1243 iiDelay(pB, 700);
1246 return II_DOWN_GOOD;
1248 case LOADWARE_BAD:
1249 default:
1250 return II_DOWN_BAD;
1254 iiDelay(pB, 10); // 10 mS granularity on checking condition
1257 // Drop-through --> timed out waiting for firmware confirmation
1259 pB->i2eState = II_STATE_BADLOAD;
1260 return II_DOWN_TIMEOUT;
1263 //******************************************************************************
1264 // Function: iiDownloadAll(pB, pSource, isStandard, size)
1265 // Parameters: pB - pointer to board structure
1266 // pSource - loadware block to download
1267 // isStandard - True if "standard" loadware, else false.
1268 // size - size of data to download (in bytes)
1270 // Returns: Success or Failure
1272 // Description:
1274 // Given a pointer to a board structure, a pointer to the beginning of some
1275 // loadware, whether it is considered the "standard loadware", and the size of
1276 // the array in bytes loads the entire array to the board as loadware.
1278 // Assumes the board has been freshly reset and the power-up reset message read.
1279 // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
1280 // too much or too little data to load, or if iiDownloadBlock complains.
1281 //******************************************************************************
1282 static int
1283 iiDownloadAll(i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard, int size)
1285 int status;
1287 // We know (from context) board should be ready for the first block of
1288 // download. Complain if not.
1289 if (pB->i2eState != II_STATE_READY) return II_DOWN_BADSTATE;
1291 while (size > 0) {
1292 size -= LOADWARE_BLOCK_SIZE; // How much data should there be left to
1293 // load after the following operation ?
1295 // Note we just bump pSource by "one", because its size is actually that
1296 // of an entire block, same as LOADWARE_BLOCK_SIZE.
1297 status = iiDownloadBlock(pB, pSource++, isStandard);
1299 switch(status)
1301 case II_DOWN_GOOD:
1302 return ( (size > 0) ? II_DOWN_OVER : II_DOWN_GOOD);
1304 case II_DOWN_CONTINUING:
1305 break;
1307 default:
1308 return status;
1312 // We shouldn't drop out: it means "while" caught us with nothing left to
1313 // download, yet the previous DownloadBlock did not return complete. Ergo,
1314 // not enough data to match the size byte in the header.
1315 return II_DOWN_UNDER;