diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/char/rio/rio_linux.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/char/rio/rio_linux.c')
-rw-r--r-- | drivers/char/rio/rio_linux.c | 1380 |
1 files changed, 1380 insertions, 0 deletions
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c new file mode 100644 index 000000000000..a91ae271cf0a --- /dev/null +++ b/drivers/char/rio/rio_linux.c | |||
@@ -0,0 +1,1380 @@ | |||
1 | |||
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 | * | ||
28 | * Revision history: | ||
29 | * $Log: rio.c,v $ | ||
30 | * Revision 1.1 1999/07/11 10:13:54 wolff | ||
31 | * Initial revision | ||
32 | * | ||
33 | * */ | ||
34 | |||
35 | #include <linux/module.h> | ||
36 | #include <linux/config.h> | ||
37 | #include <linux/kdev_t.h> | ||
38 | #include <asm/io.h> | ||
39 | #include <linux/kernel.h> | ||
40 | #include <linux/sched.h> | ||
41 | #include <linux/ioport.h> | ||
42 | #include <linux/interrupt.h> | ||
43 | #include <linux/errno.h> | ||
44 | #include <linux/tty.h> | ||
45 | #include <linux/tty_flip.h> | ||
46 | #include <linux/mm.h> | ||
47 | #include <linux/serial.h> | ||
48 | #include <linux/fcntl.h> | ||
49 | #include <linux/major.h> | ||
50 | #include <linux/delay.h> | ||
51 | #include <linux/pci.h> | ||
52 | #include <linux/slab.h> | ||
53 | #include <linux/miscdevice.h> | ||
54 | #include <linux/init.h> | ||
55 | |||
56 | #include <linux/generic_serial.h> | ||
57 | #include <asm/uaccess.h> | ||
58 | |||
59 | #if BITS_PER_LONG != 32 | ||
60 | # error FIXME: this driver only works on 32-bit platforms | ||
61 | #endif | ||
62 | |||
63 | #include "linux_compat.h" | ||
64 | #include "typdef.h" | ||
65 | #include "pkt.h" | ||
66 | #include "daemon.h" | ||
67 | #include "rio.h" | ||
68 | #include "riospace.h" | ||
69 | #include "top.h" | ||
70 | #include "cmdpkt.h" | ||
71 | #include "map.h" | ||
72 | #include "riotypes.h" | ||
73 | #include "rup.h" | ||
74 | #include "port.h" | ||
75 | #include "riodrvr.h" | ||
76 | #include "rioinfo.h" | ||
77 | #include "func.h" | ||
78 | #include "errors.h" | ||
79 | #include "pci.h" | ||
80 | |||
81 | #include "parmmap.h" | ||
82 | #include "unixrup.h" | ||
83 | #include "board.h" | ||
84 | #include "host.h" | ||
85 | #include "error.h" | ||
86 | #include "phb.h" | ||
87 | #include "link.h" | ||
88 | #include "cmdblk.h" | ||
89 | #include "route.h" | ||
90 | #include "control.h" | ||
91 | #include "cirrus.h" | ||
92 | #include "rioioctl.h" | ||
93 | #include "param.h" | ||
94 | #include "list.h" | ||
95 | #include "sam.h" | ||
96 | #include "protsts.h" | ||
97 | #include "rioboard.h" | ||
98 | |||
99 | |||
100 | #include "rio_linux.h" | ||
101 | |||
102 | /* I don't think that this driver can handle more than 512 ports on | ||
103 | one machine. Specialix specifies max 4 boards in one machine. I don't | ||
104 | know why. If you want to try anyway you'll have to increase the number | ||
105 | of boards in rio.h. You'll have to allocate more majors if you need | ||
106 | more than 512 ports.... */ | ||
107 | |||
108 | #ifndef RIO_NORMAL_MAJOR0 | ||
109 | /* This allows overriding on the compiler commandline, or in a "major.h" | ||
110 | include or something like that */ | ||
111 | #define RIO_NORMAL_MAJOR0 154 | ||
112 | #define RIO_NORMAL_MAJOR1 156 | ||
113 | #endif | ||
114 | |||
115 | #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 | ||
116 | #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000 | ||
117 | #endif | ||
118 | |||
119 | #ifndef RIO_WINDOW_LEN | ||
120 | #define RIO_WINDOW_LEN 0x10000 | ||
121 | #endif | ||
122 | |||
123 | |||
124 | /* Configurable options: | ||
125 | (Don't be too sure that it'll work if you toggle them) */ | ||
126 | |||
127 | /* Am I paranoid or not ? ;-) */ | ||
128 | #undef RIO_PARANOIA_CHECK | ||
129 | |||
130 | |||
131 | /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000 | ||
132 | Hz, but it is user configurable. I don't recommend going above 1000 | ||
133 | Hz. The interrupt ratelimit might trigger if the interrupt is | ||
134 | shared with a very active other device. | ||
135 | undef this if you want to disable the check.... | ||
136 | */ | ||
137 | #define IRQ_RATE_LIMIT 200 | ||
138 | |||
139 | #if 0 | ||
140 | /* Not implemented */ | ||
141 | /* | ||
142 | * The following defines are mostly for testing purposes. But if you need | ||
143 | * some nice reporting in your syslog, you can define them also. | ||
144 | */ | ||
145 | #define RIO_REPORT_FIFO | ||
146 | #define RIO_REPORT_OVERRUN | ||
147 | #endif | ||
148 | |||
149 | |||
150 | /* These constants are derived from SCO Source */ | ||
151 | static struct Conf | ||
152 | RIOConf = | ||
153 | { | ||
154 | /* locator */ "RIO Config here", | ||
155 | /* startuptime */ HZ*2, /* how long to wait for card to run */ | ||
156 | /* slowcook */ 0, /* TRUE -> always use line disc. */ | ||
157 | /* intrpolltime */ 1, /* The frequency of OUR polls */ | ||
158 | /* breakinterval */ 25, /* x10 mS XXX: units seem to be 1ms not 10! -- REW*/ | ||
159 | /* timer */ 10, /* mS */ | ||
160 | /* RtaLoadBase */ 0x7000, | ||
161 | /* HostLoadBase */ 0x7C00, | ||
162 | /* XpHz */ 5, /* number of Xprint hits per second */ | ||
163 | /* XpCps */ 120, /* Xprint characters per second */ | ||
164 | /* XpOn */ "\033d#", /* start Xprint for a wyse 60 */ | ||
165 | /* XpOff */ "\024", /* end Xprint for a wyse 60 */ | ||
166 | /* MaxXpCps */ 2000, /* highest Xprint speed */ | ||
167 | /* MinXpCps */ 10, /* slowest Xprint speed */ | ||
168 | /* SpinCmds */ 1, /* non-zero for mega fast boots */ | ||
169 | /* First Addr */ 0x0A0000, /* First address to look at */ | ||
170 | /* Last Addr */ 0xFF0000, /* Last address looked at */ | ||
171 | /* BufferSize */ 1024, /* Bytes per port of buffering */ | ||
172 | /* LowWater */ 256, /* how much data left before wakeup */ | ||
173 | /* LineLength */ 80, /* how wide is the console? */ | ||
174 | /* CmdTimeout */ HZ, /* how long a close command may take */ | ||
175 | }; | ||
176 | |||
177 | |||
178 | |||
179 | |||
180 | /* Function prototypes */ | ||
181 | |||
182 | static void rio_disable_tx_interrupts (void * ptr); | ||
183 | static void rio_enable_tx_interrupts (void * ptr); | ||
184 | static void rio_disable_rx_interrupts (void * ptr); | ||
185 | static void rio_enable_rx_interrupts (void * ptr); | ||
186 | static int rio_get_CD (void * ptr); | ||
187 | static void rio_shutdown_port (void * ptr); | ||
188 | static int rio_set_real_termios (void *ptr); | ||
189 | static void rio_hungup (void *ptr); | ||
190 | static void rio_close (void *ptr); | ||
191 | static int rio_chars_in_buffer (void * ptr); | ||
192 | static int rio_fw_ioctl (struct inode *inode, struct file *filp, | ||
193 | unsigned int cmd, unsigned long arg); | ||
194 | static int rio_init_drivers(void); | ||
195 | |||
196 | static void my_hd (void *addr, int len); | ||
197 | |||
198 | static struct tty_driver *rio_driver, *rio_driver2; | ||
199 | |||
200 | /* The name "p" is a bit non-descript. But that's what the rio-lynxos | ||
201 | sources use all over the place. */ | ||
202 | struct rio_info *p; | ||
203 | |||
204 | int rio_debug; | ||
205 | |||
206 | |||
207 | /* You can have the driver poll your card. | ||
208 | - Set rio_poll to 1 to poll every timer tick (10ms on Intel). | ||
209 | This is used when the card cannot use an interrupt for some reason. | ||
210 | */ | ||
211 | static int rio_poll = 1; | ||
212 | |||
213 | |||
214 | /* These are the only open spaces in my computer. Yours may have more | ||
215 | or less.... */ | ||
216 | static int rio_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000}; | ||
217 | |||
218 | #define NR_RIO_ADDRS (sizeof(rio_probe_addrs)/sizeof (int)) | ||
219 | |||
220 | |||
221 | /* Set the mask to all-ones. This alas, only supports 32 interrupts. | ||
222 | Some architectures may need more. -- Changed to LONG to | ||
223 | support up to 64 bits on 64bit architectures. -- REW 20/06/99 */ | ||
224 | long rio_irqmask = -1; | ||
225 | |||
226 | MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>"); | ||
227 | MODULE_DESCRIPTION("RIO driver"); | ||
228 | MODULE_LICENSE("GPL"); | ||
229 | module_param(rio_poll, int, 0); | ||
230 | module_param(rio_debug, int, 0644); | ||
231 | module_param(rio_irqmask, long, 0); | ||
232 | |||
233 | static struct real_driver rio_real_driver = { | ||
234 | rio_disable_tx_interrupts, | ||
235 | rio_enable_tx_interrupts, | ||
236 | rio_disable_rx_interrupts, | ||
237 | rio_enable_rx_interrupts, | ||
238 | rio_get_CD, | ||
239 | rio_shutdown_port, | ||
240 | rio_set_real_termios, | ||
241 | rio_chars_in_buffer, | ||
242 | rio_close, | ||
243 | rio_hungup, | ||
244 | NULL | ||
245 | }; | ||
246 | |||
247 | /* | ||
248 | * Firmware loader driver specific routines | ||
249 | * | ||
250 | */ | ||
251 | |||
252 | static struct file_operations rio_fw_fops = { | ||
253 | .owner = THIS_MODULE, | ||
254 | .ioctl = rio_fw_ioctl, | ||
255 | }; | ||
256 | |||
257 | static struct miscdevice rio_fw_device = { | ||
258 | RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops | ||
259 | }; | ||
260 | |||
261 | |||
262 | |||
263 | |||
264 | |||
265 | #ifdef RIO_PARANOIA_CHECK | ||
266 | |||
267 | /* This doesn't work. Who's paranoid around here? Not me! */ | ||
268 | |||
269 | static inline int rio_paranoia_check(struct rio_port const * port, | ||
270 | char *name, const char *routine) | ||
271 | { | ||
272 | |||
273 | static const char *badmagic = | ||
274 | KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n"; | ||
275 | static const char *badinfo = | ||
276 | KERN_ERR "rio: Warning: null rio port for device %s in %s\n"; | ||
277 | |||
278 | if (!port) { | ||
279 | printk (badinfo, name, routine); | ||
280 | return 1; | ||
281 | } | ||
282 | if (port->magic != RIO_MAGIC) { | ||
283 | printk (badmagic, name, routine); | ||
284 | return 1; | ||
285 | } | ||
286 | |||
287 | return 0; | ||
288 | } | ||
289 | #else | ||
290 | #define rio_paranoia_check(a,b,c) 0 | ||
291 | #endif | ||
292 | |||
293 | |||
294 | #ifdef DEBUG | ||
295 | static void my_hd (void *ad, int len) | ||
296 | { | ||
297 | int i, j, ch; | ||
298 | unsigned char *addr = ad; | ||
299 | |||
300 | for (i=0;i<len;i+=16) { | ||
301 | rio_dprintk (RIO_DEBUG_PARAM, "%08x ", (int) addr+i); | ||
302 | for (j=0;j<16;j++) { | ||
303 | rio_dprintk (RIO_DEBUG_PARAM, "%02x %s", addr[j+i], (j==7)?" ":""); | ||
304 | } | ||
305 | for (j=0;j<16;j++) { | ||
306 | ch = addr[j+i]; | ||
307 | rio_dprintk (RIO_DEBUG_PARAM, "%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch)); | ||
308 | } | ||
309 | rio_dprintk (RIO_DEBUG_PARAM, "\n"); | ||
310 | } | ||
311 | } | ||
312 | #else | ||
313 | #define my_hd(ad,len) do{/* nothing*/ } while (0) | ||
314 | #endif | ||
315 | |||
316 | |||
317 | /* Delay a number of jiffies, allowing a signal to interrupt */ | ||
318 | int RIODelay (struct Port *PortP, int njiffies) | ||
319 | { | ||
320 | func_enter (); | ||
321 | |||
322 | rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies); | ||
323 | msleep_interruptible(jiffies_to_msecs(njiffies)); | ||
324 | func_exit(); | ||
325 | |||
326 | if (signal_pending(current)) | ||
327 | return RIO_FAIL; | ||
328 | else | ||
329 | return !RIO_FAIL; | ||
330 | } | ||
331 | |||
332 | |||
333 | /* Delay a number of jiffies, disallowing a signal to interrupt */ | ||
334 | int RIODelay_ni (struct Port *PortP, int njiffies) | ||
335 | { | ||
336 | func_enter (); | ||
337 | |||
338 | rio_dprintk (RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies); | ||
339 | msleep(jiffies_to_msecs(njiffies)); | ||
340 | func_exit(); | ||
341 | return !RIO_FAIL; | ||
342 | } | ||
343 | |||
344 | |||
345 | int rio_minor(struct tty_struct *tty) | ||
346 | { | ||
347 | return tty->index + (tty->driver == rio_driver) ? 0 : 256; | ||
348 | } | ||
349 | |||
350 | |||
351 | int rio_ismodem(struct tty_struct *tty) | ||
352 | { | ||
353 | return 1; | ||
354 | } | ||
355 | |||
356 | |||
357 | void rio_udelay (int usecs) | ||
358 | { | ||
359 | udelay (usecs); | ||
360 | } | ||
361 | |||
362 | static int rio_set_real_termios (void *ptr) | ||
363 | { | ||
364 | int rv, modem; | ||
365 | struct tty_struct *tty; | ||
366 | func_enter(); | ||
367 | |||
368 | tty = ((struct Port *)ptr)->gs.tty; | ||
369 | |||
370 | modem = rio_ismodem(tty); | ||
371 | |||
372 | rv = RIOParam( (struct Port *) ptr, CONFIG, modem, 1); | ||
373 | |||
374 | func_exit (); | ||
375 | |||
376 | return rv; | ||
377 | } | ||
378 | |||
379 | |||
380 | static void rio_reset_interrupt (struct Host *HostP) | ||
381 | { | ||
382 | func_enter(); | ||
383 | |||
384 | switch( HostP->Type ) { | ||
385 | case RIO_AT: | ||
386 | case RIO_MCA: | ||
387 | case RIO_PCI: | ||
388 | WBYTE(HostP->ResetInt , 0xff); | ||
389 | } | ||
390 | |||
391 | func_exit(); | ||
392 | } | ||
393 | |||
394 | |||
395 | static irqreturn_t rio_interrupt (int irq, void *ptr, struct pt_regs *regs) | ||
396 | { | ||
397 | struct Host *HostP; | ||
398 | func_enter (); | ||
399 | |||
400 | HostP = (struct Host*)ptr; /* &p->RIOHosts[(long)ptr]; */ | ||
401 | rio_dprintk (RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", | ||
402 | irq, HostP->Ivec); | ||
403 | |||
404 | /* AAargh! The order in which to do these things is essential and | ||
405 | not trivial. | ||
406 | |||
407 | - Rate limit goes before "recursive". Otherwise a series of | ||
408 | recursive calls will hang the machine in the interrupt routine. | ||
409 | |||
410 | - hardware twiddling goes before "recursive". Otherwise when we | ||
411 | poll the card, and a recursive interrupt happens, we won't | ||
412 | ack the card, so it might keep on interrupting us. (especially | ||
413 | level sensitive interrupt systems like PCI). | ||
414 | |||
415 | - Rate limit goes before hardware twiddling. Otherwise we won't | ||
416 | catch a card that has gone bonkers. | ||
417 | |||
418 | - The "initialized" test goes after the hardware twiddling. Otherwise | ||
419 | the card will stick us in the interrupt routine again. | ||
420 | |||
421 | - The initialized test goes before recursive. | ||
422 | */ | ||
423 | |||
424 | |||
425 | |||
426 | #ifdef IRQ_RATE_LIMIT | ||
427 | /* Aaargh! I'm ashamed. This costs more lines-of-code than the | ||
428 | actual interrupt routine!. (Well, used to when I wrote that comment) */ | ||
429 | { | ||
430 | static int lastjif; | ||
431 | static int nintr=0; | ||
432 | |||
433 | if (lastjif == jiffies) { | ||
434 | if (++nintr > IRQ_RATE_LIMIT) { | ||
435 | free_irq (HostP->Ivec, ptr); | ||
436 | printk (KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", | ||
437 | HostP->Ivec); | ||
438 | } | ||
439 | } else { | ||
440 | lastjif = jiffies; | ||
441 | nintr = 0; | ||
442 | } | ||
443 | } | ||
444 | #endif | ||
445 | rio_dprintk (RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n"); | ||
446 | if (HostP->Ivec == irq) { | ||
447 | /* Tell the card we've noticed the interrupt. */ | ||
448 | rio_reset_interrupt (HostP); | ||
449 | } | ||
450 | |||
451 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) | ||
452 | return IRQ_HANDLED; | ||
453 | |||
454 | if (test_and_set_bit (RIO_BOARD_INTR_LOCK, &HostP->locks)) { | ||
455 | printk (KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", | ||
456 | (int) ptr, HostP->Ivec); | ||
457 | return IRQ_HANDLED; | ||
458 | } | ||
459 | |||
460 | RIOServiceHost(p, HostP, irq); | ||
461 | |||
462 | rio_dprintk ( RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", | ||
463 | (int) ptr, HostP->Type); | ||
464 | |||
465 | clear_bit (RIO_BOARD_INTR_LOCK, &HostP->locks); | ||
466 | rio_dprintk (RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", | ||
467 | irq, HostP->Ivec); | ||
468 | func_exit (); | ||
469 | return IRQ_HANDLED; | ||
470 | } | ||
471 | |||
472 | |||
473 | static void rio_pollfunc (unsigned long data) | ||
474 | { | ||
475 | func_enter (); | ||
476 | |||
477 | rio_interrupt (0, &p->RIOHosts[data], NULL); | ||
478 | p->RIOHosts[data].timer.expires = jiffies + rio_poll; | ||
479 | add_timer (&p->RIOHosts[data].timer); | ||
480 | |||
481 | func_exit (); | ||
482 | } | ||
483 | |||
484 | |||
485 | /* ********************************************************************** * | ||
486 | * Here are the routines that actually * | ||
487 | * interface with the generic_serial driver * | ||
488 | * ********************************************************************** */ | ||
489 | |||
490 | /* Ehhm. I don't know how to fiddle with interrupts on the Specialix | ||
491 | cards. .... Hmm. Ok I figured it out. You don't. -- REW */ | ||
492 | |||
493 | static void rio_disable_tx_interrupts (void * ptr) | ||
494 | { | ||
495 | func_enter(); | ||
496 | |||
497 | /* port->gs.flags &= ~GS_TX_INTEN; */ | ||
498 | |||
499 | func_exit(); | ||
500 | } | ||
501 | |||
502 | |||
503 | static void rio_enable_tx_interrupts (void * ptr) | ||
504 | { | ||
505 | struct Port *PortP = ptr; | ||
506 | /* int hn; */ | ||
507 | |||
508 | func_enter(); | ||
509 | |||
510 | /* hn = PortP->HostP - p->RIOHosts; | ||
511 | |||
512 | rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn); | ||
513 | rio_interrupt (-1,(void *) hn, NULL); */ | ||
514 | |||
515 | RIOTxEnable((char *) PortP); | ||
516 | |||
517 | /* | ||
518 | * In general we cannot count on "tx empty" interrupts, although | ||
519 | * the interrupt routine seems to be able to tell the difference. | ||
520 | */ | ||
521 | PortP->gs.flags &= ~GS_TX_INTEN; | ||
522 | |||
523 | func_exit(); | ||
524 | } | ||
525 | |||
526 | |||
527 | static void rio_disable_rx_interrupts (void * ptr) | ||
528 | { | ||
529 | func_enter(); | ||
530 | func_exit(); | ||
531 | } | ||
532 | |||
533 | static void rio_enable_rx_interrupts (void * ptr) | ||
534 | { | ||
535 | /* struct rio_port *port = ptr; */ | ||
536 | func_enter(); | ||
537 | func_exit(); | ||
538 | } | ||
539 | |||
540 | |||
541 | /* Jeez. Isn't this simple? */ | ||
542 | static int rio_get_CD (void * ptr) | ||
543 | { | ||
544 | struct Port *PortP = ptr; | ||
545 | int rv; | ||
546 | |||
547 | func_enter(); | ||
548 | rv = (PortP->ModemState & MSVR1_CD) != 0; | ||
549 | |||
550 | rio_dprintk (RIO_DEBUG_INIT, "Getting CD status: %d\n", rv); | ||
551 | |||
552 | func_exit(); | ||
553 | return rv; | ||
554 | } | ||
555 | |||
556 | |||
557 | /* Jeez. Isn't this simple? Actually, we can sync with the actual port | ||
558 | by just pushing stuff into the queue going to the port... */ | ||
559 | static int rio_chars_in_buffer (void * ptr) | ||
560 | { | ||
561 | func_enter(); | ||
562 | |||
563 | func_exit(); | ||
564 | return 0; | ||
565 | } | ||
566 | |||
567 | |||
568 | /* Nothing special here... */ | ||
569 | static void rio_shutdown_port (void * ptr) | ||
570 | { | ||
571 | struct Port *PortP; | ||
572 | |||
573 | func_enter(); | ||
574 | |||
575 | PortP = (struct Port *)ptr; | ||
576 | PortP->gs.tty = NULL; | ||
577 | #if 0 | ||
578 | port->gs.flags &= ~ GS_ACTIVE; | ||
579 | if (!port->gs.tty) { | ||
580 | rio_dprintk (RIO_DBUG_TTY, "No tty.\n"); | ||
581 | return; | ||
582 | } | ||
583 | if (!port->gs.tty->termios) { | ||
584 | rio_dprintk (RIO_DEBUG_TTY, "No termios.\n"); | ||
585 | return; | ||
586 | } | ||
587 | if (port->gs.tty->termios->c_cflag & HUPCL) { | ||
588 | rio_setsignals (port, 0, 0); | ||
589 | } | ||
590 | #endif | ||
591 | |||
592 | func_exit(); | ||
593 | } | ||
594 | |||
595 | |||
596 | /* I haven't the foggiest why the decrement use count has to happen | ||
597 | here. The whole linux serial drivers stuff needs to be redesigned. | ||
598 | My guess is that this is a hack to minimize the impact of a bug | ||
599 | elsewhere. Thinking about it some more. (try it sometime) Try | ||
600 | running minicom on a serial port that is driven by a modularized | ||
601 | driver. Have the modem hangup. Then remove the driver module. Then | ||
602 | exit minicom. I expect an "oops". -- REW */ | ||
603 | static void rio_hungup (void *ptr) | ||
604 | { | ||
605 | struct Port *PortP; | ||
606 | |||
607 | func_enter(); | ||
608 | |||
609 | PortP = (struct Port *)ptr; | ||
610 | PortP->gs.tty = NULL; | ||
611 | |||
612 | func_exit (); | ||
613 | } | ||
614 | |||
615 | |||
616 | /* The standard serial_close would become shorter if you'd wrap it like | ||
617 | this. | ||
618 | rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;} | ||
619 | */ | ||
620 | static void rio_close (void *ptr) | ||
621 | { | ||
622 | struct Port *PortP; | ||
623 | |||
624 | func_enter (); | ||
625 | |||
626 | PortP = (struct Port *)ptr; | ||
627 | |||
628 | riotclose (ptr); | ||
629 | |||
630 | if(PortP->gs.count) { | ||
631 | printk (KERN_ERR "WARNING port count:%d\n", PortP->gs.count); | ||
632 | PortP->gs.count = 0; | ||
633 | } | ||
634 | |||
635 | PortP->gs.tty = NULL; | ||
636 | func_exit (); | ||
637 | } | ||
638 | |||
639 | |||
640 | |||
641 | static int rio_fw_ioctl (struct inode *inode, struct file *filp, | ||
642 | unsigned int cmd, unsigned long arg) | ||
643 | { | ||
644 | int rc = 0; | ||
645 | func_enter(); | ||
646 | |||
647 | /* The "dev" argument isn't used. */ | ||
648 | rc = riocontrol (p, 0, cmd, (void *)arg, capable(CAP_SYS_ADMIN)); | ||
649 | |||
650 | func_exit (); | ||
651 | return rc; | ||
652 | } | ||
653 | |||
654 | extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, | ||
655 | int command, int len, int arg); | ||
656 | |||
657 | static int rio_ioctl (struct tty_struct * tty, struct file * filp, | ||
658 | unsigned int cmd, unsigned long arg) | ||
659 | { | ||
660 | int rc; | ||
661 | struct Port *PortP; | ||
662 | int ival; | ||
663 | |||
664 | func_enter(); | ||
665 | |||
666 | PortP = (struct Port *)tty->driver_data; | ||
667 | |||
668 | rc = 0; | ||
669 | switch (cmd) { | ||
670 | #if 0 | ||
671 | case TIOCGSOFTCAR: | ||
672 | rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), | ||
673 | (unsigned int *) arg); | ||
674 | break; | ||
675 | #endif | ||
676 | case TIOCSSOFTCAR: | ||
677 | if ((rc = get_user(ival, (unsigned int *) arg)) == 0) { | ||
678 | tty->termios->c_cflag = | ||
679 | (tty->termios->c_cflag & ~CLOCAL) | | ||
680 | (ival ? CLOCAL : 0); | ||
681 | } | ||
682 | break; | ||
683 | case TIOCGSERIAL: | ||
684 | rc = -EFAULT; | ||
685 | if (access_ok(VERIFY_WRITE, (void *) arg, | ||
686 | sizeof(struct serial_struct))) | ||
687 | rc = gs_getserial(&PortP->gs, (struct serial_struct *) arg); | ||
688 | break; | ||
689 | case TCSBRK: | ||
690 | if ( PortP->State & RIO_DELETED ) { | ||
691 | rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); | ||
692 | rc = -EIO; | ||
693 | } else { | ||
694 | if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) { | ||
695 | rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); | ||
696 | rc = -EIO; | ||
697 | } | ||
698 | } | ||
699 | break; | ||
700 | case TCSBRKP: | ||
701 | if ( PortP->State & RIO_DELETED ) { | ||
702 | rio_dprintk (RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); | ||
703 | rc = -EIO; | ||
704 | } else { | ||
705 | int l; | ||
706 | l = arg?arg*100:250; | ||
707 | if (l > 255) l = 255; | ||
708 | if (RIOShortCommand(p, PortP, SBREAK, 2, arg?arg*100:250) == RIO_FAIL) { | ||
709 | rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); | ||
710 | rc = -EIO; | ||
711 | } | ||
712 | } | ||
713 | break; | ||
714 | case TIOCSSERIAL: | ||
715 | rc = -EFAULT; | ||
716 | if (access_ok(VERIFY_READ, (void *) arg, | ||
717 | sizeof(struct serial_struct))) | ||
718 | rc = gs_setserial(&PortP->gs, (struct serial_struct *) arg); | ||
719 | break; | ||
720 | #if 0 | ||
721 | /* | ||
722 | * note: these IOCTLs no longer reach here. Use | ||
723 | * tiocmset/tiocmget driver methods instead. The | ||
724 | * #if 0 disablement predates this comment. | ||
725 | */ | ||
726 | case TIOCMGET: | ||
727 | rc = -EFAULT; | ||
728 | if (access_ok(VERIFY_WRITE, (void *) arg, | ||
729 | sizeof(unsigned int))) { | ||
730 | rc = 0; | ||
731 | ival = rio_getsignals(port); | ||
732 | put_user(ival, (unsigned int *) arg); | ||
733 | } | ||
734 | break; | ||
735 | case TIOCMBIS: | ||
736 | if ((rc = get_user(ival, (unsigned int *) arg)) == 0) { | ||
737 | rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : -1), | ||
738 | ((ival & TIOCM_RTS) ? 1 : -1)); | ||
739 | } | ||
740 | break; | ||
741 | case TIOCMBIC: | ||
742 | if ((rc = get_user(ival, (unsigned int *) arg)) == 0) { | ||
743 | rio_setsignals(port, ((ival & TIOCM_DTR) ? 0 : -1), | ||
744 | ((ival & TIOCM_RTS) ? 0 : -1)); | ||
745 | } | ||
746 | break; | ||
747 | case TIOCMSET: | ||
748 | if ((rc = get_user(ival, (unsigned int *) arg)) == 0) { | ||
749 | rio_setsignals(port, ((ival & TIOCM_DTR) ? 1 : 0), | ||
750 | ((ival & TIOCM_RTS) ? 1 : 0)); | ||
751 | } | ||
752 | break; | ||
753 | #endif | ||
754 | default: | ||
755 | rc = -ENOIOCTLCMD; | ||
756 | break; | ||
757 | } | ||
758 | func_exit(); | ||
759 | return rc; | ||
760 | } | ||
761 | |||
762 | |||
763 | /* The throttle/unthrottle scheme for the Specialix card is different | ||
764 | * from other drivers and deserves some explanation. | ||
765 | * The Specialix hardware takes care of XON/XOFF | ||
766 | * and CTS/RTS flow control itself. This means that all we have to | ||
767 | * do when signalled by the upper tty layer to throttle/unthrottle is | ||
768 | * to make a note of it here. When we come to read characters from the | ||
769 | * rx buffers on the card (rio_receive_chars()) we look to see if the | ||
770 | * upper layer can accept more (as noted here in rio_rx_throt[]). | ||
771 | * If it can't we simply don't remove chars from the cards buffer. | ||
772 | * When the tty layer can accept chars, we again note that here and when | ||
773 | * rio_receive_chars() is called it will remove them from the cards buffer. | ||
774 | * The card will notice that a ports buffer has drained below some low | ||
775 | * water mark and will unflow control the line itself, using whatever | ||
776 | * flow control scheme is in use for that port. -- Simon Allen | ||
777 | */ | ||
778 | |||
779 | static void rio_throttle (struct tty_struct * tty) | ||
780 | { | ||
781 | struct Port *port = (struct Port *)tty->driver_data; | ||
782 | |||
783 | func_enter(); | ||
784 | /* If the port is using any type of input flow | ||
785 | * control then throttle the port. | ||
786 | */ | ||
787 | |||
788 | if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) { | ||
789 | port->State |= RIO_THROTTLE_RX; | ||
790 | } | ||
791 | |||
792 | func_exit(); | ||
793 | } | ||
794 | |||
795 | |||
796 | static void rio_unthrottle (struct tty_struct * tty) | ||
797 | { | ||
798 | struct Port *port = (struct Port *)tty->driver_data; | ||
799 | |||
800 | func_enter(); | ||
801 | /* Always unthrottle even if flow control is not enabled on | ||
802 | * this port in case we disabled flow control while the port | ||
803 | * was throttled | ||
804 | */ | ||
805 | |||
806 | port->State &= ~RIO_THROTTLE_RX; | ||
807 | |||
808 | func_exit(); | ||
809 | return; | ||
810 | } | ||
811 | |||
812 | |||
813 | |||
814 | |||
815 | |||
816 | /* ********************************************************************** * | ||
817 | * Here are the initialization routines. * | ||
818 | * ********************************************************************** */ | ||
819 | |||
820 | |||
821 | static struct vpd_prom *get_VPD_PROM (struct Host *hp) | ||
822 | { | ||
823 | static struct vpd_prom vpdp; | ||
824 | char *p; | ||
825 | int i; | ||
826 | |||
827 | func_enter(); | ||
828 | rio_dprintk (RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", | ||
829 | hp->Caddr + RIO_VPD_ROM); | ||
830 | |||
831 | p = (char *) &vpdp; | ||
832 | for (i=0;i< sizeof (struct vpd_prom);i++) | ||
833 | *p++ = readb (hp->Caddr+RIO_VPD_ROM + i*2); | ||
834 | /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */ | ||
835 | |||
836 | /* Terminate the identifier string. | ||
837 | *** requires one extra byte in struct vpd_prom *** */ | ||
838 | *p++=0; | ||
839 | |||
840 | if (rio_debug & RIO_DEBUG_PROBE) | ||
841 | my_hd ((char *)&vpdp, 0x20); | ||
842 | |||
843 | func_exit(); | ||
844 | |||
845 | return &vpdp; | ||
846 | } | ||
847 | |||
848 | static struct tty_operations rio_ops = { | ||
849 | .open = riotopen, | ||
850 | .close = gs_close, | ||
851 | .write = gs_write, | ||
852 | .put_char = gs_put_char, | ||
853 | .flush_chars = gs_flush_chars, | ||
854 | .write_room = gs_write_room, | ||
855 | .chars_in_buffer = gs_chars_in_buffer, | ||
856 | .flush_buffer = gs_flush_buffer, | ||
857 | .ioctl = rio_ioctl, | ||
858 | .throttle = rio_throttle, | ||
859 | .unthrottle = rio_unthrottle, | ||
860 | .set_termios = gs_set_termios, | ||
861 | .stop = gs_stop, | ||
862 | .start = gs_start, | ||
863 | .hangup = gs_hangup, | ||
864 | }; | ||
865 | |||
866 | static int rio_init_drivers(void) | ||
867 | { | ||
868 | int error = -ENOMEM; | ||
869 | |||
870 | rio_driver = alloc_tty_driver(256); | ||
871 | if (!rio_driver) | ||
872 | goto out; | ||
873 | rio_driver2 = alloc_tty_driver(256); | ||
874 | if (!rio_driver2) | ||
875 | goto out1; | ||
876 | |||
877 | func_enter(); | ||
878 | |||
879 | rio_driver->owner = THIS_MODULE; | ||
880 | rio_driver->driver_name = "specialix_rio"; | ||
881 | rio_driver->name = "ttySR"; | ||
882 | rio_driver->major = RIO_NORMAL_MAJOR0; | ||
883 | rio_driver->type = TTY_DRIVER_TYPE_SERIAL; | ||
884 | rio_driver->subtype = SERIAL_TYPE_NORMAL; | ||
885 | rio_driver->init_termios = tty_std_termios; | ||
886 | rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | ||
887 | rio_driver->flags = TTY_DRIVER_REAL_RAW; | ||
888 | tty_set_operations(rio_driver, &rio_ops); | ||
889 | |||
890 | rio_driver2->owner = THIS_MODULE; | ||
891 | rio_driver2->driver_name = "specialix_rio"; | ||
892 | rio_driver2->name = "ttySR"; | ||
893 | rio_driver2->major = RIO_NORMAL_MAJOR1; | ||
894 | rio_driver2->type = TTY_DRIVER_TYPE_SERIAL; | ||
895 | rio_driver2->subtype = SERIAL_TYPE_NORMAL; | ||
896 | rio_driver2->init_termios = tty_std_termios; | ||
897 | rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | ||
898 | rio_driver2->flags = TTY_DRIVER_REAL_RAW; | ||
899 | tty_set_operations(rio_driver2, &rio_ops); | ||
900 | |||
901 | rio_dprintk (RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios); | ||
902 | |||
903 | if ((error = tty_register_driver(rio_driver))) | ||
904 | goto out2; | ||
905 | if ((error = tty_register_driver(rio_driver2))) | ||
906 | goto out3; | ||
907 | func_exit(); | ||
908 | return 0; | ||
909 | out3: | ||
910 | tty_unregister_driver(rio_driver); | ||
911 | out2: | ||
912 | put_tty_driver(rio_driver2); | ||
913 | out1: | ||
914 | put_tty_driver(rio_driver); | ||
915 | out: | ||
916 | printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", | ||
917 | error); | ||
918 | return 1; | ||
919 | } | ||
920 | |||
921 | |||
922 | static void * ckmalloc (int size) | ||
923 | { | ||
924 | void *p; | ||
925 | |||
926 | p = kmalloc(size, GFP_KERNEL); | ||
927 | if (p) | ||
928 | memset(p, 0, size); | ||
929 | return p; | ||
930 | } | ||
931 | |||
932 | |||
933 | |||
934 | static int rio_init_datastructures (void) | ||
935 | { | ||
936 | int i; | ||
937 | struct Port *port; | ||
938 | func_enter(); | ||
939 | |||
940 | /* Many drivers statically allocate the maximum number of ports | ||
941 | There is no reason not to allocate them dynamically. Is there? -- REW */ | ||
942 | /* However, the RIO driver allows users to configure their first | ||
943 | RTA as the ports numbered 504-511. We therefore need to allocate | ||
944 | the whole range. :-( -- REW */ | ||
945 | |||
946 | #define RI_SZ sizeof(struct rio_info) | ||
947 | #define HOST_SZ sizeof(struct Host) | ||
948 | #define PORT_SZ sizeof(struct Port *) | ||
949 | #define TMIO_SZ sizeof(struct termios *) | ||
950 | rio_dprintk (RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", | ||
951 | RI_SZ, | ||
952 | RIO_HOSTS * HOST_SZ, | ||
953 | RIO_PORTS * PORT_SZ, | ||
954 | RIO_PORTS * TMIO_SZ, | ||
955 | RIO_PORTS * TMIO_SZ); | ||
956 | |||
957 | if (!(p = ckmalloc ( RI_SZ))) goto free0; | ||
958 | if (!(p->RIOHosts = ckmalloc (RIO_HOSTS * HOST_SZ))) goto free1; | ||
959 | if (!(p->RIOPortp = ckmalloc (RIO_PORTS * PORT_SZ))) goto free2; | ||
960 | p->RIOConf = RIOConf; | ||
961 | rio_dprintk (RIO_DEBUG_INIT, "Got : %p %p %p\n", | ||
962 | p, p->RIOHosts, p->RIOPortp); | ||
963 | |||
964 | #if 1 | ||
965 | for (i = 0; i < RIO_PORTS; i++) { | ||
966 | port = p->RIOPortp[i] = ckmalloc (sizeof (struct Port)); | ||
967 | if (!port) { | ||
968 | goto free6; | ||
969 | } | ||
970 | rio_dprintk (RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped); | ||
971 | port->PortNum = i; | ||
972 | port->gs.magic = RIO_MAGIC; | ||
973 | port->gs.close_delay = HZ/2; | ||
974 | port->gs.closing_wait = 30 * HZ; | ||
975 | port->gs.rd = &rio_real_driver; | ||
976 | spin_lock_init(&port->portSem); | ||
977 | /* | ||
978 | * Initializing wait queue | ||
979 | */ | ||
980 | init_waitqueue_head(&port->gs.open_wait); | ||
981 | init_waitqueue_head(&port->gs.close_wait); | ||
982 | } | ||
983 | #else | ||
984 | /* We could postpone initializing them to when they are configured. */ | ||
985 | #endif | ||
986 | |||
987 | |||
988 | |||
989 | if (rio_debug & RIO_DEBUG_INIT) { | ||
990 | my_hd (&rio_real_driver, sizeof (rio_real_driver)); | ||
991 | } | ||
992 | |||
993 | |||
994 | func_exit(); | ||
995 | return 0; | ||
996 | |||
997 | free6:for (i--;i>=0;i--) | ||
998 | kfree (p->RIOPortp[i]); | ||
999 | /*free5: | ||
1000 | free4: | ||
1001 | free3:*/kfree (p->RIOPortp); | ||
1002 | free2:kfree (p->RIOHosts); | ||
1003 | free1: | ||
1004 | rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", | ||
1005 | p, p->RIOHosts, p->RIOPortp); | ||
1006 | kfree(p); | ||
1007 | free0: | ||
1008 | return -ENOMEM; | ||
1009 | } | ||
1010 | |||
1011 | static void __exit rio_release_drivers(void) | ||
1012 | { | ||
1013 | func_enter(); | ||
1014 | tty_unregister_driver(rio_driver2); | ||
1015 | tty_unregister_driver(rio_driver); | ||
1016 | put_tty_driver(rio_driver2); | ||
1017 | put_tty_driver(rio_driver); | ||
1018 | func_exit(); | ||
1019 | } | ||
1020 | |||
1021 | |||
1022 | #ifdef CONFIG_PCI | ||
1023 | /* This was written for SX, but applies to RIO too... | ||
1024 | (including bugs....) | ||
1025 | |||
1026 | There is another bit besides Bit 17. Turning that bit off | ||
1027 | (on boards shipped with the fix in the eeprom) results in a | ||
1028 | hang on the next access to the card. | ||
1029 | */ | ||
1030 | |||
1031 | /******************************************************** | ||
1032 | * Setting bit 17 in the CNTRL register of the PLX 9050 * | ||
1033 | * chip forces a retry on writes while a read is pending.* | ||
1034 | * This is to prevent the card locking up on Intel Xeon * | ||
1035 | * multiprocessor systems with the NX chipset. -- NV * | ||
1036 | ********************************************************/ | ||
1037 | |||
1038 | /* Newer cards are produced with this bit set from the configuration | ||
1039 | EEprom. As the bit is read/write for the CPU, we can fix it here, | ||
1040 | if we detect that it isn't set correctly. -- REW */ | ||
1041 | |||
1042 | static void fix_rio_pci (struct pci_dev *pdev) | ||
1043 | { | ||
1044 | unsigned int hwbase; | ||
1045 | unsigned long rebase; | ||
1046 | unsigned int t; | ||
1047 | |||
1048 | #define CNTRL_REG_OFFSET 0x50 | ||
1049 | #define CNTRL_REG_GOODVALUE 0x18260000 | ||
1050 | |||
1051 | pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); | ||
1052 | hwbase &= PCI_BASE_ADDRESS_MEM_MASK; | ||
1053 | rebase = (ulong) ioremap(hwbase, 0x80); | ||
1054 | t = readl (rebase + CNTRL_REG_OFFSET); | ||
1055 | if (t != CNTRL_REG_GOODVALUE) { | ||
1056 | printk (KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", | ||
1057 | t, CNTRL_REG_GOODVALUE); | ||
1058 | writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); | ||
1059 | } | ||
1060 | iounmap((char*) rebase); | ||
1061 | } | ||
1062 | #endif | ||
1063 | |||
1064 | |||
1065 | static int __init rio_init(void) | ||
1066 | { | ||
1067 | int found = 0; | ||
1068 | int i; | ||
1069 | struct Host *hp; | ||
1070 | int retval; | ||
1071 | struct vpd_prom *vpdp; | ||
1072 | int okboard; | ||
1073 | |||
1074 | #ifdef CONFIG_PCI | ||
1075 | struct pci_dev *pdev = NULL; | ||
1076 | unsigned int tint; | ||
1077 | unsigned short tshort; | ||
1078 | #endif | ||
1079 | |||
1080 | func_enter(); | ||
1081 | rio_dprintk (RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", | ||
1082 | rio_debug); | ||
1083 | |||
1084 | if (abs ((long) (&rio_debug) - rio_debug) < 0x10000) { | ||
1085 | printk (KERN_WARNING "rio: rio_debug is an address, instead of a value. " | ||
1086 | "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug); | ||
1087 | rio_debug=-1; | ||
1088 | } | ||
1089 | |||
1090 | if (misc_register(&rio_fw_device) < 0) { | ||
1091 | printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n"); | ||
1092 | return -EIO; | ||
1093 | } | ||
1094 | |||
1095 | retval = rio_init_datastructures (); | ||
1096 | if (retval < 0) { | ||
1097 | misc_deregister(&rio_fw_device); | ||
1098 | return retval; | ||
1099 | } | ||
1100 | |||
1101 | #ifdef CONFIG_PCI | ||
1102 | /* First look for the JET devices: */ | ||
1103 | while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, | ||
1104 | PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, | ||
1105 | pdev))) { | ||
1106 | if (pci_enable_device(pdev)) continue; | ||
1107 | |||
1108 | /* Specialix has a whole bunch of cards with | ||
1109 | 0x2000 as the device ID. They say its because | ||
1110 | the standard requires it. Stupid standard. */ | ||
1111 | /* It seems that reading a word doesn't work reliably on 2.0. | ||
1112 | Also, reading a non-aligned dword doesn't work. So we read the | ||
1113 | whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID) | ||
1114 | ourselves */ | ||
1115 | /* I don't know why the define doesn't work, constant 0x2c does --REW */ | ||
1116 | pci_read_config_dword (pdev, 0x2c, &tint); | ||
1117 | tshort = (tint >> 16) & 0xffff; | ||
1118 | rio_dprintk (RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint); | ||
1119 | if (tshort != 0x0100) { | ||
1120 | rio_dprintk (RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", | ||
1121 | tshort); | ||
1122 | continue; | ||
1123 | } | ||
1124 | rio_dprintk (RIO_DEBUG_PROBE, "cp1\n"); | ||
1125 | |||
1126 | pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint); | ||
1127 | |||
1128 | hp = &p->RIOHosts[p->RIONumHosts]; | ||
1129 | hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK; | ||
1130 | hp->Ivec = pdev->irq; | ||
1131 | if (((1 << hp->Ivec) & rio_irqmask) == 0) | ||
1132 | hp->Ivec = 0; | ||
1133 | hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); | ||
1134 | hp->CardP = (struct DpRam *) hp->Caddr; | ||
1135 | hp->Type = RIO_PCI; | ||
1136 | hp->Copy = rio_pcicopy; | ||
1137 | hp->Mode = RIO_PCI_BOOT_FROM_RAM; | ||
1138 | spin_lock_init(&hp->HostLock); | ||
1139 | rio_reset_interrupt (hp); | ||
1140 | rio_start_card_running (hp); | ||
1141 | |||
1142 | rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", | ||
1143 | (void *)p->RIOHosts[p->RIONumHosts].PaddrP, | ||
1144 | p->RIOHosts[p->RIONumHosts].Caddr); | ||
1145 | if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP, | ||
1146 | p->RIOHosts[p->RIONumHosts].Caddr, | ||
1147 | RIO_PCI, 0 ) == RIO_SUCCESS) { | ||
1148 | rio_dprintk (RIO_DEBUG_INIT, "Done RIOBoardTest\n"); | ||
1149 | WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff); | ||
1150 | p->RIOHosts[p->RIONumHosts].UniqueNum = | ||
1151 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)| | ||
1152 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)| | ||
1153 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)| | ||
1154 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24); | ||
1155 | rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", | ||
1156 | p->RIOHosts[p->RIONumHosts].UniqueNum); | ||
1157 | |||
1158 | fix_rio_pci (pdev); | ||
1159 | p->RIOLastPCISearch = RIO_SUCCESS; | ||
1160 | p->RIONumHosts++; | ||
1161 | found++; | ||
1162 | } else { | ||
1163 | iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr)); | ||
1164 | } | ||
1165 | } | ||
1166 | |||
1167 | /* Then look for the older PCI card.... : */ | ||
1168 | |||
1169 | /* These older PCI cards have problems (only byte-mode access is | ||
1170 | supported), which makes them a bit awkward to support. | ||
1171 | They also have problems sharing interrupts. Be careful. | ||
1172 | (The driver now refuses to share interrupts for these | ||
1173 | cards. This should be sufficient). | ||
1174 | */ | ||
1175 | |||
1176 | /* Then look for the older RIO/PCI devices: */ | ||
1177 | while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, | ||
1178 | PCI_DEVICE_ID_SPECIALIX_RIO, | ||
1179 | pdev))) { | ||
1180 | if (pci_enable_device(pdev)) continue; | ||
1181 | |||
1182 | #ifdef CONFIG_RIO_OLDPCI | ||
1183 | pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint); | ||
1184 | |||
1185 | hp = &p->RIOHosts[p->RIONumHosts]; | ||
1186 | hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK; | ||
1187 | hp->Ivec = pdev->irq; | ||
1188 | if (((1 << hp->Ivec) & rio_irqmask) == 0) | ||
1189 | hp->Ivec = 0; | ||
1190 | hp->Ivec |= 0x8000; /* Mark as non-sharable */ | ||
1191 | hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); | ||
1192 | hp->CardP = (struct DpRam *) hp->Caddr; | ||
1193 | hp->Type = RIO_PCI; | ||
1194 | hp->Copy = rio_pcicopy; | ||
1195 | hp->Mode = RIO_PCI_BOOT_FROM_RAM; | ||
1196 | spin_lock_init(&hp->HostLock); | ||
1197 | |||
1198 | rio_dprintk (RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec); | ||
1199 | rio_dprintk (RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode); | ||
1200 | |||
1201 | rio_reset_interrupt (hp); | ||
1202 | rio_start_card_running (hp); | ||
1203 | rio_dprintk (RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", | ||
1204 | (void *)p->RIOHosts[p->RIONumHosts].PaddrP, | ||
1205 | p->RIOHosts[p->RIONumHosts].Caddr); | ||
1206 | if (RIOBoardTest( p->RIOHosts[p->RIONumHosts].PaddrP, | ||
1207 | p->RIOHosts[p->RIONumHosts].Caddr, | ||
1208 | RIO_PCI, 0 ) == RIO_SUCCESS) { | ||
1209 | WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff); | ||
1210 | p->RIOHosts[p->RIONumHosts].UniqueNum = | ||
1211 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) &0xFF)<< 0)| | ||
1212 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) &0xFF)<< 8)| | ||
1213 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) &0xFF)<<16)| | ||
1214 | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) &0xFF)<<24); | ||
1215 | rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", | ||
1216 | p->RIOHosts[p->RIONumHosts].UniqueNum); | ||
1217 | |||
1218 | p->RIOLastPCISearch = RIO_SUCCESS; | ||
1219 | p->RIONumHosts++; | ||
1220 | found++; | ||
1221 | } else { | ||
1222 | iounmap((char*) (p->RIOHosts[p->RIONumHosts].Caddr)); | ||
1223 | } | ||
1224 | #else | ||
1225 | printk (KERN_ERR "Found an older RIO PCI card, but the driver is not " | ||
1226 | "compiled to support it.\n"); | ||
1227 | #endif | ||
1228 | } | ||
1229 | #endif /* PCI */ | ||
1230 | |||
1231 | /* Now probe for ISA cards... */ | ||
1232 | for (i=0;i<NR_RIO_ADDRS;i++) { | ||
1233 | hp = &p->RIOHosts[p->RIONumHosts]; | ||
1234 | hp->PaddrP = rio_probe_addrs[i]; | ||
1235 | /* There was something about the IRQs of these cards. 'Forget what.--REW */ | ||
1236 | hp->Ivec = 0; | ||
1237 | hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); | ||
1238 | hp->CardP = (struct DpRam *) hp->Caddr; | ||
1239 | hp->Type = RIO_AT; | ||
1240 | hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL | ||
1241 | * -- YES! this is now a normal copy. Only the | ||
1242 | * old PCI card uses the special PCI copy. | ||
1243 | * Moreover, the ISA card will work with the | ||
1244 | * special PCI copy anyway. -- REW */ | ||
1245 | hp->Mode = 0; | ||
1246 | spin_lock_init(&hp->HostLock); | ||
1247 | |||
1248 | vpdp = get_VPD_PROM (hp); | ||
1249 | rio_dprintk (RIO_DEBUG_PROBE, "Got VPD ROM\n"); | ||
1250 | okboard = 0; | ||
1251 | if ((strncmp (vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || | ||
1252 | (strncmp (vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || | ||
1253 | (strncmp (vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) { | ||
1254 | /* Board is present... */ | ||
1255 | if (RIOBoardTest (hp->PaddrP, | ||
1256 | hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) { | ||
1257 | /* ... and feeling fine!!!! */ | ||
1258 | rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", | ||
1259 | p->RIOHosts[p->RIONumHosts].UniqueNum); | ||
1260 | if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) { | ||
1261 | rio_dprintk (RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", | ||
1262 | p->RIONumHosts, | ||
1263 | p->RIOHosts[p->RIONumHosts-1].UniqueNum); | ||
1264 | okboard++; | ||
1265 | found++; | ||
1266 | } | ||
1267 | } | ||
1268 | |||
1269 | if (!okboard) | ||
1270 | iounmap ((char*) (hp->Caddr)); | ||
1271 | } | ||
1272 | } | ||
1273 | |||
1274 | |||
1275 | for (i=0;i<p->RIONumHosts;i++) { | ||
1276 | hp = &p->RIOHosts[i]; | ||
1277 | if (hp->Ivec) { | ||
1278 | int mode = SA_SHIRQ; | ||
1279 | if (hp->Ivec & 0x8000) {mode = 0; hp->Ivec &= 0x7fff;} | ||
1280 | rio_dprintk (RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp,hp->Ivec, hp->Mode); | ||
1281 | retval = request_irq (hp->Ivec, rio_interrupt, mode, "rio", hp); | ||
1282 | rio_dprintk (RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval); | ||
1283 | if (retval) { | ||
1284 | printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec); | ||
1285 | hp->Ivec = 0; | ||
1286 | } | ||
1287 | rio_dprintk (RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec); | ||
1288 | if (hp->Ivec != 0){ | ||
1289 | rio_dprintk (RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); | ||
1290 | hp->Mode |= RIO_PCI_INT_ENABLE; | ||
1291 | } else | ||
1292 | hp->Mode &= !RIO_PCI_INT_ENABLE; | ||
1293 | rio_dprintk (RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode); | ||
1294 | rio_start_card_running (hp); | ||
1295 | } | ||
1296 | /* Init the timer "always" to make sure that it can safely be | ||
1297 | deleted when we unload... */ | ||
1298 | |||
1299 | init_timer (&hp->timer); | ||
1300 | if (!hp->Ivec) { | ||
1301 | rio_dprintk (RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", | ||
1302 | rio_poll); | ||
1303 | hp->timer.data = i; | ||
1304 | hp->timer.function = rio_pollfunc; | ||
1305 | hp->timer.expires = jiffies + rio_poll; | ||
1306 | add_timer (&hp->timer); | ||
1307 | } | ||
1308 | } | ||
1309 | |||
1310 | if (found) { | ||
1311 | rio_dprintk (RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found); | ||
1312 | rio_init_drivers (); | ||
1313 | } else { | ||
1314 | /* deregister the misc device we created earlier */ | ||
1315 | misc_deregister(&rio_fw_device); | ||
1316 | } | ||
1317 | |||
1318 | func_exit(); | ||
1319 | return found?0:-EIO; | ||
1320 | } | ||
1321 | |||
1322 | |||
1323 | static void __exit rio_exit (void) | ||
1324 | { | ||
1325 | int i; | ||
1326 | struct Host *hp; | ||
1327 | |||
1328 | func_enter(); | ||
1329 | |||
1330 | for (i=0,hp=p->RIOHosts;i<p->RIONumHosts;i++, hp++) { | ||
1331 | RIOHostReset (hp->Type, hp->CardP, hp->Slot); | ||
1332 | if (hp->Ivec) { | ||
1333 | free_irq (hp->Ivec, hp); | ||
1334 | rio_dprintk (RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec); | ||
1335 | } | ||
1336 | /* It is safe/allowed to del_timer a non-active timer */ | ||
1337 | del_timer (&hp->timer); | ||
1338 | } | ||
1339 | |||
1340 | if (misc_deregister(&rio_fw_device) < 0) { | ||
1341 | printk (KERN_INFO "rio: couldn't deregister control-device\n"); | ||
1342 | } | ||
1343 | |||
1344 | |||
1345 | rio_dprintk (RIO_DEBUG_CLEANUP, "Cleaning up drivers\n"); | ||
1346 | |||
1347 | rio_release_drivers (); | ||
1348 | |||
1349 | /* Release dynamically allocated memory */ | ||
1350 | kfree (p->RIOPortp); | ||
1351 | kfree (p->RIOHosts); | ||
1352 | kfree (p); | ||
1353 | |||
1354 | func_exit(); | ||
1355 | } | ||
1356 | |||
1357 | module_init(rio_init); | ||
1358 | module_exit(rio_exit); | ||
1359 | |||
1360 | /* | ||
1361 | * Anybody who knows why this doesn't work for me, please tell me -- REW. | ||
1362 | * Snatched from scsi.c (fixed one spelling error): | ||
1363 | * Overrides for Emacs so that we follow Linus' tabbing style. | ||
1364 | * Emacs will notice this stuff at the end of the file and automatically | ||
1365 | * adjust the settings for this buffer only. This must remain at the end | ||
1366 | * of the file. | ||
1367 | * --------------------------------------------------------------------------- | ||
1368 | * Local Variables: | ||
1369 | * c-indent-level: 4 | ||
1370 | * c-brace-imaginary-offset: 0 | ||
1371 | * c-brace-offset: -4 | ||
1372 | * c-argdecl-indent: 4 | ||
1373 | * c-label-offset: -4 | ||
1374 | * c-continued-statement-offset: 4 | ||
1375 | * c-continued-brace-offset: 0 | ||
1376 | * indent-tabs-mode: nil | ||
1377 | * tab-width: 8 | ||
1378 | * End: | ||
1379 | */ | ||
1380 | |||