cam_packet_util.h 6.1 KB

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