cam_custom_context.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (c) 2019, 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. * @hw_update_data: HW update data for this request
  58. *
  59. */
  60. struct cam_custom_dev_ctx_req {
  61. struct cam_ctx_request *base;
  62. struct cam_hw_update_entry cfg
  63. [CAM_CUSTOM_CTX_CFG_MAX];
  64. uint32_t num_cfg;
  65. struct cam_hw_fence_map_entry fence_map_out
  66. [CAM_CUSTOM_DEV_CTX_RES_MAX];
  67. uint32_t num_fence_map_out;
  68. struct cam_hw_fence_map_entry fence_map_in
  69. [CAM_CUSTOM_DEV_CTX_RES_MAX];
  70. uint32_t num_fence_map_in;
  71. uint32_t num_acked;
  72. struct cam_custom_prepare_hw_update_data hw_update_data;
  73. };
  74. /**
  75. * struct cam_custom_context - Custom device context
  76. * @base: custom device context object
  77. * @state_machine: state machine for Custom device context
  78. * @state: Common context state
  79. * @hw_ctx: HW object returned by the acquire device command
  80. * @init_received: Indicate whether init config packet is received
  81. * @subscribe_event: The irq event mask that CRM subscribes to,
  82. * custom HW will invoke CRM cb at those event.
  83. * @active_req_cnt: Counter for the active request
  84. * @frame_id: Frame id tracking for the custom context
  85. * @hw_acquired: Flag to indicate if HW is acquired for this context
  86. * @substate_actiavted: Current substate for the activated state.
  87. * @substate_machine: Custom substate machine for external interface
  88. * @substate_machine_irq: Custom substate machine for irq handling
  89. * @req_base: common request structure
  90. * @req_custom: custom request structure
  91. *
  92. */
  93. struct cam_custom_context {
  94. struct cam_context *base;
  95. struct cam_ctx_ops *state_machine;
  96. uint32_t state;
  97. void *hw_ctx;
  98. bool init_received;
  99. uint32_t subscribe_event;
  100. uint32_t active_req_cnt;
  101. int64_t frame_id;
  102. bool hw_acquired;
  103. uint32_t substate_activated;
  104. struct cam_ctx_ops *substate_machine;
  105. struct cam_custom_ctx_irq_ops *substate_machine_irq;
  106. struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
  107. struct cam_custom_dev_ctx_req req_custom[CAM_CTX_REQ_MAX];
  108. };
  109. /**
  110. * cam_custom_dev_context_init()
  111. *
  112. * @brief: Initialization function for the custom context
  113. *
  114. * @ctx: Custom context obj to be initialized
  115. * @bridge_ops: Bridge call back funciton
  116. * @hw_intf: Cust hw manager interface
  117. * @ctx_id: ID for this context
  118. *
  119. */
  120. int cam_custom_dev_context_init(struct cam_custom_context *ctx,
  121. struct cam_context *ctx_base,
  122. struct cam_req_mgr_kmd_ops *bridge_ops,
  123. struct cam_hw_mgr_intf *hw_intf,
  124. uint32_t ctx_id);
  125. /**
  126. * cam_custom_dev_context_deinit()
  127. *
  128. * @brief: Deinitialize function for the Custom context
  129. *
  130. * @ctx: Custom context obj to be deinitialized
  131. *
  132. */
  133. int cam_custom_dev_context_deinit(struct cam_custom_context *ctx);
  134. #endif /* _CAM_CUSTOM_CONTEXT_H_ */