linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config
@ 2019-11-04 13:09 Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 2/6] media: v4l2_ctrl: Add const pointer to ctrl_ptr Ricardo Ribalda Delgado
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Ricardo Ribalda Delgado @ 2019-11-04 13:09 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, linux-kernel; +Cc: Ricardo Ribalda Delgado

This allows setting the default value on compound controls created via
v4l2_ctrl_new_custom.

Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
 drivers/media/v4l2-core/v4l2-ctrls.c | 2 +-
 include/media/v4l2-ctrls.h           | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index b4caf2d4d076..73d99c3561ce 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -2690,7 +2690,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
 			type, min, max,
 			is_menu ? cfg->menu_skip_mask : step, def,
 			cfg->dims, cfg->elem_size,
-			flags, qmenu, qmenu_int, ptr_null, priv);
+			flags, qmenu, qmenu_int, cfg->p_def, priv);
 	if (ctrl)
 		ctrl->is_private = cfg->is_private;
 	return ctrl;
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index e719d56fc024..78a97b10c89e 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -382,6 +382,7 @@ struct v4l2_ctrl_handler {
  * @max:	The control's maximum value.
  * @step:	The control's step value for non-menu controls.
  * @def:	The control's default value.
+ * @p_def:	The control's default value for compound controls.
  * @dims:	The size of each dimension.
  * @elem_size:	The size in bytes of the control.
  * @flags:	The control's flags.
@@ -410,6 +411,7 @@ struct v4l2_ctrl_config {
 	s64 max;
 	u64 step;
 	s64 def;
+	union v4l2_ctrl_ptr p_def;
 	u32 dims[V4L2_CTRL_MAX_DIMS];
 	u32 elem_size;
 	u32 flags;
-- 
2.24.0.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 2/6] media: v4l2_ctrl: Add const pointer to ctrl_ptr
  2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
@ 2019-11-04 13:09 ` Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 3/6] media: vivid: Add an area control Ricardo Ribalda Delgado
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Ricardo Ribalda Delgado @ 2019-11-04 13:09 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, linux-kernel; +Cc: Ricardo Ribalda Delgado

This pointer is used to point to data that is constant. Thanks to this
we can avoid a lot of casting and we make more clear when the data is
constant or variable.

Suggested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
 include/media/v4l2-ctrls.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 78a97b10c89e..7db9e719a583 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -56,6 +56,7 @@ struct poll_table_struct;
  * @p_hevc_slice_params:	Pointer to an HEVC slice parameters structure.
  * @p_area:			Pointer to an area.
  * @p:				Pointer to a compound value.
+ * @p_const:			Pointer to a constant compound value.
  */
 union v4l2_ctrl_ptr {
 	s32 *p_s32;
@@ -78,6 +79,7 @@ union v4l2_ctrl_ptr {
 	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
 	struct v4l2_area *p_area;
 	void *p;
+	const void *p_const;
 };
 
 /**
-- 
2.24.0.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 3/6] media: vivid: Add an area control
  2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 2/6] media: v4l2_ctrl: Add const pointer to ctrl_ptr Ricardo Ribalda Delgado
@ 2019-11-04 13:09 ` Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 4/6] media: v4l2_core: Add p_area to struct v4l2_ext_control Ricardo Ribalda Delgado
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Ricardo Ribalda Delgado @ 2019-11-04 13:09 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, linux-kernel; +Cc: Ricardo Ribalda Delgado

This control represents a generic read/write area.

Suggested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
 drivers/media/platform/vivid/vivid-ctrls.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/media/platform/vivid/vivid-ctrls.c b/drivers/media/platform/vivid/vivid-ctrls.c
index b250fc3764e2..68e8124c7973 100644
--- a/drivers/media/platform/vivid/vivid-ctrls.c
+++ b/drivers/media/platform/vivid/vivid-ctrls.c
@@ -32,6 +32,7 @@
 #define VIVID_CID_U32_ARRAY		(VIVID_CID_CUSTOM_BASE + 8)
 #define VIVID_CID_U16_MATRIX		(VIVID_CID_CUSTOM_BASE + 9)
 #define VIVID_CID_U8_4D_ARRAY		(VIVID_CID_CUSTOM_BASE + 10)
+#define VIVID_CID_AREA			(VIVID_CID_CUSTOM_BASE + 11)
 
 #define VIVID_CID_VIVID_BASE		(0x00f00000 | 0xf000)
 #define VIVID_CID_VIVID_CLASS		(0x00f00000 | 1)
@@ -266,6 +267,18 @@ static const struct v4l2_ctrl_config vivid_ctrl_disconnect = {
 	.type = V4L2_CTRL_TYPE_BUTTON,
 };
 
+static const struct v4l2_area area = {
+	.width = 1000,
+	.height = 2000,
+};
+
+static const struct v4l2_ctrl_config vivid_ctrl_area = {
+	.ops = &vivid_user_gen_ctrl_ops,
+	.id = VIVID_CID_AREA,
+	.name = "Area",
+	.type = V4L2_CTRL_TYPE_AREA,
+	.p_def.p_const = &area,
+};
 
 /* Framebuffer Controls */
 
@@ -1574,6 +1587,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	dev->string = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_string, NULL);
 	dev->bitmask = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_bitmask, NULL);
 	dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL);
+	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL);
 	v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u8_4d_array, NULL);
-- 
2.24.0.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 4/6] media: v4l2_core: Add p_area to struct v4l2_ext_control
  2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 2/6] media: v4l2_ctrl: Add const pointer to ctrl_ptr Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 3/6] media: vivid: Add an area control Ricardo Ribalda Delgado
@ 2019-11-04 13:09 ` Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 5/6] Documentation: v42l_core: v4l2_ext_control Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 6/6] media: v4l2-ctrl: Use p_const when possible Ricardo Ribalda Delgado
  4 siblings, 0 replies; 6+ messages in thread
From: Ricardo Ribalda Delgado @ 2019-11-04 13:09 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, linux-kernel; +Cc: Ricardo Ribalda Delgado

Allow accessing V4L2_CTRL_TYPE_AREA controls without any casting.

Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
 include/uapi/linux/videodev2.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index f98bbcced8ff..04481c717fee 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -1684,6 +1684,7 @@ struct v4l2_ext_control {
 		__u8 __user *p_u8;
 		__u16 __user *p_u16;
 		__u32 __user *p_u32;
+		struct v4l2_area __user *p_area;
 		void __user *ptr;
 	};
 } __attribute__ ((packed));
-- 
2.24.0.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 5/6] Documentation: v42l_core: v4l2_ext_control
  2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
                   ` (2 preceding siblings ...)
  2019-11-04 13:09 ` [PATCH v4 4/6] media: v4l2_core: Add p_area to struct v4l2_ext_control Ricardo Ribalda Delgado
@ 2019-11-04 13:09 ` Ricardo Ribalda Delgado
  2019-11-04 13:09 ` [PATCH v4 6/6] media: v4l2-ctrl: Use p_const when possible Ricardo Ribalda Delgado
  4 siblings, 0 replies; 6+ messages in thread
From: Ricardo Ribalda Delgado @ 2019-11-04 13:09 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, linux-kernel; +Cc: Ricardo Ribalda Delgado

Describe p_area field from v4l2_ext_ctrl

Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
 Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst b/Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst
index 13dc1a986249..271cac18afbb 100644
--- a/Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst
+++ b/Documentation/media/uapi/v4l/vidioc-g-ext-ctrls.rst
@@ -198,6 +198,11 @@ still cause this situation.
       - ``p_u32``
       - A pointer to a matrix control of unsigned 32-bit values. Valid if
 	this control is of type ``V4L2_CTRL_TYPE_U32``.
+    * -
+      - :c:type:`v4l2_area` *
+      - ``p_area``
+      - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is
+        of type ``V4L2_CTRL_TYPE_AREA``.
     * -
       - void *
       - ``ptr``
-- 
2.24.0.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 6/6] media: v4l2-ctrl: Use p_const when possible
  2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
                   ` (3 preceding siblings ...)
  2019-11-04 13:09 ` [PATCH v4 5/6] Documentation: v42l_core: v4l2_ext_control Ricardo Ribalda Delgado
@ 2019-11-04 13:09 ` Ricardo Ribalda Delgado
  4 siblings, 0 replies; 6+ messages in thread
From: Ricardo Ribalda Delgado @ 2019-11-04 13:09 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, linux-kernel; +Cc: Ricardo Ribalda Delgado

After adding a const pointer to ctrl_ptr, lets use it where it make
sense.

Suggested-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Ricardo Ribalda Delgado <ribalda@kernel.org>
---
 drivers/media/v4l2-core/v4l2-ctrls.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index 73d99c3561ce..a565ae3ba7e4 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -1556,7 +1556,8 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 		if (ctrl->is_int)
 			return ptr1.p_s32[idx] == ptr2.p_s32[idx];
 		idx *= ctrl->elem_size;
-		return !memcmp(ptr1.p + idx, ptr2.p + idx, ctrl->elem_size);
+		return !memcmp(ptr1.p_const + idx, ptr2.p_const + idx,
+			       ctrl->elem_size);
 	}
 }
 
@@ -1566,8 +1567,8 @@ static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
 	void *p = ptr.p + idx * ctrl->elem_size;
 
-	if (ctrl->p_def.p)
-		memcpy(p, ctrl->p_def.p, ctrl->elem_size);
+	if (ctrl->p_def.p_const)
+		memcpy(p, ctrl->p_def.p_const, ctrl->elem_size);
 	else
 		memset(p, 0, ctrl->elem_size);
 
@@ -1954,7 +1955,7 @@ static int ptr_to_user(struct v4l2_ext_control *c,
 	u32 len;
 
 	if (ctrl->is_ptr && !ctrl->is_string)
-		return copy_to_user(c->ptr, ptr.p, c->size) ?
+		return copy_to_user(c->ptr, ptr.p_const, c->size) ?
 		       -EFAULT : 0;
 
 	switch (ctrl->type) {
@@ -2069,7 +2070,7 @@ static void ptr_to_ptr(struct v4l2_ctrl *ctrl,
 {
 	if (ctrl == NULL)
 		return;
-	memcpy(to.p, from.p, ctrl->elems * ctrl->elem_size);
+	memcpy(to.p, from.p_const, ctrl->elems * ctrl->elem_size);
 }
 
 /* Copy the new value to the current value. */
@@ -2587,7 +2588,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 		 is_array)
 		sz_extra += 2 * tot_ctrl_size;
 
-	if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p)
+	if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const)
 		sz_extra += elem_size;
 
 	ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
@@ -2634,9 +2635,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 		ctrl->p_cur.p = &ctrl->cur.val;
 	}
 
-	if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p) {
+	if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) {
 		ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size;
-		memcpy(ctrl->p_def.p, p_def.p, elem_size);
+		memcpy(ctrl->p_def.p, p_def.p_const, elem_size);
 	}
 
 	for (idx = 0; idx < elems; idx++) {
-- 
2.24.0.rc1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-04 13:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 13:09 [PATCH v4 1/6] media: v4l2_ctrl: Add p_def to v4l2_ctrl_config Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 2/6] media: v4l2_ctrl: Add const pointer to ctrl_ptr Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 3/6] media: vivid: Add an area control Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 4/6] media: v4l2_core: Add p_area to struct v4l2_ext_control Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 5/6] Documentation: v42l_core: v4l2_ext_control Ricardo Ribalda Delgado
2019-11-04 13:09 ` [PATCH v4 6/6] media: v4l2-ctrl: Use p_const when possible Ricardo Ribalda Delgado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).