2 * linux/drivers/ide/ide.c Version 7.00beta2 Mar 05 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
119 * Some additional driver compile-time options are in ./include/linux/ide.h
121 * To do, in likely order of completion:
122 * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
126 #define REVISION "Revision: 7.00alpha2"
127 #define VERSION "Id: ide.c 7.00a2 20020906"
129 #undef REALLY_SLOW_IO /* most systems can safely undef this */
131 #define _IDE_C /* Tell ide.h it's really us */
133 #include <linux/config.h>
134 #include <linux/module.h>
135 #include <linux/types.h>
136 #include <linux/string.h>
137 #include <linux/kernel.h>
138 #include <linux/timer.h>
139 #include <linux/mm.h>
140 #include <linux/interrupt.h>
141 #include <linux/major.h>
142 #include <linux/errno.h>
143 #include <linux/genhd.h>
144 #include <linux/blkpg.h>
145 #include <linux/slab.h>
146 #include <linux/init.h>
147 #include <linux/pci.h>
148 #include <linux/delay.h>
149 #include <linux/ide.h>
150 #include <linux/devfs_fs_kernel.h>
151 #include <linux/completion.h>
152 #include <linux/reboot.h>
153 #include <linux/cdrom.h>
154 #include <linux/seq_file.h>
155 #include <linux/device.h>
156 #include <linux/bitops.h>
158 #include <asm/byteorder.h>
160 #include <asm/uaccess.h>
164 /* default maximum number of failures */
165 #define IDE_DEFAULT_MAX_FAILURES 1
167 static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
168 IDE2_MAJOR, IDE3_MAJOR,
169 IDE4_MAJOR, IDE5_MAJOR,
170 IDE6_MAJOR, IDE7_MAJOR,
171 IDE8_MAJOR, IDE9_MAJOR };
173 static int idebus_parameter; /* holds the "idebus=" parameter */
174 static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
175 static int initializing; /* set while initializing built-in drivers */
177 DECLARE_MUTEX(ide_cfg_sem);
178 spinlock_t ide_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
180 #ifdef CONFIG_BLK_DEV_IDEPCI
181 static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
184 #ifdef CONFIG_IDEDMA_AUTO
190 EXPORT_SYMBOL(noautodma);
193 * This is declared extern in ide.h, for access by other IDE modules:
195 ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
197 EXPORT_SYMBOL(ide_hwifs);
199 extern ide_driver_t idedefault_driver;
200 static void setup_driver_defaults(ide_driver_t *driver);
203 * Do not even *think* about calling this!
205 static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
209 /* bulk initialize hwif & drive info with zeros */
210 memset(hwif, 0, sizeof(ide_hwif_t));
212 /* fill in any non-zero initial values */
214 hwif->major = ide_hwif_to_major[index];
219 hwif->name[3] = '0' + index;
221 hwif->bus_state = BUSSTATE_ON;
223 hwif->atapi_dma = 0; /* disable all atapi dma */
224 hwif->ultra_mask = 0x80; /* disable all ultra */
225 hwif->mwdma_mask = 0x80; /* disable all mwdma */
226 hwif->swdma_mask = 0x80; /* disable all swdma */
228 sema_init(&hwif->gendev_rel_sem, 0);
230 default_hwif_iops(hwif);
231 default_hwif_transport(hwif);
232 for (unit = 0; unit < MAX_DRIVES; ++unit) {
233 ide_drive_t *drive = &hwif->drives[unit];
235 drive->media = ide_disk;
236 drive->select.all = (unit<<4)|0xa0;
239 drive->ready_stat = READY_STAT;
240 drive->bad_wstat = BAD_W_STAT;
241 drive->special.b.recalibrate = 1;
242 drive->special.b.set_geometry = 1;
243 drive->name[0] = 'h';
244 drive->name[1] = 'd';
245 drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
246 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
247 drive->using_dma = 0;
249 drive->driver = &idedefault_driver;
251 INIT_LIST_HEAD(&drive->list);
252 sema_init(&drive->gendev_rel_sem, 0);
256 static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
260 memset(&hw, 0, sizeof(hw_regs_t));
262 ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
264 memcpy(&hwif->hw, &hw, sizeof(hw));
265 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
267 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
268 #ifdef CONFIG_BLK_DEV_HD
269 if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
270 hwif->noprobe = 1; /* may be overridden by ide_setup() */
274 extern void ide_arm_init(void);
277 * init_ide_data() sets reasonable default values into all fields
278 * of all instances of the hwifs and drives, but only on the first call.
279 * Subsequent calls have no effect (they don't wipe out anything).
281 * This routine is normally called at driver initialization time,
282 * but may also be called MUCH earlier during kernel "command-line"
283 * parameter processing. As such, we cannot depend on any other parts
284 * of the kernel (such as memory allocation) to be functioning yet.
286 * This is too bad, as otherwise we could dynamically allocate the
287 * ide_drive_t structs as needed, rather than always consuming memory
288 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
290 * FIXME: We should stuff the setup data into __init and copy the
291 * relevant hwifs/allocate them properly during boot.
293 #define MAGIC_COOKIE 0x12345678
294 static void __init init_ide_data (void)
298 static unsigned long magic_cookie = MAGIC_COOKIE;
300 if (magic_cookie != MAGIC_COOKIE)
301 return; /* already initialized */
304 setup_driver_defaults(&idedefault_driver);
306 /* Initialise all interface structures */
307 for (index = 0; index < MAX_HWIFS; ++index) {
308 hwif = &ide_hwifs[index];
309 init_hwif_data(hwif, index);
310 init_hwif_default(hwif, index);
311 #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
312 hwif->irq = hwif->hw.irq =
313 ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
316 #ifdef CONFIG_IDE_ARM
324 * ide_system_bus_speed - guess bus speed
326 * ide_system_bus_speed() returns what we think is the system VESA/PCI
327 * bus speed (in MHz). This is used for calculating interface PIO timings.
328 * The default is 40 for known PCI systems, 50 otherwise.
329 * The "idebus=xx" parameter can be used to override this value.
330 * The actual value to be used is computed/displayed the first time
331 * through. Drivers should only use this as a last resort.
333 * Returns a guessed speed in MHz.
336 int ide_system_bus_speed (void)
338 static struct pci_device_id pci_default[] = {
339 { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
343 if (!system_bus_speed) {
344 if (idebus_parameter) {
345 /* user supplied value */
346 system_bus_speed = idebus_parameter;
347 } else if (pci_dev_present(pci_default)) {
348 /* safe default value for PCI */
349 system_bus_speed = 33;
351 /* safe default value for VESA and PCI */
352 system_bus_speed = 50;
354 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
355 "for PIO modes%s\n", system_bus_speed,
356 idebus_parameter ? "" : "; override with idebus=xx");
358 return system_bus_speed;
362 * current_capacity - drive capacity
363 * @drive: drive to query
365 * Return the current capacity (in sectors) of a drive according to
366 * its current geometry/LBA settings. Empty removables are reported
370 sector_t current_capacity (ide_drive_t *drive)
374 return DRIVER(drive)->capacity(drive);
377 EXPORT_SYMBOL(current_capacity);
380 * ide_dump_status - translate ATA error
381 * @drive: drive the error occured on
382 * @msg: information string
385 * Error reporting, in human readable form (luxurious, but a memory hog).
386 * Combines the drive name, message and status byte to provide a
387 * user understandable explanation of the device error.
390 u8 ide_dump_status (ide_drive_t *drive, const char *msg, u8 stat)
392 ide_hwif_t *hwif = HWIF(drive);
396 local_irq_set(flags);
397 printk(KERN_WARNING "%s: %s: status=0x%02x", drive->name, msg, stat);
399 if (stat & BUSY_STAT) {
402 if (stat & READY_STAT) printk("DriveReady ");
403 if (stat & WRERR_STAT) printk("DeviceFault ");
404 if (stat & SEEK_STAT) printk("SeekComplete ");
405 if (stat & DRQ_STAT) printk("DataRequest ");
406 if (stat & ECC_STAT) printk("CorrectedError ");
407 if (stat & INDEX_STAT) printk("Index ");
408 if (stat & ERR_STAT) printk("Error ");
412 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
413 err = hwif->INB(IDE_ERROR_REG);
414 printk("%s: %s: error=0x%02x", drive->name, msg, err);
415 if (drive->media == ide_disk) {
417 if (err & ABRT_ERR) printk("DriveStatusError ");
418 if (err & ICRC_ERR) printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector");
419 if (err & ECC_ERR) printk("UncorrectableError ");
420 if (err & ID_ERR) printk("SectorIdNotFound ");
421 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
422 if (err & MARK_ERR) printk("AddrMarkNotFound ");
424 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
425 if ((drive->id->command_set_2 & 0x0400) &&
426 (drive->id->cfs_enable_2 & 0x0400) &&
427 (drive->addressing == 1)) {
430 u32 low = ide_read_24(drive);
431 hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
432 high = ide_read_24(drive);
434 sectors = ((u64)high << 24) | low;
435 printk(", LBAsect=%llu, high=%d, low=%d",
439 u8 cur = hwif->INB(IDE_SELECT_REG);
440 if (cur & 0x40) { /* using LBA? */
441 printk(", LBAsect=%ld", (unsigned long)
443 |(hwif->INB(IDE_HCYL_REG)<<16)
444 |(hwif->INB(IDE_LCYL_REG)<<8)
445 | hwif->INB(IDE_SECTOR_REG));
447 printk(", CHS=%d/%d/%d",
448 (hwif->INB(IDE_HCYL_REG)<<8) +
449 hwif->INB(IDE_LCYL_REG),
451 hwif->INB(IDE_SECTOR_REG));
454 if (HWGROUP(drive) && HWGROUP(drive)->rq)
455 printk(", sector=%llu", (unsigned long long)HWGROUP(drive)->rq->sector);
464 spin_lock(&ide_lock);
467 rq = HWGROUP(drive)->rq;
468 spin_unlock(&ide_lock);
471 if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK)) {
472 char *args = rq->buffer;
475 } else if (rq->flags & REQ_DRIVE_TASKFILE) {
476 ide_task_t *args = rq->special;
478 task_struct_t *tf = (task_struct_t *) args->tfRegister;
479 opcode = tf->command;
483 printk("ide: failed opcode was %x\n", opcode);
486 local_irq_restore(flags);
490 EXPORT_SYMBOL(ide_dump_status);
492 static int ide_open (struct inode * inode, struct file * filp)
498 * drives_lock protects the list of drives, drivers_lock the
499 * list of drivers. Currently nobody takes both at once.
502 static spinlock_t drives_lock = SPIN_LOCK_UNLOCKED;
503 static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
504 static LIST_HEAD(drivers);
506 /* Iterator for the driver list. */
508 static void *m_start(struct seq_file *m, loff_t *pos)
512 spin_lock(&drivers_lock);
513 list_for_each(p, &drivers)
515 return list_entry(p, ide_driver_t, drivers);
519 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
521 struct list_head *p = ((ide_driver_t *)v)->drivers.next;
523 return p==&drivers ? NULL : list_entry(p, ide_driver_t, drivers);
526 static void m_stop(struct seq_file *m, void *v)
528 spin_unlock(&drivers_lock);
531 static int show_driver(struct seq_file *m, void *v)
533 ide_driver_t *driver = v;
534 seq_printf(m, "%s version %s\n", driver->name, driver->version);
538 struct seq_operations ide_drivers_op = {
545 #ifdef CONFIG_PROC_FS
546 struct proc_dir_entry *proc_ide_root;
548 ide_proc_entry_t generic_subdriver_entries[] = {
549 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
550 { NULL, 0, NULL, NULL }
554 static struct resource* hwif_request_region(ide_hwif_t *hwif,
555 unsigned long addr, int num)
557 struct resource *res = request_region(addr, num, hwif->name);
560 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
561 hwif->name, addr, addr+num-1);
566 * ide_hwif_request_regions - request resources for IDE
567 * @hwif: interface to use
569 * Requests all the needed resources for an interface.
570 * Right now core IDE code does this work which is deeply wrong.
571 * MMIO leaves it to the controller driver,
572 * PIO will migrate this way over time.
575 int ide_hwif_request_regions(ide_hwif_t *hwif)
582 BUG_ON(hwif->mmio == 1);
583 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
584 if (addr && !hwif_request_region(hwif, addr, 1))
585 goto control_region_busy;
587 addr = hwif->io_ports[IDE_DATA_OFFSET];
588 if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
589 if (!hwif_request_region(hwif, addr, 8))
590 goto data_region_busy;
594 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
595 addr = hwif->io_ports[i];
596 if (!hwif_request_region(hwif, addr, 1)) {
598 release_region(addr, 1);
599 goto data_region_busy;
605 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
607 release_region(addr, 1);
609 /* If any errors are return, we drop the hwif interface. */
614 * ide_hwif_release_regions - free IDE resources
616 * Note that we only release the standard ports,
617 * and do not even try to handle any extra ports
618 * allocated for weird IDE interface chipsets.
620 * Note also that we don't yet handle mmio resources here. More
621 * importantly our caller should be doing this so we need to
622 * restructure this as a helper function for drivers.
625 void ide_hwif_release_regions(ide_hwif_t *hwif)
631 if (hwif->io_ports[IDE_CONTROL_OFFSET])
632 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
633 if (hwif->straight8) {
634 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
637 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
638 if (hwif->io_ports[i])
639 release_region(hwif->io_ports[i], 1);
643 * ide_hwif_restore - restore hwif to template
644 * @hwif: hwif to update
645 * @tmp_hwif: template
647 * Restore hwif to a previous state by copying most settngs
651 static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
653 hwif->hwgroup = tmp_hwif->hwgroup;
655 hwif->gendev.parent = tmp_hwif->gendev.parent;
657 hwif->proc = tmp_hwif->proc;
659 hwif->major = tmp_hwif->major;
660 hwif->straight8 = tmp_hwif->straight8;
661 hwif->bus_state = tmp_hwif->bus_state;
663 hwif->atapi_dma = tmp_hwif->atapi_dma;
664 hwif->ultra_mask = tmp_hwif->ultra_mask;
665 hwif->mwdma_mask = tmp_hwif->mwdma_mask;
666 hwif->swdma_mask = tmp_hwif->swdma_mask;
668 hwif->chipset = tmp_hwif->chipset;
669 hwif->hold = tmp_hwif->hold;
671 #ifdef CONFIG_BLK_DEV_IDEPCI
672 hwif->pci_dev = tmp_hwif->pci_dev;
673 hwif->cds = tmp_hwif->cds;
676 hwif->tuneproc = tmp_hwif->tuneproc;
677 hwif->speedproc = tmp_hwif->speedproc;
678 hwif->selectproc = tmp_hwif->selectproc;
679 hwif->reset_poll = tmp_hwif->reset_poll;
680 hwif->pre_reset = tmp_hwif->pre_reset;
681 hwif->resetproc = tmp_hwif->resetproc;
682 hwif->intrproc = tmp_hwif->intrproc;
683 hwif->maskproc = tmp_hwif->maskproc;
684 hwif->quirkproc = tmp_hwif->quirkproc;
685 hwif->busproc = tmp_hwif->busproc;
687 hwif->ata_input_data = tmp_hwif->ata_input_data;
688 hwif->ata_output_data = tmp_hwif->ata_output_data;
689 hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
690 hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
692 hwif->dma_setup = tmp_hwif->dma_setup;
693 hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
694 hwif->dma_start = tmp_hwif->dma_start;
695 hwif->ide_dma_end = tmp_hwif->ide_dma_end;
696 hwif->ide_dma_check = tmp_hwif->ide_dma_check;
697 hwif->ide_dma_on = tmp_hwif->ide_dma_on;
698 hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly;
699 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
700 hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on;
701 hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off;
702 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
703 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
705 hwif->OUTB = tmp_hwif->OUTB;
706 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
707 hwif->OUTW = tmp_hwif->OUTW;
708 hwif->OUTL = tmp_hwif->OUTL;
709 hwif->OUTSW = tmp_hwif->OUTSW;
710 hwif->OUTSL = tmp_hwif->OUTSL;
712 hwif->INB = tmp_hwif->INB;
713 hwif->INW = tmp_hwif->INW;
714 hwif->INL = tmp_hwif->INL;
715 hwif->INSW = tmp_hwif->INSW;
716 hwif->INSL = tmp_hwif->INSL;
718 hwif->sg_max_nents = tmp_hwif->sg_max_nents;
720 hwif->mmio = tmp_hwif->mmio;
721 hwif->rqsize = tmp_hwif->rqsize;
722 hwif->no_lba48 = tmp_hwif->no_lba48;
724 #ifndef CONFIG_BLK_DEV_IDECS
725 hwif->irq = tmp_hwif->irq;
728 hwif->dma_base = tmp_hwif->dma_base;
729 hwif->dma_master = tmp_hwif->dma_master;
730 hwif->dma_command = tmp_hwif->dma_command;
731 hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
732 hwif->dma_status = tmp_hwif->dma_status;
733 hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
734 hwif->dma_prdtable = tmp_hwif->dma_prdtable;
736 hwif->dma_extra = tmp_hwif->dma_extra;
737 hwif->config_data = tmp_hwif->config_data;
738 hwif->select_data = tmp_hwif->select_data;
739 hwif->autodma = tmp_hwif->autodma;
740 hwif->udma_four = tmp_hwif->udma_four;
741 hwif->no_dsc = tmp_hwif->no_dsc;
743 hwif->hwif_data = tmp_hwif->hwif_data;
747 * ide_unregister - free an ide interface
748 * @index: index of interface (will change soon to a pointer)
750 * Perform the final unregister of an IDE interface. At the moment
751 * we don't refcount interfaces so this will also get split up.
754 * The caller must not hold the IDE locks
755 * The drive present/vanishing is not yet properly locked
756 * Take care with the callbacks. These have been split to avoid
757 * deadlocking the IDE layer. The shutdown callback is called
758 * before we take the lock and free resources. It is up to the
759 * caller to be sure there is no pending I/O here, and that
760 * the interfce will not be reopened (present/vanishing locking
761 * isnt yet done btw). After we commit to the final kill we
762 * call the cleanup callback with the ide locks held.
764 * Unregister restores the hwif structures to the default state.
765 * This is raving bonkers.
768 void ide_unregister(unsigned int index)
771 ide_hwif_t *hwif, *g;
772 static ide_hwif_t tmp_hwif; /* protected by ide_cfg_sem */
773 ide_hwgroup_t *hwgroup;
774 int irq_count = 0, unit, i;
776 BUG_ON(index >= MAX_HWIFS);
778 BUG_ON(in_interrupt());
779 BUG_ON(irqs_disabled());
781 spin_lock_irq(&ide_lock);
782 hwif = &ide_hwifs[index];
785 for (unit = 0; unit < MAX_DRIVES; ++unit) {
786 drive = &hwif->drives[unit];
789 if (drive->usage || DRIVER(drive)->busy)
795 spin_unlock_irq(&ide_lock);
797 for (unit = 0; unit < MAX_DRIVES; ++unit) {
798 drive = &hwif->drives[unit];
801 DRIVER(drive)->cleanup(drive);
804 destroy_proc_ide_interface(hwif);
806 hwgroup = hwif->hwgroup;
808 * free the irq if we were the only hwif using it
812 if (g->irq == hwif->irq)
815 } while (g != hwgroup->hwif);
817 free_irq(hwif->irq, hwgroup);
819 spin_lock_irq(&ide_lock);
821 * Note that we only release the standard ports,
822 * and do not even try to handle any extra ports
823 * allocated for weird IDE interface chipsets.
825 ide_hwif_release_regions(hwif);
828 * Remove us from the hwgroup, and free
829 * the hwgroup if we were the only member
831 for (i = 0; i < MAX_DRIVES; ++i) {
832 drive = &hwif->drives[i];
833 if (drive->devfs_name[0] != '\0') {
834 devfs_remove(drive->devfs_name);
835 drive->devfs_name[0] = '\0';
839 if (drive == drive->next) {
840 /* special case: last drive from hwgroup. */
841 BUG_ON(hwgroup->drive != drive);
842 hwgroup->drive = NULL;
846 walk = hwgroup->drive;
847 while (walk->next != drive)
849 walk->next = drive->next;
850 if (hwgroup->drive == drive) {
851 hwgroup->drive = drive->next;
852 hwgroup->hwif = HWIF(hwgroup->drive);
855 BUG_ON(hwgroup->drive == drive);
856 if (drive->id != NULL) {
861 /* Messed up locking ... */
862 spin_unlock_irq(&ide_lock);
863 blk_cleanup_queue(drive->queue);
864 device_unregister(&drive->gendev);
865 down(&drive->gendev_rel_sem);
866 spin_lock_irq(&ide_lock);
869 if (hwif->next == hwif) {
870 BUG_ON(hwgroup->hwif != hwif);
873 /* There is another interface in hwgroup.
874 * Unlink us, and set hwgroup->drive and ->hwif to
878 while (g->next != hwif)
880 g->next = hwif->next;
881 if (hwgroup->hwif == hwif) {
882 /* Chose a random hwif for hwgroup->hwif.
883 * It's guaranteed that there are no drives
884 * left in the hwgroup.
886 BUG_ON(hwgroup->drive != NULL);
889 BUG_ON(hwgroup->hwif == hwif);
892 /* More messed up locking ... */
893 spin_unlock_irq(&ide_lock);
894 device_unregister(&hwif->gendev);
895 down(&hwif->gendev_rel_sem);
898 * Remove us from the kernel's knowledge
900 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
901 for (i = 0; i < MAX_DRIVES; i++) {
902 struct gendisk *disk = hwif->drives[i].disk;
903 hwif->drives[i].disk = NULL;
906 kfree(hwif->sg_table);
907 unregister_blkdev(hwif->major, hwif->name);
908 spin_lock_irq(&ide_lock);
910 if (hwif->dma_base) {
911 (void) ide_release_dma(hwif);
914 hwif->dma_master = 0;
915 hwif->dma_command = 0;
916 hwif->dma_vendor1 = 0;
917 hwif->dma_status = 0;
918 hwif->dma_vendor3 = 0;
919 hwif->dma_prdtable = 0;
922 /* copy original settings */
925 /* restore hwif data to pristine status */
926 init_hwif_data(hwif, index);
927 init_hwif_default(hwif, index);
929 ide_hwif_restore(hwif, &tmp_hwif);
932 spin_unlock_irq(&ide_lock);
936 EXPORT_SYMBOL(ide_unregister);
940 * ide_setup_ports - set up IDE interface ports
941 * @hw: register descriptions
942 * @base: base register
943 * @offsets: table of register offsets
944 * @ctrl: control register
946 * @irq: interrupt lie
948 * Setup hw_regs_t structure described by parameters. You
949 * may set up the hw structure yourself OR use this routine to
950 * do it for you. This is basically a helper
954 void ide_setup_ports ( hw_regs_t *hw,
955 unsigned long base, int *offsets,
956 unsigned long ctrl, unsigned long intr,
957 ide_ack_intr_t *ack_intr,
959 * ide_io_ops_t *iops,
965 for (i = 0; i < IDE_NR_PORTS; i++) {
966 if (offsets[i] == -1) {
968 case IDE_CONTROL_OFFSET:
969 hw->io_ports[i] = ctrl;
971 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
973 hw->io_ports[i] = intr;
975 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
981 hw->io_ports[i] = base + offsets[i];
986 hw->ack_intr = ack_intr;
993 * ide_register_hw_with_fixup - register IDE interface
994 * @hw: hardware registers
995 * @hwifp: pointer to returned hwif
996 * @fixup: fixup function
998 * Register an IDE interface, specifying exactly the registers etc.
999 * Set init=1 iff calling before probes have taken place.
1001 * Returns -1 on error.
1004 int ide_register_hw_with_fixup(hw_regs_t *hw, ide_hwif_t **hwifp, void(*fixup)(ide_hwif_t *hwif))
1006 int index, retry = 1;
1010 for (index = 0; index < MAX_HWIFS; ++index) {
1011 hwif = &ide_hwifs[index];
1012 if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
1015 for (index = 0; index < MAX_HWIFS; ++index) {
1016 hwif = &ide_hwifs[index];
1019 if ((!hwif->present && !hwif->mate && !initializing) ||
1020 (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
1023 for (index = 0; index < MAX_HWIFS; index++)
1024 ide_unregister(index);
1029 ide_unregister(index);
1030 else if (!hwif->hold) {
1031 init_hwif_data(hwif, index);
1032 init_hwif_default(hwif, index);
1036 memcpy(&hwif->hw, hw, sizeof(*hw));
1037 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
1038 hwif->irq = hw->irq;
1040 hwif->chipset = hw->chipset;
1042 if (!initializing) {
1043 probe_hwif_init_with_fixup(hwif, fixup);
1044 create_proc_ide_interfaces();
1050 return (initializing || hwif->present) ? index : -1;
1053 EXPORT_SYMBOL(ide_register_hw_with_fixup);
1055 int ide_register_hw(hw_regs_t *hw, ide_hwif_t **hwifp)
1057 return ide_register_hw_with_fixup(hw, hwifp, NULL);
1060 EXPORT_SYMBOL(ide_register_hw);
1063 * Locks for IDE setting functionality
1066 DECLARE_MUTEX(ide_setting_sem);
1069 * ide_add_setting - add an ide setting option
1070 * @drive: drive to use
1071 * @name: setting name
1072 * @rw: true if the function is read write
1073 * @read_ioctl: function to call on read
1074 * @write_ioctl: function to call on write
1075 * @data_type: type of data
1076 * @min: range minimum
1077 * @max: range maximum
1078 * @mul_factor: multiplication scale
1079 * @div_factor: divison scale
1080 * @data: private data field
1083 * Removes the setting named from the device if it is present.
1084 * The function takes the settings_lock to protect against
1085 * parallel changes. This function must not be called from IRQ
1086 * context. Returns 0 on success or -1 on failure.
1088 * BUGS: This code is seriously over-engineered. There is also
1089 * magic about how the driver specific features are setup. If
1090 * a driver is attached we assume the driver settings are auto
1094 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)
1096 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
1098 down(&ide_setting_sem);
1099 while ((*p) && strcmp((*p)->name, name) < 0)
1101 if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
1103 memset(setting, 0, sizeof(*setting));
1104 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
1106 strcpy(setting->name, name);
1108 setting->read_ioctl = read_ioctl;
1109 setting->write_ioctl = write_ioctl;
1110 setting->data_type = data_type;
1113 setting->mul_factor = mul_factor;
1114 setting->div_factor = div_factor;
1115 setting->data = data;
1119 if (drive->driver != &idedefault_driver)
1120 setting->auto_remove = 1;
1122 up(&ide_setting_sem);
1125 up(&ide_setting_sem);
1131 EXPORT_SYMBOL(ide_add_setting);
1134 * __ide_remove_setting - remove an ide setting option
1135 * @drive: drive to use
1136 * @name: setting name
1138 * Removes the setting named from the device if it is present.
1139 * The caller must hold the setting semaphore.
1142 static void __ide_remove_setting (ide_drive_t *drive, char *name)
1144 ide_settings_t **p, *setting;
1146 p = (ide_settings_t **) &drive->settings;
1148 while ((*p) && strcmp((*p)->name, name))
1150 if ((setting = (*p)) == NULL)
1153 (*p) = setting->next;
1155 kfree(setting->name);
1160 * ide_find_setting_by_ioctl - find a drive specific ioctl
1161 * @drive: drive to scan
1162 * @cmd: ioctl command to handle
1164 * Scan's the device setting table for a matching entry and returns
1165 * this or NULL if no entry is found. The caller must hold the
1169 static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
1171 ide_settings_t *setting = drive->settings;
1174 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
1176 setting = setting->next;
1183 * ide_find_setting_by_name - find a drive specific setting
1184 * @drive: drive to scan
1185 * @name: setting name
1187 * Scan's the device setting table for a matching entry and returns
1188 * this or NULL if no entry is found. The caller must hold the
1192 ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
1194 ide_settings_t *setting = drive->settings;
1197 if (strcmp(setting->name, name) == 0)
1199 setting = setting->next;
1205 * auto_remove_settings - remove driver specific settings
1208 * Automatically remove all the driver specific settings for this
1209 * drive. This function may sleep and must not be called from IRQ
1210 * context. The caller must hold ide_setting_sem.
1213 static void auto_remove_settings (ide_drive_t *drive)
1215 ide_settings_t *setting;
1217 setting = drive->settings;
1219 if (setting->auto_remove) {
1220 __ide_remove_setting(drive, setting->name);
1223 setting = setting->next;
1228 * ide_read_setting - read an IDE setting
1229 * @drive: drive to read from
1230 * @setting: drive setting
1232 * Read a drive setting and return the value. The caller
1233 * must hold the ide_setting_sem when making this call.
1235 * BUGS: the data return and error are the same return value
1236 * so an error -EINVAL and true return of the same value cannot
1240 int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1243 unsigned long flags;
1245 if ((setting->rw & SETTING_READ)) {
1246 spin_lock_irqsave(&ide_lock, flags);
1247 switch(setting->data_type) {
1249 val = *((u8 *) setting->data);
1252 val = *((u16 *) setting->data);
1256 val = *((u32 *) setting->data);
1259 spin_unlock_irqrestore(&ide_lock, flags);
1265 * ide_spin_wait_hwgroup - wait for group
1266 * @drive: drive in the group
1268 * Wait for an IDE device group to go non busy and then return
1269 * holding the ide_lock which guards the hwgroup->busy status
1270 * and right to use it.
1273 int ide_spin_wait_hwgroup (ide_drive_t *drive)
1275 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1276 unsigned long timeout = jiffies + (3 * HZ);
1278 spin_lock_irq(&ide_lock);
1280 while (hwgroup->busy) {
1281 unsigned long lflags;
1282 spin_unlock_irq(&ide_lock);
1283 local_irq_set(lflags);
1284 if (time_after(jiffies, timeout)) {
1285 local_irq_restore(lflags);
1286 printk(KERN_ERR "%s: channel busy\n", drive->name);
1289 local_irq_restore(lflags);
1290 spin_lock_irq(&ide_lock);
1295 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1298 * ide_write_setting - read an IDE setting
1299 * @drive: drive to read from
1300 * @setting: drive setting
1303 * Write a drive setting if it is possible. The caller
1304 * must hold the ide_setting_sem when making this call.
1306 * BUGS: the data return and error are the same return value
1307 * so an error -EINVAL and true return of the same value cannot
1310 * FIXME: This should be changed to enqueue a special request
1311 * to the driver to change settings, and then wait on a sema for completion.
1312 * The current scheme of polling is kludgy, though safe enough.
1315 int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1320 if (!capable(CAP_SYS_ADMIN))
1322 if (!(setting->rw & SETTING_WRITE))
1324 if (val < setting->min || val > setting->max)
1327 return setting->set(drive, val);
1328 if (ide_spin_wait_hwgroup(drive))
1330 switch (setting->data_type) {
1332 *((u8 *) setting->data) = val;
1335 *((u16 *) setting->data) = val;
1338 *((u32 *) setting->data) = val;
1341 p = (u32 *) setting->data;
1342 for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1346 spin_unlock_irq(&ide_lock);
1350 static int set_io_32bit(ide_drive_t *drive, int arg)
1352 drive->io_32bit = arg;
1353 #ifdef CONFIG_BLK_DEV_DTC2278
1354 if (HWIF(drive)->chipset == ide_dtc2278)
1355 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1356 #endif /* CONFIG_BLK_DEV_DTC2278 */
1360 static int set_using_dma (ide_drive_t *drive, int arg)
1362 #ifdef CONFIG_BLK_DEV_IDEDMA
1363 if (!drive->id || !(drive->id->capability & 1))
1365 if (HWIF(drive)->ide_dma_check == NULL)
1368 if (HWIF(drive)->ide_dma_check(drive)) return -EIO;
1369 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1371 if (__ide_dma_off(drive))
1380 static int set_pio_mode (ide_drive_t *drive, int arg)
1384 if (!HWIF(drive)->tuneproc)
1386 if (drive->special.b.set_tune)
1388 ide_init_drive_cmd(&rq);
1389 drive->tune_req = (u8) arg;
1390 drive->special.b.set_tune = 1;
1391 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1395 static int set_xfer_rate (ide_drive_t *drive, int arg)
1397 int err = ide_wait_cmd(drive,
1398 WIN_SETFEATURES, (u8) arg,
1399 SETFEATURES_XFER, 0, NULL);
1402 ide_set_xfer_rate(drive, (u8) arg);
1403 ide_driveid_update(drive);
1409 * ide_add_generic_settings - generic ide settings
1410 * @drive: drive being configured
1412 * Add the generic parts of the system settings to the /proc files and
1413 * ioctls for this IDE device. The caller must not be holding the
1417 void ide_add_generic_settings (ide_drive_t *drive)
1420 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1422 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);
1423 ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL);
1424 ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL);
1425 ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode);
1426 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);
1427 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);
1428 ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL);
1429 ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate);
1430 ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL);
1434 * system_bus_clock - clock guess
1436 * External version of the bus clock guess used by very old IDE drivers
1437 * for things like VLB timings. Should not be used.
1440 int system_bus_clock (void)
1442 return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1445 EXPORT_SYMBOL(system_bus_clock);
1448 * Locking is badly broken here - since way back. That sucker is
1449 * root-only, but that's not an excuse... The real question is what
1450 * exclusion rules do we want here.
1452 int ide_replace_subdriver (ide_drive_t *drive, const char *driver)
1454 if (!drive->present || drive->usage || drive->dead)
1456 if (DRIVER(drive)->cleanup(drive))
1458 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
1459 if (ata_attach(drive)) {
1460 spin_lock(&drives_lock);
1461 list_del_init(&drive->list);
1462 spin_unlock(&drives_lock);
1463 drive->driver_req[0] = 0;
1466 drive->driver_req[0] = 0;
1468 if (DRIVER(drive)!= &idedefault_driver && !strcmp(DRIVER(drive)->name, driver))
1475 * ata_attach - attach an ATA/ATAPI device
1476 * @drive: drive to attach
1478 * Takes a drive that is as yet not assigned to any midlayer IDE
1479 * driver (or is assigned to the default driver) and figures out
1480 * which driver would like to own it. If nobody claims the drive
1481 * then it is automatically attached to the default driver used for
1482 * unclaimed objects.
1484 * A return of zero indicates attachment to a driver, of one
1485 * attachment to the default driver.
1487 * Takes drivers_lock.
1490 int ata_attach(ide_drive_t *drive)
1492 struct list_head *p;
1493 spin_lock(&drivers_lock);
1494 list_for_each(p, &drivers) {
1495 ide_driver_t *driver = list_entry(p, ide_driver_t, drivers);
1496 if (!try_module_get(driver->owner))
1498 spin_unlock(&drivers_lock);
1499 if (driver->attach(drive) == 0) {
1500 module_put(driver->owner);
1501 drive->gendev.driver = &driver->gen_driver;
1504 spin_lock(&drivers_lock);
1505 module_put(driver->owner);
1507 drive->gendev.driver = &idedefault_driver.gen_driver;
1508 spin_unlock(&drivers_lock);
1509 if(idedefault_driver.attach(drive) != 0)
1510 panic("ide: default attach failed");
1514 static int generic_ide_suspend(struct device *dev, u32 state)
1516 ide_drive_t *drive = dev->driver_data;
1518 struct request_pm_state rqpm;
1521 memset(&rq, 0, sizeof(rq));
1522 memset(&rqpm, 0, sizeof(rqpm));
1523 memset(&args, 0, sizeof(args));
1524 rq.flags = REQ_PM_SUSPEND;
1527 rqpm.pm_step = ide_pm_state_start_suspend;
1528 rqpm.pm_state = state;
1530 return ide_do_drive_cmd(drive, &rq, ide_wait);
1533 static int generic_ide_resume(struct device *dev)
1535 ide_drive_t *drive = dev->driver_data;
1537 struct request_pm_state rqpm;
1540 memset(&rq, 0, sizeof(rq));
1541 memset(&rqpm, 0, sizeof(rqpm));
1542 memset(&args, 0, sizeof(args));
1543 rq.flags = REQ_PM_RESUME;
1546 rqpm.pm_step = ide_pm_state_start_resume;
1549 return ide_do_drive_cmd(drive, &rq, ide_head_wait);
1552 int generic_ide_ioctl(struct file *file, struct block_device *bdev,
1553 unsigned int cmd, unsigned long arg)
1555 ide_drive_t *drive = bdev->bd_disk->private_data;
1556 ide_settings_t *setting;
1558 void __user *p = (void __user *)arg;
1560 down(&ide_setting_sem);
1561 if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1562 if (cmd == setting->read_ioctl) {
1563 err = ide_read_setting(drive, setting);
1564 up(&ide_setting_sem);
1565 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1567 if (bdev != bdev->bd_contains)
1570 err = ide_write_setting(drive, setting, arg);
1571 up(&ide_setting_sem);
1575 up(&ide_setting_sem);
1580 struct hd_geometry geom;
1581 if (!p || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1582 geom.heads = drive->bios_head;
1583 geom.sectors = drive->bios_sect;
1584 geom.cylinders = (u16)drive->bios_cyl; /* truncate */
1585 geom.start = get_start_sect(bdev);
1586 if (copy_to_user(p, &geom, sizeof(struct hd_geometry)))
1591 case HDIO_OBSOLETE_IDENTITY:
1592 case HDIO_GET_IDENTITY:
1593 if (bdev != bdev->bd_contains)
1595 if (drive->id_read == 0)
1597 if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1602 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
1603 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
1604 drive->nice0 << IDE_NICE_0 |
1605 drive->nice1 << IDE_NICE_1 |
1606 drive->nice2 << IDE_NICE_2,
1607 (long __user *) arg);
1609 #ifdef CONFIG_IDE_TASK_IOCTL
1610 case HDIO_DRIVE_TASKFILE:
1611 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1613 switch(drive->media) {
1615 return ide_taskfile_ioctl(drive, cmd, arg);
1619 #endif /* CONFIG_IDE_TASK_IOCTL */
1621 case HDIO_DRIVE_CMD:
1622 if (!capable(CAP_SYS_RAWIO))
1624 return ide_cmd_ioctl(drive, cmd, arg);
1626 case HDIO_DRIVE_TASK:
1627 if (!capable(CAP_SYS_RAWIO))
1629 return ide_task_ioctl(drive, cmd, arg);
1631 case HDIO_SCAN_HWIF:
1635 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1636 if (copy_from_user(args, p, 3 * sizeof(int)))
1638 memset(&hw, 0, sizeof(hw));
1639 ide_init_hwif_ports(&hw, (unsigned long) args[0],
1640 (unsigned long) args[1], NULL);
1642 if (ide_register_hw(&hw, NULL) == -1)
1646 case HDIO_UNREGISTER_HWIF:
1647 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1648 /* (arg > MAX_HWIFS) checked in function */
1649 ide_unregister(arg);
1652 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1653 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1655 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1656 if (drive->dsc_overlap && !DRIVER(drive)->supports_dsc_overlap) {
1657 drive->dsc_overlap = 0;
1660 drive->nice1 = (arg >> IDE_NICE_1) & 1;
1662 case HDIO_DRIVE_RESET:
1664 unsigned long flags;
1665 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1668 * Abort the current command on the
1669 * group if there is one, taking
1670 * care not to allow anything else
1671 * to be queued and to die on the
1672 * spot if we miss one somehow
1675 spin_lock_irqsave(&ide_lock, flags);
1677 DRIVER(drive)->abort(drive, "drive reset");
1678 if(HWGROUP(drive)->handler)
1681 /* Ensure nothing gets queued after we
1682 drop the lock. Reset will clear the busy */
1684 HWGROUP(drive)->busy = 1;
1685 spin_unlock_irqrestore(&ide_lock, flags);
1686 (void) ide_do_reset(drive);
1687 if (drive->suspend_reset) {
1689 * APM WAKE UP todo !!
1690 * int nogoodpower = 1;
1691 * while(nogoodpower) {
1692 * check_power1() or check_power2()
1695 * HWIF(drive)->multiproc(drive);
1697 return ioctl_by_bdev(bdev, BLKRRPART, 0);
1703 case CDROMCLOSETRAY:
1704 return scsi_cmd_ioctl(file, bdev->bd_disk, cmd, p);
1706 case HDIO_GET_BUSSTATE:
1707 if (!capable(CAP_SYS_ADMIN))
1709 if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
1713 case HDIO_SET_BUSSTATE:
1714 if (!capable(CAP_SYS_ADMIN))
1716 if (HWIF(drive)->busproc)
1717 return HWIF(drive)->busproc(drive, (int)arg);
1724 EXPORT_SYMBOL(generic_ide_ioctl);
1727 * stridx() returns the offset of c within s,
1728 * or -1 if c is '\0' or not found within s.
1730 static int __init stridx (const char *s, char c)
1732 char *i = strchr(s, c);
1733 return (i && c) ? i - s : -1;
1737 * match_parm() does parsing for ide_setup():
1739 * 1. the first char of s must be '='.
1740 * 2. if the remainder matches one of the supplied keywords,
1741 * the index (1 based) of the keyword is negated and returned.
1742 * 3. if the remainder is a series of no more than max_vals numbers
1743 * separated by commas, the numbers are saved in vals[] and a
1744 * count of how many were saved is returned. Base10 is assumed,
1745 * and base16 is allowed when prefixed with "0x".
1746 * 4. otherwise, zero is returned.
1748 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
1750 static const char *decimal = "0123456789";
1751 static const char *hex = "0123456789abcdef";
1756 * Try matching against the supplied keywords,
1757 * and return -(index+1) if we match one
1759 if (keywords != NULL) {
1760 for (i = 0; *keywords != NULL; ++i) {
1761 if (!strcmp(s, *keywords++))
1766 * Look for a series of no more than "max_vals"
1767 * numeric values separated by commas, in base10,
1768 * or base16 when prefixed with "0x".
1769 * Return a count of how many were found.
1771 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
1773 while ((i = stridx(decimal, *++s)) >= 0)
1774 vals[n] = (vals[n] * 10) + i;
1775 if (*s == 'x' && !vals[n]) {
1776 while ((i = stridx(hex, *++s)) >= 0)
1777 vals[n] = (vals[n] * 0x10) + i;
1779 if (++n == max_vals)
1781 if (*s == ',' || *s == ';')
1787 return 0; /* zero = nothing matched */
1790 #ifdef CONFIG_BLK_DEV_ALI14XX
1791 static int __initdata probe_ali14xx;
1792 extern int ali14xx_init(void);
1794 #ifdef CONFIG_BLK_DEV_UMC8672
1795 static int __initdata probe_umc8672;
1796 extern int umc8672_init(void);
1798 #ifdef CONFIG_BLK_DEV_DTC2278
1799 static int __initdata probe_dtc2278;
1800 extern int dtc2278_init(void);
1802 #ifdef CONFIG_BLK_DEV_HT6560B
1803 static int __initdata probe_ht6560b;
1804 extern int ht6560b_init(void);
1806 #ifdef CONFIG_BLK_DEV_QD65XX
1807 static int __initdata probe_qd65xx;
1808 extern int qd65xx_init(void);
1811 static int __initdata is_chipset_set[MAX_HWIFS];
1814 * ide_setup() gets called VERY EARLY during initialization,
1815 * to handle kernel "command line" strings beginning with "hdx=" or "ide".
1817 * Remember to update Documentation/ide.txt if you change something here.
1819 int __init ide_setup (char *s)
1824 unsigned int hw, unit;
1825 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
1826 const char max_hwif = '0' + (MAX_HWIFS - 1);
1829 if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
1830 return 0; /* driver and not us */
1832 if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1835 printk(KERN_INFO "ide_setup: %s", s);
1838 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
1839 if (!strcmp(s, "ide=doubler")) {
1840 extern int ide_doubler;
1842 printk(" : Enabled support for IDE doublers\n");
1846 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1848 if (!strcmp(s, "ide=nodma")) {
1849 printk(" : Prevented DMA\n");
1854 #ifdef CONFIG_BLK_DEV_IDEPCI
1855 if (!strcmp(s, "ide=reverse")) {
1856 ide_scan_direction = 1;
1857 printk(" : Enabled support for IDE inverse scan order.\n");
1860 #endif /* CONFIG_BLK_DEV_IDEPCI */
1863 * Look for drive options: "hdx="
1865 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1866 const char *hd_words[] = {
1867 "none", "noprobe", "nowerr", "cdrom", "serialize",
1868 "autotune", "noautotune", "minus8", "swapdata", "bswap",
1869 "minus11", "remap", "remap63", "scsi", NULL };
1871 hw = unit / MAX_DRIVES;
1872 unit = unit % MAX_DRIVES;
1873 hwif = &ide_hwifs[hw];
1874 drive = &hwif->drives[unit];
1875 if (strncmp(s + 4, "ide-", 4) == 0) {
1876 strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1879 switch (match_parm(&s[3], hd_words, vals, 3)) {
1880 case -1: /* "none" */
1881 case -2: /* "noprobe" */
1884 case -3: /* "nowerr" */
1885 drive->bad_wstat = BAD_R_STAT;
1888 case -4: /* "cdrom" */
1890 drive->media = ide_cdrom;
1893 case -5: /* "serialize" */
1894 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1896 case -6: /* "autotune" */
1897 drive->autotune = IDE_TUNE_AUTO;
1898 goto obsolete_option;
1899 case -7: /* "noautotune" */
1900 drive->autotune = IDE_TUNE_NOAUTO;
1901 goto obsolete_option;
1902 case -9: /* "swapdata" */
1903 case -10: /* "bswap" */
1906 case -12: /* "remap" */
1907 drive->remap_0_to_1 = 1;
1909 case -13: /* "remap63" */
1912 case -14: /* "scsi" */
1915 case 3: /* cyl,head,sect */
1916 drive->media = ide_disk;
1917 drive->cyl = drive->bios_cyl = vals[0];
1918 drive->head = drive->bios_head = vals[1];
1919 drive->sect = drive->bios_sect = vals[2];
1921 drive->forced_geom = 1;
1929 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1932 * Look for bus speed option: "idebus="
1934 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1935 if (match_parm(&s[6], NULL, vals, 1) != 1)
1937 if (vals[0] >= 20 && vals[0] <= 66) {
1938 idebus_parameter = vals[0];
1940 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1944 * Look for interface options: "idex="
1946 if (s[3] >= '0' && s[3] <= max_hwif) {
1948 * Be VERY CAREFUL changing this: note hardcoded indexes below
1949 * (-8, -9, -10) are reserved to ease the hardcoding.
1951 static const char *ide_words[] = {
1952 "noprobe", "serialize", "autotune", "noautotune",
1953 "reset", "dma", "ata66", "minus8", "minus9",
1954 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1955 "dtc2278", "umc8672", "ali14xx", NULL };
1957 hwif = &ide_hwifs[hw];
1958 i = match_parm(&s[4], ide_words, vals, 3);
1961 * Cryptic check to ensure chipset not already set for hwif.
1962 * Note: we can't depend on hwif->chipset here.
1964 if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
1965 /* chipset already specified */
1966 if (is_chipset_set[hw])
1968 if (i > -18 && i <= -11) {
1969 /* these drivers are for "ide0=" only */
1972 /* chipset already specified for 2nd port */
1973 if (is_chipset_set[hw+1])
1976 is_chipset_set[hw] = 1;
1981 #ifdef CONFIG_BLK_DEV_ALI14XX
1982 case -17: /* "ali14xx" */
1986 #ifdef CONFIG_BLK_DEV_UMC8672
1987 case -16: /* "umc8672" */
1991 #ifdef CONFIG_BLK_DEV_DTC2278
1992 case -15: /* "dtc2278" */
1996 #ifdef CONFIG_BLK_DEV_CMD640
1997 case -14: /* "cmd640_vlb" */
1999 extern int cmd640_vlb; /* flag for cmd640.c */
2004 #ifdef CONFIG_BLK_DEV_HT6560B
2005 case -13: /* "ht6560b" */
2009 #ifdef CONFIG_BLK_DEV_QD65XX
2010 case -12: /* "qd65xx" */
2014 #ifdef CONFIG_BLK_DEV_4DRIVES
2015 case -11: /* "four" drives on one set of ports */
2017 ide_hwif_t *mate = &ide_hwifs[hw^1];
2018 mate->drives[0].select.all ^= 0x20;
2019 mate->drives[1].select.all ^= 0x20;
2020 hwif->chipset = mate->chipset = ide_4drives;
2021 mate->irq = hwif->irq;
2022 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
2025 #endif /* CONFIG_BLK_DEV_4DRIVES */
2026 case -10: /* minus10 */
2027 case -9: /* minus9 */
2028 case -8: /* minus8 */
2030 case -7: /* ata66 */
2031 #ifdef CONFIG_BLK_DEV_IDEPCI
2032 hwif->udma_four = 1;
2033 goto obsolete_option;
2039 goto obsolete_option;
2040 case -5: /* "reset" */
2042 goto obsolete_option;
2043 case -4: /* "noautotune" */
2044 hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
2045 hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
2046 goto obsolete_option;
2047 case -3: /* "autotune" */
2048 hwif->drives[0].autotune = IDE_TUNE_AUTO;
2049 hwif->drives[1].autotune = IDE_TUNE_AUTO;
2050 goto obsolete_option;
2051 case -2: /* "serialize" */
2053 hwif->mate = &ide_hwifs[hw^1];
2054 hwif->mate->mate = hwif;
2055 hwif->serialized = hwif->mate->serialized = 1;
2056 goto obsolete_option;
2058 case -1: /* "noprobe" */
2063 vals[1] = vals[0] + 0x206; /* default ctl */
2064 case 2: /* base,ctl */
2065 vals[2] = 0; /* default irq = probe for it */
2066 case 3: /* base,ctl,irq */
2067 hwif->hw.irq = vals[2];
2068 ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
2069 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
2070 hwif->irq = vals[2];
2072 hwif->chipset = ide_forced;
2073 goto obsolete_option;
2075 case 0: goto bad_option;
2077 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2082 printk(" -- BAD OPTION\n");
2085 printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
2088 printk("-- NOT SUPPORTED ON ide%d", hw);
2094 extern void pnpide_init(void);
2095 extern void h8300_ide_init(void);
2098 * probe_for_hwifs() finds/initializes "known" IDE interfaces
2100 static void __init probe_for_hwifs (void)
2102 #ifdef CONFIG_BLK_DEV_IDEPCI
2103 ide_scan_pcibus(ide_scan_direction);
2104 #endif /* CONFIG_BLK_DEV_IDEPCI */
2106 #ifdef CONFIG_ETRAX_IDE
2108 extern void init_e100_ide(void);
2111 #endif /* CONFIG_ETRAX_IDE */
2112 #ifdef CONFIG_BLK_DEV_CMD640
2114 extern void ide_probe_for_cmd640x(void);
2115 ide_probe_for_cmd640x();
2117 #endif /* CONFIG_BLK_DEV_CMD640 */
2118 #ifdef CONFIG_BLK_DEV_IDE_PMAC
2120 extern void pmac_ide_probe(void);
2123 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
2124 #ifdef CONFIG_BLK_DEV_GAYLE
2126 extern void gayle_init(void);
2129 #endif /* CONFIG_BLK_DEV_GAYLE */
2130 #ifdef CONFIG_BLK_DEV_FALCON_IDE
2132 extern void falconide_init(void);
2135 #endif /* CONFIG_BLK_DEV_FALCON_IDE */
2136 #ifdef CONFIG_BLK_DEV_MAC_IDE
2138 extern void macide_init(void);
2141 #endif /* CONFIG_BLK_DEV_MAC_IDE */
2142 #ifdef CONFIG_BLK_DEV_Q40IDE
2144 extern void q40ide_init(void);
2147 #endif /* CONFIG_BLK_DEV_Q40IDE */
2148 #ifdef CONFIG_BLK_DEV_BUDDHA
2150 extern void buddha_init(void);
2153 #endif /* CONFIG_BLK_DEV_BUDDHA */
2154 #ifdef CONFIG_BLK_DEV_IDEPNP
2163 * Actually unregister the subdriver. Called with the
2164 * request lock dropped.
2167 static int default_cleanup (ide_drive_t *drive)
2169 return ide_unregister_subdriver(drive);
2172 static ide_startstop_t default_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
2174 ide_end_request(drive, 0, 0);
2178 static int default_end_request (ide_drive_t *drive, int uptodate, int nr_sects)
2180 return ide_end_request(drive, uptodate, nr_sects);
2183 static u8 default_sense (ide_drive_t *drive, const char *msg, u8 stat)
2185 return ide_dump_status(drive, msg, stat);
2188 static ide_startstop_t default_error (ide_drive_t *drive, const char *msg, u8 stat)
2190 return ide_error(drive, msg, stat);
2193 static void default_pre_reset (ide_drive_t *drive)
2197 static sector_t default_capacity (ide_drive_t *drive)
2202 static ide_startstop_t default_special (ide_drive_t *drive)
2204 special_t *s = &drive->special;
2207 drive->mult_req = 0;
2211 static int default_attach (ide_drive_t *drive)
2213 printk(KERN_ERR "%s: does not support hotswap of device class !\n",
2219 static ide_startstop_t default_abort (ide_drive_t *drive, const char *msg)
2221 return ide_abort(drive, msg);
2224 static ide_startstop_t default_start_power_step(ide_drive_t *drive,
2227 rq->pm->pm_step = ide_pm_state_completed;
2231 static void setup_driver_defaults (ide_driver_t *d)
2233 if (d->cleanup == NULL) d->cleanup = default_cleanup;
2234 if (d->do_request == NULL) d->do_request = default_do_request;
2235 if (d->end_request == NULL) d->end_request = default_end_request;
2236 if (d->sense == NULL) d->sense = default_sense;
2237 if (d->error == NULL) d->error = default_error;
2238 if (d->abort == NULL) d->abort = default_abort;
2239 if (d->pre_reset == NULL) d->pre_reset = default_pre_reset;
2240 if (d->capacity == NULL) d->capacity = default_capacity;
2241 if (d->special == NULL) d->special = default_special;
2242 if (d->attach == NULL) d->attach = default_attach;
2243 if (d->start_power_step == NULL)
2244 d->start_power_step = default_start_power_step;
2247 int ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
2249 unsigned long flags;
2251 BUG_ON(!drive->driver);
2253 spin_lock_irqsave(&ide_lock, flags);
2254 if (!drive->present || drive->driver != &idedefault_driver ||
2255 drive->usage || drive->dead) {
2256 spin_unlock_irqrestore(&ide_lock, flags);
2259 drive->driver = driver;
2260 spin_unlock_irqrestore(&ide_lock, flags);
2261 spin_lock(&drives_lock);
2262 list_add_tail(&drive->list, &driver->drives);
2263 spin_unlock(&drives_lock);
2264 // printk(KERN_INFO "%s: attached %s driver.\n", drive->name, driver->name);
2265 if ((drive->autotune == IDE_TUNE_DEFAULT) ||
2266 (drive->autotune == IDE_TUNE_AUTO)) {
2267 /* DMA timings and setup moved to ide-probe.c */
2268 drive->dsc_overlap = (drive->next != drive && driver->supports_dsc_overlap);
2271 drive->suspend_reset = 0;
2272 #ifdef CONFIG_PROC_FS
2273 if (drive->driver != &idedefault_driver) {
2274 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
2275 ide_add_proc_entries(drive->proc, driver->proc, drive);
2281 EXPORT_SYMBOL(ide_register_subdriver);
2284 * ide_unregister_subdriver - disconnect drive from driver
2285 * @drive: drive to unplug
2287 * Disconnect a drive from the driver it was attached to and then
2288 * clean up the various proc files and other objects attached to it.
2290 * Takes ide_setting_sem, ide_lock and drives_lock.
2291 * Caller must hold none of the locks.
2293 * No locking versus subdriver unload because we are moving to the
2294 * default driver anyway. Wants double checking.
2297 int ide_unregister_subdriver (ide_drive_t *drive)
2299 unsigned long flags;
2301 down(&ide_setting_sem);
2302 spin_lock_irqsave(&ide_lock, flags);
2303 if (drive->usage || drive->driver == &idedefault_driver || DRIVER(drive)->busy) {
2304 spin_unlock_irqrestore(&ide_lock, flags);
2305 up(&ide_setting_sem);
2308 #ifdef CONFIG_PROC_FS
2309 ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc);
2310 ide_remove_proc_entries(drive->proc, generic_subdriver_entries);
2312 auto_remove_settings(drive);
2313 drive->driver = &idedefault_driver;
2314 spin_unlock_irqrestore(&ide_lock, flags);
2315 up(&ide_setting_sem);
2316 spin_lock(&drives_lock);
2317 list_del_init(&drive->list);
2318 spin_unlock(&drives_lock);
2319 /* drive will be added to &idedefault_driver->drives in ata_attach() */
2323 EXPORT_SYMBOL(ide_unregister_subdriver);
2325 static int ide_drive_remove(struct device * dev)
2327 ide_drive_t * drive = container_of(dev,ide_drive_t,gendev);
2328 DRIVER(drive)->cleanup(drive);
2333 * ide_register_driver - register IDE device driver
2334 * @driver: the IDE device driver
2336 * Register a new device driver and then scan the devices
2337 * on the IDE bus in case any should be attached to the
2338 * driver we have just registered. If so attach them.
2340 * Takes drivers_lock and drives_lock.
2343 int ide_register_driver(ide_driver_t *driver)
2345 struct list_head list;
2346 struct list_head *list_loop;
2347 struct list_head *tmp_storage;
2349 setup_driver_defaults(driver);
2351 spin_lock(&drivers_lock);
2352 list_add(&driver->drivers, &drivers);
2353 spin_unlock(&drivers_lock);
2355 INIT_LIST_HEAD(&list);
2356 spin_lock(&drives_lock);
2357 list_splice_init(&idedefault_driver.drives, &list);
2358 spin_unlock(&drives_lock);
2360 list_for_each_safe(list_loop, tmp_storage, &list) {
2361 ide_drive_t *drive = container_of(list_loop, ide_drive_t, list);
2362 list_del_init(&drive->list);
2366 driver->gen_driver.name = (char *) driver->name;
2367 driver->gen_driver.bus = &ide_bus_type;
2368 driver->gen_driver.remove = ide_drive_remove;
2369 return driver_register(&driver->gen_driver);
2372 EXPORT_SYMBOL(ide_register_driver);
2375 * ide_unregister_driver - unregister IDE device driver
2376 * @driver: the IDE device driver
2378 * Called when a driver module is being unloaded. We reattach any
2379 * devices to whatever driver claims them next (typically the default
2382 * Takes drivers_lock and called functions will take ide_setting_sem.
2385 void ide_unregister_driver(ide_driver_t *driver)
2389 spin_lock(&drivers_lock);
2390 list_del(&driver->drivers);
2391 spin_unlock(&drivers_lock);
2393 driver_unregister(&driver->gen_driver);
2395 while(!list_empty(&driver->drives)) {
2396 drive = list_entry(driver->drives.next, ide_drive_t, list);
2397 if (driver->cleanup(drive)) {
2398 printk(KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
2405 EXPORT_SYMBOL(ide_unregister_driver);
2407 struct block_device_operations ide_fops[] = {{
2408 .owner = THIS_MODULE,
2412 EXPORT_SYMBOL(ide_fops);
2418 EXPORT_SYMBOL(ide_lock);
2420 struct bus_type ide_bus_type = {
2422 .suspend = generic_ide_suspend,
2423 .resume = generic_ide_resume,
2427 * This is gets invoked once during initialization, to set *everything* up
2429 int __init ide_init (void)
2431 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
2432 devfs_mk_dir("ide");
2433 system_bus_speed = ide_system_bus_speed();
2435 bus_register(&ide_bus_type);
2439 #ifdef CONFIG_PROC_FS
2440 proc_ide_root = proc_mkdir("ide", NULL);
2443 #ifdef CONFIG_BLK_DEV_ALI14XX
2445 (void)ali14xx_init();
2447 #ifdef CONFIG_BLK_DEV_UMC8672
2449 (void)umc8672_init();
2451 #ifdef CONFIG_BLK_DEV_DTC2278
2453 (void)dtc2278_init();
2455 #ifdef CONFIG_BLK_DEV_HT6560B
2457 (void)ht6560b_init();
2459 #ifdef CONFIG_BLK_DEV_QD65XX
2461 (void)qd65xx_init();
2465 /* Probe for special PCI and other "known" interface chipsets. */
2469 #ifdef CONFIG_PROC_FS
2476 char *options = NULL;
2477 module_param(options, charp, 0);
2478 MODULE_LICENSE("GPL");
2480 static void __init parse_options (char *line)
2484 if (line == NULL || !*line)
2486 while ((line = next) != NULL) {
2487 if ((next = strchr(line,' ')) != NULL)
2489 if (!ide_setup(line))
2490 printk (KERN_INFO "Unknown option '%s'\n", line);
2494 int init_module (void)
2496 parse_options(options);
2500 void cleanup_module (void)
2504 for (index = 0; index < MAX_HWIFS; ++index) {
2505 ide_unregister(index);
2506 if (ide_hwifs[index].dma_base)
2507 (void) ide_release_dma(&ide_hwifs[index]);
2510 #ifdef CONFIG_PROC_FS
2513 devfs_remove("ide");
2515 bus_unregister(&ide_bus_type);
2520 __setup("", ide_setup);
2522 module_init(ide_init);