ia64/linux-2.6.18-xen.hg

annotate drivers/char/rio/rio_linux.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

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