From 244ab90e17e4feefbf35224d6d7bd96d394b4b26 Mon Sep 17 00:00:00 2001 From: aliguori Date: Thu, 5 Feb 2009 21:23:50 +0000 Subject: 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 git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6522 c046a42c-6fe2-441c-8c8c-71466251a162 --- dma-helpers.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 dma-helpers.c (limited to 'dma-helpers.c') diff --git a/dma-helpers.c b/dma-helpers.c new file mode 100644 index 0000000000..11ad3a4344 --- /dev/null +++ b/dma-helpers.c @@ -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); +} + -- cgit v1.2.1