msm_vidc_memory.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_VIDC_MEMORY_H_
  7. #define _MSM_VIDC_MEMORY_H_
  8. #include "msm_vidc_internal.h"
  9. struct msm_vidc_core;
  10. struct msm_vidc_inst;
  11. #define MSM_MEM_POOL_PACKET_SIZE 1024
  12. struct msm_memory_dmabuf {
  13. struct list_head list;
  14. struct dma_buf *dmabuf;
  15. u32 refcount;
  16. };
  17. enum msm_memory_pool_type {
  18. MSM_MEM_POOL_BUFFER = 0,
  19. MSM_MEM_POOL_ALLOC_MAP,
  20. MSM_MEM_POOL_TIMESTAMP,
  21. MSM_MEM_POOL_DMABUF,
  22. MSM_MEM_POOL_PACKET,
  23. MSM_MEM_POOL_BUF_TIMER,
  24. MSM_MEM_POOL_BUF_STATS,
  25. MSM_MEM_POOL_MAX,
  26. };
  27. struct msm_memory_alloc_header {
  28. struct list_head list;
  29. u32 type;
  30. bool busy;
  31. void *buf;
  32. };
  33. struct msm_memory_pool {
  34. u32 size;
  35. char *name;
  36. struct list_head free_pool; /* list of struct msm_memory_alloc_header */
  37. struct list_head busy_pool; /* list of struct msm_memory_alloc_header */
  38. };
  39. void *msm_vidc_pool_alloc(struct msm_vidc_inst *inst,
  40. enum msm_memory_pool_type type);
  41. void msm_vidc_pool_free(struct msm_vidc_inst *inst, void *vidc_buf);
  42. int msm_vidc_pools_init(struct msm_vidc_inst *inst);
  43. void msm_vidc_pools_deinit(struct msm_vidc_inst *inst);
  44. #define call_mem_op(c, op, ...) \
  45. (((c) && (c)->mem_ops && (c)->mem_ops->op) ? \
  46. ((c)->mem_ops->op(__VA_ARGS__)) : 0)
  47. struct msm_vidc_memory_ops {
  48. struct dma_buf *(*dma_buf_get)(struct msm_vidc_inst *inst,
  49. int fd);
  50. void (*dma_buf_put)(struct msm_vidc_inst *inst,
  51. struct dma_buf *dmabuf);
  52. void (*dma_buf_put_completely)(struct msm_vidc_inst *inst,
  53. struct msm_memory_dmabuf *buf);
  54. struct dma_buf_attachment *(*dma_buf_attach)(struct msm_vidc_core *core,
  55. struct dma_buf *dbuf, struct device *dev);
  56. int (*dma_buf_detach)(struct msm_vidc_core *core, struct dma_buf *dbuf,
  57. struct dma_buf_attachment *attach);
  58. struct sg_table
  59. *(*dma_buf_map_attachment)(struct msm_vidc_core *core,
  60. struct dma_buf_attachment *attach);
  61. int (*dma_buf_unmap_attachment)(struct msm_vidc_core *core,
  62. struct dma_buf_attachment *attach,
  63. struct sg_table *table);
  64. int (*memory_alloc_map)(struct msm_vidc_core *core,
  65. struct msm_vidc_mem *mem);
  66. int (*memory_unmap_free)(struct msm_vidc_core *core,
  67. struct msm_vidc_mem *mem);
  68. int (*mem_dma_map_page)(struct msm_vidc_core *core,
  69. struct msm_vidc_mem *mem);
  70. int (*mem_dma_unmap_page)(struct msm_vidc_core *core,
  71. struct msm_vidc_mem *mem);
  72. u32 (*buffer_region)(struct msm_vidc_inst *inst,
  73. enum msm_vidc_buffer_type buffer_type);
  74. int (*iommu_map)(struct msm_vidc_core *core,
  75. struct msm_vidc_mem *mem);
  76. int (*iommu_unmap)(struct msm_vidc_core *core,
  77. struct msm_vidc_mem *mem);
  78. };
  79. const struct msm_vidc_memory_ops *get_mem_ops(void);
  80. #endif // _MSM_VIDC_MEMORY_H_