dma.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2015
  4. * Texas Instruments Incorporated, <www.ti.com>
  5. */
  6. #ifndef _DMA_H_
  7. #define _DMA_H_
  8. /*
  9. * enum dma_direction - dma transfer direction indicator
  10. * @DMA_MEM_TO_MEM: Memcpy mode
  11. * @DMA_MEM_TO_DEV: From Memory to Device
  12. * @DMA_DEV_TO_MEM: From Device to Memory
  13. * @DMA_DEV_TO_DEV: From Device to Device
  14. */
  15. enum dma_direction {
  16. DMA_MEM_TO_MEM,
  17. DMA_MEM_TO_DEV,
  18. DMA_DEV_TO_MEM,
  19. DMA_DEV_TO_DEV,
  20. };
  21. #define DMA_SUPPORTS_MEM_TO_MEM BIT(0)
  22. #define DMA_SUPPORTS_MEM_TO_DEV BIT(1)
  23. #define DMA_SUPPORTS_DEV_TO_MEM BIT(2)
  24. #define DMA_SUPPORTS_DEV_TO_DEV BIT(3)
  25. /*
  26. * struct dma_ops - Driver model DMA operations
  27. *
  28. * The uclass interface is implemented by all DMA devices which use
  29. * driver model.
  30. */
  31. struct dma_ops {
  32. /*
  33. * Get the current timer count
  34. *
  35. * @dev: The DMA device
  36. * @direction: direction of data transfer should be one from
  37. enum dma_direction
  38. * @dst: Destination pointer
  39. * @src: Source pointer
  40. * @len: Length of the data to be copied.
  41. * @return: 0 if OK, -ve on error
  42. */
  43. int (*transfer)(struct udevice *dev, int direction, void *dst,
  44. void *src, size_t len);
  45. };
  46. /*
  47. * struct dma_dev_priv - information about a device used by the uclass
  48. *
  49. * @supported: mode of transfers that DMA can support, should be
  50. * one/multiple of DMA_SUPPORTS_*
  51. */
  52. struct dma_dev_priv {
  53. u32 supported;
  54. };
  55. /*
  56. * dma_get_device - get a DMA device which supports transfer
  57. * type of transfer_type
  58. *
  59. * @transfer_type - transfer type should be one/multiple of
  60. * DMA_SUPPORTS_*
  61. * @devp - udevice pointer to return the found device
  62. * @return - will return on success and devp will hold the
  63. * pointer to the device
  64. */
  65. int dma_get_device(u32 transfer_type, struct udevice **devp);
  66. /*
  67. * dma_memcpy - try to use DMA to do a mem copy which will be
  68. * much faster than CPU mem copy
  69. *
  70. * @dst - destination pointer
  71. * @src - souce pointer
  72. * @len - data length to be copied
  73. * @return - on successful transfer returns no of bytes
  74. transferred and on failure return error code.
  75. */
  76. int dma_memcpy(void *dst, void *src, size_t len);
  77. #endif /* _DMA_H_ */