hidma.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 initialized; /* initialized flag */
  45. u8 trch_state; /* trch_state of the device */
  46. u8 evch_state; /* evch_state of the device */
  47. u8 chidx; /* channel index in the core */
  48. u32 nr_tres; /* max number of configs */
  49. spinlock_t lock; /* reentrancy */
  50. struct hidma_tre *trepool; /* trepool of user configs */
  51. struct device *dev; /* device */
  52. void __iomem *trca; /* Transfer Channel address */
  53. void __iomem *evca; /* Event Channel address */
  54. struct hidma_tre
  55. **pending_tre_list; /* Pointers to pending TREs */
  56. s32 pending_tre_count; /* Number of TREs pending */
  57. void *tre_ring; /* TRE ring */
  58. dma_addr_t tre_dma; /* TRE ring to be shared with HW */
  59. u32 tre_ring_size; /* Byte size of the ring */
  60. u32 tre_processed_off; /* last processed TRE */
  61. void *evre_ring; /* EVRE ring */
  62. dma_addr_t evre_dma; /* EVRE ring to be shared with HW */
  63. u32 evre_ring_size; /* Byte size of the ring */
  64. u32 evre_processed_off; /* last processed EVRE */
  65. u32 tre_write_offset; /* TRE write location */
  66. struct tasklet_struct task; /* task delivering notifications */
  67. DECLARE_KFIFO_PTR(handoff_fifo,
  68. struct hidma_tre *); /* pending TREs FIFO */
  69. };
  70. struct hidma_desc {
  71. struct dma_async_tx_descriptor desc;
  72. /* link list node for this channel*/
  73. struct list_head node;
  74. u32 tre_ch;
  75. };
  76. struct hidma_chan {
  77. bool paused;
  78. bool allocated;
  79. char dbg_name[16];
  80. u32 dma_sig;
  81. dma_cookie_t last_success;
  82. /*
  83. * active descriptor on this channel
  84. * It is used by the DMA complete notification to
  85. * locate the descriptor that initiated the transfer.
  86. */
  87. struct dentry *debugfs;
  88. struct dentry *stats;
  89. struct hidma_dev *dmadev;
  90. struct hidma_desc *running;
  91. struct dma_chan chan;
  92. struct list_head free;
  93. struct list_head prepared;
  94. struct list_head active;
  95. struct list_head completed;
  96. /* Lock for this structure */
  97. spinlock_t lock;
  98. };
  99. struct hidma_dev {
  100. int irq;
  101. int chidx;
  102. u32 nr_descriptors;
  103. struct hidma_lldev *lldev;
  104. void __iomem *dev_trca;
  105. struct resource *trca_resource;
  106. void __iomem *dev_evca;
  107. struct resource *evca_resource;
  108. /* used to protect the pending channel list*/
  109. spinlock_t lock;
  110. struct dma_device ddev;
  111. struct dentry *debugfs;
  112. struct dentry *stats;
  113. /* Task delivering issue_pending */
  114. struct tasklet_struct task;
  115. };
  116. int hidma_ll_request(struct hidma_lldev *llhndl, u32 dev_id,
  117. const char *dev_name,
  118. void (*callback)(void *data), void *data, u32 *tre_ch);
  119. void hidma_ll_free(struct hidma_lldev *llhndl, u32 tre_ch);
  120. enum dma_status hidma_ll_status(struct hidma_lldev *llhndl, u32 tre_ch);
  121. bool hidma_ll_isenabled(struct hidma_lldev *llhndl);
  122. void hidma_ll_queue_request(struct hidma_lldev *llhndl, u32 tre_ch);
  123. void hidma_ll_start(struct hidma_lldev *llhndl);
  124. int hidma_ll_disable(struct hidma_lldev *lldev);
  125. int hidma_ll_enable(struct hidma_lldev *llhndl);
  126. void hidma_ll_set_transfer_params(struct hidma_lldev *llhndl, u32 tre_ch,
  127. dma_addr_t src, dma_addr_t dest, u32 len, u32 flags);
  128. int hidma_ll_setup(struct hidma_lldev *lldev);
  129. struct hidma_lldev *hidma_ll_init(struct device *dev, u32 max_channels,
  130. void __iomem *trca, void __iomem *evca,
  131. u8 chidx);
  132. int hidma_ll_uninit(struct hidma_lldev *llhndl);
  133. irqreturn_t hidma_ll_inthandler(int irq, void *arg);
  134. void hidma_cleanup_pending_tre(struct hidma_lldev *llhndl, u8 err_info,
  135. u8 err_code);
  136. int hidma_debug_init(struct hidma_dev *dmadev);
  137. void hidma_debug_uninit(struct hidma_dev *dmadev);
  138. #endif