hidma.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Qualcomm Technologies HIDMA data structures
  4. *
  5. * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
  6. */
  7. #ifndef QCOM_HIDMA_H
  8. #define QCOM_HIDMA_H
  9. #include <linux/kfifo.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/dmaengine.h>
  12. #define HIDMA_TRE_SIZE 32 /* each TRE is 32 bytes */
  13. #define HIDMA_TRE_CFG_IDX 0
  14. #define HIDMA_TRE_LEN_IDX 1
  15. #define HIDMA_TRE_SRC_LOW_IDX 2
  16. #define HIDMA_TRE_SRC_HI_IDX 3
  17. #define HIDMA_TRE_DEST_LOW_IDX 4
  18. #define HIDMA_TRE_DEST_HI_IDX 5
  19. enum tre_type {
  20. HIDMA_TRE_MEMCPY = 3,
  21. HIDMA_TRE_MEMSET = 4,
  22. };
  23. struct hidma_tre {
  24. atomic_t allocated; /* if this channel is allocated */
  25. bool queued; /* flag whether this is pending */
  26. u16 status; /* status */
  27. u32 idx; /* index of the tre */
  28. u32 dma_sig; /* signature of the tre */
  29. const char *dev_name; /* name of the device */
  30. void (*callback)(void *data); /* requester callback */
  31. void *data; /* Data associated with this channel*/
  32. struct hidma_lldev *lldev; /* lldma device pointer */
  33. u32 tre_local[HIDMA_TRE_SIZE / sizeof(u32) + 1]; /* TRE local copy */
  34. u32 tre_index; /* the offset where this was written*/
  35. u32 int_flags; /* interrupt flags */
  36. u8 err_info; /* error record in this transfer */
  37. u8 err_code; /* completion code */
  38. };
  39. struct hidma_lldev {
  40. bool msi_support; /* flag indicating MSI support */
  41. bool initialized; /* initialized flag */
  42. u8 trch_state; /* trch_state of the device */
  43. u8 evch_state; /* evch_state of the device */
  44. u8 chidx; /* channel index in the core */
  45. u32 nr_tres; /* max number of configs */
  46. spinlock_t lock; /* reentrancy */
  47. struct hidma_tre *trepool; /* trepool of user configs */
  48. struct device *dev; /* device */
  49. void __iomem *trca; /* Transfer Channel address */
  50. void __iomem *evca; /* Event Channel address */
  51. struct hidma_tre
  52. **pending_tre_list; /* Pointers to pending TREs */
  53. atomic_t pending_tre_count; /* Number of TREs pending */
  54. void *tre_ring; /* TRE ring */
  55. dma_addr_t tre_dma; /* TRE ring to be shared with HW */
  56. u32 tre_ring_size; /* Byte size of the ring */
  57. u32 tre_processed_off; /* last processed TRE */
  58. void *evre_ring; /* EVRE ring */
  59. dma_addr_t evre_dma; /* EVRE ring to be shared with HW */
  60. u32 evre_ring_size; /* Byte size of the ring */
  61. u32 evre_processed_off; /* last processed EVRE */
  62. u32 tre_write_offset; /* TRE write location */
  63. struct tasklet_struct task; /* task delivering notifications */
  64. DECLARE_KFIFO_PTR(handoff_fifo,
  65. struct hidma_tre *); /* pending TREs FIFO */
  66. };
  67. struct hidma_desc {
  68. struct dma_async_tx_descriptor desc;
  69. /* link list node for this channel*/
  70. struct list_head node;
  71. u32 tre_ch;
  72. };
  73. struct hidma_chan {
  74. bool paused;
  75. bool allocated;
  76. char dbg_name[16];
  77. u32 dma_sig;
  78. dma_cookie_t last_success;
  79. /*
  80. * active descriptor on this channel
  81. * It is used by the DMA complete notification to
  82. * locate the descriptor that initiated the transfer.
  83. */
  84. struct hidma_dev *dmadev;
  85. struct hidma_desc *running;
  86. struct dma_chan chan;
  87. struct list_head free;
  88. struct list_head prepared;
  89. struct list_head queued;
  90. struct list_head active;
  91. struct list_head completed;
  92. /* Lock for this structure */
  93. spinlock_t lock;
  94. };
  95. struct hidma_dev {
  96. int irq;
  97. int chidx;
  98. u32 nr_descriptors;
  99. int msi_virqbase;
  100. struct hidma_lldev *lldev;
  101. void __iomem *dev_trca;
  102. struct resource *trca_resource;
  103. void __iomem *dev_evca;
  104. struct resource *evca_resource;
  105. /* used to protect the pending channel list*/
  106. spinlock_t lock;
  107. struct dma_device ddev;
  108. struct dentry *debugfs;
  109. /* sysfs entry for the channel id */
  110. struct device_attribute *chid_attrs;
  111. /* Task delivering issue_pending */
  112. struct tasklet_struct task;
  113. };
  114. int hidma_ll_request(struct hidma_lldev *llhndl, u32 dev_id,
  115. const char *dev_name,
  116. void (*callback)(void *data), void *data, u32 *tre_ch);
  117. void hidma_ll_free(struct hidma_lldev *llhndl, u32 tre_ch);
  118. enum dma_status hidma_ll_status(struct hidma_lldev *llhndl, u32 tre_ch);
  119. bool hidma_ll_isenabled(struct hidma_lldev *llhndl);
  120. void hidma_ll_queue_request(struct hidma_lldev *llhndl, u32 tre_ch);
  121. void hidma_ll_start(struct hidma_lldev *llhndl);
  122. int hidma_ll_disable(struct hidma_lldev *lldev);
  123. int hidma_ll_enable(struct hidma_lldev *llhndl);
  124. void hidma_ll_set_transfer_params(struct hidma_lldev *llhndl, u32 tre_ch,
  125. dma_addr_t src, dma_addr_t dest, u32 len, u32 flags, u32 txntype);
  126. void hidma_ll_setup_irq(struct hidma_lldev *lldev, bool msi);
  127. int hidma_ll_setup(struct hidma_lldev *lldev);
  128. struct hidma_lldev *hidma_ll_init(struct device *dev, u32 max_channels,
  129. void __iomem *trca, void __iomem *evca,
  130. u8 chidx);
  131. int hidma_ll_uninit(struct hidma_lldev *llhndl);
  132. irqreturn_t hidma_ll_inthandler(int irq, void *arg);
  133. irqreturn_t hidma_ll_inthandler_msi(int irq, void *arg, int cause);
  134. void hidma_cleanup_pending_tre(struct hidma_lldev *llhndl, u8 err_info,
  135. u8 err_code);
  136. void hidma_debug_init(struct hidma_dev *dmadev);
  137. void hidma_debug_uninit(struct hidma_dev *dmadev);
  138. #endif