]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide.c
ide: move ioctls handling to ide-ioctls.c
[linux-2.6-omap-h63xx.git] / drivers / ide / ide.c
index 60f0ca66aa93735d68f27478888cf01132457d47..349d7fa7558532f4cf6f378ec92619e443b91b54 100644 (file)
@@ -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>
 
@@ -97,8 +96,6 @@ void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
        hwif->name[2]   = 'e';
        hwif->name[3]   = '0' + index;
 
-       hwif->bus_state = BUSSTATE_ON;
-
        init_completion(&hwif->gendev_rel_comp);
 
        hwif->tp_ops = &default_tp_ops;
@@ -119,7 +116,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;
@@ -253,8 +250,6 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
 
 DEFINE_MUTEX(ide_setting_mtx);
 
-EXPORT_SYMBOL_GPL(ide_setting_mtx);
-
 /**
  *     ide_spin_wait_hwgroup   -       wait for group
  *     @drive: drive in the group
@@ -288,6 +283,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)
@@ -306,7 +303,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;
@@ -319,6 +318,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
@@ -328,7 +329,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)
@@ -395,7 +396,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;
@@ -486,137 +489,52 @@ static int generic_ide_resume(struct device *dev)
        return err;
 }
 
-static int generic_drive_reset(ide_drive_t *drive)
+/**
+ * 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 request *rq;
-       int ret = 0;
+       struct device *host_dev;
+       struct module *module;
 
-       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;
-}
+       if (!get_device(&drive->gendev))
+               return -ENXIO;
 
-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;
-
-       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_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;
-       case HDIO_SET_UNMASKINTR:   setfunc = set_unmaskirq;     goto set_val;
-       case HDIO_SET_DMA:          setfunc = set_using_dma;     goto set_val;
-       }
+       host_dev = drive->hwif->host->dev[0];
+       module = host_dev ? host_dev->driver->owner : NULL;
 
-       switch (cmd) {
-               case HDIO_OBSOLETE_IDENTITY:
-               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;
-
-               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
-               case HDIO_DRIVE_TASKFILE:
-                       if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
-                               return -EACCES;
-                       switch(drive->media) {
-                               case ide_disk:
-                                       return ide_taskfile_ioctl(drive, cmd, arg);
-                               default:
-                                       return -ENOMSG;
-                       }
-#endif /* CONFIG_IDE_TASK_IOCTL */
-
-               case HDIO_DRIVE_CMD:
-                       if (!capable(CAP_SYS_RAWIO))
-                               return -EACCES;
-                       return ide_cmd_ioctl(drive, cmd, arg);
-
-               case HDIO_DRIVE_TASK:
-                       if (!capable(CAP_SYS_RAWIO))
-                               return -EACCES;
-                       return ide_task_ioctl(drive, cmd, arg);
-               case HDIO_SET_NICE:
-                       if (!capable(CAP_SYS_ADMIN)) return -EACCES;
-                       if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
-                               return -EPERM;
-                       drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
-                       drv = *(ide_driver_t **)bdev->bd_disk->private_data;
-                       if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
-                               drive->dsc_overlap = 0;
-                               return -EPERM;
-                       }
-                       drive->nice1 = (arg >> IDE_NICE_1) & 1;
-                       return 0;
-               case HDIO_DRIVE_RESET:
-                       if (!capable(CAP_SYS_ADMIN))
-                               return -EACCES;
-
-                       return generic_drive_reset(drive);
-
-               case HDIO_GET_BUSSTATE:
-                       if (!capable(CAP_SYS_ADMIN))
-                               return -EACCES;
-                       if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
-                               return -EFAULT;
-                       return 0;
-
-               case HDIO_SET_BUSSTATE:
-                       if (!capable(CAP_SYS_ADMIN))
-                               return -EACCES;
-                       return -EOPNOTSUPP;
-               default:
-                       return -EINVAL;
+       if (module && !try_module_get(module)) {
+               put_device(&drive->gendev);
+               return -ENXIO;
        }
 
-read_val:
-       mutex_lock(&ide_setting_mtx);
-       spin_lock_irqsave(&ide_lock, flags);
-       err = *val;
-       spin_unlock_irqrestore(&ide_lock, flags);
-       mutex_unlock(&ide_setting_mtx);
-       return err >= 0 ? put_user(err, (long __user *)arg) : err;
-
-set_val:
-       if (bdev != bdev->bd_contains)
-               err = -EINVAL;
-       else {
-               if (!capable(CAP_SYS_ADMIN))
-                       err = -EACCES;
-               else {
-                       mutex_lock(&ide_setting_mtx);
-                       err = setfunc(drive, arg);
-                       mutex_unlock(&ide_setting_mtx);
-               }
-       }
-       return err;
+       return 0;
 }
+EXPORT_SYMBOL_GPL(ide_device_get);
 
-EXPORT_SYMBOL(generic_ide_ioctl);
+/**
+ * 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)
 {
@@ -663,21 +581,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[] = {
@@ -794,7 +712,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;
 
@@ -859,7 +777,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;
        }
@@ -880,7 +798,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;
        }
 }