From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>
Subject: [Qemu-devel] [PATCH 4/4] Convert IDE to use new dma helpers
Date: Wed, 4 Feb 2009 14:25:14 +0200 [thread overview]
Message-ID: <1233750314-23301-5-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1233750314-23301-1-git-send-email-avi@redhat.com>
Use the new dma block helpers to perform dma disk I/O.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
hw/ide.c | 76 ++++++++-----------------------------------------------------
1 files changed, 10 insertions(+), 66 deletions(-)
diff --git a/hw/ide.c b/hw/ide.c
index bcaee46..1db0bcd 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -33,6 +33,7 @@
#include "ppc_mac.h"
#include "mac_dbdma.h"
#include "sh.h"
+#include "dma.h"
/* debug IDE devices */
//#define DEBUG_IDE
@@ -423,7 +424,7 @@ typedef struct IDEState {
int atapi_dma; /* true if dma is requested for the packet cmd */
/* ATA DMA state */
int io_buffer_size;
- QEMUIOVector iovec;
+ QEMUSGList sg;
/* PIO transfer handling */
int req_nb_sectors; /* number of sectors per interrupt */
EndTransferFunc *end_transfer_func;
@@ -876,10 +877,8 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
uint32_t size;
} prd;
int l, len;
- void *mem;
- target_phys_addr_t l1;
- qemu_iovec_init(&s->iovec, s->nsector / (TARGET_PAGE_SIZE/512) + 1);
+ qemu_sglist_init(&s->sg, s->nsector / (TARGET_PAGE_SIZE/512) + 1);
s->io_buffer_size = 0;
for(;;) {
if (bm->cur_prd_len == 0) {
@@ -900,15 +899,10 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
}
l = bm->cur_prd_len;
if (l > 0) {
- l1 = l;
- mem = cpu_physical_memory_map(bm->cur_prd_addr, &l1, is_write);
- if (!mem) {
- break;
- }
- qemu_iovec_add(&s->iovec, mem, l1);
- bm->cur_prd_addr += l1;
- bm->cur_prd_len -= l1;
- s->io_buffer_size += l1;
+ qemu_sglist_add(&s->sg, bm->cur_prd_addr, l);
+ bm->cur_prd_addr += l;
+ bm->cur_prd_len -= l;
+ s->io_buffer_size += l;
}
}
return 1;
@@ -916,14 +910,7 @@ static int dma_buf_prepare(BMDMAState *bm, int is_write)
static void dma_buf_commit(IDEState *s, int is_write)
{
- int i;
-
- for (i = 0; i < s->iovec.niov; ++i) {
- cpu_physical_memory_unmap(s->iovec.iov[i].iov_base,
- s->iovec.iov[i].iov_len, is_write,
- s->iovec.iov[i].iov_len);
- }
- qemu_iovec_destroy(&s->iovec);
+ qemu_sglist_destroy(&s->sg);
}
static void ide_dma_error(IDEState *s)
@@ -1006,39 +993,6 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
return 1;
}
-typedef struct {
- BMDMAState *bm;
- void (*cb)(void *opaque, int ret);
- QEMUBH *bh;
-} MapFailureContinuation;
-
-static void reschedule_dma(void *opaque)
-{
- MapFailureContinuation *cont = opaque;
-
- cont->cb(cont->bm, 0);
- qemu_bh_delete(cont->bh);
- qemu_free(cont);
-}
-
-static void continue_after_map_failure(void *opaque)
-{
- MapFailureContinuation *cont = opaque;
-
- cont->bh = qemu_bh_new(reschedule_dma, opaque);
- qemu_bh_schedule(cont->bh);
-}
-
-static void wait_for_bounce_buffer(BMDMAState *bmdma,
- void (*cb)(void *opaque, int ret))
-{
- MapFailureContinuation *cont = qemu_malloc(sizeof(*cont));
-
- cont->bm = bmdma;
- cont->cb = cb;
- cpu_register_map_client(cont, continue_after_map_failure);
-}
-
static void ide_read_dma_cb(void *opaque, int ret)
{
BMDMAState *bm = opaque;
@@ -1080,15 +1034,10 @@ static void ide_read_dma_cb(void *opaque, int ret)
s->io_buffer_size = n * 512;
if (dma_buf_prepare(bm, 1) == 0)
goto eot;
- if (!s->iovec.niov) {
- wait_for_bounce_buffer(bm, ide_read_dma_cb);
- return;
- }
#ifdef DEBUG_AIO
printf("aio_read: sector_num=%" PRId64 " n=%d\n", sector_num, n);
#endif
- bm->aiocb = bdrv_aio_readv(s->bs, sector_num, &s->iovec, n,
- ide_read_dma_cb, bm);
+ bm->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num, ide_read_dma_cb, bm);
ide_dma_submit_check(s, ide_read_dma_cb, bm);
}
@@ -1209,15 +1158,10 @@ static void ide_write_dma_cb(void *opaque, int ret)
/* launch next transfer */
if (dma_buf_prepare(bm, 0) == 0)
goto eot;
- if (!s->iovec.niov) {
- wait_for_bounce_buffer(bm, ide_write_dma_cb);
- return;
- }
#ifdef DEBUG_AIO
printf("aio_write: sector_num=%" PRId64 " n=%d\n", sector_num, n);
#endif
- bm->aiocb = bdrv_aio_writev(s->bs, sector_num, &s->iovec, n,
- ide_write_dma_cb, bm);
+ bm->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num, ide_write_dma_cb, bm);
ide_dma_submit_check(s, ide_write_dma_cb, bm);
}
--
1.6.1.1
next prev parent reply other threads:[~2009-02-04 12:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-04 12:25 [Qemu-devel] [PATCH 0/4] Block DMA helpers Avi Kivity
2009-02-04 12:25 ` [Qemu-devel] [PATCH 1/4] Add a scatter-gather list type and accessors Avi Kivity
2009-02-04 19:27 ` [Qemu-devel] " Anthony Liguori
2009-02-04 20:30 ` Avi Kivity
2009-02-04 20:36 ` Anthony Liguori
2009-02-04 20:46 ` Avi Kivity
2009-02-04 20:50 ` Anthony Liguori
2009-02-04 21:03 ` Avi Kivity
2009-02-04 23:58 ` Paul Brook
2009-02-05 7:25 ` Avi Kivity
2009-02-05 0:29 ` M. Warner Losh
2009-02-05 1:56 ` Anthony Liguori
2009-02-04 23:49 ` Paul Brook
2009-02-04 12:25 ` [Qemu-devel] [PATCH 2/4] Add qemu_iovec_reset() Avi Kivity
2009-02-04 12:25 ` [Qemu-devel] [PATCH 3/4] Introduce block dma helpers Avi Kivity
2009-02-04 19:29 ` [Qemu-devel] " Anthony Liguori
2009-02-04 12:25 ` Avi Kivity [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-02-05 9:33 [Qemu-devel] [PATCH 0/4] Block DMA helpers (v2) Avi Kivity
2009-02-05 9:33 ` [Qemu-devel] [PATCH 4/4] Convert IDE to use new dma helpers Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1233750314-23301-5-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).