2 * linux/drivers/ide/ide.c Version 7.00beta3 Apr 22 2003
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
8 * Mostly written by Mark Lord <mlord@pobox.com>
9 * and Gadi Oxman <gadio@netvision.net.il>
10 * and Andre Hedrick <andre@linux-ide.org>
12 * See linux/MAINTAINERS for address of current maintainer.
14 * This is the multiple IDE interface driver, as evolved from hd.c.
15 * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
17 * There can be up to two drives per interface, as per the ATA-2 spec.
19 * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64
20 * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64
21 * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64
22 * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64
27 * | It traverses the request-list, using interrupts to jump between functions.
28 * | As nearly all functions can be called within interrupts, we may not sleep.
29 * | Special care is recommended. Have Fun!
31 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
33 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
34 * | in the early extended-partition checks and added DM partitions.
36 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
38 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
39 * | and general streamlining by Mark Lord (mlord@pobox.com).
41 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
43 * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
44 * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
45 * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
47 * This was a rewrite of just about everything from hd.c, though some original
48 * code is still sprinkled about. Think of it as a major evolution, with
49 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
51 * Version 1.0 ALPHA initial code, primary i/f working okay
52 * Version 1.3 BETA dual i/f on shared irq tested & working!
53 * Version 1.4 BETA added auto probing for irq(s)
54 * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms,
56 * Version 5.50 allow values as small as 20 for idebus=
57 * Version 5.51 force non io_32bit in drive_cmd_intr()
58 * change delay_10ms() to delay_50ms() to fix problems
59 * Version 5.52 fix incorrect invalidation of removable devices
60 * add "hdx=slow" command line option
61 * Version 5.60 start to modularize the driver; the disk and ATAPI
62 * drivers can be compiled as loadable modules.
63 * move IDE probe code to ide-probe.c
64 * move IDE disk code to ide-disk.c
65 * add support for generic IDE device subdrivers
66 * add m68k code from Geert Uytterhoeven
67 * probe all interfaces by default
68 * add ioctl to (re)probe an interface
69 * Version 6.00 use per device request queues
70 * attempt to optimize shared hwgroup performance
71 * add ioctl to manually adjust bandwidth algorithms
72 * add kerneld support for the probe module
73 * fix bug in ide_error()
74 * fix bug in the first ide_get_lock() call for Atari
75 * don't flush leftover data for ATAPI devices
76 * Version 6.01 clear hwgroup->active while the hwgroup sleeps
77 * support HDIO_GETGEO for floppies
78 * Version 6.02 fix ide_ack_intr() call
79 * check partition table on floppies
80 * Version 6.03 handle bad status bit sequencing in ide_wait_stat()
81 * Version 6.10 deleted old entries from this list of updates
82 * replaced triton.c with ide-dma.c generic PCI DMA
83 * added support for BIOS-enabled UltraDMA
84 * rename all "promise" things to "pdc4030"
85 * fix EZ-DRIVE handling on small disks
86 * Version 6.11 fix probe error in ide_scan_devices()
87 * fix ancient "jiffies" polling bugs
88 * mask all hwgroup interrupts on each irq entry
89 * Version 6.12 integrate ioctl and proc interfaces
90 * fix parsing of "idex=" command line parameter
91 * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com
92 * Version 6.14 fixed IRQ sharing among PCI devices
93 * Version 6.15 added SMP awareness to IDE drivers
94 * Version 6.16 fixed various bugs; even more SMP friendly
95 * Version 6.17 fix for newest EZ-Drive problem
96 * Version 6.18 default unpartitioned-disk translation now "BIOS LBA"
97 * Version 6.19 Re-design for a UNIFORM driver for all platforms,
98 * model based on suggestions from Russell King and
100 * Promise DC4030VL now supported.
101 * add support for ide6/ide7
102 * delay_50ms() changed to ide_delay_50ms() and exported.
103 * Version 6.20 Added/Fixed Generic ATA-66 support and hwif detection.
104 * Added hdx=flash to allow for second flash disk
105 * detection w/o the hang loop.
106 * Added support for ide8/ide9
107 * Added idex=ata66 for the quirky chipsets that are
108 * ATA-66 compliant, but have yet to determine a method
109 * of verification of the 80c cable presence.
110 * Specifically Promise's PDC20262 chipset.
111 * Version 6.21 Fixing/Fixed SMP spinlock issue with insight from an old
112 * hat that clarified original low level driver design.
113 * Version 6.30 Added SMP support; fixed multmode issues. -ml
114 * Version 6.31 Debug Share INTR's and request queue streaming
115 * Native ATA-100 support
116 * Prep for Cascades Project
117 * Version 7.00alpha First named revision of ide rearrange
118 * Version 7.00beta (2.4 backport)
120 * Some additional driver compile-time options are in ./include/linux/ide.h
124 #define REVISION "Revision: 7.00beta4-2.4"
125 #define VERSION "Id: ide.c 7.00b4 20030520"
127 #undef REALLY_SLOW_IO /* most systems can safely undef this */
129 #define _IDE_C /* Tell ide.h it's really us */
131 #include <linux/config.h>
132 #include <linux/module.h>
133 #include <linux/types.h>
134 #include <linux/string.h>
135 #include <linux/kernel.h>
136 #include <linux/timer.h>
137 #include <linux/mm.h>
138 #include <linux/interrupt.h>
139 #include <linux/major.h>
140 #include <linux/errno.h>
141 #include <linux/genhd.h>
142 #include <linux/blkpg.h>
143 #include <linux/slab.h>
144 #include <linux/init.h>
145 #include <linux/pci.h>
146 #include <linux/delay.h>
147 #include <linux/ide.h>
148 #include <linux/devfs_fs_kernel.h>
149 #include <linux/completion.h>
150 #include <linux/reboot.h>
152 #include <asm/byteorder.h>
154 #include <asm/uaccess.h>
156 #include <asm/bitops.h>
158 #include "ide_modes.h"
160 #include <linux/kmod.h>
162 /* default maximum number of failures */
163 #define IDE_DEFAULT_MAX_FAILURES 1
165 static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
166 IDE2_MAJOR, IDE3_MAJOR,
167 IDE4_MAJOR, IDE5_MAJOR,
168 IDE6_MAJOR, IDE7_MAJOR,
169 IDE8_MAJOR, IDE9_MAJOR };
171 static int idebus_parameter; /* holds the "idebus=" parameter */
172 static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
173 static int initializing; /* set while initializing built-in drivers */
175 static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
177 #ifdef CONFIG_IDEDMA_AUTO
183 EXPORT_SYMBOL(noautodma);
187 * ide_modules keeps track of the available IDE chipset/probe/driver modules.
189 ide_module_t *ide_chipsets;
190 ide_module_t *ide_modules;
191 ide_module_t *ide_probe;
194 * This is declared extern in ide.h, for access by other IDE modules:
196 ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
198 EXPORT_SYMBOL(ide_hwifs);
200 ide_devices_t *idedisk;
201 ide_devices_t *idecd;
202 ide_devices_t *idefloppy;
203 ide_devices_t *idetape;
204 ide_devices_t *idescsi;
206 EXPORT_SYMBOL(idedisk);
207 EXPORT_SYMBOL(idecd);
208 EXPORT_SYMBOL(idefloppy);
209 EXPORT_SYMBOL(idetape);
210 EXPORT_SYMBOL(idescsi);
212 extern ide_driver_t idedefault_driver;
213 static void setup_driver_defaults (ide_drive_t *drive);
216 * Do not even *think* about calling this!
218 static void init_hwif_data (unsigned int index)
222 ide_hwif_t *hwif = &ide_hwifs[index];
224 /* bulk initialize hwif & drive info with zeros */
225 memset(hwif, 0, sizeof(ide_hwif_t));
226 memset(&hw, 0, sizeof(hw_regs_t));
228 /* fill in any non-zero initial values */
230 ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
231 memcpy(&hwif->hw, &hw, sizeof(hw));
232 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
233 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
234 #ifdef CONFIG_BLK_DEV_HD
235 if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
236 hwif->noprobe = 1; /* may be overridden by ide_setup() */
237 #endif /* CONFIG_BLK_DEV_HD */
238 hwif->major = ide_hwif_to_major[index];
242 hwif->name[3] = '0' + index;
243 hwif->bus_state = BUSSTATE_ON;
244 hwif->reset_poll= NULL;
245 hwif->pre_reset = NULL;
247 hwif->atapi_dma = 0; /* disable all atapi dma */
248 hwif->ultra_mask = 0x80; /* disable all ultra */
249 hwif->mwdma_mask = 0x80; /* disable all mwdma */
250 hwif->swdma_mask = 0x80; /* disable all swdma */
251 hwif->sata = 0; /* assume PATA */
253 default_hwif_iops(hwif);
254 default_hwif_transport(hwif);
255 for (unit = 0; unit < MAX_DRIVES; ++unit) {
256 ide_drive_t *drive = &hwif->drives[unit];
258 drive->media = ide_disk;
259 drive->select.all = (unit<<4)|0xa0;
262 drive->ready_stat = READY_STAT;
263 drive->bad_wstat = BAD_W_STAT;
264 drive->special.b.recalibrate = 1;
265 drive->special.b.set_geometry = 1;
266 drive->name[0] = 'h';
267 drive->name[1] = 'd';
268 drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
269 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
270 drive->using_dma = 0;
272 drive->driver = &idedefault_driver;
273 setup_driver_defaults(drive);
274 init_waitqueue_head(&drive->wqueue);
279 * init_ide_data() sets reasonable default values into all fields
280 * of all instances of the hwifs and drives, but only on the first call.
281 * Subsequent calls have no effect (they don't wipe out anything).
283 * This routine is normally called at driver initialization time,
284 * but may also be called MUCH earlier during kernel "command-line"
285 * parameter processing. As such, we cannot depend on any other parts
286 * of the kernel (such as memory allocation) to be functioning yet.
288 * This is too bad, as otherwise we could dynamically allocate the
289 * ide_drive_t structs as needed, rather than always consuming memory
290 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
292 * FIXME: We should stuff the setup data into __init and copy the
293 * relevant hwifs/allocate them properly during boot.
295 #define MAGIC_COOKIE 0x12345678
296 static void __init init_ide_data (void)
299 static unsigned long magic_cookie = MAGIC_COOKIE;
301 if (magic_cookie != MAGIC_COOKIE)
302 return; /* already initialized */
305 /* Initialise all interface structures */
306 for (index = 0; index < MAX_HWIFS; ++index)
307 init_hwif_data(index);
309 /* Add default hw interfaces */
310 ide_init_default_hwifs();
312 idebus_parameter = 0;
313 system_bus_speed = 0;
317 * ide_system_bus_speed() returns what we think is the system VESA/PCI
318 * bus speed (in MHz). This is used for calculating interface PIO timings.
319 * The default is 40 for known PCI systems, 50 otherwise.
320 * The "idebus=xx" parameter can be used to override this value.
321 * The actual value to be used is computed/displayed the first time through.
323 int ide_system_bus_speed (void)
325 if (!system_bus_speed) {
326 if (idebus_parameter) {
327 /* user supplied value */
328 system_bus_speed = idebus_parameter;
329 } else if (pci_present()) {
330 /* safe default value for PCI */
331 system_bus_speed = 33;
333 /* safe default value for VESA and PCI */
334 system_bus_speed = 50;
336 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
337 "for PIO modes%s\n", system_bus_speed,
338 idebus_parameter ? "" : "; override with idebus=xx");
340 return system_bus_speed;
344 * current_capacity() returns the capacity (in sectors) of a drive
345 * according to its current geometry/LBA settings.
347 unsigned long current_capacity (ide_drive_t *drive)
351 return DRIVER(drive)->capacity(drive);
354 EXPORT_SYMBOL(current_capacity);
356 static inline u32 read_24 (ide_drive_t *drive)
358 return (HWIF(drive)->INB(IDE_HCYL_REG)<<16) |
359 (HWIF(drive)->INB(IDE_LCYL_REG)<<8) |
360 HWIF(drive)->INB(IDE_SECTOR_REG);
364 * Error reporting, in human readable form (luxurious, but a memory hog).
366 u8 ide_dump_status (ide_drive_t *drive, const char *msg, u8 stat)
368 ide_hwif_t *hwif = HWIF(drive);
372 local_irq_set(flags);
373 printk(KERN_WARNING "%s: %s: status=0x%02x", drive->name, msg, stat);
374 #if FANCY_STATUS_DUMPS
376 if (stat & BUSY_STAT) {
379 if (stat & READY_STAT) printk("DriveReady ");
380 if (stat & WRERR_STAT) printk("DeviceFault ");
381 if (stat & SEEK_STAT) printk("SeekComplete ");
382 if (stat & DRQ_STAT) printk("DataRequest ");
383 if (stat & ECC_STAT) printk("CorrectedError ");
384 if (stat & INDEX_STAT) printk("Index ");
385 if (stat & ERR_STAT) printk("Error ");
388 #endif /* FANCY_STATUS_DUMPS */
390 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
391 err = hwif->INB(IDE_ERROR_REG);
392 printk("%s: %s: error=0x%02x", drive->name, msg, err);
393 #if FANCY_STATUS_DUMPS
394 if (drive->media == ide_disk) {
396 if (err & ABRT_ERR) printk("DriveStatusError ");
397 if (err & ICRC_ERR) printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector");
398 if (err & ECC_ERR) printk("UncorrectableError ");
399 if (err & ID_ERR) printk("SectorIdNotFound ");
400 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
401 if (err & MARK_ERR) printk("AddrMarkNotFound ");
403 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
404 if ((drive->id->command_set_2 & 0x0400) &&
405 (drive->id->cfs_enable_2 & 0x0400) &&
406 (drive->addressing == 1)) {
409 u32 low = read_24(drive);
410 hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
411 high = read_24(drive);
413 sectors = ((u64)high << 24) | low;
414 printk(", LBAsect=%llu, high=%d, low=%d",
418 u8 cur = hwif->INB(IDE_SELECT_REG);
419 if (cur & 0x40) { /* using LBA? */
420 printk(", LBAsect=%ld", (unsigned long)
422 |(hwif->INB(IDE_HCYL_REG)<<16)
423 |(hwif->INB(IDE_LCYL_REG)<<8)
424 | hwif->INB(IDE_SECTOR_REG));
426 printk(", CHS=%d/%d/%d",
427 (hwif->INB(IDE_HCYL_REG)<<8) +
428 hwif->INB(IDE_LCYL_REG),
430 hwif->INB(IDE_SECTOR_REG));
433 if (HWGROUP(drive) && HWGROUP(drive)->rq)
434 printk(", sector=%ld", HWGROUP(drive)->rq->sector);
437 #endif /* FANCY_STATUS_DUMPS */
440 local_irq_restore(flags);
444 EXPORT_SYMBOL(ide_dump_status);
448 * This routine is called to flush all partitions and partition tables
449 * for a changed disk, and then re-read the new partition table.
450 * If we are revalidating a disk because of a media change, then we
451 * enter with usage == 0. If we are using an ioctl, we automatically have
452 * usage == 1 (we need an open channel to use an ioctl :-), so this
455 int ide_revalidate_disk (kdev_t i_rdev)
458 ide_hwgroup_t *hwgroup;
459 unsigned int p, major, minor;
462 if ((drive = ide_info_ptr(i_rdev, 0)) == NULL)
464 major = MAJOR(i_rdev);
465 minor = drive->select.b.unit << PARTN_BITS;
466 hwgroup = HWGROUP(drive);
467 spin_lock_irqsave(&io_request_lock, flags);
468 if (drive->busy || (drive->usage > 1)) {
469 spin_unlock_irqrestore(&io_request_lock, flags);
474 spin_unlock_irqrestore(&io_request_lock, flags);
476 for (p = 0; p < (1<<PARTN_BITS); ++p) {
477 if (drive->part[p].nr_sects > 0) {
478 kdev_t devp = MKDEV(major, minor+p);
479 invalidate_device(devp, 1);
481 drive->part[p].start_sect = 0;
482 drive->part[p].nr_sects = 0;
485 if (DRIVER(drive)->revalidate)
486 DRIVER(drive)->revalidate(drive);
489 wake_up(&drive->wqueue);
494 EXPORT_SYMBOL(ide_revalidate_disk);
496 static void revalidate_drives (int revaldiate)
502 for (index = 0; index < MAX_HWIFS; ++index) {
503 hwif = &ide_hwifs[index];
504 for (unit = 0; unit < MAX_DRIVES; ++unit) {
505 drive = &ide_hwifs[index].drives[unit];
506 if (drive->revalidate) {
507 drive->revalidate = 0;
508 if ((!initializing) && (revaldiate))
509 (void) ide_revalidate_disk(MKDEV(hwif->major, unit<<PARTN_BITS));
515 void ide_probe_module (int revaldiate)
518 #if defined(CONFIG_BLK_DEV_IDE_MODULE)
519 (void) request_module("ide-probe-mod");
522 (void) ide_probe->init();
524 revalidate_drives(revaldiate);
527 EXPORT_SYMBOL(ide_probe_module);
529 void ide_driver_module (int revaldiate)
532 ide_module_t *module = ide_modules;
534 for (index = 0; index < MAX_HWIFS; ++index)
535 if (ide_hwifs[index].present)
537 ide_probe_module(revaldiate);
540 (void) module->init();
541 module = module->next;
543 revalidate_drives(revaldiate);
546 EXPORT_SYMBOL(ide_driver_module);
548 static int ide_open (struct inode * inode, struct file * filp)
551 int force = 1/*FIXME 0*/;
553 if(capable(CAP_SYS_ADMIN) && (filp->f_flags & O_NDELAY))
556 if ((drive = ide_info_ptr(inode->i_rdev, force)) == NULL)
560 * If the device is present make sure that we attach any
566 if (drive->driver == &idedefault_driver)
567 ide_driver_module(1);
568 if (drive->driver == &idedefault_driver) {
569 if (drive->media == ide_disk)
570 (void) request_module("ide-disk");
572 (void) request_module("ide-scsi");
573 if (drive->media == ide_cdrom)
574 (void) request_module("ide-cd");
575 if (drive->media == ide_tape)
576 (void) request_module("ide-tape");
577 if (drive->media == ide_floppy)
578 (void) request_module("ide-floppy");
581 /* The locking here isnt enough, but this is hard to fix
584 sleep_on(&drive->wqueue);
588 * Now do the actual open
592 if (!drive->dead || force)
593 return DRIVER(drive)->open(inode, filp, drive);
594 printk(KERN_WARNING "%s: driver not present\n", drive->name);
600 * Releasing a block device means we sync() it, so that it can safely
601 * be forgotten about...
603 static int ide_release (struct inode * inode, struct file * file)
607 if ((drive = ide_info_ptr(inode->i_rdev, 1)) != NULL) {
609 DRIVER(drive)->release(inode, file, drive);
614 #ifdef CONFIG_PROC_FS
615 ide_proc_entry_t generic_subdriver_entries[] = {
616 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
617 { NULL, 0, NULL, NULL }
622 #define hwif_release_region(addr, num) \
623 ((hwif->mmio) ? release_mem_region((addr),(num)) : release_region((addr),(num)))
626 * Note that we only release the standard ports,
627 * and do not even try to handle any extra ports
628 * allocated for weird IDE interface chipsets.
630 void hwif_unregister (ide_hwif_t *hwif)
636 if (hwif->io_ports[IDE_CONTROL_OFFSET])
637 hwif_release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
638 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
639 if (hwif->io_ports[IDE_IRQ_OFFSET])
640 hwif_release_region(hwif->io_ports[IDE_IRQ_OFFSET], 1);
641 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
643 if (hwif->straight8) {
644 hwif_release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
647 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
648 if (hwif->io_ports[i]) {
649 hwif_release_region(hwif->io_ports[i], 1);
654 EXPORT_SYMBOL(hwif_unregister);
656 extern void init_hwif_data(unsigned int index);
659 * ide_prepare_tristate - prepare interface for warm unplug
660 * @drive: drive on this hwif we are using
662 * Prepares a drive for shutdown after a bus tristate. The
663 * drives must be quiescent and the only user the calling ioctl
666 static int ide_prepare_tristate(ide_drive_t *our_drive)
674 ide_hwif_t *hwif = HWIF(our_drive);
677 printk("HUH? We are busy.\n");
681 spin_lock_irqsave(&io_request_lock, flags);
683 /* Abort if anything is busy */
684 for (unit = 0; unit < MAX_DRIVES; ++unit) {
685 drive = &hwif->drives[unit];
688 if (drive == our_drive && drive->usage != 1)
690 if (drive != our_drive && drive->usage)
695 /* Commit to shutdown sequence */
696 for (unit = 0; unit < MAX_DRIVES; ++unit) {
697 drive = &hwif->drives[unit];
700 if (drive != our_drive && DRIVER(drive)->shutdown(drive))
703 /* We hold the lock here.. which is important as we need to play
704 with usage counts beyond the scenes */
707 i = DRIVER(our_drive)->shutdown(our_drive);
710 /* Drive shutdown sequence done */
711 /* Prevent new opens ?? */
712 spin_unlock_irqrestore(&io_request_lock, flags);
714 * Flush kernel side caches, and dump the /proc files
716 spin_unlock_irqrestore(&io_request_lock, flags);
717 for (unit = 0; unit < MAX_DRIVES; ++unit) {
718 drive = &hwif->drives[unit];
721 DRIVER(drive)->cleanup(drive);
722 minor = drive->select.b.unit << PARTN_BITS;
723 for (p = 0; p < (1<<PARTN_BITS); ++p) {
724 if (drive->part[p].nr_sects > 0) {
725 kdev_t devp = MKDEV(hwif->major, minor+p);
726 invalidate_device(devp, 0);
729 #ifdef CONFIG_PROC_FS
730 destroy_proc_ide_drives(hwif);
733 spin_lock_irqsave(&io_request_lock, flags);
735 for (i = 0; i < MAX_DRIVES; ++i) {
736 drive = &hwif->drives[i];
738 devfs_unregister(drive->de);
743 if (drive->id != NULL) {
748 /* Safe to clear now */
751 spin_unlock_irqrestore(&io_request_lock, flags);
757 spin_unlock_irqrestore(&io_request_lock, flags);
763 * ide_resume_hwif - return a hwif to active mode
764 * @hwif: interface to resume
766 * Restore a dead interface from tristate back to normality. At this
767 * point the hardware driver busproc has reconnected the bus, but
768 * nothing else has happened
771 static int ide_resume_hwif(ide_drive_t *our_drive)
773 ide_hwif_t *hwif = HWIF(our_drive);
774 int err = ide_wait_hwif_ready(hwif);
781 printk(KERN_ERR "%s: drives not ready.\n", our_drive->name);
785 /* The drives are now taking commands */
791 /* Identify and probe the drives */
793 for (unit = 0; unit < MAX_DRIVES; ++unit) {
794 ide_drive_t *drive = &hwif->drives[unit];
795 drive->dn = ((hwif->channel ? 2 : 0) + unit);
798 hwif->drives[unit].dn = ((hwif->channel ? 2 : 0) + unit);
799 (void) ide_probe_for_drive(drive);
803 ide_probe_reset(hwif);
808 printk(KERN_INFO "ide: drives found on hot-added interface.\n");
811 * Set up the drive modes (Even if we didnt swap drives
812 * we may have lost settings when we disconnected the bus)
815 ide_tune_drives(hwif);
820 * Reattach the devices to drivers
822 for (unit = 0; unit < MAX_DRIVES; ++unit) {
823 ide_drive_t *drive = &hwif->drives[unit];
824 if(drive->present && !drive->dead)
825 ide_attach_drive(drive);
831 int ide_unregister (unsigned int index)
834 ide_drive_t *drive, *d;
835 ide_hwif_t *hwif, *g;
836 ide_hwgroup_t *hwgroup;
837 int irq_count = 0, unit, i;
839 unsigned int p, minor;
842 if (index >= MAX_HWIFS)
845 spin_lock_irqsave(&io_request_lock, flags);
846 hwif = &ide_hwifs[index];
849 for (unit = 0; unit < MAX_DRIVES; ++unit) {
850 drive = &hwif->drives[unit];
853 if (drive->busy || drive->usage)
855 if (DRIVER(drive)->shutdown(drive))
861 * All clear? Then blow away the buffer cache
863 spin_unlock_irqrestore(&io_request_lock, flags);
864 for (unit = 0; unit < MAX_DRIVES; ++unit) {
865 drive = &hwif->drives[unit];
868 DRIVER(drive)->cleanup(drive);
869 minor = drive->select.b.unit << PARTN_BITS;
870 for (p = 0; p < (1<<PARTN_BITS); ++p) {
871 if (drive->part[p].nr_sects > 0) {
872 kdev_t devp = MKDEV(hwif->major, minor+p);
873 invalidate_device(devp, 0);
876 #ifdef CONFIG_PROC_FS
877 destroy_proc_ide_drives(hwif);
881 spin_lock_irqsave(&io_request_lock, flags);
882 hwgroup = hwif->hwgroup;
885 * free the irq if we were the only hwif using it
889 if (g->irq == hwif->irq)
892 } while (g != hwgroup->hwif);
894 free_irq(hwif->irq, hwgroup);
897 * Note that we only release the standard ports,
898 * and do not even try to handle any extra ports
899 * allocated for weird IDE interface chipsets.
901 hwif_unregister(hwif);
904 * Remove us from the hwgroup, and free
905 * the hwgroup if we were the only member
908 for (i = 0; i < MAX_DRIVES; ++i) {
909 drive = &hwif->drives[i];
911 devfs_unregister(drive->de);
916 while (hwgroup->drive->next != drive)
917 hwgroup->drive = hwgroup->drive->next;
918 hwgroup->drive->next = drive->next;
919 if (hwgroup->drive == drive)
920 hwgroup->drive = NULL;
921 if (drive->id != NULL) {
926 blk_cleanup_queue(&drive->queue);
930 while (hwgroup->hwif->next != hwif)
931 hwgroup->hwif = hwgroup->hwif->next;
932 hwgroup->hwif->next = hwif->next;
933 if (hwgroup->hwif == hwif)
936 hwgroup->hwif = HWIF(hwgroup->drive);
938 #if !defined(CONFIG_DMA_NONPCI)
939 if (hwif->dma_base) {
940 (void) ide_release_dma(hwif);
943 hwif->dma_master = 0;
944 hwif->dma_command = 0;
945 hwif->dma_vendor1 = 0;
946 hwif->dma_status = 0;
947 hwif->dma_vendor3 = 0;
948 hwif->dma_prdtable = 0;
950 #endif /* !(CONFIG_DMA_NONPCI) */
953 * Remove us from the kernel's knowledge
955 unregister_blkdev(hwif->major, hwif->name);
956 kfree(blksize_size[hwif->major]);
957 kfree(max_sectors[hwif->major]);
958 kfree(max_readahead[hwif->major]);
959 blk_dev[hwif->major].data = NULL;
960 blk_dev[hwif->major].queue = NULL;
961 blksize_size[hwif->major] = NULL;
976 init_hwif_data(index); /* restore hwif data to pristine status */
977 hwif->hwgroup = old_hwif.hwgroup;
979 hwif->proc = old_hwif.proc;
981 hwif->major = old_hwif.major;
982 // hwif->index = old_hwif.index;
983 // hwif->channel = old_hwif.channel;
984 hwif->straight8 = old_hwif.straight8;
985 hwif->bus_state = old_hwif.bus_state;
987 hwif->atapi_dma = old_hwif.atapi_dma;
988 hwif->ultra_mask = old_hwif.ultra_mask;
989 hwif->mwdma_mask = old_hwif.mwdma_mask;
990 hwif->swdma_mask = old_hwif.swdma_mask;
992 hwif->chipset = old_hwif.chipset;
993 hwif->hold = old_hwif.hold;
995 #ifdef CONFIG_BLK_DEV_IDEPCI
996 hwif->pci_dev = old_hwif.pci_dev;
997 hwif->cds = old_hwif.cds;
998 #endif /* CONFIG_BLK_DEV_IDEPCI */
1001 hwif->hwifops = old_hwif.hwifops;
1003 hwif->identify = old_hwif.identify;
1004 hwif->tuneproc = old_hwif.tuneproc;
1005 hwif->speedproc = old_hwif.speedproc;
1006 hwif->selectproc = old_hwif.selectproc;
1007 hwif->reset_poll = old_hwif.reset_poll;
1008 hwif->pre_reset = old_hwif.pre_reset;
1009 hwif->resetproc = old_hwif.resetproc;
1010 hwif->intrproc = old_hwif.intrproc;
1011 hwif->maskproc = old_hwif.maskproc;
1012 hwif->quirkproc = old_hwif.quirkproc;
1013 hwif->busproc = old_hwif.busproc;
1017 hwif->pioops = old_hwif.pioops;
1019 hwif->ata_input_data = old_hwif.ata_input_data;
1020 hwif->ata_output_data = old_hwif.ata_output_data;
1021 hwif->atapi_input_bytes = old_hwif.atapi_input_bytes;
1022 hwif->atapi_output_bytes = old_hwif.atapi_output_bytes;
1026 hwif->dmaops = old_hwif.dmaops;
1028 hwif->ide_dma_read = old_hwif.ide_dma_read;
1029 hwif->ide_dma_write = old_hwif.ide_dma_write;
1030 hwif->ide_dma_begin = old_hwif.ide_dma_begin;
1031 hwif->ide_dma_end = old_hwif.ide_dma_end;
1032 hwif->ide_dma_check = old_hwif.ide_dma_check;
1033 hwif->ide_dma_on = old_hwif.ide_dma_on;
1034 hwif->ide_dma_off = old_hwif.ide_dma_off;
1035 hwif->ide_dma_off_quietly = old_hwif.ide_dma_off_quietly;
1036 hwif->ide_dma_test_irq = old_hwif.ide_dma_test_irq;
1037 hwif->ide_dma_host_on = old_hwif.ide_dma_host_on;
1038 hwif->ide_dma_host_off = old_hwif.ide_dma_host_off;
1039 hwif->ide_dma_bad_drive = old_hwif.ide_dma_bad_drive;
1040 hwif->ide_dma_good_drive = old_hwif.ide_dma_good_drive;
1041 hwif->ide_dma_count = old_hwif.ide_dma_count;
1042 hwif->ide_dma_verbose = old_hwif.ide_dma_verbose;
1043 hwif->ide_dma_retune = old_hwif.ide_dma_retune;
1044 hwif->ide_dma_lostirq = old_hwif.ide_dma_lostirq;
1045 hwif->ide_dma_timeout = old_hwif.ide_dma_timeout;
1049 hwif->iops = old_hwif.iops;
1051 hwif->OUTB = old_hwif.OUTB;
1052 hwif->OUTBSYNC = old_hwif.OUTBSYNC;
1053 hwif->OUTW = old_hwif.OUTW;
1054 hwif->OUTL = old_hwif.OUTL;
1055 hwif->OUTSW = old_hwif.OUTSW;
1056 hwif->OUTSL = old_hwif.OUTSL;
1058 hwif->INB = old_hwif.INB;
1059 hwif->INW = old_hwif.INW;
1060 hwif->INL = old_hwif.INL;
1061 hwif->INSW = old_hwif.INSW;
1062 hwif->INSL = old_hwif.INSL;
1065 hwif->mmio = old_hwif.mmio;
1066 hwif->rqsize = old_hwif.rqsize;
1067 hwif->addressing = old_hwif.addressing;
1068 #ifndef CONFIG_BLK_DEV_IDECS
1069 hwif->irq = old_hwif.irq;
1070 #endif /* CONFIG_BLK_DEV_IDECS */
1071 hwif->initializing = old_hwif.initializing;
1073 hwif->dma_base = old_hwif.dma_base;
1074 hwif->dma_master = old_hwif.dma_master;
1075 hwif->dma_command = old_hwif.dma_command;
1076 hwif->dma_vendor1 = old_hwif.dma_vendor1;
1077 hwif->dma_status = old_hwif.dma_status;
1078 hwif->dma_vendor3 = old_hwif.dma_vendor3;
1079 hwif->dma_prdtable = old_hwif.dma_prdtable;
1081 hwif->dma_extra = old_hwif.dma_extra;
1082 hwif->config_data = old_hwif.config_data;
1083 hwif->select_data = old_hwif.select_data;
1084 hwif->autodma = old_hwif.autodma;
1085 hwif->udma_four = old_hwif.udma_four;
1086 hwif->no_dsc = old_hwif.no_dsc;
1088 hwif->hwif_data = old_hwif.hwif_data;
1089 spin_unlock_irqrestore(&io_request_lock, flags);
1093 spin_unlock_irqrestore(&io_request_lock, flags);
1098 EXPORT_SYMBOL(ide_unregister);
1101 * Setup hw_regs_t structure described by parameters. You
1102 * may set up the hw structure yourself OR use this routine to
1105 void ide_setup_ports ( hw_regs_t *hw,
1106 ide_ioreg_t base, int *offsets,
1107 ide_ioreg_t ctrl, ide_ioreg_t intr,
1108 ide_ack_intr_t *ack_intr,
1110 * ide_io_ops_t *iops,
1116 for (i = 0; i < IDE_NR_PORTS; i++) {
1117 if (offsets[i] == -1) {
1119 case IDE_CONTROL_OFFSET:
1120 hw->io_ports[i] = ctrl;
1122 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
1123 case IDE_IRQ_OFFSET:
1124 hw->io_ports[i] = intr;
1126 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
1128 hw->io_ports[i] = 0;
1132 hw->io_ports[i] = base + offsets[i];
1137 hw->ack_intr = ack_intr;
1143 EXPORT_SYMBOL(ide_setup_ports);
1146 * Register an IDE interface, specifing exactly the registers etc
1147 * Set init=1 iff calling before probes have taken place.
1149 int ide_register_hw (hw_regs_t *hw, ide_hwif_t **hwifp)
1151 int index, retry = 1;
1155 for (index = 0; index < MAX_HWIFS; ++index) {
1156 hwif = &ide_hwifs[index];
1157 if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
1160 for (index = 0; index < MAX_HWIFS; ++index) {
1161 hwif = &ide_hwifs[index];
1162 if (!hwif->hold && ((!hwif->present && !hwif->mate && !initializing) ||
1163 (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing)))
1166 for (index = 0; index < MAX_HWIFS; index++)
1167 ide_unregister(index);
1172 ide_unregister(index);
1173 else if (!hwif->hold)
1174 init_hwif_data(index);
1177 memcpy(&hwif->hw, hw, sizeof(*hw));
1178 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
1179 hwif->irq = hw->irq;
1181 hwif->chipset = hw->chipset;
1183 if (!initializing) {
1184 ide_probe_module(1);
1185 #ifdef CONFIG_PROC_FS
1186 create_proc_ide_interfaces();
1188 ide_driver_module(1);
1194 return (initializing || hwif->present) ? index : -1;
1197 EXPORT_SYMBOL(ide_register_hw);
1200 * Compatability function with existing drivers. If you want
1201 * something different, use the function above.
1203 int ide_register (int arg1, int arg2, int irq)
1206 ide_init_hwif_ports(&hw, (ide_ioreg_t) arg1, (ide_ioreg_t) arg2, NULL);
1208 return ide_register_hw(&hw, NULL);
1211 EXPORT_SYMBOL(ide_register);
1215 * Locks for IDE setting functionality
1218 DECLARE_MUTEX(ide_setting_sem);
1219 EXPORT_SYMBOL(ide_setting_sem);
1222 * ide_add_setting - add an ide setting option
1223 * @drive: drive to use
1224 * @name: setting name
1225 * @rw: true if the function is read write
1226 * @read_ioctl: function to call on read
1227 * @write_ioctl: function to call on write
1228 * @data_type: type of data
1229 * @min: range minimum
1230 * @max: range maximum
1231 * @mul_factor: multiplication scale
1232 * @div_factor: divison scale
1233 * @data: private data field
1236 * Removes the setting named from the device if it is present.
1237 * The function takes the settings_lock to protect against
1238 * parallel changes. This function must not be called from IRQ
1239 * context. Returns 0 on success or -1 on failure.
1241 * BUGS: This code is seriously over-engineered. There is also
1242 * magic about how the driver specific features are setup. If
1243 * a driver is attached we assume the driver settings are auto
1247 int ide_add_setting (ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
1249 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
1251 down(&ide_setting_sem);
1252 while ((*p) && strcmp((*p)->name, name) < 0)
1254 if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
1256 memset(setting, 0, sizeof(*setting));
1257 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
1259 strcpy(setting->name, name);
1261 setting->read_ioctl = read_ioctl;
1262 setting->write_ioctl = write_ioctl;
1263 setting->data_type = data_type;
1266 setting->mul_factor = mul_factor;
1267 setting->div_factor = div_factor;
1268 setting->data = data;
1272 if (drive->driver != &idedefault_driver)
1273 setting->auto_remove = 1;
1275 up(&ide_setting_sem);
1278 up(&ide_setting_sem);
1284 EXPORT_SYMBOL(ide_add_setting);
1287 * __ide_remove_setting - remove an ide setting option
1288 * @drive: drive to use
1289 * @name: setting name
1291 * Removes the setting named from the device if it is present.
1292 * The caller must hold the setting semaphore.
1295 static void __ide_remove_setting (ide_drive_t *drive, char *name)
1297 ide_settings_t **p, *setting;
1299 p = (ide_settings_t **) &drive->settings;
1301 while ((*p) && strcmp((*p)->name, name))
1303 if ((setting = (*p)) == NULL)
1306 (*p) = setting->next;
1308 kfree(setting->name);
1313 * ide_remove_setting - remove an ide setting option
1314 * @drive: drive to use
1315 * @name: setting name
1317 * Removes the setting named from the device if it is present.
1318 * The function takes the settings_lock to protect against
1319 * parallel changes. This function must not be called from IRQ
1323 void ide_remove_setting (ide_drive_t *drive, char *name)
1325 down(&ide_setting_sem);
1326 __ide_remove_setting(drive, name);
1327 up(&ide_setting_sem);
1330 EXPORT_SYMBOL(ide_remove_setting);
1333 * ide_find_setting_by_ioctl - find a drive specific ioctl
1334 * @drive: drive to scan
1335 * @cmd: ioctl command to handle
1337 * Scan's the device setting table for a matching entry and returns
1338 * this or NULL if no entry is found. The caller must hold the
1342 static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
1344 ide_settings_t *setting = drive->settings;
1347 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
1349 setting = setting->next;
1356 * ide_find_setting_by_name - find a drive specific setting
1357 * @drive: drive to scan
1358 * @name: setting name
1360 * Scan's the device setting table for a matching entry and returns
1361 * this or NULL if no entry is found. The caller must hold the
1365 ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
1367 ide_settings_t *setting = drive->settings;
1370 if (strcmp(setting->name, name) == 0)
1372 setting = setting->next;
1378 * auto_remove_settings - remove driver specific settings
1381 * Automatically remove all the driver specific settings for this
1382 * drive. This function may sleep and must not be called from IRQ
1383 * context. Caller must hold the setting lock.
1386 static void auto_remove_settings (ide_drive_t *drive)
1388 ide_settings_t *setting;
1390 setting = drive->settings;
1392 if (setting->auto_remove) {
1393 __ide_remove_setting(drive, setting->name);
1396 setting = setting->next;
1401 * ide_read_setting - read an IDE setting
1402 * @drive: drive to read from
1403 * @setting: drive setting
1405 * Read a drive setting and return the value. The caller
1406 * must hold the ide_setting_sem when making this call.
1408 * BUGS: the data return and error are the same return value
1409 * so an error -EINVAL and true return of the same value cannot
1413 int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1416 unsigned long flags;
1418 if ((setting->rw & SETTING_READ)) {
1419 spin_lock_irqsave(&io_request_lock, flags);
1420 switch(setting->data_type) {
1422 val = *((u8 *) setting->data);
1425 val = *((u16 *) setting->data);
1429 val = *((u32 *) setting->data);
1432 spin_unlock_irqrestore(&io_request_lock, flags);
1437 int ide_spin_wait_hwgroup (ide_drive_t *drive)
1439 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1440 unsigned long timeout = jiffies + (3 * HZ);
1442 spin_lock_irq(&io_request_lock);
1444 while (hwgroup->busy) {
1445 unsigned long lflags;
1446 spin_unlock_irq(&io_request_lock);
1447 local_irq_set(lflags);
1448 if (time_after(jiffies, timeout)) {
1449 local_irq_restore(lflags);
1450 printk(KERN_ERR "%s: channel busy\n", drive->name);
1453 local_irq_restore(lflags);
1454 spin_lock_irq(&io_request_lock);
1459 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1462 * ide_write_setting - read an IDE setting
1463 * @drive: drive to read from
1464 * @setting: drive setting
1467 * Write a drive setting if it is possible. The caller
1468 * must hold the ide_setting_sem when making this call.
1470 * BUGS: the data return and error are the same return value
1471 * so an error -EINVAL and true return of the same value cannot
1474 * FIXME: This should be changed to enqueue a special request
1475 * to the driver to change settings, and then wait on a sema for completion.
1476 * The current scheme of polling is kludgy, though safe enough.
1478 int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1483 if (!capable(CAP_SYS_ADMIN))
1485 if (!(setting->rw & SETTING_WRITE))
1487 if (val < setting->min || val > setting->max)
1490 return setting->set(drive, val);
1491 if (ide_spin_wait_hwgroup(drive))
1493 switch (setting->data_type) {
1495 *((u8 *) setting->data) = val;
1498 *((u16 *) setting->data) = val;
1501 *((u32 *) setting->data) = val;
1504 p = (u32 *) setting->data;
1505 for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1509 spin_unlock_irq(&io_request_lock);
1513 EXPORT_SYMBOL(ide_write_setting);
1515 static int set_io_32bit(ide_drive_t *drive, int arg)
1517 drive->io_32bit = arg;
1518 #ifdef CONFIG_BLK_DEV_DTC2278
1519 if (HWIF(drive)->chipset == ide_dtc2278)
1520 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1521 #endif /* CONFIG_BLK_DEV_DTC2278 */
1525 static int set_using_dma (ide_drive_t *drive, int arg)
1527 if (!DRIVER(drive)->supports_dma)
1529 if (!(drive->id->capability & 1))
1531 if (HWIF(drive)->ide_dma_check == NULL)
1533 if (HWIF(drive)->ide_dma_check(drive) != 0)
1536 if (HWIF(drive)->ide_dma_check(drive) != 0)
1538 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1540 if (HWIF(drive)->ide_dma_off(drive)) return -EIO;
1545 static int set_pio_mode (ide_drive_t *drive, int arg)
1549 if (!HWIF(drive)->tuneproc)
1551 if (drive->special.b.set_tune)
1553 ide_init_drive_cmd(&rq);
1554 drive->tune_req = (u8) arg;
1555 drive->special.b.set_tune = 1;
1556 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1560 static int set_xfer_rate (ide_drive_t *drive, int arg)
1562 int err = ide_wait_cmd(drive,
1563 WIN_SETFEATURES, (u8) arg,
1564 SETFEATURES_XFER, 0, NULL);
1567 ide_set_xfer_rate(drive, (u8) arg);
1568 ide_driveid_update(drive);
1573 int ide_atapi_to_scsi (ide_drive_t *drive, int arg)
1575 if (drive->media == ide_disk) {
1579 if (DRIVER(drive)->cleanup(drive)) {
1583 drive->scsi = (u8) arg;
1584 ide_attach_drive(drive);
1588 void ide_add_generic_settings (ide_drive_t *drive)
1591 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1593 ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, HDIO_GET_32BIT, HDIO_SET_32BIT, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit);
1594 ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL);
1595 ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL);
1596 ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode);
1597 ide_add_setting(drive, "slow", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->slow, NULL);
1598 ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL);
1599 ide_add_setting(drive, "using_dma", SETTING_RW, HDIO_GET_DMA, HDIO_SET_DMA, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma);
1600 ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL);
1601 ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate);
1602 ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL);
1604 /* Experimental, but this needs the setting/register locking rewritten to be used */
1605 if (drive->media != ide_disk)
1606 ide_add_setting(drive, "ide-scsi", SETTING_RW, -1, HDIO_SET_IDE_SCSI, TYPE_BYTE, 0, 1, 1, 1, &drive->scsi, ide_atapi_to_scsi);
1610 EXPORT_SYMBOL_GPL(ide_add_generic_settings);
1613 * Delay for *at least* 50ms. As we don't know how much time is left
1614 * until the next tick occurs, we wait an extra tick to be safe.
1615 * This is used only during the probing/polling for drives at boot time.
1617 * However, its usefullness may be needed in other places, thus we export it now.
1618 * The future may change this to a millisecond setable delay.
1620 void ide_delay_50ms (void)
1622 #ifndef CONFIG_BLK_DEV_IDECS
1625 __set_current_state(TASK_UNINTERRUPTIBLE);
1626 schedule_timeout(1+HZ/20);
1627 #endif /* CONFIG_BLK_DEV_IDECS */
1630 EXPORT_SYMBOL(ide_delay_50ms);
1632 int system_bus_clock (void)
1634 return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1637 EXPORT_SYMBOL(system_bus_clock);
1639 int ide_replace_subdriver (ide_drive_t *drive, const char *driver)
1641 if (!drive->present || drive->busy || drive->usage || drive->dead)
1643 if (DRIVER(drive)->cleanup(drive))
1645 strncpy(drive->driver_req, driver, 9);
1646 ide_driver_module(0);
1647 drive->driver_req[0] = 0;
1648 ide_driver_module(0);
1649 if (!strcmp(DRIVER(drive)->name, driver))
1655 EXPORT_SYMBOL(ide_replace_subdriver);
1657 int ide_attach_drive (ide_drive_t *drive)
1659 /* Someone unplugged the device on us */
1663 #ifdef CONFIG_BLK_DEV_IDESCSI
1665 extern int idescsi_attach(ide_drive_t *drive);
1666 if (idescsi_attach(drive))
1669 #endif /* CONFIG_BLK_DEV_IDESCSI */
1671 switch (drive->media) {
1672 #ifdef CONFIG_BLK_DEV_IDECD
1675 extern int ide_cdrom_attach(ide_drive_t *drive);
1676 if (ide_cdrom_attach(drive))
1680 #endif /* CONFIG_BLK_DEV_IDECD */
1681 #ifdef CONFIG_BLK_DEV_IDEDISK
1684 extern int idedisk_attach(ide_drive_t *drive);
1685 if (idedisk_attach(drive))
1689 #endif /* CONFIG_BLK_DEV_IDEDISK */
1690 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
1693 extern int idefloppy_attach(ide_drive_t *drive);
1694 if (idefloppy_attach(drive))
1698 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
1699 #ifdef CONFIG_BLK_DEV_IDETAPE
1702 extern int idetape_attach(ide_drive_t *drive);
1703 if (idetape_attach(drive))
1707 #endif /* CONFIG_BLK_DEV_IDETAPE */
1710 extern int idedefault_attach(ide_drive_t *drive);
1711 if(idedefault_attach(drive))
1712 printk(KERN_CRIT "ide: failed to attach default driver.\n");
1719 EXPORT_SYMBOL(ide_attach_drive);
1721 static int ide_ioctl (struct inode *inode, struct file *file,
1722 unsigned int cmd, unsigned long arg)
1724 int err = 0, major, minor;
1728 ide_settings_t *setting;
1731 if (!inode || !(dev = inode->i_rdev))
1736 case HDIO_GET_BUSSTATE:
1737 case HDIO_SET_BUSSTATE:
1738 case HDIO_SCAN_HWIF:
1739 case HDIO_UNREGISTER_HWIF:
1743 major = MAJOR(dev); minor = MINOR(dev);
1744 if ((drive = ide_info_ptr(inode->i_rdev, force)) == NULL)
1747 down(&ide_setting_sem);
1748 if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1749 if (cmd == setting->read_ioctl) {
1750 err = ide_read_setting(drive, setting);
1751 up(&ide_setting_sem);
1752 return err >= 0 ? put_user(err, (long *) arg) : err;
1754 if ((MINOR(inode->i_rdev) & PARTN_MASK))
1757 err = ide_write_setting(drive, setting, arg);
1758 up(&ide_setting_sem);
1762 up(&ide_setting_sem);
1764 ide_init_drive_cmd (&rq);
1768 struct hd_geometry *loc = (struct hd_geometry *) arg;
1769 u16 bios_cyl = drive->bios_cyl; /* truncate */
1770 if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1771 if (put_user(drive->bios_head, (u8 *) &loc->heads)) return -EFAULT;
1772 if (put_user(drive->bios_sect, (u8 *) &loc->sectors)) return -EFAULT;
1773 if (put_user(bios_cyl, (u16 *) &loc->cylinders)) return -EFAULT;
1774 if (put_user((unsigned)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].start_sect,
1775 (unsigned long *) &loc->start)) return -EFAULT;
1779 case HDIO_GETGEO_BIG:
1781 struct hd_big_geometry *loc = (struct hd_big_geometry *) arg;
1782 if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1783 if (put_user(drive->bios_head, (u8 *) &loc->heads)) return -EFAULT;
1784 if (put_user(drive->bios_sect, (u8 *) &loc->sectors)) return -EFAULT;
1785 if (put_user(drive->bios_cyl, (unsigned int *) &loc->cylinders)) return -EFAULT;
1786 if (put_user((unsigned)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].start_sect,
1787 (unsigned long *) &loc->start)) return -EFAULT;
1791 case HDIO_GETGEO_BIG_RAW:
1793 struct hd_big_geometry *loc = (struct hd_big_geometry *) arg;
1794 if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1795 if (put_user(drive->head, (u8 *) &loc->heads)) return -EFAULT;
1796 if (put_user(drive->sect, (u8 *) &loc->sectors)) return -EFAULT;
1797 if (put_user(drive->cyl, (unsigned int *) &loc->cylinders)) return -EFAULT;
1798 if (put_user((unsigned)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].start_sect,
1799 (unsigned long *) &loc->start)) return -EFAULT;
1803 case BLKGETSIZE: /* Return device size */
1804 return put_user(drive->part[MINOR(inode->i_rdev)&PARTN_MASK].nr_sects, (unsigned long *) arg);
1806 return put_user((u64)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].nr_sects << 9, (u64 *) arg);
1808 case BLKRRPART: /* Re-read partition tables */
1809 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1810 return ide_revalidate_disk(inode->i_rdev);
1812 case HDIO_OBSOLETE_IDENTITY:
1813 case HDIO_GET_IDENTITY:
1814 if (MINOR(inode->i_rdev) & PARTN_MASK)
1816 if (drive->id_read == 0)
1818 if (copy_to_user((char *)arg, (char *)drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1823 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
1824 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
1825 drive->nice0 << IDE_NICE_0 |
1826 drive->nice1 << IDE_NICE_1 |
1827 drive->nice2 << IDE_NICE_2,
1830 #ifdef CONFIG_IDE_TASK_IOCTL
1831 case HDIO_DRIVE_TASKFILE:
1832 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1834 switch(drive->media) {
1836 return ide_taskfile_ioctl(drive, inode, file, cmd, arg);
1837 #ifdef CONFIG_PKT_TASK_IOCTL
1841 return pkt_taskfile_ioctl(drive, inode, file, cmd, arg);
1842 #endif /* CONFIG_PKT_TASK_IOCTL */
1846 #endif /* CONFIG_IDE_TASK_IOCTL */
1848 case HDIO_DRIVE_CMD:
1849 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1851 return ide_cmd_ioctl(drive, inode, file, cmd, arg);
1853 case HDIO_DRIVE_TASK:
1854 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1856 return ide_task_ioctl(drive, inode, file, cmd, arg);
1858 case HDIO_SCAN_HWIF:
1861 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1862 if (copy_from_user(args, (void *)arg, 3 * sizeof(int)))
1864 if (ide_register(args[0], args[1], args[2]) == -1)
1868 case HDIO_UNREGISTER_HWIF:
1869 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1870 /* (arg > MAX_HWIFS) checked in function */
1871 ide_unregister(arg);
1874 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1875 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1877 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1878 if (drive->dsc_overlap && !DRIVER(drive)->supports_dsc_overlap) {
1879 drive->dsc_overlap = 0;
1882 drive->nice1 = (arg >> IDE_NICE_1) & 1;
1884 case HDIO_DRIVE_RESET:
1886 unsigned long flags;
1887 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1890 * Abort the current command on the
1891 * group if there is one, taking
1892 * care not to allow anything else
1893 * to be queued and to die on the
1894 * spot if we miss one somehow
1897 spin_lock_irqsave(&io_request_lock, flags);
1899 DRIVER(drive)->abort(drive, "drive reset");
1900 if(HWGROUP(drive)->handler)
1903 /* Ensure nothing gets queued after we
1904 drop the lock. Reset will clear the busy */
1906 HWGROUP(drive)->busy = 1;
1907 spin_unlock_irqrestore(&io_request_lock, flags);
1909 (void) ide_do_reset(drive);
1910 if (drive->suspend_reset) {
1912 * APM WAKE UP todo !!
1913 * int nogoodpower = 1;
1914 * while(nogoodpower) {
1915 * check_power1() or check_power2()
1918 * HWIF(drive)->multiproc(drive);
1920 return ide_revalidate_disk(inode->i_rdev);
1933 return blk_ioctl(inode->i_rdev, cmd, arg);
1935 case HDIO_GET_BUSSTATE:
1936 if (!capable(CAP_SYS_ADMIN))
1938 if (put_user(HWIF(drive)->bus_state, (long *)arg))
1942 case HDIO_SET_BUSSTATE:
1944 ide_hwif_t *hwif = HWIF(drive);
1946 if (!capable(CAP_SYS_ADMIN))
1950 return HWIF(drive)->busproc(drive, (int)arg);
1953 if(hwif->bus_state == arg)
1956 if(hwif->bus_state == BUSSTATE_ON)
1958 /* "drive" may vanish beyond here */
1959 if((err = ide_prepare_tristate(drive)) != 0)
1961 hwif->bus_state = arg;
1965 err = hwif->busproc(drive, (int)arg);
1969 if(arg != BUSSTATE_OFF)
1971 err = ide_resume_hwif(drive);
1972 hwif->bus_state = arg;
1981 return DRIVER(drive)->ioctl(drive, inode, file, cmd, arg);
1986 static int ide_check_media_change (kdev_t i_rdev)
1990 if ((drive = ide_info_ptr(i_rdev, 0)) == NULL)
1992 return DRIVER(drive)->media_change(drive);
1996 * stridx() returns the offset of c within s,
1997 * or -1 if c is '\0' or not found within s.
1999 static int __init stridx (const char *s, char c)
2001 char *i = strchr(s, c);
2002 return (i && c) ? i - s : -1;
2006 * match_parm() does parsing for ide_setup():
2008 * 1. the first char of s must be '='.
2009 * 2. if the remainder matches one of the supplied keywords,
2010 * the index (1 based) of the keyword is negated and returned.
2011 * 3. if the remainder is a series of no more than max_vals numbers
2012 * separated by commas, the numbers are saved in vals[] and a
2013 * count of how many were saved is returned. Base10 is assumed,
2014 * and base16 is allowed when prefixed with "0x".
2015 * 4. otherwise, zero is returned.
2017 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
2019 static const char *decimal = "0123456789";
2020 static const char *hex = "0123456789abcdef";
2025 * Try matching against the supplied keywords,
2026 * and return -(index+1) if we match one
2028 if (keywords != NULL) {
2029 for (i = 0; *keywords != NULL; ++i) {
2030 if (!strcmp(s, *keywords++))
2035 * Look for a series of no more than "max_vals"
2036 * numeric values separated by commas, in base10,
2037 * or base16 when prefixed with "0x".
2038 * Return a count of how many were found.
2040 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
2042 while ((i = stridx(decimal, *++s)) >= 0)
2043 vals[n] = (vals[n] * 10) + i;
2044 if (*s == 'x' && !vals[n]) {
2045 while ((i = stridx(hex, *++s)) >= 0)
2046 vals[n] = (vals[n] * 0x10) + i;
2048 if (++n == max_vals)
2050 if (*s == ',' || *s == ';')
2056 return 0; /* zero = nothing matched */
2060 * ide_setup() gets called VERY EARLY during initialization,
2061 * to handle kernel "command line" strings beginning with "hdx="
2062 * or "ide". Here is the complete set currently supported:
2064 * "hdx=" is recognized for all "x" from "a" to "h", such as "hdc".
2065 * "idex=" is recognized for all "x" from "0" to "3", such as "ide1".
2067 * "hdx=noprobe" : drive may be present, but do not probe for it
2068 * "hdx=none" : drive is NOT present, ignore cmos and do not probe
2069 * "hdx=nowerr" : ignore the WRERR_STAT bit on this drive
2070 * "hdx=cdrom" : drive is present, and is a cdrom drive
2071 * "hdx=cyl,head,sect" : disk drive is present, with specified geometry
2072 * "hdx=noremap" : do not remap 0->1 even though EZD was detected
2073 * "hdx=autotune" : driver will attempt to tune interface speed
2074 * to the fastest PIO mode supported,
2075 * if possible for this drive only.
2076 * Not fully supported by all chipset types,
2077 * and quite likely to cause trouble with
2078 * older/odd IDE drives.
2080 * "hdx=slow" : insert a huge pause after each access to the data
2081 * port. Should be used only as a last resort.
2083 * "hdx=swapdata" : when the drive is a disk, byte swap all data
2084 * "hdx=bswap" : same as above..........
2085 * "hdxlun=xx" : set the drive last logical unit.
2086 * "hdx=flash" : allows for more than one ata_flash disk to be
2087 * registered. In most cases, only one device
2089 * "hdx=scsi" : the return of the ide-scsi flag, this is useful for
2090 * allowwing ide-floppy, ide-tape, and ide-cdrom|writers
2091 * to use ide-scsi emulation on a device specific option.
2092 * "idebus=xx" : inform IDE driver of VESA/PCI bus speed in MHz,
2093 * where "xx" is between 20 and 66 inclusive,
2094 * used when tuning chipset PIO modes.
2095 * For PCI bus, 25 is correct for a P75 system,
2096 * 30 is correct for P90,P120,P180 systems,
2097 * and 33 is used for P100,P133,P166 systems.
2098 * If in doubt, use idebus=33 for PCI.
2099 * As for VLB, it is safest to not specify it.
2101 * "idex=noprobe" : do not attempt to access/use this interface
2102 * "idex=base" : probe for an interface at the addr specified,
2103 * where "base" is usually 0x1f0 or 0x170
2104 * and "ctl" is assumed to be "base"+0x206
2105 * "idex=base,ctl" : specify both base and ctl
2106 * "idex=base,ctl,irq" : specify base, ctl, and irq number
2107 * "idex=autotune" : driver will attempt to tune interface speed
2108 * to the fastest PIO mode supported,
2109 * for all drives on this interface.
2110 * Not fully supported by all chipset types,
2111 * and quite likely to cause trouble with
2112 * older/odd IDE drives.
2113 * "idex=noautotune" : driver will NOT attempt to tune interface speed
2114 * This is the default for most chipsets,
2115 * except the cmd640.
2116 * "idex=serialize" : do not overlap operations on idex and ide(x^1)
2117 * "idex=four" : four drives on idex and ide(x^1) share same ports
2118 * "idex=reset" : reset interface before first use
2119 * "idex=dma" : enable DMA by default on both drives if possible
2120 * "idex=ata66" : informs the interface that it has an 80c cable
2121 * for chipsets that are ATA-66 capable, but
2122 * the ablity to bit test for detection is
2123 * currently unknown.
2124 * "ide=reverse" : Formerly called to pci sub-system, but now local.
2126 * The following are valid ONLY on ide0, (except dc4030)
2127 * and the defaults for the base,ctl ports must not be altered.
2129 * "ide0=dtc2278" : probe/support DTC2278 interface
2130 * "ide0=ht6560b" : probe/support HT6560B interface
2131 * "ide0=cmd640_vlb" : *REQUIRED* for VLB cards with the CMD640 chip
2132 * (not for PCI -- automatically detected)
2133 * "ide0=qd65xx" : probe/support qd65xx interface
2134 * "ide0=ali14xx" : probe/support ali14xx chipsets (ALI M1439, M1443, M1445)
2135 * "ide0=umc8672" : probe/support umc8672 chipsets
2136 * "idex=dc4030" : probe/support Promise DC4030VL interface
2137 * "ide=doubler" : probe/support IDE doublers on Amiga
2139 int __init ide_setup (char *s)
2144 unsigned int hw, unit;
2145 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
2146 const char max_hwif = '0' + (MAX_HWIFS - 1);
2149 if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
2150 return 0; /* driver and not us */
2152 if (strncmp(s,"ide",3) &&
2153 strncmp(s,"idebus",6) &&
2154 strncmp(s,"hd",2)) /* hdx= & hdxlun= */
2157 printk(KERN_INFO "ide_setup: %s", s);
2160 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
2161 if (!strcmp(s, "ide=doubler")) {
2162 extern int ide_doubler;
2164 printk(" : Enabled support for IDE doublers\n");
2168 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
2170 if (!strcmp(s, "ide=nodma")) {
2171 printk(" : Prevented DMA\n");
2176 #ifdef CONFIG_BLK_DEV_IDEPCI
2177 if (!strcmp(s, "ide=reverse")) {
2178 ide_scan_direction = 1;
2179 printk(" : Enabled support for IDE inverse scan order.\n");
2182 #endif /* CONFIG_BLK_DEV_IDEPCI */
2185 * Look for drive options: "hdx="
2187 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
2188 const char *hd_words[] = {"none", "noprobe", "nowerr", "cdrom",
2189 "serialize", "autotune", "noautotune",
2190 "slow", "swapdata", "bswap", "flash",
2191 "remap", "noremap", "scsi", NULL};
2193 hw = unit / MAX_DRIVES;
2194 unit = unit % MAX_DRIVES;
2195 hwif = &ide_hwifs[hw];
2196 drive = &hwif->drives[unit];
2197 if (strncmp(s + 4, "ide-", 4) == 0) {
2198 strncpy(drive->driver_req, s + 4, 9);
2202 * Look for last lun option: "hdxlun="
2204 if (s[3] == 'l' && s[4] == 'u' && s[5] == 'n') {
2205 if (match_parm(&s[6], NULL, vals, 1) != 1)
2207 if (vals[0] >= 0 && vals[0] <= 7) {
2208 drive->last_lun = vals[0];
2209 drive->forced_lun = 1;
2211 printk(" -- BAD LAST LUN! Expected value from 0 to 7");
2214 switch (match_parm(&s[3], hd_words, vals, 3)) {
2215 case -1: /* "none" */
2216 drive->nobios = 1; /* drop into "noprobe" */
2217 case -2: /* "noprobe" */
2220 case -3: /* "nowerr" */
2221 drive->bad_wstat = BAD_R_STAT;
2224 case -4: /* "cdrom" */
2226 drive->media = ide_cdrom;
2229 case -5: /* "serialize" */
2230 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
2232 case -6: /* "autotune" */
2233 drive->autotune = 1;
2235 case -7: /* "noautotune" */
2236 drive->autotune = 2;
2238 case -8: /* "slow" */
2241 case -9: /* "swapdata" or "bswap" */
2245 case -11: /* "flash" */
2246 drive->ata_flash = 1;
2248 case -12: /* "remap" */
2249 drive->remap_0_to_1 = 1;
2251 case -13: /* "noremap" */
2252 drive->remap_0_to_1 = 2;
2254 case -14: /* "scsi" */
2257 case 3: /* cyl,head,sect */
2258 drive->media = ide_disk;
2259 drive->cyl = drive->bios_cyl = vals[0];
2260 drive->head = drive->bios_head = vals[1];
2261 drive->sect = drive->bios_sect = vals[2];
2263 drive->forced_geom = 1;
2271 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
2274 * Look for bus speed option: "idebus="
2276 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
2277 if (match_parm(&s[6], NULL, vals, 1) != 1)
2279 if (vals[0] >= 20 && vals[0] <= 66) {
2280 idebus_parameter = vals[0];
2282 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
2286 * Look for interface options: "idex="
2288 if (s[3] >= '0' && s[3] <= max_hwif) {
2290 * Be VERY CAREFUL changing this: note hardcoded indexes below
2291 * -8,-9,-10 : are reserved for future idex calls to ease the hardcoding.
2293 const char *ide_words[] = {
2294 "noprobe", "serialize", "autotune", "noautotune", "reset", "dma", "ata66",
2295 "minus8", "minus9", "minus10",
2296 "four", "qd65xx", "ht6560b", "cmd640_vlb", "dtc2278", "umc8672", "ali14xx", "dc4030", NULL };
2298 hwif = &ide_hwifs[hw];
2299 i = match_parm(&s[4], ide_words, vals, 3);
2302 * Cryptic check to ensure chipset not already set for hwif:
2304 if (i > 0 || i <= -11) { /* is parameter a chipset name? */
2305 if (hwif->chipset != ide_unknown)
2306 goto bad_option; /* chipset already specified */
2307 if (i <= -11 && i != -18 && hw != 0)
2308 goto bad_hwif; /* chipset drivers are for "ide0=" only */
2309 if (i <= -11 && i != -18 && ide_hwifs[hw+1].chipset != ide_unknown)
2310 goto bad_option; /* chipset for 2nd port already specified */
2315 #ifdef CONFIG_BLK_DEV_PDC4030
2316 case -18: /* "dc4030" */
2318 extern void init_pdc4030(void);
2322 #endif /* CONFIG_BLK_DEV_PDC4030 */
2323 #ifdef CONFIG_BLK_DEV_ALI14XX
2324 case -17: /* "ali14xx" */
2326 extern void init_ali14xx (void);
2330 #endif /* CONFIG_BLK_DEV_ALI14XX */
2331 #ifdef CONFIG_BLK_DEV_UMC8672
2332 case -16: /* "umc8672" */
2334 extern void init_umc8672 (void);
2338 #endif /* CONFIG_BLK_DEV_UMC8672 */
2339 #ifdef CONFIG_BLK_DEV_DTC2278
2340 case -15: /* "dtc2278" */
2342 extern void init_dtc2278 (void);
2346 #endif /* CONFIG_BLK_DEV_DTC2278 */
2347 #ifdef CONFIG_BLK_DEV_CMD640
2348 case -14: /* "cmd640_vlb" */
2350 extern void init_cmd640_vlb (void);
2354 #endif /* CONFIG_BLK_DEV_CMD640 */
2355 #ifdef CONFIG_BLK_DEV_HT6560B
2356 case -13: /* "ht6560b" */
2358 extern void init_ht6560b (void);
2362 #endif /* CONFIG_BLK_DEV_HT6560B */
2363 #if CONFIG_BLK_DEV_QD65XX
2364 case -12: /* "qd65xx" */
2366 extern void init_qd65xx (void);
2370 #endif /* CONFIG_BLK_DEV_QD65XX */
2371 #ifdef CONFIG_BLK_DEV_4DRIVES
2372 case -11: /* "four" drives on one set of ports */
2374 ide_hwif_t *mate = &ide_hwifs[hw^1];
2375 mate->drives[0].select.all ^= 0x20;
2376 mate->drives[1].select.all ^= 0x20;
2377 hwif->chipset = mate->chipset = ide_4drives;
2378 mate->irq = hwif->irq;
2379 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
2382 #endif /* CONFIG_BLK_DEV_4DRIVES */
2383 case -10: /* minus10 */
2384 case -9: /* minus9 */
2385 case -8: /* minus8 */
2387 case -7: /* ata66 */
2388 #ifdef CONFIG_BLK_DEV_IDEPCI
2389 hwif->udma_four = 1;
2391 #else /* !CONFIG_BLK_DEV_IDEPCI */
2392 hwif->udma_four = 0;
2394 #endif /* CONFIG_BLK_DEV_IDEPCI */
2398 case -5: /* "reset" */
2401 case -4: /* "noautotune" */
2402 hwif->drives[0].autotune = 2;
2403 hwif->drives[1].autotune = 2;
2405 case -3: /* "autotune" */
2406 hwif->drives[0].autotune = 1;
2407 hwif->drives[1].autotune = 1;
2409 case -2: /* "serialize" */
2411 hwif->mate = &ide_hwifs[hw^1];
2412 hwif->mate->mate = hwif;
2413 hwif->serialized = hwif->mate->serialized = 1;
2416 case -1: /* "noprobe" */
2421 vals[1] = vals[0] + 0x206; /* default ctl */
2422 case 2: /* base,ctl */
2423 vals[2] = 0; /* default irq = probe for it */
2424 case 3: /* base,ctl,irq */
2425 hwif->hw.irq = vals[2];
2426 ide_init_hwif_ports(&hwif->hw, (ide_ioreg_t) vals[0], (ide_ioreg_t) vals[1], &hwif->irq);
2427 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
2428 hwif->irq = vals[2];
2430 hwif->chipset = ide_generic;
2433 case 0: goto bad_option;
2435 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2440 printk(" -- BAD OPTION\n");
2443 printk("-- NOT SUPPORTED ON ide%d", hw);
2450 * Legacy interface registration
2452 #define NUM_DRIVER 32
2455 * Yes this is moronically simple, but why not - it works!
2458 static __initdata ide_driver_call ide_scan[NUM_DRIVER];
2459 static int drivers_run = 0;
2461 void __init ide_register_driver(ide_driver_call scan)
2463 static int ide_scans = 0;
2464 if(ide_scans == NUM_DRIVER)
2465 panic("Too many IDE drivers");
2466 ide_scan[ide_scans++]=scan;
2469 printk(KERN_ERR "ide: late registration of driver.\n");
2474 EXPORT_SYMBOL(ide_register_driver);
2476 static void __init ide_scan_drivers(void)
2488 * probe_for_hwifs() finds/initializes "known" IDE interfaces
2490 static void __init probe_for_hwifs (void)
2492 #ifdef CONFIG_BLK_DEV_IDEPCI
2495 ide_scan_pcibus(ide_scan_direction);
2497 #endif /* CONFIG_BLK_DEV_IDEPCI */
2501 * Unconverted drivers
2503 #ifdef CONFIG_ETRAX_IDE
2505 extern void init_e100_ide(void);
2508 #endif /* CONFIG_ETRAX_IDE */
2509 #ifdef CONFIG_BLK_DEV_IDE_PMAC
2511 extern void pmac_ide_probe(void);
2514 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
2515 #ifdef CONFIG_BLK_DEV_IDE_SIBYTE
2517 extern void sibyte_ide_probe(void);
2520 #endif /* CONFIG_BLK_DEV_IDE_SIBYTE */
2521 #ifdef CONFIG_BLK_DEV_IDE_ICSIDE
2523 extern void icside_init(void);
2526 #endif /* CONFIG_BLK_DEV_IDE_ICSIDE */
2527 #ifdef CONFIG_BLK_DEV_IDE_RAPIDE
2529 extern void rapide_init(void);
2532 #endif /* CONFIG_BLK_DEV_IDE_RAPIDE */
2533 #ifdef CONFIG_BLK_DEV_GAYLE
2535 extern void gayle_init(void);
2538 #endif /* CONFIG_BLK_DEV_GAYLE */
2539 #ifdef CONFIG_BLK_DEV_FALCON_IDE
2541 extern void falconide_init(void);
2544 #endif /* CONFIG_BLK_DEV_FALCON_IDE */
2545 #ifdef CONFIG_BLK_DEV_MAC_IDE
2547 extern void macide_init(void);
2550 #endif /* CONFIG_BLK_DEV_MAC_IDE */
2551 #ifdef CONFIG_BLK_DEV_CPCI405_IDE
2553 extern void cpci405ide_init(void);
2556 #endif /* CONFIG_BLK_DEV_CPCI405_IDE */
2557 #ifdef CONFIG_BLK_DEV_Q40IDE
2559 extern void q40ide_init(void);
2562 #endif /* CONFIG_BLK_DEV_Q40IDE */
2563 #ifdef CONFIG_BLK_DEV_BUDDHA
2565 extern void buddha_init(void);
2568 #endif /* CONFIG_BLK_DEV_BUDDHA */
2571 void __init ide_init_builtin_subdrivers (void)
2574 #ifdef CONFIG_BLK_DEV_IDEDISK
2575 (void) idedisk_init();
2576 #endif /* CONFIG_BLK_DEV_IDEDISK */
2577 #ifdef CONFIG_BLK_DEV_IDECD
2578 (void) ide_cdrom_init();
2579 #endif /* CONFIG_BLK_DEV_IDECD */
2580 #ifdef CONFIG_BLK_DEV_IDETAPE
2581 (void) idetape_init();
2582 #endif /* CONFIG_BLK_DEV_IDETAPE */
2583 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
2584 (void) idefloppy_init();
2585 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
2586 #ifdef CONFIG_BLK_DEV_IDESCSI
2588 (void) idescsi_init();
2590 #warning ide scsi-emulation selected but no SCSI-subsystem in kernel
2592 #endif /* CONFIG_BLK_DEV_IDESCSI */
2595 #ifndef CLASSIC_BUILTINS_METHOD
2596 # ifndef DIRECT_HWIF_PROBE_ATTACH_METHOD
2597 # ifdef FAKE_CLASSIC_ATTACH_METHOD
2599 * Attempt to match drivers for the available drives
2601 void ide_attach_devices (void)
2607 for (i = 0; i < MAX_HWIFS; i++) {
2608 hwif = &ide_hwifs[i];
2611 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2612 drive = &hwif->drives[unit];
2613 if (drive->present && !drive->dead)
2614 ide_attach_drive(drive);
2618 # endif /* FAKE_CLASSIC_ATTACH_METHOD */
2619 # endif /* DIRECT_HWIF_PROBE_ATTACH_METHOD */
2620 #endif /* CLASSIC_BUILTINS_METHOD */
2622 void __init ide_init_builtin_drivers (void)
2625 * Attach null driver
2629 * Probe for special PCI and other "known" interface chipsets
2633 #ifdef CONFIG_BLK_DEV_IDE
2634 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
2635 ide_get_lock(NULL, NULL); /* for atari only */
2637 (void) ideprobe_init();
2639 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
2640 ide_release_lock(); /* for atari only */
2641 #endif /* CONFIG_BLK_DEV_IDE */
2643 #ifdef CONFIG_PROC_FS
2647 #ifdef CLASSIC_BUILTINS_METHOD
2648 ide_init_builtin_subdrivers();
2649 #else /* ! CLASSIC_BUILTINS_METHOD */
2650 # ifndef DIRECT_HWIF_PROBE_ATTACH_METHOD
2651 # ifdef FAKE_CLASSIC_ATTACH_METHOD
2652 ide_attach_devices();
2653 # endif /* FAKE_CLASSIC_ATTACH_METHOD */
2654 # endif /* DIRECT_HWIF_PROBE_ATTACH_METHOD */
2655 #endif /* CLASSIC_BUILTINS_METHOD */
2659 * Actually unregister the subdriver. Called with the
2660 * request lock dropped.
2663 static int default_cleanup (ide_drive_t *drive)
2665 return ide_unregister_subdriver(drive);
2669 * Check if we can unregister the subdriver. Called with the
2670 * request lock held.
2673 static int default_shutdown(ide_drive_t *drive)
2675 if (drive->usage || drive->busy || DRIVER(drive)->busy) {
2682 static int default_standby (ide_drive_t *drive)
2687 static int default_suspend (ide_drive_t *drive)
2692 static int default_resume (ide_drive_t *drive)
2697 static int default_flushcache (ide_drive_t *drive)
2702 static ide_startstop_t default_do_request (ide_drive_t *drive, struct request *rq, unsigned long block)
2704 ide_end_request(drive, 0);
2708 static int default_end_request (ide_drive_t *drive, int uptodate)
2710 return ide_end_request(drive, uptodate);
2713 static u8 default_sense (ide_drive_t *drive, const char *msg, u8 stat)
2715 return ide_dump_status(drive, msg, stat);
2718 static ide_startstop_t default_error (ide_drive_t *drive, const char *msg, u8 stat)
2720 return ide_error(drive, msg, stat);
2723 static ide_startstop_t default_abort (ide_drive_t *drive, const char *msg)
2725 return ide_abort(drive, msg);
2728 static int default_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
2729 unsigned int cmd, unsigned long arg)
2734 static int default_open (struct inode *inode, struct file *filp, ide_drive_t *drive)
2740 static void default_release (struct inode *inode, struct file *filp, ide_drive_t *drive)
2744 static int default_check_media_change (ide_drive_t *drive)
2749 static void default_pre_reset (ide_drive_t *drive)
2753 static unsigned long default_capacity (ide_drive_t *drive)
2758 static ide_startstop_t default_special (ide_drive_t *drive)
2760 special_t *s = &drive->special;
2763 drive->mult_req = 0;
2767 static int default_init (void)
2772 static int default_attach (ide_drive_t *drive)
2774 printk(KERN_ERR "%s: does not support hotswap of device class !\n",
2780 static void setup_driver_defaults (ide_drive_t *drive)
2782 ide_driver_t *d = drive->driver;
2784 if (d->cleanup == NULL) d->cleanup = default_cleanup;
2785 if (d->shutdown == NULL) d->shutdown = default_shutdown;
2786 if (d->standby == NULL) d->standby = default_standby;
2787 if (d->suspend == NULL) d->suspend = default_suspend;
2788 if (d->resume == NULL) d->resume = default_resume;
2789 if (d->flushcache == NULL) d->flushcache = default_flushcache;
2790 if (d->do_request == NULL) d->do_request = default_do_request;
2791 if (d->end_request == NULL) d->end_request = default_end_request;
2792 if (d->sense == NULL) d->sense = default_sense;
2793 if (d->error == NULL) d->error = default_error;
2794 if (d->error == NULL) d->abort = default_abort;
2795 if (d->ioctl == NULL) d->ioctl = default_ioctl;
2796 if (d->open == NULL) d->open = default_open;
2797 if (d->release == NULL) d->release = default_release;
2798 if (d->media_change == NULL) d->media_change = default_check_media_change;
2799 if (d->pre_reset == NULL) d->pre_reset = default_pre_reset;
2800 if (d->capacity == NULL) d->capacity = default_capacity;
2801 if (d->special == NULL) d->special = default_special;
2802 if (d->init == NULL) d->init = default_init;
2803 if (d->attach == NULL) d->attach = default_attach;
2806 ide_drive_t *ide_scan_devices (u8 media, const char *name, ide_driver_t *driver, int n)
2808 unsigned int unit, index, i;
2810 if(driver == NULL) /* No driver is actually &idedefault_driver */
2811 driver = &idedefault_driver;
2813 for (index = 0, i = 0; index < MAX_HWIFS; ++index) {
2814 ide_hwif_t *hwif = &ide_hwifs[index];
2817 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2818 ide_drive_t *drive = &hwif->drives[unit];
2819 char *req = drive->driver_req;
2820 if (*req && !strstr(name, req))
2822 if (drive->present && drive->media == media &&
2823 drive->driver == driver && ++i > n)
2830 EXPORT_SYMBOL(ide_scan_devices);
2832 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version)
2834 unsigned long flags;
2836 BUG_ON(drive->driver == NULL);
2838 spin_lock_irqsave(&io_request_lock, flags);
2839 if (version != IDE_SUBDRIVER_VERSION || !drive->present ||
2840 drive->driver != &idedefault_driver || drive->busy || drive->usage) {
2841 spin_unlock_irqrestore(&io_request_lock, flags);
2844 drive->driver = driver;
2845 setup_driver_defaults(drive);
2846 printk("%s: attached %s driver.\n", drive->name, driver->name);
2847 spin_unlock_irqrestore(&io_request_lock, flags);
2848 if (drive->autotune != 2) {
2849 /* DMA timings and setup moved to ide-probe.c */
2850 if (!driver->supports_dma && HWIF(drive)->ide_dma_off_quietly)
2851 // HWIF(drive)->ide_dma_off_quietly(drive);
2852 HWIF(drive)->ide_dma_off(drive);
2853 drive->dsc_overlap = (drive->next != drive && driver->supports_dsc_overlap);
2856 drive->revalidate = 1;
2857 drive->suspend_reset = 0;
2858 #ifdef CONFIG_PROC_FS
2859 if (drive->driver != &idedefault_driver) {
2860 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
2861 ide_add_proc_entries(drive->proc, driver->proc, drive);
2867 EXPORT_SYMBOL(ide_register_subdriver);
2869 int ide_unregister_subdriver (ide_drive_t *drive)
2871 unsigned long flags;
2873 down(&ide_setting_sem);
2874 spin_lock_irqsave(&io_request_lock, flags);
2875 if (drive->usage || drive->busy || DRIVER(drive)->busy) {
2876 spin_unlock_irqrestore(&io_request_lock, flags);
2877 up(&ide_setting_sem);
2880 #ifdef CONFIG_PROC_FS
2881 ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc);
2882 ide_remove_proc_entries(drive->proc, generic_subdriver_entries);
2884 drive->driver = &idedefault_driver;
2885 setup_driver_defaults(drive);
2886 auto_remove_settings(drive);
2887 spin_unlock_irqrestore(&io_request_lock, flags);
2888 up(&ide_setting_sem);
2892 EXPORT_SYMBOL(ide_unregister_subdriver);
2894 int ide_register_module (ide_module_t *module)
2896 ide_module_t *p = ide_modules;
2903 module->next = ide_modules;
2904 ide_modules = module;
2905 revalidate_drives(1);
2909 EXPORT_SYMBOL(ide_register_module);
2911 void ide_unregister_module (ide_module_t *module)
2915 for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next));
2920 EXPORT_SYMBOL(ide_unregister_module);
2922 struct block_device_operations ide_fops[] = {{
2925 release: ide_release,
2927 check_media_change: ide_check_media_change,
2928 revalidate: ide_revalidate_disk
2931 EXPORT_SYMBOL(ide_fops);
2934 * ide_geninit() is called exactly *once* for each interface.
2936 void ide_geninit (ide_hwif_t *hwif)
2939 struct gendisk *gd = hwif->gd;
2941 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2942 ide_drive_t *drive = &hwif->drives[unit];
2944 if (!drive->present)
2946 if (drive->media!=ide_disk && drive->media!=ide_floppy)
2948 register_disk(gd,MKDEV(hwif->major,unit<<PARTN_BITS),
2949 #ifdef CONFIG_BLK_DEV_ISAPNP
2950 (drive->forced_geom && drive->noprobe) ? 1 :
2951 #endif /* CONFIG_BLK_DEV_ISAPNP */
2952 1<<PARTN_BITS, ide_fops,
2953 current_capacity(drive));
2957 EXPORT_SYMBOL(ide_geninit);
2963 devfs_handle_t ide_devfs_handle;
2965 EXPORT_SYMBOL(ide_probe);
2966 EXPORT_SYMBOL(ide_devfs_handle);
2968 static int ide_notify_reboot (struct notifier_block *this, unsigned long event, void *x)
2983 printk(KERN_INFO "flushing ide devices: ");
2985 for (i = 0; i < MAX_HWIFS; i++) {
2986 hwif = &ide_hwifs[i];
2989 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2990 drive = &hwif->drives[unit];
2991 if (!drive->present)
2994 /* set the drive to standby */
2995 printk("%s ", drive->name);
2997 /* On Alpha, halt(8) doesn't actually turn the machine
2998 off, it puts you into the sort of firmware monitor.
2999 Typically, it's used to boot another kernel image,
3000 so it's not much different from reboot(8).
3001 Therefore, we don't need to spin down the disk in
3002 this case, especially since Alpha firmware doesn't
3003 handle disks in standby mode properly.
3004 On the other hand, it's reasonably safe to turn
3005 the power off when the shutdown process reaches
3006 the firmware prompt, as the firmware initialization
3007 takes rather long time - at least 10 seconds,
3008 which should be sufficient for the disk to expire
3010 if (event == SYS_POWER_OFF)
3012 if (event != SYS_RESTART)
3014 if (DRIVER(drive)->standby(drive))
3017 DRIVER(drive)->cleanup(drive);
3025 static struct notifier_block ide_notifier = {
3032 * This is gets invoked once during initialization, to set *everything* up
3034 int __init ide_init (void)
3036 static char banner_printed;
3039 if (!banner_printed) {
3040 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
3041 ide_devfs_handle = devfs_mk_dir(NULL, "ide", NULL);
3042 system_bus_speed = ide_system_bus_speed();
3048 #ifndef CLASSIC_BUILTINS_METHOD
3049 ide_init_builtin_subdrivers();
3050 #endif /* CLASSIC_BUILTINS_METHOD */
3053 ide_init_builtin_drivers();
3056 for (i = 0; i < MAX_HWIFS; ++i) {
3057 ide_hwif_t *hwif = &ide_hwifs[i];
3062 register_reboot_notifier(&ide_notifier);
3067 char *options = NULL;
3068 MODULE_PARM(options,"s");
3069 MODULE_LICENSE("GPL");
3071 static void __init parse_options (char *line)
3075 if (line == NULL || !*line)
3077 while ((line = next) != NULL) {
3078 if ((next = strchr(line,' ')) != NULL)
3080 if (!ide_setup(line))
3081 printk ("Unknown option '%s'\n", line);
3085 int init_module (void)
3087 parse_options(options);
3091 void cleanup_module (void)
3095 unregister_reboot_notifier(&ide_notifier);
3096 for (index = 0; index < MAX_HWIFS; ++index) {
3097 ide_unregister(index);
3098 #if !defined(CONFIG_DMA_NONPCI)
3099 if (ide_hwifs[index].dma_base)
3100 (void) ide_release_dma(&ide_hwifs[index]);
3101 #endif /* !(CONFIG_DMA_NONPCI) */
3104 #ifdef CONFIG_PROC_FS
3107 devfs_unregister (ide_devfs_handle);
3112 __setup("", ide_setup);
3113 module_init(ide_init);