]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide.c
ide: remove read-only ->atapi_overlap field from ide_drive_t
[linux-2.6-omap-h63xx.git] / drivers / ide / ide.c
index d4a6b102a77227d29b4052281704f4053700156d..5b3bfc78dcddc841ef79dd4758d73e004636e777 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
  */
 
 /*
@@ -44,8 +44,6 @@
  *  inspiration from lots of linux users, esp.  hamish@zot.apana.org.au
  */
 
-#define _IDE_C                 /* Tell ide.h it's really us */
-
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/string.h>
@@ -58,6 +56,7 @@
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
+#include <linux/hdreg.h>
 #include <linux/completion.h>
 #include <linux/device.h>
 
@@ -101,8 +100,7 @@ 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);
 }
@@ -120,7 +118,7 @@ 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->ready_stat               = READY_STAT;
+               drive->ready_stat               = ATA_DRDY;
                drive->bad_wstat                = BAD_W_STAT;
                drive->special.b.recalibrate    = 1;
                drive->special.b.set_geometry   = 1;
@@ -134,41 +132,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
        }
 }
 
-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)
 {
@@ -269,16 +232,9 @@ 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));
@@ -287,8 +243,8 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
        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
@@ -331,6 +287,8 @@ int ide_spin_wait_hwgroup (ide_drive_t *drive)
 
 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
 
+ide_devset_get(io_32bit, io_32bit);
+
 int set_io_32bit(ide_drive_t *drive, int arg)
 {
        if (drive->no_io_32bit)
@@ -349,7 +307,9 @@ int set_io_32bit(ide_drive_t *drive, int arg)
        return 0;
 }
 
-static int set_ksettings(ide_drive_t *drive, int arg)
+ide_devset_get(ksettings, keep_settings);
+
+int set_ksettings(ide_drive_t *drive, int arg)
 {
        if (arg < 0 || arg > 1)
                return -EINVAL;
@@ -362,6 +322,8 @@ static int set_ksettings(ide_drive_t *drive, int arg)
        return 0;
 }
 
+ide_devset_get(using_dma, using_dma);
+
 int set_using_dma(ide_drive_t *drive, int arg)
 {
 #ifdef CONFIG_BLK_DEV_IDEDMA
@@ -371,7 +333,7 @@ int set_using_dma(ide_drive_t *drive, int arg)
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
-       if (!drive->id || !(drive->id->capability & 1))
+       if (ata_id_has_dma(drive->id) == 0)
                goto out;
 
        if (hwif->dma_ops == NULL)
@@ -438,7 +400,9 @@ int set_pio_mode(ide_drive_t *drive, int arg)
        return 0;
 }
 
-static int set_unmaskirq(ide_drive_t *drive, int arg)
+ide_devset_get(unmaskirq, unmask);
+
+int set_unmaskirq(ide_drive_t *drive, int arg)
 {
        if (drive->no_unmask)
                return -EPERM;
@@ -545,20 +509,67 @@ static int generic_drive_reset(ide_drive_t *drive)
        return ret;
 }
 
+static inline void ide_id_to_hd_driveid(u16 *id)
+{
+#ifdef __BIG_ENDIAN
+       /* accessed in struct hd_driveid as 8-bit values */
+       id[ATA_ID_MAX_MULTSECT]  = __cpu_to_le16(id[ATA_ID_MAX_MULTSECT]);
+       id[ATA_ID_CAPABILITY]    = __cpu_to_le16(id[ATA_ID_CAPABILITY]);
+       id[ATA_ID_OLD_PIO_MODES] = __cpu_to_le16(id[ATA_ID_OLD_PIO_MODES]);
+       id[ATA_ID_OLD_DMA_MODES] = __cpu_to_le16(id[ATA_ID_OLD_DMA_MODES]);
+       id[ATA_ID_MULTSECT]      = __cpu_to_le16(id[ATA_ID_MULTSECT]);
+
+       /* as 32-bit values */
+       *(u32 *)&id[ATA_ID_LBA_CAPACITY] = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
+       *(u32 *)&id[ATA_ID_SPG]          = ata_id_u32(id, ATA_ID_SPG);
+
+       /* as 64-bit value */
+       *(u64 *)&id[ATA_ID_LBA_CAPACITY_2] =
+               ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
+#endif
+}
+
+static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
+                                 unsigned long arg)
+{
+       u16 *id = NULL;
+       int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
+       int rc = 0;
+
+       if (drive->id_read == 0) {
+               rc = -ENOMSG;
+               goto out;
+       }
+
+       id = kmalloc(size, GFP_KERNEL);
+       if (id == NULL) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       memcpy(id, drive->id, size);
+       ide_id_to_hd_driveid(id);
+
+       if (copy_to_user((void __user *)arg, id, size))
+               rc = -EFAULT;
+
+       kfree(id);
+out:
+       return rc;
+}
+
 int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
                        unsigned int cmd, unsigned long arg)
 {
        unsigned long flags;
        ide_driver_t *drv;
-       void __user *p = (void __user *)arg;
-       int err = 0, (*setfunc)(ide_drive_t *, int);
-       u8 *val;
+       int err = 0, (*getfunc)(ide_drive_t *), (*setfunc)(ide_drive_t *, int);
 
        switch (cmd) {
-       case HDIO_GET_32BIT:        val = &drive->io_32bit;      goto read_val;
-       case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
-       case HDIO_GET_UNMASKINTR:   val = &drive->unmask;        goto read_val;
-       case HDIO_GET_DMA:          val = &drive->using_dma;     goto read_val;
+       case HDIO_GET_32BIT:        getfunc = get_io_32bit;      goto read_val;
+       case HDIO_GET_KEEPSETTINGS: getfunc = get_ksettings;     goto read_val;
+       case HDIO_GET_UNMASKINTR:   getfunc = get_unmaskirq;     goto read_val;
+       case HDIO_GET_DMA:          getfunc = get_using_dma;     goto read_val;
        case HDIO_SET_32BIT:        setfunc = set_io_32bit;      goto set_val;
        case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings;     goto set_val;
        case HDIO_SET_PIO_MODE:     setfunc = set_pio_mode;      goto set_val;
@@ -571,15 +582,9 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
                case HDIO_GET_IDENTITY:
                        if (bdev != bdev->bd_contains)
                                return -EINVAL;
-                       if (drive->id_read == 0)
-                               return -ENOMSG;
-                       if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
-                               return -EFAULT;
-                       return 0;
-
+                       return ide_get_identity_ioctl(drive, cmd, arg);
                case HDIO_GET_NICE:
                        return put_user(drive->dsc_overlap      <<      IDE_NICE_DSC_OVERLAP    |
-                                       drive->atapi_overlap    <<      IDE_NICE_ATAPI_OVERLAP  |
                                        drive->nice1 << IDE_NICE_1,
                                        (long __user *) arg);
 #ifdef CONFIG_IDE_TASK_IOCTL
@@ -639,7 +644,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
 read_val:
        mutex_lock(&ide_setting_mtx);
        spin_lock_irqsave(&ide_lock, flags);
-       err = *val;
+       err = getfunc(drive);
        spin_unlock_irqrestore(&ide_lock, flags);
        mutex_unlock(&ide_setting_mtx);
        return err >= 0 ? put_user(err, (long __user *)arg) : err;
@@ -661,6 +666,53 @@ set_val:
 
 EXPORT_SYMBOL(generic_ide_ioctl);
 
+/**
+ * ide_device_get      -       get an additional reference to a ide_drive_t
+ * @drive:     device to get a reference to
+ *
+ * Gets a reference to the ide_drive_t and increments the use count of the
+ * underlying LLDD module.
+ */
+int ide_device_get(ide_drive_t *drive)
+{
+       struct device *host_dev;
+       struct module *module;
+
+       if (!get_device(&drive->gendev))
+               return -ENXIO;
+
+       host_dev = drive->hwif->host->dev[0];
+       module = host_dev ? host_dev->driver->owner : NULL;
+
+       if (module && !try_module_get(module)) {
+               put_device(&drive->gendev);
+               return -ENXIO;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ide_device_get);
+
+/**
+ * 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)
 {
        return 1;
@@ -706,21 +758,21 @@ static ssize_t model_show(struct device *dev, struct device_attribute *attr,
                          char *buf)
 {
        ide_drive_t *drive = to_ide_device(dev);
-       return sprintf(buf, "%s\n", drive->id->model);
+       return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
 }
 
 static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
                             char *buf)
 {
        ide_drive_t *drive = to_ide_device(dev);
-       return sprintf(buf, "%s\n", drive->id->fw_rev);
+       return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
 }
 
 static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
                           char *buf)
 {
        ide_drive_t *drive = to_ide_device(dev);
-       return sprintf(buf, "%s\n", drive->id->serial_no);
+       return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
 }
 
 static struct device_attribute ide_dev_attrs[] = {
@@ -837,7 +889,7 @@ MODULE_PARM_DESC(noprobe, "skip probing for a device");
 static unsigned int ide_nowerr;
 
 module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0);
-MODULE_PARM_DESC(nowerr, "ignore the WRERR_STAT bit for a device");
+MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
 
 static unsigned int ide_cdroms;
 
@@ -902,7 +954,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
                drive->noprobe = 1;
        }
        if (ide_nowerr & (1 << i)) {
-               printk(KERN_INFO "ide: ignoring the WRERR_STAT bit for %s\n",
+               printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
                                 drive->name);
                drive->bad_wstat = BAD_R_STAT;
        }
@@ -923,7 +975,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
                                 drive->cyl, drive->head, drive->sect);
                drive->present = 1;
                drive->media = ide_disk;
-               drive->ready_stat = READY_STAT;
+               drive->ready_stat = ATA_DRDY;
        }
 }