]> git.proxmox.com Git - qemu.git/blob - dma-helpers.c
Add a scatter-gather list type and accessors (Avi Kivity)
[qemu.git] / dma-helpers.c
1 /*
2 * DMA helper functions
3 *
4 * Copyright (c) 2009 Red Hat
5 *
6 * This work is licensed under the terms of the GNU General Public License
7 * (GNU GPL), version 2 or later.
8 */
9
10 #include "dma.h"
11
12
13 void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint)
14 {
15 qsg->sg = qemu_malloc(alloc_hint * sizeof(ScatterGatherEntry));
16 qsg->nsg = 0;
17 qsg->nalloc = alloc_hint;
18 qsg->size = 0;
19 }
20
21 void qemu_sglist_add(QEMUSGList *qsg, target_phys_addr_t base,
22 target_phys_addr_t len)
23 {
24 if (qsg->nsg == qsg->nalloc) {
25 qsg->nalloc = 2 * qsg->nalloc + 1;
26 qsg->sg = qemu_realloc(qsg->sg, qsg->nalloc * sizeof(ScatterGatherEntry));
27 }
28 qsg->sg[qsg->nsg].base = base;
29 qsg->sg[qsg->nsg].len = len;
30 qsg->size += len;
31 ++qsg->nsg;
32 }
33
34 void qemu_sglist_destroy(QEMUSGList *qsg)
35 {
36 qemu_free(qsg->sg);
37 }
38