From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUnQ8-0000b1-VJ for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:28:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUnQ6-0000aR-If for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:28:23 -0500 Received: from [199.232.76.173] (port=45300 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUnQ6-0000aO-BQ for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:28:22 -0500 Received: from e32.co.us.ibm.com ([32.97.110.150]:46265) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LUnQ5-0005j6-TP for qemu-devel@nongnu.org; Wed, 04 Feb 2009 14:28:22 -0500 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e32.co.us.ibm.com (8.13.1/8.13.1) with ESMTP id n14JQ3r5011648 for ; Wed, 4 Feb 2009 12:26:03 -0700 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id n14JRxu4027660 for ; Wed, 4 Feb 2009 12:28:03 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n14JRw3T027136 for ; Wed, 4 Feb 2009 12:27:58 -0700 Message-ID: <4989EC29.9050705@us.ibm.com> Date: Wed, 04 Feb 2009 13:27:37 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1233750314-23301-1-git-send-email-avi@redhat.com> <1233750314-23301-2-git-send-email-avi@redhat.com> In-Reply-To: <1233750314-23301-2-git-send-email-avi@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 1/4] Add a scatter-gather list type and accessors Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel@nongnu.org Avi Kivity wrote: > Scatter-gather lists are used extensively in dma-capable devices; a > single data structure allows more code reuse later on. > > Signed-off-by: Avi Kivity > --- > Makefile.target | 2 +- > dma-helpers.c | 29 +++++++++++++++++++++++++++++ > dma.h | 24 ++++++++++++++++++++++++ > 3 files changed, 54 insertions(+), 1 deletions(-) > create mode 100644 dma-helpers.c > create mode 100644 dma.h > > diff --git a/Makefile.target b/Makefile.target > index 372d185..28ba17f 100644 > --- a/Makefile.target > +++ b/Makefile.target > @@ -500,7 +500,7 @@ endif #CONFIG_BSD_USER > # System emulator target > ifndef CONFIG_USER_ONLY > > -OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o > +OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o dma-helpers.o > # virtio has to be here due to weird dependency between PCI and virtio-net. > # need to fix this properly > OBJS+=virtio.o virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o > diff --git a/dma-helpers.c b/dma-helpers.c > new file mode 100644 > index 0000000..315834e > --- /dev/null > +++ b/dma-helpers.c > @@ -0,0 +1,29 @@ > Needs copyright/license. > +#include "dma.h" > + > + > +void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint) > +{ > + qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry)); > Would be nice to check for malloc failures and fail gracefully at least. > + qsg->nsg = 0; > + qsg->nalloc = alloc_hint; > + qsg->size = 0; > +} > + > +void qemu_sglist_add(QEMUSGList *qsg, target_phys_addr_t base, > + target_phys_addr_t len) > +{ > + if (qsg->nsg == qsg->nalloc) { > + qsg->nalloc = 2 * qsg->nalloc + 1; > Do you really want exponential growth verses linear growth? The sg lists should be relatively small so linear growth should be fine. Regards, Anthony Liguori > + qsg->sg = qemu_realloc(qsg->sg, qsg->nalloc * sizeof(ScatterGatherEntry)); > + } > + qsg->sg[qsg->nsg].base = base; > + qsg->sg[qsg->nsg].len = len; > + qsg->size += len; > + ++qsg->nsg; > +} > + > +void qemu_sglist_destroy(QEMUSGList *qsg) > +{ > + qemu_free(qsg->sg); > +} > + > diff --git a/dma.h b/dma.h > new file mode 100644 > index 0000000..3b56fa6 > --- /dev/null > +++ b/dma.h > @@ -0,0 +1,24 @@ > +#ifndef DMA_H > +#define DMA_H > + > +#include > +#include "cpu.h" > + > +typedef struct { > + target_phys_addr_t base; > + target_phys_addr_t len; > +} ScatterGatherEntry; > + > +typedef struct { > + ScatterGatherEntry *sg; > + int nsg; > + int nalloc; > + target_phys_addr_t size; > +} QEMUSGList; > + > +void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint); > +void qemu_sglist_add(QEMUSGList *qsg, target_phys_addr_t base, > + target_phys_addr_t len); > +void qemu_sglist_destroy(QEMUSGList *qsg); > + > +#endif >