Commit 244ab90e17e4feefbf35224d6d7bd96d394b4b26

Authored by aliguori
1 parent f3902383

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 <avi@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6522 c046a42c-6fe2-441c-8c8c-71466251a162
Makefile.target
... ... @@ -500,7 +500,7 @@ endif #CONFIG_BSD_USER
500 500 # System emulator target
501 501 ifndef CONFIG_USER_ONLY
502 502  
503   -OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o
  503 +OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o dma-helpers.o
504 504 # virtio has to be here due to weird dependency between PCI and virtio-net.
505 505 # need to fix this properly
506 506 OBJS+=virtio.o virtio-blk.o virtio-balloon.o virtio-net.o virtio-console.o
... ...
dma-helpers.c 0 → 100644
  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 +
... ...
dma.h 0 → 100644
  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 +#ifndef DMA_H
  11 +#define DMA_H
  12 +
  13 +#include <stdio.h>
  14 +#include "cpu.h"
  15 +
  16 +typedef struct {
  17 + target_phys_addr_t base;
  18 + target_phys_addr_t len;
  19 +} ScatterGatherEntry;
  20 +
  21 +typedef struct {
  22 + ScatterGatherEntry *sg;
  23 + int nsg;
  24 + int nalloc;
  25 + target_phys_addr_t size;
  26 +} QEMUSGList;
  27 +
  28 +void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint);
  29 +void qemu_sglist_add(QEMUSGList *qsg, target_phys_addr_t base,
  30 + target_phys_addr_t len);
  31 +void qemu_sglist_destroy(QEMUSGList *qsg);
  32 +
  33 +#endif
... ...