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