Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 2 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) |
| 3 | * Copyrifht (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Mostly written by Mark Lord <mlord@pobox.com> |
| 8 | * and Gadi Oxman <gadio@netvision.net.il> |
| 9 | * and Andre Hedrick <andre@linux-ide.org> |
| 10 | * |
| 11 | * See linux/MAINTAINERS for address of current maintainer. |
| 12 | * |
| 13 | * This is the multiple IDE interface driver, as evolved from hd.c. |
| 14 | * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs |
| 15 | * (usually 14 & 15). |
| 16 | * There can be up to two drives per interface, as per the ATA-2 spec. |
| 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * ... |
| 19 | * |
| 20 | * From hd.c: |
| 21 | * | |
| 22 | * | It traverses the request-list, using interrupts to jump between functions. |
| 23 | * | As nearly all functions can be called within interrupts, we may not sleep. |
| 24 | * | Special care is recommended. Have Fun! |
| 25 | * | |
| 26 | * | modified by Drew Eckhardt to check nr of hd's from the CMOS. |
| 27 | * | |
| 28 | * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug |
| 29 | * | in the early extended-partition checks and added DM partitions. |
| 30 | * | |
| 31 | * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI). |
| 32 | * | |
| 33 | * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads", |
| 34 | * | and general streamlining by Mark Lord (mlord@pobox.com). |
| 35 | * |
| 36 | * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by: |
| 37 | * |
| 38 | * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg) |
| 39 | * Delman Lee (delman@ieee.org) ("Mr. atdisk2") |
| 40 | * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom) |
| 41 | * |
| 42 | * This was a rewrite of just about everything from hd.c, though some original |
| 43 | * code is still sprinkled about. Think of it as a major evolution, with |
| 44 | * inspiration from lots of linux users, esp. hamish@zot.apana.org.au |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | */ |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define _IDE_C /* Tell ide.h it's really us */ |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/module.h> |
| 50 | #include <linux/types.h> |
| 51 | #include <linux/string.h> |
| 52 | #include <linux/kernel.h> |
| 53 | #include <linux/timer.h> |
| 54 | #include <linux/mm.h> |
| 55 | #include <linux/interrupt.h> |
| 56 | #include <linux/major.h> |
| 57 | #include <linux/errno.h> |
| 58 | #include <linux/genhd.h> |
| 59 | #include <linux/blkpg.h> |
| 60 | #include <linux/slab.h> |
| 61 | #include <linux/init.h> |
| 62 | #include <linux/pci.h> |
| 63 | #include <linux/delay.h> |
| 64 | #include <linux/ide.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <linux/completion.h> |
| 66 | #include <linux/reboot.h> |
| 67 | #include <linux/cdrom.h> |
| 68 | #include <linux/seq_file.h> |
| 69 | #include <linux/device.h> |
| 70 | #include <linux/bitops.h> |
| 71 | |
| 72 | #include <asm/byteorder.h> |
| 73 | #include <asm/irq.h> |
| 74 | #include <asm/uaccess.h> |
| 75 | #include <asm/io.h> |
| 76 | |
| 77 | |
| 78 | /* default maximum number of failures */ |
| 79 | #define IDE_DEFAULT_MAX_FAILURES 1 |
| 80 | |
Bartlomiej Zolnierkiewicz | f74c914 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 81 | struct class *ide_port_class; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR, |
| 84 | IDE2_MAJOR, IDE3_MAJOR, |
| 85 | IDE4_MAJOR, IDE5_MAJOR, |
| 86 | IDE6_MAJOR, IDE7_MAJOR, |
| 87 | IDE8_MAJOR, IDE9_MAJOR }; |
| 88 | |
| 89 | static int idebus_parameter; /* holds the "idebus=" parameter */ |
| 90 | static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Matthias Kaehlcke | ef29888 | 2007-07-09 23:17:55 +0200 | [diff] [blame] | 92 | DEFINE_MUTEX(ide_cfg_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock); |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | int noautodma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 97 | #ifdef CONFIG_BLK_DEV_IDEACPI |
| 98 | int ide_noacpi = 0; |
| 99 | int ide_noacpitfs = 1; |
| 100 | int ide_noacpionboot = 1; |
| 101 | #endif |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* |
| 104 | * This is declared extern in ide.h, for access by other IDE modules: |
| 105 | */ |
| 106 | ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */ |
| 107 | |
| 108 | EXPORT_SYMBOL(ide_hwifs); |
| 109 | |
Bartlomiej Zolnierkiewicz | 43514ed | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 110 | static void ide_port_init_devices_data(ide_hwif_t *); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Do not even *think* about calling this! |
| 114 | */ |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 115 | void ide_init_port_data(ide_hwif_t *hwif, unsigned int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* bulk initialize hwif & drive info with zeros */ |
| 118 | memset(hwif, 0, sizeof(ide_hwif_t)); |
| 119 | |
| 120 | /* fill in any non-zero initial values */ |
| 121 | hwif->index = index; |
| 122 | hwif->major = ide_hwif_to_major[index]; |
| 123 | |
| 124 | hwif->name[0] = 'i'; |
| 125 | hwif->name[1] = 'd'; |
| 126 | hwif->name[2] = 'e'; |
| 127 | hwif->name[3] = '0' + index; |
| 128 | |
| 129 | hwif->bus_state = BUSSTATE_ON; |
| 130 | |
Aleksey Makarov | f36d402 | 2006-01-09 15:59:27 -0800 | [diff] [blame] | 131 | init_completion(&hwif->gendev_rel_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | default_hwif_iops(hwif); |
| 134 | default_hwif_transport(hwif); |
Bartlomiej Zolnierkiewicz | 43514ed | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 135 | |
| 136 | ide_port_init_devices_data(hwif); |
| 137 | } |
| 138 | EXPORT_SYMBOL_GPL(ide_init_port_data); |
| 139 | |
| 140 | static void ide_port_init_devices_data(ide_hwif_t *hwif) |
| 141 | { |
| 142 | int unit; |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | for (unit = 0; unit < MAX_DRIVES; ++unit) { |
| 145 | ide_drive_t *drive = &hwif->drives[unit]; |
Bartlomiej Zolnierkiewicz | 43514ed | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 146 | u8 j = (hwif->index * MAX_DRIVES) + unit; |
| 147 | |
| 148 | memset(drive, 0, sizeof(*drive)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | drive->media = ide_disk; |
| 151 | drive->select.all = (unit<<4)|0xa0; |
| 152 | drive->hwif = hwif; |
| 153 | drive->ctl = 0x08; |
| 154 | drive->ready_stat = READY_STAT; |
| 155 | drive->bad_wstat = BAD_W_STAT; |
| 156 | drive->special.b.recalibrate = 1; |
| 157 | drive->special.b.set_geometry = 1; |
| 158 | drive->name[0] = 'h'; |
| 159 | drive->name[1] = 'd'; |
Bartlomiej Zolnierkiewicz | 43514ed | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 160 | drive->name[2] = 'a' + j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | drive->max_failures = IDE_DEFAULT_MAX_FAILURES; |
Bartlomiej Zolnierkiewicz | 43514ed | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | INIT_LIST_HEAD(&drive->list); |
Aleksey Makarov | f36d402 | 2006-01-09 15:59:27 -0800 | [diff] [blame] | 164 | init_completion(&drive->gendev_rel_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
Bartlomiej Zolnierkiewicz | 43514ed | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
| 169 | * init_ide_data() sets reasonable default values into all fields |
| 170 | * of all instances of the hwifs and drives, but only on the first call. |
| 171 | * Subsequent calls have no effect (they don't wipe out anything). |
| 172 | * |
| 173 | * This routine is normally called at driver initialization time, |
| 174 | * but may also be called MUCH earlier during kernel "command-line" |
| 175 | * parameter processing. As such, we cannot depend on any other parts |
| 176 | * of the kernel (such as memory allocation) to be functioning yet. |
| 177 | * |
| 178 | * This is too bad, as otherwise we could dynamically allocate the |
| 179 | * ide_drive_t structs as needed, rather than always consuming memory |
| 180 | * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them. |
| 181 | * |
| 182 | * FIXME: We should stuff the setup data into __init and copy the |
| 183 | * relevant hwifs/allocate them properly during boot. |
| 184 | */ |
| 185 | #define MAGIC_COOKIE 0x12345678 |
| 186 | static void __init init_ide_data (void) |
| 187 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | unsigned int index; |
| 189 | static unsigned long magic_cookie = MAGIC_COOKIE; |
| 190 | |
| 191 | if (magic_cookie != MAGIC_COOKIE) |
| 192 | return; /* already initialized */ |
| 193 | magic_cookie = 0; |
| 194 | |
| 195 | /* Initialise all interface structures */ |
| 196 | for (index = 0; index < MAX_HWIFS; ++index) { |
Bartlomiej Zolnierkiewicz | 0573426 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 197 | ide_hwif_t *hwif = &ide_hwifs[index]; |
| 198 | |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 199 | ide_init_port_data(hwif, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
| 204 | * ide_system_bus_speed - guess bus speed |
| 205 | * |
| 206 | * ide_system_bus_speed() returns what we think is the system VESA/PCI |
| 207 | * bus speed (in MHz). This is used for calculating interface PIO timings. |
| 208 | * The default is 40 for known PCI systems, 50 otherwise. |
| 209 | * The "idebus=xx" parameter can be used to override this value. |
| 210 | * The actual value to be used is computed/displayed the first time |
| 211 | * through. Drivers should only use this as a last resort. |
| 212 | * |
| 213 | * Returns a guessed speed in MHz. |
| 214 | */ |
| 215 | |
| 216 | static int ide_system_bus_speed(void) |
| 217 | { |
| 218 | #ifdef CONFIG_PCI |
| 219 | static struct pci_device_id pci_default[] = { |
| 220 | { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) }, |
| 221 | { } |
| 222 | }; |
| 223 | #else |
| 224 | #define pci_default 0 |
| 225 | #endif /* CONFIG_PCI */ |
| 226 | |
Bartlomiej Zolnierkiewicz | 537f06c | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 227 | /* user supplied value */ |
| 228 | if (idebus_parameter) |
| 229 | return idebus_parameter; |
| 230 | |
| 231 | /* safe default value for PCI or VESA and PCI*/ |
| 232 | return pci_dev_present(pci_default) ? 33 : 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Bartlomiej Zolnierkiewicz | baa8f3e | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 235 | ide_hwif_t * ide_find_port(unsigned long base) |
| 236 | { |
| 237 | ide_hwif_t *hwif; |
| 238 | int i; |
| 239 | |
| 240 | for (i = 0; i < MAX_HWIFS; i++) { |
| 241 | hwif = &ide_hwifs[i]; |
| 242 | if (hwif->io_ports[IDE_DATA_OFFSET] == base) |
| 243 | goto found; |
| 244 | } |
| 245 | |
| 246 | for (i = 0; i < MAX_HWIFS; i++) { |
| 247 | hwif = &ide_hwifs[i]; |
Bartlomiej Zolnierkiewicz | 2625cd5 | 2008-04-18 00:46:21 +0200 | [diff] [blame] | 248 | if (hwif->chipset == ide_unknown) |
Bartlomiej Zolnierkiewicz | baa8f3e | 2007-10-20 00:32:31 +0200 | [diff] [blame] | 249 | goto found; |
| 250 | } |
| 251 | |
| 252 | hwif = NULL; |
| 253 | found: |
| 254 | return hwif; |
| 255 | } |
| 256 | |
| 257 | EXPORT_SYMBOL_GPL(ide_find_port); |
| 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | static struct resource* hwif_request_region(ide_hwif_t *hwif, |
| 260 | unsigned long addr, int num) |
| 261 | { |
| 262 | struct resource *res = request_region(addr, num, hwif->name); |
| 263 | |
| 264 | if (!res) |
| 265 | printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n", |
| 266 | hwif->name, addr, addr+num-1); |
| 267 | return res; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * ide_hwif_request_regions - request resources for IDE |
| 272 | * @hwif: interface to use |
| 273 | * |
| 274 | * Requests all the needed resources for an interface. |
| 275 | * Right now core IDE code does this work which is deeply wrong. |
| 276 | * MMIO leaves it to the controller driver, |
| 277 | * PIO will migrate this way over time. |
| 278 | */ |
| 279 | |
| 280 | int ide_hwif_request_regions(ide_hwif_t *hwif) |
| 281 | { |
| 282 | unsigned long addr; |
| 283 | unsigned int i; |
| 284 | |
Bartlomiej Zolnierkiewicz | 2ad1e55 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 285 | if (hwif->mmio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | addr = hwif->io_ports[IDE_CONTROL_OFFSET]; |
| 288 | if (addr && !hwif_request_region(hwif, addr, 1)) |
| 289 | goto control_region_busy; |
| 290 | hwif->straight8 = 0; |
| 291 | addr = hwif->io_ports[IDE_DATA_OFFSET]; |
| 292 | if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) { |
| 293 | if (!hwif_request_region(hwif, addr, 8)) |
| 294 | goto data_region_busy; |
| 295 | hwif->straight8 = 1; |
| 296 | return 0; |
| 297 | } |
| 298 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { |
| 299 | addr = hwif->io_ports[i]; |
| 300 | if (!hwif_request_region(hwif, addr, 1)) { |
| 301 | while (--i) |
| 302 | release_region(addr, 1); |
| 303 | goto data_region_busy; |
| 304 | } |
| 305 | } |
| 306 | return 0; |
| 307 | |
| 308 | data_region_busy: |
| 309 | addr = hwif->io_ports[IDE_CONTROL_OFFSET]; |
| 310 | if (addr) |
| 311 | release_region(addr, 1); |
| 312 | control_region_busy: |
| 313 | /* If any errors are return, we drop the hwif interface. */ |
| 314 | return -EBUSY; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * ide_hwif_release_regions - free IDE resources |
| 319 | * |
| 320 | * Note that we only release the standard ports, |
| 321 | * and do not even try to handle any extra ports |
| 322 | * allocated for weird IDE interface chipsets. |
| 323 | * |
| 324 | * Note also that we don't yet handle mmio resources here. More |
| 325 | * importantly our caller should be doing this so we need to |
| 326 | * restructure this as a helper function for drivers. |
| 327 | */ |
| 328 | |
| 329 | void ide_hwif_release_regions(ide_hwif_t *hwif) |
| 330 | { |
| 331 | u32 i = 0; |
| 332 | |
Bartlomiej Zolnierkiewicz | 2ad1e55 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 333 | if (hwif->mmio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | return; |
| 335 | if (hwif->io_ports[IDE_CONTROL_OFFSET]) |
| 336 | release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1); |
| 337 | if (hwif->straight8) { |
| 338 | release_region(hwif->io_ports[IDE_DATA_OFFSET], 8); |
| 339 | return; |
| 340 | } |
| 341 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) |
| 342 | if (hwif->io_ports[i]) |
| 343 | release_region(hwif->io_ports[i], 1); |
| 344 | } |
| 345 | |
Bartlomiej Zolnierkiewicz | fbd1308 | 2008-02-01 23:09:36 +0100 | [diff] [blame] | 346 | void ide_remove_port_from_hwgroup(ide_hwif_t *hwif) |
Bartlomiej Zolnierkiewicz | 96e5ad3 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 347 | { |
| 348 | ide_hwgroup_t *hwgroup = hwif->hwgroup; |
| 349 | |
| 350 | spin_lock_irq(&ide_lock); |
| 351 | /* |
| 352 | * Remove us from the hwgroup, and free |
| 353 | * the hwgroup if we were the only member |
| 354 | */ |
| 355 | if (hwif->next == hwif) { |
| 356 | BUG_ON(hwgroup->hwif != hwif); |
| 357 | kfree(hwgroup); |
| 358 | } else { |
| 359 | /* There is another interface in hwgroup. |
| 360 | * Unlink us, and set hwgroup->drive and ->hwif to |
| 361 | * something sane. |
| 362 | */ |
| 363 | ide_hwif_t *g = hwgroup->hwif; |
| 364 | |
| 365 | while (g->next != hwif) |
| 366 | g = g->next; |
| 367 | g->next = hwif->next; |
| 368 | if (hwgroup->hwif == hwif) { |
| 369 | /* Chose a random hwif for hwgroup->hwif. |
| 370 | * It's guaranteed that there are no drives |
| 371 | * left in the hwgroup. |
| 372 | */ |
| 373 | BUG_ON(hwgroup->drive != NULL); |
| 374 | hwgroup->hwif = g; |
| 375 | } |
| 376 | BUG_ON(hwgroup->hwif == hwif); |
| 377 | } |
| 378 | spin_unlock_irq(&ide_lock); |
| 379 | } |
| 380 | |
Bartlomiej Zolnierkiewicz | 71bf9f6 | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 381 | /* Called with ide_lock held. */ |
Bartlomiej Zolnierkiewicz | 2dde786 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 382 | static void __ide_port_unregister_devices(ide_hwif_t *hwif) |
Bartlomiej Zolnierkiewicz | 71bf9f6 | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 383 | { |
| 384 | int i; |
| 385 | |
| 386 | for (i = 0; i < MAX_DRIVES; i++) { |
| 387 | ide_drive_t *drive = &hwif->drives[i]; |
| 388 | |
| 389 | if (drive->present) { |
| 390 | spin_unlock_irq(&ide_lock); |
| 391 | device_unregister(&drive->gendev); |
| 392 | wait_for_completion(&drive->gendev_rel_comp); |
| 393 | spin_lock_irq(&ide_lock); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
Bartlomiej Zolnierkiewicz | 2dde786 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 398 | void ide_port_unregister_devices(ide_hwif_t *hwif) |
| 399 | { |
| 400 | mutex_lock(&ide_cfg_mtx); |
| 401 | spin_lock_irq(&ide_lock); |
| 402 | __ide_port_unregister_devices(hwif); |
| 403 | hwif->present = 0; |
| 404 | ide_port_init_devices_data(hwif); |
| 405 | spin_unlock_irq(&ide_lock); |
| 406 | mutex_unlock(&ide_cfg_mtx); |
| 407 | } |
| 408 | EXPORT_SYMBOL_GPL(ide_port_unregister_devices); |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /** |
Sergei Shtylylov | 020e322 | 2006-10-03 01:14:13 -0700 | [diff] [blame] | 411 | * ide_unregister - free an IDE interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | * @index: index of interface (will change soon to a pointer) |
| 413 | * |
| 414 | * Perform the final unregister of an IDE interface. At the moment |
| 415 | * we don't refcount interfaces so this will also get split up. |
| 416 | * |
| 417 | * Locking: |
| 418 | * The caller must not hold the IDE locks |
| 419 | * The drive present/vanishing is not yet properly locked |
| 420 | * Take care with the callbacks. These have been split to avoid |
| 421 | * deadlocking the IDE layer. The shutdown callback is called |
| 422 | * before we take the lock and free resources. It is up to the |
| 423 | * caller to be sure there is no pending I/O here, and that |
Sergei Shtylylov | 020e322 | 2006-10-03 01:14:13 -0700 | [diff] [blame] | 424 | * the interface will not be reopened (present/vanishing locking |
| 425 | * isn't yet done BTW). After we commit to the final kill we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | * call the cleanup callback with the ide locks held. |
| 427 | * |
| 428 | * Unregister restores the hwif structures to the default state. |
| 429 | * This is raving bonkers. |
| 430 | */ |
| 431 | |
Bartlomiej Zolnierkiewicz | 93de00f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 432 | void ide_unregister(unsigned int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | ide_hwif_t *hwif, *g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | ide_hwgroup_t *hwgroup; |
Bartlomiej Zolnierkiewicz | 71bf9f6 | 2008-04-18 00:46:22 +0200 | [diff] [blame] | 436 | int irq_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | BUG_ON(index >= MAX_HWIFS); |
| 439 | |
| 440 | BUG_ON(in_interrupt()); |
| 441 | BUG_ON(irqs_disabled()); |
Matthias Kaehlcke | ef29888 | 2007-07-09 23:17:55 +0200 | [diff] [blame] | 442 | mutex_lock(&ide_cfg_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | spin_lock_irq(&ide_lock); |
| 444 | hwif = &ide_hwifs[index]; |
| 445 | if (!hwif->present) |
| 446 | goto abort; |
Bartlomiej Zolnierkiewicz | 2dde786 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 447 | __ide_port_unregister_devices(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | hwif->present = 0; |
| 449 | |
| 450 | spin_unlock_irq(&ide_lock); |
| 451 | |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 452 | ide_proc_unregister_port(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
| 454 | hwgroup = hwif->hwgroup; |
| 455 | /* |
| 456 | * free the irq if we were the only hwif using it |
| 457 | */ |
| 458 | g = hwgroup->hwif; |
| 459 | do { |
| 460 | if (g->irq == hwif->irq) |
| 461 | ++irq_count; |
| 462 | g = g->next; |
| 463 | } while (g != hwgroup->hwif); |
| 464 | if (irq_count == 1) |
| 465 | free_irq(hwif->irq, hwgroup); |
| 466 | |
Bartlomiej Zolnierkiewicz | 96e5ad3 | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 467 | ide_remove_port_from_hwgroup(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Bartlomiej Zolnierkiewicz | f74c914 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 469 | device_unregister(hwif->portdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | device_unregister(&hwif->gendev); |
Aleksey Makarov | f36d402 | 2006-01-09 15:59:27 -0800 | [diff] [blame] | 471 | wait_for_completion(&hwif->gendev_rel_comp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * Remove us from the kernel's knowledge |
| 475 | */ |
| 476 | blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS); |
| 477 | kfree(hwif->sg_table); |
| 478 | unregister_blkdev(hwif->major, hwif->name); |
| 479 | spin_lock_irq(&ide_lock); |
| 480 | |
Bartlomiej Zolnierkiewicz | 93de00f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 481 | if (hwif->dma_base) |
| 482 | (void)ide_release_dma(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Bartlomiej Zolnierkiewicz | 7cba97f | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 484 | ide_hwif_release_regions(hwif); |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | /* restore hwif data to pristine status */ |
Bartlomiej Zolnierkiewicz | cbb010c | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 487 | ide_init_port_data(hwif, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | abort: |
| 490 | spin_unlock_irq(&ide_lock); |
Matthias Kaehlcke | ef29888 | 2007-07-09 23:17:55 +0200 | [diff] [blame] | 491 | mutex_unlock(&ide_cfg_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | EXPORT_SYMBOL(ide_unregister); |
| 495 | |
Bartlomiej Zolnierkiewicz | 57c802e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 496 | void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) |
| 497 | { |
| 498 | memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports)); |
| 499 | hwif->irq = hw->irq; |
| 500 | hwif->noprobe = 0; |
| 501 | hwif->chipset = hw->chipset; |
| 502 | hwif->gendev.parent = hw->dev; |
| 503 | hwif->ack_intr = hw->ack_intr; |
| 504 | } |
| 505 | EXPORT_SYMBOL_GPL(ide_init_port_hw); |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* |
| 508 | * Locks for IDE setting functionality |
| 509 | */ |
| 510 | |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 511 | DEFINE_MUTEX(ide_setting_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 513 | EXPORT_SYMBOL_GPL(ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | * ide_spin_wait_hwgroup - wait for group |
| 517 | * @drive: drive in the group |
| 518 | * |
| 519 | * Wait for an IDE device group to go non busy and then return |
| 520 | * holding the ide_lock which guards the hwgroup->busy status |
| 521 | * and right to use it. |
| 522 | */ |
| 523 | |
| 524 | int ide_spin_wait_hwgroup (ide_drive_t *drive) |
| 525 | { |
| 526 | ide_hwgroup_t *hwgroup = HWGROUP(drive); |
| 527 | unsigned long timeout = jiffies + (3 * HZ); |
| 528 | |
| 529 | spin_lock_irq(&ide_lock); |
| 530 | |
| 531 | while (hwgroup->busy) { |
| 532 | unsigned long lflags; |
| 533 | spin_unlock_irq(&ide_lock); |
| 534 | local_irq_set(lflags); |
| 535 | if (time_after(jiffies, timeout)) { |
| 536 | local_irq_restore(lflags); |
| 537 | printk(KERN_ERR "%s: channel busy\n", drive->name); |
| 538 | return -EBUSY; |
| 539 | } |
| 540 | local_irq_restore(lflags); |
| 541 | spin_lock_irq(&ide_lock); |
| 542 | } |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | EXPORT_SYMBOL(ide_spin_wait_hwgroup); |
| 547 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 548 | int set_io_32bit(ide_drive_t *drive, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 550 | if (drive->no_io_32bit) |
| 551 | return -EPERM; |
| 552 | |
| 553 | if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) |
| 554 | return -EINVAL; |
| 555 | |
Bartlomiej Zolnierkiewicz | 644a9d7 | 2007-12-12 23:32:00 +0100 | [diff] [blame] | 556 | if (ide_spin_wait_hwgroup(drive)) |
| 557 | return -EBUSY; |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | drive->io_32bit = arg; |
Bartlomiej Zolnierkiewicz | 644a9d7 | 2007-12-12 23:32:00 +0100 | [diff] [blame] | 560 | |
| 561 | spin_unlock_irq(&ide_lock); |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return 0; |
| 564 | } |
| 565 | |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 566 | static int set_ksettings(ide_drive_t *drive, int arg) |
| 567 | { |
| 568 | if (arg < 0 || arg > 1) |
| 569 | return -EINVAL; |
| 570 | |
| 571 | if (ide_spin_wait_hwgroup(drive)) |
| 572 | return -EBUSY; |
| 573 | drive->keep_settings = arg; |
| 574 | spin_unlock_irq(&ide_lock); |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 579 | int set_using_dma(ide_drive_t *drive, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
| 581 | #ifdef CONFIG_BLK_DEV_IDEDMA |
Bartlomiej Zolnierkiewicz | 8799620 | 2007-03-26 23:03:19 +0200 | [diff] [blame] | 582 | ide_hwif_t *hwif = drive->hwif; |
| 583 | int err = -EPERM; |
| 584 | |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 585 | if (arg < 0 || arg > 1) |
| 586 | return -EINVAL; |
| 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | if (!drive->id || !(drive->id->capability & 1)) |
Bartlomiej Zolnierkiewicz | 8799620 | 2007-03-26 23:03:19 +0200 | [diff] [blame] | 589 | goto out; |
| 590 | |
Bartlomiej Zolnierkiewicz | 15ce926 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 591 | if (hwif->dma_host_set == NULL) |
Bartlomiej Zolnierkiewicz | 8799620 | 2007-03-26 23:03:19 +0200 | [diff] [blame] | 592 | goto out; |
| 593 | |
| 594 | err = -EBUSY; |
| 595 | if (ide_spin_wait_hwgroup(drive)) |
| 596 | goto out; |
| 597 | /* |
| 598 | * set ->busy flag, unlock and let it ride |
| 599 | */ |
| 600 | hwif->hwgroup->busy = 1; |
| 601 | spin_unlock_irq(&ide_lock); |
| 602 | |
| 603 | err = 0; |
| 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | if (arg) { |
Bartlomiej Zolnierkiewicz | 23b1bd4 | 2008-01-25 22:17:19 +0100 | [diff] [blame] | 606 | if (ide_set_dma(drive)) |
Bartlomiej Zolnierkiewicz | 8799620 | 2007-03-26 23:03:19 +0200 | [diff] [blame] | 607 | err = -EIO; |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 608 | } else |
| 609 | ide_dma_off(drive); |
Bartlomiej Zolnierkiewicz | 8799620 | 2007-03-26 23:03:19 +0200 | [diff] [blame] | 610 | |
| 611 | /* |
| 612 | * lock, clear ->busy flag and unlock before leaving |
| 613 | */ |
| 614 | spin_lock_irq(&ide_lock); |
| 615 | hwif->hwgroup->busy = 0; |
| 616 | spin_unlock_irq(&ide_lock); |
| 617 | out: |
| 618 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #else |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 620 | if (arg < 0 || arg > 1) |
| 621 | return -EINVAL; |
| 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return -EPERM; |
| 624 | #endif |
| 625 | } |
| 626 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 627 | int set_pio_mode(ide_drive_t *drive, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
| 629 | struct request rq; |
| 630 | |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 631 | if (arg < 0 || arg > 255) |
| 632 | return -EINVAL; |
| 633 | |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 634 | if (drive->hwif->set_pio_mode == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | return -ENOSYS; |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | if (drive->special.b.set_tune) |
| 638 | return -EBUSY; |
Bartlomiej Zolnierkiewicz | 145b75e | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | ide_init_drive_cmd(&rq); |
Bartlomiej Zolnierkiewicz | 852738f | 2008-01-26 20:13:12 +0100 | [diff] [blame] | 641 | rq.cmd_type = REQ_TYPE_ATA_TASKFILE; |
Bartlomiej Zolnierkiewicz | 145b75e | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | drive->tune_req = (u8) arg; |
| 644 | drive->special.b.set_tune = 1; |
| 645 | (void) ide_do_drive_cmd(drive, &rq, ide_wait); |
| 646 | return 0; |
| 647 | } |
| 648 | |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 649 | static int set_unmaskirq(ide_drive_t *drive, int arg) |
| 650 | { |
| 651 | if (drive->no_unmask) |
| 652 | return -EPERM; |
| 653 | |
| 654 | if (arg < 0 || arg > 1) |
| 655 | return -EINVAL; |
| 656 | |
| 657 | if (ide_spin_wait_hwgroup(drive)) |
| 658 | return -EBUSY; |
| 659 | drive->unmask = arg; |
| 660 | spin_unlock_irq(&ide_lock); |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | /** |
| 666 | * system_bus_clock - clock guess |
| 667 | * |
| 668 | * External version of the bus clock guess used by very old IDE drivers |
| 669 | * for things like VLB timings. Should not be used. |
| 670 | */ |
| 671 | |
| 672 | int system_bus_clock (void) |
| 673 | { |
Bartlomiej Zolnierkiewicz | 537f06c | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 674 | return system_bus_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | EXPORT_SYMBOL(system_bus_clock); |
| 678 | |
David Brownell | b887d2e | 2006-08-14 23:11:05 -0700 | [diff] [blame] | 679 | static int generic_ide_suspend(struct device *dev, pm_message_t mesg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
| 681 | ide_drive_t *drive = dev->driver_data; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 682 | ide_hwif_t *hwif = HWIF(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | struct request rq; |
| 684 | struct request_pm_state rqpm; |
| 685 | ide_task_t args; |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 686 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 688 | /* Call ACPI _GTM only once */ |
| 689 | if (!(drive->dn % 2)) |
| 690 | ide_acpi_get_timing(hwif); |
| 691 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | memset(&rq, 0, sizeof(rq)); |
| 693 | memset(&rqpm, 0, sizeof(rqpm)); |
| 694 | memset(&args, 0, sizeof(args)); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 695 | rq.cmd_type = REQ_TYPE_PM_SUSPEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | rq.special = &args; |
Jens Axboe | c00895a | 2006-09-30 20:29:12 +0200 | [diff] [blame] | 697 | rq.data = &rqpm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | rqpm.pm_step = ide_pm_state_start_suspend; |
David Brownell | b887d2e | 2006-08-14 23:11:05 -0700 | [diff] [blame] | 699 | if (mesg.event == PM_EVENT_PRETHAW) |
| 700 | mesg.event = PM_EVENT_FREEZE; |
| 701 | rqpm.pm_state = mesg.event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 703 | ret = ide_do_drive_cmd(drive, &rq, ide_wait); |
| 704 | /* only call ACPI _PS3 after both drivers are suspended */ |
| 705 | if (!ret && (((drive->dn % 2) && hwif->drives[0].present |
| 706 | && hwif->drives[1].present) |
| 707 | || !hwif->drives[0].present |
| 708 | || !hwif->drives[1].present)) |
| 709 | ide_acpi_set_state(hwif, 0); |
| 710 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | static int generic_ide_resume(struct device *dev) |
| 714 | { |
| 715 | ide_drive_t *drive = dev->driver_data; |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 716 | ide_hwif_t *hwif = HWIF(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | struct request rq; |
| 718 | struct request_pm_state rqpm; |
| 719 | ide_task_t args; |
Lee Trager | 0d2157f | 2007-06-08 15:14:30 +0200 | [diff] [blame] | 720 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 722 | /* Call ACPI _STM only once */ |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 723 | if (!(drive->dn % 2)) { |
| 724 | ide_acpi_set_state(hwif, 1); |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 725 | ide_acpi_push_timing(hwif); |
Shaohua Li | 5e32132 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 726 | } |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 727 | |
| 728 | ide_acpi_exec_tfs(drive); |
| 729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | memset(&rq, 0, sizeof(rq)); |
| 731 | memset(&rqpm, 0, sizeof(rqpm)); |
| 732 | memset(&args, 0, sizeof(args)); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 733 | rq.cmd_type = REQ_TYPE_PM_RESUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | rq.special = &args; |
Jens Axboe | c00895a | 2006-09-30 20:29:12 +0200 | [diff] [blame] | 735 | rq.data = &rqpm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | rqpm.pm_step = ide_pm_state_start_resume; |
Pavel Machek | ca078ba | 2005-09-03 15:56:57 -0700 | [diff] [blame] | 737 | rqpm.pm_state = PM_EVENT_ON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Lee Trager | 0d2157f | 2007-06-08 15:14:30 +0200 | [diff] [blame] | 739 | err = ide_do_drive_cmd(drive, &rq, ide_head_wait); |
| 740 | |
Rafael J. Wysocki | ce9b2b0 | 2007-06-16 02:24:43 +0200 | [diff] [blame] | 741 | if (err == 0 && dev->driver) { |
| 742 | ide_driver_t *drv = to_ide_driver(dev->driver); |
| 743 | |
| 744 | if (drv->resume) |
| 745 | drv->resume(drive); |
| 746 | } |
Lee Trager | 0d2157f | 2007-06-08 15:14:30 +0200 | [diff] [blame] | 747 | |
| 748 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, |
| 752 | unsigned int cmd, unsigned long arg) |
| 753 | { |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 754 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | ide_driver_t *drv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | void __user *p = (void __user *)arg; |
Linus Torvalds | 1985026 | 2007-07-17 15:57:42 -0700 | [diff] [blame] | 757 | int err = 0, (*setfunc)(ide_drive_t *, int); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 758 | u8 *val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 760 | switch (cmd) { |
| 761 | case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val; |
| 762 | case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val; |
| 763 | case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val; |
| 764 | case HDIO_GET_DMA: val = &drive->using_dma; goto read_val; |
| 765 | case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val; |
| 766 | case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val; |
| 767 | case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val; |
| 768 | case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val; |
| 769 | case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | case HDIO_OBSOLETE_IDENTITY: |
| 774 | case HDIO_GET_IDENTITY: |
| 775 | if (bdev != bdev->bd_contains) |
| 776 | return -EINVAL; |
| 777 | if (drive->id_read == 0) |
| 778 | return -ENOMSG; |
| 779 | if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142)) |
| 780 | return -EFAULT; |
| 781 | return 0; |
| 782 | |
| 783 | case HDIO_GET_NICE: |
| 784 | return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP | |
| 785 | drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP | |
Bartlomiej Zolnierkiewicz | 92b83c8 | 2008-02-02 19:56:45 +0100 | [diff] [blame] | 786 | drive->nice1 << IDE_NICE_1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | (long __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | #ifdef CONFIG_IDE_TASK_IOCTL |
| 789 | case HDIO_DRIVE_TASKFILE: |
| 790 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) |
| 791 | return -EACCES; |
| 792 | switch(drive->media) { |
| 793 | case ide_disk: |
| 794 | return ide_taskfile_ioctl(drive, cmd, arg); |
| 795 | default: |
| 796 | return -ENOMSG; |
| 797 | } |
| 798 | #endif /* CONFIG_IDE_TASK_IOCTL */ |
| 799 | |
| 800 | case HDIO_DRIVE_CMD: |
| 801 | if (!capable(CAP_SYS_RAWIO)) |
| 802 | return -EACCES; |
| 803 | return ide_cmd_ioctl(drive, cmd, arg); |
| 804 | |
| 805 | case HDIO_DRIVE_TASK: |
| 806 | if (!capable(CAP_SYS_RAWIO)) |
| 807 | return -EACCES; |
| 808 | return ide_task_ioctl(drive, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | case HDIO_SET_NICE: |
| 810 | if (!capable(CAP_SYS_ADMIN)) return -EACCES; |
| 811 | if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1)))) |
| 812 | return -EPERM; |
| 813 | drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1; |
| 814 | drv = *(ide_driver_t **)bdev->bd_disk->private_data; |
| 815 | if (drive->dsc_overlap && !drv->supports_dsc_overlap) { |
| 816 | drive->dsc_overlap = 0; |
| 817 | return -EPERM; |
| 818 | } |
| 819 | drive->nice1 = (arg >> IDE_NICE_1) & 1; |
| 820 | return 0; |
| 821 | case HDIO_DRIVE_RESET: |
Bartlomiej Zolnierkiewicz | dbecebc | 2008-02-26 21:50:35 +0100 | [diff] [blame] | 822 | if (!capable(CAP_SYS_ADMIN)) |
| 823 | return -EACCES; |
| 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | /* |
| 826 | * Abort the current command on the |
| 827 | * group if there is one, taking |
| 828 | * care not to allow anything else |
| 829 | * to be queued and to die on the |
| 830 | * spot if we miss one somehow |
| 831 | */ |
| 832 | |
| 833 | spin_lock_irqsave(&ide_lock, flags); |
| 834 | |
Alan Cox | 913759a | 2006-10-03 01:14:33 -0700 | [diff] [blame] | 835 | if (HWGROUP(drive)->resetting) { |
| 836 | spin_unlock_irqrestore(&ide_lock, flags); |
| 837 | return -EBUSY; |
| 838 | } |
| 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | ide_abort(drive, "drive reset"); |
| 841 | |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 842 | BUG_ON(HWGROUP(drive)->handler); |
Bartlomiej Zolnierkiewicz | dbecebc | 2008-02-26 21:50:35 +0100 | [diff] [blame] | 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | /* Ensure nothing gets queued after we |
| 845 | drop the lock. Reset will clear the busy */ |
Bartlomiej Zolnierkiewicz | dbecebc | 2008-02-26 21:50:35 +0100 | [diff] [blame] | 846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | HWGROUP(drive)->busy = 1; |
| 848 | spin_unlock_irqrestore(&ide_lock, flags); |
| 849 | (void) ide_do_reset(drive); |
| 850 | |
| 851 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | case HDIO_GET_BUSSTATE: |
| 853 | if (!capable(CAP_SYS_ADMIN)) |
| 854 | return -EACCES; |
| 855 | if (put_user(HWIF(drive)->bus_state, (long __user *)arg)) |
| 856 | return -EFAULT; |
| 857 | return 0; |
| 858 | |
| 859 | case HDIO_SET_BUSSTATE: |
| 860 | if (!capable(CAP_SYS_ADMIN)) |
| 861 | return -EACCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | return -EOPNOTSUPP; |
| 863 | default: |
| 864 | return -EINVAL; |
| 865 | } |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 866 | |
| 867 | read_val: |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 868 | mutex_lock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 869 | spin_lock_irqsave(&ide_lock, flags); |
| 870 | err = *val; |
| 871 | spin_unlock_irqrestore(&ide_lock, flags); |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 872 | mutex_unlock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 873 | return err >= 0 ? put_user(err, (long __user *)arg) : err; |
| 874 | |
| 875 | set_val: |
| 876 | if (bdev != bdev->bd_contains) |
| 877 | err = -EINVAL; |
| 878 | else { |
| 879 | if (!capable(CAP_SYS_ADMIN)) |
| 880 | err = -EACCES; |
| 881 | else { |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 882 | mutex_lock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 883 | err = setfunc(drive, arg); |
Matthias Kaehlcke | f9383c4 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 884 | mutex_unlock(&ide_setting_mtx); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | EXPORT_SYMBOL(generic_ide_ioctl); |
| 891 | |
| 892 | /* |
| 893 | * stridx() returns the offset of c within s, |
| 894 | * or -1 if c is '\0' or not found within s. |
| 895 | */ |
| 896 | static int __init stridx (const char *s, char c) |
| 897 | { |
| 898 | char *i = strchr(s, c); |
| 899 | return (i && c) ? i - s : -1; |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | * match_parm() does parsing for ide_setup(): |
| 904 | * |
| 905 | * 1. the first char of s must be '='. |
| 906 | * 2. if the remainder matches one of the supplied keywords, |
| 907 | * the index (1 based) of the keyword is negated and returned. |
| 908 | * 3. if the remainder is a series of no more than max_vals numbers |
| 909 | * separated by commas, the numbers are saved in vals[] and a |
| 910 | * count of how many were saved is returned. Base10 is assumed, |
| 911 | * and base16 is allowed when prefixed with "0x". |
| 912 | * 4. otherwise, zero is returned. |
| 913 | */ |
| 914 | static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals) |
| 915 | { |
| 916 | static const char *decimal = "0123456789"; |
| 917 | static const char *hex = "0123456789abcdef"; |
| 918 | int i, n; |
| 919 | |
| 920 | if (*s++ == '=') { |
| 921 | /* |
| 922 | * Try matching against the supplied keywords, |
| 923 | * and return -(index+1) if we match one |
| 924 | */ |
| 925 | if (keywords != NULL) { |
| 926 | for (i = 0; *keywords != NULL; ++i) { |
| 927 | if (!strcmp(s, *keywords++)) |
| 928 | return -(i+1); |
| 929 | } |
| 930 | } |
| 931 | /* |
| 932 | * Look for a series of no more than "max_vals" |
| 933 | * numeric values separated by commas, in base10, |
| 934 | * or base16 when prefixed with "0x". |
| 935 | * Return a count of how many were found. |
| 936 | */ |
| 937 | for (n = 0; (i = stridx(decimal, *s)) >= 0;) { |
| 938 | vals[n] = i; |
| 939 | while ((i = stridx(decimal, *++s)) >= 0) |
| 940 | vals[n] = (vals[n] * 10) + i; |
| 941 | if (*s == 'x' && !vals[n]) { |
| 942 | while ((i = stridx(hex, *++s)) >= 0) |
| 943 | vals[n] = (vals[n] * 0x10) + i; |
| 944 | } |
| 945 | if (++n == max_vals) |
| 946 | break; |
| 947 | if (*s == ',' || *s == ';') |
| 948 | ++s; |
| 949 | } |
| 950 | if (!*s) |
| 951 | return n; |
| 952 | } |
| 953 | return 0; /* zero = nothing matched */ |
| 954 | } |
| 955 | |
Bartlomiej Zolnierkiewicz | 8491388 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 956 | extern int probe_ali14xx; |
Bartlomiej Zolnierkiewicz | 8491388 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 957 | extern int probe_umc8672; |
Bartlomiej Zolnierkiewicz | 8491388 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 958 | extern int probe_dtc2278; |
Bartlomiej Zolnierkiewicz | 8491388 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 959 | extern int probe_ht6560b; |
Bartlomiej Zolnierkiewicz | 8491388 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 960 | extern int probe_qd65xx; |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 961 | extern int cmd640_vlb; |
Bartlomiej Zolnierkiewicz | ffd4f6f | 2008-04-18 00:46:34 +0200 | [diff] [blame] | 962 | extern int probe_4drives; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
Bartlomiej Zolnierkiewicz | 9a0e77f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 964 | static int __initdata is_chipset_set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
| 966 | /* |
| 967 | * ide_setup() gets called VERY EARLY during initialization, |
| 968 | * to handle kernel "command line" strings beginning with "hdx=" or "ide". |
| 969 | * |
Randy Dunlap | 1c10e93 | 2008-03-07 21:53:50 +0100 | [diff] [blame] | 970 | * Remember to update Documentation/ide/ide.txt if you change something here. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | */ |
| 972 | static int __init ide_setup(char *s) |
| 973 | { |
| 974 | int i, vals[3]; |
| 975 | ide_hwif_t *hwif; |
| 976 | ide_drive_t *drive; |
| 977 | unsigned int hw, unit; |
| 978 | const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1); |
| 979 | const char max_hwif = '0' + (MAX_HWIFS - 1); |
| 980 | |
| 981 | |
| 982 | if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */ |
| 983 | return 0; /* driver and not us */ |
| 984 | |
| 985 | if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2)) |
| 986 | return 0; |
| 987 | |
| 988 | printk(KERN_INFO "ide_setup: %s", s); |
| 989 | init_ide_data (); |
| 990 | |
| 991 | #ifdef CONFIG_BLK_DEV_IDEDOUBLER |
| 992 | if (!strcmp(s, "ide=doubler")) { |
| 993 | extern int ide_doubler; |
| 994 | |
| 995 | printk(" : Enabled support for IDE doublers\n"); |
| 996 | ide_doubler = 1; |
| 997 | return 1; |
| 998 | } |
| 999 | #endif /* CONFIG_BLK_DEV_IDEDOUBLER */ |
| 1000 | |
| 1001 | if (!strcmp(s, "ide=nodma")) { |
| 1002 | printk(" : Prevented DMA\n"); |
| 1003 | noautodma = 1; |
Bartlomiej Zolnierkiewicz | c223701 | 2007-10-16 22:29:58 +0200 | [diff] [blame] | 1004 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Hannes Reinecke | e3a59b4 | 2007-02-07 18:19:37 +0100 | [diff] [blame] | 1007 | #ifdef CONFIG_BLK_DEV_IDEACPI |
| 1008 | if (!strcmp(s, "ide=noacpi")) { |
| 1009 | //printk(" : Disable IDE ACPI support.\n"); |
| 1010 | ide_noacpi = 1; |
| 1011 | return 1; |
| 1012 | } |
| 1013 | if (!strcmp(s, "ide=acpigtf")) { |
| 1014 | //printk(" : Enable IDE ACPI _GTF support.\n"); |
| 1015 | ide_noacpitfs = 0; |
| 1016 | return 1; |
| 1017 | } |
| 1018 | if (!strcmp(s, "ide=acpionboot")) { |
| 1019 | //printk(" : Call IDE ACPI methods on boot.\n"); |
| 1020 | ide_noacpionboot = 0; |
| 1021 | return 1; |
| 1022 | } |
| 1023 | #endif /* CONFIG_BLK_DEV_IDEACPI */ |
| 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | /* |
| 1026 | * Look for drive options: "hdx=" |
| 1027 | */ |
| 1028 | if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) { |
| 1029 | const char *hd_words[] = { |
Bartlomiej Zolnierkiewicz | c223701 | 2007-10-16 22:29:58 +0200 | [diff] [blame] | 1030 | "none", "noprobe", "nowerr", "cdrom", "nodma", |
Bartlomiej Zolnierkiewicz | 9e47be0 | 2008-01-26 20:13:09 +0100 | [diff] [blame] | 1031 | "autotune", "noautotune", "-8", "-9", "-10", |
Jens Axboe | 3619348 | 2006-07-28 08:54:59 +0200 | [diff] [blame] | 1032 | "noflush", "remap", "remap63", "scsi", NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | unit = s[2] - 'a'; |
| 1034 | hw = unit / MAX_DRIVES; |
| 1035 | unit = unit % MAX_DRIVES; |
| 1036 | hwif = &ide_hwifs[hw]; |
| 1037 | drive = &hwif->drives[unit]; |
| 1038 | if (strncmp(s + 4, "ide-", 4) == 0) { |
| 1039 | strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req)); |
Bartlomiej Zolnierkiewicz | 15220d9 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1040 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | switch (match_parm(&s[3], hd_words, vals, 3)) { |
| 1043 | case -1: /* "none" */ |
| 1044 | case -2: /* "noprobe" */ |
| 1045 | drive->noprobe = 1; |
| 1046 | goto done; |
| 1047 | case -3: /* "nowerr" */ |
| 1048 | drive->bad_wstat = BAD_R_STAT; |
| 1049 | hwif->noprobe = 0; |
| 1050 | goto done; |
| 1051 | case -4: /* "cdrom" */ |
| 1052 | drive->present = 1; |
| 1053 | drive->media = ide_cdrom; |
| 1054 | /* an ATAPI device ignores DRDY */ |
| 1055 | drive->ready_stat = 0; |
| 1056 | hwif->noprobe = 0; |
| 1057 | goto done; |
Bartlomiej Zolnierkiewicz | c223701 | 2007-10-16 22:29:58 +0200 | [diff] [blame] | 1058 | case -5: /* nodma */ |
| 1059 | drive->nodma = 1; |
| 1060 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | case -6: /* "autotune" */ |
| 1062 | drive->autotune = IDE_TUNE_AUTO; |
| 1063 | goto obsolete_option; |
| 1064 | case -7: /* "noautotune" */ |
| 1065 | drive->autotune = IDE_TUNE_NOAUTO; |
| 1066 | goto obsolete_option; |
Jens Axboe | 3619348 | 2006-07-28 08:54:59 +0200 | [diff] [blame] | 1067 | case -11: /* noflush */ |
| 1068 | drive->noflush = 1; |
| 1069 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | case -12: /* "remap" */ |
| 1071 | drive->remap_0_to_1 = 1; |
Bartlomiej Zolnierkiewicz | d708c40 | 2008-03-22 16:40:22 +0100 | [diff] [blame] | 1072 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | case -13: /* "remap63" */ |
| 1074 | drive->sect0 = 63; |
Bartlomiej Zolnierkiewicz | d708c40 | 2008-03-22 16:40:22 +0100 | [diff] [blame] | 1075 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | case -14: /* "scsi" */ |
| 1077 | drive->scsi = 1; |
Bartlomiej Zolnierkiewicz | 15220d9 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1078 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | case 3: /* cyl,head,sect */ |
| 1080 | drive->media = ide_disk; |
| 1081 | drive->ready_stat = READY_STAT; |
| 1082 | drive->cyl = drive->bios_cyl = vals[0]; |
| 1083 | drive->head = drive->bios_head = vals[1]; |
| 1084 | drive->sect = drive->bios_sect = vals[2]; |
| 1085 | drive->present = 1; |
| 1086 | drive->forced_geom = 1; |
| 1087 | hwif->noprobe = 0; |
| 1088 | goto done; |
| 1089 | default: |
| 1090 | goto bad_option; |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e') |
| 1095 | goto bad_option; |
| 1096 | /* |
| 1097 | * Look for bus speed option: "idebus=" |
| 1098 | */ |
| 1099 | if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') { |
| 1100 | if (match_parm(&s[6], NULL, vals, 1) != 1) |
| 1101 | goto bad_option; |
| 1102 | if (vals[0] >= 20 && vals[0] <= 66) { |
| 1103 | idebus_parameter = vals[0]; |
| 1104 | } else |
| 1105 | printk(" -- BAD BUS SPEED! Expected value from 20 to 66"); |
| 1106 | goto done; |
| 1107 | } |
| 1108 | /* |
| 1109 | * Look for interface options: "idex=" |
| 1110 | */ |
| 1111 | if (s[3] >= '0' && s[3] <= max_hwif) { |
| 1112 | /* |
| 1113 | * Be VERY CAREFUL changing this: note hardcoded indexes below |
| 1114 | * (-8, -9, -10) are reserved to ease the hardcoding. |
| 1115 | */ |
| 1116 | static const char *ide_words[] = { |
Bartlomiej Zolnierkiewicz | f01674e | 2008-04-18 00:46:35 +0200 | [diff] [blame] | 1117 | "minus1", "serialize", "minus3", "minus4", |
Bartlomiej Zolnierkiewicz | 1b51694 | 2007-10-16 22:29:57 +0200 | [diff] [blame] | 1118 | "reset", "minus6", "ata66", "minus8", "minus9", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb", |
| 1120 | "dtc2278", "umc8672", "ali14xx", NULL }; |
Bartlomiej Zolnierkiewicz | 9239b33 | 2007-10-20 00:32:33 +0200 | [diff] [blame] | 1121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | hw = s[3] - '0'; |
| 1123 | hwif = &ide_hwifs[hw]; |
| 1124 | i = match_parm(&s[4], ide_words, vals, 3); |
| 1125 | |
| 1126 | /* |
| 1127 | * Cryptic check to ensure chipset not already set for hwif. |
| 1128 | * Note: we can't depend on hwif->chipset here. |
| 1129 | */ |
Bartlomiej Zolnierkiewicz | 9a0e77f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 1130 | if (i >= -18 && i <= -11) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | /* chipset already specified */ |
Bartlomiej Zolnierkiewicz | 9a0e77f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 1132 | if (is_chipset_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | goto bad_option; |
Bartlomiej Zolnierkiewicz | 9a0e77f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 1134 | /* these drivers are for "ide0=" only */ |
| 1135 | if (hw != 0) |
| 1136 | goto bad_hwif; |
| 1137 | is_chipset_set = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | printk("\n"); |
| 1139 | } |
| 1140 | |
| 1141 | switch (i) { |
| 1142 | #ifdef CONFIG_BLK_DEV_ALI14XX |
| 1143 | case -17: /* "ali14xx" */ |
| 1144 | probe_ali14xx = 1; |
Bartlomiej Zolnierkiewicz | 9c027c6 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1145 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | #endif |
| 1147 | #ifdef CONFIG_BLK_DEV_UMC8672 |
| 1148 | case -16: /* "umc8672" */ |
| 1149 | probe_umc8672 = 1; |
Bartlomiej Zolnierkiewicz | 9c027c6 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1150 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | #endif |
| 1152 | #ifdef CONFIG_BLK_DEV_DTC2278 |
| 1153 | case -15: /* "dtc2278" */ |
| 1154 | probe_dtc2278 = 1; |
Bartlomiej Zolnierkiewicz | 9c027c6 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1155 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | #endif |
| 1157 | #ifdef CONFIG_BLK_DEV_CMD640 |
| 1158 | case -14: /* "cmd640_vlb" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | cmd640_vlb = 1; |
Bartlomiej Zolnierkiewicz | 9c027c6 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1160 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | #endif |
| 1162 | #ifdef CONFIG_BLK_DEV_HT6560B |
| 1163 | case -13: /* "ht6560b" */ |
| 1164 | probe_ht6560b = 1; |
Bartlomiej Zolnierkiewicz | 9c027c6 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1165 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | #endif |
| 1167 | #ifdef CONFIG_BLK_DEV_QD65XX |
| 1168 | case -12: /* "qd65xx" */ |
| 1169 | probe_qd65xx = 1; |
Bartlomiej Zolnierkiewicz | 9c027c6 | 2008-03-22 16:40:21 +0100 | [diff] [blame] | 1170 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | #endif |
| 1172 | #ifdef CONFIG_BLK_DEV_4DRIVES |
| 1173 | case -11: /* "four" drives on one set of ports */ |
Bartlomiej Zolnierkiewicz | ffd4f6f | 2008-04-18 00:46:34 +0200 | [diff] [blame] | 1174 | probe_4drives = 1; |
Bartlomiej Zolnierkiewicz | b6209a9 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 1175 | goto obsolete_option; |
Bartlomiej Zolnierkiewicz | ffd4f6f | 2008-04-18 00:46:34 +0200 | [diff] [blame] | 1176 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | case -10: /* minus10 */ |
| 1178 | case -9: /* minus9 */ |
| 1179 | case -8: /* minus8 */ |
Bartlomiej Zolnierkiewicz | 1b51694 | 2007-10-16 22:29:57 +0200 | [diff] [blame] | 1180 | case -6: |
Bartlomiej Zolnierkiewicz | b6209a9 | 2007-03-03 17:48:55 +0100 | [diff] [blame] | 1181 | case -4: |
| 1182 | case -3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | goto bad_option; |
| 1184 | case -7: /* ata66 */ |
| 1185 | #ifdef CONFIG_BLK_DEV_IDEPCI |
Bartlomiej Zolnierkiewicz | 49521f9 | 2007-07-09 23:17:58 +0200 | [diff] [blame] | 1186 | /* |
| 1187 | * Use ATA_CBL_PATA40_SHORT so drive side |
| 1188 | * cable detection is also overriden. |
| 1189 | */ |
| 1190 | hwif->cbl = ATA_CBL_PATA40_SHORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | goto obsolete_option; |
| 1192 | #else |
| 1193 | goto bad_hwif; |
| 1194 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | case -5: /* "reset" */ |
| 1196 | hwif->reset = 1; |
| 1197 | goto obsolete_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | case -2: /* "serialize" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | hwif->mate = &ide_hwifs[hw^1]; |
| 1200 | hwif->mate->mate = hwif; |
| 1201 | hwif->serialized = hwif->mate->serialized = 1; |
| 1202 | goto obsolete_option; |
| 1203 | |
Bartlomiej Zolnierkiewicz | f01674e | 2008-04-18 00:46:35 +0200 | [diff] [blame] | 1204 | case -1: |
Bartlomiej Zolnierkiewicz | 9a0e77f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 1205 | case 0: |
| 1206 | case 1: |
| 1207 | case 2: |
| 1208 | case 3: |
| 1209 | goto bad_option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | default: |
| 1211 | printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n"); |
| 1212 | return 1; |
| 1213 | } |
| 1214 | } |
| 1215 | bad_option: |
| 1216 | printk(" -- BAD OPTION\n"); |
| 1217 | return 1; |
| 1218 | obsolete_option: |
| 1219 | printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n"); |
| 1220 | return 1; |
| 1221 | bad_hwif: |
| 1222 | printk("-- NOT SUPPORTED ON ide%d", hw); |
| 1223 | done: |
| 1224 | printk("\n"); |
| 1225 | return 1; |
| 1226 | } |
| 1227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | EXPORT_SYMBOL(ide_lock); |
| 1229 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1230 | static int ide_bus_match(struct device *dev, struct device_driver *drv) |
| 1231 | { |
| 1232 | return 1; |
| 1233 | } |
| 1234 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1235 | static char *media_string(ide_drive_t *drive) |
| 1236 | { |
| 1237 | switch (drive->media) { |
| 1238 | case ide_disk: |
| 1239 | return "disk"; |
| 1240 | case ide_cdrom: |
| 1241 | return "cdrom"; |
| 1242 | case ide_tape: |
| 1243 | return "tape"; |
| 1244 | case ide_floppy: |
| 1245 | return "floppy"; |
Danny Kukawka | a7a832d | 2007-04-10 22:39:14 +0200 | [diff] [blame] | 1246 | case ide_optical: |
| 1247 | return "optical"; |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1248 | default: |
| 1249 | return "UNKNOWN"; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1254 | { |
| 1255 | ide_drive_t *drive = to_ide_device(dev); |
| 1256 | return sprintf(buf, "%s\n", media_string(drive)); |
| 1257 | } |
| 1258 | |
| 1259 | static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1260 | { |
| 1261 | ide_drive_t *drive = to_ide_device(dev); |
| 1262 | return sprintf(buf, "%s\n", drive->name); |
| 1263 | } |
| 1264 | |
| 1265 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 1266 | { |
| 1267 | ide_drive_t *drive = to_ide_device(dev); |
| 1268 | return sprintf(buf, "ide:m-%s\n", media_string(drive)); |
| 1269 | } |
| 1270 | |
Bartlomiej Zolnierkiewicz | e11b903 | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 1271 | static ssize_t model_show(struct device *dev, struct device_attribute *attr, |
| 1272 | char *buf) |
| 1273 | { |
| 1274 | ide_drive_t *drive = to_ide_device(dev); |
| 1275 | return sprintf(buf, "%s\n", drive->id->model); |
| 1276 | } |
| 1277 | |
| 1278 | static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, |
| 1279 | char *buf) |
| 1280 | { |
| 1281 | ide_drive_t *drive = to_ide_device(dev); |
| 1282 | return sprintf(buf, "%s\n", drive->id->fw_rev); |
| 1283 | } |
| 1284 | |
| 1285 | static ssize_t serial_show(struct device *dev, struct device_attribute *attr, |
| 1286 | char *buf) |
| 1287 | { |
| 1288 | ide_drive_t *drive = to_ide_device(dev); |
| 1289 | return sprintf(buf, "%s\n", drive->id->serial_no); |
| 1290 | } |
| 1291 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1292 | static struct device_attribute ide_dev_attrs[] = { |
| 1293 | __ATTR_RO(media), |
| 1294 | __ATTR_RO(drivename), |
| 1295 | __ATTR_RO(modalias), |
Bartlomiej Zolnierkiewicz | e11b903 | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 1296 | __ATTR_RO(model), |
| 1297 | __ATTR_RO(firmware), |
| 1298 | __ATTR(serial, 0400, serial_show, NULL), |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1299 | __ATTR_NULL |
| 1300 | }; |
| 1301 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1302 | static int ide_uevent(struct device *dev, struct kobj_uevent_env *env) |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1303 | { |
| 1304 | ide_drive_t *drive = to_ide_device(dev); |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1305 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1306 | add_uevent_var(env, "MEDIA=%s", media_string(drive)); |
| 1307 | add_uevent_var(env, "DRIVENAME=%s", drive->name); |
| 1308 | add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive)); |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1309 | return 0; |
| 1310 | } |
| 1311 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1312 | static int generic_ide_probe(struct device *dev) |
| 1313 | { |
| 1314 | ide_drive_t *drive = to_ide_device(dev); |
| 1315 | ide_driver_t *drv = to_ide_driver(dev->driver); |
| 1316 | |
| 1317 | return drv->probe ? drv->probe(drive) : -ENODEV; |
| 1318 | } |
| 1319 | |
| 1320 | static int generic_ide_remove(struct device *dev) |
| 1321 | { |
| 1322 | ide_drive_t *drive = to_ide_device(dev); |
| 1323 | ide_driver_t *drv = to_ide_driver(dev->driver); |
| 1324 | |
| 1325 | if (drv->remove) |
| 1326 | drv->remove(drive); |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static void generic_ide_shutdown(struct device *dev) |
| 1332 | { |
| 1333 | ide_drive_t *drive = to_ide_device(dev); |
| 1334 | ide_driver_t *drv = to_ide_driver(dev->driver); |
| 1335 | |
| 1336 | if (dev->driver && drv->shutdown) |
| 1337 | drv->shutdown(drive); |
| 1338 | } |
| 1339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | struct bus_type ide_bus_type = { |
| 1341 | .name = "ide", |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1342 | .match = ide_bus_match, |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1343 | .uevent = ide_uevent, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1344 | .probe = generic_ide_probe, |
| 1345 | .remove = generic_ide_remove, |
| 1346 | .shutdown = generic_ide_shutdown, |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1347 | .dev_attrs = ide_dev_attrs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | .suspend = generic_ide_suspend, |
| 1349 | .resume = generic_ide_resume, |
| 1350 | }; |
| 1351 | |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1352 | EXPORT_SYMBOL_GPL(ide_bus_type); |
| 1353 | |
Bartlomiej Zolnierkiewicz | f74c914 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 1354 | static void ide_port_class_release(struct device *portdev) |
| 1355 | { |
| 1356 | ide_hwif_t *hwif = dev_get_drvdata(portdev); |
| 1357 | |
| 1358 | put_device(&hwif->gendev); |
| 1359 | } |
| 1360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | /* |
| 1362 | * This is gets invoked once during initialization, to set *everything* up |
| 1363 | */ |
| 1364 | static int __init ide_init(void) |
| 1365 | { |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 1366 | int ret; |
| 1367 | |
Bartlomiej Zolnierkiewicz | eba8ff9 | 2008-02-11 00:32:13 +0100 | [diff] [blame] | 1368 | printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | system_bus_speed = ide_system_bus_speed(); |
| 1370 | |
Bartlomiej Zolnierkiewicz | 537f06c | 2008-02-01 23:09:35 +0100 | [diff] [blame] | 1371 | printk(KERN_INFO "ide: Assuming %dMHz system bus speed " |
| 1372 | "for PIO modes%s\n", system_bus_speed, |
| 1373 | idebus_parameter ? "" : "; override with idebus=xx"); |
| 1374 | |
Randy Dunlap | 349ae23 | 2006-10-03 01:14:23 -0700 | [diff] [blame] | 1375 | ret = bus_register(&ide_bus_type); |
| 1376 | if (ret < 0) { |
| 1377 | printk(KERN_WARNING "IDE: bus_register error: %d\n", ret); |
| 1378 | return ret; |
| 1379 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
Bartlomiej Zolnierkiewicz | f74c914 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 1381 | ide_port_class = class_create(THIS_MODULE, "ide_port"); |
| 1382 | if (IS_ERR(ide_port_class)) { |
| 1383 | ret = PTR_ERR(ide_port_class); |
| 1384 | goto out_port_class; |
| 1385 | } |
| 1386 | ide_port_class->dev_release = ide_port_class_release; |
| 1387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | init_ide_data(); |
| 1389 | |
Bartlomiej Zolnierkiewicz | 5cbf79c | 2007-05-10 00:01:11 +0200 | [diff] [blame] | 1390 | proc_ide_create(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | return 0; |
Bartlomiej Zolnierkiewicz | f74c914 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 1393 | |
| 1394 | out_port_class: |
| 1395 | bus_unregister(&ide_bus_type); |
| 1396 | |
| 1397 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | #ifdef MODULE |
| 1401 | static char *options = NULL; |
| 1402 | module_param(options, charp, 0); |
| 1403 | MODULE_LICENSE("GPL"); |
| 1404 | |
| 1405 | static void __init parse_options (char *line) |
| 1406 | { |
| 1407 | char *next = line; |
| 1408 | |
| 1409 | if (line == NULL || !*line) |
| 1410 | return; |
| 1411 | while ((line = next) != NULL) { |
| 1412 | if ((next = strchr(line,' ')) != NULL) |
| 1413 | *next++ = 0; |
| 1414 | if (!ide_setup(line)) |
| 1415 | printk (KERN_INFO "Unknown option '%s'\n", line); |
| 1416 | } |
| 1417 | } |
| 1418 | |
Sam Ravnborg | fbd8ad3 | 2006-03-25 03:07:11 -0800 | [diff] [blame] | 1419 | int __init init_module (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | { |
| 1421 | parse_options(options); |
| 1422 | return ide_init(); |
| 1423 | } |
| 1424 | |
Al Viro | eb79722 | 2007-02-01 13:52:38 +0000 | [diff] [blame] | 1425 | void __exit cleanup_module (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | { |
| 1427 | int index; |
| 1428 | |
| 1429 | for (index = 0; index < MAX_HWIFS; ++index) |
Bartlomiej Zolnierkiewicz | 93de00f | 2008-04-18 00:46:24 +0200 | [diff] [blame] | 1430 | ide_unregister(index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | proc_ide_destroy(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Bartlomiej Zolnierkiewicz | f74c914 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 1434 | class_destroy(ide_port_class); |
| 1435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | bus_unregister(&ide_bus_type); |
| 1437 | } |
| 1438 | |
| 1439 | #else /* !MODULE */ |
| 1440 | |
| 1441 | __setup("", ide_setup); |
| 1442 | |
| 1443 | module_init(ide_init); |
| 1444 | |
| 1445 | #endif /* MODULE */ |