linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Jacopo Mondi <jacopo@jmondi.org>
Cc: Eugen.Hristev@microchip.com, linux-media@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Claudiu.Beznea@microchip.com, robh+dt@kernel.org,
	Nicolas.Ferre@microchip.com
Subject: Re: [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification
Date: Fri, 29 Apr 2022 12:13:46 +0200	[thread overview]
Message-ID: <a10a255c-e3b7-4c5f-2a7e-9474e0526a61@xs4all.nl> (raw)
In-Reply-To: <Ymu4ywjEvX5HbE/W@pendragon.ideasonboard.com>

On 29/04/2022 12:07, Laurent Pinchart wrote:
> On Fri, Apr 29, 2022 at 11:58:48AM +0200, Jacopo Mondi wrote:
>> On Fri, Apr 29, 2022 at 10:43:09AM +0200, Hans Verkuil wrote:
>>> On 29/04/2022 10:28, Eugen.Hristev@microchip.com wrote:
>>>> On 4/29/22 11:17 AM, Hans Verkuil wrote:
>>>>> On 10/03/2022 10:51, Eugen Hristev wrote:
>>>>>> As a top MC video driver, the atmel-isc should not propagate the format to the
>>>>>> subdevice, it should rather check at start_streaming() time if the subdev is properly
>>>>>> configured with a compatible format.
>>>>>> Removed the whole format finding logic, and reworked the format verification
>>>>>> at start_streaming time, such that the ISC will return an error if the subdevice
>>>>>> is not properly configured. To achieve this, media_pipeline_start
>>>>>> is called and a link_validate callback is created to check the formats.
>>>>>> With this being done, the module parameter 'sensor_preferred' makes no sense
>>>>>> anymore. The ISC should not decide which format the sensor is using. The
>>>>>> ISC should only cope with the situation and inform userspace if the streaming
>>>>>> is possible in the current configuration.
>>>>>> The redesign of the format propagation has also risen the question of the
>>>>>> enumfmt callback. If enumfmt is called with an mbus_code, the enumfmt handler
>>>>>> should only return the formats that are supported for this mbus_code.
>>>>>> Otherwise, the enumfmt will report all the formats that the ISC could output.
>>>>>> With this rework, the dynamic list of user formats is removed. It makes no
>>>>>> more sense to identify at complete time which formats the sensor could emit,
>>>>>> and add those into a separate dynamic list.
>>>>>> The ISC will start with a simple preconfigured default format, and at
>>>>>> link validate time, decide whether it can use the format that is configured
>>>>>> on the sink or not.
>>>>>>
>>>>>> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
>>>>>> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
>>>>>> ---
>>>>>> Changes in v9:
>>>>>> - isc_link_validate now static
>>>>>>
>>>>>> Changes in v7:
>>>>>> - minor typos as suggested by Jacopo
>>>>>> - small changes, reduce some indentation, modified an index, as suggested by
>>>>>> Jacopo
>>>>>>
>>>>>> Changes in v6:
>>>>>> - reworked a bit enum_fmt as suggested by Jacopo
>>>>>>
>>>>>> Changes in v5:
>>>>>> - removed user_formats dynamic list as it is now pointless
>>>>>> - greatly simplified the enum_fmt function
>>>>>> - removed some init code that was useless now
>>>>>>
>>>>>> Changes in v4:
>>>>>> - moved validation code into link_validate and used media_pipeline_start
>>>>>> - merged this patch with the enum_fmt patch which was previously in v3 of
>>>>>> the series
>>>>>>
>>>>>> Changes in v3:
>>>>>> - clamp to maximum resolution once the frame size from the subdev is found
>>>>>>   drivers/media/platform/atmel/atmel-isc-base.c | 412 ++++++++----------
>>>>>>   .../media/platform/atmel/atmel-isc-scaler.c   |   5 +
>>>>>>   drivers/media/platform/atmel/atmel-isc.h      |  13 +-
>>>>>>   .../media/platform/atmel/atmel-sama5d2-isc.c  |  20 +
>>>>>>   .../media/platform/atmel/atmel-sama7g5-isc.c  |  20 +
>>>>>>   5 files changed, 236 insertions(+), 234 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
>>>>>> index ee1dda6707a0..fe2c0af58060 100644
>>>>>> --- a/drivers/media/platform/atmel/atmel-isc-base.c
>>>>>> +++ b/drivers/media/platform/atmel/atmel-isc-base.c
>>>>>> @@ -36,11 +36,6 @@ static unsigned int debug;
>>>>>>   module_param(debug, int, 0644);
>>>>>>   MODULE_PARM_DESC(debug, "debug level (0-2)");
>>>>>>
>>>>>> -static unsigned int sensor_preferred = 1;
>>>>>> -module_param(sensor_preferred, uint, 0644);
>>>>>> -MODULE_PARM_DESC(sensor_preferred,
>>>>>> -              "Sensor is preferred to output the specified format (1-on 0-off), default 1");
>>>>>> -
>>>>>>   #define ISC_IS_FORMAT_RAW(mbus_code) \
>>>>>>        (((mbus_code) & 0xf000) == 0x3000)
>>>>>>
>>>>>> @@ -337,6 +332,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
>>>>>>        unsigned long flags;
>>>>>>        int ret;
>>>>>>
>>>>>> +     ret = media_pipeline_start(&isc->video_dev.entity, &isc->mpipe);
>>>>>
>>>>> The pipeline validation is done in start_streaming, but I don't think that
>>>>> is the best place: if STREAMON is called before buffers are queued, then
>>>>> an invalid pipeline isn't discovered until enough buffers are queued to
>>>>> kick off start_streaming.
>>>>>
>>>>> Drivers like vsp1, omap3isp and the samsung drivers all do this in streamon().
>>>>>
>>>>> I think that is the correct time to do this.
>>>>
>>>> Hello Hans,
>>>>
>>>> Initially (v2, v3) I had this in streamon(). The problem that I faced at
>>>> that time was that streamoff was never called, so I could not call
>>>> media_pipeline_stop(). Then Jacopo told me to move it to start_streaming
>>>> (see change log for v4) , and I did not face any more problems.
>>
>> Yes indeed, seems I suggested to use media_pipeline_handler in a
>> comment on your v3
>>
>> "at s_stream time your top driver calls media_pipeline_start()"
>>
>> sorry about that, I should have looked around a bit more carefully and
>> notice most drivers do so at vb2 streamon
>>
>> However I don't see media_pipeline_start being called at all in v3 of
>> the patch
>>
>>> It's a mess. Looking at some drivers I see that omap3isp calls media_pipeline_stop
>>> in streamoff (so will have the same problem as you described if VIDIOC_STREAMOFF
>>> isn't called), exynos4-is does the same, but it also checks the streaming state in
>>> the release() fop callback, so that would fix this problem. And vimc does this
>>> in stop_streaming.
>>>
>>> I'm in favor of fixing this in vb2, that framework knows exactly when this needs
>>> to be called.
>>
>> Are you suggesting to have vb2 to call media_pipeline_start() or is it
>> more complex than this ?
> 
> I think Hans meant adding a .validate() operation to vb2.
> 
> vb2 is already quite complex, I don't think adding more features is a
> good idea. I'd rather have vb2 focus on buffer management only
> (.start_streaming() and .stop_streaming() shouldn't have been in there
> in my opinion), and handle validation in the .streamon() handler. I'd
> expect most drivers that deal with media pipelines to do more work in
> .streamon() anyway.

I disagree with that :-)

It's vb2 that keeps track of the streaming state and when what actions
need to be taken. Drivers really shouldn't need to care about the ioctls
themselves, and just implement the relevant vb2 callbacks. Relying on
drivers to handle any of the streaming ioctls is asking for problems,
as this shows: most drivers implement this wrong today.

The vb2 framework knows when e.g. the pipeline needs to be started or
stopped, and can do this at the best time, without drivers needing to
keep track of when streamon/off/release is called. Keep that logic in
vb2.

Regards,

	Hans

  reply	other threads:[~2022-04-29 10:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10  9:51 [PATCH v9 00/13] media: atmel: atmel-isc: implement media controller Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 01/13] media: atmel: atmel-isc-base: use streaming status when queueing buffers Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 02/13] media: atmel: atmel-isc-base: replace is_streaming call in s_fmt_vid_cap Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 03/13] media: atmel: atmel-isc: remove redundant comments Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 04/13] media: atmel: atmel-isc: implement media controller Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 05/13] media: atmel: atmel-sama5d2-isc: fix wrong mask in YUYV format check Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 06/13] media: atmel: atmel-isc-base: use mutex to lock awb workqueue from streaming Eugen Hristev
2022-04-29  7:41   ` Hans Verkuil
2022-04-29  8:08     ` Eugen.Hristev
2022-04-29  8:18       ` Hans Verkuil
2022-03-10  9:51 ` [PATCH v9 07/13] media: atmel: atmel-isc: compact the controller formats list Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 08/13] media: atmel: atmel-isc: change format propagation to subdev into only verification Eugen Hristev
2022-04-29  8:17   ` Hans Verkuil
2022-04-29  8:28     ` Eugen.Hristev
2022-04-29  8:43       ` Hans Verkuil
2022-04-29  9:58         ` Jacopo Mondi
2022-04-29 10:03           ` Hans Verkuil
2022-04-29 10:09             ` Eugen.Hristev
2022-04-29 10:07           ` Laurent Pinchart
2022-04-29 10:13             ` Hans Verkuil [this message]
2022-04-29 10:20               ` Laurent Pinchart
2022-04-29 11:17                 ` Hans Verkuil
2022-04-29 12:02                   ` Laurent Pinchart
2022-04-29 12:23                     ` Hans Verkuil
2022-04-29 12:28                       ` Laurent Pinchart
2022-04-29 12:38                         ` Jacopo Mondi
2022-04-29 12:47                           ` Laurent Pinchart
2022-04-29 12:50                           ` Hans Verkuil
2022-04-29 12:59                             ` Eugen.Hristev
2022-03-10  9:51 ` [PATCH v9 09/13] media: atmel: atmel-sama7g5-isc: remove stray line Eugen Hristev
2022-03-10  9:51 ` [PATCH v9 10/13] dt-bindings: media: microchip,xisc: add bus-width of 14 Eugen Hristev
2022-03-10  9:52 ` [PATCH v9 11/13] ARM: dts: at91: sama7g5: add nodes for video capture Eugen Hristev
2022-03-10  9:52 ` [PATCH v9 12/13] ARM: configs: at91: sama7: add xisc and csi2dc Eugen Hristev
2022-03-10  9:52 ` [PATCH v9 13/13] ARM: multi_v7_defconfig: add atmel video pipeline modules Eugen Hristev
2022-04-29  8:05 ` [PATCH v9 00/13] media: atmel: atmel-isc: implement media controller Hans Verkuil
2022-04-29  8:20   ` Eugen.Hristev
2022-04-29  8:33     ` Hans Verkuil
2022-04-29  8:39       ` Eugen.Hristev
2022-04-29  8:45         ` Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a10a255c-e3b7-4c5f-2a7e-9474e0526a61@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=Claudiu.Beznea@microchip.com \
    --cc=Eugen.Hristev@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jacopo@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).