cam_custom_context.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CUSTOM_CONTEXT_H_
  6. #define _CAM_CUSTOM_CONTEXT_H_
  7. #include <linux/spinlock_types.h>
  8. #include <media/cam_custom.h>
  9. #include <media/cam_defs.h>
  10. #include "cam_context.h"
  11. #include "cam_custom_hw_mgr_intf.h"
  12. /*
  13. * Maximum hw resource - This number is based on the maximum
  14. * output port resource. The current maximum resource number
  15. * is 2.
  16. */
  17. #define CAM_CUSTOM_DEV_CTX_RES_MAX 1
  18. #define CAM_CUSTOM_CTX_CFG_MAX 8
  19. /* forward declaration */
  20. struct cam_custom_context;
  21. /* cam custom context irq handling function type */
  22. typedef int (*cam_custom_hw_event_cb_func)(
  23. struct cam_custom_context *custom_ctx, void *evt_data);
  24. /**
  25. * enum cam_custom_ctx_activated_substate - sub states for activated
  26. *
  27. */
  28. enum cam_custom_ctx_activated_substate {
  29. CAM_CUSTOM_CTX_ACTIVATED_SOF,
  30. CAM_CUSTOM_CTX_ACTIVATED_APPLIED,
  31. CAM_CUSTOM_CTX_ACTIVATED_HW_ERROR,
  32. CAM_CUSTOM_CTX_ACTIVATED_HALT,
  33. CAM_CUSTOM_CTX_ACTIVATED_MAX,
  34. };
  35. /**
  36. * struct cam_custom_ctx_irq_ops - Function table for handling IRQ callbacks
  37. *
  38. * @irq_ops: Array of handle function pointers.
  39. *
  40. */
  41. struct cam_custom_ctx_irq_ops {
  42. cam_custom_hw_event_cb_func irq_ops[CAM_CUSTOM_HW_EVENT_MAX];
  43. };
  44. /**
  45. * struct cam_custom_dev_ctx_req - Custom context request object
  46. *
  47. * @base: Common request object pointer
  48. * @cfg: Custom hardware configuration array
  49. * @num_cfg: Number of custom hardware configuration entries
  50. * @fence_map_out: Output fence mapping array
  51. * @num_fence_map_out: Number of the output fence map
  52. * @fence_map_in: Input fence mapping array
  53. * @num_fence_map_in: Number of input fence map
  54. * @num_acked: Count to track acked entried for output.
  55. * If count equals the number of fence out, it means
  56. * the request has been completed.
  57. * @bubble_report: If bubble recovery is needed
  58. * @bubble_detected: request has bubbled
  59. * @hw_update_data: HW update data for this request
  60. *
  61. */
  62. struct cam_custom_dev_ctx_req {
  63. struct cam_ctx_request *base;
  64. struct cam_hw_update_entry cfg
  65. [CAM_CUSTOM_CTX_CFG_MAX];
  66. uint32_t num_cfg;
  67. struct cam_hw_fence_map_entry fence_map_out
  68. [CAM_CUSTOM_DEV_CTX_RES_MAX];
  69. uint32_t num_fence_map_out;
  70. struct cam_hw_fence_map_entry fence_map_in
  71. [CAM_CUSTOM_DEV_CTX_RES_MAX];
  72. uint32_t num_fence_map_in;
  73. uint32_t num_acked;
  74. int32_t bubble_report;
  75. bool bubble_detected;
  76. struct cam_custom_prepare_hw_update_data hw_update_data;
  77. };
  78. /**
  79. * struct cam_custom_context - Custom device context
  80. * @base: custom device context object
  81. * @state_machine: state machine for Custom device context
  82. * @state: Common context state
  83. * @hw_ctx: HW object returned by the acquire device command
  84. * @init_received: Indicate whether init config packet is received
  85. * @active_req_cnt: Counter for the active request
  86. * @frame_id: Frame id tracking for the custom context
  87. * @hw_acquired: Flag to indicate if HW is acquired for this context
  88. * @process_bubble: If ctx currently processing bubble
  89. * @substate_actiavted: Current substate for the activated state.
  90. * @substate_machine: Custom substate machine for external interface
  91. * @substate_machine_irq: Custom substate machine for irq handling
  92. * @req_base: common request structure
  93. * @req_custom: custom request structure
  94. *
  95. */
  96. struct cam_custom_context {
  97. struct cam_context *base;
  98. struct cam_ctx_ops *state_machine;
  99. uint32_t state;
  100. void *hw_ctx;
  101. bool init_received;
  102. uint32_t active_req_cnt;
  103. int64_t frame_id;
  104. bool hw_acquired;
  105. uint32_t substate_activated;
  106. atomic_t process_bubble;
  107. struct cam_ctx_ops *substate_machine;
  108. struct cam_custom_ctx_irq_ops *substate_machine_irq;
  109. struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
  110. struct cam_custom_dev_ctx_req req_custom[CAM_CTX_REQ_MAX];
  111. };
  112. /**
  113. * cam_custom_dev_context_init()
  114. *
  115. * @brief: Initialization function for the custom context
  116. *
  117. * @ctx: Custom context obj to be initialized
  118. * @bridge_ops: Bridge call back funciton
  119. * @hw_intf: Cust hw manager interface
  120. * @ctx_id: ID for this context
  121. * @img_iommu_hdl: IOMMU HDL for Image buffers
  122. *
  123. */
  124. int cam_custom_dev_context_init(struct cam_custom_context *ctx,
  125. struct cam_context *ctx_base,
  126. struct cam_req_mgr_kmd_ops *bridge_ops,
  127. struct cam_hw_mgr_intf *hw_intf,
  128. uint32_t ctx_id, int img_iommu_hdl);
  129. /**
  130. * cam_custom_dev_context_deinit()
  131. *
  132. * @brief: Deinitialize function for the Custom context
  133. *
  134. * @ctx: Custom context obj to be deinitialized
  135. *
  136. */
  137. int cam_custom_dev_context_deinit(struct cam_custom_context *ctx);
  138. #endif /* _CAM_CUSTOM_CONTEXT_H_ */