blob: 70ea8763567dcc7b1b7fd946275dea49303534f6 [file] [log] [blame]
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +02001#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>
Bruno Prémontb0aedb02009-04-22 20:33:41 +020010#include <linux/dmi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020012
13#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
14#define IDE_DISK_MINORS (1 << PARTN_BITS)
15#else
16#define IDE_DISK_MINORS 0
17#endif
18
19#include "ide-disk.h"
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +020020#include "ide-floppy.h"
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020021
22#define IDE_GD_VERSION "1.18"
23
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +020024/* module parameters */
Arnd Bergmann2a48fc02010-06-02 14:28:52 +020025static DEFINE_MUTEX(ide_gd_mutex);
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +020026static unsigned long debug_mask;
27module_param(debug_mask, ulong, 0644);
28
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020029static DEFINE_MUTEX(ide_disk_ref_mutex);
30
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010031static void ide_disk_release(struct device *);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020032
33static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
34{
35 struct ide_disk_obj *idkp = NULL;
36
37 mutex_lock(&ide_disk_ref_mutex);
38 idkp = ide_drv_g(disk, ide_disk_obj);
39 if (idkp) {
40 if (ide_device_get(idkp->drive))
41 idkp = NULL;
42 else
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010043 get_device(&idkp->dev);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020044 }
45 mutex_unlock(&ide_disk_ref_mutex);
46 return idkp;
47}
48
49static void ide_disk_put(struct ide_disk_obj *idkp)
50{
51 ide_drive_t *drive = idkp->drive;
52
53 mutex_lock(&ide_disk_ref_mutex);
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010054 put_device(&idkp->dev);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020055 ide_device_put(drive);
56 mutex_unlock(&ide_disk_ref_mutex);
57}
58
59sector_t ide_gd_capacity(ide_drive_t *drive)
60{
61 return drive->capacity64;
62}
63
64static int ide_gd_probe(ide_drive_t *);
65
66static void ide_gd_remove(ide_drive_t *drive)
67{
68 struct ide_disk_obj *idkp = drive->driver_data;
69 struct gendisk *g = idkp->disk;
70
71 ide_proc_unregister_driver(drive, idkp->driver);
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010072 device_del(&idkp->dev);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020073 del_gendisk(g);
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +020074 drive->disk_ops->flush(drive);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020075
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010076 mutex_lock(&ide_disk_ref_mutex);
77 put_device(&idkp->dev);
78 mutex_unlock(&ide_disk_ref_mutex);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020079}
80
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010081static void ide_disk_release(struct device *dev)
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020082{
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +010083 struct ide_disk_obj *idkp = to_ide_drv(dev, ide_disk_obj);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020084 ide_drive_t *drive = idkp->drive;
85 struct gendisk *g = idkp->disk;
86
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +020087 drive->disk_ops = NULL;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020088 drive->driver_data = NULL;
89 g->private_data = NULL;
90 put_disk(g);
91 kfree(idkp);
92}
93
94/*
95 * On HPA drives the capacity needs to be
Uwe Kleine-König421f91d2010-06-11 12:17:00 +020096 * reinitialized on resume otherwise the disk
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +020097 * can not be used and a hard reset is required
98 */
99static void ide_gd_resume(ide_drive_t *drive)
100{
101 if (ata_id_hpa_enabled(drive->id))
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200102 (void)drive->disk_ops->get_capacity(drive);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200103}
104
Bruno Prémontb0aedb02009-04-22 20:33:41 +0200105static const struct dmi_system_id ide_coldreboot_table[] = {
106 {
107 /* Acer TravelMate 66x cuts power during reboot */
108 .ident = "Acer TravelMate 660",
109 .matches = {
110 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
111 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 660"),
112 },
113 },
114
115 { } /* terminate list */
116};
117
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200118static void ide_gd_shutdown(ide_drive_t *drive)
119{
120#ifdef CONFIG_ALPHA
121 /* On Alpha, halt(8) doesn't actually turn the machine off,
122 it puts you into the sort of firmware monitor. Typically,
123 it's used to boot another kernel image, so it's not much
124 different from reboot(8). Therefore, we don't need to
125 spin down the disk in this case, especially since Alpha
126 firmware doesn't handle disks in standby mode properly.
127 On the other hand, it's reasonably safe to turn the power
128 off when the shutdown process reaches the firmware prompt,
129 as the firmware initialization takes rather long time -
130 at least 10 seconds, which should be sufficient for
131 the disk to expire its write cache. */
132 if (system_state != SYSTEM_POWER_OFF) {
133#else
Bruno Prémontb0aedb02009-04-22 20:33:41 +0200134 if (system_state == SYSTEM_RESTART &&
135 !dmi_check_system(ide_coldreboot_table)) {
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200136#endif
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200137 drive->disk_ops->flush(drive);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200138 return;
139 }
140
141 printk(KERN_INFO "Shutdown: %s\n", drive->name);
142
143 drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
144}
145
Bartlomiej Zolnierkiewicz79cb3802008-10-17 18:09:13 +0200146#ifdef CONFIG_IDE_PROC_FS
147static ide_proc_entry_t *ide_disk_proc_entries(ide_drive_t *drive)
148{
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200149 return (drive->media == ide_disk) ? ide_disk_proc : ide_floppy_proc;
Bartlomiej Zolnierkiewicz79cb3802008-10-17 18:09:13 +0200150}
151
152static const struct ide_proc_devset *ide_disk_proc_devsets(ide_drive_t *drive)
153{
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200154 return (drive->media == ide_disk) ? ide_disk_settings
155 : ide_floppy_settings;
Bartlomiej Zolnierkiewicz79cb3802008-10-17 18:09:13 +0200156}
157#endif
158
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200159static ide_startstop_t ide_gd_do_request(ide_drive_t *drive,
160 struct request *rq, sector_t sector)
161{
162 return drive->disk_ops->do_request(drive, rq, sector);
163}
164
Bartlomiej Zolnierkiewicz7f3c8682009-01-06 17:20:53 +0100165static struct ide_driver ide_gd_driver = {
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200166 .gen_driver = {
167 .owner = THIS_MODULE,
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200168 .name = "ide-gd",
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200169 .bus = &ide_bus_type,
170 },
171 .probe = ide_gd_probe,
172 .remove = ide_gd_remove,
173 .resume = ide_gd_resume,
174 .shutdown = ide_gd_shutdown,
175 .version = IDE_GD_VERSION,
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200176 .do_request = ide_gd_do_request,
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200177#ifdef CONFIG_IDE_PROC_FS
Bartlomiej Zolnierkiewicz79cb3802008-10-17 18:09:13 +0200178 .proc_entries = ide_disk_proc_entries,
179 .proc_devsets = ide_disk_proc_devsets,
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200180#endif
181};
182
Al Virob2f21e02008-10-16 10:34:00 -0400183static int ide_gd_open(struct block_device *bdev, fmode_t mode)
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200184{
Al Virob2f21e02008-10-16 10:34:00 -0400185 struct gendisk *disk = bdev->bd_disk;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200186 struct ide_disk_obj *idkp;
187 ide_drive_t *drive;
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200188 int ret = 0;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200189
190 idkp = ide_disk_get(disk);
191 if (idkp == NULL)
192 return -ENXIO;
193
194 drive = idkp->drive;
195
Borislav Petkov088b1b82009-01-02 13:34:47 +0100196 ide_debug_log(IDE_DBG_FUNC, "enter");
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200197
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200198 idkp->openers++;
199
200 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200201 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
202 /* Just in case */
203
204 ret = drive->disk_ops->init_media(drive, disk);
205
206 /*
207 * Allow O_NDELAY to open a drive without a disk, or with an
208 * unreadable disk, so that we can get the format capacity
209 * of the drive or begin the format - Sam
210 */
Al Virob2f21e02008-10-16 10:34:00 -0400211 if (ret && (mode & FMODE_NDELAY) == 0) {
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200212 ret = -EIO;
213 goto out_put_idkp;
214 }
215
Al Virob2f21e02008-10-16 10:34:00 -0400216 if ((drive->dev_flags & IDE_DFLAG_WP) && (mode & FMODE_WRITE)) {
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200217 ret = -EROFS;
218 goto out_put_idkp;
219 }
220
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200221 /*
222 * Ignore the return code from door_lock,
223 * since the open() has already succeeded,
224 * and the door_lock is irrelevant at this point.
225 */
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200226 drive->disk_ops->set_doorlock(drive, disk, 1);
Bartlomiej Zolnierkiewiczcedd1202008-10-17 18:09:12 +0200227 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
Al Virob2f21e02008-10-16 10:34:00 -0400228 check_disk_change(bdev);
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200229 } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
230 ret = -EBUSY;
231 goto out_put_idkp;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200232 }
233 return 0;
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200234
235out_put_idkp:
236 idkp->openers--;
237 ide_disk_put(idkp);
238 return ret;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200239}
240
Arnd Bergmann6e9624b2010-08-07 18:25:34 +0200241static int ide_gd_unlocked_open(struct block_device *bdev, fmode_t mode)
242{
243 int ret;
244
Arnd Bergmann2a48fc02010-06-02 14:28:52 +0200245 mutex_lock(&ide_gd_mutex);
Arnd Bergmann6e9624b2010-08-07 18:25:34 +0200246 ret = ide_gd_open(bdev, mode);
Arnd Bergmann2a48fc02010-06-02 14:28:52 +0200247 mutex_unlock(&ide_gd_mutex);
Arnd Bergmann6e9624b2010-08-07 18:25:34 +0200248
249 return ret;
250}
251
252
Al Virob2f21e02008-10-16 10:34:00 -0400253static int ide_gd_release(struct gendisk *disk, fmode_t mode)
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200254{
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200255 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
256 ide_drive_t *drive = idkp->drive;
257
Borislav Petkov088b1b82009-01-02 13:34:47 +0100258 ide_debug_log(IDE_DBG_FUNC, "enter");
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200259
Arnd Bergmann2a48fc02010-06-02 14:28:52 +0200260 mutex_lock(&ide_gd_mutex);
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200261 if (idkp->openers == 1)
262 drive->disk_ops->flush(drive);
263
264 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
265 drive->disk_ops->set_doorlock(drive, disk, 0);
266 drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS;
267 }
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200268
269 idkp->openers--;
270
271 ide_disk_put(idkp);
Arnd Bergmann2a48fc02010-06-02 14:28:52 +0200272 mutex_unlock(&ide_gd_mutex);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200273
274 return 0;
275}
276
277static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
278{
279 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
280 ide_drive_t *drive = idkp->drive;
281
282 geo->heads = drive->bios_head;
283 geo->sectors = drive->bios_sect;
284 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
285 return 0;
286}
287
Tejun Heo5b03a1b2011-03-09 19:54:27 +0100288static unsigned int ide_gd_check_events(struct gendisk *disk,
289 unsigned int clearing)
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200290{
291 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
292 ide_drive_t *drive = idkp->drive;
Tejun Heo5b03a1b2011-03-09 19:54:27 +0100293 bool ret;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200294
295 /* do not scan partitions twice if this is a removable device */
296 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
297 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
298 return 0;
299 }
300
Tejun Heo7eec77a2011-04-21 19:43:59 +0200301 /*
302 * The following is used to force revalidation on the first open on
303 * removeable devices, and never gets reported to userland as
304 * genhd->events is 0. This is intended as removeable ide disk
305 * can't really detect MEDIA_CHANGE events.
306 */
Tejun Heo5b03a1b2011-03-09 19:54:27 +0100307 ret = drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED;
Bartlomiej Zolnierkiewiczcedd1202008-10-17 18:09:12 +0200308 drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED;
309
Tejun Heo5b03a1b2011-03-09 19:54:27 +0100310 return ret ? DISK_EVENT_MEDIA_CHANGE : 0;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200311}
312
Tejun Heoc3e33e02010-05-15 20:09:29 +0200313static void ide_gd_unlock_native_capacity(struct gendisk *disk)
Bartlomiej Zolnierkiewicze957b602009-06-07 13:52:52 +0200314{
315 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
316 ide_drive_t *drive = idkp->drive;
317 const struct ide_disk_ops *disk_ops = drive->disk_ops;
318
Tejun Heoc3e33e02010-05-15 20:09:29 +0200319 if (disk_ops->unlock_native_capacity)
320 disk_ops->unlock_native_capacity(drive);
Bartlomiej Zolnierkiewicze957b602009-06-07 13:52:52 +0200321}
322
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200323static int ide_gd_revalidate_disk(struct gendisk *disk)
324{
325 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
Borislav Petkov52ebb432008-11-02 21:40:10 +0100326 ide_drive_t *drive = idkp->drive;
327
Tejun Heo5b03a1b2011-03-09 19:54:27 +0100328 if (ide_gd_check_events(disk, 0))
Borislav Petkov52ebb432008-11-02 21:40:10 +0100329 drive->disk_ops->get_capacity(drive);
330
331 set_capacity(disk, ide_gd_capacity(drive));
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200332 return 0;
333}
334
Al Virob2f21e02008-10-16 10:34:00 -0400335static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode,
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200336 unsigned int cmd, unsigned long arg)
337{
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200338 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
339 ide_drive_t *drive = idkp->drive;
340
Al Virob2f21e02008-10-16 10:34:00 -0400341 return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg);
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200342}
343
Alexey Dobriyan83d5cde2009-09-21 17:01:13 -0700344static const struct block_device_operations ide_gd_ops = {
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200345 .owner = THIS_MODULE,
Arnd Bergmann6e9624b2010-08-07 18:25:34 +0200346 .open = ide_gd_unlocked_open,
Al Virob2f21e02008-10-16 10:34:00 -0400347 .release = ide_gd_release,
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +0200348 .ioctl = ide_gd_ioctl,
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200349 .getgeo = ide_gd_getgeo,
Tejun Heo5b03a1b2011-03-09 19:54:27 +0100350 .check_events = ide_gd_check_events,
Tejun Heoc3e33e02010-05-15 20:09:29 +0200351 .unlock_native_capacity = ide_gd_unlock_native_capacity,
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200352 .revalidate_disk = ide_gd_revalidate_disk
353};
354
355static int ide_gd_probe(ide_drive_t *drive)
356{
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200357 const struct ide_disk_ops *disk_ops = NULL;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200358 struct ide_disk_obj *idkp;
359 struct gendisk *g;
360
361 /* strstr("foo", "") is non-NULL */
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200362 if (!strstr("ide-gd", drive->driver_req))
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200363 goto failed;
364
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200365#ifdef CONFIG_IDE_GD_ATA
366 if (drive->media == ide_disk)
367 disk_ops = &ide_ata_disk_ops;
368#endif
369#ifdef CONFIG_IDE_GD_ATAPI
370 if (drive->media == ide_floppy)
371 disk_ops = &ide_atapi_disk_ops;
372#endif
373 if (disk_ops == NULL)
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200374 goto failed;
375
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200376 if (disk_ops->check(drive, DRV_NAME) == 0) {
377 printk(KERN_ERR PFX "%s: not supported by this driver\n",
378 drive->name);
379 goto failed;
380 }
381
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200382 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200383 if (!idkp) {
384 printk(KERN_ERR PFX "%s: can't allocate a disk structure\n",
385 drive->name);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200386 goto failed;
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200387 }
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200388
389 g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif));
390 if (!g)
391 goto out_free_idkp;
392
393 ide_init_disk(g, drive);
394
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +0100395 idkp->dev.parent = &drive->gendev;
396 idkp->dev.release = ide_disk_release;
397 dev_set_name(&idkp->dev, dev_name(&drive->gendev));
398
399 if (device_register(&idkp->dev))
400 goto out_free_disk;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200401
402 idkp->drive = drive;
403 idkp->driver = &ide_gd_driver;
404 idkp->disk = g;
405
406 g->private_data = &idkp->driver;
407
408 drive->driver_data = idkp;
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200409 drive->debug_mask = debug_mask;
410 drive->disk_ops = disk_ops;
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200411
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200412 disk_ops->setup(drive);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200413
414 set_capacity(g, ide_gd_capacity(drive));
415
416 g->minors = IDE_DISK_MINORS;
417 g->driverfs_dev = &drive->gendev;
418 g->flags |= GENHD_FL_EXT_DEVT;
419 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
420 g->flags = GENHD_FL_REMOVABLE;
421 g->fops = &ide_gd_ops;
422 add_disk(g);
423 return 0;
424
Bartlomiej Zolnierkiewicz8fed4362009-02-25 20:28:24 +0100425out_free_disk:
426 put_disk(g);
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200427out_free_idkp:
428 kfree(idkp);
429failed:
430 return -ENODEV;
431}
432
433static int __init ide_gd_init(void)
434{
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200435 printk(KERN_INFO DRV_NAME " driver " IDE_GD_VERSION "\n");
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200436 return driver_register(&ide_gd_driver.gen_driver);
437}
438
439static void __exit ide_gd_exit(void)
440{
441 driver_unregister(&ide_gd_driver.gen_driver);
442}
443
444MODULE_ALIAS("ide:*m-disk*");
445MODULE_ALIAS("ide-disk");
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200446MODULE_ALIAS("ide:*m-floppy*");
447MODULE_ALIAS("ide-floppy");
Bartlomiej Zolnierkiewicz5fef0e52008-10-17 18:09:12 +0200448module_init(ide_gd_init);
449module_exit(ide_gd_exit);
450MODULE_LICENSE("GPL");
Bartlomiej Zolnierkiewicz806f80a2008-10-17 18:09:14 +0200451MODULE_DESCRIPTION("generic ATA/ATAPI disk driver");