rioinit.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. /*
  2. ** -----------------------------------------------------------------------------
  3. **
  4. ** Perle Specialix driver for Linux
  5. ** Ported from existing RIO Driver for SCO sources.
  6. *
  7. * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. **
  23. ** Module : rioinit.c
  24. ** SID : 1.3
  25. ** Last Modified : 11/6/98 10:33:43
  26. ** Retrieved : 11/6/98 10:33:49
  27. **
  28. ** ident @(#)rioinit.c 1.3
  29. **
  30. ** -----------------------------------------------------------------------------
  31. */
  32. #ifdef SCCS_LABELS
  33. static char *_rioinit_c_sccs_ = "@(#)rioinit.c 1.3";
  34. #endif
  35. #include <linux/config.h>
  36. #include <linux/module.h>
  37. #include <linux/slab.h>
  38. #include <linux/errno.h>
  39. #include <linux/delay.h>
  40. #include <asm/io.h>
  41. #include <asm/system.h>
  42. #include <asm/string.h>
  43. #include <asm/semaphore.h>
  44. #include <asm/uaccess.h>
  45. #include <linux/termios.h>
  46. #include <linux/serial.h>
  47. #include <linux/generic_serial.h>
  48. #include "linux_compat.h"
  49. #include "typdef.h"
  50. #include "pkt.h"
  51. #include "daemon.h"
  52. #include "rio.h"
  53. #include "riospace.h"
  54. #include "top.h"
  55. #include "cmdpkt.h"
  56. #include "map.h"
  57. #include "riotypes.h"
  58. #include "rup.h"
  59. #include "port.h"
  60. #include "riodrvr.h"
  61. #include "rioinfo.h"
  62. #include "func.h"
  63. #include "errors.h"
  64. #include "pci.h"
  65. #include "parmmap.h"
  66. #include "unixrup.h"
  67. #include "board.h"
  68. #include "host.h"
  69. #include "error.h"
  70. #include "phb.h"
  71. #include "link.h"
  72. #include "cmdblk.h"
  73. #include "route.h"
  74. #include "control.h"
  75. #include "cirrus.h"
  76. #include "rioioctl.h"
  77. #include "rio_linux.h"
  78. #undef bcopy
  79. #define bcopy rio_pcicopy
  80. int RIOPCIinit(struct rio_info *p, int Mode);
  81. #if 0
  82. static void RIOAllocateInterrupts(struct rio_info *);
  83. static int RIOReport(struct rio_info *);
  84. static void RIOStopInterrupts(struct rio_info *, int, int);
  85. #endif
  86. static int RIOScrub(int, BYTE *, int);
  87. #if 0
  88. extern int rio_intr();
  89. /*
  90. ** Init time code.
  91. */
  92. void
  93. rioinit( p, info )
  94. struct rio_info * p;
  95. struct RioHostInfo * info;
  96. {
  97. /*
  98. ** Multi-Host card support - taking the easy way out - sorry !
  99. ** We allocate and set up the Host and Port structs when the
  100. ** driver is called to 'install' the first host.
  101. ** We check for this first 'call' by testing the RIOPortp pointer.
  102. */
  103. if ( !p->RIOPortp )
  104. {
  105. rio_dprintk (RIO_DEBUG_INIT, "Allocating and setting up driver data structures\n");
  106. RIOAllocDataStructs(p); /* allocate host/port structs */
  107. RIOSetupDataStructs(p); /* setup topology structs */
  108. }
  109. RIOInitHosts( p, info ); /* hunt down the hardware */
  110. RIOAllocateInterrupts(p); /* allocate interrupts */
  111. RIOReport(p); /* show what we found */
  112. }
  113. /*
  114. ** Initialise the Cards
  115. */
  116. void
  117. RIOInitHosts(p, info)
  118. struct rio_info * p;
  119. struct RioHostInfo * info;
  120. {
  121. /*
  122. ** 15.10.1998 ARG - ESIL 0762 part fix
  123. ** If there is no ISA card definition - we always look for PCI cards.
  124. ** As we currently only support one host card this lets an ISA card
  125. ** definition take precedence over PLUG and PLAY.
  126. ** No ISA card - we are PLUG and PLAY with PCI.
  127. */
  128. /*
  129. ** Note - for PCI both these will be zero, that's okay because
  130. ** RIOPCIInit() fills them in if a card is found.
  131. */
  132. p->RIOHosts[p->RIONumHosts].Ivec = info->vector;
  133. p->RIOHosts[p->RIONumHosts].PaddrP = info->location;
  134. /*
  135. ** Check that we are able to accommodate another host
  136. */
  137. if ( p->RIONumHosts >= RIO_HOSTS )
  138. {
  139. p->RIOFailed++;
  140. return;
  141. }
  142. if ( info->bus & ISA_BUS )
  143. {
  144. rio_dprintk (RIO_DEBUG_INIT, "initialising card %d (ISA)\n", p->RIONumHosts);
  145. RIOISAinit(p, p->mode);
  146. }
  147. else
  148. {
  149. rio_dprintk (RIO_DEBUG_INIT, "initialising card %d (PCI)\n", p->RIONumHosts);
  150. RIOPCIinit(p, RIO_PCI_DEFAULT_MODE);
  151. }
  152. rio_dprintk (RIO_DEBUG_INIT, "Total hosts initialised so far : %d\n", p->RIONumHosts);
  153. #ifdef FUTURE_RELEASE
  154. if (p->bus & EISA_BUS)
  155. /* EISA card */
  156. RIOEISAinit(p, RIO_EISA_DEFAULT_MODE);
  157. if (p->bus & MCA_BUS)
  158. /* MCA card */
  159. RIOMCAinit(p, RIO_MCA_DEFAULT_MODE);
  160. #endif
  161. }
  162. /*
  163. ** go through memory for an AT host that we pass in the device info
  164. ** structure and initialise
  165. */
  166. void
  167. RIOISAinit(p, mode)
  168. struct rio_info * p;
  169. int mode;
  170. {
  171. /* XXX Need to implement this. */
  172. #if 0
  173. p->intr_tid = iointset(p->RIOHosts[p->RIONumHosts].Ivec,
  174. (int (*)())rio_intr, (char*)p->RIONumHosts);
  175. rio_dprintk (RIO_DEBUG_INIT, "Set interrupt handler, intr_tid = 0x%x\n", p->intr_tid );
  176. if (RIODoAT(p, p->RIOHosts[p->RIONumHosts].PaddrP, mode)) {
  177. return;
  178. }
  179. else {
  180. rio_dprintk (RIO_DEBUG_INIT, "RIODoAT failed\n");
  181. p->RIOFailed++;
  182. }
  183. #endif
  184. }
  185. /*
  186. ** RIODoAT :
  187. **
  188. ** Map in a boards physical address, check that the board is there,
  189. ** test the board and if everything is okay assign the board an entry
  190. ** in the Rio Hosts structure.
  191. */
  192. int
  193. RIODoAT(p, Base, mode)
  194. struct rio_info * p;
  195. int Base;
  196. int mode;
  197. {
  198. #define FOUND 1
  199. #define NOT_FOUND 0
  200. caddr_t cardAddr;
  201. /*
  202. ** Check to see if we actually have a board at this physical address.
  203. */
  204. if ((cardAddr = RIOCheckForATCard(Base)) != 0) {
  205. /*
  206. ** Now test the board to see if it is working.
  207. */
  208. if (RIOBoardTest(Base, cardAddr, RIO_AT, 0) == RIO_SUCCESS) {
  209. /*
  210. ** Fill out a slot in the Rio host structure.
  211. */
  212. if (RIOAssignAT(p, Base, cardAddr, mode)) {
  213. return(FOUND);
  214. }
  215. }
  216. RIOMapout(Base, RIO_AT_MEM_SIZE, cardAddr);
  217. }
  218. return(NOT_FOUND);
  219. }
  220. caddr_t
  221. RIOCheckForATCard(Base)
  222. int Base;
  223. {
  224. int off;
  225. struct DpRam *cardp; /* (Points at the host) */
  226. caddr_t virtAddr;
  227. unsigned char RIOSigTab[24];
  228. /*
  229. ** Table of values to search for as prom signature of a host card
  230. */
  231. strcpy(RIOSigTab, "JBJGPGGHINSMJPJR");
  232. /*
  233. ** Hey! Yes, You reading this code! Yo, grab a load a this:
  234. **
  235. ** IF the card is using WORD MODE rather than BYTE MODE
  236. ** then it will occupy 128K of PHYSICAL memory area. So,
  237. ** you might think that the following Mapin is wrong. Well,
  238. ** it isn't, because the SECOND 64K of occupied space is an
  239. ** EXACT COPY of the FIRST 64K. (good?), so, we need only
  240. ** map it in in one 64K block.
  241. */
  242. if (RIOMapin(Base, RIO_AT_MEM_SIZE, &virtAddr) == -1) {
  243. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Couldn't map the board in!\n");
  244. return((caddr_t)0);
  245. }
  246. /*
  247. ** virtAddr points to the DP ram of the system.
  248. ** We now cast this to a pointer to a RIO Host,
  249. ** and have a rummage about in the PROM.
  250. */
  251. cardp = (struct DpRam *)virtAddr;
  252. for (off=0; RIOSigTab[off]; off++) {
  253. if ((RBYTE(cardp->DpSignature[off]) & 0xFF) != RIOSigTab[off]) {
  254. /*
  255. ** Signature mismatch - card not at this address
  256. */
  257. RIOMapout(Base, RIO_AT_MEM_SIZE, virtAddr);
  258. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Couldn't match the signature 0x%x 0x%x!\n",
  259. (int)cardp, off);
  260. return((caddr_t)0);
  261. }
  262. }
  263. /*
  264. ** If we get here then we must have found a valid board so return
  265. ** its virtual address.
  266. */
  267. return(virtAddr);
  268. }
  269. #endif
  270. /**
  271. ** RIOAssignAT :
  272. **
  273. ** Fill out the fields in the p->RIOHosts structure now we know we know
  274. ** we have a board present.
  275. **
  276. ** bits < 0 indicates 8 bit operation requested,
  277. ** bits > 0 indicates 16 bit operation.
  278. */
  279. int
  280. RIOAssignAT(p, Base, virtAddr, mode)
  281. struct rio_info * p;
  282. int Base;
  283. caddr_t virtAddr;
  284. int mode;
  285. {
  286. int bits;
  287. struct DpRam *cardp = (struct DpRam *)virtAddr;
  288. if ((Base < ONE_MEG) || (mode & BYTE_ACCESS_MODE))
  289. bits = BYTE_OPERATION;
  290. else
  291. bits = WORD_OPERATION;
  292. /*
  293. ** Board has passed its scrub test. Fill in all the
  294. ** transient stuff.
  295. */
  296. p->RIOHosts[p->RIONumHosts].Caddr = virtAddr;
  297. p->RIOHosts[p->RIONumHosts].CardP = (struct DpRam *)virtAddr;
  298. /*
  299. ** Revision 01 AT host cards don't support WORD operations,
  300. */
  301. if ( RBYTE(cardp->DpRevision) == 01 )
  302. bits = BYTE_OPERATION;
  303. p->RIOHosts[p->RIONumHosts].Type = RIO_AT;
  304. p->RIOHosts[p->RIONumHosts].Copy = bcopy;
  305. /* set this later */
  306. p->RIOHosts[p->RIONumHosts].Slot = -1;
  307. p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits;
  308. WBYTE(p->RIOHosts[p->RIONumHosts].Control,
  309. BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  310. p->RIOHosts[p->RIONumHosts].Mode |
  311. INTERRUPT_DISABLE );
  312. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
  313. WBYTE(p->RIOHosts[p->RIONumHosts].Control,
  314. BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  315. p->RIOHosts[p->RIONumHosts].Mode |
  316. INTERRUPT_DISABLE );
  317. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
  318. p->RIOHosts[p->RIONumHosts].UniqueNum =
  319. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
  320. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
  321. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
  322. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
  323. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum);
  324. p->RIONumHosts++;
  325. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Tests Passed at 0x%x\n", Base);
  326. return(1);
  327. }
  328. #if 0
  329. #ifdef FUTURE_RELEASE
  330. int RIOMCAinit(int Mode)
  331. {
  332. uchar SlotNumber;
  333. caddr_t Caddr;
  334. uint Paddr;
  335. uint Ivec;
  336. int Handle;
  337. int ret = 0;
  338. /*
  339. ** Valid mode information for MCA cards
  340. ** is only FAST LINKS
  341. */
  342. Mode = (Mode & FAST_LINKS) ? McaTpFastLinks : McaTpSlowLinks;
  343. rio_dprintk (RIO_DEBUG_INIT, "RIOMCAinit(%d)\n",Mode);
  344. /*
  345. ** Check out each of the slots
  346. */
  347. for (SlotNumber = 0; SlotNumber < McaMaxSlots; SlotNumber++) {
  348. /*
  349. ** Enable the slot we want to talk to
  350. */
  351. outb( McaSlotSelect, SlotNumber | McaSlotEnable );
  352. /*
  353. ** Read the ID word from the slot
  354. */
  355. if (((inb(McaIdHigh)<< 8)|inb(McaIdLow)) == McaRIOId)
  356. {
  357. rio_dprintk (RIO_DEBUG_INIT, "Potential MCA card in slot %d\n", SlotNumber);
  358. /*
  359. ** Card appears to be a RIO MCA card!
  360. */
  361. RIOMachineType |= (1<<RIO_MCA);
  362. /*
  363. ** Just check we haven't found too many wonderful objects
  364. */
  365. if ( RIONumHosts >= RIO_HOSTS )
  366. {
  367. Rprintf(RIOMesgTooManyCards);
  368. return(ret);
  369. }
  370. /*
  371. ** McaIrqEnable contains the interrupt vector, and a card
  372. ** enable bit.
  373. */
  374. Ivec = inb(McaIrqEnable);
  375. rio_dprintk (RIO_DEBUG_INIT, "Ivec is %x\n", Ivec);
  376. switch ( Ivec & McaIrqMask )
  377. {
  378. case McaIrq9:
  379. rio_dprintk (RIO_DEBUG_INIT, "IRQ9\n");
  380. break;
  381. case McaIrq3:
  382. rio_dprintk (RIO_DEBUG_INIT, "IRQ3\n");
  383. break;
  384. case McaIrq4:
  385. rio_dprintk (RIO_DEBUG_INIT, "IRQ4\n");
  386. break;
  387. case McaIrq7:
  388. rio_dprintk (RIO_DEBUG_INIT, "IRQ7\n");
  389. break;
  390. case McaIrq10:
  391. rio_dprintk (RIO_DEBUG_INIT, "IRQ10\n");
  392. break;
  393. case McaIrq11:
  394. rio_dprintk (RIO_DEBUG_INIT, "IRQ11\n");
  395. break;
  396. case McaIrq12:
  397. rio_dprintk (RIO_DEBUG_INIT, "IRQ12\n");
  398. break;
  399. case McaIrq15:
  400. rio_dprintk (RIO_DEBUG_INIT, "IRQ15\n");
  401. break;
  402. }
  403. /*
  404. ** If the card enable bit isn't set, then set it!
  405. */
  406. if ((Ivec & McaCardEnable) != McaCardEnable) {
  407. rio_dprintk (RIO_DEBUG_INIT, "McaCardEnable not set - setting!\n");
  408. outb(McaIrqEnable,Ivec|McaCardEnable);
  409. } else
  410. rio_dprintk (RIO_DEBUG_INIT, "McaCardEnable already set\n");
  411. /*
  412. ** Convert the IRQ enable mask into something useful
  413. */
  414. Ivec = RIOMcaToIvec[Ivec & McaIrqMask];
  415. /*
  416. ** Find the physical address
  417. */
  418. rio_dprintk (RIO_DEBUG_INIT, "inb(McaMemory) is %x\n", inb(McaMemory));
  419. Paddr = McaAddress(inb(McaMemory));
  420. rio_dprintk (RIO_DEBUG_INIT, "MCA card has Ivec %d Addr %x\n", Ivec, Paddr);
  421. if ( Paddr != 0 )
  422. {
  423. /*
  424. ** Tell the memory mapper that we want to talk to it
  425. */
  426. Handle = RIOMapin( Paddr, RIO_MCA_MEM_SIZE, &Caddr );
  427. if ( Handle == -1 ) {
  428. rio_dprintk (RIO_DEBUG_INIT, "Couldn't map %d bytes at %x\n", RIO_MCA_MEM_SIZE, Paddr;
  429. continue;
  430. }
  431. rio_dprintk (RIO_DEBUG_INIT, "Board mapped to vaddr 0x%x\n", Caddr);
  432. /*
  433. ** And check that it is actually there!
  434. */
  435. if ( RIOBoardTest( Paddr,Caddr,RIO_MCA,SlotNumber ) == RIO_SUCCESS )
  436. {
  437. rio_dprintk (RIO_DEBUG_INIT, "Board has passed test\n");
  438. rio_dprintk (RIO_DEBUG_INIT, "Slot %d. Type %d. Paddr 0x%x. Caddr 0x%x. Mode 0x%x.\n",
  439. SlotNumber, RIO_MCA, Paddr, Caddr, Mode);
  440. /*
  441. ** Board has passed its scrub test. Fill in all the
  442. ** transient stuff.
  443. */
  444. p->RIOHosts[RIONumHosts].Slot = SlotNumber;
  445. p->RIOHosts[RIONumHosts].Ivec = Ivec;
  446. p->RIOHosts[RIONumHosts].Type = RIO_MCA;
  447. p->RIOHosts[RIONumHosts].Copy = bcopy;
  448. p->RIOHosts[RIONumHosts].PaddrP = Paddr;
  449. p->RIOHosts[RIONumHosts].Caddr = Caddr;
  450. p->RIOHosts[RIONumHosts].CardP = (struct DpRam *)Caddr;
  451. p->RIOHosts[RIONumHosts].Mode = Mode;
  452. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt , 0xff);
  453. p->RIOHosts[RIONumHosts].UniqueNum =
  454. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[0])&0xFF)<<0)|
  455. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[1])&0xFF)<<8)|
  456. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[2])&0xFF)<<16)|
  457. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[3])&0xFF)<<24);
  458. RIONumHosts++;
  459. ret++;
  460. }
  461. else
  462. {
  463. /*
  464. ** It failed the test, so ignore it.
  465. */
  466. rio_dprintk (RIO_DEBUG_INIT, "TEST FAILED\n");
  467. RIOMapout(Paddr, RIO_MCA_MEM_SIZE, Caddr );
  468. }
  469. }
  470. else
  471. {
  472. rio_dprintk (RIO_DEBUG_INIT, "Slot %d - Paddr zero!\n", SlotNumber);
  473. }
  474. }
  475. else
  476. {
  477. rio_dprintk (RIO_DEBUG_INIT, "Slot %d NOT RIO\n", SlotNumber);
  478. }
  479. }
  480. /*
  481. ** Now we have checked all the slots, turn off the MCA slot selector
  482. */
  483. outb(McaSlotSelect,0);
  484. rio_dprintk (RIO_DEBUG_INIT, "Slot %d NOT RIO\n", SlotNumber);
  485. return ret;
  486. }
  487. int RIOEISAinit( int Mode )
  488. {
  489. static int EISADone = 0;
  490. uint Paddr;
  491. int PollIntMixMsgDone = 0;
  492. caddr_t Caddr;
  493. ushort Ident;
  494. uchar EisaSlot;
  495. uchar Ivec;
  496. int ret = 0;
  497. /*
  498. ** The only valid mode information for EISA hosts is fast or slow
  499. ** links.
  500. */
  501. Mode = (Mode & FAST_LINKS) ? EISA_TP_FAST_LINKS : EISA_TP_SLOW_LINKS;
  502. if ( EISADone )
  503. {
  504. rio_dprintk (RIO_DEBUG_INIT, "RIOEISAinit() - already done, return.\n");
  505. return(0);
  506. }
  507. EISADone++;
  508. rio_dprintk (RIO_DEBUG_INIT, "RIOEISAinit()\n");
  509. /*
  510. ** First check all cards to see if ANY are set for polled mode operation.
  511. ** If so, set ALL to polled.
  512. */
  513. for ( EisaSlot=1; EisaSlot<=RIO_MAX_EISA_SLOTS; EisaSlot++ )
  514. {
  515. Ident = (INBZ(EisaSlot,EISA_PRODUCT_IDENT_HI)<<8) |
  516. INBZ(EisaSlot,EISA_PRODUCT_IDENT_LO);
  517. if ( Ident == RIO_EISA_IDENT )
  518. {
  519. rio_dprintk (RIO_DEBUG_INIT, "Found Specialix product\n");
  520. if ( INBZ(EisaSlot,EISA_PRODUCT_NUMBER) != RIO_EISA_PRODUCT_CODE )
  521. {
  522. rio_dprintk (RIO_DEBUG_INIT, "Not Specialix RIO - Product number %x\n",
  523. INBZ(EisaSlot, EISA_PRODUCT_NUMBER));
  524. continue; /* next slot */
  525. }
  526. /*
  527. ** Its a Specialix RIO!
  528. */
  529. rio_dprintk (RIO_DEBUG_INIT, "RIO Revision %d\n",
  530. INBZ(EisaSlot, EISA_REVISION_NUMBER));
  531. RIOMachineType |= (1<<RIO_EISA);
  532. /*
  533. ** Just check we haven't found too many wonderful objects
  534. */
  535. if ( RIONumHosts >= RIO_HOSTS )
  536. {
  537. Rprintf(RIOMesgTooManyCards);
  538. return 0;
  539. }
  540. /*
  541. ** Ensure that the enable bit is set!
  542. */
  543. OUTBZ( EisaSlot, EISA_ENABLE, RIO_EISA_ENABLE_BIT );
  544. /*
  545. ** EISA_INTERRUPT_VEC contains the interrupt vector.
  546. */
  547. Ivec = INBZ(EisaSlot,EISA_INTERRUPT_VEC);
  548. #ifdef RIODEBUG
  549. switch ( Ivec & EISA_INTERRUPT_MASK )
  550. {
  551. case EISA_IRQ_3:
  552. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 3\n");
  553. break;
  554. case EISA_IRQ_4:
  555. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 4\n");
  556. break;
  557. case EISA_IRQ_5:
  558. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 5\n");
  559. break;
  560. case EISA_IRQ_6:
  561. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 6\n");
  562. break;
  563. case EISA_IRQ_7:
  564. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 7\n");
  565. break;
  566. case EISA_IRQ_9:
  567. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 9\n");
  568. break;
  569. case EISA_IRQ_10:
  570. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 10\n");
  571. break;
  572. case EISA_IRQ_11:
  573. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 11\n");
  574. break;
  575. case EISA_IRQ_12:
  576. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 12\n");
  577. break;
  578. case EISA_IRQ_14:
  579. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 14\n");
  580. break;
  581. case EISA_IRQ_15:
  582. rio_dprintk (RIO_DEBUG_INIT, "EISA IRQ 15\n");
  583. break;
  584. case EISA_POLLED:
  585. rio_dprintk (RIO_DEBUG_INIT, "EISA POLLED\n");
  586. break;
  587. default:
  588. rio_dprintk (RIO_DEBUG_INIT, NULL,DBG_INIT|DBG_FAIL,"Shagged interrupt number!\n");
  589. Ivec &= EISA_CONTROL_MASK;
  590. }
  591. #endif
  592. if ( (Ivec & EISA_INTERRUPT_MASK) ==
  593. EISA_POLLED )
  594. {
  595. RIOWillPoll = 1;
  596. break; /* From EisaSlot loop */
  597. }
  598. }
  599. }
  600. /*
  601. ** Do it all again now we know whether to change all cards to polled
  602. ** mode or not
  603. */
  604. for ( EisaSlot=1; EisaSlot<=RIO_MAX_EISA_SLOTS; EisaSlot++ )
  605. {
  606. Ident = (INBZ(EisaSlot,EISA_PRODUCT_IDENT_HI)<<8) |
  607. INBZ(EisaSlot,EISA_PRODUCT_IDENT_LO);
  608. if ( Ident == RIO_EISA_IDENT )
  609. {
  610. if ( INBZ(EisaSlot,EISA_PRODUCT_NUMBER) != RIO_EISA_PRODUCT_CODE )
  611. continue; /* next slot */
  612. /*
  613. ** Its a Specialix RIO!
  614. */
  615. /*
  616. ** Ensure that the enable bit is set!
  617. */
  618. OUTBZ( EisaSlot, EISA_ENABLE, RIO_EISA_ENABLE_BIT );
  619. /*
  620. ** EISA_INTERRUPT_VEC contains the interrupt vector.
  621. */
  622. Ivec = INBZ(EisaSlot,EISA_INTERRUPT_VEC);
  623. if ( RIOWillPoll )
  624. {
  625. /*
  626. ** If we are going to operate in polled mode, but this
  627. ** board is configured to be interrupt driven, display
  628. ** the message explaining the situation to the punter,
  629. ** assuming we haven't already done so.
  630. */
  631. if ( !PollIntMixMsgDone &&
  632. (Ivec & EISA_INTERRUPT_MASK) != EISA_POLLED )
  633. {
  634. Rprintf(RIOMesgAllPolled);
  635. PollIntMixMsgDone = 1;
  636. }
  637. /*
  638. ** Ungraciously ignore whatever the board reports as its
  639. ** interrupt vector...
  640. */
  641. Ivec &= ~EISA_INTERRUPT_MASK;
  642. /*
  643. ** ...and force it to dance to the poll tune.
  644. */
  645. Ivec |= EISA_POLLED;
  646. }
  647. /*
  648. ** Convert the IRQ enable mask into something useful (0-15)
  649. */
  650. Ivec = RIOEisaToIvec(Ivec);
  651. rio_dprintk (RIO_DEBUG_INIT, "EISA host in slot %d has Ivec 0x%x\n",
  652. EisaSlot, Ivec);
  653. /*
  654. ** Find the physical address
  655. */
  656. Paddr = (INBZ(EisaSlot,EISA_MEMORY_BASE_HI)<<24) |
  657. (INBZ(EisaSlot,EISA_MEMORY_BASE_LO)<<16);
  658. rio_dprintk (RIO_DEBUG_INIT, "EISA card has Ivec %d Addr %x\n", Ivec, Paddr);
  659. if ( Paddr == 0 )
  660. {
  661. rio_dprintk (RIO_DEBUG_INIT,
  662. "Board in slot %d configured for address zero!\n", EisaSlot);
  663. continue;
  664. }
  665. /*
  666. ** Tell the memory mapper that we want to talk to it
  667. */
  668. rio_dprintk (RIO_DEBUG_INIT, "About to map EISA card \n");
  669. if (RIOMapin( Paddr, RIO_EISA_MEM_SIZE, &Caddr) == -1) {
  670. rio_dprintk (RIO_DEBUG_INIT, "Couldn't map %d bytes at %x\n",
  671. RIO_EISA_MEM_SIZE,Paddr);
  672. continue;
  673. }
  674. rio_dprintk (RIO_DEBUG_INIT, "Board mapped to vaddr 0x%x\n", Caddr);
  675. /*
  676. ** And check that it is actually there!
  677. */
  678. if ( RIOBoardTest( Paddr,Caddr,RIO_EISA,EisaSlot) == RIO_SUCCESS )
  679. {
  680. rio_dprintk (RIO_DEBUG_INIT, "Board has passed test\n");
  681. rio_dprintk (RIO_DEBUG_INIT,
  682. "Slot %d. Ivec %d. Type %d. Paddr 0x%x. Caddr 0x%x. Mode 0x%x.\n",
  683. EisaSlot,Ivec,RIO_EISA,Paddr,Caddr,Mode);
  684. /*
  685. ** Board has passed its scrub test. Fill in all the
  686. ** transient stuff.
  687. */
  688. p->RIOHosts[RIONumHosts].Slot = EisaSlot;
  689. p->RIOHosts[RIONumHosts].Ivec = Ivec;
  690. p->RIOHosts[RIONumHosts].Type = RIO_EISA;
  691. p->RIOHosts[RIONumHosts].Copy = bcopy;
  692. p->RIOHosts[RIONumHosts].PaddrP = Paddr;
  693. p->RIOHosts[RIONumHosts].Caddr = Caddr;
  694. p->RIOHosts[RIONumHosts].CardP = (struct DpRam *)Caddr;
  695. p->RIOHosts[RIONumHosts].Mode = Mode;
  696. /*
  697. ** because the EISA prom is mapped into IO space, we
  698. ** need to copy the unqiue number into the memory area
  699. ** that it would have occupied, so that the download
  700. ** code can determine its ID and card type.
  701. */
  702. WBYTE(p->RIOHosts[RIONumHosts].Unique[0],INBZ(EisaSlot,EISA_UNIQUE_NUM_0));
  703. WBYTE(p->RIOHosts[RIONumHosts].Unique[1],INBZ(EisaSlot,EISA_UNIQUE_NUM_1));
  704. WBYTE(p->RIOHosts[RIONumHosts].Unique[2],INBZ(EisaSlot,EISA_UNIQUE_NUM_2));
  705. WBYTE(p->RIOHosts[RIONumHosts].Unique[3],INBZ(EisaSlot,EISA_UNIQUE_NUM_3));
  706. p->RIOHosts[RIONumHosts].UniqueNum =
  707. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[0])&0xFF)<<0)|
  708. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[1])&0xFF)<<8)|
  709. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[2])&0xFF)<<16)|
  710. ((RBYTE(p->RIOHosts[RIONumHosts].Unique[3])&0xFF)<<24);
  711. INBZ(EisaSlot,EISA_INTERRUPT_RESET);
  712. RIONumHosts++;
  713. ret++;
  714. }
  715. else
  716. {
  717. /*
  718. ** It failed the test, so ignore it.
  719. */
  720. rio_dprintk (RIO_DEBUG_INIT, "TEST FAILED\n");
  721. RIOMapout(Paddr, RIO_EISA_MEM_SIZE, Caddr );
  722. }
  723. }
  724. }
  725. if (RIOMachineType & RIO_EISA)
  726. return ret+1;
  727. return ret;
  728. }
  729. #endif
  730. #ifndef linux
  731. #define CONFIG_ADDRESS 0xcf8
  732. #define CONFIG_DATA 0xcfc
  733. #define FORWARD_REG 0xcfa
  734. static int
  735. read_config(int bus_number, int device_num, int r_number)
  736. {
  737. unsigned int cav;
  738. unsigned int val;
  739. /*
  740. Build config_address_value:
  741. 31 24 23 16 15 11 10 8 7 0
  742. ------------------------------------------------------
  743. |1| 0000000 | bus_number | device # | 000 | register |
  744. ------------------------------------------------------
  745. */
  746. cav = r_number & 0xff;
  747. cav |= ((device_num & 0x1f) << 11);
  748. cav |= ((bus_number & 0xff) << 16);
  749. cav |= 0x80000000; /* Enable bit */
  750. outpd(CONFIG_ADDRESS,cav);
  751. val = inpd(CONFIG_DATA);
  752. outpd(CONFIG_ADDRESS,0);
  753. return val;
  754. }
  755. static
  756. write_config(bus_number,device_num,r_number,val)
  757. {
  758. unsigned int cav;
  759. /*
  760. Build config_address_value:
  761. 31 24 23 16 15 11 10 8 7 0
  762. ------------------------------------------------------
  763. |1| 0000000 | bus_number | device # | 000 | register |
  764. ------------------------------------------------------
  765. */
  766. cav = r_number & 0xff;
  767. cav |= ((device_num & 0x1f) << 11);
  768. cav |= ((bus_number & 0xff) << 16);
  769. cav |= 0x80000000; /* Enable bit */
  770. outpd(CONFIG_ADDRESS, cav);
  771. outpd(CONFIG_DATA, val);
  772. outpd(CONFIG_ADDRESS, 0);
  773. return val;
  774. }
  775. #else
  776. /* XXX Implement these... */
  777. static int
  778. read_config(int bus_number, int device_num, int r_number)
  779. {
  780. return 0;
  781. }
  782. static int
  783. write_config(int bus_number, int device_num, int r_number)
  784. {
  785. return 0;
  786. }
  787. #endif
  788. int
  789. RIOPCIinit(p, Mode)
  790. struct rio_info *p;
  791. int Mode;
  792. {
  793. #define MAX_PCI_SLOT 32
  794. #define RIO_PCI_JET_CARD 0x200011CB
  795. static int slot; /* count of machine's PCI slots searched so far */
  796. caddr_t Caddr; /* Virtual address of the current PCI host card. */
  797. unsigned char Ivec; /* interrupt vector for the current PCI host */
  798. unsigned long Paddr; /* Physical address for the current PCI host */
  799. int Handle; /* Handle to Virtual memory allocated for current PCI host */
  800. rio_dprintk (RIO_DEBUG_INIT, "Search for a RIO PCI card - start at slot %d\n", slot);
  801. /*
  802. ** Initialise the search status
  803. */
  804. p->RIOLastPCISearch = RIO_FAIL;
  805. while ( (slot < MAX_PCI_SLOT) & (p->RIOLastPCISearch != RIO_SUCCESS) )
  806. {
  807. rio_dprintk (RIO_DEBUG_INIT, "Currently testing slot %d\n", slot);
  808. if (read_config(0,slot,0) == RIO_PCI_JET_CARD) {
  809. p->RIOHosts[p->RIONumHosts].Ivec = 0;
  810. Paddr = read_config(0,slot,0x18);
  811. Paddr = Paddr - (Paddr & 0x1); /* Mask off the io bit */
  812. if ( (Paddr == 0) || ((Paddr & 0xffff0000) == 0xffff0000) ) {
  813. rio_dprintk (RIO_DEBUG_INIT, "Goofed up slot\n"); /* what! */
  814. slot++;
  815. continue;
  816. }
  817. p->RIOHosts[p->RIONumHosts].PaddrP = Paddr;
  818. Ivec = (read_config(0,slot,0x3c) & 0xff);
  819. rio_dprintk (RIO_DEBUG_INIT, "PCI Host at 0x%x, Intr %d\n", (int)Paddr, Ivec);
  820. Handle = RIOMapin( Paddr, RIO_PCI_MEM_SIZE, &Caddr );
  821. if (Handle == -1) {
  822. rio_dprintk (RIO_DEBUG_INIT, "Couldn't map %d bytes at 0x%x\n", RIO_PCI_MEM_SIZE, (int)Paddr);
  823. slot++;
  824. continue;
  825. }
  826. p->RIOHosts[p->RIONumHosts].Ivec = Ivec + 32;
  827. p->intr_tid = iointset(p->RIOHosts[p->RIONumHosts].Ivec,
  828. (int (*)())rio_intr, (char *)p->RIONumHosts);
  829. if (RIOBoardTest( Paddr, Caddr, RIO_PCI, 0 ) == RIO_SUCCESS) {
  830. rio_dprintk (RIO_DEBUG_INIT, ("Board has passed test\n");
  831. rio_dprintk (RIO_DEBUG_INIT, ("Paddr 0x%x. Caddr 0x%x. Mode 0x%x.\n", Paddr, Caddr, Mode);
  832. /*
  833. ** Board has passed its scrub test. Fill in all the
  834. ** transient stuff.
  835. */
  836. p->RIOHosts[p->RIONumHosts].Slot = 0;
  837. p->RIOHosts[p->RIONumHosts].Ivec = Ivec + 32;
  838. p->RIOHosts[p->RIONumHosts].Type = RIO_PCI;
  839. p->RIOHosts[p->RIONumHosts].Copy = rio_pcicopy;
  840. p->RIOHosts[p->RIONumHosts].PaddrP = Paddr;
  841. p->RIOHosts[p->RIONumHosts].Caddr = Caddr;
  842. p->RIOHosts[p->RIONumHosts].CardP = (struct DpRam *)Caddr;
  843. p->RIOHosts[p->RIONumHosts].Mode = Mode;
  844. #if 0
  845. WBYTE(p->RIOHosts[p->RIONumHosts].Control,
  846. BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  847. p->RIOHosts[p->RIONumHosts].Mode |
  848. INTERRUPT_DISABLE );
  849. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
  850. WBYTE(p->RIOHosts[p->RIONumHosts].Control,
  851. BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  852. p->RIOHosts[p->RIONumHosts].Mode |
  853. INTERRUPT_DISABLE );
  854. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
  855. #else
  856. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
  857. #endif
  858. p->RIOHosts[p->RIONumHosts].UniqueNum =
  859. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
  860. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
  861. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
  862. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
  863. rio_dprintk (RIO_DEBUG_INIT, "Unique no 0x%x.\n",
  864. p->RIOHosts[p->RIONumHosts].UniqueNum);
  865. p->RIOLastPCISearch = RIO_SUCCESS;
  866. p->RIONumHosts++;
  867. }
  868. }
  869. slot++;
  870. }
  871. if ( slot >= MAX_PCI_SLOT ) {
  872. rio_dprintk (RIO_DEBUG_INIT, "All %d PCI slots have tested for RIO cards !!!\n",
  873. MAX_PCI_SLOT);
  874. }
  875. /*
  876. ** I don't think we want to do this anymore
  877. **
  878. if (!p->RIOLastPCISearch == RIO_FAIL ) {
  879. p->RIOFailed++;
  880. }
  881. **
  882. */
  883. }
  884. #ifdef FUTURE_RELEASE
  885. void riohalt( void )
  886. {
  887. int host;
  888. for ( host=0; host<p->RIONumHosts; host++ )
  889. {
  890. rio_dprintk (RIO_DEBUG_INIT, "Stop host %d\n", host);
  891. (void)RIOBoardTest( p->RIOHosts[host].PaddrP, p->RIOHosts[host].Caddr, p->RIOHosts[host].Type,p->RIOHosts[host].Slot );
  892. }
  893. }
  894. #endif
  895. #endif
  896. static uchar val[] = {
  897. #ifdef VERY_LONG_TEST
  898. 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  899. 0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36,
  900. #endif
  901. 0xff, 0x00, 0x00 };
  902. #define TEST_END sizeof(val)
  903. /*
  904. ** RAM test a board.
  905. ** Nothing too complicated, just enough to check it out.
  906. */
  907. int
  908. RIOBoardTest(paddr, caddr, type, slot)
  909. paddr_t paddr;
  910. caddr_t caddr;
  911. uchar type;
  912. int slot;
  913. {
  914. struct DpRam *DpRam = (struct DpRam *)caddr;
  915. char *ram[4];
  916. int size[4];
  917. int op, bank;
  918. int nbanks;
  919. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=0x%x, slot=%d\n",
  920. type,(int)DpRam, slot);
  921. RIOHostReset(type, DpRam, slot);
  922. /*
  923. ** Scrub the memory. This comes in several banks:
  924. ** DPsram1 - 7000h bytes
  925. ** DPsram2 - 200h bytes
  926. ** DPsram3 - 7000h bytes
  927. ** scratch - 1000h bytes
  928. */
  929. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Setup ram/size arrays\n");
  930. size[0] = DP_SRAM1_SIZE;
  931. size[1] = DP_SRAM2_SIZE;
  932. size[2] = DP_SRAM3_SIZE;
  933. size[3] = DP_SCRATCH_SIZE;
  934. ram[0] = (char *)&DpRam->DpSram1[0];
  935. ram[1] = (char *)&DpRam->DpSram2[0];
  936. ram[2] = (char *)&DpRam->DpSram3[0];
  937. nbanks = (type == RIO_PCI) ? 3 : 4;
  938. if (nbanks == 4)
  939. ram[3] = (char *)&DpRam->DpScratch[0];
  940. if (nbanks == 3) {
  941. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
  942. (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2]);
  943. } else {
  944. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n",
  945. (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2], (int)ram[3],
  946. size[3]);
  947. }
  948. /*
  949. ** This scrub operation will test for crosstalk between
  950. ** banks. TEST_END is a magic number, and relates to the offset
  951. ** within the 'val' array used by Scrub.
  952. */
  953. for (op=0; op<TEST_END; op++) {
  954. for (bank=0; bank<nbanks; bank++) {
  955. if (RIOScrub(op, (BYTE *)ram[bank], size[bank]) == RIO_FAIL) {
  956. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n",
  957. bank, op);
  958. return RIO_FAIL;
  959. }
  960. }
  961. }
  962. rio_dprintk (RIO_DEBUG_INIT, "Test completed\n");
  963. return RIO_SUCCESS;
  964. }
  965. /*
  966. ** Scrub an area of RAM.
  967. ** Define PRETEST and POSTTEST for a more thorough checking of the
  968. ** state of the memory.
  969. ** Call with op set to an index into the above 'val' array to determine
  970. ** which value will be written into memory.
  971. ** Call with op set to zero means that the RAM will not be read and checked
  972. ** before it is written.
  973. ** Call with op not zero, and the RAM will be read and compated with val[op-1]
  974. ** to check that the data from the previous phase was retained.
  975. */
  976. static int
  977. RIOScrub(op, ram, size)
  978. int op;
  979. BYTE * ram;
  980. int size;
  981. {
  982. int off;
  983. unsigned char oldbyte;
  984. unsigned char newbyte;
  985. unsigned char invbyte;
  986. unsigned short oldword;
  987. unsigned short newword;
  988. unsigned short invword;
  989. unsigned short swapword;
  990. if (op) {
  991. oldbyte = val[op-1];
  992. oldword = oldbyte | (oldbyte<<8);
  993. } else
  994. oldbyte = oldword = 0; /* Tell the compiler we've initilalized them. */
  995. newbyte = val[op];
  996. newword = newbyte | (newbyte<<8);
  997. invbyte = ~newbyte;
  998. invword = invbyte | (invbyte<<8);
  999. /*
  1000. ** Check that the RAM contains the value that should have been left there
  1001. ** by the previous test (not applicable for pass zero)
  1002. */
  1003. if (op) {
  1004. for (off=0; off<size; off++) {
  1005. if (RBYTE(ram[off]) != oldbyte) {
  1006. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 1: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off]));
  1007. return RIO_FAIL;
  1008. }
  1009. }
  1010. for (off=0; off<size; off+=2) {
  1011. if (*(ushort *)&ram[off] != oldword) {
  1012. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: WORD at offset 0x%x should have been=%x, was=%x\n",off,oldword,*(ushort *)&ram[off]);
  1013. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
  1014. return RIO_FAIL;
  1015. }
  1016. }
  1017. }
  1018. /*
  1019. ** Now write the INVERSE of the test data into every location, using
  1020. ** BYTE write operations, first checking before each byte is written
  1021. ** that the location contains the old value still, and checking after
  1022. ** the write that the location contains the data specified - this is
  1023. ** the BYTE read/write test.
  1024. */
  1025. for (off=0; off<size; off++) {
  1026. if (op && (RBYTE(ram[off]) != oldbyte)) {
  1027. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off]));
  1028. return RIO_FAIL;
  1029. }
  1030. WBYTE(ram[off],invbyte);
  1031. if (RBYTE(ram[off]) != invbyte) {
  1032. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Inv Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, invbyte, RBYTE(ram[off]));
  1033. return RIO_FAIL;
  1034. }
  1035. }
  1036. /*
  1037. ** now, use WORD operations to write the test value into every location,
  1038. ** check as before that the location contains the previous test value
  1039. ** before overwriting, and that it contains the data value written
  1040. ** afterwards.
  1041. ** This is the WORD operation test.
  1042. */
  1043. for (off=0; off<size; off+=2) {
  1044. if (*(ushort *)&ram[off] != invword) {
  1045. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: WORD at offset 0x%x should have been=%x, was=%x\n", off, invword, *(ushort *)&ram[off]);
  1046. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
  1047. return RIO_FAIL;
  1048. }
  1049. *(ushort *)&ram[off] = newword;
  1050. if ( *(ushort *)&ram[off] != newword ) {
  1051. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]);
  1052. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
  1053. return RIO_FAIL;
  1054. }
  1055. }
  1056. /*
  1057. ** now run through the block of memory again, first in byte mode
  1058. ** then in word mode, and check that all the locations contain the
  1059. ** required test data.
  1060. */
  1061. for (off=0; off<size; off++) {
  1062. if (RBYTE(ram[off]) != newbyte) {
  1063. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Byte Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off]));
  1064. return RIO_FAIL;
  1065. }
  1066. }
  1067. for (off=0; off<size; off+=2) {
  1068. if ( *(ushort *)&ram[off] != newword ) {
  1069. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]);
  1070. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
  1071. return RIO_FAIL;
  1072. }
  1073. }
  1074. /*
  1075. ** time to check out byte swapping errors
  1076. */
  1077. swapword = invbyte | (newbyte << 8);
  1078. for (off=0; off<size; off+=2) {
  1079. WBYTE(ram[off],invbyte);
  1080. WBYTE(ram[off+1],newbyte);
  1081. }
  1082. for ( off=0; off<size; off+=2 ) {
  1083. if (*(ushort *)&ram[off] != swapword) {
  1084. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, swapword, *((ushort *)&ram[off]));
  1085. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1]));
  1086. return RIO_FAIL;
  1087. }
  1088. *((ushort *)&ram[off]) = ~swapword;
  1089. }
  1090. for (off=0; off<size; off+=2) {
  1091. if (RBYTE(ram[off]) != newbyte) {
  1092. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off]));
  1093. return RIO_FAIL;
  1094. }
  1095. if (RBYTE(ram[off+1]) != invbyte) {
  1096. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off+1, invbyte, RBYTE(ram[off+1]));
  1097. return RIO_FAIL;
  1098. }
  1099. *((ushort *)&ram[off]) = newword;
  1100. }
  1101. return RIO_SUCCESS;
  1102. }
  1103. /*
  1104. ** try to ensure that every host is either in polled mode
  1105. ** or is in interrupt mode. Only allow interrupt mode if
  1106. ** all hosts can interrupt (why?)
  1107. ** and force into polled mode if told to. Patch up the
  1108. ** interrupt vector & salute The Queen when you've done.
  1109. */
  1110. #if 0
  1111. static void
  1112. RIOAllocateInterrupts(p)
  1113. struct rio_info * p;
  1114. {
  1115. int Host;
  1116. /*
  1117. ** Easy case - if we have been told to poll, then we poll.
  1118. */
  1119. if (p->mode & POLLED_MODE) {
  1120. RIOStopInterrupts(p, 0, 0);
  1121. return;
  1122. }
  1123. /*
  1124. ** check - if any host has been set to polled mode, then all must be.
  1125. */
  1126. for (Host=0; Host<p->RIONumHosts; Host++) {
  1127. if ( (p->RIOHosts[Host].Type != RIO_AT) &&
  1128. (p->RIOHosts[Host].Ivec == POLLED) ) {
  1129. RIOStopInterrupts(p, 1, Host );
  1130. return;
  1131. }
  1132. }
  1133. for (Host=0; Host<p->RIONumHosts; Host++) {
  1134. if (p->RIOHosts[Host].Type == RIO_AT) {
  1135. if ( (p->RIOHosts[Host].Ivec - 32) == 0) {
  1136. RIOStopInterrupts(p, 2, Host );
  1137. return;
  1138. }
  1139. }
  1140. }
  1141. }
  1142. /*
  1143. ** something has decided that we can't be doing with these
  1144. ** new-fangled interrupt thingies. Set everything up to just
  1145. ** poll.
  1146. */
  1147. static void
  1148. RIOStopInterrupts(p, Reason, Host)
  1149. struct rio_info * p;
  1150. int Reason;
  1151. int Host;
  1152. {
  1153. #ifdef FUTURE_RELEASE
  1154. switch (Reason) {
  1155. case 0: /* forced into polling by rio_polled */
  1156. break;
  1157. case 1: /* SCU has set 'Host' into polled mode */
  1158. break;
  1159. case 2: /* there aren't enough interrupt vectors for 'Host' */
  1160. break;
  1161. }
  1162. #endif
  1163. for (Host=0; Host<p->RIONumHosts; Host++ ) {
  1164. struct Host *HostP = &p->RIOHosts[Host];
  1165. switch (HostP->Type) {
  1166. case RIO_AT:
  1167. /*
  1168. ** The AT host has it's interrupts disabled by clearing the
  1169. ** int_enable bit.
  1170. */
  1171. HostP->Mode &= ~INTERRUPT_ENABLE;
  1172. HostP->Ivec = POLLED;
  1173. break;
  1174. #ifdef FUTURE_RELEASE
  1175. case RIO_EISA:
  1176. /*
  1177. ** The EISA host has it's interrupts disabled by setting the
  1178. ** Ivec to zero
  1179. */
  1180. HostP->Ivec = POLLED;
  1181. break;
  1182. #endif
  1183. case RIO_PCI:
  1184. /*
  1185. ** The PCI host has it's interrupts disabled by clearing the
  1186. ** int_enable bit, like a regular host card.
  1187. */
  1188. HostP->Mode &= ~RIO_PCI_INT_ENABLE;
  1189. HostP->Ivec = POLLED;
  1190. break;
  1191. #ifdef FUTURE_RELEASE
  1192. case RIO_MCA:
  1193. /*
  1194. ** There's always one, isn't there?
  1195. ** The MCA host card cannot have it's interrupts disabled.
  1196. */
  1197. RIOPatchVec(HostP);
  1198. break;
  1199. #endif
  1200. }
  1201. }
  1202. }
  1203. /*
  1204. ** This function is called at init time to setup the data structures.
  1205. */
  1206. void
  1207. RIOAllocDataStructs(p)
  1208. struct rio_info * p;
  1209. {
  1210. int port,
  1211. host,
  1212. tm;
  1213. p->RIOPortp = (struct Port *)sysbrk(RIO_PORTS * sizeof(struct Port));
  1214. if (!p->RIOPortp) {
  1215. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: No memory for port structures\n");
  1216. p->RIOFailed++;
  1217. return;
  1218. }
  1219. bzero( p->RIOPortp, sizeof(struct Port) * RIO_PORTS );
  1220. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: allocated and cleared memory for port structs\n");
  1221. rio_dprintk (RIO_DEBUG_INIT, "First RIO port struct @0x%x, size=0x%x bytes\n",
  1222. (int)p->RIOPortp, sizeof(struct Port));
  1223. for( port=0; port<RIO_PORTS; port++ ) {
  1224. p->RIOPortp[port].PortNum = port;
  1225. p->RIOPortp[port].TtyP = &p->channel[port];
  1226. sreset (p->RIOPortp[port].InUse); /* Let the first guy uses it */
  1227. p->RIOPortp[port].portSem = -1; /* Let the first guy takes it */
  1228. p->RIOPortp[port].ParamSem = -1; /* Let the first guy takes it */
  1229. p->RIOPortp[port].timeout_id = 0; /* Let the first guy takes it */
  1230. }
  1231. p->RIOHosts = (struct Host *)sysbrk(RIO_HOSTS * sizeof(struct Host));
  1232. if (!p->RIOHosts) {
  1233. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: No memory for host structures\n");
  1234. p->RIOFailed++;
  1235. return;
  1236. }
  1237. bzero(p->RIOHosts, sizeof(struct Host)*RIO_HOSTS);
  1238. rio_dprintk (RIO_DEBUG_INIT, "RIO-init: allocated and cleared memory for host structs\n");
  1239. rio_dprintk (RIO_DEBUG_INIT, "First RIO host struct @0x%x, size=0x%x bytes\n",
  1240. (int)p->RIOHosts, sizeof(struct Host));
  1241. for( host=0; host<RIO_HOSTS; host++ ) {
  1242. spin_lock_init (&p->RIOHosts[host].HostLock);
  1243. p->RIOHosts[host].timeout_id = 0; /* Let the first guy takes it */
  1244. }
  1245. /*
  1246. ** check that the buffer size is valid, round down to the next power of
  1247. ** two if necessary; if the result is zero, then, hey, no double buffers.
  1248. */
  1249. for ( tm = 1; tm && tm <= p->RIOConf.BufferSize; tm <<= 1 )
  1250. ;
  1251. tm >>= 1;
  1252. p->RIOBufferSize = tm;
  1253. p->RIOBufferMask = tm ? tm - 1 : 0;
  1254. }
  1255. /*
  1256. ** this function gets called whenever the data structures need to be
  1257. ** re-setup, for example, after a riohalt (why did I ever invent it?)
  1258. */
  1259. void
  1260. RIOSetupDataStructs(p)
  1261. struct rio_info * p;
  1262. {
  1263. int host, entry, rup;
  1264. for ( host=0; host<RIO_HOSTS; host++ ) {
  1265. struct Host *HostP = &p->RIOHosts[host];
  1266. for ( entry=0; entry<LINKS_PER_UNIT; entry++ ) {
  1267. HostP->Topology[entry].Unit = ROUTE_DISCONNECT;
  1268. HostP->Topology[entry].Link = NO_LINK;
  1269. }
  1270. bcopy("HOST X", HostP->Name, 7);
  1271. HostP->Name[5] = '1'+host;
  1272. for (rup=0; rup<(MAX_RUP + LINKS_PER_UNIT); rup++) {
  1273. if (rup < MAX_RUP) {
  1274. for (entry=0; entry<LINKS_PER_UNIT; entry++ ) {
  1275. HostP->Mapping[rup].Topology[entry].Unit = ROUTE_DISCONNECT;
  1276. HostP->Mapping[rup].Topology[entry].Link = NO_LINK;
  1277. }
  1278. RIODefaultName(p, HostP, rup);
  1279. }
  1280. spin_lock_init(&HostP->UnixRups[rup].RupLock);
  1281. }
  1282. }
  1283. }
  1284. #endif
  1285. int
  1286. RIODefaultName(p, HostP, UnitId)
  1287. struct rio_info * p;
  1288. struct Host * HostP;
  1289. uint UnitId;
  1290. {
  1291. #ifdef CHECK
  1292. CheckHost( Host );
  1293. CheckUnitId( UnitId );
  1294. #endif
  1295. bcopy("UNKNOWN RTA X-XX",HostP->Mapping[UnitId].Name,17);
  1296. HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts);
  1297. if ((UnitId+1) > 9) {
  1298. HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10);
  1299. HostP->Mapping[UnitId].Name[15]='0'+((UnitId+1)%10);
  1300. }
  1301. else {
  1302. HostP->Mapping[UnitId].Name[14]='1'+UnitId;
  1303. HostP->Mapping[UnitId].Name[15]=0;
  1304. }
  1305. return 0;
  1306. }
  1307. #define RIO_RELEASE "Linux"
  1308. #define RELEASE_ID "1.0"
  1309. #if 0
  1310. static int
  1311. RIOReport(p)
  1312. struct rio_info * p;
  1313. {
  1314. char * RIORelease = RIO_RELEASE;
  1315. char * RIORelID = RELEASE_ID;
  1316. int host;
  1317. rio_dprintk (RIO_DEBUG_INIT, "RIO : Release: %s ID: %s\n", RIORelease, RIORelID);
  1318. if ( p->RIONumHosts==0 ) {
  1319. rio_dprintk (RIO_DEBUG_INIT, "\nNo Hosts configured\n");
  1320. return(0);
  1321. }
  1322. for ( host=0; host < p->RIONumHosts; host++ ) {
  1323. struct Host *HostP = &p->RIOHosts[host];
  1324. switch ( HostP->Type ) {
  1325. case RIO_AT:
  1326. rio_dprintk (RIO_DEBUG_INIT, "AT BUS : found the card at 0x%x\n", HostP->PaddrP);
  1327. }
  1328. }
  1329. return 0;
  1330. }
  1331. #endif
  1332. static struct rioVersion stVersion;
  1333. struct rioVersion *
  1334. RIOVersid(void)
  1335. {
  1336. strlcpy(stVersion.version, "RIO driver for linux V1.0",
  1337. sizeof(stVersion.version));
  1338. strlcpy(stVersion.buildDate, __DATE__,
  1339. sizeof(stVersion.buildDate));
  1340. return &stVersion;
  1341. }
  1342. #if 0
  1343. int
  1344. RIOMapin(paddr, size, vaddr)
  1345. paddr_t paddr;
  1346. int size;
  1347. caddr_t * vaddr;
  1348. {
  1349. *vaddr = (caddr_t)permap( (long)paddr, size);
  1350. return ((int)*vaddr);
  1351. }
  1352. void
  1353. RIOMapout(paddr, size, vaddr)
  1354. paddr_t paddr;
  1355. long size;
  1356. caddr_t vaddr;
  1357. {
  1358. }
  1359. #endif
  1360. void
  1361. RIOHostReset(Type, DpRamP, Slot)
  1362. uint Type;
  1363. volatile struct DpRam *DpRamP;
  1364. uint Slot;
  1365. {
  1366. /*
  1367. ** Reset the Tpu
  1368. */
  1369. rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: type 0x%x", Type);
  1370. switch ( Type ) {
  1371. case RIO_AT:
  1372. rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n");
  1373. WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  1374. INTERRUPT_DISABLE | BYTE_OPERATION |
  1375. SLOW_LINKS | SLOW_AT_BUS);
  1376. WBYTE(DpRamP->DpResetTpu, 0xFF);
  1377. udelay(3);
  1378. rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: Don't know if it worked. Try reset again\n");
  1379. WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
  1380. INTERRUPT_DISABLE | BYTE_OPERATION |
  1381. SLOW_LINKS | SLOW_AT_BUS);
  1382. WBYTE(DpRamP->DpResetTpu, 0xFF);
  1383. udelay(3);
  1384. break;
  1385. #ifdef FUTURE_RELEASE
  1386. case RIO_EISA:
  1387. /*
  1388. ** Bet this doesn't work!
  1389. */
  1390. OUTBZ( Slot, EISA_CONTROL_PORT,
  1391. EISA_TP_RUN | EISA_TP_BUS_DISABLE |
  1392. EISA_TP_SLOW_LINKS | EISA_TP_BOOT_FROM_RAM );
  1393. OUTBZ( Slot, EISA_CONTROL_PORT,
  1394. EISA_TP_RESET | EISA_TP_BUS_DISABLE |
  1395. EISA_TP_SLOW_LINKS | EISA_TP_BOOT_FROM_RAM );
  1396. suspend( 3 );
  1397. OUTBZ( Slot, EISA_CONTROL_PORT,
  1398. EISA_TP_RUN | EISA_TP_BUS_DISABLE |
  1399. EISA_TP_SLOW_LINKS | EISA_TP_BOOT_FROM_RAM );
  1400. break;
  1401. case RIO_MCA:
  1402. WBYTE(DpRamP->DpControl , McaTpBootFromRam | McaTpBusDisable );
  1403. WBYTE(DpRamP->DpResetTpu , 0xFF );
  1404. suspend( 3 );
  1405. WBYTE(DpRamP->DpControl , McaTpBootFromRam | McaTpBusDisable );
  1406. WBYTE(DpRamP->DpResetTpu , 0xFF );
  1407. suspend( 3 );
  1408. break;
  1409. #endif
  1410. case RIO_PCI:
  1411. rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n");
  1412. DpRamP->DpControl = RIO_PCI_BOOT_FROM_RAM;
  1413. DpRamP->DpResetInt = 0xFF;
  1414. DpRamP->DpResetTpu = 0xFF;
  1415. udelay(100);
  1416. /* for (i=0; i<6000; i++); */
  1417. /* suspend( 3 ); */
  1418. break;
  1419. #ifdef FUTURE_RELEASE
  1420. default:
  1421. Rprintf(RIOMesgNoSupport,Type,DpRamP,Slot);
  1422. return;
  1423. #endif
  1424. default:
  1425. rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n");
  1426. break;
  1427. }
  1428. return;
  1429. }