Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2123402ybh; Fri, 24 Jul 2020 05:07:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsBKBDPPucY4EIt7VVjW7cjC65R7RZAjL04lBC3F0mD7rdgJXGDkLSF89W0oQN6PvpQ3mS X-Received: by 2002:a17:906:3816:: with SMTP id v22mr9284580ejc.332.1595592449074; Fri, 24 Jul 2020 05:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595592449; cv=none; d=google.com; s=arc-20160816; b=gfoJsB7rKhhbn8Ym3o54It8uAexmHeh/adLLkBcTAOpR+q030XbzkFgT/IcsV7OBmu OyJWlN2RG+F4TUslsCX+0xULBH1RqJCdjb+OJrh2uu20mAtgTQvs0HPtmrMD/gD2Poxv zpCpq9ahcghNgZyz9JDPYXBKnGg+1rP3jAKD1fpD9c8n0PkARqCpZjolESSAYAeLX8uR RSsEyOKQKtIeLu8AZ/BllS93xr5dKOSdPxPflvVrC9N+iK9sSkVjtwCg5Cl8uthoMNGz TQpGaQYmyppeCfMA5vefTrQ81nRkEIlRGd0coYkqOFhCVAH1TgV7q2apq3r4b9kycac6 ghYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cvnh2hEgqr+H3PqRAzGMgrE9Ro4XZW4OvEzfzGD53mo=; b=iVeexZ3W6dCl7eBS2hLF0BvthDQvjS9ggqM+ZPSu4zTh/HKKc6lqmfVmmzfhZBAOw3 ogfytoGWv+rFMED+VtPZLZnBFt0ORg1Tsqv/Fl058dyE8r06qwvpObkWB0CnWC6yK3yT 1E3I8W+jhYl8ErmMieNuup4NTp1ZjofafcklGUo9EH0SNXGvFGrdHy8V1iIHL3BcMzuQ oU80Qwkldh+2BcaDxwTslwOXDn49XM3fOZ6q9k/4s9ZixXwfUyMfScgOnS8BFqdguXoO DuTkkHCUO1JZ5zW4+qxYQthXpLu9i+Jp6NJoN1Cg431ZPRuTzhkuuaTBEuquTvPg+czs Poew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.s=20150623 header.b=VeE6kkrh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=iitr.ac.in Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s25si367147edw.533.2020.07.24.05.07.06; Fri, 24 Jul 2020 05:07:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@es-iitr-ac-in.20150623.gappssmtp.com header.s=20150623 header.b=VeE6kkrh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=iitr.ac.in Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726975AbgGXMCi (ORCPT + 99 others); Fri, 24 Jul 2020 08:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbgGXMCc (ORCPT ); Fri, 24 Jul 2020 08:02:32 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1FBC0619E4 for ; Fri, 24 Jul 2020 05:02:32 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id q17so4315751pls.9 for ; Fri, 24 Jul 2020 05:02:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cvnh2hEgqr+H3PqRAzGMgrE9Ro4XZW4OvEzfzGD53mo=; b=VeE6kkrhkfhNP5LUcTBQH11gWeFF2+m6gYWJQs7hF4vvMOESDioBiAvItJzO2SMFbK 8FCqkBz8VjNAQkhBINnbqgV765p/yY2MKpyR4pbsPScOW6XqETJq3/hC8OqcV1u/nyIE hMUwPK0tvMmRutyClsFgP7hCPQTUJsihOINYnmTVNYLXqJ8rkWEPfnMB81qnj645CWZs dN700jzBqr3D81QOg2wZtaTObxl7GCECZHV90gHavWW8j3JFlJ1C9JeyqdtW6qXJZtSo qIzIT2xN8tCc1kIhTppQog0LsNo2J49gakquKZFtFBoH/c3FduITekszQUZJPtJ2NeuW GzPw== 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:mime-version:content-transfer-encoding; bh=Cvnh2hEgqr+H3PqRAzGMgrE9Ro4XZW4OvEzfzGD53mo=; b=R+d6tEvtS25ERMXrlymkZDEFb3wCxgAPV3wFLTsxglFvvih17xBGV0wWVz3jMuHzOM 3YmFhN4O5UxzByKUD46D6BBJDw3qjgfFJk8dEM47w4EcICFSUYguml/GPKoSxozAPvre JZduseQ3BorkL8YtRectJfJdO/q38q5GkbZbZXJ/Ic9mHqkcuqEPDCd2e8JqfMFBcDGL md9NZH6FfGRM4coMzQVWuM1FIQoHNXYiALfuIekg09LiMx6B/jQid1TSX9BGeslgt+yL ZWY+sjshlp7Qe3aVhA+R90tPP7hv3qB/9KX2XXQ2ejP3o2rEnUxhPSf5XU7L8CfVDB23 kD3g== X-Gm-Message-State: AOAM533bVwy5kaybBOZ5cznexglD+BeuN/uduMD7elKSaVGO0HYWiWV5 CDyald24I6lNe1fPSmjItLmBZA== X-Received: by 2002:a17:90b:4b84:: with SMTP id lr4mr4891056pjb.111.1595592151966; Fri, 24 Jul 2020 05:02:31 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.178]) by smtp.gmail.com with ESMTPSA id h15sm6293300pfo.192.2020.07.24.05.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 05:02:31 -0700 (PDT) From: Kaaira Gupta To: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Kieran Bingham , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Cc: Kaaira Gupta Subject: [PATCH v2 1/3] media: vimc: Add usage count to subdevices Date: Fri, 24 Jul 2020 17:32:11 +0530 Message-Id: <20200724120213.17119-2-kgupta@es.iitr.ac.in> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200724120213.17119-1-kgupta@es.iitr.ac.in> References: <20200724120213.17119-1-kgupta@es.iitr.ac.in> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prepare for multiple video streams from the same sensor by adding a use counter to each subdevice. The counter is increased for every s_stream(1) and decremented for every s_stream(0) call. The subdevice stream is not started or stopped unless the usage count go from 0 to 1 (started) or from 1 to 0 (stopped). This allows for multiple s_stream() calls to try to either start or stop the device while only the first/last call will actually effect the state of the device. [Kaaira: rebased the patch on current HEAD of media-tree (8f2a4a9d5ff5202d0b3e3a144ebb9b67aabadd29)] Signed-off-by: Niklas Söderlund Signed-off-by: Kaaira Gupta --- drivers/media/test-drivers/vimc/vimc-debayer.c | 8 ++++++++ drivers/media/test-drivers/vimc/vimc-scaler.c | 8 ++++++++ drivers/media/test-drivers/vimc/vimc-sensor.c | 9 ++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/media/test-drivers/vimc/vimc-debayer.c b/drivers/media/test-drivers/vimc/vimc-debayer.c index c3f6fef34f68..93fe19d8d2b4 100644 --- a/drivers/media/test-drivers/vimc/vimc-debayer.c +++ b/drivers/media/test-drivers/vimc/vimc-debayer.c @@ -29,6 +29,7 @@ struct vimc_deb_pix_map { struct vimc_deb_device { struct vimc_ent_device ved; struct v4l2_subdev sd; + atomic_t use_count; /* The active format */ struct v4l2_mbus_framefmt sink_fmt; u32 src_code; @@ -343,6 +344,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable) const struct vimc_pix_map *vpix; unsigned int frame_size; + if (atomic_inc_return(&vdeb->use_count) != 1) + return 0; + if (vdeb->src_frame) return 0; @@ -368,6 +372,9 @@ static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable) return -ENOMEM; } else { + if (atomic_dec_return(&vdeb->use_count) != 0) + return 0; + if (!vdeb->src_frame) return 0; @@ -595,6 +602,7 @@ static struct vimc_ent_device *vimc_deb_add(struct vimc_device *vimc, vdeb->ved.process_frame = vimc_deb_process_frame; vdeb->ved.dev = vimc->mdev.dev; vdeb->mean_win_size = vimc_deb_ctrl_mean_win_size.def; + atomic_set(&vdeb->use_count, 0); /* Initialize the frame format */ vdeb->sink_fmt = sink_fmt_default; diff --git a/drivers/media/test-drivers/vimc/vimc-scaler.c b/drivers/media/test-drivers/vimc/vimc-scaler.c index 121fa7d62a2e..9b8458dbe57c 100644 --- a/drivers/media/test-drivers/vimc/vimc-scaler.c +++ b/drivers/media/test-drivers/vimc/vimc-scaler.c @@ -25,6 +25,7 @@ MODULE_PARM_DESC(sca_mult, " the image size multiplier"); struct vimc_sca_device { struct vimc_ent_device ved; struct v4l2_subdev sd; + atomic_t use_count; /* NOTE: the source fmt is the same as the sink * with the width and hight multiplied by mult */ @@ -340,6 +341,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable) const struct vimc_pix_map *vpix; unsigned int frame_size; + if (atomic_inc_return(&vsca->use_count) != 1) + return 0; + if (vsca->src_frame) return 0; @@ -363,6 +367,9 @@ static int vimc_sca_s_stream(struct v4l2_subdev *sd, int enable) return -ENOMEM; } else { + if (atomic_dec_return(&vsca->use_count) != 0) + return 0; + if (!vsca->src_frame) return 0; @@ -506,6 +513,7 @@ static struct vimc_ent_device *vimc_sca_add(struct vimc_device *vimc, vsca->ved.process_frame = vimc_sca_process_frame; vsca->ved.dev = vimc->mdev.dev; + atomic_set(&vsca->use_count, 0); /* Initialize the frame format */ vsca->sink_fmt = sink_fmt_default; diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/test-drivers/vimc/vimc-sensor.c index ba5db5a150b4..dbe169604e71 100644 --- a/drivers/media/test-drivers/vimc/vimc-sensor.c +++ b/drivers/media/test-drivers/vimc/vimc-sensor.c @@ -24,6 +24,7 @@ struct vimc_sen_device { struct vimc_ent_device ved; struct v4l2_subdev sd; struct tpg_data tpg; + atomic_t use_count; u8 *frame; enum vimc_sen_osd_mode osd_value; u64 start_stream_ts; @@ -250,8 +251,10 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable) const struct vimc_pix_map *vpix; unsigned int frame_size; - vsen->start_stream_ts = ktime_get_ns(); + if (atomic_inc_return(&vsen->use_count) != 1) + return 0; + vsen->start_stream_ts = ktime_get_ns(); /* Calculate the frame size */ vpix = vimc_pix_map_by_code(vsen->mbus_format.code); frame_size = vsen->mbus_format.width * vpix->bpp * @@ -270,6 +273,9 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable) } else { + if (atomic_dec_return(&vsen->use_count) != 0) + return 0; + vfree(vsen->frame); vsen->frame = NULL; } @@ -430,6 +436,7 @@ static struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc, vsen->ved.process_frame = vimc_sen_process_frame; vsen->ved.dev = vimc->mdev.dev; + atomic_set(&vsen->use_count, 0); /* Initialize the frame format */ vsen->mbus_format = fmt_default; -- 2.17.1