cam_jpeg_context.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2019, 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, unsigned long iova,
  16. uint32_t buf_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. int rc = 0;
  23. int closest_port;
  24. bool b_mem_found = false;
  25. if (!ctx) {
  26. CAM_ERR(CAM_JPEG, "Invalid ctx");
  27. return -EINVAL;
  28. }
  29. CAM_INFO(CAM_JPEG, "iommu fault for jpeg ctx %d state %d",
  30. ctx->ctx_id, ctx->state);
  31. list_for_each_entry_safe(req, req_temp,
  32. &ctx->active_req_list, list) {
  33. pf_dbg_entry = &(req->pf_data);
  34. closest_port = -1;
  35. CAM_INFO(CAM_JPEG, "req_id : %lld ", req->request_id);
  36. rc = cam_context_dump_pf_info_to_hw(ctx, pf_dbg_entry->packet,
  37. iova, buf_info, &b_mem_found);
  38. if (rc)
  39. CAM_ERR(CAM_JPEG, "Failed to dump pf info");
  40. if (b_mem_found)
  41. CAM_ERR(CAM_JPEG, "Found page fault in req %lld %d",
  42. req->request_id, rc);
  43. }
  44. return rc;
  45. }
  46. static int __cam_jpeg_ctx_acquire_dev_in_available(struct cam_context *ctx,
  47. struct cam_acquire_dev_cmd *cmd)
  48. {
  49. int rc;
  50. rc = cam_context_acquire_dev_to_hw(ctx, cmd);
  51. if (rc)
  52. CAM_ERR(CAM_JPEG, "Unable to Acquire device %d", rc);
  53. else
  54. ctx->state = CAM_CTX_ACQUIRED;
  55. return rc;
  56. }
  57. static int __cam_jpeg_ctx_release_dev_in_acquired(struct cam_context *ctx,
  58. struct cam_release_dev_cmd *cmd)
  59. {
  60. int rc;
  61. rc = cam_context_release_dev_to_hw(ctx, cmd);
  62. if (rc)
  63. CAM_ERR(CAM_JPEG, "Unable to release device %d", rc);
  64. ctx->state = CAM_CTX_AVAILABLE;
  65. return rc;
  66. }
  67. static int __cam_jpeg_ctx_flush_dev_in_acquired(struct cam_context *ctx,
  68. struct cam_flush_dev_cmd *cmd)
  69. {
  70. int rc;
  71. rc = cam_context_flush_dev_to_hw(ctx, cmd);
  72. if (rc)
  73. CAM_ERR(CAM_ICP, "Failed to flush device");
  74. return rc;
  75. }
  76. static int __cam_jpeg_ctx_config_dev_in_acquired(struct cam_context *ctx,
  77. struct cam_config_dev_cmd *cmd)
  78. {
  79. return cam_context_prepare_dev_to_hw(ctx, cmd);
  80. }
  81. static int __cam_jpeg_ctx_handle_buf_done_in_acquired(void *ctx,
  82. uint32_t evt_id, void *done)
  83. {
  84. return cam_context_buf_done_from_hw(ctx, done, evt_id);
  85. }
  86. static int __cam_jpeg_ctx_stop_dev_in_acquired(struct cam_context *ctx,
  87. struct cam_start_stop_dev_cmd *cmd)
  88. {
  89. int rc;
  90. rc = cam_context_stop_dev_to_hw(ctx);
  91. if (rc) {
  92. CAM_ERR(CAM_JPEG, "Failed in Stop dev, rc=%d", rc);
  93. return rc;
  94. }
  95. return rc;
  96. }
  97. /* top state machine */
  98. static struct cam_ctx_ops
  99. cam_jpeg_ctx_state_machine[CAM_CTX_STATE_MAX] = {
  100. /* Uninit */
  101. {
  102. .ioctl_ops = { },
  103. .crm_ops = { },
  104. .irq_ops = NULL,
  105. },
  106. /* Available */
  107. {
  108. .ioctl_ops = {
  109. .acquire_dev = __cam_jpeg_ctx_acquire_dev_in_available,
  110. },
  111. .crm_ops = { },
  112. .irq_ops = NULL,
  113. },
  114. /* Acquired */
  115. {
  116. .ioctl_ops = {
  117. .release_dev = __cam_jpeg_ctx_release_dev_in_acquired,
  118. .config_dev = __cam_jpeg_ctx_config_dev_in_acquired,
  119. .stop_dev = __cam_jpeg_ctx_stop_dev_in_acquired,
  120. .flush_dev = __cam_jpeg_ctx_flush_dev_in_acquired,
  121. },
  122. .crm_ops = { },
  123. .irq_ops = __cam_jpeg_ctx_handle_buf_done_in_acquired,
  124. .pagefault_ops = cam_jpeg_context_dump_active_request,
  125. },
  126. };
  127. int cam_jpeg_context_init(struct cam_jpeg_context *ctx,
  128. struct cam_context *ctx_base,
  129. struct cam_hw_mgr_intf *hw_intf,
  130. uint32_t ctx_id)
  131. {
  132. int rc;
  133. int i;
  134. if (!ctx || !ctx_base) {
  135. CAM_ERR(CAM_JPEG, "Invalid Context");
  136. rc = -EFAULT;
  137. goto err;
  138. }
  139. memset(ctx, 0, sizeof(*ctx));
  140. ctx->base = ctx_base;
  141. for (i = 0; i < CAM_CTX_REQ_MAX; i++)
  142. ctx->req_base[i].req_priv = ctx;
  143. rc = cam_context_init(ctx_base, jpeg_dev_name, CAM_JPEG, ctx_id,
  144. NULL, hw_intf, ctx->req_base, CAM_CTX_REQ_MAX);
  145. if (rc) {
  146. CAM_ERR(CAM_JPEG, "Camera Context Base init failed");
  147. goto err;
  148. }
  149. ctx_base->state_machine = cam_jpeg_ctx_state_machine;
  150. ctx_base->ctx_priv = ctx;
  151. err:
  152. return rc;
  153. }
  154. int cam_jpeg_context_deinit(struct cam_jpeg_context *ctx)
  155. {
  156. if (!ctx || !ctx->base) {
  157. CAM_ERR(CAM_JPEG, "Invalid params: %pK", ctx);
  158. return -EINVAL;
  159. }
  160. cam_context_deinit(ctx->base);
  161. memset(ctx, 0, sizeof(*ctx));
  162. return 0;
  163. }