ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / ide / ide.c
1 /*
2  *  linux/drivers/ide/ide.c             Version 7.00beta2       Mar 05 2003
3  *
4  *  Copyright (C) 1994-1998  Linus Torvalds & authors (see below)
5  */
6
7 /*
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>
11  *
12  *  See linux/MAINTAINERS for address of current maintainer.
13  *
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
16  *   (usually 14 & 15).
17  * There can be up to two drives per interface, as per the ATA-2 spec.
18  *
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
23  * ...
24  *
25  *  From hd.c:
26  *  |
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!
30  *  |
31  *  | modified by Drew Eckhardt to check nr of hd's from the CMOS.
32  *  |
33  *  | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
34  *  | in the early extended-partition checks and added DM partitions.
35  *  |
36  *  | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
37  *  |
38  *  | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
39  *  | and general streamlining by Mark Lord (mlord@pobox.com).
40  *
41  *  October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
42  *
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)
46  *
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
50  *
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,
55  *  ...
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
99  *                        Geert Uytterhoeven
100  *                      Promise DC4030VL now supported.
101  *                      add support for ide6/ide7
102  *                      delay_50ms() changed to ide_delay_50ms() and exported.
103  * Version 6.20         Added/Fixed Generic ATA-66 support and hwif detection.
104  *                      Added hdx=flash to allow for second flash disk
105  *                        detection w/o the hang loop.
106  *                      Added support for ide8/ide9
107  *                      Added idex=ata66 for the quirky chipsets that are
108  *                        ATA-66 compliant, but have yet to determine a method
109  *                        of verification of the 80c cable presence.
110  *                        Specifically Promise's PDC20262 chipset.
111  * Version 6.21         Fixing/Fixed SMP spinlock issue with insight from an old
112  *                        hat that clarified original low level driver design.
113  * Version 6.30         Added SMP support; fixed multmode issues.  -ml
114  * Version 6.31         Debug Share INTR's and request queue streaming
115  *                      Native ATA-100 support
116  *                      Prep for Cascades Project
117  * Version 7.00alpha    First named revision of ide rearrange
118  *
119  *  Some additional driver compile-time options are in ./include/linux/ide.h
120  *
121  *  To do, in likely order of completion:
122  *      - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f
123  *
124  */
125
126 #define REVISION        "Revision: 7.00alpha2"
127 #define VERSION         "Id: ide.c 7.00a2 20020906"
128
129 #undef REALLY_SLOW_IO           /* most systems can safely undef this */
130
131 #define _IDE_C                  /* Tell ide.h it's really us */
132
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
157 #include <asm/byteorder.h>
158 #include <asm/irq.h>
159 #include <asm/uaccess.h>
160 #include <asm/io.h>
161 #include <asm/bitops.h>
162
163
164 /* default maximum number of failures */
165 #define IDE_DEFAULT_MAX_FAILURES        1
166
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 };
172
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 */
176
177 DECLARE_MUTEX(ide_cfg_sem);
178 spinlock_t ide_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
179
180 #ifdef CONFIG_BLK_DEV_IDEPCI
181 static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
182 #endif
183
184 #ifdef CONFIG_IDEDMA_AUTO
185 int noautodma = 0;
186 #else
187 int noautodma = 1;
188 #endif
189
190 EXPORT_SYMBOL(noautodma);
191 EXPORT_SYMBOL(ide_bus_type);
192
193 /*
194  * This is declared extern in ide.h, for access by other IDE modules:
195  */
196 ide_hwif_t ide_hwifs[MAX_HWIFS];        /* master data repository */
197
198 EXPORT_SYMBOL(ide_hwifs);
199
200 extern ide_driver_t idedefault_driver;
201 static void setup_driver_defaults(ide_driver_t *driver);
202
203 /*
204  * Do not even *think* about calling this!
205  */
206 static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
207 {
208         unsigned int unit;
209
210         /* bulk initialize hwif & drive info with zeros */
211         memset(hwif, 0, sizeof(ide_hwif_t));
212
213         /* fill in any non-zero initial values */
214         hwif->index     = index;
215         hwif->major     = ide_hwif_to_major[index];
216
217         hwif->name[0]   = 'i';
218         hwif->name[1]   = 'd';
219         hwif->name[2]   = 'e';
220         hwif->name[3]   = '0' + index;
221
222         hwif->bus_state = BUSSTATE_ON;
223
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 */
228
229         sema_init(&hwif->gendev_rel_sem, 0);
230
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];
235
236                 drive->media                    = ide_disk;
237                 drive->select.all               = (unit<<4)|0xa0;
238                 drive->hwif                     = hwif;
239                 drive->ctl                      = 0x08;
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;
249                 drive->is_flash                 = 0;
250                 drive->driver                   = &idedefault_driver;
251                 drive->vdma                     = 0;
252                 INIT_LIST_HEAD(&drive->list);
253                 sema_init(&drive->gendev_rel_sem, 0);
254         }
255 }
256
257 static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
258 {
259         hw_regs_t hw;
260
261         memset(&hw, 0, sizeof(hw_regs_t));
262
263         ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
264
265         memcpy(&hwif->hw, &hw, sizeof(hw));
266         memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
267
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() */
272 #endif
273 }
274
275 /*
276  * init_ide_data() sets reasonable default values into all fields
277  * of all instances of the hwifs and drives, but only on the first call.
278  * Subsequent calls have no effect (they don't wipe out anything).
279  *
280  * This routine is normally called at driver initialization time,
281  * but may also be called MUCH earlier during kernel "command-line"
282  * parameter processing.  As such, we cannot depend on any other parts
283  * of the kernel (such as memory allocation) to be functioning yet.
284  *
285  * This is too bad, as otherwise we could dynamically allocate the
286  * ide_drive_t structs as needed, rather than always consuming memory
287  * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
288  *
289  * FIXME: We should stuff the setup data into __init and copy the
290  * relevant hwifs/allocate them properly during boot.
291  */
292 #define MAGIC_COOKIE 0x12345678
293 static void __init init_ide_data (void)
294 {
295         ide_hwif_t *hwif;
296         unsigned int index;
297         static unsigned long magic_cookie = MAGIC_COOKIE;
298
299         if (magic_cookie != MAGIC_COOKIE)
300                 return;         /* already initialized */
301         magic_cookie = 0;
302
303         setup_driver_defaults(&idedefault_driver);
304
305         /* Initialise all interface structures */
306         for (index = 0; index < MAX_HWIFS; ++index) {
307                 hwif = &ide_hwifs[index];
308                 init_hwif_data(hwif, index);
309                 init_hwif_default(hwif, index);
310 #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
311                 hwif->irq = hwif->hw.irq =
312                         ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
313 #endif
314         }
315
316 /* OBSOLETE: still needed on arm26 and arm */
317 #ifdef CONFIG_ARM
318         /* Add default hw interfaces */
319         initializing = 1;
320         ide_init_default_hwifs();
321         initializing = 0;
322 #endif
323 }
324
325 /*
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 through.
331  */
332 int ide_system_bus_speed (void)
333 {
334         if (!system_bus_speed) {
335                 if (idebus_parameter) {
336                         /* user supplied value */
337                         system_bus_speed = idebus_parameter;
338                 } else if (pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL) != NULL) {
339                         /* safe default value for PCI */
340                         system_bus_speed = 33;
341                 } else {
342                         /* safe default value for VESA and PCI */
343                         system_bus_speed = 50;
344                 }
345                 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
346                         "for PIO modes%s\n", system_bus_speed,
347                         idebus_parameter ? "" : "; override with idebus=xx");
348         }
349         return system_bus_speed;
350 }
351
352 /*
353  * current_capacity() returns the capacity (in sectors) of a drive
354  * according to its current geometry/LBA settings.
355  */
356 sector_t current_capacity (ide_drive_t *drive)
357 {
358         if (!drive->present)
359                 return 0;
360         return DRIVER(drive)->capacity(drive);
361 }
362
363 EXPORT_SYMBOL(current_capacity);
364
365 /*
366  * Error reporting, in human readable form (luxurious, but a memory hog).
367  */
368 u8 ide_dump_status (ide_drive_t *drive, const char *msg, u8 stat)
369 {
370         ide_hwif_t *hwif = HWIF(drive);
371         unsigned long flags;
372         u8 err = 0;
373
374         local_irq_set(flags);
375         printk(KERN_WARNING "%s: %s: status=0x%02x", drive->name, msg, stat);
376 #if FANCY_STATUS_DUMPS
377         printk(" { ");
378         if (stat & BUSY_STAT) {
379                 printk("Busy ");
380         } else {
381                 if (stat & READY_STAT)  printk("DriveReady ");
382                 if (stat & WRERR_STAT)  printk("DeviceFault ");
383                 if (stat & SEEK_STAT)   printk("SeekComplete ");
384                 if (stat & DRQ_STAT)    printk("DataRequest ");
385                 if (stat & ECC_STAT)    printk("CorrectedError ");
386                 if (stat & INDEX_STAT)  printk("Index ");
387                 if (stat & ERR_STAT)    printk("Error ");
388         }
389         printk("}");
390 #endif  /* FANCY_STATUS_DUMPS */
391         printk("\n");
392         if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
393                 err = hwif->INB(IDE_ERROR_REG);
394                 printk("%s: %s: error=0x%02x", drive->name, msg, err);
395 #if FANCY_STATUS_DUMPS
396                 if (drive->media == ide_disk) {
397                         printk(" { ");
398                         if (err & ABRT_ERR)     printk("DriveStatusError ");
399                         if (err & ICRC_ERR)     printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector");
400                         if (err & ECC_ERR)      printk("UncorrectableError ");
401                         if (err & ID_ERR)       printk("SectorIdNotFound ");
402                         if (err & TRK0_ERR)     printk("TrackZeroNotFound ");
403                         if (err & MARK_ERR)     printk("AddrMarkNotFound ");
404                         printk("}");
405                         if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
406                                 if ((drive->id->command_set_2 & 0x0400) &&
407                                     (drive->id->cfs_enable_2 & 0x0400) &&
408                                     (drive->addressing == 1)) {
409                                         u64 sectors = 0;
410                                         u32 high = 0;
411                                         u32 low = ide_read_24(drive);
412                                         hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
413                                         high = ide_read_24(drive);
414
415                                         sectors = ((u64)high << 24) | low;
416                                         printk(", LBAsect=%llu, high=%d, low=%d",
417                                                (long long) sectors,
418                                                high, low);
419                                 } else {
420                                         u8 cur = hwif->INB(IDE_SELECT_REG);
421                                         if (cur & 0x40) {       /* using LBA? */
422                                                 printk(", LBAsect=%ld", (unsigned long)
423                                                  ((cur&0xf)<<24)
424                                                  |(hwif->INB(IDE_HCYL_REG)<<16)
425                                                  |(hwif->INB(IDE_LCYL_REG)<<8)
426                                                  | hwif->INB(IDE_SECTOR_REG));
427                                         } else {
428                                                 printk(", CHS=%d/%d/%d",
429                                                  (hwif->INB(IDE_HCYL_REG)<<8) +
430                                                   hwif->INB(IDE_LCYL_REG),
431                                                   cur & 0xf,
432                                                   hwif->INB(IDE_SECTOR_REG));
433                                         }
434                                 }
435                                 if (HWGROUP(drive) && HWGROUP(drive)->rq)
436                                         printk(", sector=%llu", (unsigned long long)HWGROUP(drive)->rq->sector);
437                         }
438                 }
439 #endif  /* FANCY_STATUS_DUMPS */
440                 printk("\n");
441         }
442         local_irq_restore(flags);
443         return err;
444 }
445
446 EXPORT_SYMBOL(ide_dump_status);
447
448 static int ide_open (struct inode * inode, struct file * filp)
449 {
450         return -ENXIO;
451 }
452
453 static spinlock_t drives_lock = SPIN_LOCK_UNLOCKED;
454 static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
455 static LIST_HEAD(drivers);
456
457 /* Iterator */
458 static void *m_start(struct seq_file *m, loff_t *pos)
459 {
460         struct list_head *p;
461         loff_t l = *pos;
462         spin_lock(&drivers_lock);
463         list_for_each(p, &drivers)
464                 if (!l--)
465                         return list_entry(p, ide_driver_t, drivers);
466         return NULL;
467 }
468 static void *m_next(struct seq_file *m, void *v, loff_t *pos)
469 {
470         struct list_head *p = ((ide_driver_t *)v)->drivers.next;
471         (*pos)++;
472         return p==&drivers ? NULL : list_entry(p, ide_driver_t, drivers);
473 }
474 static void m_stop(struct seq_file *m, void *v)
475 {
476         spin_unlock(&drivers_lock);
477 }
478 static int show_driver(struct seq_file *m, void *v)
479 {
480         ide_driver_t *driver = v;
481         seq_printf(m, "%s version %s\n", driver->name, driver->version);
482         return 0;
483 }
484 struct seq_operations ide_drivers_op = {
485         .start  = m_start,
486         .next   = m_next,
487         .stop   = m_stop,
488         .show   = show_driver
489 };
490
491 #ifdef CONFIG_PROC_FS
492 struct proc_dir_entry *proc_ide_root;
493
494 ide_proc_entry_t generic_subdriver_entries[] = {
495         { "capacity",   S_IFREG|S_IRUGO,        proc_ide_read_capacity, NULL },
496         { NULL, 0, NULL, NULL }
497 };
498 #endif
499
500 static struct resource* hwif_request_region(ide_hwif_t *hwif,
501                                             unsigned long addr, int num)
502 {
503         struct resource *res = request_region(addr, num, hwif->name);
504
505         if (!res)
506                 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
507                                 hwif->name, addr, addr+num-1);
508         return res;
509 }
510
511 /**
512  *      ide_hwif_request_regions - request resources for IDE
513  *      @hwif: interface to use
514  *
515  *      Requests all the needed resources for an interface.
516  *      Right now core IDE code does this work which is deeply wrong.
517  *      MMIO leaves it to the controller driver,
518  *      PIO will migrate this way over time.
519  */
520 int ide_hwif_request_regions(ide_hwif_t *hwif)
521 {
522         unsigned long addr;
523         unsigned int i;
524
525         if (hwif->mmio == 2)
526                 return 0;
527         BUG_ON(hwif->mmio == 1);
528         addr = hwif->io_ports[IDE_CONTROL_OFFSET];
529         if (addr && !hwif_request_region(hwif, addr, 1))
530                 goto control_region_busy;
531         hwif->straight8 = 0;
532         addr = hwif->io_ports[IDE_DATA_OFFSET];
533         if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
534                 if (!hwif_request_region(hwif, addr, 8))
535                         goto data_region_busy;
536                 hwif->straight8 = 1;
537                 return 0;
538         }
539         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
540                 addr = hwif->io_ports[i];
541                 if (!hwif_request_region(hwif, addr, 1)) {
542                         while (--i)
543                                 release_region(addr, 1);
544                         goto data_region_busy;
545                 }
546         }
547         return 0;
548
549 data_region_busy:
550         addr = hwif->io_ports[IDE_CONTROL_OFFSET];
551         if (addr)
552                 release_region(addr, 1);
553 control_region_busy:
554         /* If any errors are return, we drop the hwif interface. */
555         return -EBUSY;
556 }
557
558 EXPORT_SYMBOL(ide_hwif_request_regions);
559
560 /**
561  *      ide_hwif_release_regions - free IDE resources
562  *
563  *      Note that we only release the standard ports,
564  *      and do not even try to handle any extra ports
565  *      allocated for weird IDE interface chipsets.
566  *
567  *      Note also that we don't yet handle mmio resources here. More
568  *      importantly our caller should be doing this so we need to 
569  *      restructure this as a helper function for drivers.
570  */
571 void ide_hwif_release_regions(ide_hwif_t *hwif)
572 {
573         u32 i = 0;
574
575         if (hwif->mmio == 2)
576                 return;
577         if (hwif->io_ports[IDE_CONTROL_OFFSET])
578                 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
579         if (hwif->straight8) {
580                 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
581                 return;
582         }
583         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
584                 if (hwif->io_ports[i])
585                         release_region(hwif->io_ports[i], 1);
586 }
587
588 EXPORT_SYMBOL(ide_hwif_release_regions);
589
590 /**
591  *      ide_unregister          -       free an ide interface
592  *      @index: index of interface (will change soon to a pointer)
593  *
594  *      Perform the final unregister of an IDE interface. At the moment
595  *      we don't refcount interfaces so this will also get split up.
596  *
597  *      Locking:
598  *      The caller must not hold the IDE locks
599  *      The drive present/vanishing is not yet properly locked
600  *      Take care with the callbacks. These have been split to avoid
601  *      deadlocking the IDE layer. The shutdown callback is called
602  *      before we take the lock and free resources. It is up to the
603  *      caller to be sure there is no pending I/O here, and that
604  *      the interfce will not be reopened (present/vanishing locking
605  *      isnt yet done btw). After we commit to the final kill we
606  *      call the cleanup callback with the ide locks held.
607  *
608  *      Unregister restores the hwif structures to the default state.
609  *      This is raving bonkers.
610  */
611  
612 void ide_unregister (unsigned int index)
613 {
614         ide_drive_t *drive;
615         ide_hwif_t *hwif, *g;
616         ide_hwgroup_t *hwgroup;
617         int irq_count = 0, unit, i;
618         ide_hwif_t old_hwif;
619
620         if (index >= MAX_HWIFS)
621                 BUG();
622                 
623         BUG_ON(in_interrupt());
624         BUG_ON(irqs_disabled());
625         down(&ide_cfg_sem);
626         spin_lock_irq(&ide_lock);
627         hwif = &ide_hwifs[index];
628         if (!hwif->present)
629                 goto abort;
630         for (unit = 0; unit < MAX_DRIVES; ++unit) {
631                 drive = &hwif->drives[unit];
632                 if (!drive->present)
633                         continue;
634                 if (drive->usage || DRIVER(drive)->busy)
635                         goto abort;
636                 drive->dead = 1;
637         }
638         hwif->present = 0;
639         
640         spin_unlock_irq(&ide_lock);
641
642         for (unit = 0; unit < MAX_DRIVES; ++unit) {
643                 drive = &hwif->drives[unit];
644                 if (!drive->present)
645                         continue;
646                 DRIVER(drive)->cleanup(drive);
647         }
648         
649 #ifdef CONFIG_PROC_FS
650         destroy_proc_ide_drives(hwif);
651 #endif
652
653         hwgroup = hwif->hwgroup;
654         /*
655          * free the irq if we were the only hwif using it
656          */
657         g = hwgroup->hwif;
658         do {
659                 if (g->irq == hwif->irq)
660                         ++irq_count;
661                 g = g->next;
662         } while (g != hwgroup->hwif);
663         if (irq_count == 1)
664                 free_irq(hwif->irq, hwgroup);
665
666         spin_lock_irq(&ide_lock);
667         /*
668          * Note that we only release the standard ports,
669          * and do not even try to handle any extra ports
670          * allocated for weird IDE interface chipsets.
671          */
672         ide_hwif_release_regions(hwif);
673
674         /*
675          * Remove us from the hwgroup, and free
676          * the hwgroup if we were the only member
677          */
678         for (i = 0; i < MAX_DRIVES; ++i) {
679                 drive = &hwif->drives[i];
680                 if (drive->devfs_name[0] != '\0') {
681                         devfs_remove(drive->devfs_name);
682                         drive->devfs_name[0] = '\0';
683                 }
684                 if (!drive->present)
685                         continue;
686                 if (drive == drive->next) {
687                         /* special case: last drive from hwgroup. */
688                         BUG_ON(hwgroup->drive != drive);
689                         hwgroup->drive = NULL;
690                 } else {
691                         ide_drive_t *walk;
692
693                         walk = hwgroup->drive;
694                         while (walk->next != drive)
695                                 walk = walk->next;
696                         walk->next = drive->next;
697                         if (hwgroup->drive == drive) {
698                                 hwgroup->drive = drive->next;
699                                 hwgroup->hwif = HWIF(hwgroup->drive);
700                         }
701                 }
702                 BUG_ON(hwgroup->drive == drive);
703                 if (drive->id != NULL) {
704                         kfree(drive->id);
705                         drive->id = NULL;
706                 }
707                 drive->present = 0;
708                 /* Messed up locking ... */
709                 spin_unlock_irq(&ide_lock);
710                 blk_cleanup_queue(drive->queue);
711                 device_unregister(&drive->gendev);
712                 down(&drive->gendev_rel_sem);
713                 spin_lock_irq(&ide_lock);
714                 drive->queue = NULL;
715         }
716         if (hwif->next == hwif) {
717                 BUG_ON(hwgroup->hwif != hwif);
718                 kfree(hwgroup);
719         } else {
720                 /* There is another interface in hwgroup.
721                  * Unlink us, and set hwgroup->drive and ->hwif to
722                  * something sane.
723                  */
724                 g = hwgroup->hwif;
725                 while (g->next != hwif)
726                         g = g->next;
727                 g->next = hwif->next;
728                 if (hwgroup->hwif == hwif) {
729                         /* Chose a random hwif for hwgroup->hwif.
730                          * It's guaranteed that there are no drives
731                          * left in the hwgroup.
732                          */
733                         BUG_ON(hwgroup->drive != NULL);
734                         hwgroup->hwif = g;
735                 }
736                 BUG_ON(hwgroup->hwif == hwif);
737         }
738
739         /* More messed up locking ... */
740         spin_unlock_irq(&ide_lock);
741         device_unregister(&hwif->gendev);
742         down(&hwif->gendev_rel_sem);
743
744         /*
745          * Remove us from the kernel's knowledge
746          */
747         blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
748         for (i = 0; i < MAX_DRIVES; i++) {
749                 struct gendisk *disk = hwif->drives[i].disk;
750                 hwif->drives[i].disk = NULL;
751                 put_disk(disk);
752         }
753         unregister_blkdev(hwif->major, hwif->name);
754         spin_lock_irq(&ide_lock);
755
756         if (hwif->dma_base) {
757                 (void) ide_release_dma(hwif);
758
759                 hwif->dma_base = 0;
760                 hwif->dma_master = 0;
761                 hwif->dma_command = 0;
762                 hwif->dma_vendor1 = 0;
763                 hwif->dma_status = 0;
764                 hwif->dma_vendor3 = 0;
765                 hwif->dma_prdtable = 0;
766         }
767
768         old_hwif                        = *hwif;
769
770         init_hwif_data(hwif, index);    /* restore hwif data to pristine status */
771         init_hwif_default(hwif, index);
772
773         hwif->hwgroup                   = old_hwif.hwgroup;
774
775         hwif->gendev.parent             = old_hwif.gendev.parent;
776
777         hwif->proc                      = old_hwif.proc;
778
779         hwif->major                     = old_hwif.major;
780 //      hwif->index                     = old_hwif.index;
781 //      hwif->channel                   = old_hwif.channel;
782         hwif->straight8                 = old_hwif.straight8;
783         hwif->bus_state                 = old_hwif.bus_state;
784
785         hwif->atapi_dma                 = old_hwif.atapi_dma;
786         hwif->ultra_mask                = old_hwif.ultra_mask;
787         hwif->mwdma_mask                = old_hwif.mwdma_mask;
788         hwif->swdma_mask                = old_hwif.swdma_mask;
789
790         hwif->chipset                   = old_hwif.chipset;
791         hwif->hold                      = old_hwif.hold;
792
793 #ifdef CONFIG_BLK_DEV_IDEPCI
794         hwif->pci_dev                   = old_hwif.pci_dev;
795         hwif->cds                       = old_hwif.cds;
796 #endif /* CONFIG_BLK_DEV_IDEPCI */
797
798 #if 0
799         hwif->hwifops                   = old_hwif.hwifops;
800 #else
801         hwif->identify                  = old_hwif.identify;
802         hwif->tuneproc                  = old_hwif.tuneproc;
803         hwif->speedproc                 = old_hwif.speedproc;
804         hwif->selectproc                = old_hwif.selectproc;
805         hwif->reset_poll                = old_hwif.reset_poll;
806         hwif->pre_reset                 = old_hwif.pre_reset;
807         hwif->resetproc                 = old_hwif.resetproc;
808         hwif->intrproc                  = old_hwif.intrproc;
809         hwif->maskproc                  = old_hwif.maskproc;
810         hwif->quirkproc                 = old_hwif.quirkproc;
811         hwif->busproc                   = old_hwif.busproc;
812 #endif
813
814 #if 0
815         hwif->pioops                    = old_hwif.pioops;
816 #else
817         hwif->ata_input_data            = old_hwif.ata_input_data;
818         hwif->ata_output_data           = old_hwif.ata_output_data;
819         hwif->atapi_input_bytes         = old_hwif.atapi_input_bytes;
820         hwif->atapi_output_bytes        = old_hwif.atapi_output_bytes;
821 #endif
822
823 #if 0
824         hwif->dmaops                    = old_hwif.dmaops;
825 #else
826         hwif->ide_dma_read              = old_hwif.ide_dma_read;
827         hwif->ide_dma_write             = old_hwif.ide_dma_write;
828         hwif->ide_dma_begin             = old_hwif.ide_dma_begin;
829         hwif->ide_dma_end               = old_hwif.ide_dma_end;
830         hwif->ide_dma_check             = old_hwif.ide_dma_check;
831         hwif->ide_dma_on                = old_hwif.ide_dma_on;
832         hwif->ide_dma_off_quietly       = old_hwif.ide_dma_off_quietly;
833         hwif->ide_dma_test_irq          = old_hwif.ide_dma_test_irq;
834         hwif->ide_dma_host_on           = old_hwif.ide_dma_host_on;
835         hwif->ide_dma_host_off          = old_hwif.ide_dma_host_off;
836         hwif->ide_dma_verbose           = old_hwif.ide_dma_verbose;
837         hwif->ide_dma_lostirq           = old_hwif.ide_dma_lostirq;
838         hwif->ide_dma_timeout           = old_hwif.ide_dma_timeout;
839 #endif
840
841 #if 0
842         hwif->iops                      = old_hwif.iops;
843 #else
844         hwif->OUTB              = old_hwif.OUTB;
845         hwif->OUTBSYNC          = old_hwif.OUTBSYNC;
846         hwif->OUTW              = old_hwif.OUTW;
847         hwif->OUTL              = old_hwif.OUTL;
848         hwif->OUTSW             = old_hwif.OUTSW;
849         hwif->OUTSL             = old_hwif.OUTSL;
850
851         hwif->INB               = old_hwif.INB;
852         hwif->INW               = old_hwif.INW;
853         hwif->INL               = old_hwif.INL;
854         hwif->INSW              = old_hwif.INSW;
855         hwif->INSL              = old_hwif.INSL;
856 #endif
857
858         hwif->mmio                      = old_hwif.mmio;
859         hwif->rqsize                    = old_hwif.rqsize;
860         hwif->no_lba48                  = old_hwif.no_lba48;
861 #ifndef CONFIG_BLK_DEV_IDECS
862         hwif->irq                       = old_hwif.irq;
863 #endif /* CONFIG_BLK_DEV_IDECS */
864
865         hwif->dma_base                  = old_hwif.dma_base;
866         hwif->dma_master                = old_hwif.dma_master;
867         hwif->dma_command               = old_hwif.dma_command;
868         hwif->dma_vendor1               = old_hwif.dma_vendor1;
869         hwif->dma_status                = old_hwif.dma_status;
870         hwif->dma_vendor3               = old_hwif.dma_vendor3;
871         hwif->dma_prdtable              = old_hwif.dma_prdtable;
872
873         hwif->dma_extra                 = old_hwif.dma_extra;
874         hwif->config_data               = old_hwif.config_data;
875         hwif->select_data               = old_hwif.select_data;
876         hwif->autodma                   = old_hwif.autodma;
877         hwif->udma_four                 = old_hwif.udma_four;
878         hwif->no_dsc                    = old_hwif.no_dsc;
879
880         hwif->hwif_data                 = old_hwif.hwif_data;
881 abort:
882         spin_unlock_irq(&ide_lock);
883         up(&ide_cfg_sem);
884 }
885
886 EXPORT_SYMBOL(ide_unregister);
887
888
889 /**
890  *      ide_setup_ports         -       set up IDE interface ports
891  *      @hw: register descriptions
892  *      @base: base register
893  *      @offsets: table of register offsets
894  *      @ctrl: control register
895  *      @ack_irq: IRQ ack
896  *      @irq: interrupt lie
897  *
898  *      Setup hw_regs_t structure described by parameters.  You
899  *      may set up the hw structure yourself OR use this routine to
900  *      do it for you. This is basically a helper
901  *
902  */
903  
904 void ide_setup_ports (  hw_regs_t *hw,
905                         unsigned long base, int *offsets,
906                         unsigned long ctrl, unsigned long intr,
907                         ide_ack_intr_t *ack_intr,
908 /*
909  *                      ide_io_ops_t *iops,
910  */
911                         int irq)
912 {
913         int i;
914
915         for (i = 0; i < IDE_NR_PORTS; i++) {
916                 if (offsets[i] == -1) {
917                         switch(i) {
918                                 case IDE_CONTROL_OFFSET:
919                                         hw->io_ports[i] = ctrl;
920                                         break;
921 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
922                                 case IDE_IRQ_OFFSET:
923                                         hw->io_ports[i] = intr;
924                                         break;
925 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
926                                 default:
927                                         hw->io_ports[i] = 0;
928                                         break;
929                         }
930                 } else {
931                         hw->io_ports[i] = base + offsets[i];
932                 }
933         }
934         hw->irq = irq;
935         hw->dma = NO_DMA;
936         hw->ack_intr = ack_intr;
937 /*
938  *      hw->iops = iops;
939  */
940 }
941
942 EXPORT_SYMBOL(ide_setup_ports);
943
944 /*
945  * Register an IDE interface, specifying exactly the registers etc
946  * Set init=1 iff calling before probes have taken place.
947  */
948 int ide_register_hw (hw_regs_t *hw, ide_hwif_t **hwifp)
949 {
950         int index, retry = 1;
951         ide_hwif_t *hwif;
952
953         do {
954                 for (index = 0; index < MAX_HWIFS; ++index) {
955                         hwif = &ide_hwifs[index];
956                         if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
957                                 goto found;
958                 }
959                 for (index = 0; index < MAX_HWIFS; ++index) {
960                         hwif = &ide_hwifs[index];
961                         if (hwif->hold)
962                                 continue;
963                         if ((!hwif->present && !hwif->mate && !initializing) ||
964                             (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
965                                 goto found;
966                 }
967                 for (index = 0; index < MAX_HWIFS; index++)
968                         ide_unregister(index);
969         } while (retry--);
970         return -1;
971 found:
972         if (hwif->present)
973                 ide_unregister(index);
974         else if (!hwif->hold) {
975                 init_hwif_data(hwif, index);
976                 init_hwif_default(hwif, index);
977         }
978         if (hwif->present)
979                 return -1;
980         memcpy(&hwif->hw, hw, sizeof(*hw));
981         memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
982         hwif->irq = hw->irq;
983         hwif->noprobe = 0;
984         hwif->chipset = hw->chipset;
985
986         if (!initializing) {
987                 probe_hwif_init(hwif);
988                 create_proc_ide_interfaces();
989         }
990
991         if (hwifp)
992                 *hwifp = hwif;
993
994         return (initializing || hwif->present) ? index : -1;
995 }
996
997 EXPORT_SYMBOL(ide_register_hw);
998
999 /*
1000  *      Locks for IDE setting functionality
1001  */
1002
1003 DECLARE_MUTEX(ide_setting_sem);
1004 EXPORT_SYMBOL(ide_setting_sem);
1005
1006 /**
1007  *      ide_add_setting -       add an ide setting option
1008  *      @drive: drive to use
1009  *      @name: setting name
1010  *      @rw: true if the function is read write
1011  *      @read_ioctl: function to call on read
1012  *      @write_ioctl: function to call on write
1013  *      @data_type: type of data
1014  *      @min: range minimum
1015  *      @max: range maximum
1016  *      @mul_factor: multiplication scale
1017  *      @div_factor: divison scale
1018  *      @data: private data field
1019  *      @set: setting
1020  *
1021  *      Removes the setting named from the device if it is present.
1022  *      The function takes the settings_lock to protect against 
1023  *      parallel changes. This function must not be called from IRQ
1024  *      context. Returns 0 on success or -1 on failure.
1025  *
1026  *      BUGS: This code is seriously over-engineered. There is also
1027  *      magic about how the driver specific features are setup. If
1028  *      a driver is attached we assume the driver settings are auto
1029  *      remove.
1030  */
1031  
1032 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)
1033 {
1034         ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
1035
1036         down(&ide_setting_sem);
1037         while ((*p) && strcmp((*p)->name, name) < 0)
1038                 p = &((*p)->next);
1039         if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
1040                 goto abort;
1041         memset(setting, 0, sizeof(*setting));
1042         if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
1043                 goto abort;
1044         strcpy(setting->name, name);
1045         setting->rw = rw;
1046         setting->read_ioctl = read_ioctl;
1047         setting->write_ioctl = write_ioctl;
1048         setting->data_type = data_type;
1049         setting->min = min;
1050         setting->max = max;
1051         setting->mul_factor = mul_factor;
1052         setting->div_factor = div_factor;
1053         setting->data = data;
1054         setting->set = set;
1055         
1056         setting->next = *p;
1057         if (drive->driver != &idedefault_driver)
1058                 setting->auto_remove = 1;
1059         *p = setting;
1060         up(&ide_setting_sem);
1061         return 0;
1062 abort:
1063         up(&ide_setting_sem);
1064         if (setting)
1065                 kfree(setting);
1066         return -1;
1067 }
1068
1069 EXPORT_SYMBOL(ide_add_setting);
1070
1071 /**
1072  *      __ide_remove_setting    -       remove an ide setting option
1073  *      @drive: drive to use
1074  *      @name: setting name
1075  *
1076  *      Removes the setting named from the device if it is present.
1077  *      The caller must hold the setting semaphore.
1078  */
1079  
1080 static void __ide_remove_setting (ide_drive_t *drive, char *name)
1081 {
1082         ide_settings_t **p, *setting;
1083
1084         p = (ide_settings_t **) &drive->settings;
1085
1086         while ((*p) && strcmp((*p)->name, name))
1087                 p = &((*p)->next);
1088         if ((setting = (*p)) == NULL)
1089                 return;
1090
1091         (*p) = setting->next;
1092         
1093         kfree(setting->name);
1094         kfree(setting);
1095 }
1096
1097 /**
1098  *      ide_remove_setting      -       remove an ide setting option
1099  *      @drive: drive to use
1100  *      @name: setting name
1101  *
1102  *      Removes the setting named from the device if it is present.
1103  *      The function takes the settings_lock to protect against 
1104  *      parallel changes. This function must not be called from IRQ
1105  *      context.
1106  */
1107  
1108 void ide_remove_setting (ide_drive_t *drive, char *name)
1109 {
1110         down(&ide_setting_sem);
1111         __ide_remove_setting(drive, name);
1112         up(&ide_setting_sem);
1113 }
1114
1115 EXPORT_SYMBOL(ide_remove_setting);
1116
1117 /**
1118  *      ide_find_setting_by_ioctl       -       find a drive specific ioctl
1119  *      @drive: drive to scan
1120  *      @cmd: ioctl command to handle
1121  *
1122  *      Scan's the device setting table for a matching entry and returns
1123  *      this or NULL if no entry is found. The caller must hold the
1124  *      setting semaphore
1125  */
1126  
1127 static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
1128 {
1129         ide_settings_t *setting = drive->settings;
1130
1131         while (setting) {
1132                 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
1133                         break;
1134                 setting = setting->next;
1135         }
1136         
1137         return setting;
1138 }
1139
1140 /**
1141  *      ide_find_setting_by_name        -       find a drive specific setting
1142  *      @drive: drive to scan
1143  *      @name: setting name
1144  *
1145  *      Scan's the device setting table for a matching entry and returns
1146  *      this or NULL if no entry is found. The caller must hold the
1147  *      setting semaphore
1148  */
1149  
1150 ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
1151 {
1152         ide_settings_t *setting = drive->settings;
1153
1154         while (setting) {
1155                 if (strcmp(setting->name, name) == 0)
1156                         break;
1157                 setting = setting->next;
1158         }
1159         return setting;
1160 }
1161
1162 /**
1163  *      auto_remove_settings    -       remove driver specific settings
1164  *      @drive: drive
1165  *
1166  *      Automatically remove all the driver specific settings for this
1167  *      drive. This function may sleep and must not be called from IRQ
1168  *      context. The caller must hold ide_setting_sem.
1169  */
1170  
1171 static void auto_remove_settings (ide_drive_t *drive)
1172 {
1173         ide_settings_t *setting;
1174 repeat:
1175         setting = drive->settings;
1176         while (setting) {
1177                 if (setting->auto_remove) {
1178                         __ide_remove_setting(drive, setting->name);
1179                         goto repeat;
1180                 }
1181                 setting = setting->next;
1182         }
1183 }
1184
1185 /**
1186  *      ide_read_setting        -       read an IDE setting
1187  *      @drive: drive to read from
1188  *      @setting: drive setting
1189  *
1190  *      Read a drive setting and return the value. The caller
1191  *      must hold the ide_setting_sem when making this call.
1192  *
1193  *      BUGS: the data return and error are the same return value
1194  *      so an error -EINVAL and true return of the same value cannot
1195  *      be told apart
1196  */
1197  
1198 int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1199 {
1200         int             val = -EINVAL;
1201         unsigned long   flags;
1202
1203         if ((setting->rw & SETTING_READ)) {
1204                 spin_lock_irqsave(&ide_lock, flags);
1205                 switch(setting->data_type) {
1206                         case TYPE_BYTE:
1207                                 val = *((u8 *) setting->data);
1208                                 break;
1209                         case TYPE_SHORT:
1210                                 val = *((u16 *) setting->data);
1211                                 break;
1212                         case TYPE_INT:
1213                         case TYPE_INTA:
1214                                 val = *((u32 *) setting->data);
1215                                 break;
1216                 }
1217                 spin_unlock_irqrestore(&ide_lock, flags);
1218         }
1219         return val;
1220 }
1221
1222 int ide_spin_wait_hwgroup (ide_drive_t *drive)
1223 {
1224         ide_hwgroup_t *hwgroup = HWGROUP(drive);
1225         unsigned long timeout = jiffies + (3 * HZ);
1226
1227         spin_lock_irq(&ide_lock);
1228
1229         while (hwgroup->busy) {
1230                 unsigned long lflags;
1231                 spin_unlock_irq(&ide_lock);
1232                 local_irq_set(lflags);
1233                 if (time_after(jiffies, timeout)) {
1234                         local_irq_restore(lflags);
1235                         printk(KERN_ERR "%s: channel busy\n", drive->name);
1236                         return -EBUSY;
1237                 }
1238                 local_irq_restore(lflags);
1239                 spin_lock_irq(&ide_lock);
1240         }
1241         return 0;
1242 }
1243
1244 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1245
1246 /**
1247  *      ide_write_setting       -       read an IDE setting
1248  *      @drive: drive to read from
1249  *      @setting: drive setting
1250  *      @val: value
1251  *
1252  *      Write a drive setting if it is possible. The caller
1253  *      must hold the ide_setting_sem when making this call.
1254  *
1255  *      BUGS: the data return and error are the same return value
1256  *      so an error -EINVAL and true return of the same value cannot
1257  *      be told apart
1258  *
1259  *      FIXME:  This should be changed to enqueue a special request
1260  *      to the driver to change settings, and then wait on a sema for completion.
1261  *      The current scheme of polling is kludgy, though safe enough.
1262  */
1263 int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1264 {
1265         int i;
1266         u32 *p;
1267
1268         if (!capable(CAP_SYS_ADMIN))
1269                 return -EACCES;
1270         if (!(setting->rw & SETTING_WRITE))
1271                 return -EPERM;
1272         if (val < setting->min || val > setting->max)
1273                 return -EINVAL;
1274         if (setting->set)
1275                 return setting->set(drive, val);
1276         if (ide_spin_wait_hwgroup(drive))
1277                 return -EBUSY;
1278         switch (setting->data_type) {
1279                 case TYPE_BYTE:
1280                         *((u8 *) setting->data) = val;
1281                         break;
1282                 case TYPE_SHORT:
1283                         *((u16 *) setting->data) = val;
1284                         break;
1285                 case TYPE_INT:
1286                         *((u32 *) setting->data) = val;
1287                         break;
1288                 case TYPE_INTA:
1289                         p = (u32 *) setting->data;
1290                         for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1291                                 *p = val;
1292                         break;
1293         }
1294         spin_unlock_irq(&ide_lock);
1295         return 0;
1296 }
1297
1298 EXPORT_SYMBOL(ide_write_setting);
1299
1300 static int set_io_32bit(ide_drive_t *drive, int arg)
1301 {
1302         drive->io_32bit = arg;
1303 #ifdef CONFIG_BLK_DEV_DTC2278
1304         if (HWIF(drive)->chipset == ide_dtc2278)
1305                 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1306 #endif /* CONFIG_BLK_DEV_DTC2278 */
1307         return 0;
1308 }
1309
1310 static int set_using_dma (ide_drive_t *drive, int arg)
1311 {
1312 #ifdef CONFIG_BLK_DEV_IDEDMA
1313         if (!drive->id || !(drive->id->capability & 1))
1314                 return -EPERM;
1315         if (HWIF(drive)->ide_dma_check == NULL)
1316                 return -EPERM;
1317         if (arg) {
1318                 if (HWIF(drive)->ide_dma_check(drive)) return -EIO;
1319                 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1320         } else {
1321                 if (__ide_dma_off(drive))
1322                         return -EIO;
1323         }
1324         return 0;
1325 #else
1326         return -EPERM;
1327 #endif
1328 }
1329
1330 static int set_pio_mode (ide_drive_t *drive, int arg)
1331 {
1332         struct request rq;
1333
1334         if (!HWIF(drive)->tuneproc)
1335                 return -ENOSYS;
1336         if (drive->special.b.set_tune)
1337                 return -EBUSY;
1338         ide_init_drive_cmd(&rq);
1339         drive->tune_req = (u8) arg;
1340         drive->special.b.set_tune = 1;
1341         (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1342         return 0;
1343 }
1344
1345 static int set_xfer_rate (ide_drive_t *drive, int arg)
1346 {
1347         int err = ide_wait_cmd(drive,
1348                         WIN_SETFEATURES, (u8) arg,
1349                         SETFEATURES_XFER, 0, NULL);
1350
1351         if (!err && arg) {
1352                 ide_set_xfer_rate(drive, (u8) arg);
1353                 ide_driveid_update(drive);
1354         }
1355         return err;
1356 }
1357
1358 int ide_atapi_to_scsi (ide_drive_t *drive, int arg)
1359 {
1360         if (drive->media == ide_disk) {
1361                 drive->scsi = 0;
1362                 return 0;
1363         }
1364
1365         if (DRIVER(drive)->cleanup(drive)) {
1366                 drive->scsi = 0;
1367                 return 0;
1368         }
1369
1370         drive->scsi = (u8) arg;
1371         ata_attach(drive);
1372         return 0;
1373 }
1374
1375 void ide_add_generic_settings (ide_drive_t *drive)
1376 {
1377 /*
1378  *                      drive   setting name            read/write access                               read ioctl              write ioctl             data type       min     max                             mul_factor      div_factor      data pointer                    set function
1379  */
1380         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);
1381         ide_add_setting(drive,  "keepsettings",         SETTING_RW,                                     HDIO_GET_KEEPSETTINGS,  HDIO_SET_KEEPSETTINGS,  TYPE_BYTE,      0,      1,                              1,              1,              &drive->keep_settings,          NULL);
1382         ide_add_setting(drive,  "nice1",                SETTING_RW,                                     -1,                     -1,                     TYPE_BYTE,      0,      1,                              1,              1,              &drive->nice1,                  NULL);
1383         ide_add_setting(drive,  "pio_mode",             SETTING_WRITE,                                  -1,                     HDIO_SET_PIO_MODE,      TYPE_BYTE,      0,      255,                            1,              1,              NULL,                           set_pio_mode);
1384         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);
1385         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);
1386         ide_add_setting(drive,  "init_speed",           SETTING_RW,                                     -1,                     -1,                     TYPE_BYTE,      0,      70,                             1,              1,              &drive->init_speed,             NULL);
1387         ide_add_setting(drive,  "current_speed",        SETTING_RW,                                     -1,                     -1,                     TYPE_BYTE,      0,      70,                             1,              1,              &drive->current_speed,          set_xfer_rate);
1388         ide_add_setting(drive,  "number",               SETTING_RW,                                     -1,                     -1,                     TYPE_BYTE,      0,      3,                              1,              1,              &drive->dn,                     NULL);
1389         if (drive->media != ide_disk)
1390                 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);
1391 }
1392
1393 /*
1394  * Delay for *at least* 50ms.  As we don't know how much time is left
1395  * until the next tick occurs, we wait an extra tick to be safe.
1396  * This is used only during the probing/polling for drives at boot time.
1397  *
1398  * However, its usefullness may be needed in other places, thus we export it now.
1399  * The future may change this to a millisecond setable delay.
1400  */
1401 void ide_delay_50ms (void)
1402 {
1403 #ifndef CONFIG_BLK_DEV_IDECS
1404         mdelay(50);
1405 #else
1406         __set_current_state(TASK_UNINTERRUPTIBLE);
1407         schedule_timeout(1+HZ/20);
1408 #endif /* CONFIG_BLK_DEV_IDECS */
1409 }
1410
1411 EXPORT_SYMBOL(ide_delay_50ms);
1412
1413 int system_bus_clock (void)
1414 {
1415         return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1416 }
1417
1418 EXPORT_SYMBOL(system_bus_clock);
1419
1420 /*
1421  *      Locking is badly broken here - since way back.  That sucker is
1422  * root-only, but that's not an excuse...  The real question is what
1423  * exclusion rules do we want here.
1424  */
1425 int ide_replace_subdriver (ide_drive_t *drive, const char *driver)
1426 {
1427         if (!drive->present || drive->usage || drive->dead)
1428                 goto abort;
1429         if (DRIVER(drive)->cleanup(drive))
1430                 goto abort;
1431         strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
1432         if (ata_attach(drive)) {
1433                 spin_lock(&drives_lock);
1434                 list_del_init(&drive->list);
1435                 spin_unlock(&drives_lock);
1436                 drive->driver_req[0] = 0;
1437                 ata_attach(drive);
1438         } else {
1439                 drive->driver_req[0] = 0;
1440         }
1441         if (DRIVER(drive)!= &idedefault_driver && !strcmp(DRIVER(drive)->name, driver))
1442                 return 0;
1443 abort:
1444         return 1;
1445 }
1446
1447 EXPORT_SYMBOL(ide_replace_subdriver);
1448
1449 int ata_attach(ide_drive_t *drive)
1450 {
1451         struct list_head *p;
1452         spin_lock(&drivers_lock);
1453         list_for_each(p, &drivers) {
1454                 ide_driver_t *driver = list_entry(p, ide_driver_t, drivers);
1455                 if (!try_module_get(driver->owner))
1456                         continue;
1457                 spin_unlock(&drivers_lock);
1458                 if (driver->attach(drive) == 0) {
1459                         module_put(driver->owner);
1460                         drive->gendev.driver = &driver->gen_driver;
1461                         return 0;
1462                 }
1463                 spin_lock(&drivers_lock);
1464                 module_put(driver->owner);
1465         }
1466         drive->gendev.driver = &idedefault_driver.gen_driver;
1467         spin_unlock(&drivers_lock);
1468         if(idedefault_driver.attach(drive) != 0)
1469                 panic("ide: default attach failed");
1470         return 1;
1471 }
1472
1473 EXPORT_SYMBOL(ata_attach);
1474
1475 static int generic_ide_suspend(struct device *dev, u32 state)
1476 {
1477         ide_drive_t *drive = dev->driver_data;
1478         struct request rq;
1479         struct request_pm_state rqpm;
1480         ide_task_t args;
1481
1482         memset(&rq, 0, sizeof(rq));
1483         memset(&rqpm, 0, sizeof(rqpm));
1484         memset(&args, 0, sizeof(args));
1485         rq.flags = REQ_PM_SUSPEND;
1486         rq.special = &args;
1487         rq.pm = &rqpm;
1488         rqpm.pm_step = ide_pm_state_start_suspend;
1489         rqpm.pm_state = state;
1490
1491         return ide_do_drive_cmd(drive, &rq, ide_wait);
1492 }
1493
1494 static int generic_ide_resume(struct device *dev)
1495 {
1496         ide_drive_t *drive = dev->driver_data;
1497         struct request rq;
1498         struct request_pm_state rqpm;
1499         ide_task_t args;
1500
1501         memset(&rq, 0, sizeof(rq));
1502         memset(&rqpm, 0, sizeof(rqpm));
1503         memset(&args, 0, sizeof(args));
1504         rq.flags = REQ_PM_RESUME;
1505         rq.special = &args;
1506         rq.pm = &rqpm;
1507         rqpm.pm_step = ide_pm_state_start_resume;
1508         rqpm.pm_state = 0;
1509
1510         return ide_do_drive_cmd(drive, &rq, ide_head_wait);
1511 }
1512
1513 int generic_ide_ioctl(struct block_device *bdev, unsigned int cmd,
1514                         unsigned long arg)
1515 {
1516         ide_drive_t *drive = bdev->bd_disk->private_data;
1517         ide_settings_t *setting;
1518         int err = 0;
1519
1520         down(&ide_setting_sem);
1521         if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1522                 if (cmd == setting->read_ioctl) {
1523                         err = ide_read_setting(drive, setting);
1524                         up(&ide_setting_sem);
1525                         return err >= 0 ? put_user(err, (long *) arg) : err;
1526                 } else {
1527                         if (bdev != bdev->bd_contains)
1528                                 err = -EINVAL;
1529                         else
1530                                 err = ide_write_setting(drive, setting, arg);
1531                         up(&ide_setting_sem);
1532                         return err;
1533                 }
1534         }
1535         up(&ide_setting_sem);
1536
1537         switch (cmd) {
1538                 case HDIO_GETGEO:
1539                 {
1540                         struct hd_geometry *loc = (struct hd_geometry *) arg;
1541                         u16 bios_cyl = drive->bios_cyl; /* truncate */
1542                         if (!loc || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1543                         if (put_user(drive->bios_head, (u8 *) &loc->heads)) return -EFAULT;
1544                         if (put_user(drive->bios_sect, (u8 *) &loc->sectors)) return -EFAULT;
1545                         if (put_user(bios_cyl, (u16 *) &loc->cylinders)) return -EFAULT;
1546                         if (put_user((unsigned)get_start_sect(bdev),
1547                                 (unsigned long *) &loc->start)) return -EFAULT;
1548                         return 0;
1549                 }
1550
1551                 case HDIO_OBSOLETE_IDENTITY:
1552                 case HDIO_GET_IDENTITY:
1553                         if (bdev != bdev->bd_contains)
1554                                 return -EINVAL;
1555                         if (drive->id_read == 0)
1556                                 return -ENOMSG;
1557                         if (copy_to_user((char *)arg, (char *)drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1558                                 return -EFAULT;
1559                         return 0;
1560
1561                 case HDIO_GET_NICE:
1562                         return put_user(drive->dsc_overlap      <<      IDE_NICE_DSC_OVERLAP    |
1563                                         drive->atapi_overlap    <<      IDE_NICE_ATAPI_OVERLAP  |
1564                                         drive->nice0            <<      IDE_NICE_0              |
1565                                         drive->nice1            <<      IDE_NICE_1              |
1566                                         drive->nice2            <<      IDE_NICE_2,
1567                                         (long *) arg);
1568
1569 #ifdef CONFIG_IDE_TASK_IOCTL
1570                 case HDIO_DRIVE_TASKFILE:
1571                         if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1572                                 return -EACCES;
1573                         switch(drive->media) {
1574                                 case ide_disk:
1575                                         return ide_taskfile_ioctl(drive, cmd, arg);
1576                                 default:
1577                                         return -ENOMSG;
1578                         }
1579 #endif /* CONFIG_IDE_TASK_IOCTL */
1580
1581                 case HDIO_DRIVE_CMD:
1582                         if (!capable(CAP_SYS_RAWIO))
1583                                 return -EACCES;
1584                         return ide_cmd_ioctl(drive, cmd, arg);
1585
1586                 case HDIO_DRIVE_TASK:
1587                         if (!capable(CAP_SYS_RAWIO))
1588                                 return -EACCES;
1589                         return ide_task_ioctl(drive, cmd, arg);
1590
1591                 case HDIO_SCAN_HWIF:
1592                 {
1593                         hw_regs_t hw;
1594                         int args[3];
1595                         if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1596                         if (copy_from_user(args, (void *)arg, 3 * sizeof(int)))
1597                                 return -EFAULT;
1598                         memset(&hw, 0, sizeof(hw));
1599                         ide_init_hwif_ports(&hw, (unsigned long) args[0],
1600                                             (unsigned long) args[1], NULL);
1601                         hw.irq = args[2];
1602                         if (ide_register_hw(&hw, NULL) == -1)
1603                                 return -EIO;
1604                         return 0;
1605                 }
1606                 case HDIO_UNREGISTER_HWIF:
1607                         if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1608                         /* (arg > MAX_HWIFS) checked in function */
1609                         ide_unregister(arg);
1610                         return 0;
1611                 case HDIO_SET_NICE:
1612                         if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1613                         if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1614                                 return -EPERM;
1615                         drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1616                         if (drive->dsc_overlap && !DRIVER(drive)->supports_dsc_overlap) {
1617                                 drive->dsc_overlap = 0;
1618                                 return -EPERM;
1619                         }
1620                         drive->nice1 = (arg >> IDE_NICE_1) & 1;
1621                         return 0;
1622                 case HDIO_DRIVE_RESET:
1623                 {
1624                         unsigned long flags;
1625                         if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1626                         
1627                         /*
1628                          *      Abort the current command on the
1629                          *      group if there is one, taking
1630                          *      care not to allow anything else
1631                          *      to be queued and to die on the
1632                          *      spot if we miss one somehow
1633                          */
1634
1635                         spin_lock_irqsave(&ide_lock, flags);
1636                         
1637                         DRIVER(drive)->abort(drive, "drive reset");
1638                         if(HWGROUP(drive)->handler)
1639                                 BUG();
1640                                 
1641                         /* Ensure nothing gets queued after we
1642                            drop the lock. Reset will clear the busy */
1643                    
1644                         HWGROUP(drive)->busy = 1;
1645                         spin_unlock_irqrestore(&ide_lock, flags);
1646                         (void) ide_do_reset(drive);
1647                         if (drive->suspend_reset) {
1648 /*
1649  *                              APM WAKE UP todo !!
1650  *                              int nogoodpower = 1;
1651  *                              while(nogoodpower) {
1652  *                                      check_power1() or check_power2()
1653  *                                      nogoodpower = 0;
1654  *                              } 
1655  *                              HWIF(drive)->multiproc(drive);
1656  */
1657                                 return ioctl_by_bdev(bdev, BLKRRPART, 0);
1658                         }
1659                         return 0;
1660                 }
1661
1662                 case CDROMEJECT:
1663                 case CDROMCLOSETRAY:
1664                         return scsi_cmd_ioctl(bdev->bd_disk, cmd, arg);
1665
1666                 case HDIO_GET_BUSSTATE:
1667                         if (!capable(CAP_SYS_ADMIN))
1668                                 return -EACCES;
1669                         if (put_user(HWIF(drive)->bus_state, (long *)arg))
1670                                 return -EFAULT;
1671                         return 0;
1672
1673                 case HDIO_SET_BUSSTATE:
1674                         if (!capable(CAP_SYS_ADMIN))
1675                                 return -EACCES;
1676                         if (HWIF(drive)->busproc)
1677                                 return HWIF(drive)->busproc(drive, (int)arg);
1678                         return -EOPNOTSUPP;
1679                 default:
1680                         return -EINVAL;
1681         }
1682 }
1683
1684 EXPORT_SYMBOL(generic_ide_ioctl);
1685
1686 /*
1687  * stridx() returns the offset of c within s,
1688  * or -1 if c is '\0' or not found within s.
1689  */
1690 static int __init stridx (const char *s, char c)
1691 {
1692         char *i = strchr(s, c);
1693         return (i && c) ? i - s : -1;
1694 }
1695
1696 /*
1697  * match_parm() does parsing for ide_setup():
1698  *
1699  * 1. the first char of s must be '='.
1700  * 2. if the remainder matches one of the supplied keywords,
1701  *     the index (1 based) of the keyword is negated and returned.
1702  * 3. if the remainder is a series of no more than max_vals numbers
1703  *     separated by commas, the numbers are saved in vals[] and a
1704  *     count of how many were saved is returned.  Base10 is assumed,
1705  *     and base16 is allowed when prefixed with "0x".
1706  * 4. otherwise, zero is returned.
1707  */
1708 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
1709 {
1710         static const char *decimal = "0123456789";
1711         static const char *hex = "0123456789abcdef";
1712         int i, n;
1713
1714         if (*s++ == '=') {
1715                 /*
1716                  * Try matching against the supplied keywords,
1717                  * and return -(index+1) if we match one
1718                  */
1719                 if (keywords != NULL) {
1720                         for (i = 0; *keywords != NULL; ++i) {
1721                                 if (!strcmp(s, *keywords++))
1722                                         return -(i+1);
1723                         }
1724                 }
1725                 /*
1726                  * Look for a series of no more than "max_vals"
1727                  * numeric values separated by commas, in base10,
1728                  * or base16 when prefixed with "0x".
1729                  * Return a count of how many were found.
1730                  */
1731                 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
1732                         vals[n] = i;
1733                         while ((i = stridx(decimal, *++s)) >= 0)
1734                                 vals[n] = (vals[n] * 10) + i;
1735                         if (*s == 'x' && !vals[n]) {
1736                                 while ((i = stridx(hex, *++s)) >= 0)
1737                                         vals[n] = (vals[n] * 0x10) + i;
1738                         }
1739                         if (++n == max_vals)
1740                                 break;
1741                         if (*s == ',' || *s == ';')
1742                                 ++s;
1743                 }
1744                 if (!*s)
1745                         return n;
1746         }
1747         return 0;       /* zero = nothing matched */
1748 }
1749
1750 #ifdef CONFIG_BLK_DEV_PDC4030
1751 static int __initdata probe_pdc4030;
1752 #endif
1753 #ifdef CONFIG_BLK_DEV_ALI14XX
1754 static int __initdata probe_ali14xx;
1755 extern int ali14xx_init(void);
1756 #endif
1757 #ifdef CONFIG_BLK_DEV_UMC8672
1758 static int __initdata probe_umc8672;
1759 extern int umc8672_init(void);
1760 #endif
1761 #ifdef CONFIG_BLK_DEV_DTC2278
1762 static int __initdata probe_dtc2278;
1763 extern int dtc2278_init(void);
1764 #endif
1765 #ifdef CONFIG_BLK_DEV_HT6560B
1766 static int __initdata probe_ht6560b;
1767 extern int ht6560b_init(void);
1768 #endif
1769 #ifdef CONFIG_BLK_DEV_QD65XX
1770 static int __initdata probe_qd65xx;
1771 extern int qd65xx_init(void);
1772 #endif
1773
1774 static int __initdata is_chipset_set[MAX_HWIFS];
1775
1776 /*
1777  * ide_setup() gets called VERY EARLY during initialization,
1778  * to handle kernel "command line" strings beginning with "hdx=" or "ide".
1779  *
1780  * Remember to update Documentation/ide.txt if you change something here.
1781  */
1782 int __init ide_setup (char *s)
1783 {
1784         int i, vals[3];
1785         ide_hwif_t *hwif;
1786         ide_drive_t *drive;
1787         unsigned int hw, unit;
1788         const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
1789         const char max_hwif  = '0' + (MAX_HWIFS - 1);
1790
1791         
1792         if (strncmp(s,"hd",2) == 0 && s[2] == '=')      /* hd= is for hd.c   */
1793                 return 0;                               /* driver and not us */
1794
1795         if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1796                 return 0;
1797
1798         printk(KERN_INFO "ide_setup: %s", s);
1799         init_ide_data ();
1800
1801 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
1802         if (!strcmp(s, "ide=doubler")) {
1803                 extern int ide_doubler;
1804
1805                 printk(" : Enabled support for IDE doublers\n");
1806                 ide_doubler = 1;
1807                 return 1;
1808         }
1809 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1810
1811         if (!strcmp(s, "ide=nodma")) {
1812                 printk("IDE: Prevented DMA\n");
1813                 noautodma = 1;
1814                 return 1;
1815         }
1816
1817 #ifdef CONFIG_BLK_DEV_IDEPCI
1818         if (!strcmp(s, "ide=reverse")) {
1819                 ide_scan_direction = 1;
1820                 printk(" : Enabled support for IDE inverse scan order.\n");
1821                 return 1;
1822         }
1823 #endif /* CONFIG_BLK_DEV_IDEPCI */
1824
1825         /*
1826          * Look for drive options:  "hdx="
1827          */
1828         if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1829                 const char *hd_words[] = {
1830                         "none", "noprobe", "nowerr", "cdrom", "serialize",
1831                         "autotune", "noautotune", "minus8", "swapdata", "bswap",
1832                         "minus11", "remap", "remap63", "scsi", NULL };
1833                 unit = s[2] - 'a';
1834                 hw   = unit / MAX_DRIVES;
1835                 unit = unit % MAX_DRIVES;
1836                 hwif = &ide_hwifs[hw];
1837                 drive = &hwif->drives[unit];
1838                 if (strncmp(s + 4, "ide-", 4) == 0) {
1839                         strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1840                         goto done;
1841                 }
1842                 switch (match_parm(&s[3], hd_words, vals, 3)) {
1843                         case -1: /* "none" */
1844                         case -2: /* "noprobe" */
1845                                 drive->noprobe = 1;
1846                                 goto done;
1847                         case -3: /* "nowerr" */
1848                                 drive->bad_wstat = BAD_R_STAT;
1849                                 hwif->noprobe = 0;
1850                                 goto done;
1851                         case -4: /* "cdrom" */
1852                                 drive->present = 1;
1853                                 drive->media = ide_cdrom;
1854                                 hwif->noprobe = 0;
1855                                 goto done;
1856                         case -5: /* "serialize" */
1857                                 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1858                                 goto do_serialize;
1859                         case -6: /* "autotune" */
1860                                 drive->autotune = IDE_TUNE_AUTO;
1861                                 goto done;
1862                         case -7: /* "noautotune" */
1863                                 drive->autotune = IDE_TUNE_NOAUTO;
1864                                 goto done;
1865                         case -9: /* "swapdata" */
1866                         case -10: /* "bswap" */
1867                                 drive->bswap = 1;
1868                                 goto done;
1869                         case -12: /* "remap" */
1870                                 drive->remap_0_to_1 = 1;
1871                                 goto done;
1872                         case -13: /* "remap63" */
1873                                 drive->sect0 = 63;
1874                                 goto done;
1875                         case -14: /* "scsi" */
1876                                 drive->scsi = 1;
1877                                 goto done;
1878                         case 3: /* cyl,head,sect */
1879                                 drive->media    = ide_disk;
1880                                 drive->cyl      = drive->bios_cyl  = vals[0];
1881                                 drive->head     = drive->bios_head = vals[1];
1882                                 drive->sect     = drive->bios_sect = vals[2];
1883                                 drive->present  = 1;
1884                                 drive->forced_geom = 1;
1885                                 hwif->noprobe = 0;
1886                                 goto done;
1887                         default:
1888                                 goto bad_option;
1889                 }
1890         }
1891
1892         if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1893                 goto bad_option;
1894         /*
1895          * Look for bus speed option:  "idebus="
1896          */
1897         if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1898                 if (match_parm(&s[6], NULL, vals, 1) != 1)
1899                         goto bad_option;
1900                 if (vals[0] >= 20 && vals[0] <= 66) {
1901                         idebus_parameter = vals[0];
1902                 } else
1903                         printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1904                 goto done;
1905         }
1906         /*
1907          * Look for interface options:  "idex="
1908          */
1909         if (s[3] >= '0' && s[3] <= max_hwif) {
1910                 /*
1911                  * Be VERY CAREFUL changing this: note hardcoded indexes below
1912                  * (-8, -9, -10) are reserved to ease the hardcoding.
1913                  */
1914                 static const char *ide_words[] = {
1915                         "noprobe", "serialize", "autotune", "noautotune", 
1916                         "reset", "dma", "ata66", "minus8", "minus9",
1917                         "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1918                         "dtc2278", "umc8672", "ali14xx", "dc4030", NULL };
1919                 hw = s[3] - '0';
1920                 hwif = &ide_hwifs[hw];
1921                 i = match_parm(&s[4], ide_words, vals, 3);
1922
1923                 /*
1924                  * Cryptic check to ensure chipset not already set for hwif.
1925                  * Note: we can't depend on hwif->chipset here.
1926                  */
1927                 if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
1928                         /* chipset already specified */
1929                         if (is_chipset_set[hw])
1930                                 goto bad_option;
1931                         if (i > -18 && i <= -11) {
1932                                 /* these drivers are for "ide0=" only */
1933                                 if (hw != 0)
1934                                         goto bad_hwif;
1935                                 /* chipset already specified for 2nd port */
1936                                 if (is_chipset_set[hw+1])
1937                                         goto bad_option;
1938                         }
1939                         is_chipset_set[hw] = 1;
1940                         printk("\n");
1941                 }
1942
1943                 switch (i) {
1944 #ifdef CONFIG_BLK_DEV_PDC4030
1945                         case -18: /* "dc4030" */
1946                                 probe_pdc4030 = 1;
1947                                 goto done;
1948 #endif
1949 #ifdef CONFIG_BLK_DEV_ALI14XX
1950                         case -17: /* "ali14xx" */
1951                                 probe_ali14xx = 1;
1952                                 goto done;
1953 #endif
1954 #ifdef CONFIG_BLK_DEV_UMC8672
1955                         case -16: /* "umc8672" */
1956                                 probe_umc8672 = 1;
1957                                 goto done;
1958 #endif
1959 #ifdef CONFIG_BLK_DEV_DTC2278
1960                         case -15: /* "dtc2278" */
1961                                 probe_dtc2278 = 1;
1962                                 goto done;
1963 #endif
1964 #ifdef CONFIG_BLK_DEV_CMD640
1965                         case -14: /* "cmd640_vlb" */
1966                         {
1967                                 extern int cmd640_vlb; /* flag for cmd640.c */
1968                                 cmd640_vlb = 1;
1969                                 goto done;
1970                         }
1971 #endif
1972 #ifdef CONFIG_BLK_DEV_HT6560B
1973                         case -13: /* "ht6560b" */
1974                                 probe_ht6560b = 1;
1975                                 goto done;
1976 #endif
1977 #ifdef CONFIG_BLK_DEV_QD65XX
1978                         case -12: /* "qd65xx" */
1979                                 probe_qd65xx = 1;
1980                                 goto done;
1981 #endif
1982 #ifdef CONFIG_BLK_DEV_4DRIVES
1983                         case -11: /* "four" drives on one set of ports */
1984                         {
1985                                 ide_hwif_t *mate = &ide_hwifs[hw^1];
1986                                 mate->drives[0].select.all ^= 0x20;
1987                                 mate->drives[1].select.all ^= 0x20;
1988                                 hwif->chipset = mate->chipset = ide_4drives;
1989                                 mate->irq = hwif->irq;
1990                                 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
1991                                 goto do_serialize;
1992                         }
1993 #endif /* CONFIG_BLK_DEV_4DRIVES */
1994                         case -10: /* minus10 */
1995                         case -9: /* minus9 */
1996                         case -8: /* minus8 */
1997                                 goto bad_option;
1998                         case -7: /* ata66 */
1999 #ifdef CONFIG_BLK_DEV_IDEPCI
2000                                 hwif->udma_four = 1;
2001                                 goto done;
2002 #else
2003                                 goto bad_hwif;
2004 #endif
2005                         case -6: /* dma */
2006                                 hwif->autodma = 1;
2007                                 goto done;
2008                         case -5: /* "reset" */
2009                                 hwif->reset = 1;
2010                                 goto done;
2011                         case -4: /* "noautotune" */
2012                                 hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
2013                                 hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
2014                                 goto done;
2015                         case -3: /* "autotune" */
2016                                 hwif->drives[0].autotune = IDE_TUNE_AUTO;
2017                                 hwif->drives[1].autotune = IDE_TUNE_AUTO;
2018                                 goto done;
2019                         case -2: /* "serialize" */
2020                         do_serialize:
2021                                 hwif->mate = &ide_hwifs[hw^1];
2022                                 hwif->mate->mate = hwif;
2023                                 hwif->serialized = hwif->mate->serialized = 1;
2024                                 goto done;
2025
2026                         case -1: /* "noprobe" */
2027                                 hwif->noprobe = 1;
2028                                 goto done;
2029
2030                         case 1: /* base */
2031                                 vals[1] = vals[0] + 0x206; /* default ctl */
2032                         case 2: /* base,ctl */
2033                                 vals[2] = 0;    /* default irq = probe for it */
2034                         case 3: /* base,ctl,irq */
2035                                 hwif->hw.irq = vals[2];
2036                                 ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
2037                                 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
2038                                 hwif->irq      = vals[2];
2039                                 hwif->noprobe  = 0;
2040                                 hwif->chipset  = ide_forced;
2041                                 goto done;
2042
2043                         case 0: goto bad_option;
2044                         default:
2045                                 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
2046                                 return 1;
2047                 }
2048         }
2049 bad_option:
2050         printk(" -- BAD OPTION\n");
2051         return 1;
2052 bad_hwif:
2053         printk("-- NOT SUPPORTED ON ide%d", hw);
2054 done:
2055         printk("\n");
2056         return 1;
2057 }
2058
2059 /*
2060  * probe_for_hwifs() finds/initializes "known" IDE interfaces
2061  */
2062 static void __init probe_for_hwifs (void)
2063 {
2064 #ifdef CONFIG_BLK_DEV_IDEPCI
2065         ide_scan_pcibus(ide_scan_direction);
2066 #endif /* CONFIG_BLK_DEV_IDEPCI */
2067
2068 #ifdef CONFIG_ETRAX_IDE
2069         {
2070                 extern void init_e100_ide(void);
2071                 init_e100_ide();
2072         }
2073 #endif /* CONFIG_ETRAX_IDE */
2074 #ifdef CONFIG_BLK_DEV_CMD640
2075         {
2076                 extern void ide_probe_for_cmd640x(void);
2077                 ide_probe_for_cmd640x();
2078         }
2079 #endif /* CONFIG_BLK_DEV_CMD640 */
2080 #ifdef CONFIG_BLK_DEV_PDC4030
2081         {
2082                 extern int pdc4030_init(void);
2083                 if (probe_pdc4030)
2084                         (void)pdc4030_init();
2085         }
2086 #endif /* CONFIG_BLK_DEV_PDC4030 */
2087 #ifdef CONFIG_BLK_DEV_IDE_PMAC
2088         {
2089                 extern void pmac_ide_probe(void);
2090                 pmac_ide_probe();
2091         }
2092 #endif /* CONFIG_BLK_DEV_IDE_PMAC */
2093 #ifdef CONFIG_BLK_DEV_IDE_SWARM
2094         {
2095                 extern void swarm_ide_probe(void);
2096                 swarm_ide_probe();
2097         }
2098 #endif /* CONFIG_BLK_DEV_IDE_SWARM */
2099 #ifdef CONFIG_BLK_DEV_GAYLE
2100         {
2101                 extern void gayle_init(void);
2102                 gayle_init();
2103         }
2104 #endif /* CONFIG_BLK_DEV_GAYLE */
2105 #ifdef CONFIG_BLK_DEV_FALCON_IDE
2106         {
2107                 extern void falconide_init(void);
2108                 falconide_init();
2109         }
2110 #endif /* CONFIG_BLK_DEV_FALCON_IDE */
2111 #ifdef CONFIG_BLK_DEV_MAC_IDE
2112         {
2113                 extern void macide_init(void);
2114                 macide_init();
2115         }
2116 #endif /* CONFIG_BLK_DEV_MAC_IDE */
2117 #ifdef CONFIG_BLK_DEV_Q40IDE
2118         {
2119                 extern void q40ide_init(void);
2120                 q40ide_init();
2121         }
2122 #endif /* CONFIG_BLK_DEV_Q40IDE */
2123 #ifdef CONFIG_BLK_DEV_BUDDHA
2124         {
2125                 extern void buddha_init(void);
2126                 buddha_init();
2127         }
2128 #endif /* CONFIG_BLK_DEV_BUDDHA */
2129 #if defined(CONFIG_BLK_DEV_IDEPNP) && defined(CONFIG_PNP)
2130         {
2131                 extern void pnpide_init(int enable);
2132                 pnpide_init(1);
2133         }
2134 #endif /* CONFIG_BLK_DEV_IDEPNP */
2135 }
2136
2137 /*
2138  *      Actually unregister the subdriver. Called with the
2139  *      request lock dropped.
2140  */
2141  
2142 static int default_cleanup (ide_drive_t *drive)
2143 {
2144         return ide_unregister_subdriver(drive);
2145 }
2146
2147 static ide_startstop_t default_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
2148 {
2149         ide_end_request(drive, 0, 0);
2150         return ide_stopped;
2151 }
2152
2153 static int default_end_request (ide_drive_t *drive, int uptodate, int nr_sects)
2154 {
2155         return ide_end_request(drive, uptodate, nr_sects);
2156 }
2157
2158 static u8 default_sense (ide_drive_t *drive, const char *msg, u8 stat)
2159 {
2160         return ide_dump_status(drive, msg, stat);
2161 }
2162
2163 static ide_startstop_t default_error (ide_drive_t *drive, const char *msg, u8 stat)
2164 {
2165         return ide_error(drive, msg, stat);
2166 }
2167
2168 static void default_pre_reset (ide_drive_t *drive)
2169 {
2170 }
2171
2172 static sector_t default_capacity (ide_drive_t *drive)
2173 {
2174         return 0x7fffffff;
2175 }
2176
2177 static ide_startstop_t default_special (ide_drive_t *drive)
2178 {
2179         special_t *s = &drive->special;
2180
2181         s->all = 0;
2182         drive->mult_req = 0;
2183         return ide_stopped;
2184 }
2185
2186 static int default_attach (ide_drive_t *drive)
2187 {
2188         printk(KERN_ERR "%s: does not support hotswap of device class !\n",
2189                 drive->name);
2190
2191         return 0;
2192 }
2193
2194 static ide_startstop_t default_abort (ide_drive_t *drive, const char *msg)
2195 {
2196         return ide_abort(drive, msg);
2197 }
2198
2199 static ide_startstop_t default_start_power_step(ide_drive_t *drive,
2200                                                 struct request *rq)
2201 {
2202         rq->pm->pm_step = ide_pm_state_completed;
2203         return ide_stopped;
2204 }
2205
2206 static void setup_driver_defaults (ide_driver_t *d)
2207 {
2208         if (d->cleanup == NULL)         d->cleanup = default_cleanup;
2209         if (d->do_request == NULL)      d->do_request = default_do_request;
2210         if (d->end_request == NULL)     d->end_request = default_end_request;
2211         if (d->sense == NULL)           d->sense = default_sense;
2212         if (d->error == NULL)           d->error = default_error;
2213         if (d->abort == NULL)           d->abort = default_abort;
2214         if (d->pre_reset == NULL)       d->pre_reset = default_pre_reset;
2215         if (d->capacity == NULL)        d->capacity = default_capacity;
2216         if (d->special == NULL)         d->special = default_special;
2217         if (d->attach == NULL)          d->attach = default_attach;
2218         if (d->start_power_step == NULL)
2219                 d->start_power_step = default_start_power_step;
2220 }
2221
2222 int ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
2223 {
2224         unsigned long flags;
2225
2226         BUG_ON(!drive->driver);
2227
2228         spin_lock_irqsave(&ide_lock, flags);
2229         if (!drive->present || drive->driver != &idedefault_driver ||
2230             drive->usage || drive->dead) {
2231                 spin_unlock_irqrestore(&ide_lock, flags);
2232                 return 1;
2233         }
2234         drive->driver = driver;
2235         spin_unlock_irqrestore(&ide_lock, flags);
2236         spin_lock(&drives_lock);
2237         list_add_tail(&drive->list, &driver->drives);
2238         spin_unlock(&drives_lock);
2239 //      printk(KERN_INFO "%s: attached %s driver.\n", drive->name, driver->name);
2240         if ((drive->autotune == IDE_TUNE_DEFAULT) ||
2241                 (drive->autotune == IDE_TUNE_AUTO)) {
2242                 /* DMA timings and setup moved to ide-probe.c */
2243                 drive->dsc_overlap = (drive->next != drive && driver->supports_dsc_overlap);
2244                 drive->nice1 = 1;
2245         }
2246         drive->suspend_reset = 0;
2247 #ifdef CONFIG_PROC_FS
2248         if (drive->driver != &idedefault_driver) {
2249                 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
2250                 ide_add_proc_entries(drive->proc, driver->proc, drive);
2251         }
2252 #endif
2253         return 0;
2254 }
2255
2256 EXPORT_SYMBOL(ide_register_subdriver);
2257
2258 int ide_unregister_subdriver (ide_drive_t *drive)
2259 {
2260         unsigned long flags;
2261         
2262         down(&ide_setting_sem);
2263         spin_lock_irqsave(&ide_lock, flags);
2264         if (drive->usage || drive->driver == &idedefault_driver || DRIVER(drive)->busy) {
2265                 spin_unlock_irqrestore(&ide_lock, flags);
2266                 up(&ide_setting_sem);
2267                 return 1;
2268         }
2269 #if defined(CONFIG_BLK_DEV_IDEPNP) && defined(CONFIG_PNP) && defined(MODULE)
2270         pnpide_init(0);
2271 #endif /* CONFIG_BLK_DEV_IDEPNP */
2272 #ifdef CONFIG_PROC_FS
2273         ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc);
2274         ide_remove_proc_entries(drive->proc, generic_subdriver_entries);
2275 #endif
2276         auto_remove_settings(drive);
2277         drive->driver = &idedefault_driver;
2278         spin_unlock_irqrestore(&ide_lock, flags);
2279         up(&ide_setting_sem);
2280         spin_lock(&drives_lock);
2281         list_del_init(&drive->list);
2282         spin_unlock(&drives_lock);
2283         /* drive will be added to &idedefault_driver->drives in ata_attach() */
2284         return 0;
2285 }
2286
2287 EXPORT_SYMBOL(ide_unregister_subdriver);
2288
2289 static int ide_drive_remove(struct device * dev)
2290 {
2291         ide_drive_t * drive = container_of(dev,ide_drive_t,gendev);
2292         DRIVER(drive)->cleanup(drive);
2293         return 0;
2294 }
2295
2296 int ide_register_driver(ide_driver_t *driver)
2297 {
2298         struct list_head list;
2299         struct list_head *list_loop;
2300         struct list_head *tmp_storage;
2301
2302         setup_driver_defaults(driver);
2303
2304         spin_lock(&drivers_lock);
2305         list_add(&driver->drivers, &drivers);
2306         spin_unlock(&drivers_lock);
2307
2308         INIT_LIST_HEAD(&list);
2309         spin_lock(&drives_lock);
2310         list_splice_init(&idedefault_driver.drives, &list);
2311         spin_unlock(&drives_lock);
2312
2313         list_for_each_safe(list_loop, tmp_storage, &list) {
2314                 ide_drive_t *drive = container_of(list_loop, ide_drive_t, list);
2315                 list_del_init(&drive->list);
2316                 if (drive->present)
2317                         ata_attach(drive);
2318         }
2319         driver->gen_driver.name = (char *) driver->name;
2320         driver->gen_driver.bus = &ide_bus_type;
2321         driver->gen_driver.remove = ide_drive_remove;
2322         return driver_register(&driver->gen_driver);
2323 }
2324
2325 EXPORT_SYMBOL(ide_register_driver);
2326
2327 void ide_unregister_driver(ide_driver_t *driver)
2328 {
2329         ide_drive_t *drive;
2330
2331         spin_lock(&drivers_lock);
2332         list_del(&driver->drivers);
2333         spin_unlock(&drivers_lock);
2334
2335         driver_unregister(&driver->gen_driver);
2336
2337         while(!list_empty(&driver->drives)) {
2338                 drive = list_entry(driver->drives.next, ide_drive_t, list);
2339                 if (driver->cleanup(drive)) {
2340                         printk(KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
2341                         BUG();
2342                 }
2343                 ata_attach(drive);
2344         }
2345 }
2346
2347 EXPORT_SYMBOL(ide_unregister_driver);
2348
2349 struct block_device_operations ide_fops[] = {{
2350         .owner          = THIS_MODULE,
2351         .open           = ide_open,
2352 }};
2353
2354 EXPORT_SYMBOL(ide_fops);
2355
2356 /*
2357  * Probe module
2358  */
2359
2360 EXPORT_SYMBOL(ide_lock);
2361
2362 struct bus_type ide_bus_type = {
2363         .name           = "ide",
2364         .suspend        = generic_ide_suspend,
2365         .resume         = generic_ide_resume,
2366 };
2367
2368 /*
2369  * This is gets invoked once during initialization, to set *everything* up
2370  */
2371 int __init ide_init (void)
2372 {
2373         printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
2374         devfs_mk_dir("ide");
2375         system_bus_speed = ide_system_bus_speed();
2376
2377         bus_register(&ide_bus_type);
2378
2379         init_ide_data();
2380
2381 #ifdef CONFIG_PROC_FS
2382         proc_ide_root = proc_mkdir("ide", 0);
2383 #endif
2384
2385 #ifdef CONFIG_BLK_DEV_ALI14XX
2386         if (probe_ali14xx)
2387                 (void)ali14xx_init();
2388 #endif
2389 #ifdef CONFIG_BLK_DEV_UMC8672
2390         if (probe_umc8672)
2391                 (void)umc8672_init();
2392 #endif
2393 #ifdef CONFIG_BLK_DEV_DTC2278
2394         if (probe_dtc2278)
2395                 (void)dtc2278_init();
2396 #endif
2397 #ifdef CONFIG_BLK_DEV_HT6560B
2398         if (probe_ht6560b)
2399                 (void)ht6560b_init();
2400 #endif
2401 #ifdef CONFIG_BLK_DEV_QD65XX
2402         if (probe_qd65xx)
2403                 (void)qd65xx_init();
2404 #endif
2405
2406         initializing = 1;
2407         /* Probe for special PCI and other "known" interface chipsets. */
2408         probe_for_hwifs();
2409         initializing = 0;
2410
2411 #ifdef CONFIG_PROC_FS
2412         proc_ide_create();
2413 #endif
2414         return 0;
2415 }
2416
2417 #ifdef MODULE
2418 char *options = NULL;
2419 MODULE_PARM(options,"s");
2420 MODULE_LICENSE("GPL");
2421
2422 static void __init parse_options (char *line)
2423 {
2424         char *next = line;
2425
2426         if (line == NULL || !*line)
2427                 return;
2428         while ((line = next) != NULL) {
2429                 if ((next = strchr(line,' ')) != NULL)
2430                         *next++ = 0;
2431                 if (!ide_setup(line))
2432                         printk (KERN_INFO "Unknown option '%s'\n", line);
2433         }
2434 }
2435
2436 int init_module (void)
2437 {
2438         parse_options(options);
2439         return ide_init();
2440 }
2441
2442 void cleanup_module (void)
2443 {
2444         int index;
2445
2446         for (index = 0; index < MAX_HWIFS; ++index) {
2447                 ide_unregister(index);
2448                 if (ide_hwifs[index].dma_base)
2449                         (void) ide_release_dma(&ide_hwifs[index]);
2450         }
2451
2452 #ifdef CONFIG_PROC_FS
2453         proc_ide_destroy();
2454 #endif
2455         devfs_remove("ide");
2456
2457         bus_unregister(&ide_bus_type);
2458 }
2459
2460 #else /* !MODULE */
2461
2462 __setup("", ide_setup);
2463
2464 module_init(ide_init);
2465
2466 #endif /* MODULE */