blob: a13209d7eb55531d7801acc32dbaa6f5e1d5420a [file] [log] [blame]
aliguori244ab902009-02-05 21:23:50 +00001/*
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>
Paul Brook1ad21342009-05-19 16:17:58 +010014//#include "cpu.h"
15#include "hw/hw.h"
aliguori59a703e2009-02-05 21:23:58 +000016#include "block.h"
aliguori244ab902009-02-05 21:23:50 +000017
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020018typedef struct ScatterGatherEntry ScatterGatherEntry;
19
20#if defined(TARGET_PHYS_ADDR_BITS)
David Gibsond9d10552011-10-31 17:06:45 +110021typedef target_phys_addr_t dma_addr_t;
22
23#define DMA_ADDR_FMT TARGET_FMT_plx
24
25typedef enum {
26 DMA_DIRECTION_TO_DEVICE = 0,
27 DMA_DIRECTION_FROM_DEVICE = 1,
28} DMADirection;
29
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020030struct ScatterGatherEntry {
David Gibsond3231182011-10-31 17:06:46 +110031 dma_addr_t base;
32 dma_addr_t len;
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020033};
aliguori244ab902009-02-05 21:23:50 +000034
Gerd Hoffmannd35bf9a2011-07-12 13:36:23 +020035struct QEMUSGList {
aliguori244ab902009-02-05 21:23:50 +000036 ScatterGatherEntry *sg;
37 int nsg;
38 int nalloc;
David Gibsond3231182011-10-31 17:06:46 +110039 dma_addr_t size;
Gerd Hoffmannd35bf9a2011-07-12 13:36:23 +020040};
aliguori244ab902009-02-05 21:23:50 +000041
42void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint);
David Gibsond3231182011-10-31 17:06:46 +110043void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len);
aliguori244ab902009-02-05 21:23:50 +000044void qemu_sglist_destroy(QEMUSGList *qsg);
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020045#endif
aliguori244ab902009-02-05 21:23:50 +000046
Christoph Hellwigcb144cc2011-05-19 10:57:59 +020047typedef BlockDriverAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num,
48 QEMUIOVector *iov, int nb_sectors,
49 BlockDriverCompletionFunc *cb, void *opaque);
50
51BlockDriverAIOCB *dma_bdrv_io(BlockDriverState *bs,
52 QEMUSGList *sg, uint64_t sector_num,
53 DMAIOFunc *io_func, BlockDriverCompletionFunc *cb,
Paolo Bonzinibbca72c2011-09-16 16:40:00 +020054 void *opaque, bool to_dev);
aliguori59a703e2009-02-05 21:23:58 +000055BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs,
56 QEMUSGList *sg, uint64_t sector,
57 BlockDriverCompletionFunc *cb, void *opaque);
58BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
59 QEMUSGList *sg, uint64_t sector,
60 BlockDriverCompletionFunc *cb, void *opaque);
aliguori244ab902009-02-05 21:23:50 +000061#endif