dma.h 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _PCILIB_DMA_H
  2. #define _PCILIB_DMA_H
  3. #include <pcilib.h>
  4. #include <pcilib/bank.h>
  5. #include <pcilib/register.h>
  6. #define PCILIB_DMA_BUFFER_INVALID ((size_t)-1)
  7. typedef struct {
  8. int used; /**< Indicates if buffer has unread data or empty and ready for DMA */
  9. int error; /**< Indicates if data is complete and correctly transfered or some error occured during the DMA transfer */
  10. int first; /**< Indicates the first buffer of the packet */
  11. int last; /**< Indicates the last buffer of the packet */
  12. size_t size; /**< Indicates number of bytes actually written to the buffer */
  13. } pcilib_dma_buffer_status_t;
  14. typedef struct {
  15. int started; /**< Informs if the engine is currently started or not */
  16. size_t ring_size, buffer_size; /**< The number of allocated DMA buffers and size of each buffer in bytes */
  17. size_t ring_head, ring_tail; /**< The first and the last buffer containing the data */
  18. } pcilib_dma_engine_status_t;
  19. typedef enum {
  20. PCILIB_DMA_TYPE_BLOCK, /**< Simple DMA engine */
  21. PCILIB_DMA_TYPE_PACKET, /**< Streaming (scatter-gather) DMA engine */
  22. PCILIB_DMA_TYPE_UNKNOWN
  23. } pcilib_dma_engine_type_t;
  24. typedef struct {
  25. pcilib_dma_engine_addr_t addr; /**< Address of DMA engine (from 0) */
  26. pcilib_dma_engine_type_t type; /**< Type of DMA engine */
  27. pcilib_dma_direction_t direction; /**< Defines which kind of transfer does engine support: C2S, S2C, or both */
  28. size_t addr_bits; /**< Number of addressable bits in the system memory (we currently work with 32-bits only) */
  29. const char *name; /**< Defines a short name of engine (its main use, i.e. main, auxilliary, etc.) */
  30. const char *description; /**< Defines a longer description of the engine */
  31. } pcilib_dma_engine_description_t;
  32. /*
  33. typedef struct {
  34. int ignore_eop;
  35. } pcilib_dma_parameters_t;
  36. */
  37. typedef struct {
  38. // pcilib_dma_parameters_t params;
  39. pcilib_t *pcilib; /**< Reference to the pcilib context */
  40. } pcilib_dma_context_t;
  41. typedef struct {
  42. pcilib_version_t version;
  43. pcilib_dma_context_t *(*init)(pcilib_t *ctx, const char *model, const void *arg);
  44. void (*free)(pcilib_dma_context_t *ctx);
  45. int (*status)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers);
  46. int (*enable_irq)(pcilib_dma_context_t *ctx, pcilib_irq_type_t irq_type, pcilib_dma_flags_t flags);
  47. int (*disable_irq)(pcilib_dma_context_t *ctx, pcilib_dma_flags_t flags);
  48. int (*acknowledge_irq)(pcilib_dma_context_t *ctx, pcilib_irq_type_t irq_type, pcilib_irq_source_t irq_source);
  49. int (*start_dma)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
  50. int (*stop_dma)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
  51. int (*push)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *written);
  52. int (*stream)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, pcilib_dma_callback_t cb, void *cbattr);
  53. double (*benchmark)(pcilib_dma_context_t *ctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction);
  54. } pcilib_dma_api_description_t;
  55. typedef struct {
  56. const pcilib_dma_api_description_t *api; /**< Defines all API functions for DMA operation */
  57. const pcilib_register_bank_description_t *banks; /**< Pre-defined register banks exposed by DMA interface, additional banks can be defined during DMA initialization */
  58. const pcilib_register_description_t *registers; /**< Pre-defined registers exposed by DMA interface, additional registers can be defined during DMA initialization */
  59. const pcilib_dma_engine_description_t *engines; /**< List of DMA engines exposed by DMA interface, alternatively engines can be added during DMA initialization */
  60. const char *model; /**< If NULL, the actually used event model is used instead */
  61. const void *args; /**< Custom DMA-specific arguments. The actual structure may depend on the specified model */
  62. const char *name; /**< Short name of DMA interface */
  63. const char *description; /**< A bit longer description of DMA interface */
  64. } pcilib_dma_description_t;
  65. const pcilib_dma_description_t *pcilib_get_dma_description(pcilib_t *ctx);
  66. pcilib_dma_engine_t pcilib_add_dma_engine(pcilib_t *ctx, pcilib_dma_engine_description_t *desc);
  67. int pcilib_get_dma_status(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers);
  68. int pcilib_init_dma(pcilib_t *ctx);
  69. #endif /* _PCILIB_DMA_H */