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
36 #define RCS_ID "$Id: rio.c,v 1.1 1999/07/11 10:13:54 wolff Exp wolff $"
37 #define RCS_REV "$Revision: 1.1 $"
40 #include <linux/module.h>
41 #include <linux/config.h>
42 #include <linux/kdev_t.h>
44 #include <linux/kernel.h>
45 #include <linux/sched.h>
46 #include <linux/ioport.h>
47 #include <linux/interrupt.h>
48 #include <linux/errno.h>
49 #include <linux/tty.h>
50 #include <linux/tty_flip.h>
52 #include <linux/serial.h>
53 #include <linux/fcntl.h>
54 #include <linux/major.h>
55 #include <linux/delay.h>
56 #include <linux/pci.h>
57 #include <linux/slab.h>
58 #include <linux/miscdevice.h>
59 #include <linux/init.h>
61 #include <linux/generic_serial.h>
62 #include <asm/uaccess.h>
64 #if BITS_PER_LONG != 32
65 # error FIXME: this driver only works on 32-bit platforms
68 #include "linux_compat.h"
102 #include "rioboard.h"
105 #include "rio_linux.h"
107 /* I don't think that this driver can handle more than 512 ports on
108 one machine. Specialix specifies max 4 boards in one machine. I don't
109 know why. If you want to try anyway you'll have to increase the number
110 of boards in rio.h. You'll have to allocate more majors if you need
111 more than 512 ports.... */
113 #ifndef RIO_NORMAL_MAJOR0
114 /* This allows overriding on the compiler commandline, or in a "major.h"
115 include or something like that */
116 #define RIO_NORMAL_MAJOR0 154
117 #define RIO_NORMAL_MAJOR1 156
120 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
121 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
124 #ifndef RIO_WINDOW_LEN
125 #define RIO_WINDOW_LEN 0x10000
129 /* Configurable options:
130 (Don't be too sure that it'll work if you toggle them) */
132 /* Am I paranoid or not ? ;-) */
133 #undef RIO_PARANOIA_CHECK
136 /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
137 Hz, but it is user configurable. I don't recommend going above 1000
138 Hz. The interrupt ratelimit might trigger if the interrupt is
139 shared with a very active other device.
140 undef this if you want to disable the check....
142 #define IRQ_RATE_LIMIT 200
145 /* Not implemented */
147 * The following defines are mostly for testing purposes. But if you need
148 * some nice reporting in your syslog, you can define them also.
150 #define RIO_REPORT_FIFO
151 #define RIO_REPORT_OVERRUN
155 /* These constants are derived from SCO Source */
159 /* locator */ "RIO Config here",
160 /* startuptime */ HZ*2, /* how long to wait for card to run */
161 /* slowcook */ 0, /* TRUE -> always use line disc. */
162 /* intrpolltime */ 1, /* The frequency of OUR polls */
163 /* breakinterval */ 25, /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/
164 /* timer */ 10, /* mS */
165 /* RtaLoadBase */ 0x7000,
166 /* HostLoadBase */ 0x7C00,
167 /* XpHz */ 5, /* number of Xprint hits per second */
168 /* XpCps */ 120, /* Xprint characters per second */
169 /* XpOn */ "\033d#", /* start Xprint for a wyse 60 */
170 /* XpOff */ "\024", /* end Xprint for a wyse 60 */
171 /* MaxXpCps */ 2000, /* highest Xprint speed */
172 /* MinXpCps */ 10, /* slowest Xprint speed */
173 /* SpinCmds */ 1, /* non-zero for mega fast boots */
174 /* First Addr */ 0x0A0000, /* First address to look at */
175 /* Last Addr */ 0xFF0000, /* Last address looked at */
176 /* BufferSize */ 1024, /* Bytes per port of buffering */
177 /* LowWater */ 256, /* how much data left before wakeup */
178 /* LineLength */ 80, /* how wide is the console? */
179 /* CmdTimeout */ HZ, /* how long a close command may take */
185 /* Function prototypes */
187 static void rio_disable_tx_interrupts (void * ptr);
188 static void rio_enable_tx_interrupts (void * ptr);
189 static void rio_disable_rx_interrupts (void * ptr);
190 static void rio_enable_rx_interrupts (void * ptr);
191 static int rio_get_CD (void * ptr);
192 static void rio_shutdown_port (void * ptr);
193 static int rio_set_real_termios (void *ptr);
194 static void rio_hungup (void *ptr);
195 static void rio_close (void *ptr);
196 static int rio_chars_in_buffer (void * ptr);
197 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
198 unsigned int cmd, unsigned long arg);
199 static int rio_init_drivers(void);
201 void my_hd (void *addr, int len);
203 static struct tty_driver *rio_driver, *rio_driver2;
205 /* The name "p" is a bit non-descript. But that's what the rio-lynxos
206 sources use all over the place. */
209 /* struct rio_board boards[RIO_HOSTS]; */
210 struct rio_port *rio_ports;
217 /* You can have the driver poll your card.
218 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
219 This is used when the card cannot use an interrupt for some reason.
224 /* These are the only open spaces in my computer. Yours may have more
226 int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000};
228 #define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int))
231 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
232 Some architectures may need more. -- Changed to LONG to
233 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
234 long rio_irqmask = -1;
236 MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
237 MODULE_DESCRIPTION("RIO driver");
238 MODULE_LICENSE("GPL");
239 module_param(rio_poll, int, 0);
240 module_param(rio_debug, int, 0644);
241 module_param(rio_irqmask, long, 0);
243 static struct real_driver rio_real_driver = {
244 rio_disable_tx_interrupts,
245 rio_enable_tx_interrupts,
246 rio_disable_rx_interrupts,
247 rio_enable_rx_interrupts,
250 rio_set_real_termios,
258 * Firmware loader driver specific routines
262 static struct file_operations rio_fw_fops = {
263 .owner = THIS_MODULE,
264 .ioctl = rio_fw_ioctl,
267 struct miscdevice rio_fw_device = {
268 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
275 #ifdef RIO_PARANOIA_CHECK
277 /* This doesn't work. Who's paranoid around here? Not me! */
279 static inline int rio_paranoia_check(struct rio_port const * port,
280 char *name, const char *routine)
283 static const char *badmagic =
284 KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
285 static const char *badinfo =
286 KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
289 printk (badinfo, name, routine);
292 if (port->magic != RIO_MAGIC) {
293 printk (badmagic, name, routine);
300 #define rio_paranoia_check(a,b,c) 0
305 void my_hd (void *ad, int len)
308 unsigned char *addr = ad;
310 for (i=0;i<len;i+=16) {
311 rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i);
313 rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":"");
317 rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
319 rio_dprintk (RIO_DEBUG_PARAM, "\n");
323 #define my_hd(ad,len) do{/* nothing*/ } while (0)
327 /* Delay a number of jiffies, allowing a signal to interrupt */
328 int RIODelay (struct Port *PortP, int njiffies)
332 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
333 msleep_interruptible(jiffies_to_msecs(njiffies));
336 if (signal_pending(current))
343 /* Delay a number of jiffies, disallowing a signal to interrupt */
344 int RIODelay_ni (struct Port *PortP, int njiffies)
348 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
349 msleep(jiffies_to_msecs(njiffies));
355 int rio_minor(struct tty_struct *tty)
357 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
361 int rio_ismodem(struct tty_struct *tty)
367 void rio_udelay (int usecs)
372 static int rio_set_real_termios (void *ptr)
375 struct tty_struct *tty;
378 tty = ((struct Port *)ptr)->gs.tty;
380 modem = rio_ismodem(tty);
382 rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
390 void rio_reset_interrupt (struct Host *HostP)
394 switch( HostP->Type ) {
398 WBYTE(HostP->ResetInt , 0xff);
405 static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
410 HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
411 rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n",
414 /* AAargh! The order in which to do these things is essential and
417 - Rate limit goes before "recursive". Otherwise a series of
418 recursive calls will hang the machine in the interrupt routine.
420 - hardware twiddling goes before "recursive". Otherwise when we
421 poll the card, and a recursive interrupt happens, we won't
422 ack the card, so it might keep on interrupting us. (especially
423 level sensitive interrupt systems like PCI).
425 - Rate limit goes before hardware twiddling. Otherwise we won't
426 catch a card that has gone bonkers.
428 - The "initialized" test goes after the hardware twiddling. Otherwise
429 the card will stick us in the interrupt routine again.
431 - The initialized test goes before recursive.
436 #ifdef IRQ_RATE_LIMIT
437 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
438 actual interrupt routine!. (Well, used to when I wrote that comment) */
443 if (lastjif == jiffies) {
444 if (++nintr > IRQ_RATE_LIMIT) {
445 free_irq (HostP->Ivec, ptr);
446 printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n",
455 rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
456 if (HostP->Ivec == irq) {
457 /* Tell the card we've noticed the interrupt. */
458 rio_reset_interrupt (HostP);
461 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
464 if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
465 printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n",
466 (int) ptr, HostP->Ivec);
470 RIOServiceHost(p, HostP, irq);
472 rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n",
473 (int) ptr, HostP->Type);
475 clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
476 rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n",
483 static void rio_pollfunc (unsigned long data)
487 rio_interrupt (0, &p->RIOHosts[data], NULL);
488 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
489 add_timer (&p->RIOHosts[data].timer);
495 /* ********************************************************************** *
496 * Here are the routines that actually *
497 * interface with the generic_serial driver *
498 * ********************************************************************** */
500 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix
501 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
503 static void rio_disable_tx_interrupts (void * ptr)
507 /* port->gs.flags &= ~GS_TX_INTEN; */
513 static void rio_enable_tx_interrupts (void * ptr)
515 struct Port *PortP = ptr;
520 /* hn = PortP->HostP - p->RIOHosts;
522 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
523 rio_interrupt (-1,(void *) hn, NULL); */
525 RIOTxEnable((char *) PortP);
528 * In general we cannot count on "tx empty" interrupts, although
529 * the interrupt routine seems to be able to tell the difference.
531 PortP->gs.flags &= ~GS_TX_INTEN;
537 static void rio_disable_rx_interrupts (void * ptr)
543 static void rio_enable_rx_interrupts (void * ptr)
545 /* struct rio_port *port = ptr; */
551 /* Jeez. Isn't this simple? */
552 static int rio_get_CD (void * ptr)
554 struct Port *PortP = ptr;
558 rv = (PortP->ModemState & MSVR1_CD) != 0;
560 rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
567 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
568 by just pushing stuff into the queue going to the port... */
569 static int rio_chars_in_buffer (void * ptr)
578 /* Nothing special here... */
579 static void rio_shutdown_port (void * ptr)
585 PortP = (struct Port *)ptr;
586 PortP->gs.tty = NULL;
588 port->gs.flags &= ~ GS_ACTIVE;
590 rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
593 if (!port->gs.tty->termios) {
594 rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
597 if (port->gs.tty->termios->c_cflag & HUPCL) {
598 rio_setsignals (port, 0, 0);
606 /* I haven't the foggiest why the decrement use count has to happen
607 here. The whole linux serial drivers stuff needs to be redesigned.
608 My guess is that this is a hack to minimize the impact of a bug
609 elsewhere. Thinking about it some more. (try it sometime) Try
610 running minicom on a serial port that is driven by a modularized
611 driver. Have the modem hangup. Then remove the driver module. Then
612 exit minicom. I expect an "oops". -- REW */
613 static void rio_hungup (void *ptr)
619 PortP = (struct Port *)ptr;
620 PortP->gs.tty = NULL;
626 /* The standard serial_close would become shorter if you'd wrap it like
628 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
630 static void rio_close (void *ptr)
636 PortP = (struct Port *)ptr;
640 if(PortP->gs.count) {
641 printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
645 PortP->gs.tty = NULL;
651 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
652 unsigned int cmd, unsigned long arg)
657 /* The "dev" argument isn't used. */
658 rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
664 extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
665 int command, int len, int arg);
667 static int rio_ioctl (struct tty_struct * tty, struct file * filp,
668 unsigned int cmd, unsigned long arg)
676 PortP = (struct Port *)tty->driver_data;
682 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
683 (unsigned int *) arg);
687 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
688 tty->termios->c_cflag =
689 (tty->termios->c_cflag & ~CLOCAL) |
694 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
695 sizeof(struct serial_struct))) == 0)
696 rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
699 if ( PortP->State & RIO_DELETED ) {
700 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
703 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
704 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
710 if ( PortP->State & RIO_DELETED ) {
711 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
716 if (l > 255) l = 255;
717 if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
718 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
724 if ((rc = verify_area(VERIFY_READ, (void *) arg,
725 sizeof(struct serial_struct))) == 0)
726 rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
730 * note: these IOCTLs no longer reach here. Use
731 * tiocmset/tiocmget driver methods instead. The
732 * #if 0 disablement predates this comment.
735 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
736 sizeof(unsigned int))) == 0) {
737 ival = rio_getsignals(port);
738 put_user(ival, (unsigned int *) arg);
742 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
743 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
744 ((ival & TIOCM_RTS) ? 1 : -1));
748 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
749 rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
750 ((ival & TIOCM_RTS) ? 0 : -1));
754 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
755 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
756 ((ival & TIOCM_RTS) ? 1 : 0));
769 /* The throttle/unthrottle scheme for the Specialix card is different
770 * from other drivers and deserves some explanation.
771 * The Specialix hardware takes care of XON/XOFF
772 * and CTS/RTS flow control itself. This means that all we have to
773 * do when signalled by the upper tty layer to throttle/unthrottle is
774 * to make a note of it here. When we come to read characters from the
775 * rx buffers on the card (rio_receive_chars()) we look to see if the
776 * upper layer can accept more (as noted here in rio_rx_throt[]).
777 * If it can't we simply don't remove chars from the cards buffer.
778 * When the tty layer can accept chars, we again note that here and when
779 * rio_receive_chars() is called it will remove them from the cards buffer.
780 * The card will notice that a ports buffer has drained below some low
781 * water mark and will unflow control the line itself, using whatever
782 * flow control scheme is in use for that port. -- Simon Allen
785 static void rio_throttle (struct tty_struct * tty)
787 struct Port *port = (struct Port *)tty->driver_data;
790 /* If the port is using any type of input flow
791 * control then throttle the port.
794 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
795 port->State |= RIO_THROTTLE_RX;
802 static void rio_unthrottle (struct tty_struct * tty)
804 struct Port *port = (struct Port *)tty->driver_data;
807 /* Always unthrottle even if flow control is not enabled on
808 * this port in case we disabled flow control while the port
812 port->State &= ~RIO_THROTTLE_RX;
822 /* ********************************************************************** *
823 * Here are the initialization routines. *
824 * ********************************************************************** */
827 struct vpd_prom *get_VPD_PROM (struct Host *hp)
829 static struct vpd_prom vpdp;
834 rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
835 hp->Caddr + RIO_VPD_ROM);
838 for (i=0;i< sizeof (struct vpd_prom);i++)
839 *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
840 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
842 /* Terminate the identifier string.
843 *** requires one extra byte in struct vpd_prom *** */
846 if (rio_debug & RIO_DEBUG_PROBE)
847 my_hd ((char *)&vpdp, 0x20);
854 static struct tty_operations rio_ops = {
858 .put_char = gs_put_char,
859 .flush_chars = gs_flush_chars,
860 .write_room = gs_write_room,
861 .chars_in_buffer = gs_chars_in_buffer,
862 .flush_buffer = gs_flush_buffer,
864 .throttle = rio_throttle,
865 .unthrottle = rio_unthrottle,
866 .set_termios = gs_set_termios,
872 static int rio_init_drivers(void)
876 rio_driver = alloc_tty_driver(256);
879 rio_driver2 = alloc_tty_driver(256);
885 rio_driver->owner = THIS_MODULE;
886 rio_driver->driver_name = "specialix_rio";
887 rio_driver->name = "ttySR";
888 rio_driver->major = RIO_NORMAL_MAJOR0;
889 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
890 rio_driver->subtype = SERIAL_TYPE_NORMAL;
891 rio_driver->init_termios = tty_std_termios;
892 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
893 rio_driver->flags = TTY_DRIVER_REAL_RAW;
894 tty_set_operations(rio_driver, &rio_ops);
896 rio_driver2->owner = THIS_MODULE;
897 rio_driver2->driver_name = "specialix_rio";
898 rio_driver2->name = "ttySR";
899 rio_driver2->major = RIO_NORMAL_MAJOR1;
900 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
901 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
902 rio_driver2->init_termios = tty_std_termios;
903 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
904 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
905 tty_set_operations(rio_driver2, &rio_ops);
907 rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
909 if ((error = tty_register_driver(rio_driver)))
911 if ((error = tty_register_driver(rio_driver2)))
916 tty_unregister_driver(rio_driver);
918 put_tty_driver(rio_driver2);
920 put_tty_driver(rio_driver);
922 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
928 static void * ckmalloc (int size)
932 p = kmalloc(size, GFP_KERNEL);
940 static int rio_init_datastructures (void)
946 /* Many drivers statically allocate the maximum number of ports
947 There is no reason not to allocate them dynamically. Is there? -- REW */
948 /* However, the RIO driver allows users to configure their first
949 RTA as the ports numbered 504-511. We therefore need to allocate
950 the whole range. :-( -- REW */
952 #define RI_SZ sizeof(struct rio_info)
953 #define HOST_SZ sizeof(struct Host)
954 #define PORT_SZ sizeof(struct Port *)
955 #define TMIO_SZ sizeof(struct termios *)
956 rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n",
961 RIO_PORTS * TMIO_SZ);
963 if (!(p = ckmalloc ( RI_SZ))) goto free0;
964 if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
965 if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
966 p->RIOConf = RIOConf;
967 rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n",
968 p, p->RIOHosts, p->RIOPortp);
971 for (i = 0; i < RIO_PORTS; i++) {
972 port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
976 rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
978 port->gs.magic = RIO_MAGIC;
979 port->gs.close_delay = HZ/2;
980 port->gs.closing_wait = 30 * HZ;
981 port->gs.rd = &rio_real_driver;
982 port->portSem = SPIN_LOCK_UNLOCKED;
984 * Initializing wait queue
986 init_waitqueue_head(&port->gs.open_wait);
987 init_waitqueue_head(&port->gs.close_wait);
990 /* We could postpone initializing them to when they are configured. */
995 if (rio_debug & RIO_DEBUG_INIT) {
996 my_hd (&rio_real_driver, sizeof (rio_real_driver));
1003 free6:for (i--;i>=0;i--)
1004 kfree (p->RIOPortp[i]);
1007 free3:*/kfree (p->RIOPortp);
1008 free2:kfree (p->RIOHosts);
1010 rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n",
1011 p, p->RIOHosts, p->RIOPortp);
1017 static void __exit rio_release_drivers(void)
1020 tty_unregister_driver(rio_driver2);
1021 tty_unregister_driver(rio_driver);
1022 put_tty_driver(rio_driver2);
1023 put_tty_driver(rio_driver);
1029 /* This was written for SX, but applies to RIO too...
1030 (including bugs....)
1032 There is another bit besides Bit 17. Turning that bit off
1033 (on boards shipped with the fix in the eeprom) results in a
1034 hang on the next access to the card.
1037 /********************************************************
1038 * Setting bit 17 in the CNTRL register of the PLX 9050 *
1039 * chip forces a retry on writes while a read is pending.*
1040 * This is to prevent the card locking up on Intel Xeon *
1041 * multiprocessor systems with the NX chipset. -- NV *
1042 ********************************************************/
1044 /* Newer cards are produced with this bit set from the configuration
1045 EEprom. As the bit is read/write for the CPU, we can fix it here,
1046 if we detect that it isn't set correctly. -- REW */
1048 void fix_rio_pci (struct pci_dev *pdev)
1050 unsigned int hwbase;
1051 unsigned long rebase;
1054 #define CNTRL_REG_OFFSET 0x50
1055 #define CNTRL_REG_GOODVALUE 0x18260000
1057 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
1058 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
1059 rebase = (ulong) ioremap(hwbase, 0x80);
1060 t = readl (rebase + CNTRL_REG_OFFSET);
1061 if (t != CNTRL_REG_GOODVALUE) {
1062 printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n",
1063 t, CNTRL_REG_GOODVALUE);
1064 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
1066 iounmap((char*) rebase);
1071 static int __init rio_init(void)
1077 struct vpd_prom *vpdp;
1081 struct pci_dev *pdev = NULL;
1083 unsigned short tshort;
1087 rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n",
1090 if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
1091 printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
1092 "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
1096 if (misc_register(&rio_fw_device) < 0) {
1097 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
1101 retval = rio_init_datastructures ();
1103 misc_deregister(&rio_fw_device);
1108 /* First look for the JET devices: */
1109 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
1110 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
1112 if (pci_enable_device(pdev)) continue;
1114 /* Specialix has a whole bunch of cards with
1115 0x2000 as the device ID. They say its because
1116 the standard requires it. Stupid standard. */
1117 /* It seems that reading a word doesn't work reliably on 2.0.
1118 Also, reading a non-aligned dword doesn't work. So we read the
1119 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1121 /* I don't know why the define doesn't work, constant 0x2c does --REW */
1122 pci_read_config_dword (pdev, 0x2c, &tint);
1123 tshort = (tint >> 16) & 0xffff;
1124 rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
1125 if (tshort != 0x0100) {
1126 rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n",
1130 rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
1132 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
1134 hp = &p->RIOHosts[p->RIONumHosts];
1135 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1136 hp->Ivec = pdev->irq;
1137 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1139 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1140 hp->CardP = (struct DpRam *) hp->Caddr;
1142 hp->Copy = rio_pcicopy;
1143 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1144 hp->HostLock = SPIN_LOCK_UNLOCKED;
1145 rio_reset_interrupt (hp);
1146 rio_start_card_running (hp);
1148 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1149 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1150 p->RIOHosts[p->RIONumHosts].Caddr);
1151 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1152 p->RIOHosts[p->RIONumHosts].Caddr,
1153 RIO_PCI, 0 ) == RIO_SUCCESS) {
1154 rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1155 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1156 p->RIOHosts[p->RIONumHosts].UniqueNum =
1157 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1158 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1159 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1160 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1161 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1162 p->RIOHosts[p->RIONumHosts].UniqueNum);
1165 p->RIOLastPCISearch = RIO_SUCCESS;
1169 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1173 /* Then look for the older PCI card.... : */
1175 /* These older PCI cards have problems (only byte-mode access is
1176 supported), which makes them a bit awkward to support.
1177 They also have problems sharing interrupts. Be careful.
1178 (The driver now refuses to share interrupts for these
1179 cards. This should be sufficient).
1182 /* Then look for the older RIO/PCI devices: */
1183 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
1184 PCI_DEVICE_ID_SPECIALIX_RIO,
1186 if (pci_enable_device(pdev)) continue;
1188 #ifdef CONFIG_RIO_OLDPCI
1189 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
1191 hp = &p->RIOHosts[p->RIONumHosts];
1192 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1193 hp->Ivec = pdev->irq;
1194 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1196 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1197 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1198 hp->CardP = (struct DpRam *) hp->Caddr;
1200 hp->Copy = rio_pcicopy;
1201 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1202 hp->HostLock = SPIN_LOCK_UNLOCKED;
1204 rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1205 rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1207 rio_reset_interrupt (hp);
1208 rio_start_card_running (hp);
1209 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1210 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1211 p->RIOHosts[p->RIONumHosts].Caddr);
1212 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1213 p->RIOHosts[p->RIONumHosts].Caddr,
1214 RIO_PCI, 0 ) == RIO_SUCCESS) {
1215 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1216 p->RIOHosts[p->RIONumHosts].UniqueNum =
1217 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1218 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1219 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1220 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1221 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1222 p->RIOHosts[p->RIONumHosts].UniqueNum);
1224 p->RIOLastPCISearch = RIO_SUCCESS;
1228 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1231 printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
1232 "compiled to support it.\n");
1237 /* Now probe for ISA cards... */
1238 for (i=0;i<NR_RIO_ADDRS;i++) {
1239 hp = &p->RIOHosts[p->RIONumHosts];
1240 hp->PaddrP = rio_probe_addrs[i];
1241 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1243 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1244 hp->CardP = (struct DpRam *) hp->Caddr;
1246 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
1247 * -- YES! this is now a normal copy. Only the
1248 * old PCI card uses the special PCI copy.
1249 * Moreover, the ISA card will work with the
1250 * special PCI copy anyway. -- REW */
1252 hp->HostLock = SPIN_LOCK_UNLOCKED;
1254 vpdp = get_VPD_PROM (hp);
1255 rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
1257 if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
1258 (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
1259 (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1260 /* Board is present... */
1261 if (RIOBoardTest (hp->PaddrP,
1262 hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
1263 /* ... and feeling fine!!!! */
1264 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1265 p->RIOHosts[p->RIONumHosts].UniqueNum);
1266 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1267 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
1269 p->RIOHosts[p->RIONumHosts-1].UniqueNum);
1276 iounmap ((char*) (hp->Caddr));
1281 for (i=0;i<p->RIONumHosts;i++) {
1282 hp = &p->RIOHosts[i];
1284 int mode = SA_SHIRQ;
1285 if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
1286 rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
1287 retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
1288 rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1290 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1293 rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1295 rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1296 hp->Mode |= RIO_PCI_INT_ENABLE;
1298 hp->Mode &= !RIO_PCI_INT_ENABLE;
1299 rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1300 rio_start_card_running (hp);
1302 /* Init the timer "always" to make sure that it can safely be
1303 deleted when we unload... */
1305 init_timer (&hp->timer);
1307 rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n",
1310 hp->timer.function = rio_pollfunc;
1311 hp->timer.expires = jiffies + rio_poll;
1312 add_timer (&hp->timer);
1317 rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1318 rio_init_drivers ();
1320 /* deregister the misc device we created earlier */
1321 misc_deregister(&rio_fw_device);
1325 return found?0:-EIO;
1329 static void __exit rio_exit (void)
1336 for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
1337 RIOHostReset (hp->Type, hp->CardP, hp->Slot);
1339 free_irq (hp->Ivec, hp);
1340 rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1342 /* It is safe/allowed to del_timer a non-active timer */
1343 del_timer (&hp->timer);
1346 if (misc_deregister(&rio_fw_device) < 0) {
1347 printk (KERN_INFO "rio: couldn't deregister control-device\n");
1351 rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1353 rio_release_drivers ();
1355 /* Release dynamically allocated memory */
1356 kfree (p->RIOPortp);
1357 kfree (p->RIOHosts);
1363 module_init(rio_init);
1364 module_exit(rio_exit);
1367 * Anybody who knows why this doesn't work for me, please tell me -- REW.
1368 * Snatched from scsi.c (fixed one spelling error):
1369 * Overrides for Emacs so that we follow Linus' tabbing style.
1370 * Emacs will notice this stuff at the end of the file and automatically
1371 * adjust the settings for this buffer only. This must remain at the end
1373 * ---------------------------------------------------------------------------
1376 * c-brace-imaginary-offset: 0
1377 * c-brace-offset: -4
1378 * c-argdecl-indent: 4
1379 * c-label-offset: -4
1380 * c-continued-statement-offset: 4
1381 * c-continued-brace-offset: 0
1382 * indent-tabs-mode: nil