cam_packet_util.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CAM_PACKET_UTIL_H_
  7. #define _CAM_PACKET_UTIL_H_
  8. #include <media/cam_defs.h>
  9. /**
  10. * @brief KMD scratch buffer information
  11. *
  12. * @handle: Memory handle
  13. * @cpu_addr: Cpu address
  14. * @offset: Offset from the start of the buffer
  15. * @size: Size of the buffer in bytes
  16. * @used_bytes: Used memory in bytes
  17. *
  18. */
  19. struct cam_kmd_buf_info {
  20. int handle;
  21. uint32_t *cpu_addr;
  22. uint32_t offset;
  23. uint32_t size;
  24. uint32_t used_bytes;
  25. };
  26. /* Generic Cmd Buffer blob callback function type */
  27. typedef int (*cam_packet_generic_blob_handler)(void *user_data,
  28. uint32_t blob_type, uint32_t blob_size, uint8_t *blob_data);
  29. /**
  30. * cam_packet_util_get_cmd_mem_addr()
  31. *
  32. * @brief Get command buffer address
  33. *
  34. * @handle: Command buffer memory handle
  35. * @buf_addr: Command buffer cpu mapped address
  36. * @len: Command buffer length
  37. *
  38. * @return: 0 for success
  39. * -EINVAL for Fail
  40. */
  41. int cam_packet_util_get_cmd_mem_addr(int handle, uint32_t **buf_addr,
  42. size_t *len);
  43. /**
  44. * cam_packet_util_validate_packet()
  45. *
  46. * @brief Validate the packet
  47. *
  48. * @packet: Packet to be validated
  49. *
  50. * @remain_len: CPU buff length after config offset
  51. *
  52. * @return: 0 for success
  53. * -EINVAL for Fail
  54. */
  55. int cam_packet_util_validate_packet(struct cam_packet *packet,
  56. size_t remain_len);
  57. /**
  58. * cam_packet_util_validate_cmd_desc()
  59. *
  60. * @brief Validate the packet
  61. *
  62. * @cmd_desc: Command descriptor to be validated
  63. *
  64. * @return: 0 for success
  65. * -EINVAL for Fail
  66. */
  67. int cam_packet_util_validate_cmd_desc(struct cam_cmd_buf_desc *cmd_desc);
  68. /**
  69. * cam_packet_util_get_kmd_buffer()
  70. *
  71. * @brief Get the kmd buffer from the packet command descriptor
  72. *
  73. * @packet: Packet data
  74. * @kmd_buf: Extracted the KMD buffer information
  75. *
  76. * @return: 0 for success
  77. * -EINVAL for Fail
  78. */
  79. int cam_packet_util_get_kmd_buffer(struct cam_packet *packet,
  80. struct cam_kmd_buf_info *kmd_buf_info);
  81. /**
  82. * cam_packet_dump_patch_info()
  83. *
  84. * @brief: Dump patch info in case of page fault
  85. *
  86. * @packet: Input packet containing Command Buffers and Patches
  87. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  88. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  89. * received the packet
  90. *
  91. */
  92. void cam_packet_dump_patch_info(struct cam_packet *packet,
  93. int32_t iommu_hdl, int32_t sec_mmu_hdl);
  94. /**
  95. * cam_packet_util_process_patches()
  96. *
  97. * @brief: Replace the handle in Packet to Address using the
  98. * information from patches.
  99. *
  100. * @packet: Input packet containing Command Buffers and Patches
  101. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  102. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  103. * received the packet
  104. * @exp_mem: Boolean to know if patched address is in expanded memory range
  105. * or within default 32-bit address space.
  106. *
  107. * @return: 0: Success
  108. * Negative: Failure
  109. */
  110. int cam_packet_util_process_patches(struct cam_packet *packet,
  111. int32_t iommu_hdl, int32_t sec_mmu_hdl, bool exp_mem);
  112. /**
  113. * cam_packet_util_process_generic_cmd_buffer()
  114. *
  115. * @brief: Process Generic Blob command buffer. This utility
  116. * function process the command buffer and calls the
  117. * blob_handle_cb callback for each blob that exists
  118. * in the command buffer.
  119. *
  120. * @cmd_buf: Generic Blob Cmd Buffer handle
  121. * @blob_handler_cb: Callback pointer to call for each blob exists in the
  122. * command buffer
  123. * @user_data: User data to be passed while callback
  124. *
  125. * @return: 0: Success
  126. * Negative: Failure
  127. */
  128. int cam_packet_util_process_generic_cmd_buffer(
  129. struct cam_cmd_buf_desc *cmd_buf,
  130. cam_packet_generic_blob_handler blob_handler_cb, void *user_data);
  131. /**
  132. * @brief : API to retrieve image buffers from presil after processing is
  133. * done,using packet from request
  134. *
  135. * @packet: Packet pointer for current request
  136. * @iommu_hdl: IOMMU hdl for Image buffers
  137. * @out_res_id: Resource ID corresponding to the output buffer
  138. *
  139. * @return: Success or Failure
  140. */
  141. int cam_presil_retrieve_buffers_from_packet(struct cam_packet *packet, int iommu_hdl,
  142. int out_res_id);
  143. /**
  144. * @brief : API to send relevant buffers to presil
  145. *
  146. * @packet : Packet pointer for current request
  147. * @img_iommu_hdl: IOMMU hdl for Image buffers
  148. * @cdm_iommu_hdl: IOMMU hdl for cdm buffers
  149. *
  150. */
  151. int cam_presil_send_buffers_from_packet(struct cam_packet *packet, int img_iommu_hdl,
  152. int cdm_iommu_hdl);
  153. #endif /* _CAM_PACKET_UTIL_H_ */