1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <linux/module.h>
31#include <linux/kdev_t.h>
32#include <asm/io.h>
33#include <linux/kernel.h>
34#include <linux/sched.h>
35#include <linux/ioport.h>
36#include <linux/interrupt.h>
37#include <linux/errno.h>
38#include <linux/tty.h>
39#include <linux/tty_flip.h>
40#include <linux/mm.h>
41#include <linux/serial.h>
42#include <linux/fcntl.h>
43#include <linux/major.h>
44#include <linux/delay.h>
45#include <linux/pci.h>
46#include <linux/slab.h>
47#include <linux/smp_lock.h>
48#include <linux/miscdevice.h>
49#include <linux/init.h>
50
51#include <linux/generic_serial.h>
52#include <asm/uaccess.h>
53
54#include "linux_compat.h"
55#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
59#include "cmdpkt.h"
60#include "map.h"
61#include "rup.h"
62#include "port.h"
63#include "riodrvr.h"
64#include "rioinfo.h"
65#include "func.h"
66#include "errors.h"
67#include "pci.h"
68
69#include "parmmap.h"
70#include "unixrup.h"
71#include "board.h"
72#include "host.h"
73#include "phb.h"
74#include "link.h"
75#include "cmdblk.h"
76#include "route.h"
77#include "cirrus.h"
78#include "rioioctl.h"
79#include "param.h"
80#include "protsts.h"
81#include "rioboard.h"
82
83
84#include "rio_linux.h"
85
86
87
88
89
90
91
92#ifndef RIO_NORMAL_MAJOR0
93
94
95#define RIO_NORMAL_MAJOR0 154
96#define RIO_NORMAL_MAJOR1 156
97#endif
98
99#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
100#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
101#endif
102
103#ifndef RIO_WINDOW_LEN
104#define RIO_WINDOW_LEN 0x10000
105#endif
106
107
108
109
110
111
112#undef RIO_PARANOIA_CHECK
113
114
115
116
117
118
119
120
121#define IRQ_RATE_LIMIT 200
122
123
124
125static struct Conf
126 RIOConf = {
127 "RIO Config here",
128 HZ * 2,
129
130 0,
131
132 1,
133
134 25,
135
136 10,
137
138 0x7000,
139 0x7C00,
140 5,
141
142 120,
143
144 "\033d#",
145
146 "\024",
147
148 2000,
149
150 10,
151
152 1,
153
154 0x0A0000,
155
156 0xFF0000,
157
158 1024,
159
160 256,
161
162 80,
163
164 HZ,
165
166};
167
168
169
170
171
172
173static void rio_disable_tx_interrupts(void *ptr);
174static void rio_enable_tx_interrupts(void *ptr);
175static void rio_disable_rx_interrupts(void *ptr);
176static void rio_enable_rx_interrupts(void *ptr);
177static int rio_carrier_raised(struct tty_port *port);
178static void rio_shutdown_port(void *ptr);
179static int rio_set_real_termios(void *ptr);
180static void rio_hungup(void *ptr);
181static void rio_close(void *ptr);
182static int rio_chars_in_buffer(void *ptr);
183static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
184static int rio_init_drivers(void);
185
186static void my_hd(void *addr, int len);
187
188static struct tty_driver *rio_driver, *rio_driver2;
189
190
191
192struct rio_info *p;
193
194int rio_debug;
195
196
197
198
199
200
201static int rio_poll = 1;
202
203
204
205
206static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
207
208#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
209
210
211
212
213
214static long rio_irqmask = -1;
215
216MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
217MODULE_DESCRIPTION("RIO driver");
218MODULE_LICENSE("GPL");
219module_param(rio_poll, int, 0);
220module_param(rio_debug, int, 0644);
221module_param(rio_irqmask, long, 0);
222
223static struct real_driver rio_real_driver = {
224 rio_disable_tx_interrupts,
225 rio_enable_tx_interrupts,
226 rio_disable_rx_interrupts,
227 rio_enable_rx_interrupts,
228 rio_shutdown_port,
229 rio_set_real_termios,
230 rio_chars_in_buffer,
231 rio_close,
232 rio_hungup,
233 NULL
234};
235
236
237
238
239
240
241static const struct file_operations rio_fw_fops = {
242 .owner = THIS_MODULE,
243 .unlocked_ioctl = rio_fw_ioctl,
244};
245
246static struct miscdevice rio_fw_device = {
247 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
248};
249
250
251
252
253
254#ifdef RIO_PARANOIA_CHECK
255
256
257
258static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
259{
260
261 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
262 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
263
264 if (!port) {
265 printk(badinfo, name, routine);
266 return 1;
267 }
268 if (port->magic != RIO_MAGIC) {
269 printk(badmagic, name, routine);
270 return 1;
271 }
272
273 return 0;
274}
275#else
276#define rio_paranoia_check(a,b,c) 0
277#endif
278
279
280#ifdef DEBUG
281static void my_hd(void *ad, int len)
282{
283 int i, j, ch;
284 unsigned char *addr = ad;
285
286 for (i = 0; i < len; i += 16) {
287 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
288 for (j = 0; j < 16; j++) {
289 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
290 }
291 for (j = 0; j < 16; j++) {
292 ch = addr[j + i];
293 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
294 }
295 rio_dprintk(RIO_DEBUG_PARAM, "\n");
296 }
297}
298#else
299#define my_hd(ad,len) do{ } while (0)
300#endif
301
302
303
304int RIODelay(struct Port *PortP, int njiffies)
305{
306 func_enter();
307
308 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
309 msleep_interruptible(jiffies_to_msecs(njiffies));
310 func_exit();
311
312 if (signal_pending(current))
313 return RIO_FAIL;
314 else
315 return !RIO_FAIL;
316}
317
318
319
320int RIODelay_ni(struct Port *PortP, int njiffies)
321{
322 func_enter();
323
324 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
325 msleep(jiffies_to_msecs(njiffies));
326 func_exit();
327 return !RIO_FAIL;
328}
329
330void rio_copy_to_card(void *from, void __iomem *to, int len)
331{
332 rio_copy_toio(to, from, len);
333}
334
335int rio_minor(struct tty_struct *tty)
336{
337 return tty->index + ((tty->driver == rio_driver) ? 0 : 256);
338}
339
340static int rio_set_real_termios(void *ptr)
341{
342 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
343}
344
345
346static void rio_reset_interrupt(struct Host *HostP)
347{
348 func_enter();
349
350 switch (HostP->Type) {
351 case RIO_AT:
352 case RIO_MCA:
353 case RIO_PCI:
354 writeb(0xFF, &HostP->ResetInt);
355 }
356
357 func_exit();
358}
359
360
361static irqreturn_t rio_interrupt(int irq, void *ptr)
362{
363 struct Host *HostP;
364 func_enter();
365
366 HostP = ptr;
367 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
387 if (HostP->Ivec == irq) {
388
389 rio_reset_interrupt(HostP);
390 }
391
392 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
393 return IRQ_HANDLED;
394
395 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
396 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
397 return IRQ_HANDLED;
398 }
399
400 RIOServiceHost(p, HostP);
401
402 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
403
404 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
405 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
406 func_exit();
407 return IRQ_HANDLED;
408}
409
410
411static void rio_pollfunc(unsigned long data)
412{
413 func_enter();
414
415 rio_interrupt(0, &p->RIOHosts[data]);
416 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
417
418 func_exit();
419}
420
421
422
423
424
425
426
427
428
429
430static void rio_disable_tx_interrupts(void *ptr)
431{
432 func_enter();
433
434
435
436 func_exit();
437}
438
439
440static void rio_enable_tx_interrupts(void *ptr)
441{
442 struct Port *PortP = ptr;
443
444
445 func_enter();
446
447
448
449
450
451
452 RIOTxEnable((char *) PortP);
453
454
455
456
457
458 PortP->gs.port.flags &= ~GS_TX_INTEN;
459
460 func_exit();
461}
462
463
464static void rio_disable_rx_interrupts(void *ptr)
465{
466 func_enter();
467 func_exit();
468}
469
470static void rio_enable_rx_interrupts(void *ptr)
471{
472
473 func_enter();
474 func_exit();
475}
476
477
478
479static int rio_carrier_raised(struct tty_port *port)
480{
481 struct Port *PortP = container_of(port, struct Port, gs.port);
482 int rv;
483
484 func_enter();
485 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
486
487 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
488
489 func_exit();
490 return rv;
491}
492
493
494
495
496static int rio_chars_in_buffer(void *ptr)
497{
498 func_enter();
499
500 func_exit();
501 return 0;
502}
503
504
505
506static void rio_shutdown_port(void *ptr)
507{
508 struct Port *PortP;
509
510 func_enter();
511
512 PortP = (struct Port *) ptr;
513 PortP->gs.port.tty = NULL;
514 func_exit();
515}
516
517
518
519
520
521
522
523
524
525static void rio_hungup(void *ptr)
526{
527 struct Port *PortP;
528
529 func_enter();
530
531 PortP = (struct Port *) ptr;
532 PortP->gs.port.tty = NULL;
533
534 func_exit();
535}
536
537
538
539
540
541
542static void rio_close(void *ptr)
543{
544 struct Port *PortP;
545
546 func_enter();
547
548 PortP = (struct Port *) ptr;
549
550 riotclose(ptr);
551
552 if (PortP->gs.port.count) {
553 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
554 PortP->gs.port.count = 0;
555 }
556
557 PortP->gs.port.tty = NULL;
558 func_exit();
559}
560
561
562
563static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
564{
565 int rc = 0;
566 func_enter();
567
568
569 lock_kernel();
570 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
571 unlock_kernel();
572
573 func_exit();
574 return rc;
575}
576
577extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
578
579static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
580{
581 void __user *argp = (void __user *)arg;
582 int rc;
583 struct Port *PortP;
584 int ival;
585
586 func_enter();
587
588 PortP = (struct Port *) tty->driver_data;
589
590 rc = 0;
591 switch (cmd) {
592 case TIOCSSOFTCAR:
593 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
594 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
595 }
596 break;
597 case TIOCGSERIAL:
598 rc = -EFAULT;
599 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
600 rc = gs_getserial(&PortP->gs, argp);
601 break;
602 case TCSBRK:
603 if (PortP->State & RIO_DELETED) {
604 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
605 rc = -EIO;
606 } else {
607 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
608 RIO_FAIL) {
609 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
610 rc = -EIO;
611 }
612 }
613 break;
614 case TCSBRKP:
615 if (PortP->State & RIO_DELETED) {
616 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
617 rc = -EIO;
618 } else {
619 int l;
620 l = arg ? arg * 100 : 250;
621 if (l > 255)
622 l = 255;
623 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
624 arg ? arg * 100 : 250) == RIO_FAIL) {
625 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
626 rc = -EIO;
627 }
628 }
629 break;
630 case TIOCSSERIAL:
631 rc = -EFAULT;
632 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
633 rc = gs_setserial(&PortP->gs, argp);
634 break;
635 default:
636 rc = -ENOIOCTLCMD;
637 break;
638 }
639 func_exit();
640 return rc;
641}
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660static void rio_throttle(struct tty_struct *tty)
661{
662 struct Port *port = (struct Port *) tty->driver_data;
663
664 func_enter();
665
666
667
668
669 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
670 port->State |= RIO_THROTTLE_RX;
671 }
672
673 func_exit();
674}
675
676
677static void rio_unthrottle(struct tty_struct *tty)
678{
679 struct Port *port = (struct Port *) tty->driver_data;
680
681 func_enter();
682
683
684
685
686
687 port->State &= ~RIO_THROTTLE_RX;
688
689 func_exit();
690 return;
691}
692
693
694
695
696
697
698
699
700
701
702static struct vpd_prom *get_VPD_PROM(struct Host *hp)
703{
704 static struct vpd_prom vpdp;
705 char *p;
706 int i;
707
708 func_enter();
709 rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
710
711 p = (char *) &vpdp;
712 for (i = 0; i < sizeof(struct vpd_prom); i++)
713 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
714
715
716
717
718 *p++ = 0;
719
720 if (rio_debug & RIO_DEBUG_PROBE)
721 my_hd((char *) &vpdp, 0x20);
722
723 func_exit();
724
725 return &vpdp;
726}
727
728static const struct tty_operations rio_ops = {
729 .open = riotopen,
730 .close = gs_close,
731 .write = gs_write,
732 .put_char = gs_put_char,
733 .flush_chars = gs_flush_chars,
734 .write_room = gs_write_room,
735 .chars_in_buffer = gs_chars_in_buffer,
736 .flush_buffer = gs_flush_buffer,
737 .ioctl = rio_ioctl,
738 .throttle = rio_throttle,
739 .unthrottle = rio_unthrottle,
740 .set_termios = gs_set_termios,
741 .stop = gs_stop,
742 .start = gs_start,
743 .hangup = gs_hangup,
744};
745
746static int rio_init_drivers(void)
747{
748 int error = -ENOMEM;
749
750 rio_driver = alloc_tty_driver(256);
751 if (!rio_driver)
752 goto out;
753 rio_driver2 = alloc_tty_driver(256);
754 if (!rio_driver2)
755 goto out1;
756
757 func_enter();
758
759 rio_driver->owner = THIS_MODULE;
760 rio_driver->driver_name = "specialix_rio";
761 rio_driver->name = "ttySR";
762 rio_driver->major = RIO_NORMAL_MAJOR0;
763 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
764 rio_driver->subtype = SERIAL_TYPE_NORMAL;
765 rio_driver->init_termios = tty_std_termios;
766 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
767 rio_driver->flags = TTY_DRIVER_REAL_RAW;
768 tty_set_operations(rio_driver, &rio_ops);
769
770 rio_driver2->owner = THIS_MODULE;
771 rio_driver2->driver_name = "specialix_rio";
772 rio_driver2->name = "ttySR";
773 rio_driver2->major = RIO_NORMAL_MAJOR1;
774 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
775 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
776 rio_driver2->init_termios = tty_std_termios;
777 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
778 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
779 tty_set_operations(rio_driver2, &rio_ops);
780
781 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
782
783 if ((error = tty_register_driver(rio_driver)))
784 goto out2;
785 if ((error = tty_register_driver(rio_driver2)))
786 goto out3;
787 func_exit();
788 return 0;
789 out3:
790 tty_unregister_driver(rio_driver);
791 out2:
792 put_tty_driver(rio_driver2);
793 out1:
794 put_tty_driver(rio_driver);
795 out:
796 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
797 return 1;
798}
799
800static const struct tty_port_operations rio_port_ops = {
801 .carrier_raised = rio_carrier_raised,
802};
803
804static int rio_init_datastructures(void)
805{
806 int i;
807 struct Port *port;
808 func_enter();
809
810
811
812
813
814
815
816#define RI_SZ sizeof(struct rio_info)
817#define HOST_SZ sizeof(struct Host)
818#define PORT_SZ sizeof(struct Port *)
819#define TMIO_SZ sizeof(struct termios *)
820 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);
821
822 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
823 goto free0;
824 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
825 goto free1;
826 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
827 goto free2;
828 p->RIOConf = RIOConf;
829 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
830
831#if 1
832 for (i = 0; i < RIO_PORTS; i++) {
833 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
834 if (!port) {
835 goto free6;
836 }
837 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
838 tty_port_init(&port->gs.port);
839 port->gs.port.ops = &rio_port_ops;
840 port->PortNum = i;
841 port->gs.magic = RIO_MAGIC;
842 port->gs.close_delay = HZ / 2;
843 port->gs.closing_wait = 30 * HZ;
844 port->gs.rd = &rio_real_driver;
845 spin_lock_init(&port->portSem);
846 }
847#else
848
849#endif
850
851
852
853 if (rio_debug & RIO_DEBUG_INIT) {
854 my_hd(&rio_real_driver, sizeof(rio_real_driver));
855 }
856
857
858 func_exit();
859 return 0;
860
861 free6:for (i--; i >= 0; i--)
862 kfree(p->RIOPortp[i]);
863
864
865 kfree(p->RIOPortp);
866 free2:kfree(p->RIOHosts);
867 free1:
868 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
869 kfree(p);
870 free0:
871 return -ENOMEM;
872}
873
874static void __exit rio_release_drivers(void)
875{
876 func_enter();
877 tty_unregister_driver(rio_driver2);
878 tty_unregister_driver(rio_driver);
879 put_tty_driver(rio_driver2);
880 put_tty_driver(rio_driver);
881 func_exit();
882}
883
884
885#ifdef CONFIG_PCI
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905static void fix_rio_pci(struct pci_dev *pdev)
906{
907 unsigned long hwbase;
908 unsigned char __iomem *rebase;
909 unsigned int t;
910
911#define CNTRL_REG_OFFSET 0x50
912#define CNTRL_REG_GOODVALUE 0x18260000
913
914 hwbase = pci_resource_start(pdev, 0);
915 rebase = ioremap(hwbase, 0x80);
916 t = readl(rebase + CNTRL_REG_OFFSET);
917 if (t != CNTRL_REG_GOODVALUE) {
918 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
919 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
920 }
921 iounmap(rebase);
922}
923#endif
924
925
926static int __init rio_init(void)
927{
928 int found = 0;
929 int i;
930 struct Host *hp;
931 int retval;
932 struct vpd_prom *vpdp;
933 int okboard;
934
935#ifdef CONFIG_PCI
936 struct pci_dev *pdev = NULL;
937 unsigned short tshort;
938#endif
939
940 func_enter();
941 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
942
943 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
944 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
945 rio_debug = -1;
946 }
947
948 if (misc_register(&rio_fw_device) < 0) {
949 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
950 return -EIO;
951 }
952
953 retval = rio_init_datastructures();
954 if (retval < 0) {
955 misc_deregister(&rio_fw_device);
956 return retval;
957 }
958#ifdef CONFIG_PCI
959
960 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
961 u32 tint;
962
963 if (pci_enable_device(pdev))
964 continue;
965
966
967
968
969
970
971
972
973 pci_read_config_dword(pdev, 0x2c, &tint);
974 tshort = (tint >> 16) & 0xffff;
975 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
976 if (tshort != 0x0100) {
977 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
978 continue;
979 }
980 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
981
982 hp = &p->RIOHosts[p->RIONumHosts];
983 hp->PaddrP = pci_resource_start(pdev, 2);
984 hp->Ivec = pdev->irq;
985 if (((1 << hp->Ivec) & rio_irqmask) == 0)
986 hp->Ivec = 0;
987 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
988 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
989 hp->Type = RIO_PCI;
990 hp->Copy = rio_copy_to_card;
991 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
992 spin_lock_init(&hp->HostLock);
993 rio_reset_interrupt(hp);
994 rio_start_card_running(hp);
995
996 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
997 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
998 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
999 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1000 p->RIOHosts[p->RIONumHosts].UniqueNum =
1001 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1002 ((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);
1003 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1004
1005 fix_rio_pci(pdev);
1006
1007 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1008 pci_dev_get(pdev);
1009
1010 p->RIOLastPCISearch = 0;
1011 p->RIONumHosts++;
1012 found++;
1013 } else {
1014 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1015 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1016 }
1017 }
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1030 if (pci_enable_device(pdev))
1031 continue;
1032
1033#ifdef CONFIG_RIO_OLDPCI
1034 hp = &p->RIOHosts[p->RIONumHosts];
1035 hp->PaddrP = pci_resource_start(pdev, 0);
1036 hp->Ivec = pdev->irq;
1037 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1038 hp->Ivec = 0;
1039 hp->Ivec |= 0x8000;
1040 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1041 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
1042 hp->Type = RIO_PCI;
1043 hp->Copy = rio_copy_to_card;
1044 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1045 spin_lock_init(&hp->HostLock);
1046
1047 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1048 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1049
1050 rio_reset_interrupt(hp);
1051 rio_start_card_running(hp);
1052 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1053 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
1054 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1055 p->RIOHosts[p->RIONumHosts].UniqueNum =
1056 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1057 ((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);
1058 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1059
1060 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1061 pci_dev_get(pdev);
1062
1063 p->RIOLastPCISearch = 0;
1064 p->RIONumHosts++;
1065 found++;
1066 } else {
1067 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1068 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1069 }
1070#else
1071 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
1072#endif
1073 }
1074#endif
1075
1076
1077 for (i = 0; i < NR_RIO_ADDRS; i++) {
1078 hp = &p->RIOHosts[p->RIONumHosts];
1079 hp->PaddrP = rio_probe_addrs[i];
1080
1081 hp->Ivec = 0;
1082 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1083 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
1084 hp->Type = RIO_AT;
1085 hp->Copy = rio_copy_to_card;
1086
1087
1088
1089
1090 hp->Mode = 0;
1091 spin_lock_init(&hp->HostLock);
1092
1093 vpdp = get_VPD_PROM(hp);
1094 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1095 okboard = 0;
1096 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)) {
1097
1098 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
1099
1100 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1101 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1102 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1103 okboard++;
1104 found++;
1105 }
1106 }
1107
1108 if (!okboard) {
1109 iounmap(hp->Caddr);
1110 hp->Caddr = NULL;
1111 }
1112 }
1113 }
1114
1115
1116 for (i = 0; i < p->RIONumHosts; i++) {
1117 hp = &p->RIOHosts[i];
1118 if (hp->Ivec) {
1119 int mode = IRQF_SHARED;
1120 if (hp->Ivec & 0x8000) {
1121 mode = 0;
1122 hp->Ivec &= 0x7fff;
1123 }
1124 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1125 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1126 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1127 if (retval) {
1128 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1129 hp->Ivec = 0;
1130 }
1131 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1132 if (hp->Ivec != 0) {
1133 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1134 hp->Mode |= RIO_PCI_INT_ENABLE;
1135 } else
1136 hp->Mode &= ~RIO_PCI_INT_ENABLE;
1137 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1138 rio_start_card_running(hp);
1139 }
1140
1141
1142
1143 setup_timer(&hp->timer, rio_pollfunc, i);
1144 if (!hp->Ivec) {
1145 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
1146 mod_timer(&hp->timer, jiffies + rio_poll);
1147 }
1148 }
1149
1150 if (found) {
1151 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1152 rio_init_drivers();
1153 } else {
1154
1155 misc_deregister(&rio_fw_device);
1156 }
1157
1158 func_exit();
1159 return found ? 0 : -EIO;
1160}
1161
1162
1163static void __exit rio_exit(void)
1164{
1165 int i;
1166 struct Host *hp;
1167
1168 func_enter();
1169
1170 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1171 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1172 if (hp->Ivec) {
1173 free_irq(hp->Ivec, hp);
1174 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1175 }
1176
1177 del_timer_sync(&hp->timer);
1178 if (hp->Caddr)
1179 iounmap(hp->Caddr);
1180 if (hp->Type == RIO_PCI)
1181 pci_dev_put(hp->pdev);
1182 }
1183
1184 if (misc_deregister(&rio_fw_device) < 0) {
1185 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1186 }
1187
1188
1189 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1190
1191 rio_release_drivers();
1192
1193
1194 kfree(p->RIOPortp);
1195 kfree(p->RIOHosts);
1196 kfree(p);
1197
1198 func_exit();
1199}
1200
1201module_init(rio_init);
1202module_exit(rio_exit);
1203