aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 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> |
Paul Brook | 1ad2134 | 2009-05-19 16:17:58 +0100 | [diff] [blame] | 14 | //#include "cpu.h" |
| 15 | #include "hw/hw.h" |
aliguori | 59a703e | 2009-02-05 21:23:58 +0000 | [diff] [blame] | 16 | #include "block.h" |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 17 | |
Paolo Bonzini | 10dc8ae | 2011-09-16 16:40:01 +0200 | [diff] [blame] | 18 | typedef struct ScatterGatherEntry ScatterGatherEntry; |
| 19 | |
| 20 | #if defined(TARGET_PHYS_ADDR_BITS) |
David Gibson | d9d1055 | 2011-10-31 17:06:45 +1100 | [diff] [blame] | 21 | typedef target_phys_addr_t dma_addr_t; |
| 22 | |
| 23 | #define DMA_ADDR_FMT TARGET_FMT_plx |
| 24 | |
| 25 | typedef enum { |
| 26 | DMA_DIRECTION_TO_DEVICE = 0, |
| 27 | DMA_DIRECTION_FROM_DEVICE = 1, |
| 28 | } DMADirection; |
| 29 | |
Paolo Bonzini | 10dc8ae | 2011-09-16 16:40:01 +0200 | [diff] [blame] | 30 | struct ScatterGatherEntry { |
David Gibson | d323118 | 2011-10-31 17:06:46 +1100 | [diff] [blame] | 31 | dma_addr_t base; |
| 32 | dma_addr_t len; |
Paolo Bonzini | 10dc8ae | 2011-09-16 16:40:01 +0200 | [diff] [blame] | 33 | }; |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 34 | |
Gerd Hoffmann | d35bf9a | 2011-07-12 13:36:23 +0200 | [diff] [blame] | 35 | struct QEMUSGList { |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 36 | ScatterGatherEntry *sg; |
| 37 | int nsg; |
| 38 | int nalloc; |
David Gibson | d323118 | 2011-10-31 17:06:46 +1100 | [diff] [blame] | 39 | dma_addr_t size; |
Gerd Hoffmann | d35bf9a | 2011-07-12 13:36:23 +0200 | [diff] [blame] | 40 | }; |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 41 | |
| 42 | void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint); |
David Gibson | d323118 | 2011-10-31 17:06:46 +1100 | [diff] [blame] | 43 | void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len); |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 44 | void qemu_sglist_destroy(QEMUSGList *qsg); |
Paolo Bonzini | 10dc8ae | 2011-09-16 16:40:01 +0200 | [diff] [blame] | 45 | #endif |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 46 | |
Christoph Hellwig | cb144cc | 2011-05-19 10:57:59 +0200 | [diff] [blame] | 47 | typedef BlockDriverAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num, |
| 48 | QEMUIOVector *iov, int nb_sectors, |
| 49 | BlockDriverCompletionFunc *cb, void *opaque); |
| 50 | |
| 51 | BlockDriverAIOCB *dma_bdrv_io(BlockDriverState *bs, |
| 52 | QEMUSGList *sg, uint64_t sector_num, |
| 53 | DMAIOFunc *io_func, BlockDriverCompletionFunc *cb, |
Paolo Bonzini | bbca72c | 2011-09-16 16:40:00 +0200 | [diff] [blame] | 54 | void *opaque, bool to_dev); |
aliguori | 59a703e | 2009-02-05 21:23:58 +0000 | [diff] [blame] | 55 | BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs, |
| 56 | QEMUSGList *sg, uint64_t sector, |
| 57 | BlockDriverCompletionFunc *cb, void *opaque); |
| 58 | BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs, |
| 59 | QEMUSGList *sg, uint64_t sector, |
| 60 | BlockDriverCompletionFunc *cb, void *opaque); |
aliguori | 244ab90 | 2009-02-05 21:23:50 +0000 | [diff] [blame] | 61 | #endif |