From 48ea0be06028d97b57602372f032afbec02e7e97 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Thu, 10 May 2012 05:36:00 -0300 Subject: [media] v4l2-dev/ioctl: determine the valid ioctls upfront Rather than testing whether an ioctl is implemented in the driver or not every time the ioctl is called, do it upfront when the device is registered. This also allows a driver to disable certain ioctls based on the capabilities of the detected board, something you can't do today without creating separate v4l2_ioctl_ops structs for each new variation. For the most part it is pretty straightforward, but for control ioctls a flag is needed since it is possible that you have per-filehandle controls, and that can't be determined upfront of course. Signed-off-by: Hans Verkuil Acked-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-dev.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/media') diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index d00b9d3511f2..a5ecec66d3c8 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -126,6 +126,7 @@ struct video_device /* ioctl callbacks */ const struct v4l2_ioctl_ops *ioctl_ops; + DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE); /* serialization lock */ DECLARE_BITMAP(dont_use_lock, BASE_VIDIOC_PRIVATE); @@ -184,6 +185,16 @@ static inline void v4l2_dont_use_lock(struct video_device *vdev, unsigned int cm set_bit(_IOC_NR(cmd), vdev->dont_use_lock); } +/* Mark that this command isn't implemented, must be called before + video_device_register. See also the comments in determine_valid_ioctls(). + This function allows drivers to provide just one v4l2_ioctl_ops struct, but + disable ioctls based on the specific card that is actually found. */ +static inline void v4l2_dont_use_cmd(struct video_device *vdev, unsigned int cmd) +{ + if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE) + set_bit(_IOC_NR(cmd), vdev->valid_ioctls); +} + /* helper functions to access driver private data. */ static inline void *video_get_drvdata(struct video_device *vdev) { -- cgit v1.2.3