cam_packet_util.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. #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. * cam_packet_util_get_cmd_mem_addr()
  43. *
  44. * @brief Get command buffer address
  45. *
  46. * @handle: Command buffer memory handle
  47. * @buf_addr: Command buffer cpu mapped address
  48. * @len: Command buffer length
  49. *
  50. * @return: 0 for success
  51. * -EINVAL for Fail
  52. */
  53. int cam_packet_util_get_cmd_mem_addr(int handle, uint32_t **buf_addr,
  54. size_t *len);
  55. /**
  56. * cam_packet_util_validate_packet()
  57. *
  58. * @brief Validate the packet
  59. *
  60. * @packet: Packet to be validated
  61. *
  62. * @remain_len: CPU buff length after config offset
  63. *
  64. * @return: 0 for success
  65. * -EINVAL for Fail
  66. */
  67. int cam_packet_util_validate_packet(struct cam_packet *packet,
  68. size_t remain_len);
  69. /**
  70. * cam_packet_util_validate_cmd_desc()
  71. *
  72. * @brief Validate the packet
  73. *
  74. * @cmd_desc: Command descriptor to be validated
  75. *
  76. * @return: 0 for success
  77. * -EINVAL for Fail
  78. */
  79. int cam_packet_util_validate_cmd_desc(struct cam_cmd_buf_desc *cmd_desc);
  80. /**
  81. * cam_packet_util_get_kmd_buffer()
  82. *
  83. * @brief Get the kmd buffer from the packet command descriptor
  84. *
  85. * @packet: Packet data
  86. * @kmd_buf: Extracted the KMD buffer information
  87. *
  88. * @return: 0 for success
  89. * -EINVAL for Fail
  90. */
  91. int cam_packet_util_get_kmd_buffer(struct cam_packet *packet,
  92. struct cam_kmd_buf_info *kmd_buf_info);
  93. /**
  94. * cam_packet_util_dump_patch_info()
  95. *
  96. * @brief: Dump patch info in case of page fault
  97. *
  98. * @packet: Input packet containing Command Buffers and Patches
  99. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  100. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  101. * received the packet
  102. * @pf_args: Page fault arguments
  103. *
  104. */
  105. void cam_packet_util_dump_patch_info(struct cam_packet *packet,
  106. int32_t iommu_hdl, int32_t sec_iommu_hdl, struct cam_hw_dump_pf_args *pf_args);
  107. /**
  108. * cam_packet_util_process_patches()
  109. *
  110. * @brief: Replace the handle in Packet to Address using the
  111. * information from patches.
  112. *
  113. * @packet: Input packet containing Command Buffers and Patches
  114. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  115. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  116. * received the packet
  117. * @exp_mem: Boolean to know if patched address is in expanded memory range
  118. * or within default 32-bit address space.
  119. *
  120. * @return: 0: Success
  121. * Negative: Failure
  122. */
  123. int cam_packet_util_process_patches(struct cam_packet *packet,
  124. int32_t iommu_hdl, int32_t sec_mmu_hdl, bool exp_mem);
  125. /**
  126. * cam_packet_util_dump_io_bufs()
  127. *
  128. * @brief: Search for faulted io buffer in packet and print io buffers info
  129. *
  130. * @packet: Input packet containing io buffers
  131. * @iommu_hdl: IOMMU handle of the HW Device that received the packet
  132. * @sec_iommu_hdl: Secure IOMMU handle of the HW Device that
  133. * received the packet
  134. * @pf_args: Pault Fault related info
  135. * @res_id_support: if the specific device has knowledge of the resource id for hw
  136. */
  137. void cam_packet_util_dump_io_bufs(struct cam_packet *packet,
  138. int32_t iommu_hdl, int32_t sec_mmu_hdl,
  139. struct cam_hw_dump_pf_args *pf_args, bool res_id_support);
  140. /**
  141. * cam_packet_util_process_generic_cmd_buffer()
  142. *
  143. * @brief: Process Generic Blob command buffer. This utility
  144. * function process the command buffer and calls the
  145. * blob_handle_cb callback for each blob that exists
  146. * in the command buffer.
  147. *
  148. * @cmd_buf: Generic Blob Cmd Buffer handle
  149. * @blob_handler_cb: Callback pointer to call for each blob exists in the
  150. * command buffer
  151. * @user_data: User data to be passed while callback
  152. *
  153. * @return: 0: Success
  154. * Negative: Failure
  155. */
  156. int cam_packet_util_process_generic_cmd_buffer(
  157. struct cam_cmd_buf_desc *cmd_buf,
  158. cam_packet_generic_blob_handler blob_handler_cb, void *user_data);
  159. /**
  160. * @brief : API to retrieve image buffers from presil after processing is
  161. * done,using packet from request
  162. *
  163. * @packet: Packet pointer for current request
  164. * @iommu_hdl: IOMMU hdl for Image buffers
  165. * @out_res_id: Resource ID corresponding to the output buffer
  166. *
  167. * @return: Success or Failure
  168. */
  169. int cam_presil_retrieve_buffers_from_packet(struct cam_packet *packet, int iommu_hdl,
  170. int out_res_id);
  171. /**
  172. * @brief : API to send relevant buffers to presil
  173. *
  174. * @packet : Packet pointer for current request
  175. * @img_iommu_hdl: IOMMU hdl for Image buffers
  176. * @cdm_iommu_hdl: IOMMU hdl for cdm buffers
  177. *
  178. */
  179. int cam_presil_send_buffers_from_packet(struct cam_packet *packet, int img_iommu_hdl,
  180. int cdm_iommu_hdl);
  181. #endif /* _CAM_PACKET_UTIL_H_ */