Lines Matching full:ctrl
41 struct v4l2_ctrl *ctrl, in ptr_to_user() argument
46 if (ctrl->is_ptr && !ctrl->is_string) in ptr_to_user()
50 switch (ctrl->type) { in ptr_to_user()
54 c->size = ctrl->elem_size; in ptr_to_user()
70 static int cur_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) in cur_to_user() argument
72 return ptr_to_user(c, ctrl, ctrl->p_cur); in cur_to_user()
77 struct v4l2_ctrl *ctrl) in new_to_user() argument
79 return ptr_to_user(c, ctrl, ctrl->p_new); in new_to_user()
86 return ptr_to_user(c, ref->ctrl, ref->p_req); in req_to_user()
90 static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) in def_to_user() argument
92 ctrl->type_ops->init(ctrl, 0, ctrl->p_new); in def_to_user()
94 return ptr_to_user(c, ctrl, ctrl->p_new); in def_to_user()
98 static int user_to_new(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) in user_to_new() argument
103 ctrl->is_new = 0; in user_to_new()
104 if (ctrl->is_dyn_array && in user_to_new()
105 c->size > ctrl->p_array_alloc_elems * ctrl->elem_size) { in user_to_new()
106 void *old = ctrl->p_array; in user_to_new()
111 memcpy(tmp, ctrl->p_new.p, ctrl->elems * ctrl->elem_size); in user_to_new()
112 memcpy(tmp + c->size, ctrl->p_cur.p, ctrl->elems * ctrl->elem_size); in user_to_new()
113 ctrl->p_new.p = tmp; in user_to_new()
114 ctrl->p_cur.p = tmp + c->size; in user_to_new()
115 ctrl->p_array = tmp; in user_to_new()
116 ctrl->p_array_alloc_elems = c->size / ctrl->elem_size; in user_to_new()
120 if (ctrl->is_ptr && !ctrl->is_string) { in user_to_new()
121 unsigned int elems = c->size / ctrl->elem_size; in user_to_new()
123 if (copy_from_user(ctrl->p_new.p, c->ptr, c->size)) in user_to_new()
125 ctrl->is_new = 1; in user_to_new()
126 if (ctrl->is_dyn_array) in user_to_new()
127 ctrl->new_elems = elems; in user_to_new()
128 else if (ctrl->is_array) in user_to_new()
129 ctrl->type_ops->init(ctrl, elems, ctrl->p_new); in user_to_new()
133 switch (ctrl->type) { in user_to_new()
135 *ctrl->p_new.p_s64 = c->value64; in user_to_new()
141 if (size > ctrl->maximum + 1) in user_to_new()
142 size = ctrl->maximum + 1; in user_to_new()
143 ret = copy_from_user(ctrl->p_new.p_char, c->string, size) ? -EFAULT : 0; in user_to_new()
145 char last = ctrl->p_new.p_char[size - 1]; in user_to_new()
147 ctrl->p_new.p_char[size - 1] = 0; in user_to_new()
149 * If the string was longer than ctrl->maximum, in user_to_new()
152 if (strlen(ctrl->p_new.p_char) == ctrl->maximum && last) in user_to_new()
154 ctrl->is_new = 1; in user_to_new()
158 *ctrl->p_new.p_s32 = c->value; in user_to_new()
161 ctrl->is_new = 1; in user_to_new()
226 struct v4l2_ctrl *ctrl; in prepare_ext_ctrls() local
256 ctrl = ref->ctrl; in prepare_ext_ctrls()
257 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED) { in prepare_ext_ctrls()
262 if (ctrl->cluster[0]->ncontrols > 1) in prepare_ext_ctrls()
264 if (ctrl->cluster[0] != ctrl) in prepare_ext_ctrls()
265 ref = find_ref_lock(hdl, ctrl->cluster[0]->id); in prepare_ext_ctrls()
266 if (ctrl->is_dyn_array) { in prepare_ext_ctrls()
267 unsigned int max_size = ctrl->dims[0] * ctrl->elem_size; in prepare_ext_ctrls()
268 unsigned int tot_size = ctrl->elem_size; in prepare_ext_ctrls()
273 tot_size *= ctrl->elems; in prepare_ext_ctrls()
275 c->size = ctrl->elem_size * (c->size / ctrl->elem_size); in prepare_ext_ctrls()
290 } else if (ctrl->is_ptr && !ctrl->is_string) { in prepare_ext_ctrls()
291 unsigned int tot_size = ctrl->elems * ctrl->elem_size; in prepare_ext_ctrls()
417 if (helpers[i].ref->ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in v4l2_g_ext_ctrls_common()
428 master = helpers[i].mref->ctrl; in v4l2_g_ext_ctrls_common()
465 ret = def_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
471 ret = new_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
473 ret = cur_to_user(cs->controls + idx, ref->ctrl); in v4l2_g_ext_ctrls_common()
496 static int validate_new(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr p_new) in validate_new() argument
498 return ctrl->type_ops->validate(ctrl, p_new); in validate_new()
512 struct v4l2_ctrl *ctrl = helpers[i].ref->ctrl; in validate_ctrls() local
517 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) { in validate_ctrls()
520 ctrl->id); in validate_ctrls()
531 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) { in validate_ctrls()
534 ctrl->id); in validate_ctrls()
541 if (ctrl->is_ptr) in validate_ctrls()
543 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in validate_ctrls()
547 ret = validate_new(ctrl, p_new); in validate_ctrls()
604 master = helpers[i].mref->ctrl; in try_set_ext_ctrls_common()
631 if (helpers[tmp_idx].ref->ctrl == master) in try_set_ext_ctrls_common()
648 struct v4l2_ctrl *ctrl = helpers[idx].ref->ctrl; in try_set_ext_ctrls_common() local
650 ret = user_to_new(cs->controls + idx, ctrl); in try_set_ext_ctrls_common()
651 if (!ret && ctrl->is_ptr) { in try_set_ext_ctrls_common()
652 ret = validate_new(ctrl, ctrl->p_new); in try_set_ext_ctrls_common()
656 v4l2_ctrl_get_name(ctrl->id), ret); in try_set_ext_ctrls_common()
678 helpers[idx].ref->ctrl); in try_set_ext_ctrls_common()
734 static int get_ctrl(struct v4l2_ctrl *ctrl, struct v4l2_ext_control *c) in get_ctrl() argument
736 struct v4l2_ctrl *master = ctrl->cluster[0]; in get_ctrl()
744 if (!ctrl->is_int && ctrl->type != V4L2_CTRL_TYPE_INTEGER64) in get_ctrl()
747 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) in get_ctrl()
752 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in get_ctrl()
757 ret = new_to_user(c, ctrl); in get_ctrl()
759 ret = cur_to_user(c, ctrl); in get_ctrl()
767 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl() local
771 if (!ctrl || !ctrl->is_int) in v4l2_g_ctrl()
773 ret = get_ctrl(ctrl, &c); in v4l2_g_ctrl()
783 static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags) in set_ctrl() argument
785 struct v4l2_ctrl *master = ctrl->cluster[0]; in set_ctrl()
794 ret = validate_new(ctrl, ctrl->p_new); in set_ctrl()
803 if (master->is_auto && master->has_volatiles && ctrl == master && in set_ctrl()
804 !is_cur_manual(master) && ctrl->val == master->manual_mode_value) in set_ctrl()
807 ctrl->is_new = 1; in set_ctrl()
812 static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, in set_ctrl_lock() argument
817 v4l2_ctrl_lock(ctrl); in set_ctrl_lock()
818 ret = user_to_new(c, ctrl); in set_ctrl_lock()
820 ret = set_ctrl(fh, ctrl, 0); in set_ctrl_lock()
822 ret = cur_to_user(c, ctrl); in set_ctrl_lock()
823 v4l2_ctrl_unlock(ctrl); in set_ctrl_lock()
830 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl() local
834 if (!ctrl || !ctrl->is_int) in v4l2_s_ctrl()
837 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) in v4l2_s_ctrl()
841 ret = set_ctrl_lock(fh, ctrl, &c); in v4l2_s_ctrl()
851 s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl) in v4l2_ctrl_g_ctrl() argument
856 if (WARN_ON(!ctrl->is_int)) in v4l2_ctrl_g_ctrl()
859 get_ctrl(ctrl, &c); in v4l2_ctrl_g_ctrl()
864 s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl) in v4l2_ctrl_g_ctrl_int64() argument
869 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in v4l2_ctrl_g_ctrl_int64()
872 get_ctrl(ctrl, &c); in v4l2_ctrl_g_ctrl_int64()
877 int __v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val) in __v4l2_ctrl_s_ctrl() argument
879 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl()
882 if (WARN_ON(!ctrl->is_int)) in __v4l2_ctrl_s_ctrl()
884 ctrl->val = val; in __v4l2_ctrl_s_ctrl()
885 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl()
889 int __v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val) in __v4l2_ctrl_s_ctrl_int64() argument
891 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_int64()
894 if (WARN_ON(ctrl->is_ptr || ctrl->type != V4L2_CTRL_TYPE_INTEGER64)) in __v4l2_ctrl_s_ctrl_int64()
896 *ctrl->p_new.p_s64 = val; in __v4l2_ctrl_s_ctrl_int64()
897 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl_int64()
901 int __v4l2_ctrl_s_ctrl_string(struct v4l2_ctrl *ctrl, const char *s) in __v4l2_ctrl_s_ctrl_string() argument
903 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_string()
906 if (WARN_ON(ctrl->type != V4L2_CTRL_TYPE_STRING)) in __v4l2_ctrl_s_ctrl_string()
908 strscpy(ctrl->p_new.p_char, s, ctrl->maximum + 1); in __v4l2_ctrl_s_ctrl_string()
909 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl_string()
913 int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl, in __v4l2_ctrl_s_ctrl_compound() argument
916 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_s_ctrl_compound()
919 if (WARN_ON(ctrl->type != type)) in __v4l2_ctrl_s_ctrl_compound()
922 if (WARN_ON(ctrl->is_dyn_array)) in __v4l2_ctrl_s_ctrl_compound()
924 memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size); in __v4l2_ctrl_s_ctrl_compound()
925 return set_ctrl(NULL, ctrl, 0); in __v4l2_ctrl_s_ctrl_compound()
932 int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, in __v4l2_ctrl_modify_range() argument
939 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_range()
941 switch (ctrl->type) { in __v4l2_ctrl_modify_range()
951 if (ctrl->is_array) in __v4l2_ctrl_modify_range()
953 ret = check_range(ctrl->type, min, max, step, def); in __v4l2_ctrl_modify_range()
960 if (ctrl->minimum != min || ctrl->maximum != max || in __v4l2_ctrl_modify_range()
961 ctrl->step != step || ctrl->default_value != def) { in __v4l2_ctrl_modify_range()
963 ctrl->minimum = min; in __v4l2_ctrl_modify_range()
964 ctrl->maximum = max; in __v4l2_ctrl_modify_range()
965 ctrl->step = step; in __v4l2_ctrl_modify_range()
966 ctrl->default_value = def; in __v4l2_ctrl_modify_range()
968 cur_to_new(ctrl); in __v4l2_ctrl_modify_range()
969 if (validate_new(ctrl, ctrl->p_new)) { in __v4l2_ctrl_modify_range()
970 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
971 *ctrl->p_new.p_s64 = def; in __v4l2_ctrl_modify_range()
973 *ctrl->p_new.p_s32 = def; in __v4l2_ctrl_modify_range()
976 if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) in __v4l2_ctrl_modify_range()
977 value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64; in __v4l2_ctrl_modify_range()
979 value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32; in __v4l2_ctrl_modify_range()
981 ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE); in __v4l2_ctrl_modify_range()
983 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE); in __v4l2_ctrl_modify_range()
988 int __v4l2_ctrl_modify_dimensions(struct v4l2_ctrl *ctrl, in __v4l2_ctrl_modify_dimensions() argument
995 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_modify_dimensions()
997 if (!ctrl->is_array || ctrl->is_dyn_array) in __v4l2_ctrl_modify_dimensions()
1000 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
1004 p_array = kvzalloc(2 * elems * ctrl->elem_size, GFP_KERNEL); in __v4l2_ctrl_modify_dimensions()
1007 kvfree(ctrl->p_array); in __v4l2_ctrl_modify_dimensions()
1008 ctrl->p_array_alloc_elems = elems; in __v4l2_ctrl_modify_dimensions()
1009 ctrl->elems = elems; in __v4l2_ctrl_modify_dimensions()
1010 ctrl->new_elems = elems; in __v4l2_ctrl_modify_dimensions()
1011 ctrl->p_array = p_array; in __v4l2_ctrl_modify_dimensions()
1012 ctrl->p_new.p = p_array; in __v4l2_ctrl_modify_dimensions()
1013 ctrl->p_cur.p = p_array + elems * ctrl->elem_size; in __v4l2_ctrl_modify_dimensions()
1014 for (i = 0; i < ctrl->nr_of_dims; i++) in __v4l2_ctrl_modify_dimensions()
1015 ctrl->dims[i] = dims[i]; in __v4l2_ctrl_modify_dimensions()
1016 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); in __v4l2_ctrl_modify_dimensions()
1017 cur_to_new(ctrl); in __v4l2_ctrl_modify_dimensions()
1018 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_VALUE | in __v4l2_ctrl_modify_dimensions()
1030 struct v4l2_ctrl *ctrl; in v4l2_query_ext_ctrl() local
1068 is_compound = pos->ctrl->is_array || in v4l2_query_ext_ctrl()
1069 pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1070 if (id < pos->ctrl->id && in v4l2_query_ext_ctrl()
1086 is_compound = pos->ctrl->is_array || in v4l2_query_ext_ctrl()
1087 pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES; in v4l2_query_ext_ctrl()
1088 if (id < pos->ctrl->id && in v4l2_query_ext_ctrl()
1101 ctrl = ref->ctrl; in v4l2_query_ext_ctrl()
1106 qc->id = ctrl->id; in v4l2_query_ext_ctrl()
1107 strscpy(qc->name, ctrl->name, sizeof(qc->name)); in v4l2_query_ext_ctrl()
1108 qc->flags = user_flags(ctrl); in v4l2_query_ext_ctrl()
1109 qc->type = ctrl->type; in v4l2_query_ext_ctrl()
1110 qc->elem_size = ctrl->elem_size; in v4l2_query_ext_ctrl()
1111 qc->elems = ctrl->elems; in v4l2_query_ext_ctrl()
1112 qc->nr_of_dims = ctrl->nr_of_dims; in v4l2_query_ext_ctrl()
1113 memcpy(qc->dims, ctrl->dims, qc->nr_of_dims * sizeof(qc->dims[0])); in v4l2_query_ext_ctrl()
1114 qc->minimum = ctrl->minimum; in v4l2_query_ext_ctrl()
1115 qc->maximum = ctrl->maximum; in v4l2_query_ext_ctrl()
1116 qc->default_value = ctrl->default_value; in v4l2_query_ext_ctrl()
1117 if (ctrl->type == V4L2_CTRL_TYPE_MENU || in v4l2_query_ext_ctrl()
1118 ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in v4l2_query_ext_ctrl()
1121 qc->step = ctrl->step; in v4l2_query_ext_ctrl()
1166 struct v4l2_ctrl *ctrl; in v4l2_querymenu() local
1169 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
1170 if (!ctrl) in v4l2_querymenu()
1175 switch (ctrl->type) { in v4l2_querymenu()
1177 if (!ctrl->qmenu) in v4l2_querymenu()
1181 if (!ctrl->qmenu_int) in v4l2_querymenu()
1188 if (i < ctrl->minimum || i > ctrl->maximum) in v4l2_querymenu()
1192 if (i < BITS_PER_LONG_LONG && (ctrl->menu_skip_mask & BIT_ULL(i))) in v4l2_querymenu()
1195 if (ctrl->type == V4L2_CTRL_TYPE_MENU) { in v4l2_querymenu()
1196 if (!ctrl->qmenu[i] || ctrl->qmenu[i][0] == '\0') in v4l2_querymenu()
1198 strscpy(qm->name, ctrl->qmenu[i], sizeof(qm->name)); in v4l2_querymenu()
1200 qm->value = ctrl->qmenu_int[i]; in v4l2_querymenu()
1236 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_add_event() local
1238 if (!ctrl) in v4l2_ctrl_add_event()
1241 v4l2_ctrl_lock(ctrl); in v4l2_ctrl_add_event()
1242 list_add_tail(&sev->node, &ctrl->ev_subs); in v4l2_ctrl_add_event()
1243 if (ctrl->type != V4L2_CTRL_TYPE_CTRL_CLASS && in v4l2_ctrl_add_event()
1245 send_initial_event(sev->fh, ctrl); in v4l2_ctrl_add_event()
1246 v4l2_ctrl_unlock(ctrl); in v4l2_ctrl_add_event()
1252 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); in v4l2_ctrl_del_event() local
1254 if (!ctrl) in v4l2_ctrl_del_event()
1257 v4l2_ctrl_lock(ctrl); in v4l2_ctrl_del_event()
1259 v4l2_ctrl_unlock(ctrl); in v4l2_ctrl_del_event()
1264 u32 old_changes = old->u.ctrl.changes; in v4l2_ctrl_replace()
1266 old->u.ctrl = new->u.ctrl; in v4l2_ctrl_replace()
1267 old->u.ctrl.changes |= old_changes; in v4l2_ctrl_replace()
1273 new->u.ctrl.changes |= old->u.ctrl.changes; in v4l2_ctrl_merge()