i2ellis.c 45 KB

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