]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide.c
ide: add device flags
[linux-2.6-omap-h63xx.git] / drivers / ide / ide.c
index f78e789ea5f78eb6f9f9e1daff2715a493e18964..78776bbb537e01aa03757adee980886f957c6a0f 100644 (file)
@@ -138,7 +138,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
 
-               if (drive->present) {
+               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
                        spin_unlock_irq(&ide_lock);
                        device_unregister(&drive->gendev);
                        wait_for_completion(&drive->gendev_rel_comp);
@@ -250,82 +250,41 @@ 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
- *
- *     Wait for an IDE device group to go non busy and then return
- *     holding the ide_lock which guards the hwgroup->busy status
- *     and right to use it.
- */
-
-int ide_spin_wait_hwgroup (ide_drive_t *drive)
-{
-       ide_hwgroup_t *hwgroup = HWGROUP(drive);
-       unsigned long timeout = jiffies + (3 * HZ);
-
-       spin_lock_irq(&ide_lock);
-
-       while (hwgroup->busy) {
-               unsigned long lflags;
-               spin_unlock_irq(&ide_lock);
-               local_irq_set(lflags);
-               if (time_after(jiffies, timeout)) {
-                       local_irq_restore(lflags);
-                       printk(KERN_ERR "%s: channel busy\n", drive->name);
-                       return -EBUSY;
-               }
-               local_irq_restore(lflags);
-               spin_lock_irq(&ide_lock);
-       }
-       return 0;
-}
-
-EXPORT_SYMBOL(ide_spin_wait_hwgroup);
-
 ide_devset_get(io_32bit, io_32bit);
 
-int set_io_32bit(ide_drive_t *drive, int arg)
+static int set_io_32bit(ide_drive_t *drive, int arg)
 {
-       if (drive->no_io_32bit)
+       if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
                return -EPERM;
 
        if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
                return -EINVAL;
 
-       if (ide_spin_wait_hwgroup(drive))
-               return -EBUSY;
-
        drive->io_32bit = arg;
 
-       spin_unlock_irq(&ide_lock);
-
        return 0;
 }
 
-ide_devset_get(ksettings, keep_settings);
+ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
 
-int set_ksettings(ide_drive_t *drive, int arg)
+static int set_ksettings(ide_drive_t *drive, int arg)
 {
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
-       if (ide_spin_wait_hwgroup(drive))
-               return -EBUSY;
-       drive->keep_settings = arg;
-       spin_unlock_irq(&ide_lock);
+       if (arg)
+               drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
 
        return 0;
 }
 
-ide_devset_get(using_dma, using_dma);
+ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
 
-int set_using_dma(ide_drive_t *drive, int arg)
+static int set_using_dma(ide_drive_t *drive, int arg)
 {
 #ifdef CONFIG_BLK_DEV_IDEDMA
-       ide_hwif_t *hwif = drive->hwif;
        int err = -EPERM;
 
        if (arg < 0 || arg > 1)
@@ -334,17 +293,8 @@ int set_using_dma(ide_drive_t *drive, int arg)
        if (ata_id_has_dma(drive->id) == 0)
                goto out;
 
-       if (hwif->dma_ops == NULL)
-               goto out;
-
-       err = -EBUSY;
-       if (ide_spin_wait_hwgroup(drive))
+       if (drive->hwif->dma_ops == NULL)
                goto out;
-       /*
-        * set ->busy flag, unlock and let it ride
-        */
-       hwif->hwgroup->busy = 1;
-       spin_unlock_irq(&ide_lock);
 
        err = 0;
 
@@ -354,12 +304,6 @@ int set_using_dma(ide_drive_t *drive, int arg)
        } else
                ide_dma_off(drive);
 
-       /*
-        * lock, clear ->busy flag and unlock before leaving
-        */
-       spin_lock_irq(&ide_lock);
-       hwif->hwgroup->busy = 0;
-       spin_unlock_irq(&ide_lock);
 out:
        return err;
 #else
@@ -370,7 +314,7 @@ out:
 #endif
 }
 
-int set_pio_mode(ide_drive_t *drive, int arg)
+static int set_pio_mode(ide_drive_t *drive, int arg)
 {
        struct request *rq;
        ide_hwif_t *hwif = drive->hwif;
@@ -398,35 +342,44 @@ int set_pio_mode(ide_drive_t *drive, int arg)
        return 0;
 }
 
-ide_devset_get(unmaskirq, unmask);
+ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
 
-int set_unmaskirq(ide_drive_t *drive, int arg)
+static int set_unmaskirq(ide_drive_t *drive, int arg)
 {
-       if (drive->no_unmask)
+       if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
                return -EPERM;
 
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
-       if (ide_spin_wait_hwgroup(drive))
-               return -EBUSY;
-       drive->unmask = arg;
-       spin_unlock_irq(&ide_lock);
+       if (arg)
+               drive->dev_flags |= IDE_DFLAG_UNMASK;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_UNMASK;
 
        return 0;
 }
 
+#define ide_gen_devset_rw(_name, _func) \
+__IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func)
+
+ide_gen_devset_rw(io_32bit, io_32bit);
+ide_gen_devset_rw(keepsettings, ksettings);
+ide_gen_devset_rw(unmaskirq, unmaskirq);
+ide_gen_devset_rw(using_dma, using_dma);
+__IDE_DEVSET(pio_mode, 0, NULL, set_pio_mode);
+
 static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
 {
-       ide_drive_t *drive = dev->driver_data;
+       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
        ide_hwif_t *hwif = HWIF(drive);
        struct request *rq;
        struct request_pm_state rqpm;
        ide_task_t args;
        int ret;
 
-       /* Call ACPI _GTM only once */
-       if (!(drive->dn % 2))
+       /* call ACPI _GTM only once */
+       if ((drive->dn & 1) == 0 || pair == NULL)
                ide_acpi_get_timing(hwif);
 
        memset(&rqpm, 0, sizeof(rqpm));
@@ -442,26 +395,25 @@ static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
 
        ret = blk_execute_rq(drive->queue, NULL, rq, 0);
        blk_put_request(rq);
-       /* only call ACPI _PS3 after both drivers are suspended */
-       if (!ret && (((drive->dn % 2) && hwif->drives[0].present
-                && hwif->drives[1].present)
-                || !hwif->drives[0].present
-                || !hwif->drives[1].present))
+
+       /* call ACPI _PS3 only after both devices are suspended */
+       if (ret == 0 && ((drive->dn & 1) || pair == NULL))
                ide_acpi_set_state(hwif, 0);
+
        return ret;
 }
 
 static int generic_ide_resume(struct device *dev)
 {
-       ide_drive_t *drive = dev->driver_data;
+       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
        ide_hwif_t *hwif = HWIF(drive);
        struct request *rq;
        struct request_pm_state rqpm;
        ide_task_t args;
        int err;
 
-       /* Call ACPI _STM only once */
-       if (!(drive->dn % 2)) {
+       /* call ACPI _PS0 / _STM only once */
+       if ((drive->dn & 1) == 0 || pair == NULL) {
                ide_acpi_set_state(hwif, 1);
                ide_acpi_push_timing(hwif);
        }
@@ -491,170 +443,6 @@ 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;
-}
-
-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);
-       ata_id_to_hd_driveid(id);
-
-       if (copy_to_user((void __user *)arg, id, size))
-               rc = -EFAULT;
-
-       kfree(id);
-out:
-       return rc;
-}
-
-static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg)
-{
-       return put_user((drive->dsc_overlap << IDE_NICE_DSC_OVERLAP) |
-                       (drive->nice1 << IDE_NICE_1), (long __user *)arg);
-}
-
-static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
-{
-       if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
-               return -EPERM;
-
-       if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
-           (drive->media == ide_disk || drive->media == ide_floppy ||
-            drive->scsi))
-               return -EPERM;
-
-       drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
-       drive->nice1 = (arg >> IDE_NICE_1) & 1;
-
-       return 0;
-}
-
-int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
-                       unsigned int cmd, unsigned long arg)
-{
-       unsigned long flags;
-       int err = 0, (*getfunc)(ide_drive_t *), (*setfunc)(ide_drive_t *, int);
-
-       switch (cmd) {
-       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;
-       case HDIO_SET_UNMASKINTR:   setfunc = set_unmaskirq;     goto set_val;
-       case HDIO_SET_DMA:          setfunc = set_using_dma;     goto set_val;
-       }
-
-       switch (cmd) {
-               case HDIO_OBSOLETE_IDENTITY:
-               case HDIO_GET_IDENTITY:
-                       if (bdev != bdev->bd_contains)
-                               return -EINVAL;
-                       return ide_get_identity_ioctl(drive, cmd, arg);
-               case HDIO_GET_NICE:
-                       return ide_get_nice_ioctl(drive, 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;
-                       return ide_set_nice_ioctl(drive, arg);
-               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(BUSSTATE_ON, (long __user *)arg))
-                               return -EFAULT;
-                       return 0;
-
-               case HDIO_SET_BUSSTATE:
-                       if (!capable(CAP_SYS_ADMIN))
-                               return -EACCES;
-                       return -EOPNOTSUPP;
-               default:
-                       return -EINVAL;
-       }
-
-read_val:
-       mutex_lock(&ide_setting_mtx);
-       spin_lock_irqsave(&ide_lock, flags);
-       err = getfunc(drive);
-       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;
-}
-
-EXPORT_SYMBOL(generic_ide_ioctl);
-
 /**
  * ide_device_get      -       get an additional reference to a ide_drive_t
  * @drive:     device to get a reference to
@@ -931,16 +719,16 @@ static void ide_dev_apply_params(ide_drive_t *drive)
 
        if (ide_nodma & (1 << i)) {
                printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
-               drive->nodma = 1;
+               drive->dev_flags |= IDE_DFLAG_NODMA;
        }
        if (ide_noflush & (1 << i)) {
                printk(KERN_INFO "ide: disabling flush requests for %s\n",
                                 drive->name);
-               drive->noflush = 1;
+               drive->dev_flags |= IDE_DFLAG_NOFLUSH;
        }
        if (ide_noprobe & (1 << i)) {
                printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
-               drive->noprobe = 1;
+               drive->dev_flags |= IDE_DFLAG_NOPROBE;
        }
        if (ide_nowerr & (1 << i)) {
                printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
@@ -949,7 +737,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
        }
        if (ide_cdroms & (1 << i)) {
                printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
-               drive->present = 1;
+               drive->dev_flags |= IDE_DFLAG_PRESENT;
                drive->media = ide_cdrom;
                /* an ATAPI device ignores DRDY */
                drive->ready_stat = 0;
@@ -958,11 +746,12 @@ static void ide_dev_apply_params(ide_drive_t *drive)
                drive->cyl  = drive->bios_cyl  = ide_disks_chs[i].cyl;
                drive->head = drive->bios_head = ide_disks_chs[i].head;
                drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
-               drive->forced_geom = 1;
+
                printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
                                 drive->name,
                                 drive->cyl, drive->head, drive->sect);
-               drive->present = 1;
+
+               drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
                drive->media = ide_disk;
                drive->ready_stat = ATA_DRDY;
        }