Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 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" |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 18 | #include "ide-floppy.h" |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 19 | |
| 20 | #define IDE_GD_VERSION "1.18" |
| 21 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 22 | /* module parameters */ |
| 23 | static unsigned long debug_mask; |
| 24 | module_param(debug_mask, ulong, 0644); |
| 25 | |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 26 | static DEFINE_MUTEX(ide_disk_ref_mutex); |
| 27 | |
| 28 | static void ide_disk_release(struct kref *); |
| 29 | |
| 30 | static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) |
| 31 | { |
| 32 | struct ide_disk_obj *idkp = NULL; |
| 33 | |
| 34 | mutex_lock(&ide_disk_ref_mutex); |
| 35 | idkp = ide_drv_g(disk, ide_disk_obj); |
| 36 | if (idkp) { |
| 37 | if (ide_device_get(idkp->drive)) |
| 38 | idkp = NULL; |
| 39 | else |
| 40 | kref_get(&idkp->kref); |
| 41 | } |
| 42 | mutex_unlock(&ide_disk_ref_mutex); |
| 43 | return idkp; |
| 44 | } |
| 45 | |
| 46 | static void ide_disk_put(struct ide_disk_obj *idkp) |
| 47 | { |
| 48 | ide_drive_t *drive = idkp->drive; |
| 49 | |
| 50 | mutex_lock(&ide_disk_ref_mutex); |
| 51 | kref_put(&idkp->kref, ide_disk_release); |
| 52 | ide_device_put(drive); |
| 53 | mutex_unlock(&ide_disk_ref_mutex); |
| 54 | } |
| 55 | |
| 56 | sector_t ide_gd_capacity(ide_drive_t *drive) |
| 57 | { |
| 58 | return drive->capacity64; |
| 59 | } |
| 60 | |
| 61 | static int ide_gd_probe(ide_drive_t *); |
| 62 | |
| 63 | static void ide_gd_remove(ide_drive_t *drive) |
| 64 | { |
| 65 | struct ide_disk_obj *idkp = drive->driver_data; |
| 66 | struct gendisk *g = idkp->disk; |
| 67 | |
| 68 | ide_proc_unregister_driver(drive, idkp->driver); |
| 69 | |
| 70 | del_gendisk(g); |
| 71 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 72 | drive->disk_ops->flush(drive); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 73 | |
| 74 | ide_disk_put(idkp); |
| 75 | } |
| 76 | |
| 77 | static void ide_disk_release(struct kref *kref) |
| 78 | { |
| 79 | struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj); |
| 80 | ide_drive_t *drive = idkp->drive; |
| 81 | struct gendisk *g = idkp->disk; |
| 82 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 83 | drive->disk_ops = NULL; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 84 | drive->driver_data = NULL; |
| 85 | g->private_data = NULL; |
| 86 | put_disk(g); |
| 87 | kfree(idkp); |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * On HPA drives the capacity needs to be |
| 92 | * reinitilized on resume otherwise the disk |
| 93 | * can not be used and a hard reset is required |
| 94 | */ |
| 95 | static void ide_gd_resume(ide_drive_t *drive) |
| 96 | { |
| 97 | if (ata_id_hpa_enabled(drive->id)) |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 98 | (void)drive->disk_ops->get_capacity(drive); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void ide_gd_shutdown(ide_drive_t *drive) |
| 102 | { |
| 103 | #ifdef CONFIG_ALPHA |
| 104 | /* On Alpha, halt(8) doesn't actually turn the machine off, |
| 105 | it puts you into the sort of firmware monitor. Typically, |
| 106 | it's used to boot another kernel image, so it's not much |
| 107 | different from reboot(8). Therefore, we don't need to |
| 108 | spin down the disk in this case, especially since Alpha |
| 109 | firmware doesn't handle disks in standby mode properly. |
| 110 | On the other hand, it's reasonably safe to turn the power |
| 111 | off when the shutdown process reaches the firmware prompt, |
| 112 | as the firmware initialization takes rather long time - |
| 113 | at least 10 seconds, which should be sufficient for |
| 114 | the disk to expire its write cache. */ |
| 115 | if (system_state != SYSTEM_POWER_OFF) { |
| 116 | #else |
| 117 | if (system_state == SYSTEM_RESTART) { |
| 118 | #endif |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 119 | drive->disk_ops->flush(drive); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 120 | return; |
| 121 | } |
| 122 | |
| 123 | printk(KERN_INFO "Shutdown: %s\n", drive->name); |
| 124 | |
| 125 | drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND); |
| 126 | } |
| 127 | |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 128 | #ifdef CONFIG_IDE_PROC_FS |
| 129 | static ide_proc_entry_t *ide_disk_proc_entries(ide_drive_t *drive) |
| 130 | { |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 131 | return (drive->media == ide_disk) ? ide_disk_proc : ide_floppy_proc; |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static const struct ide_proc_devset *ide_disk_proc_devsets(ide_drive_t *drive) |
| 135 | { |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 136 | return (drive->media == ide_disk) ? ide_disk_settings |
| 137 | : ide_floppy_settings; |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 138 | } |
| 139 | #endif |
| 140 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 141 | static ide_startstop_t ide_gd_do_request(ide_drive_t *drive, |
| 142 | struct request *rq, sector_t sector) |
| 143 | { |
| 144 | return drive->disk_ops->do_request(drive, rq, sector); |
| 145 | } |
| 146 | |
| 147 | static int ide_gd_end_request(ide_drive_t *drive, int uptodate, int nrsecs) |
| 148 | { |
| 149 | return drive->disk_ops->end_request(drive, uptodate, nrsecs); |
| 150 | } |
| 151 | |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 152 | static ide_driver_t ide_gd_driver = { |
| 153 | .gen_driver = { |
| 154 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 155 | .name = "ide-gd", |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 156 | .bus = &ide_bus_type, |
| 157 | }, |
| 158 | .probe = ide_gd_probe, |
| 159 | .remove = ide_gd_remove, |
| 160 | .resume = ide_gd_resume, |
| 161 | .shutdown = ide_gd_shutdown, |
| 162 | .version = IDE_GD_VERSION, |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 163 | .do_request = ide_gd_do_request, |
| 164 | .end_request = ide_gd_end_request, |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 165 | .error = __ide_error, |
| 166 | #ifdef CONFIG_IDE_PROC_FS |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 167 | .proc_entries = ide_disk_proc_entries, |
| 168 | .proc_devsets = ide_disk_proc_devsets, |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 169 | #endif |
| 170 | }; |
| 171 | |
| 172 | static int ide_gd_open(struct inode *inode, struct file *filp) |
| 173 | { |
| 174 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 175 | struct ide_disk_obj *idkp; |
| 176 | ide_drive_t *drive; |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 177 | int ret = 0; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 178 | |
| 179 | idkp = ide_disk_get(disk); |
| 180 | if (idkp == NULL) |
| 181 | return -ENXIO; |
| 182 | |
| 183 | drive = idkp->drive; |
| 184 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 185 | ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); |
| 186 | |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 187 | idkp->openers++; |
| 188 | |
| 189 | if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) { |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 190 | drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS; |
| 191 | /* Just in case */ |
| 192 | |
| 193 | ret = drive->disk_ops->init_media(drive, disk); |
| 194 | |
| 195 | /* |
| 196 | * Allow O_NDELAY to open a drive without a disk, or with an |
| 197 | * unreadable disk, so that we can get the format capacity |
| 198 | * of the drive or begin the format - Sam |
| 199 | */ |
| 200 | if (ret && (filp->f_flags & O_NDELAY) == 0) { |
| 201 | ret = -EIO; |
| 202 | goto out_put_idkp; |
| 203 | } |
| 204 | |
| 205 | if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) { |
| 206 | ret = -EROFS; |
| 207 | goto out_put_idkp; |
| 208 | } |
| 209 | |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 210 | /* |
| 211 | * Ignore the return code from door_lock, |
| 212 | * since the open() has already succeeded, |
| 213 | * and the door_lock is irrelevant at this point. |
| 214 | */ |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 215 | drive->disk_ops->set_doorlock(drive, disk, 1); |
Bartlomiej Zolnierkiewicz | cedd120 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 216 | drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 217 | check_disk_change(inode->i_bdev); |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 218 | } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) { |
| 219 | ret = -EBUSY; |
| 220 | goto out_put_idkp; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 221 | } |
| 222 | return 0; |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 223 | |
| 224 | out_put_idkp: |
| 225 | idkp->openers--; |
| 226 | ide_disk_put(idkp); |
| 227 | return ret; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int ide_gd_release(struct inode *inode, struct file *filp) |
| 231 | { |
| 232 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 233 | struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); |
| 234 | ide_drive_t *drive = idkp->drive; |
| 235 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 236 | ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 237 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 238 | if (idkp->openers == 1) |
| 239 | drive->disk_ops->flush(drive); |
| 240 | |
| 241 | if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) { |
| 242 | drive->disk_ops->set_doorlock(drive, disk, 0); |
| 243 | drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS; |
| 244 | } |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 245 | |
| 246 | idkp->openers--; |
| 247 | |
| 248 | ide_disk_put(idkp); |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int ide_gd_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 254 | { |
| 255 | struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj); |
| 256 | ide_drive_t *drive = idkp->drive; |
| 257 | |
| 258 | geo->heads = drive->bios_head; |
| 259 | geo->sectors = drive->bios_sect; |
| 260 | geo->cylinders = (u16)drive->bios_cyl; /* truncate */ |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | static int ide_gd_media_changed(struct gendisk *disk) |
| 265 | { |
| 266 | struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); |
| 267 | ide_drive_t *drive = idkp->drive; |
Bartlomiej Zolnierkiewicz | cedd120 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 268 | int ret; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 269 | |
| 270 | /* do not scan partitions twice if this is a removable device */ |
| 271 | if (drive->dev_flags & IDE_DFLAG_ATTACH) { |
| 272 | drive->dev_flags &= ~IDE_DFLAG_ATTACH; |
| 273 | return 0; |
| 274 | } |
| 275 | |
Bartlomiej Zolnierkiewicz | cedd120 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 276 | ret = !!(drive->dev_flags & IDE_DFLAG_MEDIA_CHANGED); |
| 277 | drive->dev_flags &= ~IDE_DFLAG_MEDIA_CHANGED; |
| 278 | |
| 279 | return ret; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static int ide_gd_revalidate_disk(struct gendisk *disk) |
| 283 | { |
| 284 | struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); |
| 285 | set_capacity(disk, ide_gd_capacity(idkp->drive)); |
| 286 | return 0; |
| 287 | } |
| 288 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 289 | static int ide_gd_ioctl(struct inode *inode, struct file *file, |
| 290 | unsigned int cmd, unsigned long arg) |
| 291 | { |
| 292 | struct block_device *bdev = inode->i_bdev; |
| 293 | struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj); |
| 294 | ide_drive_t *drive = idkp->drive; |
| 295 | |
| 296 | return drive->disk_ops->ioctl(drive, inode, file, cmd, arg); |
| 297 | } |
| 298 | |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 299 | static struct block_device_operations ide_gd_ops = { |
| 300 | .owner = THIS_MODULE, |
| 301 | .open = ide_gd_open, |
| 302 | .release = ide_gd_release, |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 303 | .ioctl = ide_gd_ioctl, |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 304 | .getgeo = ide_gd_getgeo, |
| 305 | .media_changed = ide_gd_media_changed, |
| 306 | .revalidate_disk = ide_gd_revalidate_disk |
| 307 | }; |
| 308 | |
| 309 | static int ide_gd_probe(ide_drive_t *drive) |
| 310 | { |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 311 | const struct ide_disk_ops *disk_ops = NULL; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 312 | struct ide_disk_obj *idkp; |
| 313 | struct gendisk *g; |
| 314 | |
| 315 | /* strstr("foo", "") is non-NULL */ |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 316 | if (!strstr("ide-gd", drive->driver_req)) |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 317 | goto failed; |
| 318 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 319 | #ifdef CONFIG_IDE_GD_ATA |
| 320 | if (drive->media == ide_disk) |
| 321 | disk_ops = &ide_ata_disk_ops; |
| 322 | #endif |
| 323 | #ifdef CONFIG_IDE_GD_ATAPI |
| 324 | if (drive->media == ide_floppy) |
| 325 | disk_ops = &ide_atapi_disk_ops; |
| 326 | #endif |
| 327 | if (disk_ops == NULL) |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 328 | goto failed; |
| 329 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 330 | if (disk_ops->check(drive, DRV_NAME) == 0) { |
| 331 | printk(KERN_ERR PFX "%s: not supported by this driver\n", |
| 332 | drive->name); |
| 333 | goto failed; |
| 334 | } |
| 335 | |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 336 | idkp = kzalloc(sizeof(*idkp), GFP_KERNEL); |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 337 | if (!idkp) { |
| 338 | printk(KERN_ERR PFX "%s: can't allocate a disk structure\n", |
| 339 | drive->name); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 340 | goto failed; |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 341 | } |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 342 | |
| 343 | g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif)); |
| 344 | if (!g) |
| 345 | goto out_free_idkp; |
| 346 | |
| 347 | ide_init_disk(g, drive); |
| 348 | |
| 349 | kref_init(&idkp->kref); |
| 350 | |
| 351 | idkp->drive = drive; |
| 352 | idkp->driver = &ide_gd_driver; |
| 353 | idkp->disk = g; |
| 354 | |
| 355 | g->private_data = &idkp->driver; |
| 356 | |
| 357 | drive->driver_data = idkp; |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 358 | drive->debug_mask = debug_mask; |
| 359 | drive->disk_ops = disk_ops; |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 360 | |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 361 | disk_ops->setup(drive); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 362 | |
| 363 | set_capacity(g, ide_gd_capacity(drive)); |
| 364 | |
| 365 | g->minors = IDE_DISK_MINORS; |
| 366 | g->driverfs_dev = &drive->gendev; |
| 367 | g->flags |= GENHD_FL_EXT_DEVT; |
| 368 | if (drive->dev_flags & IDE_DFLAG_REMOVABLE) |
| 369 | g->flags = GENHD_FL_REMOVABLE; |
| 370 | g->fops = &ide_gd_ops; |
| 371 | add_disk(g); |
| 372 | return 0; |
| 373 | |
| 374 | out_free_idkp: |
| 375 | kfree(idkp); |
| 376 | failed: |
| 377 | return -ENODEV; |
| 378 | } |
| 379 | |
| 380 | static int __init ide_gd_init(void) |
| 381 | { |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 382 | printk(KERN_INFO DRV_NAME " driver " IDE_GD_VERSION "\n"); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 383 | return driver_register(&ide_gd_driver.gen_driver); |
| 384 | } |
| 385 | |
| 386 | static void __exit ide_gd_exit(void) |
| 387 | { |
| 388 | driver_unregister(&ide_gd_driver.gen_driver); |
| 389 | } |
| 390 | |
| 391 | MODULE_ALIAS("ide:*m-disk*"); |
| 392 | MODULE_ALIAS("ide-disk"); |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 393 | MODULE_ALIAS("ide:*m-floppy*"); |
| 394 | MODULE_ALIAS("ide-floppy"); |
Bartlomiej Zolnierkiewicz | 5fef0e5 | 2008-10-17 18:09:12 +0200 | [diff] [blame] | 395 | module_init(ide_gd_init); |
| 396 | module_exit(ide_gd_exit); |
| 397 | MODULE_LICENSE("GPL"); |
Bartlomiej Zolnierkiewicz | 806f80a | 2008-10-17 18:09:14 +0200 | [diff] [blame^] | 398 | MODULE_DESCRIPTION("generic ATA/ATAPI disk driver"); |