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_PARM(rio_poll, "i");
240 MODULE_PARM(rio_debug, "i");
241 MODULE_PARM(rio_irqmask, "i");
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 current->state = TASK_INTERRUPTIBLE;
334 schedule_timeout(njiffies);
337 if (signal_pending(current))
344 /* Delay a number of jiffies, disallowing a signal to interrupt */
345 int RIODelay_ni (struct Port *PortP, int njiffies)
349 rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
350 current->state = TASK_UNINTERRUPTIBLE;
351 schedule_timeout(njiffies);
357 int rio_minor(struct tty_struct *tty)
359 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
363 int rio_ismodem(struct tty_struct *tty)
369 void rio_udelay (int usecs)
374 static int rio_set_real_termios (void *ptr)
377 struct tty_struct *tty;
380 tty = ((struct Port *)ptr)->gs.tty;
382 modem = rio_ismodem(tty);
384 rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1);
392 void rio_reset_interrupt (struct Host *HostP)
396 switch( HostP->Type ) {
400 WBYTE(HostP->ResetInt , 0xff);
407 static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs)
412 HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */
413 rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n",
416 /* AAargh! The order in which to do these things is essential and
419 - Rate limit goes before "recursive". Otherwise a series of
420 recursive calls will hang the machine in the interrupt routine.
422 - hardware twiddling goes before "recursive". Otherwise when we
423 poll the card, and a recursive interrupt happens, we won't
424 ack the card, so it might keep on interrupting us. (especially
425 level sensitive interrupt systems like PCI).
427 - Rate limit goes before hardware twiddling. Otherwise we won't
428 catch a card that has gone bonkers.
430 - The "initialized" test goes after the hardware twiddling. Otherwise
431 the card will stick us in the interrupt routine again.
433 - The initialized test goes before recursive.
438 #ifdef IRQ_RATE_LIMIT
439 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
440 actual interrupt routine!. (Well, used to when I wrote that comment) */
445 if (lastjif == jiffies) {
446 if (++nintr > IRQ_RATE_LIMIT) {
447 free_irq (HostP->Ivec, ptr);
448 printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n",
457 rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
458 if (HostP->Ivec == irq) {
459 /* Tell the card we've noticed the interrupt. */
460 rio_reset_interrupt (HostP);
463 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
466 if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) {
467 printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n",
468 (int) ptr, HostP->Ivec);
472 RIOServiceHost(p, HostP, irq);
474 rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n",
475 (int) ptr, HostP->Type);
477 clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks);
478 rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n",
485 static void rio_pollfunc (unsigned long data)
489 rio_interrupt (0, &p->RIOHosts[data], NULL);
490 p->RIOHosts[data].timer.expires = jiffies + rio_poll;
491 add_timer (&p->RIOHosts[data].timer);
497 /* ********************************************************************** *
498 * Here are the routines that actually *
499 * interface with the generic_serial driver *
500 * ********************************************************************** */
502 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix
503 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
505 static void rio_disable_tx_interrupts (void * ptr)
509 /* port->gs.flags &= ~GS_TX_INTEN; */
515 static void rio_enable_tx_interrupts (void * ptr)
517 struct Port *PortP = ptr;
522 /* hn = PortP->HostP - p->RIOHosts;
524 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
525 rio_interrupt (-1,(void *) hn, NULL); */
527 RIOTxEnable((char *) PortP);
530 * In general we cannot count on "tx empty" interrupts, although
531 * the interrupt routine seems to be able to tell the difference.
533 PortP->gs.flags &= ~GS_TX_INTEN;
539 static void rio_disable_rx_interrupts (void * ptr)
545 static void rio_enable_rx_interrupts (void * ptr)
547 /* struct rio_port *port = ptr; */
553 /* Jeez. Isn't this simple? */
554 static int rio_get_CD (void * ptr)
556 struct Port *PortP = ptr;
560 rv = (PortP->ModemState & MSVR1_CD) != 0;
562 rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
569 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
570 by just pushing stuff into the queue going to the port... */
571 static int rio_chars_in_buffer (void * ptr)
580 /* Nothing special here... */
581 static void rio_shutdown_port (void * ptr)
587 PortP = (struct Port *)ptr;
588 PortP->gs.tty = NULL;
590 port->gs.flags &= ~ GS_ACTIVE;
592 rio_dprintk (RIO_DBUG_TTY, "No tty.\n");
595 if (!port->gs.tty->termios) {
596 rio_dprintk (RIO_DEBUG_TTY, "No termios.\n");
599 if (port->gs.tty->termios->c_cflag & HUPCL) {
600 rio_setsignals (port, 0, 0);
608 /* I haven't the foggiest why the decrement use count has to happen
609 here. The whole linux serial drivers stuff needs to be redesigned.
610 My guess is that this is a hack to minimize the impact of a bug
611 elsewhere. Thinking about it some more. (try it sometime) Try
612 running minicom on a serial port that is driven by a modularized
613 driver. Have the modem hangup. Then remove the driver module. Then
614 exit minicom. I expect an "oops". -- REW */
615 static void rio_hungup (void *ptr)
621 PortP = (struct Port *)ptr;
622 PortP->gs.tty = NULL;
628 /* The standard serial_close would become shorter if you'd wrap it like
630 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
632 static void rio_close (void *ptr)
638 PortP = (struct Port *)ptr;
642 if(PortP->gs.count) {
643 printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count);
647 PortP->gs.tty = NULL;
653 static int rio_fw_ioctl (struct inode *inode, struct file *filp,
654 unsigned int cmd, unsigned long arg)
659 /* The "dev" argument isn't used. */
660 rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN));
666 extern int RIOShortCommand(struct rio_info *p, struct Port *PortP,
667 int command, int len, int arg);
669 static int rio_ioctl (struct tty_struct * tty, struct file * filp,
670 unsigned int cmd, unsigned long arg)
678 PortP = (struct Port *)tty->driver_data;
684 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
685 (unsigned int *) arg);
689 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
690 tty->termios->c_cflag =
691 (tty->termios->c_cflag & ~CLOCAL) |
696 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
697 sizeof(struct serial_struct))) == 0)
698 rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg);
701 if ( PortP->State & RIO_DELETED ) {
702 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
705 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) {
706 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
712 if ( PortP->State & RIO_DELETED ) {
713 rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
718 if (l > 255) l = 255;
719 if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) {
720 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
726 if ((rc = verify_area(VERIFY_READ, (void *) arg,
727 sizeof(struct serial_struct))) == 0)
728 rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg);
732 * note: these IOCTLs no longer reach here. Use
733 * tiocmset/tiocmget driver methods instead. The
734 * #if 0 disablement predates this comment.
737 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
738 sizeof(unsigned int))) == 0) {
739 ival = rio_getsignals(port);
740 put_user(ival, (unsigned int *) arg);
744 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
745 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1),
746 ((ival & TIOCM_RTS) ? 1 : -1));
750 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
751 rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1),
752 ((ival & TIOCM_RTS) ? 0 : -1));
756 if ((rc = get_user(ival, (unsigned int *) arg)) == 0) {
757 rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0),
758 ((ival & TIOCM_RTS) ? 1 : 0));
771 /* The throttle/unthrottle scheme for the Specialix card is different
772 * from other drivers and deserves some explanation.
773 * The Specialix hardware takes care of XON/XOFF
774 * and CTS/RTS flow control itself. This means that all we have to
775 * do when signalled by the upper tty layer to throttle/unthrottle is
776 * to make a note of it here. When we come to read characters from the
777 * rx buffers on the card (rio_receive_chars()) we look to see if the
778 * upper layer can accept more (as noted here in rio_rx_throt[]).
779 * If it can't we simply don't remove chars from the cards buffer.
780 * When the tty layer can accept chars, we again note that here and when
781 * rio_receive_chars() is called it will remove them from the cards buffer.
782 * The card will notice that a ports buffer has drained below some low
783 * water mark and will unflow control the line itself, using whatever
784 * flow control scheme is in use for that port. -- Simon Allen
787 static void rio_throttle (struct tty_struct * tty)
789 struct Port *port = (struct Port *)tty->driver_data;
792 /* If the port is using any type of input flow
793 * control then throttle the port.
796 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
797 port->State |= RIO_THROTTLE_RX;
804 static void rio_unthrottle (struct tty_struct * tty)
806 struct Port *port = (struct Port *)tty->driver_data;
809 /* Always unthrottle even if flow control is not enabled on
810 * this port in case we disabled flow control while the port
814 port->State &= ~RIO_THROTTLE_RX;
824 /* ********************************************************************** *
825 * Here are the initialization routines. *
826 * ********************************************************************** */
829 struct vpd_prom *get_VPD_PROM (struct Host *hp)
831 static struct vpd_prom vpdp;
836 rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
837 hp->Caddr + RIO_VPD_ROM);
840 for (i=0;i< sizeof (struct vpd_prom);i++)
841 *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2);
842 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
844 /* Terminate the identifier string.
845 *** requires one extra byte in struct vpd_prom *** */
848 if (rio_debug & RIO_DEBUG_PROBE)
849 my_hd ((char *)&vpdp, 0x20);
856 static struct tty_operations rio_ops = {
860 .put_char = gs_put_char,
861 .flush_chars = gs_flush_chars,
862 .write_room = gs_write_room,
863 .chars_in_buffer = gs_chars_in_buffer,
864 .flush_buffer = gs_flush_buffer,
866 .throttle = rio_throttle,
867 .unthrottle = rio_unthrottle,
868 .set_termios = gs_set_termios,
874 static int rio_init_drivers(void)
878 rio_driver = alloc_tty_driver(256);
881 rio_driver2 = alloc_tty_driver(256);
887 rio_driver->owner = THIS_MODULE;
888 rio_driver->driver_name = "specialix_rio";
889 rio_driver->name = "ttySR";
890 rio_driver->major = RIO_NORMAL_MAJOR0;
891 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
892 rio_driver->subtype = SERIAL_TYPE_NORMAL;
893 rio_driver->init_termios = tty_std_termios;
894 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
895 rio_driver->flags = TTY_DRIVER_REAL_RAW;
896 tty_set_operations(rio_driver, &rio_ops);
898 rio_driver2->owner = THIS_MODULE;
899 rio_driver2->driver_name = "specialix_rio";
900 rio_driver2->name = "ttySR";
901 rio_driver2->major = RIO_NORMAL_MAJOR1;
902 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
903 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
904 rio_driver2->init_termios = tty_std_termios;
905 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
906 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
907 tty_set_operations(rio_driver2, &rio_ops);
909 rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
911 if ((error = tty_register_driver(rio_driver)))
913 if ((error = tty_register_driver(rio_driver2)))
918 tty_unregister_driver(rio_driver);
920 put_tty_driver(rio_driver2);
922 put_tty_driver(rio_driver);
924 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n",
930 static void * ckmalloc (int size)
934 p = kmalloc(size, GFP_KERNEL);
942 static int rio_init_datastructures (void)
948 /* Many drivers statically allocate the maximum number of ports
949 There is no reason not to allocate them dynamically. Is there? -- REW */
950 /* However, the RIO driver allows users to configure their first
951 RTA as the ports numbered 504-511. We therefore need to allocate
952 the whole range. :-( -- REW */
954 #define RI_SZ sizeof(struct rio_info)
955 #define HOST_SZ sizeof(struct Host)
956 #define PORT_SZ sizeof(struct Port *)
957 #define TMIO_SZ sizeof(struct termios *)
958 rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n",
963 RIO_PORTS * TMIO_SZ);
965 if (!(p = ckmalloc ( RI_SZ))) goto free0;
966 if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1;
967 if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2;
968 p->RIOConf = RIOConf;
969 rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n",
970 p, p->RIOHosts, p->RIOPortp);
973 for (i = 0; i < RIO_PORTS; i++) {
974 port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port));
978 rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
980 port->gs.magic = RIO_MAGIC;
981 port->gs.close_delay = HZ/2;
982 port->gs.closing_wait = 30 * HZ;
983 port->gs.rd = &rio_real_driver;
984 port->portSem = SPIN_LOCK_UNLOCKED;
986 * Initializing wait queue
988 init_waitqueue_head(&port->gs.open_wait);
989 init_waitqueue_head(&port->gs.close_wait);
992 /* We could postpone initializing them to when they are configured. */
997 if (rio_debug & RIO_DEBUG_INIT) {
998 my_hd (&rio_real_driver, sizeof (rio_real_driver));
1005 free6:for (i--;i>=0;i--)
1006 kfree (p->RIOPortp[i]);
1009 free3:*/kfree (p->RIOPortp);
1010 free2:kfree (p->RIOHosts);
1012 rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n",
1013 p, p->RIOHosts, p->RIOPortp);
1019 static void __exit rio_release_drivers(void)
1022 tty_unregister_driver(rio_driver2);
1023 tty_unregister_driver(rio_driver);
1024 put_tty_driver(rio_driver2);
1025 put_tty_driver(rio_driver);
1031 /* This was written for SX, but applies to RIO too...
1032 (including bugs....)
1034 There is another bit besides Bit 17. Turning that bit off
1035 (on boards shipped with the fix in the eeprom) results in a
1036 hang on the next access to the card.
1039 /********************************************************
1040 * Setting bit 17 in the CNTRL register of the PLX 9050 *
1041 * chip forces a retry on writes while a read is pending.*
1042 * This is to prevent the card locking up on Intel Xeon *
1043 * multiprocessor systems with the NX chipset. -- NV *
1044 ********************************************************/
1046 /* Newer cards are produced with this bit set from the configuration
1047 EEprom. As the bit is read/write for the CPU, we can fix it here,
1048 if we detect that it isn't set correctly. -- REW */
1050 void fix_rio_pci (struct pci_dev *pdev)
1052 unsigned int hwbase;
1053 unsigned long rebase;
1056 #define CNTRL_REG_OFFSET 0x50
1057 #define CNTRL_REG_GOODVALUE 0x18260000
1059 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
1060 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
1061 rebase = (ulong) ioremap(hwbase, 0x80);
1062 t = readl (rebase + CNTRL_REG_OFFSET);
1063 if (t != CNTRL_REG_GOODVALUE) {
1064 printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n",
1065 t, CNTRL_REG_GOODVALUE);
1066 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
1068 iounmap((char*) rebase);
1073 static int __init rio_init(void)
1079 struct vpd_prom *vpdp;
1083 struct pci_dev *pdev = NULL;
1085 unsigned short tshort;
1089 rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n",
1092 if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) {
1093 printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. "
1094 "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
1098 if (misc_register(&rio_fw_device) < 0) {
1099 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
1103 retval = rio_init_datastructures ();
1105 misc_deregister(&rio_fw_device);
1110 /* First look for the JET devices: */
1111 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
1112 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
1114 if (pci_enable_device(pdev)) continue;
1116 /* Specialix has a whole bunch of cards with
1117 0x2000 as the device ID. They say its because
1118 the standard requires it. Stupid standard. */
1119 /* It seems that reading a word doesn't work reliably on 2.0.
1120 Also, reading a non-aligned dword doesn't work. So we read the
1121 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1123 /* I don't know why the define doesn't work, constant 0x2c does --REW */
1124 pci_read_config_dword (pdev, 0x2c, &tint);
1125 tshort = (tint >> 16) & 0xffff;
1126 rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
1127 if (tshort != 0x0100) {
1128 rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n",
1132 rio_dprintk (RIO_DEBUG_PROBE, "cp1\n");
1134 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
1136 hp = &p->RIOHosts[p->RIONumHosts];
1137 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1138 hp->Ivec = pdev->irq;
1139 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1141 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1142 hp->CardP = (struct DpRam *) hp->Caddr;
1144 hp->Copy = rio_pcicopy;
1145 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1146 hp->HostLock = SPIN_LOCK_UNLOCKED;
1147 rio_reset_interrupt (hp);
1148 rio_start_card_running (hp);
1150 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1151 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1152 p->RIOHosts[p->RIONumHosts].Caddr);
1153 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1154 p->RIOHosts[p->RIONumHosts].Caddr,
1155 RIO_PCI, 0 ) == RIO_SUCCESS) {
1156 rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1157 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1158 p->RIOHosts[p->RIONumHosts].UniqueNum =
1159 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1160 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1161 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1162 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1163 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1164 p->RIOHosts[p->RIONumHosts].UniqueNum);
1167 p->RIOLastPCISearch = RIO_SUCCESS;
1171 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1175 /* Then look for the older PCI card.... : */
1177 /* These older PCI cards have problems (only byte-mode access is
1178 supported), which makes them a bit awkward to support.
1179 They also have problems sharing interrupts. Be careful.
1180 (The driver now refuses to share interrupts for these
1181 cards. This should be sufficient).
1184 /* Then look for the older RIO/PCI devices: */
1185 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
1186 PCI_DEVICE_ID_SPECIALIX_RIO,
1188 if (pci_enable_device(pdev)) continue;
1190 #ifdef CONFIG_RIO_OLDPCI
1191 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
1193 hp = &p->RIOHosts[p->RIONumHosts];
1194 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK;
1195 hp->Ivec = pdev->irq;
1196 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1198 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1199 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1200 hp->CardP = (struct DpRam *) hp->Caddr;
1202 hp->Copy = rio_pcicopy;
1203 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1204 hp->HostLock = SPIN_LOCK_UNLOCKED;
1206 rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1207 rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1209 rio_reset_interrupt (hp);
1210 rio_start_card_running (hp);
1211 rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n",
1212 (void *)p->RIOHosts[p->RIONumHosts].PaddrP,
1213 p->RIOHosts[p->RIONumHosts].Caddr);
1214 if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP,
1215 p->RIOHosts[p->RIONumHosts].Caddr,
1216 RIO_PCI, 0 ) == RIO_SUCCESS) {
1217 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff);
1218 p->RIOHosts[p->RIONumHosts].UniqueNum =
1219 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)|
1220 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)|
1221 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)|
1222 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24);
1223 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1224 p->RIOHosts[p->RIONumHosts].UniqueNum);
1226 p->RIOLastPCISearch = RIO_SUCCESS;
1230 iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr));
1233 printk (KERN_ERR "Found an older RIO PCI card, but the driver is not "
1234 "compiled to support it.\n");
1239 /* Now probe for ISA cards... */
1240 for (i=0;i<NR_RIO_ADDRS;i++) {
1241 hp = &p->RIOHosts[p->RIONumHosts];
1242 hp->PaddrP = rio_probe_addrs[i];
1243 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1245 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1246 hp->CardP = (struct DpRam *) hp->Caddr;
1248 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL
1249 * -- YES! this is now a normal copy. Only the
1250 * old PCI card uses the special PCI copy.
1251 * Moreover, the ISA card will work with the
1252 * special PCI copy anyway. -- REW */
1254 hp->HostLock = SPIN_LOCK_UNLOCKED;
1256 vpdp = get_VPD_PROM (hp);
1257 rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n");
1259 if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) ||
1260 (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) ||
1261 (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1262 /* Board is present... */
1263 if (RIOBoardTest (hp->PaddrP,
1264 hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) {
1265 /* ... and feeling fine!!!! */
1266 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n",
1267 p->RIOHosts[p->RIONumHosts].UniqueNum);
1268 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1269 rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n",
1271 p->RIOHosts[p->RIONumHosts-1].UniqueNum);
1278 iounmap ((char*) (hp->Caddr));
1283 for (i=0;i<p->RIONumHosts;i++) {
1284 hp = &p->RIOHosts[i];
1286 int mode = SA_SHIRQ;
1287 if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;}
1288 rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode);
1289 retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp);
1290 rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1292 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1295 rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1297 rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1298 hp->Mode |= RIO_PCI_INT_ENABLE;
1300 hp->Mode &= !RIO_PCI_INT_ENABLE;
1301 rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1302 rio_start_card_running (hp);
1304 /* Init the timer "always" to make sure that it can safely be
1305 deleted when we unload... */
1307 init_timer (&hp->timer);
1309 rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n",
1312 hp->timer.function = rio_pollfunc;
1313 hp->timer.expires = jiffies + rio_poll;
1314 add_timer (&hp->timer);
1319 rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1320 rio_init_drivers ();
1322 /* deregister the misc device we created earlier */
1323 misc_deregister(&rio_fw_device);
1327 return found?0:-EIO;
1331 static void __exit rio_exit (void)
1338 for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) {
1339 RIOHostReset (hp->Type, hp->CardP, hp->Slot);
1341 free_irq (hp->Ivec, hp);
1342 rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1344 /* It is safe/allowed to del_timer a non-active timer */
1345 del_timer (&hp->timer);
1348 if (misc_deregister(&rio_fw_device) < 0) {
1349 printk (KERN_INFO "rio: couldn't deregister control-device\n");
1353 rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1355 rio_release_drivers ();
1357 /* Release dynamically allocated memory */
1358 kfree (p->RIOPortp);
1359 kfree (p->RIOHosts);
1365 module_init(rio_init);
1366 module_exit(rio_exit);
1369 * Anybody who knows why this doesn't work for me, please tell me -- REW.
1370 * Snatched from scsi.c (fixed one spelling error):
1371 * Overrides for Emacs so that we follow Linus' tabbing style.
1372 * Emacs will notice this stuff at the end of the file and automatically
1373 * adjust the settings for this buffer only. This must remain at the end
1375 * ---------------------------------------------------------------------------
1378 * c-brace-imaginary-offset: 0
1379 * c-brace-offset: -4
1380 * c-argdecl-indent: 4
1381 * c-label-offset: -4
1382 * c-continued-statement-offset: 4
1383 * c-continued-brace-offset: 0
1384 * indent-tabs-mode: nil