msm_cvp_buf.h 6.3 KB

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