Received: by 10.223.176.46 with SMTP id f43csp283038wra; Thu, 25 Jan 2018 22:03:35 -0800 (PST) X-Google-Smtp-Source: AH8x224i90fgxY8WxY4krB4lH+HYFgDWC3nXZjiEL7QhpYWr5InSefTdxedRDAMnwRwnuV2RmFcH X-Received: by 10.98.205.72 with SMTP id o69mr15848531pfg.104.1516946615467; Thu, 25 Jan 2018 22:03:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516946615; cv=none; d=google.com; s=arc-20160816; b=ZjCH1tynrYl7R/JSB4B+I/JNhTS5S1aE+KghV61gSH272zXGc55AloS2m00ctBSTNw RK0FaS7QZkjDd6AR9VVPUG4HCodhhGLz9nb6o6qGsLIVk69PtOwRaWAedNemhJL//ha9 T6fLyxb40nR5GI/99C6ECQebME8UWlwDigxdtCUfmkJIlkyqN6Ck3duqjcuYjdAzlO4Z OhxWsFTF+jFSydgKIOWJrhcO6sbmuUplC4uYQmTYsgRBirMLg26JAmkESgYn7WMoDT3i MO1A0LD8k39oExn8/y1g7QpecJAg1kdEZS4r1uSkipHvgrCPVSBBS9qxxu2EhQfoQX2o blcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=vIjgyLZ9+ivnV0icUHFTF+IyaNp0JTucoEY5pYSU85Q=; b=PMenFa5pquvwjdOlspk5FrrfWLNXqprdbP2zX+ATK6xDDVlz+8zrY+xBLyyp8T3pIh rVQIcoYsxUqWj2yDUr7djz4FgpgUtLS9LJk5ES4VyQOVK2mphJv4/ryF6nwgeC/Pa9o5 6p4LBhg7hdcj5/pYgdvsJUZRZ06ddvkz3g/3meiLw7+6G/8vEQDh/9dNqJWJQbW1oJqq 7jWKpY3eG6SxGuqSleIvEYPf2Bfa6RXRvGien78SIT1IKbNbpupJg1IcYVlE60Aysiob jMDKYXIPQrmPsswBV1vGBaaaHmLLiUr8QeEMTqHJl2q58hluMkDe8Agrm7TOmw7DzMvN II7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QRIv+E3E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d199si5811560pfd.387.2018.01.25.22.03.19; Thu, 25 Jan 2018 22:03:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QRIv+E3E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751771AbeAZGCn (ORCPT + 99 others); Fri, 26 Jan 2018 01:02:43 -0500 Received: from mail-pg0-f47.google.com ([74.125.83.47]:40846 "EHLO mail-pg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751534AbeAZGCl (ORCPT ); Fri, 26 Jan 2018 01:02:41 -0500 Received: by mail-pg0-f47.google.com with SMTP id g16so6618934pgn.7 for ; Thu, 25 Jan 2018 22:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=vIjgyLZ9+ivnV0icUHFTF+IyaNp0JTucoEY5pYSU85Q=; b=QRIv+E3E2c2XY/Rem+S28eRziSbj2LVLly6G/KOEZfJ71JDPdDflPs+t5B9AN1zEI7 sxe41J9QIl3rYhfnx+NBDV77MjpULjAuvwb5mQ0QkcWXwHtpm9rbw274aoN6IS3BErfx n18Elowwr1fYCK2HgDimBFeCIAPoZ0Jnq/TVg= 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; bh=vIjgyLZ9+ivnV0icUHFTF+IyaNp0JTucoEY5pYSU85Q=; b=KoQfBjSqp6m1vL7CxnTlsD0XRCNUC2I5mnIFPBwyXq2vJ+b15VOLtojrS5FuI28/p0 l/t21hFe9q/zxSqlW2BZvkVetDjFHcCwjYW/D3yG8yJUYR9mXsGjmEyd6SGd8vxSMpF1 LWXymUFZ7oXmS3xUAxtMMT6w8+uHowyNP8zkeIh9wpIJ7hpukpedLANwMzTTsIPn86mZ aGKnwtHAvgE0yUrt+Y1AAdZqRLhSFt8uglKGuFKHjseuCA6HIIQ2OiGi3O0Misp5uHJb BJDaUJ1cNTqw1p/h45t5sikLRE7xq+v2nfkQveM5b5y1BzvshQQBlvfgrMa7VOhjU+hG IqQA== X-Gm-Message-State: AKwxyteXhTb2uFaInUzBUYEORNE0o3z/x+Gy56bxfqgd40aVdvoGpjc0 GAmksJXZvhrCUytLN9vNNdevvA== X-Received: by 2002:a17:902:6881:: with SMTP id i1-v6mr13757675plk.323.1516946561159; Thu, 25 Jan 2018 22:02:41 -0800 (PST) Received: from acourbot.tok.corp.google.com ([2401:fa00:4:1002:a6cd:a898:e07b:a331]) by smtp.gmail.com with ESMTPSA id j3sm14543201pfh.39.2018.01.25.22.02.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jan 2018 22:02:40 -0800 (PST) From: Alexandre Courbot To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Pawel Osciak , Marek Szyprowski , Tomasz Figa , Sakari Ailus , Gustavo Padovan Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot Subject: [RFC PATCH 0/8] [media] Request API, take three Date: Fri, 26 Jan 2018 15:02:08 +0900 Message-Id: <20180126060216.147918-1-acourbot@chromium.org> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Howdy. Here is your bi-weekly request API redesign! ;) Again, this is a simple version that only implements the flow of requests, without applying controls. The intent is to get an agreement on a base to work on, since the previous versions went straight back to the redesign board. Highlights of this version: * As requested by Hans, request-bound buffers are now passed earlier to drivers, as early as the request itself is submitted. Doing it earlier is not be useful since the driver would not know the state of the request, and thus cannot do anything with the buffer. Drivers are now responsible for applying request parameters themselves. * As a consequence, there is no such thing as a "request queue" anymore. The flow of buffers decides the order in which requests are processed. Individual devices of the same pipeline can implement synchronization if needed, but this is beyond this first version. * VB2 code is still a bit shady. Some of it will interfere with the fences series, so I am waiting for the latter to land to do it properly. * Requests that are not yet submitted effectively act as fences on the buffers they own, resulting in the buffer queue being blocked until the request is submitted. An alternate design would be to only block the not-submitted-request's buffer and let further buffers pass before it, but since buffer order is becoming increasingly important I have decided to just block the queue. This is open to discussion though. * Documentation! Also described usecases for codec and simple (i.e. not part of a complex pipeline) capture device. Still remaining to do: * As pointed out by Hans on the previous revision, do not assume that drivers using v4l2_fh have a per-handle state. I have not yet found a good way to differenciate both usages. * Integrate Hans' patchset for control handling: as said above, this is futile unless we can agree on the basic design, which I hope we can do this time. Chrome OS needs this really badly now and will have to move forward no matter what, so I hope this will be considered good enough for a common base of work. A few thoughts/questions that emerged when writing this patchset: * Since requests are exposed as file descriptors, we could easily move the MEDIA_REQ_CMD_SUBMIT and MEDIA_REQ_CMD_REININT commands as ioctls on the requests themselves, instead of having to perform them on the media device that provided the request in the first place. That would add a bit more flexibility if/when passing requests around and means the media device only needs to handle MEDIA_REQ_CMD_ALLOC. Conceptually speaking, this seems to make sense to me. Any comment for/against that? * For the codec usecase, I have experimented a bit marking CAPTURE buffers with the request FD that produced them (vim2m acts that way). This seems to work well, however FDs are process-local and could be closed before the CAPTURE buffer is dequeued, rendering that information less meaningful, if not dangerous. Wouldn't it be better/safer to use a global request ID for such information instead? That ID would be returned upon MEDIA_REQ_CMD_ALLOC so user-space knows which request ID a FD refers to. * Using the media node to provide requests makes absolute sense for complex camera devices, but is tedious for codec devices which work on one node and require to protect request/media related code with #ifdef CONFIG_MEDIA_CONTROLLER. For these devices, the sole role of the media node is to produce the request, and that's it (since request submission could be moved to the request FD as explained above). That's a modest use that hardly justifies bringing in the whole media framework IMHO. With a bit of extra abstraction, it should be possible to decouple the base requests from the media controller altogether, and propose two kinds of requests implementations: one simpler implementation that works directly with a single V4L2 node (useful for codecs), and another one that works on a media node and can control all its entities (good for camera). This would allow codecs to use the request API without forcing the media controller, and would considerably simplify the use-case. Any objection to that? IIRC the earlier design documents mentioned this possibility. Alexandre Courbot (6): media: add request API core and UAPI media: videobuf2: add support for requests media: vb2: add support for requests in QBUF ioctl v4l2: document the request API interface media: vim2m: add media device media: vim2m: add request support Hans Verkuil (1): videodev2.h: Add request field to v4l2_buffer Laurent Pinchart (1): media: Document the media request API Documentation/media/uapi/mediactl/media-funcs.rst | 1 + .../media/uapi/mediactl/media-ioc-request-cmd.rst | 140 ++++++++++ Documentation/media/uapi/v4l/buffer.rst | 10 +- Documentation/media/uapi/v4l/common.rst | 1 + Documentation/media/uapi/v4l/request-api.rst | 194 +++++++++++++ Documentation/media/uapi/v4l/vidioc-qbuf.rst | 21 ++ drivers/media/Makefile | 3 +- drivers/media/media-device.c | 7 + drivers/media/media-request-mgr.c | 107 +++++++ drivers/media/media-request.c | 308 +++++++++++++++++++++ drivers/media/platform/vim2m.c | 55 ++++ drivers/media/usb/cpia2/cpia2_v4l.c | 2 +- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 7 +- drivers/media/v4l2-core/v4l2-ioctl.c | 85 +++++- drivers/media/v4l2-core/videobuf2-core.c | 125 ++++++++- drivers/media/v4l2-core/videobuf2-v4l2.c | 31 ++- include/media/media-device.h | 3 + include/media/media-request-mgr.h | 73 +++++ include/media/media-request.h | 184 ++++++++++++ include/media/videobuf2-core.h | 15 +- include/media/videobuf2-v4l2.h | 2 + include/uapi/linux/media.h | 10 + include/uapi/linux/videodev2.h | 3 +- 23 files changed, 1365 insertions(+), 22 deletions(-) create mode 100644 Documentation/media/uapi/mediactl/media-ioc-request-cmd.rst create mode 100644 Documentation/media/uapi/v4l/request-api.rst create mode 100644 drivers/media/media-request-mgr.c create mode 100644 drivers/media/media-request.c create mode 100644 include/media/media-request-mgr.h create mode 100644 include/media/media-request.h -- 2.16.0.rc1.238.g530d649a79-goog