]> git.proxmox.com Git - qemu.git/blame - dma.h
dma-helpers: add dma_buf_read and dma_buf_write
[qemu.git] / dma.h
CommitLineData
244ab90e
AL
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>
1ad2134f
PB
14//#include "cpu.h"
15#include "hw/hw.h"
59a703eb 16#include "block.h"
244ab90e 17
10dc8aef
PB
18typedef struct ScatterGatherEntry ScatterGatherEntry;
19
fead0c24
PB
20struct QEMUSGList {
21 ScatterGatherEntry *sg;
22 int nsg;
23 int nalloc;
24 size_t size;
25};
26
10dc8aef 27#if defined(TARGET_PHYS_ADDR_BITS)
d9d1055e
DG
28typedef target_phys_addr_t dma_addr_t;
29
30#define DMA_ADDR_FMT TARGET_FMT_plx
31
32typedef enum {
33 DMA_DIRECTION_TO_DEVICE = 0,
34 DMA_DIRECTION_FROM_DEVICE = 1,
35} DMADirection;
36
10dc8aef 37struct ScatterGatherEntry {
d3231181
DG
38 dma_addr_t base;
39 dma_addr_t len;
10dc8aef 40};
244ab90e 41
244ab90e 42void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint);
d3231181 43void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len);
244ab90e 44void qemu_sglist_destroy(QEMUSGList *qsg);
10dc8aef 45#endif
244ab90e 46
cb144ccb
CH
47typedef 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,
bbca72c6 54 void *opaque, bool to_dev);
59a703eb
AL
55BlockDriverAIOCB *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);
8171ee35
PB
61uint64_t dma_buf_read(uint8_t *ptr, int32_t len, QEMUSGList *sg);
62uint64_t dma_buf_write(uint8_t *ptr, int32_t len, QEMUSGList *sg);
63
244ab90e 64#endif