Эх сурвалжийг харах

Merge "video: driver: acquire lock for request queue"

qctecmdr 3 жил өмнө
parent
commit
098d0f1579

+ 0 - 15
driver/vidc/src/msm_vidc.c

@@ -480,33 +480,18 @@ int msm_vidc_qbuf(void *instance, struct media_device *mdev,
 	int rc = 0;
 	struct msm_vidc_inst *inst = instance;
 	struct vb2_queue *q;
-	u64 timestamp_us = 0;
 
 	if (!inst || !inst->core || !b || !valid_v4l2_buffer(b, inst)) {
 		d_vpr_e("%s: invalid params %pK %pK\n", __func__, inst, b);
 		return -EINVAL;
 	}
 
-	/* Expecting non-zero filledlen on INPUT port */
-	if (b->type == INPUT_MPLANE && !b->m.planes[0].bytesused) {
-		i_vpr_e(inst,
-			"%s: zero bytesused input buffer not supported\n", __func__);
-		return -EINVAL;
-	}
-
 	q = msm_vidc_get_vb2q(inst, b->type, __func__);
 	if (!q) {
 		rc = -EINVAL;
 		goto exit;
 	}
 
-	if (is_encode_session(inst) && b->type == INPUT_MPLANE) {
-		timestamp_us = (u64)((b->timestamp.tv_sec * USEC_PER_SEC) +
-			b->timestamp.tv_usec);
-		msm_vidc_set_auto_framerate(inst, timestamp_us);
-	}
-	inst->last_qbuf_time_ns = ktime_get_ns();
-
 	rc = vb2_qbuf(q, mdev, b);
 	if (rc)
 		i_vpr_e(inst, "%s: failed with %d\n", __func__, rc);

+ 10 - 9
driver/vidc/src/msm_vidc_v4l2.c

@@ -384,18 +384,19 @@ int msm_v4l2_qbuf(struct file *filp, void *fh,
 		return -EINVAL;
 	}
 
-	inst_lock(inst, __func__);
-	if (is_session_error(inst)) {
-		i_vpr_e(inst, "%s: inst in error state\n", __func__);
-		rc = -EBUSY;
-		goto unlock;
-	}
+	/*
+	 * do not acquire inst lock here. acquire it in msm_vidc_buf_queue.
+	 * for requests, msm_vidc_buf_queue() is not called from here.
+	 * instead it's called as part of msm_v4l2_request_queue().
+	 * hence acquire the inst lock in common function i.e
+	 * msm_vidc_buf_queue, to handle both requests and non-request
+	 * scenarios.
+	 */
 	rc = msm_vidc_qbuf(inst, vdev->v4l2_dev->mdev, b);
 	if (rc)
-		goto unlock;
+		goto exit;
 
-unlock:
-	inst_unlock(inst, __func__);
+exit:
 	put_inst(inst);
 
 	return rc;

+ 40 - 9
driver/vidc/src/msm_vidc_vb2.c

@@ -15,6 +15,8 @@
 #include "msm_vidc_debug.h"
 #include "msm_vidc_control.h"
 
+extern struct msm_vidc_core *g_core;
+
 struct vb2_queue *msm_vidc_get_vb2q(struct msm_vidc_inst *inst,
 	u32 type, const char *func)
 {
@@ -352,6 +354,7 @@ void msm_vidc_buf_queue(struct vb2_buffer *vb2)
 {
 	int rc = 0;
 	struct msm_vidc_inst *inst;
+	u64 timestamp_us = 0;
 
 	inst = vb2_get_drv_priv(vb2->vb2_queue);
 	if (!inst) {
@@ -359,6 +362,32 @@ void msm_vidc_buf_queue(struct vb2_buffer *vb2)
 		return;
 	}
 
+	inst = get_inst_ref(g_core, inst);
+	if (!inst) {
+		d_vpr_e("%s: invalid instance\n", __func__);
+		return;
+	}
+
+	inst_lock(inst, __func__);
+	if (is_session_error(inst)) {
+		i_vpr_e(inst, "%s: inst in error state\n", __func__);
+		rc = -EINVAL;
+		goto unlock;
+	}
+
+	/* Expecting non-zero filledlen on INPUT port */
+	if (vb2->type == INPUT_MPLANE && !vb2->planes[0].bytesused) {
+		i_vpr_e(inst,
+			"%s: zero bytesused input buffer not supported\n", __func__);
+		rc = -EINVAL;
+		goto unlock;
+	}
+
+	if (is_encode_session(inst) && vb2->type == INPUT_MPLANE) {
+		timestamp_us = vb2->timestamp;
+		msm_vidc_set_auto_framerate(inst, timestamp_us);
+	}
+	inst->last_qbuf_time_ns = ktime_get_ns();
 	/*
 	 * As part of every qbuf initalise request to true.
 	 * If there are any dynamic controls associated with qbuf,
@@ -374,14 +403,14 @@ void msm_vidc_buf_queue(struct vb2_buffer *vb2)
 		inst->request = false;
 		i_vpr_e(inst, "%s: request setup failed, error %d\n",
 			__func__, rc);
-		goto error;
+		goto unlock;
 	}
 	inst->request = false;
 
 	if (inst->capabilities->cap[INPUT_META_VIA_REQUEST].value) {
 		rc = msm_vidc_update_input_meta_buffer_index(inst, vb2);
 		if (rc)
-			goto error;
+			goto unlock;
 	}
 
 	if (is_decode_session(inst))
@@ -390,17 +419,19 @@ void msm_vidc_buf_queue(struct vb2_buffer *vb2)
 		rc = msm_venc_qbuf(inst, vb2);
 	else
 		rc = -EINVAL;
-
 	if (rc) {
 		print_vb2_buffer("failed vb2-qbuf", inst, vb2);
-		goto error;
+		goto unlock;
 	}
-	return;
 
-error:
-	msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
-	v4l2_ctrl_request_complete(vb2->req_obj.req, &inst->ctrl_handler);
-	vb2_buffer_done(vb2, VB2_BUF_STATE_ERROR);
+unlock:
+	if (rc) {
+		msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
+		v4l2_ctrl_request_complete(vb2->req_obj.req, &inst->ctrl_handler);
+		vb2_buffer_done(vb2, VB2_BUF_STATE_ERROR);
+	}
+	inst_unlock(inst, __func__);
+	put_inst(inst);
 }
 
 void msm_vidc_buf_cleanup(struct vb2_buffer *vb)