[{"id":28101,"web_url":"https://patchwork.libcamera.org/comment/28101/","msgid":"<20231120041657.GG524@pendragon.ideasonboard.com>","date":"2023-11-20T04:16:57","subject":"Re: [libcamera-devel] [PATCH v1 3/5] libcamera: control: Add vendor\n\tcontrol id range reservation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Naush,\n\nThank you for the patch.\n\nOn Fri, Nov 10, 2023 at 11:00:00AM +0000, Naushir Patuck via libcamera-devel wrote:\n> Add a new control_ranges.yaml file that is used to reserve control id\n> ranges/offsets for libcamera and vendor specific controls. This file is\n> used by the gen-controls.py script to generate control id values for\n> each control.\n> \n> Draft controls now have a seprate range from core libcamera controls,\n\ns/seprate/separate/\n\n> breaking the existing numbering behaviour.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  include/libcamera/meson.build     |  3 ++-\n>  src/libcamera/control_ranges.yaml | 17 +++++++++++++++++\n>  utils/gen-controls.py             | 15 ++++++++++++---\n>  3 files changed, 31 insertions(+), 4 deletions(-)\n>  create mode 100644 src/libcamera/control_ranges.yaml\n> \n> diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\n> index f8af51174f08..98339b93777c 100644\n> --- a/include/libcamera/meson.build\n> +++ b/include/libcamera/meson.build\n> @@ -82,11 +82,12 @@ foreach header, mode : control_source_files\n>      endforeach\n>  \n>      template_file = files(header + '.h.in')\n> +    ranges_file = files('../../src/libcamera/control_ranges.yaml')\n>      control_headers += custom_target(header + '_h',\n>                                       input : input_files,\n>                                       output : header + '.h',\n>                                       command : [gen_controls, '-o', '@OUTPUT@', '-i', '@INPUT@',\n> -                                                '--mode', mode, '-t', template_file],\n> +                                                '--mode', mode, '-t', template_file, '-r', ranges_file],\n>                                       install : true,\n>                                       install_dir : libcamera_headers_install_dir)\n>  endforeach\n> diff --git a/src/libcamera/control_ranges.yaml b/src/libcamera/control_ranges.yaml\n> new file mode 100644\n> index 000000000000..e908a8a3a110\n> --- /dev/null\n> +++ b/src/libcamera/control_ranges.yaml\n> @@ -0,0 +1,17 @@\n> +# SPDX-License-Identifier: LGPL-2.1-or-later\n> +#\n> +# Copyright (C) 2023, Raspberry Pi Ltd\n> +#\n> +%YAML 1.1\n> +---\n> +# Specifies the control id ranges/offsets for core libcamera and vendor specific\n> +# controls.\n> +ranges:\n> +  # Core libcamera controls\n> +  libcamera: 0\n> +  # Draft designated libcamera controls\n> +  draft: 1000\n> +  # Raspberry Pi vendor controls\n> +  rpi: 2000\n> +\n> +...\n> diff --git a/utils/gen-controls.py b/utils/gen-controls.py\n> index 3c490a562676..a10b9fdc19ee 100755\n> --- a/utils/gen-controls.py\n> +++ b/utils/gen-controls.py\n> @@ -259,7 +259,7 @@ ${vendor_controls_map}\n>      }\n>  \n>  \n> -def generate_h(controls, mode):\n> +def generate_h(controls, mode, ranges):\n>      enum_template_start = string.Template('''enum ${name}Enum {''')\n>      enum_value_template = string.Template('''\\t${name} = ${value},''')\n>      enum_values_template = string.Template('''extern const std::array<const ControlValue, ${size}> ${name}Values;''')\n> @@ -277,8 +277,10 @@ def generate_h(controls, mode):\n>              vendor = 'draft' if ctrl.is_draft else 'libcamera'\n>  \n>          if vendor not in ctrls:\n> +            if vendor not in ranges.keys():\n> +                raise RuntimeError('Vendor range is not defined')\n\nIt would be nice to print the vendor name here.\n\n> +            id_value[vendor] = ranges[vendor] + 1\n>              ids[vendor] = []\n> -            id_value[vendor] = 1\n>              ctrls[vendor] = []\n>  \n>          # Core and draft controls use the same ID value\n> @@ -370,8 +372,15 @@ def main(argv):\n>                          help='Template file name.')\n>      parser.add_argument('--mode', type=str, required=True, choices=['controls', 'properties'],\n>                          help='Mode of operation')\n> +    parser.add_argument('-r', dest='ranges', type=str,\n> +                        help='Control id range reservation file.')\n>      args = parser.parse_args(argv[1:])\n>  \n> +    ranges = []\n> +    if args.ranges:\n> +        data = open(args.ranges, 'rb').read()\n> +        ranges = yaml.safe_load(data)['ranges']\n> +\n>      controls = []\n>      for input in args.inputs:\n>          data = open(input, 'rb').read()\n> @@ -382,7 +391,7 @@ def main(argv):\n>      if args.template.endswith('.cpp.in'):\n>          data = generate_cpp(controls)\n>      elif args.template.endswith('.h.in'):\n> -        data = generate_h(controls, args.mode)\n> +        data = generate_h(controls, args.mode, ranges)\n>      else:\n>          raise RuntimeError('Unknown template type')\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B83E9C3200\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Nov 2023 04:16:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 38776629B6;\n\tMon, 20 Nov 2023 05:16:52 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DFC6B61DA9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Nov 2023 05:16:50 +0100 (CET)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 41E3174A;\n\tMon, 20 Nov 2023 05:16:21 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1700453812;\n\tbh=Ni4yKNROrfqwKgKl1tNZr/QLwxC3MlUPjdBy180MBTc=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=vFdak38+8/J345p6b51hDqjSrEBCfox5R1wkfNd9MIVC8zlJa8YIzjgtWbCE2nr6H\n\t/4QewjQnv6g3RbBylLCOVYh75r7XFG6kUh43tr2w4aJlRJtcn+J11vW2hJsKCbEilT\n\tL1KkqJ9lIJW2ixoy5fK/WI0P9KIC2UWmkyFhR0UZ+HB2mKtsehXLfRhdu520ovpvtw\n\tJFclKj7Sk90czHJhNsPjMoT/fe7GMuLTZdTHCPtAn60dddMQiOEPg6kfuwnZ0ZCNnc\n\tUz7/uTA/37mOoqUvj+NhThIBWAl1+VLmt0IdT8mAOp3wa3pgnI+QQzdnvIOyv8odpT\n\tjPAIi4BwnxS7Q==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1700453781;\n\tbh=Ni4yKNROrfqwKgKl1tNZr/QLwxC3MlUPjdBy180MBTc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=PWQcLjR4ckVAEPXAV2Nx9Z6FJ9eLhAjDNAhZ0AVc2NR3e5m0x9/yEzbDS39VtE3MS\n\tOlB6qmgb5+AXo6esd2ZlRuZd/ue8v9PMwFRe4Ysts4NmL4oc4Saf5vddoa73KxGHr9\n\tvIFX+MgsHZyuHTmN1KNpO7BNBymm/rNfVvvDCqlI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"PWQcLjR4\"; dkim-atps=neutral","Date":"Mon, 20 Nov 2023 06:16:57 +0200","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<20231120041657.GG524@pendragon.ideasonboard.com>","References":"<20231110110002.21381-1-naush@raspberrypi.com>\n\t<20231110110002.21381-4-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20231110110002.21381-4-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v1 3/5] libcamera: control: Add vendor\n\tcontrol id range reservation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]