]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/ide/ide.c
f338fe96ff6d510f989dacce54377b4629be4a32
[linux-2.6-omap-h63xx.git] / drivers / ide / ide.c
1 /*
2  *  Copyright (C) 1994-1998         Linus Torvalds & authors (see below)
3  *  Copyrifht (C) 2003-2005, 2007   Bartlomiej Zolnierkiewicz
4  */
5
6 /*
7  *  Mostly written by Mark Lord  <mlord@pobox.com>
8  *                and Gadi Oxman <gadio@netvision.net.il>
9  *                and Andre Hedrick <andre@linux-ide.org>
10  *
11  *  See linux/MAINTAINERS for address of current maintainer.
12  *
13  * This is the multiple IDE interface driver, as evolved from hd.c.
14  * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
15  *   (usually 14 & 15).
16  * There can be up to two drives per interface, as per the ATA-2 spec.
17  *
18  * ...
19  *
20  *  From hd.c:
21  *  |
22  *  | It traverses the request-list, using interrupts to jump between functions.
23  *  | As nearly all functions can be called within interrupts, we may not sleep.
24  *  | Special care is recommended.  Have Fun!
25  *  |
26  *  | modified by Drew Eckhardt to check nr of hd's from the CMOS.
27  *  |
28  *  | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
29  *  | in the early extended-partition checks and added DM partitions.
30  *  |
31  *  | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
32  *  |
33  *  | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
34  *  | and general streamlining by Mark Lord (mlord@pobox.com).
35  *
36  *  October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
37  *
38  *      Mark Lord       (mlord@pobox.com)               (IDE Perf.Pkg)
39  *      Delman Lee      (delman@ieee.org)               ("Mr. atdisk2")
40  *      Scott Snyder    (snyder@fnald0.fnal.gov)        (ATAPI IDE cd-rom)
41  *
42  *  This was a rewrite of just about everything from hd.c, though some original
43  *  code is still sprinkled about.  Think of it as a major evolution, with
44  *  inspiration from lots of linux users, esp.  hamish@zot.apana.org.au
45  */
46
47 #define _IDE_C                  /* Tell ide.h it's really us */
48
49 #include <linux/module.h>
50 #include <linux/types.h>
51 #include <linux/string.h>
52 #include <linux/kernel.h>
53 #include <linux/timer.h>
54 #include <linux/mm.h>
55 #include <linux/interrupt.h>
56 #include <linux/major.h>
57 #include <linux/errno.h>
58 #include <linux/genhd.h>
59 #include <linux/blkpg.h>
60 #include <linux/slab.h>
61 #include <linux/init.h>
62 #include <linux/pci.h>
63 #include <linux/delay.h>
64 #include <linux/ide.h>
65 #include <linux/completion.h>
66 #include <linux/reboot.h>
67 #include <linux/cdrom.h>
68 #include <linux/seq_file.h>
69 #include <linux/device.h>
70 #include <linux/bitops.h>
71
72 #include <asm/byteorder.h>
73 #include <asm/irq.h>
74 #include <asm/uaccess.h>
75 #include <asm/io.h>
76
77
78 /* default maximum number of failures */
79 #define IDE_DEFAULT_MAX_FAILURES        1
80
81 struct class *ide_port_class;
82
83 static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
84                                         IDE2_MAJOR, IDE3_MAJOR,
85                                         IDE4_MAJOR, IDE5_MAJOR,
86                                         IDE6_MAJOR, IDE7_MAJOR,
87                                         IDE8_MAJOR, IDE9_MAJOR };
88
89 static int idebus_parameter;    /* holds the "idebus=" parameter */
90 static int system_bus_speed;    /* holds what we think is VESA/PCI bus speed */
91
92 DEFINE_MUTEX(ide_cfg_mtx);
93  __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
94
95 int noautodma = 0;
96
97 #ifdef CONFIG_BLK_DEV_IDEACPI
98 int ide_noacpi = 0;
99 int ide_noacpitfs = 1;
100 int ide_noacpionboot = 1;
101 #endif
102
103 /*
104  * This is declared extern in ide.h, for access by other IDE modules:
105  */
106 ide_hwif_t ide_hwifs[MAX_HWIFS];        /* master data repository */
107
108 EXPORT_SYMBOL(ide_hwifs);
109
110 static void ide_port_init_devices_data(ide_hwif_t *);
111
112 /*
113  * Do not even *think* about calling this!
114  */
115 void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
116 {
117         /* bulk initialize hwif & drive info with zeros */
118         memset(hwif, 0, sizeof(ide_hwif_t));
119
120         /* fill in any non-zero initial values */
121         hwif->index     = index;
122         hwif->major     = ide_hwif_to_major[index];
123
124         hwif->name[0]   = 'i';
125         hwif->name[1]   = 'd';
126         hwif->name[2]   = 'e';
127         hwif->name[3]   = '0' + index;
128
129         hwif->bus_state = BUSSTATE_ON;
130
131         init_completion(&hwif->gendev_rel_comp);
132
133         default_hwif_iops(hwif);
134         default_hwif_transport(hwif);
135
136         ide_port_init_devices_data(hwif);
137 }
138 EXPORT_SYMBOL_GPL(ide_init_port_data);
139
140 static void ide_port_init_devices_data(ide_hwif_t *hwif)
141 {
142         int unit;
143
144         for (unit = 0; unit < MAX_DRIVES; ++unit) {
145                 ide_drive_t *drive = &hwif->drives[unit];
146                 u8 j = (hwif->index * MAX_DRIVES) + unit;
147
148                 memset(drive, 0, sizeof(*drive));
149
150                 drive->media                    = ide_disk;
151                 drive->select.all               = (unit<<4)|0xa0;
152                 drive->hwif                     = hwif;
153                 drive->ctl                      = 0x08;
154                 drive->ready_stat               = READY_STAT;
155                 drive->bad_wstat                = BAD_W_STAT;
156                 drive->special.b.recalibrate    = 1;
157                 drive->special.b.set_geometry   = 1;
158                 drive->name[0]                  = 'h';
159                 drive->name[1]                  = 'd';
160                 drive->name[2]                  = 'a' + j;
161                 drive->max_failures             = IDE_DEFAULT_MAX_FAILURES;
162
163                 INIT_LIST_HEAD(&drive->list);
164                 init_completion(&drive->gendev_rel_comp);
165         }
166 }
167
168 /*
169  * init_ide_data() sets reasonable default values into all fields
170  * of all instances of the hwifs and drives, but only on the first call.
171  * Subsequent calls have no effect (they don't wipe out anything).
172  *
173  * This routine is normally called at driver initialization time,
174  * but may also be called MUCH earlier during kernel "command-line"
175  * parameter processing.  As such, we cannot depend on any other parts
176  * of the kernel (such as memory allocation) to be functioning yet.
177  *
178  * This is too bad, as otherwise we could dynamically allocate the
179  * ide_drive_t structs as needed, rather than always consuming memory
180  * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
181  *
182  * FIXME: We should stuff the setup data into __init and copy the
183  * relevant hwifs/allocate them properly during boot.
184  */
185 #define MAGIC_COOKIE 0x12345678
186 static void __init init_ide_data (void)
187 {
188         unsigned int index;
189         static unsigned long magic_cookie = MAGIC_COOKIE;
190
191         if (magic_cookie != MAGIC_COOKIE)
192                 return;         /* already initialized */
193         magic_cookie = 0;
194
195         /* Initialise all interface structures */
196         for (index = 0; index < MAX_HWIFS; ++index) {
197                 ide_hwif_t *hwif = &ide_hwifs[index];
198
199                 ide_init_port_data(hwif, index);
200         }
201 }
202
203 /**
204  *      ide_system_bus_speed    -       guess bus speed
205  *
206  *      ide_system_bus_speed() returns what we think is the system VESA/PCI
207  *      bus speed (in MHz). This is used for calculating interface PIO timings.
208  *      The default is 40 for known PCI systems, 50 otherwise.
209  *      The "idebus=xx" parameter can be used to override this value.
210  *      The actual value to be used is computed/displayed the first time
211  *      through. Drivers should only use this as a last resort.
212  *
213  *      Returns a guessed speed in MHz.
214  */
215
216 static int ide_system_bus_speed(void)
217 {
218 #ifdef CONFIG_PCI
219         static struct pci_device_id pci_default[] = {
220                 { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
221                 { }
222         };
223 #else
224 #define pci_default 0
225 #endif /* CONFIG_PCI */
226
227         /* user supplied value */
228         if (idebus_parameter)
229                 return idebus_parameter;
230
231         /* safe default value for PCI or VESA and PCI*/
232         return pci_dev_present(pci_default) ? 33 : 50;
233 }
234
235 static struct resource* hwif_request_region(ide_hwif_t *hwif,
236                                             unsigned long addr, int num)
237 {
238         struct resource *res = request_region(addr, num, hwif->name);
239
240         if (!res)
241                 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
242                                 hwif->name, addr, addr+num-1);
243         return res;
244 }
245
246 /**
247  *      ide_hwif_request_regions - request resources for IDE
248  *      @hwif: interface to use
249  *
250  *      Requests all the needed resources for an interface.
251  *      Right now core IDE code does this work which is deeply wrong.
252  *      MMIO leaves it to the controller driver,
253  *      PIO will migrate this way over time.
254  */
255
256 int ide_hwif_request_regions(ide_hwif_t *hwif)
257 {
258         unsigned long addr;
259         unsigned int i;
260
261         if (hwif->mmio)
262                 return 0;
263         addr = hwif->io_ports[IDE_CONTROL_OFFSET];
264         if (addr && !hwif_request_region(hwif, addr, 1))
265                 goto control_region_busy;
266         hwif->straight8 = 0;
267         addr = hwif->io_ports[IDE_DATA_OFFSET];
268         if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
269                 if (!hwif_request_region(hwif, addr, 8))
270                         goto data_region_busy;
271                 hwif->straight8 = 1;
272                 return 0;
273         }
274         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
275                 addr = hwif->io_ports[i];
276                 if (!hwif_request_region(hwif, addr, 1)) {
277                         while (--i)
278                                 release_region(addr, 1);
279                         goto data_region_busy;
280                 }
281         }
282         return 0;
283
284 data_region_busy:
285         addr = hwif->io_ports[IDE_CONTROL_OFFSET];
286         if (addr)
287                 release_region(addr, 1);
288 control_region_busy:
289         /* If any errors are return, we drop the hwif interface. */
290         return -EBUSY;
291 }
292
293 /**
294  *      ide_hwif_release_regions - free IDE resources
295  *
296  *      Note that we only release the standard ports,
297  *      and do not even try to handle any extra ports
298  *      allocated for weird IDE interface chipsets.
299  *
300  *      Note also that we don't yet handle mmio resources here. More
301  *      importantly our caller should be doing this so we need to 
302  *      restructure this as a helper function for drivers.
303  */
304
305 void ide_hwif_release_regions(ide_hwif_t *hwif)
306 {
307         u32 i = 0;
308
309         if (hwif->mmio)
310                 return;
311         if (hwif->io_ports[IDE_CONTROL_OFFSET])
312                 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
313         if (hwif->straight8) {
314                 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
315                 return;
316         }
317         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
318                 if (hwif->io_ports[i])
319                         release_region(hwif->io_ports[i], 1);
320 }
321
322 void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
323 {
324         ide_hwgroup_t *hwgroup = hwif->hwgroup;
325
326         spin_lock_irq(&ide_lock);
327         /*
328          * Remove us from the hwgroup, and free
329          * the hwgroup if we were the only member
330          */
331         if (hwif->next == hwif) {
332                 BUG_ON(hwgroup->hwif != hwif);
333                 kfree(hwgroup);
334         } else {
335                 /* There is another interface in hwgroup.
336                  * Unlink us, and set hwgroup->drive and ->hwif to
337                  * something sane.
338                  */
339                 ide_hwif_t *g = hwgroup->hwif;
340
341                 while (g->next != hwif)
342                         g = g->next;
343                 g->next = hwif->next;
344                 if (hwgroup->hwif == hwif) {
345                         /* Chose a random hwif for hwgroup->hwif.
346                          * It's guaranteed that there are no drives
347                          * left in the hwgroup.
348                          */
349                         BUG_ON(hwgroup->drive != NULL);
350                         hwgroup->hwif = g;
351                 }
352                 BUG_ON(hwgroup->hwif == hwif);
353         }
354         spin_unlock_irq(&ide_lock);
355 }
356
357 /* Called with ide_lock held. */
358 static void __ide_port_unregister_devices(ide_hwif_t *hwif)
359 {
360         int i;
361
362         for (i = 0; i < MAX_DRIVES; i++) {
363                 ide_drive_t *drive = &hwif->drives[i];
364
365                 if (drive->present) {
366                         spin_unlock_irq(&ide_lock);
367                         device_unregister(&drive->gendev);
368                         wait_for_completion(&drive->gendev_rel_comp);
369                         spin_lock_irq(&ide_lock);
370                 }
371         }
372 }
373
374 void ide_port_unregister_devices(ide_hwif_t *hwif)
375 {
376         mutex_lock(&ide_cfg_mtx);
377         spin_lock_irq(&ide_lock);
378         __ide_port_unregister_devices(hwif);
379         hwif->present = 0;
380         ide_port_init_devices_data(hwif);
381         spin_unlock_irq(&ide_lock);
382         mutex_unlock(&ide_cfg_mtx);
383 }
384 EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
385
386 /**
387  *      ide_unregister          -       free an IDE interface
388  *      @index: index of interface (will change soon to a pointer)
389  *
390  *      Perform the final unregister of an IDE interface. At the moment
391  *      we don't refcount interfaces so this will also get split up.
392  *
393  *      Locking:
394  *      The caller must not hold the IDE locks
395  *      The drive present/vanishing is not yet properly locked
396  *      Take care with the callbacks. These have been split to avoid
397  *      deadlocking the IDE layer. The shutdown callback is called
398  *      before we take the lock and free resources. It is up to the
399  *      caller to be sure there is no pending I/O here, and that
400  *      the interface will not be reopened (present/vanishing locking
401  *      isn't yet done BTW). After we commit to the final kill we
402  *      call the cleanup callback with the ide locks held.
403  *
404  *      Unregister restores the hwif structures to the default state.
405  *      This is raving bonkers.
406  */
407
408 void ide_unregister(unsigned int index)
409 {
410         ide_hwif_t *hwif, *g;
411         ide_hwgroup_t *hwgroup;
412         int irq_count = 0;
413
414         BUG_ON(index >= MAX_HWIFS);
415
416         BUG_ON(in_interrupt());
417         BUG_ON(irqs_disabled());
418         mutex_lock(&ide_cfg_mtx);
419         spin_lock_irq(&ide_lock);
420         hwif = &ide_hwifs[index];
421         if (!hwif->present)
422                 goto abort;
423         __ide_port_unregister_devices(hwif);
424         hwif->present = 0;
425
426         spin_unlock_irq(&ide_lock);
427
428         ide_proc_unregister_port(hwif);
429
430         hwgroup = hwif->hwgroup;
431         /*
432          * free the irq if we were the only hwif using it
433          */
434         g = hwgroup->hwif;
435         do {
436                 if (g->irq == hwif->irq)
437                         ++irq_count;
438                 g = g->next;
439         } while (g != hwgroup->hwif);
440         if (irq_count == 1)
441                 free_irq(hwif->irq, hwgroup);
442
443         ide_remove_port_from_hwgroup(hwif);
444
445         device_unregister(hwif->portdev);
446         device_unregister(&hwif->gendev);
447         wait_for_completion(&hwif->gendev_rel_comp);
448
449         /*
450          * Remove us from the kernel's knowledge
451          */
452         blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
453         kfree(hwif->sg_table);
454         unregister_blkdev(hwif->major, hwif->name);
455         spin_lock_irq(&ide_lock);
456
457         if (hwif->dma_base)
458                 (void)ide_release_dma(hwif);
459
460         ide_hwif_release_regions(hwif);
461
462         /* restore hwif data to pristine status */
463         ide_init_port_data(hwif, index);
464
465 abort:
466         spin_unlock_irq(&ide_lock);
467         mutex_unlock(&ide_cfg_mtx);
468 }
469
470 EXPORT_SYMBOL(ide_unregister);
471
472 void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
473 {
474         memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
475         hwif->irq = hw->irq;
476         hwif->noprobe = 0;
477         hwif->chipset = hw->chipset;
478         hwif->gendev.parent = hw->dev;
479         hwif->ack_intr = hw->ack_intr;
480 }
481 EXPORT_SYMBOL_GPL(ide_init_port_hw);
482
483 /*
484  *      Locks for IDE setting functionality
485  */
486
487 DEFINE_MUTEX(ide_setting_mtx);
488
489 EXPORT_SYMBOL_GPL(ide_setting_mtx);
490
491 /**
492  *      ide_spin_wait_hwgroup   -       wait for group
493  *      @drive: drive in the group
494  *
495  *      Wait for an IDE device group to go non busy and then return
496  *      holding the ide_lock which guards the hwgroup->busy status
497  *      and right to use it.
498  */
499
500 int ide_spin_wait_hwgroup (ide_drive_t *drive)
501 {
502         ide_hwgroup_t *hwgroup = HWGROUP(drive);
503         unsigned long timeout = jiffies + (3 * HZ);
504
505         spin_lock_irq(&ide_lock);
506
507         while (hwgroup->busy) {
508                 unsigned long lflags;
509                 spin_unlock_irq(&ide_lock);
510                 local_irq_set(lflags);
511                 if (time_after(jiffies, timeout)) {
512                         local_irq_restore(lflags);
513                         printk(KERN_ERR "%s: channel busy\n", drive->name);
514                         return -EBUSY;
515                 }
516                 local_irq_restore(lflags);
517                 spin_lock_irq(&ide_lock);
518         }
519         return 0;
520 }
521
522 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
523
524 int set_io_32bit(ide_drive_t *drive, int arg)
525 {
526         if (drive->no_io_32bit)
527                 return -EPERM;
528
529         if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
530                 return -EINVAL;
531
532         if (ide_spin_wait_hwgroup(drive))
533                 return -EBUSY;
534
535         drive->io_32bit = arg;
536
537         spin_unlock_irq(&ide_lock);
538
539         return 0;
540 }
541
542 static int set_ksettings(ide_drive_t *drive, int arg)
543 {
544         if (arg < 0 || arg > 1)
545                 return -EINVAL;
546
547         if (ide_spin_wait_hwgroup(drive))
548                 return -EBUSY;
549         drive->keep_settings = arg;
550         spin_unlock_irq(&ide_lock);
551
552         return 0;
553 }
554
555 int set_using_dma(ide_drive_t *drive, int arg)
556 {
557 #ifdef CONFIG_BLK_DEV_IDEDMA
558         ide_hwif_t *hwif = drive->hwif;
559         int err = -EPERM;
560
561         if (arg < 0 || arg > 1)
562                 return -EINVAL;
563
564         if (!drive->id || !(drive->id->capability & 1))
565                 goto out;
566
567         if (hwif->dma_host_set == NULL)
568                 goto out;
569
570         err = -EBUSY;
571         if (ide_spin_wait_hwgroup(drive))
572                 goto out;
573         /*
574          * set ->busy flag, unlock and let it ride
575          */
576         hwif->hwgroup->busy = 1;
577         spin_unlock_irq(&ide_lock);
578
579         err = 0;
580
581         if (arg) {
582                 if (ide_set_dma(drive))
583                         err = -EIO;
584         } else
585                 ide_dma_off(drive);
586
587         /*
588          * lock, clear ->busy flag and unlock before leaving
589          */
590         spin_lock_irq(&ide_lock);
591         hwif->hwgroup->busy = 0;
592         spin_unlock_irq(&ide_lock);
593 out:
594         return err;
595 #else
596         if (arg < 0 || arg > 1)
597                 return -EINVAL;
598
599         return -EPERM;
600 #endif
601 }
602
603 int set_pio_mode(ide_drive_t *drive, int arg)
604 {
605         struct request rq;
606
607         if (arg < 0 || arg > 255)
608                 return -EINVAL;
609
610         if (drive->hwif->set_pio_mode == NULL)
611                 return -ENOSYS;
612
613         if (drive->special.b.set_tune)
614                 return -EBUSY;
615
616         ide_init_drive_cmd(&rq);
617         rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
618
619         drive->tune_req = (u8) arg;
620         drive->special.b.set_tune = 1;
621         (void) ide_do_drive_cmd(drive, &rq, ide_wait);
622         return 0;
623 }
624
625 static int set_unmaskirq(ide_drive_t *drive, int arg)
626 {
627         if (drive->no_unmask)
628                 return -EPERM;
629
630         if (arg < 0 || arg > 1)
631                 return -EINVAL;
632
633         if (ide_spin_wait_hwgroup(drive))
634                 return -EBUSY;
635         drive->unmask = arg;
636         spin_unlock_irq(&ide_lock);
637
638         return 0;
639 }
640
641 /**
642  *      system_bus_clock        -       clock guess
643  *
644  *      External version of the bus clock guess used by very old IDE drivers
645  *      for things like VLB timings. Should not be used.
646  */
647
648 int system_bus_clock (void)
649 {
650         return system_bus_speed;
651 }
652
653 EXPORT_SYMBOL(system_bus_clock);
654
655 static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
656 {
657         ide_drive_t *drive = dev->driver_data;
658         ide_hwif_t *hwif = HWIF(drive);
659         struct request rq;
660         struct request_pm_state rqpm;
661         ide_task_t args;
662         int ret;
663
664         /* Call ACPI _GTM only once */
665         if (!(drive->dn % 2))
666                 ide_acpi_get_timing(hwif);
667
668         memset(&rq, 0, sizeof(rq));
669         memset(&rqpm, 0, sizeof(rqpm));
670         memset(&args, 0, sizeof(args));
671         rq.cmd_type = REQ_TYPE_PM_SUSPEND;
672         rq.special = &args;
673         rq.data = &rqpm;
674         rqpm.pm_step = ide_pm_state_start_suspend;
675         if (mesg.event == PM_EVENT_PRETHAW)
676                 mesg.event = PM_EVENT_FREEZE;
677         rqpm.pm_state = mesg.event;
678
679         ret = ide_do_drive_cmd(drive, &rq, ide_wait);
680         /* only call ACPI _PS3 after both drivers are suspended */
681         if (!ret && (((drive->dn % 2) && hwif->drives[0].present
682                  && hwif->drives[1].present)
683                  || !hwif->drives[0].present
684                  || !hwif->drives[1].present))
685                 ide_acpi_set_state(hwif, 0);
686         return ret;
687 }
688
689 static int generic_ide_resume(struct device *dev)
690 {
691         ide_drive_t *drive = dev->driver_data;
692         ide_hwif_t *hwif = HWIF(drive);
693         struct request rq;
694         struct request_pm_state rqpm;
695         ide_task_t args;
696         int err;
697
698         /* Call ACPI _STM only once */
699         if (!(drive->dn % 2)) {
700                 ide_acpi_set_state(hwif, 1);
701                 ide_acpi_push_timing(hwif);
702         }
703
704         ide_acpi_exec_tfs(drive);
705
706         memset(&rq, 0, sizeof(rq));
707         memset(&rqpm, 0, sizeof(rqpm));
708         memset(&args, 0, sizeof(args));
709         rq.cmd_type = REQ_TYPE_PM_RESUME;
710         rq.special = &args;
711         rq.data = &rqpm;
712         rqpm.pm_step = ide_pm_state_start_resume;
713         rqpm.pm_state = PM_EVENT_ON;
714
715         err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
716
717         if (err == 0 && dev->driver) {
718                 ide_driver_t *drv = to_ide_driver(dev->driver);
719
720                 if (drv->resume)
721                         drv->resume(drive);
722         }
723
724         return err;
725 }
726
727 int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
728                         unsigned int cmd, unsigned long arg)
729 {
730         unsigned long flags;
731         ide_driver_t *drv;
732         void __user *p = (void __user *)arg;
733         int err = 0, (*setfunc)(ide_drive_t *, int);
734         u8 *val;
735
736         switch (cmd) {
737         case HDIO_GET_32BIT:        val = &drive->io_32bit;      goto read_val;
738         case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
739         case HDIO_GET_UNMASKINTR:   val = &drive->unmask;        goto read_val;
740         case HDIO_GET_DMA:          val = &drive->using_dma;     goto read_val;
741         case HDIO_SET_32BIT:        setfunc = set_io_32bit;      goto set_val;
742         case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings;     goto set_val;
743         case HDIO_SET_PIO_MODE:     setfunc = set_pio_mode;      goto set_val;
744         case HDIO_SET_UNMASKINTR:   setfunc = set_unmaskirq;     goto set_val;
745         case HDIO_SET_DMA:          setfunc = set_using_dma;     goto set_val;
746         }
747
748         switch (cmd) {
749                 case HDIO_OBSOLETE_IDENTITY:
750                 case HDIO_GET_IDENTITY:
751                         if (bdev != bdev->bd_contains)
752                                 return -EINVAL;
753                         if (drive->id_read == 0)
754                                 return -ENOMSG;
755                         if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
756                                 return -EFAULT;
757                         return 0;
758
759                 case HDIO_GET_NICE:
760                         return put_user(drive->dsc_overlap      <<      IDE_NICE_DSC_OVERLAP    |
761                                         drive->atapi_overlap    <<      IDE_NICE_ATAPI_OVERLAP  |
762                                         drive->nice1 << IDE_NICE_1,
763                                         (long __user *) arg);
764 #ifdef CONFIG_IDE_TASK_IOCTL
765                 case HDIO_DRIVE_TASKFILE:
766                         if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
767                                 return -EACCES;
768                         switch(drive->media) {
769                                 case ide_disk:
770                                         return ide_taskfile_ioctl(drive, cmd, arg);
771                                 default:
772                                         return -ENOMSG;
773                         }
774 #endif /* CONFIG_IDE_TASK_IOCTL */
775
776                 case HDIO_DRIVE_CMD:
777                         if (!capable(CAP_SYS_RAWIO))
778                                 return -EACCES;
779                         return ide_cmd_ioctl(drive, cmd, arg);
780
781                 case HDIO_DRIVE_TASK:
782                         if (!capable(CAP_SYS_RAWIO))
783                                 return -EACCES;
784                         return ide_task_ioctl(drive, cmd, arg);
785                 case HDIO_SET_NICE:
786                         if (!capable(CAP_SYS_ADMIN)) return -EACCES;
787                         if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
788                                 return -EPERM;
789                         drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
790                         drv = *(ide_driver_t **)bdev->bd_disk->private_data;
791                         if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
792                                 drive->dsc_overlap = 0;
793                                 return -EPERM;
794                         }
795                         drive->nice1 = (arg >> IDE_NICE_1) & 1;
796                         return 0;
797                 case HDIO_DRIVE_RESET:
798                         if (!capable(CAP_SYS_ADMIN))
799                                 return -EACCES;
800
801                         /*
802                          *      Abort the current command on the
803                          *      group if there is one, taking
804                          *      care not to allow anything else
805                          *      to be queued and to die on the
806                          *      spot if we miss one somehow
807                          */
808
809                         spin_lock_irqsave(&ide_lock, flags);
810
811                         if (HWGROUP(drive)->resetting) {
812                                 spin_unlock_irqrestore(&ide_lock, flags);
813                                 return -EBUSY;
814                         }
815
816                         ide_abort(drive, "drive reset");
817
818                         BUG_ON(HWGROUP(drive)->handler);
819
820                         /* Ensure nothing gets queued after we
821                            drop the lock. Reset will clear the busy */
822
823                         HWGROUP(drive)->busy = 1;
824                         spin_unlock_irqrestore(&ide_lock, flags);
825                         (void) ide_do_reset(drive);
826
827                         return 0;
828                 case HDIO_GET_BUSSTATE:
829                         if (!capable(CAP_SYS_ADMIN))
830                                 return -EACCES;
831                         if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
832                                 return -EFAULT;
833                         return 0;
834
835                 case HDIO_SET_BUSSTATE:
836                         if (!capable(CAP_SYS_ADMIN))
837                                 return -EACCES;
838                         return -EOPNOTSUPP;
839                 default:
840                         return -EINVAL;
841         }
842
843 read_val:
844         mutex_lock(&ide_setting_mtx);
845         spin_lock_irqsave(&ide_lock, flags);
846         err = *val;
847         spin_unlock_irqrestore(&ide_lock, flags);
848         mutex_unlock(&ide_setting_mtx);
849         return err >= 0 ? put_user(err, (long __user *)arg) : err;
850
851 set_val:
852         if (bdev != bdev->bd_contains)
853                 err = -EINVAL;
854         else {
855                 if (!capable(CAP_SYS_ADMIN))
856                         err = -EACCES;
857                 else {
858                         mutex_lock(&ide_setting_mtx);
859                         err = setfunc(drive, arg);
860                         mutex_unlock(&ide_setting_mtx);
861                 }
862         }
863         return err;
864 }
865
866 EXPORT_SYMBOL(generic_ide_ioctl);
867
868 /*
869  * stridx() returns the offset of c within s,
870  * or -1 if c is '\0' or not found within s.
871  */
872 static int __init stridx (const char *s, char c)
873 {
874         char *i = strchr(s, c);
875         return (i && c) ? i - s : -1;
876 }
877
878 /*
879  * match_parm() does parsing for ide_setup():
880  *
881  * 1. the first char of s must be '='.
882  * 2. if the remainder matches one of the supplied keywords,
883  *     the index (1 based) of the keyword is negated and returned.
884  * 3. if the remainder is a series of no more than max_vals numbers
885  *     separated by commas, the numbers are saved in vals[] and a
886  *     count of how many were saved is returned.  Base10 is assumed,
887  *     and base16 is allowed when prefixed with "0x".
888  * 4. otherwise, zero is returned.
889  */
890 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
891 {
892         static const char *decimal = "0123456789";
893         static const char *hex = "0123456789abcdef";
894         int i, n;
895
896         if (*s++ == '=') {
897                 /*
898                  * Try matching against the supplied keywords,
899                  * and return -(index+1) if we match one
900                  */
901                 if (keywords != NULL) {
902                         for (i = 0; *keywords != NULL; ++i) {
903                                 if (!strcmp(s, *keywords++))
904                                         return -(i+1);
905                         }
906                 }
907                 /*
908                  * Look for a series of no more than "max_vals"
909                  * numeric values separated by commas, in base10,
910                  * or base16 when prefixed with "0x".
911                  * Return a count of how many were found.
912                  */
913                 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
914                         vals[n] = i;
915                         while ((i = stridx(decimal, *++s)) >= 0)
916                                 vals[n] = (vals[n] * 10) + i;
917                         if (*s == 'x' && !vals[n]) {
918                                 while ((i = stridx(hex, *++s)) >= 0)
919                                         vals[n] = (vals[n] * 0x10) + i;
920                         }
921                         if (++n == max_vals)
922                                 break;
923                         if (*s == ',' || *s == ';')
924                                 ++s;
925                 }
926                 if (!*s)
927                         return n;
928         }
929         return 0;       /* zero = nothing matched */
930 }
931
932 extern int probe_ali14xx;
933 extern int probe_umc8672;
934 extern int probe_dtc2278;
935 extern int probe_ht6560b;
936 extern int probe_qd65xx;
937 extern int cmd640_vlb;
938 extern int probe_4drives;
939
940 static int __initdata is_chipset_set;
941
942 /*
943  * ide_setup() gets called VERY EARLY during initialization,
944  * to handle kernel "command line" strings beginning with "hdx=" or "ide".
945  *
946  * Remember to update Documentation/ide/ide.txt if you change something here.
947  */
948 static int __init ide_setup(char *s)
949 {
950         int i, vals[3];
951         ide_hwif_t *hwif;
952         ide_drive_t *drive;
953         unsigned int hw, unit;
954         const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
955         const char max_hwif  = '0' + (MAX_HWIFS - 1);
956
957         
958         if (strncmp(s,"hd",2) == 0 && s[2] == '=')      /* hd= is for hd.c   */
959                 return 0;                               /* driver and not us */
960
961         if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
962                 return 0;
963
964         printk(KERN_INFO "ide_setup: %s", s);
965         init_ide_data ();
966
967 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
968         if (!strcmp(s, "ide=doubler")) {
969                 extern int ide_doubler;
970
971                 printk(" : Enabled support for IDE doublers\n");
972                 ide_doubler = 1;
973                 return 1;
974         }
975 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
976
977         if (!strcmp(s, "ide=nodma")) {
978                 printk(" : Prevented DMA\n");
979                 noautodma = 1;
980                 goto obsolete_option;
981         }
982
983 #ifdef CONFIG_BLK_DEV_IDEACPI
984         if (!strcmp(s, "ide=noacpi")) {
985                 //printk(" : Disable IDE ACPI support.\n");
986                 ide_noacpi = 1;
987                 return 1;
988         }
989         if (!strcmp(s, "ide=acpigtf")) {
990                 //printk(" : Enable IDE ACPI _GTF support.\n");
991                 ide_noacpitfs = 0;
992                 return 1;
993         }
994         if (!strcmp(s, "ide=acpionboot")) {
995                 //printk(" : Call IDE ACPI methods on boot.\n");
996                 ide_noacpionboot = 0;
997                 return 1;
998         }
999 #endif /* CONFIG_BLK_DEV_IDEACPI */
1000
1001         /*
1002          * Look for drive options:  "hdx="
1003          */
1004         if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1005                 const char *hd_words[] = {
1006                         "none", "noprobe", "nowerr", "cdrom", "nodma",
1007                         "autotune", "noautotune", "-8", "-9", "-10",
1008                         "noflush", "remap", "remap63", "scsi", NULL };
1009                 unit = s[2] - 'a';
1010                 hw   = unit / MAX_DRIVES;
1011                 unit = unit % MAX_DRIVES;
1012                 hwif = &ide_hwifs[hw];
1013                 drive = &hwif->drives[unit];
1014                 if (strncmp(s + 4, "ide-", 4) == 0) {
1015                         strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1016                         goto obsolete_option;
1017                 }
1018                 switch (match_parm(&s[3], hd_words, vals, 3)) {
1019                         case -1: /* "none" */
1020                         case -2: /* "noprobe" */
1021                                 drive->noprobe = 1;
1022                                 goto done;
1023                         case -3: /* "nowerr" */
1024                                 drive->bad_wstat = BAD_R_STAT;
1025                                 hwif->noprobe = 0;
1026                                 goto done;
1027                         case -4: /* "cdrom" */
1028                                 drive->present = 1;
1029                                 drive->media = ide_cdrom;
1030                                 /* an ATAPI device ignores DRDY */
1031                                 drive->ready_stat = 0;
1032                                 hwif->noprobe = 0;
1033                                 goto done;
1034                         case -5: /* nodma */
1035                                 drive->nodma = 1;
1036                                 goto done;
1037                         case -6: /* "autotune" */
1038                                 drive->autotune = IDE_TUNE_AUTO;
1039                                 goto obsolete_option;
1040                         case -7: /* "noautotune" */
1041                                 drive->autotune = IDE_TUNE_NOAUTO;
1042                                 goto obsolete_option;
1043                         case -11: /* noflush */
1044                                 drive->noflush = 1;
1045                                 goto done;
1046                         case -12: /* "remap" */
1047                                 drive->remap_0_to_1 = 1;
1048                                 goto obsolete_option;
1049                         case -13: /* "remap63" */
1050                                 drive->sect0 = 63;
1051                                 goto obsolete_option;
1052                         case -14: /* "scsi" */
1053                                 drive->scsi = 1;
1054                                 goto obsolete_option;
1055                         case 3: /* cyl,head,sect */
1056                                 drive->media    = ide_disk;
1057                                 drive->ready_stat = READY_STAT;
1058                                 drive->cyl      = drive->bios_cyl  = vals[0];
1059                                 drive->head     = drive->bios_head = vals[1];
1060                                 drive->sect     = drive->bios_sect = vals[2];
1061                                 drive->present  = 1;
1062                                 drive->forced_geom = 1;
1063                                 hwif->noprobe = 0;
1064                                 goto done;
1065                         default:
1066                                 goto bad_option;
1067                 }
1068         }
1069
1070         if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1071                 goto bad_option;
1072         /*
1073          * Look for bus speed option:  "idebus="
1074          */
1075         if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1076                 if (match_parm(&s[6], NULL, vals, 1) != 1)
1077                         goto bad_option;
1078                 if (vals[0] >= 20 && vals[0] <= 66) {
1079                         idebus_parameter = vals[0];
1080                 } else
1081                         printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1082                 goto done;
1083         }
1084         /*
1085          * Look for interface options:  "idex="
1086          */
1087         if (s[3] >= '0' && s[3] <= max_hwif) {
1088                 /*
1089                  * Be VERY CAREFUL changing this: note hardcoded indexes below
1090                  * (-8, -9, -10) are reserved to ease the hardcoding.
1091                  */
1092                 static const char *ide_words[] = {
1093                         "minus1", "serialize", "minus3", "minus4",
1094                         "reset", "minus6", "ata66", "minus8", "minus9",
1095                         "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1096                         "dtc2278", "umc8672", "ali14xx", NULL };
1097
1098                 hw = s[3] - '0';
1099                 hwif = &ide_hwifs[hw];
1100                 i = match_parm(&s[4], ide_words, vals, 3);
1101
1102                 /*
1103                  * Cryptic check to ensure chipset not already set for hwif.
1104                  * Note: we can't depend on hwif->chipset here.
1105                  */
1106                 if (i >= -18 && i <= -11) {
1107                         /* chipset already specified */
1108                         if (is_chipset_set)
1109                                 goto bad_option;
1110                         /* these drivers are for "ide0=" only */
1111                         if (hw != 0)
1112                                 goto bad_hwif;
1113                         is_chipset_set = 1;
1114                         printk("\n");
1115                 }
1116
1117                 switch (i) {
1118 #ifdef CONFIG_BLK_DEV_ALI14XX
1119                         case -17: /* "ali14xx" */
1120                                 probe_ali14xx = 1;
1121                                 goto obsolete_option;
1122 #endif
1123 #ifdef CONFIG_BLK_DEV_UMC8672
1124                         case -16: /* "umc8672" */
1125                                 probe_umc8672 = 1;
1126                                 goto obsolete_option;
1127 #endif
1128 #ifdef CONFIG_BLK_DEV_DTC2278
1129                         case -15: /* "dtc2278" */
1130                                 probe_dtc2278 = 1;
1131                                 goto obsolete_option;
1132 #endif
1133 #ifdef CONFIG_BLK_DEV_CMD640
1134                         case -14: /* "cmd640_vlb" */
1135                                 cmd640_vlb = 1;
1136                                 goto obsolete_option;
1137 #endif
1138 #ifdef CONFIG_BLK_DEV_HT6560B
1139                         case -13: /* "ht6560b" */
1140                                 probe_ht6560b = 1;
1141                                 goto obsolete_option;
1142 #endif
1143 #ifdef CONFIG_BLK_DEV_QD65XX
1144                         case -12: /* "qd65xx" */
1145                                 probe_qd65xx = 1;
1146                                 goto obsolete_option;
1147 #endif
1148 #ifdef CONFIG_BLK_DEV_4DRIVES
1149                         case -11: /* "four" drives on one set of ports */
1150                                 probe_4drives = 1;
1151                                 goto obsolete_option;
1152 #endif
1153                         case -10: /* minus10 */
1154                         case -9: /* minus9 */
1155                         case -8: /* minus8 */
1156                         case -6:
1157                         case -4:
1158                         case -3:
1159                                 goto bad_option;
1160                         case -7: /* ata66 */
1161 #ifdef CONFIG_BLK_DEV_IDEPCI
1162                                 /*
1163                                  * Use ATA_CBL_PATA40_SHORT so drive side
1164                                  * cable detection is also overriden.
1165                                  */
1166                                 hwif->cbl = ATA_CBL_PATA40_SHORT;
1167                                 goto obsolete_option;
1168 #else
1169                                 goto bad_hwif;
1170 #endif
1171                         case -5: /* "reset" */
1172                                 hwif->reset = 1;
1173                                 goto obsolete_option;
1174                         case -2: /* "serialize" */
1175                                 hwif->mate = &ide_hwifs[hw^1];
1176                                 hwif->mate->mate = hwif;
1177                                 hwif->serialized = hwif->mate->serialized = 1;
1178                                 goto obsolete_option;
1179
1180                         case -1:
1181                         case 0:
1182                         case 1:
1183                         case 2:
1184                         case 3:
1185                                 goto bad_option;
1186                         default:
1187                                 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
1188                                 return 1;
1189                 }
1190         }
1191 bad_option:
1192         printk(" -- BAD OPTION\n");
1193         return 1;
1194 obsolete_option:
1195         printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
1196         return 1;
1197 bad_hwif:
1198         printk("-- NOT SUPPORTED ON ide%d", hw);
1199 done:
1200         printk("\n");
1201         return 1;
1202 }
1203
1204 EXPORT_SYMBOL(ide_lock);
1205
1206 static int ide_bus_match(struct device *dev, struct device_driver *drv)
1207 {
1208         return 1;
1209 }
1210
1211 static char *media_string(ide_drive_t *drive)
1212 {
1213         switch (drive->media) {
1214         case ide_disk:
1215                 return "disk";
1216         case ide_cdrom:
1217                 return "cdrom";
1218         case ide_tape:
1219                 return "tape";
1220         case ide_floppy:
1221                 return "floppy";
1222         case ide_optical:
1223                 return "optical";
1224         default:
1225                 return "UNKNOWN";
1226         }
1227 }
1228
1229 static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
1230 {
1231         ide_drive_t *drive = to_ide_device(dev);
1232         return sprintf(buf, "%s\n", media_string(drive));
1233 }
1234
1235 static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
1236 {
1237         ide_drive_t *drive = to_ide_device(dev);
1238         return sprintf(buf, "%s\n", drive->name);
1239 }
1240
1241 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
1242 {
1243         ide_drive_t *drive = to_ide_device(dev);
1244         return sprintf(buf, "ide:m-%s\n", media_string(drive));
1245 }
1246
1247 static ssize_t model_show(struct device *dev, struct device_attribute *attr,
1248                           char *buf)
1249 {
1250         ide_drive_t *drive = to_ide_device(dev);
1251         return sprintf(buf, "%s\n", drive->id->model);
1252 }
1253
1254 static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
1255                              char *buf)
1256 {
1257         ide_drive_t *drive = to_ide_device(dev);
1258         return sprintf(buf, "%s\n", drive->id->fw_rev);
1259 }
1260
1261 static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
1262                            char *buf)
1263 {
1264         ide_drive_t *drive = to_ide_device(dev);
1265         return sprintf(buf, "%s\n", drive->id->serial_no);
1266 }
1267
1268 static struct device_attribute ide_dev_attrs[] = {
1269         __ATTR_RO(media),
1270         __ATTR_RO(drivename),
1271         __ATTR_RO(modalias),
1272         __ATTR_RO(model),
1273         __ATTR_RO(firmware),
1274         __ATTR(serial, 0400, serial_show, NULL),
1275         __ATTR_NULL
1276 };
1277
1278 static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
1279 {
1280         ide_drive_t *drive = to_ide_device(dev);
1281
1282         add_uevent_var(env, "MEDIA=%s", media_string(drive));
1283         add_uevent_var(env, "DRIVENAME=%s", drive->name);
1284         add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
1285         return 0;
1286 }
1287
1288 static int generic_ide_probe(struct device *dev)
1289 {
1290         ide_drive_t *drive = to_ide_device(dev);
1291         ide_driver_t *drv = to_ide_driver(dev->driver);
1292
1293         return drv->probe ? drv->probe(drive) : -ENODEV;
1294 }
1295
1296 static int generic_ide_remove(struct device *dev)
1297 {
1298         ide_drive_t *drive = to_ide_device(dev);
1299         ide_driver_t *drv = to_ide_driver(dev->driver);
1300
1301         if (drv->remove)
1302                 drv->remove(drive);
1303
1304         return 0;
1305 }
1306
1307 static void generic_ide_shutdown(struct device *dev)
1308 {
1309         ide_drive_t *drive = to_ide_device(dev);
1310         ide_driver_t *drv = to_ide_driver(dev->driver);
1311
1312         if (dev->driver && drv->shutdown)
1313                 drv->shutdown(drive);
1314 }
1315
1316 struct bus_type ide_bus_type = {
1317         .name           = "ide",
1318         .match          = ide_bus_match,
1319         .uevent         = ide_uevent,
1320         .probe          = generic_ide_probe,
1321         .remove         = generic_ide_remove,
1322         .shutdown       = generic_ide_shutdown,
1323         .dev_attrs      = ide_dev_attrs,
1324         .suspend        = generic_ide_suspend,
1325         .resume         = generic_ide_resume,
1326 };
1327
1328 EXPORT_SYMBOL_GPL(ide_bus_type);
1329
1330 static void ide_port_class_release(struct device *portdev)
1331 {
1332         ide_hwif_t *hwif = dev_get_drvdata(portdev);
1333
1334         put_device(&hwif->gendev);
1335 }
1336
1337 /*
1338  * This is gets invoked once during initialization, to set *everything* up
1339  */
1340 static int __init ide_init(void)
1341 {
1342         int ret;
1343
1344         printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
1345         system_bus_speed = ide_system_bus_speed();
1346
1347         printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
1348                          "for PIO modes%s\n", system_bus_speed,
1349                         idebus_parameter ? "" : "; override with idebus=xx");
1350
1351         ret = bus_register(&ide_bus_type);
1352         if (ret < 0) {
1353                 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
1354                 return ret;
1355         }
1356
1357         ide_port_class = class_create(THIS_MODULE, "ide_port");
1358         if (IS_ERR(ide_port_class)) {
1359                 ret = PTR_ERR(ide_port_class);
1360                 goto out_port_class;
1361         }
1362         ide_port_class->dev_release = ide_port_class_release;
1363
1364         init_ide_data();
1365
1366         proc_ide_create();
1367
1368         return 0;
1369
1370 out_port_class:
1371         bus_unregister(&ide_bus_type);
1372
1373         return ret;
1374 }
1375
1376 #ifdef MODULE
1377 static char *options = NULL;
1378 module_param(options, charp, 0);
1379 MODULE_LICENSE("GPL");
1380
1381 static void __init parse_options (char *line)
1382 {
1383         char *next = line;
1384
1385         if (line == NULL || !*line)
1386                 return;
1387         while ((line = next) != NULL) {
1388                 if ((next = strchr(line,' ')) != NULL)
1389                         *next++ = 0;
1390                 if (!ide_setup(line))
1391                         printk (KERN_INFO "Unknown option '%s'\n", line);
1392         }
1393 }
1394
1395 int __init init_module (void)
1396 {
1397         parse_options(options);
1398         return ide_init();
1399 }
1400
1401 void __exit cleanup_module (void)
1402 {
1403         int index;
1404
1405         for (index = 0; index < MAX_HWIFS; ++index)
1406                 ide_unregister(index);
1407
1408         proc_ide_destroy();
1409
1410         class_destroy(ide_port_class);
1411
1412         bus_unregister(&ide_bus_type);
1413 }
1414
1415 #else /* !MODULE */
1416
1417 __setup("", ide_setup);
1418
1419 module_init(ide_init);
1420
1421 #endif /* MODULE */