2 * linux/drivers/ide/ide.c Version 7.00beta1 Nov 29 2002
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.00beta-2.4"
125 #define VERSION "Id: ide.c 7.00b1 20021129"
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 #if defined(__mc68000__) || defined(CONFIG_APUS)
179 * ide_lock is used by the Atari code to obtain access to the IDE interrupt,
180 * which is shared between several drivers.
182 static int ide_intr_lock;
183 #endif /* __mc68000__ || CONFIG_APUS */
185 #ifdef CONFIG_IDEDMA_AUTO
191 EXPORT_SYMBOL(noautodma);
195 * ide_modules keeps track of the available IDE chipset/probe/driver modules.
197 ide_module_t *ide_chipsets;
198 ide_module_t *ide_modules;
199 ide_module_t *ide_probe;
202 * This is declared extern in ide.h, for access by other IDE modules:
204 ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
206 EXPORT_SYMBOL(ide_hwifs);
208 ide_devices_t *idedisk;
209 ide_devices_t *idecd;
210 ide_devices_t *idefloppy;
211 ide_devices_t *idetape;
212 ide_devices_t *idescsi;
214 EXPORT_SYMBOL(idedisk);
215 EXPORT_SYMBOL(idecd);
216 EXPORT_SYMBOL(idefloppy);
217 EXPORT_SYMBOL(idetape);
218 EXPORT_SYMBOL(idescsi);
221 * Do not even *think* about calling this!
223 static void init_hwif_data (unsigned int index)
227 ide_hwif_t *hwif = &ide_hwifs[index];
229 /* bulk initialize hwif & drive info with zeros */
230 memset(hwif, 0, sizeof(ide_hwif_t));
231 memset(&hw, 0, sizeof(hw_regs_t));
233 /* fill in any non-zero initial values */
235 ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
236 memcpy(&hwif->hw, &hw, sizeof(hw));
237 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
238 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
239 #ifdef CONFIG_BLK_DEV_HD
240 if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
241 hwif->noprobe = 1; /* may be overridden by ide_setup() */
242 #endif /* CONFIG_BLK_DEV_HD */
243 hwif->major = ide_hwif_to_major[index];
247 hwif->name[3] = '0' + index;
248 hwif->bus_state = BUSSTATE_ON;
249 hwif->reset_poll= NULL;
250 hwif->pre_reset = NULL;
252 hwif->atapi_dma = 0; /* disable all atapi dma */
253 hwif->ultra_mask = 0x80; /* disable all ultra */
254 hwif->mwdma_mask = 0x80; /* disable all mwdma */
255 hwif->swdma_mask = 0x80; /* disable all swdma */
257 default_hwif_iops(hwif);
258 default_hwif_transport(hwif);
259 for (unit = 0; unit < MAX_DRIVES; ++unit) {
260 ide_drive_t *drive = &hwif->drives[unit];
262 drive->media = ide_disk;
263 drive->select.all = (unit<<4)|0xa0;
266 drive->ready_stat = READY_STAT;
267 drive->bad_wstat = BAD_W_STAT;
268 drive->special.b.recalibrate = 1;
269 drive->special.b.set_geometry = 1;
270 drive->name[0] = 'h';
271 drive->name[1] = 'd';
272 drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
273 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
274 drive->using_dma = 0;
276 init_waitqueue_head(&drive->wqueue);
281 * init_ide_data() sets reasonable default values into all fields
282 * of all instances of the hwifs and drives, but only on the first call.
283 * Subsequent calls have no effect (they don't wipe out anything).
285 * This routine is normally called at driver initialization time,
286 * but may also be called MUCH earlier during kernel "command-line"
287 * parameter processing. As such, we cannot depend on any other parts
288 * of the kernel (such as memory allocation) to be functioning yet.
290 * This is too bad, as otherwise we could dynamically allocate the
291 * ide_drive_t structs as needed, rather than always consuming memory
292 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
294 * FIXME: We should stuff the setup data into __init and copy the
295 * relevant hwifs/allocate them properly during boot.
297 #define MAGIC_COOKIE 0x12345678
298 static void __init init_ide_data (void)
301 static unsigned long magic_cookie = MAGIC_COOKIE;
303 if (magic_cookie != MAGIC_COOKIE)
304 return; /* already initialized */
307 /* Initialise all interface structures */
308 for (index = 0; index < MAX_HWIFS; ++index)
309 init_hwif_data(index);
311 /* Add default hw interfaces */
312 ide_init_default_hwifs();
314 idebus_parameter = 0;
315 system_bus_speed = 0;
319 * ide_system_bus_speed() returns what we think is the system VESA/PCI
320 * bus speed (in MHz). This is used for calculating interface PIO timings.
321 * The default is 40 for known PCI systems, 50 otherwise.
322 * The "idebus=xx" parameter can be used to override this value.
323 * The actual value to be used is computed/displayed the first time through.
325 int ide_system_bus_speed (void)
327 if (!system_bus_speed) {
328 if (idebus_parameter) {
329 /* user supplied value */
330 system_bus_speed = idebus_parameter;
331 } else if (pci_present()) {
332 /* safe default value for PCI */
333 system_bus_speed = 33;
335 /* safe default value for VESA and PCI */
336 system_bus_speed = 50;
338 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
339 "for PIO modes%s\n", system_bus_speed,
340 idebus_parameter ? "" : "; override with idebus=xx");
342 return system_bus_speed;
346 * current_capacity() returns the capacity (in sectors) of a drive
347 * according to its current geometry/LBA settings.
349 unsigned long current_capacity (ide_drive_t *drive)
353 if (drive->driver != NULL)
354 return DRIVER(drive)->capacity(drive);
358 EXPORT_SYMBOL(current_capacity);
360 static inline u32 read_24 (ide_drive_t *drive)
362 return (HWIF(drive)->INB(IDE_HCYL_REG)<<16) |
363 (HWIF(drive)->INB(IDE_LCYL_REG)<<8) |
364 HWIF(drive)->INB(IDE_SECTOR_REG);
368 * Error reporting, in human readable form (luxurious, but a memory hog).
370 u8 ide_dump_status (ide_drive_t *drive, const char *msg, u8 stat)
372 ide_hwif_t *hwif = HWIF(drive);
376 local_irq_set(flags);
377 printk(KERN_WARNING "%s: %s: status=0x%02x", drive->name, msg, stat);
378 #if FANCY_STATUS_DUMPS
380 if (stat & BUSY_STAT) {
383 if (stat & READY_STAT) printk("DriveReady ");
384 if (stat & WRERR_STAT) printk("DeviceFault ");
385 if (stat & SEEK_STAT) printk("SeekComplete ");
386 if (stat & DRQ_STAT) printk("DataRequest ");
387 if (stat & ECC_STAT) printk("CorrectedError ");
388 if (stat & INDEX_STAT) printk("Index ");
389 if (stat & ERR_STAT) printk("Error ");
392 #endif /* FANCY_STATUS_DUMPS */
394 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
395 err = hwif->INB(IDE_ERROR_REG);
396 printk("%s: %s: error=0x%02x", drive->name, msg, err);
397 #if FANCY_STATUS_DUMPS
398 if (drive->media == ide_disk) {
400 if (err & ABRT_ERR) printk("DriveStatusError ");
401 if (err & ICRC_ERR) printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector");
402 if (err & ECC_ERR) printk("UncorrectableError ");
403 if (err & ID_ERR) printk("SectorIdNotFound ");
404 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
405 if (err & MARK_ERR) printk("AddrMarkNotFound ");
407 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
408 if ((drive->id->command_set_2 & 0x0400) &&
409 (drive->id->cfs_enable_2 & 0x0400) &&
410 (drive->addressing == 1)) {
413 u32 low = read_24(drive);
414 hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
415 high = read_24(drive);
417 sectors = ((u64)high << 24) | low;
418 printk(", LBAsect=%llu, high=%d, low=%d",
422 u8 cur = hwif->INB(IDE_SELECT_REG);
423 if (cur & 0x40) { /* using LBA? */
424 printk(", LBAsect=%ld", (unsigned long)
426 |(hwif->INB(IDE_HCYL_REG)<<16)
427 |(hwif->INB(IDE_LCYL_REG)<<8)
428 | hwif->INB(IDE_SECTOR_REG));
430 printk(", CHS=%d/%d/%d",
431 (hwif->INB(IDE_HCYL_REG)<<8) +
432 hwif->INB(IDE_LCYL_REG),
434 hwif->INB(IDE_SECTOR_REG));
437 if (HWGROUP(drive) && HWGROUP(drive)->rq)
438 printk(", sector=%ld", HWGROUP(drive)->rq->sector);
441 #endif /* FANCY_STATUS_DUMPS */
444 local_irq_restore(flags);
448 EXPORT_SYMBOL(ide_dump_status);
452 * This routine is called to flush all partitions and partition tables
453 * for a changed disk, and then re-read the new partition table.
454 * If we are revalidating a disk because of a media change, then we
455 * enter with usage == 0. If we are using an ioctl, we automatically have
456 * usage == 1 (we need an open channel to use an ioctl :-), so this
459 int ide_revalidate_disk (kdev_t i_rdev)
462 ide_hwgroup_t *hwgroup;
463 unsigned int p, major, minor;
466 if ((drive = get_info_ptr(i_rdev)) == NULL)
468 major = MAJOR(i_rdev);
469 minor = drive->select.b.unit << PARTN_BITS;
470 hwgroup = HWGROUP(drive);
471 spin_lock_irqsave(&io_request_lock, flags);
472 if (drive->busy || (drive->usage > 1)) {
473 spin_unlock_irqrestore(&io_request_lock, flags);
478 spin_unlock_irqrestore(&io_request_lock, flags);
480 for (p = 0; p < (1<<PARTN_BITS); ++p) {
481 if (drive->part[p].nr_sects > 0) {
482 kdev_t devp = MKDEV(major, minor+p);
483 invalidate_device(devp, 1);
485 drive->part[p].start_sect = 0;
486 drive->part[p].nr_sects = 0;
489 if (DRIVER(drive) && DRIVER(drive)->revalidate)
490 DRIVER(drive)->revalidate(drive);
493 wake_up(&drive->wqueue);
498 EXPORT_SYMBOL(ide_revalidate_disk);
500 static void revalidate_drives (int revaldiate)
506 for (index = 0; index < MAX_HWIFS; ++index) {
507 hwif = &ide_hwifs[index];
508 for (unit = 0; unit < MAX_DRIVES; ++unit) {
509 drive = &ide_hwifs[index].drives[unit];
510 if (drive->revalidate) {
511 drive->revalidate = 0;
512 if ((!initializing) && (revaldiate))
513 (void) ide_revalidate_disk(MKDEV(hwif->major, unit<<PARTN_BITS));
519 void ide_probe_module (int revaldiate)
522 #if defined(CONFIG_BLK_DEV_IDE_MODULE)
523 (void) request_module("ide-probe-mod");
526 (void) ide_probe->init();
528 revalidate_drives(revaldiate);
531 EXPORT_SYMBOL(ide_probe_module);
533 void ide_driver_module (int revaldiate)
536 ide_module_t *module = ide_modules;
538 for (index = 0; index < MAX_HWIFS; ++index)
539 if (ide_hwifs[index].present)
541 ide_probe_module(revaldiate);
544 (void) module->init();
545 module = module->next;
547 revalidate_drives(revaldiate);
550 EXPORT_SYMBOL(ide_driver_module);
552 static int ide_open (struct inode * inode, struct file * filp)
556 if ((drive = get_info_ptr(inode->i_rdev)) == NULL)
558 if (drive->driver == NULL)
559 ide_driver_module(1);
560 if (drive->driver == NULL) {
561 if (drive->media == ide_disk)
562 (void) request_module("ide-disk");
564 (void) request_module("ide-scsi");
565 if (drive->media == ide_cdrom)
566 (void) request_module("ide-cd");
567 if (drive->media == ide_tape)
568 (void) request_module("ide-tape");
569 if (drive->media == ide_floppy)
570 (void) request_module("ide-floppy");
573 /* The locking here isnt enough, but this is hard to fix
576 sleep_on(&drive->wqueue);
578 if (drive->driver != NULL && !drive->dead)
579 return DRIVER(drive)->open(inode, filp, drive);
580 printk(KERN_WARNING "%s: driver not present\n", drive->name);
586 * Releasing a block device means we sync() it, so that it can safely
587 * be forgotten about...
589 static int ide_release (struct inode * inode, struct file * file)
593 if ((drive = get_info_ptr(inode->i_rdev)) != NULL) {
595 if (drive->driver != NULL)
596 DRIVER(drive)->release(inode, file, drive);
601 #ifdef CONFIG_PROC_FS
602 ide_proc_entry_t generic_subdriver_entries[] = {
603 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
604 { NULL, 0, NULL, NULL }
609 #define hwif_release_region(addr, num) \
610 ((hwif->mmio) ? release_mem_region((addr),(num)) : release_region((addr),(num)))
613 * Note that we only release the standard ports,
614 * and do not even try to handle any extra ports
615 * allocated for weird IDE interface chipsets.
617 void hwif_unregister (ide_hwif_t *hwif)
623 if (hwif->io_ports[IDE_CONTROL_OFFSET])
624 hwif_release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
625 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
626 if (hwif->io_ports[IDE_IRQ_OFFSET])
627 hwif_release_region(hwif->io_ports[IDE_IRQ_OFFSET], 1);
628 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
630 if (hwif->straight8) {
631 hwif_release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
634 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
635 if (hwif->io_ports[i]) {
636 hwif_release_region(hwif->io_ports[i], 1);
641 EXPORT_SYMBOL(hwif_unregister);
643 extern void init_hwif_data(unsigned int index);
645 int ide_unregister (unsigned int index)
648 ide_drive_t *drive, *d;
649 ide_hwif_t *hwif, *g;
650 ide_hwgroup_t *hwgroup;
651 int irq_count = 0, unit, i;
653 unsigned int p, minor;
656 if (index >= MAX_HWIFS)
659 spin_lock_irqsave(&io_request_lock, flags);
660 hwif = &ide_hwifs[index];
663 for (unit = 0; unit < MAX_DRIVES; ++unit) {
664 drive = &hwif->drives[unit];
667 if (drive->busy || drive->usage)
669 if (drive->driver != NULL && DRIVER(drive)->shutdown(drive))
675 * All clear? Then blow away the buffer cache
677 spin_unlock_irqrestore(&io_request_lock, flags);
678 for (unit = 0; unit < MAX_DRIVES; ++unit) {
679 drive = &hwif->drives[unit];
682 if (drive->driver != NULL)
683 DRIVER(drive)->cleanup(drive);
684 minor = drive->select.b.unit << PARTN_BITS;
685 for (p = 0; p < (1<<PARTN_BITS); ++p) {
686 if (drive->part[p].nr_sects > 0) {
687 kdev_t devp = MKDEV(hwif->major, minor+p);
688 invalidate_device(devp, 0);
691 #ifdef CONFIG_PROC_FS
692 destroy_proc_ide_drives(hwif);
696 spin_lock_irqsave(&io_request_lock, flags);
697 hwgroup = hwif->hwgroup;
700 * free the irq if we were the only hwif using it
704 if (g->irq == hwif->irq)
707 } while (g != hwgroup->hwif);
709 free_irq(hwif->irq, hwgroup);
712 * Note that we only release the standard ports,
713 * and do not even try to handle any extra ports
714 * allocated for weird IDE interface chipsets.
716 hwif_unregister(hwif);
719 * Remove us from the hwgroup, and free
720 * the hwgroup if we were the only member
723 for (i = 0; i < MAX_DRIVES; ++i) {
724 drive = &hwif->drives[i];
726 devfs_unregister(drive->de);
731 while (hwgroup->drive->next != drive)
732 hwgroup->drive = hwgroup->drive->next;
733 hwgroup->drive->next = drive->next;
734 if (hwgroup->drive == drive)
735 hwgroup->drive = NULL;
736 if (drive->id != NULL) {
741 blk_cleanup_queue(&drive->queue);
745 while (hwgroup->hwif->next != hwif)
746 hwgroup->hwif = hwgroup->hwif->next;
747 hwgroup->hwif->next = hwif->next;
748 if (hwgroup->hwif == hwif)
751 hwgroup->hwif = HWIF(hwgroup->drive);
753 #if !defined(CONFIG_DMA_NONPCI)
754 if (hwif->dma_base) {
755 (void) ide_release_dma(hwif);
758 hwif->dma_master = 0;
759 hwif->dma_command = 0;
760 hwif->dma_vendor1 = 0;
761 hwif->dma_status = 0;
762 hwif->dma_vendor3 = 0;
763 hwif->dma_prdtable = 0;
765 #endif /* !(CONFIG_DMA_NONPCI) */
768 * Remove us from the kernel's knowledge
770 unregister_blkdev(hwif->major, hwif->name);
771 kfree(blksize_size[hwif->major]);
772 kfree(max_sectors[hwif->major]);
773 kfree(max_readahead[hwif->major]);
774 blk_dev[hwif->major].data = NULL;
775 blk_dev[hwif->major].queue = NULL;
776 blksize_size[hwif->major] = NULL;
791 init_hwif_data(index); /* restore hwif data to pristine status */
792 hwif->hwgroup = old_hwif.hwgroup;
794 hwif->proc = old_hwif.proc;
796 hwif->major = old_hwif.major;
797 // hwif->index = old_hwif.index;
798 // hwif->channel = old_hwif.channel;
799 hwif->straight8 = old_hwif.straight8;
800 hwif->bus_state = old_hwif.bus_state;
802 hwif->atapi_dma = old_hwif.atapi_dma;
803 hwif->ultra_mask = old_hwif.ultra_mask;
804 hwif->mwdma_mask = old_hwif.mwdma_mask;
805 hwif->swdma_mask = old_hwif.swdma_mask;
807 hwif->chipset = old_hwif.chipset;
809 #ifdef CONFIG_BLK_DEV_IDEPCI
810 hwif->pci_dev = old_hwif.pci_dev;
811 hwif->cds = old_hwif.cds;
812 #endif /* CONFIG_BLK_DEV_IDEPCI */
815 hwif->hwifops = old_hwif.hwifops;
817 hwif->identify = old_hwif.identify;
818 hwif->tuneproc = old_hwif.tuneproc;
819 hwif->speedproc = old_hwif.speedproc;
820 hwif->selectproc = old_hwif.selectproc;
821 hwif->reset_poll = old_hwif.reset_poll;
822 hwif->pre_reset = old_hwif.pre_reset;
823 hwif->resetproc = old_hwif.resetproc;
824 hwif->intrproc = old_hwif.intrproc;
825 hwif->maskproc = old_hwif.maskproc;
826 hwif->quirkproc = old_hwif.quirkproc;
827 hwif->busproc = old_hwif.busproc;
831 hwif->pioops = old_hwif.pioops;
833 hwif->ata_input_data = old_hwif.ata_input_data;
834 hwif->ata_output_data = old_hwif.ata_output_data;
835 hwif->atapi_input_bytes = old_hwif.atapi_input_bytes;
836 hwif->atapi_output_bytes = old_hwif.atapi_output_bytes;
840 hwif->dmaops = old_hwif.dmaops;
842 hwif->ide_dma_read = old_hwif.ide_dma_read;
843 hwif->ide_dma_write = old_hwif.ide_dma_write;
844 hwif->ide_dma_begin = old_hwif.ide_dma_begin;
845 hwif->ide_dma_end = old_hwif.ide_dma_end;
846 hwif->ide_dma_check = old_hwif.ide_dma_check;
847 hwif->ide_dma_on = old_hwif.ide_dma_on;
848 hwif->ide_dma_off = old_hwif.ide_dma_off;
849 hwif->ide_dma_off_quietly = old_hwif.ide_dma_off_quietly;
850 hwif->ide_dma_test_irq = old_hwif.ide_dma_test_irq;
851 hwif->ide_dma_host_on = old_hwif.ide_dma_host_on;
852 hwif->ide_dma_host_off = old_hwif.ide_dma_host_off;
853 hwif->ide_dma_bad_drive = old_hwif.ide_dma_bad_drive;
854 hwif->ide_dma_good_drive = old_hwif.ide_dma_good_drive;
855 hwif->ide_dma_count = old_hwif.ide_dma_count;
856 hwif->ide_dma_verbose = old_hwif.ide_dma_verbose;
857 hwif->ide_dma_retune = old_hwif.ide_dma_retune;
858 hwif->ide_dma_lostirq = old_hwif.ide_dma_lostirq;
859 hwif->ide_dma_timeout = old_hwif.ide_dma_timeout;
863 hwif->iops = old_hwif.iops;
865 hwif->OUTB = old_hwif.OUTB;
866 hwif->OUTW = old_hwif.OUTW;
867 hwif->OUTL = old_hwif.OUTL;
868 hwif->OUTSW = old_hwif.OUTSW;
869 hwif->OUTSL = old_hwif.OUTSL;
871 hwif->INB = old_hwif.INB;
872 hwif->INW = old_hwif.INW;
873 hwif->INL = old_hwif.INL;
874 hwif->INSW = old_hwif.INSW;
875 hwif->INSL = old_hwif.INSL;
878 hwif->mmio = old_hwif.mmio;
879 hwif->rqsize = old_hwif.rqsize;
880 hwif->addressing = old_hwif.addressing;
881 #ifndef CONFIG_BLK_DEV_IDECS
882 hwif->irq = old_hwif.irq;
883 #endif /* CONFIG_BLK_DEV_IDECS */
884 hwif->initializing = old_hwif.initializing;
886 hwif->dma_base = old_hwif.dma_base;
887 hwif->dma_master = old_hwif.dma_master;
888 hwif->dma_command = old_hwif.dma_command;
889 hwif->dma_vendor1 = old_hwif.dma_vendor1;
890 hwif->dma_status = old_hwif.dma_status;
891 hwif->dma_vendor3 = old_hwif.dma_vendor3;
892 hwif->dma_prdtable = old_hwif.dma_prdtable;
894 hwif->dma_extra = old_hwif.dma_extra;
895 hwif->config_data = old_hwif.config_data;
896 hwif->select_data = old_hwif.select_data;
897 hwif->autodma = old_hwif.autodma;
898 hwif->udma_four = old_hwif.udma_four;
899 hwif->no_dsc = old_hwif.no_dsc;
901 hwif->hwif_data = old_hwif.hwif_data;
902 spin_unlock_irqrestore(&io_request_lock, flags);
906 spin_unlock_irqrestore(&io_request_lock, flags);
911 EXPORT_SYMBOL(ide_unregister);
914 * Setup hw_regs_t structure described by parameters. You
915 * may set up the hw structure yourself OR use this routine to
918 void ide_setup_ports ( hw_regs_t *hw,
919 ide_ioreg_t base, int *offsets,
920 ide_ioreg_t ctrl, ide_ioreg_t intr,
921 ide_ack_intr_t *ack_intr,
923 * ide_io_ops_t *iops,
929 for (i = 0; i < IDE_NR_PORTS; i++) {
930 if (offsets[i] == -1) {
932 case IDE_CONTROL_OFFSET:
933 hw->io_ports[i] = ctrl;
935 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
937 hw->io_ports[i] = intr;
939 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
945 hw->io_ports[i] = base + offsets[i];
950 hw->ack_intr = ack_intr;
951 hw->chipset = ide_generic;
957 EXPORT_SYMBOL(ide_setup_ports);
960 * Register an IDE interface, specifing exactly the registers etc
961 * Set init=1 iff calling before probes have taken place.
963 int ide_register_hw (hw_regs_t *hw, ide_hwif_t **hwifp)
965 int index, retry = 1;
969 for (index = 0; index < MAX_HWIFS; ++index) {
970 hwif = &ide_hwifs[index];
971 if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
974 for (index = 0; index < MAX_HWIFS; ++index) {
975 hwif = &ide_hwifs[index];
976 if ((!hwif->present && !hwif->mate && !initializing) ||
977 (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
980 for (index = 0; index < MAX_HWIFS; index++)
981 ide_unregister(index);
986 ide_unregister(index);
989 memcpy(&hwif->hw, hw, sizeof(*hw));
990 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
993 hwif->chipset = hw->chipset;
997 #ifdef CONFIG_PROC_FS
998 create_proc_ide_interfaces();
1000 ide_driver_module(1);
1006 return (initializing || hwif->present) ? index : -1;
1009 EXPORT_SYMBOL(ide_register_hw);
1012 * Compatability function with existing drivers. If you want
1013 * something different, use the function above.
1015 int ide_register (int arg1, int arg2, int irq)
1018 ide_init_hwif_ports(&hw, (ide_ioreg_t) arg1, (ide_ioreg_t) arg2, NULL);
1020 hw.chipset = ide_unknown;
1021 return ide_register_hw(&hw, NULL);
1024 EXPORT_SYMBOL(ide_register);
1026 void 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)
1028 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
1030 while ((*p) && strcmp((*p)->name, name) < 0)
1032 if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
1034 memset(setting, 0, sizeof(*setting));
1035 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
1037 strcpy(setting->name, name);
1039 setting->read_ioctl = read_ioctl;
1040 setting->write_ioctl = write_ioctl;
1041 setting->data_type = data_type;
1044 setting->mul_factor = mul_factor;
1045 setting->div_factor = div_factor;
1046 setting->data = data;
1050 setting->auto_remove = 1;
1058 EXPORT_SYMBOL(ide_add_setting);
1060 void ide_remove_setting (ide_drive_t *drive, char *name)
1062 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting;
1064 while ((*p) && strcmp((*p)->name, name))
1066 if ((setting = (*p)) == NULL)
1068 (*p) = setting->next;
1069 kfree(setting->name);
1073 EXPORT_SYMBOL(ide_remove_setting);
1075 static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
1077 ide_settings_t *setting = drive->settings;
1080 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
1082 setting = setting->next;
1087 ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
1089 ide_settings_t *setting = drive->settings;
1092 if (strcmp(setting->name, name) == 0)
1094 setting = setting->next;
1099 static void auto_remove_settings (ide_drive_t *drive)
1101 ide_settings_t *setting;
1103 setting = drive->settings;
1105 if (setting->auto_remove) {
1106 ide_remove_setting(drive, setting->name);
1109 setting = setting->next;
1113 int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1116 unsigned long flags;
1118 if ((setting->rw & SETTING_READ)) {
1119 spin_lock_irqsave(&io_request_lock, flags);
1120 switch(setting->data_type) {
1122 val = *((u8 *) setting->data);
1125 val = *((u16 *) setting->data);
1129 val = *((u32 *) setting->data);
1132 spin_unlock_irqrestore(&io_request_lock, flags);
1137 int ide_spin_wait_hwgroup (ide_drive_t *drive)
1139 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1140 unsigned long timeout = jiffies + (3 * HZ);
1142 spin_lock_irq(&io_request_lock);
1144 while (hwgroup->busy) {
1145 unsigned long lflags;
1146 spin_unlock_irq(&io_request_lock);
1147 local_irq_set(lflags);
1148 if (time_after(jiffies, timeout)) {
1149 local_irq_restore(lflags);
1150 printk(KERN_ERR "%s: channel busy\n", drive->name);
1153 local_irq_restore(lflags);
1154 spin_lock_irq(&io_request_lock);
1159 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1162 * FIXME: This should be changed to enqueue a special request
1163 * to the driver to change settings, and then wait on a sema for completion.
1164 * The current scheme of polling is kludgey, though safe enough.
1166 int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1171 if (!capable(CAP_SYS_ADMIN))
1173 if (!(setting->rw & SETTING_WRITE))
1175 if (val < setting->min || val > setting->max)
1178 return setting->set(drive, val);
1179 if (ide_spin_wait_hwgroup(drive))
1181 switch (setting->data_type) {
1183 *((u8 *) setting->data) = val;
1186 *((u16 *) setting->data) = val;
1189 *((u32 *) setting->data) = val;
1192 p = (u32 *) setting->data;
1193 for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1197 spin_unlock_irq(&io_request_lock);
1201 EXPORT_SYMBOL(ide_write_setting);
1203 static int set_io_32bit(ide_drive_t *drive, int arg)
1205 drive->io_32bit = arg;
1206 #ifdef CONFIG_BLK_DEV_DTC2278
1207 if (HWIF(drive)->chipset == ide_dtc2278)
1208 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1209 #endif /* CONFIG_BLK_DEV_DTC2278 */
1213 static int set_using_dma (ide_drive_t *drive, int arg)
1215 if (!drive->driver || !DRIVER(drive)->supports_dma)
1217 if (!drive->id || !(drive->id->capability & 1))
1219 if (HWIF(drive)->ide_dma_check == NULL)
1222 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1224 if (HWIF(drive)->ide_dma_off(drive)) return -EIO;
1229 static int set_pio_mode (ide_drive_t *drive, int arg)
1233 if (!HWIF(drive)->tuneproc)
1235 if (drive->special.b.set_tune)
1237 ide_init_drive_cmd(&rq);
1238 drive->tune_req = (u8) arg;
1239 drive->special.b.set_tune = 1;
1240 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1244 static int set_xfer_rate (ide_drive_t *drive, int arg)
1246 int err = ide_wait_cmd(drive,
1247 WIN_SETFEATURES, (u8) arg,
1248 SETFEATURES_XFER, 0, NULL);
1251 ide_set_xfer_rate(drive, (u8) arg);
1252 ide_driveid_update(drive);
1257 int ide_atapi_to_scsi (ide_drive_t *drive, int arg)
1259 if (drive->media == ide_disk) {
1263 if (drive->driver != NULL) {
1264 if (DRIVER(drive)->cleanup(drive)) {
1269 drive->scsi = (u8) arg;
1270 ide_attach_drive(drive);
1274 void ide_add_generic_settings (ide_drive_t *drive)
1277 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1279 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);
1280 ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL);
1281 ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL);
1282 ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode);
1283 ide_add_setting(drive, "slow", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->slow, NULL);
1284 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);
1285 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);
1286 ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL);
1287 ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate);
1288 ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL);
1289 if (drive->media != ide_disk)
1290 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);
1294 * Delay for *at least* 50ms. As we don't know how much time is left
1295 * until the next tick occurs, we wait an extra tick to be safe.
1296 * This is used only during the probing/polling for drives at boot time.
1298 * However, its usefullness may be needed in other places, thus we export it now.
1299 * The future may change this to a millisecond setable delay.
1301 void ide_delay_50ms (void)
1303 #ifndef CONFIG_BLK_DEV_IDECS
1306 __set_current_state(TASK_UNINTERRUPTIBLE);
1307 schedule_timeout(HZ/20);
1308 #endif /* CONFIG_BLK_DEV_IDECS */
1311 EXPORT_SYMBOL(ide_delay_50ms);
1313 int system_bus_clock (void)
1315 return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1318 EXPORT_SYMBOL(system_bus_clock);
1320 int ide_replace_subdriver (ide_drive_t *drive, const char *driver)
1322 if (!drive->present || drive->busy || drive->usage || drive->dead)
1324 if (drive->driver != NULL && DRIVER(drive)->cleanup(drive))
1326 strncpy(drive->driver_req, driver, 9);
1327 ide_driver_module(0);
1328 drive->driver_req[0] = 0;
1329 ide_driver_module(0);
1330 if (DRIVER(drive) && !strcmp(DRIVER(drive)->name, driver))
1336 EXPORT_SYMBOL(ide_replace_subdriver);
1338 int ide_attach_drive (ide_drive_t *drive)
1340 /* Someone unplugged the device on us */
1344 #ifdef CONFIG_BLK_DEV_IDESCSI
1346 extern int idescsi_attach(ide_drive_t *drive);
1347 if (idescsi_attach(drive))
1350 #endif /* CONFIG_BLK_DEV_IDESCSI */
1352 switch (drive->media) {
1353 #ifdef CONFIG_BLK_DEV_IDECD
1356 extern int ide_cdrom_attach(ide_drive_t *drive);
1357 if (ide_cdrom_attach(drive))
1361 #endif /* CONFIG_BLK_DEV_IDECD */
1362 #ifdef CONFIG_BLK_DEV_IDEDISK
1365 extern int idedisk_attach(ide_drive_t *drive);
1366 if (idedisk_attach(drive))
1370 #endif /* CONFIG_BLK_DEV_IDEDISK */
1371 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
1374 extern int idefloppy_attach(ide_drive_t *drive);
1375 if (idefloppy_attach(drive))
1379 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
1380 #ifdef CONFIG_BLK_DEV_IDETAPE
1383 extern int idetape_attach(ide_drive_t *drive);
1384 if (idetape_attach(drive))
1388 #endif /* CONFIG_BLK_DEV_IDETAPE */
1395 EXPORT_SYMBOL(ide_attach_drive);
1397 static int ide_ioctl (struct inode *inode, struct file *file,
1398 unsigned int cmd, unsigned long arg)
1400 int err = 0, major, minor;
1404 ide_settings_t *setting;
1406 if (!inode || !(dev = inode->i_rdev))
1408 major = MAJOR(dev); minor = MINOR(dev);
1409 if ((drive = get_info_ptr(inode->i_rdev)) == NULL)
1412 if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1413 if (cmd == setting->read_ioctl) {
1414 err = ide_read_setting(drive, setting);
1415 return err >= 0 ? put_user(err, (long *) arg) : err;
1417 if ((MINOR(inode->i_rdev) & PARTN_MASK))
1419 return ide_write_setting(drive, setting, arg);
1423 ide_init_drive_cmd (&rq);
1427 struct hd_geometry *loc = (struct hd_geometry *) arg;
1428 u16 bios_cyl = drive->bios_cyl; /* truncate */
1429 if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1430 if (put_user(drive->bios_head, (u8 *) &loc->heads)) return -EFAULT;
1431 if (put_user(drive->bios_sect, (u8 *) &loc->sectors)) return -EFAULT;
1432 if (put_user(bios_cyl, (u16 *) &loc->cylinders)) return -EFAULT;
1433 if (put_user((unsigned)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].start_sect,
1434 (unsigned long *) &loc->start)) return -EFAULT;
1438 case HDIO_GETGEO_BIG:
1440 struct hd_big_geometry *loc = (struct hd_big_geometry *) arg;
1441 if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1442 if (put_user(drive->bios_head, (u8 *) &loc->heads)) return -EFAULT;
1443 if (put_user(drive->bios_sect, (u8 *) &loc->sectors)) return -EFAULT;
1444 if (put_user(drive->bios_cyl, (unsigned int *) &loc->cylinders)) return -EFAULT;
1445 if (put_user((unsigned)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].start_sect,
1446 (unsigned long *) &loc->start)) return -EFAULT;
1450 case HDIO_GETGEO_BIG_RAW:
1452 struct hd_big_geometry *loc = (struct hd_big_geometry *) arg;
1453 if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1454 if (put_user(drive->head, (u8 *) &loc->heads)) return -EFAULT;
1455 if (put_user(drive->sect, (u8 *) &loc->sectors)) return -EFAULT;
1456 if (put_user(drive->cyl, (unsigned int *) &loc->cylinders)) return -EFAULT;
1457 if (put_user((unsigned)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].start_sect,
1458 (unsigned long *) &loc->start)) return -EFAULT;
1462 case BLKGETSIZE: /* Return device size */
1463 return put_user(drive->part[MINOR(inode->i_rdev)&PARTN_MASK].nr_sects, (unsigned long *) arg);
1465 return put_user((u64)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].nr_sects << 9, (u64 *) arg);
1467 case BLKRRPART: /* Re-read partition tables */
1468 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1469 return ide_revalidate_disk(inode->i_rdev);
1471 case HDIO_OBSOLETE_IDENTITY:
1472 case HDIO_GET_IDENTITY:
1473 if (MINOR(inode->i_rdev) & PARTN_MASK)
1475 if (drive->id == NULL)
1477 if (copy_to_user((char *)arg, (char *)drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1482 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
1483 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
1484 drive->nice0 << IDE_NICE_0 |
1485 drive->nice1 << IDE_NICE_1 |
1486 drive->nice2 << IDE_NICE_2,
1489 #ifdef CONFIG_IDE_TASK_IOCTL
1490 case HDIO_DRIVE_TASKFILE:
1491 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1493 switch(drive->media) {
1495 return ide_taskfile_ioctl(drive, inode, file, cmd, arg);
1496 #ifdef CONFIG_PKT_TASK_IOCTL
1500 return pkt_taskfile_ioctl(drive, inode, file, cmd, arg);
1501 #endif /* CONFIG_PKT_TASK_IOCTL */
1505 #endif /* CONFIG_IDE_TASK_IOCTL */
1507 case HDIO_DRIVE_CMD:
1508 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1510 return ide_cmd_ioctl(drive, inode, file, cmd, arg);
1512 case HDIO_DRIVE_TASK:
1513 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1515 return ide_task_ioctl(drive, inode, file, cmd, arg);
1517 case HDIO_SCAN_HWIF:
1520 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1521 if (copy_from_user(args, (void *)arg, 3 * sizeof(int)))
1523 if (ide_register(args[0], args[1], args[2]) == -1)
1527 case HDIO_UNREGISTER_HWIF:
1528 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1529 /* (arg > MAX_HWIFS) checked in function */
1530 ide_unregister(arg);
1533 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1534 if (drive->driver == NULL)
1536 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1538 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1539 if (drive->dsc_overlap && !DRIVER(drive)->supports_dsc_overlap) {
1540 drive->dsc_overlap = 0;
1543 drive->nice1 = (arg >> IDE_NICE_1) & 1;
1545 case HDIO_DRIVE_RESET:
1547 unsigned long flags;
1548 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1550 spin_lock_irqsave(&io_request_lock, flags);
1551 if ( HWGROUP(drive)->handler != NULL) {
1552 printk(KERN_ERR "%s: ide_set_handler: handler not null; %p\n", drive->name, HWGROUP(drive)->handler);
1553 (void) HWGROUP(drive)->handler(drive);
1554 // HWGROUP(drive)->handler = NULL;
1555 HWGROUP(drive)->expiry = NULL;
1556 del_timer(&HWGROUP(drive)->timer);
1558 spin_unlock_irqrestore(&io_request_lock, flags);
1561 (void) ide_do_reset(drive);
1562 if (drive->suspend_reset) {
1564 * APM WAKE UP todo !!
1565 * int nogoodpower = 1;
1566 * while(nogoodpower) {
1567 * check_power1() or check_power2()
1570 * HWIF(drive)->multiproc(drive);
1572 return ide_revalidate_disk(inode->i_rdev);
1585 return blk_ioctl(inode->i_rdev, cmd, arg);
1587 case HDIO_GET_BUSSTATE:
1588 if (!capable(CAP_SYS_ADMIN))
1590 if (put_user(HWIF(drive)->bus_state, (long *)arg))
1594 case HDIO_SET_BUSSTATE:
1595 if (!capable(CAP_SYS_ADMIN))
1597 if (HWIF(drive)->busproc)
1598 HWIF(drive)->busproc(drive, (int)arg);
1602 if (drive->driver != NULL)
1603 return DRIVER(drive)->ioctl(drive, inode, file, cmd, arg);
1608 static int ide_check_media_change (kdev_t i_rdev)
1612 if ((drive = get_info_ptr(i_rdev)) == NULL)
1614 if (drive->driver != NULL)
1615 return DRIVER(drive)->media_change(drive);
1620 * stridx() returns the offset of c within s,
1621 * or -1 if c is '\0' or not found within s.
1623 static int __init stridx (const char *s, char c)
1625 char *i = strchr(s, c);
1626 return (i && c) ? i - s : -1;
1630 * match_parm() does parsing for ide_setup():
1632 * 1. the first char of s must be '='.
1633 * 2. if the remainder matches one of the supplied keywords,
1634 * the index (1 based) of the keyword is negated and returned.
1635 * 3. if the remainder is a series of no more than max_vals numbers
1636 * separated by commas, the numbers are saved in vals[] and a
1637 * count of how many were saved is returned. Base10 is assumed,
1638 * and base16 is allowed when prefixed with "0x".
1639 * 4. otherwise, zero is returned.
1641 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
1643 static const char *decimal = "0123456789";
1644 static const char *hex = "0123456789abcdef";
1649 * Try matching against the supplied keywords,
1650 * and return -(index+1) if we match one
1652 if (keywords != NULL) {
1653 for (i = 0; *keywords != NULL; ++i) {
1654 if (!strcmp(s, *keywords++))
1659 * Look for a series of no more than "max_vals"
1660 * numeric values separated by commas, in base10,
1661 * or base16 when prefixed with "0x".
1662 * Return a count of how many were found.
1664 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
1666 while ((i = stridx(decimal, *++s)) >= 0)
1667 vals[n] = (vals[n] * 10) + i;
1668 if (*s == 'x' && !vals[n]) {
1669 while ((i = stridx(hex, *++s)) >= 0)
1670 vals[n] = (vals[n] * 0x10) + i;
1672 if (++n == max_vals)
1674 if (*s == ',' || *s == ';')
1680 return 0; /* zero = nothing matched */
1684 * ide_setup() gets called VERY EARLY during initialization,
1685 * to handle kernel "command line" strings beginning with "hdx="
1686 * or "ide". Here is the complete set currently supported:
1688 * "hdx=" is recognized for all "x" from "a" to "h", such as "hdc".
1689 * "idex=" is recognized for all "x" from "0" to "3", such as "ide1".
1691 * "hdx=noprobe" : drive may be present, but do not probe for it
1692 * "hdx=none" : drive is NOT present, ignore cmos and do not probe
1693 * "hdx=nowerr" : ignore the WRERR_STAT bit on this drive
1694 * "hdx=cdrom" : drive is present, and is a cdrom drive
1695 * "hdx=cyl,head,sect" : disk drive is present, with specified geometry
1696 * "hdx=noremap" : do not remap 0->1 even though EZD was detected
1697 * "hdx=autotune" : driver will attempt to tune interface speed
1698 * to the fastest PIO mode supported,
1699 * if possible for this drive only.
1700 * Not fully supported by all chipset types,
1701 * and quite likely to cause trouble with
1702 * older/odd IDE drives.
1704 * "hdx=slow" : insert a huge pause after each access to the data
1705 * port. Should be used only as a last resort.
1707 * "hdx=swapdata" : when the drive is a disk, byte swap all data
1708 * "hdx=bswap" : same as above..........
1709 * "hdxlun=xx" : set the drive last logical unit.
1710 * "hdx=flash" : allows for more than one ata_flash disk to be
1711 * registered. In most cases, only one device
1713 * "hdx=scsi" : the return of the ide-scsi flag, this is useful for
1714 * allowwing ide-floppy, ide-tape, and ide-cdrom|writers
1715 * to use ide-scsi emulation on a device specific option.
1716 * "idebus=xx" : inform IDE driver of VESA/PCI bus speed in MHz,
1717 * where "xx" is between 20 and 66 inclusive,
1718 * used when tuning chipset PIO modes.
1719 * For PCI bus, 25 is correct for a P75 system,
1720 * 30 is correct for P90,P120,P180 systems,
1721 * and 33 is used for P100,P133,P166 systems.
1722 * If in doubt, use idebus=33 for PCI.
1723 * As for VLB, it is safest to not specify it.
1725 * "idex=noprobe" : do not attempt to access/use this interface
1726 * "idex=base" : probe for an interface at the addr specified,
1727 * where "base" is usually 0x1f0 or 0x170
1728 * and "ctl" is assumed to be "base"+0x206
1729 * "idex=base,ctl" : specify both base and ctl
1730 * "idex=base,ctl,irq" : specify base, ctl, and irq number
1731 * "idex=autotune" : driver will attempt to tune interface speed
1732 * to the fastest PIO mode supported,
1733 * for all drives on this interface.
1734 * Not fully supported by all chipset types,
1735 * and quite likely to cause trouble with
1736 * older/odd IDE drives.
1737 * "idex=noautotune" : driver will NOT attempt to tune interface speed
1738 * This is the default for most chipsets,
1739 * except the cmd640.
1740 * "idex=serialize" : do not overlap operations on idex and ide(x^1)
1741 * "idex=four" : four drives on idex and ide(x^1) share same ports
1742 * "idex=reset" : reset interface before first use
1743 * "idex=dma" : enable DMA by default on both drives if possible
1744 * "idex=ata66" : informs the interface that it has an 80c cable
1745 * for chipsets that are ATA-66 capable, but
1746 * the ablity to bit test for detection is
1747 * currently unknown.
1748 * "ide=reverse" : Formerly called to pci sub-system, but now local.
1750 * The following are valid ONLY on ide0, (except dc4030)
1751 * and the defaults for the base,ctl ports must not be altered.
1753 * "ide0=dtc2278" : probe/support DTC2278 interface
1754 * "ide0=ht6560b" : probe/support HT6560B interface
1755 * "ide0=cmd640_vlb" : *REQUIRED* for VLB cards with the CMD640 chip
1756 * (not for PCI -- automatically detected)
1757 * "ide0=qd65xx" : probe/support qd65xx interface
1758 * "ide0=ali14xx" : probe/support ali14xx chipsets (ALI M1439, M1443, M1445)
1759 * "ide0=umc8672" : probe/support umc8672 chipsets
1760 * "idex=dc4030" : probe/support Promise DC4030VL interface
1761 * "ide=doubler" : probe/support IDE doublers on Amiga
1763 int __init ide_setup (char *s)
1768 unsigned int hw, unit;
1769 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
1770 const char max_hwif = '0' + (MAX_HWIFS - 1);
1773 if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
1774 return 0; /* driver and not us */
1776 if (strncmp(s,"ide",3) &&
1777 strncmp(s,"idebus",6) &&
1778 strncmp(s,"hd",2)) /* hdx= & hdxlun= */
1781 printk(KERN_INFO "ide_setup: %s", s);
1784 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
1785 if (!strcmp(s, "ide=doubler")) {
1786 extern int ide_doubler;
1788 printk(" : Enabled support for IDE doublers\n");
1792 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1794 if (!strcmp(s, "ide=nodma")) {
1795 printk(" : Prevented DMA\n");
1800 #ifdef CONFIG_BLK_DEV_IDEPCI
1801 if (!strcmp(s, "ide=reverse")) {
1802 ide_scan_direction = 1;
1803 printk(" : Enabled support for IDE inverse scan order.\n");
1806 #endif /* CONFIG_BLK_DEV_IDEPCI */
1809 * Look for drive options: "hdx="
1811 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1812 const char *hd_words[] = {"none", "noprobe", "nowerr", "cdrom",
1813 "serialize", "autotune", "noautotune",
1814 "slow", "swapdata", "bswap", "flash",
1815 "remap", "noremap", "scsi", NULL};
1817 hw = unit / MAX_DRIVES;
1818 unit = unit % MAX_DRIVES;
1819 hwif = &ide_hwifs[hw];
1820 drive = &hwif->drives[unit];
1821 if (strncmp(s + 4, "ide-", 4) == 0) {
1822 strncpy(drive->driver_req, s + 4, 9);
1826 * Look for last lun option: "hdxlun="
1828 if (s[3] == 'l' && s[4] == 'u' && s[5] == 'n') {
1829 if (match_parm(&s[6], NULL, vals, 1) != 1)
1831 if (vals[0] >= 0 && vals[0] <= 7) {
1832 drive->last_lun = vals[0];
1833 drive->forced_lun = 1;
1835 printk(" -- BAD LAST LUN! Expected value from 0 to 7");
1838 switch (match_parm(&s[3], hd_words, vals, 3)) {
1839 case -1: /* "none" */
1840 drive->nobios = 1; /* drop into "noprobe" */
1841 case -2: /* "noprobe" */
1844 case -3: /* "nowerr" */
1845 drive->bad_wstat = BAD_R_STAT;
1848 case -4: /* "cdrom" */
1850 drive->media = ide_cdrom;
1853 case -5: /* "serialize" */
1854 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1856 case -6: /* "autotune" */
1857 drive->autotune = 1;
1859 case -7: /* "noautotune" */
1860 drive->autotune = 2;
1862 case -8: /* "slow" */
1865 case -9: /* "swapdata" or "bswap" */
1869 case -11: /* "flash" */
1870 drive->ata_flash = 1;
1872 case -12: /* "remap" */
1873 drive->remap_0_to_1 = 1;
1875 case -13: /* "noremap" */
1876 drive->remap_0_to_1 = 2;
1878 case -14: /* "scsi" */
1879 #if defined(CONFIG_BLK_DEV_IDESCSI) && defined(CONFIG_SCSI)
1885 #endif /* defined(CONFIG_BLK_DEV_IDESCSI) && defined(CONFIG_SCSI) */
1886 case 3: /* cyl,head,sect */
1887 drive->media = ide_disk;
1888 drive->cyl = drive->bios_cyl = vals[0];
1889 drive->head = drive->bios_head = vals[1];
1890 drive->sect = drive->bios_sect = vals[2];
1892 drive->forced_geom = 1;
1900 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1903 * Look for bus speed option: "idebus="
1905 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1906 if (match_parm(&s[6], NULL, vals, 1) != 1)
1908 if (vals[0] >= 20 && vals[0] <= 66) {
1909 idebus_parameter = vals[0];
1911 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1915 * Look for interface options: "idex="
1917 if (s[3] >= '0' && s[3] <= max_hwif) {
1919 * Be VERY CAREFUL changing this: note hardcoded indexes below
1920 * -8,-9,-10 : are reserved for future idex calls to ease the hardcoding.
1922 const char *ide_words[] = {
1923 "noprobe", "serialize", "autotune", "noautotune", "reset", "dma", "ata66",
1924 "minus8", "minus9", "minus10",
1925 "four", "qd65xx", "ht6560b", "cmd640_vlb", "dtc2278", "umc8672", "ali14xx", "dc4030", NULL };
1927 hwif = &ide_hwifs[hw];
1928 i = match_parm(&s[4], ide_words, vals, 3);
1931 * Cryptic check to ensure chipset not already set for hwif:
1933 if (i > 0 || i <= -11) { /* is parameter a chipset name? */
1934 if (hwif->chipset != ide_unknown)
1935 goto bad_option; /* chipset already specified */
1936 if (i <= -11 && i != -18 && hw != 0)
1937 goto bad_hwif; /* chipset drivers are for "ide0=" only */
1938 if (i <= -11 && i != -18 && ide_hwifs[hw+1].chipset != ide_unknown)
1939 goto bad_option; /* chipset for 2nd port already specified */
1944 #ifdef CONFIG_BLK_DEV_PDC4030
1945 case -18: /* "dc4030" */
1947 extern void init_pdc4030(void);
1951 #endif /* CONFIG_BLK_DEV_PDC4030 */
1952 #ifdef CONFIG_BLK_DEV_ALI14XX
1953 case -17: /* "ali14xx" */
1955 extern void init_ali14xx (void);
1959 #endif /* CONFIG_BLK_DEV_ALI14XX */
1960 #ifdef CONFIG_BLK_DEV_UMC8672
1961 case -16: /* "umc8672" */
1963 extern void init_umc8672 (void);
1967 #endif /* CONFIG_BLK_DEV_UMC8672 */
1968 #ifdef CONFIG_BLK_DEV_DTC2278
1969 case -15: /* "dtc2278" */
1971 extern void init_dtc2278 (void);
1975 #endif /* CONFIG_BLK_DEV_DTC2278 */
1976 #ifdef CONFIG_BLK_DEV_CMD640
1977 case -14: /* "cmd640_vlb" */
1979 extern int cmd640_vlb; /* flag for cmd640.c */
1983 #endif /* CONFIG_BLK_DEV_CMD640 */
1984 #ifdef CONFIG_BLK_DEV_HT6560B
1985 case -13: /* "ht6560b" */
1987 extern void init_ht6560b (void);
1991 #endif /* CONFIG_BLK_DEV_HT6560B */
1992 #if CONFIG_BLK_DEV_QD65XX
1993 case -12: /* "qd65xx" */
1995 extern void init_qd65xx (void);
1999 #endif /* CONFIG_BLK_DEV_QD65XX */
2000 #ifdef CONFIG_BLK_DEV_4DRIVES
2001 case -11: /* "four" drives on one set of ports */
2003 ide_hwif_t *mate = &ide_hwifs[hw^1];
2004 mate->drives[0].select.all ^= 0x20;
2005 mate->drives[1].select.all ^= 0x20;
2006 hwif->chipset = mate->chipset = ide_4drives;
2007 mate->irq = hwif->irq;
2008 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
2011 #endif /* CONFIG_BLK_DEV_4DRIVES */
2012 case -10: /* minus10 */
2013 case -9: /* minus9 */
2014 case -8: /* minus8 */
2016 case -7: /* ata66 */
2017 #ifdef CONFIG_BLK_DEV_IDEPCI
2018 hwif->udma_four = 1;
2020 #else /* !CONFIG_BLK_DEV_IDEPCI */
2021 hwif->udma_four = 0;
2023 #endif /* CONFIG_BLK_DEV_IDEPCI */
2027 case -5: /* "reset" */
2030 case -4: /* "noautotune" */
2031 hwif->drives[0].autotune = 2;
2032 hwif->drives[1].autotune = 2;
2034 case -3: /* "autotune" */
2035 hwif->drives[0].autotune = 1;
2036 hwif->drives[1].autotune = 1;
2038 case -2: /* "serialize" */
2040 hwif->mate = &ide_hwifs[hw^1];
2041 hwif->mate->mate = hwif;
2042 hwif->serialized = hwif->mate->serialized = 1;
2045 case -1: /* "noprobe" */
2050 vals[1] = vals[0] + 0x206; /* default ctl */
2051 case 2: /* base,ctl */
2052 vals[2] = 0; /* default irq = probe for it */
2053 case 3: /* base,ctl,irq */
2054 hwif->hw.irq = vals[2];
2055 ide_init_hwif_ports(&hwif->hw, (ide_ioreg_t) vals[0], (ide_ioreg_t) vals[1], &hwif->irq);
2056 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
2057 hwif->irq = vals[2];
2059 hwif->chipset = ide_generic;
2062 case 0: goto bad_option;
2064 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2069 printk(" -- BAD OPTION\n");
2072 printk("-- NOT SUPPORTED ON ide%d", hw);
2079 * probe_for_hwifs() finds/initializes "known" IDE interfaces
2081 static void __init probe_for_hwifs (void)
2083 #ifdef CONFIG_BLK_DEV_IDEPCI
2086 ide_scan_pcibus(ide_scan_direction);
2088 #endif /* CONFIG_BLK_DEV_IDEPCI */
2090 #ifdef CONFIG_ETRAX_IDE
2092 extern void init_e100_ide(void);
2095 #endif /* CONFIG_ETRAX_IDE */
2096 #ifdef CONFIG_BLK_DEV_CMD640
2098 extern void ide_probe_for_cmd640x(void);
2099 ide_probe_for_cmd640x();
2101 #endif /* CONFIG_BLK_DEV_CMD640 */
2102 #ifdef CONFIG_BLK_DEV_PDC4030
2104 extern int ide_probe_for_pdc4030(void);
2105 (void) ide_probe_for_pdc4030();
2107 #endif /* CONFIG_BLK_DEV_PDC4030 */
2108 #ifdef CONFIG_BLK_DEV_IDE_PMAC
2110 extern void pmac_ide_probe(void);
2113 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
2114 #ifdef CONFIG_BLK_DEV_IDE_SIBYTE
2116 extern void sibyte_ide_probe(void);
2119 #endif /* CONFIG_BLK_DEV_IDE_SIBYTE */
2120 #ifdef CONFIG_BLK_DEV_IDE_ICSIDE
2122 extern void icside_init(void);
2125 #endif /* CONFIG_BLK_DEV_IDE_ICSIDE */
2126 #ifdef CONFIG_BLK_DEV_IDE_RAPIDE
2128 extern void rapide_init(void);
2131 #endif /* CONFIG_BLK_DEV_IDE_RAPIDE */
2132 #ifdef CONFIG_BLK_DEV_GAYLE
2134 extern void gayle_init(void);
2137 #endif /* CONFIG_BLK_DEV_GAYLE */
2138 #ifdef CONFIG_BLK_DEV_FALCON_IDE
2140 extern void falconide_init(void);
2143 #endif /* CONFIG_BLK_DEV_FALCON_IDE */
2144 #ifdef CONFIG_BLK_DEV_MAC_IDE
2146 extern void macide_init(void);
2149 #endif /* CONFIG_BLK_DEV_MAC_IDE */
2150 #ifdef CONFIG_BLK_DEV_CPCI405_IDE
2152 extern void cpci405ide_init(void);
2155 #endif /* CONFIG_BLK_DEV_CPCI405_IDE */
2156 #ifdef CONFIG_BLK_DEV_Q40IDE
2158 extern void q40ide_init(void);
2161 #endif /* CONFIG_BLK_DEV_Q40IDE */
2162 #ifdef CONFIG_BLK_DEV_BUDDHA
2164 extern void buddha_init(void);
2167 #endif /* CONFIG_BLK_DEV_BUDDHA */
2168 #if defined(CONFIG_BLK_DEV_ISAPNP) && defined(CONFIG_ISAPNP)
2170 extern void pnpide_init(int enable);
2173 #endif /* CONFIG_BLK_DEV_ISAPNP */
2176 void __init ide_init_builtin_subdrivers (void)
2178 #ifdef CONFIG_BLK_DEV_IDEDISK
2179 (void) idedisk_init();
2180 #endif /* CONFIG_BLK_DEV_IDEDISK */
2181 #ifdef CONFIG_BLK_DEV_IDECD
2182 (void) ide_cdrom_init();
2183 #endif /* CONFIG_BLK_DEV_IDECD */
2184 #ifdef CONFIG_BLK_DEV_IDETAPE
2185 (void) idetape_init();
2186 #endif /* CONFIG_BLK_DEV_IDETAPE */
2187 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
2188 (void) idefloppy_init();
2189 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
2190 #ifdef CONFIG_BLK_DEV_IDESCSI
2192 (void) idescsi_init();
2194 #warning ide scsi-emulation selected but no SCSI-subsystem in kernel
2196 #endif /* CONFIG_BLK_DEV_IDESCSI */
2199 #ifndef CLASSIC_BUILTINS_METHOD
2200 # ifndef DIRECT_HWIF_PROBE_ATTACH_METHOD
2201 # ifdef FAKE_CLASSIC_ATTACH_METHOD
2203 * Attempt to match drivers for the available drives
2205 void ide_attach_devices (void)
2211 for (i = 0; i < MAX_HWIFS; i++) {
2212 hwif = &ide_hwifs[i];
2215 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2216 drive = &hwif->drives[unit];
2217 if (drive->present && !drive->dead)
2218 ide_attach_drive(drive);
2222 # endif /* FAKE_CLASSIC_ATTACH_METHOD */
2223 # endif /* DIRECT_HWIF_PROBE_ATTACH_METHOD */
2224 #endif /* CLASSIC_BUILTINS_METHOD */
2226 void __init ide_init_builtin_drivers (void)
2229 * Probe for special PCI and other "known" interface chipsets
2233 #ifdef CONFIG_BLK_DEV_IDE
2234 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
2235 ide_get_lock(&ide_intr_lock, NULL, NULL); /* for atari only */
2237 (void) ideprobe_init();
2239 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
2240 ide_release_lock(&ide_intr_lock); /* for atari only */
2241 #endif /* CONFIG_BLK_DEV_IDE */
2243 #ifdef CONFIG_PROC_FS
2247 #ifdef CLASSIC_BUILTINS_METHOD
2248 ide_init_builtin_subdrivers();
2249 #else /* ! CLASSIC_BUILTINS_METHOD */
2250 # ifndef DIRECT_HWIF_PROBE_ATTACH_METHOD
2251 # ifdef FAKE_CLASSIC_ATTACH_METHOD
2252 ide_attach_devices();
2253 # endif /* FAKE_CLASSIC_ATTACH_METHOD */
2254 # endif /* DIRECT_HWIF_PROBE_ATTACH_METHOD */
2255 #endif /* CLASSIC_BUILTINS_METHOD */
2259 * Actually unregister the subdriver. Called with the
2260 * request lock dropped.
2263 static int default_cleanup (ide_drive_t *drive)
2265 return ide_unregister_subdriver(drive);
2269 * Check if we can unregister the subdriver. Called with the
2270 * request lock held.
2273 static int default_shutdown(ide_drive_t *drive)
2275 if (drive->usage || drive->busy ||
2276 drive->driver == NULL || DRIVER(drive)->busy) {
2283 static int default_standby (ide_drive_t *drive)
2288 static int default_suspend (ide_drive_t *drive)
2293 static int default_resume (ide_drive_t *drive)
2298 static int default_flushcache (ide_drive_t *drive)
2303 static ide_startstop_t default_do_request (ide_drive_t *drive, struct request *rq, unsigned long block)
2305 ide_end_request(drive, 0);
2309 static int default_end_request (ide_drive_t *drive, int uptodate)
2311 return ide_end_request(drive, uptodate);
2314 static u8 default_sense (ide_drive_t *drive, const char *msg, u8 stat)
2316 return ide_dump_status(drive, msg, stat);
2319 static ide_startstop_t default_error (ide_drive_t *drive, const char *msg, u8 stat)
2321 return ide_error(drive, msg, stat);
2324 static int default_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
2325 unsigned int cmd, unsigned long arg)
2330 static int default_open (struct inode *inode, struct file *filp, ide_drive_t *drive)
2336 static void default_release (struct inode *inode, struct file *filp, ide_drive_t *drive)
2340 static int default_check_media_change (ide_drive_t *drive)
2345 static void default_pre_reset (ide_drive_t *drive)
2349 static unsigned long default_capacity (ide_drive_t *drive)
2354 static ide_startstop_t default_special (ide_drive_t *drive)
2356 special_t *s = &drive->special;
2359 drive->mult_req = 0;
2363 static int default_init (void)
2368 static int default_attach (ide_drive_t *drive)
2370 printk(KERN_ERR "%s: does not support hotswap of device class !\n",
2376 static void setup_driver_defaults (ide_drive_t *drive)
2378 ide_driver_t *d = drive->driver;
2380 if (d->cleanup == NULL) d->cleanup = default_cleanup;
2381 if (d->shutdown == NULL) d->shutdown = default_shutdown;
2382 if (d->standby == NULL) d->standby = default_standby;
2383 if (d->suspend == NULL) d->suspend = default_suspend;
2384 if (d->resume == NULL) d->resume = default_resume;
2385 if (d->flushcache == NULL) d->flushcache = default_flushcache;
2386 if (d->do_request == NULL) d->do_request = default_do_request;
2387 if (d->end_request == NULL) d->end_request = default_end_request;
2388 if (d->sense == NULL) d->sense = default_sense;
2389 if (d->error == NULL) d->error = default_error;
2390 if (d->ioctl == NULL) d->ioctl = default_ioctl;
2391 if (d->open == NULL) d->open = default_open;
2392 if (d->release == NULL) d->release = default_release;
2393 if (d->media_change == NULL) d->media_change = default_check_media_change;
2394 if (d->pre_reset == NULL) d->pre_reset = default_pre_reset;
2395 if (d->capacity == NULL) d->capacity = default_capacity;
2396 if (d->special == NULL) d->special = default_special;
2397 if (d->init == NULL) d->init = default_init;
2398 if (d->attach == NULL) d->attach = default_attach;
2401 ide_drive_t *ide_scan_devices (u8 media, const char *name, ide_driver_t *driver, int n)
2403 unsigned int unit, index, i;
2405 for (index = 0, i = 0; index < MAX_HWIFS; ++index) {
2406 ide_hwif_t *hwif = &ide_hwifs[index];
2409 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2410 ide_drive_t *drive = &hwif->drives[unit];
2411 char *req = drive->driver_req;
2412 if (*req && !strstr(name, req))
2414 if (drive->present && drive->media == media &&
2415 drive->driver == driver && ++i > n)
2422 EXPORT_SYMBOL(ide_scan_devices);
2424 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version)
2426 unsigned long flags;
2428 spin_lock_irqsave(&io_request_lock, flags);
2429 if (version != IDE_SUBDRIVER_VERSION || !drive->present ||
2430 drive->driver != NULL || drive->busy || drive->usage) {
2431 spin_unlock_irqrestore(&io_request_lock, flags);
2434 drive->driver = driver;
2435 setup_driver_defaults(drive);
2436 spin_unlock_irqrestore(&io_request_lock, flags);
2437 if (drive->autotune != 2) {
2438 /* DMA timings and setup moved to ide-probe.c */
2439 if (!driver->supports_dma && HWIF(drive)->ide_dma_off_quietly)
2440 // HWIF(drive)->ide_dma_off_quietly(drive);
2441 HWIF(drive)->ide_dma_off(drive);
2442 drive->dsc_overlap = (drive->next != drive && driver->supports_dsc_overlap);
2445 drive->revalidate = 1;
2446 drive->suspend_reset = 0;
2447 #ifdef CONFIG_PROC_FS
2448 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
2449 ide_add_proc_entries(drive->proc, driver->proc, drive);
2454 EXPORT_SYMBOL(ide_register_subdriver);
2456 int ide_unregister_subdriver (ide_drive_t *drive)
2458 unsigned long flags;
2460 spin_lock_irqsave(&io_request_lock, flags);
2461 if (drive->usage || drive->busy ||
2462 drive->driver == NULL || DRIVER(drive)->busy) {
2463 spin_unlock_irqrestore(&io_request_lock, flags);
2466 #if defined(CONFIG_BLK_DEV_ISAPNP) && defined(CONFIG_ISAPNP) && defined(MODULE)
2468 #endif /* CONFIG_BLK_DEV_ISAPNP */
2469 #ifdef CONFIG_PROC_FS
2470 ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc);
2471 ide_remove_proc_entries(drive->proc, generic_subdriver_entries);
2473 auto_remove_settings(drive);
2474 drive->driver = NULL;
2475 spin_unlock_irqrestore(&io_request_lock, flags);
2479 EXPORT_SYMBOL(ide_unregister_subdriver);
2481 int ide_register_module (ide_module_t *module)
2483 ide_module_t *p = ide_modules;
2490 module->next = ide_modules;
2491 ide_modules = module;
2492 revalidate_drives(1);
2496 EXPORT_SYMBOL(ide_register_module);
2498 void ide_unregister_module (ide_module_t *module)
2502 for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next));
2507 EXPORT_SYMBOL(ide_unregister_module);
2509 struct block_device_operations ide_fops[] = {{
2512 release: ide_release,
2514 check_media_change: ide_check_media_change,
2515 revalidate: ide_revalidate_disk
2518 EXPORT_SYMBOL(ide_fops);
2521 * ide_geninit() is called exactly *once* for each interface.
2523 void ide_geninit (ide_hwif_t *hwif)
2526 struct gendisk *gd = hwif->gd;
2528 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2529 ide_drive_t *drive = &hwif->drives[unit];
2531 if (!drive->present)
2533 if (drive->media!=ide_disk && drive->media!=ide_floppy)
2535 register_disk(gd,MKDEV(hwif->major,unit<<PARTN_BITS),
2536 #ifdef CONFIG_BLK_DEV_ISAPNP
2537 (drive->forced_geom && drive->noprobe) ? 1 :
2538 #endif /* CONFIG_BLK_DEV_ISAPNP */
2539 1<<PARTN_BITS, ide_fops,
2540 current_capacity(drive));
2544 EXPORT_SYMBOL(ide_geninit);
2550 devfs_handle_t ide_devfs_handle;
2552 EXPORT_SYMBOL(ide_probe);
2553 EXPORT_SYMBOL(ide_devfs_handle);
2555 static int ide_notify_reboot (struct notifier_block *this, unsigned long event, void *x)
2570 printk(KERN_INFO "flushing ide devices: ");
2572 for (i = 0; i < MAX_HWIFS; i++) {
2573 hwif = &ide_hwifs[i];
2576 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2577 drive = &hwif->drives[unit];
2578 if (!drive->present)
2581 /* set the drive to standby */
2582 printk("%s ", drive->name);
2583 if (event != SYS_RESTART)
2584 if (drive->driver != NULL && DRIVER(drive)->standby(drive))
2587 if (drive->driver != NULL)
2589 DRIVER(drive)->cleanup(drive);
2598 static struct notifier_block ide_notifier = {
2605 * This is gets invoked once during initialization, to set *everything* up
2607 int __init ide_init (void)
2609 static char banner_printed;
2612 if (!banner_printed) {
2613 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
2614 ide_devfs_handle = devfs_mk_dir(NULL, "ide", NULL);
2615 system_bus_speed = ide_system_bus_speed();
2621 #ifndef CLASSIC_BUILTINS_METHOD
2622 ide_init_builtin_subdrivers();
2623 #endif /* CLASSIC_BUILTINS_METHOD */
2626 ide_init_builtin_drivers();
2629 for (i = 0; i < MAX_HWIFS; ++i) {
2630 ide_hwif_t *hwif = &ide_hwifs[i];
2635 register_reboot_notifier(&ide_notifier);
2640 char *options = NULL;
2641 MODULE_PARM(options,"s");
2642 MODULE_LICENSE("GPL");
2644 static void __init parse_options (char *line)
2648 if (line == NULL || !*line)
2650 while ((line = next) != NULL) {
2651 if ((next = strchr(line,' ')) != NULL)
2653 if (!ide_setup(line))
2654 printk ("Unknown option '%s'\n", line);
2658 int init_module (void)
2660 parse_options(options);
2664 void cleanup_module (void)
2668 unregister_reboot_notifier(&ide_notifier);
2669 for (index = 0; index < MAX_HWIFS; ++index) {
2670 ide_unregister(index);
2671 #if !defined(CONFIG_DMA_NONPCI)
2672 if (ide_hwifs[index].dma_base)
2673 (void) ide_release_dma(&ide_hwifs[index]);
2674 #endif /* !(CONFIG_DMA_NONPCI) */
2677 #ifdef CONFIG_PROC_FS
2680 devfs_unregister (ide_devfs_handle);
2685 __setup("", ide_setup);
2686 module_init(ide_init);