cam_packet_util.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, 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. #include "cam_hw_mgr_intf.h"
  10. /**
  11. * @brief KMD scratch buffer information
  12. *
  13. * @handle: Memory handle
  14. * @cpu_addr: Cpu address
  15. * @offset: Offset from the start of the buffer
  16. * @size: Size of the buffer in bytes
  17. * @used_bytes: Used memory in bytes
  18. *
  19. */
  20. struct cam_kmd_buf_info {
  21. int handle;
  22. uint32_t *cpu_addr;
  23. uint32_t offset;
  24. uint32_t size;
  25. uint32_t used_bytes;
  26. };
  27. /* Generic Cmd Buffer blob callback function type */
  28. typedef int (*cam_packet_generic_blob_handler)(void *user_data,
  29. uint32_t blob_type, uint32_t blob_size, uint8_t *blob_data);
  30. /**
  31. * @brief Get packet buffer address
  32. *
  33. * @packet: Pointer to packet to be retrieved
  34. * @packet_handle: Buffer handle of the packet
  35. * @offset: offset to packet start address
  36. *
  37. * @return: 0 for success
  38. */
  39. int cam_packet_util_get_packet_addr(struct cam_packet **packet,
  40. uint64_t packet_handle, uint32_t offset);
  41. /**
  42. * @brief Put packet buffer address
  43. *
  44. * @packet_handle: Buffer handle of the packet
  45. */
  46. void cam_packet_util_put_packet_addr(uint64_t packet_handle);
  47. /**
  48. * cam_packet_util_get_cmd_mem_addr()
  49. *
  50. * @brief Get command buffer address
  51. *
  52. * @handle: Command buffer memory handle
  53. * @buf_addr: Command buffer cpu mapped address
  54. * @len: Command buffer length
  55. *
  56. * @return: 0 for success
  57. * -EINVAL for Fail
  58. */
  59. int cam_packet_util_get_cmd_mem_addr(int handle, uint32_t **buf_addr,
  60. size_t *len);
  61. /**
  62. * cam_packet_util_validate_packet()
  63. *
  64. * @brief Validate the packet
  65. *
  66. * @packet: Packet to be validated
  67. *
  68. * @remain_len: CPU buff length after config offset
  69. *
  70. * @return: 0 for success
  71. * -EINVAL for Fail
  72. */
  73. int cam_packet_util_validate_packet(struct cam_packet *packet,
  74. size_t remain_len);
  75. /**
  76. * cam_packet_util_validate_cmd_desc()
  77. *
  78. * @brief Validate the packet
  79. *
  80. * @cmd_desc: Command descriptor to be validated
  81. *
  82. * @return: 0 for success
  83. * -EINVAL for Fail
  84. */
  85. int cam_packet_util_validate_cmd_desc(struct cam_cmd_buf_desc *cmd_desc);
  86. /**
  87. * cam_packet_util_get_kmd_buffer()
  88. *
  89. * @brief Get the kmd buffer from the packet command descriptor
  90. *
  91. * @packet: Packet data
  92. * @kmd_buf: Extracted the KMD buffer information
  93. *
  94. * @return: 0 for success
  95. * -EINVAL for Fail
  96. */
  97. int cam_packet_util_get_kmd_buffer(struct cam_packet *packet,
  98. struct cam_kmd_buf_info *kmd_buf_info);
  99. /**
  100. * cam_packet_util_dump_patch_info()
  101. *
  102. * @brief: Dump patch info in case of page fault
  103. *
  104. * @packet: Input packet containing Command Buffers and Patches
  105. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  106. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  107. * received the packet
  108. * @pf_args: Page fault arguments
  109. *
  110. */
  111. void cam_packet_util_dump_patch_info(struct cam_packet *packet,
  112. int32_t iommu_hdl, int32_t sec_iommu_hdl, struct cam_hw_dump_pf_args *pf_args);
  113. /**
  114. * cam_packet_util_process_patches()
  115. *
  116. * @brief: Replace the handle in Packet to Address using the
  117. * information from patches.
  118. *
  119. * @packet: Input packet containing Command Buffers and Patches
  120. * @mapped_io_list: List in to add patches/buffers to for reference counting
  121. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  122. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  123. * received the packet
  124. * @exp_mem: Boolean to know if patched address is in expanded memory range
  125. * or within default 32-bit address space.
  126. *
  127. * @return: 0: Success
  128. * Negative: Failure
  129. */
  130. int cam_packet_util_process_patches(struct cam_packet *packet,
  131. struct list_head *mapped_io_list, int32_t iommu_hdl, int32_t sec_mmu_hdl,
  132. bool exp_mem);
  133. /**
  134. * cam_packet_util_dump_io_bufs()
  135. *
  136. * @brief: Search for faulted io buffer in packet and print io buffers info
  137. *
  138. * @packet: Input packet containing io buffers
  139. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  140. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  141. * received the packet
  142. * @pf_args: Pault Fault related info
  143. * @res_id_support: if the specific device has knowledge of the resource id for hw
  144. */
  145. void cam_packet_util_dump_io_bufs(struct cam_packet *packet,
  146. int32_t iommu_hdl, int32_t sec_mmu_hdl,
  147. struct cam_hw_dump_pf_args *pf_args, bool res_id_support);
  148. /**
  149. * cam_packet_util_process_generic_cmd_buffer()
  150. *
  151. * @brief: Process Generic Blob command buffer. This utility
  152. * function process the command buffer and calls the
  153. * blob_handle_cb callback for each blob that exists
  154. * in the command buffer.
  155. *
  156. * @cmd_buf: Generic Blob Cmd Buffer handle
  157. * @blob_handler_cb: Callback pointer to call for each blob exists in the
  158. * command buffer
  159. * @user_data: User data to be passed while callback
  160. *
  161. * @return: 0: Success
  162. * Negative: Failure
  163. */
  164. int cam_packet_util_process_generic_cmd_buffer(
  165. struct cam_cmd_buf_desc *cmd_buf,
  166. cam_packet_generic_blob_handler blob_handler_cb, void *user_data);
  167. /**
  168. * @brief : API to retrieve image buffers from presil after processing is
  169. * done,using packet from request
  170. *
  171. * @packet: Packet pointer for current request
  172. * @iommu_hdl: IOMMU hdl for Image buffers
  173. * @out_res_id: Resource ID corresponding to the output buffer
  174. *
  175. * @return: Success or Failure
  176. */
  177. int cam_presil_retrieve_buffers_from_packet(struct cam_packet *packet, int iommu_hdl,
  178. int out_res_id);
  179. /**
  180. * @brief : API to send relevant buffers to presil
  181. *
  182. * @packet : Packet pointer for current request
  183. * @img_iommu_hdl: IOMMU hdl for Image buffers
  184. * @cdm_iommu_hdl: IOMMU hdl for cdm buffers
  185. *
  186. */
  187. int cam_presil_send_buffers_from_packet(struct cam_packet *packet, int img_iommu_hdl,
  188. int cdm_iommu_hdl);
  189. #endif /* _CAM_PACKET_UTIL_H_ */