hidma.h 5.6 KB

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