msm_cvp_buf.h 5.8 KB

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