]> err.no Git - linux-2.6/blobdiff - drivers/ide/ide.c
Rename WARN() to WARNING() to clear the namespace
[linux-2.6] / drivers / ide / ide.c
index e8c88ff2f6b6391406f01c175ec6c32c8181d39d..772451600e4d96064b57f8732a7579481ee2b3a1 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 1994-1998        Linus Torvalds & authors (see below)
- *  Copyrifht (C) 2003-2005, 2007   Bartlomiej Zolnierkiewicz
+ *  Copyright (C) 2003-2005, 2007   Bartlomiej Zolnierkiewicz
  */
 
 /*
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/kernel.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/major.h>
 #include <linux/errno.h>
 #include <linux/genhd.h>
-#include <linux/blkpg.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/pci.h>
-#include <linux/delay.h>
 #include <linux/ide.h>
 #include <linux/completion.h>
-#include <linux/reboot.h>
-#include <linux/cdrom.h>
-#include <linux/seq_file.h>
 #include <linux/device.h>
-#include <linux/bitops.h>
-
-#include <asm/byteorder.h>
-#include <asm/irq.h>
-#include <asm/uaccess.h>
-#include <asm/io.h>
 
 
 /* default maximum number of failures */
@@ -87,11 +74,9 @@ static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
                                        IDE8_MAJOR, IDE9_MAJOR };
 
 DEFINE_MUTEX(ide_cfg_mtx);
- __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
-
-int noautodma = 0;
 
-ide_hwif_t ide_hwifs[MAX_HWIFS];       /* master data repository */
+__cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
+EXPORT_SYMBOL(ide_lock);
 
 static void ide_port_init_devices_data(ide_hwif_t *);
 
@@ -116,12 +101,10 @@ void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
 
        init_completion(&hwif->gendev_rel_comp);
 
-       default_hwif_iops(hwif);
-       default_hwif_transport(hwif);
+       hwif->tp_ops = &default_tp_ops;
 
        ide_port_init_devices_data(hwif);
 }
-EXPORT_SYMBOL_GPL(ide_init_port_data);
 
 static void ide_port_init_devices_data(ide_hwif_t *hwif)
 {
@@ -136,7 +119,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
                drive->media                    = ide_disk;
                drive->select.all               = (unit<<4)|0xa0;
                drive->hwif                     = hwif;
-               drive->ctl                      = 0x08;
                drive->ready_stat               = READY_STAT;
                drive->bad_wstat                = BAD_W_STAT;
                drive->special.b.recalibrate    = 1;
@@ -151,53 +133,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
        }
 }
 
-static void __init init_ide_data (void)
-{
-       unsigned int index;
-
-       /* Initialise all interface structures */
-       for (index = 0; index < MAX_HWIFS; ++index) {
-               ide_hwif_t *hwif = &ide_hwifs[index];
-
-               ide_init_port_data(hwif, index);
-       }
-}
-
-void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
-{
-       ide_hwgroup_t *hwgroup = hwif->hwgroup;
-
-       spin_lock_irq(&ide_lock);
-       /*
-        * Remove us from the hwgroup, and free
-        * the hwgroup if we were the only member
-        */
-       if (hwif->next == hwif) {
-               BUG_ON(hwgroup->hwif != hwif);
-               kfree(hwgroup);
-       } else {
-               /* There is another interface in hwgroup.
-                * Unlink us, and set hwgroup->drive and ->hwif to
-                * something sane.
-                */
-               ide_hwif_t *g = hwgroup->hwif;
-
-               while (g->next != hwif)
-                       g = g->next;
-               g->next = hwif->next;
-               if (hwgroup->hwif == hwif) {
-                       /* Chose a random hwif for hwgroup->hwif.
-                        * It's guaranteed that there are no drives
-                        * left in the hwgroup.
-                        */
-                       BUG_ON(hwgroup->drive != NULL);
-                       hwgroup->hwif = g;
-               }
-               BUG_ON(hwgroup->hwif == hwif);
-       }
-       spin_unlock_irq(&ide_lock);
-}
-
 /* Called with ide_lock held. */
 static void __ide_port_unregister_devices(ide_hwif_t *hwif)
 {
@@ -298,25 +233,19 @@ void ide_unregister(ide_hwif_t *hwif)
        if (hwif->dma_base)
                ide_release_dma_engine(hwif);
 
-       spin_lock_irq(&ide_lock);
-       /* restore hwif data to pristine status */
-       ide_init_port_data(hwif, hwif->index);
-       spin_unlock_irq(&ide_lock);
-
        mutex_unlock(&ide_cfg_mtx);
 }
 
-EXPORT_SYMBOL(ide_unregister);
-
 void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
 {
        memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports));
        hwif->irq = hw->irq;
        hwif->chipset = hw->chipset;
-       hwif->gendev.parent = hw->dev;
+       hwif->dev = hw->dev;
+       hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
        hwif->ack_intr = hw->ack_intr;
+       hwif->config_data = hw->config;
 }
-EXPORT_SYMBOL_GPL(ide_init_port_hw);
 
 /*
  *     Locks for IDE setting functionality
@@ -557,6 +486,22 @@ static int generic_ide_resume(struct device *dev)
        return err;
 }
 
+static int generic_drive_reset(ide_drive_t *drive)
+{
+       struct request *rq;
+       int ret = 0;
+
+       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
+       rq->cmd_type = REQ_TYPE_SPECIAL;
+       rq->cmd_len = 1;
+       rq->cmd[0] = REQ_DRIVE_RESET;
+       rq->cmd_flags |= REQ_SOFTBARRIER;
+       if (blk_execute_rq(drive->queue, NULL, rq, 1))
+               ret = rq->errors;
+       blk_put_request(rq);
+       return ret;
+}
+
 int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
                        unsigned int cmd, unsigned long arg)
 {
@@ -631,33 +576,8 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
                        if (!capable(CAP_SYS_ADMIN))
                                return -EACCES;
 
-                       /*
-                        *      Abort the current command on the
-                        *      group if there is one, taking
-                        *      care not to allow anything else
-                        *      to be queued and to die on the
-                        *      spot if we miss one somehow
-                        */
-
-                       spin_lock_irqsave(&ide_lock, flags);
-
-                       if (HWGROUP(drive)->resetting) {
-                               spin_unlock_irqrestore(&ide_lock, flags);
-                               return -EBUSY;
-                       }
-
-                       ide_abort(drive, "drive reset");
+                       return generic_drive_reset(drive);
 
-                       BUG_ON(HWGROUP(drive)->handler);
-
-                       /* Ensure nothing gets queued after we
-                          drop the lock. Reset will clear the busy */
-
-                       HWGROUP(drive)->busy = 1;
-                       spin_unlock_irqrestore(&ide_lock, flags);
-                       (void) ide_do_reset(drive);
-
-                       return 0;
                case HDIO_GET_BUSSTATE:
                        if (!capable(CAP_SYS_ADMIN))
                                return -EACCES;
@@ -698,58 +618,52 @@ set_val:
 
 EXPORT_SYMBOL(generic_ide_ioctl);
 
-/*
- * ide_setup() gets called VERY EARLY during initialization,
- * to handle kernel "command line" strings beginning with "ide".
+/**
+ * ide_device_get      -       get an additional reference to a ide_drive_t
+ * @drive:     device to get a reference to
  *
- * Remember to update Documentation/ide/ide.txt if you change something here.
+ * Gets a reference to the ide_drive_t and increments the use count of the
+ * underlying LLDD module.
  */
-static int __init ide_setup(char *s)
+int ide_device_get(ide_drive_t *drive)
 {
-       printk(KERN_INFO "ide_setup: %s", s);
-
-#ifdef CONFIG_BLK_DEV_IDEDOUBLER
-       if (!strcmp(s, "ide=doubler")) {
-               extern int ide_doubler;
+       struct device *host_dev;
+       struct module *module;
 
-               printk(" : Enabled support for IDE doublers\n");
-               ide_doubler = 1;
-               goto obsolete_option;
-       }
-#endif /* CONFIG_BLK_DEV_IDEDOUBLER */
+       if (!get_device(&drive->gendev))
+               return -ENXIO;
 
-       if (!strcmp(s, "ide=nodma")) {
-               printk(" : Prevented DMA\n");
-               noautodma = 1;
-               goto obsolete_option;
-       }
+       host_dev = drive->hwif->host->dev[0];
+       module = host_dev ? host_dev->driver->owner : NULL;
 
-#ifdef CONFIG_BLK_DEV_IDEACPI
-       if (!strcmp(s, "ide=noacpi")) {
-               //printk(" : Disable IDE ACPI support.\n");
-               ide_noacpi = 1;
-               goto obsolete_option;
+       if (module && !try_module_get(module)) {
+               put_device(&drive->gendev);
+               return -ENXIO;
        }
-       if (!strcmp(s, "ide=acpigtf")) {
-               //printk(" : Enable IDE ACPI _GTF support.\n");
-               ide_acpigtf = 1;
-               goto obsolete_option;
-       }
-       if (!strcmp(s, "ide=acpionboot")) {
-               //printk(" : Call IDE ACPI methods on boot.\n");
-               ide_acpionboot = 1;
-               goto obsolete_option;
-       }
-#endif /* CONFIG_BLK_DEV_IDEACPI */
 
-       printk(" -- BAD OPTION\n");
-       return 1;
-obsolete_option:
-       printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
-       return 1;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(ide_device_get);
 
-EXPORT_SYMBOL(ide_lock);
+/**
+ * ide_device_put      -       release a reference to a ide_drive_t
+ * @drive:     device to release a reference on
+ *
+ * Release a reference to the ide_drive_t and decrements the use count of
+ * the underlying LLDD module.
+ */
+void ide_device_put(ide_drive_t *drive)
+{
+#ifdef CONFIG_MODULE_UNLOAD
+       struct device *host_dev = drive->hwif->host->dev[0];
+       struct module *module = host_dev ? host_dev->driver->owner : NULL;
+
+       if (module)
+               module_put(module);
+#endif
+       put_device(&drive->gendev);
+}
+EXPORT_SYMBOL_GPL(ide_device_put);
 
 static int ide_bus_match(struct device *dev, struct device_driver *drv)
 {
@@ -1075,8 +989,6 @@ static int __init ide_init(void)
                goto out_port_class;
        }
 
-       init_ide_data();
-
        proc_ide_create();
 
        return 0;
@@ -1087,32 +999,7 @@ out_port_class:
        return ret;
 }
 
-#ifdef MODULE
-static char *options = NULL;
-module_param(options, charp, 0);
-MODULE_LICENSE("GPL");
-
-static void __init parse_options (char *line)
-{
-       char *next = line;
-
-       if (line == NULL || !*line)
-               return;
-       while ((line = next) != NULL) {
-               if ((next = strchr(line,' ')) != NULL)
-                       *next++ = 0;
-               if (!ide_setup(line))
-                       printk (KERN_INFO "Unknown option '%s'\n", line);
-       }
-}
-
-int __init init_module (void)
-{
-       parse_options(options);
-       return ide_init();
-}
-
-void __exit cleanup_module (void)
+static void __exit ide_exit(void)
 {
        proc_ide_destroy();
 
@@ -1121,10 +1008,7 @@ void __exit cleanup_module (void)
        bus_unregister(&ide_bus_type);
 }
 
-#else /* !MODULE */
-
-__setup("", ide_setup);
-
 module_init(ide_init);
+module_exit(ide_exit);
 
-#endif /* MODULE */
+MODULE_LICENSE("GPL");