msm_vidc_inst.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021,, The Linux Foundation. All rights reserved.
  4. */
  5. /* Copyright (c) 2022. Qualcomm Innovation Center, Inc. All rights reserved. */
  6. #ifndef _MSM_VIDC_INST_H_
  7. #define _MSM_VIDC_INST_H_
  8. #include "msm_vidc_internal.h"
  9. #include "msm_vidc_memory.h"
  10. #include "hfi_property.h"
  11. struct msm_vidc_inst;
  12. #define FOREACH_STATE(STATE) { \
  13. STATE(NONE) \
  14. STATE(OPEN) \
  15. STATE(INPUT_STREAMING) \
  16. STATE(OUTPUT_STREAMING) \
  17. STATE(STREAMING) \
  18. STATE(CLOSE) \
  19. STATE(ERROR) \
  20. }
  21. #define call_session_op(c, op, ...) \
  22. (((c) && (c)->session_ops && (c)->session_ops->op) ? \
  23. ((c)->session_ops->op(__VA_ARGS__)) : 0)
  24. struct msm_vidc_session_ops {
  25. u64 (*calc_freq)(struct msm_vidc_inst *inst, u32 data_size);
  26. int (*calc_bw)(struct msm_vidc_inst *inst,
  27. struct vidc_bus_vote_data* vote_data);
  28. int (*decide_work_route)(struct msm_vidc_inst *inst);
  29. int (*decide_work_mode)(struct msm_vidc_inst *inst);
  30. int (*decide_quality_mode)(struct msm_vidc_inst *inst);
  31. int (*buffer_size)(struct msm_vidc_inst *inst, enum msm_vidc_buffer_type type);
  32. int (*min_count)(struct msm_vidc_inst *inst, enum msm_vidc_buffer_type type);
  33. int (*extra_count)(struct msm_vidc_inst *inst, enum msm_vidc_buffer_type type);
  34. };
  35. struct msm_vidc_allocations_info {
  36. struct msm_vidc_allocations bin;
  37. struct msm_vidc_allocations arp;
  38. struct msm_vidc_allocations comv;
  39. struct msm_vidc_allocations non_comv;
  40. struct msm_vidc_allocations line;
  41. struct msm_vidc_allocations dpb;
  42. struct msm_vidc_allocations persist;
  43. struct msm_vidc_allocations vpss;
  44. struct msm_vidc_allocations partial_data;
  45. };
  46. struct msm_vidc_mappings_info {
  47. struct msm_vidc_mappings bin;
  48. struct msm_vidc_mappings arp;
  49. struct msm_vidc_mappings comv;
  50. struct msm_vidc_mappings non_comv;
  51. struct msm_vidc_mappings line;
  52. struct msm_vidc_mappings dpb;
  53. struct msm_vidc_mappings persist;
  54. struct msm_vidc_mappings vpss;
  55. struct msm_vidc_mappings partial_data;
  56. };
  57. struct msm_vidc_buffers_info {
  58. struct msm_vidc_buffers input;
  59. struct msm_vidc_buffers output;
  60. struct msm_vidc_buffers read_only;
  61. struct msm_vidc_buffers input_meta;
  62. struct msm_vidc_buffers output_meta;
  63. struct msm_vidc_buffers bin;
  64. struct msm_vidc_buffers arp;
  65. struct msm_vidc_buffers comv;
  66. struct msm_vidc_buffers non_comv;
  67. struct msm_vidc_buffers line;
  68. struct msm_vidc_buffers dpb;
  69. struct msm_vidc_buffers persist;
  70. struct msm_vidc_buffers vpss;
  71. struct msm_vidc_buffers partial_data;
  72. };
  73. enum msm_vidc_state FOREACH_STATE(GENERATE_MSM_VIDC_ENUM);
  74. #define MSM_VIDC_SUB_STATE_NONE 0
  75. #define MSM_VIDC_MAX_SUB_STATES 6
  76. /*
  77. * max value of inst->sub_state if all
  78. * the 6 valid bits are set i.e 111111==>63
  79. */
  80. #define MSM_VIDC_MAX_SUB_STATE_VALUE ((1 << MSM_VIDC_MAX_SUB_STATES) - 1)
  81. enum msm_vidc_sub_state {
  82. MSM_VIDC_DRAIN = BIT(0),
  83. MSM_VIDC_DRC = BIT(1),
  84. MSM_VIDC_DRAIN_LAST_BUFFER = BIT(2),
  85. MSM_VIDC_DRC_LAST_BUFFER = BIT(3),
  86. MSM_VIDC_INPUT_PAUSE = BIT(4),
  87. MSM_VIDC_OUTPUT_PAUSE = BIT(5),
  88. };
  89. struct buf_queue {
  90. struct vb2_queue *vb2q;
  91. };
  92. struct msm_vidc_inst {
  93. struct list_head list;
  94. struct mutex lock;
  95. struct mutex request_lock;
  96. struct mutex client_lock;
  97. enum msm_vidc_state state;
  98. enum msm_vidc_sub_state sub_state;
  99. char sub_state_name[MAX_NAME_LENGTH];
  100. enum msm_vidc_domain_type domain;
  101. enum msm_vidc_codec_type codec;
  102. void *core;
  103. struct kref kref;
  104. u32 session_id;
  105. u8 debug_str[24];
  106. void *packet;
  107. u32 packet_size;
  108. struct v4l2_format fmts[MAX_PORT];
  109. struct v4l2_ctrl_handler ctrl_handler;
  110. struct v4l2_fh event_handler;
  111. struct v4l2_m2m_dev *m2m_dev;
  112. struct v4l2_m2m_ctx *m2m_ctx;
  113. struct v4l2_ctrl **ctrls;
  114. u32 num_ctrls;
  115. enum hfi_rate_control hfi_rc_type;
  116. enum hfi_layer_encoding_type hfi_layer_type;
  117. bool request;
  118. struct buf_queue bufq[MAX_PORT];
  119. struct msm_vidc_rectangle crop;
  120. struct msm_vidc_rectangle compose;
  121. struct msm_vidc_power power;
  122. struct vidc_bus_vote_data bus_data;
  123. struct msm_memory_pool pool[MSM_MEM_POOL_MAX];
  124. struct msm_vidc_buffers_info buffers;
  125. struct msm_vidc_mappings_info mappings;
  126. struct msm_vidc_allocations_info allocations;
  127. struct msm_vidc_timestamps timestamps;
  128. struct msm_vidc_timestamps ts_reorder; /* list of struct msm_vidc_timestamp */
  129. bool subscribed_input_psc;
  130. bool subscribed_output_psc;
  131. bool subscribed_input_prop;
  132. bool subscribed_output_prop;
  133. struct msm_vidc_subscription_params subcr_params[MAX_PORT];
  134. struct msm_vidc_hfi_frame_info hfi_frame_info;
  135. struct msm_vidc_decode_batch decode_batch;
  136. struct msm_vidc_decode_vpp_delay decode_vpp_delay;
  137. struct msm_vidc_session_idle session_idle;
  138. struct delayed_work stats_work;
  139. struct work_struct stability_work;
  140. struct msm_vidc_stability stability;
  141. struct workqueue_struct *workq;
  142. struct list_head enc_input_crs;
  143. struct list_head dmabuf_tracker; /* list of struct msm_memory_dmabuf */
  144. struct list_head input_timer_list; /* list of struct msm_vidc_input_timer */
  145. struct list_head caps_list;
  146. struct list_head children_list; /* struct msm_vidc_inst_cap_entry */
  147. struct list_head firmware_list; /* struct msm_vidc_inst_cap_entry */
  148. struct list_head pending_pkts; /* list of struct hfi_pending_packet */
  149. struct list_head fence_list; /* list of struct msm_vidc_fence */
  150. struct list_head buffer_stats_list; /* struct msm_vidc_buffer_stats */
  151. bool once_per_session_set;
  152. bool ipsc_properties_set;
  153. bool opsc_properties_set;
  154. struct dentry *debugfs_root;
  155. struct msm_vidc_debug debug;
  156. struct debug_buf_count debug_count;
  157. struct msm_vidc_statistics stats;
  158. struct msm_vidc_inst_capability *capabilities;
  159. struct completion completions[MAX_SIGNAL];
  160. struct msm_vidc_fence_context fence_context;
  161. bool active;
  162. u64 last_qbuf_time_ns;
  163. u64 initial_time_us;
  164. bool vb2q_init;
  165. u32 max_input_data_size;
  166. u32 dpb_list_payload[MAX_DPB_LIST_ARRAY_SIZE];
  167. u32 max_map_output_count;
  168. u32 auto_framerate;
  169. u32 max_rate;
  170. bool has_bframe;
  171. bool ir_enabled;
  172. u32 adjust_priority;
  173. bool iframe;
  174. };
  175. #endif // _MSM_VIDC_INST_H_