cam_mem_mgr.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_MEM_MGR_H_
  6. #define _CAM_MEM_MGR_H_
  7. #include <linux/mutex.h>
  8. #include <linux/dma-buf.h>
  9. #if IS_REACHABLE(CONFIG_DMABUF_HEAPS)
  10. #include <linux/dma-heap.h>
  11. #endif
  12. #include <media/cam_req_mgr.h>
  13. #include "cam_mem_mgr_api.h"
  14. /* Enum for possible mem mgr states */
  15. enum cam_mem_mgr_state {
  16. CAM_MEM_MGR_UNINITIALIZED,
  17. CAM_MEM_MGR_INITIALIZED,
  18. };
  19. /*Enum for possible SMMU operations */
  20. enum cam_smmu_mapping_client {
  21. CAM_SMMU_MAPPING_USER,
  22. CAM_SMMU_MAPPING_KERNEL,
  23. };
  24. /**
  25. * struct cam_mem_buf_queue
  26. *
  27. * @dma_buf: pointer to the allocated dma_buf in the table
  28. * @q_lock: mutex lock for buffer
  29. * @hdls: list of mapped handles
  30. * @num_hdl: number of handles
  31. * @fd: file descriptor of buffer
  32. * @buf_handle: unique handle for buffer
  33. * @align: alignment for allocation
  34. * @len: size of buffer
  35. * @flags: attributes of buffer
  36. * @vaddr: IOVA of buffer
  37. * @kmdvaddr: Kernel virtual address
  38. * @active: state of the buffer
  39. * @is_imported: Flag indicating if buffer is imported from an FD in user space
  40. * @is_internal: Flag indicating kernel allocated buffer
  41. * @timestamp: Timestamp at which this entry in tbl was made
  42. */
  43. struct cam_mem_buf_queue {
  44. struct dma_buf *dma_buf;
  45. struct mutex q_lock;
  46. int32_t hdls[CAM_MEM_MMU_MAX_HANDLE];
  47. int32_t num_hdl;
  48. int32_t fd;
  49. int32_t buf_handle;
  50. int32_t align;
  51. size_t len;
  52. uint32_t flags;
  53. uint64_t vaddr;
  54. uintptr_t kmdvaddr;
  55. bool active;
  56. bool is_imported;
  57. bool is_internal;
  58. struct timespec64 timestamp;
  59. };
  60. /**
  61. * struct cam_mem_table
  62. *
  63. * @m_lock: mutex lock for table
  64. * @bitmap: bitmap of the mem mgr utility
  65. * @bits: max bits of the utility
  66. * @bufq: array of buffers
  67. * @dentry: Debugfs entry
  68. * @alloc_profile_enable: Whether to enable alloc profiling
  69. * @dbg_buf_idx: debug buffer index to get usecases info
  70. * @force_cache_allocs: Force all internal buffer allocations with cache
  71. */
  72. struct cam_mem_table {
  73. struct mutex m_lock;
  74. void *bitmap;
  75. size_t bits;
  76. struct cam_mem_buf_queue bufq[CAM_MEM_BUFQ_MAX];
  77. struct dentry *dentry;
  78. bool alloc_profile_enable;
  79. size_t dbg_buf_idx;
  80. bool force_cache_allocs;
  81. #if IS_REACHABLE(CONFIG_DMABUF_HEAPS)
  82. struct dma_heap *system_heap;
  83. struct dma_heap *system_uncached_heap;
  84. struct dma_heap *camera_heap;
  85. struct dma_heap *camera_uncached_heap;
  86. struct dma_heap *secure_display_heap;
  87. #endif
  88. };
  89. /**
  90. * @brief: Allocates and maps buffer
  91. *
  92. * @cmd: Allocation information
  93. *
  94. * @return Status of operation. Negative in case of error. Zero otherwise.
  95. */
  96. int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd);
  97. /**
  98. * @brief: Releases a buffer reference
  99. *
  100. * @cmd: Buffer release information
  101. *
  102. * @return Status of operation. Negative in case of error. Zero otherwise.
  103. */
  104. int cam_mem_mgr_release(struct cam_mem_mgr_release_cmd *cmd);
  105. /**
  106. * @brief Maps a buffer
  107. *
  108. * @cmd: Buffer mapping information
  109. *
  110. * @return Status of operation. Negative in case of error. Zero otherwise.
  111. */
  112. int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd);
  113. /**
  114. * @brief: Perform cache ops on the buffer
  115. *
  116. * @cmd: Cache ops information
  117. *
  118. * @return Status of operation. Negative in case of error. Zero otherwise.
  119. */
  120. int cam_mem_mgr_cache_ops(struct cam_mem_cache_ops_cmd *cmd);
  121. /**
  122. * @brief: Initializes the memory manager
  123. *
  124. * @return Status of operation. Negative in case of error. Zero otherwise.
  125. */
  126. int cam_mem_mgr_init(void);
  127. /**
  128. * @brief: Tears down the memory manager
  129. *
  130. * @return None
  131. */
  132. void cam_mem_mgr_deinit(void);
  133. #endif /* _CAM_MEM_MGR_H_ */