Lines Matching refs:hdl
1707 static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err) in handler_set_err() argument
1709 if (hdl->error == 0) in handler_set_err()
1710 hdl->error = err; in handler_set_err()
1715 int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_handler_init_class() argument
1719 hdl->lock = &hdl->_lock; in v4l2_ctrl_handler_init_class()
1720 mutex_init(hdl->lock); in v4l2_ctrl_handler_init_class()
1721 lockdep_set_class_and_name(hdl->lock, key, name); in v4l2_ctrl_handler_init_class()
1722 INIT_LIST_HEAD(&hdl->ctrls); in v4l2_ctrl_handler_init_class()
1723 INIT_LIST_HEAD(&hdl->ctrl_refs); in v4l2_ctrl_handler_init_class()
1724 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; in v4l2_ctrl_handler_init_class()
1725 hdl->buckets = kcalloc(hdl->nr_of_buckets, sizeof(hdl->buckets[0]), in v4l2_ctrl_handler_init_class()
1727 hdl->error = hdl->buckets ? 0 : -ENOMEM; in v4l2_ctrl_handler_init_class()
1728 return hdl->error; in v4l2_ctrl_handler_init_class()
1733 void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl) in v4l2_ctrl_handler_free() argument
1739 if (hdl == NULL || hdl->buckets == NULL) in v4l2_ctrl_handler_free()
1742 mutex_lock(hdl->lock); in v4l2_ctrl_handler_free()
1744 list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { in v4l2_ctrl_handler_free()
1749 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_free()
1755 kfree(hdl->buckets); in v4l2_ctrl_handler_free()
1756 hdl->buckets = NULL; in v4l2_ctrl_handler_free()
1757 hdl->cached = NULL; in v4l2_ctrl_handler_free()
1758 hdl->error = 0; in v4l2_ctrl_handler_free()
1759 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_free()
1770 struct v4l2_ctrl_handler *hdl, u32 id) in find_private_ref() argument
1775 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in find_private_ref()
1791 static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id) in find_ref() argument
1800 return find_private_ref(hdl, id); in find_ref()
1801 bucket = id % hdl->nr_of_buckets; in find_ref()
1804 if (hdl->cached && hdl->cached->ctrl->id == id) in find_ref()
1805 return hdl->cached; in find_ref()
1808 ref = hdl->buckets ? hdl->buckets[bucket] : NULL; in find_ref()
1813 hdl->cached = ref; /* cache it! */ in find_ref()
1819 struct v4l2_ctrl_handler *hdl, u32 id) in find_ref_lock() argument
1823 if (hdl) { in find_ref_lock()
1824 mutex_lock(hdl->lock); in find_ref_lock()
1825 ref = find_ref(hdl, id); in find_ref_lock()
1826 mutex_unlock(hdl->lock); in find_ref_lock()
1832 struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id) in v4l2_ctrl_find() argument
1834 struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id); in v4l2_ctrl_find()
1841 static int handler_new_ref(struct v4l2_ctrl_handler *hdl, in handler_new_ref() argument
1848 int bucket = id % hdl->nr_of_buckets; /* which bucket to use */ in handler_new_ref()
1855 id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL) in handler_new_ref()
1856 if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0)) in handler_new_ref()
1857 return hdl->error; in handler_new_ref()
1859 if (hdl->error) in handler_new_ref()
1860 return hdl->error; in handler_new_ref()
1864 return handler_set_err(hdl, -ENOMEM); in handler_new_ref()
1866 if (ctrl->handler == hdl) { in handler_new_ref()
1877 mutex_lock(hdl->lock); in handler_new_ref()
1883 if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) { in handler_new_ref()
1884 list_add_tail(&new_ref->node, &hdl->ctrl_refs); in handler_new_ref()
1889 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in handler_new_ref()
1903 new_ref->next = hdl->buckets[bucket]; in handler_new_ref()
1904 hdl->buckets[bucket] = new_ref; in handler_new_ref()
1907 mutex_unlock(hdl->lock); in handler_new_ref()
1912 static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new() argument
1931 if (hdl->error) in v4l2_ctrl_new()
1971 handler_set_err(hdl, -ERANGE); in v4l2_ctrl_new()
1976 handler_set_err(hdl, err); in v4l2_ctrl_new()
1980 handler_set_err(hdl, -ERANGE); in v4l2_ctrl_new()
1986 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new()
2004 handler_set_err(hdl, -ENOMEM); in v4l2_ctrl_new()
2010 ctrl->handler = hdl; in v4l2_ctrl_new()
2050 if (handler_new_ref(hdl, ctrl)) { in v4l2_ctrl_new()
2054 mutex_lock(hdl->lock); in v4l2_ctrl_new()
2055 list_add_tail(&ctrl->node, &hdl->ctrls); in v4l2_ctrl_new()
2056 mutex_unlock(hdl->lock); in v4l2_ctrl_new()
2060 struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_custom() argument
2089 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_custom()
2093 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name, in v4l2_ctrl_new_custom()
2105 struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_std() argument
2117 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std()
2120 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_std()
2127 struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_std_menu() argument
2150 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu()
2153 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_std_menu()
2160 struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_std_menu_items() argument
2176 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2182 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2185 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_std_menu_items()
2193 struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_new_int_menu() argument
2207 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_int_menu()
2210 return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, in v4l2_ctrl_new_int_menu()
2217 struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_add_ctrl() argument
2220 if (hdl == NULL || hdl->error) in v4l2_ctrl_add_ctrl()
2223 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_add_ctrl()
2226 if (ctrl->handler == hdl) in v4l2_ctrl_add_ctrl()
2228 return handler_new_ref(hdl, ctrl) ? NULL : ctrl; in v4l2_ctrl_add_ctrl()
2233 int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_add_handler() argument
2241 if (!hdl || !add || hdl == add) in v4l2_ctrl_add_handler()
2243 if (hdl->error) in v4l2_ctrl_add_handler()
2244 return hdl->error; in v4l2_ctrl_add_handler()
2258 ret = handler_new_ref(hdl, ctrl); in v4l2_ctrl_add_handler()
2410 void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl, in v4l2_ctrl_handler_log_status() argument
2417 if (hdl == NULL) in v4l2_ctrl_handler_log_status()
2424 mutex_lock(hdl->lock); in v4l2_ctrl_handler_log_status()
2425 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_log_status()
2428 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_log_status()
2440 int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) in v4l2_ctrl_handler_setup() argument
2445 if (hdl == NULL) in v4l2_ctrl_handler_setup()
2447 mutex_lock(hdl->lock); in v4l2_ctrl_handler_setup()
2448 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_setup()
2451 list_for_each_entry(ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_setup()
2472 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_setup()
2478 int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctrl *qc) in v4l2_query_ext_ctrl() argument
2485 if (hdl == NULL) in v4l2_query_ext_ctrl()
2488 mutex_lock(hdl->lock); in v4l2_query_ext_ctrl()
2491 ref = find_ref(hdl, id); in v4l2_query_ext_ctrl()
2493 if ((qc->id & next_flags) && !list_empty(&hdl->ctrl_refs)) { in v4l2_query_ext_ctrl()
2510 if (id >= node2id(hdl->ctrl_refs.prev)) { in v4l2_query_ext_ctrl()
2515 list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
2522 if (&ref->node == &hdl->ctrl_refs) in v4l2_query_ext_ctrl()
2529 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in v4l2_query_ext_ctrl()
2536 if (&ref->node == &hdl->ctrl_refs) in v4l2_query_ext_ctrl()
2540 mutex_unlock(hdl->lock); in v4l2_query_ext_ctrl()
2573 int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc) in v4l2_queryctrl() argument
2578 rc = v4l2_query_ext_ctrl(hdl, &qec); in v4l2_queryctrl()
2618 int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm) in v4l2_querymenu() argument
2623 ctrl = v4l2_ctrl_find(hdl, qm->id); in v4l2_querymenu()
2709 static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, in prepare_ext_ctrls() argument
2733 ref = find_ref_lock(hdl, id); in prepare_ext_ctrls()
2743 ref = find_ref_lock(hdl, ctrl->cluster[0]->id); in prepare_ext_ctrls()
2774 mutex_lock(hdl->lock); in prepare_ext_ctrls()
2796 mutex_unlock(hdl->lock); in prepare_ext_ctrls()
2803 static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class) in class_check() argument
2806 return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0; in class_check()
2807 return find_ref_lock(hdl, ctrl_class | 1) ? 0 : -EINVAL; in class_check()
2813 int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) in v4l2_g_ext_ctrls() argument
2823 if (hdl == NULL) in v4l2_g_ext_ctrls()
2827 return class_check(hdl, cs->ctrl_class); in v4l2_g_ext_ctrls()
2836 ret = prepare_ext_ctrls(hdl, cs, helpers, true); in v4l2_g_ext_ctrls()
2922 int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control) in v4l2_g_ctrl() argument
2924 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_g_ctrl()
3070 static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, in try_set_ext_ctrls() argument
3082 if (hdl == NULL) in try_set_ext_ctrls()
3086 return class_check(hdl, cs->ctrl_class); in try_set_ext_ctrls()
3094 ret = prepare_ext_ctrls(hdl, cs, helpers, false); in try_set_ext_ctrls()
3171 int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs) in v4l2_try_ext_ctrls() argument
3173 return try_set_ext_ctrls(NULL, hdl, cs, false); in v4l2_try_ext_ctrls()
3177 int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, in v4l2_s_ext_ctrls() argument
3180 return try_set_ext_ctrls(fh, hdl, cs, true); in v4l2_s_ext_ctrls()
3238 int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl, in v4l2_s_ctrl() argument
3241 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id); in v4l2_s_ctrl()