[{"id":21790,"web_url":"https://patchwork.libcamera.org/comment/21790/","msgid":"<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>","date":"2021-12-14T22:22:08","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Daniel,\n\nThank you for the patch.\n\nOn Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n> Upon an async fwnode match, there's some typical behaviour that the\n> notifier and matching subdev will want to do. For example, a notifier\n> representing a sensor matching to an async subdev representing its\n> VCM will want to create an ancillary link to expose that relationship\n> to userspace.\n> \n> To avoid lots of code in individual drivers, try to build these links\n> within v4l2 core.\n> \n> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n> ---\n> Changes since the rfc:\n> \n> \t- None\n> \n>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n>  1 file changed, 51 insertions(+)\n> \n> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n> index 0404267f1ae4..6575b1cbe95f 100644\n> --- a/drivers/media/v4l2-core/v4l2-async.c\n> +++ b/drivers/media/v4l2-core/v4l2-async.c\n> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n>  static int\n>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n>  \n> +static int\n> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n> +\t\t\t\t   struct v4l2_subdev *sd)\n> +{\n> +\tstruct media_link *link;\n> +\n> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n> +\t\treturn -EINVAL;\n> +\n> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n\nIs there a guarantee at this point that notifier->sd->entity has already\nbeen registered with the media_device ? That's done by\nmedia_device_register_entity() called from\nv4l2_device_register_subdev().\n\n> +\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n> +\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n> +\n> +\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n> +}\n> +\n> +/*\n> + * Setup links on behalf of the notifier and subdev, where it's obvious what\n\ns/Setup/Create/ (\"link setup\" refers to another operation, enabling and\ndisabling links at runtime)\n\n> + * should be done. At the moment, we only support cases where the notifier\n> + * is a sensor and the subdev is a lens.\n\ns/sensor/camera sensor/\ns/lens/lens controller/\n\n> + *\n> + * TODO: Setup pad links if the notifier's function is MEDIA_ENT_F_VID_IF_BRIDGE\n> + * and the subdev's is MEDIA_ENT_F_CAM_SENSOR\n> + */\n> +static int v4l2_async_try_create_links(struct v4l2_async_notifier *notifier,\n> +\t\t\t\t       struct v4l2_subdev *sd)\n> +{\n> +\tif (!notifier->sd)\n> +\t\treturn 0;\n> +\n> +\tswitch (notifier->sd->entity.function) {\n> +\tcase MEDIA_ENT_F_CAM_SENSOR:\n> +\t\treturn __v4l2_async_create_ancillary_link(notifier, sd);\n> +\tdefault:\n> +\t\treturn 0;\n> +\t}\n> +}\n> +\n>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>  \t\t\t\t   struct v4l2_device *v4l2_dev,\n>  \t\t\t\t   struct v4l2_subdev *sd,\n> @@ -293,6 +332,18 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>  \t\treturn ret;\n>  \t}\n>  \n> +\t/*\n> +\t * Depending of the function of the entities involved, we may want to\n> +\t * create links between them (for example between a sensor and its lens\n> +\t * or between a sensor's source pad and the connected device's sink\n> +\t * pad)\n\ns/)/)./\n\n> +\t */\n> +\tret = v4l2_async_try_create_links(notifier, sd);\n> +\tif (ret) {\n> +\t\tv4l2_device_unregister_subdev(sd);\n> +\t\treturn ret;\n> +\t}\n> +\n>  \t/* Remove from the waiting list */\n>  \tlist_del(&asd->list);\n>  \tsd->asd = asd;","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 26AEDBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Dec 2021 22:22:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 62464608A4;\n\tTue, 14 Dec 2021 23:22:13 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 67F9C60117\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Dec 2021 23:22:11 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B30B48C4;\n\tTue, 14 Dec 2021 23:22:10 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"NplJSJh8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1639520530;\n\tbh=Djanrb1qArmdt1u2pGupDqDFG1HBvjOlso+yEQW/YtA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=NplJSJh8y0uUkg1U/xTMlIyorkI6pfgNT8GxSFyg86uOFCdSLBSeZ7cgxGsZotiUH\n\t634wHyI8zDmMCy7nTjJMsPnz0PuNQT9puw0cqJVNQhBP6GB/XkV+d2zP2M/VMW1xgp\n\tIRxHf4EuxtEd2tZrhMh6P+EEY5d0C0gHxPJ8Josw=","Date":"Wed, 15 Dec 2021 00:22:08 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211213232849.40071-6-djrscally@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, sakari.ailus@linux.intel.com,\n\tlinux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21791,"web_url":"https://patchwork.libcamera.org/comment/21791/","msgid":"<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>","date":"2021-12-14T22:36:01","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":90,"url":"https://patchwork.libcamera.org/api/people/90/","name":"Daniel Scally","email":"djrscally@gmail.com"},"content":"Hi Laurent\n\nOn 14/12/2021 22:22, Laurent Pinchart wrote:\n> Hi Daniel,\n> \n> Thank you for the patch.\n> \n> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n>> Upon an async fwnode match, there's some typical behaviour that the\n>> notifier and matching subdev will want to do. For example, a notifier\n>> representing a sensor matching to an async subdev representing its\n>> VCM will want to create an ancillary link to expose that relationship\n>> to userspace.\n>>\n>> To avoid lots of code in individual drivers, try to build these links\n>> within v4l2 core.\n>>\n>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n>> ---\n>> Changes since the rfc:\n>>\n>> \t- None\n>>\n>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n>>  1 file changed, 51 insertions(+)\n>>\n>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n>> index 0404267f1ae4..6575b1cbe95f 100644\n>> --- a/drivers/media/v4l2-core/v4l2-async.c\n>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n>>  static int\n>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n>>  \n>> +static int\n>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n>> +\t\t\t\t   struct v4l2_subdev *sd)\n>> +{\n>> +\tstruct media_link *link;\n>> +\n>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n>> +\t\treturn -EINVAL;\n>> +\n>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n> \n> Is there a guarantee at this point that notifier->sd->entity has already\n> been registered with the media_device ? That's done by\n> media_device_register_entity() called from\n> v4l2_device_register_subdev().\n\nv4l2_async_match_notify() calls v4l2_device_register_subdev() before the\npoint that I've added the call to v4l2_async_try_create_links(), so I\nthink that's covered there.\n\n>> +\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n>> +\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n>> +\n>> +\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n>> +}\n>> +\n>> +/*\n>> + * Setup links on behalf of the notifier and subdev, where it's obvious what\n> \n> s/Setup/Create/ (\"link setup\" refers to another operation, enabling and\n> disabling links at runtime)\n\nYes, good point; although that too is a piece of terminology I find a\nbit jarring to be honest; I would have named that function\nmedia_entity_configure_link()\n\n> \n>> + * should be done. At the moment, we only support cases where the notifier\n>> + * is a sensor and the subdev is a lens.\n> \n> s/sensor/camera sensor/\n> s/lens/lens controller/\n> \n>> + *\n>> + * TODO: Setup pad links if the notifier's function is MEDIA_ENT_F_VID_IF_BRIDGE\n>> + * and the subdev's is MEDIA_ENT_F_CAM_SENSOR\n>> + */\n>> +static int v4l2_async_try_create_links(struct v4l2_async_notifier *notifier,\n>> +\t\t\t\t       struct v4l2_subdev *sd)\n>> +{\n>> +\tif (!notifier->sd)\n>> +\t\treturn 0;\n>> +\n>> +\tswitch (notifier->sd->entity.function) {\n>> +\tcase MEDIA_ENT_F_CAM_SENSOR:\n>> +\t\treturn __v4l2_async_create_ancillary_link(notifier, sd);\n>> +\tdefault:\n>> +\t\treturn 0;\n>> +\t}\n>> +}\n>> +\n>>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>>  \t\t\t\t   struct v4l2_device *v4l2_dev,\n>>  \t\t\t\t   struct v4l2_subdev *sd,\n>> @@ -293,6 +332,18 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>>  \t\treturn ret;\n>>  \t}\n>>  \n>> +\t/*\n>> +\t * Depending of the function of the entities involved, we may want to\n>> +\t * create links between them (for example between a sensor and its lens\n>> +\t * or between a sensor's source pad and the connected device's sink\n>> +\t * pad)\n> \n> s/)/)./\n> \n>> +\t */\n>> +\tret = v4l2_async_try_create_links(notifier, sd);\n>> +\tif (ret) {\n>> +\t\tv4l2_device_unregister_subdev(sd);\n>> +\t\treturn ret;\n>> +\t}\n>> +\n>>  \t/* Remove from the waiting list */\n>>  \tlist_del(&asd->list);\n>>  \tsd->asd = asd;\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 DAEFFBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Dec 2021 22:36:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2E5FC608A4;\n\tTue, 14 Dec 2021 23:36:05 +0100 (CET)","from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\n\t[IPv6:2a00:1450:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 12D6D60117\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Dec 2021 23:36:04 +0100 (CET)","by mail-wr1-x42e.google.com with SMTP id k9so17130219wrd.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Dec 2021 14:36:04 -0800 (PST)","from [192.168.0.16]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id\n\tt127sm3809854wma.9.2021.12.14.14.36.02\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tTue, 14 Dec 2021 14:36:03 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"RDcd9yHB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=jd8H/ss1tY2RZQujVlK9cQ65SRUkbsyN0fjB8qEQAH4=;\n\tb=RDcd9yHBA8CSAsfEMENSG0B2Xx1FBfNoUuOtDEEo0U9QP3zbOcxPC4zxxGfOkKjlJI\n\tgC9LGpM+TGjMF1ahM609/RPwWfvCkn3xfGMOaxxLSqnNERvKTaodZa1ZaKokQR0LqHPR\n\ttN72sW8+7FK8MBqgZ+EQWgkodkHIunBwopslFN59bPV4pdOSebtN1X+B/aE9//Vmm2ys\n\tr6vEWc/dxmnVXtXrK9kFVr74lhURu3jzPldXjSLDtFOHy8Ghpj8cM/IXQ7/Q6cyjGWo4\n\toEyAaCw0IXXJ1HCEi3IXbbI/jiHGuARoucpRo2H1XRPiEkNBKMUyqZxwNn1p9Qw4vm81\n\tW+HA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=jd8H/ss1tY2RZQujVlK9cQ65SRUkbsyN0fjB8qEQAH4=;\n\tb=tjgbuEaOT+sVbHVAg6aKCRhurT/5qYtQYxExHtSi34dEPUCjYeX3AXQwaPKi4lmMkj\n\tW0FHl7g2RrPbQ2RUcsSM3luhRYojAufZHe/IQZBTTSEROc8wWNqX51tb37rhT/xaB1Us\n\tPxTqhlkC0tHqoQ4DqOMuYPX0MYi6uYBW6hmVRM2ayi0bI2zz/6/T+BQ//WQbNsx3njZ+\n\tfcGFt9baZwKcBerTfwLf+70yAIYPW5LTbucsn0dlv3R6pbCYSYcKeDGjyufI2vKxGiEM\n\tlvXreSxXJkND6knyqYgOKeBIY6pXQ4hCqpF+T1PA01xsYJ/Y+u5VYWdycE21OwPiEqik\n\tVraA==","X-Gm-Message-State":"AOAM530NdWC/fLmneRfhWX7cEr+tJ7rM2uw5rRu/MglLFzg0goQsALco\n\ttlMtEfOHlxqIXNAOGimlGjY=","X-Google-Smtp-Source":"ABdhPJz7kF7FtCBrgbLD/u1TI2970NsvX2ShwYfQc7KkdW/MitLbutnIch66/rQ2EEtQyJAAnI07Gg==","X-Received":"by 2002:adf:e3d1:: with SMTP id\n\tk17mr1797688wrm.610.1639521363683; \n\tTue, 14 Dec 2021 14:36:03 -0800 (PST)","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>","From":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>","Date":"Tue, 14 Dec 2021 22:36:01 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.14.0","MIME-Version":"1.0","In-Reply-To":"<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, sakari.ailus@linux.intel.com,\n\tlinux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21792,"web_url":"https://patchwork.libcamera.org/comment/21792/","msgid":"<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>","date":"2021-12-14T23:01:14","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Daniel,\n\nOn Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n> On 14/12/2021 22:22, Laurent Pinchart wrote:\n> > On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n> >> Upon an async fwnode match, there's some typical behaviour that the\n> >> notifier and matching subdev will want to do. For example, a notifier\n> >> representing a sensor matching to an async subdev representing its\n> >> VCM will want to create an ancillary link to expose that relationship\n> >> to userspace.\n> >>\n> >> To avoid lots of code in individual drivers, try to build these links\n> >> within v4l2 core.\n> >>\n> >> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n> >> ---\n> >> Changes since the rfc:\n> >>\n> >> \t- None\n> >>\n> >>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n> >>  1 file changed, 51 insertions(+)\n> >>\n> >> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n> >> index 0404267f1ae4..6575b1cbe95f 100644\n> >> --- a/drivers/media/v4l2-core/v4l2-async.c\n> >> +++ b/drivers/media/v4l2-core/v4l2-async.c\n> >> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n> >>  static int\n> >>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n> >>  \n> >> +static int\n> >> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n> >> +\t\t\t\t   struct v4l2_subdev *sd)\n> >> +{\n> >> +\tstruct media_link *link;\n> >> +\n> >> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n> >> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n> >> +\t\treturn -EINVAL;\n> >> +\n> >> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n> > \n> > Is there a guarantee at this point that notifier->sd->entity has already\n> > been registered with the media_device ? That's done by\n> > media_device_register_entity() called from\n> > v4l2_device_register_subdev().\n> \n> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n> point that I've added the call to v4l2_async_try_create_links(), so I\n> think that's covered there.\n\nIt calls it on sd, not notifier->sd. It's the latter that concerns me.\n\n> >> +\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n> >> +\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n> >> +\n> >> +\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n> >> +}\n> >> +\n> >> +/*\n> >> + * Setup links on behalf of the notifier and subdev, where it's obvious what\n> > \n> > s/Setup/Create/ (\"link setup\" refers to another operation, enabling and\n> > disabling links at runtime)\n> \n> Yes, good point; although that too is a piece of terminology I find a\n> bit jarring to be honest; I would have named that function\n> media_entity_configure_link()\n> \n> >> + * should be done. At the moment, we only support cases where the notifier\n> >> + * is a sensor and the subdev is a lens.\n> > \n> > s/sensor/camera sensor/\n> > s/lens/lens controller/\n> > \n> >> + *\n> >> + * TODO: Setup pad links if the notifier's function is MEDIA_ENT_F_VID_IF_BRIDGE\n> >> + * and the subdev's is MEDIA_ENT_F_CAM_SENSOR\n> >> + */\n> >> +static int v4l2_async_try_create_links(struct v4l2_async_notifier *notifier,\n> >> +\t\t\t\t       struct v4l2_subdev *sd)\n> >> +{\n> >> +\tif (!notifier->sd)\n> >> +\t\treturn 0;\n> >> +\n> >> +\tswitch (notifier->sd->entity.function) {\n> >> +\tcase MEDIA_ENT_F_CAM_SENSOR:\n> >> +\t\treturn __v4l2_async_create_ancillary_link(notifier, sd);\n> >> +\tdefault:\n> >> +\t\treturn 0;\n> >> +\t}\n> >> +}\n> >> +\n> >>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n> >>  \t\t\t\t   struct v4l2_device *v4l2_dev,\n> >>  \t\t\t\t   struct v4l2_subdev *sd,\n> >> @@ -293,6 +332,18 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n> >>  \t\treturn ret;\n> >>  \t}\n> >>  \n> >> +\t/*\n> >> +\t * Depending of the function of the entities involved, we may want to\n> >> +\t * create links between them (for example between a sensor and its lens\n> >> +\t * or between a sensor's source pad and the connected device's sink\n> >> +\t * pad)\n> > \n> > s/)/)./\n> > \n> >> +\t */\n> >> +\tret = v4l2_async_try_create_links(notifier, sd);\n> >> +\tif (ret) {\n> >> +\t\tv4l2_device_unregister_subdev(sd);\n> >> +\t\treturn ret;\n> >> +\t}\n> >> +\n> >>  \t/* Remove from the waiting list */\n> >>  \tlist_del(&asd->list);\n> >>  \tsd->asd = asd;","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 84BC9BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Dec 2021 23:01:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B9083608A4;\n\tWed, 15 Dec 2021 00:01:18 +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 47E9C605A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Dec 2021 00:01:17 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9F15D292;\n\tWed, 15 Dec 2021 00:01:16 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IEeCxvWQ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1639522876;\n\tbh=WW05fv1VLQrbsGZbylUTBiWpqUxjM7JMu++jEWs2he8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IEeCxvWQfkN4g4qZhFGelmInKwbfZEOLAMmx2skgO18hs78L8X2oneNmcDdS2vn66\n\ttsAJc27oK7Eg5QrZdeu1sj0kXZyNUKrMC3uyQ9AUsNy5jZnTdsUJ/kUszbPB3x+ePV\n\t1NoRTSa0OUNBfr7DT/mFIT2JmwsNCAsOrez1K4pk=","Date":"Wed, 15 Dec 2021 01:01:14 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, sakari.ailus@linux.intel.com,\n\tlinux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21793,"web_url":"https://patchwork.libcamera.org/comment/21793/","msgid":"<35553048-f338-8650-027f-708cfaac030d@gmail.com>","date":"2021-12-14T23:41:27","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":90,"url":"https://patchwork.libcamera.org/api/people/90/","name":"Daniel Scally","email":"djrscally@gmail.com"},"content":"Hi Laurent\n\nOn 14/12/2021 23:01, Laurent Pinchart wrote:\n> Hi Daniel,\n>\n> On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n>> On 14/12/2021 22:22, Laurent Pinchart wrote:\n>>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n>>>> Upon an async fwnode match, there's some typical behaviour that the\n>>>> notifier and matching subdev will want to do. For example, a notifier\n>>>> representing a sensor matching to an async subdev representing its\n>>>> VCM will want to create an ancillary link to expose that relationship\n>>>> to userspace.\n>>>>\n>>>> To avoid lots of code in individual drivers, try to build these links\n>>>> within v4l2 core.\n>>>>\n>>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n>>>> ---\n>>>> Changes since the rfc:\n>>>>\n>>>> \t- None\n>>>>\n>>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n>>>>  1 file changed, 51 insertions(+)\n>>>>\n>>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n>>>> index 0404267f1ae4..6575b1cbe95f 100644\n>>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n>>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n>>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n>>>>  static int\n>>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n>>>>  \n>>>> +static int\n>>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n>>>> +\t\t\t\t   struct v4l2_subdev *sd)\n>>>> +{\n>>>> +\tstruct media_link *link;\n>>>> +\n>>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n>>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n>>>> +\t\treturn -EINVAL;\n>>>> +\n>>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n>>> Is there a guarantee at this point that notifier->sd->entity has already\n>>> been registered with the media_device ? That's done by\n>>> media_device_register_entity() called from\n>>> v4l2_device_register_subdev().\n>> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n>> point that I've added the call to v4l2_async_try_create_links(), so I\n>> think that's covered there.\n> It calls it on sd, not notifier->sd. It's the latter that concerns me.\n\n\nAh, you're right of course...I guess in that case the notifier->sd would\nget registered during the v4l2_async_match_notify() where the sensor\ndriver's subdev is sd, but I don't think there's any guarantee that that\nwould happen first...I haven't traced it through but my guess is that it\nwould depend on the order in which the ipu3-cio2, sensor and lens\ncontroller drivers probed. I'll check to try and be sure how it works\ntomorrow\n\n>\n>>>> +\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n>>>> +\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n>>>> +\n>>>> +\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n>>>> +}\n>>>> +\n>>>> +/*\n>>>> + * Setup links on behalf of the notifier and subdev, where it's obvious what\n>>> s/Setup/Create/ (\"link setup\" refers to another operation, enabling and\n>>> disabling links at runtime)\n>> Yes, good point; although that too is a piece of terminology I find a\n>> bit jarring to be honest; I would have named that function\n>> media_entity_configure_link()\n>>\n>>>> + * should be done. At the moment, we only support cases where the notifier\n>>>> + * is a sensor and the subdev is a lens.\n>>> s/sensor/camera sensor/\n>>> s/lens/lens controller/\n>>>\n>>>> + *\n>>>> + * TODO: Setup pad links if the notifier's function is MEDIA_ENT_F_VID_IF_BRIDGE\n>>>> + * and the subdev's is MEDIA_ENT_F_CAM_SENSOR\n>>>> + */\n>>>> +static int v4l2_async_try_create_links(struct v4l2_async_notifier *notifier,\n>>>> +\t\t\t\t       struct v4l2_subdev *sd)\n>>>> +{\n>>>> +\tif (!notifier->sd)\n>>>> +\t\treturn 0;\n>>>> +\n>>>> +\tswitch (notifier->sd->entity.function) {\n>>>> +\tcase MEDIA_ENT_F_CAM_SENSOR:\n>>>> +\t\treturn __v4l2_async_create_ancillary_link(notifier, sd);\n>>>> +\tdefault:\n>>>> +\t\treturn 0;\n>>>> +\t}\n>>>> +}\n>>>> +\n>>>>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>>>>  \t\t\t\t   struct v4l2_device *v4l2_dev,\n>>>>  \t\t\t\t   struct v4l2_subdev *sd,\n>>>> @@ -293,6 +332,18 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>>>>  \t\treturn ret;\n>>>>  \t}\n>>>>  \n>>>> +\t/*\n>>>> +\t * Depending of the function of the entities involved, we may want to\n>>>> +\t * create links between them (for example between a sensor and its lens\n>>>> +\t * or between a sensor's source pad and the connected device's sink\n>>>> +\t * pad)\n>>> s/)/)./\n>>>\n>>>> +\t */\n>>>> +\tret = v4l2_async_try_create_links(notifier, sd);\n>>>> +\tif (ret) {\n>>>> +\t\tv4l2_device_unregister_subdev(sd);\n>>>> +\t\treturn ret;\n>>>> +\t}\n>>>> +\n>>>>  \t/* Remove from the waiting list */\n>>>>  \tlist_del(&asd->list);\n>>>>  \tsd->asd = asd;","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 29A54BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Dec 2021 23:41:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 64183608E6;\n\tWed, 15 Dec 2021 00:41:30 +0100 (CET)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 21F83605A7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Dec 2021 00:41:29 +0100 (CET)","by mail-wr1-x436.google.com with SMTP id u17so35137684wrt.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Dec 2021 15:41:29 -0800 (PST)","from [192.168.0.14]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id z11sm44201wmf.9.2021.12.14.15.41.27\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tTue, 14 Dec 2021 15:41:28 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"J/+KgmOZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-transfer-encoding:content-language; \n\tbh=WBK9ujCDquphOcxIQprqcX8PBsYrqY9YsFZztCmyu+w=;\n\tb=J/+KgmOZx0YEhVBC7ORIVWiXCntUsExUoUlJkmWAGpGaguA5CDHCj8HEvwBPEgrbq3\n\tUrgZ6myH4S5nUSZGvfjwpFlVFFP0jBdyFKmDW/zrv+oCfB1WCWlrmOyKhyxgtkKJTyu1\n\ty4r7vgoqYU3cAoxKwMA69rC/y1/Cbbz6i4mR/dIPJI9YOCfigLz0GLW38MTo8z/OxgKc\n\tecb0ArEQZUDXo2e8v8Lg8KREU6jxljy/zZSaY7dmTUMgQeNr56hwwG2ewStD4o3NTa8i\n\t0mC9i8U7Gtl5Tkojks19FhNwTb+DjogY51votEXtqGTcZFy2JGvoIPR0PYk5fr4B8XHm\n\t6MVA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-transfer-encoding\n\t:content-language;\n\tbh=WBK9ujCDquphOcxIQprqcX8PBsYrqY9YsFZztCmyu+w=;\n\tb=y8hwo/5WtkUS+ZpkMSpxKAO+8Fd134CjOP9XJYMTbwicCPwQXV6uybEs4KOlg9ZRDP\n\tAftviakct3Zbx8+8v/FLfKM2veNmhI/v1e1RJwYFao3q6SqaKy95jdFE1CmWWv09PHjc\n\tLlnsy+SPsXUiNQuWfF6BzPMvfASeKbF/nhfAYo+/EtnHjkEwjJ07uNajxGyedg5mTnC/\n\toc1jGPlL8v+wI4X1+a2SUcFZV7n6Or57u3LOPpVXI9gvdEkjt30dAV3YcU4dIJjHwsC+\n\tm7IZs85v3OP0eaOzndUs0xzTNdgMtzHgAlv4c942Aa2RN7X8H9sELXqBD5Dv6TMLM1U5\n\tFcDw==","X-Gm-Message-State":"AOAM5312Yc0pLW1V/hfxW4eXrLNAN6a2XCOniLFwG9JyXSXLApLCqJkG\n\t5Tl/FOcGOXP/w22bTRZQ0Bg=","X-Google-Smtp-Source":"ABdhPJyrPUAXlrNwrLSNpDogiN1Qn8r4voz8GFUDBsOXg108m5oiR4+mErISzycCgyuU5FD8DHJ2Pg==","X-Received":"by 2002:a05:6000:1788:: with SMTP id\n\te8mr2073411wrg.45.1639525288776; \n\tTue, 14 Dec 2021 15:41:28 -0800 (PST)","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>","From":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<35553048-f338-8650-027f-708cfaac030d@gmail.com>","Date":"Tue, 14 Dec 2021 23:41:27 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.14.0","MIME-Version":"1.0","In-Reply-To":"<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, sakari.ailus@linux.intel.com,\n\tlinux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21794,"web_url":"https://patchwork.libcamera.org/comment/21794/","msgid":"<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>","date":"2021-12-15T09:04:44","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Dan,\n\nOn Tue, Dec 14, 2021 at 11:41:27PM +0000, Daniel Scally wrote:\n> On 14/12/2021 23:01, Laurent Pinchart wrote:\n> > On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n> >> On 14/12/2021 22:22, Laurent Pinchart wrote:\n> >>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n> >>>> Upon an async fwnode match, there's some typical behaviour that the\n> >>>> notifier and matching subdev will want to do. For example, a notifier\n> >>>> representing a sensor matching to an async subdev representing its\n> >>>> VCM will want to create an ancillary link to expose that relationship\n> >>>> to userspace.\n> >>>>\n> >>>> To avoid lots of code in individual drivers, try to build these links\n> >>>> within v4l2 core.\n> >>>>\n> >>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n> >>>> ---\n> >>>> Changes since the rfc:\n> >>>>\n> >>>> \t- None\n> >>>>\n> >>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n> >>>>  1 file changed, 51 insertions(+)\n> >>>>\n> >>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n> >>>> index 0404267f1ae4..6575b1cbe95f 100644\n> >>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n> >>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n> >>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n> >>>>  static int\n> >>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n> >>>>  \n> >>>> +static int\n> >>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n> >>>> +\t\t\t\t   struct v4l2_subdev *sd)\n> >>>> +{\n> >>>> +\tstruct media_link *link;\n> >>>> +\n> >>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n> >>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n> >>>> +\t\treturn -EINVAL;\n> >>>> +\n> >>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n> >>>\n> >>> Is there a guarantee at this point that notifier->sd->entity has already\n> >>> been registered with the media_device ? That's done by\n> >>> media_device_register_entity() called from\n> >>> v4l2_device_register_subdev().\n> >>\n> >> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n> >> point that I've added the call to v4l2_async_try_create_links(), so I\n> >> think that's covered there.\n> >\n> > It calls it on sd, not notifier->sd. It's the latter that concerns me.\n> \n> Ah, you're right of course...I guess in that case the notifier->sd would\n> get registered during the v4l2_async_match_notify() where the sensor\n> driver's subdev is sd, but I don't think there's any guarantee that that\n> would happen first...I haven't traced it through but my guess is that it\n> would depend on the order in which the ipu3-cio2, sensor and lens\n> controller drivers probed. I'll check to try and be sure how it works\n> tomorrow\n\nI was looking at media_device_register_entity(), and it sets\n\n\tINIT_LIST_HEAD(&entity->links);\n\tentity->num_links = 0;\n\tentity->num_backlinks = 0;\n\nIf we create links before that, things may go bad.\n\n> >>>> +\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n> >>>> +\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n> >>>> +\n> >>>> +\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n> >>>> +}\n> >>>> +\n> >>>> +/*\n> >>>> + * Setup links on behalf of the notifier and subdev, where it's obvious what\n> >>>\n> >>> s/Setup/Create/ (\"link setup\" refers to another operation, enabling and\n> >>> disabling links at runtime)\n> >>\n> >> Yes, good point; although that too is a piece of terminology I find a\n> >> bit jarring to be honest; I would have named that function\n> >> media_entity_configure_link()\n> >>\n> >>>> + * should be done. At the moment, we only support cases where the notifier\n> >>>> + * is a sensor and the subdev is a lens.\n> >>>\n> >>> s/sensor/camera sensor/\n> >>> s/lens/lens controller/\n> >>>\n> >>>> + *\n> >>>> + * TODO: Setup pad links if the notifier's function is MEDIA_ENT_F_VID_IF_BRIDGE\n> >>>> + * and the subdev's is MEDIA_ENT_F_CAM_SENSOR\n> >>>> + */\n> >>>> +static int v4l2_async_try_create_links(struct v4l2_async_notifier *notifier,\n> >>>> +\t\t\t\t       struct v4l2_subdev *sd)\n> >>>> +{\n> >>>> +\tif (!notifier->sd)\n> >>>> +\t\treturn 0;\n> >>>> +\n> >>>> +\tswitch (notifier->sd->entity.function) {\n> >>>> +\tcase MEDIA_ENT_F_CAM_SENSOR:\n> >>>> +\t\treturn __v4l2_async_create_ancillary_link(notifier, sd);\n> >>>> +\tdefault:\n> >>>> +\t\treturn 0;\n> >>>> +\t}\n> >>>> +}\n> >>>> +\n> >>>>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n> >>>>  \t\t\t\t   struct v4l2_device *v4l2_dev,\n> >>>>  \t\t\t\t   struct v4l2_subdev *sd,\n> >>>> @@ -293,6 +332,18 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n> >>>>  \t\treturn ret;\n> >>>>  \t}\n> >>>>  \n> >>>> +\t/*\n> >>>> +\t * Depending of the function of the entities involved, we may want to\n> >>>> +\t * create links between them (for example between a sensor and its lens\n> >>>> +\t * or between a sensor's source pad and the connected device's sink\n> >>>> +\t * pad)\n> >>>\n> >>> s/)/)./\n> >>>\n> >>>> +\t */\n> >>>> +\tret = v4l2_async_try_create_links(notifier, sd);\n> >>>> +\tif (ret) {\n> >>>> +\t\tv4l2_device_unregister_subdev(sd);\n> >>>> +\t\treturn ret;\n> >>>> +\t}\n> >>>> +\n> >>>>  \t/* Remove from the waiting list */\n> >>>>  \tlist_del(&asd->list);\n> >>>>  \tsd->asd = asd;","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 7ABF3BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Dec 2021 09:04:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A842D608A4;\n\tWed, 15 Dec 2021 10:04:48 +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 D69A960114\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Dec 2021 10:04:47 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D5D2292;\n\tWed, 15 Dec 2021 10:04:47 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"L2hZD3bv\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1639559087;\n\tbh=5mui19vUSsh1aYFIGuLJ08ropHVGPHwxWvnOyrEqnUc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L2hZD3bvkk8NlGj+Cz9k4OD+DcERszTP+NujUjHJmf+SWd3GhIgjifG161hCH/pGs\n\td10zG5Qho/GLHI17DwD3GdCRTV13oIg0nYJ/jhM8lDl9gog2CH0oqv3J7Jy1r2XceZ\n\tBME/mnCcGXgbQE6L+YdY3hx1o9kqYUlm755c6agg=","Date":"Wed, 15 Dec 2021 11:04:44 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>\n\t<35553048-f338-8650-027f-708cfaac030d@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<35553048-f338-8650-027f-708cfaac030d@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, sakari.ailus@linux.intel.com,\n\tlinux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21797,"web_url":"https://patchwork.libcamera.org/comment/21797/","msgid":"<Ybm4/Ulnw5VwSOSk@paasikivi.fi.intel.com>","date":"2021-12-15T09:44:29","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":37,"url":"https://patchwork.libcamera.org/api/people/37/","name":"Sakari Ailus","email":"sakari.ailus@linux.intel.com"},"content":"On Wed, Dec 15, 2021 at 11:04:44AM +0200, Laurent Pinchart wrote:\n> Hi Dan,\n> \n> On Tue, Dec 14, 2021 at 11:41:27PM +0000, Daniel Scally wrote:\n> > On 14/12/2021 23:01, Laurent Pinchart wrote:\n> > > On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n> > >> On 14/12/2021 22:22, Laurent Pinchart wrote:\n> > >>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n> > >>>> Upon an async fwnode match, there's some typical behaviour that the\n> > >>>> notifier and matching subdev will want to do. For example, a notifier\n> > >>>> representing a sensor matching to an async subdev representing its\n> > >>>> VCM will want to create an ancillary link to expose that relationship\n> > >>>> to userspace.\n> > >>>>\n> > >>>> To avoid lots of code in individual drivers, try to build these links\n> > >>>> within v4l2 core.\n> > >>>>\n> > >>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n> > >>>> ---\n> > >>>> Changes since the rfc:\n> > >>>>\n> > >>>> \t- None\n> > >>>>\n> > >>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n> > >>>>  1 file changed, 51 insertions(+)\n> > >>>>\n> > >>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n> > >>>> index 0404267f1ae4..6575b1cbe95f 100644\n> > >>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n> > >>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n> > >>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n> > >>>>  static int\n> > >>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n> > >>>>  \n> > >>>> +static int\n> > >>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n> > >>>> +\t\t\t\t   struct v4l2_subdev *sd)\n> > >>>> +{\n> > >>>> +\tstruct media_link *link;\n> > >>>> +\n> > >>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n> > >>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n> > >>>> +\t\treturn -EINVAL;\n> > >>>> +\n> > >>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n> > >>>\n> > >>> Is there a guarantee at this point that notifier->sd->entity has already\n> > >>> been registered with the media_device ? That's done by\n> > >>> media_device_register_entity() called from\n> > >>> v4l2_device_register_subdev().\n> > >>\n> > >> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n> > >> point that I've added the call to v4l2_async_try_create_links(), so I\n> > >> think that's covered there.\n> > >\n> > > It calls it on sd, not notifier->sd. It's the latter that concerns me.\n> > \n> > Ah, you're right of course...I guess in that case the notifier->sd would\n> > get registered during the v4l2_async_match_notify() where the sensor\n> > driver's subdev is sd, but I don't think there's any guarantee that that\n> > would happen first...I haven't traced it through but my guess is that it\n> > would depend on the order in which the ipu3-cio2, sensor and lens\n> > controller drivers probed. I'll check to try and be sure how it works\n> > tomorrow\n> \n> I was looking at media_device_register_entity(), and it sets\n> \n> \tINIT_LIST_HEAD(&entity->links);\n> \tentity->num_links = 0;\n> \tentity->num_backlinks = 0;\n> \n> If we create links before that, things may go bad.\n\nYes.\n\nThere's a guarantee that the notifier's complete callback is called once\nthe notifier's subdevs as well as sub-notifiers are bound and complete. But\nthere's no guarantee on the initialisation of related entities.\n\nEspecially for sensors, the async subdev is registered after the sensor's\nown async notifier.\n\nI wonder if the ugly registered callback could be used for this purpose.\nBetter of course would be to avoid that.","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 E2B64BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Dec 2021 09:44:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 37F27608A4;\n\tWed, 15 Dec 2021 10:44:39 +0100 (CET)","from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F4DF60114\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Dec 2021 10:44:36 +0100 (CET)","from fmsmga007.fm.intel.com ([10.253.24.52])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; \n\t15 Dec 2021 01:44:33 -0800","from paasikivi.fi.intel.com ([10.237.72.42])\n\tby fmsmga007-auth.fm.intel.com with\n\tESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2021 01:44:31 -0800","from paasikivi.fi.intel.com (localhost [127.0.0.1])\n\tby paasikivi.fi.intel.com (Postfix) with SMTP id 3538C20462;\n\tWed, 15 Dec 2021 11:44:29 +0200 (EET)"],"X-IronPort-AV":["E=McAfee;i=\"6200,9189,10198\"; a=\"219205820\"","E=Sophos;i=\"5.88,207,1635231600\"; d=\"scan'208\";a=\"219205820\"","E=Sophos;i=\"5.88,207,1635231600\"; d=\"scan'208\";a=\"519672479\""],"Date":"Wed, 15 Dec 2021 11:44:29 +0200","From":"Sakari Ailus <sakari.ailus@linux.intel.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<Ybm4/Ulnw5VwSOSk@paasikivi.fi.intel.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>\n\t<35553048-f338-8650-027f-708cfaac030d@gmail.com>\n\t<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, linux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21799,"web_url":"https://patchwork.libcamera.org/comment/21799/","msgid":"<Ybm7dR81LjKQycSB@pendragon.ideasonboard.com>","date":"2021-12-15T09:55:01","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Sakari,\n\nOn Wed, Dec 15, 2021 at 11:44:29AM +0200, Sakari Ailus wrote:\n> On Wed, Dec 15, 2021 at 11:04:44AM +0200, Laurent Pinchart wrote:\n> > On Tue, Dec 14, 2021 at 11:41:27PM +0000, Daniel Scally wrote:\n> > > On 14/12/2021 23:01, Laurent Pinchart wrote:\n> > > > On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n> > > >> On 14/12/2021 22:22, Laurent Pinchart wrote:\n> > > >>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n> > > >>>> Upon an async fwnode match, there's some typical behaviour that the\n> > > >>>> notifier and matching subdev will want to do. For example, a notifier\n> > > >>>> representing a sensor matching to an async subdev representing its\n> > > >>>> VCM will want to create an ancillary link to expose that relationship\n> > > >>>> to userspace.\n> > > >>>>\n> > > >>>> To avoid lots of code in individual drivers, try to build these links\n> > > >>>> within v4l2 core.\n> > > >>>>\n> > > >>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n> > > >>>> ---\n> > > >>>> Changes since the rfc:\n> > > >>>>\n> > > >>>> \t- None\n> > > >>>>\n> > > >>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n> > > >>>>  1 file changed, 51 insertions(+)\n> > > >>>>\n> > > >>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n> > > >>>> index 0404267f1ae4..6575b1cbe95f 100644\n> > > >>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n> > > >>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n> > > >>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n> > > >>>>  static int\n> > > >>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n> > > >>>>  \n> > > >>>> +static int\n> > > >>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n> > > >>>> +\t\t\t\t   struct v4l2_subdev *sd)\n> > > >>>> +{\n> > > >>>> +\tstruct media_link *link;\n> > > >>>> +\n> > > >>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n> > > >>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n> > > >>>> +\t\treturn -EINVAL;\n> > > >>>> +\n> > > >>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n> > > >>>\n> > > >>> Is there a guarantee at this point that notifier->sd->entity has already\n> > > >>> been registered with the media_device ? That's done by\n> > > >>> media_device_register_entity() called from\n> > > >>> v4l2_device_register_subdev().\n> > > >>\n> > > >> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n> > > >> point that I've added the call to v4l2_async_try_create_links(), so I\n> > > >> think that's covered there.\n> > > >\n> > > > It calls it on sd, not notifier->sd. It's the latter that concerns me.\n> > > \n> > > Ah, you're right of course...I guess in that case the notifier->sd would\n> > > get registered during the v4l2_async_match_notify() where the sensor\n> > > driver's subdev is sd, but I don't think there's any guarantee that that\n> > > would happen first...I haven't traced it through but my guess is that it\n> > > would depend on the order in which the ipu3-cio2, sensor and lens\n> > > controller drivers probed. I'll check to try and be sure how it works\n> > > tomorrow\n> > \n> > I was looking at media_device_register_entity(), and it sets\n> > \n> > \tINIT_LIST_HEAD(&entity->links);\n> > \tentity->num_links = 0;\n> > \tentity->num_backlinks = 0;\n> > \n> > If we create links before that, things may go bad.\n> \n> Yes.\n> \n> There's a guarantee that the notifier's complete callback is called once\n> the notifier's subdevs as well as sub-notifiers are bound and complete. But\n> there's no guarantee on the initialisation of related entities.\n> \n> Especially for sensors, the async subdev is registered after the sensor's\n> own async notifier.\n> \n> I wonder if the ugly registered callback could be used for this purpose.\n> Better of course would be to avoid that.\n\nI'd really like all these links to be created automatically by the code,\nbut given the very loosely defined rules regarding entity\ninitialization, I'm worried this may not be possible without quite a bit\nof cleanup first :-(\n\nIt looks like quite a bit of the work done in\nmedia_device_register_entity() could (and likely should) be moved to\nmedia_entity_init(), but I'm not sure if that would be enough to\nproperly fix the issue.","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 14B47BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Dec 2021 09:55:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5ED30608A4;\n\tWed, 15 Dec 2021 10:55:08 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C6BA60114\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Dec 2021 10:55:04 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EA624292;\n\tWed, 15 Dec 2021 10:55:03 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ndR4yvM5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1639562104;\n\tbh=Owpkw8ItCbtZtIQsPjnaUibtqD5JmFO9ijjqHGgWJjE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ndR4yvM5OUyVIk3iJFFt7jvcqLF/BvNz10vY0C3CDF47uWCxDhV5quwMoN4nI1WXm\n\tCIvGRy8JKoLW+nghM5Rteh5+QgoegtklAhJdC6GHOdWREtrPUbx8igEZzQ8fAEthxJ\n\t03FIHtngc1Mb1bHxljGWEmqk/BTxmzf1kTtbM60Y=","Date":"Wed, 15 Dec 2021 11:55:01 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Sakari Ailus <sakari.ailus@linux.intel.com>","Message-ID":"<Ybm7dR81LjKQycSB@pendragon.ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>\n\t<35553048-f338-8650-027f-708cfaac030d@gmail.com>\n\t<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>\n\t<Ybm4/Ulnw5VwSOSk@paasikivi.fi.intel.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<Ybm4/Ulnw5VwSOSk@paasikivi.fi.intel.com>","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, linux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21802,"web_url":"https://patchwork.libcamera.org/comment/21802/","msgid":"<88932b3f-a0ca-acdb-a3b7-0894c7fdfbc5@gmail.com>","date":"2021-12-15T23:10:09","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":90,"url":"https://patchwork.libcamera.org/api/people/90/","name":"Daniel Scally","email":"djrscally@gmail.com"},"content":"Hi Laurent, Sakari\n\nOn 15/12/2021 09:55, Laurent Pinchart wrote:\n> Hi Sakari,\n> \n> On Wed, Dec 15, 2021 at 11:44:29AM +0200, Sakari Ailus wrote:\n>> On Wed, Dec 15, 2021 at 11:04:44AM +0200, Laurent Pinchart wrote:\n>>> On Tue, Dec 14, 2021 at 11:41:27PM +0000, Daniel Scally wrote:\n>>>> On 14/12/2021 23:01, Laurent Pinchart wrote:\n>>>>> On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n>>>>>> On 14/12/2021 22:22, Laurent Pinchart wrote:\n>>>>>>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n>>>>>>>> Upon an async fwnode match, there's some typical behaviour that the\n>>>>>>>> notifier and matching subdev will want to do. For example, a notifier\n>>>>>>>> representing a sensor matching to an async subdev representing its\n>>>>>>>> VCM will want to create an ancillary link to expose that relationship\n>>>>>>>> to userspace.\n>>>>>>>>\n>>>>>>>> To avoid lots of code in individual drivers, try to build these links\n>>>>>>>> within v4l2 core.\n>>>>>>>>\n>>>>>>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n>>>>>>>> ---\n>>>>>>>> Changes since the rfc:\n>>>>>>>>\n>>>>>>>> \t- None\n>>>>>>>>\n>>>>>>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n>>>>>>>>  1 file changed, 51 insertions(+)\n>>>>>>>>\n>>>>>>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n>>>>>>>> index 0404267f1ae4..6575b1cbe95f 100644\n>>>>>>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n>>>>>>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n>>>>>>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n>>>>>>>>  static int\n>>>>>>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n>>>>>>>>  \n>>>>>>>> +static int\n>>>>>>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n>>>>>>>> +\t\t\t\t   struct v4l2_subdev *sd)\n>>>>>>>> +{\n>>>>>>>> +\tstruct media_link *link;\n>>>>>>>> +\n>>>>>>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n>>>>>>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n>>>>>>>> +\t\treturn -EINVAL;\n>>>>>>>> +\n>>>>>>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n>>>>>>>\n>>>>>>> Is there a guarantee at this point that notifier->sd->entity has already\n>>>>>>> been registered with the media_device ? That's done by\n>>>>>>> media_device_register_entity() called from\n>>>>>>> v4l2_device_register_subdev().\n>>>>>>\n>>>>>> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n>>>>>> point that I've added the call to v4l2_async_try_create_links(), so I\n>>>>>> think that's covered there.\n>>>>>\n>>>>> It calls it on sd, not notifier->sd. It's the latter that concerns me.\n>>>>\n>>>> Ah, you're right of course...I guess in that case the notifier->sd would\n>>>> get registered during the v4l2_async_match_notify() where the sensor\n>>>> driver's subdev is sd, but I don't think there's any guarantee that that\n>>>> would happen first...I haven't traced it through but my guess is that it\n>>>> would depend on the order in which the ipu3-cio2, sensor and lens\n>>>> controller drivers probed. I'll check to try and be sure how it works\n>>>> tomorrow\n>>>\n>>> I was looking at media_device_register_entity(), and it sets\n>>>\n>>> \tINIT_LIST_HEAD(&entity->links);\n>>> \tentity->num_links = 0;\n>>> \tentity->num_backlinks = 0;\n>>>\n>>> If we create links before that, things may go bad.\n\nYep, that definitely looks like it would make things go badly wrong. I'm\nbuilding with a delayed ov8865 probe now, let's see what happens...\n\n>>\n>> Yes.\n>>\n>> There's a guarantee that the notifier's complete callback is called once\n>> the notifier's subdevs as well as sub-notifiers are bound and complete. But\n>> there's no guarantee on the initialisation of related entities.\n>>\n>> Especially for sensors, the async subdev is registered after the sensor's\n>> own async notifier.\n>>\n>> I wonder if the ugly registered callback could be used for this purpose.\n>> Better of course would be to avoid that.\n> \n> I'd really like all these links to be created automatically by the code,\n> but given the very loosely defined rules regarding entity\n> initialization, I'm worried this may not be possible without quite a bit\n> of cleanup first :-(\n\n\nYeah. At present at least the primary entity would need to be linked to\nthe media dev, as it's taking primary->graph_obj.mdev as the pointer to\nuse in media_gobj_create() in media_create_ancillary_link(). That's a\npretty big problem actually...but I'd really like to try and solve it as\nwe could cut a lot of code out the other drivers if we do the same thing\nfor the data links.\n\nOne way around it might be to defer matching in v4l2_async_find_match()\nif the notifier's subdev hasn't picked up an mdev itself yet...which\ncould guarantee the ordering but sort of breaks the asynchronicity of it\nall. I'm almost certainly missing some other reason that that's a\nterrible idea too.\n\nI'll try and explore some ways to do this that still keeps the link\nsetup within core - thanks for pointing it out Laurent\n\n> It looks like quite a bit of the work done in\n> media_device_register_entity() could (and likely should) be moved to\n> media_entity_init(), but I'm not sure if that would be enough to\n> properly fix the issue.\n\nI guess you mean media_entity_pads_init()? Or media_device_init()?\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 2FE49BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Dec 2021 23:10:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D03D60894;\n\tThu, 16 Dec 2021 00:10:14 +0100 (CET)","from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\n\t[IPv6:2a00:1450:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ABFAB60117\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Dec 2021 00:10:11 +0100 (CET)","by mail-wr1-x42e.google.com with SMTP id s1so6687030wrg.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 15 Dec 2021 15:10:11 -0800 (PST)","from [192.168.0.16]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id\n\tk33sm67329wms.21.2021.12.15.15.10.10\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tWed, 15 Dec 2021 15:10:10 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"L13ywTWa\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=MKNd7uP+uhb0Oc8cbpGurc8hpaoIh9STeUavOpe6UaE=;\n\tb=L13ywTWaEOTpcQVOuir2dAG+AgTRTfo1c63AjXpg/0UR2FxIZU98S6E61PWQpN2vcE\n\tQtxcA8chQXFFhsGLWMrTYA/CogI9OefaGFqNYQqtgpnMfhfUjfpbv9Lz9jfzS4NTD6Mk\n\tV4Cpf83Zbf7weea7jeMiN/0HDfYof71balneUbEPscAOWsyJQbf/kQpvW1WvD+ni4iXm\n\tHYsnAOcK3UVC740gh+jY1y5ICwIPqNj3kqkZmBWzAoUhGSEb7oEwz8bNB29fS+XGl3rB\n\taXEB52h+i8N25y0I8juXCKV0i+xMiLxlfpazkdM4O2EVmE1CplM1PSQpHYR8fgznpzhK\n\tFBXQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=MKNd7uP+uhb0Oc8cbpGurc8hpaoIh9STeUavOpe6UaE=;\n\tb=wblgPG0ZNcNDmpddFjdWBsKN7IkFWeotQEQFiCKCfb/tYjSfmcdw6PMOMiDTtS7F+H\n\tcuygBhDsc8LxD0+TT5CSLC+q9v8ckuMAi2ygY7kPtzjKRORfe9x1zJIPDWx+v5kbR5Je\n\toJWcVst33kLGkUzRUQ5zMJZ4AhHgmlxsT1lS8IJHCR7prOripRue8O5itCqUafeduDVf\n\tIlBwNC/V3rVNFWjyRdhh+5EyLtnDEFT+Bclf5g4QTcLeEne3k7TW5EuDgioO21rngBfU\n\tLGUHoihvgtWxcbB9jpzZYXlys5lKW8IYpqyVx14Kiag7IHnSkAmg0i2w3FuAqLpvxa73\n\tzUSg==","X-Gm-Message-State":"AOAM531vg/FDQLAsnsEmQpciy6EJoS3irhmyvNZsLyD0q8UZjL/6BC4m\n\t8pRCw3D8LUy8aX/MBrpEcQU=","X-Google-Smtp-Source":"ABdhPJx8umOxyeNomiPo0xZ+dgfv03eiTvHc3TmyuX9q5jtZ1MFa9E+zlPFLTP1SKt6BJym1xgvefA==","X-Received":"by 2002:a5d:59af:: with SMTP id\n\tp15mr6167954wrr.493.1639609811202; \n\tWed, 15 Dec 2021 15:10:11 -0800 (PST)","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tSakari Ailus <sakari.ailus@linux.intel.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>\n\t<35553048-f338-8650-027f-708cfaac030d@gmail.com>\n\t<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>\n\t<Ybm4/Ulnw5VwSOSk@paasikivi.fi.intel.com>\n\t<Ybm7dR81LjKQycSB@pendragon.ideasonboard.com>","From":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<88932b3f-a0ca-acdb-a3b7-0894c7fdfbc5@gmail.com>","Date":"Wed, 15 Dec 2021 23:10:09 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.14.0","MIME-Version":"1.0","In-Reply-To":"<Ybm7dR81LjKQycSB@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, linux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21803,"web_url":"https://patchwork.libcamera.org/comment/21803/","msgid":"<Ybp23sKCVAINx8tm@pendragon.ideasonboard.com>","date":"2021-12-15T23:14:38","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Dan,\n\nOn Wed, Dec 15, 2021 at 11:10:09PM +0000, Daniel Scally wrote:\n> On 15/12/2021 09:55, Laurent Pinchart wrote:\n> > On Wed, Dec 15, 2021 at 11:44:29AM +0200, Sakari Ailus wrote:\n> >> On Wed, Dec 15, 2021 at 11:04:44AM +0200, Laurent Pinchart wrote:\n> >>> On Tue, Dec 14, 2021 at 11:41:27PM +0000, Daniel Scally wrote:\n> >>>> On 14/12/2021 23:01, Laurent Pinchart wrote:\n> >>>>> On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n> >>>>>> On 14/12/2021 22:22, Laurent Pinchart wrote:\n> >>>>>>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n> >>>>>>>> Upon an async fwnode match, there's some typical behaviour that the\n> >>>>>>>> notifier and matching subdev will want to do. For example, a notifier\n> >>>>>>>> representing a sensor matching to an async subdev representing its\n> >>>>>>>> VCM will want to create an ancillary link to expose that relationship\n> >>>>>>>> to userspace.\n> >>>>>>>>\n> >>>>>>>> To avoid lots of code in individual drivers, try to build these links\n> >>>>>>>> within v4l2 core.\n> >>>>>>>>\n> >>>>>>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n> >>>>>>>> ---\n> >>>>>>>> Changes since the rfc:\n> >>>>>>>>\n> >>>>>>>> \t- None\n> >>>>>>>>\n> >>>>>>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n> >>>>>>>>  1 file changed, 51 insertions(+)\n> >>>>>>>>\n> >>>>>>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n> >>>>>>>> index 0404267f1ae4..6575b1cbe95f 100644\n> >>>>>>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n> >>>>>>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n> >>>>>>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n> >>>>>>>>  static int\n> >>>>>>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n> >>>>>>>>  \n> >>>>>>>> +static int\n> >>>>>>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n> >>>>>>>> +\t\t\t\t   struct v4l2_subdev *sd)\n> >>>>>>>> +{\n> >>>>>>>> +\tstruct media_link *link;\n> >>>>>>>> +\n> >>>>>>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n> >>>>>>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n> >>>>>>>> +\t\treturn -EINVAL;\n> >>>>>>>> +\n> >>>>>>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n> >>>>>>>\n> >>>>>>> Is there a guarantee at this point that notifier->sd->entity has already\n> >>>>>>> been registered with the media_device ? That's done by\n> >>>>>>> media_device_register_entity() called from\n> >>>>>>> v4l2_device_register_subdev().\n> >>>>>>\n> >>>>>> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n> >>>>>> point that I've added the call to v4l2_async_try_create_links(), so I\n> >>>>>> think that's covered there.\n> >>>>>\n> >>>>> It calls it on sd, not notifier->sd. It's the latter that concerns me.\n> >>>>\n> >>>> Ah, you're right of course...I guess in that case the notifier->sd would\n> >>>> get registered during the v4l2_async_match_notify() where the sensor\n> >>>> driver's subdev is sd, but I don't think there's any guarantee that that\n> >>>> would happen first...I haven't traced it through but my guess is that it\n> >>>> would depend on the order in which the ipu3-cio2, sensor and lens\n> >>>> controller drivers probed. I'll check to try and be sure how it works\n> >>>> tomorrow\n> >>>\n> >>> I was looking at media_device_register_entity(), and it sets\n> >>>\n> >>> \tINIT_LIST_HEAD(&entity->links);\n> >>> \tentity->num_links = 0;\n> >>> \tentity->num_backlinks = 0;\n> >>>\n> >>> If we create links before that, things may go bad.\n> \n> Yep, that definitely looks like it would make things go badly wrong. I'm\n> building with a delayed ov8865 probe now, let's see what happens...\n> \n> >> Yes.\n> >>\n> >> There's a guarantee that the notifier's complete callback is called once\n> >> the notifier's subdevs as well as sub-notifiers are bound and complete. But\n> >> there's no guarantee on the initialisation of related entities.\n> >>\n> >> Especially for sensors, the async subdev is registered after the sensor's\n> >> own async notifier.\n> >>\n> >> I wonder if the ugly registered callback could be used for this purpose.\n> >> Better of course would be to avoid that.\n> > \n> > I'd really like all these links to be created automatically by the code,\n> > but given the very loosely defined rules regarding entity\n> > initialization, I'm worried this may not be possible without quite a bit\n> > of cleanup first :-(\n> \n> Yeah. At present at least the primary entity would need to be linked to\n> the media dev, as it's taking primary->graph_obj.mdev as the pointer to\n> use in media_gobj_create() in media_create_ancillary_link(). That's a\n> pretty big problem actually...but I'd really like to try and solve it as\n> we could cut a lot of code out the other drivers if we do the same thing\n> for the data links.\n> \n> One way around it might be to defer matching in v4l2_async_find_match()\n> if the notifier's subdev hasn't picked up an mdev itself yet...which\n> could guarantee the ordering but sort of breaks the asynchronicity of it\n> all. I'm almost certainly missing some other reason that that's a\n> terrible idea too.\n\nv4l2-async is a mess, that's the main reason why everybody is reluctant\nto touch it :-) On my long todo list is a task to rewrite it from\nscratch, with an API that wouldn't be V4L2-specific.\n\n> I'll try and explore some ways to do this that still keeps the link\n> setup within core - thanks for pointing it out Laurent\n> \n> > It looks like quite a bit of the work done in\n> > media_device_register_entity() could (and likely should) be moved to\n> > media_entity_init(), but I'm not sure if that would be enough to\n> > properly fix the issue.\n> \n> I guess you mean media_entity_pads_init()? Or media_device_init()?\n\nThe former, sorry.","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 D8E73BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 15 Dec 2021 23:14:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 40EA560894;\n\tThu, 16 Dec 2021 00:14:43 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 73B5C60117\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Dec 2021 00:14:41 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B933F3F6;\n\tThu, 16 Dec 2021 00:14:40 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"TQNdP04C\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1639610080;\n\tbh=rcMsNAX3Sh7cZNxJMooZzfFa/c7JbDoyDM7+o8i60/Q=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=TQNdP04C7OlUe8sm0UDqHMIv8Pf4bkKMzzDnNWeEakFoJyNbWbhT0pBFn4O2527IW\n\tULbdVihSkGQVnl5YpxdubFMHcnmj4E9Hw8igqIWMsaN/y/OHzrGnd7mQRk4i+TKlP/\n\tv5PuVkGZRCvn3HBjZ3XfQ/p1gjg2d+ZIgYgEZvBo=","Date":"Thu, 16 Dec 2021 01:14:38 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<Ybp23sKCVAINx8tm@pendragon.ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>\n\t<35553048-f338-8650-027f-708cfaac030d@gmail.com>\n\t<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>\n\t<Ybm4/Ulnw5VwSOSk@paasikivi.fi.intel.com>\n\t<Ybm7dR81LjKQycSB@pendragon.ideasonboard.com>\n\t<88932b3f-a0ca-acdb-a3b7-0894c7fdfbc5@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<88932b3f-a0ca-acdb-a3b7-0894c7fdfbc5@gmail.com>","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org,\n\tSakari Ailus <sakari.ailus@linux.intel.com>, linux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21805,"web_url":"https://patchwork.libcamera.org/comment/21805/","msgid":"<202112161906.gHHRLukN-lkp@intel.com>","date":"2021-12-16T11:10:17","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":45,"url":"https://patchwork.libcamera.org/api/people/45/","name":"kernel test robot","email":"lkp@intel.com"},"content":"Hi Daniel,\n\nI love your patch! Yet something to improve:\n\n[auto build test ERROR on media-tree/master]\n[also build test ERROR on v5.16-rc5 next-20211215]\n[If your patch is applied to the wrong git tree, kindly drop us a note.\nAnd when submitting patch, we suggest to use '--base' as documented in\nhttps://git-scm.com/docs/git-format-patch]\n\nurl:    https://github.com/0day-ci/linux/commits/Daniel-Scally/Introduce-ancillary-links/20211214-073020\nbase:   git://linuxtv.org/media_tree.git master\nconfig: x86_64-randconfig-r015-20211216 (https://download.01.org/0day-ci/archive/20211216/202112161906.gHHRLukN-lkp@intel.com/config)\ncompiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dd245bab9fbb364faa1581e4f92ba3119a872fba)\nreproduce (this is a W=1 build):\n        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross\n        chmod +x ~/bin/make.cross\n        # https://github.com/0day-ci/linux/commit/7e7fcd65e8144f3ffa337760c26fb786f4028466\n        git remote add linux-review https://github.com/0day-ci/linux\n        git fetch --no-tags linux-review Daniel-Scally/Introduce-ancillary-links/20211214-073020\n        git checkout 7e7fcd65e8144f3ffa337760c26fb786f4028466\n        # save the config file to linux build tree\n        mkdir build_dir\n        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/media/v4l2-core/\n\nIf you fix the issue, kindly add following tag as appropriate\nReported-by: kernel test robot <lkp@intel.com>\n\nAll errors (new ones prefixed by >>):\n\n>> drivers/media/v4l2-core/v4l2-async.c:284:10: error: no member named 'entity' in 'struct v4l2_subdev'\n           if (sd->entity.function != MEDIA_ENT_F_LENS &&\n               ~~  ^\n   drivers/media/v4l2-core/v4l2-async.c:285:10: error: no member named 'entity' in 'struct v4l2_subdev'\n               sd->entity.function != MEDIA_ENT_F_FLASH)\n               ~~  ^\n   drivers/media/v4l2-core/v4l2-async.c:288:52: error: no member named 'entity' in 'struct v4l2_subdev'\n           link = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n                                               ~~~~~~~~~~~~  ^\n   drivers/media/v4l2-core/v4l2-async.c:288:65: error: no member named 'entity' in 'struct v4l2_subdev'\n           link = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n                                                                      ~~  ^\n   drivers/media/v4l2-core/v4l2-async.c:309:24: error: no member named 'entity' in 'struct v4l2_subdev'\n           switch (notifier->sd->entity.function) {\n                   ~~~~~~~~~~~~  ^\n   5 errors generated.\n\n\nvim +284 drivers/media/v4l2-core/v4l2-async.c\n\n   277\t\n   278\tstatic int\n   279\t__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n   280\t\t\t\t\t   struct v4l2_subdev *sd)\n   281\t{\n   282\t\tstruct media_link *link;\n   283\t\n > 284\t\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n   285\t\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n   286\t\t\treturn -EINVAL;\n   287\t\n   288\t\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n   289\t\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n   290\t\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n   291\t\n   292\t\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n   293\t}\n   294\t\n\n---\n0-DAY CI Kernel Test Service, Intel Corporation\nhttps://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org","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 8BE60BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 16 Dec 2021 11:11:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CAE89608A4;\n\tThu, 16 Dec 2021 12:11:04 +0100 (CET)","from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F2A760868\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Dec 2021 12:11:02 +0100 (CET)","from fmsmga004.fm.intel.com ([10.253.24.48])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; \n\t16 Dec 2021 03:11:00 -0800","from lkp-server02.sh.intel.com (HELO 9f38c0981d9f)\n\t([10.239.97.151])\n\tby fmsmga004.fm.intel.com with ESMTP; 16 Dec 2021 03:10:57 -0800","from kbuild by 9f38c0981d9f with local (Exim 4.92)\n\t(envelope-from <lkp@intel.com>)\n\tid 1mxof3-00033S-4R; Thu, 16 Dec 2021 11:10:57 +0000"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=intel.com header.i=@intel.com\n\theader.b=\"nO9S0vio\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n\td=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n\tt=1639653063; x=1671189063;\n\th=date:from:to:cc:subject:message-id:references:\n\tmime-version:in-reply-to;\n\tbh=tLmQDIOY/nuxj81xa9HFBkghDkLFp+wjKf+/8rQrsx0=;\n\tb=nO9S0vioQvzaaa0FO72Y62yBSLDtXCR171DTfPee5ta1NRtXjl4Qx4Su\n\tSQDNAeF6sbr2EBuyxBQPdWU8/6dBAA7/aEUkuxfxqSOvTDZoMxjewgAhN\n\thJ/emPmM7S/74nSpbpYFnQxnNkyjNmLtUq6rQR43cYaGEPp8Ok6pjd6R0\n\t8edpkHnSc2XFeLbV18d5//iJOoVQDO2MEd2duTQZLUp2Kq3SB1sgNONh/\n\tC2XutJ/Y4/oTBPnTn7glvL1kD9lKZXyuU3nm8zCKOQ+JO07/hVeBAw0w3\n\tYyWitbsYNCNycuqe5WM/TEMMDsNNsnzWWYUX4sxRi04uZjOESQwtMkrge Q==;","X-IronPort-AV":["E=McAfee;i=\"6200,9189,10199\"; a=\"219477333\"","E=Sophos;i=\"5.88,211,1635231600\"; d=\"scan'208\";a=\"219477333\"","E=Sophos;i=\"5.88,211,1635231600\"; d=\"scan'208\";a=\"584811970\""],"X-ExtLoop1":"1","Date":"Thu, 16 Dec 2021 19:10:17 +0800","From":"kernel test robot <lkp@intel.com>","To":"Daniel Scally <djrscally@gmail.com>, linux-media@vger.kernel.org,\n\tlibcamera-devel@lists.libcamera.org","Message-ID":"<202112161906.gHHRLukN-lkp@intel.com>","References":"<20211213232849.40071-6-djrscally@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20211213232849.40071-6-djrscally@gmail.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"kbuild-all@lists.01.org, llvm@lists.linux.dev,\n\tsakari.ailus@linux.intel.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":21806,"web_url":"https://patchwork.libcamera.org/comment/21806/","msgid":"<2808edaf-f397-fa23-de67-1022ddb8f447@gmail.com>","date":"2021-12-16T11:14:36","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":90,"url":"https://patchwork.libcamera.org/api/people/90/","name":"Daniel Scally","email":"djrscally@gmail.com"},"content":"I guess this needs to be a no-op if the media controller API isn't\nconfigured.\n\nOn 16/12/2021 11:10, kernel test robot wrote:\n> Hi Daniel,\n>\n> I love your patch! Yet something to improve:\n>\n> [auto build test ERROR on media-tree/master]\n> [also build test ERROR on v5.16-rc5 next-20211215]\n> [If your patch is applied to the wrong git tree, kindly drop us a note.\n> And when submitting patch, we suggest to use '--base' as documented in\n> https://git-scm.com/docs/git-format-patch]\n>\n> url:    https://github.com/0day-ci/linux/commits/Daniel-Scally/Introduce-ancillary-links/20211214-073020\n> base:   git://linuxtv.org/media_tree.git master\n> config: x86_64-randconfig-r015-20211216 (https://download.01.org/0day-ci/archive/20211216/202112161906.gHHRLukN-lkp@intel.com/config)\n> compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dd245bab9fbb364faa1581e4f92ba3119a872fba)\n> reproduce (this is a W=1 build):\n>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross\n>         chmod +x ~/bin/make.cross\n>         # https://github.com/0day-ci/linux/commit/7e7fcd65e8144f3ffa337760c26fb786f4028466\n>         git remote add linux-review https://github.com/0day-ci/linux\n>         git fetch --no-tags linux-review Daniel-Scally/Introduce-ancillary-links/20211214-073020\n>         git checkout 7e7fcd65e8144f3ffa337760c26fb786f4028466\n>         # save the config file to linux build tree\n>         mkdir build_dir\n>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/media/v4l2-core/\n>\n> If you fix the issue, kindly add following tag as appropriate\n> Reported-by: kernel test robot <lkp@intel.com>\n>\n> All errors (new ones prefixed by >>):\n>\n>>> drivers/media/v4l2-core/v4l2-async.c:284:10: error: no member named 'entity' in 'struct v4l2_subdev'\n>            if (sd->entity.function != MEDIA_ENT_F_LENS &&\n>                ~~  ^\n>    drivers/media/v4l2-core/v4l2-async.c:285:10: error: no member named 'entity' in 'struct v4l2_subdev'\n>                sd->entity.function != MEDIA_ENT_F_FLASH)\n>                ~~  ^\n>    drivers/media/v4l2-core/v4l2-async.c:288:52: error: no member named 'entity' in 'struct v4l2_subdev'\n>            link = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n>                                                ~~~~~~~~~~~~  ^\n>    drivers/media/v4l2-core/v4l2-async.c:288:65: error: no member named 'entity' in 'struct v4l2_subdev'\n>            link = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n>                                                                       ~~  ^\n>    drivers/media/v4l2-core/v4l2-async.c:309:24: error: no member named 'entity' in 'struct v4l2_subdev'\n>            switch (notifier->sd->entity.function) {\n>                    ~~~~~~~~~~~~  ^\n>    5 errors generated.\n>\n>\n> vim +284 drivers/media/v4l2-core/v4l2-async.c\n>\n>    277\t\n>    278\tstatic int\n>    279\t__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n>    280\t\t\t\t\t   struct v4l2_subdev *sd)\n>    281\t{\n>    282\t\tstruct media_link *link;\n>    283\t\n>  > 284\t\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n>    285\t\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n>    286\t\t\treturn -EINVAL;\n>    287\t\n>    288\t\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n>    289\t\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n>    290\t\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n>    291\t\n>    292\t\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n>    293\t}\n>    294\t\n>\n> ---\n> 0-DAY CI Kernel Test Service, Intel Corporation\n> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org","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 4AE94BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 16 Dec 2021 11:14:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7D74C608A4;\n\tThu, 16 Dec 2021 12:14:39 +0100 (CET)","from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D2E3B60868\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Dec 2021 12:14:37 +0100 (CET)","by mail-wm1-x32e.google.com with SMTP id p18so18647770wmq.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Dec 2021 03:14:37 -0800 (PST)","from [192.168.0.14]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id\n\tr17sm4399204wmq.11.2021.12.16.03.14.36\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tThu, 16 Dec 2021 03:14:37 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"Q/sYXNrz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-transfer-encoding:content-language; \n\tbh=R2P5SbvHWGoTsxNtYXEi10Ks7r/T0PX45WZ+b50xuqA=;\n\tb=Q/sYXNrzRzCd+QDMU83vvuw4wRd0FhYaDpOYmxQZSeEoTCIBk9p1j7QVYJMAOJdzDW\n\t8axAPZcvaFqlBaA9cQ6QNCiEBKNpLpyoG/kKtyHvyeylFrNq4IVsUO2+Lr+QcD2kGNm8\n\ttilfwdMpsJ4inn7+TxZ9Dybc9OUMw41ACVDx7Fhx+rci56hLosZsyHfYDko+twr4ySdm\n\t0L6R8rCyXHQPulnNCOq5XmeNiH0uh1Hx7vsRetOely3J1CfBaRRAtcI0m3WQdas5BXhi\n\tkAP24UP1OPzZhlkusStpA56XeDgevy61wpyOLLuXB43qWaX4oGmaAGcGcdyp+/moW3ks\n\trkPg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-transfer-encoding\n\t:content-language;\n\tbh=R2P5SbvHWGoTsxNtYXEi10Ks7r/T0PX45WZ+b50xuqA=;\n\tb=CTtixY1RNx3588CaeN2SDW7zHMtZKBOix0zl2JQSt1ZOIz5UxXByqX0fh1p3o9kwyp\n\txTriMzaeZfLCuWAQpHXchTgB1vHdhJ8GCY2GHCPJ3gkHGH0jRE8jOcw6BGzJLnP2BKbz\n\t14RtCA/eVLh2ATXxjfcuCrYddhQZZBz4HtQjZZzPz6Q0sCi+RD9Qeu5tc3uKQk5Wy3tn\n\tAfl1kbqFWtgXwg4vzs0MgQnoJwz/tKsfUt04V5R1R94bQlGMa0dn1QSKqk+BN8C+VZCM\n\t27sVngJ2VTP0CJYHL7d57RSHl27n4QePjIPLOj11AYI0wh82ZfP+qRAtMfb0Td3yym+r\n\tFDbA==","X-Gm-Message-State":"AOAM532EkUsdSg9p471+cT2JWh3KdYsxbSgk0XaIfShhhYyV4QS9ICMi\n\t7YWDAGqcIL9wHWm8OTJOD/c=","X-Google-Smtp-Source":"ABdhPJyNqwmvRxxXHOZ8zm2W6GRQWF01Og1R4QWBD4C+kwLKdsrJzmOCw0W2JnQiFJ9CMmtzKzxqww==","X-Received":"by 2002:a05:600c:3787:: with SMTP id\n\to7mr4511708wmr.110.1639653277522; \n\tThu, 16 Dec 2021 03:14:37 -0800 (PST)","To":"kernel test robot <lkp@intel.com>, linux-media@vger.kernel.org,\n\tlibcamera-devel@lists.libcamera.org","References":"<20211213232849.40071-6-djrscally@gmail.com>\n\t<202112161906.gHHRLukN-lkp@intel.com>","From":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<2808edaf-f397-fa23-de67-1022ddb8f447@gmail.com>","Date":"Thu, 16 Dec 2021 11:14:36 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.14.0","MIME-Version":"1.0","In-Reply-To":"<202112161906.gHHRLukN-lkp@intel.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"kbuild-all@lists.01.org, llvm@lists.linux.dev,\n\tsakari.ailus@linux.intel.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":22037,"web_url":"https://patchwork.libcamera.org/comment/22037/","msgid":"<9487f650-370f-7cd5-af93-4af7f8afed2c@gmail.com>","date":"2022-01-16T00:01:47","subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","submitter":{"id":90,"url":"https://patchwork.libcamera.org/api/people/90/","name":"Daniel Scally","email":"djrscally@gmail.com"},"content":"Hi Laurent\n\nOn 15/12/2021 09:04, Laurent Pinchart wrote:\n\nA month to the day! Sorry about the delay - more on that below...\n\n> Hi Dan,\n>\n> On Tue, Dec 14, 2021 at 11:41:27PM +0000, Daniel Scally wrote:\n>> On 14/12/2021 23:01, Laurent Pinchart wrote:\n>>> On Tue, Dec 14, 2021 at 10:36:01PM +0000, Daniel Scally wrote:\n>>>> On 14/12/2021 22:22, Laurent Pinchart wrote:\n>>>>> On Mon, Dec 13, 2021 at 11:28:49PM +0000, Daniel Scally wrote:\n>>>>>> Upon an async fwnode match, there's some typical behaviour that the\n>>>>>> notifier and matching subdev will want to do. For example, a notifier\n>>>>>> representing a sensor matching to an async subdev representing its\n>>>>>> VCM will want to create an ancillary link to expose that relationship\n>>>>>> to userspace.\n>>>>>>\n>>>>>> To avoid lots of code in individual drivers, try to build these links\n>>>>>> within v4l2 core.\n>>>>>>\n>>>>>> Signed-off-by: Daniel Scally <djrscally@gmail.com>\n>>>>>> ---\n>>>>>> Changes since the rfc:\n>>>>>>\n>>>>>> \t- None\n>>>>>>\n>>>>>>  drivers/media/v4l2-core/v4l2-async.c | 51 ++++++++++++++++++++++++++++\n>>>>>>  1 file changed, 51 insertions(+)\n>>>>>>\n>>>>>> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c\n>>>>>> index 0404267f1ae4..6575b1cbe95f 100644\n>>>>>> --- a/drivers/media/v4l2-core/v4l2-async.c\n>>>>>> +++ b/drivers/media/v4l2-core/v4l2-async.c\n>>>>>> @@ -275,6 +275,45 @@ v4l2_async_nf_try_complete(struct v4l2_async_notifier *notifier)\n>>>>>>  static int\n>>>>>>  v4l2_async_nf_try_all_subdevs(struct v4l2_async_notifier *notifier);\n>>>>>>  \n>>>>>> +static int\n>>>>>> +__v4l2_async_create_ancillary_link(struct v4l2_async_notifier *notifier,\n>>>>>> +\t\t\t\t   struct v4l2_subdev *sd)\n>>>>>> +{\n>>>>>> +\tstruct media_link *link;\n>>>>>> +\n>>>>>> +\tif (sd->entity.function != MEDIA_ENT_F_LENS &&\n>>>>>> +\t    sd->entity.function != MEDIA_ENT_F_FLASH)\n>>>>>> +\t\treturn -EINVAL;\n>>>>>> +\n>>>>>> +\tlink = media_create_ancillary_link(&notifier->sd->entity, &sd->entity,\n>>>>> Is there a guarantee at this point that notifier->sd->entity has already\n>>>>> been registered with the media_device ? That's done by\n>>>>> media_device_register_entity() called from\n>>>>> v4l2_device_register_subdev().\n>>>> v4l2_async_match_notify() calls v4l2_device_register_subdev() before the\n>>>> point that I've added the call to v4l2_async_try_create_links(), so I\n>>>> think that's covered there.\n>>> It calls it on sd, not notifier->sd. It's the latter that concerns me.\n>> Ah, you're right of course...I guess in that case the notifier->sd would\n>> get registered during the v4l2_async_match_notify() where the sensor\n>> driver's subdev is sd, but I don't think there's any guarantee that that\n>> would happen first...I haven't traced it through but my guess is that it\n>> would depend on the order in which the ipu3-cio2, sensor and lens\n>> controller drivers probed. I'll check to try and be sure how it works\n>> tomorrow\n> I was looking at media_device_register_entity(), and it sets\n>\n> \tINIT_LIST_HEAD(&entity->links);\n> \tentity->num_links = 0;\n> \tentity->num_backlinks = 0;\n>\n> If we create links before that, things may go bad.\n\n\nIt looks like there _is_ a guarantee of ordering actually. When the\nov8865's notifier is registered in v4l2_async_register_subdev_sensor(),\nv4l2_async_nf_try_all_subdevs() is called against it, but at that point\nv4l2_async_nf_find_v4l2_dev() won't find anything for the ov8865's\nnotifier even if the dw9719 has already probed and has it's async_subdev\nwaiting because the notifier has no parent and no directly assigned\nv4l2_dev, so the function exits before trying to match anything (this\nsame logic guards all calls to v4l2_async_find_match()). Very shortly\nafter that v4l2_async_register_subdev() is called for the ov8865's\nsubdev which will match to ipu3-cio2's notifier. In\nv4l2_async_match_notify() for that match the ipu3-cio2's notifier is\nassigned as parent to the ov8865's notifier, but _after_\nv4l2_device_register_subdev() is called for the ov8865. From that point\non v4l2_async_nf_find_v4l2_dev() will return a pointer and the matching\nfor the dw9719 will work correctly. So unless I've missed something, I\nthink it's ok.\n\nThis took me a long time to figure out, because I reset libcamera to\nmaster for some reason and then totally forgot that I had done\nthat...which meant the auto-focus wasn't working when I tested it and I\nconvinced myself that my deliberate screwing of the probe ordering _did_\nbreak it. After tearing my hair out for an embarrassing amount of time I\neventually figured out what I had done and got to the bottom of it -\nsorry for the delay!\n\n>\n>>>>>> +\t\t\t\t\t   MEDIA_LNK_FL_ENABLED |\n>>>>>> +\t\t\t\t\t   MEDIA_LNK_FL_IMMUTABLE);\n>>>>>> +\n>>>>>> +\treturn IS_ERR(link) ? PTR_ERR(link) : 0;\n>>>>>> +}\n>>>>>> +\n>>>>>> +/*\n>>>>>> + * Setup links on behalf of the notifier and subdev, where it's obvious what\n>>>>> s/Setup/Create/ (\"link setup\" refers to another operation, enabling and\n>>>>> disabling links at runtime)\n>>>> Yes, good point; although that too is a piece of terminology I find a\n>>>> bit jarring to be honest; I would have named that function\n>>>> media_entity_configure_link()\n>>>>\n>>>>>> + * should be done. At the moment, we only support cases where the notifier\n>>>>>> + * is a sensor and the subdev is a lens.\n>>>>> s/sensor/camera sensor/\n>>>>> s/lens/lens controller/\n>>>>>\n>>>>>> + *\n>>>>>> + * TODO: Setup pad links if the notifier's function is MEDIA_ENT_F_VID_IF_BRIDGE\n>>>>>> + * and the subdev's is MEDIA_ENT_F_CAM_SENSOR\n>>>>>> + */\n>>>>>> +static int v4l2_async_try_create_links(struct v4l2_async_notifier *notifier,\n>>>>>> +\t\t\t\t       struct v4l2_subdev *sd)\n>>>>>> +{\n>>>>>> +\tif (!notifier->sd)\n>>>>>> +\t\treturn 0;\n>>>>>> +\n>>>>>> +\tswitch (notifier->sd->entity.function) {\n>>>>>> +\tcase MEDIA_ENT_F_CAM_SENSOR:\n>>>>>> +\t\treturn __v4l2_async_create_ancillary_link(notifier, sd);\n>>>>>> +\tdefault:\n>>>>>> +\t\treturn 0;\n>>>>>> +\t}\n>>>>>> +}\n>>>>>> +\n>>>>>>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>>>>>>  \t\t\t\t   struct v4l2_device *v4l2_dev,\n>>>>>>  \t\t\t\t   struct v4l2_subdev *sd,\n>>>>>> @@ -293,6 +332,18 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,\n>>>>>>  \t\treturn ret;\n>>>>>>  \t}\n>>>>>>  \n>>>>>> +\t/*\n>>>>>> +\t * Depending of the function of the entities involved, we may want to\n>>>>>> +\t * create links between them (for example between a sensor and its lens\n>>>>>> +\t * or between a sensor's source pad and the connected device's sink\n>>>>>> +\t * pad)\n>>>>> s/)/)./\n>>>>>\n>>>>>> +\t */\n>>>>>> +\tret = v4l2_async_try_create_links(notifier, sd);\n>>>>>> +\tif (ret) {\n>>>>>> +\t\tv4l2_device_unregister_subdev(sd);\n>>>>>> +\t\treturn ret;\n>>>>>> +\t}\n>>>>>> +\n>>>>>>  \t/* Remove from the waiting list */\n>>>>>>  \tlist_del(&asd->list);\n>>>>>>  \tsd->asd = asd;","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 2AA8CBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 16 Jan 2022 00:01:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 539FA60935;\n\tSun, 16 Jan 2022 01:01:51 +0100 (CET)","from mail-wm1-x329.google.com (mail-wm1-x329.google.com\n\t[IPv6:2a00:1450:4864:20::329])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34F6C6017B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 16 Jan 2022 01:01:49 +0100 (CET)","by mail-wm1-x329.google.com with SMTP id\n\tc126-20020a1c9a84000000b00346f9ebee43so13408274wme.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 15 Jan 2022 16:01:49 -0800 (PST)","from [192.168.0.14]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161])\n\tby smtp.gmail.com with ESMTPSA id\n\tj9sm9869012wms.0.2022.01.15.16.01.47\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tSat, 15 Jan 2022 16:01:48 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"RHFTLFHp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-transfer-encoding:content-language; \n\tbh=rpjlmYlLEZWQedrA0ENP51FyVWn5wNIXw+Twa+rxyHU=;\n\tb=RHFTLFHpPHmUuWZ+5HSV7DG3enArYrQneFf5SiIfDU/YzlMISa2CFFzY7y3m73NXZe\n\tsTQFo/YNm43sEmoTnZUl5Sd5WgA67hHn9BpfMNhydf6NjIa+d6vsQKnlyeqUFgITHfum\n\tvRWWkXpugNpyn9ECVQll9wTJhnEWRazalaf3vYk2K75aBdS4BgfwMsZd0oFugrQnLUXA\n\twKuabGD9FPbxdkTTJRtVjjOZQHGMyfE4P/clGjaA9jASmxI4Ezf3ZZa2jyARPgfQGbDL\n\tD2qfYgb4tbJoLjv5ZmusUdepNe6SwQUFeFAPNSgJnxImObuxZOFRYk9xpkyL1BgCpxp6\n\tc08Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-transfer-encoding\n\t:content-language;\n\tbh=rpjlmYlLEZWQedrA0ENP51FyVWn5wNIXw+Twa+rxyHU=;\n\tb=oWa5ayrr1k0kNjDcwSYMHXGn2QVz9Tr+6HXUDJkqbT7UR0w2s4Gmw2ZvgyHnZtYfCQ\n\tupT8agj4fTeHedtKUp7vcSFMmimIGJF+5lkDACY5ZTXZqLqO0VJn62u+v4MBxVQCe5GR\n\tp6mdKV0ZDH8sHzyi9WrH+Q8muF35WfV8InDqlB2yJ48u49f+MaJ/HiCi4TxSYaLqxZ/7\n\tEhZ3pHiReW2H9hGJb/eYHpNKvHzyZbhekm3OS5/4ZQDWJfLvhuZdtMkJghvIaqPKn4Yq\n\tGa1YvL+nihJlG/klHRs+Wmh2lHE+YHRTSxWKH4Xxtrr0Mmao8YFGvI1MTdAX9USwCWGg\n\tQHOA==","X-Gm-Message-State":"AOAM532EHjYH29hnNqrzHZqE320igl24mpp5mGvBefEv6R6X3t+ruu//\n\tnAPmj4QY9SAV9qh+IEfzY6w=","X-Google-Smtp-Source":"ABdhPJzQL50kRnX2MYG8K37nHrnYVFMTrWJlRQsKPRqYLwGcsbY1ehzc8qQVvPLvLKC73qqWfwvRcA==","X-Received":"by 2002:adf:e810:: with SMTP id\n\to16mr2559777wrm.148.1642291308768; \n\tSat, 15 Jan 2022 16:01:48 -0800 (PST)","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20211213232849.40071-1-djrscally@gmail.com>\n\t<20211213232849.40071-6-djrscally@gmail.com>\n\t<YbkZEDKHP2gyKjqd@pendragon.ideasonboard.com>\n\t<73e56a19-13a8-2c76-386f-dbc5e1babce7@gmail.com>\n\t<YbkiOoHnl9duDjUR@pendragon.ideasonboard.com>\n\t<35553048-f338-8650-027f-708cfaac030d@gmail.com>\n\t<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>","From":"Daniel Scally <djrscally@gmail.com>","Message-ID":"<9487f650-370f-7cd5-af93-4af7f8afed2c@gmail.com>","Date":"Sun, 16 Jan 2022 00:01:47 +0000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.14.0","MIME-Version":"1.0","In-Reply-To":"<YbmvrHzvM9UzmwcV@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 5/5] media: v4l2-async: Create links\n\tduring v4l2_async_match_notify()","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>","Cc":"libcamera-devel@lists.libcamera.org, sakari.ailus@linux.intel.com,\n\tlinux-media@vger.kernel.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]