Skip to content

Commit

Permalink
ide: add generic ATA/ATAPI disk driver
Browse files Browse the repository at this point in the history
* Add struct ide_disk_ops containing protocol specific methods.

* Add 'struct ide_disk_ops *' to ide_drive_t.

* Convert ide-{disk,floppy} drivers to use struct ide_disk_ops.

* Merge ide-{disk,floppy} drivers into generic ide-gd driver.

While at it:
- ide_disk_init_capacity() -> ide_disk_get_capacity()

Acked-by: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
  • Loading branch information
Bartlomiej Zolnierkiewicz committed Oct 17, 2008
1 parent 79cb380 commit 806f80a
Show file tree
Hide file tree
Showing 13 changed files with 303 additions and 455 deletions.
64 changes: 30 additions & 34 deletions drivers/ide/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,40 @@ config BLK_DEV_IDE_SATA

If unsure, say N.

config BLK_DEV_IDEDISK
tristate "Include IDE/ATA-2 DISK support"
---help---
This will include enhanced support for MFM/RLL/IDE hard disks. If
you have a MFM/RLL/IDE disk, and there is no special reason to use
the old hard disk driver instead, say Y. If you have an SCSI-only
system, you can say N here.
config IDE_GD
tristate "generic ATA/ATAPI disk support"
default y
help
Support for ATA/ATAPI disks (including ATAPI floppy drives).

To compile this driver as a module, choose M here: the
module will be called ide-disk.
Do not compile this driver as a module if your root file system
(the one containing the directory /) is located on the IDE disk.
To compile this driver as a module, choose M here.
The module will be called ide-gd_mod.

If unsure, say Y.

config IDE_GD_ATA
bool "ATA disk support"
depends on IDE_GD
default y
help
This will include support for ATA hard disks.

If unsure, say Y.

config IDE_GD_ATAPI
bool "ATAPI floppy support"
depends on IDE_GD
select IDE_ATAPI
help
This will include support for ATAPI floppy drives
(i.e. Iomega ZIP or MKE LS-120).

For information about jumper settings and the question
of when a ZIP drive uses a partition table, see
<http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>.

If unsure, say N.

config BLK_DEV_IDECS
tristate "PCMCIA IDE support"
depends on PCMCIA
Expand Down Expand Up @@ -163,29 +182,6 @@ config BLK_DEV_IDETAPE
To compile this driver as a module, choose M here: the
module will be called ide-tape.

config BLK_DEV_IDEFLOPPY
tristate "Include IDE/ATAPI FLOPPY support"
select IDE_ATAPI
---help---
If you have an IDE floppy drive which uses the ATAPI protocol,
answer Y. ATAPI is a newer protocol used by IDE CD-ROM/tape/floppy
drives, similar to the SCSI protocol.

The LS-120 and the IDE/ATAPI Iomega ZIP drive are also supported by
this driver. For information about jumper settings and the question
of when a ZIP drive uses a partition table, see
<http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>.
(ATAPI PD-CD/CDR drives are not supported by this driver; support
for PD-CD/CDR drives is available if you answer Y to
"SCSI emulation support", below).

If you say Y here, the FLOPPY drive will be identified along with
other IDE devices, as "hdb" or "hdc", or something similar (check
the boot messages with dmesg).

To compile this driver as a module, choose M here: the
module will be called ide-floppy.

config BLK_DEV_IDESCSI
tristate "SCSI emulation support (DEPRECATED)"
depends on SCSI
Expand Down
19 changes: 13 additions & 6 deletions drivers/ide/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,25 @@ obj-$(CONFIG_IDE_H8300) += h8300/
obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o

ide-disk_mod-y += ide-gd.o ide-disk.o ide-disk_ioctl.o
ide-gd_mod-y += ide-gd.o
ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
ide-floppy_mod-y += ide-gd-floppy.o ide-floppy.o ide-floppy_ioctl.o

ifeq ($(CONFIG_IDE_GD_ATA), y)
ide-gd_mod-y += ide-disk.o ide-disk_ioctl.o
ifeq ($(CONFIG_IDE_PROC_FS), y)
ide-disk_mod-y += ide-disk_proc.o
ide-floppy_mod-y += ide-floppy_proc.o
ide-gd_mod-y += ide-disk_proc.o
endif
endif

ifeq ($(CONFIG_IDE_GD_ATAPI), y)
ide-gd_mod-y += ide-floppy.o ide-floppy_ioctl.o
ifeq ($(CONFIG_IDE_PROC_FS), y)
ide-gd_mod-y += ide-floppy_proc.o
endif
endif

obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk_mod.o
obj-$(CONFIG_IDE_GD) += ide-gd_mod.o
obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o
obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o

ifeq ($(CONFIG_BLK_DEV_IDECS), y)
Expand Down
39 changes: 32 additions & 7 deletions drivers/ide/ide-disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
* 1073741822 == 549756 MB or 48bit addressing fake drive
*/

ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
sector_t block)
static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
sector_t block)
{
ide_hwif_t *hwif = HWIF(drive);

Expand Down Expand Up @@ -333,7 +333,7 @@ static void idedisk_check_hpa(ide_drive_t *drive)
}
}

void ide_disk_init_capacity(ide_drive_t *drive)
static int ide_disk_get_capacity(ide_drive_t *drive)
{
u16 *id = drive->id;
int lba;
Expand Down Expand Up @@ -382,6 +382,8 @@ void ide_disk_init_capacity(ide_drive_t *drive)
} else
drive->dev_flags &= ~IDE_DFLAG_LBA48;
}

return 0;
}

static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
Expand Down Expand Up @@ -590,7 +592,12 @@ ide_ext_devset_rw(wcache, wcache);

ide_ext_devset_rw_sync(nowerr, nowerr);

void ide_disk_setup(ide_drive_t *drive)
static int ide_disk_check(ide_drive_t *drive, const char *s)
{
return 1;
}

static void ide_disk_setup(ide_drive_t *drive)
{
struct ide_disk_obj *idkp = drive->driver_data;
ide_hwif_t *hwif = drive->hwif;
Expand Down Expand Up @@ -626,7 +633,7 @@ void ide_disk_setup(ide_drive_t *drive)
drive->queue->max_sectors / 2);

/* calculate drive capacity, and select LBA if possible */
ide_disk_init_capacity(drive);
ide_disk_get_capacity(drive);

/*
* if possible, give fdisk access to more of the drive,
Expand Down Expand Up @@ -682,7 +689,7 @@ void ide_disk_setup(ide_drive_t *drive)
drive->dev_flags |= IDE_DFLAG_ATTACH;
}

void ide_disk_flush(ide_drive_t *drive)
static void ide_disk_flush(ide_drive_t *drive)
{
if (ata_id_flush_enabled(drive->id) == 0 ||
(drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
Expand All @@ -692,7 +699,13 @@ void ide_disk_flush(ide_drive_t *drive)
printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
}

int ide_disk_set_doorlock(ide_drive_t *drive, int on)
static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
{
return 0;
}

static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
int on)
{
ide_task_t task;
int ret;
Expand All @@ -711,3 +724,15 @@ int ide_disk_set_doorlock(ide_drive_t *drive, int on)

return ret;
}

const struct ide_disk_ops ide_ata_disk_ops = {
.check = ide_disk_check,
.get_capacity = ide_disk_get_capacity,
.setup = ide_disk_setup,
.flush = ide_disk_flush,
.init_media = ide_disk_init_media,
.set_doorlock = ide_disk_set_doorlock,
.do_request = ide_do_rw_disk,
.end_request = ide_end_request,
.ioctl = ide_disk_ioctl,
};
24 changes: 9 additions & 15 deletions drivers/ide/ide-disk.h
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
#ifndef __IDE_DISK_H
#define __IDE_DISK_H

struct ide_disk_obj {
ide_drive_t *drive;
ide_driver_t *driver;
struct gendisk *disk;
struct kref kref;
unsigned int openers; /* protected by BKL for now */
};

sector_t ide_gd_capacity(ide_drive_t *);
#include "ide-gd.h"

#ifdef CONFIG_IDE_GD_ATA
/* ide-disk.c */
void ide_disk_init_capacity(ide_drive_t *);
void ide_disk_setup(ide_drive_t *);
void ide_disk_flush(ide_drive_t *);
int ide_disk_set_doorlock(ide_drive_t *, int);
ide_startstop_t ide_do_rw_disk(ide_drive_t *, struct request *, sector_t);
extern const struct ide_disk_ops ide_ata_disk_ops;
ide_decl_devset(address);
ide_decl_devset(multcount);
ide_decl_devset(nowerr);
ide_decl_devset(wcache);
ide_decl_devset(acoustic);

/* ide-disk_ioctl.c */
int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
int ide_disk_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int,
unsigned long);

#ifdef CONFIG_IDE_PROC_FS
/* ide-disk_proc.c */
extern ide_proc_entry_t ide_disk_proc[];
extern const struct ide_proc_devset ide_disk_settings[];
#endif
#else
#define ide_disk_proc NULL
#define ide_disk_settings NULL
#endif

#endif /* __IDE_DISK_H */
4 changes: 1 addition & 3 deletions drivers/ide/ide-disk_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
{ 0 }
};

int ide_disk_ioctl(struct inode *inode, struct file *file,
int ide_disk_ioctl(ide_drive_t *drive, struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct block_device *bdev = inode->i_bdev;
struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
int err;

err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
Expand Down
45 changes: 37 additions & 8 deletions drivers/ide/ide-floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
* Used to finish servicing a request. For read/write requests, we will call
* ide_end_request to pass to the next buffer.
*/
int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
{
idefloppy_floppy_t *floppy = drive->driver_data;
struct request *rq = HWGROUP(drive)->rq;
Expand Down Expand Up @@ -280,13 +280,12 @@ static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
pc->req_xfer = pc->buf_size = rq->data_len;
}

ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, struct request *rq,
sector_t block_s)
static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
struct request *rq, sector_t block)
{
idefloppy_floppy_t *floppy = drive->driver_data;
ide_hwif_t *hwif = drive->hwif;
struct ide_atapi_pc *pc;
unsigned long block = (unsigned long)block_s;

ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
"errors: %d\n",
Expand Down Expand Up @@ -316,7 +315,7 @@ ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, struct request *rq,
return ide_stopped;
}
pc = &floppy->queued_pc;
idefloppy_create_rw_cmd(drive, pc, rq, block);
idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
} else if (blk_special_request(rq)) {
pc = (struct ide_atapi_pc *) rq->buffer;
} else if (blk_pc_request(rq)) {
Expand Down Expand Up @@ -406,7 +405,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
* Determine if a media is present in the floppy drive, and if so, its LBA
* capacity.
*/
int ide_floppy_get_capacity(ide_drive_t *drive)
static int ide_floppy_get_capacity(ide_drive_t *drive)
{
idefloppy_floppy_t *floppy = drive->driver_data;
struct gendisk *disk = floppy->disk;
Expand Down Expand Up @@ -505,9 +504,9 @@ int ide_floppy_get_capacity(ide_drive_t *drive)
return rc;
}

void ide_floppy_setup(ide_drive_t *drive)
static void ide_floppy_setup(ide_drive_t *drive)
{
struct ide_floppy_obj *floppy = drive->driver_data;
struct ide_disk_obj *floppy = drive->driver_data;
u16 *id = drive->id;

drive->pc_callback = ide_floppy_callback;
Expand Down Expand Up @@ -547,3 +546,33 @@ void ide_floppy_setup(ide_drive_t *drive)

drive->dev_flags |= IDE_DFLAG_ATTACH;
}

static void ide_floppy_flush(ide_drive_t *drive)
{
}

static int ide_floppy_init_media(ide_drive_t *drive, struct gendisk *disk)
{
int ret = 0;

if (ide_do_test_unit_ready(drive, disk))
ide_do_start_stop(drive, disk, 1);

ret = ide_floppy_get_capacity(drive);

set_capacity(disk, ide_gd_capacity(drive));

return ret;
}

const struct ide_disk_ops ide_atapi_disk_ops = {
.check = ide_check_atapi_device,
.get_capacity = ide_floppy_get_capacity,
.setup = ide_floppy_setup,
.flush = ide_floppy_flush,
.init_media = ide_floppy_init_media,
.set_doorlock = ide_set_media_lock,
.do_request = ide_floppy_do_request,
.end_request = ide_floppy_end_request,
.ioctl = ide_floppy_ioctl,
};
Loading

0 comments on commit 806f80a

Please sign in to comment.