cam_mem_mgr.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. */
  39. struct cam_mem_buf_queue {
  40. struct dma_buf *dma_buf;
  41. struct mutex q_lock;
  42. int32_t hdls[CAM_MEM_MMU_MAX_HANDLE];
  43. int32_t num_hdl;
  44. int32_t fd;
  45. int32_t buf_handle;
  46. int32_t align;
  47. size_t len;
  48. uint32_t flags;
  49. uint64_t vaddr;
  50. uintptr_t kmdvaddr;
  51. bool active;
  52. bool is_imported;
  53. };
  54. /**
  55. * struct cam_mem_table
  56. *
  57. * @m_lock: mutex lock for table
  58. * @bitmap: bitmap of the mem mgr utility
  59. * @bits: max bits of the utility
  60. * @bufq: array of buffers
  61. * @dentry: Debugfs entry
  62. * @alloc_profile_enable: Whether to enable alloc profiling
  63. */
  64. struct cam_mem_table {
  65. struct mutex m_lock;
  66. void *bitmap;
  67. size_t bits;
  68. struct cam_mem_buf_queue bufq[CAM_MEM_BUFQ_MAX];
  69. struct dentry *dentry;
  70. bool alloc_profile_enable;
  71. };
  72. /**
  73. * @brief: Allocates and maps buffer
  74. *
  75. * @cmd: Allocation information
  76. *
  77. * @return Status of operation. Negative in case of error. Zero otherwise.
  78. */
  79. int cam_mem_mgr_alloc_and_map(struct cam_mem_mgr_alloc_cmd *cmd);
  80. /**
  81. * @brief: Releases a buffer reference
  82. *
  83. * @cmd: Buffer release information
  84. *
  85. * @return Status of operation. Negative in case of error. Zero otherwise.
  86. */
  87. int cam_mem_mgr_release(struct cam_mem_mgr_release_cmd *cmd);
  88. /**
  89. * @brief Maps a buffer
  90. *
  91. * @cmd: Buffer mapping information
  92. *
  93. * @return Status of operation. Negative in case of error. Zero otherwise.
  94. */
  95. int cam_mem_mgr_map(struct cam_mem_mgr_map_cmd *cmd);
  96. /**
  97. * @brief: Perform cache ops on the buffer
  98. *
  99. * @cmd: Cache ops information
  100. *
  101. * @return Status of operation. Negative in case of error. Zero otherwise.
  102. */
  103. int cam_mem_mgr_cache_ops(struct cam_mem_cache_ops_cmd *cmd);
  104. /**
  105. * @brief: Initializes the memory manager
  106. *
  107. * @return Status of operation. Negative in case of error. Zero otherwise.
  108. */
  109. int cam_mem_mgr_init(void);
  110. /**
  111. * @brief: Tears down the memory manager
  112. *
  113. * @return None
  114. */
  115. void cam_mem_mgr_deinit(void);
  116. #endif /* _CAM_MEM_MGR_H_ */