hidma.h 5.2 KB

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