Generic line based metadata support, internal pads
Subsystems (6)
Sakari Ailus
maintainerv4 cover Generic line based metadata support, internal pads
Hi folks,
Here are a few patches to add support generic, line based metadata as well as internal pads. While the amount of code is not very large, to the contrary it is quite small actually IMO, I presume what this is about and why it is being proposed requires some explaining.
Metadata mbus codes and formats have existed for some time in V4L2. They however have been only used by drivers that produce the data itself and effectively this metadata has always been statistics of some sort (at least when it comes to ISPs). What is different here is that we intend to add support for metadata originating from camera sensors.
Camera sensors produce different kinds of metadata, embedded data (usually register address--value pairs used to capture the frame, in a more or less sensor specific format), histograms (in a very sensor specific format), dark pixels etc. The number of these formats is probably going to be about as large as image data formats if not larger, as the image data formats are much better standardised but a smaller subset of them will be supported by V4L2, at least initially but possibly much more in the long run.
Having this many device specific formats would be a major problem for all the other drivers along that pipeline (not to mention the users of those drivers), including bridge (e.g. CSI-2 to parallel) but especially CSI-2 receiver drivers that have DMA: the poor driver developer would not only need to know camera sensor specific formats but to choose the specific packing of that format suitable for the DMA used by the hardware. It is unlikely many of these would ever get tested while being present on the driver API. Also adding new sensors with new embedded data formats would involve updating all bridge and CSI-2 receiver drivers. I don't expect this to be a workable approach.
Instead what I'm proposing is to use specific metadata formats on the sensor devices only, on internal pads (more about those soon) of the sensors, only visible in the UAPI, and then generic mbus formats along the pipeline and finally generic V4L2 metadata formats on the DMAs (specific to bit depth and packing). This would unsnarl the two, defining what data there is (specific mbus code) and how that is transported and packed (generic mbus codes and V4L2 formats).
The user space would be required to "know" the path of that data from the sensor's internal pad to the V4L2 video node. I do not see this as these devices require at least some knowledge of the pipeline, i.e. hardware at hand. Separating what the data means and how it is packed may even be
beneficial: it allows separating code that interprets the data (sensor internal mbus code) from the code that accesses it (packing).
These formats are in practice line based, meaning that there may be padding at the end of the line, depending on the bus as well as the DMA. If non-line based formats are needed, it is always possible to set the "height" field to 1.
The internal (source) pads are an alternative to source routes [1]. The source routes were not universally liked and I do have to say I like re-using existing interface concepts (pads and everything you can do with pads, including access format, selections etc.) wherever it makes sense, instead of duplicating functionality.
Effectively internal source pads behave mostly just like sink pads, but they describe a flow of data that originates from a sub-device instead of arriving to a sub-device. The SUBDEV_S_ROUTING IOCTLs are used to enable and disable routes from internal source pads to sub-device's source pads. The subdev format IOCTLs are usable, too, so one can find which subdev format is available on given internal source pad.
This set depends on these patches:
<URL:https://lore.kernel.org/linux-media/[email protected]/T/#t>
I've also pushed these here and I'll keep updating the branch, I've also included untested OV2740 patches:
<URL:https://git.linuxtv.org/sailus/media_tree.git/log/?h=metadata>
Questions and comments are most welcome.
I have used IMX219 as an example on routing in a sensor driver in this version. I also hope I can add OV2740 support in the next version after testing the patches.
[1] <URL:https://lore.kernel.org/linux-media/[email protected]/>
since v3:
- Separate preparation patches from this set.
- Add a definition for "Data unit", a pixel that is not image data and use it instead in format documentation.
- Fix more numbered lists in dev-subdev.rst.
- Remove a redundant definition for V4L2_META_FMT_GENERIC_CSI2_2_24 --- V4L2_META_FMT_GENERIC_CSI2_12 can be used instead.
- Use "X" instead of "p" to denote padding in format documentation.
- Use IMX219 in examples instead of CCS.
- Document that the generic V4L2 CSI-2 metadata formats use padding defined in CSI-2 spec and packing defined in CCS spec.
- Add patches to align [GS]_ROUTING behaviour with V4L2. This means mainly returning configured routes as part of S_ROUTING as well. "len_routes" field is added to denote the length of the array and having more routes than fits in the array is no longer an error. Also added more reserved fields.
- Added trivial support for S_ROUTING (via G_ROUTING implementation) for use in drivers with static-only routes.
- Added helper functions to obtain mbus format as well as crop and compose rectangles that are streams-independent.
- Added a patch to define generic CSI-2 long packet types.
- Removed MEDIA_BUS_FMT_IS_META() macro. It didn't seem useful in the end.
- Use a single CCS embedded data format. The bit depth can be selected using the meta stream on the source pad.
- Fix mbus code numbers (there were holes due to removed redundant formats).
- Fix generic mbus code documentation (byte was being used instead of bit).
- Fix spelling of "length".
- Added a patch to remove v4l2_subdev_enable_streams_api that disables streams API. This should be merged once libcamera support for streams works nicely.
- Don't use strings in printing frame descriptor flags.
- Warn on string truncation in printing frame descriptor.
since v2:
- Add a better example, with formats.
- Add CCS static data media bus codes.
- Added an example demonstrating the use of internal pads. --- Is the level of detail enough for the purpose?
- Improved documentation.
- Added a macro to tell whether a format is a metadata format. (Documentation could be added.)
- A small ReST syntax fix in the same section.
- Drop leftovers of a patch checking for the INTERNAL_SOURCE flag.
since v1:
- Make the new pad flag just "INTERNAL", requiring either SINK or SOURCE pad flag to accompany it. Removed the union in struct v4l2_subdev_route.
- Add the term "stream" to MC glossary.
- Improved and fixed documentation (according to comments).
- Note these formats are little endian.
- Remove 1X8 from the names of the mbus codes. These formats have generally 8 bits per pixel.
- Fix mbus code numbering (had holes in RFC).
- Add new metadata fields to debug prints.
- Fix a minor documentation build issue.
Sakari Ailus (23):
media: mc: Add INTERNAL pad flag
media: uapi: Add generic serial metadata mbus formats
media: uapi: Document which mbus format fields are valid for metadata
media: uapi: Add generic 8-bit metadata format definitions
media: v4l: Support line-based metadata capture
media: uapi: ccs: Add media bus code for MIPI CCS embedded data
media: Documentation: ccs: Document routing
media: Documentation: Additional streams generally don't harm capture
media: Documentation: Document embedded data guidelines for camera
sensors
media: Documentation: v4l: Document source routes
media: Documentation: Document S_ROUTING behaviour
media: v4l: subdev: Add helpers for format, crop and compose pointers
media: ccs: Move ccs_validate_csi_data_format up
media: ccs: Support frame descriptors
media: ccs: Add support for embedded data stream
media: Add MIPI CSI-2 generic long packet type definition
media: v4l: subdev: Move G_ROUTING handling below S_ROUTING
media: v4l: subdev: Copy argument back to user also for S_ROUTING
media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
media: v4l: subdev: Return routes set using S_ROUTING
media: uapi: Allow a larger number of routes than there's room for
media: v4l: subdev: Add trivial set_routing support
media: uapi: v4l: subdev: Enable streams API
.../driver-api/media/camera-sensor.rst | 23 + .../userspace-api/media/drivers/ccs.rst | 34 +- .../userspace-api/media/glossary.rst | 14 + .../media/mediactl/media-types.rst | 6 + .../userspace-api/media/v4l/dev-meta.rst | 15 + .../userspace-api/media/v4l/dev-subdev.rst | 208 ++++++++- .../userspace-api/media/v4l/meta-formats.rst | 1 + .../media/v4l/metafmt-generic.rst | 304 +++++++++++++ .../media/v4l/subdev-formats.rst | 288 ++++++++++++ .../media/v4l/vidioc-enum-fmt.rst | 7 + .../media/v4l/vidioc-subdev-g-routing.rst | 40 +- .../media/videodev2.h.rst.exceptions | 1 + drivers/media/i2c/ccs/ccs-core.c | 419 ++++++++++++++++-- drivers/media/i2c/ccs/ccs-quirk.h | 7 + drivers/media/i2c/ccs/ccs.h | 19 +- drivers/media/mc/mc-entity.c | 10 +- drivers/media/v4l2-core/v4l2-ioctl.c | 19 +- drivers/media/v4l2-core/v4l2-subdev.c | 132 +++--- include/media/mipi-csi2.h | 1 + include/media/v4l2-subdev.h | 58 +++ include/uapi/linux/media-bus-format.h | 12 + include/uapi/linux/media.h | 1 + include/uapi/linux/v4l2-mediabus.h | 18 +- include/uapi/linux/v4l2-subdev.h | 8 +- include/uapi/linux/videodev2.h | 18 + 25 files changed, 1534 insertions(+), 129 deletions(-) create mode 100644 Documentation/userspace-api/media/v4l/metafmt-generic.rst
base-commit: 1eb313b9ec4b45825601f4dbf9bd7b441e96f9cc
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 1/23 media: mc: Add INTERNAL pad flag
Internal source pads will be used as routing endpoints in V4L2 [GS]_ROUTING IOCTLs, to indicate that the stream begins in the entity.
Also prevent creating links to pads that have been flagged as internal and initialising source pads with internal flag set.
--- Documentation/userspace-api/media/glossary.rst | 6 ++++++ .../userspace-api/media/mediactl/media-types.rst | 6 ++++++ drivers/media/mc/mc-entity.c | 10 ++++++++-- include/uapi/linux/media.h | 1 + 4 files changed, 21 insertions(+), 2 deletions(-)
Documentation/userspace-api/media/glossary.rst +6 -0
@@ -173,6 +173,12 @@ Glossary An integrated circuit that integrates all components of a computer or other electronic systems. +_media-glossary-stream: + Stream + A distinct flow of data (image data or metadata) over a media pipeline + from source to sink. A source may be e.g. an image sensor and a sink + e.g. a memory buffer. + V4L2 API **V4L2 userspace API**
Documentation/userspace-api/media/mediactl/media-types.rst +6 -0
@@ -361,6 +361,7 @@ Types and flags used to represent the media graph elements .. _MEDIA-PAD-FL-SINK: .. _MEDIA-PAD-FL-SOURCE: .. _MEDIA-PAD-FL-MUST-CONNECT: +.. _MEDIA-PAD-FL-INTERNAL: .. flat-table:: Media pad flags :header-rows: 0
@@ -382,6 +383,11 @@ Types and flags used to represent the media graph elements when this flag isn't set; the absence of the flag doesn't imply there is none. + * - ``MEDIA_PAD_FL_INTERNAL`` + - The internal flag indicates an internal pad that has no external + connections. Such a pad shall not be connected with a link. The + internal flag indicates that the :ref:``stream + <media-glossary-stream>`` either starts or ends in the entity. One and only one of ``MEDIA_PAD_FL_SINK`` and ``MEDIA_PAD_FL_SOURCE`` must be set for every pad.
drivers/media/mc/mc-entity.c +8 -2
@@ -213,7 +213,9 @@ int media_entity_pads_init(struct media_entity *entity, u16 num_pads, iter->index = i++;if (hweight32 (iter->flags & (MEDIA_PAD_FL_SINK | -MEDIA_PAD_FL_SOURCE )) !=1 ) { +MEDIA_PAD_FL_SOURCE )) !=1 || + (iter->flags &MEDIA_PAD_FL_INTERNAL && + !(iter->flags &MEDIA_PAD_FL_SINK ))) { ret = -EINVAL ;break ; }
@@ -1075,7 +1077,8 @@ int media_get_pad_index(struct media_entity *entity, u32 pad_type,for (i =0 ; i < entity->num_pads; i++) {if ((entity->pads[i].flags & - (MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_SOURCE )) != pad_type) + (MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_SOURCE | +MEDIA_PAD_FL_INTERNAL )) != pad_type)continue ;if (entity->pads[i].sig_type == sig_type)
@@ -1100,6 +1103,9 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,return -EINVAL ;if (WARN_ON (!(sink->pads[sink_pad].flags &MEDIA_PAD_FL_SINK )))return -EINVAL ; +if (WARN_ON (source->pads[source_pad].flags &MEDIA_PAD_FL_INTERNAL ) || +WARN_ON (source->pads[sink_pad].flags &MEDIA_PAD_FL_INTERNAL )) +return -EINVAL ; link =media_add_link (&source->links);if (link ==NULL )
include/uapi/linux/media.h +1 -0
@@ -208,6 +208,7 @@ struct media_entity_desc {#define MEDIA_PAD_FL_SINK (1U << 0)#define MEDIA_PAD_FL_SOURCE (1U << 1)#define MEDIA_PAD_FL_MUST_CONNECT (1U << 2) +#define MEDIA_PAD_FL_INTERNAL (1U << 3)struct media_pad_desc {__u32 entity;/* entity ID */
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 2/23 media: uapi: Add generic serial metadata mbus formats
In reply to Sakari AilusAdd generic serial metadata mbus formats. These formats describe data width and packing but not the content itself. The reason for specifying such formats is that the formats as such are fairly device specific but they are still handled by CSI-2 receiver drivers that should not be aware of device specific formats. What makes generic metadata formats possible is that these formats are parsed by software only, after capturing the data to system memory.
Also add a definition for "Data unit" to cover what is essentially a pixel but is not image data.
--- .../userspace-api/media/glossary.rst | 8 + .../media/v4l/subdev-formats.rst | 258 ++++++++++++++++++ include/uapi/linux/media-bus-format.h | 9 + 3 files changed, 275 insertions(+)
Documentation/userspace-api/media/glossary.rst +8 -0
@@ -25,6 +25,14 @@ Glossary See :ref:`cec`. +.. _media-glossary-data-unit: + + Data unit + + Unit of data transported by a bus. On parallel buses, this is called a + sample while on serial buses the data unit is logical. If the data unit + is image data, it may also be called a pixel. + Device Driver Part of the Linux Kernel that implements support for a hardware component.
Documentation/userspace-api/media/v4l/subdev-formats.rst +258 -0
261 lines not on this page · raw message
include/uapi/linux/media-bus-format.h +9 -0
@@ -173,4 +173,13 @@*/ #define MEDIA_BUS_FMT_METADATA_FIXED 0x7001 +/* Generic line based metadata formats for serial buses. Next is 0x8008. */ +#define MEDIA_BUS_FMT_META_8 0x8001 +#define MEDIA_BUS_FMT_META_10 0x8002 +#define MEDIA_BUS_FMT_META_12 0x8003 +#define MEDIA_BUS_FMT_META_14 0x8004 +#define MEDIA_BUS_FMT_META_16 0x8005 +#define MEDIA_BUS_FMT_META_20 0x8006 +#define MEDIA_BUS_FMT_META_24 0x8007 +#endif /* __LINUX_MEDIA_BUS_FORMAT_H */
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 3/23 media: uapi: Document which mbus format fields are valid for metadata
In reply to Sakari AilusNow that metadata mbus formats have been added, it is necessary to define which fields in struct v4l2_mbus_format are applicable to them (not many).
--- include/uapi/linux/v4l2-mediabus.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
include/uapi/linux/v4l2-mediabus.h +12 -6
@@ -19,12 +19,18 @@* @width: image width * @height: image height * @code: data format code (from enum v4l2_mbus_pixelcode) -* @field: used interlacing type (from enum v4l2_field) -* @colorspace: colorspace of the data (from enum v4l2_colorspace) -* @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding) -* @hsv_enc: HSV encoding of the data (from enum v4l2_hsv_encoding) -* @quantization: quantization of the data (from enum v4l2_quantization) -* @xfer_func: transfer function of the data (from enum v4l2_xfer_func) +* @field: used interlacing type (from enum v4l2_field), not applicable +* to metadata mbus codes +* @colorspace: colorspace of the data (from enum v4l2_colorspace), zero on +* metadata mbus codes +* @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding), zero +* on metadata mbus codes +* @hsv_enc: HSV encoding of the data (from enum v4l2_hsv_encoding), zero on +* metadata mbus codes +* @quantization: quantization of the data (from enum v4l2_quantization), zero +* on metadata mbus codes +* @xfer_func: transfer function of the data (from enum v4l2_xfer_func), zero +* on metadata mbus codes * @flags: flags (V4L2_MBUS_FRAMEFMT_*) * @reserved: reserved bytes that can be later used */
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 4/23 media: uapi: Add generic 8-bit metadata format definitions
In reply to Sakari AilusGeneric 8-bit metadata formats define the in-memory data layout but not the format of the data itself. The reasoning for having such formats is to allow CSI-2 receiver drivers to receive and DMA drivers to write the data to memory without knowing a large number of device specific formats.
These formats may be used only in conjunction of a Media controller pipeline where the internal pad of the source sub-device defines the specific format of the data (using an mbus code).
--- .../userspace-api/media/v4l/dev-subdev.rst | 2 + .../userspace-api/media/v4l/meta-formats.rst | 1 + .../media/v4l/metafmt-generic.rst | 304 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-ioctl.c | 7 + include/uapi/linux/videodev2.h | 8 + 5 files changed, 322 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/metafmt-generic.rst
Documentation/userspace-api/media/v4l/dev-subdev.rst +2 -0
@@ -506,6 +506,8 @@ source pads. subdev-formats +.. _subdev-routing: + Streams, multiplexed media pads and internal routing ----------------------------------------------------
Documentation/userspace-api/media/v4l/meta-formats.rst +1 -0
@@ -19,3 +19,4 @@ These formats are used for the :ref:`metadata` interface only. metafmt-vsp1-hgo metafmt-vsp1-hgt metafmt-vivid + metafmt-generic
Documentation/userspace-api/media/v4l/metafmt-generic.rst new file +304 -0
304 lines not on this page · raw message
drivers/media/v4l2-core/v4l2-ioctl.c +7 -0
@@ -1452,6 +1452,13 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)case V4L2_PIX_FMT_Y210 : descr ="10-bit YUYV Packed" ;break ;case V4L2_PIX_FMT_Y212 : descr ="12-bit YUYV Packed" ;break ;case V4L2_PIX_FMT_Y216 : descr ="16-bit YUYV Packed" ;break ; +case V4L2_META_FMT_GENERIC_8 : descr ="8-bit Generic Metadata" ;break ; +case V4L2_META_FMT_GENERIC_CSI2_10 : descr ="8b Generic Meta, 10b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_CSI2_12 : descr ="8b Generic Meta, 12b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_CSI2_14 : descr ="8b Generic Meta, 14b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_CSI2_16 : descr ="8b Generic Meta, 16b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_CSI2_20 : descr ="8b Generic Meta, 20b CSI-2" ;break ; +case V4L2_META_FMT_GENERIC_CSI2_24 : descr ="8b Generic Meta, 24b CSI-2" ;break ;default :/* Compressed formats */
include/uapi/linux/videodev2.h +8 -0
@@ -839,6 +839,14 @@ struct v4l2_pix_format {#define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P')/* Rockchip ISP1 3A Parameters */ #define V4L2_META_FMT_RK_ISP1_STAT_3A v4l2_fourcc('R', 'K', '1', 'S')/* Rockchip ISP1 3A Statistics */ +#define V4L2_META_FMT_GENERIC_8 v4l2_fourcc('M', 'E', 'T', '8')/* Generic 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_10 v4l2_fourcc('M', 'C', '1', 'A')/* 10-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_12 v4l2_fourcc('M', 'C', '1', 'C')/* 12-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_14 v4l2_fourcc('M', 'C', '1', 'E')/* 14-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_16 v4l2_fourcc('M', 'C', '1', 'G')/* 16-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_20 v4l2_fourcc('M', 'C', '1', 'K')/* 20-bit CSI-2 packed 8-bit metadata */ +#define V4L2_META_FMT_GENERIC_CSI2_24 v4l2_fourcc('M', 'C', '1', 'O')/* 24-bit CSI-2 packed 8-bit metadata */ +/* priv field value to indicates that subsequent fields are valid. */ #define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 5/23 media: v4l: Support line-based metadata capture
In reply to Sakari Ailusmany camera sensors, among other devices, transmit embedded data and image data for each CSI-2 frame. This embedded data typically contains register configuration of the sensor that has been used to capture the image data of the same frame.
The embedded data is received by the CSI-2 receiver and has the same properties as the image data, including that it is line based: it has width, height and bytesperline (stride).
Add these fields to struct v4l2_meta_format and document them.
Also add V4L2_FMT_FLAG_META_LINE_BASED to tell a given format is line-based i.e. these fields of struct v4l2_meta_format are valid for it.
--- .../userspace-api/media/v4l/dev-meta.rst | 15 +++++++++++++++ .../userspace-api/media/v4l/vidioc-enum-fmt.rst | 7 +++++++ .../media/videodev2.h.rst.exceptions | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 5 +++-- include/uapi/linux/videodev2.h | 10 ++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-)
Documentation/userspace-api/media/v4l/dev-meta.rst +15 -0
@@ -65,3 +65,18 @@ to 0. - ``buffersize`` - Maximum buffer size in bytes required for data. The value is set by the driver. + * - __u32 + - ``width`` + - Width of a line of metadata in Data units. Valid when + :c:type`v4l2_fmtdesc` flag ``V4L2_FMT_FLAG_META_LINE_BASED`` is set, + otherwise zero. See :c:func:`VIDIOC_ENUM_FMT`. + * - __u32 + - ``height`` + - Number of rows of metadata. Valid when :c:type`v4l2_fmtdesc` flag + ``V4L2_FMT_FLAG_META_LINE_BASED`` is set, otherwise zero. See + :c:func:`VIDIOC_ENUM_FMT`. + * - __u32 + - ``bytesperline`` + - Offset in bytes between the beginning of two consecutive lines. Valid + when :c:type`v4l2_fmtdesc` flag ``V4L2_FMT_FLAG_META_LINE_BASED`` is + set, otherwise zero. See :c:func:`VIDIOC_ENUM_FMT`.
Documentation/userspace-api/media/v4l/vidioc-enum-fmt.rst +7 -0
@@ -227,6 +227,13 @@ the ``mbus_code`` field is handled differently: The application can ask to configure the quantization of the capture device when calling the :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl with :ref:`V4L2_PIX_FMT_FLAG_SET_CSC <v4l2-pix-fmt-flag-set-csc>` set. + * - ``V4L2_FMT_FLAG_META_LINE_BASED`` + - 0x0200 + - The metadata format is line-based. In this case the ``width``, + ``height`` and ``bytesperline`` fields of :c:type:`v4l2_meta_format` are + valid. The buffer consists of ``height`` lines, each having ``width`` + Data units of data and offset (in bytes) between the beginning of each + two consecutive lines is ``bytesperline``. Return Value ============
Documentation/userspace-api/media/videodev2.h.rst.exceptions +1 -0
@@ -215,6 +215,7 @@ replace define V4L2_FMT_FLAG_CSC_XFER_FUNC fmtdesc-flags replace define V4L2_FMT_FLAG_CSC_YCBCR_ENC fmtdesc-flags replace define V4L2_FMT_FLAG_CSC_HSV_ENC fmtdesc-flags replace define V4L2_FMT_FLAG_CSC_QUANTIZATION fmtdesc-flags +replace define V4L2_FMT_FLAG_META_LINE_BASED fmtdesc-flags # V4L2 timecode types replace define V4L2_TC_TYPE_24FPS timecode-type
drivers/media/v4l2-core/v4l2-ioctl.c +3 -2
@@ -343,8 +343,9 @@ static void v4l_print_format(const void *arg, bool write_only)case V4L2_BUF_TYPE_META_OUTPUT : meta = &p->fmt.meta; pixelformat = meta->dataformat; -pr_cont (", dataformat=%p4cc, buffersize=%u\n" , - &pixelformat, meta->buffersize); +pr_cont (", dataformat=%p4cc, buffersize=%u, width=%u, height=%u, bytesperline=%u\n" , + &pixelformat, meta->buffersize, meta->width, + meta->height, meta->bytesperline);break ; } }
include/uapi/linux/videodev2.h +10 -0
@@ -877,6 +877,7 @@ struct v4l2_fmtdesc {#define V4L2_FMT_FLAG_CSC_YCBCR_ENC 0x0080#define V4L2_FMT_FLAG_CSC_HSV_ENC V4L2_FMT_FLAG_CSC_YCBCR_ENC#define V4L2_FMT_FLAG_CSC_QUANTIZATION 0x0100 +#define V4L2_FMT_FLAG_META_LINE_BASED 0x0200/* Frame Size and frame rate enumeration */ /*
@@ -2420,10 +2421,19 @@ struct v4l2_sdr_format {* struct v4l2_meta_format - metadata format definition * @dataformat: little endian four character code (fourcc) * @buffersize: maximum size in bytes required for data +* @width: number of data units of data per line (valid for line +* based formats only, see format documentation) +* @height: number of lines of data per buffer (valid for line based +* formats only) +* @bytesperline: offset between the beginnings of two adjacent lines in +* bytes (valid for line based formats only) */ struct v4l2_meta_format {__u32 dataformat;__u32 buffersize; +__u32 width; +__u32 height; +__u32 bytesperline; } __attribute__ ((packed));/**
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 6/23 media: uapi: ccs: Add media bus code for MIPI CCS embedded data
In reply to Sakari AilusAdd new MIPI CCS embedded data media bus code
(MEDIA_BUS_FMT_CCS_EMBEDDED).
--- .../media/v4l/subdev-formats.rst | 28 +++++++++++++++++++ include/uapi/linux/media-bus-format.h | 3 ++ 2 files changed, 31 insertions(+)
Documentation/userspace-api/media/v4l/subdev-formats.rst +28 -0
@@ -8492,3 +8492,31 @@ and finally the bit number in subscript. "X" indicates a padding bit. - X - X - X + +.. _MEDIA-BUS-FMT-CCS-EMBEDDED: + +MIPI CCS Embedded Data Formats +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +`MIPI CCS <https://www.mipi.org/specifications/camera-command-set>`_ defines a +metadata format for sensor embedded data, which is used to store the register +configuration used for capturing a given frame. The format is defined in the CCS +specification. The media bus code for this format is +``MEDIA_BUS_FMT_CCS_EMBEDDED``. + +The CCS embedded data format definition includes three levels: + +1. Padding within CSI-2 bus :ref:`Data unit <media-glossary-data-unit>` as + documented in the MIPI CCS specification. + +2. The tagged data format as documented in the MIPI CCS specification. + +3. Register addresses and register documentation as documented in the MIPI CCS + specification. + +The format definition shall be used only by devices that fulfill all three +levels above. + +This mbus code are only used for "2-byte simplified tagged data format" (code +0xa) but their use may be extended further in the future, to cover other CCS +embedded data format codes.
include/uapi/linux/media-bus-format.h +3 -0
@@ -182,4 +182,7 @@#define MEDIA_BUS_FMT_META_20 0x8006#define MEDIA_BUS_FMT_META_24 0x8007 +/* Specific metadata formats. Next is 0x9002. */ +#define MEDIA_BUS_FMT_CCS_EMBEDDED 0x9001 +#endif /* __LINUX_MEDIA_BUS_FORMAT_H */
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 7/23 media: Documentation: ccs: Document routing
In reply to Sakari AilusDocument which routes are available for the CCS driver (source) sub-device and what configuration are possible.
Also update copyright.
--- .../userspace-api/media/drivers/ccs.rst | 34 ++++++++++++++++++- .../media/v4l/subdev-formats.rst | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-)
Documentation/userspace-api/media/drivers/ccs.rst +33 -1
@@ -107,4 +107,36 @@ than in the centre. Shading correction needs to be enabled for luminance correction level to have an effect. -**Copyright** |copy| 2020 Intel Corporation +.. _media-ccs-routes: + +Routes +------ + +The CCS driver implements one or two :ref:`routes <subdev-routing>` in +its source sub-device (scaler sub-device if exists for the device, otherwise +binner) depending on whether the sensor supports embedded data. (All CCS +compliant sensors do but the CCS driver supports preceding standards that did +not require embedded data support, too.) + +The first route of the CCS source sub-device is for pixel data (internal pad +1/stream 0 -> pad 0/stream 0) and the second one is for embedded data (internal +pad 2/stream 0 -> pad 0/stream 1). + +Embedded data +~~~~~~~~~~~~~ + +MIPI CCS supports generation of camera sensor embedded data. The media bus code +used for this format is :ref:`MEDIA_BUS_FMT_CCS_EMBEDDDED +<MEDIA-BUS-FMT-CCS-EMBEDDED>`. + +The bit depth of the CCS pixel data affects how the sensor will output the +embedded data, adding padding to align with CSI-2 bus :ref:`Data units +<media-glossary-data-unit>` for that particular bit depth. This is indicated by +the generic metadata format on the sensor's source sub-device's source pad. + +Embedded data for bit depths greater than or equal to 16 may support more dense +packing or legacy single metadata byte per data unit, or both of these, +depending on the device. The supported embedded data formats can be enumerated +and configured on stream 1 of the source pad (1) of the CCS source sub-device. + +**Copyright** |copy| 2020, 2023 Intel Corporation
Documentation/userspace-api/media/v4l/subdev-formats.rst +2 -0
@@ -8520,3 +8520,5 @@ levels above. This mbus code are only used for "2-byte simplified tagged data format" (code 0xa) but their use may be extended further in the future, to cover other CCS embedded data format codes. + +Also see :ref:`CCS driver documentation <media-ccs-routes>`.
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 8/23 media: Documentation: Additional streams generally don't harm capture
In reply to Sakari AilusHaving extra streams on the source end of the link that cannot be captured by the sink sub-device generally are not an issue, at least not on CSI-2 bus. Still document that there may be hardware specific limitations. For example on parallel bus this might not work on all cases.
--- Documentation/userspace-api/media/v4l/dev-subdev.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/v4l/dev-subdev.rst +3 -3
@@ -529,9 +529,9 @@ the its sink pad and allows to route them individually to one of its source pads. Subdevice drivers that support multiplexed streams are compatible with -non-multiplexed subdev drivers, but, of course, require a routing configuration -where the link between those two types of drivers contains only a single -stream. +non-multiplexed subdev drivers. However, if the driver at the sink end of a link +does not support streams, then only the stream 0 on source end may be +captured. There may be additional hardware specific limitations. Understanding streams ^^^^^^^^^^^^^^^^^^^^^
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 9/23 media: Documentation: Document embedded data guidelines for camera sensors
In reply to Sakari AilusDocument how embedded data support should be implemented for camera sensors, and when and how CCS embedded data format should be referenced.
--- .../driver-api/media/camera-sensor.rst | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+)
Documentation/driver-api/media/camera-sensor.rst +23 -0
@@ -200,3 +200,26 @@ V4L2_CID_VFLIP controls with the values programmed by the register sequences. The default values of these controls shall be 0 (disabled). Especially these controls shall not be inverted, independently of the sensor's mounting rotation. + +Embedded data +------------- + +Many sensors, mostly raw sensors, support embedded data which is used to convey +the sensor configuration for the captured frame back to the host. While CSI-2 is +the most common bus used by such sensors, embedded data is not entirely limited +to CSI-2 bus due to e.g. bridge devices. + +Embedded data support should use an internal source pad and route to the +external pad. If embedded data output can be disabled in hardware, it should be +possible to disable the embedded data route via ``VIDIOC_SUBDEV_S_ROUTING`` +IOCTL. + +CCS and non-CCS embedded data +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Embedded data which is compliant with CCS definitions shall use ``CCS embedded +data format <MEDIA-BUS-FMT-CCS-EMBEDDED>``. Device specific embedded data which +is compliant up to MIPI CCS embedded data levels 1 or 2 only shall refer to CCS +embedded data formats and document the level of conformance. The rest of the +device specific embedded data format shall be documented in the context of the +data format itself.
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 10/23 media: Documentation: v4l: Document source routes
In reply to Sakari AilusDocument how internal pads are used on source routes. Use the IMX219 camera sensor as an example.
--- .../userspace-api/media/v4l/dev-subdev.rst | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+)
Documentation/userspace-api/media/v4l/dev-subdev.rst +179 -0
@@ -553,6 +553,27 @@ A stream at a specific point in the media pipeline is identified by the sub-device and a (pad, stream) pair. For sub-devices that do not support multiplexed streams the 'stream' field is always 0. +.. _v4l2-subdev-source-routes: + +Internal pads and source routes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Cases where a single sub-device source pad is traversed by multiple streams one +or more of which originate from within the sub-device itself are special as +there is no external sink pad for such routes. In those cases, the sources of +the internally generated streams are represented by internal sink pads, which +are sink pads that have the :ref:`MEDIA_PAD_FL_INTERNAL <MEDIA-PAD-FL-INTERNAL>` +pad flag set. + +Internal pads have all the properties of an external pad, including formats and +selections. The format in this case is the source format of the stream. An +internal pad always has a single stream only (0). + +*Source routes* are routes from an internal sink pad to an external source +pad. In most cases source routes are not modifiable but they can be activated +and deactivated using the :ref:`V4L2_SUBDEV_ROUTE_FL_ACTIVE +<v4l2-subdev-routing-flags>` flag, depending on driver capabilities. + Interaction between routes, streams, formats and selections ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -668,3 +689,161 @@ To configure this pipeline, the userspace must take the following steps: the configurations along the stream towards the receiver, using :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls to configure each stream endpoint in each sub-device. + +Internal pads setup example +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A simple example of a multiplexed stream setup might be as follows: + +- A CCS camera sensor source sub-device, with one sink pad (0), one source pad + (1), an internal sink pad (2) that represents the source of embedded + data. There are two routes, one from the sink pad to the source, and another + from the internal sink pad to the source pad. The embedded data stream needs + to be enabled by activating the related route. The configuration of the rest + of the CCS sub-devices is omitted from this example. + +- Multiplexer bridge (Bridge). The bridge has one sink pad, connected to the + sensor (pad 0), and one source pad (pad 1), which outputs two streams. + +- Receiver in the SoC (Receiver). The receiver has a single sink pad (pad 0), + connected to the bridge, and two source pads (pads 1-2), going to the DMA + engine. The receiver demultiplexes the incoming streams to the source pads. + +- DMA Engines in the SoC (DMA Engine), one for each stream. Each DMA engine is + connected to a single source pad in the receiver. + +The sensor, the bridge and the receiver are modeled as V4L2 sub-devices, +exposed to userspace via /dev/v4l-subdevX device nodes. The DMA engines are +modeled as V4L2 devices, exposed to userspace via /dev/videoX nodes. + +To configure this pipeline, the userspace must take the following steps: + +1) Set up media links between entities: connect the sensors to the bridge, + bridge to the receiver, and the receiver to the DMA engines. This step does + not differ from normal non-multiplexed media controller setup. + +2) Configure routing + +.. flat-table:: Camera sensor + :header-rows: 1 + + * - Sink Pad/Stream + - Source Pad/Stream + - Routing Flags + - Comments + * - 0/0 + - 1/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Pixel data stream from the sink pad + * - 2/0 + - 1/1 + - **V4L2_SUBDEV_ROUTE_FL_ACTIVE** + - Metadata stream from the internal sink pad + +.. flat-table:: Bridge routing table + :header-rows: 1 + + * - Sink Pad/Stream + - Source Pad/Stream + - Routing Flags + - Comments + * - 0/0 + - 1/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Pixel data stream from camera sensor + * - 0/1 + - 1/1 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Metadata stream from camera sensor + +.. flat-table:: Receiver routing table + :header-rows: 1 + + * - Sink Pad/Stream + - Source Pad/Stream + - Routing Flags + - Comments + * - 0/0 + - 1/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Pixel data stream from camera sensor + * - 0/1 + - 2/0 + - V4L2_SUBDEV_ROUTE_FL_ACTIVE + - Metadata stream from camera sensor + +The options available in sensor's routing configuration are dictated by +hardware capabilities: typically camera sensors always produce image data +stream while the embedded data stream typically can be either enabled or +disabled. + +3) Configure formats and selections + + This example assumes that the formats are propagated from sink pad to the + source pad as-is. The tables contain fields of both struct v4l2_subdev_format + and struct v4l2_mbus_framefmt. + +.. flat-table:: Formats set on the sub-devices. Bold values are set, others are + static or propagated. + :header-rows: 1 + :fill-cells: + + * - Sub-device + - Pad/Stream + - Width + - Height + - Code + * - :rspan:`3` Camera sensor sub-device (IMX219) + - 1/0 + - 3296 + - 2480 + - MEDIA_BUS_FMT_SRGGB10 + * - 0/0 + - **3296** + - **2480** + - **MEDIA_BUS_FMT_SRGGB10** + * - 2/0 + - 3296 + - 2 + - MEDIA_BUS_FMT_IMX219_EMBEDDED + * - 1/1 + - 3296 + - 2 + - MEDIA_BUS_FMT_META_10 + * - :rspan:`3` Bridge + - 0/0 + - **3296** + - **2480** + - **MEDIA_BUS_FMT_SRGGB10** + * - 1/0 + - 3296 + - 2480 + - MEDIA_BUS_FMT_SRGGB10 + * - 0/1 + - **3296** + - **2** + - **MEDIA_BUS_FMT_META_10** + * - 1/1 + - 3296 + - 2 + - MEDIA_BUS_FMT_META_10 + * - :rspan:`3` Receiver + - 0/0 + - **3296** + - **2480** + - **MEDIA_BUS_FMT_SRGGB10** + * - 1/0 + - 3296 + - 2480 + - MEDIA_BUS_FMT_SRGGB10 + * - 0/1 + - **3296** + - **2** + - **MEDIA_BUS_FMT_META_10** + * - 2/0 + - 3296 + - 2 + - MEDIA_BUS_FMT_META_10 + +The embedded data format does not need to be configured as the format is +dictated by the pixel data format in this case.
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 11/23 media: Documentation: Document S_ROUTING behaviour
In reply to Sakari AilusDocument S_ROUTING behaviour for different devices.
Generally in devices that produce streams the streams are static and some can be enabled and disabled, whereas in devices that just transport them or write them to memory, more configurability is allowed. Document this.
--- .../userspace-api/media/v4l/dev-subdev.rst | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
Documentation/userspace-api/media/v4l/dev-subdev.rst +21 -0
@@ -593,6 +593,27 @@ Any configurations of a stream within a pad, such as format or selections, are independent of similar configurations on other streams. This is subject to change in the future. +Device types and routing setup +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Different kinds of sub-devices have differing behaviour for route inactivation, +depending on the hardware. Devices generating the streams may often allow +enabling and disabling some of these or the configuration is fixed. If these +routes can be disabled, not declaring these routes (or declaring them without +``VIDIOC_SUBDEV_STREAM_FL_ACTIVE`` flag set) in ``VIDIOC_SUBDEV_S_ROUTING`` will +disable the routes while the sub-device driver retain the streams and their +configuration. The ``VIDIOC_SUBDEV_S_ROUTING`` will still return such routes +back to the user in the routes array, with the ``V4L2_SUBDEV_STREAM_FL_ACTIVE`` +flag unset. + +Devices transporting the streams almost always have more configurability with +respect to routing. Typically any route between the sub-device's sink and source +pads is possible, and multiple routes (usually up to certain limited number) may +be active simultaneously. For such devices, no routes are created by the driver +and user-created routes are fully replaced when ``VIDIOC_SUBDEV_S_ROUTING`` is +called on the sub-device. Such newly created routes have the device's default +configuration for format and selection rectangles. + Configuring streams ^^^^^^^^^^^^^^^^^^^
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 12/23 media: v4l: subdev: Add helpers for format, crop and compose pointers
In reply to Sakari AilusAdd a helper for obtaining format, crop and compose pointers. These are convenient for drivers, independently of the driver uses streams or not.
--- drivers/media/v4l2-core/v4l2-subdev.c | 54 ++++++++++++++++++++++---- include/media/v4l2-subdev.h | 56 +++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 8 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +46 -8
@@ -1573,19 +1573,57 @@ v4l2_subdev_init_stream_configs(struct v4l2_subdev_stream_configs *stream_configreturn 0 ; } +struct v4l2_mbus_framefmt +*v4l2_subdev_get_fmt_ptr (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,unsigned int pad, +unsigned int stream) +{ +if (sd->flags &V4L2_SUBDEV_FL_STREAMS ) +return v4l2_subdev_state_get_stream_format (state, pad, stream); + +if (pad < sd->entity.num_pads && stream ==0 ) +return v4l2_subdev_get_pad_format (sd, state, pad); + +return NULL ; +} +EXPORT_SYMBOL_GPL (v4l2_subdev_get_fmt_ptr); + +struct v4l2_rect +*v4l2_subdev_get_crop_ptr (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,unsigned int pad, +unsigned int stream) +{ +if (sd->flags &V4L2_SUBDEV_FL_STREAMS ) +return v4l2_subdev_state_get_stream_crop (state, pad, stream); + +if (pad < sd->entity.num_pads && stream ==0 ) +return v4l2_subdev_get_pad_crop (sd, state, pad); + +return NULL ; +} +EXPORT_SYMBOL_GPL (v4l2_subdev_get_crop_ptr); + +struct v4l2_rect +*v4l2_subdev_get_compose_ptr (struct v4l2_subdev *sd, +struct v4l2_subdev_state *state,unsigned int pad, +unsigned int stream) +{ +if (sd->flags &V4L2_SUBDEV_FL_STREAMS ) +return v4l2_subdev_state_get_stream_compose (state, pad, stream); + +if (pad < sd->entity.num_pads && stream ==0 ) +return v4l2_subdev_get_pad_compose (sd, state, pad); + +return NULL ; +} +EXPORT_SYMBOL_GPL (v4l2_subdev_get_compose_ptr); +int v4l2_subdev_get_fmt (struct v4l2_subdev *sd,struct v4l2_subdev_state *state,struct v4l2_subdev_format *format) {struct v4l2_mbus_framefmt *fmt; -if (sd->flags &V4L2_SUBDEV_FL_STREAMS ) - fmt =v4l2_subdev_state_get_stream_format (state, format->pad, - format->stream); -else if (format->pad < sd->entity.num_pads && format->stream ==0 ) - fmt =v4l2_subdev_get_pad_format (sd, state, format->pad); -else - fmt =NULL ; - + fmt =v4l2_subdev_get_fmt_ptr (sd, state, format->pad, format->stream);if (!fmt)return -EINVAL ;
include/media/v4l2-subdev.h +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 13/23 media: ccs: Move ccs_validate_csi_data_format up
In reply to Sakari Ailusccs_validate_csi_data_format() will soon be needed elsewhere, above its current location. Move it up.
--- drivers/media/i2c/ccs/ccs-core.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +14 -14
@@ -1976,6 +1976,20 @@ static int ccs_post_streamoff(struct v4l2_subdev *subdev)return pm_runtime_put (&client->dev); } +static const struct ccs_csi_data_format +*ccs_validate_csi_data_format (struct ccs_sensor *sensor,u32 code) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (ccs_csi_data_formats); i++) { +if (sensor->mbus_frame_fmts & (1 << i) && + ccs_csi_data_formats[i].code == code) +return &ccs_csi_data_formats[i]; + } + +return sensor->csi_format; +} +static int ccs_enum_mbus_code (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)
@@ -2107,20 +2121,6 @@ static void ccs_propagate(struct v4l2_subdev *subdev, } } -static const struct ccs_csi_data_format -*ccs_validate_csi_data_format (struct ccs_sensor *sensor,u32 code) -{ -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (ccs_csi_data_formats); i++) { -if (sensor->mbus_frame_fmts & (1 << i) && - ccs_csi_data_formats[i].code == code) -return &ccs_csi_data_formats[i]; - } - -return sensor->csi_format; -} -static int ccs_set_format_source (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_format *fmt)
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 14/23 media: ccs: Support frame descriptors
In reply to Sakari AilusProvide information on the frame layout using frame descriptors.
--- drivers/media/i2c/ccs/ccs-core.c | 60 +++++++++++++++++++++++++++++++ drivers/media/i2c/ccs/ccs-quirk.h | 7 ++++ drivers/media/i2c/ccs/ccs.h | 4 +++ 3 files changed, 71 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +60 -0
@@ -25,6 +25,7 @@#include <linux/slab.h> #include <linux/smiapp.h> #include <linux/v4l2-mediabus.h> +#include <media/mipi-csi2.h> #include <media/v4l2-fwnode.h> #include <media/v4l2-device.h> #include <uapi/linux/ccs.h>
@@ -235,6 +236,33 @@ static int ccs_read_all_limits(struct ccs_sensor *sensor)return ret; } +static u8 ccs_mipi_csi2_data_type (unsigned int bpp) +{ +switch (bpp) { +case 6 : +return MIPI_CSI2_DT_RAW6 ; +case 7 : +return MIPI_CSI2_DT_RAW7 ; +case 8 : +return MIPI_CSI2_DT_RAW8 ; +case 10 : +return MIPI_CSI2_DT_RAW10 ; +case 12 : +return MIPI_CSI2_DT_RAW12 ; +case 14 : +return MIPI_CSI2_DT_RAW14 ; +case 16 : +return MIPI_CSI2_DT_RAW16 ; +case 20 : +return MIPI_CSI2_DT_RAW20 ; +case 24 : +return MIPI_CSI2_DT_RAW24 ; +default : +WARN_ON (1 ); +return 0 ; + } +} +static int ccs_read_frame_fmt (struct ccs_sensor *sensor) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);
@@ -2625,6 +2653,37 @@ static int ccs_set_selection(struct v4l2_subdev *subdev,return ret; } +static int ccs_get_frame_desc (struct v4l2_subdev *subdev,unsigned int pad, +struct v4l2_mbus_frame_desc *desc) +{ +struct ccs_sensor *sensor =to_ccs_sensor (subdev); +struct v4l2_mbus_frame_desc_entry *entry = desc->entry; + +if (ccs_has_quirk (sensor, frame_desc)) +return ccs_call_quirk (sensor, frame_desc, desc); + +switch (sensor->hwcfg.csi_signalling_mode) { +case CCS_CSI_SIGNALING_MODE_CSI_2_DPHY : +case CCS_CSI_SIGNALING_MODE_CSI_2_CPHY : + desc->type =V4L2_MBUS_FRAME_DESC_TYPE_CSI2 ; +break ; +default : +/* FIXME: CCP2 support */ +return -EINVAL ; + } + + entry->pixelcode = sensor->csi_format->code; + entry->stream =CCS_STREAM_PIXEL ; + entry->bus.csi2.dt = + sensor->csi_format->width == sensor->csi_format->compressed ? +ccs_mipi_csi2_data_type (sensor->csi_format->compressed) : +CCS_DEFAULT_COMPRESSED_DT ; + entry++; + desc->num_entries++; + +return 0 ; +} +static int ccs_get_skip_frames (struct v4l2_subdev *subdev,u32 *frames) {struct ccs_sensor *sensor =to_ccs_sensor (subdev);
@@ -3049,6 +3108,7 @@ static const struct v4l2_subdev_pad_ops ccs_pad_ops = { .set_fmt = ccs_set_format, .get_selection = ccs_get_selection, .set_selection = ccs_set_selection, + .get_frame_desc = ccs_get_frame_desc, };static const struct v4l2_subdev_sensor_ops ccs_sensor_ops = {
drivers/media/i2c/ccs/ccs-quirk.h +7 -0
@@ -36,6 +36,7 @@ struct ccs_sensor;* access may be done by the caller (default read * value is zero), else negative error code on error * @flags: Quirk flags +* @frame_desc: Obtain the frame descriptor */ struct ccs_quirk {int (*limits)(struct ccs_sensor *sensor);
@@ -46,6 +47,8 @@ struct ccs_quirk {int (*init)(struct ccs_sensor *sensor);int (*reg_access)(struct ccs_sensor *sensor,bool write,u32 *reg,u32 *val); +int (*frame_desc)(struct ccs_sensor *sensor, +struct v4l2_mbus_frame_desc *desc);unsigned long flags; };
@@ -62,6 +65,10 @@ struct ccs_reg_8 { .val = _val, \ } +#define ccs_has_quirk (sensor, _quirk) \ + ((sensor)->minfo.quirk && \ + (sensor)->minfo.quirk->_quirk) +#define ccs_call_quirk (sensor, _quirk, ...) \ ((sensor)->minfo.quirk && \ (sensor)->minfo.quirk->_quirk ? \
drivers/media/i2c/ccs/ccs.h +4 -0
@@ -45,6 +45,8 @@#define CCS_COLOUR_COMPONENTS 4 +#define CCS_DEFAULT_COMPRESSED_DT 0x30 +#define SMIAPP_NAME "smiapp"#define CCS_NAME "ccs"
@@ -174,6 +176,8 @@ struct ccs_csi_data_format {#define CCS_PAD_SRC 1#define CCS_PADS 2 +#define CCS_STREAM_PIXEL 0 +struct ccs_binning_subtype {u8 horizontal:4 ;u8 vertical:4 ;
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 15/23 media: ccs: Add support for embedded data stream
In reply to Sakari AilusAdd support for embedded data stream, in UAPI and frame descriptor.
This patch adds also a new embedded data pad (2) to the source sub-device.
--- drivers/media/i2c/ccs/ccs-core.c | 331 +++++++++++++++++++++++++++++-- drivers/media/i2c/ccs/ccs.h | 17 +- 2 files changed, 324 insertions(+), 24 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +311 -20
@@ -2018,6 +2018,57 @@ static const struct ccs_csi_data_formatreturn sensor->csi_format; } +#define CCS_EMBEDDED_CODE_DEPTH (depth, half_depth) \ + depth, \ + CCS_EMB_DATA_CAPABILITY_TWO_BYTES_PER_RAW##depth, \ + CCS_EMB_DATA_CAPABILITY_NO_ONE_BYTE_PER_RAW##depth, \ + CCS_EMB_DATA_CTRL_RAW##half_depth##_PACKING_FOR_RAW##depth, \ + MEDIA_BUS_FMT_META_##half_depth, \ + MEDIA_BUS_FMT_META_##depth, \ + +static const struct ccs_embedded_code { +u8 depth; +u8 cap_two_bytes_per_sample; +u8 cap_no_legacy; +u8 ctrl; +u32 code_two_bytes; +u32 code_legacy; +} ccs_embedded_codes[] = { + {CCS_EMBEDDED_CODE_DEPTH (16 ,8 ) }, + {CCS_EMBEDDED_CODE_DEPTH (20 ,10 ) }, + {CCS_EMBEDDED_CODE_DEPTH (24 ,12 ) }, +}; + +static const struct ccs_embedded_code *ccs_embedded_code (unsigned int bpp) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (ccs_embedded_codes); i++) +if (ccs_embedded_codes[i].depth == bpp) +return ccs_embedded_codes + i; + +WARN_ON (1 ); + +return ccs_embedded_codes; +} + +static u32 +ccs_default_embedded_code (struct ccs_sensor *sensor, +const struct ccs_embedded_code *embedded_code) +{ +if (CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_two_bytes_per_sample)) +return embedded_code->code_two_bytes; + +if (!(CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_no_legacy))) +return embedded_code->code_legacy; + +WARN_ON (1 ); + +return embedded_code->code_legacy; +} +static int ccs_enum_mbus_code (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code)
@@ -2033,6 +2084,69 @@ static int ccs_enum_mbus_code(struct v4l2_subdev *subdev,dev_err (&client->dev,"subdev %s, pad %u, index %u\n" , subdev->name, code->pad, code->index); +if (subdev == &sensor->src->sd) { +if (code->pad ==CCS_PAD_META ) { +if (code->index) + goto out; + + code->code =MEDIA_BUS_FMT_CCS_EMBEDDED ; + + rval =0 ; + goto out; + } +if (code->stream ==CCS_STREAM_META ) { +struct v4l2_mbus_framefmt *pix_fmt = +v4l2_subdev_state_get_stream_format (sd_state, +CCS_PAD_SRC , +CCS_STREAM_PIXEL ); +const struct ccs_csi_data_format *csi_format = +ccs_validate_csi_data_format (sensor, + pix_fmt->code); +unsigned int i =0 ; +u32 codes[2 ]; + +switch (csi_format->compressed) { +case 8 : + codes[i++] =MEDIA_BUS_FMT_META_8 ; +break ; +case 10 : + codes[i++] =MEDIA_BUS_FMT_META_10 ; +break ; +case 12 : + codes[i++] =MEDIA_BUS_FMT_META_12 ; +break ; +case 14 : + codes[i++] =MEDIA_BUS_FMT_META_14 ; +break ; +case 16 : +case 20 : +case 24 : { +const struct ccs_embedded_code *embedded_code = +ccs_embedded_code (csi_format->compressed); + +if (CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_two_bytes_per_sample)) + codes[i++] = + embedded_code->code_two_bytes; + +if (!(CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_no_legacy))) + codes[i++] = embedded_code->code_legacy; +break ; + } +default : +WARN_ON (1 ); + } + +if (WARN_ON (i >ARRAY_SIZE (codes)) || code->index >= i) + goto out; + + code->code = codes[code->index]; + rval =0 ; + goto out; + } + } +if (subdev != &sensor->src->sd || code->pad !=CCS_PAD_SRC ) {if (code->index) goto out;
@@ -2075,8 +2189,10 @@ static int __ccs_get_format(struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - fmt->format = *v4l2_subdev_get_pad_format(subdev, sd_state, fmt->pad); - fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad); + fmt->format = *v4l2_subdev_get_fmt_ptr(subdev, sd_state, fmt->pad, fmt->stream); + +if (fmt->pad !=CCS_PAD_META && fmt->stream !=CCS_STREAM_META ) + fmt->format.code =__ccs_get_mbus_code (subdev, fmt->pad);return 0 ; }
@@ -2106,10 +2222,12 @@ static void ccs_get_crop_compose(struct v4l2_subdev *subdev,if (crops)for (i =0 ; i < subdev->entity.num_pads; i++) crops[i] = -v4l2_subdev_get_pad_crop (subdev, sd_state, i); +v4l2_subdev_get_crop_ptr (subdev, sd_state, i, +CCS_STREAM_PIXEL );if (comps) - *comps =v4l2_subdev_get_pad_compose (subdev, sd_state, - ssd->sink_pad); + *comps =v4l2_subdev_get_compose_ptr (subdev, sd_state, + ssd->sink_pad, +CCS_STREAM_PIXEL ); }/* Changes require propagation only on sink pad. */
@@ -2202,6 +2320,79 @@ static int ccs_set_format_source(struct v4l2_subdev *subdev,return ccs_pll_update (sensor); } +static int ccs_set_format_meta (struct v4l2_subdev *subdev, +struct v4l2_subdev_state *sd_state, +struct v4l2_mbus_framefmt *fmt) +{ +struct ccs_sensor *sensor =to_ccs_sensor (subdev); +const struct ccs_csi_data_format *csi_format; +struct v4l2_mbus_framefmt *pix_fmt; +struct v4l2_mbus_framefmt *meta_fmt; +struct v4l2_mbus_framefmt *meta_out_fmt; +u32 code; + + pix_fmt =v4l2_subdev_state_get_stream_format (sd_state,CCS_PAD_SRC , +CCS_STREAM_PIXEL ); + meta_fmt =v4l2_subdev_state_get_stream_format (sd_state,CCS_PAD_META , +0 ); + meta_out_fmt =v4l2_subdev_state_get_stream_format (sd_state, +CCS_PAD_SRC , +CCS_STREAM_META ); + + code = fmt ? fmt->code : meta_out_fmt->code; + + meta_out_fmt->width = meta_fmt->width = pix_fmt->width; + meta_out_fmt->height = meta_fmt->height = + sensor->embedded_end - sensor->embedded_start; + meta_fmt->code =MEDIA_BUS_FMT_CCS_EMBEDDED ; + + csi_format =ccs_validate_csi_data_format (sensor, pix_fmt->code); + +switch (csi_format->compressed) { +case 8 : + meta_out_fmt->code =MEDIA_BUS_FMT_META_8 ; +break ; +case 10 : + meta_out_fmt->code =MEDIA_BUS_FMT_META_10 ; +break ; +case 12 : + meta_out_fmt->code =MEDIA_BUS_FMT_META_12 ; +break ; +case 14 : + meta_out_fmt->code =MEDIA_BUS_FMT_META_14 ; +break ; +case 16 : +case 20 : +case 24 : { +const struct ccs_embedded_code *embedded_code; + + embedded_code =ccs_embedded_code (csi_format->compressed); + meta_out_fmt->code = +ccs_default_embedded_code (sensor, embedded_code); + +if (!(CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_no_legacy)) && + code == embedded_code->code_legacy) + meta_out_fmt->code = embedded_code->code_legacy; + +if (CCS_LIM (sensor,EMB_DATA_CAPABILITY ) & +BIT (embedded_code->cap_two_bytes_per_sample) && + code == embedded_code->code_two_bytes) + meta_out_fmt->code = embedded_code->code_two_bytes; + +break ; + } +default : +WARN_ON (1 ); +return 0 ; + } + +if (fmt) + *fmt = *meta_out_fmt; + +return 0 ; +} +static int ccs_set_format (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_format *fmt)
@@ -2210,12 +2401,24 @@ static int ccs_set_format(struct v4l2_subdev *subdev,struct ccs_subdev *ssd =to_ccs_subdev (subdev);struct v4l2_rect *crops[CCS_PADS ]; +if (subdev == &sensor->src->sd && fmt->pad ==CCS_PAD_META ) +return ccs_get_format (subdev, sd_state, fmt); +mutex_lock (&sensor->mutex); +if (subdev == &sensor->src->sd && fmt->stream ==CCS_STREAM_META ) { +ccs_set_format_meta (subdev, sd_state, &fmt->format); + +mutex_unlock (&sensor->mutex); + +return 0 ; + } +if (fmt->pad == ssd->source_pad) {int rval; rval =ccs_set_format_source (subdev, sd_state, fmt); +ccs_set_format_meta (subdev, sd_state,0 );mutex_unlock (&sensor->mutex);
@@ -2490,6 +2693,12 @@ static int ccs_sel_supported(struct v4l2_subdev *subdev,struct ccs_sensor *sensor =to_ccs_sensor (subdev);struct ccs_subdev *ssd =to_ccs_subdev (subdev); +if (sel->stream !=CCS_STREAM_PIXEL ) +return -EINVAL ; + +if (sel->pad ==CCS_PAD_META ) +return -EINVAL ; +/* We only implement crop in three places. */ switch (sel->target) {case V4L2_SEL_TGT_CROP :
@@ -2534,7 +2743,8 @@ static int ccs_set_crop(struct v4l2_subdev *subdev,if (sel->pad == ssd->sink_pad) {struct v4l2_mbus_framefmt *mfmt = -v4l2_subdev_get_pad_format (subdev, sd_state, sel->pad); +v4l2_subdev_get_fmt_ptr (subdev, sd_state, sel->pad, +CCS_STREAM_PIXEL ); src_size.width = mfmt->width; src_size.height = mfmt->height;
@@ -2594,8 +2804,10 @@ static int ccs_get_selection(struct v4l2_subdev *subdev,ccs_get_native_size (ssd, &sel->r); }else if (sel->pad == ssd->sink_pad) {struct v4l2_mbus_framefmt *sink_fmt = -v4l2_subdev_get_pad_format (subdev, sd_state, - ssd->sink_pad); +v4l2_subdev_get_fmt_ptr (subdev, sd_state, + ssd->sink_pad, +CCS_STREAM_PIXEL ); + sel->r.top = sel->r.left =0 ; sel->r.width = sink_fmt->width; sel->r.height = sink_fmt->height;
@@ -2681,6 +2893,13 @@ static int ccs_get_frame_desc(struct v4l2_subdev *subdev, unsigned int pad, entry++; desc->num_entries++; +if (sensor->embedded_start != sensor->embedded_end) { + entry->stream =CCS_STREAM_META ; + entry->bus.csi2.dt =MIPI_CSI2_DT_EMBEDDED_8B ; + entry++; + desc->num_entries++; + } +return 0 ; }
@@ -3042,18 +3261,23 @@ static void ccs_create_subdev(struct ccs_sensor *sensor, ssd->sensor = sensor; ssd->npads = num_pads; - ssd->source_pad = num_pads -1 ; + ssd->source_pad = + ssd == sensor->pixel_array ?CCS_PA_PAD_SRC :CCS_PAD_SRC ;v4l2_i2c_subdev_set_name (&ssd->sd, client, sensor->minfo.name, name); + ssd->sd.entity.ops = &ccs_entity_ops; + ssd->pads[ssd->source_pad].flags =MEDIA_PAD_FL_SOURCE ;if (ssd != sensor->pixel_array) ssd->pads[ssd->sink_pad].flags =MEDIA_PAD_FL_SINK ; - ssd->sd.entity.ops = &ccs_entity_ops; - -if (ssd == sensor->src) +if (ssd == sensor->src) { + ssd->sd.flags |=V4L2_SUBDEV_FL_STREAMS ; + ssd->pads[CCS_PAD_META ].flags = +MEDIA_PAD_FL_SINK |MEDIA_PAD_FL_INTERNAL ;return ; + } ssd->sd.owner =THIS_MODULE ; ssd->sd.dev = &client->dev;
@@ -3071,11 +3295,16 @@ static int ccs_init_cfg(struct v4l2_subdev *sd,for (i =0 ; i < ssd->npads; i++) {struct v4l2_mbus_framefmt *fmt = -v4l2_subdev_get_pad_format (sd, sd_state, i); +v4l2_subdev_get_fmt_ptr (sd, sd_state, i, +CCS_STREAM_PIXEL );struct v4l2_rect *crop = -v4l2_subdev_get_pad_crop (sd, sd_state, i); +v4l2_subdev_get_crop_ptr (sd, sd_state, i, +CCS_STREAM_PIXEL );struct v4l2_rect *comp; +if (!fmt) +continue ; +ccs_get_native_size (ssd, crop); fmt->width = crop->width;
@@ -3086,7 +3315,8 @@ static int ccs_init_cfg(struct v4l2_subdev *sd,if (ssd == sensor->pixel_array)continue ; - comp =v4l2_subdev_get_pad_compose (sd, sd_state, i); + comp =v4l2_subdev_get_compose_ptr (sd, sd_state, i, +CCS_STREAM_PIXEL ); *comp = *crop; }
@@ -3095,6 +3325,46 @@ static int ccs_init_cfg(struct v4l2_subdev *sd,return 0 ; } +static int ccs_src_init_cfg (struct v4l2_subdev *sd,struct v4l2_subdev_state *sd_state) +{ +struct v4l2_subdev_route routes[] = { + { + .sink_pad =CCS_PAD_SINK , + .source_pad =CCS_PAD_SRC , + .source_stream =CCS_STREAM_PIXEL , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE , + }, { + .sink_pad =CCS_PAD_META , + .source_pad =CCS_PAD_SRC , + .source_stream =CCS_STREAM_META , + .flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE , + } + }; +struct v4l2_subdev_krouting routing = { + .routes = routes, + .num_routes =1 , + }; +struct ccs_subdev *ssd =to_ccs_subdev (sd); +struct ccs_sensor *sensor = ssd->sensor; +int rval; + +if (sensor->embedded_start != sensor->embedded_end) + routing.num_routes++; + + rval =v4l2_subdev_set_routing (sd, sd_state, &routing); +if (rval) +return rval; + + rval =ccs_init_cfg (sd, sd_state); +if (rval) +return rval; + +if (sensor->embedded_start != sensor->embedded_end) +ccs_set_format_meta (sd, sd_state,NULL ); + +return 0 ; +} +static const struct v4l2_subdev_video_ops ccs_video_ops = { .s_stream = ccs_set_stream, .pre_streamon = ccs_pre_streamon,
@@ -3108,6 +3378,15 @@ static const struct v4l2_subdev_pad_ops ccs_pad_ops = { .set_fmt = ccs_set_format, .get_selection = ccs_get_selection, .set_selection = ccs_set_selection, +}; + +static const struct v4l2_subdev_pad_ops ccs_src_pad_ops = { + .init_cfg = ccs_src_init_cfg, + .enum_mbus_code = ccs_enum_mbus_code, + .get_fmt = ccs_get_format, + .set_fmt = ccs_set_format, + .get_selection = ccs_get_selection, + .set_selection = ccs_set_selection, .get_frame_desc = ccs_get_frame_desc, };
@@ -3122,6 +3401,12 @@ static const struct v4l2_subdev_ops ccs_ops = { .sensor = &ccs_sensor_ops, }; +static const struct v4l2_subdev_ops ccs_src_ops = { + .video = &ccs_video_ops, + .pad = &ccs_src_pad_ops, + .sensor = &ccs_sensor_ops, +}; +static const struct media_entity_operations ccs_entity_ops = { .link_validate = v4l2_subdev_link_validate, };
@@ -3275,7 +3560,7 @@ static int ccs_probe(struct i2c_client *client) sensor->src = &sensor->ssds[sensor->ssds_used]; -v4l2_i2c_subdev_init (&sensor->src->sd, client, &ccs_ops); +v4l2_i2c_subdev_init (&sensor->src->sd, client, &ccs_src_ops); sensor->src->sd.internal_ops = &ccs_internal_src_ops; sensor->regulators = devm_kcalloc(&client->dev,
@@ -3534,9 +3819,15 @@ static int ccs_probe(struct i2c_client *client) sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN ); -ccs_create_subdev (sensor, sensor->scaler," scaler" ,2 , +ccs_create_subdev (sensor, sensor->scaler," scaler" , + sensor->ssds_used !=CCS_SUBDEVS ?CCS_PADS_NOMETA : + sensor->embedded_start == sensor->embedded_end ? +CCS_PADS_NOMETA :CCS_PADS ,MEDIA_ENT_F_PROC_VIDEO_SCALER ); -ccs_create_subdev (sensor, sensor->binner," binner" ,2 , +ccs_create_subdev (sensor, sensor->binner," binner" , + sensor->ssds_used ==CCS_SUBDEVS ?CCS_PADS_NOMETA : + sensor->embedded_start == sensor->embedded_end ? +CCS_PADS_NOMETA :CCS_PADS ,MEDIA_ENT_F_PROC_VIDEO_SCALER );ccs_create_subdev (sensor, sensor->pixel_array," pixel_array" ,1 ,MEDIA_ENT_F_CAM_SENSOR );
@@ -3572,8 +3863,8 @@ static int ccs_probe(struct i2c_client *client) sensor->streaming = false; sensor->dev_init_done = true; - rval =media_entity_pads_init (&sensor->src->sd.entity,2 , - sensor->src->pads); + rval =media_entity_pads_init (&sensor->src->sd.entity, + sensor->src->npads, sensor->src->pads);if (rval <0 ) goto out_media_entity_cleanup;
drivers/media/i2c/ccs/ccs.h +13 -4
@@ -172,11 +172,18 @@ struct ccs_csi_data_format {#define CCS_SUBDEVS 3#define CCS_PA_PAD_SRC 0 -#define CCS_PAD_SINK 0 -#define CCS_PAD_SRC 1 -#define CCS_PADS 2 +enum { +CCS_PAD_SINK , +CCS_PAD_SRC , +CCS_PAD_META , +CCS_PADS_NOMETA =CCS_PAD_META , +CCS_PADS , +}; -#define CCS_STREAM_PIXEL 0 +enum { +CCS_STREAM_PIXEL , +CCS_STREAM_META , +};struct ccs_binning_subtype {u8 horizontal:4 ;
@@ -226,6 +233,8 @@ struct ccs_sensor {int default_pixel_order;struct ccs_data_container sdata, mdata; +u32 embedded_mbus_code; +u8 binning_horizontal;u8 binning_vertical;
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 16/23 media: Add MIPI CSI-2 generic long packet type definition
In reply to Sakari AilusAdd a definition for MIPI CSI-2 generic long packet types. The generic long packet types are numbered from 1 to 4.
--- include/media/mipi-csi2.h | 1 + 1 file changed, 1 insertion(+)
include/media/mipi-csi2.h +1 -0
@@ -19,6 +19,7 @@#define MIPI_CSI2_DT_NULL 0x10#define MIPI_CSI2_DT_BLANKING 0x11#define MIPI_CSI2_DT_EMBEDDED_8B 0x12 +#define MIPI_CSI2_DT_GENERIC_LONG (n) (0x12 + (n))/* 1..4 */ #define MIPI_CSI2_DT_YUV420_8B 0x18#define MIPI_CSI2_DT_YUV420_10B 0x19#define MIPI_CSI2_DT_YUV420_8B_LEGACY 0x1a
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 17/23 media: v4l: subdev: Move G_ROUTING handling below S_ROUTING
In reply to Sakari AilusMove G_ROUTING IOCTL handling below that of S_ROUTING. G_ROUTING implementation will soon needed in handling S_ROUTING as well.
--- drivers/media/v4l2-core/v4l2-subdev.c | 54 +++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +27 -27
@@ -887,33 +887,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,case VIDIOC_SUBDEV_QUERYSTD :return v4l2_subdev_call (sd, video, querystd, arg); -case VIDIOC_SUBDEV_G_ROUTING : { -struct v4l2_subdev_routing *routing = arg; -struct v4l2_subdev_krouting *krouting; - -if (!v4l2_subdev_enable_streams_api) -return -ENOIOCTLCMD ; - -if (!(sd->flags &V4L2_SUBDEV_FL_STREAMS )) -return -ENOIOCTLCMD ; - -memset (routing->reserved,0 ,sizeof (routing->reserved)); - - krouting = &state->routing; - -if (routing->num_routes < krouting->num_routes) { - routing->num_routes = krouting->num_routes; -return -ENOSPC ; - } - -memcpy ((struct v4l2_subdev_route *)(uintptr_t )routing->routes, - krouting->routes, - krouting->num_routes *sizeof (*krouting->routes)); - routing->num_routes = krouting->num_routes; - -return 0 ; - } -case VIDIOC_SUBDEV_S_ROUTING : {struct v4l2_subdev_routing *routing = arg; struct v4l2_subdev_route *routes =
@@ -962,6 +935,33 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, routing->which, &krouting); } +case VIDIOC_SUBDEV_G_ROUTING : { +struct v4l2_subdev_routing *routing = arg; +struct v4l2_subdev_krouting *krouting; + +if (!v4l2_subdev_enable_streams_api) +return -ENOIOCTLCMD ; + +if (!(sd->flags &V4L2_SUBDEV_FL_STREAMS )) +return -ENOIOCTLCMD ; + +memset (routing->reserved,0 ,sizeof (routing->reserved)); + + krouting = &state->routing; + +if (routing->num_routes < krouting->num_routes) { + routing->num_routes = krouting->num_routes; +return -ENOSPC ; + } + +memcpy ((struct v4l2_subdev_route *)(uintptr_t )routing->routes, + krouting->routes, + krouting->num_routes *sizeof (*krouting->routes)); + routing->num_routes = krouting->num_routes; + +return 0 ; + } +case VIDIOC_SUBDEV_G_CLIENT_CAP : {struct v4l2_subdev_client_capability *client_cap = arg;
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 18/23 media: v4l: subdev: Copy argument back to user also for S_ROUTING
In reply to Sakari AilusAs the user needs to know what went wrong for S_ROUTING, copy array arguments back to the user.
--- drivers/media/v4l2-core/v4l2-ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ioctl.c +2 -1
@@ -3419,7 +3419,8 @@ video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg,* in case of failure, but it is not defined here as part of the * 'v4l2_ioctls' array, insert an ad-hoc check to address that. */ -if (err <0 && !always_copy && cmd !=VIDIOC_SUBDEV_G_ROUTING ) +if (err <0 && !always_copy && cmd !=VIDIOC_SUBDEV_G_ROUTING && + cmd !=VIDIOC_SUBDEV_S_ROUTING ) goto out;if (has_array_args) {
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 19/23 media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
In reply to Sakari AilusThe len_routes field is used to tell the size of the routes array in struct v4l2_subdev_routing. This way the number of routes returned from S_ROUTING IOCTL may be larger than the number of routes provided, in case there are more routes returned by the driver.
Note that this changes the (now-disabled) UAPI, users must be updated.
--- .../media/v4l/vidioc-subdev-g-routing.rst | 31 ++++++++++++------- drivers/media/v4l2-core/v4l2-ioctl.c | 4 +-- drivers/media/v4l2-core/v4l2-subdev.c | 6 +++- include/media/v4l2-subdev.h | 2 ++ include/uapi/linux/v4l2-subdev.h | 8 +++-- 5 files changed, 34 insertions(+), 17 deletions(-)
Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +20 -11
@@ -46,20 +46,26 @@ with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and setting or clearing flags of the ``flags`` field of a struct :c:type:`v4l2_subdev_route`. -All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called. This -means that the userspace must reconfigure all streams after calling the ioctl -with e.g. ``VIDIOC_SUBDEV_S_FMT``. +All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is +called. This means that the userspace must reconfigure all streams after calling +the ioctl with e.g. ``VIDIOC_SUBDEV_S_FMT``. Only subdevices which have both sink and source pads can support routing. -When inspecting routes through ``VIDIOC_SUBDEV_G_ROUTING`` and the application -provided ``num_routes`` is not big enough to contain all the available routes -the subdevice exposes, drivers return the ENOSPC error code and adjust the -value of the ``num_routes`` field. Application should then reserve enough memory -for all the route entries and call ``VIDIOC_SUBDEV_G_ROUTING`` again. +The ``num_routes`` field is used to denote the number of routes set (set by user +space on ``VIDIOC_SUBDEV_S_ROUTING`` argument) on the routing table as well as +the number of routes returned back from both IOCTLs. The ``len_routes`` +signifies the number of routes that can fit into the ``routes`` array. The +userspace shall set ``len_routes`` for both IOCTLs and ``num_routes`` for +``VIDIOC_SUBDEV_S_ROUTING``. -On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the -``num_routes`` field to reflect the actual number of routes returned. +On a ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the ``num_routes`` +field to reflect the actual number of routes known by the driver. ``num_routes`` +larger than ``len_routes`` in both IOCTLs. In this ``len_routes`` were returned +back to the userspace. This is not an error. + +Also ``VIDIOC_SUBDEV_S_ROUTING`` may return more route than the user provided in +``num_routes`` field due to e.g. hardware properties. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
@@ -74,6 +80,9 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the - ``which`` - Format to modified, from enum :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. + * - __u32 + - ``len_routes`` + - The length of the array (as in memory reserved for the array) * - struct :c:type:`v4l2_subdev_route` - ``routes[]`` - Array of struct :c:type:`v4l2_subdev_route` entries
@@ -81,7 +90,7 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the - ``num_routes`` - Number of entries of the routes array * - __u32 - - ``reserved``\ [5] + - ``reserved``\ [11] - Reserved for future extensions. Applications and drivers must set the array to zero.
drivers/media/v4l2-core/v4l2-ioctl.c +2 -2
@@ -3155,13 +3155,13 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,case VIDIOC_SUBDEV_S_ROUTING : {struct v4l2_subdev_routing *routing = parg; -if (routing->num_routes >256 ) +if (routing->len_routes >256 )return -E2BIG ; *user_ptr =u64_to_user_ptr (routing->routes); *kernel_ptr = (void **)&routing->routes; *array_size =sizeof (struct v4l2_subdev_route ) - * routing->num_routes; + * routing->len_routes; ret =1 ;break ; }
drivers/media/v4l2-core/v4l2-subdev.c +5 -1
@@ -903,6 +903,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,if (routing->which !=V4L2_SUBDEV_FORMAT_TRY && ro_subdev)return -EPERM ; +if (routing->num_routes > routing->len_routes) +return -EINVAL ; +memset (routing->reserved,0 ,sizeof (routing->reserved));for (i =0 ; i < routing->num_routes; ++i) {
@@ -929,6 +932,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, } krouting.num_routes = routing->num_routes; + krouting.len_routes = routing->len_routes; krouting.routes = routes; return v4l2_subdev_call(sd, pad, set_routing, state,
@@ -949,7 +953,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting = &state->routing; -if (routing->num_routes < krouting->num_routes) { +if (routing->len_routes < krouting->num_routes) { routing->num_routes = krouting->num_routes;return -ENOSPC ; }
include/media/v4l2-subdev.h +2 -0
@@ -741,12 +741,14 @@ struct v4l2_subdev_stream_configs {/** * struct v4l2_subdev_krouting - subdev routing table * +* @len_routes: length of routes array, in routes * @num_routes: number of routes * @routes: &struct v4l2_subdev_route * * This structure contains the routing table for a subdev. */ struct v4l2_subdev_krouting { +unsigned int len_routes;unsigned int num_routes;struct v4l2_subdev_route *routes; };
include/uapi/linux/v4l2-subdev.h +5 -3
@@ -222,15 +222,17 @@ struct v4l2_subdev_route {* struct v4l2_subdev_routing - Subdev routing information * * @which: configuration type (from enum v4l2_subdev_format_whence) -* @num_routes: the total number of routes in the routes array +* @len_routes: the length of the routes array, in routes * @routes: pointer to the routes array +* @num_routes: the total number of routes in the routes array * @reserved: drivers and applications must zero this array */ struct v4l2_subdev_routing {__u32 which; -__u32 num_routes; +__u32 len_routes;__u64 routes; -__u32 reserved[6 ]; +__u32 num_routes; +__u32 reserved[11 ]; };/*
Signature · 1 line
2.39.2
Laurent Pinchart
maintainerRe: [PATCH v4 19/23] media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
Hi Sakari,
Thank you for the patch.
Quoted 6 lines · Sakari Ailus
The
len_routesfield is used to tell the size of the routes array in structv4l2_subdev_routing. This way the number of routes returned fromS_ROUTINGIOCTL may be larger than the number of routes provided, in case there are more routes returned by the driver.Note that this changes the (now-disabled) UAPI, users must be updated.
This cause a regression in all upstream drivers that call v4l2_subdev_set_routing(). You need to patch the following files:
drivers/media/i2c/ds90ub913.c drivers/media/i2c/ds90ub953.c drivers/media/i2c/ds90ub960.c drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
It's a bit error-prone though. Consider the following change:
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +1 -0
@@ -201,6 +201,7 @@ static int mxc_isi_crossbar_init_cfg(struct v4l2_subdev *sd, route->flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE ; } + routing.len_routes = xbar->num_sources; routing.num_routes = xbar->num_sources; routing.routes = routes;
It's easy to forget to set len_routes :-S I wonder if we could do better.
Quoted 164 lines
Signed-off-by Sakari Ailus <[email protected]>--- .../media/v4l/vidioc-subdev-g-routing.rst | 31 ++++++++++++------- drivers/media/v4l2-core/v4l2-ioctl.c | 4 +-- drivers/media/v4l2-core/v4l2-subdev.c | 6 +++- include/media/v4l2-subdev.h | 2 ++ include/uapi/linux/v4l2-subdev.h | 8 +++-- 5 files changed, 34 insertions(+), 17 deletions(-)Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +20
-11@@ -46,20 +46,26 @@ with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and setting or clearing flags of the ``flags`` field of a struct :c:type:`v4l2_subdev_route`. -All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called. This -means that the userspace must reconfigure all streams after calling the ioctl -with e.g. ``VIDIOC_SUBDEV_S_FMT``. +All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is +called. This means that the userspace must reconfigure all streams after calling +the ioctl with e.g. ``VIDIOC_SUBDEV_S_FMT``. Only subdevices which have both sink and source pads can support routing. -When inspecting routes through ``VIDIOC_SUBDEV_G_ROUTING`` and the application -provided ``num_routes`` is not big enough to contain all the available routes -the subdevice exposes, drivers return the ENOSPC error code and adjust the -value of the ``num_routes`` field. Application should then reserve enough memory -for all the route entries and call ``VIDIOC_SUBDEV_G_ROUTING`` again. +The ``num_routes`` field is used to denote the number of routes set (set by user +space on ``VIDIOC_SUBDEV_S_ROUTING`` argument) on the routing table as well as +the number of routes returned back from both IOCTLs. The ``len_routes`` +signifies the number of routes that can fit into the ``routes`` array. The +userspace shall set ``len_routes`` for both IOCTLs and ``num_routes`` for +``VIDIOC_SUBDEV_S_ROUTING``. -On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the -``num_routes`` field to reflect the actual number of routes returned. +On a ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the ``num_routes`` +field to reflect the actual number of routes known by the driver. ``num_routes`` +larger than ``len_routes`` in both IOCTLs. In this ``len_routes`` were returned +back to the userspace. This is not an error. + +Also ``VIDIOC_SUBDEV_S_ROUTING`` may return more route than the user provided in +``num_routes`` field due to e.g. hardware properties. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|@@ -74,6 +80,9 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the - ``which`` - Format to modified, from enum :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. + * - __u32 + - ``len_routes`` + - The length of the array (as in memory reserved for the array) * - struct :c:type:`v4l2_subdev_route` - ``routes[]`` - Array of struct :c:type:`v4l2_subdev_route` entries@@ -81,7 +90,7 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the - ``num_routes`` - Number of entries of the routes array * - __u32 - - ``reserved``\ [5] + - ``reserved``\ [11] - Reserved for future extensions. Applications and drivers must set the array to zero.drivers/media/v4l2-core/v4l2-ioctl.c +2
-2@@ -3155,13 +3155,13 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,case VIDIOC_SUBDEV_S_ROUTING : {struct v4l2_subdev_routing *routing = parg; -if (routing->num_routes >256 ) +if (routing->len_routes >256 )return -E2BIG ; *user_ptr =u64_to_user_ptr (routing->routes); *kernel_ptr = (void **)&routing->routes; *array_size =sizeof (struct v4l2_subdev_route ) - * routing->num_routes; + * routing->len_routes; ret =1 ;break ; }drivers/media/v4l2-core/v4l2-subdev.c +5
-1@@ -903,6 +903,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,if (routing->which !=V4L2_SUBDEV_FORMAT_TRY && ro_subdev)return -EPERM ; +if (routing->num_routes > routing->len_routes) +return -EINVAL ; +memset (routing->reserved,0 ,sizeof (routing->reserved));for (i =0 ; i < routing->num_routes; ++i) {@@ -929,6 +932,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, } krouting.num_routes = routing->num_routes; + krouting.len_routes = routing->len_routes; krouting.routes = routes; return v4l2_subdev_call(sd, pad, set_routing, state,@@ -949,7 +953,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting = &state->routing; -if (routing->num_routes < krouting->num_routes) { +if (routing->len_routes < krouting->num_routes) { routing->num_routes = krouting->num_routes;return -ENOSPC ; }include/media/v4l2-subdev.h +2
-0@@ -741,12 +741,14 @@ struct v4l2_subdev_stream_configs {/** * struct v4l2_subdev_krouting - subdev routing table * +* @len_routes: length of routes array, in routes * @num_routes: number of routes * @routes: &struct v4l2_subdev_route * * This structure contains the routing table for a subdev. */ struct v4l2_subdev_krouting { +unsigned int len_routes;unsigned int num_routes;struct v4l2_subdev_route *routes; };include/uapi/linux/v4l2-subdev.h +5
-3@@ -222,15 +222,17 @@ struct v4l2_subdev_route {* struct v4l2_subdev_routing - Subdev routing information * * @which: configuration type (from enum v4l2_subdev_format_whence) -* @num_routes: the total number of routes in the routes array +* @len_routes: the length of the routes array, in routes * @routes: pointer to the routes array +* @num_routes: the total number of routes in the routes array * @reserved: drivers and applications must zero this array */ struct v4l2_subdev_routing {__u32 which; -__u32 num_routes; +__u32 len_routes;__u64 routes; -__u32 reserved[6 ]; +__u32 num_routes; +__u32 reserved[11 ]; };/*
Signature · 3 lines
Regards, Laurent Pinchart
Laurent Pinchart
maintainerRe: [PATCH v4 19/23] media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
Quoted 34 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 6 lines · Sakari Ailus
The
len_routesfield is used to tell the size of the routes array in structv4l2_subdev_routing. This way the number of routes returned fromS_ROUTINGIOCTL may be larger than the number of routes provided, in case there are more routes returned by the driver.Note that this changes the (now-disabled) UAPI, users must be updated.
This cause a regression in all upstream drivers that call
v4l2_subdev_set_routing(). You need to patch the following files:
drivers/media/i2c/ds90ub913.cdrivers/media/i2c/ds90ub953.cdrivers/media/i2c/ds90ub960.cdrivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.cIt's a bit error-prone though. Consider the following change:
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +1
-0@@ -201,6 +201,7 @@ static int mxc_isi_crossbar_init_cfg(struct v4l2_subdev *sd, route->flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE ; } + routing.len_routes = xbar->num_sources; routing.num_routes = xbar->num_sources; routing.routes = routes;
Quoted 2 lines
It's easy to forget to set
len_routes:-S I wonder if we could do better.
Actually, this isn't needed. My problem was caused by a bug in patch 21/23.
Still, not initializing len_routes in drivers feels wrong.
Quoted 164 lines
Quoted 164 lines
Signed-off-by Sakari Ailus <[email protected]>--- .../media/v4l/vidioc-subdev-g-routing.rst | 31 ++++++++++++------- drivers/media/v4l2-core/v4l2-ioctl.c | 4 +-- drivers/media/v4l2-core/v4l2-subdev.c | 6 +++- include/media/v4l2-subdev.h | 2 ++ include/uapi/linux/v4l2-subdev.h | 8 +++-- 5 files changed, 34 insertions(+), 17 deletions(-)Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +20
-11@@ -46,20 +46,26 @@ with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and setting or clearing flags of the ``flags`` field of a struct :c:type:`v4l2_subdev_route`. -All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called. This -means that the userspace must reconfigure all streams after calling the ioctl -with e.g. ``VIDIOC_SUBDEV_S_FMT``. +All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is +called. This means that the userspace must reconfigure all streams after calling +the ioctl with e.g. ``VIDIOC_SUBDEV_S_FMT``. Only subdevices which have both sink and source pads can support routing. -When inspecting routes through ``VIDIOC_SUBDEV_G_ROUTING`` and the application -provided ``num_routes`` is not big enough to contain all the available routes -the subdevice exposes, drivers return the ENOSPC error code and adjust the -value of the ``num_routes`` field. Application should then reserve enough memory -for all the route entries and call ``VIDIOC_SUBDEV_G_ROUTING`` again. +The ``num_routes`` field is used to denote the number of routes set (set by user +space on ``VIDIOC_SUBDEV_S_ROUTING`` argument) on the routing table as well as +the number of routes returned back from both IOCTLs. The ``len_routes`` +signifies the number of routes that can fit into the ``routes`` array. The +userspace shall set ``len_routes`` for both IOCTLs and ``num_routes`` for +``VIDIOC_SUBDEV_S_ROUTING``. -On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the -``num_routes`` field to reflect the actual number of routes returned. +On a ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the ``num_routes`` +field to reflect the actual number of routes known by the driver. ``num_routes`` +larger than ``len_routes`` in both IOCTLs. In this ``len_routes`` were returned +back to the userspace. This is not an error. + +Also ``VIDIOC_SUBDEV_S_ROUTING`` may return more route than the user provided in +``num_routes`` field due to e.g. hardware properties. .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|@@ -74,6 +80,9 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the - ``which`` - Format to modified, from enum :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. + * - __u32 + - ``len_routes`` + - The length of the array (as in memory reserved for the array) * - struct :c:type:`v4l2_subdev_route` - ``routes[]`` - Array of struct :c:type:`v4l2_subdev_route` entries@@ -81,7 +90,7 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the - ``num_routes`` - Number of entries of the routes array * - __u32 - - ``reserved``\ [5] + - ``reserved``\ [11] - Reserved for future extensions. Applications and drivers must set the array to zero.drivers/media/v4l2-core/v4l2-ioctl.c +2
-2@@ -3155,13 +3155,13 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,case VIDIOC_SUBDEV_S_ROUTING : {struct v4l2_subdev_routing *routing = parg; -if (routing->num_routes >256 ) +if (routing->len_routes >256 )return -E2BIG ; *user_ptr =u64_to_user_ptr (routing->routes); *kernel_ptr = (void **)&routing->routes; *array_size =sizeof (struct v4l2_subdev_route ) - * routing->num_routes; + * routing->len_routes; ret =1 ;break ; }drivers/media/v4l2-core/v4l2-subdev.c +5
-1@@ -903,6 +903,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,if (routing->which !=V4L2_SUBDEV_FORMAT_TRY && ro_subdev)return -EPERM ; +if (routing->num_routes > routing->len_routes) +return -EINVAL ; +memset (routing->reserved,0 ,sizeof (routing->reserved));for (i =0 ; i < routing->num_routes; ++i) {@@ -929,6 +932,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, } krouting.num_routes = routing->num_routes; + krouting.len_routes = routing->len_routes; krouting.routes = routes; return v4l2_subdev_call(sd, pad, set_routing, state,@@ -949,7 +953,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting = &state->routing; -if (routing->num_routes < krouting->num_routes) { +if (routing->len_routes < krouting->num_routes) { routing->num_routes = krouting->num_routes;return -ENOSPC ; }include/media/v4l2-subdev.h +2
-0@@ -741,12 +741,14 @@ struct v4l2_subdev_stream_configs {/** * struct v4l2_subdev_krouting - subdev routing table * +* @len_routes: length of routes array, in routes * @num_routes: number of routes * @routes: &struct v4l2_subdev_route * * This structure contains the routing table for a subdev. */ struct v4l2_subdev_krouting { +unsigned int len_routes;unsigned int num_routes;struct v4l2_subdev_route *routes; };include/uapi/linux/v4l2-subdev.h +5
-3@@ -222,15 +222,17 @@ struct v4l2_subdev_route {* struct v4l2_subdev_routing - Subdev routing information * * @which: configuration type (from enum v4l2_subdev_format_whence) -* @num_routes: the total number of routes in the routes array +* @len_routes: the length of the routes array, in routes * @routes: pointer to the routes array +* @num_routes: the total number of routes in the routes array * @reserved: drivers and applications must zero this array */ struct v4l2_subdev_routing {__u32 which; -__u32 num_routes; +__u32 len_routes;__u64 routes; -__u32 reserved[6 ]; +__u32 num_routes; +__u32 reserved[11 ]; };/*
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH v4 19/23] media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
Hi Laurent,
Thanks for the review.
Quoted 35 lines · Laurent Pinchart
Quoted 34 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 6 lines · Sakari Ailus
The
len_routesfield is used to tell the size of the routes array in structv4l2_subdev_routing. This way the number of routes returned fromS_ROUTINGIOCTL may be larger than the number of routes provided, in case there are more routes returned by the driver.Note that this changes the (now-disabled) UAPI, users must be updated.
This cause a regression in all upstream drivers that call
v4l2_subdev_set_routing(). You need to patch the following files:
drivers/media/i2c/ds90ub913.cdrivers/media/i2c/ds90ub953.cdrivers/media/i2c/ds90ub960.cdrivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.cIt's a bit error-prone though. Consider the following change:
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +1
-0@@ -201,6 +201,7 @@ static int mxc_isi_crossbar_init_cfg(struct v4l2_subdev *sd, route->flags =V4L2_SUBDEV_ROUTE_FL_ACTIVE ; } + routing.len_routes = xbar->num_sources; routing.num_routes = xbar->num_sources; routing.routes = routes;
Quoted 7 lines
Quoted 2 lines
It's easy to forget to set
len_routes:-S I wonder if we could do better.Actually, this isn't needed. My problem was caused by a bug in patch 21/23.
Still, not initializing
len_routesin drivers feels wrong.
len_routes signifies the number of routes that can fit to the user-allocated routes array. Drivers do need to ensure they don't write more routes there, as the kernel allocates as much memory for the in-kernel array.
Signature · 3 lines
Kind regards, Sakari Ailus
Sakari Ailus
maintainerPATCH v4 20/23 media: v4l: subdev: Return routes set using S_ROUTING
In reply to Sakari AilusReturn the routes set using S_ROUTING back to the user. Also reflect this in documentation.
--- .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst | 5 +++-- drivers/media/v4l2-core/v4l2-subdev.c | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-)
Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +3 -2
@@ -43,8 +43,9 @@ The routing configuration determines the flows of data inside an entity. Drivers report their current routing tables using the ``VIDIOC_SUBDEV_G_ROUTING`` ioctl and application may enable or disable routes with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and -setting or clearing flags of the ``flags`` field of a -struct :c:type:`v4l2_subdev_route`. +setting or clearing flags of the ``flags`` field of a struct +:c:type:`v4l2_subdev_route`. Similarly to ``VIDIOC_SUBDEV_G_ROUTING``, also +``VIDIOC_SUBDEV_S_ROUTING`` returns the routes back to the user. All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called. This means that the userspace must reconfigure all streams after calling
drivers/media/v4l2-core/v4l2-subdev.c +4 -1
@@ -935,9 +935,12 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting.len_routes = routing->len_routes; krouting.routes = routes; -return v4l2_subdev_call (sd, pad, set_routing, state, + rval =v4l2_subdev_call (sd, pad, set_routing, state, routing->which, &krouting); +if (rval <0 ) +return rval; } + fallthrough;case VIDIOC_SUBDEV_G_ROUTING : {struct v4l2_subdev_routing *routing = arg;
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 21/23 media: uapi: Allow a larger number of routes than there's room for
In reply to Sakari AilusOn VIDIOC_SUBDEV_[GS]_ROUTING, only return as many routes back to the user as there's room. Do not consider it an error if more routes existed. Simply inform the user there are more routes.
--- .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst | 4 ---- drivers/media/v4l2-core/v4l2-subdev.c | 8 ++------ 2 files changed, 2 insertions(+), 10 deletions(-)
Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +0 -4
@@ -145,10 +145,6 @@ On success 0 is returned, on error -1 and the ``errno`` variable is set appropriately. The generic error codes are described at the :ref:`Generic Error Codes <gen-errors>` chapter. -ENOSPC - The application provided ``num_routes`` is not big enough to contain - all the available routes the subdevice exposes. - EINVAL The sink or source pad identifiers reference a non-existing pad, or reference pads of different types (ie. the sink_pad identifiers refers to a source pad).
drivers/media/v4l2-core/v4l2-subdev.c +2 -6
@@ -956,14 +956,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting = &state->routing; -if (routing->len_routes < krouting->num_routes) { - routing->num_routes = krouting->num_routes; -return -ENOSPC ; - } -memcpy ((struct v4l2_subdev_route *)(uintptr_t )routing->routes, krouting->routes, - krouting->num_routes *sizeof (*krouting->routes)); +min (krouting->num_routes, krouting->len_routes) * +sizeof (*krouting->routes)); routing->num_routes = krouting->num_routes;return 0 ;
Signature · 1 line
2.39.2
Laurent Pinchart
maintainerRe: [PATCH v4 21/23] media: uapi: Allow a larger number of routes than there's room for
Hi Sakari,
Thank you for the patch.
Quoted 32 lines · Sakari Ailus
On VIDIOC_SUBDEV_[GS]_ROUTING, only return as many routes back to the user as there's room. Do not consider it an error if more routes existed. Simply inform the user there are more routes.
Signed-off-by Sakari Ailus <[email protected]>--- .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst | 4 ---- drivers/media/v4l2-core/v4l2-subdev.c | 8 ++------ 2 files changed, 2 insertions(+), 10 deletions(-)Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +0
-4@@ -145,10 +145,6 @@ On success 0 is returned, on error -1 and the ``errno`` variable is set appropriately. The generic error codes are described at the :ref:`Generic Error Codes <gen-errors>` chapter. -ENOSPC - The application provided ``num_routes`` is not big enough to contain - all the available routes the subdevice exposes. - EINVAL The sink or source pad identifiers reference a non-existing pad, or reference pads of different types (ie. the sink_pad identifiers refers to a source pad).drivers/media/v4l2-core/v4l2-subdev.c +0
-0@@ -956,14 +956,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting = &state->routing;
drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 961
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +1
-6-if (routing->len_routes < krouting->num_routes) { - routing->num_routes = krouting->num_routes; -return -ENOSPC ; - } - memcpy((struct v4l2_subdev_route *)(uintptr_t)routing->routes, krouting->routes, - krouting->num_routes *sizeof (*krouting->routes)); + min(krouting->num_routes, krouting->len_routes) *
This should be
min(krouting->num_routes, routing->len_routes) *
Quoted 4 lines
drivers/media/v4l2-core/v4l2-subdev.c +1
-0+ sizeof(*krouting->routes)); routing->num_routes = krouting->num_routes;return 0 ;
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerRe: [PATCH v4 21/23] media: uapi: Allow a larger number of routes than there's room for
Quoted 50 lines · Laurent Pinchart
Hi Sakari,
Thank you for the patch.
Quoted 32 lines · Sakari Ailus
On VIDIOC_SUBDEV_[GS]_ROUTING, only return as many routes back to the user as there's room. Do not consider it an error if more routes existed. Simply inform the user there are more routes.
Signed-off-by Sakari Ailus <[email protected]>--- .../userspace-api/media/v4l/vidioc-subdev-g-routing.rst | 4 ---- drivers/media/v4l2-core/v4l2-subdev.c | 8 ++------ 2 files changed, 2 insertions(+), 10 deletions(-)Documentation/userspace-api/media/v4l/vidioc-subdev-g-routing.rst +0
-4@@ -145,10 +145,6 @@ On success 0 is returned, on error -1 and the ``errno`` variable is set appropriately. The generic error codes are described at the :ref:`Generic Error Codes <gen-errors>` chapter. -ENOSPC - The application provided ``num_routes`` is not big enough to contain - all the available routes the subdevice exposes. - EINVAL The sink or source pad identifiers reference a non-existing pad, or reference pads of different types (ie. the sink_pad identifiers refers to a source pad).drivers/media/v4l2-core/v4l2-subdev.c +0
-0@@ -956,14 +956,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, krouting = &state->routing;drivers/media/v4l2-core/v4l2-subdev.c static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg, · line 961
Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +1
-6-if (routing->len_routes < krouting->num_routes) { - routing->num_routes = krouting->num_routes; -return -ENOSPC ; - } - memcpy((struct v4l2_subdev_route *)(uintptr_t)routing->routes, krouting->routes, - krouting->num_routes *sizeof (*krouting->routes)); + min(krouting->num_routes, krouting->len_routes) *This should be
Quoted 1 line
min(krouting->num_routes, routing->len_routes) *
Thanks. I'll address this in v5.
Quoted 5 lines
Quoted 5 lines
drivers/media/v4l2-core/v4l2-subdev.c +1
-0+ sizeof(*krouting->routes)); routing->num_routes = krouting->num_routes;return 0 ;
Signature · 1 line
Sakari Ailus
Sakari Ailus
maintainerPATCH v4 22/23 media: v4l: subdev: Add trivial set_routing support
In reply to Sakari AilusAdd trivial S_ROUTING IOCTL support for drivers where routing is static. Essentially this means returning the same information G_ROUTING call would have done.
--- drivers/media/v4l2-core/v4l2-subdev.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/v4l2-core/v4l2-subdev.c +4 -0
@@ -894,6 +894,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,struct v4l2_subdev_krouting krouting = {};unsigned int i; +if (!v4l2_subdev_has_op (sd, pad, set_routing)) + goto do_vidioc_subdev_g_routing; +if (!v4l2_subdev_enable_streams_api)return -ENOIOCTLCMD ;
@@ -941,6 +944,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,return rval; } fallthrough; +do_vidioc_subdev_g_routing:case VIDIOC_SUBDEV_G_ROUTING : {struct v4l2_subdev_routing *routing = arg;
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH v4 23/23 media: uapi: v4l: subdev: Enable streams API
In reply to Sakari AilusRemove v4l2_subdev_enable_streams_api variable that was used to easily enable streams API for development, and conditions that use the variable.
This patch enables the streams API for V4L2 sub-device interface which allows transporting multiple streams on a single MC link.
--- drivers/media/v4l2-core/v4l2-subdev.c | 23 ----------------------- 1 file changed, 23 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +0 -23
@@ -26,15 +26,6 @@#include <media/v4l2-fh.h> #include <media/v4l2-ioctl.h> -#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API ) -/* -* The Streams API is an experimental feature. To use the Streams API, set -* 'v4l2_subdev_enable_streams_api' to 1 below. -*/ - -static bool v4l2_subdev_enable_streams_api; -#endif -/* * Maximum stream ID is 63 for now, as we use u64 bitmask to represent a set * of streams.
@@ -897,9 +888,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,if (!v4l2_subdev_has_op (sd, pad, set_routing)) goto do_vidioc_subdev_g_routing; -if (!v4l2_subdev_enable_streams_api) -return -ENOIOCTLCMD ; -if (!(sd->flags &V4L2_SUBDEV_FL_STREAMS ))return -ENOIOCTLCMD ;
@@ -950,9 +938,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,struct v4l2_subdev_routing *routing = arg;struct v4l2_subdev_krouting *krouting; -if (!v4l2_subdev_enable_streams_api) -return -ENOIOCTLCMD ; -if (!(sd->flags &V4L2_SUBDEV_FL_STREAMS ))return -ENOIOCTLCMD ;
@@ -980,14 +965,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,case VIDIOC_SUBDEV_S_CLIENT_CAP : {struct v4l2_subdev_client_capability *client_cap = arg; -/* -* Clear V4L2_SUBDEV_CLIENT_CAP_STREAMS if streams API is not -* enabled. Remove this when streams API is no longer -* experimental. -*/ -if (!v4l2_subdev_enable_streams_api) - client_cap->capabilities &= ~V4L2_SUBDEV_CLIENT_CAP_STREAMS ; -/* Filter out unsupported capabilities */ client_cap->capabilities &=V4L2_SUBDEV_CLIENT_CAP_STREAMS ;
Signature · 1 line
2.39.2