msm_cvp_buf.h 5.7 KB

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