aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/ide-floppy.h2
-rw-r--r--drivers/ide/ide-floppy_proc.c2
-rw-r--r--drivers/ide/ide-gd-floppy.c179
3 files changed, 91 insertions, 92 deletions
diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h
index 836a70e6e3ef..b965da2f41ce 100644
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -57,7 +57,7 @@ typedef struct ide_floppy_obj {
57#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602 57#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
58#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603 58#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
59 59
60sector_t ide_floppy_capacity(ide_drive_t *); 60sector_t ide_gd_capacity(ide_drive_t *);
61 61
62/* ide-floppy.c */ 62/* ide-floppy.c */
63void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8); 63void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
index 76f0c6c4eca3..3ec762cb60ab 100644
--- a/drivers/ide/ide-floppy_proc.c
+++ b/drivers/ide/ide-floppy_proc.c
@@ -9,7 +9,7 @@ static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
9 ide_drive_t*drive = (ide_drive_t *)data; 9 ide_drive_t*drive = (ide_drive_t *)data;
10 int len; 10 int len;
11 11
12 len = sprintf(page, "%llu\n", (long long)ide_floppy_capacity(drive)); 12 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
13 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 13 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
14} 14}
15 15
diff --git a/drivers/ide/ide-gd-floppy.c b/drivers/ide/ide-gd-floppy.c
index 7afd013b4c55..986253418794 100644
--- a/drivers/ide/ide-gd-floppy.c
+++ b/drivers/ide/ide-gd-floppy.c
@@ -16,75 +16,75 @@
16static unsigned long debug_mask; 16static unsigned long debug_mask;
17module_param(debug_mask, ulong, 0644); 17module_param(debug_mask, ulong, 0644);
18 18
19static DEFINE_MUTEX(idefloppy_ref_mutex); 19static DEFINE_MUTEX(ide_disk_ref_mutex);
20 20
21static void idefloppy_cleanup_obj(struct kref *); 21static void ide_disk_release(struct kref *);
22 22
23static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) 23static struct ide_floppy_obj *ide_disk_get(struct gendisk *disk)
24{ 24{
25 struct ide_floppy_obj *floppy = NULL; 25 struct ide_floppy_obj *idkp = NULL;
26 26
27 mutex_lock(&idefloppy_ref_mutex); 27 mutex_lock(&ide_disk_ref_mutex);
28 floppy = ide_drv_g(disk, ide_floppy_obj); 28 idkp = ide_drv_g(disk, ide_floppy_obj);
29 if (floppy) { 29 if (idkp) {
30 if (ide_device_get(floppy->drive)) 30 if (ide_device_get(idkp->drive))
31 floppy = NULL; 31 idkp = NULL;
32 else 32 else
33 kref_get(&floppy->kref); 33 kref_get(&idkp->kref);
34 } 34 }
35 mutex_unlock(&idefloppy_ref_mutex); 35 mutex_unlock(&ide_disk_ref_mutex);
36 return floppy; 36 return idkp;
37} 37}
38 38
39static void ide_floppy_put(struct ide_floppy_obj *floppy) 39static void ide_disk_put(struct ide_floppy_obj *idkp)
40{ 40{
41 ide_drive_t *drive = floppy->drive; 41 ide_drive_t *drive = idkp->drive;
42 42
43 mutex_lock(&idefloppy_ref_mutex); 43 mutex_lock(&ide_disk_ref_mutex);
44 kref_put(&floppy->kref, idefloppy_cleanup_obj); 44 kref_put(&idkp->kref, ide_disk_release);
45 ide_device_put(drive); 45 ide_device_put(drive);
46 mutex_unlock(&idefloppy_ref_mutex); 46 mutex_unlock(&ide_disk_ref_mutex);
47} 47}
48 48
49sector_t ide_floppy_capacity(ide_drive_t *drive) 49sector_t ide_gd_capacity(ide_drive_t *drive)
50{ 50{
51 return drive->capacity64; 51 return drive->capacity64;
52} 52}
53 53
54static void ide_floppy_remove(ide_drive_t *drive) 54static int ide_gd_probe(ide_drive_t *);
55
56static void ide_gd_remove(ide_drive_t *drive)
55{ 57{
56 idefloppy_floppy_t *floppy = drive->driver_data; 58 struct ide_floppy_obj *idkp = drive->driver_data;
57 struct gendisk *g = floppy->disk; 59 struct gendisk *g = idkp->disk;
58 60
59 ide_proc_unregister_driver(drive, floppy->driver); 61 ide_proc_unregister_driver(drive, idkp->driver);
60 62
61 del_gendisk(g); 63 del_gendisk(g);
62 64
63 ide_floppy_put(floppy); 65 ide_disk_put(idkp);
64} 66}
65 67
66static void idefloppy_cleanup_obj(struct kref *kref) 68static void ide_disk_release(struct kref *kref)
67{ 69{
68 struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj); 70 struct ide_floppy_obj *idkp = to_ide_drv(kref, ide_floppy_obj);
69 ide_drive_t *drive = floppy->drive; 71 ide_drive_t *drive = idkp->drive;
70 struct gendisk *g = floppy->disk; 72 struct gendisk *g = idkp->disk;
71 73
72 drive->driver_data = NULL; 74 drive->driver_data = NULL;
73 g->private_data = NULL; 75 g->private_data = NULL;
74 put_disk(g); 76 put_disk(g);
75 kfree(floppy); 77 kfree(idkp);
76} 78}
77 79
78static int ide_floppy_probe(ide_drive_t *); 80static ide_driver_t ide_gd_driver = {
79
80static ide_driver_t idefloppy_driver = {
81 .gen_driver = { 81 .gen_driver = {
82 .owner = THIS_MODULE, 82 .owner = THIS_MODULE,
83 .name = "ide-floppy", 83 .name = "ide-floppy",
84 .bus = &ide_bus_type, 84 .bus = &ide_bus_type,
85 }, 85 },
86 .probe = ide_floppy_probe, 86 .probe = ide_gd_probe,
87 .remove = ide_floppy_remove, 87 .remove = ide_gd_remove,
88 .version = IDEFLOPPY_VERSION, 88 .version = IDEFLOPPY_VERSION,
89 .do_request = ide_floppy_do_request, 89 .do_request = ide_floppy_do_request,
90 .end_request = ide_floppy_end_request, 90 .end_request = ide_floppy_end_request,
@@ -95,24 +95,24 @@ static ide_driver_t idefloppy_driver = {
95#endif 95#endif
96}; 96};
97 97
98static int idefloppy_open(struct inode *inode, struct file *filp) 98static int ide_gd_open(struct inode *inode, struct file *filp)
99{ 99{
100 struct gendisk *disk = inode->i_bdev->bd_disk; 100 struct gendisk *disk = inode->i_bdev->bd_disk;
101 struct ide_floppy_obj *floppy; 101 struct ide_floppy_obj *idkp;
102 ide_drive_t *drive; 102 ide_drive_t *drive;
103 int ret = 0; 103 int ret = 0;
104 104
105 floppy = ide_floppy_get(disk); 105 idkp = ide_disk_get(disk);
106 if (!floppy) 106 if (idkp == NULL)
107 return -ENXIO; 107 return -ENXIO;
108 108
109 drive = floppy->drive; 109 drive = idkp->drive;
110 110
111 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 111 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
112 112
113 floppy->openers++; 113 idkp->openers++;
114 114
115 if (floppy->openers == 1) { 115 if (idkp->openers == 1) {
116 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS; 116 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
117 /* Just in case */ 117 /* Just in case */
118 118
@@ -121,7 +121,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
121 121
122 ret = ide_floppy_get_capacity(drive); 122 ret = ide_floppy_get_capacity(drive);
123 123
124 set_capacity(disk, ide_floppy_capacity(drive)); 124 set_capacity(disk, ide_gd_capacity(drive));
125 125
126 if (ret && (filp->f_flags & O_NDELAY) == 0) { 126 if (ret && (filp->f_flags & O_NDELAY) == 0) {
127 /* 127 /*
@@ -130,12 +130,12 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
130 * of the drive or begin the format - Sam 130 * of the drive or begin the format - Sam
131 */ 131 */
132 ret = -EIO; 132 ret = -EIO;
133 goto out_put_floppy; 133 goto out_put_idkp;
134 } 134 }
135 135
136 if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) { 136 if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) {
137 ret = -EROFS; 137 ret = -EROFS;
138 goto out_put_floppy; 138 goto out_put_idkp;
139 } 139 }
140 140
141 ide_set_media_lock(drive, disk, 1); 141 ide_set_media_lock(drive, disk, 1);
@@ -143,41 +143,40 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
143 check_disk_change(inode->i_bdev); 143 check_disk_change(inode->i_bdev);
144 } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) { 144 } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
145 ret = -EBUSY; 145 ret = -EBUSY;
146 goto out_put_floppy; 146 goto out_put_idkp;
147 } 147 }
148 return 0; 148 return 0;
149 149
150out_put_floppy: 150out_put_idkp:
151 floppy->openers--; 151 idkp->openers--;
152 ide_floppy_put(floppy); 152 ide_disk_put(idkp);
153 return ret; 153 return ret;
154} 154}
155 155
156static int idefloppy_release(struct inode *inode, struct file *filp) 156static int ide_gd_release(struct inode *inode, struct file *filp)
157{ 157{
158 struct gendisk *disk = inode->i_bdev->bd_disk; 158 struct gendisk *disk = inode->i_bdev->bd_disk;
159 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj); 159 struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
160 ide_drive_t *drive = floppy->drive; 160 ide_drive_t *drive = idkp->drive;
161 161
162 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 162 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
163 163
164 if (floppy->openers == 1) { 164 if (idkp->openers == 1) {
165 ide_set_media_lock(drive, disk, 0); 165 ide_set_media_lock(drive, disk, 0);
166 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS; 166 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
167 } 167 }
168 168
169 floppy->openers--; 169 idkp->openers--;
170 170
171 ide_floppy_put(floppy); 171 ide_disk_put(idkp);
172 172
173 return 0; 173 return 0;
174} 174}
175 175
176static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) 176static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
177{ 177{
178 struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk, 178 struct ide_floppy_obj *idkp = ide_drv_g(bdev->bd_disk, ide_floppy_obj);
179 ide_floppy_obj); 179 ide_drive_t *drive = idkp->drive;
180 ide_drive_t *drive = floppy->drive;
181 180
182 geo->heads = drive->bios_head; 181 geo->heads = drive->bios_head;
183 geo->sectors = drive->bios_sect; 182 geo->sectors = drive->bios_sect;
@@ -185,10 +184,10 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
185 return 0; 184 return 0;
186} 185}
187 186
188static int idefloppy_media_changed(struct gendisk *disk) 187static int ide_gd_media_changed(struct gendisk *disk)
189{ 188{
190 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj); 189 struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
191 ide_drive_t *drive = floppy->drive; 190 ide_drive_t *drive = idkp->drive;
192 int ret; 191 int ret;
193 192
194 /* do not scan partitions twice if this is a removable device */ 193 /* do not scan partitions twice if this is a removable device */
@@ -203,26 +202,26 @@ static int idefloppy_media_changed(struct gendisk *disk)
203 return ret; 202 return ret;
204} 203}
205 204
206static int idefloppy_revalidate_disk(struct gendisk *disk) 205static int ide_gd_revalidate_disk(struct gendisk *disk)
207{ 206{
208 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj); 207 struct ide_floppy_obj *idkp = ide_drv_g(disk, ide_floppy_obj);
209 set_capacity(disk, ide_floppy_capacity(floppy->drive)); 208 set_capacity(disk, ide_gd_capacity(idkp->drive));
210 return 0; 209 return 0;
211} 210}
212 211
213static struct block_device_operations idefloppy_ops = { 212static struct block_device_operations ide_gd_ops = {
214 .owner = THIS_MODULE, 213 .owner = THIS_MODULE,
215 .open = idefloppy_open, 214 .open = ide_gd_open,
216 .release = idefloppy_release, 215 .release = ide_gd_release,
217 .ioctl = ide_floppy_ioctl, 216 .ioctl = ide_floppy_ioctl,
218 .getgeo = idefloppy_getgeo, 217 .getgeo = ide_gd_getgeo,
219 .media_changed = idefloppy_media_changed, 218 .media_changed = ide_gd_media_changed,
220 .revalidate_disk = idefloppy_revalidate_disk 219 .revalidate_disk = ide_gd_revalidate_disk
221}; 220};
222 221
223static int ide_floppy_probe(ide_drive_t *drive) 222static int ide_gd_probe(ide_drive_t *drive)
224{ 223{
225 idefloppy_floppy_t *floppy; 224 struct ide_floppy_obj *idkp;
226 struct gendisk *g; 225 struct gendisk *g;
227 226
228 if (!strstr("ide-floppy", drive->driver_req)) 227 if (!strstr("ide-floppy", drive->driver_req))
@@ -236,8 +235,8 @@ static int ide_floppy_probe(ide_drive_t *drive)
236 DRV_NAME "\n", drive->name); 235 DRV_NAME "\n", drive->name);
237 goto failed; 236 goto failed;
238 } 237 }
239 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL); 238 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
240 if (!floppy) { 239 if (!idkp) {
241 printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n", 240 printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
242 drive->name); 241 drive->name);
243 goto failed; 242 goto failed;
@@ -245,54 +244,54 @@ static int ide_floppy_probe(ide_drive_t *drive)
245 244
246 g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif)); 245 g = alloc_disk_node(1 << PARTN_BITS, hwif_to_node(drive->hwif));
247 if (!g) 246 if (!g)
248 goto out_free_floppy; 247 goto out_free_idkp;
249 248
250 ide_init_disk(g, drive); 249 ide_init_disk(g, drive);
251 250
252 kref_init(&floppy->kref); 251 kref_init(&idkp->kref);
253 252
254 floppy->drive = drive; 253 idkp->drive = drive;
255 floppy->driver = &idefloppy_driver; 254 idkp->driver = &ide_gd_driver;
256 floppy->disk = g; 255 idkp->disk = g;
257 256
258 g->private_data = &floppy->driver; 257 g->private_data = &idkp->driver;
259 258
260 drive->driver_data = floppy; 259 drive->driver_data = idkp;
261 260
262 drive->debug_mask = debug_mask; 261 drive->debug_mask = debug_mask;
263 262
264 ide_floppy_setup(drive); 263 ide_floppy_setup(drive);
265 264
266 set_capacity(g, ide_floppy_capacity(drive)); 265 set_capacity(g, ide_gd_capacity(drive));
267 266
268 g->minors = 1 << PARTN_BITS; 267 g->minors = 1 << PARTN_BITS;
269 g->driverfs_dev = &drive->gendev; 268 g->driverfs_dev = &drive->gendev;
270 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) 269 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
271 g->flags = GENHD_FL_REMOVABLE; 270 g->flags = GENHD_FL_REMOVABLE;
272 g->fops = &idefloppy_ops; 271 g->fops = &ide_gd_ops;
273 add_disk(g); 272 add_disk(g);
274 return 0; 273 return 0;
275 274
276out_free_floppy: 275out_free_idkp:
277 kfree(floppy); 276 kfree(idkp);
278failed: 277failed:
279 return -ENODEV; 278 return -ENODEV;
280} 279}
281 280
282static int __init idefloppy_init(void) 281static int __init ide_gd_init(void)
283{ 282{
284 printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n"); 283 printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
285 return driver_register(&idefloppy_driver.gen_driver); 284 return driver_register(&ide_gd_driver.gen_driver);
286} 285}
287 286
288static void __exit idefloppy_exit(void) 287static void __exit ide_gd_exit(void)
289{ 288{
290 driver_unregister(&idefloppy_driver.gen_driver); 289 driver_unregister(&ide_gd_driver.gen_driver);
291} 290}
292 291
293MODULE_ALIAS("ide:*m-floppy*"); 292MODULE_ALIAS("ide:*m-floppy*");
294MODULE_ALIAS("ide-floppy"); 293MODULE_ALIAS("ide-floppy");
295module_init(idefloppy_init); 294module_init(ide_gd_init);
296module_exit(idefloppy_exit); 295module_exit(ide_gd_exit);
297MODULE_LICENSE("GPL"); 296MODULE_LICENSE("GPL");
298MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); 297MODULE_DESCRIPTION("ATAPI FLOPPY Driver");