From patchwork Fri Dec 4 10:01:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 337746 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp110395ilb; Fri, 4 Dec 2020 02:03:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2dd2tJgMTuzgmCtE9c8adPKxTg+sIPwu3/83rReyo/3gxwPyl4PoQchb3+6E3LJMLBvdx X-Received: by 2002:a17:906:1db1:: with SMTP id u17mr6369624ejh.359.1607076186323; Fri, 04 Dec 2020 02:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607076186; cv=none; d=google.com; s=arc-20160816; b=0GOFKGVjD74tjOk0ilUyKlRR3vJHzYh1EJiR9D8c0sj/bdU76wEvQd5pQdGcUGhoii goi2Fc374K1xPCGtQg1Y/VB7/puZ7CY3WJfp1dW3IQyIMCxSx80ijv2Zcj9IV0CEqSnD G21xDz4Q2Kb4qCGlmegIG+3nkIYKvF73lBOWHFs2nS9PzjxSL2pD3op0ItP1MogTBkxJ ZvzEage2FC8LF/kjfrLaGaJ9Nwpfy36BPUmarnHk37Al7DovWtBQ7g9KPFziwYBoSWCq azsHuahPidw9eEArSopaIZfPqQDcuorTGLc8A1r9hvFqPH8IRRmSxrTdHZUb6Qmaeovb sFEA== 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=/YIHndOkuyRiMsQ82HY4dIjLYZOfc93bxXe51T4cmZ0=; b=GR8uK0nSTAxdPhltfUgZ/dKBjemwtinkjDGLX31todyOOwbSekjtu1qA0a2xqRkd6R nm3VaIiKUY7XA4a6OuRydZo3moKc9vWctzQxi9T/tKNc0a62BjFkd+O0Nd8B0pi7EPwr 3hdJHZA8WxwM3pBRId1ji0sWiAvjt0ogumoto0s9T7sO3rZc0uhH+lq2OpaUuViQ/4Dr fkieQs464HuKaBtZz9S6AEKtf7c6DjOE5Knx4JF1gbY7gWEfaiGKJlnV2ABL64SgGNER eyA4165lcgJEaDHCeZUhFraErAfk5Xh4OHYiZhwB0ECWErhOX+htQS12uH50aC/54VMx qPLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRePSCV6; 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 v22si2652393edt.77.2020.12.04.02.03.05; Fri, 04 Dec 2020 02:03:06 -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=SRePSCV6; 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 S1729686AbgLDKCs (ORCPT + 15 others); Fri, 4 Dec 2020 05:02:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729512AbgLDKCs (ORCPT ); Fri, 4 Dec 2020 05:02:48 -0500 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1661C061A52 for ; Fri, 4 Dec 2020 02:02:07 -0800 (PST) Received: by mail-ej1-x641.google.com with SMTP id ce23so4059767ejb.8 for ; Fri, 04 Dec 2020 02:02:07 -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=/YIHndOkuyRiMsQ82HY4dIjLYZOfc93bxXe51T4cmZ0=; b=SRePSCV6dz/lPsfZpnayLbYuACan0Ha9kwWTtbojMk2TVx94Q4AWxd+nN89U92fo2e KBOYsAucPT7TB7pAYI4G2DalZBdokr0qh1VpG9IVDSp6Luu1ivRc3jHMUQZMxhl+gzpi ELt9tBDEDw2e2Jw6/IlJATISL5JmxFf8Dnn9htD85ANTnLeDbBkb3T3z7TFoh/DVdCBP Z0LF0rH1/VW1Pi96MU9RAsdjonSsXOHB6/xZDBKrb9zHG42F31UC1D/v57cof3WE24Ks RE2F0YU4xTr3dF5CIkN4PNi6OTKMo1dvjd/I1xlWFtMqBEos1ENrZQjpfUlTiX4+1umu ReYw== 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=/YIHndOkuyRiMsQ82HY4dIjLYZOfc93bxXe51T4cmZ0=; b=n1q3L2lU9yX8aixzAOK765tJD4X0lvpgE3LHLIYVhMz2YHByHYQqiUmFQpDbJ7aEot bEF17iTWqYc44/Y47E+pVypkweMk7Dfzj5ZJl0PIeBMOYcHlQWGJ5ZJ8E9x4aTssZOsZ mUaM7uUIW7f9ry2PNMd4u21TaKuKyL8XUP2m2pu6IQvzEGRiF4VJuNeaypLq/9Yt/c5o Yvdh3adJ1piFi6l3EXRPFEeKgpjzMuxpn2rl+JnMS/AeXMbigTk9+r9rXgLVNeh6CK9q HHrwozbpnwAooy8lOied5iyiy8MTqTEdX3apHB02B4BUqBqO7zaLvffUWGYOFH4NfGRn qLpg== X-Gm-Message-State: AOAM5312KUsXPmiR/ksxXR6s27lJzgf4BseITUdf6IPnlVXj2V4bEa+i 0pe29H9bzS1Wty0qVcX4PLvemg== X-Received: by 2002:a17:906:e082:: with SMTP id gh2mr6080367ejb.406.1607076126537; Fri, 04 Dec 2020 02:02:06 -0800 (PST) Received: from localhost.localdomain (hst-221-106.medicom.bg. [84.238.221.106]) by smtp.gmail.com with ESMTPSA id p35sm3238242edd.58.2020.12.04.02.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:02:06 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dikshita@codeaurora.org, Alexandre Courbot , Vikash Garodia , Stanimir Varbanov Subject: [PATCH v2 1/4] venus: venc: Init the session only once in queue_setup Date: Fri, 4 Dec 2020 12:01:36 +0200 Message-Id: <20201204100139.6216-2-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201204100139.6216-1-stanimir.varbanov@linaro.org> References: <20201204100139.6216-1-stanimir.varbanov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Init the hfi session only once in queue_setup and also cover that with inst->lock. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/venc.c | 85 ++++++++++++++++++------ 1 file changed, 64 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 1c61602c5de1..e0053cc1b7eb 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -725,7 +725,9 @@ static int venc_init_session(struct venus_inst *inst) int ret; ret = hfi_session_init(inst, inst->fmt_cap->pixfmt); - if (ret) + if (ret == -EINVAL) + return 0; + else if (ret) return ret; ret = venus_helper_set_input_resolution(inst, inst->width, @@ -762,17 +764,13 @@ static int venc_out_num_buffers(struct venus_inst *inst, unsigned int *num) struct hfi_buffer_requirements bufreq; int ret; - ret = venc_init_session(inst); + ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); if (ret) return ret; - ret = venus_helper_get_bufreq(inst, HFI_BUFFER_INPUT, &bufreq); - *num = bufreq.count_actual; - hfi_session_deinit(inst); - - return ret; + return 0; } static int venc_queue_setup(struct vb2_queue *q, @@ -781,7 +779,7 @@ static int venc_queue_setup(struct vb2_queue *q, { struct venus_inst *inst = vb2_get_drv_priv(q); unsigned int num, min = 4; - int ret = 0; + int ret; if (*num_planes) { if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && @@ -803,6 +801,13 @@ static int venc_queue_setup(struct vb2_queue *q, return 0; } + mutex_lock(&inst->lock); + ret = venc_init_session(inst); + mutex_unlock(&inst->lock); + + if (ret) + return ret; + switch (q->type) { case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: *num_planes = inst->fmt_out->num_planes; @@ -838,6 +843,49 @@ static int venc_queue_setup(struct vb2_queue *q, return ret; } +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_release_session(struct venus_inst *inst) +{ + int ret; + + mutex_lock(&inst->lock); + + ret = hfi_session_deinit(inst); + if (ret || inst->session_error) + hfi_session_abort(inst); + + mutex_unlock(&inst->lock); + + venus_pm_load_scale(inst); + INIT_LIST_HEAD(&inst->registeredbufs); + venus_pm_release_core(inst); +} + +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; @@ -888,38 +936,32 @@ static int venc_start_streaming(struct vb2_queue *q, unsigned int count) inst->sequence_cap = 0; inst->sequence_out = 0; - ret = venc_init_session(inst); - if (ret) - goto bufs_done; - ret = venus_pm_acquire_core(inst); if (ret) - goto deinit_sess; + goto error; ret = venc_set_properties(inst); if (ret) - goto deinit_sess; + goto error; ret = venc_verify_conf(inst); if (ret) - goto deinit_sess; + goto error; ret = venus_helper_set_num_bufs(inst, inst->num_input_bufs, inst->num_output_bufs, 0); if (ret) - goto deinit_sess; + goto error; ret = venus_helper_vb2_start_streaming(inst); if (ret) - goto deinit_sess; + goto error; mutex_unlock(&inst->lock); return 0; -deinit_sess: - hfi_session_deinit(inst); -bufs_done: +error: venus_helper_buffers_done(inst, q->type, VB2_BUF_STATE_QUEUED); if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) inst->streamon_out = 0; @@ -931,7 +973,8 @@ static int venc_start_streaming(struct vb2_queue *q, unsigned int count) 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, From patchwork Fri Dec 4 10:01:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 337747 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp111722ilb; Fri, 4 Dec 2020 02:04:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4ioQ/b3D6kFAZr8j08Mqlp4vbZBzBW7jMoWdGJ1h+kIr51LLh73pclu7r30Y9g6rtTQVl X-Received: by 2002:a17:906:5847:: with SMTP id h7mr6160229ejs.124.1607076291315; Fri, 04 Dec 2020 02:04:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607076291; cv=none; d=google.com; s=arc-20160816; b=QgBsZYwVr0Y3ncGrNs9PxtMecFucVceR4Hv09GxQJaJvtOvthDco6FpGzHIoFuSL5q nZlXR0Ax/WfLa+ql2I6jrrhs+MVfj103/nrjh1WIiOxl53p9c0seK0EXD+MtpzxJq73s 9eY+XQW2kUrCxAb3gT4HUvWxXYqRG8iOHJHBaYWmRNENqDgCLMG28egdUe9BZ/vRdq/R wha681sLYCQvk+k/lQuprVk6/n6rz3dK6jNnyQDWPbqu3XYL0o4scDERujsKW7s3ZC7T ft5vqjJ+WoXwMKh6E5czk6qfp/UUe2sx2oBxHlHoYyTPK5F/xXmEjqeyKJffFTtcoDVx wHxw== 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=LyeOql6QYmpd/1nhWP8WR5ehn5BlBeFQlh24gAVBRhU=; b=FejIkfj8FTYLfIb3hXuViXCT5SCLQ+/zb09IPfQ5iXLFpBi9ljS0RqiwgVXwlGZ99e 9wmofvXgpu5ZAGVlVGvD1p2tiq9wH7U+Iuze1hWrjUQ2wSxwssqsNQ/Ve3cJ1Dfg/gzr 8yOutIOR155fEhIjXOfyIDaYGDBr/KHBlcaV5zzrObQCvyFtjjC2znIjb3g8pelIQL4J nUSVwq1G8EStZdImyE72gW8Zwf5R8Pi/w/p/im2BE82aRnoiTlMpM+3gdkXc5QUkTrMM T4pHmJRuEMPAY7hdtUrGdvPkla3YB46gSWTCUFSpNuyId6MHWGGy36y1CS+yPvm6nEWP N5eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qgzeAQEa; 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 nq7si1077203ejb.109.2020.12.04.02.04.51; Fri, 04 Dec 2020 02:04:51 -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=qgzeAQEa; 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 S2387867AbgLDKD3 (ORCPT + 15 others); Fri, 4 Dec 2020 05:03:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387832AbgLDKD2 (ORCPT ); Fri, 4 Dec 2020 05:03:28 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F35DC061A56 for ; Fri, 4 Dec 2020 02:02:09 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id v22so5200967edt.9 for ; Fri, 04 Dec 2020 02:02:09 -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=LyeOql6QYmpd/1nhWP8WR5ehn5BlBeFQlh24gAVBRhU=; b=qgzeAQEaUfEMnYTzNM6py9Wnux2p0x09OoGjBhg6NOU+FMrXss1qgfQ2Uo9T7VGEFY 16Bg01jAAwONWqA+zIP0xQdFQ+WuV9G5+CWhheMyc0v/q9uLo9HhQldX2zN2V6chcSSs NFQ4OVqUn8nKlV5wiYdOnU+C7sXxPsTFJXehDaoz0XvfMVi8MDhNjTnuqxKT6/GjUOpj 5BipSy7smzfy9UHC2OpEr3RC/830bP9YW0DDPkivv2ZAoPd+i7x4Jbt/HrXKB6oWCXdI dcTHH0KTii8Jlnw61wrgR7lo7b6KuMu49VfvcBxEtQfd7RTrsAhboI0uD0dojTGwgNjp fDjA== 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=LyeOql6QYmpd/1nhWP8WR5ehn5BlBeFQlh24gAVBRhU=; b=AOdjpNbJYQub6T5P2Wzd1LuJkMyVUjbOEE8/tHCPcLWyOKdF3DtP+RnhH6j5Oq6m7a vrqjTruDJ1e0BucnktbWf8wW5pb0AFSOz4dX5jy+OeCbLYWsdWnOBAgpsg8ubA4zB/9t ES1SacM6E46RmObe8bgFZBIVUJmgV3qR0Px2yVGvJ0vEzJg+5YlywJD85qpDaoX2Q1NN wlvZa4kpaY8uDIWtCiMlsPKZZrGnZiTWIC13zf7bjQxIZX74KrxtvA5AvhaMOV7+6+r3 dbl2/JU6j2x+R4cxig/l2SVVjuu41ScZ6wTmnFyDadm9YmArrfOIceMMCuo4T7HPfbjt UCKg== X-Gm-Message-State: AOAM532xxPc6GDaJdNHRyCQYhYW0YGakk3abM4p+e1HOUTpwr9wWokOk GHiQqxUNVGma+J4+pi3gifhkng== X-Received: by 2002:a50:b941:: with SMTP id m59mr6871336ede.371.1607076128347; Fri, 04 Dec 2020 02:02:08 -0800 (PST) Received: from localhost.localdomain (hst-221-106.medicom.bg. [84.238.221.106]) by smtp.gmail.com with ESMTPSA id p35sm3238242edd.58.2020.12.04.02.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:02:07 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dikshita@codeaurora.org, Alexandre Courbot , Vikash Garodia , Stanimir Varbanov Subject: [PATCH v2 2/4] venus: Limit HFI sessions to the maximum supported Date: Fri, 4 Dec 2020 12:01:37 +0200 Message-Id: <20201204100139.6216-3-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201204100139.6216-1-stanimir.varbanov@linaro.org> References: <20201204100139.6216-1-stanimir.varbanov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Currently we rely on firmware to return error when we reach the maximum supported number of sessions. But this errors are happened at reqbuf time which is a bit later. The more reasonable way looks like is to return the error on driver open. To achieve that modify hfi_session_create to return error when we reach maximum count of sessions and thus refuse open. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/core.h | 1 + drivers/media/platform/qcom/venus/hfi.c | 16 +++++++++++++--- drivers/media/platform/qcom/venus/hfi_parser.c | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index f03ed427accd..775d7bf6587d 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -96,6 +96,7 @@ struct venus_format { #define MAX_CAP_ENTRIES 32 #define MAX_ALLOC_MODE_ENTRIES 16 #define MAX_CODEC_NUM 32 +#define MAX_SESSIONS 16 struct raw_formats { u32 buftype; diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c index 638ed5cfe05e..8786609d269e 100644 --- a/drivers/media/platform/qcom/venus/hfi.c +++ b/drivers/media/platform/qcom/venus/hfi.c @@ -175,6 +175,8 @@ static int wait_session_msg(struct venus_inst *inst) int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops) { struct venus_core *core = inst->core; + bool max; + int ret; if (!ops) return -EINVAL; @@ -184,11 +186,19 @@ int hfi_session_create(struct venus_inst *inst, const struct hfi_inst_ops *ops) inst->ops = ops; mutex_lock(&core->lock); - list_add_tail(&inst->list, &core->instances); - atomic_inc(&core->insts_count); + + max = atomic_add_unless(&core->insts_count, 1, + core->max_sessions_supported); + if (!max) { + ret = -EAGAIN; + } else { + list_add_tail(&inst->list, &core->instances); + ret = 0; + } + mutex_unlock(&core->lock); - return 0; + return ret; } EXPORT_SYMBOL_GPL(hfi_session_create); diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/venus/hfi_parser.c index 363ee2a65453..52898633a8e6 100644 --- a/drivers/media/platform/qcom/venus/hfi_parser.c +++ b/drivers/media/platform/qcom/venus/hfi_parser.c @@ -276,6 +276,9 @@ u32 hfi_parser(struct venus_core *core, struct venus_inst *inst, void *buf, words_count--; } + if (!core->max_sessions_supported) + core->max_sessions_supported = MAX_SESSIONS; + parser_fini(inst, codecs, domain); return HFI_ERR_NONE; From patchwork Fri Dec 4 10:01:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 337804 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08BD9C193FE for ; Fri, 4 Dec 2020 10:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA1DB22525 for ; Fri, 4 Dec 2020 10:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387902AbgLDKDj (ORCPT ); Fri, 4 Dec 2020 05:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387897AbgLDKDd (ORCPT ); Fri, 4 Dec 2020 05:03:33 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC915C08E862 for ; Fri, 4 Dec 2020 02:02:13 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id ce23so4060194ejb.8 for ; Fri, 04 Dec 2020 02:02:13 -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=fik6fEowz12+2Ryuqjd810QUwD4ENaiIRDI49CE7Imo=; b=s0IPi2BAvrZXVg6MFhcozWTscLQzWG5DFcmiVlxDGmRFk0HHGu3rKsyxBoR2ctJDmS ybNq+4AZfWqrIOWlOwMMn9ypj6s/3xIywX/t+a5UUsOdWxhzpUNYUhXAEX4nOrMahzgl E2HbZZoHFdF9h0xQq7Ot8KVfRHaHcNhyfGw5gHPcN4Img0/YCjUtf2LlRFhe+ypQTA15 B/498boF+b3BY6jxxh1TnBalh1CtYptZLZF36jb5L6n7/fNUlHZolwjUIMDfEqW+QuC1 XZ7+YsaRBQJbZvr5SdtIoyuQXN+LxAxCAykzXM6hSWoNG7VV1IVkuB8tPfN783mK4Qyw zwEQ== 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=fik6fEowz12+2Ryuqjd810QUwD4ENaiIRDI49CE7Imo=; b=Uco+gs+fgi3KV/S8FKWMK5KBfasPvkonTqyGxn8B16sNgKsTgVeg2qwMpHw7l3zHMc a3m5QuHVfod31JHwlrJwXT5nZ3qV6p8txSaabmGLIdeGXfQrtfIZFvFeSiQyZy13oYus fq93dB608inynZlZxWXeVMnSG66QclYv+bK7mZrBW9OF9XrF/UHDOP2lWUJMXmvwzRu/ 8TcsMefa39ulPBlWeHTcBS3vRgbE35CHCSzNEoI2ZipHfqcNCXpI0IjoLE2ektjgNWi4 m4XmelxxxHFpXhh6PD7BdC7dhAW8frbKKXbq/Tn7d2bmhfndRfwFSOmKoy1FmNzXRzhf 5yAg== X-Gm-Message-State: AOAM531313be6oHgn26BuOp/+7azPo4PnlfhzT1WBeysjNiHEp4PEfqI n/F3IzO1pvx5cm7ELEWzj9cUJw== X-Google-Smtp-Source: ABdhPJx6JYmI+hOefPFTpkOizK3567s+04FShF8enu15CF/OdVhVGAL1qWVPO77wZleP+ulEo6irpw== X-Received: by 2002:a17:906:7aca:: with SMTP id k10mr6229230ejo.215.1607076132455; Fri, 04 Dec 2020 02:02:12 -0800 (PST) Received: from localhost.localdomain (hst-221-106.medicom.bg. [84.238.221.106]) by smtp.gmail.com with ESMTPSA id p35sm3238242edd.58.2020.12.04.02.02.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 02:02:11 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dikshita@codeaurora.org, Alexandre Courbot , Vikash Garodia , Stanimir Varbanov Subject: [PATCH v2 4/4] venus: hfi: Correct session init return error Date: Fri, 4 Dec 2020 12:01:39 +0200 Message-Id: <20201204100139.6216-5-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201204100139.6216-1-stanimir.varbanov@linaro.org> References: <20201204100139.6216-1-stanimir.varbanov@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The hfi_session_init can be called many times and it returns EINVAL when the session was already initialized. This error code (EINVAL) is confusing for the callers. Change hfi_session_init to return EALREADY error code when the session has been already initialized. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/hfi.c | 2 +- drivers/media/platform/qcom/venus/vdec.c | 2 +- drivers/media/platform/qcom/venus/venc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/venus/hfi.c index 8786609d269e..0f2482367e06 100644 --- a/drivers/media/platform/qcom/venus/hfi.c +++ b/drivers/media/platform/qcom/venus/hfi.c @@ -221,7 +221,7 @@ int hfi_session_init(struct venus_inst *inst, u32 pixfmt) mutex_unlock(&core->lock); if (inst->state != INST_UNINIT) - return -EINVAL; + return -EALREADY; inst->hfi_codec = to_codec_type(pixfmt); reinit_completion(&inst->done); diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 8488411204c3..5337387eef27 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -741,7 +741,7 @@ static int vdec_session_init(struct venus_inst *inst) int ret; ret = hfi_session_init(inst, inst->fmt_out->pixfmt); - if (ret == -EINVAL) + if (ret == -EALREADY) return 0; else if (ret) return ret; diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index e0053cc1b7eb..cb8ff10e38c7 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -725,7 +725,7 @@ static int venc_init_session(struct venus_inst *inst) int ret; ret = hfi_session_init(inst, inst->fmt_cap->pixfmt); - if (ret == -EINVAL) + if (ret == -EALREADY) return 0; else if (ret) return ret;