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>
157 #include <asm/byteorder.h>
159 #include <asm/uaccess.h>
161 #include <asm/bitops.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);
191 EXPORT_SYMBOL(ide_bus_type);
194 * This is declared extern in ide.h, for access by other IDE modules:
196 ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
198 EXPORT_SYMBOL(ide_hwifs);
200 extern ide_driver_t idedefault_driver;
201 static void setup_driver_defaults(ide_driver_t *driver);
204 * Do not even *think* about calling this!
206 static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
210 /* bulk initialize hwif & drive info with zeros */
211 memset(hwif, 0, sizeof(ide_hwif_t));
213 /* fill in any non-zero initial values */
215 hwif->major = ide_hwif_to_major[index];
220 hwif->name[3] = '0' + index;
222 hwif->bus_state = BUSSTATE_ON;
224 hwif->atapi_dma = 0; /* disable all atapi dma */
225 hwif->ultra_mask = 0x80; /* disable all ultra */
226 hwif->mwdma_mask = 0x80; /* disable all mwdma */
227 hwif->swdma_mask = 0x80; /* disable all swdma */
229 sema_init(&hwif->gendev_rel_sem, 0);
231 default_hwif_iops(hwif);
232 default_hwif_transport(hwif);
233 for (unit = 0; unit < MAX_DRIVES; ++unit) {
234 ide_drive_t *drive = &hwif->drives[unit];
236 drive->media = ide_disk;
237 drive->select.all = (unit<<4)|0xa0;
240 drive->ready_stat = READY_STAT;
241 drive->bad_wstat = BAD_W_STAT;
242 drive->special.b.recalibrate = 1;
243 drive->special.b.set_geometry = 1;
244 drive->name[0] = 'h';
245 drive->name[1] = 'd';
246 drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
247 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
248 drive->using_dma = 0;
250 drive->driver = &idedefault_driver;
252 INIT_LIST_HEAD(&drive->list);
253 sema_init(&drive->gendev_rel_sem, 0);
257 static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
261 memset(&hw, 0, sizeof(hw_regs_t));
263 ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
265 memcpy(&hwif->hw, &hw, sizeof(hw));
266 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
268 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
269 #ifdef CONFIG_BLK_DEV_HD
270 if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
271 hwif->noprobe = 1; /* may be overridden by ide_setup() */
275 extern void ide_arm_init(void);
278 * init_ide_data() sets reasonable default values into all fields
279 * of all instances of the hwifs and drives, but only on the first call.
280 * Subsequent calls have no effect (they don't wipe out anything).
282 * This routine is normally called at driver initialization time,
283 * but may also be called MUCH earlier during kernel "command-line"
284 * parameter processing. As such, we cannot depend on any other parts
285 * of the kernel (such as memory allocation) to be functioning yet.
287 * This is too bad, as otherwise we could dynamically allocate the
288 * ide_drive_t structs as needed, rather than always consuming memory
289 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
291 * FIXME: We should stuff the setup data into __init and copy the
292 * relevant hwifs/allocate them properly during boot.
294 #define MAGIC_COOKIE 0x12345678
295 static void __init init_ide_data (void)
299 static unsigned long magic_cookie = MAGIC_COOKIE;
301 if (magic_cookie != MAGIC_COOKIE)
302 return; /* already initialized */
305 setup_driver_defaults(&idedefault_driver);
307 /* Initialise all interface structures */
308 for (index = 0; index < MAX_HWIFS; ++index) {
309 hwif = &ide_hwifs[index];
310 init_hwif_data(hwif, index);
311 init_hwif_default(hwif, index);
312 #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
313 hwif->irq = hwif->hw.irq =
314 ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
317 #ifdef CONFIG_IDE_ARM
325 * ide_system_bus_speed() returns what we think is the system VESA/PCI
326 * bus speed (in MHz). This is used for calculating interface PIO timings.
327 * The default is 40 for known PCI systems, 50 otherwise.
328 * The "idebus=xx" parameter can be used to override this value.
329 * The actual value to be used is computed/displayed the first time through.
331 int ide_system_bus_speed (void)
333 if (!system_bus_speed) {
334 if (idebus_parameter) {
335 /* user supplied value */
336 system_bus_speed = idebus_parameter;
337 } else if (pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL) != NULL) {
338 /* safe default value for PCI */
339 system_bus_speed = 33;
341 /* safe default value for VESA and PCI */
342 system_bus_speed = 50;
344 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
345 "for PIO modes%s\n", system_bus_speed,
346 idebus_parameter ? "" : "; override with idebus=xx");
348 return system_bus_speed;
352 * current_capacity() returns the capacity (in sectors) of a drive
353 * according to its current geometry/LBA settings.
355 sector_t current_capacity (ide_drive_t *drive)
359 return DRIVER(drive)->capacity(drive);
362 EXPORT_SYMBOL(current_capacity);
365 * Error reporting, in human readable form (luxurious, but a memory hog).
367 u8 ide_dump_status (ide_drive_t *drive, const char *msg, u8 stat)
369 ide_hwif_t *hwif = HWIF(drive);
373 local_irq_set(flags);
374 printk(KERN_WARNING "%s: %s: status=0x%02x", drive->name, msg, stat);
375 #if FANCY_STATUS_DUMPS
377 if (stat & BUSY_STAT) {
380 if (stat & READY_STAT) printk("DriveReady ");
381 if (stat & WRERR_STAT) printk("DeviceFault ");
382 if (stat & SEEK_STAT) printk("SeekComplete ");
383 if (stat & DRQ_STAT) printk("DataRequest ");
384 if (stat & ECC_STAT) printk("CorrectedError ");
385 if (stat & INDEX_STAT) printk("Index ");
386 if (stat & ERR_STAT) printk("Error ");
389 #endif /* FANCY_STATUS_DUMPS */
391 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
392 err = hwif->INB(IDE_ERROR_REG);
393 printk("%s: %s: error=0x%02x", drive->name, msg, err);
394 #if FANCY_STATUS_DUMPS
395 if (drive->media == ide_disk) {
397 if (err & ABRT_ERR) printk("DriveStatusError ");
398 if (err & ICRC_ERR) printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector");
399 if (err & ECC_ERR) printk("UncorrectableError ");
400 if (err & ID_ERR) printk("SectorIdNotFound ");
401 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
402 if (err & MARK_ERR) printk("AddrMarkNotFound ");
404 if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
405 if ((drive->id->command_set_2 & 0x0400) &&
406 (drive->id->cfs_enable_2 & 0x0400) &&
407 (drive->addressing == 1)) {
410 u32 low = ide_read_24(drive);
411 hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
412 high = ide_read_24(drive);
414 sectors = ((u64)high << 24) | low;
415 printk(", LBAsect=%llu, high=%d, low=%d",
419 u8 cur = hwif->INB(IDE_SELECT_REG);
420 if (cur & 0x40) { /* using LBA? */
421 printk(", LBAsect=%ld", (unsigned long)
423 |(hwif->INB(IDE_HCYL_REG)<<16)
424 |(hwif->INB(IDE_LCYL_REG)<<8)
425 | hwif->INB(IDE_SECTOR_REG));
427 printk(", CHS=%d/%d/%d",
428 (hwif->INB(IDE_HCYL_REG)<<8) +
429 hwif->INB(IDE_LCYL_REG),
431 hwif->INB(IDE_SECTOR_REG));
434 if (HWGROUP(drive) && HWGROUP(drive)->rq)
435 printk(", sector=%llu", (unsigned long long)HWGROUP(drive)->rq->sector);
438 #endif /* FANCY_STATUS_DUMPS */
441 local_irq_restore(flags);
445 EXPORT_SYMBOL(ide_dump_status);
447 static int ide_open (struct inode * inode, struct file * filp)
452 static spinlock_t drives_lock = SPIN_LOCK_UNLOCKED;
453 static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
454 static LIST_HEAD(drivers);
457 static void *m_start(struct seq_file *m, loff_t *pos)
461 spin_lock(&drivers_lock);
462 list_for_each(p, &drivers)
464 return list_entry(p, ide_driver_t, drivers);
467 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
469 struct list_head *p = ((ide_driver_t *)v)->drivers.next;
471 return p==&drivers ? NULL : list_entry(p, ide_driver_t, drivers);
473 static void m_stop(struct seq_file *m, void *v)
475 spin_unlock(&drivers_lock);
477 static int show_driver(struct seq_file *m, void *v)
479 ide_driver_t *driver = v;
480 seq_printf(m, "%s version %s\n", driver->name, driver->version);
483 struct seq_operations ide_drivers_op = {
490 #ifdef CONFIG_PROC_FS
491 struct proc_dir_entry *proc_ide_root;
493 ide_proc_entry_t generic_subdriver_entries[] = {
494 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
495 { NULL, 0, NULL, NULL }
499 static struct resource* hwif_request_region(ide_hwif_t *hwif,
500 unsigned long addr, int num)
502 struct resource *res = request_region(addr, num, hwif->name);
505 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
506 hwif->name, addr, addr+num-1);
511 * ide_hwif_request_regions - request resources for IDE
512 * @hwif: interface to use
514 * Requests all the needed resources for an interface.
515 * Right now core IDE code does this work which is deeply wrong.
516 * MMIO leaves it to the controller driver,
517 * PIO will migrate this way over time.
519 int ide_hwif_request_regions(ide_hwif_t *hwif)
526 BUG_ON(hwif->mmio == 1);
527 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
528 if (addr && !hwif_request_region(hwif, addr, 1))
529 goto control_region_busy;
531 addr = hwif->io_ports[IDE_DATA_OFFSET];
532 if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
533 if (!hwif_request_region(hwif, addr, 8))
534 goto data_region_busy;
538 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
539 addr = hwif->io_ports[i];
540 if (!hwif_request_region(hwif, addr, 1)) {
542 release_region(addr, 1);
543 goto data_region_busy;
549 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
551 release_region(addr, 1);
553 /* If any errors are return, we drop the hwif interface. */
557 EXPORT_SYMBOL(ide_hwif_request_regions);
560 * ide_hwif_release_regions - free IDE resources
562 * Note that we only release the standard ports,
563 * and do not even try to handle any extra ports
564 * allocated for weird IDE interface chipsets.
566 * Note also that we don't yet handle mmio resources here. More
567 * importantly our caller should be doing this so we need to
568 * restructure this as a helper function for drivers.
570 void ide_hwif_release_regions(ide_hwif_t *hwif)
576 if (hwif->io_ports[IDE_CONTROL_OFFSET])
577 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
578 if (hwif->straight8) {
579 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
582 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
583 if (hwif->io_ports[i])
584 release_region(hwif->io_ports[i], 1);
587 EXPORT_SYMBOL(ide_hwif_release_regions);
589 /* restore hwif to a sane state */
590 static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
592 hwif->hwgroup = tmp_hwif->hwgroup;
594 hwif->gendev.parent = tmp_hwif->gendev.parent;
596 hwif->proc = tmp_hwif->proc;
598 hwif->major = tmp_hwif->major;
599 hwif->straight8 = tmp_hwif->straight8;
600 hwif->bus_state = tmp_hwif->bus_state;
602 hwif->atapi_dma = tmp_hwif->atapi_dma;
603 hwif->ultra_mask = tmp_hwif->ultra_mask;
604 hwif->mwdma_mask = tmp_hwif->mwdma_mask;
605 hwif->swdma_mask = tmp_hwif->swdma_mask;
607 hwif->chipset = tmp_hwif->chipset;
608 hwif->hold = tmp_hwif->hold;
610 #ifdef CONFIG_BLK_DEV_IDEPCI
611 hwif->pci_dev = tmp_hwif->pci_dev;
612 hwif->cds = tmp_hwif->cds;
615 hwif->identify = tmp_hwif->identify;
616 hwif->tuneproc = tmp_hwif->tuneproc;
617 hwif->speedproc = tmp_hwif->speedproc;
618 hwif->selectproc = tmp_hwif->selectproc;
619 hwif->reset_poll = tmp_hwif->reset_poll;
620 hwif->pre_reset = tmp_hwif->pre_reset;
621 hwif->resetproc = tmp_hwif->resetproc;
622 hwif->intrproc = tmp_hwif->intrproc;
623 hwif->maskproc = tmp_hwif->maskproc;
624 hwif->quirkproc = tmp_hwif->quirkproc;
625 hwif->busproc = tmp_hwif->busproc;
627 hwif->ata_input_data = tmp_hwif->ata_input_data;
628 hwif->ata_output_data = tmp_hwif->ata_output_data;
629 hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
630 hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
632 hwif->ide_dma_read = tmp_hwif->ide_dma_read;
633 hwif->ide_dma_write = tmp_hwif->ide_dma_write;
634 hwif->ide_dma_begin = tmp_hwif->ide_dma_begin;
635 hwif->ide_dma_end = tmp_hwif->ide_dma_end;
636 hwif->ide_dma_check = tmp_hwif->ide_dma_check;
637 hwif->ide_dma_on = tmp_hwif->ide_dma_on;
638 hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly;
639 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
640 hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on;
641 hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off;
642 hwif->ide_dma_verbose = tmp_hwif->ide_dma_verbose;
643 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
644 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
646 hwif->OUTB = tmp_hwif->OUTB;
647 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
648 hwif->OUTW = tmp_hwif->OUTW;
649 hwif->OUTL = tmp_hwif->OUTL;
650 hwif->OUTSW = tmp_hwif->OUTSW;
651 hwif->OUTSL = tmp_hwif->OUTSL;
653 hwif->INB = tmp_hwif->INB;
654 hwif->INW = tmp_hwif->INW;
655 hwif->INL = tmp_hwif->INL;
656 hwif->INSW = tmp_hwif->INSW;
657 hwif->INSL = tmp_hwif->INSL;
659 hwif->mmio = tmp_hwif->mmio;
660 hwif->rqsize = tmp_hwif->rqsize;
661 hwif->no_lba48 = tmp_hwif->no_lba48;
663 #ifndef CONFIG_BLK_DEV_IDECS
664 hwif->irq = tmp_hwif->irq;
667 hwif->dma_base = tmp_hwif->dma_base;
668 hwif->dma_master = tmp_hwif->dma_master;
669 hwif->dma_command = tmp_hwif->dma_command;
670 hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
671 hwif->dma_status = tmp_hwif->dma_status;
672 hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
673 hwif->dma_prdtable = tmp_hwif->dma_prdtable;
675 hwif->dma_extra = tmp_hwif->dma_extra;
676 hwif->config_data = tmp_hwif->config_data;
677 hwif->select_data = tmp_hwif->select_data;
678 hwif->autodma = tmp_hwif->autodma;
679 hwif->udma_four = tmp_hwif->udma_four;
680 hwif->no_dsc = tmp_hwif->no_dsc;
682 hwif->hwif_data = tmp_hwif->hwif_data;
686 * ide_unregister - free an ide interface
687 * @index: index of interface (will change soon to a pointer)
689 * Perform the final unregister of an IDE interface. At the moment
690 * we don't refcount interfaces so this will also get split up.
693 * The caller must not hold the IDE locks
694 * The drive present/vanishing is not yet properly locked
695 * Take care with the callbacks. These have been split to avoid
696 * deadlocking the IDE layer. The shutdown callback is called
697 * before we take the lock and free resources. It is up to the
698 * caller to be sure there is no pending I/O here, and that
699 * the interfce will not be reopened (present/vanishing locking
700 * isnt yet done btw). After we commit to the final kill we
701 * call the cleanup callback with the ide locks held.
703 * Unregister restores the hwif structures to the default state.
704 * This is raving bonkers.
707 void ide_unregister(unsigned int index)
710 ide_hwif_t *hwif, *g, *tmp_hwif;
711 ide_hwgroup_t *hwgroup;
712 int irq_count = 0, unit, i;
714 BUG_ON(index >= MAX_HWIFS);
716 tmp_hwif = kmalloc(sizeof(*tmp_hwif), GFP_KERNEL|__GFP_NOFAIL);
718 printk(KERN_ERR "%s: unable to allocate memory\n", __FUNCTION__);
722 BUG_ON(in_interrupt());
723 BUG_ON(irqs_disabled());
725 spin_lock_irq(&ide_lock);
726 hwif = &ide_hwifs[index];
729 for (unit = 0; unit < MAX_DRIVES; ++unit) {
730 drive = &hwif->drives[unit];
733 if (drive->usage || DRIVER(drive)->busy)
739 spin_unlock_irq(&ide_lock);
741 for (unit = 0; unit < MAX_DRIVES; ++unit) {
742 drive = &hwif->drives[unit];
745 DRIVER(drive)->cleanup(drive);
748 #ifdef CONFIG_PROC_FS
749 destroy_proc_ide_drives(hwif);
752 hwgroup = hwif->hwgroup;
754 * free the irq if we were the only hwif using it
758 if (g->irq == hwif->irq)
761 } while (g != hwgroup->hwif);
763 free_irq(hwif->irq, hwgroup);
765 spin_lock_irq(&ide_lock);
767 * Note that we only release the standard ports,
768 * and do not even try to handle any extra ports
769 * allocated for weird IDE interface chipsets.
771 ide_hwif_release_regions(hwif);
774 * Remove us from the hwgroup, and free
775 * the hwgroup if we were the only member
777 for (i = 0; i < MAX_DRIVES; ++i) {
778 drive = &hwif->drives[i];
779 if (drive->devfs_name[0] != '\0') {
780 devfs_remove(drive->devfs_name);
781 drive->devfs_name[0] = '\0';
785 if (drive == drive->next) {
786 /* special case: last drive from hwgroup. */
787 BUG_ON(hwgroup->drive != drive);
788 hwgroup->drive = NULL;
792 walk = hwgroup->drive;
793 while (walk->next != drive)
795 walk->next = drive->next;
796 if (hwgroup->drive == drive) {
797 hwgroup->drive = drive->next;
798 hwgroup->hwif = HWIF(hwgroup->drive);
801 BUG_ON(hwgroup->drive == drive);
802 if (drive->id != NULL) {
807 /* Messed up locking ... */
808 spin_unlock_irq(&ide_lock);
809 blk_cleanup_queue(drive->queue);
810 device_unregister(&drive->gendev);
811 down(&drive->gendev_rel_sem);
812 spin_lock_irq(&ide_lock);
815 if (hwif->next == hwif) {
816 BUG_ON(hwgroup->hwif != hwif);
819 /* There is another interface in hwgroup.
820 * Unlink us, and set hwgroup->drive and ->hwif to
824 while (g->next != hwif)
826 g->next = hwif->next;
827 if (hwgroup->hwif == hwif) {
828 /* Chose a random hwif for hwgroup->hwif.
829 * It's guaranteed that there are no drives
830 * left in the hwgroup.
832 BUG_ON(hwgroup->drive != NULL);
835 BUG_ON(hwgroup->hwif == hwif);
838 /* More messed up locking ... */
839 spin_unlock_irq(&ide_lock);
840 device_unregister(&hwif->gendev);
841 down(&hwif->gendev_rel_sem);
844 * Remove us from the kernel's knowledge
846 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
847 for (i = 0; i < MAX_DRIVES; i++) {
848 struct gendisk *disk = hwif->drives[i].disk;
849 hwif->drives[i].disk = NULL;
852 unregister_blkdev(hwif->major, hwif->name);
853 spin_lock_irq(&ide_lock);
855 if (hwif->dma_base) {
856 (void) ide_release_dma(hwif);
859 hwif->dma_master = 0;
860 hwif->dma_command = 0;
861 hwif->dma_vendor1 = 0;
862 hwif->dma_status = 0;
863 hwif->dma_vendor3 = 0;
864 hwif->dma_prdtable = 0;
867 /* copy original settings */
870 /* restore hwif data to pristine status */
871 init_hwif_data(hwif, index);
872 init_hwif_default(hwif, index);
874 ide_hwif_restore(hwif, tmp_hwif);
877 spin_unlock_irq(&ide_lock);
883 EXPORT_SYMBOL(ide_unregister);
887 * ide_setup_ports - set up IDE interface ports
888 * @hw: register descriptions
889 * @base: base register
890 * @offsets: table of register offsets
891 * @ctrl: control register
893 * @irq: interrupt lie
895 * Setup hw_regs_t structure described by parameters. You
896 * may set up the hw structure yourself OR use this routine to
897 * do it for you. This is basically a helper
901 void ide_setup_ports ( hw_regs_t *hw,
902 unsigned long base, int *offsets,
903 unsigned long ctrl, unsigned long intr,
904 ide_ack_intr_t *ack_intr,
906 * ide_io_ops_t *iops,
912 for (i = 0; i < IDE_NR_PORTS; i++) {
913 if (offsets[i] == -1) {
915 case IDE_CONTROL_OFFSET:
916 hw->io_ports[i] = ctrl;
918 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
920 hw->io_ports[i] = intr;
922 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
928 hw->io_ports[i] = base + offsets[i];
933 hw->ack_intr = ack_intr;
939 EXPORT_SYMBOL(ide_setup_ports);
942 * Register an IDE interface, specifying exactly the registers etc
943 * Set init=1 iff calling before probes have taken place.
945 int ide_register_hw (hw_regs_t *hw, ide_hwif_t **hwifp)
947 int index, retry = 1;
951 for (index = 0; index < MAX_HWIFS; ++index) {
952 hwif = &ide_hwifs[index];
953 if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
956 for (index = 0; index < MAX_HWIFS; ++index) {
957 hwif = &ide_hwifs[index];
960 if ((!hwif->present && !hwif->mate && !initializing) ||
961 (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
964 for (index = 0; index < MAX_HWIFS; index++)
965 ide_unregister(index);
970 ide_unregister(index);
971 else if (!hwif->hold) {
972 init_hwif_data(hwif, index);
973 init_hwif_default(hwif, index);
977 memcpy(&hwif->hw, hw, sizeof(*hw));
978 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
981 hwif->chipset = hw->chipset;
984 probe_hwif_init(hwif);
985 create_proc_ide_interfaces();
991 return (initializing || hwif->present) ? index : -1;
994 EXPORT_SYMBOL(ide_register_hw);
997 * Locks for IDE setting functionality
1000 DECLARE_MUTEX(ide_setting_sem);
1001 EXPORT_SYMBOL(ide_setting_sem);
1004 * ide_add_setting - add an ide setting option
1005 * @drive: drive to use
1006 * @name: setting name
1007 * @rw: true if the function is read write
1008 * @read_ioctl: function to call on read
1009 * @write_ioctl: function to call on write
1010 * @data_type: type of data
1011 * @min: range minimum
1012 * @max: range maximum
1013 * @mul_factor: multiplication scale
1014 * @div_factor: divison scale
1015 * @data: private data field
1018 * Removes the setting named from the device if it is present.
1019 * The function takes the settings_lock to protect against
1020 * parallel changes. This function must not be called from IRQ
1021 * context. Returns 0 on success or -1 on failure.
1023 * BUGS: This code is seriously over-engineered. There is also
1024 * magic about how the driver specific features are setup. If
1025 * a driver is attached we assume the driver settings are auto
1029 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)
1031 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
1033 down(&ide_setting_sem);
1034 while ((*p) && strcmp((*p)->name, name) < 0)
1036 if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
1038 memset(setting, 0, sizeof(*setting));
1039 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
1041 strcpy(setting->name, name);
1043 setting->read_ioctl = read_ioctl;
1044 setting->write_ioctl = write_ioctl;
1045 setting->data_type = data_type;
1048 setting->mul_factor = mul_factor;
1049 setting->div_factor = div_factor;
1050 setting->data = data;
1054 if (drive->driver != &idedefault_driver)
1055 setting->auto_remove = 1;
1057 up(&ide_setting_sem);
1060 up(&ide_setting_sem);
1066 EXPORT_SYMBOL(ide_add_setting);
1069 * __ide_remove_setting - remove an ide setting option
1070 * @drive: drive to use
1071 * @name: setting name
1073 * Removes the setting named from the device if it is present.
1074 * The caller must hold the setting semaphore.
1077 static void __ide_remove_setting (ide_drive_t *drive, char *name)
1079 ide_settings_t **p, *setting;
1081 p = (ide_settings_t **) &drive->settings;
1083 while ((*p) && strcmp((*p)->name, name))
1085 if ((setting = (*p)) == NULL)
1088 (*p) = setting->next;
1090 kfree(setting->name);
1095 * ide_remove_setting - remove an ide setting option
1096 * @drive: drive to use
1097 * @name: setting name
1099 * Removes the setting named from the device if it is present.
1100 * The function takes the settings_lock to protect against
1101 * parallel changes. This function must not be called from IRQ
1105 void ide_remove_setting (ide_drive_t *drive, char *name)
1107 down(&ide_setting_sem);
1108 __ide_remove_setting(drive, name);
1109 up(&ide_setting_sem);
1112 EXPORT_SYMBOL(ide_remove_setting);
1115 * ide_find_setting_by_ioctl - find a drive specific ioctl
1116 * @drive: drive to scan
1117 * @cmd: ioctl command to handle
1119 * Scan's the device setting table for a matching entry and returns
1120 * this or NULL if no entry is found. The caller must hold the
1124 static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
1126 ide_settings_t *setting = drive->settings;
1129 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
1131 setting = setting->next;
1138 * ide_find_setting_by_name - find a drive specific setting
1139 * @drive: drive to scan
1140 * @name: setting name
1142 * Scan's the device setting table for a matching entry and returns
1143 * this or NULL if no entry is found. The caller must hold the
1147 ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
1149 ide_settings_t *setting = drive->settings;
1152 if (strcmp(setting->name, name) == 0)
1154 setting = setting->next;
1160 * auto_remove_settings - remove driver specific settings
1163 * Automatically remove all the driver specific settings for this
1164 * drive. This function may sleep and must not be called from IRQ
1165 * context. The caller must hold ide_setting_sem.
1168 static void auto_remove_settings (ide_drive_t *drive)
1170 ide_settings_t *setting;
1172 setting = drive->settings;
1174 if (setting->auto_remove) {
1175 __ide_remove_setting(drive, setting->name);
1178 setting = setting->next;
1183 * ide_read_setting - read an IDE setting
1184 * @drive: drive to read from
1185 * @setting: drive setting
1187 * Read a drive setting and return the value. The caller
1188 * must hold the ide_setting_sem when making this call.
1190 * BUGS: the data return and error are the same return value
1191 * so an error -EINVAL and true return of the same value cannot
1195 int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1198 unsigned long flags;
1200 if ((setting->rw & SETTING_READ)) {
1201 spin_lock_irqsave(&ide_lock, flags);
1202 switch(setting->data_type) {
1204 val = *((u8 *) setting->data);
1207 val = *((u16 *) setting->data);
1211 val = *((u32 *) setting->data);
1214 spin_unlock_irqrestore(&ide_lock, flags);
1219 int ide_spin_wait_hwgroup (ide_drive_t *drive)
1221 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1222 unsigned long timeout = jiffies + (3 * HZ);
1224 spin_lock_irq(&ide_lock);
1226 while (hwgroup->busy) {
1227 unsigned long lflags;
1228 spin_unlock_irq(&ide_lock);
1229 local_irq_set(lflags);
1230 if (time_after(jiffies, timeout)) {
1231 local_irq_restore(lflags);
1232 printk(KERN_ERR "%s: channel busy\n", drive->name);
1235 local_irq_restore(lflags);
1236 spin_lock_irq(&ide_lock);
1241 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1244 * ide_write_setting - read an IDE setting
1245 * @drive: drive to read from
1246 * @setting: drive setting
1249 * Write a drive setting if it is possible. The caller
1250 * must hold the ide_setting_sem when making this call.
1252 * BUGS: the data return and error are the same return value
1253 * so an error -EINVAL and true return of the same value cannot
1256 * FIXME: This should be changed to enqueue a special request
1257 * to the driver to change settings, and then wait on a sema for completion.
1258 * The current scheme of polling is kludgy, though safe enough.
1260 int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1265 if (!capable(CAP_SYS_ADMIN))
1267 if (!(setting->rw & SETTING_WRITE))
1269 if (val < setting->min || val > setting->max)
1272 return setting->set(drive, val);
1273 if (ide_spin_wait_hwgroup(drive))
1275 switch (setting->data_type) {
1277 *((u8 *) setting->data) = val;
1280 *((u16 *) setting->data) = val;
1283 *((u32 *) setting->data) = val;
1286 p = (u32 *) setting->data;
1287 for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1291 spin_unlock_irq(&ide_lock);
1295 EXPORT_SYMBOL(ide_write_setting);
1297 static int set_io_32bit(ide_drive_t *drive, int arg)
1299 drive->io_32bit = arg;
1300 #ifdef CONFIG_BLK_DEV_DTC2278
1301 if (HWIF(drive)->chipset == ide_dtc2278)
1302 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1303 #endif /* CONFIG_BLK_DEV_DTC2278 */
1307 static int set_using_dma (ide_drive_t *drive, int arg)
1309 #ifdef CONFIG_BLK_DEV_IDEDMA
1310 if (!drive->id || !(drive->id->capability & 1))
1312 if (HWIF(drive)->ide_dma_check == NULL)
1315 if (HWIF(drive)->ide_dma_check(drive)) return -EIO;
1316 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1318 if (__ide_dma_off(drive))
1327 static int set_pio_mode (ide_drive_t *drive, int arg)
1331 if (!HWIF(drive)->tuneproc)
1333 if (drive->special.b.set_tune)
1335 ide_init_drive_cmd(&rq);
1336 drive->tune_req = (u8) arg;
1337 drive->special.b.set_tune = 1;
1338 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1342 static int set_xfer_rate (ide_drive_t *drive, int arg)
1344 int err = ide_wait_cmd(drive,
1345 WIN_SETFEATURES, (u8) arg,
1346 SETFEATURES_XFER, 0, NULL);
1349 ide_set_xfer_rate(drive, (u8) arg);
1350 ide_driveid_update(drive);
1355 int ide_atapi_to_scsi (ide_drive_t *drive, int arg)
1357 if (drive->media == ide_disk) {
1362 if (DRIVER(drive)->cleanup(drive)) {
1367 drive->scsi = (u8) arg;
1372 void ide_add_generic_settings (ide_drive_t *drive)
1375 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1377 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);
1378 ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL);
1379 ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL);
1380 ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode);
1381 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);
1382 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);
1383 ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL);
1384 ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate);
1385 ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL);
1386 if (drive->media != ide_disk)
1387 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);
1390 int system_bus_clock (void)
1392 return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1395 EXPORT_SYMBOL(system_bus_clock);
1398 * Locking is badly broken here - since way back. That sucker is
1399 * root-only, but that's not an excuse... The real question is what
1400 * exclusion rules do we want here.
1402 int ide_replace_subdriver (ide_drive_t *drive, const char *driver)
1404 if (!drive->present || drive->usage || drive->dead)
1406 if (DRIVER(drive)->cleanup(drive))
1408 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
1409 if (ata_attach(drive)) {
1410 spin_lock(&drives_lock);
1411 list_del_init(&drive->list);
1412 spin_unlock(&drives_lock);
1413 drive->driver_req[0] = 0;
1416 drive->driver_req[0] = 0;
1418 if (DRIVER(drive)!= &idedefault_driver && !strcmp(DRIVER(drive)->name, driver))
1424 EXPORT_SYMBOL(ide_replace_subdriver);
1426 int ata_attach(ide_drive_t *drive)
1428 struct list_head *p;
1429 spin_lock(&drivers_lock);
1430 list_for_each(p, &drivers) {
1431 ide_driver_t *driver = list_entry(p, ide_driver_t, drivers);
1432 if (!try_module_get(driver->owner))
1434 spin_unlock(&drivers_lock);
1435 if (driver->attach(drive) == 0) {
1436 module_put(driver->owner);
1437 drive->gendev.driver = &driver->gen_driver;
1440 spin_lock(&drivers_lock);
1441 module_put(driver->owner);
1443 drive->gendev.driver = &idedefault_driver.gen_driver;
1444 spin_unlock(&drivers_lock);
1445 if(idedefault_driver.attach(drive) != 0)
1446 panic("ide: default attach failed");
1450 EXPORT_SYMBOL(ata_attach);
1452 static int generic_ide_suspend(struct device *dev, u32 state)
1454 ide_drive_t *drive = dev->driver_data;
1456 struct request_pm_state rqpm;
1459 memset(&rq, 0, sizeof(rq));
1460 memset(&rqpm, 0, sizeof(rqpm));
1461 memset(&args, 0, sizeof(args));
1462 rq.flags = REQ_PM_SUSPEND;
1465 rqpm.pm_step = ide_pm_state_start_suspend;
1466 rqpm.pm_state = state;
1468 return ide_do_drive_cmd(drive, &rq, ide_wait);
1471 static int generic_ide_resume(struct device *dev)
1473 ide_drive_t *drive = dev->driver_data;
1475 struct request_pm_state rqpm;
1478 memset(&rq, 0, sizeof(rq));
1479 memset(&rqpm, 0, sizeof(rqpm));
1480 memset(&args, 0, sizeof(args));
1481 rq.flags = REQ_PM_RESUME;
1484 rqpm.pm_step = ide_pm_state_start_resume;
1487 return ide_do_drive_cmd(drive, &rq, ide_head_wait);
1490 int generic_ide_ioctl(struct block_device *bdev, unsigned int cmd,
1493 ide_drive_t *drive = bdev->bd_disk->private_data;
1494 ide_settings_t *setting;
1496 void __user *p = (void __user *)arg;
1498 down(&ide_setting_sem);
1499 if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1500 if (cmd == setting->read_ioctl) {
1501 err = ide_read_setting(drive, setting);
1502 up(&ide_setting_sem);
1503 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1505 if (bdev != bdev->bd_contains)
1508 err = ide_write_setting(drive, setting, arg);
1509 up(&ide_setting_sem);
1513 up(&ide_setting_sem);
1518 struct hd_geometry geom;
1519 if (!p || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1520 geom.heads = drive->bios_head;
1521 geom.sectors = drive->bios_sect;
1522 geom.cylinders = (u16)drive->bios_cyl; /* truncate */
1523 geom.start = get_start_sect(bdev);
1524 if (copy_to_user(p, &geom, sizeof(struct hd_geometry)))
1529 case HDIO_OBSOLETE_IDENTITY:
1530 case HDIO_GET_IDENTITY:
1531 if (bdev != bdev->bd_contains)
1533 if (drive->id_read == 0)
1535 if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1540 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
1541 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
1542 drive->nice0 << IDE_NICE_0 |
1543 drive->nice1 << IDE_NICE_1 |
1544 drive->nice2 << IDE_NICE_2,
1545 (long __user *) arg);
1547 #ifdef CONFIG_IDE_TASK_IOCTL
1548 case HDIO_DRIVE_TASKFILE:
1549 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1551 switch(drive->media) {
1553 return ide_taskfile_ioctl(drive, cmd, arg);
1557 #endif /* CONFIG_IDE_TASK_IOCTL */
1559 case HDIO_DRIVE_CMD:
1560 if (!capable(CAP_SYS_RAWIO))
1562 return ide_cmd_ioctl(drive, cmd, arg);
1564 case HDIO_DRIVE_TASK:
1565 if (!capable(CAP_SYS_RAWIO))
1567 return ide_task_ioctl(drive, cmd, arg);
1569 case HDIO_SCAN_HWIF:
1573 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1574 if (copy_from_user(args, p, 3 * sizeof(int)))
1576 memset(&hw, 0, sizeof(hw));
1577 ide_init_hwif_ports(&hw, (unsigned long) args[0],
1578 (unsigned long) args[1], NULL);
1580 if (ide_register_hw(&hw, NULL) == -1)
1584 case HDIO_UNREGISTER_HWIF:
1585 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1586 /* (arg > MAX_HWIFS) checked in function */
1587 ide_unregister(arg);
1590 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1591 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1593 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1594 if (drive->dsc_overlap && !DRIVER(drive)->supports_dsc_overlap) {
1595 drive->dsc_overlap = 0;
1598 drive->nice1 = (arg >> IDE_NICE_1) & 1;
1600 case HDIO_DRIVE_RESET:
1602 unsigned long flags;
1603 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1606 * Abort the current command on the
1607 * group if there is one, taking
1608 * care not to allow anything else
1609 * to be queued and to die on the
1610 * spot if we miss one somehow
1613 spin_lock_irqsave(&ide_lock, flags);
1615 DRIVER(drive)->abort(drive, "drive reset");
1616 if(HWGROUP(drive)->handler)
1619 /* Ensure nothing gets queued after we
1620 drop the lock. Reset will clear the busy */
1622 HWGROUP(drive)->busy = 1;
1623 spin_unlock_irqrestore(&ide_lock, flags);
1624 (void) ide_do_reset(drive);
1625 if (drive->suspend_reset) {
1627 * APM WAKE UP todo !!
1628 * int nogoodpower = 1;
1629 * while(nogoodpower) {
1630 * check_power1() or check_power2()
1633 * HWIF(drive)->multiproc(drive);
1635 return ioctl_by_bdev(bdev, BLKRRPART, 0);
1641 case CDROMCLOSETRAY:
1642 return scsi_cmd_ioctl(bdev->bd_disk, cmd, p);
1644 case HDIO_GET_BUSSTATE:
1645 if (!capable(CAP_SYS_ADMIN))
1647 if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
1651 case HDIO_SET_BUSSTATE:
1652 if (!capable(CAP_SYS_ADMIN))
1654 if (HWIF(drive)->busproc)
1655 return HWIF(drive)->busproc(drive, (int)arg);
1662 EXPORT_SYMBOL(generic_ide_ioctl);
1665 * stridx() returns the offset of c within s,
1666 * or -1 if c is '\0' or not found within s.
1668 static int __init stridx (const char *s, char c)
1670 char *i = strchr(s, c);
1671 return (i && c) ? i - s : -1;
1675 * match_parm() does parsing for ide_setup():
1677 * 1. the first char of s must be '='.
1678 * 2. if the remainder matches one of the supplied keywords,
1679 * the index (1 based) of the keyword is negated and returned.
1680 * 3. if the remainder is a series of no more than max_vals numbers
1681 * separated by commas, the numbers are saved in vals[] and a
1682 * count of how many were saved is returned. Base10 is assumed,
1683 * and base16 is allowed when prefixed with "0x".
1684 * 4. otherwise, zero is returned.
1686 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
1688 static const char *decimal = "0123456789";
1689 static const char *hex = "0123456789abcdef";
1694 * Try matching against the supplied keywords,
1695 * and return -(index+1) if we match one
1697 if (keywords != NULL) {
1698 for (i = 0; *keywords != NULL; ++i) {
1699 if (!strcmp(s, *keywords++))
1704 * Look for a series of no more than "max_vals"
1705 * numeric values separated by commas, in base10,
1706 * or base16 when prefixed with "0x".
1707 * Return a count of how many were found.
1709 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
1711 while ((i = stridx(decimal, *++s)) >= 0)
1712 vals[n] = (vals[n] * 10) + i;
1713 if (*s == 'x' && !vals[n]) {
1714 while ((i = stridx(hex, *++s)) >= 0)
1715 vals[n] = (vals[n] * 0x10) + i;
1717 if (++n == max_vals)
1719 if (*s == ',' || *s == ';')
1725 return 0; /* zero = nothing matched */
1728 #ifdef CONFIG_BLK_DEV_PDC4030
1729 static int __initdata probe_pdc4030;
1731 #ifdef CONFIG_BLK_DEV_ALI14XX
1732 static int __initdata probe_ali14xx;
1733 extern int ali14xx_init(void);
1735 #ifdef CONFIG_BLK_DEV_UMC8672
1736 static int __initdata probe_umc8672;
1737 extern int umc8672_init(void);
1739 #ifdef CONFIG_BLK_DEV_DTC2278
1740 static int __initdata probe_dtc2278;
1741 extern int dtc2278_init(void);
1743 #ifdef CONFIG_BLK_DEV_HT6560B
1744 static int __initdata probe_ht6560b;
1745 extern int ht6560b_init(void);
1747 #ifdef CONFIG_BLK_DEV_QD65XX
1748 static int __initdata probe_qd65xx;
1749 extern int qd65xx_init(void);
1752 static int __initdata is_chipset_set[MAX_HWIFS];
1755 * ide_setup() gets called VERY EARLY during initialization,
1756 * to handle kernel "command line" strings beginning with "hdx=" or "ide".
1758 * Remember to update Documentation/ide.txt if you change something here.
1760 int __init ide_setup (char *s)
1765 unsigned int hw, unit;
1766 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
1767 const char max_hwif = '0' + (MAX_HWIFS - 1);
1770 if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
1771 return 0; /* driver and not us */
1773 if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1776 printk(KERN_INFO "ide_setup: %s", s);
1779 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
1780 if (!strcmp(s, "ide=doubler")) {
1781 extern int ide_doubler;
1783 printk(" : Enabled support for IDE doublers\n");
1787 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1789 if (!strcmp(s, "ide=nodma")) {
1790 printk("IDE: Prevented DMA\n");
1795 #ifdef CONFIG_BLK_DEV_IDEPCI
1796 if (!strcmp(s, "ide=reverse")) {
1797 ide_scan_direction = 1;
1798 printk(" : Enabled support for IDE inverse scan order.\n");
1801 #endif /* CONFIG_BLK_DEV_IDEPCI */
1804 * Look for drive options: "hdx="
1806 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1807 const char *hd_words[] = {
1808 "none", "noprobe", "nowerr", "cdrom", "serialize",
1809 "autotune", "noautotune", "minus8", "swapdata", "bswap",
1810 "minus11", "remap", "remap63", "scsi", NULL };
1812 hw = unit / MAX_DRIVES;
1813 unit = unit % MAX_DRIVES;
1814 hwif = &ide_hwifs[hw];
1815 drive = &hwif->drives[unit];
1816 if (strncmp(s + 4, "ide-", 4) == 0) {
1817 strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1820 switch (match_parm(&s[3], hd_words, vals, 3)) {
1821 case -1: /* "none" */
1822 case -2: /* "noprobe" */
1825 case -3: /* "nowerr" */
1826 drive->bad_wstat = BAD_R_STAT;
1829 case -4: /* "cdrom" */
1831 drive->media = ide_cdrom;
1834 case -5: /* "serialize" */
1835 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1837 case -6: /* "autotune" */
1838 drive->autotune = IDE_TUNE_AUTO;
1840 case -7: /* "noautotune" */
1841 drive->autotune = IDE_TUNE_NOAUTO;
1843 case -9: /* "swapdata" */
1844 case -10: /* "bswap" */
1847 case -12: /* "remap" */
1848 drive->remap_0_to_1 = 1;
1850 case -13: /* "remap63" */
1853 case -14: /* "scsi" */
1856 case 3: /* cyl,head,sect */
1857 drive->media = ide_disk;
1858 drive->cyl = drive->bios_cyl = vals[0];
1859 drive->head = drive->bios_head = vals[1];
1860 drive->sect = drive->bios_sect = vals[2];
1862 drive->forced_geom = 1;
1870 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1873 * Look for bus speed option: "idebus="
1875 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1876 if (match_parm(&s[6], NULL, vals, 1) != 1)
1878 if (vals[0] >= 20 && vals[0] <= 66) {
1879 idebus_parameter = vals[0];
1881 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1885 * Look for interface options: "idex="
1887 if (s[3] >= '0' && s[3] <= max_hwif) {
1889 * Be VERY CAREFUL changing this: note hardcoded indexes below
1890 * (-8, -9, -10) are reserved to ease the hardcoding.
1892 static const char *ide_words[] = {
1893 "noprobe", "serialize", "autotune", "noautotune",
1894 "reset", "dma", "ata66", "minus8", "minus9",
1895 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1896 "dtc2278", "umc8672", "ali14xx", "dc4030", NULL };
1898 hwif = &ide_hwifs[hw];
1899 i = match_parm(&s[4], ide_words, vals, 3);
1902 * Cryptic check to ensure chipset not already set for hwif.
1903 * Note: we can't depend on hwif->chipset here.
1905 if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
1906 /* chipset already specified */
1907 if (is_chipset_set[hw])
1909 if (i > -18 && i <= -11) {
1910 /* these drivers are for "ide0=" only */
1913 /* chipset already specified for 2nd port */
1914 if (is_chipset_set[hw+1])
1917 is_chipset_set[hw] = 1;
1922 #ifdef CONFIG_BLK_DEV_PDC4030
1923 case -18: /* "dc4030" */
1927 #ifdef CONFIG_BLK_DEV_ALI14XX
1928 case -17: /* "ali14xx" */
1932 #ifdef CONFIG_BLK_DEV_UMC8672
1933 case -16: /* "umc8672" */
1937 #ifdef CONFIG_BLK_DEV_DTC2278
1938 case -15: /* "dtc2278" */
1942 #ifdef CONFIG_BLK_DEV_CMD640
1943 case -14: /* "cmd640_vlb" */
1945 extern int cmd640_vlb; /* flag for cmd640.c */
1950 #ifdef CONFIG_BLK_DEV_HT6560B
1951 case -13: /* "ht6560b" */
1955 #ifdef CONFIG_BLK_DEV_QD65XX
1956 case -12: /* "qd65xx" */
1960 #ifdef CONFIG_BLK_DEV_4DRIVES
1961 case -11: /* "four" drives on one set of ports */
1963 ide_hwif_t *mate = &ide_hwifs[hw^1];
1964 mate->drives[0].select.all ^= 0x20;
1965 mate->drives[1].select.all ^= 0x20;
1966 hwif->chipset = mate->chipset = ide_4drives;
1967 mate->irq = hwif->irq;
1968 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
1971 #endif /* CONFIG_BLK_DEV_4DRIVES */
1972 case -10: /* minus10 */
1973 case -9: /* minus9 */
1974 case -8: /* minus8 */
1976 case -7: /* ata66 */
1977 #ifdef CONFIG_BLK_DEV_IDEPCI
1978 hwif->udma_four = 1;
1986 case -5: /* "reset" */
1989 case -4: /* "noautotune" */
1990 hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
1991 hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
1993 case -3: /* "autotune" */
1994 hwif->drives[0].autotune = IDE_TUNE_AUTO;
1995 hwif->drives[1].autotune = IDE_TUNE_AUTO;
1997 case -2: /* "serialize" */
1999 hwif->mate = &ide_hwifs[hw^1];
2000 hwif->mate->mate = hwif;
2001 hwif->serialized = hwif->mate->serialized = 1;
2004 case -1: /* "noprobe" */
2009 vals[1] = vals[0] + 0x206; /* default ctl */
2010 case 2: /* base,ctl */
2011 vals[2] = 0; /* default irq = probe for it */
2012 case 3: /* base,ctl,irq */
2013 hwif->hw.irq = vals[2];
2014 ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
2015 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
2016 hwif->irq = vals[2];
2018 hwif->chipset = ide_forced;
2021 case 0: goto bad_option;
2023 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2028 printk(" -- BAD OPTION\n");
2031 printk("-- NOT SUPPORTED ON ide%d", hw);
2037 extern void h8300_ide_init(void);
2040 * probe_for_hwifs() finds/initializes "known" IDE interfaces
2042 static void __init probe_for_hwifs (void)
2044 #ifdef CONFIG_BLK_DEV_IDEPCI
2045 ide_scan_pcibus(ide_scan_direction);
2046 #endif /* CONFIG_BLK_DEV_IDEPCI */
2048 #ifdef CONFIG_ETRAX_IDE
2050 extern void init_e100_ide(void);
2053 #endif /* CONFIG_ETRAX_IDE */
2054 #ifdef CONFIG_BLK_DEV_CMD640
2056 extern void ide_probe_for_cmd640x(void);
2057 ide_probe_for_cmd640x();
2059 #endif /* CONFIG_BLK_DEV_CMD640 */
2060 #ifdef CONFIG_BLK_DEV_PDC4030
2062 extern int pdc4030_init(void);
2064 (void)pdc4030_init();
2066 #endif /* CONFIG_BLK_DEV_PDC4030 */
2067 #ifdef CONFIG_BLK_DEV_IDE_PMAC
2069 extern void pmac_ide_probe(void);
2072 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
2073 #ifdef CONFIG_BLK_DEV_GAYLE
2075 extern void gayle_init(void);
2078 #endif /* CONFIG_BLK_DEV_GAYLE */
2079 #ifdef CONFIG_BLK_DEV_FALCON_IDE
2081 extern void falconide_init(void);
2084 #endif /* CONFIG_BLK_DEV_FALCON_IDE */
2085 #ifdef CONFIG_BLK_DEV_MAC_IDE
2087 extern void macide_init(void);
2090 #endif /* CONFIG_BLK_DEV_MAC_IDE */
2091 #ifdef CONFIG_BLK_DEV_Q40IDE
2093 extern void q40ide_init(void);
2096 #endif /* CONFIG_BLK_DEV_Q40IDE */
2097 #ifdef CONFIG_BLK_DEV_BUDDHA
2099 extern void buddha_init(void);
2102 #endif /* CONFIG_BLK_DEV_BUDDHA */
2103 #if defined(CONFIG_BLK_DEV_IDEPNP) && defined(CONFIG_PNP)
2105 extern void pnpide_init(int enable);
2108 #endif /* CONFIG_BLK_DEV_IDEPNP */
2115 * Actually unregister the subdriver. Called with the
2116 * request lock dropped.
2119 static int default_cleanup (ide_drive_t *drive)
2121 return ide_unregister_subdriver(drive);
2124 static ide_startstop_t default_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
2126 ide_end_request(drive, 0, 0);
2130 static int default_end_request (ide_drive_t *drive, int uptodate, int nr_sects)
2132 return ide_end_request(drive, uptodate, nr_sects);
2135 static u8 default_sense (ide_drive_t *drive, const char *msg, u8 stat)
2137 return ide_dump_status(drive, msg, stat);
2140 static ide_startstop_t default_error (ide_drive_t *drive, const char *msg, u8 stat)
2142 return ide_error(drive, msg, stat);
2145 static void default_pre_reset (ide_drive_t *drive)
2149 static sector_t default_capacity (ide_drive_t *drive)
2154 static ide_startstop_t default_special (ide_drive_t *drive)
2156 special_t *s = &drive->special;
2159 drive->mult_req = 0;
2163 static int default_attach (ide_drive_t *drive)
2165 printk(KERN_ERR "%s: does not support hotswap of device class !\n",
2171 static ide_startstop_t default_abort (ide_drive_t *drive, const char *msg)
2173 return ide_abort(drive, msg);
2176 static ide_startstop_t default_start_power_step(ide_drive_t *drive,
2179 rq->pm->pm_step = ide_pm_state_completed;
2183 static void setup_driver_defaults (ide_driver_t *d)
2185 if (d->cleanup == NULL) d->cleanup = default_cleanup;
2186 if (d->do_request == NULL) d->do_request = default_do_request;
2187 if (d->end_request == NULL) d->end_request = default_end_request;
2188 if (d->sense == NULL) d->sense = default_sense;
2189 if (d->error == NULL) d->error = default_error;
2190 if (d->abort == NULL) d->abort = default_abort;
2191 if (d->pre_reset == NULL) d->pre_reset = default_pre_reset;
2192 if (d->capacity == NULL) d->capacity = default_capacity;
2193 if (d->special == NULL) d->special = default_special;
2194 if (d->attach == NULL) d->attach = default_attach;
2195 if (d->start_power_step == NULL)
2196 d->start_power_step = default_start_power_step;
2199 int ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
2201 unsigned long flags;
2203 BUG_ON(!drive->driver);
2205 spin_lock_irqsave(&ide_lock, flags);
2206 if (!drive->present || drive->driver != &idedefault_driver ||
2207 drive->usage || drive->dead) {
2208 spin_unlock_irqrestore(&ide_lock, flags);
2211 drive->driver = driver;
2212 spin_unlock_irqrestore(&ide_lock, flags);
2213 spin_lock(&drives_lock);
2214 list_add_tail(&drive->list, &driver->drives);
2215 spin_unlock(&drives_lock);
2216 // printk(KERN_INFO "%s: attached %s driver.\n", drive->name, driver->name);
2217 if ((drive->autotune == IDE_TUNE_DEFAULT) ||
2218 (drive->autotune == IDE_TUNE_AUTO)) {
2219 /* DMA timings and setup moved to ide-probe.c */
2220 drive->dsc_overlap = (drive->next != drive && driver->supports_dsc_overlap);
2223 drive->suspend_reset = 0;
2224 #ifdef CONFIG_PROC_FS
2225 if (drive->driver != &idedefault_driver) {
2226 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
2227 ide_add_proc_entries(drive->proc, driver->proc, drive);
2233 EXPORT_SYMBOL(ide_register_subdriver);
2235 int ide_unregister_subdriver (ide_drive_t *drive)
2237 unsigned long flags;
2239 down(&ide_setting_sem);
2240 spin_lock_irqsave(&ide_lock, flags);
2241 if (drive->usage || drive->driver == &idedefault_driver || DRIVER(drive)->busy) {
2242 spin_unlock_irqrestore(&ide_lock, flags);
2243 up(&ide_setting_sem);
2246 #if defined(CONFIG_BLK_DEV_IDEPNP) && defined(CONFIG_PNP) && defined(MODULE)
2248 #endif /* CONFIG_BLK_DEV_IDEPNP */
2249 #ifdef CONFIG_PROC_FS
2250 ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc);
2251 ide_remove_proc_entries(drive->proc, generic_subdriver_entries);
2253 auto_remove_settings(drive);
2254 drive->driver = &idedefault_driver;
2255 spin_unlock_irqrestore(&ide_lock, flags);
2256 up(&ide_setting_sem);
2257 spin_lock(&drives_lock);
2258 list_del_init(&drive->list);
2259 spin_unlock(&drives_lock);
2260 /* drive will be added to &idedefault_driver->drives in ata_attach() */
2264 EXPORT_SYMBOL(ide_unregister_subdriver);
2266 static int ide_drive_remove(struct device * dev)
2268 ide_drive_t * drive = container_of(dev,ide_drive_t,gendev);
2269 DRIVER(drive)->cleanup(drive);
2273 int ide_register_driver(ide_driver_t *driver)
2275 struct list_head list;
2276 struct list_head *list_loop;
2277 struct list_head *tmp_storage;
2279 setup_driver_defaults(driver);
2281 spin_lock(&drivers_lock);
2282 list_add(&driver->drivers, &drivers);
2283 spin_unlock(&drivers_lock);
2285 INIT_LIST_HEAD(&list);
2286 spin_lock(&drives_lock);
2287 list_splice_init(&idedefault_driver.drives, &list);
2288 spin_unlock(&drives_lock);
2290 list_for_each_safe(list_loop, tmp_storage, &list) {
2291 ide_drive_t *drive = container_of(list_loop, ide_drive_t, list);
2292 list_del_init(&drive->list);
2296 driver->gen_driver.name = (char *) driver->name;
2297 driver->gen_driver.bus = &ide_bus_type;
2298 driver->gen_driver.remove = ide_drive_remove;
2299 return driver_register(&driver->gen_driver);
2302 EXPORT_SYMBOL(ide_register_driver);
2304 void ide_unregister_driver(ide_driver_t *driver)
2308 spin_lock(&drivers_lock);
2309 list_del(&driver->drivers);
2310 spin_unlock(&drivers_lock);
2312 driver_unregister(&driver->gen_driver);
2314 while(!list_empty(&driver->drives)) {
2315 drive = list_entry(driver->drives.next, ide_drive_t, list);
2316 if (driver->cleanup(drive)) {
2317 printk(KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
2324 EXPORT_SYMBOL(ide_unregister_driver);
2326 struct block_device_operations ide_fops[] = {{
2327 .owner = THIS_MODULE,
2331 EXPORT_SYMBOL(ide_fops);
2337 EXPORT_SYMBOL(ide_lock);
2339 struct bus_type ide_bus_type = {
2341 .suspend = generic_ide_suspend,
2342 .resume = generic_ide_resume,
2346 * This is gets invoked once during initialization, to set *everything* up
2348 int __init ide_init (void)
2350 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
2351 devfs_mk_dir("ide");
2352 system_bus_speed = ide_system_bus_speed();
2354 bus_register(&ide_bus_type);
2358 #ifdef CONFIG_PROC_FS
2359 proc_ide_root = proc_mkdir("ide", 0);
2362 #ifdef CONFIG_BLK_DEV_ALI14XX
2364 (void)ali14xx_init();
2366 #ifdef CONFIG_BLK_DEV_UMC8672
2368 (void)umc8672_init();
2370 #ifdef CONFIG_BLK_DEV_DTC2278
2372 (void)dtc2278_init();
2374 #ifdef CONFIG_BLK_DEV_HT6560B
2376 (void)ht6560b_init();
2378 #ifdef CONFIG_BLK_DEV_QD65XX
2380 (void)qd65xx_init();
2384 /* Probe for special PCI and other "known" interface chipsets. */
2388 #ifdef CONFIG_PROC_FS
2395 char *options = NULL;
2396 MODULE_PARM(options,"s");
2397 MODULE_LICENSE("GPL");
2399 static void __init parse_options (char *line)
2403 if (line == NULL || !*line)
2405 while ((line = next) != NULL) {
2406 if ((next = strchr(line,' ')) != NULL)
2408 if (!ide_setup(line))
2409 printk (KERN_INFO "Unknown option '%s'\n", line);
2413 int init_module (void)
2415 parse_options(options);
2419 void cleanup_module (void)
2423 for (index = 0; index < MAX_HWIFS; ++index) {
2424 ide_unregister(index);
2425 if (ide_hwifs[index].dma_base)
2426 (void) ide_release_dma(&ide_hwifs[index]);
2429 #ifdef CONFIG_PROC_FS
2432 devfs_remove("ide");
2434 bus_unregister(&ide_bus_type);
2439 __setup("", ide_setup);
2441 module_init(ide_init);