cam_packet_util.h 4.2 KB

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