Skip to content

Commit 3fb0ee8

Browse files
jmondimchehab
authored andcommitted
media: Documentation: media: Document read-only subdevice
Document a new kAPI function to register subdev device nodes in read only mode and for each affected ioctl report how access is restricted. Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 18200e9 commit 3fb0ee8

8 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎Documentation/driver-api/media/v4l2-subdev.rst‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,50 @@ Private ioctls
332332
All ioctls not in the above list are passed directly to the sub-device
333333
driver through the core::ioctl operation.
334334

335+
Read-only sub-device userspace API
336+
----------------------------------
337+
338+
Bridge drivers that control their connected subdevices through direct calls to
339+
the kernel API realized by :c:type:`v4l2_subdev_ops` structure do not usually
340+
want userspace to be able to change the same parameters through the subdevice
341+
device node and thus do not usually register any.
342+
343+
It is sometimes useful to report to userspace the current subdevice
344+
configuration through a read-only API, that does not permit applications to
345+
change to the device parameters but allows interfacing to the subdevice device
346+
node to inspect them.
347+
348+
For instance, to implement cameras based on computational photography, userspace
349+
needs to know the detailed camera sensor configuration (in terms of skipping,
350+
binning, cropping and scaling) for each supported output resolution. To support
351+
such use cases, bridge drivers may expose the subdevice operations to userspace
352+
through a read-only API.
353+
354+
To create a read-only device node for all the subdevices registered with the
355+
``V4L2_SUBDEV_FL_HAS_DEVNODE`` set, the :c:type:`v4l2_device` driver should call
356+
:c:func:`v4l2_device_register_ro_subdev_nodes`.
357+
358+
Access to the following ioctls for userspace applications is restricted on
359+
sub-device device nodes registered with
360+
:c:func:`v4l2_device_register_ro_subdev_nodes`.
361+
362+
``VIDIOC_SUBDEV_S_FMT``,
363+
``VIDIOC_SUBDEV_S_CROP``,
364+
``VIDIOC_SUBDEV_S_SELECTION``:
365+
366+
These ioctls are only allowed on a read-only subdevice device node
367+
for the :ref:`V4L2_SUBDEV_FORMAT_TRY <v4l2-subdev-format-whence>`
368+
formats and selection rectangles.
369+
370+
``VIDIOC_SUBDEV_S_FRAME_INTERVAL``,
371+
``VIDIOC_SUBDEV_S_DV_TIMINGS``,
372+
``VIDIOC_SUBDEV_S_STD``:
373+
374+
These ioctls are not allowed on a read-only subdevice node.
375+
376+
In case the ioctl is not allowed, or the format to modify is set to
377+
``V4L2_SUBDEV_FORMAT_ACTIVE``, the core returns a negative error code and
378+
the errno variable is set to ``-EPERM``.
335379

336380
I2C sub-device drivers
337381
----------------------

‎Documentation/userspace-api/media/v4l/dev-subdev.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ will feature a character device node on which ioctls can be called to
3939
Sub-device character device nodes, conventionally named
4040
``/dev/v4l-subdev*``, use major number 81.
4141

42+
Drivers may opt to limit the sub-device character devices to only expose
43+
operations that do not modify the device state. In such a case the sub-devices
44+
are referred to as ``read-only`` in the rest of this documentation, and the
45+
related restrictions are documented in individual ioctls.
46+
4247

4348
Controls
4449
========

‎Documentation/userspace-api/media/v4l/vidioc-g-dv-timings.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ pointer to the struct :c:type:`v4l2_dv_timings`
5757
structure as argument. If the ioctl is not supported or the timing
5858
values are not correct, the driver returns ``EINVAL`` error code.
5959
60+
Calling ``VIDIOC_SUBDEV_S_DV_TIMINGS`` on a subdev device node that has been
61+
registered in read-only mode is not allowed. An error is returned and the errno
62+
variable is set to ``-EPERM``.
63+
6064
The ``linux/v4l2-dv-timings.h`` header can be used to get the timings of
6165
the formats in the :ref:`cea861` and :ref:`vesadmt` standards. If
6266
the current input or output does not support DV timings (e.g. if
@@ -81,6 +85,8 @@ ENODATA
8185
EBUSY
8286
The device is busy and therefore can not change the timings.
8387
88+
EPERM
89+
``VIDIOC_SUBDEV_S_DV_TIMINGS`` has been called on a read-only subdevice.
8490
8591
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
8692

‎Documentation/userspace-api/media/v4l/vidioc-g-std.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ video timings (e.g. if :ref:`VIDIOC_ENUMINPUT`
6666
does not set the ``V4L2_IN_CAP_STD`` flag), then ``ENODATA`` error code is
6767
returned.
6868
69+
Calling ``VIDIOC_SUBDEV_S_STD`` on a subdev device node that has been registered
70+
in read-only mode is not allowed. An error is returned and the errno variable is
71+
set to ``-EPERM``.
6972
7073
Return Value
7174
============
@@ -79,3 +82,6 @@ EINVAL
7982
8083
ENODATA
8184
Standard video timings are not supported for this input or output.
85+
86+
EPERM
87+
``VIDIOC_SUBDEV_S_STD`` has been called on a read-only subdevice.

‎Documentation/userspace-api/media/v4l/vidioc-subdev-g-crop.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ crop rectangles and stored in the sub-device file handle. Two
7373
applications querying the same sub-device would thus not interact with
7474
each other.
7575
76+
If the subdev device node has been registered in read-only mode, calls to
77+
``VIDIOC_SUBDEV_S_CROP`` are only valid if the ``which`` field is set to
78+
``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
79+
variable is set to ``-EPERM``.
80+
7681
Drivers must not return an error solely because the requested crop
7782
rectangle doesn't match the device capabilities. They must instead
7883
modify the rectangle to match what the hardware can provide. The
@@ -123,3 +128,7 @@ EINVAL
123128
references a non-existing pad, the ``which`` field references a
124129
non-existing format, or cropping is not supported on the given
125130
subdev pad.
131+
132+
EPERM
133+
The ``VIDIOC_SUBDEV_S_CROP`` ioctl has been called on a read-only subdevice
134+
and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.

‎Documentation/userspace-api/media/v4l/vidioc-subdev-g-fmt.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ current links configuration or sub-device controls value. For instance,
7878
a low-pass noise filter might crop pixels at the frame boundaries,
7979
modifying its output frame size.
8080
81+
If the subdev device node has been registered in read-only mode, calls to
82+
``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to
83+
``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
84+
variable is set to ``-EPERM``.
85+
8186
Drivers must not return an error solely because the requested format
8287
doesn't match the device capabilities. They must instead modify the
8388
format to match what the hardware can provide. The modified format
@@ -146,6 +151,9 @@ EINVAL
146151
``pad`` references a non-existing pad, or the ``which`` field
147152
references a non-existing format.
148153
154+
EPERM
155+
The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice
156+
and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.
149157
150158
============
151159

‎Documentation/userspace-api/media/v4l/vidioc-subdev-g-frame-interval.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ struct
6565
contains the current frame interval as would be returned by a
6666
``VIDIOC_SUBDEV_G_FRAME_INTERVAL`` call.
6767
68+
Calling ``VIDIOC_SUBDEV_S_FRAME_INTERVAL`` on a subdev device node that has been
69+
registered in read-only mode is not allowed. An error is returned and the errno
70+
variable is set to ``-EPERM``.
71+
6872
Drivers must not return an error solely because the requested interval
6973
doesn't match the device capabilities. They must instead modify the
7074
interval to match what the hardware can provide. The modified interval
@@ -118,3 +122,7 @@ EINVAL
118122
:c:type:`v4l2_subdev_frame_interval`
119123
``pad`` references a non-existing pad, or the pad doesn't support
120124
frame intervals.
125+
126+
EPERM
127+
The ``VIDIOC_SUBDEV_S_FRAME_INTERVAL`` ioctl has been called on a read-only
128+
subdevice.

‎Documentation/userspace-api/media/v4l/vidioc-subdev-g-selection.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ function of the crop API, and more, are supported by the selections API.
5353
See :ref:`subdev` for more information on how each selection target
5454
affects the image processing pipeline inside the subdevice.
5555
56+
If the subdev device node has been registered in read-only mode, calls to
57+
``VIDIOC_SUBDEV_S_SELECTION`` are only valid if the ``which`` field is set to
58+
``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno
59+
variable is set to ``-EPERM``.
5660
5761
Types of selection targets
5862
--------------------------
@@ -123,3 +127,7 @@ EINVAL
123127
``pad`` references a non-existing pad, the ``which`` field
124128
references a non-existing format, or the selection target is not
125129
supported on the given subdev pad.
130+
131+
EPERM
132+
The ``VIDIOC_SUBDEV_S_SELECTION`` ioctl has been called on a read-only
133+
subdevice and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``.

0 commit comments

Comments
 (0)