[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/4] Add a scatter-gather list type and accessors
From: |
Avi Kivity |
Subject: |
[Qemu-devel] [PATCH 1/4] Add a scatter-gather list type and accessors |
Date: |
Thu, 5 Feb 2009 11:33:56 +0200 |
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 <address@hidden>
---
Makefile.target | 2 +-
dma-helpers.c | 38 ++++++++++++++++++++++++++++++++++++++
dma.h | 33 +++++++++++++++++++++++++++++++++
3 files changed, 72 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..11ad3a4
--- /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);
+}
+
diff --git a/dma.h b/dma.h
new file mode 100644
index 0000000..16af50f
--- /dev/null
+++ b/dma.h
@@ -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 <stdio.h>
+#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
--
1.6.1.1
- [Qemu-devel] [PATCH 0/4] Block DMA helpers (v2), Avi Kivity, 2009/02/05
- [Qemu-devel] [PATCH 1/4] Add a scatter-gather list type and accessors,
Avi Kivity <=
- [Qemu-devel] [PATCH 4/4] Convert IDE to use new dma helpers, Avi Kivity, 2009/02/05
- [Qemu-devel] [PATCH 2/4] Add qemu_iovec_reset(), Avi Kivity, 2009/02/05
- [Qemu-devel] [PATCH 3/4] Introduce block dma helpers, Avi Kivity, 2009/02/05
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Anthony Liguori, 2009/02/05
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Avi Kivity, 2009/02/06
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Anthony Liguori, 2009/02/06
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Avi Kivity, 2009/02/07
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Anthony Liguori, 2009/02/07
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Avi Kivity, 2009/02/08
- [Qemu-devel] Re: [PATCH 0/4] Block DMA helpers (v2), Anthony Liguori, 2009/02/08