From patchwork Fri Oct 20 21:49:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo F. Padovan" X-Patchwork-Id: 45075 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e5fFu-0001yJ-Gv; Fri, 20 Oct 2017 21:55:02 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753143AbdJTVuk (ORCPT + 1 other); Fri, 20 Oct 2017 17:50:40 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:53318 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753015AbdJTVug (ORCPT ); Fri, 20 Oct 2017 17:50:36 -0400 Received: by mail-qk0-f196.google.com with SMTP id y23so15996910qkb.10; Fri, 20 Oct 2017 14:50:36 -0700 (PDT) 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=ACDaplKworSN2vopGqaPJyMlvmEvl1EUUXmRfcowKVQ=; b=B7nn1eemi3tuU2lbZr9v+JiRx+joOrIWLI2buwKZi0SU20F8GVK1cGswltOOeagzJB FWOkXdgI8iHKOaxUFdiKsi0nD/3thCRa1S1wJr9R12onZUFZrrZ7NpBs56wRFPzwwW+m Ry9VSpudth+pzAj6Xoq1JtpvKI65/6gaTcKDFFicMNdpFOg2vThvIExG01/LsV7o6zwn FAiH6PaDqNTptns7JchPcgzZBiDo0UtZGfh5e2+33R11LAUBegUI36t9tPakBpqIEoa3 d+EKGcV9bv4cW2/H5LrMKPBVh54klffbUED1wjDzgNH5rtJVpzLRqQdbz7hyWlG0D4HT Dldw== X-Gm-Message-State: AMCzsaWBNy0sO/hn2rC7o+zlVqDj2NVC72wcd5piqHbJ/z30TbnUXtfG 3PPN3KxEUp83RDp360TzPEfmQU/7 X-Google-Smtp-Source: ABhQp+RLG6iKYiDCmVmzK7MDjJtyLn5SAoP2dVMWype0kbFZ6R8reake5UyUOf4M2TDfjedp1F/HLQ== X-Received: by 10.55.89.198 with SMTP id n189mr9008242qkb.349.1508536235661; Fri, 20 Oct 2017 14:50:35 -0700 (PDT) Received: from localhost.localdomain (189-19-125-192.dsl.telesp.net.br. [189.19.125.192]) by smtp.gmail.com with ESMTPSA id j4sm1167039qkf.75.2017.10.20.14.50.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Oct 2017 14:50:35 -0700 (PDT) From: Gustavo Padovan To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: [RFC v4 04/17] WIP: [media] v4l2: add v4l2_event_queue_fh_with_cb() Date: Fri, 20 Oct 2017 19:49:59 -0200 Message-Id: <20171020215012.20646-5-gustavo@padovan.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020215012.20646-1-gustavo@padovan.org> References: <20171020215012.20646-1-gustavo@padovan.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Gustavo Padovan For some type of events we may require the event user in the kernel to run some operation when DQ_EVENT() is called. V4L2_EVENT_OUT_FENCE is the first user of this mechanism as it needs to call v4l2 core back to install a file descriptor. This is WIP, I believe we are able to come up with better ways to do it, but as that is not the main part of the patchset I'll keep it like this for now. Signed-off-by: Gustavo Padovan --- drivers/media/v4l2-core/v4l2-event.c | 31 +++++++++++++++++++++++++++---- include/media/v4l2-event.h | 7 +++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c index 313ee9d1f9ee..6274e3e174e0 100644 --- a/drivers/media/v4l2-core/v4l2-event.c +++ b/drivers/media/v4l2-core/v4l2-event.c @@ -58,6 +58,9 @@ static int __v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event) spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); + if (kev->prepare) + kev->prepare(kev->data); + return 0; } @@ -104,8 +107,11 @@ static struct v4l2_subscribed_event *v4l2_event_subscribed( return NULL; } -static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev, - const struct timespec *ts) +static void __v4l2_event_queue_fh_with_cb(struct v4l2_fh *fh, + const struct v4l2_event *ev, + const struct timespec *ts, + void (*prepare)(void *data), + void *data) { struct v4l2_subscribed_event *sev; struct v4l2_kevent *kev; @@ -155,6 +161,8 @@ static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *e kev->event.id = ev->id; kev->event.timestamp = *ts; kev->event.sequence = fh->sequence; + kev->prepare = prepare; + kev->data = data; sev->in_use++; list_add_tail(&kev->list, &fh->available); @@ -177,7 +185,7 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev) spin_lock_irqsave(&vdev->fh_lock, flags); list_for_each_entry(fh, &vdev->fh_list, list) - __v4l2_event_queue_fh(fh, ev, ×tamp); + __v4l2_event_queue_fh_with_cb(fh, ev, ×tamp, NULL, NULL); spin_unlock_irqrestore(&vdev->fh_lock, flags); } @@ -191,11 +199,26 @@ void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev) ktime_get_ts(×tamp); spin_lock_irqsave(&fh->vdev->fh_lock, flags); - __v4l2_event_queue_fh(fh, ev, ×tamp); + __v4l2_event_queue_fh_with_cb(fh, ev, ×tamp, NULL, NULL); spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); } EXPORT_SYMBOL_GPL(v4l2_event_queue_fh); +void v4l2_event_queue_fh_with_cb(struct v4l2_fh *fh, + const struct v4l2_event *ev, + void (*prepare)(void *data), void *data) +{ + unsigned long flags; + struct timespec timestamp; + + ktime_get_ts(×tamp); + + spin_lock_irqsave(&fh->vdev->fh_lock, flags); + __v4l2_event_queue_fh_with_cb(fh, ev, ×tamp, prepare, data); + spin_unlock_irqrestore(&fh->vdev->fh_lock, flags); +} +EXPORT_SYMBOL_GPL(v4l2_event_queue_fh_with_cb); + int v4l2_event_pending(struct v4l2_fh *fh) { return fh->navailable; diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h index 2b794f2ad824..dc770257811e 100644 --- a/include/media/v4l2-event.h +++ b/include/media/v4l2-event.h @@ -68,11 +68,14 @@ struct video_device; * @list: List node for the v4l2_fh->available list. * @sev: Pointer to parent v4l2_subscribed_event. * @event: The event itself. + * @prepare: Callback to prepare the event only at DQ_EVENT() time. */ struct v4l2_kevent { struct list_head list; struct v4l2_subscribed_event *sev; struct v4l2_event event; + void (*prepare)(void *data); + void *data; }; /** @@ -160,6 +163,10 @@ void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev); */ void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev); +void v4l2_event_queue_fh_with_cb(struct v4l2_fh *fh, + const struct v4l2_event *ev, + void (*prepare)(void *data), void *data); + /** * v4l2_event_pending - Check if an event is available *