hidma.h 5.5 KB

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