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/kdev_t.h>
38 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/ioport.h>
41 #include <linux/interrupt.h>
42 #include <linux/errno.h>
43 #include <linux/tty.h>
44 #include <linux/tty_flip.h>
46 #include <linux/serial.h>
47 #include <linux/fcntl.h>
48 #include <linux/major.h>
49 #include <linux/delay.h>
50 #include <linux/pci.h>
51 #include <linux/slab.h>
52 #include <linux/miscdevice.h>
53 #include <linux/init.h>
55 #include <linux/generic_serial.h>
56 #include <asm/uaccess.h>
58 #include "linux_compat.h"
88 #include "rio_linux.h"
90 /* I don't think that this driver can handle more than 512 ports on
91 one machine. Specialix specifies max 4 boards in one machine. I don't
92 know why. If you want to try anyway you'll have to increase the number
93 of boards in rio.h. You'll have to allocate more majors if you need
94 more than 512 ports.... */
96 #ifndef RIO_NORMAL_MAJOR0
97 /* This allows overriding on the compiler commandline, or in a "major.h"
98 include or something like that */
99 #define RIO_NORMAL_MAJOR0 154
100 #define RIO_NORMAL_MAJOR1 156
103 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
104 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
107 #ifndef RIO_WINDOW_LEN
108 #define RIO_WINDOW_LEN 0x10000
112 /* Configurable options:
113 (Don't be too sure that it'll work if you toggle them) */
115 /* Am I paranoid or not ? ;-) */
116 #undef RIO_PARANOIA_CHECK
119 /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
120 Hz, but it is user configurable. I don't recommend going above 1000
121 Hz. The interrupt ratelimit might trigger if the interrupt is
122 shared with a very active other device.
123 undef this if you want to disable the check....
125 #define IRQ_RATE_LIMIT 200
128 /* These constants are derived from SCO Source */
131 /* locator */ "RIO Config here",
132 /* startuptime */ HZ
* 2,
133 /* how long to wait for card to run */
135 /* TRUE -> always use line disc. */
136 /* intrpolltime */ 1,
137 /* The frequency of OUR polls */
138 /* breakinterval */ 25,
139 /* x10 mS XXX: units seem to be 1ms not 10! -- REW */
142 /* RtaLoadBase */ 0x7000,
143 /* HostLoadBase */ 0x7C00,
145 /* number of Xprint hits per second */
147 /* Xprint characters per second */
149 /* start Xprint for a wyse 60 */
151 /* end Xprint for a wyse 60 */
153 /* highest Xprint speed */
155 /* slowest Xprint speed */
157 /* non-zero for mega fast boots */
158 /* First Addr */ 0x0A0000,
159 /* First address to look at */
160 /* Last Addr */ 0xFF0000,
161 /* Last address looked at */
162 /* BufferSize */ 1024,
163 /* Bytes per port of buffering */
165 /* how much data left before wakeup */
167 /* how wide is the console? */
169 /* how long a close command may take */
175 /* Function prototypes */
177 static void rio_disable_tx_interrupts(void *ptr
);
178 static void rio_enable_tx_interrupts(void *ptr
);
179 static void rio_disable_rx_interrupts(void *ptr
);
180 static void rio_enable_rx_interrupts(void *ptr
);
181 static int rio_get_CD(void *ptr
);
182 static void rio_shutdown_port(void *ptr
);
183 static int rio_set_real_termios(void *ptr
);
184 static void rio_hungup(void *ptr
);
185 static void rio_close(void *ptr
);
186 static int rio_chars_in_buffer(void *ptr
);
187 static int rio_fw_ioctl(struct inode
*inode
, struct file
*filp
, unsigned int cmd
, unsigned long arg
);
188 static int rio_init_drivers(void);
190 static void my_hd(void *addr
, int len
);
192 static struct tty_driver
*rio_driver
, *rio_driver2
;
194 /* The name "p" is a bit non-descript. But that's what the rio-lynxos
195 sources use all over the place. */
201 /* You can have the driver poll your card.
202 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
203 This is used when the card cannot use an interrupt for some reason.
205 static int rio_poll
= 1;
208 /* These are the only open spaces in my computer. Yours may have more
210 static int rio_probe_addrs
[] = { 0xc0000, 0xd0000, 0xe0000 };
212 #define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
215 /* Set the mask to all-ones. This alas, only supports 32 interrupts.
216 Some architectures may need more. -- Changed to LONG to
217 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
218 static long rio_irqmask
= -1;
220 MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
221 MODULE_DESCRIPTION("RIO driver");
222 MODULE_LICENSE("GPL");
223 module_param(rio_poll
, int, 0);
224 module_param(rio_debug
, int, 0644);
225 module_param(rio_irqmask
, long, 0);
227 static struct real_driver rio_real_driver
= {
228 rio_disable_tx_interrupts
,
229 rio_enable_tx_interrupts
,
230 rio_disable_rx_interrupts
,
231 rio_enable_rx_interrupts
,
234 rio_set_real_termios
,
242 * Firmware loader driver specific routines
246 static const struct file_operations rio_fw_fops
= {
247 .owner
= THIS_MODULE
,
248 .ioctl
= rio_fw_ioctl
,
251 static struct miscdevice rio_fw_device
= {
252 RIOCTL_MISC_MINOR
, "rioctl", &rio_fw_fops
259 #ifdef RIO_PARANOIA_CHECK
261 /* This doesn't work. Who's paranoid around here? Not me! */
263 static inline int rio_paranoia_check(struct rio_port
const *port
, char *name
, const char *routine
)
266 static const char *badmagic
= KERN_ERR
"rio: Warning: bad rio port magic number for device %s in %s\n";
267 static const char *badinfo
= KERN_ERR
"rio: Warning: null rio port for device %s in %s\n";
270 printk(badinfo
, name
, routine
);
273 if (port
->magic
!= RIO_MAGIC
) {
274 printk(badmagic
, name
, routine
);
281 #define rio_paranoia_check(a,b,c) 0
286 static void my_hd(void *ad
, int len
)
289 unsigned char *addr
= ad
;
291 for (i
= 0; i
< len
; i
+= 16) {
292 rio_dprintk(RIO_DEBUG_PARAM
, "%08lx ", (unsigned long) addr
+ i
);
293 for (j
= 0; j
< 16; j
++) {
294 rio_dprintk(RIO_DEBUG_PARAM
, "%02x %s", addr
[j
+ i
], (j
== 7) ? " " : "");
296 for (j
= 0; j
< 16; j
++) {
298 rio_dprintk(RIO_DEBUG_PARAM
, "%c", (ch
< 0x20) ? '.' : ((ch
> 0x7f) ? '.' : ch
));
300 rio_dprintk(RIO_DEBUG_PARAM
, "\n");
304 #define my_hd(ad,len) do{/* nothing*/ } while (0)
308 /* Delay a number of jiffies, allowing a signal to interrupt */
309 int RIODelay(struct Port
*PortP
, int njiffies
)
313 rio_dprintk(RIO_DEBUG_DELAY
, "delaying %d jiffies\n", njiffies
);
314 msleep_interruptible(jiffies_to_msecs(njiffies
));
317 if (signal_pending(current
))
324 /* Delay a number of jiffies, disallowing a signal to interrupt */
325 int RIODelay_ni(struct Port
*PortP
, int njiffies
)
329 rio_dprintk(RIO_DEBUG_DELAY
, "delaying %d jiffies (ni)\n", njiffies
);
330 msleep(jiffies_to_msecs(njiffies
));
335 void rio_copy_to_card(void *from
, void __iomem
*to
, int len
)
337 rio_copy_toio(to
, from
, len
);
340 int rio_minor(struct tty_struct
*tty
)
342 return tty
->index
+ (tty
->driver
== rio_driver
) ? 0 : 256;
345 static int rio_set_real_termios(void *ptr
)
347 return RIOParam((struct Port
*) ptr
, CONFIG
, 1, 1);
351 static void rio_reset_interrupt(struct Host
*HostP
)
355 switch (HostP
->Type
) {
359 writeb(0xFF, &HostP
->ResetInt
);
366 static irqreturn_t
rio_interrupt(int irq
, void *ptr
)
371 HostP
= ptr
; /* &p->RIOHosts[(long)ptr]; */
372 rio_dprintk(RIO_DEBUG_IFLOW
, "rio: enter rio_interrupt (%d/%d)\n", irq
, HostP
->Ivec
);
374 /* AAargh! The order in which to do these things is essential and
377 - hardware twiddling goes before "recursive". Otherwise when we
378 poll the card, and a recursive interrupt happens, we won't
379 ack the card, so it might keep on interrupting us. (especially
380 level sensitive interrupt systems like PCI).
382 - Rate limit goes before hardware twiddling. Otherwise we won't
383 catch a card that has gone bonkers.
385 - The "initialized" test goes after the hardware twiddling. Otherwise
386 the card will stick us in the interrupt routine again.
388 - The initialized test goes before recursive.
391 rio_dprintk(RIO_DEBUG_IFLOW
, "rio: We've have noticed the interrupt\n");
392 if (HostP
->Ivec
== irq
) {
393 /* Tell the card we've noticed the interrupt. */
394 rio_reset_interrupt(HostP
);
397 if ((HostP
->Flags
& RUN_STATE
) != RC_RUNNING
)
400 if (test_and_set_bit(RIO_BOARD_INTR_LOCK
, &HostP
->locks
)) {
401 printk(KERN_ERR
"Recursive interrupt! (host %p/irq%d)\n", ptr
, HostP
->Ivec
);
405 RIOServiceHost(p
, HostP
);
407 rio_dprintk(RIO_DEBUG_IFLOW
, "riointr() doing host %p type %d\n", ptr
, HostP
->Type
);
409 clear_bit(RIO_BOARD_INTR_LOCK
, &HostP
->locks
);
410 rio_dprintk(RIO_DEBUG_IFLOW
, "rio: exit rio_interrupt (%d/%d)\n", irq
, HostP
->Ivec
);
416 static void rio_pollfunc(unsigned long data
)
420 rio_interrupt(0, &p
->RIOHosts
[data
]);
421 mod_timer(&p
->RIOHosts
[data
].timer
, jiffies
+ rio_poll
);
427 /* ********************************************************************** *
428 * Here are the routines that actually *
429 * interface with the generic_serial driver *
430 * ********************************************************************** */
432 /* Ehhm. I don't know how to fiddle with interrupts on the Specialix
433 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
435 static void rio_disable_tx_interrupts(void *ptr
)
439 /* port->gs.flags &= ~GS_TX_INTEN; */
445 static void rio_enable_tx_interrupts(void *ptr
)
447 struct Port
*PortP
= ptr
;
452 /* hn = PortP->HostP - p->RIOHosts;
454 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
455 rio_interrupt (-1,(void *) hn, NULL); */
457 RIOTxEnable((char *) PortP
);
460 * In general we cannot count on "tx empty" interrupts, although
461 * the interrupt routine seems to be able to tell the difference.
463 PortP
->gs
.flags
&= ~GS_TX_INTEN
;
469 static void rio_disable_rx_interrupts(void *ptr
)
475 static void rio_enable_rx_interrupts(void *ptr
)
477 /* struct rio_port *port = ptr; */
483 /* Jeez. Isn't this simple? */
484 static int rio_get_CD(void *ptr
)
486 struct Port
*PortP
= ptr
;
490 rv
= (PortP
->ModemState
& MSVR1_CD
) != 0;
492 rio_dprintk(RIO_DEBUG_INIT
, "Getting CD status: %d\n", rv
);
499 /* Jeez. Isn't this simple? Actually, we can sync with the actual port
500 by just pushing stuff into the queue going to the port... */
501 static int rio_chars_in_buffer(void *ptr
)
510 /* Nothing special here... */
511 static void rio_shutdown_port(void *ptr
)
517 PortP
= (struct Port
*) ptr
;
518 PortP
->gs
.tty
= NULL
;
523 /* I haven't the foggiest why the decrement use count has to happen
524 here. The whole linux serial drivers stuff needs to be redesigned.
525 My guess is that this is a hack to minimize the impact of a bug
526 elsewhere. Thinking about it some more. (try it sometime) Try
527 running minicom on a serial port that is driven by a modularized
528 driver. Have the modem hangup. Then remove the driver module. Then
529 exit minicom. I expect an "oops". -- REW */
530 static void rio_hungup(void *ptr
)
536 PortP
= (struct Port
*) ptr
;
537 PortP
->gs
.tty
= NULL
;
543 /* The standard serial_close would become shorter if you'd wrap it like
545 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
547 static void rio_close(void *ptr
)
553 PortP
= (struct Port
*) ptr
;
557 if (PortP
->gs
.count
) {
558 printk(KERN_ERR
"WARNING port count:%d\n", PortP
->gs
.count
);
562 PortP
->gs
.tty
= NULL
;
568 static int rio_fw_ioctl(struct inode
*inode
, struct file
*filp
, unsigned int cmd
, unsigned long arg
)
573 /* The "dev" argument isn't used. */
574 rc
= riocontrol(p
, 0, cmd
, arg
, capable(CAP_SYS_ADMIN
));
580 extern int RIOShortCommand(struct rio_info
*p
, struct Port
*PortP
, int command
, int len
, int arg
);
582 static int rio_ioctl(struct tty_struct
*tty
, struct file
*filp
, unsigned int cmd
, unsigned long arg
)
584 void __user
*argp
= (void __user
*)arg
;
591 PortP
= (struct Port
*) tty
->driver_data
;
596 if ((rc
= get_user(ival
, (unsigned __user
*) argp
)) == 0) {
597 tty
->termios
->c_cflag
= (tty
->termios
->c_cflag
& ~CLOCAL
) | (ival
? CLOCAL
: 0);
602 if (access_ok(VERIFY_WRITE
, argp
, sizeof(struct serial_struct
)))
603 rc
= gs_getserial(&PortP
->gs
, argp
);
606 if (PortP
->State
& RIO_DELETED
) {
607 rio_dprintk(RIO_DEBUG_TTY
, "BREAK on deleted RTA\n");
610 if (RIOShortCommand(p
, PortP
, SBREAK
, 2, 250) == RIO_FAIL
) {
611 rio_dprintk(RIO_DEBUG_INTR
, "SBREAK RIOShortCommand failed\n");
617 if (PortP
->State
& RIO_DELETED
) {
618 rio_dprintk(RIO_DEBUG_TTY
, "BREAK on deleted RTA\n");
622 l
= arg
? arg
* 100 : 250;
625 if (RIOShortCommand(p
, PortP
, SBREAK
, 2, arg
? arg
* 100 : 250) == RIO_FAIL
) {
626 rio_dprintk(RIO_DEBUG_INTR
, "SBREAK RIOShortCommand failed\n");
633 if (access_ok(VERIFY_READ
, argp
, sizeof(struct serial_struct
)))
634 rc
= gs_setserial(&PortP
->gs
, argp
);
645 /* The throttle/unthrottle scheme for the Specialix card is different
646 * from other drivers and deserves some explanation.
647 * The Specialix hardware takes care of XON/XOFF
648 * and CTS/RTS flow control itself. This means that all we have to
649 * do when signalled by the upper tty layer to throttle/unthrottle is
650 * to make a note of it here. When we come to read characters from the
651 * rx buffers on the card (rio_receive_chars()) we look to see if the
652 * upper layer can accept more (as noted here in rio_rx_throt[]).
653 * If it can't we simply don't remove chars from the cards buffer.
654 * When the tty layer can accept chars, we again note that here and when
655 * rio_receive_chars() is called it will remove them from the cards buffer.
656 * The card will notice that a ports buffer has drained below some low
657 * water mark and will unflow control the line itself, using whatever
658 * flow control scheme is in use for that port. -- Simon Allen
661 static void rio_throttle(struct tty_struct
*tty
)
663 struct Port
*port
= (struct Port
*) tty
->driver_data
;
666 /* If the port is using any type of input flow
667 * control then throttle the port.
670 if ((tty
->termios
->c_cflag
& CRTSCTS
) || (I_IXOFF(tty
))) {
671 port
->State
|= RIO_THROTTLE_RX
;
678 static void rio_unthrottle(struct tty_struct
*tty
)
680 struct Port
*port
= (struct Port
*) tty
->driver_data
;
683 /* Always unthrottle even if flow control is not enabled on
684 * this port in case we disabled flow control while the port
688 port
->State
&= ~RIO_THROTTLE_RX
;
698 /* ********************************************************************** *
699 * Here are the initialization routines. *
700 * ********************************************************************** */
703 static struct vpd_prom
*get_VPD_PROM(struct Host
*hp
)
705 static struct vpd_prom vpdp
;
710 rio_dprintk(RIO_DEBUG_PROBE
, "Going to verify vpd prom at %p.\n", hp
->Caddr
+ RIO_VPD_ROM
);
713 for (i
= 0; i
< sizeof(struct vpd_prom
); i
++)
714 *p
++ = readb(hp
->Caddr
+ RIO_VPD_ROM
+ i
* 2);
715 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
717 /* Terminate the identifier string.
718 *** requires one extra byte in struct vpd_prom *** */
721 if (rio_debug
& RIO_DEBUG_PROBE
)
722 my_hd((char *) &vpdp
, 0x20);
729 static const struct tty_operations rio_ops
= {
733 .put_char
= gs_put_char
,
734 .flush_chars
= gs_flush_chars
,
735 .write_room
= gs_write_room
,
736 .chars_in_buffer
= gs_chars_in_buffer
,
737 .flush_buffer
= gs_flush_buffer
,
739 .throttle
= rio_throttle
,
740 .unthrottle
= rio_unthrottle
,
741 .set_termios
= gs_set_termios
,
747 static int rio_init_drivers(void)
751 rio_driver
= alloc_tty_driver(256);
754 rio_driver2
= alloc_tty_driver(256);
760 rio_driver
->owner
= THIS_MODULE
;
761 rio_driver
->driver_name
= "specialix_rio";
762 rio_driver
->name
= "ttySR";
763 rio_driver
->major
= RIO_NORMAL_MAJOR0
;
764 rio_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
765 rio_driver
->subtype
= SERIAL_TYPE_NORMAL
;
766 rio_driver
->init_termios
= tty_std_termios
;
767 rio_driver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
768 rio_driver
->flags
= TTY_DRIVER_REAL_RAW
;
769 tty_set_operations(rio_driver
, &rio_ops
);
771 rio_driver2
->owner
= THIS_MODULE
;
772 rio_driver2
->driver_name
= "specialix_rio";
773 rio_driver2
->name
= "ttySR";
774 rio_driver2
->major
= RIO_NORMAL_MAJOR1
;
775 rio_driver2
->type
= TTY_DRIVER_TYPE_SERIAL
;
776 rio_driver2
->subtype
= SERIAL_TYPE_NORMAL
;
777 rio_driver2
->init_termios
= tty_std_termios
;
778 rio_driver2
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
779 rio_driver2
->flags
= TTY_DRIVER_REAL_RAW
;
780 tty_set_operations(rio_driver2
, &rio_ops
);
782 rio_dprintk(RIO_DEBUG_INIT
, "set_termios = %p\n", gs_set_termios
);
784 if ((error
= tty_register_driver(rio_driver
)))
786 if ((error
= tty_register_driver(rio_driver2
)))
791 tty_unregister_driver(rio_driver
);
793 put_tty_driver(rio_driver2
);
795 put_tty_driver(rio_driver
);
797 printk(KERN_ERR
"rio: Couldn't register a rio driver, error = %d\n", error
);
802 static void *ckmalloc(int size
)
806 p
= kmalloc(size
, GFP_KERNEL
);
814 static int rio_init_datastructures(void)
820 /* Many drivers statically allocate the maximum number of ports
821 There is no reason not to allocate them dynamically. Is there? -- REW */
822 /* However, the RIO driver allows users to configure their first
823 RTA as the ports numbered 504-511. We therefore need to allocate
824 the whole range. :-( -- REW */
826 #define RI_SZ sizeof(struct rio_info)
827 #define HOST_SZ sizeof(struct Host)
828 #define PORT_SZ sizeof(struct Port *)
829 #define TMIO_SZ sizeof(struct termios *)
830 rio_dprintk(RIO_DEBUG_INIT
, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ
, RIO_HOSTS
* HOST_SZ
, RIO_PORTS
* PORT_SZ
, RIO_PORTS
* TMIO_SZ
, RIO_PORTS
* TMIO_SZ
);
832 if (!(p
= ckmalloc(RI_SZ
)))
834 if (!(p
->RIOHosts
= ckmalloc(RIO_HOSTS
* HOST_SZ
)))
836 if (!(p
->RIOPortp
= ckmalloc(RIO_PORTS
* PORT_SZ
)))
838 p
->RIOConf
= RIOConf
;
839 rio_dprintk(RIO_DEBUG_INIT
, "Got : %p %p %p\n", p
, p
->RIOHosts
, p
->RIOPortp
);
842 for (i
= 0; i
< RIO_PORTS
; i
++) {
843 port
= p
->RIOPortp
[i
] = ckmalloc(sizeof(struct Port
));
847 rio_dprintk(RIO_DEBUG_INIT
, "initing port %d (%d)\n", i
, port
->Mapped
);
849 port
->gs
.magic
= RIO_MAGIC
;
850 port
->gs
.close_delay
= HZ
/ 2;
851 port
->gs
.closing_wait
= 30 * HZ
;
852 port
->gs
.rd
= &rio_real_driver
;
853 spin_lock_init(&port
->portSem
);
855 * Initializing wait queue
857 init_waitqueue_head(&port
->gs
.open_wait
);
858 init_waitqueue_head(&port
->gs
.close_wait
);
861 /* We could postpone initializing them to when they are configured. */
866 if (rio_debug
& RIO_DEBUG_INIT
) {
867 my_hd(&rio_real_driver
, sizeof(rio_real_driver
));
874 free6
:for (i
--; i
>= 0; i
--)
875 kfree(p
->RIOPortp
[i
]);
878 free3:*/ kfree(p
->RIOPortp
);
879 free2
:kfree(p
->RIOHosts
);
881 rio_dprintk(RIO_DEBUG_INIT
, "Not enough memory! %p %p %p\n", p
, p
->RIOHosts
, p
->RIOPortp
);
887 static void __exit
rio_release_drivers(void)
890 tty_unregister_driver(rio_driver2
);
891 tty_unregister_driver(rio_driver
);
892 put_tty_driver(rio_driver2
);
893 put_tty_driver(rio_driver
);
899 /* This was written for SX, but applies to RIO too...
902 There is another bit besides Bit 17. Turning that bit off
903 (on boards shipped with the fix in the eeprom) results in a
904 hang on the next access to the card.
907 /********************************************************
908 * Setting bit 17 in the CNTRL register of the PLX 9050 *
909 * chip forces a retry on writes while a read is pending.*
910 * This is to prevent the card locking up on Intel Xeon *
911 * multiprocessor systems with the NX chipset. -- NV *
912 ********************************************************/
914 /* Newer cards are produced with this bit set from the configuration
915 EEprom. As the bit is read/write for the CPU, we can fix it here,
916 if we detect that it isn't set correctly. -- REW */
918 static void fix_rio_pci(struct pci_dev
*pdev
)
920 unsigned long hwbase
;
921 unsigned char __iomem
*rebase
;
924 #define CNTRL_REG_OFFSET 0x50
925 #define CNTRL_REG_GOODVALUE 0x18260000
927 hwbase
= pci_resource_start(pdev
, 0);
928 rebase
= ioremap(hwbase
, 0x80);
929 t
= readl(rebase
+ CNTRL_REG_OFFSET
);
930 if (t
!= CNTRL_REG_GOODVALUE
) {
931 printk(KERN_DEBUG
"rio: performing cntrl reg fix: %08x -> %08x\n", t
, CNTRL_REG_GOODVALUE
);
932 writel(CNTRL_REG_GOODVALUE
, rebase
+ CNTRL_REG_OFFSET
);
939 static int __init
rio_init(void)
945 struct vpd_prom
*vpdp
;
949 struct pci_dev
*pdev
= NULL
;
950 unsigned short tshort
;
954 rio_dprintk(RIO_DEBUG_INIT
, "Initing rio module... (rio_debug=%d)\n", rio_debug
);
956 if (abs((long) (&rio_debug
) - rio_debug
) < 0x10000) {
957 printk(KERN_WARNING
"rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug
, &rio_debug
);
961 if (misc_register(&rio_fw_device
) < 0) {
962 printk(KERN_ERR
"RIO: Unable to register firmware loader driver.\n");
966 retval
= rio_init_datastructures();
968 misc_deregister(&rio_fw_device
);
972 /* First look for the JET devices: */
973 while ((pdev
= pci_get_device(PCI_VENDOR_ID_SPECIALIX
, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
, pdev
))) {
976 if (pci_enable_device(pdev
))
979 /* Specialix has a whole bunch of cards with
980 0x2000 as the device ID. They say its because
981 the standard requires it. Stupid standard. */
982 /* It seems that reading a word doesn't work reliably on 2.0.
983 Also, reading a non-aligned dword doesn't work. So we read the
984 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
986 pci_read_config_dword(pdev
, 0x2c, &tint
);
987 tshort
= (tint
>> 16) & 0xffff;
988 rio_dprintk(RIO_DEBUG_PROBE
, "Got a specialix card: %x.\n", tint
);
989 if (tshort
!= 0x0100) {
990 rio_dprintk(RIO_DEBUG_PROBE
, "But it's not a RIO card (%d)...\n", tshort
);
993 rio_dprintk(RIO_DEBUG_PROBE
, "cp1\n");
995 hp
= &p
->RIOHosts
[p
->RIONumHosts
];
996 hp
->PaddrP
= pci_resource_start(pdev
, 2);
997 hp
->Ivec
= pdev
->irq
;
998 if (((1 << hp
->Ivec
) & rio_irqmask
) == 0)
1000 hp
->Caddr
= ioremap(p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, RIO_WINDOW_LEN
);
1001 hp
->CardP
= (struct DpRam __iomem
*) hp
->Caddr
;
1003 hp
->Copy
= rio_copy_to_card
;
1004 hp
->Mode
= RIO_PCI_BOOT_FROM_RAM
;
1005 spin_lock_init(&hp
->HostLock
);
1006 rio_reset_interrupt(hp
);
1007 rio_start_card_running(hp
);
1009 rio_dprintk(RIO_DEBUG_PROBE
, "Going to test it (%p/%p).\n", (void *) p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, p
->RIOHosts
[p
->RIONumHosts
].Caddr
);
1010 if (RIOBoardTest(p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, p
->RIOHosts
[p
->RIONumHosts
].Caddr
, RIO_PCI
, 0) == 0) {
1011 rio_dprintk(RIO_DEBUG_INIT
, "Done RIOBoardTest\n");
1012 writeb(0xFF, &p
->RIOHosts
[p
->RIONumHosts
].ResetInt
);
1013 p
->RIOHosts
[p
->RIONumHosts
].UniqueNum
=
1014 ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[0]) & 0xFF) << 0) |
1015 ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[1]) & 0xFF) << 8) | ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[2]) & 0xFF) << 16) | ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[3]) & 0xFF) << 24);
1016 rio_dprintk(RIO_DEBUG_PROBE
, "Hmm Tested ok, uniqid = %x.\n", p
->RIOHosts
[p
->RIONumHosts
].UniqueNum
);
1020 p
->RIOHosts
[p
->RIONumHosts
].pdev
= pdev
;
1023 p
->RIOLastPCISearch
= 0;
1027 iounmap(p
->RIOHosts
[p
->RIONumHosts
].Caddr
);
1028 p
->RIOHosts
[p
->RIONumHosts
].Caddr
= NULL
;
1032 /* Then look for the older PCI card.... : */
1034 /* These older PCI cards have problems (only byte-mode access is
1035 supported), which makes them a bit awkward to support.
1036 They also have problems sharing interrupts. Be careful.
1037 (The driver now refuses to share interrupts for these
1038 cards. This should be sufficient).
1041 /* Then look for the older RIO/PCI devices: */
1042 while ((pdev
= pci_get_device(PCI_VENDOR_ID_SPECIALIX
, PCI_DEVICE_ID_SPECIALIX_RIO
, pdev
))) {
1043 if (pci_enable_device(pdev
))
1046 #ifdef CONFIG_RIO_OLDPCI
1047 hp
= &p
->RIOHosts
[p
->RIONumHosts
];
1048 hp
->PaddrP
= pci_resource_start(pdev
, 0);
1049 hp
->Ivec
= pdev
->irq
;
1050 if (((1 << hp
->Ivec
) & rio_irqmask
) == 0)
1052 hp
->Ivec
|= 0x8000; /* Mark as non-sharable */
1053 hp
->Caddr
= ioremap(p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, RIO_WINDOW_LEN
);
1054 hp
->CardP
= (struct DpRam __iomem
*) hp
->Caddr
;
1056 hp
->Copy
= rio_copy_to_card
;
1057 hp
->Mode
= RIO_PCI_BOOT_FROM_RAM
;
1058 spin_lock_init(&hp
->HostLock
);
1060 rio_dprintk(RIO_DEBUG_PROBE
, "Ivec: %x\n", hp
->Ivec
);
1061 rio_dprintk(RIO_DEBUG_PROBE
, "Mode: %x\n", hp
->Mode
);
1063 rio_reset_interrupt(hp
);
1064 rio_start_card_running(hp
);
1065 rio_dprintk(RIO_DEBUG_PROBE
, "Going to test it (%p/%p).\n", (void *) p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, p
->RIOHosts
[p
->RIONumHosts
].Caddr
);
1066 if (RIOBoardTest(p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, p
->RIOHosts
[p
->RIONumHosts
].Caddr
, RIO_PCI
, 0) == 0) {
1067 writeb(0xFF, &p
->RIOHosts
[p
->RIONumHosts
].ResetInt
);
1068 p
->RIOHosts
[p
->RIONumHosts
].UniqueNum
=
1069 ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[0]) & 0xFF) << 0) |
1070 ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[1]) & 0xFF) << 8) | ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[2]) & 0xFF) << 16) | ((readb(&p
->RIOHosts
[p
->RIONumHosts
].Unique
[3]) & 0xFF) << 24);
1071 rio_dprintk(RIO_DEBUG_PROBE
, "Hmm Tested ok, uniqid = %x.\n", p
->RIOHosts
[p
->RIONumHosts
].UniqueNum
);
1073 p
->RIOHosts
[p
->RIONumHosts
].pdev
= pdev
;
1076 p
->RIOLastPCISearch
= 0;
1080 iounmap(p
->RIOHosts
[p
->RIONumHosts
].Caddr
);
1081 p
->RIOHosts
[p
->RIONumHosts
].Caddr
= NULL
;
1084 printk(KERN_ERR
"Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
1089 /* Now probe for ISA cards... */
1090 for (i
= 0; i
< NR_RIO_ADDRS
; i
++) {
1091 hp
= &p
->RIOHosts
[p
->RIONumHosts
];
1092 hp
->PaddrP
= rio_probe_addrs
[i
];
1093 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1095 hp
->Caddr
= ioremap(p
->RIOHosts
[p
->RIONumHosts
].PaddrP
, RIO_WINDOW_LEN
);
1096 hp
->CardP
= (struct DpRam __iomem
*) hp
->Caddr
;
1098 hp
->Copy
= rio_copy_to_card
; /* AT card PCI???? - PVDL
1099 * -- YES! this is now a normal copy. Only the
1100 * old PCI card uses the special PCI copy.
1101 * Moreover, the ISA card will work with the
1102 * special PCI copy anyway. -- REW */
1104 spin_lock_init(&hp
->HostLock
);
1106 vpdp
= get_VPD_PROM(hp
);
1107 rio_dprintk(RIO_DEBUG_PROBE
, "Got VPD ROM\n");
1109 if ((strncmp(vpdp
->identifier
, RIO_ISA_IDENT
, 16) == 0) || (strncmp(vpdp
->identifier
, RIO_ISA2_IDENT
, 16) == 0) || (strncmp(vpdp
->identifier
, RIO_ISA3_IDENT
, 16) == 0)) {
1110 /* Board is present... */
1111 if (RIOBoardTest(hp
->PaddrP
, hp
->Caddr
, RIO_AT
, 0) == 0) {
1112 /* ... and feeling fine!!!! */
1113 rio_dprintk(RIO_DEBUG_PROBE
, "Hmm Tested ok, uniqid = %x.\n", p
->RIOHosts
[p
->RIONumHosts
].UniqueNum
);
1114 if (RIOAssignAT(p
, hp
->PaddrP
, hp
->Caddr
, 0)) {
1115 rio_dprintk(RIO_DEBUG_PROBE
, "Hmm Tested ok, host%d uniqid = %x.\n", p
->RIONumHosts
, p
->RIOHosts
[p
->RIONumHosts
- 1].UniqueNum
);
1129 for (i
= 0; i
< p
->RIONumHosts
; i
++) {
1130 hp
= &p
->RIOHosts
[i
];
1132 int mode
= IRQF_SHARED
;
1133 if (hp
->Ivec
& 0x8000) {
1137 rio_dprintk(RIO_DEBUG_INIT
, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp
, hp
->Ivec
, hp
->Mode
);
1138 retval
= request_irq(hp
->Ivec
, rio_interrupt
, mode
, "rio", hp
);
1139 rio_dprintk(RIO_DEBUG_INIT
, "Return value from request_irq: %d\n", retval
);
1141 printk(KERN_ERR
"rio: Cannot allocate irq %d.\n", hp
->Ivec
);
1144 rio_dprintk(RIO_DEBUG_INIT
, "Got irq %d.\n", hp
->Ivec
);
1145 if (hp
->Ivec
!= 0) {
1146 rio_dprintk(RIO_DEBUG_INIT
, "Enabling interrupts on rio card.\n");
1147 hp
->Mode
|= RIO_PCI_INT_ENABLE
;
1149 hp
->Mode
&= ~RIO_PCI_INT_ENABLE
;
1150 rio_dprintk(RIO_DEBUG_INIT
, "New Mode: %x\n", hp
->Mode
);
1151 rio_start_card_running(hp
);
1153 /* Init the timer "always" to make sure that it can safely be
1154 deleted when we unload... */
1156 setup_timer(&hp
->timer
, rio_pollfunc
, i
);
1158 rio_dprintk(RIO_DEBUG_INIT
, "Starting polling at %dj intervals.\n", rio_poll
);
1159 mod_timer(&hp
->timer
, jiffies
+ rio_poll
);
1164 rio_dprintk(RIO_DEBUG_INIT
, "rio: total of %d boards detected.\n", found
);
1167 /* deregister the misc device we created earlier */
1168 misc_deregister(&rio_fw_device
);
1172 return found
? 0 : -EIO
;
1176 static void __exit
rio_exit(void)
1183 for (i
= 0, hp
= p
->RIOHosts
; i
< p
->RIONumHosts
; i
++, hp
++) {
1184 RIOHostReset(hp
->Type
, hp
->CardP
, hp
->Slot
);
1186 free_irq(hp
->Ivec
, hp
);
1187 rio_dprintk(RIO_DEBUG_INIT
, "freed irq %d.\n", hp
->Ivec
);
1189 /* It is safe/allowed to del_timer a non-active timer */
1190 del_timer_sync(&hp
->timer
);
1193 if (hp
->Type
== RIO_PCI
)
1194 pci_dev_put(hp
->pdev
);
1197 if (misc_deregister(&rio_fw_device
) < 0) {
1198 printk(KERN_INFO
"rio: couldn't deregister control-device\n");
1202 rio_dprintk(RIO_DEBUG_CLEANUP
, "Cleaning up drivers\n");
1204 rio_release_drivers();
1206 /* Release dynamically allocated memory */
1214 module_init(rio_init
);
1215 module_exit(rio_exit
);