aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/ide/Makefile2
-rw-r--r--drivers/ide/ide-disk.c305
-rw-r--r--drivers/ide/ide-disk.h8
-rw-r--r--drivers/ide/ide-disk_proc.c2
-rw-r--r--drivers/ide/ide-gd.c296
5 files changed, 314 insertions, 299 deletions
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index ceaf779054ea..8aad9395a427 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -37,7 +37,7 @@ obj-$(CONFIG_IDE_H8300) += h8300/
37obj-$(CONFIG_IDE_GENERIC) += ide-generic.o 37obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
38obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 38obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
39 39
40ide-disk_mod-y += ide-disk.o ide-disk_ioctl.o 40ide-disk_mod-y += ide-gd.o ide-disk.o ide-disk_ioctl.o
41ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o 41ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
42ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o 42ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
43 43
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");
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h
index 50d674b91c8b..104ad71288a5 100644
--- a/drivers/ide/ide-disk.h
+++ b/drivers/ide/ide-disk.h
@@ -9,8 +9,14 @@ struct ide_disk_obj {
9 unsigned int openers; /* protected by BKL for now */ 9 unsigned int openers; /* protected by BKL for now */
10}; 10};
11 11
12sector_t ide_gd_capacity(ide_drive_t *);
13
12/* ide-disk.c */ 14/* ide-disk.c */
13sector_t ide_disk_capacity(ide_drive_t *); 15void ide_disk_init_capacity(ide_drive_t *);
16void ide_disk_setup(ide_drive_t *);
17void ide_disk_flush(ide_drive_t *);
18int ide_disk_set_doorlock(ide_drive_t *, int);
19ide_startstop_t ide_do_rw_disk(ide_drive_t *, struct request *, sector_t);
14ide_decl_devset(address); 20ide_decl_devset(address);
15ide_decl_devset(multcount); 21ide_decl_devset(multcount);
16ide_decl_devset(nowerr); 22ide_decl_devset(nowerr);
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
index 4724976afe71..1146f4204c6e 100644
--- a/drivers/ide/ide-disk_proc.c
+++ b/drivers/ide/ide-disk_proc.c
@@ -56,7 +56,7 @@ static int proc_idedisk_read_capacity
56 ide_drive_t*drive = (ide_drive_t *)data; 56 ide_drive_t*drive = (ide_drive_t *)data;
57 int len; 57 int len;
58 58
59 len = sprintf(page, "%llu\n", (long long)ide_disk_capacity(drive)); 59 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
60 60
61 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 61 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
62} 62}
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
new file mode 100644
index 000000000000..84bbcfee9233
--- /dev/null
+++ b/drivers/ide/ide-gd.c
@@ -0,0 +1,296 @@
1#include <linux/module.h>
2#include <linux/types.h>
3#include <linux/string.h>
4#include <linux/kernel.h>
5#include <linux/errno.h>
6#include <linux/genhd.h>
7#include <linux/mutex.h>
8#include <linux/ide.h>
9#include <linux/hdreg.h>
10
11#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
12#define IDE_DISK_MINORS (1 << PARTN_BITS)
13#else
14#define IDE_DISK_MINORS 0
15#endif
16
17#include "ide-disk.h"
18
19#define IDE_GD_VERSION "1.18"
20
21static DEFINE_MUTEX(ide_disk_ref_mutex);
22
23static void ide_disk_release(struct kref *);
24
25static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
26{
27 struct ide_disk_obj *idkp = NULL;
28
29 mutex_lock(&ide_disk_ref_mutex);
30 idkp = ide_drv_g(disk, ide_disk_obj);
31 if (idkp) {
32 if (ide_device_get(idkp->drive))
33 idkp = NULL;
34 else
35 kref_get(&idkp->kref);
36 }
37 mutex_unlock(&ide_disk_ref_mutex);
38 return idkp;
39}
40
41static void ide_disk_put(struct ide_disk_obj *idkp)
42{
43 ide_drive_t *drive = idkp->drive;
44
45 mutex_lock(&ide_disk_ref_mutex);
46 kref_put(&idkp->kref, ide_disk_release);
47 ide_device_put(drive);
48 mutex_unlock(&ide_disk_ref_mutex);
49}
50
51sector_t ide_gd_capacity(ide_drive_t *drive)
52{
53 return drive->capacity64;
54}
55
56static int ide_gd_probe(ide_drive_t *);
57
58static void ide_gd_remove(ide_drive_t *drive)
59{
60 struct ide_disk_obj *idkp = drive->driver_data;
61 struct gendisk *g = idkp->disk;
62
63 ide_proc_unregister_driver(drive, idkp->driver);
64
65 del_gendisk(g);
66
67 ide_disk_flush(drive);
68
69 ide_disk_put(idkp);
70}
71
72static void ide_disk_release(struct kref *kref)
73{
74 struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
75 ide_drive_t *drive = idkp->drive;
76 struct gendisk *g = idkp->disk;
77
78 drive->driver_data = NULL;
79 g->private_data = NULL;
80 put_disk(g);
81 kfree(idkp);
82}
83
84/*
85 * On HPA drives the capacity needs to be
86 * reinitilized on resume otherwise the disk
87 * can not be used and a hard reset is required
88 */
89static void ide_gd_resume(ide_drive_t *drive)
90{
91 if (ata_id_hpa_enabled(drive->id))
92 ide_disk_init_capacity(drive);
93}
94
95static void ide_gd_shutdown(ide_drive_t *drive)
96{
97#ifdef CONFIG_ALPHA
98 /* On Alpha, halt(8) doesn't actually turn the machine off,
99 it puts you into the sort of firmware monitor. Typically,
100 it's used to boot another kernel image, so it's not much
101 different from reboot(8). Therefore, we don't need to
102 spin down the disk in this case, especially since Alpha
103 firmware doesn't handle disks in standby mode properly.
104 On the other hand, it's reasonably safe to turn the power
105 off when the shutdown process reaches the firmware prompt,
106 as the firmware initialization takes rather long time -
107 at least 10 seconds, which should be sufficient for
108 the disk to expire its write cache. */
109 if (system_state != SYSTEM_POWER_OFF) {
110#else
111 if (system_state == SYSTEM_RESTART) {
112#endif
113 ide_disk_flush(drive);
114 return;
115 }
116
117 printk(KERN_INFO "Shutdown: %s\n", drive->name);
118
119 drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
120}
121
122static ide_driver_t ide_gd_driver = {
123 .gen_driver = {
124 .owner = THIS_MODULE,
125 .name = "ide-disk",
126 .bus = &ide_bus_type,
127 },
128 .probe = ide_gd_probe,
129 .remove = ide_gd_remove,
130 .resume = ide_gd_resume,
131 .shutdown = ide_gd_shutdown,
132 .version = IDE_GD_VERSION,
133 .do_request = ide_do_rw_disk,
134 .end_request = ide_end_request,
135 .error = __ide_error,
136#ifdef CONFIG_IDE_PROC_FS
137 .proc = ide_disk_proc,
138 .settings = ide_disk_settings,
139#endif
140};
141
142static int ide_gd_open(struct inode *inode, struct file *filp)
143{
144 struct gendisk *disk = inode->i_bdev->bd_disk;
145 struct ide_disk_obj *idkp;
146 ide_drive_t *drive;
147
148 idkp = ide_disk_get(disk);
149 if (idkp == NULL)
150 return -ENXIO;
151
152 drive = idkp->drive;
153
154 idkp->openers++;
155
156 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
157 /*
158 * Ignore the return code from door_lock,
159 * since the open() has already succeeded,
160 * and the door_lock is irrelevant at this point.
161 */
162 ide_disk_set_doorlock(drive, 1);
163 check_disk_change(inode->i_bdev);
164 }
165 return 0;
166}
167
168static int ide_gd_release(struct inode *inode, struct file *filp)
169{
170 struct gendisk *disk = inode->i_bdev->bd_disk;
171 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
172 ide_drive_t *drive = idkp->drive;
173
174 if (idkp->openers == 1)
175 ide_disk_flush(drive);
176
177 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
178 ide_disk_set_doorlock(drive, 0);
179
180 idkp->openers--;
181
182 ide_disk_put(idkp);
183
184 return 0;
185}
186
187static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
188{
189 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
190 ide_drive_t *drive = idkp->drive;
191
192 geo->heads = drive->bios_head;
193 geo->sectors = drive->bios_sect;
194 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
195 return 0;
196}
197
198static int ide_gd_media_changed(struct gendisk *disk)
199{
200 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
201 ide_drive_t *drive = idkp->drive;
202
203 /* do not scan partitions twice if this is a removable device */
204 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
205 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
206 return 0;
207 }
208
209 /* if removable, always assume it was changed */
210 return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
211}
212
213static int ide_gd_revalidate_disk(struct gendisk *disk)
214{
215 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
216 set_capacity(disk, ide_gd_capacity(idkp->drive));
217 return 0;
218}
219
220static struct block_device_operations ide_gd_ops = {
221 .owner = THIS_MODULE,
222 .open = ide_gd_open,
223 .release = ide_gd_release,
224 .ioctl = ide_disk_ioctl,
225 .getgeo = ide_gd_getgeo,
226 .media_changed = ide_gd_media_changed,
227 .revalidate_disk = ide_gd_revalidate_disk
228};
229
230static int ide_gd_probe(ide_drive_t *drive)
231{
232 struct ide_disk_obj *idkp;
233 struct gendisk *g;
234
235 /* strstr("foo", "") is non-NULL */
236 if (!strstr("ide-disk", drive->driver_req))
237 goto failed;
238
239 if (drive->media != ide_disk)
240 goto failed;
241
242 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
243 if (!idkp)
244 goto failed;
245
246 g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif));
247 if (!g)
248 goto out_free_idkp;
249
250 ide_init_disk(g, drive);
251
252 kref_init(&idkp->kref);
253
254 idkp->drive = drive;
255 idkp->driver = &ide_gd_driver;
256 idkp->disk = g;
257
258 g->private_data = &idkp->driver;
259
260 drive->driver_data = idkp;
261
262 ide_disk_setup(drive);
263
264 set_capacity(g, ide_gd_capacity(drive));
265
266 g->minors = IDE_DISK_MINORS;
267 g->driverfs_dev = &drive->gendev;
268 g->flags |= GENHD_FL_EXT_DEVT;
269 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
270 g->flags = GENHD_FL_REMOVABLE;
271 g->fops = &ide_gd_ops;
272 add_disk(g);
273 return 0;
274
275out_free_idkp:
276 kfree(idkp);
277failed:
278 return -ENODEV;
279}
280
281static int __init ide_gd_init(void)
282{
283 return driver_register(&ide_gd_driver.gen_driver);
284}
285
286static void __exit ide_gd_exit(void)
287{
288 driver_unregister(&ide_gd_driver.gen_driver);
289}
290
291MODULE_ALIAS("ide:*m-disk*");
292MODULE_ALIAS("ide-disk");
293module_init(ide_gd_init);
294module_exit(ide_gd_exit);
295MODULE_LICENSE("GPL");
296MODULE_DESCRIPTION("ATA DISK Driver");