cam_mem_mgr.h 3.3 KB

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