msm_cvp_buf.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. void *kvaddr;
  61. u32 device_addr;
  62. dma_addr_t dma_handle;
  63. u32 size;
  64. u32 bitmap_index;
  65. u32 flags;
  66. struct cvp_dma_mapping_info mapping_info;
  67. };
  68. struct cvp_dmamap_cache {
  69. unsigned long usage_bitmap;
  70. struct mutex lock;
  71. struct msm_cvp_smem *entries[MAX_DMABUF_NUMS];
  72. unsigned int nr;
  73. };
  74. static inline void INIT_DMAMAP_CACHE(struct cvp_dmamap_cache *cache)
  75. {
  76. mutex_init(&cache->lock);
  77. cache->usage_bitmap = 0;
  78. cache->nr = 0;
  79. }
  80. static inline void DEINIT_DMAMAP_CACHE(struct cvp_dmamap_cache *cache)
  81. {
  82. mutex_destroy(&cache->lock);
  83. }
  84. struct cvp_buf_type {
  85. s32 fd;
  86. u32 size;
  87. u32 offset;
  88. u32 flags;
  89. union {
  90. struct dma_buf *dbuf;
  91. struct {
  92. u32 reserved1;
  93. u32 reserved2;
  94. };
  95. };
  96. };
  97. enum buffer_owner {
  98. DRIVER,
  99. FIRMWARE,
  100. CLIENT,
  101. DSP,
  102. MAX_OWNER
  103. };
  104. struct cvp_internal_buf {
  105. struct list_head list;
  106. s32 fd;
  107. u32 size;
  108. u32 offset;
  109. u32 type;
  110. u32 index;
  111. u64 ktid;
  112. enum buffer_owner ownership;
  113. struct msm_cvp_smem *smem;
  114. };
  115. struct msm_cvp_frame {
  116. struct list_head list;
  117. struct cvp_internal_buf bufs[MAX_FRAME_BUFFER_NUMS];
  118. u32 nr;
  119. u64 ktid;
  120. u32 pkt_type;
  121. };
  122. void print_cvp_buffer(u32 tag, const char *str,
  123. struct msm_cvp_inst *inst,
  124. struct cvp_internal_buf *cbuf);
  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_client_buffer(u32 tag, const char *str,
  129. struct msm_cvp_inst *inst,
  130. struct eva_kmd_buffer *cbuf);
  131. void print_smem(u32 tag, const char *str,
  132. struct msm_cvp_inst *inst,
  133. struct msm_cvp_smem *smem);
  134. /*Kernel DMA buffer and IOMMU mapping functions*/
  135. int msm_cvp_smem_alloc(size_t size, u32 align, int map_kernel,
  136. void *res, struct msm_cvp_smem *smem);
  137. int msm_cvp_smem_free(struct msm_cvp_smem *smem);
  138. struct context_bank_info *msm_cvp_smem_get_context_bank(
  139. struct msm_cvp_platform_resources *res,
  140. unsigned int flags);
  141. int msm_cvp_map_smem(struct msm_cvp_inst *inst,
  142. struct msm_cvp_smem *smem,
  143. const char *str);
  144. int msm_cvp_unmap_smem(struct msm_cvp_inst *inst,
  145. struct msm_cvp_smem *smem,
  146. const char *str);
  147. struct dma_buf *msm_cvp_smem_get_dma_buf(int fd);
  148. void msm_cvp_smem_put_dma_buf(void *dma_buf);
  149. int msm_cvp_smem_cache_operations(struct dma_buf *dbuf,
  150. enum smem_cache_ops cache_op,
  151. unsigned long offset,
  152. unsigned long size);
  153. int msm_cvp_map_ipcc_regs(u32 *iova);
  154. /* CVP driver internal buffer management functions*/
  155. struct cvp_internal_buf *cvp_allocate_arp_bufs(struct msm_cvp_inst *inst,
  156. u32 buffer_size);
  157. int cvp_release_arp_buffers(struct msm_cvp_inst *inst);
  158. int msm_cvp_map_buf_dsp(struct msm_cvp_inst *inst,
  159. struct eva_kmd_buffer *buf);
  160. int msm_cvp_unmap_buf_dsp(struct msm_cvp_inst *inst,
  161. struct eva_kmd_buffer *buf);
  162. int msm_cvp_map_buf_dsp_new(struct msm_cvp_inst *inst,
  163. struct eva_kmd_buffer *buf,
  164. int32_t pid,
  165. uint32_t *iova);
  166. int msm_cvp_unmap_buf_dsp_new(struct msm_cvp_inst *inst,
  167. struct eva_kmd_buffer *buf);
  168. void msm_cvp_cache_operations(struct msm_cvp_smem *smem,
  169. u32 type, u32 offset, u32 size);
  170. u32 msm_cvp_map_frame_buf(struct msm_cvp_inst *inst,
  171. struct cvp_buf_type *buf,
  172. struct msm_cvp_frame *frame);
  173. int msm_cvp_mark_user_persist(struct msm_cvp_inst *inst,
  174. struct eva_kmd_hfi_packet *in_pkt,
  175. unsigned int offset, unsigned int buf_num);
  176. int msm_cvp_map_user_persist(struct msm_cvp_inst *inst,
  177. struct eva_kmd_hfi_packet *in_pkt,
  178. unsigned int offset, unsigned int buf_num);
  179. int msm_cvp_unmap_user_persist(struct msm_cvp_inst *inst,
  180. struct eva_kmd_hfi_packet *in_pkt,
  181. unsigned int offset, unsigned int buf_num);
  182. int msm_cvp_map_frame(struct msm_cvp_inst *inst,
  183. struct eva_kmd_hfi_packet *in_pkt,
  184. unsigned int offset, unsigned int buf_num);
  185. void msm_cvp_unmap_frame(struct msm_cvp_inst *inst, u64 ktid);
  186. int msm_cvp_register_buffer(struct msm_cvp_inst *inst,
  187. struct eva_kmd_buffer *buf);
  188. int msm_cvp_unregister_buffer(struct msm_cvp_inst *inst,
  189. struct eva_kmd_buffer *buf);
  190. int msm_cvp_session_deinit_buffers(struct msm_cvp_inst *inst);
  191. void msm_cvp_print_inst_bufs(struct msm_cvp_inst *inst);
  192. int cvp_allocate_dsp_bufs(struct msm_cvp_inst *inst,
  193. struct cvp_internal_buf *buf,
  194. u32 buffer_size,
  195. u32 secure_type);
  196. int cvp_release_dsp_buffers(struct msm_cvp_inst *inst,
  197. struct cvp_internal_buf *buf);
  198. #endif