diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-10 16:39:33 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-10 16:39:33 -0400 |
commit | aa7687738af3332470e02ac1060f6c046d83c9a3 (patch) | |
tree | 2eb2cd89de0b8dcad12534e28a9178d0325ae491 /drivers/ide/ide.c | |
parent | 9232c14bff36d65de254f34386c00b732c5b6099 (diff) |
ide: add ide_setting_ioctl() helper
* Add struct ide_ioctl_devset representing ioctl device setting.
* Add ide_setting_ioctl() helper for matching given ioctl
and its parameters against table of ioctl device settings.
* Convert ide_setting_ioctl() and idedisk_ioctl() to use
ide_setting_ioctl().
* Un-export ide_setting_mtx.
While at it:
* {get,set}_lba_addressing() -> {get,set}_addressing()
There should be no functional changes caused by this patch.
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide.c')
-rw-r--r-- | drivers/ide/ide.c | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index f78e789ea5f7..4910924abeb7 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -250,8 +250,6 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) | |||
250 | 250 | ||
251 | DEFINE_MUTEX(ide_setting_mtx); | 251 | DEFINE_MUTEX(ide_setting_mtx); |
252 | 252 | ||
253 | EXPORT_SYMBOL_GPL(ide_setting_mtx); | ||
254 | |||
255 | /** | 253 | /** |
256 | * ide_spin_wait_hwgroup - wait for group | 254 | * ide_spin_wait_hwgroup - wait for group |
257 | * @drive: drive in the group | 255 | * @drive: drive in the group |
@@ -558,23 +556,23 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) | |||
558 | return 0; | 556 | return 0; |
559 | } | 557 | } |
560 | 558 | ||
559 | static const struct ide_ioctl_devset ide_ioctl_settings[] = { | ||
560 | { HDIO_GET_32BIT, HDIO_SET_32BIT, get_io_32bit, set_io_32bit }, | ||
561 | { HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, get_ksettings, set_ksettings }, | ||
562 | { HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, get_unmaskirq, set_unmaskirq }, | ||
563 | { HDIO_GET_DMA, HDIO_SET_DMA, get_using_dma, set_using_dma }, | ||
564 | { -1, HDIO_SET_PIO_MODE, NULL, set_pio_mode }, | ||
565 | { 0 } | ||
566 | }; | ||
567 | |||
561 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, | 568 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, |
562 | unsigned int cmd, unsigned long arg) | 569 | unsigned int cmd, unsigned long arg) |
563 | { | 570 | { |
564 | unsigned long flags; | 571 | int err; |
565 | int err = 0, (*getfunc)(ide_drive_t *), (*setfunc)(ide_drive_t *, int); | ||
566 | 572 | ||
567 | switch (cmd) { | 573 | err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_ioctl_settings); |
568 | case HDIO_GET_32BIT: getfunc = get_io_32bit; goto read_val; | 574 | if (err != -EOPNOTSUPP) |
569 | case HDIO_GET_KEEPSETTINGS: getfunc = get_ksettings; goto read_val; | 575 | return err; |
570 | case HDIO_GET_UNMASKINTR: getfunc = get_unmaskirq; goto read_val; | ||
571 | case HDIO_GET_DMA: getfunc = get_using_dma; goto read_val; | ||
572 | case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val; | ||
573 | case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val; | ||
574 | case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val; | ||
575 | case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val; | ||
576 | case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val; | ||
577 | } | ||
578 | 576 | ||
579 | switch (cmd) { | 577 | switch (cmd) { |
580 | case HDIO_OBSOLETE_IDENTITY: | 578 | case HDIO_OBSOLETE_IDENTITY: |
@@ -629,11 +627,29 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device | |||
629 | default: | 627 | default: |
630 | return -EINVAL; | 628 | return -EINVAL; |
631 | } | 629 | } |
630 | } | ||
631 | EXPORT_SYMBOL(generic_ide_ioctl); | ||
632 | |||
633 | int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev, | ||
634 | unsigned int cmd, unsigned long arg, | ||
635 | const struct ide_ioctl_devset *s) | ||
636 | { | ||
637 | unsigned long flags; | ||
638 | int err = -EOPNOTSUPP; | ||
639 | |||
640 | for (; s->get_ioctl; s++) { | ||
641 | if (s->get && s->get_ioctl == cmd) | ||
642 | goto read_val; | ||
643 | else if (s->set && s->set_ioctl == cmd) | ||
644 | goto set_val; | ||
645 | } | ||
646 | |||
647 | return err; | ||
632 | 648 | ||
633 | read_val: | 649 | read_val: |
634 | mutex_lock(&ide_setting_mtx); | 650 | mutex_lock(&ide_setting_mtx); |
635 | spin_lock_irqsave(&ide_lock, flags); | 651 | spin_lock_irqsave(&ide_lock, flags); |
636 | err = getfunc(drive); | 652 | err = s->get(drive); |
637 | spin_unlock_irqrestore(&ide_lock, flags); | 653 | spin_unlock_irqrestore(&ide_lock, flags); |
638 | mutex_unlock(&ide_setting_mtx); | 654 | mutex_unlock(&ide_setting_mtx); |
639 | return err >= 0 ? put_user(err, (long __user *)arg) : err; | 655 | return err >= 0 ? put_user(err, (long __user *)arg) : err; |
@@ -646,14 +662,13 @@ set_val: | |||
646 | err = -EACCES; | 662 | err = -EACCES; |
647 | else { | 663 | else { |
648 | mutex_lock(&ide_setting_mtx); | 664 | mutex_lock(&ide_setting_mtx); |
649 | err = setfunc(drive, arg); | 665 | err = s->set(drive, arg); |
650 | mutex_unlock(&ide_setting_mtx); | 666 | mutex_unlock(&ide_setting_mtx); |
651 | } | 667 | } |
652 | } | 668 | } |
653 | return err; | 669 | return err; |
654 | } | 670 | } |
655 | 671 | EXPORT_SYMBOL_GPL(ide_setting_ioctl); | |
656 | EXPORT_SYMBOL(generic_ide_ioctl); | ||
657 | 672 | ||
658 | /** | 673 | /** |
659 | * ide_device_get - get an additional reference to a ide_drive_t | 674 | * ide_device_get - get an additional reference to a ide_drive_t |