msm_cvp_buf.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _MSM_CVP_BUF_H_
  6. #define _MSM_CVP_BUF_H_
  7. #include <linux/poll.h>
  8. #include <linux/types.h>
  9. #include <linux/dma-buf.h>
  10. #include <linux/dma-heap.h>
  11. #include <linux/ion.h>
  12. #include <linux/msm_ion.h>
  13. #include <linux/refcount.h>
  14. #include <media/msm_eva_private.h>
  15. #define MAX_FRAME_BUFFER_NUMS 30
  16. #define MAX_DMABUF_NUMS 64
  17. struct msm_cvp_inst;
  18. struct msm_cvp_platform_resources;
  19. struct msm_cvp_list;
  20. enum smem_cache_ops {
  21. SMEM_CACHE_CLEAN,
  22. SMEM_CACHE_INVALIDATE,
  23. SMEM_CACHE_CLEAN_INVALIDATE,
  24. };
  25. enum smem_prop {
  26. SMEM_UNCACHED = 0x1,
  27. SMEM_CACHED = 0x2,
  28. SMEM_SECURE = 0x4,
  29. SMEM_ADSP = 0x8,
  30. SMEM_NON_PIXEL = 0x10,
  31. SMEM_PIXEL = 0x20,
  32. SMEM_CAMERA = 0x40,
  33. SMEM_PERSIST = 0x100,
  34. };
  35. struct msm_cvp_list {
  36. struct list_head list;
  37. struct mutex lock;
  38. };
  39. static inline void INIT_MSM_CVP_LIST(struct msm_cvp_list *mlist)
  40. {
  41. mutex_init(&mlist->lock);
  42. INIT_LIST_HEAD(&mlist->list);
  43. }
  44. static inline void DEINIT_MSM_CVP_LIST(struct msm_cvp_list *mlist)
  45. {
  46. mutex_destroy(&mlist->lock);
  47. }
  48. struct cvp_dma_mapping_info {
  49. struct device *dev;
  50. struct iommu_domain *domain;
  51. struct sg_table *table;
  52. struct dma_buf_attachment *attach;
  53. struct dma_buf *buf;
  54. void *cb_info;
  55. };
  56. struct msm_cvp_smem {
  57. struct list_head list;
  58. atomic_t refcount;
  59. struct dma_buf *dma_buf;
  60. struct file *file;
  61. void *kvaddr;
  62. u32 device_addr;
  63. dma_addr_t dma_handle;
  64. u32 size;
  65. u32 bitmap_index;
  66. u32 flags;
  67. struct cvp_dma_mapping_info mapping_info;
  68. };
  69. struct cvp_dmamap_cache {
  70. unsigned long usage_bitmap;
  71. struct mutex lock;
  72. struct msm_cvp_smem *entries[MAX_DMABUF_NUMS];
  73. unsigned int nr;
  74. };
  75. static inline void INIT_DMAMAP_CACHE(struct cvp_dmamap_cache *cache)
  76. {
  77. mutex_init(&cache->lock);
  78. cache->usage_bitmap = 0;
  79. cache->nr = 0;
  80. }
  81. static inline void DEINIT_DMAMAP_CACHE(struct cvp_dmamap_cache *cache)
  82. {
  83. mutex_destroy(&cache->lock);
  84. }
  85. struct cvp_buf_type {
  86. s32 fd;
  87. u32 size;
  88. u32 offset;
  89. u32 flags;
  90. union {
  91. struct dma_buf *dbuf;
  92. struct {
  93. u32 reserved1;
  94. u32 reserved2;
  95. };
  96. };
  97. };
  98. enum buffer_owner {
  99. DRIVER,
  100. FIRMWARE,
  101. CLIENT,
  102. DSP,
  103. MAX_OWNER
  104. };
  105. struct cvp_internal_buf {
  106. struct list_head list;
  107. s32 fd;
  108. u32 size;
  109. u32 offset;
  110. u32 type;
  111. u32 index;
  112. u64 ktid;
  113. enum buffer_owner ownership;
  114. struct msm_cvp_smem *smem;
  115. };
  116. struct msm_cvp_frame {
  117. struct list_head list;
  118. struct cvp_internal_buf bufs[MAX_FRAME_BUFFER_NUMS];
  119. u32 nr;
  120. u64 ktid;
  121. u32 pkt_type;
  122. };
  123. void print_cvp_buffer(u32 tag, const char *str,
  124. struct msm_cvp_inst *inst,
  125. struct cvp_internal_buf *cbuf);
  126. void print_cvp_buffer(u32 tag, const char *str,
  127. struct msm_cvp_inst *inst,
  128. struct cvp_internal_buf *cbuf);
  129. void print_client_buffer(u32 tag, const char *str,
  130. struct msm_cvp_inst *inst,
  131. struct eva_kmd_buffer *cbuf);
  132. void print_smem(u32 tag, const char *str,
  133. struct msm_cvp_inst *inst,
  134. struct msm_cvp_smem *smem);
  135. /*Kernel DMA buffer and IOMMU mapping functions*/
  136. int msm_cvp_smem_alloc(size_t size, u32 align, int map_kernel,
  137. void *res, struct msm_cvp_smem *smem);
  138. int msm_cvp_smem_free(struct msm_cvp_smem *smem);
  139. struct context_bank_info *msm_cvp_smem_get_context_bank(
  140. struct msm_cvp_platform_resources *res,
  141. unsigned int flags);
  142. int msm_cvp_map_smem(struct msm_cvp_inst *inst,
  143. struct msm_cvp_smem *smem,
  144. const char *str);
  145. int msm_cvp_unmap_smem(struct msm_cvp_inst *inst,
  146. struct msm_cvp_smem *smem,
  147. const char *str);
  148. struct dma_buf *msm_cvp_smem_get_dma_buf(int fd);
  149. void msm_cvp_smem_put_dma_buf(void *dma_buf);
  150. int msm_cvp_smem_cache_operations(struct dma_buf *dbuf,
  151. enum smem_cache_ops cache_op,
  152. unsigned long offset,
  153. unsigned long size);
  154. int msm_cvp_map_ipcc_regs(u32 *iova);
  155. /* CVP driver internal buffer management functions*/
  156. struct cvp_internal_buf *cvp_allocate_arp_bufs(struct msm_cvp_inst *inst,
  157. u32 buffer_size);
  158. int cvp_release_arp_buffers(struct msm_cvp_inst *inst);
  159. int msm_cvp_map_buf_dsp(struct msm_cvp_inst *inst,
  160. struct eva_kmd_buffer *buf);
  161. int msm_cvp_unmap_buf_dsp(struct msm_cvp_inst *inst,
  162. struct eva_kmd_buffer *buf);
  163. int msm_cvp_map_buf_dsp_new(struct msm_cvp_inst *inst,
  164. struct eva_kmd_buffer *buf,
  165. int32_t pid,
  166. uint32_t *iova);
  167. int msm_cvp_unmap_buf_dsp_new(struct msm_cvp_inst *inst,
  168. struct eva_kmd_buffer *buf);
  169. void msm_cvp_cache_operations(struct msm_cvp_smem *smem,
  170. u32 type, u32 offset, u32 size);
  171. u32 msm_cvp_map_frame_buf(struct msm_cvp_inst *inst,
  172. struct cvp_buf_type *buf,
  173. struct msm_cvp_frame *frame);
  174. int msm_cvp_mark_user_persist(struct msm_cvp_inst *inst,
  175. struct eva_kmd_hfi_packet *in_pkt,
  176. unsigned int offset, unsigned int buf_num);
  177. int msm_cvp_map_user_persist(struct msm_cvp_inst *inst,
  178. struct eva_kmd_hfi_packet *in_pkt,
  179. unsigned int offset, unsigned int buf_num);
  180. int msm_cvp_unmap_user_persist(struct msm_cvp_inst *inst,
  181. struct eva_kmd_hfi_packet *in_pkt,
  182. unsigned int offset, unsigned int buf_num);
  183. int msm_cvp_map_frame(struct msm_cvp_inst *inst,
  184. struct eva_kmd_hfi_packet *in_pkt,
  185. unsigned int offset, unsigned int buf_num);
  186. void msm_cvp_unmap_frame(struct msm_cvp_inst *inst, u64 ktid);
  187. int msm_cvp_register_buffer(struct msm_cvp_inst *inst,
  188. struct eva_kmd_buffer *buf);
  189. int msm_cvp_unregister_buffer(struct msm_cvp_inst *inst,
  190. struct eva_kmd_buffer *buf);
  191. int msm_cvp_session_deinit_buffers(struct msm_cvp_inst *inst);
  192. void msm_cvp_print_inst_bufs(struct msm_cvp_inst *inst);
  193. int cvp_allocate_dsp_bufs(struct msm_cvp_inst *inst,
  194. struct cvp_internal_buf *buf,
  195. u32 buffer_size,
  196. u32 secure_type);
  197. int cvp_release_dsp_buffers(struct msm_cvp_inst *inst,
  198. struct cvp_internal_buf *buf);
  199. #endif