dma.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #ifndef DMA_H
  10. #define DMA_H
  11. #include <stdio.h>
  12. //#include "cpu.h"
  13. #include "hw/hw.h"
  14. #include "block.h"
  15. typedef struct ScatterGatherEntry ScatterGatherEntry;
  16. #if defined(TARGET_PHYS_ADDR_BITS)
  17. typedef target_phys_addr_t dma_addr_t;
  18. #define DMA_ADDR_FMT TARGET_FMT_plx
  19. typedef enum {
  20. DMA_DIRECTION_TO_DEVICE = 0,
  21. DMA_DIRECTION_FROM_DEVICE = 1,
  22. } DMADirection;
  23. struct ScatterGatherEntry {
  24. dma_addr_t base;
  25. dma_addr_t len;
  26. };
  27. struct QEMUSGList {
  28. ScatterGatherEntry *sg;
  29. int nsg;
  30. int nalloc;
  31. dma_addr_t size;
  32. };
  33. void qemu_sglist_init(QEMUSGList *qsg, int alloc_hint);
  34. void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len);
  35. void qemu_sglist_destroy(QEMUSGList *qsg);
  36. #endif
  37. typedef BlockDriverAIOCB *DMAIOFunc(BlockDriverState *bs, int64_t sector_num,
  38. QEMUIOVector *iov, int nb_sectors,
  39. BlockDriverCompletionFunc *cb, void *opaque);
  40. BlockDriverAIOCB *dma_bdrv_io(BlockDriverState *bs,
  41. QEMUSGList *sg, uint64_t sector_num,
  42. DMAIOFunc *io_func, BlockDriverCompletionFunc *cb,
  43. void *opaque, bool to_dev);
  44. BlockDriverAIOCB *dma_bdrv_read(BlockDriverState *bs,
  45. QEMUSGList *sg, uint64_t sector,
  46. BlockDriverCompletionFunc *cb, void *opaque);
  47. BlockDriverAIOCB *dma_bdrv_write(BlockDriverState *bs,
  48. QEMUSGList *sg, uint64_t sector,
  49. BlockDriverCompletionFunc *cb, void *opaque);
  50. #endif