2018-04-22 17:33:20 -04:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-06-04 11:22:30 -03:00
|
|
|
/*
|
|
|
|
* vsp1_entity.c -- R-Car VSP1 Base Entity
|
|
|
|
*
|
2014-02-06 14:42:31 -03:00
|
|
|
* Copyright (C) 2013-2014 Renesas Electronics Corporation
|
2013-06-04 11:22:30 -03:00
|
|
|
*
|
|
|
|
* Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
|
|
|
|
#include <media/media-entity.h>
|
2013-07-10 12:03:30 -03:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2013-06-04 11:22:30 -03:00
|
|
|
#include <media/v4l2-subdev.h>
|
|
|
|
|
|
|
|
#include "vsp1.h"
|
2015-11-01 10:46:25 -02:00
|
|
|
#include "vsp1_dl.h"
|
2013-06-04 11:22:30 -03:00
|
|
|
#include "vsp1_entity.h"
|
2016-09-07 09:09:53 -03:00
|
|
|
#include "vsp1_pipe.h"
|
|
|
|
#include "vsp1_rwpf.h"
|
2015-11-01 10:46:25 -02:00
|
|
|
|
2016-09-07 09:09:53 -03:00
|
|
|
void vsp1_entity_route_setup(struct vsp1_entity *entity,
|
|
|
|
struct vsp1_pipeline *pipe,
|
2018-05-18 16:42:02 -04:00
|
|
|
struct vsp1_dl_body *dlb)
|
2015-08-02 18:58:31 -03:00
|
|
|
{
|
2016-09-07 09:09:53 -03:00
|
|
|
struct vsp1_entity *source;
|
2017-05-25 00:16:57 +03:00
|
|
|
u32 route;
|
2015-08-02 18:58:31 -03:00
|
|
|
|
2016-02-24 20:40:22 -03:00
|
|
|
if (entity->type == VSP1_ENTITY_HGO) {
|
|
|
|
u32 smppt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The HGO is a special case, its routing is configured on the
|
|
|
|
* sink pad.
|
|
|
|
*/
|
2017-06-25 20:15:22 +03:00
|
|
|
source = entity->sources[0];
|
2016-02-24 20:40:22 -03:00
|
|
|
smppt = (pipe->output->entity.index << VI6_DPR_SMPPT_TGW_SHIFT)
|
|
|
|
| (source->route->output << VI6_DPR_SMPPT_PT_SHIFT);
|
|
|
|
|
2018-05-18 16:42:02 -04:00
|
|
|
vsp1_dl_body_write(dlb, VI6_DPR_HGO_SMPPT, smppt);
|
2016-02-24 20:40:22 -03:00
|
|
|
return;
|
2016-09-06 11:38:56 -03:00
|
|
|
} else if (entity->type == VSP1_ENTITY_HGT) {
|
|
|
|
u32 smppt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The HGT is a special case, its routing is configured on the
|
|
|
|
* sink pad.
|
|
|
|
*/
|
2017-06-25 20:15:22 +03:00
|
|
|
source = entity->sources[0];
|
2016-09-06 11:38:56 -03:00
|
|
|
smppt = (pipe->output->entity.index << VI6_DPR_SMPPT_TGW_SHIFT)
|
|
|
|
| (source->route->output << VI6_DPR_SMPPT_PT_SHIFT);
|
|
|
|
|
2018-05-18 16:42:02 -04:00
|
|
|
vsp1_dl_body_write(dlb, VI6_DPR_HGT_SMPPT, smppt);
|
2016-09-06 11:38:56 -03:00
|
|
|
return;
|
2016-02-24 20:40:22 -03:00
|
|
|
}
|
|
|
|
|
2016-09-07 09:09:53 -03:00
|
|
|
source = entity;
|
2015-08-02 18:58:31 -03:00
|
|
|
if (source->route->reg == 0)
|
|
|
|
return;
|
|
|
|
|
2017-05-25 00:16:57 +03:00
|
|
|
route = source->sink->route->inputs[source->sink_pad];
|
|
|
|
/*
|
|
|
|
* The ILV and BRS share the same data path route. The extra BRSSEL bit
|
|
|
|
* selects between the ILV and BRS.
|
2025-04-01 16:22:01 +02:00
|
|
|
*
|
|
|
|
* The BRU and IIF share the same data path route. The extra IIFSEL bit
|
|
|
|
* selects between the IIF and BRU.
|
2017-05-25 00:16:57 +03:00
|
|
|
*/
|
|
|
|
if (source->type == VSP1_ENTITY_BRS)
|
|
|
|
route |= VI6_DPR_ROUTE_BRSSEL;
|
2025-04-01 16:22:01 +02:00
|
|
|
else if (source->type == VSP1_ENTITY_IIF)
|
|
|
|
route |= VI6_DPR_ROUTE_IIFSEL;
|
2018-05-18 16:42:02 -04:00
|
|
|
vsp1_dl_body_write(dlb, source->route->reg, route);
|
2015-08-02 18:58:31 -03:00
|
|
|
}
|
|
|
|
|
2018-05-18 16:42:01 -04:00
|
|
|
void vsp1_entity_configure_stream(struct vsp1_entity *entity,
|
2023-11-12 04:14:05 +02:00
|
|
|
struct v4l2_subdev_state *state,
|
2018-05-18 16:42:01 -04:00
|
|
|
struct vsp1_pipeline *pipe,
|
2019-03-11 20:13:43 +02:00
|
|
|
struct vsp1_dl_list *dl,
|
2018-05-18 16:42:02 -04:00
|
|
|
struct vsp1_dl_body *dlb)
|
2018-05-18 16:42:01 -04:00
|
|
|
{
|
|
|
|
if (entity->ops->configure_stream)
|
2023-11-12 04:14:05 +02:00
|
|
|
entity->ops->configure_stream(entity, state, pipe, dl, dlb);
|
2018-05-18 16:42:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void vsp1_entity_configure_frame(struct vsp1_entity *entity,
|
|
|
|
struct vsp1_pipeline *pipe,
|
2018-05-18 16:42:02 -04:00
|
|
|
struct vsp1_dl_list *dl,
|
|
|
|
struct vsp1_dl_body *dlb)
|
2018-05-18 16:42:01 -04:00
|
|
|
{
|
|
|
|
if (entity->ops->configure_frame)
|
2018-05-18 16:42:02 -04:00
|
|
|
entity->ops->configure_frame(entity, pipe, dl, dlb);
|
2018-05-18 16:42:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void vsp1_entity_configure_partition(struct vsp1_entity *entity,
|
|
|
|
struct vsp1_pipeline *pipe,
|
2023-11-15 00:34:56 +02:00
|
|
|
const struct vsp1_partition *partition,
|
2018-05-18 16:42:02 -04:00
|
|
|
struct vsp1_dl_list *dl,
|
|
|
|
struct vsp1_dl_body *dlb)
|
2018-05-18 16:42:01 -04:00
|
|
|
{
|
|
|
|
if (entity->ops->configure_partition)
|
2023-11-15 00:34:56 +02:00
|
|
|
entity->ops->configure_partition(entity, pipe, partition,
|
|
|
|
dl, dlb);
|
2018-05-18 16:42:01 -04:00
|
|
|
}
|
|
|
|
|
2025-04-30 02:29:00 +03:00
|
|
|
void vsp1_entity_adjust_color_space(struct v4l2_mbus_framefmt *format)
|
|
|
|
{
|
|
|
|
u8 xfer_func = format->xfer_func;
|
|
|
|
u8 ycbcr_enc = format->ycbcr_enc;
|
|
|
|
u8 quantization = format->quantization;
|
|
|
|
|
|
|
|
vsp1_adjust_color_space(format->code, &format->colorspace, &xfer_func,
|
|
|
|
&ycbcr_enc, &quantization);
|
|
|
|
|
|
|
|
format->xfer_func = xfer_func;
|
|
|
|
format->ycbcr_enc = ycbcr_enc;
|
|
|
|
format->quantization = quantization;
|
|
|
|
}
|
|
|
|
|
2013-06-04 11:22:30 -03:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* V4L2 Subdevice Operations
|
|
|
|
*/
|
|
|
|
|
2015-11-15 19:14:22 -02:00
|
|
|
/**
|
2023-11-26 03:37:15 +02:00
|
|
|
* vsp1_entity_get_state - Get the subdev state for an entity
|
2015-11-15 19:14:22 -02:00
|
|
|
* @entity: the entity
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
* @sd_state: the TRY state
|
2023-11-26 03:37:15 +02:00
|
|
|
* @which: state selector (ACTIVE or TRY)
|
2015-11-15 19:14:22 -02:00
|
|
|
*
|
2016-06-26 08:09:31 -03:00
|
|
|
* When called with which set to V4L2_SUBDEV_FORMAT_ACTIVE the caller must hold
|
|
|
|
* the entity lock to access the returned configuration.
|
|
|
|
*
|
2023-11-26 03:37:15 +02:00
|
|
|
* Return the subdev state requested by the which argument. The TRY state is
|
|
|
|
* passed explicitly to the function through the sd_state argument and simply
|
|
|
|
* returned when requested. The ACTIVE state comes from the entity structure.
|
2015-11-15 19:14:22 -02:00
|
|
|
*/
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
struct v4l2_subdev_state *
|
2023-11-26 03:37:15 +02:00
|
|
|
vsp1_entity_get_state(struct vsp1_entity *entity,
|
|
|
|
struct v4l2_subdev_state *sd_state,
|
|
|
|
enum v4l2_subdev_format_whence which)
|
2013-06-04 11:22:30 -03:00
|
|
|
{
|
|
|
|
switch (which) {
|
|
|
|
case V4L2_SUBDEV_FORMAT_ACTIVE:
|
2023-11-26 03:37:15 +02:00
|
|
|
return entity->state;
|
2015-11-15 19:14:22 -02:00
|
|
|
case V4L2_SUBDEV_FORMAT_TRY:
|
2013-06-04 11:22:30 -03:00
|
|
|
default:
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
return sd_state;
|
2013-06-04 11:22:30 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 21:10:13 -03:00
|
|
|
/*
|
|
|
|
* vsp1_subdev_get_pad_format - Subdev pad get_fmt handler
|
|
|
|
* @subdev: V4L2 subdevice
|
2023-11-26 03:37:15 +02:00
|
|
|
* @sd_state: V4L2 subdev state
|
2016-02-24 21:10:13 -03:00
|
|
|
* @fmt: V4L2 subdev format
|
|
|
|
*
|
|
|
|
* This function implements the subdev get_fmt pad operation. It can be used as
|
|
|
|
* a direct drop-in for the operation handler.
|
|
|
|
*/
|
|
|
|
int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2016-02-24 21:10:13 -03:00
|
|
|
struct v4l2_subdev_format *fmt)
|
|
|
|
{
|
|
|
|
struct vsp1_entity *entity = to_vsp1_entity(subdev);
|
2023-11-26 03:37:15 +02:00
|
|
|
struct v4l2_subdev_state *state;
|
2016-02-24 21:10:13 -03:00
|
|
|
|
2023-11-26 03:37:15 +02:00
|
|
|
state = vsp1_entity_get_state(entity, sd_state, fmt->which);
|
|
|
|
if (!state)
|
2016-02-24 21:10:13 -03:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-06-26 08:09:31 -03:00
|
|
|
mutex_lock(&entity->lock);
|
2023-11-12 04:14:05 +02:00
|
|
|
fmt->format = *v4l2_subdev_state_get_format(state, fmt->pad);
|
2016-06-26 08:09:31 -03:00
|
|
|
mutex_unlock(&entity->lock);
|
2016-02-24 21:10:13 -03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-24 20:25:42 -03:00
|
|
|
/*
|
|
|
|
* vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler
|
|
|
|
* @subdev: V4L2 subdevice
|
2023-11-26 03:37:15 +02:00
|
|
|
* @sd_state: V4L2 subdev state
|
2016-02-24 20:25:42 -03:00
|
|
|
* @code: Media bus code enumeration
|
|
|
|
* @codes: Array of supported media bus codes
|
|
|
|
* @ncodes: Number of supported media bus codes
|
|
|
|
*
|
|
|
|
* This function implements the subdev enum_mbus_code pad operation for entities
|
|
|
|
* that do not support format conversion. It enumerates the given supported
|
|
|
|
* media bus codes on the sink pad and reports a source pad format identical to
|
|
|
|
* the sink pad.
|
|
|
|
*/
|
|
|
|
int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2016-02-24 20:25:42 -03:00
|
|
|
struct v4l2_subdev_mbus_code_enum *code,
|
|
|
|
const unsigned int *codes, unsigned int ncodes)
|
|
|
|
{
|
|
|
|
struct vsp1_entity *entity = to_vsp1_entity(subdev);
|
|
|
|
|
|
|
|
if (code->pad == 0) {
|
|
|
|
if (code->index >= ncodes)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
code->code = codes[code->index];
|
|
|
|
} else {
|
2023-11-26 03:37:15 +02:00
|
|
|
struct v4l2_subdev_state *state;
|
2016-02-24 20:25:42 -03:00
|
|
|
struct v4l2_mbus_framefmt *format;
|
|
|
|
|
2017-02-26 10:29:50 -03:00
|
|
|
/*
|
|
|
|
* The entity can't perform format conversion, the sink format
|
2016-02-24 20:25:42 -03:00
|
|
|
* is always identical to the source format.
|
|
|
|
*/
|
|
|
|
if (code->index)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2023-11-26 03:37:15 +02:00
|
|
|
state = vsp1_entity_get_state(entity, sd_state, code->which);
|
|
|
|
if (!state)
|
2016-02-24 20:25:42 -03:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-06-26 08:09:31 -03:00
|
|
|
mutex_lock(&entity->lock);
|
2023-11-12 04:14:05 +02:00
|
|
|
format = v4l2_subdev_state_get_format(state, 0);
|
2016-02-24 20:25:42 -03:00
|
|
|
code->code = format->code;
|
2016-06-26 08:09:31 -03:00
|
|
|
mutex_unlock(&entity->lock);
|
2016-02-24 20:25:42 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-24 20:25:42 -03:00
|
|
|
/*
|
|
|
|
* vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler
|
|
|
|
* @subdev: V4L2 subdevice
|
2023-11-26 03:37:15 +02:00
|
|
|
* @sd_state: V4L2 subdev state
|
2016-02-24 20:25:42 -03:00
|
|
|
* @fse: Frame size enumeration
|
|
|
|
* @min_width: Minimum image width
|
|
|
|
* @min_height: Minimum image height
|
|
|
|
* @max_width: Maximum image width
|
|
|
|
* @max_height: Maximum image height
|
|
|
|
*
|
|
|
|
* This function implements the subdev enum_frame_size pad operation for
|
|
|
|
* entities that do not support scaling or cropping. It reports the given
|
|
|
|
* minimum and maximum frame width and height on the sink pad, and a fixed
|
|
|
|
* source pad size identical to the sink pad.
|
|
|
|
*/
|
|
|
|
int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev,
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2016-02-24 20:25:42 -03:00
|
|
|
struct v4l2_subdev_frame_size_enum *fse,
|
|
|
|
unsigned int min_width, unsigned int min_height,
|
|
|
|
unsigned int max_width, unsigned int max_height)
|
|
|
|
{
|
|
|
|
struct vsp1_entity *entity = to_vsp1_entity(subdev);
|
2023-11-26 03:37:15 +02:00
|
|
|
struct v4l2_subdev_state *state;
|
2016-02-24 20:25:42 -03:00
|
|
|
struct v4l2_mbus_framefmt *format;
|
2016-06-26 08:09:31 -03:00
|
|
|
int ret = 0;
|
2016-02-24 20:25:42 -03:00
|
|
|
|
2023-11-26 03:37:15 +02:00
|
|
|
state = vsp1_entity_get_state(entity, sd_state, fse->which);
|
|
|
|
if (!state)
|
2016-02-24 20:25:42 -03:00
|
|
|
return -EINVAL;
|
|
|
|
|
2023-11-12 04:14:05 +02:00
|
|
|
format = v4l2_subdev_state_get_format(state, fse->pad);
|
2016-02-24 20:25:42 -03:00
|
|
|
|
2016-06-26 08:09:31 -03:00
|
|
|
mutex_lock(&entity->lock);
|
|
|
|
|
|
|
|
if (fse->index || fse->code != format->code) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-02-24 20:25:42 -03:00
|
|
|
|
|
|
|
if (fse->pad == 0) {
|
|
|
|
fse->min_width = min_width;
|
|
|
|
fse->max_width = max_width;
|
|
|
|
fse->min_height = min_height;
|
|
|
|
fse->max_height = max_height;
|
|
|
|
} else {
|
2017-02-26 10:29:50 -03:00
|
|
|
/*
|
|
|
|
* The size on the source pad are fixed and always identical to
|
2016-02-24 20:25:42 -03:00
|
|
|
* the size on the sink pad.
|
|
|
|
*/
|
|
|
|
fse->min_width = format->width;
|
|
|
|
fse->max_width = format->width;
|
|
|
|
fse->min_height = format->height;
|
|
|
|
fse->max_height = format->height;
|
|
|
|
}
|
|
|
|
|
2016-06-26 08:09:31 -03:00
|
|
|
done:
|
|
|
|
mutex_unlock(&entity->lock);
|
|
|
|
return ret;
|
2016-02-24 20:25:42 -03:00
|
|
|
}
|
|
|
|
|
2017-11-27 14:59:45 -05:00
|
|
|
/*
|
|
|
|
* vsp1_subdev_set_pad_format - Subdev pad set_fmt handler
|
|
|
|
* @subdev: V4L2 subdevice
|
2023-11-26 03:37:15 +02:00
|
|
|
* @sd_state: V4L2 subdev state
|
2017-11-27 14:59:45 -05:00
|
|
|
* @fmt: V4L2 subdev format
|
|
|
|
* @codes: Array of supported media bus codes
|
|
|
|
* @ncodes: Number of supported media bus codes
|
|
|
|
* @min_width: Minimum image width
|
|
|
|
* @min_height: Minimum image height
|
|
|
|
* @max_width: Maximum image width
|
|
|
|
* @max_height: Maximum image height
|
|
|
|
*
|
|
|
|
* This function implements the subdev set_fmt pad operation for entities that
|
|
|
|
* do not support scaling or cropping. It defaults to the first supplied media
|
|
|
|
* bus code if the requested code isn't supported, clamps the size to the
|
|
|
|
* supplied minimum and maximum, and propagates the sink pad format to the
|
|
|
|
* source pad.
|
|
|
|
*/
|
|
|
|
int vsp1_subdev_set_pad_format(struct v4l2_subdev *subdev,
|
media: v4l2-subdev: add subdev-wide state struct
We have 'struct v4l2_subdev_pad_config' which contains configuration for
a single pad used for the TRY functionality, and an array of those
structs is passed to various v4l2_subdev_pad_ops.
I was working on subdev internal routing between pads, and realized that
there's no way to add TRY functionality for routes, which is not pad
specific configuration. Adding a separate struct for try-route config
wouldn't work either, as e.g. set-fmt needs to know the try-route
configuration to propagate the settings.
This patch adds a new struct, 'struct v4l2_subdev_state' (which at the
moment only contains the v4l2_subdev_pad_config array) and the new
struct is used in most of the places where v4l2_subdev_pad_config was
used. All v4l2_subdev_pad_ops functions taking v4l2_subdev_pad_config
are changed to instead take v4l2_subdev_state.
The changes to drivers/media/v4l2-core/v4l2-subdev.c and
include/media/v4l2-subdev.h were written by hand, and all the driver
changes were done with the semantic patch below. The spatch needs to be
applied to a select list of directories. I used the following shell
commands to apply the spatch:
dirs="drivers/media/i2c drivers/media/platform drivers/media/usb drivers/media/test-drivers/vimc drivers/media/pci drivers/staging/media"
for dir in $dirs; do spatch -j8 --dir --include-headers --no-show-diff --in-place --sp-file v4l2-subdev-state.cocci $dir; done
Note that Coccinelle chokes on a few drivers (gcc extensions?). With
minor changes we can make Coccinelle run fine, and these changes can be
reverted after spatch. The diff for these changes is:
For drivers/media/i2c/s5k5baf.c:
@@ -1481,7 +1481,7 @@ static int s5k5baf_set_selection(struct v4l2_subdev *sd,
&s5k5baf_cis_rect,
v4l2_subdev_get_try_crop(sd, cfg, PAD_CIS),
v4l2_subdev_get_try_compose(sd, cfg, PAD_CIS),
- v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT)
+ v4l2_subdev_get_try_crop(sd, cfg, PAD_OUT),
};
s5k5baf_set_rect_and_adjust(rects, rtype, &sel->r);
return 0;
For drivers/media/platform/s3c-camif/camif-capture.c:
@@ -1230,7 +1230,7 @@ static int s3c_camif_subdev_get_fmt(struct v4l2_subdev *sd,
*mf = camif->mbus_fmt;
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* crop rectangle at camera interface input */
mf->width = camif->camif_crop.width;
mf->height = camif->camif_crop.height;
@@ -1332,7 +1332,7 @@ static int s3c_camif_subdev_set_fmt(struct v4l2_subdev *sd,
}
break;
- case CAMIF_SD_PAD_SOURCE_C...CAMIF_SD_PAD_SOURCE_P:
+ case CAMIF_SD_PAD_SOURCE_C:
/* Pixel format can be only changed on the sink pad. */
mf->code = camif->mbus_fmt.code;
mf->width = crop->width;
The semantic patch is:
// <smpl>
// Change function parameter
@@
identifier func;
identifier cfg;
@@
func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...)
{
<...
- cfg
+ sd_state
...>
}
// Change function declaration parameter
@@
identifier func;
identifier cfg;
type T;
@@
T func(...,
- struct v4l2_subdev_pad_config *cfg
+ struct v4l2_subdev_state *sd_state
, ...);
// Change function return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...)
{
...
}
// Change function declaration return value
@@
identifier func;
@@
- struct v4l2_subdev_pad_config
+ struct v4l2_subdev_state
*func(...);
// Some drivers pass a local pad_cfg for a single pad to a called function. Wrap it
// inside a pad_state.
@@
identifier func;
identifier pad_cfg;
@@
func(...)
{
...
struct v4l2_subdev_pad_config pad_cfg;
+ struct v4l2_subdev_state pad_state = { .pads = &pad_cfg };
<+...
(
v4l2_subdev_call
|
sensor_call
|
isi_try_fse
|
isc_try_fse
|
saa_call_all
)
(...,
- &pad_cfg
+ &pad_state
,...)
...+>
}
// If the function uses fields from pad_config, access via state->pads
@@
identifier func;
identifier state;
@@
func(...,
struct v4l2_subdev_state *state
, ...)
{
<...
(
- state->try_fmt
+ state->pads->try_fmt
|
- state->try_crop
+ state->pads->try_crop
|
- state->try_compose
+ state->pads->try_compose
)
...>
}
// If the function accesses the filehandle, use fh->state instead
@@
struct v4l2_subdev_fh *fh;
@@
- fh->pad
+ fh->state
@@
struct v4l2_subdev_fh fh;
@@
- fh.pad
+ fh.state
// Start of vsp1 specific
@@
@@
struct vsp1_entity {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
};
@@
symbol entity;
@@
vsp1_entity_init(...)
{
...
entity->config =
- v4l2_subdev_alloc_pad_config
+ v4l2_subdev_alloc_state
(&entity->subdev);
...
}
@@
symbol entity;
@@
vsp1_entity_destroy(...)
{
...
- v4l2_subdev_free_pad_config
+ v4l2_subdev_free_state
(entity->config);
...
}
@exists@
identifier func =~ "(^vsp1.*)|(hsit_set_format)|(sru_enum_frame_size)|(sru_set_format)|(uif_get_selection)|(uif_set_selection)|(uds_enum_frame_size)|(uds_set_format)|(brx_set_format)|(brx_get_selection)|(histo_get_selection)|(histo_set_selection)|(brx_set_selection)";
symbol config;
@@
func(...) {
...
- struct v4l2_subdev_pad_config *config;
+ struct v4l2_subdev_state *config;
...
}
// End of vsp1 specific
// Start of rcar specific
@@
identifier sd;
identifier pad_cfg;
@@
rvin_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
// End of rcar specific
// Start of rockchip specific
@@
identifier func =~ "(rkisp1_rsz_get_pad_fmt)|(rkisp1_rsz_get_pad_crop)|(rkisp1_rsz_register)";
symbol rsz;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = rsz->pad_cfg };
...
- rsz->pad_cfg
+ &state
...
}
@@
identifier func =~ "(rkisp1_isp_get_pad_fmt)|(rkisp1_isp_get_pad_crop)";
symbol isp;
symbol pad_cfg;
@@
func(...)
{
+ struct v4l2_subdev_state state = { .pads = isp->pad_cfg };
...
- isp->pad_cfg
+ &state
...
}
@@
symbol rkisp1;
symbol isp;
symbol pad_cfg;
@@
rkisp1_isp_register(...)
{
+ struct v4l2_subdev_state state = { .pads = rkisp1->isp.pad_cfg };
...
- rkisp1->isp.pad_cfg
+ &state
...
}
// End of rockchip specific
// Start of tegra-video specific
@@
identifier sd;
identifier pad_cfg;
@@
__tegra_channel_try_format(...)
{
...
- struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_state *sd_state;
...
- pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+ sd_state = v4l2_subdev_alloc_state(sd);
<...
- pad_cfg
+ sd_state
...>
- v4l2_subdev_free_pad_config(pad_cfg);
+ v4l2_subdev_free_state(sd_state);
...
}
@@
identifier sd_state;
@@
__tegra_channel_try_format(...)
{
...
struct v4l2_subdev_state *sd_state;
<...
- sd_state->try_crop
+ sd_state->pads->try_crop
...>
}
// End of tegra-video specific
// </smpl>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-10 17:55:58 +03:00
|
|
|
struct v4l2_subdev_state *sd_state,
|
2017-11-27 14:59:45 -05:00
|
|
|
struct v4l2_subdev_format *fmt,
|
|
|
|
const unsigned int *codes, unsigned int ncodes,
|
|
|
|
unsigned int min_width, unsigned int min_height,
|
|
|
|
unsigned int max_width, unsigned int max_height)
|
|
|
|
{
|
|
|
|
struct vsp1_entity *entity = to_vsp1_entity(subdev);
|
2023-11-26 03:37:15 +02:00
|
|
|
struct v4l2_subdev_state *state;
|
2017-11-27 14:59:45 -05:00
|
|
|
struct v4l2_mbus_framefmt *format;
|
2017-11-27 19:27:32 -05:00
|
|
|
struct v4l2_rect *selection;
|
2017-11-27 14:59:45 -05:00
|
|
|
unsigned int i;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mutex_lock(&entity->lock);
|
|
|
|
|
2023-11-26 03:37:15 +02:00
|
|
|
state = vsp1_entity_get_state(entity, sd_state, fmt->which);
|
|
|
|
if (!state) {
|
2017-11-27 14:59:45 -05:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2023-11-12 04:14:05 +02:00
|
|
|
format = v4l2_subdev_state_get_format(state, fmt->pad);
|
2017-11-27 14:59:45 -05:00
|
|
|
|
|
|
|
if (fmt->pad == entity->source_pad) {
|
|
|
|
/* The output format can't be modified. */
|
|
|
|
fmt->format = *format;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default to the first media bus code if the requested format is not
|
|
|
|
* supported.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ncodes; ++i) {
|
|
|
|
if (fmt->format.code == codes[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
format->code = i < ncodes ? codes[i] : codes[0];
|
|
|
|
format->width = clamp_t(unsigned int, fmt->format.width,
|
|
|
|
min_width, max_width);
|
|
|
|
format->height = clamp_t(unsigned int, fmt->format.height,
|
|
|
|
min_height, max_height);
|
|
|
|
format->field = V4L2_FIELD_NONE;
|
2025-04-30 02:29:00 +03:00
|
|
|
|
|
|
|
format->colorspace = fmt->format.colorspace;
|
|
|
|
format->xfer_func = fmt->format.xfer_func;
|
|
|
|
format->ycbcr_enc = fmt->format.ycbcr_enc;
|
|
|
|
format->quantization = fmt->format.quantization;
|
|
|
|
|
|
|
|
vsp1_entity_adjust_color_space(format);
|
2017-11-27 14:59:45 -05:00
|
|
|
|
|
|
|
fmt->format = *format;
|
|
|
|
|
|
|
|
/* Propagate the format to the source pad. */
|
2023-11-12 04:14:05 +02:00
|
|
|
format = v4l2_subdev_state_get_format(state, entity->source_pad);
|
2017-11-27 14:59:45 -05:00
|
|
|
*format = fmt->format;
|
|
|
|
|
2018-08-31 10:40:44 -04:00
|
|
|
/* Reset the crop and compose rectangles. */
|
2023-11-12 04:14:05 +02:00
|
|
|
selection = v4l2_subdev_state_get_crop(state, fmt->pad);
|
2017-11-27 19:27:32 -05:00
|
|
|
selection->left = 0;
|
|
|
|
selection->top = 0;
|
|
|
|
selection->width = format->width;
|
|
|
|
selection->height = format->height;
|
|
|
|
|
2023-11-12 04:14:05 +02:00
|
|
|
selection = v4l2_subdev_state_get_compose(state, fmt->pad);
|
2017-11-27 19:27:32 -05:00
|
|
|
selection->left = 0;
|
|
|
|
selection->top = 0;
|
|
|
|
selection->width = format->width;
|
|
|
|
selection->height = format->height;
|
|
|
|
|
2017-11-27 14:59:45 -05:00
|
|
|
done:
|
|
|
|
mutex_unlock(&entity->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-11-27 11:07:44 +02:00
|
|
|
static int vsp1_entity_init_state(struct v4l2_subdev *subdev,
|
|
|
|
struct v4l2_subdev_state *sd_state)
|
|
|
|
{
|
|
|
|
unsigned int pad;
|
|
|
|
|
|
|
|
/* Initialize all pad formats with default values. */
|
|
|
|
for (pad = 0; pad < subdev->entity.num_pads - 1; ++pad) {
|
|
|
|
struct v4l2_subdev_format format = {
|
|
|
|
.pad = pad,
|
|
|
|
.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY
|
|
|
|
: V4L2_SUBDEV_FORMAT_ACTIVE,
|
|
|
|
};
|
|
|
|
|
|
|
|
v4l2_subdev_call(subdev, pad, set_fmt, sd_state, &format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct v4l2_subdev_internal_ops vsp1_entity_internal_ops = {
|
|
|
|
.init_state = vsp1_entity_init_state,
|
|
|
|
};
|
|
|
|
|
2013-06-04 11:22:30 -03:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Media Operations
|
|
|
|
*/
|
|
|
|
|
2017-06-25 20:15:22 +03:00
|
|
|
static inline struct vsp1_entity *
|
|
|
|
media_entity_to_vsp1_entity(struct media_entity *entity)
|
|
|
|
{
|
|
|
|
return container_of(entity, struct vsp1_entity, subdev.entity);
|
|
|
|
}
|
|
|
|
|
2016-09-07 09:09:53 -03:00
|
|
|
static int vsp1_entity_link_setup_source(const struct media_pad *source_pad,
|
|
|
|
const struct media_pad *sink_pad,
|
|
|
|
u32 flags)
|
2013-06-04 11:22:30 -03:00
|
|
|
{
|
|
|
|
struct vsp1_entity *source;
|
|
|
|
|
2016-09-07 09:09:53 -03:00
|
|
|
source = media_entity_to_vsp1_entity(source_pad->entity);
|
2013-06-04 11:22:30 -03:00
|
|
|
|
|
|
|
if (!source->route)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (flags & MEDIA_LNK_FL_ENABLED) {
|
2016-09-07 09:09:53 -03:00
|
|
|
struct vsp1_entity *sink
|
|
|
|
= media_entity_to_vsp1_entity(sink_pad->entity);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fan-out is limited to one for the normal data path plus
|
|
|
|
* optional HGO and HGT. We ignore the HGO and HGT here.
|
|
|
|
*/
|
|
|
|
if (sink->type != VSP1_ENTITY_HGO &&
|
|
|
|
sink->type != VSP1_ENTITY_HGT) {
|
|
|
|
if (source->sink)
|
|
|
|
return -EBUSY;
|
2017-06-25 20:15:22 +03:00
|
|
|
source->sink = sink;
|
2016-09-07 09:09:53 -03:00
|
|
|
source->sink_pad = sink_pad->index;
|
|
|
|
}
|
2013-06-04 11:22:30 -03:00
|
|
|
} else {
|
|
|
|
source->sink = NULL;
|
2013-07-10 18:37:27 -03:00
|
|
|
source->sink_pad = 0;
|
2013-06-04 11:22:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-07 09:09:53 -03:00
|
|
|
static int vsp1_entity_link_setup_sink(const struct media_pad *source_pad,
|
|
|
|
const struct media_pad *sink_pad,
|
|
|
|
u32 flags)
|
|
|
|
{
|
|
|
|
struct vsp1_entity *sink;
|
2017-06-25 20:15:22 +03:00
|
|
|
struct vsp1_entity *source;
|
2016-09-07 09:09:53 -03:00
|
|
|
|
|
|
|
sink = media_entity_to_vsp1_entity(sink_pad->entity);
|
2017-06-25 20:15:22 +03:00
|
|
|
source = media_entity_to_vsp1_entity(source_pad->entity);
|
2016-09-07 09:09:53 -03:00
|
|
|
|
|
|
|
if (flags & MEDIA_LNK_FL_ENABLED) {
|
|
|
|
/* Fan-in is limited to one. */
|
|
|
|
if (sink->sources[sink_pad->index])
|
|
|
|
return -EBUSY;
|
|
|
|
|
2017-06-25 20:15:22 +03:00
|
|
|
sink->sources[sink_pad->index] = source;
|
2016-09-07 09:09:53 -03:00
|
|
|
} else {
|
|
|
|
sink->sources[sink_pad->index] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vsp1_entity_link_setup(struct media_entity *entity,
|
|
|
|
const struct media_pad *local,
|
|
|
|
const struct media_pad *remote, u32 flags)
|
|
|
|
{
|
|
|
|
if (local->flags & MEDIA_PAD_FL_SOURCE)
|
|
|
|
return vsp1_entity_link_setup_source(local, remote, flags);
|
|
|
|
else
|
|
|
|
return vsp1_entity_link_setup_sink(remote, local, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vsp1_entity_remote_pad - Find the pad at the remote end of a link
|
|
|
|
* @pad: Pad at the local end of the link
|
|
|
|
*
|
|
|
|
* Search for a remote pad connected to the given pad by iterating over all
|
|
|
|
* links originating or terminating at that pad until an enabled link is found.
|
|
|
|
*
|
|
|
|
* Our link setup implementation guarantees that the output fan-out will not be
|
|
|
|
* higher than one for the data pipelines, except for the links to the HGO and
|
|
|
|
* HGT that can be enabled in addition to a regular data link. When traversing
|
|
|
|
* outgoing links this function ignores HGO and HGT entities and should thus be
|
2022-06-25 18:02:24 +01:00
|
|
|
* used in place of the generic media_pad_remote_pad_first() function to
|
|
|
|
* traverse data pipelines.
|
2016-09-07 09:09:53 -03:00
|
|
|
*
|
|
|
|
* Return a pointer to the pad at the remote end of the first found enabled
|
|
|
|
* link, or NULL if no enabled link has been found.
|
|
|
|
*/
|
|
|
|
struct media_pad *vsp1_entity_remote_pad(struct media_pad *pad)
|
|
|
|
{
|
|
|
|
struct media_link *link;
|
|
|
|
|
|
|
|
list_for_each_entry(link, &pad->entity->links, list) {
|
|
|
|
struct vsp1_entity *entity;
|
|
|
|
|
|
|
|
if (!(link->flags & MEDIA_LNK_FL_ENABLED))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If we're the sink the source will never be an HGO or HGT. */
|
|
|
|
if (link->sink == pad)
|
|
|
|
return link->source;
|
|
|
|
|
|
|
|
if (link->source != pad)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If the sink isn't a subdevice it can't be an HGO or HGT. */
|
|
|
|
if (!is_media_entity_v4l2_subdev(link->sink->entity))
|
|
|
|
return link->sink;
|
|
|
|
|
|
|
|
entity = media_entity_to_vsp1_entity(link->sink->entity);
|
|
|
|
if (entity->type != VSP1_ENTITY_HGO &&
|
|
|
|
entity->type != VSP1_ENTITY_HGT)
|
|
|
|
return link->sink;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-04 11:22:30 -03:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Initialization
|
|
|
|
*/
|
|
|
|
|
2016-02-24 19:10:04 -03:00
|
|
|
#define VSP1_ENTITY_ROUTE(ent) \
|
|
|
|
{ VSP1_ENTITY_##ent, 0, VI6_DPR_##ent##_ROUTE, \
|
|
|
|
{ VI6_DPR_NODE_##ent }, VI6_DPR_NODE_##ent }
|
|
|
|
|
|
|
|
#define VSP1_ENTITY_ROUTE_RPF(idx) \
|
|
|
|
{ VSP1_ENTITY_RPF, idx, VI6_DPR_RPF_ROUTE(idx), \
|
|
|
|
{ 0, }, VI6_DPR_NODE_RPF(idx) }
|
|
|
|
|
|
|
|
#define VSP1_ENTITY_ROUTE_UDS(idx) \
|
|
|
|
{ VSP1_ENTITY_UDS, idx, VI6_DPR_UDS_ROUTE(idx), \
|
|
|
|
{ VI6_DPR_NODE_UDS(idx) }, VI6_DPR_NODE_UDS(idx) }
|
|
|
|
|
2017-11-27 15:45:42 -05:00
|
|
|
#define VSP1_ENTITY_ROUTE_UIF(idx) \
|
|
|
|
{ VSP1_ENTITY_UIF, idx, VI6_DPR_UIF_ROUTE(idx), \
|
|
|
|
{ VI6_DPR_NODE_UIF(idx) }, VI6_DPR_NODE_UIF(idx) }
|
|
|
|
|
2016-02-24 19:10:04 -03:00
|
|
|
#define VSP1_ENTITY_ROUTE_WPF(idx) \
|
|
|
|
{ VSP1_ENTITY_WPF, idx, 0, \
|
|
|
|
{ VI6_DPR_NODE_WPF(idx) }, VI6_DPR_NODE_WPF(idx) }
|
|
|
|
|
2013-07-10 18:37:27 -03:00
|
|
|
static const struct vsp1_route vsp1_routes[] = {
|
2025-04-01 16:22:01 +02:00
|
|
|
{ VSP1_ENTITY_IIF, 0, VI6_DPR_BRU_ROUTE,
|
|
|
|
{ VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1),
|
|
|
|
VI6_DPR_NODE_BRU_IN(3) }, VI6_DPR_NODE_WPF(0) },
|
2017-05-25 00:16:57 +03:00
|
|
|
{ VSP1_ENTITY_BRS, 0, VI6_DPR_ILV_BRS_ROUTE,
|
|
|
|
{ VI6_DPR_NODE_BRS_IN(0), VI6_DPR_NODE_BRS_IN(1) }, 0 },
|
2013-07-10 18:03:46 -03:00
|
|
|
{ VSP1_ENTITY_BRU, 0, VI6_DPR_BRU_ROUTE,
|
|
|
|
{ VI6_DPR_NODE_BRU_IN(0), VI6_DPR_NODE_BRU_IN(1),
|
2015-09-07 08:05:39 -03:00
|
|
|
VI6_DPR_NODE_BRU_IN(2), VI6_DPR_NODE_BRU_IN(3),
|
2016-02-24 19:10:04 -03:00
|
|
|
VI6_DPR_NODE_BRU_IN(4) }, VI6_DPR_NODE_BRU_OUT },
|
2015-11-11 23:04:44 -02:00
|
|
|
VSP1_ENTITY_ROUTE(CLU),
|
2016-02-24 20:40:22 -03:00
|
|
|
{ VSP1_ENTITY_HGO, 0, 0, { 0, }, 0 },
|
2016-09-06 11:38:56 -03:00
|
|
|
{ VSP1_ENTITY_HGT, 0, 0, { 0, }, 0 },
|
2016-02-24 19:10:04 -03:00
|
|
|
VSP1_ENTITY_ROUTE(HSI),
|
|
|
|
VSP1_ENTITY_ROUTE(HST),
|
2017-06-21 16:10:18 +03:00
|
|
|
{ VSP1_ENTITY_LIF, 0, 0, { 0, }, 0 },
|
|
|
|
{ VSP1_ENTITY_LIF, 1, 0, { 0, }, 0 },
|
2016-02-24 19:10:04 -03:00
|
|
|
VSP1_ENTITY_ROUTE(LUT),
|
|
|
|
VSP1_ENTITY_ROUTE_RPF(0),
|
|
|
|
VSP1_ENTITY_ROUTE_RPF(1),
|
|
|
|
VSP1_ENTITY_ROUTE_RPF(2),
|
|
|
|
VSP1_ENTITY_ROUTE_RPF(3),
|
|
|
|
VSP1_ENTITY_ROUTE_RPF(4),
|
|
|
|
VSP1_ENTITY_ROUTE(SRU),
|
|
|
|
VSP1_ENTITY_ROUTE_UDS(0),
|
|
|
|
VSP1_ENTITY_ROUTE_UDS(1),
|
|
|
|
VSP1_ENTITY_ROUTE_UDS(2),
|
2017-11-27 15:45:42 -05:00
|
|
|
VSP1_ENTITY_ROUTE_UIF(0), /* Named UIF4 in the documentation */
|
|
|
|
VSP1_ENTITY_ROUTE_UIF(1), /* Named UIF5 in the documentation */
|
2016-02-24 19:10:04 -03:00
|
|
|
VSP1_ENTITY_ROUTE_WPF(0),
|
|
|
|
VSP1_ENTITY_ROUTE_WPF(1),
|
|
|
|
VSP1_ENTITY_ROUTE_WPF(2),
|
|
|
|
VSP1_ENTITY_ROUTE_WPF(3),
|
2013-07-10 18:37:27 -03:00
|
|
|
};
|
|
|
|
|
2013-06-04 11:22:30 -03:00
|
|
|
int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
|
2015-11-15 19:42:01 -02:00
|
|
|
const char *name, unsigned int num_pads,
|
2016-02-15 22:10:26 -02:00
|
|
|
const struct v4l2_subdev_ops *ops, u32 function)
|
2013-06-04 11:22:30 -03:00
|
|
|
{
|
media: subdev: add subdev state locking
The V4L2 subdevs have managed without centralized locking for the state
(previously pad_config), as the try-state is supposedly safe (although I
believe two TRY ioctls for the same fd would race), and the
active-state, and its locking, is managed by the drivers internally.
We now have active-state in a centralized position, and need locking.
Strictly speaking the locking is only needed for new drivers that use
the new state, as the current drivers continue behaving as they used to.
However, active-state locking is complicated by the fact that currently
the real active-state of a subdev is split into multiple parts: the new
v4l2_subdev_state, subdev control state, and subdev's internal state.
In the future all these three states should be combined into one state
(the v4l2_subdev_state), and then a single lock for the state should be
sufficient.
But to solve the current split-state situation we need to share locks
between the three states. This is accomplished by using the same lock
management as the control handler does: we use a pointer to a mutex,
allowing the driver to override the default mutex. Thus the driver can
do e.g.:
sd->state_lock = sd->ctrl_handler->lock;
before calling v4l2_subdev_init_finalize(), resulting in sharing the
same lock between the states and the controls.
The locking model for active-state is such that any subdev op that gets
the state as a parameter expects the state to be already locked by the
caller, and expects the caller to release the lock.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-04-12 10:42:46 +01:00
|
|
|
static struct lock_class_key key;
|
2015-11-15 19:42:01 -02:00
|
|
|
struct v4l2_subdev *subdev;
|
2013-06-04 11:22:30 -03:00
|
|
|
unsigned int i;
|
2015-11-15 19:42:01 -02:00
|
|
|
int ret;
|
2013-06-04 11:22:30 -03:00
|
|
|
|
2013-07-10 18:37:27 -03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(vsp1_routes); ++i) {
|
|
|
|
if (vsp1_routes[i].type == entity->type &&
|
|
|
|
vsp1_routes[i].index == entity->index) {
|
|
|
|
entity->route = &vsp1_routes[i];
|
2013-06-04 11:22:30 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 18:37:27 -03:00
|
|
|
if (i == ARRAY_SIZE(vsp1_routes))
|
2013-06-04 11:22:30 -03:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-06-26 08:09:31 -03:00
|
|
|
mutex_init(&entity->lock);
|
|
|
|
|
2013-06-04 11:22:30 -03:00
|
|
|
entity->vsp1 = vsp1;
|
|
|
|
entity->source_pad = num_pads - 1;
|
|
|
|
|
2015-11-15 19:14:22 -02:00
|
|
|
/* Allocate and initialize pads. */
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 14:07:58 -07:00
|
|
|
entity->pads = devm_kcalloc(vsp1->dev,
|
|
|
|
num_pads, sizeof(*entity->pads),
|
2013-06-04 11:22:30 -03:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (entity->pads == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < num_pads - 1; ++i)
|
|
|
|
entity->pads[i].flags = MEDIA_PAD_FL_SINK;
|
|
|
|
|
2016-09-07 09:09:53 -03:00
|
|
|
entity->sources = devm_kcalloc(vsp1->dev, max(num_pads - 1, 1U),
|
|
|
|
sizeof(*entity->sources), GFP_KERNEL);
|
|
|
|
if (entity->sources == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Single-pad entities only have a sink. */
|
|
|
|
entity->pads[num_pads - 1].flags = num_pads > 1 ? MEDIA_PAD_FL_SOURCE
|
|
|
|
: MEDIA_PAD_FL_SINK;
|
2013-06-04 11:22:30 -03:00
|
|
|
|
|
|
|
/* Initialize the media entity. */
|
2015-11-15 19:42:01 -02:00
|
|
|
ret = media_entity_pads_init(&entity->subdev.entity, num_pads,
|
|
|
|
entity->pads);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Initialize the V4L2 subdev. */
|
|
|
|
subdev = &entity->subdev;
|
|
|
|
v4l2_subdev_init(subdev, ops);
|
2023-11-27 11:07:44 +02:00
|
|
|
subdev->internal_ops = &vsp1_entity_internal_ops;
|
2015-11-15 19:42:01 -02:00
|
|
|
|
2016-02-15 22:10:26 -02:00
|
|
|
subdev->entity.function = function;
|
2015-11-15 19:42:01 -02:00
|
|
|
subdev->entity.ops = &vsp1->media_ops;
|
|
|
|
subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
|
|
|
|
|
|
|
|
snprintf(subdev->name, sizeof(subdev->name), "%s %s",
|
|
|
|
dev_name(vsp1->dev), name);
|
|
|
|
|
2023-11-27 11:07:44 +02:00
|
|
|
vsp1_entity_init_state(subdev, NULL);
|
2015-11-15 19:42:01 -02:00
|
|
|
|
2017-02-26 10:29:50 -03:00
|
|
|
/*
|
2023-11-26 03:37:15 +02:00
|
|
|
* Allocate the subdev state to store formats and selection
|
2015-11-15 19:14:22 -02:00
|
|
|
* rectangles.
|
|
|
|
*/
|
2022-04-12 10:42:42 +01:00
|
|
|
/*
|
|
|
|
* FIXME: Drop this call, drivers are not supposed to use
|
|
|
|
* __v4l2_subdev_state_alloc().
|
|
|
|
*/
|
2023-11-26 03:37:15 +02:00
|
|
|
entity->state = __v4l2_subdev_state_alloc(&entity->subdev,
|
|
|
|
"vsp1:state->lock", &key);
|
|
|
|
if (IS_ERR(entity->state)) {
|
2015-11-15 19:14:22 -02:00
|
|
|
media_entity_cleanup(&entity->subdev.entity);
|
2023-11-26 03:37:15 +02:00
|
|
|
return PTR_ERR(entity->state);
|
2015-11-15 19:14:22 -02:00
|
|
|
}
|
|
|
|
|
2015-11-15 19:42:01 -02:00
|
|
|
return 0;
|
2013-06-04 11:22:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void vsp1_entity_destroy(struct vsp1_entity *entity)
|
|
|
|
{
|
2015-11-17 12:23:23 -02:00
|
|
|
if (entity->ops && entity->ops->destroy)
|
|
|
|
entity->ops->destroy(entity);
|
2013-07-10 12:03:30 -03:00
|
|
|
if (entity->subdev.ctrl_handler)
|
|
|
|
v4l2_ctrl_handler_free(entity->subdev.ctrl_handler);
|
2023-11-26 03:37:15 +02:00
|
|
|
__v4l2_subdev_state_free(entity->state);
|
2013-06-04 11:22:30 -03:00
|
|
|
media_entity_cleanup(&entity->subdev.entity);
|
|
|
|
}
|