rio_linux.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. /* rio_linux.c -- Linux driver for the Specialix RIO series cards.
  2. *
  3. *
  4. * (C) 1999 R.E.Wolff@BitWizard.nl
  5. *
  6. * Specialix pays for the development and support of this driver.
  7. * Please DO contact support@specialix.co.uk if you require
  8. * support. But please read the documentation (rio.txt) first.
  9. *
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be
  18. * useful, but WITHOUT ANY WARRANTY; without even the implied
  19. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  20. * PURPOSE. See the GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public
  23. * License along with this program; if not, write to the Free
  24. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  25. * USA.
  26. *
  27. * Revision history:
  28. * $Log: rio.c,v $
  29. * Revision 1.1 1999/07/11 10:13:54 wolff
  30. * Initial revision
  31. *
  32. * */
  33. #include <linux/module.h>
  34. #include <linux/config.h>
  35. #include <linux/kdev_t.h>
  36. #include <asm/io.h>
  37. #include <linux/kernel.h>
  38. #include <linux/sched.h>
  39. #include <linux/ioport.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/errno.h>
  42. #include <linux/tty.h>
  43. #include <linux/tty_flip.h>
  44. #include <linux/mm.h>
  45. #include <linux/serial.h>
  46. #include <linux/fcntl.h>
  47. #include <linux/major.h>
  48. #include <linux/delay.h>
  49. #include <linux/pci.h>
  50. #include <linux/slab.h>
  51. #include <linux/miscdevice.h>
  52. #include <linux/init.h>
  53. #include <linux/generic_serial.h>
  54. #include <asm/uaccess.h>
  55. #if BITS_PER_LONG != 32
  56. # error FIXME: this driver only works on 32-bit platforms
  57. #endif
  58. #include "linux_compat.h"
  59. #include "typdef.h"
  60. #include "pkt.h"
  61. #include "daemon.h"
  62. #include "rio.h"
  63. #include "riospace.h"
  64. #include "top.h"
  65. #include "cmdpkt.h"
  66. #include "map.h"
  67. #include "riotypes.h"
  68. #include "rup.h"
  69. #include "port.h"
  70. #include "riodrvr.h"
  71. #include "rioinfo.h"
  72. #include "func.h"
  73. #include "errors.h"
  74. #include "pci.h"
  75. #include "parmmap.h"
  76. #include "unixrup.h"
  77. #include "board.h"
  78. #include "host.h"
  79. #include "error.h"
  80. #include "phb.h"
  81. #include "link.h"
  82. #include "cmdblk.h"
  83. #include "route.h"
  84. #include "control.h"
  85. #include "cirrus.h"
  86. #include "rioioctl.h"
  87. #include "param.h"
  88. #include "list.h"
  89. #include "sam.h"
  90. #include "protsts.h"
  91. #include "rioboard.h"
  92. #include "rio_linux.h"
  93. /* I don't think that this driver can handle more than 512 ports on
  94. one machine. Specialix specifies max 4 boards in one machine. I don't
  95. know why. If you want to try anyway you'll have to increase the number
  96. of boards in rio.h. You'll have to allocate more majors if you need
  97. more than 512 ports.... */
  98. #ifndef RIO_NORMAL_MAJOR0
  99. /* This allows overriding on the compiler commandline, or in a "major.h"
  100. include or something like that */
  101. #define RIO_NORMAL_MAJOR0 154
  102. #define RIO_NORMAL_MAJOR1 156
  103. #endif
  104. #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
  105. #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
  106. #endif
  107. #ifndef RIO_WINDOW_LEN
  108. #define RIO_WINDOW_LEN 0x10000
  109. #endif
  110. /* Configurable options:
  111. (Don't be too sure that it'll work if you toggle them) */
  112. /* Am I paranoid or not ? ;-) */
  113. #undef RIO_PARANOIA_CHECK
  114. /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
  115. Hz, but it is user configurable. I don't recommend going above 1000
  116. Hz. The interrupt ratelimit might trigger if the interrupt is
  117. shared with a very active other device.
  118. undef this if you want to disable the check....
  119. */
  120. #define IRQ_RATE_LIMIT 200
  121. #if 0
  122. /* Not implemented */
  123. /*
  124. * The following defines are mostly for testing purposes. But if you need
  125. * some nice reporting in your syslog, you can define them also.
  126. */
  127. #define RIO_REPORT_FIFO
  128. #define RIO_REPORT_OVERRUN
  129. #endif
  130. /* These constants are derived from SCO Source */
  131. static struct Conf
  132. RIOConf =
  133. {
  134. /* locator */ "RIO Config here",
  135. /* startuptime */ HZ*2, /* how long to wait for card to run */
  136. /* slowcook */ 0, /* TRUE -> always use line disc. */
  137. /* intrpolltime */ 1, /* The frequency of OUR polls */
  138. /* breakinterval */ 25, /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/
  139. /* timer */ 10, /* mS */
  140. /* RtaLoadBase */ 0x7000,
  141. /* HostLoadBase */ 0x7C00,
  142. /* XpHz */ 5, /* number of Xprint hits per second */
  143. /* XpCps */ 120, /* Xprint characters per second */
  144. /* XpOn */ "\033d#", /* start Xprint for a wyse 60 */
  145. /* XpOff */ "\024", /* end Xprint for a wyse 60 */
  146. /* MaxXpCps */ 2000, /* highest Xprint speed */
  147. /* MinXpCps */ 10, /* slowest Xprint speed */
  148. /* SpinCmds */ 1, /* non-zero for mega fast boots */
  149. /* First Addr */ 0x0A0000, /* First address to look at */
  150. /* Last Addr */ 0xFF0000, /* Last address looked at */
  151. /* BufferSize */ 1024, /* Bytes per port of buffering */
  152. /* LowWater */ 256, /* how much data left before wakeup */
  153. /* LineLength */ 80, /* how wide is the console? */
  154. /* CmdTimeout */ HZ, /* how long a close command may take */
  155. };
  156. /* Function prototypes */
  157. static void rio_disable_tx_interrupts (void * ptr);
  158. static void rio_enable_tx_interrupts (void * ptr);
  159. static void rio_disable_rx_interrupts (void * ptr);
  160. static void rio_enable_rx_interrupts (void * ptr);
  161. static int rio_get_CD (void * ptr);
  162. static void rio_shutdown_port (void * ptr);
  163. static int rio_set_real_termios (void *ptr);
  164. static void rio_hungup (void *ptr);
  165. static void rio_close (void *ptr);
  166. static int rio_chars_in_buffer (void * ptr);
  167. static int rio_fw_ioctl (struct inode *inode, struct file *filp,
  168. unsigned int cmd, unsigned long arg);
  169. static int rio_init_drivers(void);
  170. static void my_hd (void *addr, int len);
  171. static struct tty_driver *rio_driver, *rio_driver2;
  172. /* The name "p" is a bit non-descript. But that's what the rio-lynxos
  173. sources use all over the place. */
  174. struct rio_info *p;
  175. int rio_debug;
  176. /* You can have the driver poll your card.
  177. - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
  178. This is used when the card cannot use an interrupt for some reason.
  179. */
  180. static int rio_poll = 1;
  181. /* These are the only open spaces in my computer. Yours may have more
  182. or less.... */
  183. static int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000};
  184. #define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int))
  185. /* Set the mask to all-ones. This alas, only supports 32 interrupts.
  186. Some architectures may need more. -- Changed to LONG to
  187. support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
  188. static long rio_irqmask = -1;
  189. MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
  190. MODULE_DESCRIPTION("RIO driver");
  191. MODULE_LICENSE("GPL");
  192. module_param(rio_poll, int, 0);
  193. module_param(rio_debug, int, 0644);
  194. module_param(rio_irqmask, long, 0);
  195. static struct real_driver rio_real_driver = {
  196. rio_disable_tx_interrupts,
  197. rio_enable_tx_interrupts,
  198. rio_disable_rx_interrupts,
  199. rio_enable_rx_interrupts,
  200. rio_get_CD,
  201. rio_shutdown_port,
  202. rio_set_real_termios,
  203. rio_chars_in_buffer,
  204. rio_close,
  205. rio_hungup,
  206. NULL
  207. };
  208. /*
  209. * Firmware loader driver specific routines
  210. *
  211. */
  212. static struct file_operations rio_fw_fops = {
  213. .owner = THIS_MODULE,
  214. .ioctl = rio_fw_ioctl,
  215. };
  216. static struct miscdevice rio_fw_device = {
  217. RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
  218. };
  219. #ifdef RIO_PARANOIA_CHECK
  220. /* This doesn't work. Who's paranoid around here? Not me! */
  221. static inline int rio_paranoia_check(struct rio_port const * port,
  222. char *name, const char *routine)
  223. {
  224. static const char *badmagic =
  225. KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
  226. static const char *badinfo =
  227. KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
  228. if (!port) {
  229. printk (badinfo, name, routine);
  230. return 1;
  231. }
  232. if (port->magic != RIO_MAGIC) {
  233. printk (badmagic, name, routine);
  234. return 1;
  235. }
  236. return 0;
  237. }
  238. #else
  239. #define rio_paranoia_check(a,b,c) 0
  240. #endif
  241. #ifdef DEBUG
  242. static void my_hd (void *ad, int len)
  243. {
  244. int i, j, ch;
  245. unsigned char *addr = ad;
  246. for (i=0;i<len;i+=16) {
  247. rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i);
  248. for (j=0;j<16;j++) {
  249. rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":"");
  250. }
  251. for (j=0;j<16;j++) {
  252. ch = addr[j+i];
  253. rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
  254. }
  255. rio_dprintk (RIO_DEBUG_PARAM, "\n");
  256. }
  257. }
  258. #else
  259. #define my_hd(ad,len) do{/* nothing*/ } while (0)
  260. #endif
  261. /* Delay a number of jiffies, allowing a signal to interrupt */
  262. int RIODelay (struct Port *PortP, int njiffies)
  263. {
  264. func_enter ();
  265. rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
  266. msleep_interruptible(jiffies_to_msecs(njiffies));
  267. func_exit();
  268. if (signal_pending(current))
  269. return RIO_FAIL;
  270. else
  271. return !RIO_FAIL;
  272. }
  273. /* Delay a number of jiffies, disallowing a signal to interrupt */
  274. int RIODelay_ni (struct Port *PortP, int njiffies)
  275. {
  276. func_enter ();
  277. rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
  278. msleep(jiffies_to_msecs(njiffies));
  279. func_exit();
  280. return !RIO_FAIL;
  281. }
  282. int rio_minor(struct tty_struct *tty)
  283. {
  284. return tty->index + (tty->driver == rio_driver) ? 0 : 256;
  285. }
  286. int rio_ismodem(struct tty_struct *tty)
  287. {
  288. return 1;
  289. }
  290. static int rio_set_real_termios (void *ptr)
  291. {
  292. int rv, modem;
  293. struct tty_struct *tty;
  294. func_enter();
  295. tty = ((struct Port *)ptr)->gs.tty;
  296. modem = rio_ismodem(tty);
  297. rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
  298. func_exit ();
  299. return rv;
  300. }
  301. static void rio_reset_interrupt (struct Host *HostP)
  302. {
  303. func_enter();
  304. switch( HostP->Type ) {
  305. case RIO_AT:
  306. case RIO_MCA:
  307. case RIO_PCI:
  308. WBYTE(HostP->ResetInt , 0xff);
  309. }
  310. func_exit();
  311. }
  312. static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
  313. {
  314. struct Host *HostP;
  315. func_enter ();
  316. HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
  317. rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n",
  318. irq, HostP->Ivec);
  319. /* AAargh! The order in which to do these things is essential and
  320. not trivial.
  321. - Rate limit goes before "recursive". Otherwise a series of
  322. recursive calls will hang the machine in the interrupt routine.
  323. - hardware twiddling goes before "recursive". Otherwise when we
  324. poll the card, and a recursive interrupt happens, we won't
  325. ack the card, so it might keep on interrupting us. (especially
  326. level sensitive interrupt systems like PCI).
  327. - Rate limit goes before hardware twiddling. Otherwise we won't
  328. catch a card that has gone bonkers.
  329. - The "initialized" test goes after the hardware twiddling. Otherwise
  330. the card will stick us in the interrupt routine again.
  331. - The initialized test goes before recursive.
  332. */
  333. #ifdef IRQ_RATE_LIMIT
  334. /* Aaargh! I'm ashamed. This costs more lines-of-code than the
  335. actual interrupt routine!. (Well, used to when I wrote that comment) */
  336. {
  337. static int lastjif;
  338. static int nintr=0;
  339. if (lastjif == jiffies) {
  340. if (++nintr > IRQ_RATE_LIMIT) {
  341. free_irq (HostP->Ivec, ptr);
  342. printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n",
  343. HostP->Ivec);
  344. }
  345. } else {
  346. lastjif = jiffies;
  347. nintr = 0;
  348. }
  349. }
  350. #endif
  351. rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
  352. if (HostP->Ivec == irq) {
  353. /* Tell the card we've noticed the interrupt. */
  354. rio_reset_interrupt (HostP);
  355. }
  356. if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
  357. return IRQ_HANDLED;
  358. if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
  359. printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n",
  360. (int) ptr, HostP->Ivec);
  361. return IRQ_HANDLED;
  362. }
  363. RIOServiceHost(p, HostP, irq);
  364. rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n",
  365. (int) ptr, HostP->Type);
  366. clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
  367. rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n",
  368. irq, HostP->Ivec);
  369. func_exit ();
  370. return IRQ_HANDLED;
  371. }
  372. static void rio_pollfunc (unsigned long data)
  373. {
  374. func_enter ();
  375. rio_interrupt (0, &p->RIOHosts[data], NULL);
  376. p->RIOHosts[data].timer.expires = jiffies + rio_poll;
  377. add_timer (&p->RIOHosts[data].timer);
  378. func_exit ();
  379. }
  380. /* ********************************************************************** *
  381. * Here are the routines that actually *
  382. * interface with the generic_serial driver *
  383. * ********************************************************************** */
  384. /* Ehhm. I don't know how to fiddle with interrupts on the Specialix
  385. cards. .... Hmm. Ok I figured it out. You don't. -- REW */
  386. static void rio_disable_tx_interrupts (void * ptr)
  387. {
  388. func_enter();
  389. /* port->gs.flags &= ~GS_TX_INTEN; */
  390. func_exit();
  391. }
  392. static void rio_enable_tx_interrupts (void * ptr)
  393. {
  394. struct Port *PortP = ptr;
  395. /* int hn; */
  396. func_enter();
  397. /* hn = PortP->HostP - p->RIOHosts;
  398. rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
  399. rio_interrupt (-1,(void *) hn, NULL); */
  400. RIOTxEnable((char *) PortP);
  401. /*
  402. * In general we cannot count on "tx empty" interrupts, although
  403. * the interrupt routine seems to be able to tell the difference.
  404. */
  405. PortP->gs.flags &= ~GS_TX_INTEN;
  406. func_exit();
  407. }
  408. static void rio_disable_rx_interrupts (void * ptr)
  409. {
  410. func_enter();
  411. func_exit();
  412. }
  413. static void rio_enable_rx_interrupts (void * ptr)
  414. {
  415. /* struct rio_port *port = ptr; */
  416. func_enter();
  417. func_exit();
  418. }
  419. /* Jeez. Isn't this simple? */
  420. static int rio_get_CD (void * ptr)
  421. {
  422. struct Port *PortP = ptr;
  423. int rv;
  424. func_enter();
  425. rv = (PortP->ModemState & MSVR1_CD) != 0;
  426. rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
  427. func_exit();
  428. return rv;
  429. }
  430. /* Jeez. Isn't this simple? Actually, we can sync with the actual port
  431. by just pushing stuff into the queue going to the port... */
  432. static int rio_chars_in_buffer (void * ptr)
  433. {
  434. func_enter();
  435. func_exit();
  436. return 0;
  437. }
  438. /* Nothing special here... */
  439. static void rio_shutdown_port (void * ptr)
  440. {
  441. struct Port *PortP;
  442. func_enter();
  443. PortP = (struct Port *)ptr;
  444. PortP->gs.tty = NULL;
  445. #if 0
  446. port->gs.flags &= ~ GS_ACTIVE;
  447. if (!port->gs.tty) {
  448. rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
  449. return;
  450. }
  451. if (!port->gs.tty->termios) {
  452. rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
  453. return;
  454. }
  455. if (port->gs.tty->termios->c_cflag & HUPCL) {
  456. rio_setsignals (port, 0, 0);
  457. }
  458. #endif
  459. func_exit();
  460. }
  461. /* I haven't the foggiest why the decrement use count has to happen
  462. here. The whole linux serial drivers stuff needs to be redesigned.
  463. My guess is that this is a hack to minimize the impact of a bug
  464. elsewhere. Thinking about it some more. (try it sometime) Try
  465. running minicom on a serial port that is driven by a modularized
  466. driver. Have the modem hangup. Then remove the driver module. Then
  467. exit minicom. I expect an "oops". -- REW */
  468. static void rio_hungup (void *ptr)
  469. {
  470. struct Port *PortP;
  471. func_enter();
  472. PortP = (struct Port *)ptr;
  473. PortP->gs.tty = NULL;
  474. func_exit ();
  475. }
  476. /* The standard serial_close would become shorter if you'd wrap it like
  477. this.
  478. rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
  479. */
  480. static void rio_close (void *ptr)
  481. {
  482. struct Port *PortP;
  483. func_enter ();
  484. PortP = (struct Port *)ptr;
  485. riotclose (ptr);
  486. if(PortP->gs.count) {
  487. printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
  488. PortP->gs.count = 0;
  489. }
  490. PortP->gs.tty = NULL;
  491. func_exit ();
  492. }
  493. static int rio_fw_ioctl (struct inode *inode, struct file *filp,
  494. unsigned int cmd, unsigned long arg)
  495. {
  496. int rc = 0;
  497. func_enter();
  498. /* The "dev" argument isn't used. */
  499. rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
  500. func_exit ();
  501. return rc;
  502. }
  503. extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
  504. int command, int len, int arg);
  505. static int rio_ioctl (struct tty_struct * tty, struct file * filp,
  506. unsigned int cmd, unsigned long arg)
  507. {
  508. int rc;
  509. struct Port *PortP;
  510. int ival;
  511. func_enter();
  512. PortP = (struct Port *)tty->driver_data;
  513. rc = 0;
  514. switch (cmd) {
  515. #if 0
  516. case TIOCGSOFTCAR:
  517. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  518. (unsigned int *) arg);
  519. break;
  520. #endif
  521. case TIOCSSOFTCAR:
  522. if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
  523. tty->termios->c_cflag =
  524. (tty->termios->c_cflag & ~CLOCAL) |
  525. (ival ? CLOCAL : 0);
  526. }
  527. break;
  528. case TIOCGSERIAL:
  529. rc = -EFAULT;
  530. if (access_ok(VERIFY_WRITE, (void *) arg,
  531. sizeof(struct serial_struct)))
  532. rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
  533. break;
  534. case TCSBRK:
  535. if ( PortP->State & RIO_DELETED ) {
  536. rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
  537. rc = -EIO;
  538. } else {
  539. if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
  540. rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
  541. rc = -EIO;
  542. }
  543. }
  544. break;
  545. case TCSBRKP:
  546. if ( PortP->State & RIO_DELETED ) {
  547. rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
  548. rc = -EIO;
  549. } else {
  550. int l;
  551. l = arg?arg*100:250;
  552. if (l > 255) l = 255;
  553. if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
  554. rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
  555. rc = -EIO;
  556. }
  557. }
  558. break;
  559. case TIOCSSERIAL:
  560. rc = -EFAULT;
  561. if (access_ok(VERIFY_READ, (void *) arg,
  562. sizeof(struct serial_struct)))
  563. rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
  564. break;
  565. #if 0
  566. /*
  567. * note: these IOCTLs no longer reach here. Use
  568. * tiocmset/tiocmget driver methods instead. The
  569. * #if 0 disablement predates this comment.
  570. */
  571. case TIOCMGET:
  572. rc = -EFAULT;
  573. if (access_ok(VERIFY_WRITE, (void *) arg,
  574. sizeof(unsigned int))) {
  575. rc = 0;
  576. ival = rio_getsignals(port);
  577. put_user(ival, (unsigned int *) arg);
  578. }
  579. break;
  580. case TIOCMBIS:
  581. if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
  582. rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
  583. ((ival & TIOCM_RTS) ? 1 : -1));
  584. }
  585. break;
  586. case TIOCMBIC:
  587. if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
  588. rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
  589. ((ival & TIOCM_RTS) ? 0 : -1));
  590. }
  591. break;
  592. case TIOCMSET:
  593. if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
  594. rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
  595. ((ival & TIOCM_RTS) ? 1 : 0));
  596. }
  597. break;
  598. #endif
  599. default:
  600. rc = -ENOIOCTLCMD;
  601. break;
  602. }
  603. func_exit();
  604. return rc;
  605. }
  606. /* The throttle/unthrottle scheme for the Specialix card is different
  607. * from other drivers and deserves some explanation.
  608. * The Specialix hardware takes care of XON/XOFF
  609. * and CTS/RTS flow control itself. This means that all we have to
  610. * do when signalled by the upper tty layer to throttle/unthrottle is
  611. * to make a note of it here. When we come to read characters from the
  612. * rx buffers on the card (rio_receive_chars()) we look to see if the
  613. * upper layer can accept more (as noted here in rio_rx_throt[]).
  614. * If it can't we simply don't remove chars from the cards buffer.
  615. * When the tty layer can accept chars, we again note that here and when
  616. * rio_receive_chars() is called it will remove them from the cards buffer.
  617. * The card will notice that a ports buffer has drained below some low
  618. * water mark and will unflow control the line itself, using whatever
  619. * flow control scheme is in use for that port. -- Simon Allen
  620. */
  621. static void rio_throttle (struct tty_struct * tty)
  622. {
  623. struct Port *port = (struct Port *)tty->driver_data;
  624. func_enter();
  625. /* If the port is using any type of input flow
  626. * control then throttle the port.
  627. */
  628. if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
  629. port->State |= RIO_THROTTLE_RX;
  630. }
  631. func_exit();
  632. }
  633. static void rio_unthrottle (struct tty_struct * tty)
  634. {
  635. struct Port *port = (struct Port *)tty->driver_data;
  636. func_enter();
  637. /* Always unthrottle even if flow control is not enabled on
  638. * this port in case we disabled flow control while the port
  639. * was throttled
  640. */
  641. port->State &= ~RIO_THROTTLE_RX;
  642. func_exit();
  643. return;
  644. }
  645. /* ********************************************************************** *
  646. * Here are the initialization routines. *
  647. * ********************************************************************** */
  648. static struct vpd_prom *get_VPD_PROM (struct Host *hp)
  649. {
  650. static struct vpd_prom vpdp;
  651. char *p;
  652. int i;
  653. func_enter();
  654. rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
  655. hp->Caddr + RIO_VPD_ROM);
  656. p = (char *) &vpdp;
  657. for (i=0;i< sizeof (struct vpd_prom);i++)
  658. *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
  659. /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
  660. /* Terminate the identifier string.
  661. *** requires one extra byte in struct vpd_prom *** */
  662. *p++=0;
  663. if (rio_debug & RIO_DEBUG_PROBE)
  664. my_hd ((char *)&vpdp, 0x20);
  665. func_exit();
  666. return &vpdp;
  667. }
  668. static struct tty_operations rio_ops = {
  669. .open = riotopen,
  670. .close = gs_close,
  671. .write = gs_write,
  672. .put_char = gs_put_char,
  673. .flush_chars = gs_flush_chars,
  674. .write_room = gs_write_room,
  675. .chars_in_buffer = gs_chars_in_buffer,
  676. .flush_buffer = gs_flush_buffer,
  677. .ioctl = rio_ioctl,
  678. .throttle = rio_throttle,
  679. .unthrottle = rio_unthrottle,
  680. .set_termios = gs_set_termios,
  681. .stop = gs_stop,
  682. .start = gs_start,
  683. .hangup = gs_hangup,
  684. };
  685. static int rio_init_drivers(void)
  686. {
  687. int error = -ENOMEM;
  688. rio_driver = alloc_tty_driver(256);
  689. if (!rio_driver)
  690. goto out;
  691. rio_driver2 = alloc_tty_driver(256);
  692. if (!rio_driver2)
  693. goto out1;
  694. func_enter();
  695. rio_driver->owner = THIS_MODULE;
  696. rio_driver->driver_name = "specialix_rio";
  697. rio_driver->name = "ttySR";
  698. rio_driver->major = RIO_NORMAL_MAJOR0;
  699. rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
  700. rio_driver->subtype = SERIAL_TYPE_NORMAL;
  701. rio_driver->init_termios = tty_std_termios;
  702. rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  703. rio_driver->flags = TTY_DRIVER_REAL_RAW;
  704. tty_set_operations(rio_driver, &rio_ops);
  705. rio_driver2->owner = THIS_MODULE;
  706. rio_driver2->driver_name = "specialix_rio";
  707. rio_driver2->name = "ttySR";
  708. rio_driver2->major = RIO_NORMAL_MAJOR1;
  709. rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
  710. rio_driver2->subtype = SERIAL_TYPE_NORMAL;
  711. rio_driver2->init_termios = tty_std_termios;
  712. rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  713. rio_driver2->flags = TTY_DRIVER_REAL_RAW;
  714. tty_set_operations(rio_driver2, &rio_ops);
  715. rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
  716. if ((error = tty_register_driver(rio_driver)))
  717. goto out2;
  718. if ((error = tty_register_driver(rio_driver2)))
  719. goto out3;
  720. func_exit();
  721. return 0;
  722. out3:
  723. tty_unregister_driver(rio_driver);
  724. out2:
  725. put_tty_driver(rio_driver2);
  726. out1:
  727. put_tty_driver(rio_driver);
  728. out:
  729. printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
  730. error);
  731. return 1;
  732. }
  733. static void * ckmalloc (int size)
  734. {
  735. void *p;
  736. p = kmalloc(size, GFP_KERNEL);
  737. if (p)
  738. memset(p, 0, size);
  739. return p;
  740. }
  741. static int rio_init_datastructures (void)
  742. {
  743. int i;
  744. struct Port *port;
  745. func_enter();
  746. /* Many drivers statically allocate the maximum number of ports
  747. There is no reason not to allocate them dynamically. Is there? -- REW */
  748. /* However, the RIO driver allows users to configure their first
  749. RTA as the ports numbered 504-511. We therefore need to allocate
  750. the whole range. :-( -- REW */
  751. #define RI_SZ sizeof(struct rio_info)
  752. #define HOST_SZ sizeof(struct Host)
  753. #define PORT_SZ sizeof(struct Port *)
  754. #define TMIO_SZ sizeof(struct termios *)
  755. rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n",
  756. RI_SZ,
  757. RIO_HOSTS * HOST_SZ,
  758. RIO_PORTS * PORT_SZ,
  759. RIO_PORTS * TMIO_SZ,
  760. RIO_PORTS * TMIO_SZ);
  761. if (!(p = ckmalloc ( RI_SZ))) goto free0;
  762. if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
  763. if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
  764. p->RIOConf = RIOConf;
  765. rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n",
  766. p, p->RIOHosts, p->RIOPortp);
  767. #if 1
  768. for (i = 0; i < RIO_PORTS; i++) {
  769. port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
  770. if (!port) {
  771. goto free6;
  772. }
  773. rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
  774. port->PortNum = i;
  775. port->gs.magic = RIO_MAGIC;
  776. port->gs.close_delay = HZ/2;
  777. port->gs.closing_wait = 30 * HZ;
  778. port->gs.rd = &rio_real_driver;
  779. spin_lock_init(&port->portSem);
  780. /*
  781. * Initializing wait queue
  782. */
  783. init_waitqueue_head(&port->gs.open_wait);
  784. init_waitqueue_head(&port->gs.close_wait);
  785. }
  786. #else
  787. /* We could postpone initializing them to when they are configured. */
  788. #endif
  789. if (rio_debug & RIO_DEBUG_INIT) {
  790. my_hd (&rio_real_driver, sizeof (rio_real_driver));
  791. }
  792. func_exit();
  793. return 0;
  794. free6:for (i--;i>=0;i--)
  795. kfree (p->RIOPortp[i]);
  796. /*free5:
  797. free4:
  798. free3:*/kfree (p->RIOPortp);
  799. free2:kfree (p->RIOHosts);
  800. free1:
  801. rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n",
  802. p, p->RIOHosts, p->RIOPortp);
  803. kfree(p);
  804. free0:
  805. return -ENOMEM;
  806. }
  807. static void __exit rio_release_drivers(void)
  808. {
  809. func_enter();
  810. tty_unregister_driver(rio_driver2);
  811. tty_unregister_driver(rio_driver);
  812. put_tty_driver(rio_driver2);
  813. put_tty_driver(rio_driver);
  814. func_exit();
  815. }
  816. #ifdef CONFIG_PCI
  817. /* This was written for SX, but applies to RIO too...
  818. (including bugs....)
  819. There is another bit besides Bit 17. Turning that bit off
  820. (on boards shipped with the fix in the eeprom) results in a
  821. hang on the next access to the card.
  822. */
  823. /********************************************************
  824. * Setting bit 17 in the CNTRL register of the PLX 9050 *
  825. * chip forces a retry on writes while a read is pending.*
  826. * This is to prevent the card locking up on Intel Xeon *
  827. * multiprocessor systems with the NX chipset. -- NV *
  828. ********************************************************/
  829. /* Newer cards are produced with this bit set from the configuration
  830. EEprom. As the bit is read/write for the CPU, we can fix it here,
  831. if we detect that it isn't set correctly. -- REW */
  832. static void fix_rio_pci (struct pci_dev *pdev)
  833. {
  834. unsigned int hwbase;
  835. unsigned long rebase;
  836. unsigned int t;
  837. #define CNTRL_REG_OFFSET 0x50
  838. #define CNTRL_REG_GOODVALUE 0x18260000
  839. pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
  840. hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
  841. rebase = (ulong) ioremap(hwbase, 0x80);
  842. t = readl (rebase + CNTRL_REG_OFFSET);
  843. if (t != CNTRL_REG_GOODVALUE) {
  844. printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n",
  845. t, CNTRL_REG_GOODVALUE);
  846. writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
  847. }
  848. iounmap((char*) rebase);
  849. }
  850. #endif
  851. static int __init rio_init(void)
  852. {
  853. int found = 0;
  854. int i;
  855. struct Host *hp;
  856. int retval;
  857. struct vpd_prom *vpdp;
  858. int okboard;
  859. #ifdef CONFIG_PCI
  860. struct pci_dev *pdev = NULL;
  861. unsigned int tint;
  862. unsigned short tshort;
  863. #endif
  864. func_enter();
  865. rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n",
  866. rio_debug);
  867. if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
  868. printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
  869. "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
  870. rio_debug=-1;
  871. }
  872. if (misc_register(&rio_fw_device) < 0) {
  873. printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
  874. return -EIO;
  875. }
  876. retval = rio_init_datastructures ();
  877. if (retval < 0) {
  878. misc_deregister(&rio_fw_device);
  879. return retval;
  880. }
  881. #ifdef CONFIG_PCI
  882. /* First look for the JET devices: */
  883. while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
  884. PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
  885. pdev))) {
  886. if (pci_enable_device(pdev)) continue;
  887. /* Specialix has a whole bunch of cards with
  888. 0x2000 as the device ID. They say its because
  889. the standard requires it. Stupid standard. */
  890. /* It seems that reading a word doesn't work reliably on 2.0.
  891. Also, reading a non-aligned dword doesn't work. So we read the
  892. whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
  893. ourselves */
  894. /* I don't know why the define doesn't work, constant 0x2c does --REW */
  895. pci_read_config_dword (pdev, 0x2c, &tint);
  896. tshort = (tint >> 16) & 0xffff;
  897. rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
  898. if (tshort != 0x0100) {
  899. rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n",
  900. tshort);
  901. continue;
  902. }
  903. rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
  904. pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
  905. hp = &p->RIOHosts[p->RIONumHosts];
  906. hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
  907. hp->Ivec = pdev->irq;
  908. if (((1 << hp->Ivec) & rio_irqmask) == 0)
  909. hp->Ivec = 0;
  910. hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
  911. hp->CardP = (struct DpRam *) hp->Caddr;
  912. hp->Type = RIO_PCI;
  913. hp->Copy = rio_pcicopy;
  914. hp->Mode = RIO_PCI_BOOT_FROM_RAM;
  915. spin_lock_init(&hp->HostLock);
  916. rio_reset_interrupt (hp);
  917. rio_start_card_running (hp);
  918. rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
  919. (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
  920. p->RIOHosts[p->RIONumHosts].Caddr);
  921. if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
  922. p->RIOHosts[p->RIONumHosts].Caddr,
  923. RIO_PCI, 0 ) == RIO_SUCCESS) {
  924. rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
  925. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
  926. p->RIOHosts[p->RIONumHosts].UniqueNum =
  927. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
  928. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
  929. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
  930. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
  931. rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
  932. p->RIOHosts[p->RIONumHosts].UniqueNum);
  933. fix_rio_pci (pdev);
  934. p->RIOLastPCISearch = RIO_SUCCESS;
  935. p->RIONumHosts++;
  936. found++;
  937. } else {
  938. iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
  939. }
  940. }
  941. /* Then look for the older PCI card.... : */
  942. /* These older PCI cards have problems (only byte-mode access is
  943. supported), which makes them a bit awkward to support.
  944. They also have problems sharing interrupts. Be careful.
  945. (The driver now refuses to share interrupts for these
  946. cards. This should be sufficient).
  947. */
  948. /* Then look for the older RIO/PCI devices: */
  949. while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
  950. PCI_DEVICE_ID_SPECIALIX_RIO,
  951. pdev))) {
  952. if (pci_enable_device(pdev)) continue;
  953. #ifdef CONFIG_RIO_OLDPCI
  954. pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
  955. hp = &p->RIOHosts[p->RIONumHosts];
  956. hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
  957. hp->Ivec = pdev->irq;
  958. if (((1 << hp->Ivec) & rio_irqmask) == 0)
  959. hp->Ivec = 0;
  960. hp->Ivec |= 0x8000; /* Mark as non-sharable */
  961. hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
  962. hp->CardP = (struct DpRam *) hp->Caddr;
  963. hp->Type = RIO_PCI;
  964. hp->Copy = rio_pcicopy;
  965. hp->Mode = RIO_PCI_BOOT_FROM_RAM;
  966. spin_lock_init(&hp->HostLock);
  967. rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
  968. rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
  969. rio_reset_interrupt (hp);
  970. rio_start_card_running (hp);
  971. rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
  972. (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
  973. p->RIOHosts[p->RIONumHosts].Caddr);
  974. if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
  975. p->RIOHosts[p->RIONumHosts].Caddr,
  976. RIO_PCI, 0 ) == RIO_SUCCESS) {
  977. WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
  978. p->RIOHosts[p->RIONumHosts].UniqueNum =
  979. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
  980. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
  981. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
  982. ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
  983. rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
  984. p->RIOHosts[p->RIONumHosts].UniqueNum);
  985. p->RIOLastPCISearch = RIO_SUCCESS;
  986. p->RIONumHosts++;
  987. found++;
  988. } else {
  989. iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
  990. }
  991. #else
  992. printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
  993. "compiled to support it.\n");
  994. #endif
  995. }
  996. #endif /* PCI */
  997. /* Now probe for ISA cards... */
  998. for (i=0;i<NR_RIO_ADDRS;i++) {
  999. hp = &p->RIOHosts[p->RIONumHosts];
  1000. hp->PaddrP = rio_probe_addrs[i];
  1001. /* There was something about the IRQs of these cards. 'Forget what.--REW */
  1002. hp->Ivec = 0;
  1003. hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
  1004. hp->CardP = (struct DpRam *) hp->Caddr;
  1005. hp->Type = RIO_AT;
  1006. hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
  1007. * -- YES! this is now a normal copy. Only the
  1008. * old PCI card uses the special PCI copy.
  1009. * Moreover, the ISA card will work with the
  1010. * special PCI copy anyway. -- REW */
  1011. hp->Mode = 0;
  1012. spin_lock_init(&hp->HostLock);
  1013. vpdp = get_VPD_PROM (hp);
  1014. rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
  1015. okboard = 0;
  1016. if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
  1017. (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
  1018. (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
  1019. /* Board is present... */
  1020. if (RIOBoardTest (hp->PaddrP,
  1021. hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
  1022. /* ... and feeling fine!!!! */
  1023. rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
  1024. p->RIOHosts[p->RIONumHosts].UniqueNum);
  1025. if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
  1026. rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
  1027. p->RIONumHosts,
  1028. p->RIOHosts[p->RIONumHosts-1].UniqueNum);
  1029. okboard++;
  1030. found++;
  1031. }
  1032. }
  1033. if (!okboard)
  1034. iounmap ((char*) (hp->Caddr));
  1035. }
  1036. }
  1037. for (i=0;i<p->RIONumHosts;i++) {
  1038. hp = &p->RIOHosts[i];
  1039. if (hp->Ivec) {
  1040. int mode = SA_SHIRQ;
  1041. if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
  1042. rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
  1043. retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
  1044. rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
  1045. if (retval) {
  1046. printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
  1047. hp->Ivec = 0;
  1048. }
  1049. rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
  1050. if (hp->Ivec != 0){
  1051. rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
  1052. hp->Mode |= RIO_PCI_INT_ENABLE;
  1053. } else
  1054. hp->Mode &= !RIO_PCI_INT_ENABLE;
  1055. rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
  1056. rio_start_card_running (hp);
  1057. }
  1058. /* Init the timer "always" to make sure that it can safely be
  1059. deleted when we unload... */
  1060. init_timer (&hp->timer);
  1061. if (!hp->Ivec) {
  1062. rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n",
  1063. rio_poll);
  1064. hp->timer.data = i;
  1065. hp->timer.function = rio_pollfunc;
  1066. hp->timer.expires = jiffies + rio_poll;
  1067. add_timer (&hp->timer);
  1068. }
  1069. }
  1070. if (found) {
  1071. rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
  1072. rio_init_drivers ();
  1073. } else {
  1074. /* deregister the misc device we created earlier */
  1075. misc_deregister(&rio_fw_device);
  1076. }
  1077. func_exit();
  1078. return found?0:-EIO;
  1079. }
  1080. static void __exit rio_exit (void)
  1081. {
  1082. int i;
  1083. struct Host *hp;
  1084. func_enter();
  1085. for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
  1086. RIOHostReset (hp->Type, hp->CardP, hp->Slot);
  1087. if (hp->Ivec) {
  1088. free_irq (hp->Ivec, hp);
  1089. rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
  1090. }
  1091. /* It is safe/allowed to del_timer a non-active timer */
  1092. del_timer (&hp->timer);
  1093. }
  1094. if (misc_deregister(&rio_fw_device) < 0) {
  1095. printk (KERN_INFO "rio: couldn't deregister control-device\n");
  1096. }
  1097. rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
  1098. rio_release_drivers ();
  1099. /* Release dynamically allocated memory */
  1100. kfree (p->RIOPortp);
  1101. kfree (p->RIOHosts);
  1102. kfree (p);
  1103. func_exit();
  1104. }
  1105. module_init(rio_init);
  1106. module_exit(rio_exit);
  1107. /*
  1108. * Anybody who knows why this doesn't work for me, please tell me -- REW.
  1109. * Snatched from scsi.c (fixed one spelling error):
  1110. * Overrides for Emacs so that we follow Linus' tabbing style.
  1111. * Emacs will notice this stuff at the end of the file and automatically
  1112. * adjust the settings for this buffer only. This must remain at the end
  1113. * of the file.
  1114. * ---------------------------------------------------------------------------
  1115. * Local Variables:
  1116. * c-indent-level: 4
  1117. * c-brace-imaginary-offset: 0
  1118. * c-brace-offset: -4
  1119. * c-argdecl-indent: 4
  1120. * c-label-offset: -4
  1121. * c-continued-statement-offset: 4
  1122. * c-continued-brace-offset: 0
  1123. * indent-tabs-mode: nil
  1124. * tab-width: 8
  1125. * End:
  1126. */