From: Alexandre Courbot <acourbot@chromium.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@xs4all.nl>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Pawel Osciak <posciak@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Tomasz Figa <tfiga@chromium.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Gustavo Padovan <gustavo.padovan@collabora.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexandre Courbot <acourbot@chromium.org>
Subject: [RFC PATCH 2/9] media: request: add generic queue
Date: Fri, 15 Dec 2017 16:56:18 +0900 [thread overview]
Message-ID: <20171215075625.27028-3-acourbot@chromium.org> (raw)
In-Reply-To: <20171215075625.27028-1-acourbot@chromium.org>
Add a generic request queue that supports most use-case and should be
usable as-is by drivers without special hardware features.
The generic queue stores the requests into a FIFO list and executes them
sequentially.
Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
---
drivers/media/Makefile | 2 +-
drivers/media/media-request-queue-generic.c | 150 ++++++++++++++++++++++++++++
include/media/media-request.h | 8 ++
3 files changed, 159 insertions(+), 1 deletion(-)
create mode 100644 drivers/media/media-request-queue-generic.c
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index 985d35ec6b29..90117fff1339 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -4,7 +4,7 @@
#
media-objs := media-device.o media-devnode.o media-entity.o \
- media-request.o
+ media-request.o media-request-queue-generic.o
#
# I2C drivers should come before other drivers, otherwise they'll fail
diff --git a/drivers/media/media-request-queue-generic.c b/drivers/media/media-request-queue-generic.c
new file mode 100644
index 000000000000..780414b6d46a
--- /dev/null
+++ b/drivers/media/media-request-queue-generic.c
@@ -0,0 +1,150 @@
+/*
+ * Generic request queue implementation.
+ *
+ * Copyright (C) 2017, The Chromium OS Authors. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/slab.h>
+
+#include <media/media-request.h>
+#include <media/media-entity.h>
+
+/**
+ * struct media_request_generic - request enabled for the generic queue
+ *
+ * @base: base request member
+ * @queue: entry in media_request_queue_generic::queued_requests
+ */
+struct media_request_generic {
+ struct media_request base;
+ struct list_head queue;
+};
+#define to_generic_request(r) \
+ container_of(r, struct media_request_generic, base)
+
+/**
+ * struct media_request_queue_generic - generic request queue implementation
+ *
+ * Implements a simple request queue, where the next queued request is executed
+ * as soon as the previous one completes.
+ *
+ * @base: base request queue member
+ * @mutex: protects the queue
+ * @queued_requests: list of requests to be sequentially executed
+ */
+struct media_request_queue_generic {
+ struct media_request_queue base;
+
+ struct list_head queued_requests;
+};
+#define to_generic_queue(q) \
+ container_of(q, struct media_request_queue_generic, base)
+
+static struct media_request *
+media_request_generic_alloc(struct media_request_queue *queue)
+{
+ struct media_request_generic *req;
+
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return ERR_PTR(-ENOMEM);
+
+ return &req->base;
+}
+
+static void media_request_generic_free(struct media_request_queue *queue,
+ struct media_request *_req)
+{
+ struct media_request_generic *req = to_generic_request(_req);
+
+ kfree(req);
+}
+
+static void schedule_next_req(struct media_request_queue_generic *queue)
+{
+ struct media_request_generic *req;
+ struct media_request_entity_data *data;
+
+ req = list_first_entry_or_null(&queue->queued_requests, typeof(*req),
+ queue);
+ if (!req)
+ return;
+
+ list_del(&req->queue);
+ queue->base.active_request = &req->base;
+
+ list_for_each_entry(data, &req->base.data, list) {
+ int ret;
+
+ ret = data->entity->req_ops->apply_data(data);
+ }
+
+ list_for_each_entry(data, &req->base.data, list) {
+ data->entity->ops->process_request(&req->base, data);
+ }
+}
+
+static void media_request_generic_complete(struct media_request_queue *_queue)
+{
+ struct media_request_queue_generic *queue = to_generic_queue(_queue);
+
+ queue->base.active_request = NULL;
+ schedule_next_req(queue);
+}
+
+static int media_request_generic_queue(struct media_request_queue *_queue,
+ struct media_request *_req)
+{
+ struct media_request_queue_generic *queue = to_generic_queue(_queue);
+ struct media_request_generic *req = to_generic_request(_req);
+
+ list_add_tail(&req->queue, &queue->queued_requests);
+
+ if (!queue->base.active_request)
+ schedule_next_req(queue);
+
+ return 0;
+}
+
+static void
+media_request_generic_queue_release(struct media_request_queue *_queue)
+{
+ struct media_request_queue_generic *queue = to_generic_queue(_queue);
+
+ media_request_queue_release(&queue->base);
+ kfree(queue);
+}
+
+static const struct media_request_queue_ops request_queue_generic_ops = {
+ .release = media_request_generic_queue_release,
+ .req_alloc = media_request_generic_alloc,
+ .req_free = media_request_generic_free,
+ .req_queue = media_request_generic_queue,
+ .req_complete = media_request_generic_complete,
+};
+
+struct media_request_queue *
+media_request_queue_generic_alloc(struct media_device *mdev)
+{
+ struct media_request_queue_generic *ret;
+
+ ret = kzalloc(sizeof(*ret), GFP_KERNEL);
+ if (!ret)
+ return ERR_PTR(-ENOMEM);
+
+ media_request_queue_init(&ret->base, mdev, &request_queue_generic_ops);
+
+ INIT_LIST_HEAD(&ret->queued_requests);
+
+ return &ret->base;
+}
+EXPORT_SYMBOL(media_request_queue_generic_alloc);
diff --git a/include/media/media-request.h b/include/media/media-request.h
index ead7fd8898c4..583a1116f735 100644
--- a/include/media/media-request.h
+++ b/include/media/media-request.h
@@ -196,6 +196,14 @@ void media_request_queue_init(struct media_request_queue *queue,
*/
void media_request_queue_release(struct media_request_queue *queue);
+/**
+ * media_request_queue_generic_alloc() - return an instance of the generic queue
+ *
+ * @mdev: media device managing this queue
+ */
+struct media_request_queue *
+media_request_queue_generic_alloc(struct media_device *mdev);
+
/**
* struct media_request_entity_data - per-entity request data
*
--
2.15.1.504.g5279b80103-goog
next prev parent reply other threads:[~2017-12-15 7:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-15 7:56 [RFC PATCH 0/9] media: base request API support Alexandre Courbot
2017-12-15 7:56 ` [RFC PATCH 1/9] media: add request API core and UAPI Alexandre Courbot
2017-12-15 10:37 ` Philippe Ombredanne
2018-01-12 10:16 ` Hans Verkuil
2018-01-26 8:39 ` Sakari Ailus
2018-01-30 4:23 ` Alexandre Courbot
2018-02-02 7:33 ` Sakari Ailus
2018-02-02 7:41 ` Tomasz Figa
2018-02-02 8:00 ` Hans Verkuil
2017-12-15 7:56 ` Alexandre Courbot [this message]
2017-12-15 7:56 ` [RFC PATCH 3/9] media: request: add generic entity ops Alexandre Courbot
2017-12-15 7:56 ` [RFC PATCH 4/9] videodev2.h: Add request field to v4l2_buffer Alexandre Courbot
2018-01-12 10:22 ` Hans Verkuil
2018-01-15 8:24 ` Alexandre Courbot
2017-12-15 7:56 ` [RFC PATCH 5/9] media: vb2: add support for requests Alexandre Courbot
2018-01-12 10:49 ` Hans Verkuil
2018-01-15 8:24 ` Alexandre Courbot
2018-01-15 9:07 ` Hans Verkuil
2018-01-16 9:39 ` Alexandre Courbot
2018-01-16 10:37 ` Hans Verkuil
2018-01-17 8:01 ` Alexandre Courbot
2018-01-17 8:37 ` Hans Verkuil
2017-12-15 7:56 ` [RFC PATCH 6/9] media: vb2: add support for requests in QBUF ioctl Alexandre Courbot
2018-01-12 11:37 ` Hans Verkuil
2018-01-15 8:24 ` Alexandre Courbot
2018-01-15 9:19 ` Hans Verkuil
2018-01-16 9:40 ` Alexandre Courbot
2017-12-15 7:56 ` [RFC PATCH 7/9] media: v4l2-mem2mem: add request support Alexandre Courbot
2017-12-15 7:56 ` [RFC PATCH 8/9] media: vim2m: add media device Alexandre Courbot
2017-12-15 7:56 ` [RFC PATCH 9/9] media: vim2m: add request support Alexandre Courbot
2017-12-18 20:53 ` Gustavo Padovan
2017-12-20 9:29 ` Alexandre Courbot
2017-12-15 21:02 ` [RFC PATCH 0/9] media: base request API support Nicolas Dufresne
2017-12-20 9:24 ` Alexandre Courbot
2017-12-15 21:04 ` Nicolas Dufresne
2017-12-20 9:27 ` Alexandre Courbot
2018-01-12 11:45 ` Hans Verkuil
2018-01-15 8:24 ` Alexandre Courbot
2018-01-15 8:43 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171215075625.27028-3-acourbot@chromium.org \
--to=acourbot@chromium.org \
--cc=gustavo.padovan@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=posciak@chromium.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tfiga@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®