]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: qcom: iris: Add Long-Term Reference support for encoder
authorWangao Wang <wangao.wang@oss.qualcomm.com>
Tue, 12 May 2026 08:55:11 +0000 (16:55 +0800)
committerBryan O'Donoghue <bod@kernel.org>
Sat, 30 May 2026 07:41:48 +0000 (08:41 +0100)
Add Long-Term Reference(LTR) frame support for both gen1 and gen2
encoders by enabling the following V4L2 controls:
V4L2_CID_MPEG_VIDEO_LTR_COUNT
V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES
V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX

Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-HDK
Reviewed-by: Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>
Signed-off-by: Wangao Wang <wangao.wang@oss.qualcomm.com>
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
drivers/media/platform/qcom/iris/iris_ctrls.c
drivers/media/platform/qcom/iris/iris_ctrls.h
drivers/media/platform/qcom/iris/iris_hfi_gen1.c
drivers/media/platform/qcom/iris/iris_hfi_gen1_command.c
drivers/media/platform/qcom/iris/iris_hfi_gen1_defines.h
drivers/media/platform/qcom/iris/iris_hfi_gen2.c
drivers/media/platform/qcom/iris/iris_hfi_gen2_defines.h
drivers/media/platform/qcom/iris/iris_platform_common.h
drivers/media/platform/qcom/iris/iris_vpu_buffer.c

index 287cfc53294169cf5b75375105abc3c8c2d2a551..87d10ce1a9a572c5242d425b5a02abba01f911b5 100644 (file)
@@ -112,6 +112,12 @@ static enum platform_inst_fw_cap_type iris_get_cap_id(u32 id)
                return IR_TYPE;
        case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD:
                return IR_PERIOD;
+       case V4L2_CID_MPEG_VIDEO_LTR_COUNT:
+               return LTR_COUNT;
+       case V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES:
+               return USE_LTR;
+       case V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX:
+               return MARK_LTR;
        default:
                return INST_FW_CAP_MAX;
        }
@@ -213,6 +219,12 @@ static u32 iris_get_v4l2_id(enum platform_inst_fw_cap_type cap_id)
                return V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE;
        case IR_PERIOD:
                return V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD;
+       case LTR_COUNT:
+               return V4L2_CID_MPEG_VIDEO_LTR_COUNT;
+       case USE_LTR:
+               return V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES;
+       case MARK_LTR:
+               return V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX;
        default:
                return 0;
        }
@@ -1033,6 +1045,122 @@ int iris_set_ir_period_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_ty
                                             &ir_period, sizeof(u32));
 }
 
+int iris_set_ltr_count_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       u32 ltr_count = inst->fw_caps[cap_id].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       struct hfi_ltr_mode ltr_mode;
+
+       if (!ltr_count)
+               return -EINVAL;
+
+       ltr_mode.count = ltr_count;
+       ltr_mode.mode = HFI_LTR_MODE_MANUAL;
+       ltr_mode.trust_mode = 1;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_STRUCTURE,
+                                            &ltr_mode, sizeof(ltr_mode));
+}
+
+int iris_set_use_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       struct vb2_queue *sq = v4l2_m2m_get_src_vq(inst->m2m_ctx);
+       struct vb2_queue *dq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
+       u32 ltr_count = inst->fw_caps[LTR_COUNT].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       struct hfi_ltr_use ltr_use;
+
+       if (!vb2_is_streaming(sq) && !vb2_is_streaming(dq))
+               return -EINVAL;
+
+       if (!ltr_count)
+               return -EINVAL;
+
+       ltr_use.ref_ltr = inst->fw_caps[cap_id].value;
+       ltr_use.use_constrnt = true;
+       ltr_use.frames = 0;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_STRUCTURE,
+                                            &ltr_use, sizeof(ltr_use));
+}
+
+int iris_set_mark_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       struct vb2_queue *sq = v4l2_m2m_get_src_vq(inst->m2m_ctx);
+       struct vb2_queue *dq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
+       u32 ltr_count = inst->fw_caps[LTR_COUNT].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       struct hfi_ltr_mark ltr_mark;
+
+       if (!vb2_is_streaming(sq) && !vb2_is_streaming(dq))
+               return -EINVAL;
+
+       if (!ltr_count)
+               return -EINVAL;
+
+       ltr_mark.mark_frame = inst->fw_caps[cap_id].value;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_STRUCTURE,
+                                            &ltr_mark, sizeof(ltr_mark));
+}
+
+int iris_set_ltr_count_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       u32 ltr_count = inst->fw_caps[cap_id].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+
+       if (!ltr_count)
+               return -EINVAL;
+
+       if (inst->hfi_rc_type == HFI_RC_CBR_VFR ||
+           inst->hfi_rc_type == HFI_RC_CBR_CFR ||
+           inst->hfi_rc_type == HFI_RC_OFF) {
+               inst->fw_caps[LTR_COUNT].value = 0;
+               return -EINVAL;
+       }
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_U32,
+                                            &ltr_count, sizeof(u32));
+}
+
+int iris_set_use_and_mark_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       struct vb2_queue *sq = v4l2_m2m_get_src_vq(inst->m2m_ctx);
+       struct vb2_queue *dq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
+       u32 ltr_count = inst->fw_caps[LTR_COUNT].value;
+       u32 hfi_val = inst->fw_caps[cap_id].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+
+       if (!vb2_is_streaming(sq) && !vb2_is_streaming(dq))
+               return -EINVAL;
+
+       if (!ltr_count || hfi_val == INVALID_DEFAULT_MARK_OR_USE_LTR)
+               return -EINVAL;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_U32,
+                                            &hfi_val, sizeof(u32));
+}
+
 int iris_set_properties(struct iris_inst *inst, u32 plane)
 {
        const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
index a0d5338bdc910bd30407132e8b700c333ad74e4c..996c83fdc6f492dc252771129fc1d62e8b7a7e07 100644 (file)
@@ -36,6 +36,11 @@ int iris_set_rotation(struct iris_inst *inst, enum platform_inst_fw_cap_type cap
 int iris_set_flip(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_ir_period_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_ir_period_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_ltr_count_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_ltr_count_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_use_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_mark_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_use_and_mark_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_properties(struct iris_inst *inst, u32 plane);
 
 #endif
index 9344d20042fd4dd5ed123463a93188f36efbd137..6db693a602aca296f032dfc31987071f8e15bd1c 100644 (file)
@@ -243,6 +243,36 @@ static const struct platform_inst_fw_cap inst_fw_cap_sm8250_enc[] = {
                .flags = CAP_FLAG_OUTPUT_PORT,
                .set = iris_set_ir_period_gen1,
        },
+       {
+               .cap_id = LTR_COUNT,
+               .min = 0,
+               .max = MAX_LTR_FRAME_COUNT_GEN1,
+               .step_or_mask = 1,
+               .value = 0,
+               .hfi_id = HFI_PROPERTY_PARAM_VENC_LTRMODE,
+               .flags = CAP_FLAG_OUTPUT_PORT,
+               .set = iris_set_ltr_count_gen1,
+       },
+       {
+               .cap_id = USE_LTR,
+               .min = 0,
+               .max = ((1 << MAX_LTR_FRAME_COUNT_GEN1) - 1),
+               .step_or_mask = 0,
+               .value = 0,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_USELTRFRAME,
+               .flags = CAP_FLAG_INPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_use_ltr,
+       },
+       {
+               .cap_id = MARK_LTR,
+               .min = 0,
+               .max = (MAX_LTR_FRAME_COUNT_GEN1 - 1),
+               .step_or_mask = 1,
+               .value = 0,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME,
+               .flags = CAP_FLAG_INPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_mark_ltr,
+       },
 };
 
 static const u32 sm8250_vdec_input_config_param_default[] = {
index 051ba0d157c77263ea57b15296c86f61629621de..a441c897aaabdf1ecae37d34032cd22d4f987233 100644 (file)
@@ -695,6 +695,31 @@ iris_hfi_gen1_packet_session_set_property(struct hfi_session_set_property_pkt *p
                packet->shdr.hdr.size += sizeof(u32) + sizeof(*intra_refresh);
                break;
        }
+       case HFI_PROPERTY_PARAM_VENC_LTRMODE: {
+               struct hfi_ltr_mode *in = pdata, *ltr_mode = prop_data;
+
+               ltr_mode->mode = in->mode;
+               ltr_mode->count = in->count;
+               ltr_mode->trust_mode = in->trust_mode;
+               packet->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_mode);
+               break;
+       }
+       case HFI_PROPERTY_CONFIG_VENC_USELTRFRAME: {
+               struct hfi_ltr_use *in = pdata, *ltr_use = prop_data;
+
+               ltr_use->frames = in->frames;
+               ltr_use->ref_ltr = in->ref_ltr;
+               ltr_use->use_constrnt = in->use_constrnt;
+               packet->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_use);
+               break;
+       }
+       case HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME: {
+               struct hfi_ltr_mark *in = pdata, *ltr_mark = prop_data;
+
+               ltr_mark->mark_frame = in->mark_frame;
+               packet->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_mark);
+               break;
+       }
        default:
                return -EINVAL;
        }
index 04c79ee0463d7f32a2042044fe4564718cc01561..34249fc0d047918c2463517b8303e30df3666b97 100644 (file)
 #define HFI_INTRA_REFRESH_RANDOM               0x5
 
 #define HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH                  0x200500d
+
+#define HFI_LTR_MODE_DISABLE                   0x0
+#define HFI_LTR_MODE_MANUAL                    0x1
+#define HFI_LTR_MODE_PERIODIC                  0x2
+
+#define HFI_PROPERTY_PARAM_VENC_LTRMODE                                0x200501c
 #define HFI_PROPERTY_PARAM_VENC_MAX_NUM_B_FRAMES               0x2005020
 #define HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE                        0x2006001
+#define HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME                  0x2006009
+#define HFI_PROPERTY_CONFIG_VENC_USELTRFRAME                   0x200600a
 #define HFI_PROPERTY_CONFIG_VENC_SYNC_FRAME_SEQUENCE_HEADER    0x2006008
 
 struct hfi_pkt_hdr {
@@ -460,6 +468,22 @@ struct hfi_intra_refresh {
        u32 mbs;
 };
 
+struct hfi_ltr_mode {
+       u32 mode;
+       u32 count;
+       u32 trust_mode;
+};
+
+struct hfi_ltr_use {
+       u32 ref_ltr;
+       u32 use_constrnt;
+       u32 frames;
+};
+
+struct hfi_ltr_mark {
+       u32 mark_frame;
+};
+
 struct hfi_event_data {
        u32 error;
        u32 height;
index 401519fef0e2e87152e3c7fd7080490e9659d60d..495327160ec292f5fdc8f9532054c58046a10250 100644 (file)
@@ -715,6 +715,36 @@ static const struct platform_inst_fw_cap inst_fw_cap_sm8550_enc[] = {
                        CAP_FLAG_DYNAMIC_ALLOWED,
                .set = iris_set_ir_period_gen2,
        },
+       {
+               .cap_id = LTR_COUNT,
+               .min = 0,
+               .max = MAX_LTR_FRAME_COUNT_GEN2,
+               .step_or_mask = 1,
+               .value = 0,
+               .hfi_id = HFI_PROP_LTR_COUNT,
+               .flags = CAP_FLAG_OUTPUT_PORT,
+               .set = iris_set_ltr_count_gen2,
+       },
+       {
+               .cap_id = USE_LTR,
+               .min = 0,
+               .max = ((1 << MAX_LTR_FRAME_COUNT_GEN2) - 1),
+               .step_or_mask = 0,
+               .value = 0,
+               .hfi_id = HFI_PROP_LTR_USE,
+               .flags = CAP_FLAG_INPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_use_and_mark_ltr,
+       },
+       {
+               .cap_id = MARK_LTR,
+               .min = INVALID_DEFAULT_MARK_OR_USE_LTR,
+               .max = (MAX_LTR_FRAME_COUNT_GEN2 - 1),
+               .step_or_mask = 1,
+               .value = INVALID_DEFAULT_MARK_OR_USE_LTR,
+               .hfi_id = HFI_PROP_LTR_MARK,
+               .flags = CAP_FLAG_INPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_use_and_mark_ltr,
+       },
 };
 
 static const u32 sm8550_vdec_input_config_params_default[] = {
index cecf771c55dd36a13616344ff4583bf1d0544e17..aec19efc41a5ef47bbad2471d3c4575704859743 100644 (file)
@@ -71,6 +71,9 @@ enum hfi_rate_control {
 #define HFI_PROP_MIN_QP_PACKED                 0x0300012f
 #define HFI_PROP_MAX_QP_PACKED                 0x03000130
 #define HFI_PROP_IR_RANDOM_PERIOD              0x03000131
+#define HFI_PROP_LTR_COUNT                     0x03000134
+#define HFI_PROP_LTR_MARK                      0x03000135
+#define HFI_PROP_LTR_USE                       0x03000136
 #define HFI_PROP_TOTAL_BITRATE                 0x0300013b
 #define HFI_PROP_MAX_GOP_FRAMES                        0x03000146
 #define HFI_PROP_MAX_B_FRAMES                  0x03000147
index 6a108173be3548af9868697c2557e353136d147d..2f4392e6a42ea9280d48ae46791277394b2f3be8 100644 (file)
@@ -28,6 +28,9 @@ struct iris_inst;
 #define MAX_QP_HEVC                            63
 #define DEFAULT_QP                             20
 #define BITRATE_DEFAULT                        20000000
+#define INVALID_DEFAULT_MARK_OR_USE_LTR                -1
+#define MAX_LTR_FRAME_COUNT_GEN1               4
+#define MAX_LTR_FRAME_COUNT_GEN2               2
 
 enum stage_type {
        STAGE_1 = 1,
@@ -151,6 +154,9 @@ enum platform_inst_fw_cap_type {
        VFLIP,
        IR_TYPE,
        IR_PERIOD,
+       LTR_COUNT,
+       USE_LTR,
+       MARK_LTR,
        INST_FW_CAP_MAX,
 };
 
index 9270422c16019ba658ee8813940cb9110ad030a1..891aed5091c7a0fd0bf1f1a3a7737d49e6d8cea2 100644 (file)
@@ -934,6 +934,19 @@ static u32 iris_vpu_enc_bin_size(struct iris_inst *inst)
                                  num_vpp_pipes, inst->hfi_rc_type);
 }
 
+static inline u32 hfi_buffer_get_recon_count(struct iris_inst *inst)
+{
+       u32 num_ref = 1;
+       u32 ltr_count;
+
+       ltr_count = inst->fw_caps[LTR_COUNT].value;
+
+       if (ltr_count)
+               num_ref = num_ref + ltr_count;
+
+       return num_ref;
+}
+
 static u32 iris_vpu_dec_partial_size(struct iris_inst *inst)
 {
        struct v4l2_format *f = inst->fmt_src;
@@ -968,7 +981,7 @@ static u32 iris_vpu_enc_comv_size(struct iris_inst *inst)
 {
        u32 height = iris_vpu_enc_get_bitstream_height(inst);
        u32 width = iris_vpu_enc_get_bitstream_width(inst);
-       u32 num_recon = 1;
+       u32 num_recon = hfi_buffer_get_recon_count(inst);
        u32 lcu_size = 16;
 
        if (inst->codec == V4L2_PIX_FMT_HEVC) {
@@ -1677,10 +1690,9 @@ static u32 iris_vpu_enc_scratch2_size(struct iris_inst *inst)
 {
        u32 frame_height = iris_vpu_enc_get_bitstream_height(inst);
        u32 frame_width = iris_vpu_enc_get_bitstream_width(inst);
-       u32 num_ref = 1;
+       u32 num_ref = hfi_buffer_get_recon_count(inst);
 
-       return hfi_buffer_scratch2_enc(frame_width, frame_height, num_ref,
-                                      false);
+       return hfi_buffer_scratch2_enc(frame_width, frame_height, num_ref, false);
 }
 
 static u32 iris_vpu_enc_vpss_size(struct iris_inst *inst)