Skip to content

Commit

Permalink
ide: merge ->atapi_*put_bytes and ->ata_*put_data methods
Browse files Browse the repository at this point in the history
* Merge ->atapi_{in,out}put_bytes and ->ata_{in,out}put_data methods
  into new ->{in,out}put_data methods which take number of bytes to
  transfer as an argument and always do padding.

While at it:

* Use 'hwif' or 'drive->hwif' instead of 'HWIF(drive)'.

There should be no functional changes caused by this patch (all users
of ->ata_{in,out}put_data methods were using multiply-of-4 word counts).

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
  • Loading branch information
Bartlomiej Zolnierkiewicz committed Apr 28, 2008
1 parent 92d3ab2 commit 9567b34
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 172 deletions.
52 changes: 15 additions & 37 deletions drivers/ide/cris/ide-cris.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,8 @@ cris_ide_inb(unsigned long reg)
return (unsigned char)cris_ide_inw(reg);
}

static void cris_ide_input_data(ide_drive_t *, struct request *,
void *, unsigned int);
static void cris_ide_output_data(ide_drive_t *, struct request *,
void *, unsigned int);
static void cris_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int);
static void cris_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int);
static void cris_input_data(ide_drive_t *, struct request *, void *, unsigned);
static void cris_output_data(ide_drive_t *, struct request *, void *, unsigned);

static void cris_dma_host_set(ide_drive_t *drive, int on)
{
Expand Down Expand Up @@ -816,10 +812,9 @@ static int __init init_e100_ide(void)
ide_init_port_data(hwif, hwif->index);
ide_init_port_hw(hwif, &hw);

hwif->ata_input_data = &cris_ide_input_data;
hwif->ata_output_data = &cris_ide_output_data;
hwif->atapi_input_bytes = &cris_atapi_input_bytes;
hwif->atapi_output_bytes = &cris_atapi_output_bytes;
hwif->input_data = cris_input_data;
hwif->output_data = cris_output_data;

hwif->OUTB = &cris_ide_outb;
hwif->OUTW = &cris_ide_outw;
hwif->OUTBSYNC = &cris_ide_outbsync;
Expand Down Expand Up @@ -849,17 +844,16 @@ static int __init init_e100_ide(void)
static cris_dma_descr_type mydescr __attribute__ ((__aligned__(16)));

/*
* The following routines are mainly used by the ATAPI drivers.
* This is used for most PIO data transfers *from* the IDE interface
*
* These routines will round up any request for an odd number of bytes,
* so if an odd bytecount is specified, be sure that there's at least one
* extra byte allocated for the buffer.
*/
static void
cris_atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount)
static void cris_input_data(ide_drive_t *drive, struct request *rq,
void *buffer, unsigned int bytecount)
{
D(printk("atapi_input_bytes, buffer 0x%x, count %d\n",
buffer, bytecount));
D(printk("input_data, buffer 0x%x, count %d\n", buffer, bytecount));

if(bytecount & 1) {
printk("warning, odd bytecount in cdrom_in_bytes = %d.\n", bytecount);
Expand All @@ -877,11 +871,13 @@ cris_atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount
LED_DISK_READ(0);
}

static void
cris_atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount)
/*
* This is used for most PIO data transfers *to* the IDE interface
*/
static void cris_output_data(ide_drive_t *drive, struct request *rq,
void *buffer, unsigned int bytecount)
{
D(printk("atapi_output_bytes, buffer 0x%x, count %d\n",
buffer, bytecount));
D(printk("output_data, buffer 0x%x, count %d\n", buffer, bytecount));

if(bytecount & 1) {
printk("odd bytecount %d in atapi_out_bytes!\n", bytecount);
Expand All @@ -899,24 +895,6 @@ cris_atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecoun
LED_DISK_WRITE(0);
}

/*
* This is used for most PIO data transfers *from* the IDE interface
*/
static void cris_ide_input_data(ide_drive_t *drive, struct request *rq,
void *buffer, unsigned int wcount)
{
cris_atapi_input_bytes(drive, buffer, wcount << 2);
}

/*
* This is used for most PIO data transfers *to* the IDE interface
*/
static void cris_ide_output_data(ide_drive_t *drive, struct request *,
void *buffer, unsigned int wcount)
{
cris_atapi_output_bytes(drive, buffer, wcount << 2);
}

/* we only have one DMA channel on the chip for ATA, so we can keep these statically */
static cris_dma_descr_type ata_descrs[MAX_DMA_DESCRS] __attribute__ ((__aligned__(16)));
static unsigned int ata_tot_size;
Expand Down
14 changes: 7 additions & 7 deletions drivers/ide/ide-cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
cmd_len = ATAPI_MIN_CDB_BYTES;

/* send the command to the device */
HWIF(drive)->atapi_output_bytes(drive, rq->cmd, cmd_len);
hwif->output_data(drive, NULL, rq->cmd, cmd_len);

/* start the DMA if need be */
if (info->dma)
Expand All @@ -629,7 +629,7 @@ static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len)
{
while (len > 0) {
int dum = 0;
xf(drive, &dum, sizeof(dum));
xf(drive, NULL, &dum, sizeof(dum));
len -= sizeof(dum);
}
}
Expand All @@ -639,7 +639,7 @@ static void ide_cd_drain_data(ide_drive_t *drive, int nsects)
while (nsects > 0) {
static char dum[SECTOR_SIZE];

drive->hwif->atapi_input_bytes(drive, dum, sizeof(dum));
drive->hwif->input_data(drive, NULL, dum, sizeof(dum));
nsects--;
}
}
Expand All @@ -666,7 +666,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
drive->name, __func__);

xf = rw ? hwif->atapi_output_bytes : hwif->atapi_input_bytes;
xf = rw ? hwif->output_data : hwif->input_data;
ide_cd_pad_transfer(drive, xf, len);
} else if (rw == 0 && ireason == 1) {
/*
Expand Down Expand Up @@ -1019,10 +1019,10 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)

if (ireason == 0) {
write = 1;
xferfunc = HWIF(drive)->atapi_output_bytes;
xferfunc = hwif->output_data;
} else {
write = 0;
xferfunc = HWIF(drive)->atapi_input_bytes;
xferfunc = hwif->input_data;
}

/* transfer data */
Expand Down Expand Up @@ -1061,7 +1061,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
if (blen > thislen)
blen = thislen;

xferfunc(drive, ptr, blen);
xferfunc(drive, NULL, ptr, blen);

thislen -= blen;
len -= blen;
Expand Down
18 changes: 11 additions & 7 deletions drivers/ide/ide-floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
unsigned int bcount, int direction)
{
ide_hwif_t *hwif = drive->hwif;
struct request *rq = pc->rq;
struct req_iterator iter;
struct bio_vec *bvec;
Expand All @@ -246,9 +247,9 @@ static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,

data = bvec_kmap_irq(bvec, &flags);
if (direction)
drive->hwif->atapi_output_bytes(drive, data, count);
hwif->output_data(drive, NULL, data, count);
else
drive->hwif->atapi_input_bytes(drive, data, count);
hwif->input_data(drive, NULL, data, count);
bvec_kunmap_irq(data, &flags);

bcount -= count;
Expand Down Expand Up @@ -503,12 +504,12 @@ static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
}
}
if (pc->flags & PC_FLAG_WRITING)
xferfunc = hwif->atapi_output_bytes;
xferfunc = hwif->output_data;
else
xferfunc = hwif->atapi_input_bytes;
xferfunc = hwif->input_data;

if (pc->buf)
xferfunc(drive, pc->cur_pos, bcount);
xferfunc(drive, NULL, pc->cur_pos, bcount);
else
ide_floppy_io_buffers(drive, pc, bcount,
!!(pc->flags & PC_FLAG_WRITING));
Expand Down Expand Up @@ -548,8 +549,10 @@ static ide_startstop_t idefloppy_transfer_pc(ide_drive_t *drive)

/* Set the interrupt routine */
ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);

/* Send the actual packet */
HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
hwif->output_data(drive, NULL, floppy->pc->c, 12);

return ide_started;
}

Expand All @@ -569,7 +572,8 @@ static int idefloppy_transfer_pc2(ide_drive_t *drive)
idefloppy_floppy_t *floppy = drive->driver_data;

/* Send the actual packet */
HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
drive->hwif->output_data(drive, NULL, floppy->pc->c, 12);

/* Timeout for the packet command */
return IDEFLOPPY_WAIT_CMD;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/ide/ide-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ static void try_to_flush_leftover_data (ide_drive_t *drive)
u32 wcount = (i > 16) ? 16 : i;

i -= wcount;
drive->hwif->ata_input_data(drive, NULL, buffer, wcount);
drive->hwif->input_data(drive, NULL, buffer, wcount * 4);
}
}

Expand Down
68 changes: 25 additions & 43 deletions drivers/ide/ide-iops.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,47 @@ static void ata_vlb_sync(ide_drive_t *drive, unsigned long port)

/*
* This is used for most PIO data transfers *from* the IDE interface
*
* These routines will round up any request for an odd number of bytes,
* so if an odd len is specified, be sure that there's at least one
* extra byte allocated for the buffer.
*/
static void ata_input_data(ide_drive_t *drive, struct request *rq,
void *buffer, u32 wcount)
void *buf, unsigned int len)
{
ide_hwif_t *hwif = drive->hwif;
struct ide_io_ports *io_ports = &hwif->io_ports;
unsigned long data_addr = io_ports->data_addr;
u8 io_32bit = drive->io_32bit;

len++;

if (io_32bit) {
if (io_32bit & 2) {
unsigned long flags;

local_irq_save(flags);
ata_vlb_sync(drive, io_ports->nsect_addr);
hwif->INSL(io_ports->data_addr, buffer, wcount);
hwif->INSL(data_addr, buf, len / 4);
local_irq_restore(flags);
} else
hwif->INSL(io_ports->data_addr, buffer, wcount);
hwif->INSL(data_addr, buf, len / 4);

if ((len & 3) >= 2)
hwif->INSW(data_addr, (u8 *)buf + (len & ~3), 1);
} else
hwif->INSW(io_ports->data_addr, buffer, wcount << 1);
hwif->INSW(data_addr, buf, len / 2);
}

/*
* This is used for most PIO data transfers *to* the IDE interface
*/
static void ata_output_data(ide_drive_t *drive, struct request *rq,
void *buffer, u32 wcount)
void *buf, unsigned int len)
{
ide_hwif_t *hwif = drive->hwif;
struct ide_io_ports *io_ports = &hwif->io_ports;
unsigned long data_addr = io_ports->data_addr;
u8 io_32bit = drive->io_32bit;

if (io_32bit) {
Expand All @@ -229,50 +240,21 @@ static void ata_output_data(ide_drive_t *drive, struct request *rq,

local_irq_save(flags);
ata_vlb_sync(drive, io_ports->nsect_addr);
hwif->OUTSL(io_ports->data_addr, buffer, wcount);
hwif->OUTSL(data_addr, buf, len / 4);
local_irq_restore(flags);
} else
hwif->OUTSL(io_ports->data_addr, buffer, wcount);
} else
hwif->OUTSW(io_ports->data_addr, buffer, wcount << 1);
}

/*
* The following routines are mainly used by the ATAPI drivers.
*
* These routines will round up any request for an odd number of bytes,
* so if an odd bytecount is specified, be sure that there's at least one
* extra byte allocated for the buffer.
*/

static void atapi_input_bytes(ide_drive_t *drive, void *buffer, u32 bytecount)
{
ide_hwif_t *hwif = HWIF(drive);
hwif->OUTSL(data_addr, buf, len / 4);

++bytecount;
hwif->ata_input_data(drive, NULL, buffer, bytecount / 4);
if ((bytecount & 0x03) >= 2)
hwif->INSW(hwif->io_ports.data_addr,
(u8 *)buffer + (bytecount & ~0x03), 1);
}

static void atapi_output_bytes(ide_drive_t *drive, void *buffer, u32 bytecount)
{
ide_hwif_t *hwif = HWIF(drive);

++bytecount;
hwif->ata_output_data(drive, NULL, buffer, bytecount / 4);
if ((bytecount & 0x03) >= 2)
hwif->OUTSW(hwif->io_ports.data_addr,
(u8 *)buffer + (bytecount & ~0x03), 1);
if ((len & 3) >= 2)
hwif->OUTSW(data_addr, (u8 *)buf + (len & ~3), 1);
} else
hwif->OUTSW(data_addr, buf, len / 2);
}

void default_hwif_transport(ide_hwif_t *hwif)
{
hwif->ata_input_data = ata_input_data;
hwif->ata_output_data = ata_output_data;
hwif->atapi_input_bytes = atapi_input_bytes;
hwif->atapi_output_bytes = atapi_output_bytes;
hwif->input_data = ata_input_data;
hwif->output_data = ata_output_data;
}

void ide_fix_driveid (struct hd_driveid *id)
Expand Down Expand Up @@ -656,7 +638,7 @@ int ide_driveid_update(ide_drive_t *drive)
local_irq_restore(flags);
return 0;
}
hwif->ata_input_data(drive, NULL, id, SECTOR_WORDS);
hwif->input_data(drive, NULL, id, SECTOR_SIZE);
(void)ide_read_status(drive); /* clear drive IRQ */
local_irq_enable();
local_irq_restore(flags);
Expand Down
2 changes: 1 addition & 1 deletion drivers/ide/ide-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)

id = drive->id;
/* read 512 bytes of id info */
hwif->ata_input_data(drive, NULL, id, SECTOR_WORDS);
hwif->input_data(drive, NULL, id, SECTOR_SIZE);

drive->id_read = 1;
local_irq_enable();
Expand Down
13 changes: 7 additions & 6 deletions drivers/ide/ide-tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static void idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
count = min(
(unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
bcount);
HWIF(drive)->atapi_input_bytes(drive, bh->b_data +
drive->hwif->input_data(drive, NULL, bh->b_data +
atomic_read(&bh->b_count), count);
bcount -= count;
atomic_add(count, &bh->b_count);
Expand All @@ -427,7 +427,7 @@ static void idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
return;
}
count = min((unsigned int)pc->b_count, (unsigned int)bcount);
HWIF(drive)->atapi_output_bytes(drive, pc->b_data, count);
drive->hwif->output_data(drive, NULL, pc->b_data, count);
bcount -= count;
pc->b_data += count;
pc->b_count -= count;
Expand Down Expand Up @@ -880,16 +880,16 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
"data than expected - allowing transfer\n");
}
iobuf = &idetape_input_buffers;
xferfunc = hwif->atapi_input_bytes;
xferfunc = hwif->input_data;
} else {
iobuf = &idetape_output_buffers;
xferfunc = hwif->atapi_output_bytes;
xferfunc = hwif->output_data;
}

if (pc->bh)
iobuf(drive, pc, bcount);
else
xferfunc(drive, pc->cur_pos, bcount);
xferfunc(drive, NULL, pc->cur_pos, bcount);

/* Update the current position */
pc->xferred += bcount;
Expand Down Expand Up @@ -979,7 +979,8 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
hwif->dma_ops->dma_start(drive);
#endif
/* Send the actual packet */
HWIF(drive)->atapi_output_bytes(drive, pc->c, 12);
hwif->output_data(drive, NULL, pc->c, 12);

return ide_started;
}

Expand Down
Loading

0 comments on commit 9567b34

Please sign in to comment.