i2ellis.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /*******************************************************************************
  2. *
  3. * (c) 1998 by Computone Corporation
  4. *
  5. ********************************************************************************
  6. *
  7. *
  8. * PACKAGE: Linux tty Device Driver for IntelliPort family of multiport
  9. * serial I/O controllers.
  10. *
  11. * DESCRIPTION: Low-level interface code for the device driver
  12. * (This is included source code, not a separate compilation
  13. * module.)
  14. *
  15. *******************************************************************************/
  16. //---------------------------------------------
  17. // Function declarations private to this module
  18. //---------------------------------------------
  19. // Functions called only indirectly through i2eBordStr entries.
  20. static int iiWriteBuf16(i2eBordStrPtr, unsigned char *, int);
  21. static int iiWriteBuf8(i2eBordStrPtr, unsigned char *, int);
  22. static int iiReadBuf16(i2eBordStrPtr, unsigned char *, int);
  23. static int iiReadBuf8(i2eBordStrPtr, unsigned char *, int);
  24. static unsigned short iiReadWord16(i2eBordStrPtr);
  25. static unsigned short iiReadWord8(i2eBordStrPtr);
  26. static void iiWriteWord16(i2eBordStrPtr, unsigned short);
  27. static void iiWriteWord8(i2eBordStrPtr, unsigned short);
  28. static int iiWaitForTxEmptyII(i2eBordStrPtr, int);
  29. static int iiWaitForTxEmptyIIEX(i2eBordStrPtr, int);
  30. static int iiTxMailEmptyII(i2eBordStrPtr);
  31. static int iiTxMailEmptyIIEX(i2eBordStrPtr);
  32. static int iiTrySendMailII(i2eBordStrPtr, unsigned char);
  33. static int iiTrySendMailIIEX(i2eBordStrPtr, unsigned char);
  34. static unsigned short iiGetMailII(i2eBordStrPtr);
  35. static unsigned short iiGetMailIIEX(i2eBordStrPtr);
  36. static void iiEnableMailIrqII(i2eBordStrPtr);
  37. static void iiEnableMailIrqIIEX(i2eBordStrPtr);
  38. static void iiWriteMaskII(i2eBordStrPtr, unsigned char);
  39. static void iiWriteMaskIIEX(i2eBordStrPtr, unsigned char);
  40. static void ii2Nop(void);
  41. //***************
  42. //* Static Data *
  43. //***************
  44. static int ii2Safe; // Safe I/O address for delay routine
  45. static int iiDelayed; // Set when the iiResetDelay function is
  46. // called. Cleared when ANY board is reset.
  47. static DEFINE_RWLOCK(Dl_spinlock);
  48. //********
  49. //* Code *
  50. //********
  51. //=======================================================
  52. // Initialization Routines
  53. //
  54. // iiSetAddress
  55. // iiReset
  56. // iiResetDelay
  57. // iiInitialize
  58. //=======================================================
  59. //******************************************************************************
  60. // Function: iiEllisInit()
  61. // Parameters: None
  62. //
  63. // Returns: Nothing
  64. //
  65. // Description:
  66. //
  67. // This routine performs any required initialization of the iiEllis subsystem.
  68. //
  69. //******************************************************************************
  70. static void
  71. iiEllisInit(void)
  72. {
  73. }
  74. //******************************************************************************
  75. // Function: iiEllisCleanup()
  76. // Parameters: None
  77. //
  78. // Returns: Nothing
  79. //
  80. // Description:
  81. //
  82. // This routine performs any required cleanup of the iiEllis subsystem.
  83. //
  84. //******************************************************************************
  85. static void
  86. iiEllisCleanup(void)
  87. {
  88. }
  89. //******************************************************************************
  90. // Function: iiSetAddress(pB, address, delay)
  91. // Parameters: pB - pointer to the board structure
  92. // address - the purported I/O address of the board
  93. // delay - pointer to the 1-ms delay function to use
  94. // in this and any future operations to this board
  95. //
  96. // Returns: True if everything appears copacetic.
  97. // False if there is any error: the pB->i2eError field has the error
  98. //
  99. // Description:
  100. //
  101. // This routine (roughly) checks for address validity, sets the i2eValid OK and
  102. // sets the state to II_STATE_COLD which means that we haven't even sent a reset
  103. // yet.
  104. //
  105. //******************************************************************************
  106. static int
  107. iiSetAddress( i2eBordStrPtr pB, int address, delayFunc_t delay )
  108. {
  109. // Should any failure occur before init is finished...
  110. pB->i2eValid = I2E_INCOMPLETE;
  111. // Cannot check upper limit except extremely: Might be microchannel
  112. // Address must be on an 8-byte boundary
  113. if ((unsigned int)address <= 0x100
  114. || (unsigned int)address >= 0xfff8
  115. || (address & 0x7)
  116. )
  117. {
  118. I2_COMPLETE(pB, I2EE_BADADDR);
  119. }
  120. // Initialize accelerators
  121. pB->i2eBase = address;
  122. pB->i2eData = address + FIFO_DATA;
  123. pB->i2eStatus = address + FIFO_STATUS;
  124. pB->i2ePointer = address + FIFO_PTR;
  125. pB->i2eXMail = address + FIFO_MAIL;
  126. pB->i2eXMask = address + FIFO_MASK;
  127. // Initialize i/o address for ii2DelayIO
  128. ii2Safe = address + FIFO_NOP;
  129. // Initialize the delay routine
  130. pB->i2eDelay = ((delay != (delayFunc_t)NULL) ? delay : (delayFunc_t)ii2Nop);
  131. pB->i2eValid = I2E_MAGIC;
  132. pB->i2eState = II_STATE_COLD;
  133. I2_COMPLETE(pB, I2EE_GOOD);
  134. }
  135. //******************************************************************************
  136. // Function: iiReset(pB)
  137. // Parameters: pB - pointer to the board structure
  138. //
  139. // Returns: True if everything appears copacetic.
  140. // False if there is any error: the pB->i2eError field has the error
  141. //
  142. // Description:
  143. //
  144. // Attempts to reset the board (see also i2hw.h). Normally, we would use this to
  145. // reset a board immediately after iiSetAddress(), but it is valid to reset a
  146. // board from any state, say, in order to change or re-load loadware. (Under
  147. // such circumstances, no reason to re-run iiSetAddress(), which is why it is a
  148. // separate routine and not included in this routine.
  149. //
  150. //******************************************************************************
  151. static int
  152. iiReset(i2eBordStrPtr pB)
  153. {
  154. // Magic number should be set, else even the address is suspect
  155. if (pB->i2eValid != I2E_MAGIC)
  156. {
  157. I2_COMPLETE(pB, I2EE_BADMAGIC);
  158. }
  159. outb(0, pB->i2eBase + FIFO_RESET); /* Any data will do */
  160. iiDelay(pB, 50); // Pause between resets
  161. outb(0, pB->i2eBase + FIFO_RESET); /* Second reset */
  162. // We must wait before even attempting to read anything from the FIFO: the
  163. // board's P.O.S.T may actually attempt to read and write its end of the
  164. // FIFO in order to check flags, loop back (where supported), etc. On
  165. // completion of this testing it would reset the FIFO, and on completion
  166. // of all // P.O.S.T., write the message. We must not mistake data which
  167. // might have been sent for testing as part of the reset message. To
  168. // better utilize time, say, when resetting several boards, we allow the
  169. // delay to be performed externally; in this way the caller can reset
  170. // several boards, delay a single time, then call the initialization
  171. // routine for all.
  172. pB->i2eState = II_STATE_RESET;
  173. iiDelayed = 0; // i.e., the delay routine hasn't been called since the most
  174. // recent reset.
  175. // Ensure anything which would have been of use to standard loadware is
  176. // blanked out, since board has now forgotten everything!.
  177. pB->i2eUsingIrq = I2_IRQ_UNDEFINED; /* to not use an interrupt so far */
  178. pB->i2eWaitingForEmptyFifo = 0;
  179. pB->i2eOutMailWaiting = 0;
  180. pB->i2eChannelPtr = NULL;
  181. pB->i2eChannelCnt = 0;
  182. pB->i2eLeadoffWord[0] = 0;
  183. pB->i2eFifoInInts = 0;
  184. pB->i2eFifoOutInts = 0;
  185. pB->i2eFatalTrap = NULL;
  186. pB->i2eFatal = 0;
  187. I2_COMPLETE(pB, I2EE_GOOD);
  188. }
  189. //******************************************************************************
  190. // Function: iiResetDelay(pB)
  191. // Parameters: pB - pointer to the board structure
  192. //
  193. // Returns: True if everything appears copacetic.
  194. // False if there is any error: the pB->i2eError field has the error
  195. //
  196. // Description:
  197. //
  198. // Using the delay defined in board structure, waits two seconds (for board to
  199. // reset).
  200. //
  201. //******************************************************************************
  202. static int
  203. iiResetDelay(i2eBordStrPtr pB)
  204. {
  205. if (pB->i2eValid != I2E_MAGIC) {
  206. I2_COMPLETE(pB, I2EE_BADMAGIC);
  207. }
  208. if (pB->i2eState != II_STATE_RESET) {
  209. I2_COMPLETE(pB, I2EE_BADSTATE);
  210. }
  211. iiDelay(pB,2000); /* Now we wait for two seconds. */
  212. iiDelayed = 1; /* Delay has been called: ok to initialize */
  213. I2_COMPLETE(pB, I2EE_GOOD);
  214. }
  215. //******************************************************************************
  216. // Function: iiInitialize(pB)
  217. // Parameters: pB - pointer to the board structure
  218. //
  219. // Returns: True if everything appears copacetic.
  220. // False if there is any error: the pB->i2eError field has the error
  221. //
  222. // Description:
  223. //
  224. // Attempts to read the Power-on reset message. Initializes any remaining fields
  225. // in the pB structure.
  226. //
  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!).
  231. //
  232. //******************************************************************************
  233. static int
  234. iiInitialize(i2eBordStrPtr pB)
  235. {
  236. int itemp;
  237. unsigned char c;
  238. unsigned short utemp;
  239. unsigned int ilimit;
  240. if (pB->i2eValid != I2E_MAGIC)
  241. {
  242. I2_COMPLETE(pB, I2EE_BADMAGIC);
  243. }
  244. if (pB->i2eState != II_STATE_RESET || !iiDelayed)
  245. {
  246. I2_COMPLETE(pB, I2EE_BADSTATE);
  247. }
  248. // In case there is a failure short of our completely reading the power-up
  249. // message.
  250. pB->i2eValid = I2E_INCOMPLETE;
  251. // Now attempt to read the message.
  252. for (itemp = 0; itemp < sizeof(porStr); itemp++)
  253. {
  254. // We expect the entire message is ready.
  255. if (!I2_HAS_INPUT(pB)) {
  256. pB->i2ePomSize = itemp;
  257. I2_COMPLETE(pB, I2EE_PORM_SHORT);
  258. }
  259. pB->i2ePom.c[itemp] = c = inb(pB->i2eData);
  260. // We check the magic numbers as soon as they are supposed to be read
  261. // (rather than after) to minimize effect of reading something we
  262. // already suspect can't be "us".
  263. if ( (itemp == POR_1_INDEX && c != POR_MAGIC_1) ||
  264. (itemp == POR_2_INDEX && c != POR_MAGIC_2))
  265. {
  266. pB->i2ePomSize = itemp+1;
  267. I2_COMPLETE(pB, I2EE_BADMAGIC);
  268. }
  269. }
  270. pB->i2ePomSize = itemp;
  271. // Ensure that this was all the data...
  272. if (I2_HAS_INPUT(pB))
  273. I2_COMPLETE(pB, I2EE_PORM_LONG);
  274. // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
  275. // Implying we will not be able to download any code either: That's ok: the
  276. // condition is pretty explicit.
  277. if (pB->i2ePom.e.porDiag1 & POR_BAD_MAPPER)
  278. {
  279. I2_COMPLETE(pB, I2EE_POSTERR);
  280. }
  281. // Determine anything which must be done differently depending on the family
  282. // of boards!
  283. switch (pB->i2ePom.e.porID & POR_ID_FAMILY)
  284. {
  285. case POR_ID_FII: // IntelliPort-II
  286. pB->i2eFifoStyle = FIFO_II;
  287. pB->i2eFifoSize = 512; // 512 bytes, always
  288. pB->i2eDataWidth16 = false;
  289. pB->i2eMaxIrq = 15; // Because board cannot tell us it is in an 8-bit
  290. // slot, we do allow it to be done (documentation!)
  291. pB->i2eGoodMap[1] =
  292. pB->i2eGoodMap[2] =
  293. pB->i2eGoodMap[3] =
  294. pB->i2eChannelMap[1] =
  295. pB->i2eChannelMap[2] =
  296. pB->i2eChannelMap[3] = 0;
  297. switch (pB->i2ePom.e.porID & POR_ID_SIZE)
  298. {
  299. case POR_ID_II_4:
  300. pB->i2eGoodMap[0] =
  301. pB->i2eChannelMap[0] = 0x0f; // four-port
  302. // Since porPorts1 is based on the Hardware ID register, the numbers
  303. // should always be consistent for IntelliPort-II. Ditto below...
  304. if (pB->i2ePom.e.porPorts1 != 4)
  305. {
  306. I2_COMPLETE(pB, I2EE_INCONSIST);
  307. }
  308. break;
  309. case POR_ID_II_8:
  310. case POR_ID_II_8R:
  311. pB->i2eGoodMap[0] =
  312. pB->i2eChannelMap[0] = 0xff; // Eight port
  313. if (pB->i2ePom.e.porPorts1 != 8)
  314. {
  315. I2_COMPLETE(pB, I2EE_INCONSIST);
  316. }
  317. break;
  318. case POR_ID_II_6:
  319. pB->i2eGoodMap[0] =
  320. pB->i2eChannelMap[0] = 0x3f; // Six Port
  321. if (pB->i2ePom.e.porPorts1 != 6)
  322. {
  323. I2_COMPLETE(pB, I2EE_INCONSIST);
  324. }
  325. break;
  326. }
  327. // Fix up the "good channel list based on any errors reported.
  328. if (pB->i2ePom.e.porDiag1 & POR_BAD_UART1)
  329. {
  330. pB->i2eGoodMap[0] &= ~0x0f;
  331. }
  332. if (pB->i2ePom.e.porDiag1 & POR_BAD_UART2)
  333. {
  334. pB->i2eGoodMap[0] &= ~0xf0;
  335. }
  336. break; // POR_ID_FII case
  337. case POR_ID_FIIEX: // IntelliPort-IIEX
  338. pB->i2eFifoStyle = FIFO_IIEX;
  339. itemp = pB->i2ePom.e.porFifoSize;
  340. // Implicit assumption that fifo would not grow beyond 32k,
  341. // nor would ever be less than 256.
  342. if (itemp < 8 || itemp > 15)
  343. {
  344. I2_COMPLETE(pB, I2EE_INCONSIST);
  345. }
  346. pB->i2eFifoSize = (1 << itemp);
  347. // These are based on what P.O.S.T thinks should be there, based on
  348. // box ID registers
  349. ilimit = pB->i2ePom.e.porNumBoxes;
  350. if (ilimit > ABS_MAX_BOXES)
  351. {
  352. ilimit = ABS_MAX_BOXES;
  353. }
  354. // For as many boxes as EXIST, gives the type of box.
  355. // Added 8/6/93: check for the ISA-4 (asic) which looks like an
  356. // expandable but for whom "8 or 16?" is not the right question.
  357. utemp = pB->i2ePom.e.porFlags;
  358. if (utemp & POR_CEX4)
  359. {
  360. pB->i2eChannelMap[0] = 0x000f;
  361. } else {
  362. utemp &= POR_BOXES;
  363. for (itemp = 0; itemp < ilimit; itemp++)
  364. {
  365. pB->i2eChannelMap[itemp] =
  366. ((utemp & POR_BOX_16) ? 0xffff : 0x00ff);
  367. utemp >>= 1;
  368. }
  369. }
  370. // These are based on what P.O.S.T actually found.
  371. utemp = (pB->i2ePom.e.porPorts2 << 8) + pB->i2ePom.e.porPorts1;
  372. for (itemp = 0; itemp < ilimit; itemp++)
  373. {
  374. pB->i2eGoodMap[itemp] = 0;
  375. if (utemp & 1) pB->i2eGoodMap[itemp] |= 0x000f;
  376. if (utemp & 2) pB->i2eGoodMap[itemp] |= 0x00f0;
  377. if (utemp & 4) pB->i2eGoodMap[itemp] |= 0x0f00;
  378. if (utemp & 8) pB->i2eGoodMap[itemp] |= 0xf000;
  379. utemp >>= 4;
  380. }
  381. // Now determine whether we should transfer in 8 or 16-bit mode.
  382. switch (pB->i2ePom.e.porBus & (POR_BUS_SLOT16 | POR_BUS_DIP16) )
  383. {
  384. case POR_BUS_SLOT16 | POR_BUS_DIP16:
  385. pB->i2eDataWidth16 = true;
  386. pB->i2eMaxIrq = 15;
  387. break;
  388. case POR_BUS_SLOT16:
  389. pB->i2eDataWidth16 = false;
  390. pB->i2eMaxIrq = 15;
  391. break;
  392. case 0:
  393. case POR_BUS_DIP16: // In an 8-bit slot, DIP switch don't care.
  394. default:
  395. pB->i2eDataWidth16 = false;
  396. pB->i2eMaxIrq = 7;
  397. break;
  398. }
  399. break; // POR_ID_FIIEX case
  400. default: // Unknown type of board
  401. I2_COMPLETE(pB, I2EE_BAD_FAMILY);
  402. break;
  403. } // End the switch based on family
  404. // Temporarily, claim there is no room in the outbound fifo.
  405. // We will maintain this whenever we check for an empty outbound FIFO.
  406. pB->i2eFifoRemains = 0;
  407. // Now, based on the bus type, should we expect to be able to re-configure
  408. // interrupts (say, for testing purposes).
  409. switch (pB->i2ePom.e.porBus & POR_BUS_TYPE)
  410. {
  411. case POR_BUS_T_ISA:
  412. case POR_BUS_T_UNK: // If the type of bus is undeclared, assume ok.
  413. case POR_BUS_T_MCA:
  414. case POR_BUS_T_EISA:
  415. break;
  416. default:
  417. I2_COMPLETE(pB, I2EE_BADBUS);
  418. }
  419. if (pB->i2eDataWidth16)
  420. {
  421. pB->i2eWriteBuf = iiWriteBuf16;
  422. pB->i2eReadBuf = iiReadBuf16;
  423. pB->i2eWriteWord = iiWriteWord16;
  424. pB->i2eReadWord = iiReadWord16;
  425. } else {
  426. pB->i2eWriteBuf = iiWriteBuf8;
  427. pB->i2eReadBuf = iiReadBuf8;
  428. pB->i2eWriteWord = iiWriteWord8;
  429. pB->i2eReadWord = iiReadWord8;
  430. }
  431. switch(pB->i2eFifoStyle)
  432. {
  433. case FIFO_II:
  434. pB->i2eWaitForTxEmpty = iiWaitForTxEmptyII;
  435. pB->i2eTxMailEmpty = iiTxMailEmptyII;
  436. pB->i2eTrySendMail = iiTrySendMailII;
  437. pB->i2eGetMail = iiGetMailII;
  438. pB->i2eEnableMailIrq = iiEnableMailIrqII;
  439. pB->i2eWriteMask = iiWriteMaskII;
  440. break;
  441. case FIFO_IIEX:
  442. pB->i2eWaitForTxEmpty = iiWaitForTxEmptyIIEX;
  443. pB->i2eTxMailEmpty = iiTxMailEmptyIIEX;
  444. pB->i2eTrySendMail = iiTrySendMailIIEX;
  445. pB->i2eGetMail = iiGetMailIIEX;
  446. pB->i2eEnableMailIrq = iiEnableMailIrqIIEX;
  447. pB->i2eWriteMask = iiWriteMaskIIEX;
  448. break;
  449. default:
  450. I2_COMPLETE(pB, I2EE_INCONSIST);
  451. }
  452. // Initialize state information.
  453. pB->i2eState = II_STATE_READY; // Ready to load loadware.
  454. // Some Final cleanup:
  455. // For some boards, the bootstrap firmware may perform some sort of test
  456. // resulting in a stray character pending in the incoming mailbox. If one is
  457. // there, it should be read and discarded, especially since for the standard
  458. // firmware, it's the mailbox that interrupts the host.
  459. pB->i2eStartMail = iiGetMail(pB);
  460. // Throw it away and clear the mailbox structure element
  461. pB->i2eStartMail = NO_MAIL_HERE;
  462. // Everything is ok now, return with good status/
  463. pB->i2eValid = I2E_MAGIC;
  464. I2_COMPLETE(pB, I2EE_GOOD);
  465. }
  466. //******************************************************************************
  467. // Function: ii2DelayTimer(mseconds)
  468. // Parameters: mseconds - number of milliseconds to delay
  469. //
  470. // Returns: Nothing
  471. //
  472. // Description:
  473. //
  474. // This routine delays for approximately mseconds milliseconds and is intended
  475. // to be called indirectly through i2Delay field in i2eBordStr. It uses the
  476. // Linux timer_list mechanism.
  477. //
  478. // The Linux timers use a unit called "jiffies" which are 10mS in the Intel
  479. // architecture. This function rounds the delay period up to the next "jiffy".
  480. // In the Alpha architecture the "jiffy" is 1mS, but this driver is not intended
  481. // for Alpha platforms at this time.
  482. //
  483. //******************************************************************************
  484. static void
  485. ii2DelayTimer(unsigned int mseconds)
  486. {
  487. msleep_interruptible(mseconds);
  488. }
  489. #if 0
  490. //static void ii2DelayIO(unsigned int);
  491. //******************************************************************************
  492. // !!! Not Used, this is DOS crap, some of you young folks may be interested in
  493. // in how things were done in the stone age of caculating machines !!!
  494. // Function: ii2DelayIO(mseconds)
  495. // Parameters: mseconds - number of milliseconds to delay
  496. //
  497. // Returns: Nothing
  498. //
  499. // Description:
  500. //
  501. // This routine delays for approximately mseconds milliseconds and is intended
  502. // to be called indirectly through i2Delay field in i2eBordStr. It is intended
  503. // for use where a clock-based function is impossible: for example, DOS drivers.
  504. //
  505. // This function uses the IN instruction to place bounds on the timing and
  506. // assumes that ii2Safe has been set. This is because I/O instructions are not
  507. // subject to caching and will therefore take a certain minimum time. To ensure
  508. // the delay is at least long enough on fast machines, it is based on some
  509. // fastest-case calculations. On slower machines this may cause VERY long
  510. // delays. (3 x fastest case). In the fastest case, everything is cached except
  511. // the I/O instruction itself.
  512. //
  513. // Timing calculations:
  514. // The fastest bus speed for I/O operations is likely to be 10 MHz. The I/O
  515. // operation in question is a byte operation to an odd address. For 8-bit
  516. // operations, the architecture generally enforces two wait states. At 10 MHz, a
  517. // single cycle time is 100nS. A read operation at two wait states takes 6
  518. // cycles for a total time of 600nS. Therefore approximately 1666 iterations
  519. // would be required to generate a single millisecond delay. The worst
  520. // (reasonable) case would be an 8MHz system with no cacheing. In this case, the
  521. // I/O instruction would take 125nS x 6 cyles = 750 nS. More importantly, code
  522. // fetch of other instructions in the loop would take time (zero wait states,
  523. // however) and would be hard to estimate. This is minimized by using in-line
  524. // assembler for the in inner loop of IN instructions. This consists of just a
  525. // few bytes. So we'll guess about four code fetches per loop. Each code fetch
  526. // should take four cycles, so we have 125nS * 8 = 1000nS. Worst case then is
  527. // that what should have taken 1 mS takes instead 1666 * (1750) = 2.9 mS.
  528. //
  529. // So much for theoretical timings: results using 1666 value on some actual
  530. // machines:
  531. // IBM 286 6MHz 3.15 mS
  532. // Zenith 386 33MHz 2.45 mS
  533. // (brandX) 386 33MHz 1.90 mS (has cache)
  534. // (brandY) 486 33MHz 2.35 mS
  535. // NCR 486 ?? 1.65 mS (microchannel)
  536. //
  537. // For most machines, it is probably safe to scale this number back (remember,
  538. // for robust operation use an actual timed delay if possible), so we are using
  539. // a value of 1190. This yields 1.17 mS for the fastest machine in our sample,
  540. // 1.75 mS for typical 386 machines, and 2.25 mS the absolute slowest machine.
  541. //
  542. // 1/29/93:
  543. // The above timings are too slow. Actual cycle times might be faster. ISA cycle
  544. // times could approach 500 nS, and ...
  545. // The IBM model 77 being microchannel has no wait states for 8-bit reads and
  546. // seems to be accessing the I/O at 440 nS per access (from start of one to
  547. // start of next). This would imply we need 1000/.440 = 2272 iterations to
  548. // guarantee we are fast enough. In actual testing, we see that 2 * 1190 are in
  549. // fact enough. For diagnostics, we keep the level at 1190, but developers note
  550. // this needs tuning.
  551. //
  552. // Safe assumption: 2270 i/o reads = 1 millisecond
  553. //
  554. //******************************************************************************
  555. static int ii2DelValue = 1190; // See timing calculations below
  556. // 1666 for fastest theoretical machine
  557. // 1190 safe for most fast 386 machines
  558. // 1000 for fastest machine tested here
  559. // 540 (sic) for AT286/6Mhz
  560. static void
  561. ii2DelayIO(unsigned int mseconds)
  562. {
  563. if (!ii2Safe)
  564. return; /* Do nothing if this variable uninitialized */
  565. while(mseconds--) {
  566. int i = ii2DelValue;
  567. while ( i-- ) {
  568. inb(ii2Safe);
  569. }
  570. }
  571. }
  572. #endif
  573. //******************************************************************************
  574. // Function: ii2Nop()
  575. // Parameters: None
  576. //
  577. // Returns: Nothing
  578. //
  579. // Description:
  580. //
  581. // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
  582. // saves checking for a NULL pointer at every call.
  583. //******************************************************************************
  584. static void
  585. ii2Nop(void)
  586. {
  587. return; // no mystery here
  588. }
  589. //=======================================================
  590. // Routines which are available in 8/16-bit versions, or
  591. // in different fifo styles. These are ALL called
  592. // indirectly through the board structure.
  593. //=======================================================
  594. //******************************************************************************
  595. // Function: iiWriteBuf16(pB, address, count)
  596. // Parameters: pB - pointer to board structure
  597. // address - address of data to write
  598. // count - number of data bytes to write
  599. //
  600. // Returns: True if everything appears copacetic.
  601. // False if there is any error: the pB->i2eError field has the error
  602. //
  603. // Description:
  604. //
  605. // Writes 'count' bytes from 'address' to the data fifo specified by the board
  606. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  607. // sent (identity unknown...). Uses 16-bit (word) operations. Is called
  608. // indirectly through pB->i2eWriteBuf.
  609. //
  610. //******************************************************************************
  611. static int
  612. iiWriteBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
  613. {
  614. // Rudimentary sanity checking here.
  615. if (pB->i2eValid != I2E_MAGIC)
  616. I2_COMPLETE(pB, I2EE_INVALID);
  617. I2_OUTSW(pB->i2eData, address, count);
  618. I2_COMPLETE(pB, I2EE_GOOD);
  619. }
  620. //******************************************************************************
  621. // Function: iiWriteBuf8(pB, address, count)
  622. // Parameters: pB - pointer to board structure
  623. // address - address of data to write
  624. // count - number of data bytes to write
  625. //
  626. // Returns: True if everything appears copacetic.
  627. // False if there is any error: the pB->i2eError field has the error
  628. //
  629. // Description:
  630. //
  631. // Writes 'count' bytes from 'address' to the data fifo specified by the board
  632. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  633. // sent (identity unknown...). This is to be consistent with the 16-bit version.
  634. // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
  635. //
  636. //******************************************************************************
  637. static int
  638. iiWriteBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
  639. {
  640. /* Rudimentary sanity checking here */
  641. if (pB->i2eValid != I2E_MAGIC)
  642. I2_COMPLETE(pB, I2EE_INVALID);
  643. I2_OUTSB(pB->i2eData, address, count);
  644. I2_COMPLETE(pB, I2EE_GOOD);
  645. }
  646. //******************************************************************************
  647. // Function: iiReadBuf16(pB, address, count)
  648. // Parameters: pB - pointer to board structure
  649. // address - address to put data read
  650. // count - number of data bytes to read
  651. //
  652. // Returns: True if everything appears copacetic.
  653. // False if there is any error: the pB->i2eError field has the error
  654. //
  655. // Description:
  656. //
  657. // Reads 'count' bytes into 'address' from the data fifo specified by the board
  658. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  659. // received (identity unknown...). Uses 16-bit (word) operations. Is called
  660. // indirectly through pB->i2eReadBuf.
  661. //
  662. //******************************************************************************
  663. static int
  664. iiReadBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
  665. {
  666. // Rudimentary sanity checking here.
  667. if (pB->i2eValid != I2E_MAGIC)
  668. I2_COMPLETE(pB, I2EE_INVALID);
  669. I2_INSW(pB->i2eData, address, count);
  670. I2_COMPLETE(pB, I2EE_GOOD);
  671. }
  672. //******************************************************************************
  673. // Function: iiReadBuf8(pB, address, count)
  674. // Parameters: pB - pointer to board structure
  675. // address - address to put data read
  676. // count - number of data bytes to read
  677. //
  678. // Returns: True if everything appears copacetic.
  679. // False if there is any error: the pB->i2eError field has the error
  680. //
  681. // Description:
  682. //
  683. // Reads 'count' bytes into 'address' from the data fifo specified by the board
  684. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  685. // received (identity unknown...). This to match the 16-bit behaviour. Uses
  686. // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
  687. //
  688. //******************************************************************************
  689. static int
  690. iiReadBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
  691. {
  692. // Rudimentary sanity checking here.
  693. if (pB->i2eValid != I2E_MAGIC)
  694. I2_COMPLETE(pB, I2EE_INVALID);
  695. I2_INSB(pB->i2eData, address, count);
  696. I2_COMPLETE(pB, I2EE_GOOD);
  697. }
  698. //******************************************************************************
  699. // Function: iiReadWord16(pB)
  700. // Parameters: pB - pointer to board structure
  701. //
  702. // Returns: True if everything appears copacetic.
  703. // False if there is any error: the pB->i2eError field has the error
  704. //
  705. // Description:
  706. //
  707. // Returns the word read from the data fifo specified by the board-structure
  708. // pointer pB. Uses a 16-bit operation. Is called indirectly through
  709. // pB->i2eReadWord.
  710. //
  711. //******************************************************************************
  712. static unsigned short
  713. iiReadWord16(i2eBordStrPtr pB)
  714. {
  715. return inw(pB->i2eData);
  716. }
  717. //******************************************************************************
  718. // Function: iiReadWord8(pB)
  719. // Parameters: pB - pointer to board structure
  720. //
  721. // Returns: True if everything appears copacetic.
  722. // False if there is any error: the pB->i2eError field has the error
  723. //
  724. // Description:
  725. //
  726. // Returns the word read from the data fifo specified by the board-structure
  727. // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
  728. // called indirectly through pB->i2eReadWord.
  729. //
  730. //******************************************************************************
  731. static unsigned short
  732. iiReadWord8(i2eBordStrPtr pB)
  733. {
  734. unsigned short urs;
  735. urs = inb(pB->i2eData);
  736. return (inb(pB->i2eData) << 8) | urs;
  737. }
  738. //******************************************************************************
  739. // Function: iiWriteWord16(pB, value)
  740. // Parameters: pB - pointer to board structure
  741. // value - data to write
  742. //
  743. // Returns: True if everything appears copacetic.
  744. // False if there is any error: the pB->i2eError field has the error
  745. //
  746. // Description:
  747. //
  748. // Writes the word 'value' to the data fifo specified by the board-structure
  749. // pointer pB. Uses 16-bit operation. Is called indirectly through
  750. // pB->i2eWriteWord.
  751. //
  752. //******************************************************************************
  753. static void
  754. iiWriteWord16(i2eBordStrPtr pB, unsigned short value)
  755. {
  756. outw((int)value, pB->i2eData);
  757. }
  758. //******************************************************************************
  759. // Function: iiWriteWord8(pB, value)
  760. // Parameters: pB - pointer to board structure
  761. // value - data to write
  762. //
  763. // Returns: True if everything appears copacetic.
  764. // False if there is any error: the pB->i2eError field has the error
  765. //
  766. // Description:
  767. //
  768. // Writes the word 'value' to the data fifo specified by the board-structure
  769. // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
  770. // indirectly through pB->i2eWriteWord.
  771. //
  772. //******************************************************************************
  773. static void
  774. iiWriteWord8(i2eBordStrPtr pB, unsigned short value)
  775. {
  776. outb((char)value, pB->i2eData);
  777. outb((char)(value >> 8), pB->i2eData);
  778. }
  779. //******************************************************************************
  780. // Function: iiWaitForTxEmptyII(pB, mSdelay)
  781. // Parameters: pB - pointer to board structure
  782. // mSdelay - period to wait before returning
  783. //
  784. // Returns: True if the FIFO is empty.
  785. // False if it not empty in the required time: the pB->i2eError
  786. // field has the error.
  787. //
  788. // Description:
  789. //
  790. // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
  791. // not empty by the required time, returns false and error in pB->i2eError,
  792. // otherwise returns true.
  793. //
  794. // mSdelay == 0 is taken to mean must be empty on the first test.
  795. //
  796. // This version operates on IntelliPort-II - style FIFO's
  797. //
  798. // Note this routine is organized so that if status is ok there is no delay at
  799. // all called either before or after the test. Is called indirectly through
  800. // pB->i2eWaitForTxEmpty.
  801. //
  802. //******************************************************************************
  803. static int
  804. iiWaitForTxEmptyII(i2eBordStrPtr pB, int mSdelay)
  805. {
  806. unsigned long flags;
  807. int itemp;
  808. for (;;)
  809. {
  810. // This routine hinges on being able to see the "other" status register
  811. // (as seen by the local processor). His incoming fifo is our outgoing
  812. // FIFO.
  813. //
  814. // By the nature of this routine, you would be using this as part of a
  815. // larger atomic context: i.e., you would use this routine to ensure the
  816. // fifo empty, then act on this information. Between these two halves,
  817. // you will generally not want to service interrupts or in any way
  818. // disrupt the assumptions implicit in the larger context.
  819. //
  820. // Even worse, however, this routine "shifts" the status register to
  821. // point to the local status register which is not the usual situation.
  822. // Therefore for extra safety, we force the critical section to be
  823. // completely atomic, and pick up after ourselves before allowing any
  824. // interrupts of any kind.
  825. write_lock_irqsave(&Dl_spinlock, flags);
  826. outb(SEL_COMMAND, pB->i2ePointer);
  827. outb(SEL_CMD_SH, pB->i2ePointer);
  828. itemp = inb(pB->i2eStatus);
  829. outb(SEL_COMMAND, pB->i2ePointer);
  830. outb(SEL_CMD_UNSH, pB->i2ePointer);
  831. if (itemp & ST_IN_EMPTY)
  832. {
  833. I2_UPDATE_FIFO_ROOM(pB);
  834. write_unlock_irqrestore(&Dl_spinlock, flags);
  835. I2_COMPLETE(pB, I2EE_GOOD);
  836. }
  837. write_unlock_irqrestore(&Dl_spinlock, flags);
  838. if (mSdelay-- == 0)
  839. break;
  840. iiDelay(pB, 1); /* 1 mS granularity on checking condition */
  841. }
  842. I2_COMPLETE(pB, I2EE_TXE_TIME);
  843. }
  844. //******************************************************************************
  845. // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
  846. // Parameters: pB - pointer to board structure
  847. // mSdelay - period to wait before returning
  848. //
  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.
  852. //
  853. // Description:
  854. //
  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.
  858. //
  859. // mSdelay == 0 is taken to mean must be empty on the first test.
  860. //
  861. // This version operates on IntelliPort-IIEX - style FIFO's
  862. //
  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.
  866. //
  867. //******************************************************************************
  868. static int
  869. iiWaitForTxEmptyIIEX(i2eBordStrPtr pB, int mSdelay)
  870. {
  871. unsigned long flags;
  872. for (;;)
  873. {
  874. // By the nature of this routine, you would be using this as part of a
  875. // larger atomic context: i.e., you would use this routine to ensure the
  876. // fifo empty, then act on this information. Between these two halves,
  877. // you will generally not want to service interrupts or in any way
  878. // disrupt the assumptions implicit in the larger context.
  879. write_lock_irqsave(&Dl_spinlock, flags);
  880. if (inb(pB->i2eStatus) & STE_OUT_MT) {
  881. I2_UPDATE_FIFO_ROOM(pB);
  882. write_unlock_irqrestore(&Dl_spinlock, flags);
  883. I2_COMPLETE(pB, I2EE_GOOD);
  884. }
  885. write_unlock_irqrestore(&Dl_spinlock, flags);
  886. if (mSdelay-- == 0)
  887. break;
  888. iiDelay(pB, 1); // 1 mS granularity on checking condition
  889. }
  890. I2_COMPLETE(pB, I2EE_TXE_TIME);
  891. }
  892. //******************************************************************************
  893. // Function: iiTxMailEmptyII(pB)
  894. // Parameters: pB - pointer to board structure
  895. //
  896. // Returns: True if the transmit mailbox is empty.
  897. // False if it not empty.
  898. //
  899. // Description:
  900. //
  901. // Returns true or false according to whether the transmit mailbox is empty (and
  902. // therefore able to accept more mail)
  903. //
  904. // This version operates on IntelliPort-II - style FIFO's
  905. //
  906. //******************************************************************************
  907. static int
  908. iiTxMailEmptyII(i2eBordStrPtr pB)
  909. {
  910. int port = pB->i2ePointer;
  911. outb(SEL_OUTMAIL, port);
  912. return inb(port) == 0;
  913. }
  914. //******************************************************************************
  915. // Function: iiTxMailEmptyIIEX(pB)
  916. // Parameters: pB - pointer to board structure
  917. //
  918. // Returns: True if the transmit mailbox is empty.
  919. // False if it not empty.
  920. //
  921. // Description:
  922. //
  923. // Returns true or false according to whether the transmit mailbox is empty (and
  924. // therefore able to accept more mail)
  925. //
  926. // This version operates on IntelliPort-IIEX - style FIFO's
  927. //
  928. //******************************************************************************
  929. static int
  930. iiTxMailEmptyIIEX(i2eBordStrPtr pB)
  931. {
  932. return !(inb(pB->i2eStatus) & STE_OUT_MAIL);
  933. }
  934. //******************************************************************************
  935. // Function: iiTrySendMailII(pB,mail)
  936. // Parameters: pB - pointer to board structure
  937. // mail - value to write to mailbox
  938. //
  939. // Returns: True if the transmit mailbox is empty, and mail is sent.
  940. // False if it not empty.
  941. //
  942. // Description:
  943. //
  944. // If outgoing mailbox is empty, sends mail and returns true. If outgoing
  945. // mailbox is not empty, returns false.
  946. //
  947. // This version operates on IntelliPort-II - style FIFO's
  948. //
  949. //******************************************************************************
  950. static int
  951. iiTrySendMailII(i2eBordStrPtr pB, unsigned char mail)
  952. {
  953. int port = pB->i2ePointer;
  954. outb(SEL_OUTMAIL, port);
  955. if (inb(port) == 0) {
  956. outb(SEL_OUTMAIL, port);
  957. outb(mail, port);
  958. return 1;
  959. }
  960. return 0;
  961. }
  962. //******************************************************************************
  963. // Function: iiTrySendMailIIEX(pB,mail)
  964. // Parameters: pB - pointer to board structure
  965. // mail - value to write to mailbox
  966. //
  967. // Returns: True if the transmit mailbox is empty, and mail is sent.
  968. // False if it not empty.
  969. //
  970. // Description:
  971. //
  972. // If outgoing mailbox is empty, sends mail and returns true. If outgoing
  973. // mailbox is not empty, returns false.
  974. //
  975. // This version operates on IntelliPort-IIEX - style FIFO's
  976. //
  977. //******************************************************************************
  978. static int
  979. iiTrySendMailIIEX(i2eBordStrPtr pB, unsigned char mail)
  980. {
  981. if (inb(pB->i2eStatus) & STE_OUT_MAIL)
  982. return 0;
  983. outb(mail, pB->i2eXMail);
  984. return 1;
  985. }
  986. //******************************************************************************
  987. // Function: iiGetMailII(pB,mail)
  988. // Parameters: pB - pointer to board structure
  989. //
  990. // Returns: Mailbox data or NO_MAIL_HERE.
  991. //
  992. // Description:
  993. //
  994. // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
  995. // the mailbox, which is guaranteed != NO_MAIL_HERE.
  996. //
  997. // This version operates on IntelliPort-II - style FIFO's
  998. //
  999. //******************************************************************************
  1000. static unsigned short
  1001. iiGetMailII(i2eBordStrPtr pB)
  1002. {
  1003. if (I2_HAS_MAIL(pB)) {
  1004. outb(SEL_INMAIL, pB->i2ePointer);
  1005. return inb(pB->i2ePointer);
  1006. } else {
  1007. return NO_MAIL_HERE;
  1008. }
  1009. }
  1010. //******************************************************************************
  1011. // Function: iiGetMailIIEX(pB,mail)
  1012. // Parameters: pB - pointer to board structure
  1013. //
  1014. // Returns: Mailbox data or NO_MAIL_HERE.
  1015. //
  1016. // Description:
  1017. //
  1018. // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
  1019. // the mailbox, which is guaranteed != NO_MAIL_HERE.
  1020. //
  1021. // This version operates on IntelliPort-IIEX - style FIFO's
  1022. //
  1023. //******************************************************************************
  1024. static unsigned short
  1025. iiGetMailIIEX(i2eBordStrPtr pB)
  1026. {
  1027. if (I2_HAS_MAIL(pB))
  1028. return inb(pB->i2eXMail);
  1029. else
  1030. return NO_MAIL_HERE;
  1031. }
  1032. //******************************************************************************
  1033. // Function: iiEnableMailIrqII(pB)
  1034. // Parameters: pB - pointer to board structure
  1035. //
  1036. // Returns: Nothing
  1037. //
  1038. // Description:
  1039. //
  1040. // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
  1041. //
  1042. // This version operates on IntelliPort-II - style FIFO's
  1043. //
  1044. //******************************************************************************
  1045. static void
  1046. iiEnableMailIrqII(i2eBordStrPtr pB)
  1047. {
  1048. outb(SEL_MASK, pB->i2ePointer);
  1049. outb(ST_IN_MAIL, pB->i2ePointer);
  1050. }
  1051. //******************************************************************************
  1052. // Function: iiEnableMailIrqIIEX(pB)
  1053. // Parameters: pB - pointer to board structure
  1054. //
  1055. // Returns: Nothing
  1056. //
  1057. // Description:
  1058. //
  1059. // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
  1060. //
  1061. // This version operates on IntelliPort-IIEX - style FIFO's
  1062. //
  1063. //******************************************************************************
  1064. static void
  1065. iiEnableMailIrqIIEX(i2eBordStrPtr pB)
  1066. {
  1067. outb(MX_IN_MAIL, pB->i2eXMask);
  1068. }
  1069. //******************************************************************************
  1070. // Function: iiWriteMaskII(pB)
  1071. // Parameters: pB - pointer to board structure
  1072. //
  1073. // Returns: Nothing
  1074. //
  1075. // Description:
  1076. //
  1077. // Writes arbitrary value to the mask register.
  1078. //
  1079. // This version operates on IntelliPort-II - style FIFO's
  1080. //
  1081. //******************************************************************************
  1082. static void
  1083. iiWriteMaskII(i2eBordStrPtr pB, unsigned char value)
  1084. {
  1085. outb(SEL_MASK, pB->i2ePointer);
  1086. outb(value, pB->i2ePointer);
  1087. }
  1088. //******************************************************************************
  1089. // Function: iiWriteMaskIIEX(pB)
  1090. // Parameters: pB - pointer to board structure
  1091. //
  1092. // Returns: Nothing
  1093. //
  1094. // Description:
  1095. //
  1096. // Writes arbitrary value to the mask register.
  1097. //
  1098. // This version operates on IntelliPort-IIEX - style FIFO's
  1099. //
  1100. //******************************************************************************
  1101. static void
  1102. iiWriteMaskIIEX(i2eBordStrPtr pB, unsigned char value)
  1103. {
  1104. outb(value, pB->i2eXMask);
  1105. }
  1106. //******************************************************************************
  1107. // Function: iiDownloadBlock(pB, pSource, isStandard)
  1108. // Parameters: pB - pointer to board structure
  1109. // pSource - loadware block to download
  1110. // isStandard - True if "standard" loadware, else false.
  1111. //
  1112. // Returns: Success or Failure
  1113. //
  1114. // Description:
  1115. //
  1116. // Downloads a single block (at pSource)to the board referenced by pB. Caller
  1117. // sets isStandard to true/false according to whether the "standard" loadware is
  1118. // what's being loaded. The normal process, then, is to perform an iiInitialize
  1119. // to the board, then perform some number of iiDownloadBlocks using the returned
  1120. // state to determine when download is complete.
  1121. //
  1122. // Possible return values: (see I2ELLIS.H)
  1123. // II_DOWN_BADVALID
  1124. // II_DOWN_BADFILE
  1125. // II_DOWN_CONTINUING
  1126. // II_DOWN_GOOD
  1127. // II_DOWN_BAD
  1128. // II_DOWN_BADSTATE
  1129. // II_DOWN_TIMEOUT
  1130. //
  1131. // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
  1132. // determine whether this is the first block, whether to check for magic
  1133. // numbers, how many blocks there are to go...
  1134. //
  1135. //******************************************************************************
  1136. static int
  1137. iiDownloadBlock ( i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard)
  1138. {
  1139. int itemp;
  1140. int loadedFirst;
  1141. if (pB->i2eValid != I2E_MAGIC) return II_DOWN_BADVALID;
  1142. switch(pB->i2eState)
  1143. {
  1144. case II_STATE_READY:
  1145. // Loading the first block after reset. Must check the magic number of the
  1146. // loadfile, store the number of blocks we expect to load.
  1147. if (pSource->e.loadMagic != MAGIC_LOADFILE)
  1148. {
  1149. return II_DOWN_BADFILE;
  1150. }
  1151. // Next we store the total number of blocks to load, including this one.
  1152. pB->i2eToLoad = 1 + pSource->e.loadBlocksMore;
  1153. // Set the state, store the version numbers. ('Cause this may have come
  1154. // from a file - we might want to report these versions and revisions in
  1155. // case of an error!
  1156. pB->i2eState = II_STATE_LOADING;
  1157. pB->i2eLVersion = pSource->e.loadVersion;
  1158. pB->i2eLRevision = pSource->e.loadRevision;
  1159. pB->i2eLSub = pSource->e.loadSubRevision;
  1160. // The time and date of compilation is also available but don't bother
  1161. // storing it for normal purposes.
  1162. loadedFirst = 1;
  1163. break;
  1164. case II_STATE_LOADING:
  1165. loadedFirst = 0;
  1166. break;
  1167. default:
  1168. return II_DOWN_BADSTATE;
  1169. }
  1170. // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
  1171. // must be positive still, because otherwise we would have cleaned up last
  1172. // time and set the state to II_STATE_LOADED.
  1173. if (!iiWaitForTxEmpty(pB, MAX_DLOAD_READ_TIME)) {
  1174. return II_DOWN_TIMEOUT;
  1175. }
  1176. if (!iiWriteBuf(pB, pSource->c, LOADWARE_BLOCK_SIZE)) {
  1177. return II_DOWN_BADVALID;
  1178. }
  1179. // If we just loaded the first block, wait for the fifo to empty an extra
  1180. // long time to allow for any special startup code in the firmware, like
  1181. // sending status messages to the LCD's.
  1182. if (loadedFirst) {
  1183. if (!iiWaitForTxEmpty(pB, MAX_DLOAD_START_TIME)) {
  1184. return II_DOWN_TIMEOUT;
  1185. }
  1186. }
  1187. // Determine whether this was our last block!
  1188. if (--(pB->i2eToLoad)) {
  1189. return II_DOWN_CONTINUING; // more to come...
  1190. }
  1191. // It WAS our last block: Clean up operations...
  1192. // ...Wait for last buffer to drain from the board...
  1193. if (!iiWaitForTxEmpty(pB, MAX_DLOAD_READ_TIME)) {
  1194. return II_DOWN_TIMEOUT;
  1195. }
  1196. // If there were only a single block written, this would come back
  1197. // immediately and be harmless, though not strictly necessary.
  1198. itemp = MAX_DLOAD_ACK_TIME/10;
  1199. while (--itemp) {
  1200. if (I2_HAS_INPUT(pB)) {
  1201. switch (inb(pB->i2eData)) {
  1202. case LOADWARE_OK:
  1203. pB->i2eState =
  1204. isStandard ? II_STATE_STDLOADED :II_STATE_LOADED;
  1205. // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
  1206. // will, // if there is a debug port attached, require some
  1207. // time to send information to the debug port now. It will do
  1208. // this before // executing any of the code we just downloaded.
  1209. // It may take up to 700 milliseconds.
  1210. if (pB->i2ePom.e.porDiag2 & POR_DEBUG_PORT) {
  1211. iiDelay(pB, 700);
  1212. }
  1213. return II_DOWN_GOOD;
  1214. case LOADWARE_BAD:
  1215. default:
  1216. return II_DOWN_BAD;
  1217. }
  1218. }
  1219. iiDelay(pB, 10); // 10 mS granularity on checking condition
  1220. }
  1221. // Drop-through --> timed out waiting for firmware confirmation
  1222. pB->i2eState = II_STATE_BADLOAD;
  1223. return II_DOWN_TIMEOUT;
  1224. }
  1225. //******************************************************************************
  1226. // Function: iiDownloadAll(pB, pSource, isStandard, size)
  1227. // Parameters: pB - pointer to board structure
  1228. // pSource - loadware block to download
  1229. // isStandard - True if "standard" loadware, else false.
  1230. // size - size of data to download (in bytes)
  1231. //
  1232. // Returns: Success or Failure
  1233. //
  1234. // Description:
  1235. //
  1236. // Given a pointer to a board structure, a pointer to the beginning of some
  1237. // loadware, whether it is considered the "standard loadware", and the size of
  1238. // the array in bytes loads the entire array to the board as loadware.
  1239. //
  1240. // Assumes the board has been freshly reset and the power-up reset message read.
  1241. // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
  1242. // too much or too little data to load, or if iiDownloadBlock complains.
  1243. //******************************************************************************
  1244. static int
  1245. iiDownloadAll(i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard, int size)
  1246. {
  1247. int status;
  1248. // We know (from context) board should be ready for the first block of
  1249. // download. Complain if not.
  1250. if (pB->i2eState != II_STATE_READY) return II_DOWN_BADSTATE;
  1251. while (size > 0) {
  1252. size -= LOADWARE_BLOCK_SIZE; // How much data should there be left to
  1253. // load after the following operation ?
  1254. // Note we just bump pSource by "one", because its size is actually that
  1255. // of an entire block, same as LOADWARE_BLOCK_SIZE.
  1256. status = iiDownloadBlock(pB, pSource++, isStandard);
  1257. switch(status)
  1258. {
  1259. case II_DOWN_GOOD:
  1260. return ( (size > 0) ? II_DOWN_OVER : II_DOWN_GOOD);
  1261. case II_DOWN_CONTINUING:
  1262. break;
  1263. default:
  1264. return status;
  1265. }
  1266. }
  1267. // We shouldn't drop out: it means "while" caught us with nothing left to
  1268. // download, yet the previous DownloadBlock did not return complete. Ergo,
  1269. // not enough data to match the size byte in the header.
  1270. return II_DOWN_UNDER;
  1271. }