aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-disk.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-17 12:09:12 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-17 12:09:12 -0400
commit5fef0e5c0283949f95a7891c9424a9f84448116b (patch)
tree2451014fcca437fdcd101ddc57c3fda1ab4ec071 /drivers/ide/ide-disk.c
parent42619d35c7af2f88cad56425fe3981f1f65ff0bd (diff)
ide-disk: factor out generic disk handling code to ide-gd.c
While at it: - IDEDISK_VERSION -> IDE_GD_VERSION - ide_cacheflush_p() -> ide_disk_flush() - init_idedisk_capacity() -> ide_disk_init_capacity() - idedisk_set_doorlock() -> ide_disk_set_doorlock() - idedisk_setup() -> ide_disk_setup() - ide_disk_capacity() -> ide_gd_capacity() - ide_disk_remove() -> ide_gd_remove() - ide_disk_probe() -> ide_gd_probe() - ide_disk_resume() -> ide_gd_resume() - ide_device_shutdown() -> ide_gd_shutdown() - idedisk_driver -> ide_gd_driver - idedisk_open() -> ide_gd_open() - idedisk_release() -> ide_gd_release() - idedisk_getgeo() -> ide_gd_getgeo() - idedisk_media_changed() -> ide_gd_media_changed() - idedisk_revalidate_disk() -> ide_gd_revalidate_disk() - idedisk_ops -> ide_gd_ops - idedisk_init() -> ide_gd_init() - idedisk_exit() -> ide_gd_exit() There should be no functional changes caused by this patch. Acked-by: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-disk.c')
-rw-r--r--drivers/ide/ide-disk.c305
1 files changed, 9 insertions, 296 deletions
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 70b75f23a70e..751be7af22c2 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -14,9 +14,6 @@
14 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c. 14 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
15 */ 15 */
16 16
17#define IDEDISK_VERSION "1.18"
18
19#include <linux/module.h>
20#include <linux/types.h> 17#include <linux/types.h>
21#include <linux/string.h> 18#include <linux/string.h>
22#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -39,44 +36,8 @@
39#include <asm/io.h> 36#include <asm/io.h>
40#include <asm/div64.h> 37#include <asm/div64.h>
41 38
42#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
43#define IDE_DISK_MINORS (1 << PARTN_BITS)
44#else
45#define IDE_DISK_MINORS 0
46#endif
47
48#include "ide-disk.h" 39#include "ide-disk.h"
49 40
50static DEFINE_MUTEX(idedisk_ref_mutex);
51
52static void ide_disk_release(struct kref *);
53
54static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
55{
56 struct ide_disk_obj *idkp = NULL;
57
58 mutex_lock(&idedisk_ref_mutex);
59 idkp = ide_drv_g(disk, ide_disk_obj);
60 if (idkp) {
61 if (ide_device_get(idkp->drive))
62 idkp = NULL;
63 else
64 kref_get(&idkp->kref);
65 }
66 mutex_unlock(&idedisk_ref_mutex);
67 return idkp;
68}
69
70static void ide_disk_put(struct ide_disk_obj *idkp)
71{
72 ide_drive_t *drive = idkp->drive;
73
74 mutex_lock(&idedisk_ref_mutex);
75 kref_put(&idkp->kref, ide_disk_release);
76 ide_device_put(drive);
77 mutex_unlock(&idedisk_ref_mutex);
78}
79
80static const u8 ide_rw_cmds[] = { 41static const u8 ide_rw_cmds[] = {
81 ATA_CMD_READ_MULTI, 42 ATA_CMD_READ_MULTI,
82 ATA_CMD_WRITE_MULTI, 43 ATA_CMD_WRITE_MULTI,
@@ -223,8 +184,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
223 * 1073741822 == 549756 MB or 48bit addressing fake drive 184 * 1073741822 == 549756 MB or 48bit addressing fake drive
224 */ 185 */
225 186
226static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq, 187ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
227 sector_t block) 188 sector_t block)
228{ 189{
229 ide_hwif_t *hwif = HWIF(drive); 190 ide_hwif_t *hwif = HWIF(drive);
230 191
@@ -372,7 +333,7 @@ static void idedisk_check_hpa(ide_drive_t *drive)
372 } 333 }
373} 334}
374 335
375static void init_idedisk_capacity(ide_drive_t *drive) 336void ide_disk_init_capacity(ide_drive_t *drive)
376{ 337{
377 u16 *id = drive->id; 338 u16 *id = drive->id;
378 int lba; 339 int lba;
@@ -423,11 +384,6 @@ static void init_idedisk_capacity(ide_drive_t *drive)
423 } 384 }
424} 385}
425 386
426sector_t ide_disk_capacity(ide_drive_t *drive)
427{
428 return drive->capacity64;
429}
430
431static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 387static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
432{ 388{
433 ide_drive_t *drive = q->queuedata; 389 ide_drive_t *drive = q->queuedata;
@@ -526,7 +482,7 @@ static void update_ordered(ide_drive_t *drive)
526 * time we have trimmed the drive capacity if LBA48 is 482 * time we have trimmed the drive capacity if LBA48 is
527 * not available so we don't need to recheck that. 483 * not available so we don't need to recheck that.
528 */ 484 */
529 capacity = ide_disk_capacity(drive); 485 capacity = ide_gd_capacity(drive);
530 barrier = ata_id_flush_enabled(id) && 486 barrier = ata_id_flush_enabled(id) &&
531 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 && 487 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
532 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 || 488 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
@@ -634,7 +590,7 @@ ide_ext_devset_rw(wcache, wcache);
634 590
635ide_ext_devset_rw_sync(nowerr, nowerr); 591ide_ext_devset_rw_sync(nowerr, nowerr);
636 592
637static void idedisk_setup(ide_drive_t *drive) 593void ide_disk_setup(ide_drive_t *drive)
638{ 594{
639 struct ide_disk_obj *idkp = drive->driver_data; 595 struct ide_disk_obj *idkp = drive->driver_data;
640 ide_hwif_t *hwif = drive->hwif; 596 ide_hwif_t *hwif = drive->hwif;
@@ -670,13 +626,13 @@ static void idedisk_setup(ide_drive_t *drive)
670 drive->queue->max_sectors / 2); 626 drive->queue->max_sectors / 2);
671 627
672 /* calculate drive capacity, and select LBA if possible */ 628 /* calculate drive capacity, and select LBA if possible */
673 init_idedisk_capacity(drive); 629 ide_disk_init_capacity(drive);
674 630
675 /* 631 /*
676 * if possible, give fdisk access to more of the drive, 632 * if possible, give fdisk access to more of the drive,
677 * by correcting bios_cyls: 633 * by correcting bios_cyls:
678 */ 634 */
679 capacity = ide_disk_capacity(drive); 635 capacity = ide_gd_capacity(drive);
680 636
681 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) { 637 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
682 if (ata_id_lba48_enabled(drive->id)) { 638 if (ata_id_lba48_enabled(drive->id)) {
@@ -726,7 +682,7 @@ static void idedisk_setup(ide_drive_t *drive)
726 drive->dev_flags |= IDE_DFLAG_ATTACH; 682 drive->dev_flags |= IDE_DFLAG_ATTACH;
727} 683}
728 684
729static void ide_cacheflush_p(ide_drive_t *drive) 685void ide_disk_flush(ide_drive_t *drive)
730{ 686{
731 if (ata_id_flush_enabled(drive->id) == 0 || 687 if (ata_id_flush_enabled(drive->id) == 0 ||
732 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) 688 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
@@ -736,93 +692,7 @@ static void ide_cacheflush_p(ide_drive_t *drive)
736 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name); 692 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
737} 693}
738 694
739static void ide_disk_remove(ide_drive_t *drive) 695int ide_disk_set_doorlock(ide_drive_t *drive, int on)
740{
741 struct ide_disk_obj *idkp = drive->driver_data;
742 struct gendisk *g = idkp->disk;
743
744 ide_proc_unregister_driver(drive, idkp->driver);
745
746 del_gendisk(g);
747
748 ide_cacheflush_p(drive);
749
750 ide_disk_put(idkp);
751}
752
753static void ide_disk_release(struct kref *kref)
754{
755 struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
756 ide_drive_t *drive = idkp->drive;
757 struct gendisk *g = idkp->disk;
758
759 drive->driver_data = NULL;
760 g->private_data = NULL;
761 put_disk(g);
762 kfree(idkp);
763}
764
765static int ide_disk_probe(ide_drive_t *drive);
766
767/*
768 * On HPA drives the capacity needs to be
769 * reinitilized on resume otherwise the disk
770 * can not be used and a hard reset is required
771 */
772static void ide_disk_resume(ide_drive_t *drive)
773{
774 if (ata_id_hpa_enabled(drive->id))
775 init_idedisk_capacity(drive);
776}
777
778static void ide_device_shutdown(ide_drive_t *drive)
779{
780#ifdef CONFIG_ALPHA
781 /* On Alpha, halt(8) doesn't actually turn the machine off,
782 it puts you into the sort of firmware monitor. Typically,
783 it's used to boot another kernel image, so it's not much
784 different from reboot(8). Therefore, we don't need to
785 spin down the disk in this case, especially since Alpha
786 firmware doesn't handle disks in standby mode properly.
787 On the other hand, it's reasonably safe to turn the power
788 off when the shutdown process reaches the firmware prompt,
789 as the firmware initialization takes rather long time -
790 at least 10 seconds, which should be sufficient for
791 the disk to expire its write cache. */
792 if (system_state != SYSTEM_POWER_OFF) {
793#else
794 if (system_state == SYSTEM_RESTART) {
795#endif
796 ide_cacheflush_p(drive);
797 return;
798 }
799
800 printk(KERN_INFO "Shutdown: %s\n", drive->name);
801
802 drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
803}
804
805static ide_driver_t idedisk_driver = {
806 .gen_driver = {
807 .owner = THIS_MODULE,
808 .name = "ide-disk",
809 .bus = &ide_bus_type,
810 },
811 .probe = ide_disk_probe,
812 .remove = ide_disk_remove,
813 .resume = ide_disk_resume,
814 .shutdown = ide_device_shutdown,
815 .version = IDEDISK_VERSION,
816 .do_request = ide_do_rw_disk,
817 .end_request = ide_end_request,
818 .error = __ide_error,
819#ifdef CONFIG_IDE_PROC_FS
820 .proc = ide_disk_proc,
821 .settings = ide_disk_settings,
822#endif
823};
824
825static int idedisk_set_doorlock(ide_drive_t *drive, int on)
826{ 696{
827 ide_task_t task; 697 ide_task_t task;
828 int ret; 698 int ret;
@@ -841,160 +711,3 @@ static int idedisk_set_doorlock(ide_drive_t *drive, int on)
841 711
842 return ret; 712 return ret;
843} 713}
844
845static int idedisk_open(struct inode *inode, struct file *filp)
846{
847 struct gendisk *disk = inode->i_bdev->bd_disk;
848 struct ide_disk_obj *idkp;
849 ide_drive_t *drive;
850
851 idkp = ide_disk_get(disk);
852 if (idkp == NULL)
853 return -ENXIO;
854
855 drive = idkp->drive;
856
857 idkp->openers++;
858
859 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
860 /*
861 * Ignore the return code from door_lock,
862 * since the open() has already succeeded,
863 * and the door_lock is irrelevant at this point.
864 */
865 idedisk_set_doorlock(drive, 1);
866 check_disk_change(inode->i_bdev);
867 }
868 return 0;
869}
870
871static int idedisk_release(struct inode *inode, struct file *filp)
872{
873 struct gendisk *disk = inode->i_bdev->bd_disk;
874 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
875 ide_drive_t *drive = idkp->drive;
876
877 if (idkp->openers == 1)
878 ide_cacheflush_p(drive);
879
880 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
881 idedisk_set_doorlock(drive, 0);
882
883 idkp->openers--;
884
885 ide_disk_put(idkp);
886
887 return 0;
888}
889
890static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
891{
892 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
893 ide_drive_t *drive = idkp->drive;
894
895 geo->heads = drive->bios_head;
896 geo->sectors = drive->bios_sect;
897 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
898 return 0;
899}
900
901static int idedisk_media_changed(struct gendisk *disk)
902{
903 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
904 ide_drive_t *drive = idkp->drive;
905
906 /* do not scan partitions twice if this is a removable device */
907 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
908 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
909 return 0;
910 }
911
912 /* if removable, always assume it was changed */
913 return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
914}
915
916static int idedisk_revalidate_disk(struct gendisk *disk)
917{
918 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
919 set_capacity(disk, ide_disk_capacity(idkp->drive));
920 return 0;
921}
922
923static struct block_device_operations idedisk_ops = {
924 .owner = THIS_MODULE,
925 .open = idedisk_open,
926 .release = idedisk_release,
927 .ioctl = ide_disk_ioctl,
928 .getgeo = idedisk_getgeo,
929 .media_changed = idedisk_media_changed,
930 .revalidate_disk = idedisk_revalidate_disk
931};
932
933MODULE_DESCRIPTION("ATA DISK Driver");
934
935static int ide_disk_probe(ide_drive_t *drive)
936{
937 struct ide_disk_obj *idkp;
938 struct gendisk *g;
939
940 /* strstr("foo", "") is non-NULL */
941 if (!strstr("ide-disk", drive->driver_req))
942 goto failed;
943
944 if (drive->media != ide_disk)
945 goto failed;
946
947 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
948 if (!idkp)
949 goto failed;
950
951 g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif));
952 if (!g)
953 goto out_free_idkp;
954
955 ide_init_disk(g, drive);
956
957 kref_init(&idkp->kref);
958
959 idkp->drive = drive;
960 idkp->driver = &idedisk_driver;
961 idkp->disk = g;
962
963 g->private_data = &idkp->driver;
964
965 drive->driver_data = idkp;
966
967 idedisk_setup(drive);
968
969 set_capacity(g, ide_disk_capacity(drive));
970
971 g->minors = IDE_DISK_MINORS;
972 g->driverfs_dev = &drive->gendev;
973 g->flags |= GENHD_FL_EXT_DEVT;
974 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
975 g->flags = GENHD_FL_REMOVABLE;
976 g->fops = &idedisk_ops;
977 add_disk(g);
978 return 0;
979
980out_free_idkp:
981 kfree(idkp);
982failed:
983 return -ENODEV;
984}
985
986static void __exit idedisk_exit(void)
987{
988 driver_unregister(&idedisk_driver.gen_driver);
989}
990
991static int __init idedisk_init(void)
992{
993 return driver_register(&idedisk_driver.gen_driver);
994}
995
996MODULE_ALIAS("ide:*m-disk*");
997MODULE_ALIAS("ide-disk");
998module_init(idedisk_init);
999module_exit(idedisk_exit);
1000MODULE_LICENSE("GPL");