cam_mem_mgr.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. */
  68. struct cam_mem_table {
  69. struct mutex m_lock;
  70. void *bitmap;
  71. size_t bits;
  72. struct cam_mem_buf_queue bufq[CAM_MEM_BUFQ_MAX];
  73. struct dentry *dentry;
  74. bool alloc_profile_enable;
  75. };
  76. /**
  77. * @brief: Allocates and maps buffer
  78. *
  79. * @cmd: Allocation information
  80. *
  81. * @return Status of operation. Negative in case of error. Zero otherwise.
  82. */
  83. int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd);
  84. /**
  85. * @brief: Releases a buffer reference
  86. *
  87. * @cmd: Buffer release information
  88. *
  89. * @return Status of operation. Negative in case of error. Zero otherwise.
  90. */
  91. int cam_mem_mgr_release(struct cam_mem_mgr_release_cmd *cmd);
  92. /**
  93. * @brief Maps a buffer
  94. *
  95. * @cmd: Buffer mapping information
  96. *
  97. * @return Status of operation. Negative in case of error. Zero otherwise.
  98. */
  99. int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd);
  100. /**
  101. * @brief: Perform cache ops on the buffer
  102. *
  103. * @cmd: Cache ops information
  104. *
  105. * @return Status of operation. Negative in case of error. Zero otherwise.
  106. */
  107. int cam_mem_mgr_cache_ops(struct cam_mem_cache_ops_cmd *cmd);
  108. /**
  109. * @brief: Initializes the memory manager
  110. *
  111. * @return Status of operation. Negative in case of error. Zero otherwise.
  112. */
  113. int cam_mem_mgr_init(void);
  114. /**
  115. * @brief: Tears down the memory manager
  116. *
  117. * @return None
  118. */
  119. void cam_mem_mgr_deinit(void);
  120. #endif /* _CAM_MEM_MGR_H_ */