* [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers
@ 2010-12-20 12:45 Christoph Hellwig
2010-12-20 12:45 ` [Qemu-devel] [PATCH 2/3] ide: also reset io_buffer_index for writes Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2010-12-20 12:45 UTC (permalink / raw)
To: qemu-devel
Factor the DMA I/O path that is duplicated between read and write
commands, into common helpers using the s->is_read flag added for
the macio ATA controller.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: qemu/hw/ide/core.c
===================================================================
--- qemu.orig/hw/ide/core.c 2010-12-17 11:38:48.992003425 +0100
+++ qemu/hw/ide/core.c 2010-12-17 11:48:43.252255415 +0100
@@ -487,16 +487,18 @@ static int ide_handle_rw_error(IDEState
return 1;
}
-void ide_read_dma_cb(void *opaque, int ret)
+void ide_dma_cb(void *opaque, int ret)
{
IDEState *s = opaque;
int n;
int64_t sector_num;
if (ret < 0) {
- if (ide_handle_rw_error(s, -ret,
- BM_STATUS_DMA_RETRY | BM_STATUS_RETRY_READ))
- {
+ int op = BM_STATUS_DMA_RETRY;
+
+ if (s->is_read)
+ op |= BM_STATUS_RETRY_READ;
+ if (ide_handle_rw_error(s, -ret, op)) {
return;
}
}
@@ -504,7 +506,7 @@ void ide_read_dma_cb(void *opaque, int r
n = s->io_buffer_size >> 9;
sector_num = ide_get_sector(s);
if (n > 0) {
- dma_buf_commit(s, 1);
+ dma_buf_commit(s, s->is_read);
sector_num += n;
ide_set_sector(s, sector_num);
s->nsector -= n;
@@ -514,32 +516,44 @@ void ide_read_dma_cb(void *opaque, int r
if (s->nsector == 0) {
s->status = READY_STAT | SEEK_STAT;
ide_set_irq(s->bus);
- eot:
- s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_INT);
- ide_set_inactive(s);
- return;
+ goto eot;
}
/* launch next transfer */
n = s->nsector;
- s->io_buffer_index = 0;
+ if (s->is_read)
+ s->io_buffer_index = 0;
s->io_buffer_size = n * 512;
- if (s->bus->dma->ops->prepare_buf(s->bus->dma, 1) == 0)
+ if (s->bus->dma->ops->prepare_buf(s->bus->dma, s->is_read) == 0)
goto eot;
+
#ifdef DEBUG_AIO
- printf("aio_read: sector_num=%" PRId64 " n=%d\n", sector_num, n);
+ printf("ide_dma_cb: sector_num=%" PRId64 " n=%d, is_read=%d\n",
+ sector_num, n, s->is_read);
#endif
- s->bus->dma->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num, ide_read_dma_cb, s);
- ide_dma_submit_check(s, ide_read_dma_cb);
+
+ if (s->is_read) {
+ s->bus->dma->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num,
+ ide_dma_cb, s);
+ } else {
+ s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num,
+ ide_dma_cb, s);
+ }
+ ide_dma_submit_check(s, ide_dma_cb);
+ return;
+
+eot:
+ s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_INT);
+ ide_set_inactive(s);
}
-static void ide_sector_read_dma(IDEState *s)
+static void ide_sector_start_dma(IDEState *s, int is_read)
{
s->status = READY_STAT | SEEK_STAT | DRQ_STAT | BUSY_STAT;
s->io_buffer_index = 0;
s->io_buffer_size = 0;
- s->is_read = 1;
- s->bus->dma->ops->start_dma(s->bus->dma, s, ide_read_dma_cb);
+ s->is_read = is_read;
+ s->bus->dma->ops->start_dma(s->bus->dma, s, ide_dma_cb);
}
static void ide_sector_write_timer_cb(void *opaque)
@@ -594,57 +608,6 @@ void ide_sector_write(IDEState *s)
}
}
-void ide_write_dma_cb(void *opaque, int ret)
-{
- IDEState *s = opaque;
- int n;
- int64_t sector_num;
-
- if (ret < 0) {
- if (ide_handle_rw_error(s, -ret, BM_STATUS_DMA_RETRY))
- return;
- }
-
- n = s->io_buffer_size >> 9;
- sector_num = ide_get_sector(s);
- if (n > 0) {
- dma_buf_commit(s, 0);
- sector_num += n;
- ide_set_sector(s, sector_num);
- s->nsector -= n;
- }
-
- /* end of transfer ? */
- if (s->nsector == 0) {
- s->status = READY_STAT | SEEK_STAT;
- ide_set_irq(s->bus);
- eot:
- s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_INT);
- ide_set_inactive(s);
- return;
- }
-
- n = s->nsector;
- s->io_buffer_size = n * 512;
- /* launch next transfer */
- if (s->bus->dma->ops->prepare_buf(s->bus->dma, 0) == 0)
- goto eot;
-#ifdef DEBUG_AIO
- printf("aio_write: sector_num=%" PRId64 " n=%d\n", sector_num, n);
-#endif
- s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num, ide_write_dma_cb, s);
- ide_dma_submit_check(s, ide_write_dma_cb);
-}
-
-static void ide_sector_write_dma(IDEState *s)
-{
- s->status = READY_STAT | SEEK_STAT | DRQ_STAT | BUSY_STAT;
- s->io_buffer_index = 0;
- s->io_buffer_size = 0;
- s->is_read = 0;
- s->bus->dma->ops->start_dma(s->bus->dma, s, ide_write_dma_cb);
-}
-
void ide_atapi_cmd_ok(IDEState *s)
{
s->error = 0;
@@ -1858,7 +1821,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t
if (!s->bs)
goto abort_cmd;
ide_cmd_lba48_transform(s, lba48);
- ide_sector_read_dma(s);
+ ide_sector_start_dma(s, 1);
break;
case WIN_WRITEDMA_EXT:
lba48 = 1;
@@ -1867,7 +1830,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t
if (!s->bs)
goto abort_cmd;
ide_cmd_lba48_transform(s, lba48);
- ide_sector_write_dma(s);
+ ide_sector_start_dma(s, 0);
s->media_changed = 1;
break;
case WIN_READ_NATIVE_MAX_EXT:
Index: qemu/hw/ide/internal.h
===================================================================
--- qemu.orig/hw/ide/internal.h 2010-12-17 11:42:29.538004334 +0100
+++ qemu/hw/ide/internal.h 2010-12-17 11:48:05.464261142 +0100
@@ -439,7 +439,6 @@ struct IDEState {
uint32_t mdata_size;
uint8_t *mdata_storage;
int media_changed;
- /* for pmac */
int is_read;
/* SMART */
uint8_t smart_enabled;
@@ -560,8 +559,7 @@ void ide_init2_with_non_qdev_drives(IDEB
void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
void ide_exec_cmd(IDEBus *bus, uint32_t val);
-void ide_read_dma_cb(void *opaque, int ret);
-void ide_write_dma_cb(void *opaque, int ret);
+void ide_dma_cb(void *opaque, int ret);
void ide_sector_write(IDEState *s);
void ide_sector_read(IDEState *s);
void ide_flush_cache(IDEState *s);
Index: qemu/hw/ide/pci.c
===================================================================
--- qemu.orig/hw/ide/pci.c 2010-12-17 11:42:03.440254508 +0100
+++ qemu/hw/ide/pci.c 2010-12-17 11:42:23.998252692 +0100
@@ -178,14 +178,9 @@ static void bmdma_restart_dma(BMDMAState
s->io_buffer_index = 0;
s->io_buffer_size = 0;
s->nsector = bm->nsector;
+ s->is_read = is_read;
bm->cur_addr = bm->addr;
-
- if (is_read) {
- bm->dma_cb = ide_read_dma_cb;
- } else {
- bm->dma_cb = ide_write_dma_cb;
- }
-
+ bm->dma_cb = ide_dma_cb;
bmdma_start_dma(&bm->dma, s, bm->dma_cb);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 2/3] ide: also reset io_buffer_index for writes
2010-12-20 12:45 [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Christoph Hellwig
@ 2010-12-20 12:45 ` Christoph Hellwig
2010-12-20 12:46 ` [Qemu-devel] [PATCH 3/3] ide: kill ide_dma_submit_check Christoph Hellwig
2011-01-13 15:40 ` [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2010-12-20 12:45 UTC (permalink / raw)
To: qemu-devel
Currenly the code only resets the io_buffer_index field for reads,
but the code seems to expect this for all types of I/O. I guess
we simply don't hit large enough transfers that would require this
often enough.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: qemu/hw/ide/core.c
===================================================================
--- qemu.orig/hw/ide/core.c 2010-12-17 12:03:27.737004194 +0100
+++ qemu/hw/ide/core.c 2010-12-17 12:03:41.485004404 +0100
@@ -521,8 +521,7 @@ void ide_dma_cb(void *opaque, int ret)
/* launch next transfer */
n = s->nsector;
- if (s->is_read)
- s->io_buffer_index = 0;
+ s->io_buffer_index = 0;
s->io_buffer_size = n * 512;
if (s->bus->dma->ops->prepare_buf(s->bus->dma, s->is_read) == 0)
goto eot;
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 3/3] ide: kill ide_dma_submit_check
2010-12-20 12:45 [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Christoph Hellwig
2010-12-20 12:45 ` [Qemu-devel] [PATCH 2/3] ide: also reset io_buffer_index for writes Christoph Hellwig
@ 2010-12-20 12:46 ` Christoph Hellwig
2011-01-13 15:40 ` [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2010-12-20 12:46 UTC (permalink / raw)
To: qemu-devel
Merge ide_dma_submit_check into it's only caller. Also use tail recursion
using a goto instead of a real recursion - this avoid overflowing the
stack in the pathological situation of an recurring error that is ignored.
We'll still be busy looping in ide_dma_cb, but at least won't eat up
all stack space after this.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Index: qemu/hw/ide/core.c
===================================================================
--- qemu.orig/hw/ide/core.c 2010-12-20 13:16:11.379004054 +0100
+++ qemu/hw/ide/core.c 2010-12-20 13:16:11.000000000 +0100
@@ -321,14 +321,6 @@ static inline void ide_abort_command(IDE
s->error = ABRT_ERR;
}
-static inline void ide_dma_submit_check(IDEState *s,
- BlockDriverCompletionFunc *dma_cb)
-{
- if (s->bus->dma->aiocb)
- return;
- dma_cb(s, -1);
-}
-
/* prepare data transfer and tell what to do after */
static void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
EndTransferFunc *end_transfer_func)
@@ -493,6 +485,7 @@ void ide_dma_cb(void *opaque, int ret)
int n;
int64_t sector_num;
+handle_rw_error:
if (ret < 0) {
int op = BM_STATUS_DMA_RETRY;
@@ -538,7 +531,11 @@ void ide_dma_cb(void *opaque, int ret)
s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num,
ide_dma_cb, s);
}
- ide_dma_submit_check(s, ide_dma_cb);
+
+ if (!s->bus->dma->aiocb) {
+ ret = -1;
+ goto handle_rw_error;
+ }
return;
eot:
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers
2010-12-20 12:45 [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Christoph Hellwig
2010-12-20 12:45 ` [Qemu-devel] [PATCH 2/3] ide: also reset io_buffer_index for writes Christoph Hellwig
2010-12-20 12:46 ` [Qemu-devel] [PATCH 3/3] ide: kill ide_dma_submit_check Christoph Hellwig
@ 2011-01-13 15:40 ` Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2011-01-13 15:40 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: qemu-devel
Am 20.12.2010 13:45, schrieb Christoph Hellwig:
> Factor the DMA I/O path that is duplicated between read and write
> commands, into common helpers using the s->is_read flag added for
> the macio ATA controller.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Thanks, applied all to the block branch.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-01-13 15:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-20 12:45 [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Christoph Hellwig
2010-12-20 12:45 ` [Qemu-devel] [PATCH 2/3] ide: also reset io_buffer_index for writes Christoph Hellwig
2010-12-20 12:46 ` [Qemu-devel] [PATCH 3/3] ide: kill ide_dma_submit_check Christoph Hellwig
2011-01-13 15:40 ` [Qemu-devel] [PATCH 1/3] ide: factor dma handling helpers Kevin Wolf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.