media: rcar-vin: Allow independent VIN link enablement
Subsystems (2)
RFC PATCH 1/1 media: rcar-vin: Allow independent VIN link enablement
There is a block of code in rvin_group_link_notify() that prevents enabling a link to a VIN node if any entity in the media graph is in use. This prevents enabling a VIN link even if there is an in-use entity somewhere in the graph that is independent of the link's pipeline.
For example, the code block will prevent enabling a link from the first rcar-csi2 receiver to a VIN node even if there is an enabled link somewhere far upstream on the second independent rcar-csi2 receiver pipeline.
If this code block is meant to prevent modifying a link if the link is actively involved in streaming, there is already such a check in __media_entity_setup_link() that verifies the stream_count of the link's source and sink entities are both zero.
Remove the code block so that VIN node links can be enabled even if there are other independent in-use entities.
--- drivers/media/platform/rcar-vin/rcar-core.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/media/platform/rcar-vin/rcar-core.c +0 -6
@@ -116,7 +116,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, struct rvin_group, mdev);unsigned int master_id, channel, mask_new, i;unsigned int mask = ~0 ; -struct media_entity *entity;struct video_device *vdev;struct media_pad *csi_pad;struct rvin_dev *vin =NULL ;
@@ -131,11 +130,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, !is_media_entity_v4l2_video_device(link->sink->entity))return 0 ; -/* If any entity is in use don't allow link changes. */ -media_device_for_each_entity (entity, &group->mdev) -if (entity->use_count) -return -EBUSY ; -mutex_lock (&group->lock);/* Find the master VIN that controls the routes. */
Signature · 1 line
2.17.1
Hi Steve,
Thanks for your patch.
Quoted 10 lines · Steve Longerbeam
There is a block of code in
rvin_group_link_notify()that prevents enabling a link to a VIN node if any entity in the media graph is in use. This prevents enabling a VIN link even if there is an in-use entity somewhere in the graph that is independent of the link's pipeline.For example, the code block will prevent enabling a link from the first rcar-csi2 receiver to a VIN node even if there is an enabled link somewhere far upstream on the second independent rcar-csi2 receiver pipeline.
Unfortunately this is by design and needed due to the hardware design. The different VIN endpoints shares a configuration register which controls the routing from the CSI-2 receivers to the VIN (register name CHSEL). Modifying the CHSEL register which is what happens when a link is enabled/disabled can have side effects on running streams even if they are not shown to be dependent in the media graph.
There is a CHSEL register in VIN0 which controls the routing from all CSI-2 receivers to VIN0-3 and a CHSEL register in VIN4 which controls the same for VIN4-7.
Quoted 5 lines
If this code block is meant to prevent modifying a link if the link is actively involved in streaming, there is already such a check in
__media_entity_setup_link()that verifies thestream_countof the link's source and sink entities are both zero.
For the reason above the check in __media_entity_setup_link() is not enough :-( This register sharing is my least favorite thing about the VIN on Gen3 and forces the driver to become more complex as all VIN instances needs to know about each other and interact.
Quoted 3 lines
Remove the code block so that VIN node links can be enabled even if there are other independent in-use entities.
There is room for some improvement in this area disregarding the odd hardware design. It *could* be allowed to change a link terminating in VIN4-7 even if there is a stream running for one or more in VIN0-3.
I would be interested to test such a patch but to allow any link change which is allowed by __media_entity_setup_link() is unfortunately not possible, as I understand it. Maybe someone more clever then me can find ways to unlock even more then just the split between VIN0-3 and VIn4-7.
In essence the CHSEL register can not be changed if it's involved in a running pipeline even if the end result would be that the running pipeline would look the same. This is possible as there are multiple CHSEL settings where the same source is connected to a specific VIN while other members of the "subgroup of VINs" (e.g. VIN0-3) is routed to something else for the two CHSEL settings.
Quoted 35 lines
Fixes c0cc5aef31 ("media: rcar-vin: add link notify for Gen3")Signed-off-by Steve Longerbeam <[email protected]>--- drivers/media/platform/rcar-vin/rcar-core.c | 6 ------ 1 file changed, 6 deletions(-)drivers/media/platform/rcar-vin/rcar-core.c +0
-6@@ -116,7 +116,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, struct rvin_group, mdev);unsigned int master_id, channel, mask_new, i;unsigned int mask = ~0 ; -struct media_entity *entity;struct video_device *vdev;struct media_pad *csi_pad;struct rvin_dev *vin =NULL ;@@ -131,11 +130,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, !is_media_entity_v4l2_video_device(link->sink->entity))return 0 ; -/* If any entity is in use don't allow link changes. */ -media_device_for_each_entity (entity, &group->mdev) -if (entity->use_count) -return -EBUSY ; -mutex_lock (&group->lock);/* Find the master VIN that controls the routes. */ Signature · 1 line
2.17.1
Signature · 2 lines
Regards, Niklas Söderlund
Hi Niklas,
Quoted 15 lines · Niklas Söderlund
Hi Steve,
Thanks for your patch.
Quoted 10 lines · Steve Longerbeam
There is a block of code in
rvin_group_link_notify()that prevents enabling a link to a VIN node if any entity in the media graph is in use. This prevents enabling a VIN link even if there is an in-use entity somewhere in the graph that is independent of the link's pipeline.For example, the code block will prevent enabling a link from the first rcar-csi2 receiver to a VIN node even if there is an enabled link somewhere far upstream on the second independent rcar-csi2 receiver pipeline.
Quoted 6 lines
Unfortunately this is by design and needed due to the hardware design. The different VIN endpoints shares a configuration register which controls the routing from the CSI-2 receivers to the VIN (register name CHSEL). Modifying the CHSEL register which is what happens when a link is enabled/disabled can have side effects on running streams even if they are not shown to be dependent in the media graph.
Ok, understood, modifying CHSEL register can adversely affect running streams.
Quoted 5 lines
There is a CHSEL register in VIN0 which controls the routing from all CSI-2 receivers to VIN0-3 and a CHSEL register in VIN4 which controls the same for VIN4-7.
Quoted 9 lines
Quoted 4 lines
If this code block is meant to prevent modifying a link if the link is actively involved in streaming, there is already such a check in
__media_entity_setup_link()that verifies thestream_countof the link's source and sink entities are both zero.For the reason above the check in
__media_entity_setup_link()is not enough :-( This register sharing is my least favorite thing about the VIN on Gen3 and forces the driver to become more complex as all VIN instances needs to know about each other and interact.
Given above I understand why the stream count checks in __media_entity_setup_link() are insufficient, because only the requested link's source stream count is checked, and not the other CSI-2 receiver for example.
But why check the use counts of every entity upstream from the VIN sources? Why not check only the VIN source entities stream counts (both CSI-2 receivers and/or parallel devices), and ignore entities upstream from those?
And why are the use counts checked, it seems it should be the stream counts that should be checked.
Quoted 11 lines
Quoted 2 lines
Remove the code block so that VIN node links can be enabled even if there are other independent in-use entities.
There is room for some improvement in this area disregarding the odd hardware design. It *could* be allowed to change a link terminating in VIN4-7 even if there is a stream running for one or more in VIN0-3.
I would be interested to test such a patch but to allow any link change which is allowed by
__media_entity_setup_link()is unfortunately not possible, as I understand it. Maybe someone more clever then me can find ways to unlock even more then just the split between VIN0-3 and VIn4-7.
Quoted 6 lines
In essence the CHSEL register can not be changed if it's involved in a running pipeline even if the end result would be that the running pipeline would look the same. This is possible as there are multiple CHSEL settings where the same source is connected to a specific VIN while other members of the "subgroup of VINs" (e.g. VIN0-3) is routed to something else for the two CHSEL settings.
Right, so rvin_group_link_notify() determines whether the requested VIN link enable will result in a valid set of CSI2->VIN links for the given hardware, using the CHSEL bitmask tables. Which is why it seems it is the stream counts that should be checked as mentioned above, rather than the use counts, because the CHSEL bitmask checks are validating the set of enabled links, and the only remaining checks are to verify no streams are running on either CSI-2 receiver.
Steve
Quoted 34 lines
Quoted 34 lines
Fixes c0cc5aef31 ("media: rcar-vin: add link notify for Gen3")Signed-off-by Steve Longerbeam <[email protected]>--- drivers/media/platform/rcar-vin/rcar-core.c | 6 ------ 1 file changed, 6 deletions(-)drivers/media/platform/rcar-vin/rcar-core.c +0
-6@@ -116,7 +116,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, struct rvin_group, mdev);unsigned int master_id, channel, mask_new, i;unsigned int mask = ~0 ; -struct media_entity *entity;struct video_device *vdev;struct media_pad *csi_pad;struct rvin_dev *vin =NULL ;@@ -131,11 +130,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, !is_media_entity_v4l2_video_device(link->sink->entity))return 0 ; -/* If any entity is in use don't allow link changes. */ -media_device_for_each_entity (entity, &group->mdev) -if (entity->use_count) -return -EBUSY ; -mutex_lock (&group->lock);/* Find the master VIN that controls the routes. */ Signature · 1 line
2.17.1
Hi Niklas,
How about a patch that simply replaces the entity use_count check with a stream_count check?
As in:
drivers/media/platform/rcar-vin/rcar-core.c +0 -0
@@ -131,9 +131,13 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags,
!is_media_entity_v4l2_video_device(link->sink->entity)) return 0;
- /* If any entity is in use don't allow link changes. */ + /*
+ * Don't allow link changes if any entity in the graph is + * streaming, modifying the CHSEL register fields can disrupt + * running streams.
+ */
media_device_for_each_entity(entity, &group->mdev) - if (entity->use_count)
+ if (entity->stream_count)
return -EBUSY;
mutex_lock(&group->lock);
And that might be overkilll, maybe only the stream_count's of the VIN entities need to be checked.
Steve
Quoted 106 lines · Steve Longerbeam
Hi Niklas,
Quoted 15 lines · Niklas Söderlund
Hi Steve,
Thanks for your patch.
Quoted 10 lines · Steve Longerbeam
There is a block of code in
rvin_group_link_notify()that prevents enabling a link to a VIN node if any entity in the media graph is in use. This prevents enabling a VIN link even if there is an in-use entity somewhere in the graph that is independent of the link's pipeline.For example, the code block will prevent enabling a link from the first rcar-csi2 receiver to a VIN node even if there is an enabled link somewhere far upstream on the second independent rcar-csi2 receiver pipeline.
Quoted 6 lines
Unfortunately this is by design and needed due to the hardware design. The different VIN endpoints shares a configuration register which controls the routing from the CSI-2 receivers to the VIN (register name CHSEL). Modifying the CHSEL register which is what happens when a link is enabled/disabled can have side effects on running streams even if they are not shown to be dependent in the media graph.
Ok, understood, modifying CHSEL register can adversely affect running streams.
Quoted 5 lines
There is a CHSEL register in VIN0 which controls the routing from all CSI-2 receivers to VIN0-3 and a CHSEL register in VIN4 which controls the same for VIN4-7.
Quoted 9 lines
Quoted 4 lines
If this code block is meant to prevent modifying a link if the link is actively involved in streaming, there is already such a check in
__media_entity_setup_link()that verifies thestream_countof the link's source and sink entities are both zero.For the reason above the check in
__media_entity_setup_link()is not enough :-( This register sharing is my least favorite thing about the VIN on Gen3 and forces the driver to become more complex as all VIN instances needs to know about each other and interact.Given above I understand why the stream count checks in
__media_entity_setup_link()are insufficient, because only the requested link's source stream count is checked, and not the other CSI-2 receiver for example.But why check the use counts of every entity upstream from the VIN sources? Why not check only the VIN source entities stream counts (both CSI-2 receivers and/or parallel devices), and ignore entities upstream from those?
And why are the use counts checked, it seems it should be the stream counts that should be checked.
Quoted 11 lines
Quoted 2 lines
Remove the code block so that VIN node links can be enabled even if there are other independent in-use entities.
There is room for some improvement in this area disregarding the odd hardware design. It *could* be allowed to change a link terminating in VIN4-7 even if there is a stream running for one or more in VIN0-3.
I would be interested to test such a patch but to allow any link change which is allowed by
__media_entity_setup_link()is unfortunately not possible, as I understand it. Maybe someone more clever then me can find ways to unlock even more then just the split between VIN0-3 and VIn4-7.Quoted 6 lines
In essence the CHSEL register can not be changed if it's involved in a running pipeline even if the end result would be that the running pipeline would look the same. This is possible as there are multiple CHSEL settings where the same source is connected to a specific VIN while other members of the "subgroup of VINs" (e.g. VIN0-3) is routed to something else for the two CHSEL settings.
Right, so
rvin_group_link_notify()determines whether the requested VIN link enable will result in a valid set ofCSI2->VINlinks for the given hardware, using the CHSEL bitmask tables. Which is why it seems it is the stream counts that should be checked as mentioned above, rather than the use counts, because the CHSEL bitmask checks are validating the set of enabled links, and the only remaining checks are to verify no streams are running on either CSI-2 receiver.Steve
Quoted 34 lines
Quoted 34 lines
Fixes c0cc5aef31 ("media: rcar-vin: add link notify for Gen3")Signed-off-by Steve Longerbeam <[email protected]>---
drivers/media/platform/rcar-vin/rcar-core.c| 6 ------1 file changed, 6 deletions(-)drivers/media/platform/rcar-vin/rcar-core.c +0
-1@@ -116,7 +116,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, struct rvin_group, mdev); unsigned int master_id, channel, mask_new, i; unsigned int mask = ~0; - struct media_entity *entity; struct video_device *vdev; struct media_pad *csi_pad;struct
rvin_dev*vin = NULL;drivers/media/platform/rcar-vin/rcar-core.c +0
-0@@ -131,11 +130,6 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, !is_media_entity_v4l2_video_device(link->sink->entity)) return 0;- /* If any entity is in use don't allow link changes. */ -
media_device_for_each_entity(entity, &group->mdev)- if (entity->use_count)
- return-EBUSY;
-
mutex_lock(&group->lock);
/* Find the master VIN that controls the routes. */Signature · 1 line
2.17.1