blob: 5e33293d24e399d60f45301fdf3ad9e73f00dd9b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/* rio_linux.c -- Linux driver for the Specialix RIO series cards.
3 *
4 *
5 * (C) 1999 R.E.Wolff@BitWizard.nl
6 *
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.
10 *
11 *
12 *
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.
17 *
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.
22 *
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,
26 * USA.
27 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * */
29
30#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#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>
Arnd Bergmann613655f2010-06-02 14:28:52 +020047#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/miscdevice.h>
49#include <linux/init.h>
50
51#include <linux/generic_serial.h>
52#include <asm/uaccess.h>
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "linux_compat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "cmdpkt.h"
60#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include "phb.h"
74#include "link.h"
75#include "cmdblk.h"
76#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include "cirrus.h"
78#include "rioioctl.h"
79#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include "protsts.h"
81#include "rioboard.h"
82
83
84#include "rio_linux.h"
85
86/* I don't think that this driver can handle more than 512 ports on
87one machine. Specialix specifies max 4 boards in one machine. I don't
88know why. If you want to try anyway you'll have to increase the number
89of boards in rio.h. You'll have to allocate more majors if you need
90more than 512 ports.... */
91
92#ifndef RIO_NORMAL_MAJOR0
93/* This allows overriding on the compiler commandline, or in a "major.h"
94 include or something like that */
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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800103#ifndef RIO_WINDOW_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#define RIO_WINDOW_LEN 0x10000
105#endif
106
107
108/* Configurable options:
109 (Don't be too sure that it'll work if you toggle them) */
110
111/* Am I paranoid or not ? ;-) */
112#undef RIO_PARANOIA_CHECK
113
114
115/* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
116 Hz, but it is user configurable. I don't recommend going above 1000
117 Hz. The interrupt ratelimit might trigger if the interrupt is
118 shared with a very active other device.
119 undef this if you want to disable the check....
120*/
121#define IRQ_RATE_LIMIT 200
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* These constants are derived from SCO Source */
Arnd Bergmann613655f2010-06-02 14:28:52 +0200125static DEFINE_MUTEX(rio_fw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static struct Conf
Andrew Morton8d8706e2006-01-11 12:17:49 -0800127 RIOConf = {
128 /* locator */ "RIO Config here",
129 /* startuptime */ HZ * 2,
130 /* how long to wait for card to run */
131 /* slowcook */ 0,
132 /* TRUE -> always use line disc. */
133 /* intrpolltime */ 1,
134 /* The frequency of OUR polls */
135 /* breakinterval */ 25,
136 /* x10 mS XXX: units seem to be 1ms not 10! -- REW */
137 /* timer */ 10,
138 /* mS */
139 /* RtaLoadBase */ 0x7000,
140 /* HostLoadBase */ 0x7C00,
141 /* XpHz */ 5,
142 /* number of Xprint hits per second */
143 /* XpCps */ 120,
144 /* Xprint characters per second */
145 /* XpOn */ "\033d#",
146 /* start Xprint for a wyse 60 */
147 /* XpOff */ "\024",
148 /* end Xprint for a wyse 60 */
149 /* MaxXpCps */ 2000,
150 /* highest Xprint speed */
151 /* MinXpCps */ 10,
152 /* slowest Xprint speed */
153 /* SpinCmds */ 1,
154 /* non-zero for mega fast boots */
155 /* First Addr */ 0x0A0000,
156 /* First address to look at */
157 /* Last Addr */ 0xFF0000,
158 /* Last address looked at */
159 /* BufferSize */ 1024,
160 /* Bytes per port of buffering */
161 /* LowWater */ 256,
162 /* how much data left before wakeup */
163 /* LineLength */ 80,
164 /* how wide is the console? */
165 /* CmdTimeout */ HZ,
166 /* how long a close command may take */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167};
168
169
170
171
172/* Function prototypes */
173
Andrew Morton8d8706e2006-01-11 12:17:49 -0800174static void rio_disable_tx_interrupts(void *ptr);
175static void rio_enable_tx_interrupts(void *ptr);
176static void rio_disable_rx_interrupts(void *ptr);
177static void rio_enable_rx_interrupts(void *ptr);
Alan Cox31f35932009-01-02 13:45:05 +0000178static int rio_carrier_raised(struct tty_port *port);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800179static void rio_shutdown_port(void *ptr);
180static int rio_set_real_termios(void *ptr);
181static void rio_hungup(void *ptr);
182static void rio_close(void *ptr);
183static int rio_chars_in_buffer(void *ptr);
Alan Coxf6759fd2008-07-25 01:48:14 -0700184static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185static int rio_init_drivers(void);
186
Andrew Morton8d8706e2006-01-11 12:17:49 -0800187static void my_hd(void *addr, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189static struct tty_driver *rio_driver, *rio_driver2;
190
191/* The name "p" is a bit non-descript. But that's what the rio-lynxos
192sources use all over the place. */
193struct rio_info *p;
194
195int rio_debug;
196
197
198/* You can have the driver poll your card.
199 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
200 This is used when the card cannot use an interrupt for some reason.
201*/
202static int rio_poll = 1;
203
204
205/* These are the only open spaces in my computer. Yours may have more
206 or less.... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800207static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Tobias Klauserfe971072006-01-09 20:54:02 -0800209#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211
212/* Set the mask to all-ones. This alas, only supports 32 interrupts.
213 Some architectures may need more. -- Changed to LONG to
214 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
Adrian Bunk408b6642005-05-01 08:59:29 -0700215static long rio_irqmask = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
218MODULE_DESCRIPTION("RIO driver");
219MODULE_LICENSE("GPL");
220module_param(rio_poll, int, 0);
221module_param(rio_debug, int, 0644);
222module_param(rio_irqmask, long, 0);
223
224static struct real_driver rio_real_driver = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800225 rio_disable_tx_interrupts,
226 rio_enable_tx_interrupts,
227 rio_disable_rx_interrupts,
228 rio_enable_rx_interrupts,
Andrew Morton8d8706e2006-01-11 12:17:49 -0800229 rio_shutdown_port,
230 rio_set_real_termios,
231 rio_chars_in_buffer,
232 rio_close,
233 rio_hungup,
234 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
237/*
238 * Firmware loader driver specific routines
239 *
240 */
241
Arjan van de Ven62322d22006-07-03 00:24:21 -0700242static const struct file_operations rio_fw_fops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 .owner = THIS_MODULE,
Alan Coxf6759fd2008-07-25 01:48:14 -0700244 .unlocked_ioctl = rio_fw_ioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200245 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246};
247
248static struct miscdevice rio_fw_device = {
249 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
250};
251
252
253
254
255
256#ifdef RIO_PARANOIA_CHECK
257
258/* This doesn't work. Who's paranoid around here? Not me! */
259
Andrew Morton8d8706e2006-01-11 12:17:49 -0800260static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262
Andrew Morton8d8706e2006-01-11 12:17:49 -0800263 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
264 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Andrew Morton8d8706e2006-01-11 12:17:49 -0800266 if (!port) {
267 printk(badinfo, name, routine);
268 return 1;
269 }
270 if (port->magic != RIO_MAGIC) {
271 printk(badmagic, name, routine);
272 return 1;
273 }
274
275 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277#else
278#define rio_paranoia_check(a,b,c) 0
279#endif
280
281
282#ifdef DEBUG
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283static void my_hd(void *ad, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800285 int i, j, ch;
286 unsigned char *addr = ad;
287
288 for (i = 0; i < len; i += 16) {
Alan Cox00d83a52006-03-24 03:18:28 -0800289 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800290 for (j = 0; j < 16; j++) {
291 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
292 }
293 for (j = 0; j < 16; j++) {
294 ch = addr[j + i];
295 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
296 }
297 rio_dprintk(RIO_DEBUG_PARAM, "\n");
298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300#else
301#define my_hd(ad,len) do{/* nothing*/ } while (0)
302#endif
303
304
Andrew Morton8d8706e2006-01-11 12:17:49 -0800305/* Delay a number of jiffies, allowing a signal to interrupt */
306int RIODelay(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800308 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Andrew Morton8d8706e2006-01-11 12:17:49 -0800310 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
311 msleep_interruptible(jiffies_to_msecs(njiffies));
312 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Andrew Morton8d8706e2006-01-11 12:17:49 -0800314 if (signal_pending(current))
315 return RIO_FAIL;
316 else
317 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318}
319
320
Andrew Morton8d8706e2006-01-11 12:17:49 -0800321/* Delay a number of jiffies, disallowing a signal to interrupt */
322int RIODelay_ni(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800324 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Andrew Morton8d8706e2006-01-11 12:17:49 -0800326 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
327 msleep(jiffies_to_msecs(njiffies));
328 func_exit();
329 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
Al Viro38d0d002006-05-27 00:15:09 -0400332void rio_copy_to_card(void *from, void __iomem *to, int len)
Alan Cox00d83a52006-03-24 03:18:28 -0800333{
Al Viroae5b28a2006-05-27 01:48:08 -0400334 rio_copy_toio(to, from, len);
Alan Cox00d83a52006-03-24 03:18:28 -0800335}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337int rio_minor(struct tty_struct *tty)
338{
Roel Kluin1f854492009-04-06 17:35:34 +0100339 return tty->index + ((tty->driver == rio_driver) ? 0 : 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
Andrew Morton8d8706e2006-01-11 12:17:49 -0800342static int rio_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Jiri Slabyd6f63412008-04-30 00:53:57 -0700344 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
347
Andrew Morton8d8706e2006-01-11 12:17:49 -0800348static void rio_reset_interrupt(struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800350 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Andrew Morton8d8706e2006-01-11 12:17:49 -0800352 switch (HostP->Type) {
353 case RIO_AT:
354 case RIO_MCA:
355 case RIO_PCI:
Alan Cox00d83a52006-03-24 03:18:28 -0800356 writeb(0xFF, &HostP->ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Andrew Morton8d8706e2006-01-11 12:17:49 -0800359 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
362
David Howells7d12e782006-10-05 14:55:46 +0100363static irqreturn_t rio_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800365 struct Host *HostP;
366 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400368 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800369 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Andrew Morton8d8706e2006-01-11 12:17:49 -0800371 /* AAargh! The order in which to do these things is essential and
372 not trivial.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Andrew Morton8d8706e2006-01-11 12:17:49 -0800374 - hardware twiddling goes before "recursive". Otherwise when we
375 poll the card, and a recursive interrupt happens, we won't
376 ack the card, so it might keep on interrupting us. (especially
377 level sensitive interrupt systems like PCI).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Andrew Morton8d8706e2006-01-11 12:17:49 -0800379 - Rate limit goes before hardware twiddling. Otherwise we won't
380 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Andrew Morton8d8706e2006-01-11 12:17:49 -0800382 - The "initialized" test goes after the hardware twiddling. Otherwise
383 the card will stick us in the interrupt routine again.
384
385 - The initialized test goes before recursive.
386 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Andrew Morton8d8706e2006-01-11 12:17:49 -0800388 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
389 if (HostP->Ivec == irq) {
390 /* Tell the card we've noticed the interrupt. */
391 rio_reset_interrupt(HostP);
392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andrew Morton8d8706e2006-01-11 12:17:49 -0800394 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
395 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Andrew Morton8d8706e2006-01-11 12:17:49 -0800397 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
Alan Cox00d83a52006-03-24 03:18:28 -0800398 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800399 return IRQ_HANDLED;
400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400402 RIOServiceHost(p, HostP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Alan Cox00d83a52006-03-24 03:18:28 -0800404 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Andrew Morton8d8706e2006-01-11 12:17:49 -0800406 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
407 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
408 func_exit();
409 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
412
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413static void rio_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800415 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
David Howells7d12e782006-10-05 14:55:46 +0100417 rio_interrupt(0, &p->RIOHosts[data]);
Jiri Slaby40565f12007-02-12 00:52:31 -0800418 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Andrew Morton8d8706e2006-01-11 12:17:49 -0800420 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423
424/* ********************************************************************** *
425 * Here are the routines that actually *
426 * interface with the generic_serial driver *
427 * ********************************************************************** */
428
429/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
430 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
431
Andrew Morton8d8706e2006-01-11 12:17:49 -0800432static void rio_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800434 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Alan Coxb5391e22008-07-16 21:55:20 +0100436 /* port->gs.port.flags &= ~GS_TX_INTEN; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Andrew Morton8d8706e2006-01-11 12:17:49 -0800438 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441
Andrew Morton8d8706e2006-01-11 12:17:49 -0800442static void rio_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800444 struct Port *PortP = ptr;
445 /* int hn; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Andrew Morton8d8706e2006-01-11 12:17:49 -0800447 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Andrew Morton8d8706e2006-01-11 12:17:49 -0800449 /* hn = PortP->HostP - p->RIOHosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
452 rio_interrupt (-1,(void *) hn, NULL); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Andrew Morton8d8706e2006-01-11 12:17:49 -0800454 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Andrew Morton8d8706e2006-01-11 12:17:49 -0800456 /*
457 * In general we cannot count on "tx empty" interrupts, although
458 * the interrupt routine seems to be able to tell the difference.
459 */
Alan Coxb5391e22008-07-16 21:55:20 +0100460 PortP->gs.port.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Andrew Morton8d8706e2006-01-11 12:17:49 -0800462 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
464
465
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466static void rio_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800468 func_enter();
469 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472static void rio_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800474 /* struct rio_port *port = ptr; */
475 func_enter();
476 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
479
480/* Jeez. Isn't this simple? */
Alan Cox31f35932009-01-02 13:45:05 +0000481static int rio_carrier_raised(struct tty_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Alan Cox31f35932009-01-02 13:45:05 +0000483 struct Port *PortP = container_of(port, struct Port, gs.port);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800484 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Andrew Morton8d8706e2006-01-11 12:17:49 -0800486 func_enter();
Jiri Slabyd6f63412008-04-30 00:53:57 -0700487 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Andrew Morton8d8706e2006-01-11 12:17:49 -0800489 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
490
491 func_exit();
492 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
495
496/* Jeez. Isn't this simple? Actually, we can sync with the actual port
497 by just pushing stuff into the queue going to the port... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800498static int rio_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800500 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Andrew Morton8d8706e2006-01-11 12:17:49 -0800502 func_exit();
503 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504}
505
506
507/* Nothing special here... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800508static void rio_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Andrew Morton8d8706e2006-01-11 12:17:49 -0800512 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Andrew Morton8d8706e2006-01-11 12:17:49 -0800514 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100515 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800516 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
519
520/* I haven't the foggiest why the decrement use count has to happen
521 here. The whole linux serial drivers stuff needs to be redesigned.
522 My guess is that this is a hack to minimize the impact of a bug
523 elsewhere. Thinking about it some more. (try it sometime) Try
524 running minicom on a serial port that is driven by a modularized
525 driver. Have the modem hangup. Then remove the driver module. Then
526 exit minicom. I expect an "oops". -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800527static void rio_hungup(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800529 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100534 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800535
536 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
539
540/* The standard serial_close would become shorter if you'd wrap it like
541 this.
542 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
543 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800544static void rio_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800546 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Andrew Morton8d8706e2006-01-11 12:17:49 -0800548 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Andrew Morton8d8706e2006-01-11 12:17:49 -0800550 PortP = (struct Port *) ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 riotclose(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Alan Coxb5391e22008-07-16 21:55:20 +0100554 if (PortP->gs.port.count) {
555 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
556 PortP->gs.port.count = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Alan Coxb5391e22008-07-16 21:55:20 +0100559 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563
564
Alan Coxf6759fd2008-07-25 01:48:14 -0700565static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800567 int rc = 0;
568 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Andrew Morton8d8706e2006-01-11 12:17:49 -0800570 /* The "dev" argument isn't used. */
Arnd Bergmann613655f2010-06-02 14:28:52 +0200571 mutex_lock(&rio_fw_mutex);
Al Virod886cb52006-05-27 00:08:25 -0400572 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
Arnd Bergmann613655f2010-06-02 14:28:52 +0200573 mutex_unlock(&rio_fw_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Andrew Morton8d8706e2006-01-11 12:17:49 -0800575 func_exit();
576 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Andrew Morton8d8706e2006-01-11 12:17:49 -0800581static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Al Virod886cb52006-05-27 00:08:25 -0400583 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800584 int rc;
585 struct Port *PortP;
586 int ival;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Andrew Morton8d8706e2006-01-11 12:17:49 -0800588 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Andrew Morton8d8706e2006-01-11 12:17:49 -0800590 PortP = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Andrew Morton8d8706e2006-01-11 12:17:49 -0800592 rc = 0;
593 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800594 case TIOCSSOFTCAR:
Al Virod886cb52006-05-27 00:08:25 -0400595 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800596 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
597 }
598 break;
599 case TIOCGSERIAL:
600 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400601 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
602 rc = gs_getserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800603 break;
604 case TCSBRK:
605 if (PortP->State & RIO_DELETED) {
606 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
607 rc = -EIO;
608 } else {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700609 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
610 RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800611 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
612 rc = -EIO;
613 }
614 }
615 break;
616 case TCSBRKP:
617 if (PortP->State & RIO_DELETED) {
618 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
619 rc = -EIO;
620 } else {
621 int l;
622 l = arg ? arg * 100 : 250;
623 if (l > 255)
624 l = 255;
Jiri Slabyd6f63412008-04-30 00:53:57 -0700625 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
626 arg ? arg * 100 : 250) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
628 rc = -EIO;
629 }
630 }
631 break;
632 case TIOCSSERIAL:
633 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400634 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
635 rc = gs_setserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800636 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800637 default:
638 rc = -ENOIOCTLCMD;
639 break;
640 }
641 func_exit();
642 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
645
646/* The throttle/unthrottle scheme for the Specialix card is different
647 * from other drivers and deserves some explanation.
648 * The Specialix hardware takes care of XON/XOFF
649 * and CTS/RTS flow control itself. This means that all we have to
650 * do when signalled by the upper tty layer to throttle/unthrottle is
651 * to make a note of it here. When we come to read characters from the
652 * rx buffers on the card (rio_receive_chars()) we look to see if the
653 * upper layer can accept more (as noted here in rio_rx_throt[]).
654 * If it can't we simply don't remove chars from the cards buffer.
655 * When the tty layer can accept chars, we again note that here and when
656 * rio_receive_chars() is called it will remove them from the cards buffer.
657 * The card will notice that a ports buffer has drained below some low
658 * water mark and will unflow control the line itself, using whatever
659 * flow control scheme is in use for that port. -- Simon Allen
660 */
661
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662static void rio_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800664 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Andrew Morton8d8706e2006-01-11 12:17:49 -0800666 func_enter();
667 /* If the port is using any type of input flow
668 * control then throttle the port.
669 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Andrew Morton8d8706e2006-01-11 12:17:49 -0800671 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
672 port->State |= RIO_THROTTLE_RX;
673 }
674
675 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678
Andrew Morton8d8706e2006-01-11 12:17:49 -0800679static void rio_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800681 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Andrew Morton8d8706e2006-01-11 12:17:49 -0800683 func_enter();
684 /* Always unthrottle even if flow control is not enabled on
685 * this port in case we disabled flow control while the port
686 * was throttled
687 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Andrew Morton8d8706e2006-01-11 12:17:49 -0800689 port->State &= ~RIO_THROTTLE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Andrew Morton8d8706e2006-01-11 12:17:49 -0800691 func_exit();
692 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
695
696
697
698
699/* ********************************************************************** *
700 * Here are the initialization routines. *
701 * ********************************************************************** */
702
703
Andrew Morton8d8706e2006-01-11 12:17:49 -0800704static struct vpd_prom *get_VPD_PROM(struct Host *hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800706 static struct vpd_prom vpdp;
707 char *p;
708 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Andrew Morton8d8706e2006-01-11 12:17:49 -0800710 func_enter();
711 rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Andrew Morton8d8706e2006-01-11 12:17:49 -0800713 p = (char *) &vpdp;
714 for (i = 0; i < sizeof(struct vpd_prom); i++)
715 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
716 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Andrew Morton8d8706e2006-01-11 12:17:49 -0800718 /* Terminate the identifier string.
719 *** requires one extra byte in struct vpd_prom *** */
720 *p++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Andrew Morton8d8706e2006-01-11 12:17:49 -0800722 if (rio_debug & RIO_DEBUG_PROBE)
723 my_hd((char *) &vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Andrew Morton8d8706e2006-01-11 12:17:49 -0800725 func_exit();
726
727 return &vpdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728}
729
Jeff Dikeb68e31d2006-10-02 02:17:18 -0700730static const struct tty_operations rio_ops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800731 .open = riotopen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .close = gs_close,
733 .write = gs_write,
734 .put_char = gs_put_char,
735 .flush_chars = gs_flush_chars,
736 .write_room = gs_write_room,
737 .chars_in_buffer = gs_chars_in_buffer,
738 .flush_buffer = gs_flush_buffer,
739 .ioctl = rio_ioctl,
740 .throttle = rio_throttle,
741 .unthrottle = rio_unthrottle,
742 .set_termios = gs_set_termios,
743 .stop = gs_stop,
744 .start = gs_start,
745 .hangup = gs_hangup,
746};
747
748static int rio_init_drivers(void)
749{
750 int error = -ENOMEM;
751
752 rio_driver = alloc_tty_driver(256);
753 if (!rio_driver)
754 goto out;
755 rio_driver2 = alloc_tty_driver(256);
756 if (!rio_driver2)
757 goto out1;
758
759 func_enter();
760
761 rio_driver->owner = THIS_MODULE;
762 rio_driver->driver_name = "specialix_rio";
763 rio_driver->name = "ttySR";
764 rio_driver->major = RIO_NORMAL_MAJOR0;
765 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
766 rio_driver->subtype = SERIAL_TYPE_NORMAL;
767 rio_driver->init_termios = tty_std_termios;
768 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
769 rio_driver->flags = TTY_DRIVER_REAL_RAW;
770 tty_set_operations(rio_driver, &rio_ops);
771
772 rio_driver2->owner = THIS_MODULE;
773 rio_driver2->driver_name = "specialix_rio";
774 rio_driver2->name = "ttySR";
775 rio_driver2->major = RIO_NORMAL_MAJOR1;
776 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
777 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
778 rio_driver2->init_termios = tty_std_termios;
779 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
780 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
781 tty_set_operations(rio_driver2, &rio_ops);
782
Andrew Morton8d8706e2006-01-11 12:17:49 -0800783 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 if ((error = tty_register_driver(rio_driver)))
786 goto out2;
787 if ((error = tty_register_driver(rio_driver2)))
788 goto out3;
789 func_exit();
790 return 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800791 out3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 tty_unregister_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800793 out2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 put_tty_driver(rio_driver2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800795 out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 put_tty_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800797 out:
798 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 return 1;
800}
801
Alan Cox31f35932009-01-02 13:45:05 +0000802static const struct tty_port_operations rio_port_ops = {
803 .carrier_raised = rio_carrier_raised,
804};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Andrew Morton8d8706e2006-01-11 12:17:49 -0800806static int rio_init_datastructures(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800808 int i;
809 struct Port *port;
810 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Andrew Morton8d8706e2006-01-11 12:17:49 -0800812 /* Many drivers statically allocate the maximum number of ports
813 There is no reason not to allocate them dynamically. Is there? -- REW */
814 /* However, the RIO driver allows users to configure their first
815 RTA as the ports numbered 504-511. We therefore need to allocate
816 the whole range. :-( -- REW */
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818#define RI_SZ sizeof(struct rio_info)
819#define HOST_SZ sizeof(struct Host)
820#define PORT_SZ sizeof(struct Port *)
821#define TMIO_SZ sizeof(struct termios *)
Alan Cox00d83a52006-03-24 03:18:28 -0800822 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);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800823
Alan Coxd0c98732009-01-02 13:45:12 +0000824 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800825 goto free0;
Alan Coxd0c98732009-01-02 13:45:12 +0000826 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800827 goto free1;
Alan Coxd0c98732009-01-02 13:45:12 +0000828 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800829 goto free2;
830 p->RIOConf = RIOConf;
831 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833#if 1
Andrew Morton8d8706e2006-01-11 12:17:49 -0800834 for (i = 0; i < RIO_PORTS; i++) {
Alan Coxd0c98732009-01-02 13:45:12 +0000835 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800836 if (!port) {
837 goto free6;
838 }
839 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
Alan Cox31f35932009-01-02 13:45:05 +0000840 tty_port_init(&port->gs.port);
841 port->gs.port.ops = &rio_port_ops;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800842 port->PortNum = i;
843 port->gs.magic = RIO_MAGIC;
844 port->gs.close_delay = HZ / 2;
845 port->gs.closing_wait = 30 * HZ;
846 port->gs.rd = &rio_real_driver;
847 spin_lock_init(&port->portSem);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849#else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800850 /* We could postpone initializing them to when they are configured. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851#endif
852
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Andrew Morton8d8706e2006-01-11 12:17:49 -0800855 if (rio_debug & RIO_DEBUG_INIT) {
856 my_hd(&rio_real_driver, sizeof(rio_real_driver));
857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859
860 func_exit();
861 return 0;
862
863 free6:for (i--; i >= 0; i--)
864 kfree(p->RIOPortp[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865/*free5:
866 free4:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800867 free3:*/ kfree(p->RIOPortp);
868 free2:kfree(p->RIOHosts);
869 free1:
870 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
871 kfree(p);
872 free0:
873 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876static void __exit rio_release_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800878 func_enter();
879 tty_unregister_driver(rio_driver2);
880 tty_unregister_driver(rio_driver);
881 put_tty_driver(rio_driver2);
882 put_tty_driver(rio_driver);
883 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
885
886
887#ifdef CONFIG_PCI
888 /* This was written for SX, but applies to RIO too...
889 (including bugs....)
890
891 There is another bit besides Bit 17. Turning that bit off
892 (on boards shipped with the fix in the eeprom) results in a
893 hang on the next access to the card.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800894 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 /********************************************************
897 * Setting bit 17 in the CNTRL register of the PLX 9050 *
898 * chip forces a retry on writes while a read is pending.*
899 * This is to prevent the card locking up on Intel Xeon *
900 * multiprocessor systems with the NX chipset. -- NV *
901 ********************************************************/
902
903/* Newer cards are produced with this bit set from the configuration
904 EEprom. As the bit is read/write for the CPU, we can fix it here,
905 if we detect that it isn't set correctly. -- REW */
906
Andrew Morton8d8706e2006-01-11 12:17:49 -0800907static void fix_rio_pci(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Alan Cox00d83a52006-03-24 03:18:28 -0800909 unsigned long hwbase;
Al Virod886cb52006-05-27 00:08:25 -0400910 unsigned char __iomem *rebase;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800911 unsigned int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913#define CNTRL_REG_OFFSET 0x50
914#define CNTRL_REG_GOODVALUE 0x18260000
915
Alan Cox00d83a52006-03-24 03:18:28 -0800916 hwbase = pci_resource_start(pdev, 0);
917 rebase = ioremap(hwbase, 0x80);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800918 t = readl(rebase + CNTRL_REG_OFFSET);
919 if (t != CNTRL_REG_GOODVALUE) {
920 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
921 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
922 }
Alan Cox00d83a52006-03-24 03:18:28 -0800923 iounmap(rebase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925#endif
926
927
Andrew Morton8d8706e2006-01-11 12:17:49 -0800928static int __init rio_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800930 int found = 0;
931 int i;
932 struct Host *hp;
933 int retval;
934 struct vpd_prom *vpdp;
935 int okboard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800938 struct pci_dev *pdev = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800939 unsigned short tshort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940#endif
941
Andrew Morton8d8706e2006-01-11 12:17:49 -0800942 func_enter();
943 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Andrew Morton8d8706e2006-01-11 12:17:49 -0800945 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
946 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
947 rio_debug = -1;
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Andrew Morton8d8706e2006-01-11 12:17:49 -0800950 if (misc_register(&rio_fw_device) < 0) {
951 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
952 return -EIO;
953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Andrew Morton8d8706e2006-01-11 12:17:49 -0800955 retval = rio_init_datastructures();
956 if (retval < 0) {
957 misc_deregister(&rio_fw_device);
958 return retval;
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800961 /* First look for the JET devices: */
962 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
Alan Cox554b7c82006-03-24 03:18:32 -0800963 u32 tint;
964
Andrew Morton8d8706e2006-01-11 12:17:49 -0800965 if (pci_enable_device(pdev))
966 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Andrew Morton8d8706e2006-01-11 12:17:49 -0800968 /* Specialix has a whole bunch of cards with
969 0x2000 as the device ID. They say its because
970 the standard requires it. Stupid standard. */
971 /* It seems that reading a word doesn't work reliably on 2.0.
972 Also, reading a non-aligned dword doesn't work. So we read the
973 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
974 ourselves */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800975 pci_read_config_dword(pdev, 0x2c, &tint);
976 tshort = (tint >> 16) & 0xffff;
977 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
978 if (tshort != 0x0100) {
979 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
980 continue;
981 }
982 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Andrew Morton8d8706e2006-01-11 12:17:49 -0800984 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -0800985 hp->PaddrP = pci_resource_start(pdev, 2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800986 hp->Ivec = pdev->irq;
987 if (((1 << hp->Ivec) & rio_irqmask) == 0)
988 hp->Ivec = 0;
989 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -0400990 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800991 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -0800992 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800993 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
994 spin_lock_init(&hp->HostLock);
995 rio_reset_interrupt(hp);
996 rio_start_card_running(hp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Andrew Morton8d8706e2006-01-11 12:17:49 -0800998 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
Alan Cox554b7c82006-03-24 03:18:32 -0800999 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001000 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
Alan Cox00d83a52006-03-24 03:18:28 -08001001 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001002 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001003 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1004 ((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);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001005 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Andrew Morton8d8706e2006-01-11 12:17:49 -08001007 fix_rio_pci(pdev);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001008
1009 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1010 pci_dev_get(pdev);
1011
Alan Cox554b7c82006-03-24 03:18:32 -08001012 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001013 p->RIONumHosts++;
1014 found++;
1015 } else {
Al Virod886cb52006-05-27 00:08:25 -04001016 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001017 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001018 }
1019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Andrew Morton8d8706e2006-01-11 12:17:49 -08001021 /* Then look for the older PCI card.... : */
1022
1023 /* These older PCI cards have problems (only byte-mode access is
1024 supported), which makes them a bit awkward to support.
1025 They also have problems sharing interrupts. Be careful.
1026 (The driver now refuses to share interrupts for these
1027 cards. This should be sufficient).
1028 */
1029
1030 /* Then look for the older RIO/PCI devices: */
1031 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1032 if (pci_enable_device(pdev))
1033 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
1035#ifdef CONFIG_RIO_OLDPCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001036 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -08001037 hp->PaddrP = pci_resource_start(pdev, 0);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001038 hp->Ivec = pdev->irq;
1039 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1040 hp->Ivec = 0;
1041 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1042 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001043 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001044 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -08001045 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001046 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1047 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Andrew Morton8d8706e2006-01-11 12:17:49 -08001049 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1050 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Andrew Morton8d8706e2006-01-11 12:17:49 -08001052 rio_reset_interrupt(hp);
1053 rio_start_card_running(hp);
1054 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
Alan Cox554b7c82006-03-24 03:18:32 -08001055 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Alan Cox00d83a52006-03-24 03:18:28 -08001056 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001057 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001058 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1059 ((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);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001060 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Jiri Slaby86fbf142006-10-21 10:24:01 -07001062 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1063 pci_dev_get(pdev);
1064
Alan Cox554b7c82006-03-24 03:18:32 -08001065 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001066 p->RIONumHosts++;
1067 found++;
1068 } else {
Al Virod886cb52006-05-27 00:08:25 -04001069 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001070 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072#else
Andrew Morton8d8706e2006-01-11 12:17:49 -08001073 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -08001075 }
1076#endif /* PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Andrew Morton8d8706e2006-01-11 12:17:49 -08001078 /* Now probe for ISA cards... */
1079 for (i = 0; i < NR_RIO_ADDRS; i++) {
1080 hp = &p->RIOHosts[p->RIONumHosts];
1081 hp->PaddrP = rio_probe_addrs[i];
1082 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1083 hp->Ivec = 0;
1084 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001085 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001086 hp->Type = RIO_AT;
Alan Cox00d83a52006-03-24 03:18:28 -08001087 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1088 * -- YES! this is now a normal copy. Only the
Andrew Morton8d8706e2006-01-11 12:17:49 -08001089 * old PCI card uses the special PCI copy.
1090 * Moreover, the ISA card will work with the
1091 * special PCI copy anyway. -- REW */
1092 hp->Mode = 0;
1093 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Andrew Morton8d8706e2006-01-11 12:17:49 -08001095 vpdp = get_VPD_PROM(hp);
1096 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1097 okboard = 0;
1098 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)) {
1099 /* Board is present... */
Alan Cox554b7c82006-03-24 03:18:32 -08001100 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001101 /* ... and feeling fine!!!! */
1102 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1103 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1104 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1105 okboard++;
1106 found++;
1107 }
1108 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Amol Lad86842652006-12-06 20:35:19 -08001110 if (!okboard) {
Al Virod886cb52006-05-27 00:08:25 -04001111 iounmap(hp->Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001112 hp->Caddr = NULL;
1113 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001114 }
1115 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117
Andrew Morton8d8706e2006-01-11 12:17:49 -08001118 for (i = 0; i < p->RIONumHosts; i++) {
1119 hp = &p->RIOHosts[i];
1120 if (hp->Ivec) {
Thomas Gleixner5d8c8a22006-07-01 19:29:41 -07001121 int mode = IRQF_SHARED;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001122 if (hp->Ivec & 0x8000) {
1123 mode = 0;
1124 hp->Ivec &= 0x7fff;
1125 }
1126 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1127 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1128 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1129 if (retval) {
1130 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1131 hp->Ivec = 0;
1132 }
1133 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1134 if (hp->Ivec != 0) {
1135 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1136 hp->Mode |= RIO_PCI_INT_ENABLE;
1137 } else
Willy Tarreau88dacbe2007-02-17 18:57:09 +01001138 hp->Mode &= ~RIO_PCI_INT_ENABLE;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001139 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1140 rio_start_card_running(hp);
1141 }
1142 /* Init the timer "always" to make sure that it can safely be
1143 deleted when we unload... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Jiri Slaby40565f12007-02-12 00:52:31 -08001145 setup_timer(&hp->timer, rio_pollfunc, i);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001146 if (!hp->Ivec) {
1147 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
Jiri Slaby40565f12007-02-12 00:52:31 -08001148 mod_timer(&hp->timer, jiffies + rio_poll);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001149 }
1150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Andrew Morton8d8706e2006-01-11 12:17:49 -08001152 if (found) {
1153 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1154 rio_init_drivers();
1155 } else {
1156 /* deregister the misc device we created earlier */
1157 misc_deregister(&rio_fw_device);
1158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Andrew Morton8d8706e2006-01-11 12:17:49 -08001160 func_exit();
1161 return found ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
1164
Andrew Morton8d8706e2006-01-11 12:17:49 -08001165static void __exit rio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001167 int i;
1168 struct Host *hp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Andrew Morton8d8706e2006-01-11 12:17:49 -08001170 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Andrew Morton8d8706e2006-01-11 12:17:49 -08001172 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1173 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1174 if (hp->Ivec) {
1175 free_irq(hp->Ivec, hp);
1176 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1177 }
1178 /* It is safe/allowed to del_timer a non-active timer */
Jiri Slaby40565f12007-02-12 00:52:31 -08001179 del_timer_sync(&hp->timer);
Amol Lad86842652006-12-06 20:35:19 -08001180 if (hp->Caddr)
1181 iounmap(hp->Caddr);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001182 if (hp->Type == RIO_PCI)
1183 pci_dev_put(hp->pdev);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001184 }
1185
1186 if (misc_deregister(&rio_fw_device) < 0) {
1187 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190
Andrew Morton8d8706e2006-01-11 12:17:49 -08001191 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Andrew Morton8d8706e2006-01-11 12:17:49 -08001193 rio_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Andrew Morton8d8706e2006-01-11 12:17:49 -08001195 /* Release dynamically allocated memory */
1196 kfree(p->RIOPortp);
1197 kfree(p->RIOHosts);
1198 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Andrew Morton8d8706e2006-01-11 12:17:49 -08001200 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
1203module_init(rio_init);
1204module_exit(rio_exit);