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