From patchwork Wed Nov 11 14:37:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 323141 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp443393ils; Wed, 11 Nov 2020 06:39:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsrPs/CNghjzakcFQ/gWNyr5WiFVEs7F8pRKvs2O64eUPYUIPQ+8aiinPHhk+fo9fJMzsS X-Received: by 2002:a17:906:6013:: with SMTP id o19mr24938626ejj.348.1605105545908; Wed, 11 Nov 2020 06:39:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605105545; cv=none; d=google.com; s=arc-20160816; b=CudJ7FPzLaDyW4FkAEeWSg/bphO5SpRBY9VF1xP36grzmfWoN7azr7kb1xLa3wFBdF OfUZveJN4c3nRPcgxetC8IXXkEBIm0Clhd72riGZi2p/YhA1hRjn0lTDBgEekBclnqqy ffL5clzCyZoffKJtDiIKANt2Ad130HH9ItyuDtHXOP2H3saXJWeh9EthChupkt6vjW39 vMCZeRXLaeMbSpesTVisqBNRiJxjyNlAO2MTt3eERXUPOcqJ1T6tDYhXemWdKX2TcgIm nl9JKmfA6jbwtbZdNPA9GnhZgmYEiBAItYtMkiVMGiWHwo8GOR44J8xrlTuiRnHdDTO1 bO1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=v6PMbdcIaoeKpv1BZw7/QGsGTQk22a+f7y9ODfXyJpE=; b=fZM+HX9DcX1wKNmmlXRvOj6jy0rcIv3a6dw5yqSiQq4uDsCC06a/4QMrNMkU0CvslM 2TZht8NR3lc0TiulrANb+6ibt1bpTkJ9gunLVre2+hAGMsqo984og4cACrKNrLkodS+K sWdwu9DREB1BXapAwMcyFIGQWZ4hhtZr3BOWCAwBmUL7RvRJDHWfnOviIlKDo35Heqpa NQm0ODfiHGWCF901yCfZRo1/GHUWlpFve/u682/LA3bNr8ogdH+t46BH0eQVpLc2GUGX mSvE8kbMyEQII2Jfy7YKj3pz0lvsVu4eXWoxgndiA98+1UT5zk+jz+SUYKsdgLKoiP0o xh0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RFJWXOGA; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ho36si1583425ejc.640.2020.11.11.06.39.04; Wed, 11 Nov 2020 06:39:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RFJWXOGA; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbgKKOjC (ORCPT + 15 others); Wed, 11 Nov 2020 09:39:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727143AbgKKOik (ORCPT ); Wed, 11 Nov 2020 09:38:40 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7467BC061A52 for ; Wed, 11 Nov 2020 06:38:36 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id p22so2466476wmg.3 for ; Wed, 11 Nov 2020 06:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v6PMbdcIaoeKpv1BZw7/QGsGTQk22a+f7y9ODfXyJpE=; b=RFJWXOGAFWIA2m0DXMEeGx7fabcVR1mMGdq6TnQs1KjP24WoouQwbboYBzRcmp8jpB qi9Ny8SkABPKT9dqzlz26bVcCblnJUVm3OoDDfUZLpTjMg2LgEFlOiRSH4vMjpjZChEl vMu2jvUoBdokjDTEeM9ZhroBqIfQpJWpk2WEumL9qDGbn53+qYvWOKy6TlDbkHDARkBl UcnQGFPQTO+rI14M8It/CepOqeJFw/CpN2K2hf3jyZJGUEesPkpOAX84zNwOTE9wMJql l8iQpQFls1hnJOY9ixraUMmToUy9fCC+2LpceNKAGBwy11muuFWfBlupdTv84X/Mpp01 fpEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v6PMbdcIaoeKpv1BZw7/QGsGTQk22a+f7y9ODfXyJpE=; b=ELwyxEOFiheMzCSZJDyhXRFFY2hn8yn7UDRPYnl0u8q+AuWpuD4+LaJ5t5RXb+0W2m 4a3aAZn0m46sN21UK8Of8UJKIoTpR0Gx9Wsztanq5igbxespSZ5fxfCK5k1Wqf1uOBiK SJaQCUthdmzSF3TscdcEdAXBegFbFQgD6A5Yj4W4gw49zMbXeE6BVHi7xjMYwRXzOJGJ +tz+3+Xoax028gU4mOjbU1bj+W6YTO4H6SBmfBZOAgIqW6KTr556gJLQUdxUfmeRcdwi BvM8cKgLWYa/bGZ9sZt/N5eRabeJKHKw5UciMVXHeSL8GWVcWJiYnNKh6IPaeh/uSBNb yKQQ== X-Gm-Message-State: AOAM530X+B/aImaAc5JcVrOBzvXdwLjmoxn4s0p9bUmW7zG6gjZv/HUu zXWOC32/BtKwBtRU0+9T5SfpjA== X-Received: by 2002:a1c:c302:: with SMTP id t2mr4671828wmf.189.1605105515148; Wed, 11 Nov 2020 06:38:35 -0800 (PST) Received: from localhost.localdomain (hst-221-89.medicom.bg. [84.238.221.89]) by smtp.gmail.com with ESMTPSA id b8sm2991405wrv.57.2020.11.11.06.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 06:38:34 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Vikash Garodia , Alexandre Courbot , Fritz Koenig , Stanimir Varbanov Subject: [PATCH v2 7/8] venus: venc: Handle reset encoder state Date: Wed, 11 Nov 2020 16:37:54 +0200 Message-Id: <20201111143755.24541-8-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111143755.24541-1-stanimir.varbanov@linaro.org> References: <20201111143755.24541-1-stanimir.varbanov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Redesign the encoder driver to be compliant with stateful encoder spec - specifically adds handling of Reset state. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/venc.c | 155 ++++++++++++++++++----- 1 file changed, 122 insertions(+), 33 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 7512e4a16270..f1ae89d45a54 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -907,6 +907,54 @@ static int venc_queue_setup(struct vb2_queue *q, return ret; } +static void venc_release_session(struct venus_inst *inst) +{ + int ret, abort = 0; + + mutex_lock(&inst->lock); + + ret = hfi_session_deinit(inst); + abort = (ret && ret != -EINVAL) ? 1 : 0; + + if (inst->session_error) + abort = 1; + + if (abort) + hfi_session_abort(inst); + + venus_pm_load_scale(inst); + INIT_LIST_HEAD(&inst->registeredbufs); + mutex_unlock(&inst->lock); + + venus_pm_release_core(inst); +} + +static int venc_buf_init(struct vb2_buffer *vb) +{ + struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); + + inst->buf_count++; + + return venus_helper_vb2_buf_init(vb); +} + +static void venc_buf_cleanup(struct vb2_buffer *vb) +{ + struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct venus_buffer *buf = to_venus_buffer(vbuf); + + mutex_lock(&inst->lock); + if (vb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) + if (!list_empty(&inst->registeredbufs)) + list_del_init(&buf->reg_list); + mutex_unlock(&inst->lock); + + inst->buf_count--; + if (!inst->buf_count) + venc_release_session(inst); +} + static int venc_verify_conf(struct venus_inst *inst) { enum hfi_version ver = inst->core->res->hfi_version; @@ -938,49 +986,57 @@ static int venc_verify_conf(struct venus_inst *inst) static int venc_start_streaming(struct vb2_queue *q, unsigned int count) { struct venus_inst *inst = vb2_get_drv_priv(q); + struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx; int ret; mutex_lock(&inst->lock); - if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) + v4l2_m2m_update_start_streaming_state(m2m_ctx, q); + + if (V4L2_TYPE_IS_OUTPUT(q->type)) inst->streamon_out = 1; else inst->streamon_cap = 1; - if (!(inst->streamon_out & inst->streamon_cap)) { - mutex_unlock(&inst->lock); - return 0; - } + if (inst->streamon_out && inst->streamon_cap && + inst->state == INST_UNINIT) { + venus_helper_init_instance(inst); - venus_helper_init_instance(inst); + inst->sequence_cap = 0; + inst->sequence_out = 0; - inst->sequence_cap = 0; - inst->sequence_out = 0; + ret = venc_init_session(inst); + if (ret) + goto bufs_done; - ret = venc_init_session(inst); - if (ret) - goto bufs_done; + ret = venus_pm_acquire_core(inst); + if (ret) + goto deinit_sess; - ret = venus_pm_acquire_core(inst); - if (ret) - goto deinit_sess; + ret = venc_verify_conf(inst); + if (ret) + goto deinit_sess; - ret = venc_set_properties(inst); - if (ret) - goto deinit_sess; + ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, + inst->num_output_bufs, 0); + if (ret) + goto deinit_sess; - ret = venc_verify_conf(inst); - if (ret) - goto deinit_sess; + ret = venus_helper_vb2_start_streaming(inst); + if (ret) + goto deinit_sess; - ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, - inst->num_output_bufs, 0); - if (ret) - goto deinit_sess; + venus_helper_process_initial_out_bufs(inst); + venus_helper_process_initial_cap_bufs(inst); + } else if (V4L2_TYPE_IS_CAPTURE(q->type) && inst->streamon_cap && + inst->streamon_out) { + ret = venus_helper_vb2_start_streaming(inst); + if (ret) + goto bufs_done; - ret = venus_helper_vb2_start_streaming(inst); - if (ret) - goto deinit_sess; + venus_helper_process_initial_out_bufs(inst); + venus_helper_process_initial_cap_bufs(inst); + } mutex_unlock(&inst->lock); @@ -990,15 +1046,43 @@ static int venc_start_streaming(struct vb2_queue *q, unsigned int count) hfi_session_deinit(inst); bufs_done: venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); - if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) + if (V4L2_TYPE_IS_OUTPUT(q->type)) inst->streamon_out = 0; else inst->streamon_cap = 0; + mutex_unlock(&inst->lock); return ret; } -static void venc_vb2_buf_queue(struct vb2_buffer *vb) +static void venc_stop_streaming(struct vb2_queue *q) +{ + struct venus_inst *inst = vb2_get_drv_priv(q); + struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx; + int ret = -EINVAL; + + mutex_lock(&inst->lock); + + v4l2_m2m_clear_state(m2m_ctx); + + if (V4L2_TYPE_IS_CAPTURE(q->type)) { + ret = hfi_session_stop(inst); + ret |= hfi_session_unload_res(inst); + ret |= venus_helper_unregister_bufs(inst); + ret |= venus_helper_intbufs_free(inst); + } + + venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_ERROR); + + if (V4L2_TYPE_IS_OUTPUT(q->type)) + inst->streamon_out = 0; + else + inst->streamon_cap = 0; + + mutex_unlock(&inst->lock); +} + +static void venc_buf_queue(struct vb2_buffer *vb) { struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); @@ -1022,11 +1106,12 @@ static void venc_vb2_buf_queue(struct vb2_buffer *vb) static const struct vb2_ops venc_vb2_ops = { .queue_setup = venc_queue_setup, - .buf_init = venus_helper_vb2_buf_init, + .buf_init = venc_buf_init, + .buf_cleanup = venc_buf_cleanup, .buf_prepare = venus_helper_vb2_buf_prepare, .start_streaming = venc_start_streaming, - .stop_streaming = venus_helper_vb2_stop_streaming, - .buf_queue = venc_vb2_buf_queue, + .stop_streaming = venc_stop_streaming, + .buf_queue = venc_buf_queue, }; static void venc_buf_done(struct venus_inst *inst, unsigned int buf_type, @@ -1084,8 +1169,12 @@ static const struct hfi_inst_ops venc_hfi_ops = { .event_notify = venc_event_notify, }; +static void venc_m2m_device_run(void *priv) +{ +} + static const struct v4l2_m2m_ops venc_m2m_ops = { - .device_run = venus_helper_m2m_device_run, + .device_run = venc_m2m_device_run, .job_abort = venus_helper_m2m_job_abort, };