msm_cvp_buf.h 6.0 KB

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