msm_vidc_memory.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021,, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _MSM_VIDC_MEMORY_H_
  6. #define _MSM_VIDC_MEMORY_H_
  7. #include "msm_vidc_internal.h"
  8. struct msm_vidc_core;
  9. struct msm_vidc_inst;
  10. #define MSM_MEM_POOL_PACKET_SIZE 1024
  11. struct msm_memory_dmabuf {
  12. struct list_head list;
  13. struct dma_buf *dmabuf;
  14. u32 refcount;
  15. };
  16. enum msm_memory_pool_type {
  17. MSM_MEM_POOL_BUFFER = 0,
  18. MSM_MEM_POOL_ALLOC_MAP,
  19. MSM_MEM_POOL_TIMESTAMP,
  20. MSM_MEM_POOL_DMABUF,
  21. MSM_MEM_POOL_PACKET,
  22. MSM_MEM_POOL_BUF_TIMER,
  23. MSM_MEM_POOL_BUF_STATS,
  24. MSM_MEM_POOL_MAX,
  25. };
  26. struct msm_memory_alloc_header {
  27. struct list_head list;
  28. u32 type;
  29. bool busy;
  30. void *buf;
  31. };
  32. struct msm_memory_pool {
  33. u32 size;
  34. char *name;
  35. struct list_head free_pool; /* list of struct msm_memory_alloc_header */
  36. struct list_head busy_pool; /* list of struct msm_memory_alloc_header */
  37. };
  38. int msm_vidc_vmem_alloc(unsigned long size, void **mem, const char *msg);
  39. void msm_vidc_vmem_free(void **addr);
  40. void *msm_vidc_pool_alloc(struct msm_vidc_inst *inst,
  41. enum msm_memory_pool_type type);
  42. void msm_vidc_pool_free(struct msm_vidc_inst *inst, void *vidc_buf);
  43. int msm_vidc_pools_init(struct msm_vidc_inst *inst);
  44. void msm_vidc_pools_deinit(struct msm_vidc_inst *inst);
  45. #define call_mem_op(c, op, ...) \
  46. (((c) && (c)->mem_ops && (c)->mem_ops->op) ? \
  47. ((c)->mem_ops->op(__VA_ARGS__)) : 0)
  48. struct msm_vidc_memory_ops {
  49. struct dma_buf *(*dma_buf_get)(struct msm_vidc_inst *inst,
  50. int fd);
  51. void (*dma_buf_put)(struct msm_vidc_inst *inst,
  52. struct dma_buf *dmabuf);
  53. void (*dma_buf_put_completely)(struct msm_vidc_inst *inst,
  54. struct msm_memory_dmabuf *buf);
  55. struct dma_buf_attachment *(*dma_buf_attach)(struct msm_vidc_core *core,
  56. struct dma_buf *dbuf, struct device *dev);
  57. int (*dma_buf_detach)(struct msm_vidc_core *core, struct dma_buf *dbuf,
  58. struct dma_buf_attachment *attach);
  59. struct sg_table *(*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, struct sg_table *table);
  63. int (*memory_alloc_map)(struct msm_vidc_core *core,
  64. struct msm_vidc_mem *mem);
  65. int (*memory_unmap_free)(struct msm_vidc_core *core,
  66. struct msm_vidc_mem *mem);
  67. u32 (*buffer_region)(struct msm_vidc_inst *inst,
  68. enum msm_vidc_buffer_type buffer_type);
  69. };
  70. struct msm_vidc_memory_ops *get_mem_ops(void);
  71. #endif // _MSM_VIDC_MEMORY_H_