blob: 8c1ec8f0d205750b928911e885a72ce17f522600 [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 "hw/hw.h"
aliguori59a703e2009-02-05 21:23:58 +000015#include "block.h"
aliguori244ab902009-02-05 21:23:50 +000016
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020017typedef struct ScatterGatherEntry ScatterGatherEntry;
18
David Gibson43cf8ae2012-03-27 13:42:23 +110019typedef enum {
20 DMA_DIRECTION_TO_DEVICE = 0,
21 DMA_DIRECTION_FROM_DEVICE = 1,
22} DMADirection;
23
Paolo Bonzinifead0c22011-11-09 16:58:30 +010024struct QEMUSGList {
25 ScatterGatherEntry *sg;
26 int nsg;
27 int nalloc;
28 size_t size;
29};
30
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020031#if defined(TARGET_PHYS_ADDR_BITS)
David Gibsond9d10552011-10-31 17:06:45 +110032typedef target_phys_addr_t dma_addr_t;
33
34#define DMA_ADDR_FMT TARGET_FMT_plx
35
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020036struct ScatterGatherEntry {
David Gibsond3231182011-10-31 17:06:46 +110037 dma_addr_t base;
38 dma_addr_t len;
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020039};
aliguori244ab902009-02-05 21:23:50 +000040
aliguori244ab902009-02-05 21:23:50 +000041void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint);
David Gibsond3231182011-10-31 17:06:46 +110042void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len);
aliguori244ab902009-02-05 21:23:50 +000043void qemu_sglist_destroy(QEMUSGList *qsg);
Paolo Bonzini10dc8ae2011-09-16 16:40:01 +020044#endif
aliguori244ab902009-02-05 21:23:50 +000045
Christoph Hellwigcb144cc2011-05-19 10:57:59 +020046typedef BlockDriverAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num,
47 QEMUIOVector *iov, int nb_sectors,
48 BlockDriverCompletionFunc *cb, void *opaque);
49
50BlockDriverAIOCB *dma_bdrv_io(BlockDriverState *bs,
51 QEMUSGList *sg, uint64_t sector_num,
52 DMAIOFunc *io_func, BlockDriverCompletionFunc *cb,
David Gibson43cf8ae2012-03-27 13:42:23 +110053 void *opaque, DMADirection dir);
aliguori59a703e2009-02-05 21:23:58 +000054BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs,
55 QEMUSGList *sg, uint64_t sector,
56 BlockDriverCompletionFunc *cb, void *opaque);
57BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
58 QEMUSGList *sg, uint64_t sector,
59 BlockDriverCompletionFunc *cb, void *opaque);
Paolo Bonzini8171ee32011-07-06 08:02:14 +020060uint64_t dma_buf_read(uint8_t *ptr, int32_t len, QEMUSGList *sg);
61uint64_t dma_buf_write(uint8_t *ptr, int32_t len, QEMUSGList *sg);
62
Paolo Bonzini84a69352011-09-05 14:20:29 +020063void dma_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
64 QEMUSGList *sg, enum BlockAcctType type);
65
aliguori244ab902009-02-05 21:23:50 +000066#endif