cam_mem_mgr.h 3.1 KB

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