Received: by 10.223.185.116 with SMTP id b49csp395209wrg; Tue, 20 Feb 2018 23:42:13 -0800 (PST) X-Google-Smtp-Source: AH8x226dYwsRugbrdTugltPEzm47dsM57euPoT3B+H5jn3WxydiTpCPXQTqDzEcaT9EyfYucZ1Pz X-Received: by 10.101.93.73 with SMTP id e9mr2034747pgt.264.1519198933730; Tue, 20 Feb 2018 23:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519198933; cv=none; d=google.com; s=arc-20160816; b=ZB4tUxdLf2A2o8A2U/+TE2FOIom6k/SpFRQJIIHFrs4f0myRpQciq9T2okU2mhS98o OXjMitIOOKmVDKqYdKF9qALqfFufQOxb5y8lm1Jwsh38Afy91oBMgSmKIg3Gn0JGnyvU nXeLfVFRiJxnhamPxVcW6qg7Gk7IdLaYSAMX8E2oyAwuuVGqExnS7BQTSldeJPc+C1YN gx49xABNNckdoUvwybsP5ieNtPNZnaKMtAHdwt0x7AJHkVMtjIqlKt5aa+lfFSOSxsEY 5SdSinxnJa7OwW5U2xUfxqebpW5UNPBO3/dbsJmqSvTXIT71Um1JYGlU6oyVafJD9m4x MAGw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=9hAl9qeBXvN/hpXeQZyDGclDBH3FXmjWvA6R7UruKzE=; b=Tce6/+ExOAsgen3mDZwLc8nJvONbAjq+NUH8GcIgAdr2KBRBhvXQsMIoLDNbqxtAMr CbOk5wtheesZyMz7p7+cdDzKQWslWlNP60+OrI7VTBtUF+TWwAebEOtOeCDAhPLNqLGM clQJMIsaDTIQJaBszLi3g/eZgG7XYCRqT1uCcxjMhViewrFGJjeNX1ftqCChRwxhQc7S O450ahPN7pAE7cdaURW8dO6Hwf3Fu3C0T5hAI+23B10LT3DQQUHdm+pkco8yhy4Mtt9t HUYA7xItwJ7R/EJ2jbdQ5x+lVR/oohX3Mdg+WxlrJvZatkxLyW5EpKAfvSAnpW8ElwnD XbHg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14-v6si19350447pll.736.2018.02.20.23.41.59; Tue, 20 Feb 2018 23:42:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751851AbeBUH31 (ORCPT + 99 others); Wed, 21 Feb 2018 02:29:27 -0500 Received: from lb1-smtp-cloud9.xs4all.net ([194.109.24.22]:47789 "EHLO lb1-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751295AbeBUH3Z (ORCPT ); Wed, 21 Feb 2018 02:29:25 -0500 Received: from [192.168.2.10] ([212.251.195.8]) by smtp-cloud9.xs4all.net with ESMTPA id oOq8ePRa5oWCOoOqBenJvD; Wed, 21 Feb 2018 08:29:24 +0100 Subject: Re: [RFCv4 01/21] media: add request API core and UAPI To: Alexandre Courbot Cc: Mauro Carvalho Chehab , Laurent Pinchart , Pawel Osciak , Marek Szyprowski , Tomasz Figa , Sakari Ailus , Gustavo Padovan , Linux Media Mailing List , LKML References: <20180220044425.169493-1-acourbot@chromium.org> <20180220044425.169493-2-acourbot@chromium.org> <5fd863ad-a0fe-88d7-05bd-90c2b4096145@xs4all.nl> From: Hans Verkuil Message-ID: Date: Wed, 21 Feb 2018 08:29:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfJQhrrwLWYlRPHy2JaYi4SJPDBFzWNSYAvXsdMP9eRE2T/5LA8tlD65iCewRUElLRlPdsHC3YQQH+8MUzzb/RD13OwKf9j5Md/42jOWeNwwVBZWTvCvP g+wQP24coEFTxwe2rxojBXYMoibYcEiQZWkf/EYlU69kv7HQaZJrRpsa61AjeswQ7V5cd73PNapPi72yv0a3UQDUr1UFPjHo5JZ3Bi8prEYB6bpr2m/YZIOQ c0EZsodU9Rz91b5rvqNS2TBYo8xVrS5gzz4A8cElbSR4Qlsa+B+QXR0YRyJx8VnB6pSw7s7CyW+em/lKCmGH8lzJKS07VEK4n9f4xxOHQJlPiELE8IL0wJXP WibeEiQBnxvDmkXXmX/flhDxo/7xo/lH+pv5TOdmT3Bn1qukYpQjTBcfvkIhCntigFti6Jy4ArytU3QuAimeRjSfSs47FU5EC2FtIOHeKWmG6TpKCz2xQ72m iJIULhlZJZOyIbYU Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/21/2018 07:01 AM, Alexandre Courbot wrote: > Hi Hans, > > On Tue, Feb 20, 2018 at 7:36 PM, Hans Verkuil wrote: >> On 02/20/18 05:44, Alexandre Courbot wrote: >>> +#define MEDIA_REQUEST_IOC(__cmd, func) \ >>> + [_IOC_NR(MEDIA_REQUEST_IOC_##__cmd) - 0x80] = { \ >>> + .cmd = MEDIA_REQUEST_IOC_##__cmd, \ >>> + .fn = func, \ >>> + } >>> + >>> +struct media_request_ioctl_info { >>> + unsigned int cmd; >>> + long (*fn)(struct media_request *req); >>> +}; >>> + >>> +static const struct media_request_ioctl_info ioctl_info[] = { >>> + MEDIA_REQUEST_IOC(SUBMIT, media_request_ioctl_submit), >>> + MEDIA_REQUEST_IOC(REINIT, media_request_ioctl_reinit), >> >> There are only two ioctls, so there is really no need for the >> MEDIA_REQUEST_IOC define. Just keep it simple. > > The number of times it is used doesn't change the fact that it helps > with readability IMHO. But this macro just boils down to: static const struct media_request_ioctl_info ioctl_info[] = { { MEDIA_REQUEST_IOC_SUBMIT, media_request_ioctl_submit }, { MEDIA_REQUEST_IOC_REINIT, media_request_ioctl_reinit }, }; It's absolutely identical! So it seems senseless to me. > >> >>> +}; >>> + >>> +static long media_request_ioctl(struct file *filp, unsigned int cmd, >>> + unsigned long __arg) >>> +{ >>> + struct media_request *req = filp->private_data; >>> + const struct media_request_ioctl_info *info; >>> + >>> + if ((_IOC_NR(cmd) < 0x80) || >> >> Why start the ioctl number at 0x80? Why not just 0? >> It avoids all this hassle with the 0x80 offset. There is no clash with the MC ioctls, so I really don't believe the 0x80 offset is needed. >> >>> + _IOC_NR(cmd) >= 0x80 + ARRAY_SIZE(ioctl_info) || >>> + ioctl_info[_IOC_NR(cmd) - 0x80].cmd != cmd) >>> + return -ENOIOCTLCMD; >>> + >>> + info = &ioctl_info[_IOC_NR(cmd) - 0x80]; >>> + >>> + return info->fn(req); >>> +} >>> diff --git a/include/uapi/linux/media-request.h b/include/uapi/linux/media-request.h >>> new file mode 100644 >>> index 000000000000..5d30f731a442 >>> --- /dev/null >>> +++ b/include/uapi/linux/media-request.h >>> @@ -0,0 +1,37 @@ >>> +/* >>> + * Media requests UAPI >>> + * >>> + * Copyright (C) 2018, 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. >>> + */ >>> + >>> +#ifndef __LINUX_MEDIA_REQUEST_H >>> +#define __LINUX_MEDIA_REQUEST_H >>> + >>> +#ifndef __KERNEL__ >>> +#include >>> +#endif >>> +#include >>> +#include >>> +#include >>> + >>> +/* Only check that requests can be used, do not allocate */ >>> +#define MEDIA_REQUEST_FLAG_TEST 0x00000001 >>> + >>> +struct media_request_new { >>> + __u32 flags; >>> + __s32 fd; >>> +} __attribute__ ((packed)); >>> + >>> +#define MEDIA_REQUEST_IOC_SUBMIT _IO('|', 128) >>> +#define MEDIA_REQUEST_IOC_REINIT _IO('|', 129) >>> + >>> +#endif >>> >> >> I need to think a bit more on this internal API, so I might come back >> to this patch for more comments. > > I think I should probably elaborate on why I think it is advantageous > to have these ioctls handled here. Sorry for the confusion, I was not actually referring to these ioctls. In fact, I really like them. It was more a general comment about the request API core. I should have been more clear. Regards, Hans > > One of the reasons if that it does not force user-space to keep track > of who issued the request to operate on it. Semantically, the only > device a request could be submitted to is the device that produced it > anyway, so since that argument is constant we may as well get rid of > it (and we also don't need to pass the request FD as argument > anymore). > > It also gives us more freedom when designing new request-related > ioctls: before, all request-related operations were multiplexed under > a single MEDIA_IOC_REQUEST_CMD ioctl, which cmd field indicated the > actual operation to perform. With this design, all the arguments must > fit within the media_request_cmd structure, which may cause confusion > as it will have to be variable-sized. I am thinking in particular > about a future atomic-like API to set topology, controls and buffers > related to a request all at the same time. Having it as a request > ioctl seems perfectly fitting to me. >