cam_custom_context.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CUSTOM_CONTEXT_H_
  6. #define _CAM_CUSTOM_CONTEXT_H_
  7. #include <linux/spinlock.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. * @subscribe_event: The irq event mask that CRM subscribes to,
  86. * custom HW will invoke CRM cb at those event.
  87. * @active_req_cnt: Counter for the active request
  88. * @frame_id: Frame id tracking for the custom context
  89. * @hw_acquired: Flag to indicate if HW is acquired for this context
  90. * @process_bubble: If ctx currently processing bubble
  91. * @substate_actiavted: Current substate for the activated state.
  92. * @substate_machine: Custom substate machine for external interface
  93. * @substate_machine_irq: Custom substate machine for irq handling
  94. * @req_base: common request structure
  95. * @req_custom: custom request structure
  96. *
  97. */
  98. struct cam_custom_context {
  99. struct cam_context *base;
  100. struct cam_ctx_ops *state_machine;
  101. uint32_t state;
  102. void *hw_ctx;
  103. bool init_received;
  104. uint32_t subscribe_event;
  105. uint32_t active_req_cnt;
  106. int64_t frame_id;
  107. bool hw_acquired;
  108. uint32_t substate_activated;
  109. atomic_t process_bubble;
  110. struct cam_ctx_ops *substate_machine;
  111. struct cam_custom_ctx_irq_ops *substate_machine_irq;
  112. struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
  113. struct cam_custom_dev_ctx_req req_custom[CAM_CTX_REQ_MAX];
  114. };
  115. /**
  116. * cam_custom_dev_context_init()
  117. *
  118. * @brief: Initialization function for the custom context
  119. *
  120. * @ctx: Custom context obj to be initialized
  121. * @bridge_ops: Bridge call back funciton
  122. * @hw_intf: Cust hw manager interface
  123. * @ctx_id: ID for this context
  124. *
  125. */
  126. int cam_custom_dev_context_init(struct cam_custom_context *ctx,
  127. struct cam_context *ctx_base,
  128. struct cam_req_mgr_kmd_ops *bridge_ops,
  129. struct cam_hw_mgr_intf *hw_intf,
  130. uint32_t ctx_id);
  131. /**
  132. * cam_custom_dev_context_deinit()
  133. *
  134. * @brief: Deinitialize function for the Custom context
  135. *
  136. * @ctx: Custom context obj to be deinitialized
  137. *
  138. */
  139. int cam_custom_dev_context_deinit(struct cam_custom_context *ctx);
  140. #endif /* _CAM_CUSTOM_CONTEXT_H_ */