cam_jpeg_context.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/debugfs.h>
  6. #include <linux/videodev2.h>
  7. #include <linux/slab.h>
  8. #include <linux/uaccess.h>
  9. #include "cam_mem_mgr.h"
  10. #include "cam_jpeg_context.h"
  11. #include "cam_context_utils.h"
  12. #include "cam_debug_util.h"
  13. #include "cam_packet_util.h"
  14. static const char jpeg_dev_name[] = "cam-jpeg";
  15. static int cam_jpeg_context_dump_active_request(void *data,
  16. struct cam_smmu_pf_info *pf_info)
  17. {
  18. struct cam_context *ctx = (struct cam_context *)data;
  19. struct cam_ctx_request *req = NULL;
  20. struct cam_ctx_request *req_temp = NULL;
  21. struct cam_hw_mgr_dump_pf_data *pf_dbg_entry = NULL;
  22. uint32_t resource_type = 0;
  23. int rc = 0;
  24. int closest_port;
  25. bool b_mem_found = false, b_ctx_found = false;
  26. if (!ctx) {
  27. CAM_ERR(CAM_JPEG, "Invalid ctx");
  28. return -EINVAL;
  29. }
  30. CAM_INFO(CAM_JPEG, "iommu fault for jpeg ctx %d state %d",
  31. ctx->ctx_id, ctx->state);
  32. list_for_each_entry_safe(req, req_temp,
  33. &ctx->active_req_list, list) {
  34. pf_dbg_entry = &(req->pf_data);
  35. closest_port = -1;
  36. CAM_INFO(CAM_JPEG, "req_id : %lld ", req->request_id);
  37. rc = cam_context_dump_pf_info_to_hw(ctx, pf_dbg_entry,
  38. &b_mem_found, &b_ctx_found, &resource_type, pf_info);
  39. if (rc)
  40. CAM_ERR(CAM_JPEG, "Failed to dump pf info");
  41. if (b_mem_found)
  42. CAM_ERR(CAM_JPEG, "Found page fault in req %lld %d",
  43. req->request_id, rc);
  44. }
  45. return rc;
  46. }
  47. static int cam_jpeg_context_mini_dump(void *priv, void *args)
  48. {
  49. int rc;
  50. struct cam_context *ctx;
  51. if (!priv || args) {
  52. CAM_ERR(CAM_ICP, "Invalid param priv %pK args %pK", priv, args);
  53. return -EINVAL;
  54. }
  55. ctx = (struct cam_context *)priv;
  56. rc = cam_context_mini_dump(ctx, args);
  57. if (rc)
  58. CAM_ERR(CAM_JPEG, "Mini Dump failed %d", rc);
  59. return rc;
  60. }
  61. static int __cam_jpeg_ctx_acquire_dev_in_available(struct cam_context *ctx,
  62. struct cam_acquire_dev_cmd *cmd)
  63. {
  64. int rc;
  65. rc = cam_context_acquire_dev_to_hw(ctx, cmd);
  66. if (rc)
  67. CAM_ERR(CAM_JPEG, "Unable to Acquire device %d", rc);
  68. else
  69. ctx->state = CAM_CTX_ACQUIRED;
  70. return rc;
  71. }
  72. static int __cam_jpeg_ctx_release_dev_in_acquired(struct cam_context *ctx,
  73. struct cam_release_dev_cmd *cmd)
  74. {
  75. int rc;
  76. rc = cam_context_release_dev_to_hw(ctx, cmd);
  77. if (rc)
  78. CAM_ERR(CAM_JPEG, "Unable to release device %d", rc);
  79. ctx->state = CAM_CTX_AVAILABLE;
  80. return rc;
  81. }
  82. static int __cam_jpeg_ctx_dump_dev_in_acquired(
  83. struct cam_context *ctx,
  84. struct cam_dump_req_cmd *cmd)
  85. {
  86. int rc;
  87. rc = cam_context_dump_dev_to_hw(ctx, cmd);
  88. if (rc)
  89. CAM_ERR(CAM_JPEG, "Failed to dump device, rc=%d", rc);
  90. return rc;
  91. }
  92. static int __cam_jpeg_ctx_flush_dev_in_acquired(struct cam_context *ctx,
  93. struct cam_flush_dev_cmd *cmd)
  94. {
  95. int rc;
  96. rc = cam_context_flush_dev_to_hw(ctx, cmd);
  97. if (rc)
  98. CAM_ERR(CAM_ICP, "Failed to flush device");
  99. return rc;
  100. }
  101. static int __cam_jpeg_ctx_config_dev_in_acquired(struct cam_context *ctx,
  102. struct cam_config_dev_cmd *cmd)
  103. {
  104. return cam_context_prepare_dev_to_hw(ctx, cmd);
  105. }
  106. static int __cam_jpeg_ctx_handle_buf_done_in_acquired(void *ctx,
  107. uint32_t evt_id, void *done)
  108. {
  109. return cam_context_buf_done_from_hw(ctx, done, evt_id);
  110. }
  111. static int __cam_jpeg_ctx_stop_dev_in_acquired(struct cam_context *ctx,
  112. struct cam_start_stop_dev_cmd *cmd)
  113. {
  114. int rc;
  115. rc = cam_context_stop_dev_to_hw(ctx);
  116. if (rc) {
  117. CAM_ERR(CAM_JPEG, "Failed in Stop dev, rc=%d", rc);
  118. return rc;
  119. }
  120. return rc;
  121. }
  122. /* top state machine */
  123. static struct cam_ctx_ops
  124. cam_jpeg_ctx_state_machine[CAM_CTX_STATE_MAX] = {
  125. /* Uninit */
  126. {
  127. .ioctl_ops = { },
  128. .crm_ops = { },
  129. .irq_ops = NULL,
  130. },
  131. /* Available */
  132. {
  133. .ioctl_ops = {
  134. .acquire_dev = __cam_jpeg_ctx_acquire_dev_in_available,
  135. },
  136. .crm_ops = { },
  137. .irq_ops = NULL,
  138. .mini_dump_ops = cam_jpeg_context_mini_dump,
  139. },
  140. /* Acquired */
  141. {
  142. .ioctl_ops = {
  143. .release_dev = __cam_jpeg_ctx_release_dev_in_acquired,
  144. .config_dev = __cam_jpeg_ctx_config_dev_in_acquired,
  145. .stop_dev = __cam_jpeg_ctx_stop_dev_in_acquired,
  146. .flush_dev = __cam_jpeg_ctx_flush_dev_in_acquired,
  147. .dump_dev = __cam_jpeg_ctx_dump_dev_in_acquired,
  148. },
  149. .crm_ops = { },
  150. .irq_ops = __cam_jpeg_ctx_handle_buf_done_in_acquired,
  151. .pagefault_ops = cam_jpeg_context_dump_active_request,
  152. .mini_dump_ops = cam_jpeg_context_mini_dump,
  153. },
  154. /* Ready */
  155. {
  156. .ioctl_ops = {},
  157. },
  158. /* Flushed */
  159. {
  160. .ioctl_ops = {},
  161. },
  162. /* Activated */
  163. {
  164. .ioctl_ops = {},
  165. },
  166. };
  167. int cam_jpeg_context_init(struct cam_jpeg_context *ctx,
  168. struct cam_context *ctx_base,
  169. struct cam_hw_mgr_intf *hw_intf,
  170. uint32_t ctx_id,
  171. int img_iommu_hdl)
  172. {
  173. int rc;
  174. int i;
  175. if (!ctx || !ctx_base) {
  176. CAM_ERR(CAM_JPEG, "Invalid Context");
  177. rc = -EFAULT;
  178. goto err;
  179. }
  180. memset(ctx, 0, sizeof(*ctx));
  181. ctx->base = ctx_base;
  182. for (i = 0; i < CAM_CTX_REQ_MAX; i++)
  183. ctx->req_base[i].req_priv = &ctx->jpeg_req[i];
  184. rc = cam_context_init(ctx_base, jpeg_dev_name, CAM_JPEG, ctx_id,
  185. NULL, hw_intf, ctx->req_base, CAM_CTX_REQ_MAX, img_iommu_hdl);
  186. if (rc) {
  187. CAM_ERR(CAM_JPEG, "Camera Context Base init failed");
  188. goto err;
  189. }
  190. ctx_base->state_machine = cam_jpeg_ctx_state_machine;
  191. ctx_base->ctx_priv = ctx;
  192. ctx_base->max_hw_update_entries = CAM_CTX_CFG_MAX;
  193. ctx_base->max_in_map_entries = CAM_CTX_CFG_MAX;
  194. ctx_base->max_out_map_entries = CAM_CTX_CFG_MAX;
  195. err:
  196. return rc;
  197. }
  198. int cam_jpeg_context_deinit(struct cam_jpeg_context *ctx)
  199. {
  200. if (!ctx || !ctx->base) {
  201. CAM_ERR(CAM_JPEG, "Invalid params: %pK", ctx);
  202. return -EINVAL;
  203. }
  204. cam_context_deinit(ctx->base);
  205. memset(ctx, 0, sizeof(*ctx));
  206. return 0;
  207. }