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