2 /* rio_linux.c -- Linux driver for the Specialix RIO series cards.
5 * (C) 1999 R.E.Wolff@BitWizard.nl
7 * Specialix pays for the development and support of this driver.
8 * Please DO contact support@specialix.co.uk if you require
9 * support. But please read the documentation (rio.txt) first.
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21 * PURPOSE. See the GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public
24 * License along with this program; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
30 * Revision 1.1 1999/07/11 10:13:54 wolff
35 #include <linux/module.h>
36 #include <linux/config.h>
37 #include <linux/kdev_t.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/ioport.h>
42 #include <linux/interrupt.h>
43 #include <linux/errno.h>
44 #include <linux/tty.h>
45 #include <linux/tty_flip.h>
47 #include <linux/serial.h>
48 #include <linux/fcntl.h>
49 #include <linux/major.h>
50 #include <linux/delay.h>
51 #include <linux/pci.h>
52 #include <linux/slab.h>
53 #include <linux/miscdevice.h>
54 #include <linux/init.h>
56 #include <linux/generic_serial.h>
57 #include <asm/uaccess.h>
59 #include "linux_compat.h"
96 #include "rio_linux.h"
98 /* I don't think that this driver can handle more than 512 ports on
99 one machine. Specialix specifies max 4 boards in one machine. I don't
100 know why. If you want to try anyway you'll have to increase the number
101 of boards in rio.h. You'll have to allocate more majors if you need
102 more than 512 ports.... */
104 #ifndef RIO_NORMAL_MAJOR0
105 /* This allows overriding on the compiler commandline, or in a "major.h"
106 include or something like that */
107 #define RIO_NORMAL_MAJOR0 154
108 #define RIO_NORMAL_MAJOR1 156
111 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
112 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
115 #ifndef RIO_WINDOW_LEN
116 #define RIO_WINDOW_LEN 0x10000
120 /* Configurable options:
121 (Don't be too sure that it'll work if you toggle them) */
123 /* Am I paranoid or not ? ;-) */
124 #undef RIO_PARANOIA_CHECK
127 /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
128 Hz, but it is user configurable. I don't recommend going above 1000
129 Hz. The interrupt ratelimit might trigger if the interrupt is
130 shared with a very active other device.
131 undef this if you want to disable the check....
133 #define IRQ_RATE_LIMIT 200
136 /* Not implemented */
138 * The following defines are mostly for testing purposes. But if you need
139 * some nice reporting in your syslog, you can define them also.
141 #define RIO_REPORT_FIFO
142 #define RIO_REPORT_OVERRUN
146 /* These constants are derived from SCO Source */
150 /* locator */ "RIO Config here",
151 /* startuptime */ HZ*2, /* how long to wait for card to run */
152 /* slowcook */ 0, /* TRUE -> always use line disc. */
153 /* intrpolltime */ 1, /* The frequency of OUR polls */
154 /* breakinterval */ 25, /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/
155 /* timer */ 10, /* mS */
156 /* RtaLoadBase */ 0x7000,
157 /* HostLoadBase */ 0x7C00,
158 /* XpHz */ 5, /* number of Xprint hits per second */
159 /* XpCps */ 120, /* Xprint characters per second */
160 /* XpOn */ "\033d#", /* start Xprint for a wyse 60 */
161 /* XpOff */ "\024", /* end Xprint for a wyse 60 */
162 /* MaxXpCps */ 2000, /* highest Xprint speed */
163 /* MinXpCps */ 10, /* slowest Xprint speed */
164 /* SpinCmds */ 1, /* non-zero for mega fast boots */
165 /* First Addr */ 0x0A0000, /* First address to look at */
166 /* Last Addr */ 0xFF0000, /* Last address looked at */
167 /* BufferSize */ 1024, /* Bytes per port of buffering */
168 /* LowWater */ 256, /* how much data left before wakeup */
169 /* LineLength */ 80, /* how wide is the console? */
170 /* CmdTimeout */ HZ, /* how long a close command may take */
176 /* Function prototypes */
178 static void rio_disable_tx_interrupts (void * ptr);
179 static void rio_enable_tx_interrupts (void * ptr);
180 static void rio_disable_rx_interrupts (void * ptr);
181 static void rio_enable_rx_interrupts (void * ptr);
182 static int rio_get_CD (void * ptr);
183 static void rio_shutdown_port (void * ptr);
184 static int rio_set_real_termios (void *ptr);
185 static void rio_hungup (void *ptr);
186 static void rio_close (void *ptr);
187 static int rio_chars_in_buffer (void * ptr);
188 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
189 unsigned int cmd, unsigned long arg);
190 static int rio_init_drivers(void);
192 static void my_hd (void *addr, int len);
194 static struct tty_driver *rio_driver, *rio_driver2;
196 /* The name "p" is a bit non-descript. But that's what the rio-lynxos
197 sources use all over the place. */
203 /* You can have the driver poll your card.
204 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
205 This is used when the card cannot use an interrupt for some reason.
207 static int rio_poll = 1;
210 /* These are the only open spaces in my computer. Yours may have more
212 static int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000};
214 #define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
217 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
218 Some architectures may need more. -- Changed to LONG to
219 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
220 static long rio_irqmask = -1;
222 MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
223 MODULE_DESCRIPTION("RIO driver");
224 MODULE_LICENSE("GPL");
225 module_param(rio_poll, int, 0);
226 module_param(rio_debug, int, 0644);
227 module_param(rio_irqmask, long, 0);
229 static struct real_driver rio_real_driver = {
230 rio_disable_tx_interrupts,
231 rio_enable_tx_interrupts,
232 rio_disable_rx_interrupts,
233 rio_enable_rx_interrupts,
236 rio_set_real_termios,
244 * Firmware loader driver specific routines
248 static struct file_operations rio_fw_fops = {
249 .owner = THIS_MODULE,
250 .ioctl = rio_fw_ioctl,
253 static struct miscdevice rio_fw_device = {
254 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
261 #ifdef RIO_PARANOIA_CHECK
263 /* This doesn't work. Who's paranoid around here? Not me! */
265 static inline int rio_paranoia_check(struct rio_port const * port,
266 char *name, const char *routine)
269 static const char *badmagic =
270 KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
271 static const char *badinfo =
272 KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
275 printk (badinfo, name, routine);
278 if (port->magic != RIO_MAGIC) {
279 printk (badmagic, name, routine);
286 #define rio_paranoia_check(a,b,c) 0
291 static void my_hd (void *ad, int len)
294 unsigned char *addr = ad;
296 for (i=0;i<len;i+=16) {
297 rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i);
299 rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":"");
303 rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
305 rio_dprintk (RIO_DEBUG_PARAM, "\n");
309 #define my_hd(ad,len) do{/* nothing*/ } while (0)
313 /* Delay a number of jiffies, allowing a signal to interrupt */
314 int RIODelay (struct Port *PortP, int njiffies)
318 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
319 msleep_interruptible(jiffies_to_msecs(njiffies));
322 if (signal_pending(current))
329 /* Delay a number of jiffies, disallowing a signal to interrupt */
330 int RIODelay_ni (struct Port *PortP, int njiffies)
334 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
335 msleep(jiffies_to_msecs(njiffies));
341 int rio_minor(struct tty_struct *tty)
343 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
347 int rio_ismodem(struct tty_struct *tty)
353 static int rio_set_real_termios (void *ptr)
356 struct tty_struct *tty;
359 tty = ((struct Port *)ptr)->gs.tty;
361 modem = rio_ismodem(tty);
363 rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
371 static void rio_reset_interrupt (struct Host *HostP)
375 switch( HostP->Type ) {
379 WBYTE(HostP->ResetInt , 0xff);
386 static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
391 HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
392 rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n",
395 /* AAargh! The order in which to do these things is essential and
398 - Rate limit goes before "recursive". Otherwise a series of
399 recursive calls will hang the machine in the interrupt routine.
401 - hardware twiddling goes before "recursive". Otherwise when we
402 poll the card, and a recursive interrupt happens, we won't
403 ack the card, so it might keep on interrupting us. (especially
404 level sensitive interrupt systems like PCI).
406 - Rate limit goes before hardware twiddling. Otherwise we won't
407 catch a card that has gone bonkers.
409 - The "initialized" test goes after the hardware twiddling. Otherwise
410 the card will stick us in the interrupt routine again.
412 - The initialized test goes before recursive.
417 #ifdef IRQ_RATE_LIMIT
418 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
419 actual interrupt routine!. (Well, used to when I wrote that comment) */
424 if (lastjif == jiffies) {
425 if (++nintr > IRQ_RATE_LIMIT) {
426 free_irq (HostP->Ivec, ptr);
427 printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n",
436 rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
437 if (HostP->Ivec == irq) {
438 /* Tell the card we've noticed the interrupt. */
439 rio_reset_interrupt (HostP);
442 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
445 if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
446 printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n",
447 (int) ptr, HostP->Ivec);
451 RIOServiceHost(p, HostP, irq);
453 rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n",
454 (int) ptr, HostP->Type);
456 clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
457 rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n",
464 static void rio_pollfunc (unsigned long data)
468 rio_interrupt (0, &p->RIOHosts[data], NULL);
469 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
470 add_timer (&p->RIOHosts[data].timer);
476 /* ********************************************************************** *
477 * Here are the routines that actually *
478 * interface with the generic_serial driver *
479 * ********************************************************************** */
481 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix
482 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
484 static void rio_disable_tx_interrupts (void * ptr)
488 /* port->gs.flags &= ~GS_TX_INTEN; */
494 static void rio_enable_tx_interrupts (void * ptr)
496 struct Port *PortP = ptr;
501 /* hn = PortP->HostP - p->RIOHosts;
503 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
504 rio_interrupt (-1,(void *) hn, NULL); */
506 RIOTxEnable((char *) PortP);
509 * In general we cannot count on "tx empty" interrupts, although
510 * the interrupt routine seems to be able to tell the difference.
512 PortP->gs.flags &= ~GS_TX_INTEN;
518 static void rio_disable_rx_interrupts (void * ptr)
524 static void rio_enable_rx_interrupts (void * ptr)
526 /* struct rio_port *port = ptr; */
532 /* Jeez. Isn't this simple? */
533 static int rio_get_CD (void * ptr)
535 struct Port *PortP = ptr;
539 rv = (PortP->ModemState & MSVR1_CD) != 0;
541 rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
548 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
549 by just pushing stuff into the queue going to the port... */
550 static int rio_chars_in_buffer (void * ptr)
559 /* Nothing special here... */
560 static void rio_shutdown_port (void * ptr)
566 PortP = (struct Port *)ptr;
567 PortP->gs.tty = NULL;
569 port->gs.flags &= ~ GS_ACTIVE;
571 rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
574 if (!port->gs.tty->termios) {
575 rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
578 if (port->gs.tty->termios->c_cflag & HUPCL) {
579 rio_setsignals (port, 0, 0);
587 /* I haven't the foggiest why the decrement use count has to happen
588 here. The whole linux serial drivers stuff needs to be redesigned.
589 My guess is that this is a hack to minimize the impact of a bug
590 elsewhere. Thinking about it some more. (try it sometime) Try
591 running minicom on a serial port that is driven by a modularized
592 driver. Have the modem hangup. Then remove the driver module. Then
593 exit minicom. I expect an "oops". -- REW */
594 static void rio_hungup (void *ptr)
600 PortP = (struct Port *)ptr;
601 PortP->gs.tty = NULL;
607 /* The standard serial_close would become shorter if you'd wrap it like
609 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
611 static void rio_close (void *ptr)
617 PortP = (struct Port *)ptr;
621 if(PortP->gs.count) {
622 printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
626 PortP->gs.tty = NULL;
632 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
633 unsigned int cmd, unsigned long arg)
638 /* The "dev" argument isn't used. */
639 rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
645 extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
646 int command, int len, int arg);
648 static int rio_ioctl (struct tty_struct * tty, struct file * filp,
649 unsigned int cmd, unsigned long arg)
657 PortP = (struct Port *)tty->driver_data;
663 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
664 (unsigned int *) arg);
668 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
669 tty->termios->c_cflag =
670 (tty->termios->c_cflag & ~CLOCAL) |
676 if (access_ok(VERIFY_WRITE, (void *) arg,
677 sizeof(struct serial_struct)))
678 rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
681 if ( PortP->State & RIO_DELETED ) {
682 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
685 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
686 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
692 if ( PortP->State & RIO_DELETED ) {
693 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
698 if (l > 255) l = 255;
699 if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
700 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
707 if (access_ok(VERIFY_READ, (void *) arg,
708 sizeof(struct serial_struct)))
709 rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
713 * note: these IOCTLs no longer reach here. Use
714 * tiocmset/tiocmget driver methods instead. The
715 * #if 0 disablement predates this comment.
719 if (access_ok(VERIFY_WRITE, (void *) arg,
720 sizeof(unsigned int))) {
722 ival = rio_getsignals(port);
723 put_user(ival, (unsigned int *) arg);
727 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
728 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
729 ((ival & TIOCM_RTS) ? 1 : -1));
733 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
734 rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
735 ((ival & TIOCM_RTS) ? 0 : -1));
739 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
740 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
741 ((ival & TIOCM_RTS) ? 1 : 0));
754 /* The throttle/unthrottle scheme for the Specialix card is different
755 * from other drivers and deserves some explanation.
756 * The Specialix hardware takes care of XON/XOFF
757 * and CTS/RTS flow control itself. This means that all we have to
758 * do when signalled by the upper tty layer to throttle/unthrottle is
759 * to make a note of it here. When we come to read characters from the
760 * rx buffers on the card (rio_receive_chars()) we look to see if the
761 * upper layer can accept more (as noted here in rio_rx_throt[]).
762 * If it can't we simply don't remove chars from the cards buffer.
763 * When the tty layer can accept chars, we again note that here and when
764 * rio_receive_chars() is called it will remove them from the cards buffer.
765 * The card will notice that a ports buffer has drained below some low
766 * water mark and will unflow control the line itself, using whatever
767 * flow control scheme is in use for that port. -- Simon Allen
770 static void rio_throttle (struct tty_struct * tty)
772 struct Port *port = (struct Port *)tty->driver_data;
775 /* If the port is using any type of input flow
776 * control then throttle the port.
779 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
780 port->State |= RIO_THROTTLE_RX;
787 static void rio_unthrottle (struct tty_struct * tty)
789 struct Port *port = (struct Port *)tty->driver_data;
792 /* Always unthrottle even if flow control is not enabled on
793 * this port in case we disabled flow control while the port
797 port->State &= ~RIO_THROTTLE_RX;
807 /* ********************************************************************** *
808 * Here are the initialization routines. *
809 * ********************************************************************** */
812 static struct vpd_prom *get_VPD_PROM (struct Host *hp)
814 static struct vpd_prom vpdp;
819 rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
820 hp->Caddr + RIO_VPD_ROM);
823 for (i=0;i< sizeof (struct vpd_prom);i++)
824 *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
825 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
827 /* Terminate the identifier string.
828 *** requires one extra byte in struct vpd_prom *** */
831 if (rio_debug & RIO_DEBUG_PROBE)
832 my_hd ((char *)&vpdp, 0x20);
839 static struct tty_operations rio_ops = {
843 .put_char = gs_put_char,
844 .flush_chars = gs_flush_chars,
845 .write_room = gs_write_room,
846 .chars_in_buffer = gs_chars_in_buffer,
847 .flush_buffer = gs_flush_buffer,
849 .throttle = rio_throttle,
850 .unthrottle = rio_unthrottle,
851 .set_termios = gs_set_termios,
857 static int rio_init_drivers(void)
861 rio_driver = alloc_tty_driver(256);
864 rio_driver2 = alloc_tty_driver(256);
870 rio_driver->owner = THIS_MODULE;
871 rio_driver->driver_name = "specialix_rio";
872 rio_driver->name = "ttySR";
873 rio_driver->major = RIO_NORMAL_MAJOR0;
874 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
875 rio_driver->subtype = SERIAL_TYPE_NORMAL;
876 rio_driver->init_termios = tty_std_termios;
877 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
878 rio_driver->flags = TTY_DRIVER_REAL_RAW;
879 tty_set_operations(rio_driver, &rio_ops);
881 rio_driver2->owner = THIS_MODULE;
882 rio_driver2->driver_name = "specialix_rio";
883 rio_driver2->name = "ttySR";
884 rio_driver2->major = RIO_NORMAL_MAJOR1;
885 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
886 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
887 rio_driver2->init_termios = tty_std_termios;
888 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
889 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
890 tty_set_operations(rio_driver2, &rio_ops);
892 rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
894 if ((error = tty_register_driver(rio_driver)))
896 if ((error = tty_register_driver(rio_driver2)))
901 tty_unregister_driver(rio_driver);
903 put_tty_driver(rio_driver2);
905 put_tty_driver(rio_driver);
907 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
913 static void * ckmalloc (int size)
917 p = kmalloc(size, GFP_KERNEL);
925 static int rio_init_datastructures (void)
931 /* Many drivers statically allocate the maximum number of ports
932 There is no reason not to allocate them dynamically. Is there? -- REW */
933 /* However, the RIO driver allows users to configure their first
934 RTA as the ports numbered 504-511. We therefore need to allocate
935 the whole range. :-( -- REW */
937 #define RI_SZ sizeof(struct rio_info)
938 #define HOST_SZ sizeof(struct Host)
939 #define PORT_SZ sizeof(struct Port *)
940 #define TMIO_SZ sizeof(struct termios *)
941 rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n",
946 RIO_PORTS * TMIO_SZ);
948 if (!(p = ckmalloc ( RI_SZ))) goto free0;
949 if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
950 if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
951 p->RIOConf = RIOConf;
952 rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n",
953 p, p->RIOHosts, p->RIOPortp);
956 for (i = 0; i < RIO_PORTS; i++) {
957 port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
961 rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
963 port->gs.magic = RIO_MAGIC;
964 port->gs.close_delay = HZ/2;
965 port->gs.closing_wait = 30 * HZ;
966 port->gs.rd = &rio_real_driver;
967 spin_lock_init(&port->portSem);
969 * Initializing wait queue
971 init_waitqueue_head(&port->gs.open_wait);
972 init_waitqueue_head(&port->gs.close_wait);
975 /* We could postpone initializing them to when they are configured. */
980 if (rio_debug & RIO_DEBUG_INIT) {
981 my_hd (&rio_real_driver, sizeof (rio_real_driver));
988 free6:for (i--;i>=0;i--)
989 kfree (p->RIOPortp[i]);
992 free3:*/kfree (p->RIOPortp);
993 free2:kfree (p->RIOHosts);
995 rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n",
996 p, p->RIOHosts, p->RIOPortp);
1002 static void __exit rio_release_drivers(void)
1005 tty_unregister_driver(rio_driver2);
1006 tty_unregister_driver(rio_driver);
1007 put_tty_driver(rio_driver2);
1008 put_tty_driver(rio_driver);
1014 /* This was written for SX, but applies to RIO too...
1015 (including bugs....)
1017 There is another bit besides Bit 17. Turning that bit off
1018 (on boards shipped with the fix in the eeprom) results in a
1019 hang on the next access to the card.
1022 /********************************************************
1023 * Setting bit 17 in the CNTRL register of the PLX 9050 *
1024 * chip forces a retry on writes while a read is pending.*
1025 * This is to prevent the card locking up on Intel Xeon *
1026 * multiprocessor systems with the NX chipset. -- NV *
1027 ********************************************************/
1029 /* Newer cards are produced with this bit set from the configuration
1030 EEprom. As the bit is read/write for the CPU, we can fix it here,
1031 if we detect that it isn't set correctly. -- REW */
1033 static void fix_rio_pci (struct pci_dev *pdev)
1035 unsigned int hwbase;
1036 unsigned long rebase;
1039 #define CNTRL_REG_OFFSET 0x50
1040 #define CNTRL_REG_GOODVALUE 0x18260000
1042 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
1043 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
1044 rebase = (ulong) ioremap(hwbase, 0x80);
1045 t = readl (rebase + CNTRL_REG_OFFSET);
1046 if (t != CNTRL_REG_GOODVALUE) {
1047 printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n",
1048 t, CNTRL_REG_GOODVALUE);
1049 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
1051 iounmap((char*) rebase);
1056 static int __init rio_init(void)
1062 struct vpd_prom *vpdp;
1066 struct pci_dev *pdev = NULL;
1068 unsigned short tshort;
1072 rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n",
1075 if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
1076 printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
1077 "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
1081 if (misc_register(&rio_fw_device) < 0) {
1082 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
1086 retval = rio_init_datastructures ();
1088 misc_deregister(&rio_fw_device);
1093 /* First look for the JET devices: */
1094 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1095 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
1097 if (pci_enable_device(pdev)) continue;
1099 /* Specialix has a whole bunch of cards with
1100 0x2000 as the device ID. They say its because
1101 the standard requires it. Stupid standard. */
1102 /* It seems that reading a word doesn't work reliably on 2.0.
1103 Also, reading a non-aligned dword doesn't work. So we read the
1104 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1106 /* I don't know why the define doesn't work, constant 0x2c does --REW */
1107 pci_read_config_dword (pdev, 0x2c, &tint);
1108 tshort = (tint >> 16) & 0xffff;
1109 rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
1110 if (tshort != 0x0100) {
1111 rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n",
1115 rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
1117 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
1119 hp = &p->RIOHosts[p->RIONumHosts];
1120 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1121 hp->Ivec = pdev->irq;
1122 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1124 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1125 hp->CardP = (struct DpRam *) hp->Caddr;
1127 hp->Copy = rio_pcicopy;
1128 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1129 spin_lock_init(&hp->HostLock);
1130 rio_reset_interrupt (hp);
1131 rio_start_card_running (hp);
1133 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1134 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1135 p->RIOHosts[p->RIONumHosts].Caddr);
1136 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1137 p->RIOHosts[p->RIONumHosts].Caddr,
1138 RIO_PCI, 0 ) == RIO_SUCCESS) {
1139 rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1140 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1141 p->RIOHosts[p->RIONumHosts].UniqueNum =
1142 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1143 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1144 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1145 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1146 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1147 p->RIOHosts[p->RIONumHosts].UniqueNum);
1150 p->RIOLastPCISearch = RIO_SUCCESS;
1154 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1158 /* Then look for the older PCI card.... : */
1160 /* These older PCI cards have problems (only byte-mode access is
1161 supported), which makes them a bit awkward to support.
1162 They also have problems sharing interrupts. Be careful.
1163 (The driver now refuses to share interrupts for these
1164 cards. This should be sufficient).
1167 /* Then look for the older RIO/PCI devices: */
1168 while ((pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
1169 PCI_DEVICE_ID_SPECIALIX_RIO,
1171 if (pci_enable_device(pdev)) continue;
1173 #ifdef CONFIG_RIO_OLDPCI
1174 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
1176 hp = &p->RIOHosts[p->RIONumHosts];
1177 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1178 hp->Ivec = pdev->irq;
1179 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1181 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1182 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1183 hp->CardP = (struct DpRam *) hp->Caddr;
1185 hp->Copy = rio_pcicopy;
1186 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1187 spin_lock_init(&hp->HostLock);
1189 rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1190 rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1192 rio_reset_interrupt (hp);
1193 rio_start_card_running (hp);
1194 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1195 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1196 p->RIOHosts[p->RIONumHosts].Caddr);
1197 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1198 p->RIOHosts[p->RIONumHosts].Caddr,
1199 RIO_PCI, 0 ) == RIO_SUCCESS) {
1200 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1201 p->RIOHosts[p->RIONumHosts].UniqueNum =
1202 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1203 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1204 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1205 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1206 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1207 p->RIOHosts[p->RIONumHosts].UniqueNum);
1209 p->RIOLastPCISearch = RIO_SUCCESS;
1213 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1216 printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
1217 "compiled to support it.\n");
1222 /* Now probe for ISA cards... */
1223 for (i=0;i<NR_RIO_ADDRS;i++) {
1224 hp = &p->RIOHosts[p->RIONumHosts];
1225 hp->PaddrP = rio_probe_addrs[i];
1226 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1228 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1229 hp->CardP = (struct DpRam *) hp->Caddr;
1231 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
1232 * -- YES! this is now a normal copy. Only the
1233 * old PCI card uses the special PCI copy.
1234 * Moreover, the ISA card will work with the
1235 * special PCI copy anyway. -- REW */
1237 spin_lock_init(&hp->HostLock);
1239 vpdp = get_VPD_PROM (hp);
1240 rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
1242 if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
1243 (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
1244 (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1245 /* Board is present... */
1246 if (RIOBoardTest (hp->PaddrP,
1247 hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
1248 /* ... and feeling fine!!!! */
1249 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1250 p->RIOHosts[p->RIONumHosts].UniqueNum);
1251 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1252 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
1254 p->RIOHosts[p->RIONumHosts-1].UniqueNum);
1261 iounmap ((char*) (hp->Caddr));
1266 for (i=0;i<p->RIONumHosts;i++) {
1267 hp = &p->RIOHosts[i];
1269 int mode = SA_SHIRQ;
1270 if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
1271 rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
1272 retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
1273 rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1275 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1278 rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1280 rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1281 hp->Mode |= RIO_PCI_INT_ENABLE;
1283 hp->Mode &= !RIO_PCI_INT_ENABLE;
1284 rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1285 rio_start_card_running (hp);
1287 /* Init the timer "always" to make sure that it can safely be
1288 deleted when we unload... */
1290 init_timer (&hp->timer);
1292 rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n",
1295 hp->timer.function = rio_pollfunc;
1296 hp->timer.expires = jiffies + rio_poll;
1297 add_timer (&hp->timer);
1302 rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1303 rio_init_drivers ();
1305 /* deregister the misc device we created earlier */
1306 misc_deregister(&rio_fw_device);
1310 return found?0:-EIO;
1314 static void __exit rio_exit (void)
1321 for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
1322 RIOHostReset (hp->Type, hp->CardP, hp->Slot);
1324 free_irq (hp->Ivec, hp);
1325 rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1327 /* It is safe/allowed to del_timer a non-active timer */
1328 del_timer (&hp->timer);
1331 if (misc_deregister(&rio_fw_device) < 0) {
1332 printk (KERN_INFO "rio: couldn't deregister control-device\n");
1336 rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1338 rio_release_drivers ();
1340 /* Release dynamically allocated memory */
1341 kfree (p->RIOPortp);
1342 kfree (p->RIOHosts);
1348 module_init(rio_init);
1349 module_exit(rio_exit);
1352 * Anybody who knows why this doesn't work for me, please tell me -- REW.
1353 * Snatched from scsi.c (fixed one spelling error):
1354 * Overrides for Emacs so that we follow Linus' tabbing style.
1355 * Emacs will notice this stuff at the end of the file and automatically
1356 * adjust the settings for this buffer only. This must remain at the end
1358 * ---------------------------------------------------------------------------
1361 * c-brace-imaginary-offset: 0
1362 * c-brace-offset: -4
1363 * c-argdecl-indent: 4
1364 * c-label-offset: -4
1365 * c-continued-statement-offset: 4
1366 * c-continued-brace-offset: 0
1367 * indent-tabs-mode: nil