Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LVBhS-0007cE-G3 for qemu-devel@nongnu.org; Thu, 05 Feb 2009 16:23:54 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LVBhQ-0007bO-QO for qemu-devel@nongnu.org; Thu, 05 Feb 2009 16:23:54 -0500 Received: from [199.232.76.173] (port=38241 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LVBhQ-0007bJ-NV for qemu-devel@nongnu.org; Thu, 05 Feb 2009 16:23:52 -0500 Received: from savannah.gnu.org ([199.232.41.3]:43305 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LVBhQ-0005Th-BJ for qemu-devel@nongnu.org; Thu, 05 Feb 2009 16:23:52 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LVBhP-0005r4-Cn for qemu-devel@nongnu.org; Thu, 05 Feb 2009 21:23:51 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LVBhO-0005r0-UR for qemu-devel@nongnu.org; Thu, 05 Feb 2009 21:23:51 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 05 Feb 2009 21:23:51 +0000 Subject: [Qemu-devel] [6522] Add a scatter-gather list type and accessors (Avi Kivity) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6522 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6522 Author: aliguori Date: 2009-02-05 21:23:50 +0000 (Thu, 05 Feb 2009) Log Message: ----------- Add a scatter-gather list type and accessors (Avi Kivity) 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 Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/Makefile.target Added Paths: ----------- trunk/dma-helpers.c trunk/dma.h Modified: trunk/Makefile.target =================================================================== --- trunk/Makefile.target 2009-02-05 20:22:07 UTC (rev 6521) +++ trunk/Makefile.target 2009-02-05 21:23:50 UTC (rev 6522) @@ -500,7 +500,7 @@ # 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 Added: trunk/dma-helpers.c =================================================================== --- trunk/dma-helpers.c (rev 0) +++ trunk/dma-helpers.c 2009-02-05 21:23:50 UTC (rev 6522) @@ -0,0 +1,38 @@ +/* + * DMA helper functions + * + * Copyright (c) 2009 Red Hat + * + * This work is licensed under the terms of the GNU General Public License + * (GNU GPL), version 2 or later. + */ + +#include "dma.h" + + +void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint) +{ + qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry)); + 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; + 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); +} + Added: trunk/dma.h =================================================================== --- trunk/dma.h (rev 0) +++ trunk/dma.h 2009-02-05 21:23:50 UTC (rev 6522) @@ -0,0 +1,33 @@ +/* + * DMA helper functions + * + * Copyright (c) 2009 Red Hat + * + * This work is licensed under the terms of the GNU General Public License + * (GNU GPL), version 2 or later. + */ + +#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