mirror of
https://github.com/torvalds/linux
synced 2024-07-21 18:51:47 +00:00
media: v4l: subdev: Add len_routes field to struct v4l2_subdev_routing
The 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 uAPI is still disabled in the code, so this change can safely be done. Anyone who manually patched the code to enable this uAPI must update their code. The patch also increases the number of reserved fields in struct v4l2_subdev_routing. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
parent
38c84932de
commit
83a22a07cd
|
@ -43,23 +43,38 @@ The routing configuration determines the flows of data inside an entity.
|
||||||
Drivers report their current routing tables using the
|
Drivers report their current routing tables using the
|
||||||
``VIDIOC_SUBDEV_G_ROUTING`` ioctl and application may enable or disable routes
|
``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
|
with the ``VIDIOC_SUBDEV_S_ROUTING`` ioctl, by adding or removing routes and
|
||||||
setting or clearing flags of the ``flags`` field of a
|
setting or clearing flags of the ``flags`` field of a struct
|
||||||
struct :c:type:`v4l2_subdev_route`.
|
:c:type:`v4l2_subdev_route`.
|
||||||
|
|
||||||
All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called. This
|
All stream configurations are reset when ``VIDIOC_SUBDEV_S_ROUTING`` is called.
|
||||||
means that the userspace must reconfigure all streams after calling the ioctl
|
This means that the userspace must reconfigure all stream formats and selections
|
||||||
with e.g. ``VIDIOC_SUBDEV_S_FMT``.
|
after calling the ioctl with e.g. ``VIDIOC_SUBDEV_S_FMT``.
|
||||||
|
|
||||||
Only subdevices which have both sink and source pads can support routing.
|
Only subdevices which have both sink and source pads can support routing.
|
||||||
|
|
||||||
When inspecting routes through ``VIDIOC_SUBDEV_G_ROUTING`` and the application
|
The ``len_routes`` field indicates the number of routes that can fit in the
|
||||||
provided ``num_routes`` is not big enough to contain all the available routes
|
``routes`` array allocated by userspace. It is set by applications for both
|
||||||
the subdevice exposes, drivers return the ENOSPC error code and adjust the
|
ioctls to indicate how many routes the kernel can return, and is never modified
|
||||||
value of the ``num_routes`` field. Application should then reserve enough memory
|
by the kernel.
|
||||||
for all the route entries and call ``VIDIOC_SUBDEV_G_ROUTING`` again.
|
|
||||||
|
|
||||||
On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the
|
The ``num_routes`` field indicates the number of routes in the routing
|
||||||
``num_routes`` field to reflect the actual number of routes returned.
|
table. For ``VIDIOC_SUBDEV_S_ROUTING``, it is set by userspace to the number of
|
||||||
|
routes that the application stored in the ``routes`` array. For both ioctls, it
|
||||||
|
is returned by the kernel and indicates how many routes are stored in the
|
||||||
|
subdevice routing table. This may be smaller or larger than the value of
|
||||||
|
``num_routes`` set by the application for ``VIDIOC_SUBDEV_S_ROUTING``, as
|
||||||
|
drivers may adjust the requested routing table.
|
||||||
|
|
||||||
|
The kernel can return a ``num_routes`` value larger than ``len_routes`` from
|
||||||
|
both ioctls. This indicates thare are more routes in the routing table than fits
|
||||||
|
the ``routes`` array. In this case, the ``routes`` array is filled by the kernel
|
||||||
|
with the first ``len_routes`` entries of the subdevice routing table. This is
|
||||||
|
not considered to be an error, and the ioctl call succeeds. If the applications
|
||||||
|
wants to retrieve the missing routes, it can issue a new
|
||||||
|
``VIDIOC_SUBDEV_G_ROUTING`` call with a large enough ``routes`` array.
|
||||||
|
|
||||||
|
``VIDIOC_SUBDEV_S_ROUTING`` may return more routes than the user provided in
|
||||||
|
``num_routes`` field due to e.g. hardware properties.
|
||||||
|
|
||||||
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
|
.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
|
||||||
|
|
||||||
|
@ -74,6 +89,9 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the
|
||||||
- ``which``
|
- ``which``
|
||||||
- Routing table to be accessed, from enum
|
- Routing table to be accessed, from enum
|
||||||
:ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`.
|
: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`
|
* - struct :c:type:`v4l2_subdev_route`
|
||||||
- ``routes[]``
|
- ``routes[]``
|
||||||
- Array of struct :c:type:`v4l2_subdev_route` entries
|
- Array of struct :c:type:`v4l2_subdev_route` entries
|
||||||
|
@ -81,7 +99,7 @@ On a successful ``VIDIOC_SUBDEV_G_ROUTING`` call the driver updates the
|
||||||
- ``num_routes``
|
- ``num_routes``
|
||||||
- Number of entries of the routes array
|
- Number of entries of the routes array
|
||||||
* - __u32
|
* - __u32
|
||||||
- ``reserved``\ [5]
|
- ``reserved``\ [11]
|
||||||
- Reserved for future extensions. Applications and drivers must set
|
- Reserved for future extensions. Applications and drivers must set
|
||||||
the array to zero.
|
the array to zero.
|
||||||
|
|
||||||
|
|
|
@ -3201,13 +3201,13 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
|
||||||
case VIDIOC_SUBDEV_S_ROUTING: {
|
case VIDIOC_SUBDEV_S_ROUTING: {
|
||||||
struct v4l2_subdev_routing *routing = parg;
|
struct v4l2_subdev_routing *routing = parg;
|
||||||
|
|
||||||
if (routing->num_routes > 256)
|
if (routing->len_routes > 256)
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
|
|
||||||
*user_ptr = u64_to_user_ptr(routing->routes);
|
*user_ptr = u64_to_user_ptr(routing->routes);
|
||||||
*kernel_ptr = (void **)&routing->routes;
|
*kernel_ptr = (void **)&routing->routes;
|
||||||
*array_size = sizeof(struct v4l2_subdev_route)
|
*array_size = sizeof(struct v4l2_subdev_route)
|
||||||
* routing->num_routes;
|
* routing->len_routes;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -960,14 +960,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,
|
||||||
|
|
||||||
krouting = &state->routing;
|
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,
|
memcpy((struct v4l2_subdev_route *)(uintptr_t)routing->routes,
|
||||||
krouting->routes,
|
krouting->routes,
|
||||||
krouting->num_routes * sizeof(*krouting->routes));
|
min(krouting->num_routes, routing->len_routes) *
|
||||||
|
sizeof(*krouting->routes));
|
||||||
routing->num_routes = krouting->num_routes;
|
routing->num_routes = krouting->num_routes;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -989,6 +985,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,
|
||||||
if (routing->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)
|
if (routing->which != V4L2_SUBDEV_FORMAT_TRY && ro_subdev)
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
|
if (routing->num_routes > routing->len_routes)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
memset(routing->reserved, 0, sizeof(routing->reserved));
|
memset(routing->reserved, 0, sizeof(routing->reserved));
|
||||||
|
|
||||||
for (i = 0; i < routing->num_routes; ++i) {
|
for (i = 0; i < routing->num_routes; ++i) {
|
||||||
|
@ -1015,6 +1014,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg,
|
||||||
}
|
}
|
||||||
|
|
||||||
krouting.num_routes = routing->num_routes;
|
krouting.num_routes = routing->num_routes;
|
||||||
|
krouting.len_routes = routing->len_routes;
|
||||||
krouting.routes = routes;
|
krouting.routes = routes;
|
||||||
|
|
||||||
return v4l2_subdev_call(sd, pad, set_routing, state,
|
return v4l2_subdev_call(sd, pad, set_routing, state,
|
||||||
|
|
|
@ -714,12 +714,14 @@ struct v4l2_subdev_stream_configs {
|
||||||
/**
|
/**
|
||||||
* struct v4l2_subdev_krouting - subdev routing table
|
* struct v4l2_subdev_krouting - subdev routing table
|
||||||
*
|
*
|
||||||
|
* @len_routes: length of routes array, in routes
|
||||||
* @num_routes: number of routes
|
* @num_routes: number of routes
|
||||||
* @routes: &struct v4l2_subdev_route
|
* @routes: &struct v4l2_subdev_route
|
||||||
*
|
*
|
||||||
* This structure contains the routing table for a subdev.
|
* This structure contains the routing table for a subdev.
|
||||||
*/
|
*/
|
||||||
struct v4l2_subdev_krouting {
|
struct v4l2_subdev_krouting {
|
||||||
|
unsigned int len_routes;
|
||||||
unsigned int num_routes;
|
unsigned int num_routes;
|
||||||
struct v4l2_subdev_route *routes;
|
struct v4l2_subdev_route *routes;
|
||||||
};
|
};
|
||||||
|
|
|
@ -228,15 +228,19 @@ struct v4l2_subdev_route {
|
||||||
* struct v4l2_subdev_routing - Subdev routing information
|
* struct v4l2_subdev_routing - Subdev routing information
|
||||||
*
|
*
|
||||||
* @which: configuration type (from enum v4l2_subdev_format_whence)
|
* @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; set by the user, not
|
||||||
|
* modified by the kernel
|
||||||
* @routes: pointer to the routes array
|
* @routes: pointer to the routes array
|
||||||
|
* @num_routes: the total number of routes, possibly more than fits in the
|
||||||
|
* routes array
|
||||||
* @reserved: drivers and applications must zero this array
|
* @reserved: drivers and applications must zero this array
|
||||||
*/
|
*/
|
||||||
struct v4l2_subdev_routing {
|
struct v4l2_subdev_routing {
|
||||||
__u32 which;
|
__u32 which;
|
||||||
__u32 num_routes;
|
__u32 len_routes;
|
||||||
__u64 routes;
|
__u64 routes;
|
||||||
__u32 reserved[6];
|
__u32 num_routes;
|
||||||
|
__u32 reserved[11];
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue