From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwzQN-0002JE-Oh for qemu-devel@nongnu.org; Mon, 13 Feb 2012 12:10:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RwzQG-000572-Rt for qemu-devel@nongnu.org; Mon, 13 Feb 2012 12:10:47 -0500 Received: from mail-pz0-f45.google.com ([209.85.210.45]:45129) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwzQG-00055Q-JA for qemu-devel@nongnu.org; Mon, 13 Feb 2012 12:10:40 -0500 Received: by mail-pz0-f45.google.com with SMTP id p14so5365383dad.4 for ; Mon, 13 Feb 2012 09:10:40 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 13 Feb 2012 18:10:09 +0100 Message-Id: <1329153022-31159-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1329153022-31159-1-git-send-email-pbonzini@redhat.com> References: <1329153022-31159-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v3 02/15] dma-helpers: add dma_buf_read and dma_buf_write List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@gmail.com, christian.hoff@de.ibm.com, kvm@vger.kernel.org These helpers do a full transfer from an in-memory buffer to target memory, with support for scatter/gather lists. It will be used to store the reply of an emulated command into a QEMUSGList provided by the adapter. Signed-off-by: Paolo Bonzini --- dma-helpers.c | 30 ++++++++++++++++++++++++++++++ dma.h | 3 +++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/dma-helpers.c b/dma-helpers.c index f08cdb5..f53a51f 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -204,3 +204,33 @@ BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs, { return dma_bdrv_io(bs, sg, sector, bdrv_aio_writev, cb, opaque, true); } + + +static uint64_t dma_buf_rw(uint8_t *ptr, int32_t len, QEMUSGList *sg, bool to_dev) +{ + uint64_t resid; + int sg_cur_index; + + resid = sg->size; + sg_cur_index = 0; + len = MIN(len, resid); + while (len > 0) { + ScatterGatherEntry entry = sg->sg[sg_cur_index++]; + cpu_physical_memory_rw(entry.base, ptr, MIN(len, entry.len), !to_dev); + ptr += entry.len; + len -= entry.len; + resid -= entry.len; + } + + return resid; +} + +uint64_t dma_buf_read(uint8_t *ptr, int32_t len, QEMUSGList *sg) +{ + return dma_buf_rw(ptr, len, sg, 0); +} + +uint64_t dma_buf_write(uint8_t *ptr, int32_t len, QEMUSGList *sg) +{ + return dma_buf_rw(ptr, len, sg, 1); +} diff --git a/dma.h b/dma.h index d50019b..346ac4f 100644 --- a/dma.h +++ b/dma.h @@ -58,4 +58,7 @@ BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs, BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs, QEMUSGList *sg, uint64_t sector, BlockDriverCompletionFunc *cb, void *opaque); +uint64_t dma_buf_read(uint8_t *ptr, int32_t len, QEMUSGList *sg); +uint64_t dma_buf_write(uint8_t *ptr, int32_t len, QEMUSGList *sg); + #endif -- 1.7.7.6