hv_drv_UsbMusbDma.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * @file hv_drv_UsbMusbDma.h
  3. * @brief Header file of musb dma.
  4. *
  5. * @author HiView SoC Software Team
  6. * @version 1.0.0
  7. * @date 2022-06-15
  8. */
  9. #ifndef __HV_DRV_USB_MUSB_DMA_H
  10. #define __HV_DRV_USB_MUSB_DMA_H
  11. #define is_dma_capable() (1)
  12. struct musb_hw_ep;
  13. #include "hv_drv_UsbCoreCommonUsb.h"
  14. /*
  15. * DMA channel status ... updated by the dma controller driver whenever that
  16. * status changes, and protected by the overall controller spinlock.
  17. */
  18. enum dma_channel_status {
  19. /* unallocated */
  20. MUSB_DMA_STATUS_UNKNOWN,
  21. /* allocated ... but not busy, no errors */
  22. MUSB_DMA_STATUS_FREE,
  23. /* busy ... transactions are active */
  24. MUSB_DMA_STATUS_BUSY,
  25. /* transaction(s) aborted due to ... dma or memory bus error */
  26. MUSB_DMA_STATUS_BUS_ABORT,
  27. /* transaction(s) aborted due to ... core error or USB fault */
  28. MUSB_DMA_STATUS_CORE_ABORT
  29. };
  30. /**
  31. * struct dma_channel - A DMA channel.
  32. * @private_data: channel-private data
  33. * @max_len: the maximum number of bytes the channel can move in one
  34. * transaction (typically representing many USB maximum-sized packets)
  35. * @actual_len: how many bytes have been transferred
  36. * @status: current channel status (updated e.g. on interrupt)
  37. * @desired_mode: true if mode 1 is desired; false if mode 0 is desired
  38. *
  39. * channels are associated with an endpoint for the duration of at least
  40. * one usb transfer.
  41. */
  42. struct dma_channel {
  43. void *private_data;
  44. /* FIXME not void* private_data, but a dma_controller * */
  45. size_t max_len;
  46. size_t actual_len;
  47. enum dma_channel_status status;
  48. boolean desired_mode;
  49. };
  50. INLINE enum dma_channel_status
  51. dma_channel_status(struct dma_channel *c) {
  52. return (is_dma_capable() && c) ? c->status : MUSB_DMA_STATUS_UNKNOWN;
  53. }
  54. /**
  55. * struct dma_controller - A DMA Controller.
  56. * @start: call this to start a DMA controller;
  57. * return 0 on success, else negative errno
  58. * @stop: call this to stop a DMA controller
  59. * return 0 on success, else negative errno
  60. * @channel_alloc: call this to allocate a DMA channel
  61. * @channel_release: call this to release a DMA channel
  62. * @channel_abort: call this to abort a pending DMA transaction,
  63. * returning it to FREE (but allocated) state
  64. *
  65. * Controllers manage dma channels.
  66. */
  67. struct dma_controller {
  68. int (*start)(struct dma_controller *);
  69. int (*stop)(struct dma_controller *);
  70. struct dma_channel *(*channel_alloc)(struct dma_controller *dma, struct musb_hw_ep *ep, u8 is_tx);
  71. void (*channel_release)(struct dma_channel *dma);
  72. int (*channel_program)(struct dma_channel *channel,
  73. u16 maxpacket, u8 mode,
  74. dma_addr_t dma_addr, u32 length);
  75. int (*channel_abort)(struct dma_channel *dma);
  76. };
  77. /* called after channel_program(), may indicate a fault */
  78. extern void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit);
  79. extern struct dma_controller *dma_controller_create(struct musb *musb);
  80. extern void dma_controller_destroy(struct dma_controller *);
  81. extern void dma_controller_irq(struct musb *musb, u8 int_hsdma);
  82. #endif