cam_jpeg_context.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, 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_ctx_acquire_dev_in_available(struct cam_context *ctx,
  48. struct cam_acquire_dev_cmd *cmd)
  49. {
  50. int rc;
  51. rc = cam_context_acquire_dev_to_hw(ctx, cmd);
  52. if (rc)
  53. CAM_ERR(CAM_JPEG, "Unable to Acquire device %d", rc);
  54. else
  55. ctx->state = CAM_CTX_ACQUIRED;
  56. return rc;
  57. }
  58. static int __cam_jpeg_ctx_release_dev_in_acquired(struct cam_context *ctx,
  59. struct cam_release_dev_cmd *cmd)
  60. {
  61. int rc;
  62. rc = cam_context_release_dev_to_hw(ctx, cmd);
  63. if (rc)
  64. CAM_ERR(CAM_JPEG, "Unable to release device %d", rc);
  65. ctx->state = CAM_CTX_AVAILABLE;
  66. return rc;
  67. }
  68. static int __cam_jpeg_ctx_dump_dev_in_acquired(
  69. struct cam_context *ctx,
  70. struct cam_dump_req_cmd *cmd)
  71. {
  72. int rc;
  73. rc = cam_context_dump_dev_to_hw(ctx, cmd);
  74. if (rc)
  75. CAM_ERR(CAM_JPEG, "Failed to dump device, rc=%d", rc);
  76. return rc;
  77. }
  78. static int __cam_jpeg_ctx_flush_dev_in_acquired(struct cam_context *ctx,
  79. struct cam_flush_dev_cmd *cmd)
  80. {
  81. int rc;
  82. rc = cam_context_flush_dev_to_hw(ctx, cmd);
  83. if (rc)
  84. CAM_ERR(CAM_ICP, "Failed to flush device");
  85. return rc;
  86. }
  87. static int __cam_jpeg_ctx_config_dev_in_acquired(struct cam_context *ctx,
  88. struct cam_config_dev_cmd *cmd)
  89. {
  90. return cam_context_prepare_dev_to_hw(ctx, cmd);
  91. }
  92. static int __cam_jpeg_ctx_handle_buf_done_in_acquired(void *ctx,
  93. uint32_t evt_id, void *done)
  94. {
  95. return cam_context_buf_done_from_hw(ctx, done, evt_id);
  96. }
  97. static int __cam_jpeg_ctx_stop_dev_in_acquired(struct cam_context *ctx,
  98. struct cam_start_stop_dev_cmd *cmd)
  99. {
  100. int rc;
  101. rc = cam_context_stop_dev_to_hw(ctx);
  102. if (rc) {
  103. CAM_ERR(CAM_JPEG, "Failed in Stop dev, rc=%d", rc);
  104. return rc;
  105. }
  106. return rc;
  107. }
  108. /* top state machine */
  109. static struct cam_ctx_ops
  110. cam_jpeg_ctx_state_machine[CAM_CTX_STATE_MAX] = {
  111. /* Uninit */
  112. {
  113. .ioctl_ops = { },
  114. .crm_ops = { },
  115. .irq_ops = NULL,
  116. },
  117. /* Available */
  118. {
  119. .ioctl_ops = {
  120. .acquire_dev = __cam_jpeg_ctx_acquire_dev_in_available,
  121. },
  122. .crm_ops = { },
  123. .irq_ops = NULL,
  124. },
  125. /* Acquired */
  126. {
  127. .ioctl_ops = {
  128. .release_dev = __cam_jpeg_ctx_release_dev_in_acquired,
  129. .config_dev = __cam_jpeg_ctx_config_dev_in_acquired,
  130. .stop_dev = __cam_jpeg_ctx_stop_dev_in_acquired,
  131. .flush_dev = __cam_jpeg_ctx_flush_dev_in_acquired,
  132. .dump_dev = __cam_jpeg_ctx_dump_dev_in_acquired,
  133. },
  134. .crm_ops = { },
  135. .irq_ops = __cam_jpeg_ctx_handle_buf_done_in_acquired,
  136. .pagefault_ops = cam_jpeg_context_dump_active_request,
  137. },
  138. };
  139. int cam_jpeg_context_init(struct cam_jpeg_context *ctx,
  140. struct cam_context *ctx_base,
  141. struct cam_hw_mgr_intf *hw_intf,
  142. uint32_t ctx_id)
  143. {
  144. int rc;
  145. int i;
  146. if (!ctx || !ctx_base) {
  147. CAM_ERR(CAM_JPEG, "Invalid Context");
  148. rc = -EFAULT;
  149. goto err;
  150. }
  151. memset(ctx, 0, sizeof(*ctx));
  152. ctx->base = ctx_base;
  153. for (i = 0; i < CAM_CTX_REQ_MAX; i++)
  154. ctx->req_base[i].req_priv = ctx;
  155. rc = cam_context_init(ctx_base, jpeg_dev_name, CAM_JPEG, ctx_id,
  156. NULL, hw_intf, ctx->req_base, CAM_CTX_REQ_MAX);
  157. if (rc) {
  158. CAM_ERR(CAM_JPEG, "Camera Context Base init failed");
  159. goto err;
  160. }
  161. ctx_base->state_machine = cam_jpeg_ctx_state_machine;
  162. ctx_base->ctx_priv = ctx;
  163. ctx_base->max_hw_update_entries = CAM_CTX_CFG_MAX;
  164. ctx_base->max_in_map_entries = CAM_CTX_CFG_MAX;
  165. ctx_base->max_out_map_entries = CAM_CTX_CFG_MAX;
  166. err:
  167. return rc;
  168. }
  169. int cam_jpeg_context_deinit(struct cam_jpeg_context *ctx)
  170. {
  171. if (!ctx || !ctx->base) {
  172. CAM_ERR(CAM_JPEG, "Invalid params: %pK", ctx);
  173. return -EINVAL;
  174. }
  175. cam_context_deinit(ctx->base);
  176. memset(ctx, 0, sizeof(*ctx));
  177. return 0;
  178. }