aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-atapi.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:36 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:36 -0400
commitacaa0f5f675ccf6b8a3a11a933419068b1ea1f46 (patch)
tree8afee71c69bf765a5edd0de82c98c6470905ec20 /drivers/ide/ide-atapi.c
parentc860f955681ebd83df4a03089f1910fc4b54651f (diff)
ide: add ide_io_buffers() helper
* Make ->io_buffers method return number of bytes transferred. * Use ide_end_request() instead of idefloppy_end_request() in ide_floppy_io_buffers() and then move the call out to ide_pc_intr(). * Add ide_io_buffers() helper and convert ide-{floppy,scsi}.c to use it instead of ide*_io_buffers(). There should be no functional changes caused by this patch. Acked-by: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-atapi.c')
-rw-r--r--drivers/ide/ide-atapi.c63
1 files changed, 59 insertions, 4 deletions
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 61c52fb665ca..3d44b45650f6 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -61,12 +61,62 @@ int ide_check_atapi_device(ide_drive_t *drive, const char *s)
61} 61}
62EXPORT_SYMBOL_GPL(ide_check_atapi_device); 62EXPORT_SYMBOL_GPL(ide_check_atapi_device);
63 63
64/* PIO data transfer routine using the scatter gather table. */
65int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
66 unsigned int bcount, int write)
67{
68 ide_hwif_t *hwif = drive->hwif;
69 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
70 xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data;
71 struct scatterlist *sg = pc->sg;
72 char *buf;
73 int count, done = 0;
74
75 while (bcount) {
76 count = min(sg->length - pc->b_count, bcount);
77
78 if (PageHighMem(sg_page(sg))) {
79 unsigned long flags;
80
81 local_irq_save(flags);
82 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
83 xf(drive, NULL, buf + pc->b_count, count);
84 kunmap_atomic(buf - sg->offset, KM_IRQ0);
85 local_irq_restore(flags);
86 } else {
87 buf = sg_virt(sg);
88 xf(drive, NULL, buf + pc->b_count, count);
89 }
90
91 bcount -= count;
92 pc->b_count += count;
93 done += count;
94
95 if (pc->b_count == sg->length) {
96 if (!--pc->sg_cnt)
97 break;
98 pc->sg = sg = sg_next(sg);
99 pc->b_count = 0;
100 }
101 }
102
103 if (bcount) {
104 printk(KERN_ERR "%s: %d leftover bytes, %s\n", drive->name,
105 bcount, write ? "padding with zeros"
106 : "discarding data");
107 ide_pad_transfer(drive, write, bcount);
108 }
109
110 return done;
111}
112EXPORT_SYMBOL_GPL(ide_io_buffers);
113
64/* TODO: unify the code thus making some arguments go away */ 114/* TODO: unify the code thus making some arguments go away */
65ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, 115ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
66 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, 116 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
67 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), 117 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
68 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), 118 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
69 void (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int)) 119 int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
70{ 120{
71 ide_hwif_t *hwif = drive->hwif; 121 ide_hwif_t *hwif = drive->hwif;
72 struct request *rq = hwif->hwgroup->rq; 122 struct request *rq = hwif->hwgroup->rq;
@@ -219,9 +269,14 @@ cmd_finished:
219 269
220 if ((drive->media == ide_floppy && !scsi && !pc->buf) || 270 if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
221 (drive->media == ide_tape && !scsi && pc->bh) || 271 (drive->media == ide_tape && !scsi && pc->bh) ||
222 (scsi && pc->sg)) 272 (scsi && pc->sg)) {
223 io_buffers(drive, pc, bcount, !!(pc->flags & PC_FLAG_WRITING)); 273 int done = io_buffers(drive, pc, bcount,
224 else 274 !!(pc->flags & PC_FLAG_WRITING));
275
276 /* FIXME: don't do partial completions */
277 if (drive->media == ide_floppy && !scsi)
278 ide_end_request(drive, 1, done >> 9);
279 } else
225 xferfunc(drive, NULL, pc->cur_pos, bcount); 280 xferfunc(drive, NULL, pc->cur_pos, bcount);
226 281
227 /* Update the current position */ 282 /* Update the current position */