Lines Matching +full:frame +full:- +full:master
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2010-2021 Hans Verkuil <hverkuil-cisco@xs4all.nl>
11 #include <media/v4l2-ctrls.h>
12 #include <media/v4l2-event.h>
13 #include <media/v4l2-fwnode.h>
15 #include "v4l2-ctrls-priv.h"
23 ev->type = V4L2_EVENT_CTRL; in fill_event()
24 ev->id = ctrl->id; in fill_event()
25 ev->u.ctrl.changes = changes; in fill_event()
26 ev->u.ctrl.type = ctrl->type; in fill_event()
27 ev->u.ctrl.flags = user_flags(ctrl); in fill_event()
28 if (ctrl->is_ptr) in fill_event()
29 ev->u.ctrl.value64 = 0; in fill_event()
31 ev->u.ctrl.value64 = *ctrl->p_cur.p_s64; in fill_event()
32 ev->u.ctrl.minimum = ctrl->minimum; in fill_event()
33 ev->u.ctrl.maximum = ctrl->maximum; in fill_event()
34 if (ctrl->type == V4L2_CTRL_TYPE_MENU in fill_event()
35 || ctrl->type == V4L2_CTRL_TYPE_INTEGER_MENU) in fill_event()
36 ev->u.ctrl.step = 1; in fill_event()
38 ev->u.ctrl.step = ctrl->step; in fill_event()
39 ev->u.ctrl.default_value = ctrl->default_value; in fill_event()
47 if (!(ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)) in send_initial_event()
58 if (list_empty(&ctrl->ev_subs)) in send_event()
62 list_for_each_entry(sev, &ctrl->ev_subs, node) in send_event()
63 if (sev->fh != fh || in send_event()
64 (sev->flags & V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK)) in send_event()
65 v4l2_event_queue_fh(sev->fh, &ev); in send_event()
73 switch (ctrl->type) { in v4l2_ctrl_type_op_equal()
77 for (i = 0; i < ctrl->elems; i++) { in v4l2_ctrl_type_op_equal()
78 unsigned int idx = i * ctrl->elem_size; in v4l2_ctrl_type_op_equal()
80 /* strings are always 0-terminated */ in v4l2_ctrl_type_op_equal()
87 ctrl->elems * ctrl->elem_size); in v4l2_ctrl_type_op_equal()
92 /* Default intra MPEG-2 quantisation coefficients, from the specification. */
115 void *p = ptr.p + idx * ctrl->elem_size; in std_init_compound()
117 if (ctrl->p_def.p_const) in std_init_compound()
118 memcpy(p, ctrl->p_def.p_const, ctrl->elem_size); in std_init_compound()
120 memset(p, 0, ctrl->elem_size); in std_init_compound()
122 switch ((u32)ctrl->type) { in std_init_compound()
127 p_mpeg2_sequence->chroma_format = 1; in std_init_compound()
133 p_mpeg2_picture->picture_structure = V4L2_MPEG2_PIC_TOP_FIELD; in std_init_compound()
134 p_mpeg2_picture->picture_coding_type = in std_init_compound()
140 memcpy(p_mpeg2_quant->intra_quantiser_matrix, in std_init_compound()
144 * The default non-intra MPEG-2 quantisation in std_init_compound()
147 memset(p_mpeg2_quant->non_intra_quantiser_matrix, 16, in std_init_compound()
148 sizeof(p_mpeg2_quant->non_intra_quantiser_matrix)); in std_init_compound()
152 p_vp8_frame->num_dct_parts = 1; in std_init_compound()
156 p_vp9_frame->profile = 0; in std_init_compound()
157 p_vp9_frame->bit_depth = 8; in std_init_compound()
158 p_vp9_frame->flags |= V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING | in std_init_compound()
163 p_av1_sequence->bit_depth = 8; in std_init_compound()
167 p_fwht_params->version = V4L2_FWHT_VERSION; in std_init_compound()
168 p_fwht_params->width = 1280; in std_init_compound()
169 p_fwht_params->height = 720; in std_init_compound()
170 p_fwht_params->flags = V4L2_FWHT_FL_PIXENC_YUV | in std_init_compound()
178 * (7-8) and (7-9) of the specification. in std_init_compound()
188 void *p = ptr.p + idx * ctrl->elem_size; in std_min_compound()
190 if (ctrl->p_min.p_const) in std_min_compound()
191 memcpy(p, ctrl->p_min.p_const, ctrl->elem_size); in std_min_compound()
193 memset(p, 0, ctrl->elem_size); in std_min_compound()
199 void *p = ptr.p + idx * ctrl->elem_size; in std_max_compound()
201 if (ctrl->p_max.p_const) in std_max_compound()
202 memcpy(p, ctrl->p_max.p_const, ctrl->elem_size); in std_max_compound()
204 memset(p, 0, ctrl->elem_size); in std_max_compound()
211 u32 tot_elems = ctrl->elems; in __v4l2_ctrl_type_op_init()
212 u32 elems = tot_elems - from_idx; in __v4l2_ctrl_type_op_init()
217 value = ctrl->default_value; in __v4l2_ctrl_type_op_init()
220 value = ctrl->maximum; in __v4l2_ctrl_type_op_init()
223 value = ctrl->minimum; in __v4l2_ctrl_type_op_init()
229 switch (ctrl->type) { in __v4l2_ctrl_type_op_init()
232 value = ctrl->minimum; in __v4l2_ctrl_type_op_init()
235 unsigned int offset = i * ctrl->elem_size; in __v4l2_ctrl_type_op_init()
323 union v4l2_ctrl_ptr ptr = ctrl->p_cur; in v4l2_ctrl_type_op_log()
325 if (ctrl->is_array) { in v4l2_ctrl_type_op_log()
328 for (i = 0; i < ctrl->nr_of_dims; i++) in v4l2_ctrl_type_op_log()
329 pr_cont("[%u]", ctrl->dims[i]); in v4l2_ctrl_type_op_log()
333 switch (ctrl->type) { in v4l2_ctrl_type_op_log()
341 pr_cont("%s", ctrl->qmenu[*ptr.p_s32]); in v4l2_ctrl_type_op_log()
344 pr_cont("%lld", ctrl->qmenu_int[*ptr.p_s32]); in v4l2_ctrl_type_op_log()
365 pr_cont("%ux%u", ptr.p_area->width, ptr.p_area->height); in v4l2_ctrl_type_op_log()
441 ptr.p_rect->left, ptr.p_rect->top, in v4l2_ctrl_type_op_log()
442 ptr.p_rect->width, ptr.p_rect->height); in v4l2_ctrl_type_op_log()
445 pr_cont("unknown type %d", ctrl->type); in v4l2_ctrl_type_op_log()
454 * wrap-arounds.
459 if ((ctrl)->maximum >= 0 && \
460 val >= (ctrl)->maximum - (s32)((ctrl)->step / 2)) \
461 val = (ctrl)->maximum; \
463 val += (s32)((ctrl)->step / 2); \
465 (ctrl)->minimum, (ctrl)->maximum); \
466 offset = (val) - (ctrl)->minimum; \
467 offset = (ctrl)->step * (offset / (u32)(ctrl)->step); \
468 val = (ctrl)->minimum + offset; \
484 if (lf->flags & ~(V4L2_VP9_LOOP_FILTER_FLAG_DELTA_ENABLED | in validate_vp9_lf_params()
486 return -EINVAL; in validate_vp9_lf_params()
489 if (lf->level > GENMASK(5, 0)) in validate_vp9_lf_params()
490 return -EINVAL; in validate_vp9_lf_params()
492 if (lf->sharpness > GENMASK(2, 0)) in validate_vp9_lf_params()
493 return -EINVAL; in validate_vp9_lf_params()
495 for (i = 0; i < ARRAY_SIZE(lf->ref_deltas); i++) in validate_vp9_lf_params()
496 if (lf->ref_deltas[i] < -63 || lf->ref_deltas[i] > 63) in validate_vp9_lf_params()
497 return -EINVAL; in validate_vp9_lf_params()
499 for (i = 0; i < ARRAY_SIZE(lf->mode_deltas); i++) in validate_vp9_lf_params()
500 if (lf->mode_deltas[i] < -63 || lf->mode_deltas[i] > 63) in validate_vp9_lf_params()
501 return -EINVAL; in validate_vp9_lf_params()
510 if (quant->delta_q_y_dc < -15 || quant->delta_q_y_dc > 15 || in validate_vp9_quant_params()
511 quant->delta_q_uv_dc < -15 || quant->delta_q_uv_dc > 15 || in validate_vp9_quant_params()
512 quant->delta_q_uv_ac < -15 || quant->delta_q_uv_ac > 15) in validate_vp9_quant_params()
513 return -EINVAL; in validate_vp9_quant_params()
524 if (seg->flags & ~(V4L2_VP9_SEGMENTATION_FLAG_ENABLED | in validate_vp9_seg_params()
529 return -EINVAL; in validate_vp9_seg_params()
531 for (i = 0; i < ARRAY_SIZE(seg->feature_enabled); i++) { in validate_vp9_seg_params()
532 if (seg->feature_enabled[i] & in validate_vp9_seg_params()
534 return -EINVAL; in validate_vp9_seg_params()
537 for (i = 0; i < ARRAY_SIZE(seg->feature_data); i++) { in validate_vp9_seg_params()
540 for (j = 0; j < ARRAY_SIZE(seg->feature_data[j]); j++) { in validate_vp9_seg_params()
541 if (seg->feature_data[i][j] < -range[j] || in validate_vp9_seg_params()
542 seg->feature_data[i][j] > range[j]) in validate_vp9_seg_params()
543 return -EINVAL; in validate_vp9_seg_params()
554 if (hdr->tx_mode > V4L2_VP9_TX_MODE_SELECT) in validate_vp9_compressed_hdr()
555 return -EINVAL; in validate_vp9_compressed_hdr()
561 validate_vp9_frame(struct v4l2_ctrl_vp9_frame *frame) in validate_vp9_frame() argument
566 if (frame->flags & ~(V4L2_VP9_FRAME_FLAG_KEY_FRAME | in validate_vp9_frame()
576 return -EINVAL; in validate_vp9_frame()
578 if (frame->flags & V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT && in validate_vp9_frame()
579 frame->flags & V4L2_VP9_FRAME_FLAG_REFRESH_FRAME_CTX) in validate_vp9_frame()
580 return -EINVAL; in validate_vp9_frame()
582 if (frame->profile > V4L2_VP9_PROFILE_MAX) in validate_vp9_frame()
583 return -EINVAL; in validate_vp9_frame()
585 if (frame->reset_frame_context > V4L2_VP9_RESET_FRAME_CTX_ALL) in validate_vp9_frame()
586 return -EINVAL; in validate_vp9_frame()
588 if (frame->frame_context_idx >= V4L2_VP9_NUM_FRAME_CTX) in validate_vp9_frame()
589 return -EINVAL; in validate_vp9_frame()
592 * Profiles 0 and 1 only support 8-bit depth, profiles 2 and 3 only 10 in validate_vp9_frame()
595 if ((frame->profile < 2 && frame->bit_depth != 8) || in validate_vp9_frame()
596 (frame->profile >= 2 && in validate_vp9_frame()
597 (frame->bit_depth != 10 && frame->bit_depth != 12))) in validate_vp9_frame()
598 return -EINVAL; in validate_vp9_frame()
601 if ((frame->profile == 0 || frame->profile == 2) && in validate_vp9_frame()
602 (!(frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) || in validate_vp9_frame()
603 !(frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING))) in validate_vp9_frame()
604 return -EINVAL; in validate_vp9_frame()
607 if ((frame->profile == 1 || frame->profile == 3) && in validate_vp9_frame()
608 ((frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) && in validate_vp9_frame()
609 (frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING))) in validate_vp9_frame()
610 return -EINVAL; in validate_vp9_frame()
612 if (frame->interpolation_filter > V4L2_VP9_INTERP_FILTER_SWITCHABLE) in validate_vp9_frame()
613 return -EINVAL; in validate_vp9_frame()
619 if (frame->tile_cols_log2 > 6) in validate_vp9_frame()
620 return -EINVAL; in validate_vp9_frame()
622 if (frame->reference_mode > V4L2_VP9_REFERENCE_MODE_SELECT) in validate_vp9_frame()
623 return -EINVAL; in validate_vp9_frame()
625 ret = validate_vp9_lf_params(&frame->lf); in validate_vp9_frame()
629 ret = validate_vp9_quant_params(&frame->quant); in validate_vp9_frame()
633 ret = validate_vp9_seg_params(&frame->seg); in validate_vp9_frame()
637 zero_reserved(*frame); in validate_vp9_frame()
643 if (q->flags > GENMASK(2, 0)) in validate_av1_quantization()
644 return -EINVAL; in validate_av1_quantization()
646 if (q->delta_q_y_dc < -64 || q->delta_q_y_dc > 63 || in validate_av1_quantization()
647 q->delta_q_u_dc < -64 || q->delta_q_u_dc > 63 || in validate_av1_quantization()
648 q->delta_q_v_dc < -64 || q->delta_q_v_dc > 63 || in validate_av1_quantization()
649 q->delta_q_u_ac < -64 || q->delta_q_u_ac > 63 || in validate_av1_quantization()
650 q->delta_q_v_ac < -64 || q->delta_q_v_ac > 63 || in validate_av1_quantization()
651 q->delta_q_res > GENMASK(1, 0)) in validate_av1_quantization()
652 return -EINVAL; in validate_av1_quantization()
654 if (q->qm_y > GENMASK(3, 0) || in validate_av1_quantization()
655 q->qm_u > GENMASK(3, 0) || in validate_av1_quantization()
656 q->qm_v > GENMASK(3, 0)) in validate_av1_quantization()
657 return -EINVAL; in validate_av1_quantization()
667 if (s->flags > GENMASK(4, 0)) in validate_av1_segmentation()
668 return -EINVAL; in validate_av1_segmentation()
670 for (i = 0; i < ARRAY_SIZE(s->feature_data); i++) { in validate_av1_segmentation()
674 for (j = 0; j < ARRAY_SIZE(s->feature_data[j]); j++) { in validate_av1_segmentation()
678 if (s->feature_data[i][j] < -limit || in validate_av1_segmentation()
679 s->feature_data[i][j] > limit) in validate_av1_segmentation()
680 return -EINVAL; in validate_av1_segmentation()
682 if (s->feature_data[i][j] < 0 || s->feature_data[i][j] > limit) in validate_av1_segmentation()
683 return -EINVAL; in validate_av1_segmentation()
695 if (lf->flags > GENMASK(3, 0)) in validate_av1_loop_filter()
696 return -EINVAL; in validate_av1_loop_filter()
698 for (i = 0; i < ARRAY_SIZE(lf->level); i++) { in validate_av1_loop_filter()
699 if (lf->level[i] > GENMASK(5, 0)) in validate_av1_loop_filter()
700 return -EINVAL; in validate_av1_loop_filter()
703 if (lf->sharpness > GENMASK(2, 0)) in validate_av1_loop_filter()
704 return -EINVAL; in validate_av1_loop_filter()
706 for (i = 0; i < ARRAY_SIZE(lf->ref_deltas); i++) { in validate_av1_loop_filter()
707 if (lf->ref_deltas[i] < -64 || lf->ref_deltas[i] > 63) in validate_av1_loop_filter()
708 return -EINVAL; in validate_av1_loop_filter()
711 for (i = 0; i < ARRAY_SIZE(lf->mode_deltas); i++) { in validate_av1_loop_filter()
712 if (lf->mode_deltas[i] < -64 || lf->mode_deltas[i] > 63) in validate_av1_loop_filter()
713 return -EINVAL; in validate_av1_loop_filter()
723 if (cdef->damping_minus_3 > GENMASK(1, 0) || in validate_av1_cdef()
724 cdef->bits > GENMASK(1, 0)) in validate_av1_cdef()
725 return -EINVAL; in validate_av1_cdef()
727 for (i = 0; i < 1 << cdef->bits; i++) { in validate_av1_cdef()
728 if (cdef->y_pri_strength[i] > GENMASK(3, 0) || in validate_av1_cdef()
729 cdef->y_sec_strength[i] > 4 || in validate_av1_cdef()
730 cdef->uv_pri_strength[i] > GENMASK(3, 0) || in validate_av1_cdef()
731 cdef->uv_sec_strength[i] > 4) in validate_av1_cdef()
732 return -EINVAL; in validate_av1_cdef()
740 if (lr->lr_unit_shift > 3 || lr->lr_uv_shift > 1) in validate_av1_loop_restauration()
741 return -EINVAL; in validate_av1_loop_restauration()
750 if (fg->flags > GENMASK(4, 0)) in validate_av1_film_grain()
751 return -EINVAL; in validate_av1_film_grain()
753 if (fg->film_grain_params_ref_idx > GENMASK(2, 0) || in validate_av1_film_grain()
754 fg->num_y_points > 14 || in validate_av1_film_grain()
755 fg->num_cb_points > 10 || in validate_av1_film_grain()
756 fg->num_cr_points > GENMASK(3, 0) || in validate_av1_film_grain()
757 fg->grain_scaling_minus_8 > GENMASK(1, 0) || in validate_av1_film_grain()
758 fg->ar_coeff_lag > GENMASK(1, 0) || in validate_av1_film_grain()
759 fg->ar_coeff_shift_minus_6 > GENMASK(1, 0) || in validate_av1_film_grain()
760 fg->grain_scale_shift > GENMASK(1, 0)) in validate_av1_film_grain()
761 return -EINVAL; in validate_av1_film_grain()
763 if (!(fg->flags & V4L2_AV1_FILM_GRAIN_FLAG_APPLY_GRAIN)) in validate_av1_film_grain()
766 for (i = 1; i < fg->num_y_points; i++) in validate_av1_film_grain()
767 if (fg->point_y_value[i] <= fg->point_y_value[i - 1]) in validate_av1_film_grain()
768 return -EINVAL; in validate_av1_film_grain()
770 for (i = 1; i < fg->num_cb_points; i++) in validate_av1_film_grain()
771 if (fg->point_cb_value[i] <= fg->point_cb_value[i - 1]) in validate_av1_film_grain()
772 return -EINVAL; in validate_av1_film_grain()
774 for (i = 1; i < fg->num_cr_points; i++) in validate_av1_film_grain()
775 if (fg->point_cr_value[i] <= fg->point_cr_value[i - 1]) in validate_av1_film_grain()
776 return -EINVAL; in validate_av1_film_grain()
785 ret = validate_av1_quantization(&f->quantization); in validate_av1_frame()
788 ret = validate_av1_segmentation(&f->segmentation); in validate_av1_frame()
791 ret = validate_av1_loop_filter(&f->loop_filter); in validate_av1_frame()
794 ret = validate_av1_cdef(&f->cdef); in validate_av1_frame()
797 ret = validate_av1_loop_restauration(&f->loop_restoration); in validate_av1_frame()
801 if (f->flags & in validate_av1_frame()
822 return -EINVAL; in validate_av1_frame()
824 if (f->superres_denom > GENMASK(2, 0) + 9) in validate_av1_frame()
825 return -EINVAL; in validate_av1_frame()
832 if (s->flags & in validate_av1_sequence()
853 return -EINVAL; in validate_av1_sequence()
855 if (s->seq_profile == 1 && s->flags & V4L2_AV1_SEQUENCE_FLAG_MONO_CHROME) in validate_av1_sequence()
856 return -EINVAL; in validate_av1_sequence()
859 if (s->seq_profile > 2) in validate_av1_sequence()
860 return -EINVAL; in validate_av1_sequence()
889 void *p = ptr.p + idx * ctrl->elem_size; in std_validate_compound()
892 switch ((u32)ctrl->type) { in std_validate_compound()
896 switch (p_mpeg2_sequence->chroma_format) { in std_validate_compound()
902 return -EINVAL; in std_validate_compound()
909 switch (p_mpeg2_picture->intra_dc_precision) { in std_validate_compound()
916 return -EINVAL; in std_validate_compound()
919 switch (p_mpeg2_picture->picture_structure) { in std_validate_compound()
925 return -EINVAL; in std_validate_compound()
928 switch (p_mpeg2_picture->picture_coding_type) { in std_validate_compound()
934 return -EINVAL; in std_validate_compound()
944 if (p_fwht_params->version < V4L2_FWHT_VERSION) in std_validate_compound()
945 return -EINVAL; in std_validate_compound()
946 if (!p_fwht_params->width || !p_fwht_params->height) in std_validate_compound()
947 return -EINVAL; in std_validate_compound()
954 if (p_h264_sps->pic_order_cnt_type != 0) { in std_validate_compound()
955 p_h264_sps->log2_max_pic_order_cnt_lsb_minus4 = 0; in std_validate_compound()
956 } else if (p_h264_sps->pic_order_cnt_type != 1) { in std_validate_compound()
957 p_h264_sps->num_ref_frames_in_pic_order_cnt_cycle = 0; in std_validate_compound()
958 p_h264_sps->offset_for_non_ref_pic = 0; in std_validate_compound()
959 p_h264_sps->offset_for_top_to_bottom_field = 0; in std_validate_compound()
960 memset(&p_h264_sps->offset_for_ref_frame, 0, in std_validate_compound()
961 sizeof(p_h264_sps->offset_for_ref_frame)); in std_validate_compound()
965 p_h264_sps->chroma_format_idc = 1; in std_validate_compound()
966 p_h264_sps->bit_depth_luma_minus8 = 0; in std_validate_compound()
967 p_h264_sps->bit_depth_chroma_minus8 = 0; in std_validate_compound()
969 p_h264_sps->flags &= in std_validate_compound()
972 if (p_h264_sps->chroma_format_idc < 3) in std_validate_compound()
973 p_h264_sps->flags &= in std_validate_compound()
977 if (p_h264_sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY) in std_validate_compound()
978 p_h264_sps->flags &= in std_validate_compound()
984 * The H264 specification and well-known parser implementations in std_validate_compound()
985 * use profile-idc values directly, as that is clearer and in std_validate_compound()
988 if (p_h264_sps->profile_idc < 122 && in std_validate_compound()
989 p_h264_sps->chroma_format_idc > 1) in std_validate_compound()
990 return -EINVAL; in std_validate_compound()
992 if (p_h264_sps->profile_idc < 244 && in std_validate_compound()
993 p_h264_sps->chroma_format_idc > 2) in std_validate_compound()
994 return -EINVAL; in std_validate_compound()
995 if (p_h264_sps->chroma_format_idc > 3) in std_validate_compound()
996 return -EINVAL; in std_validate_compound()
998 if (p_h264_sps->bit_depth_luma_minus8 > 6) in std_validate_compound()
999 return -EINVAL; in std_validate_compound()
1000 if (p_h264_sps->bit_depth_chroma_minus8 > 6) in std_validate_compound()
1001 return -EINVAL; in std_validate_compound()
1002 if (p_h264_sps->log2_max_frame_num_minus4 > 12) in std_validate_compound()
1003 return -EINVAL; in std_validate_compound()
1004 if (p_h264_sps->pic_order_cnt_type > 2) in std_validate_compound()
1005 return -EINVAL; in std_validate_compound()
1006 if (p_h264_sps->log2_max_pic_order_cnt_lsb_minus4 > 12) in std_validate_compound()
1007 return -EINVAL; in std_validate_compound()
1008 if (p_h264_sps->max_num_ref_frames > V4L2_H264_REF_LIST_LEN) in std_validate_compound()
1009 return -EINVAL; in std_validate_compound()
1015 if (p_h264_pps->num_slice_groups_minus1 > 7) in std_validate_compound()
1016 return -EINVAL; in std_validate_compound()
1017 if (p_h264_pps->num_ref_idx_l0_default_active_minus1 > in std_validate_compound()
1018 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
1019 return -EINVAL; in std_validate_compound()
1020 if (p_h264_pps->num_ref_idx_l1_default_active_minus1 > in std_validate_compound()
1021 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
1022 return -EINVAL; in std_validate_compound()
1023 if (p_h264_pps->weighted_bipred_idc > 2) in std_validate_compound()
1024 return -EINVAL; in std_validate_compound()
1027 * -(26 + QpBdOffset_y) to +25, inclusive, in std_validate_compound()
1030 if (p_h264_pps->pic_init_qp_minus26 < -62 || in std_validate_compound()
1031 p_h264_pps->pic_init_qp_minus26 > 25) in std_validate_compound()
1032 return -EINVAL; in std_validate_compound()
1033 if (p_h264_pps->pic_init_qs_minus26 < -26 || in std_validate_compound()
1034 p_h264_pps->pic_init_qs_minus26 > 25) in std_validate_compound()
1035 return -EINVAL; in std_validate_compound()
1036 if (p_h264_pps->chroma_qp_index_offset < -12 || in std_validate_compound()
1037 p_h264_pps->chroma_qp_index_offset > 12) in std_validate_compound()
1038 return -EINVAL; in std_validate_compound()
1039 if (p_h264_pps->second_chroma_qp_index_offset < -12 || in std_validate_compound()
1040 p_h264_pps->second_chroma_qp_index_offset > 12) in std_validate_compound()
1041 return -EINVAL; in std_validate_compound()
1050 if (p_h264_pred_weights->luma_log2_weight_denom > 7) in std_validate_compound()
1051 return -EINVAL; in std_validate_compound()
1052 if (p_h264_pred_weights->chroma_log2_weight_denom > 7) in std_validate_compound()
1053 return -EINVAL; in std_validate_compound()
1059 if (p_h264_slice_params->slice_type != V4L2_H264_SLICE_TYPE_B) in std_validate_compound()
1060 p_h264_slice_params->flags &= in std_validate_compound()
1063 if (p_h264_slice_params->colour_plane_id > 2) in std_validate_compound()
1064 return -EINVAL; in std_validate_compound()
1065 if (p_h264_slice_params->cabac_init_idc > 2) in std_validate_compound()
1066 return -EINVAL; in std_validate_compound()
1067 if (p_h264_slice_params->disable_deblocking_filter_idc > 2) in std_validate_compound()
1068 return -EINVAL; in std_validate_compound()
1069 if (p_h264_slice_params->slice_alpha_c0_offset_div2 < -6 || in std_validate_compound()
1070 p_h264_slice_params->slice_alpha_c0_offset_div2 > 6) in std_validate_compound()
1071 return -EINVAL; in std_validate_compound()
1072 if (p_h264_slice_params->slice_beta_offset_div2 < -6 || in std_validate_compound()
1073 p_h264_slice_params->slice_beta_offset_div2 > 6) in std_validate_compound()
1074 return -EINVAL; in std_validate_compound()
1076 if (p_h264_slice_params->slice_type == V4L2_H264_SLICE_TYPE_I || in std_validate_compound()
1077 p_h264_slice_params->slice_type == V4L2_H264_SLICE_TYPE_SI) in std_validate_compound()
1078 p_h264_slice_params->num_ref_idx_l0_active_minus1 = 0; in std_validate_compound()
1079 if (p_h264_slice_params->slice_type != V4L2_H264_SLICE_TYPE_B) in std_validate_compound()
1080 p_h264_slice_params->num_ref_idx_l1_active_minus1 = 0; in std_validate_compound()
1082 if (p_h264_slice_params->num_ref_idx_l0_active_minus1 > in std_validate_compound()
1083 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
1084 return -EINVAL; in std_validate_compound()
1085 if (p_h264_slice_params->num_ref_idx_l1_active_minus1 > in std_validate_compound()
1086 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
1087 return -EINVAL; in std_validate_compound()
1094 if (p_h264_dec_params->nal_ref_idc > 3) in std_validate_compound()
1095 return -EINVAL; in std_validate_compound()
1098 &p_h264_dec_params->dpb[i]; in std_validate_compound()
1108 switch (p_vp8_frame->num_dct_parts) { in std_validate_compound()
1115 return -EINVAL; in std_validate_compound()
1117 zero_padding(p_vp8_frame->segment); in std_validate_compound()
1118 zero_padding(p_vp8_frame->lf); in std_validate_compound()
1119 zero_padding(p_vp8_frame->quant); in std_validate_compound()
1120 zero_padding(p_vp8_frame->entropy); in std_validate_compound()
1121 zero_padding(p_vp8_frame->coder_state); in std_validate_compound()
1127 if (!(p_hevc_sps->flags & V4L2_HEVC_SPS_FLAG_PCM_ENABLED)) { in std_validate_compound()
1128 p_hevc_sps->pcm_sample_bit_depth_luma_minus1 = 0; in std_validate_compound()
1129 p_hevc_sps->pcm_sample_bit_depth_chroma_minus1 = 0; in std_validate_compound()
1130 p_hevc_sps->log2_min_pcm_luma_coding_block_size_minus3 = 0; in std_validate_compound()
1131 p_hevc_sps->log2_diff_max_min_pcm_luma_coding_block_size = 0; in std_validate_compound()
1134 if (!(p_hevc_sps->flags & in std_validate_compound()
1136 p_hevc_sps->num_long_term_ref_pics_sps = 0; in std_validate_compound()
1142 if (!(p_hevc_pps->flags & in std_validate_compound()
1144 p_hevc_pps->diff_cu_qp_delta_depth = 0; in std_validate_compound()
1146 if (!(p_hevc_pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED)) { in std_validate_compound()
1147 p_hevc_pps->num_tile_columns_minus1 = 0; in std_validate_compound()
1148 p_hevc_pps->num_tile_rows_minus1 = 0; in std_validate_compound()
1149 memset(&p_hevc_pps->column_width_minus1, 0, in std_validate_compound()
1150 sizeof(p_hevc_pps->column_width_minus1)); in std_validate_compound()
1151 memset(&p_hevc_pps->row_height_minus1, 0, in std_validate_compound()
1152 sizeof(p_hevc_pps->row_height_minus1)); in std_validate_compound()
1154 p_hevc_pps->flags &= in std_validate_compound()
1158 if (p_hevc_pps->flags & in std_validate_compound()
1160 p_hevc_pps->pps_beta_offset_div2 = 0; in std_validate_compound()
1161 p_hevc_pps->pps_tc_offset_div2 = 0; in std_validate_compound()
1168 if (p_hevc_decode_params->num_active_dpb_entries > in std_validate_compound()
1170 return -EINVAL; in std_validate_compound()
1183 if (p_hdr10_mastering->display_primaries_x[i] < in std_validate_compound()
1185 p_hdr10_mastering->display_primaries_x[i] > in std_validate_compound()
1187 p_hdr10_mastering->display_primaries_y[i] < in std_validate_compound()
1189 p_hdr10_mastering->display_primaries_y[i] > in std_validate_compound()
1191 return -EINVAL; in std_validate_compound()
1194 if (p_hdr10_mastering->white_point_x < in std_validate_compound()
1196 p_hdr10_mastering->white_point_x > in std_validate_compound()
1198 p_hdr10_mastering->white_point_y < in std_validate_compound()
1200 p_hdr10_mastering->white_point_y > in std_validate_compound()
1202 return -EINVAL; in std_validate_compound()
1204 if (p_hdr10_mastering->max_display_mastering_luminance < in std_validate_compound()
1206 p_hdr10_mastering->max_display_mastering_luminance > in std_validate_compound()
1208 p_hdr10_mastering->min_display_mastering_luminance < in std_validate_compound()
1210 p_hdr10_mastering->min_display_mastering_luminance > in std_validate_compound()
1212 return -EINVAL; in std_validate_compound()
1214 /* The following restriction comes from ITU-T Rec. H.265 spec */ in std_validate_compound()
1215 if (p_hdr10_mastering->max_display_mastering_luminance == in std_validate_compound()
1217 p_hdr10_mastering->min_display_mastering_luminance == in std_validate_compound()
1219 return -EINVAL; in std_validate_compound()
1242 if (!area->width || !area->height) in std_validate_compound()
1243 return -EINVAL; in std_validate_compound()
1248 if (!rect->width || !rect->height) in std_validate_compound()
1249 return -EINVAL; in std_validate_compound()
1253 return -EINVAL; in std_validate_compound()
1266 switch ((u32)ctrl->type) { in std_validate_elem()
1275 if (ctrl->maximum >= 0 && val >= ctrl->maximum - (s64)(ctrl->step / 2)) in std_validate_elem()
1276 val = ctrl->maximum; in std_validate_elem()
1278 val += (s64)(ctrl->step / 2); in std_validate_elem()
1279 val = clamp_t(s64, val, ctrl->minimum, ctrl->maximum); in std_validate_elem()
1280 offset = val - ctrl->minimum; in std_validate_elem()
1281 do_div(offset, ctrl->step); in std_validate_elem()
1282 ptr.p_s64[idx] = ctrl->minimum + offset * ctrl->step; in std_validate_elem()
1297 if (ptr.p_s32[idx] < ctrl->minimum || ptr.p_s32[idx] > ctrl->maximum) in std_validate_elem()
1298 return -ERANGE; in std_validate_elem()
1300 (ctrl->menu_skip_mask & BIT_ULL(ptr.p_s32[idx]))) in std_validate_elem()
1301 return -EINVAL; in std_validate_elem()
1302 if (ctrl->type == V4L2_CTRL_TYPE_MENU && in std_validate_elem()
1303 ctrl->qmenu[ptr.p_s32[idx]][0] == '\0') in std_validate_elem()
1304 return -EINVAL; in std_validate_elem()
1308 ptr.p_s32[idx] &= ctrl->maximum; in std_validate_elem()
1317 idx *= ctrl->elem_size; in std_validate_elem()
1319 if (len < ctrl->minimum) in std_validate_elem()
1320 return -ERANGE; in std_validate_elem()
1321 if ((len - (u32)ctrl->minimum) % (u32)ctrl->step) in std_validate_elem()
1322 return -ERANGE; in std_validate_elem()
1336 switch ((u32)ctrl->type) { in v4l2_ctrl_type_op_validate()
1338 if (ctrl->maximum == 0xff && ctrl->minimum == 0 && ctrl->step == 1) in v4l2_ctrl_type_op_validate()
1342 if (ctrl->maximum == 0xffff && ctrl->minimum == 0 && ctrl->step == 1) in v4l2_ctrl_type_op_validate()
1346 if (ctrl->maximum == 0xffffffff && ctrl->minimum == 0 && ctrl->step == 1) in v4l2_ctrl_type_op_validate()
1352 memset(ptr.p_s32, 0, ctrl->new_elems * sizeof(s32)); in v4l2_ctrl_type_op_validate()
1356 for (i = 0; !ret && i < ctrl->new_elems; i++) in v4l2_ctrl_type_op_validate()
1376 ctrl->call_notify = 0; in v4l2_ctrl_notify()
1379 if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify)) in v4l2_ctrl_notify()
1381 ctrl->handler->notify = notify; in v4l2_ctrl_notify()
1382 ctrl->handler->notify_priv = priv; in v4l2_ctrl_notify()
1383 ctrl->call_notify = 1; in v4l2_ctrl_notify()
1394 memcpy(to.p, from.p_const, elems * ctrl->elem_size); in ptr_to_ptr()
1406 changed = ctrl->has_changed; in new_to_cur()
1408 if (ctrl->is_dyn_array) in new_to_cur()
1409 ctrl->elems = ctrl->new_elems; in new_to_cur()
1410 ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur, ctrl->elems); in new_to_cur()
1415 ctrl->flags &= in new_to_cur()
1417 if (!is_cur_manual(ctrl->cluster[0])) { in new_to_cur()
1418 ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; in new_to_cur()
1419 if (ctrl->cluster[0]->has_volatiles) in new_to_cur()
1420 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in new_to_cur()
1427 if (!ctrl->is_new) in new_to_cur()
1431 if (ctrl->call_notify && changed && ctrl->handler->notify) in new_to_cur()
1432 ctrl->handler->notify(ctrl, ctrl->handler->notify_priv); in new_to_cur()
1441 if (ctrl->is_dyn_array) in cur_to_new()
1442 ctrl->new_elems = ctrl->elems; in cur_to_new()
1443 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new, ctrl->new_elems); in cur_to_new()
1450 if (elems == ref->p_req_array_alloc_elems) in req_alloc_array()
1452 if (ref->ctrl->is_dyn_array && in req_alloc_array()
1453 elems < ref->p_req_array_alloc_elems) in req_alloc_array()
1456 tmp = kvmalloc(elems * ref->ctrl->elem_size, GFP_KERNEL); in req_alloc_array()
1459 ref->p_req_array_enomem = true; in req_alloc_array()
1462 ref->p_req_array_enomem = false; in req_alloc_array()
1463 kvfree(ref->p_req.p); in req_alloc_array()
1464 ref->p_req.p = tmp; in req_alloc_array()
1465 ref->p_req_array_alloc_elems = elems; in req_alloc_array()
1477 ctrl = ref->ctrl; in new_to_req()
1478 if (ctrl->is_array && !req_alloc_array(ref, ctrl->new_elems)) in new_to_req()
1481 ref->p_req_elems = ctrl->new_elems; in new_to_req()
1482 ptr_to_ptr(ctrl, ctrl->p_new, ref->p_req, ref->p_req_elems); in new_to_req()
1483 ref->p_req_valid = true; in new_to_req()
1494 ctrl = ref->ctrl; in cur_to_req()
1495 if (ctrl->is_array && !req_alloc_array(ref, ctrl->elems)) in cur_to_req()
1498 ref->p_req_elems = ctrl->elems; in cur_to_req()
1499 ptr_to_ptr(ctrl, ctrl->p_cur, ref->p_req, ctrl->elems); in cur_to_req()
1500 ref->p_req_valid = true; in cur_to_req()
1511 ctrl = ref->ctrl; in req_to_new()
1517 if (!ref->p_req_valid) { in req_to_new()
1518 if (ctrl->is_dyn_array) in req_to_new()
1519 ctrl->new_elems = ctrl->elems; in req_to_new()
1520 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new, ctrl->new_elems); in req_to_new()
1525 if (!ctrl->is_array) { in req_to_new()
1526 ptr_to_ptr(ctrl, ref->p_req, ctrl->p_new, ctrl->new_elems); in req_to_new()
1531 if (WARN_ON(!ref->p_req_array_alloc_elems)) in req_to_new()
1532 return -ENOMEM; in req_to_new()
1534 if (!ctrl->is_dyn_array && in req_to_new()
1535 ref->p_req_elems != ctrl->p_array_alloc_elems) in req_to_new()
1536 return -ENOMEM; in req_to_new()
1540 * elements in ctrl->p_array. If so, attempt to realloc ctrl->p_array. in req_to_new()
1545 if (ref->p_req_elems > ctrl->p_array_alloc_elems) { in req_to_new()
1546 unsigned int sz = ref->p_req_elems * ctrl->elem_size; in req_to_new()
1547 void *old = ctrl->p_array; in req_to_new()
1551 return -ENOMEM; in req_to_new()
1552 memcpy(tmp, ctrl->p_new.p, ctrl->elems * ctrl->elem_size); in req_to_new()
1553 memcpy(tmp + sz, ctrl->p_cur.p, ctrl->elems * ctrl->elem_size); in req_to_new()
1554 ctrl->p_new.p = tmp; in req_to_new()
1555 ctrl->p_cur.p = tmp + sz; in req_to_new()
1556 ctrl->p_array = tmp; in req_to_new()
1557 ctrl->p_array_alloc_elems = ref->p_req_elems; in req_to_new()
1561 ctrl->new_elems = ref->p_req_elems; in req_to_new()
1562 ptr_to_ptr(ctrl, ref->p_req, ctrl->p_new, ctrl->new_elems); in req_to_new()
1573 return -ERANGE; in check_range()
1581 return -ERANGE; in check_range()
1585 return -ERANGE; in check_range()
1591 return -ERANGE; in check_range()
1595 return -EINVAL; in check_range()
1599 return -ERANGE; in check_range()
1609 if (hdl->error == 0) in handler_set_err()
1610 hdl->error = err; in handler_set_err()
1619 mutex_init(&hdl->_lock); in v4l2_ctrl_handler_init_class()
1620 hdl->lock = &hdl->_lock; in v4l2_ctrl_handler_init_class()
1621 lockdep_set_class_and_name(hdl->lock, key, name); in v4l2_ctrl_handler_init_class()
1622 INIT_LIST_HEAD(&hdl->ctrls); in v4l2_ctrl_handler_init_class()
1623 INIT_LIST_HEAD(&hdl->ctrl_refs); in v4l2_ctrl_handler_init_class()
1624 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; in v4l2_ctrl_handler_init_class()
1625 hdl->buckets = kvcalloc(hdl->nr_of_buckets, sizeof(hdl->buckets[0]), in v4l2_ctrl_handler_init_class()
1627 hdl->error = hdl->buckets ? 0 : -ENOMEM; in v4l2_ctrl_handler_init_class()
1629 return hdl->error; in v4l2_ctrl_handler_init_class()
1640 if (hdl == NULL || hdl->buckets == NULL) in v4l2_ctrl_handler_free()
1645 mutex_lock(hdl->lock); in v4l2_ctrl_handler_free()
1647 list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { in v4l2_ctrl_handler_free()
1648 list_del(&ref->node); in v4l2_ctrl_handler_free()
1649 if (ref->p_req_array_alloc_elems) in v4l2_ctrl_handler_free()
1650 kvfree(ref->p_req.p); in v4l2_ctrl_handler_free()
1654 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_free()
1655 list_del(&ctrl->node); in v4l2_ctrl_handler_free()
1656 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node) in v4l2_ctrl_handler_free()
1657 list_del(&sev->node); in v4l2_ctrl_handler_free()
1658 kvfree(ctrl->p_array); in v4l2_ctrl_handler_free()
1661 kvfree(hdl->buckets); in v4l2_ctrl_handler_free()
1662 hdl->buckets = NULL; in v4l2_ctrl_handler_free()
1663 hdl->cached = NULL; in v4l2_ctrl_handler_free()
1664 hdl->error = 0; in v4l2_ctrl_handler_free()
1665 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_free()
1666 mutex_destroy(&hdl->_lock); in v4l2_ctrl_handler_free()
1674 We just find the n-th private user control. It's O(N), but that should not
1681 id -= V4L2_CID_PRIVATE_BASE; in find_private_ref()
1682 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in find_private_ref()
1685 if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER && in find_private_ref()
1686 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) { in find_private_ref()
1687 if (!ref->ctrl->is_int) in find_private_ref()
1691 id--; in find_private_ref()
1705 /* Old-style private controls need special handling */ in find_ref()
1708 bucket = id % hdl->nr_of_buckets; in find_ref()
1711 if (hdl->cached && hdl->cached->ctrl->id == id) in find_ref()
1712 return hdl->cached; in find_ref()
1715 ref = hdl->buckets ? hdl->buckets[bucket] : NULL; in find_ref()
1716 while (ref && ref->ctrl->id != id) in find_ref()
1717 ref = ref->next; in find_ref()
1720 hdl->cached = ref; /* cache it! */ in find_ref()
1730 mutex_lock(hdl->lock); in find_ref_lock()
1732 mutex_unlock(hdl->lock); in find_ref_lock()
1742 return ref ? ref->ctrl : NULL; in v4l2_ctrl_find()
1754 u32 id = ctrl->id; in handler_new_ref()
1756 int bucket = id % hdl->nr_of_buckets; /* which bucket to use */ in handler_new_ref()
1766 if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES && in handler_new_ref()
1769 return hdl->error; in handler_new_ref()
1771 if (hdl->error) in handler_new_ref()
1772 return hdl->error; in handler_new_ref()
1774 if (allocate_req && !ctrl->is_array) in handler_new_ref()
1775 size_extra_req = ctrl->elems * ctrl->elem_size; in handler_new_ref()
1778 return handler_set_err(hdl, -ENOMEM); in handler_new_ref()
1779 new_ref->ctrl = ctrl; in handler_new_ref()
1780 new_ref->from_other_dev = from_other_dev; in handler_new_ref()
1782 new_ref->p_req.p = &new_ref[1]; in handler_new_ref()
1784 INIT_LIST_HEAD(&new_ref->node); in handler_new_ref()
1786 mutex_lock(hdl->lock); in handler_new_ref()
1792 if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) { in handler_new_ref()
1793 list_add_tail(&new_ref->node, &hdl->ctrl_refs); in handler_new_ref()
1798 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in handler_new_ref()
1799 if (ref->ctrl->id < id) in handler_new_ref()
1802 if (ref->ctrl->id == id) { in handler_new_ref()
1806 list_add(&new_ref->node, ref->node.prev); in handler_new_ref()
1812 new_ref->next = hdl->buckets[bucket]; in handler_new_ref()
1813 hdl->buckets[bucket] = new_ref; in handler_new_ref()
1816 if (ctrl->handler == hdl) { in handler_new_ref()
1818 * new_ref->ctrl is basically a cluster array with one in handler_new_ref()
1822 ctrl->cluster = &new_ref->ctrl; in handler_new_ref()
1823 ctrl->ncontrols = 1; in handler_new_ref()
1827 mutex_unlock(hdl->lock); in handler_new_ref()
1854 if (hdl->error) in v4l2_ctrl_new()
1977 handler_set_err(hdl, -ERANGE); in v4l2_ctrl_new()
1989 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new()
1994 * For now only support this for one-dimensional arrays only. in v4l2_ctrl_new()
2000 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new()
2029 handler_set_err(hdl, -ENOMEM); in v4l2_ctrl_new()
2033 INIT_LIST_HEAD(&ctrl->node); in v4l2_ctrl_new()
2034 INIT_LIST_HEAD(&ctrl->ev_subs); in v4l2_ctrl_new()
2035 ctrl->handler = hdl; in v4l2_ctrl_new()
2036 ctrl->ops = ops; in v4l2_ctrl_new()
2037 ctrl->type_ops = type_ops ? type_ops : &std_type_ops; in v4l2_ctrl_new()
2038 ctrl->id = id; in v4l2_ctrl_new()
2039 ctrl->name = name; in v4l2_ctrl_new()
2040 ctrl->type = type; in v4l2_ctrl_new()
2041 ctrl->flags = flags; in v4l2_ctrl_new()
2042 ctrl->minimum = min; in v4l2_ctrl_new()
2043 ctrl->maximum = max; in v4l2_ctrl_new()
2044 ctrl->step = step; in v4l2_ctrl_new()
2045 ctrl->default_value = def; in v4l2_ctrl_new()
2046 ctrl->is_string = !is_array && type == V4L2_CTRL_TYPE_STRING; in v4l2_ctrl_new()
2047 ctrl->is_ptr = is_array || type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string; in v4l2_ctrl_new()
2048 ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64; in v4l2_ctrl_new()
2049 ctrl->is_array = is_array; in v4l2_ctrl_new()
2050 ctrl->is_dyn_array = !!(flags & V4L2_CTRL_FLAG_DYNAMIC_ARRAY); in v4l2_ctrl_new()
2051 ctrl->elems = elems; in v4l2_ctrl_new()
2052 ctrl->new_elems = elems; in v4l2_ctrl_new()
2053 ctrl->nr_of_dims = nr_of_dims; in v4l2_ctrl_new()
2055 memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0])); in v4l2_ctrl_new()
2056 ctrl->elem_size = elem_size; in v4l2_ctrl_new()
2058 ctrl->qmenu = qmenu; in v4l2_ctrl_new()
2060 ctrl->qmenu_int = qmenu_int; in v4l2_ctrl_new()
2061 ctrl->priv = priv; in v4l2_ctrl_new()
2062 ctrl->cur.val = ctrl->val = def; in v4l2_ctrl_new()
2065 if (ctrl->is_array) { in v4l2_ctrl_new()
2066 ctrl->p_array_alloc_elems = elems; in v4l2_ctrl_new()
2067 ctrl->p_array = kvzalloc(2 * elems * elem_size, GFP_KERNEL); in v4l2_ctrl_new()
2068 if (!ctrl->p_array) { in v4l2_ctrl_new()
2072 data = ctrl->p_array; in v4l2_ctrl_new()
2075 if (!ctrl->is_int) { in v4l2_ctrl_new()
2076 ctrl->p_new.p = data; in v4l2_ctrl_new()
2077 ctrl->p_cur.p = data + tot_ctrl_size; in v4l2_ctrl_new()
2079 ctrl->p_new.p = &ctrl->val; in v4l2_ctrl_new()
2080 ctrl->p_cur.p = &ctrl->cur.val; in v4l2_ctrl_new()
2084 if (ctrl->is_array) in v4l2_ctrl_new()
2085 ctrl->p_def.p = &ctrl[1]; in v4l2_ctrl_new()
2087 ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size; in v4l2_ctrl_new()
2088 memcpy(ctrl->p_def.p, p_def.p_const, elem_size); in v4l2_ctrl_new()
2092 void *ptr = ctrl->p_def.p; in v4l2_ctrl_new()
2096 ctrl->p_min.p = ptr; in v4l2_ctrl_new()
2097 memcpy(ctrl->p_min.p, p_min.p_const, elem_size); in v4l2_ctrl_new()
2102 ctrl->p_max.p = ptr; in v4l2_ctrl_new()
2103 memcpy(ctrl->p_max.p, p_max.p_const, elem_size); in v4l2_ctrl_new()
2107 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); in v4l2_ctrl_new()
2111 kvfree(ctrl->p_array); in v4l2_ctrl_new()
2115 mutex_lock(hdl->lock); in v4l2_ctrl_new()
2116 list_add_tail(&ctrl->node, &hdl->ctrls); in v4l2_ctrl_new()
2117 mutex_unlock(hdl->lock); in v4l2_ctrl_new()
2126 const char *name = cfg->name; in v4l2_ctrl_new_custom()
2127 const char * const *qmenu = cfg->qmenu; in v4l2_ctrl_new_custom()
2128 const s64 *qmenu_int = cfg->qmenu_int; in v4l2_ctrl_new_custom()
2129 enum v4l2_ctrl_type type = cfg->type; in v4l2_ctrl_new_custom()
2130 u32 flags = cfg->flags; in v4l2_ctrl_new_custom()
2131 s64 min = cfg->min; in v4l2_ctrl_new_custom()
2132 s64 max = cfg->max; in v4l2_ctrl_new_custom()
2133 u64 step = cfg->step; in v4l2_ctrl_new_custom()
2134 s64 def = cfg->def; in v4l2_ctrl_new_custom()
2137 v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step, in v4l2_ctrl_new_custom()
2145 WARN_ON(cfg->menu_skip_mask); in v4l2_ctrl_new_custom()
2147 qmenu = v4l2_ctrl_get_menu(cfg->id); in v4l2_ctrl_new_custom()
2149 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_custom()
2153 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name, in v4l2_ctrl_new_custom()
2155 is_menu ? cfg->menu_skip_mask : step, def, in v4l2_ctrl_new_custom()
2156 cfg->dims, cfg->elem_size, in v4l2_ctrl_new_custom()
2157 flags, qmenu, qmenu_int, cfg->p_def, cfg->p_min, in v4l2_ctrl_new_custom()
2158 cfg->p_max, priv); in v4l2_ctrl_new_custom()
2160 ctrl->is_private = cfg->is_private; in v4l2_ctrl_new_custom()
2165 /* Helper function for standard non-menu controls */
2178 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std()
2212 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu()
2239 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2245 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2270 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_compound()
2294 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_int_menu()
2316 if (hdl->error) in v4l2_ctrl_add_handler()
2317 return hdl->error; in v4l2_ctrl_add_handler()
2318 mutex_lock(add->lock); in v4l2_ctrl_add_handler()
2319 list_for_each_entry(ref, &add->ctrl_refs, node) { in v4l2_ctrl_add_handler()
2320 struct v4l2_ctrl *ctrl = ref->ctrl; in v4l2_ctrl_add_handler()
2322 /* Skip handler-private controls. */ in v4l2_ctrl_add_handler()
2323 if (ctrl->is_private) in v4l2_ctrl_add_handler()
2326 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) in v4l2_ctrl_add_handler()
2335 mutex_unlock(add->lock); in v4l2_ctrl_add_handler()
2342 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX) in v4l2_ctrl_radio_filter()
2344 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX) in v4l2_ctrl_radio_filter()
2346 switch (ctrl->id) { in v4l2_ctrl_radio_filter()
2367 /* The first control is the master control and it must not be NULL */ in v4l2_ctrl_cluster()
2373 controls[i]->cluster = controls; in v4l2_ctrl_cluster()
2374 controls[i]->ncontrols = ncontrols; in v4l2_ctrl_cluster()
2375 if (controls[i]->flags & V4L2_CTRL_FLAG_VOLATILE) in v4l2_ctrl_cluster()
2379 controls[0]->has_volatiles = has_volatiles; in v4l2_ctrl_cluster()
2386 struct v4l2_ctrl *master = controls[0]; in v4l2_ctrl_auto_cluster() local
2392 WARN_ON(manual_val < master->minimum || manual_val > master->maximum); in v4l2_ctrl_auto_cluster()
2393 WARN_ON(set_volatile && !has_op(master, g_volatile_ctrl)); in v4l2_ctrl_auto_cluster()
2394 master->is_auto = true; in v4l2_ctrl_auto_cluster()
2395 master->has_volatiles = set_volatile; in v4l2_ctrl_auto_cluster()
2396 master->manual_mode_value = manual_val; in v4l2_ctrl_auto_cluster()
2397 master->flags |= V4L2_CTRL_FLAG_UPDATE; in v4l2_ctrl_auto_cluster()
2399 if (!is_cur_manual(master)) in v4l2_ctrl_auto_cluster()
2405 controls[i]->flags |= flag; in v4l2_ctrl_auto_cluster()
2413 void update_from_auto_cluster(struct v4l2_ctrl *master) in update_from_auto_cluster() argument
2417 for (i = 1; i < master->ncontrols; i++) in update_from_auto_cluster()
2418 cur_to_new(master->cluster[i]); in update_from_auto_cluster()
2419 if (!call_op(master, g_volatile_ctrl)) in update_from_auto_cluster()
2420 for (i = 1; i < master->ncontrols; i++) in update_from_auto_cluster()
2421 if (master->cluster[i]) in update_from_auto_cluster()
2422 master->cluster[i]->is_new = 1; in update_from_auto_cluster()
2426 * Return non-zero if one or more of the controls in the cluster has a new
2429 static int cluster_changed(struct v4l2_ctrl *master) in cluster_changed() argument
2434 for (i = 0; i < master->ncontrols; i++) { in cluster_changed()
2435 struct v4l2_ctrl *ctrl = master->cluster[i]; in cluster_changed()
2441 if (ctrl->flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE) { in cluster_changed()
2450 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in cluster_changed()
2451 ctrl->has_changed = false; in cluster_changed()
2455 if (ctrl->elems != ctrl->new_elems) in cluster_changed()
2458 ctrl_changed = !ctrl->type_ops->equal(ctrl, in cluster_changed()
2459 ctrl->p_cur, ctrl->p_new); in cluster_changed()
2460 ctrl->has_changed = ctrl_changed; in cluster_changed()
2461 changed |= ctrl->has_changed; in cluster_changed()
2469 * Must be called with ctrl->handler->lock held.
2471 int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master, in try_or_set_cluster() argument
2484 for (i = 0; i < master->ncontrols; i++) { in try_or_set_cluster()
2485 struct v4l2_ctrl *ctrl = master->cluster[i]; in try_or_set_cluster()
2490 if (!ctrl->is_new) { in try_or_set_cluster()
2498 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) in try_or_set_cluster()
2499 return -EBUSY; in try_or_set_cluster()
2502 ret = call_op(master, try_ctrl); in try_or_set_cluster()
2505 if (ret || !set || !cluster_changed(master)) in try_or_set_cluster()
2507 ret = call_op(master, s_ctrl); in try_or_set_cluster()
2512 update_flag = is_cur_manual(master) != is_new_manual(master); in try_or_set_cluster()
2514 for (i = 0; i < master->ncontrols; i++) { in try_or_set_cluster()
2517 * contains volatile controls, then all non-master controls in try_or_set_cluster()
2522 if (i && update_flag && is_new_manual(master) && in try_or_set_cluster()
2523 master->has_volatiles && master->cluster[i]) in try_or_set_cluster()
2524 master->cluster[i]->has_changed = true; in try_or_set_cluster()
2526 new_to_cur(fh, master->cluster[i], ch_flags | in try_or_set_cluster()
2544 old = test_and_set_bit(4, &ctrl->flags); in v4l2_ctrl_activate()
2547 old = test_and_clear_bit(4, &ctrl->flags); in v4l2_ctrl_activate()
2560 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_grab()
2564 old = test_and_set_bit(1, &ctrl->flags); in __v4l2_ctrl_grab()
2567 old = test_and_clear_bit(1, &ctrl->flags); in __v4l2_ctrl_grab()
2582 lockdep_assert_held(hdl->lock); in __v4l2_ctrl_handler_setup()
2584 list_for_each_entry(ctrl, &hdl->ctrls, node) in __v4l2_ctrl_handler_setup()
2585 ctrl->done = false; in __v4l2_ctrl_handler_setup()
2587 list_for_each_entry(ctrl, &hdl->ctrls, node) { in __v4l2_ctrl_handler_setup()
2588 struct v4l2_ctrl *master = ctrl->cluster[0]; in __v4l2_ctrl_handler_setup() local
2592 /* Skip button controls and read-only controls. */ in __v4l2_ctrl_handler_setup()
2593 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON || in __v4l2_ctrl_handler_setup()
2594 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) in __v4l2_ctrl_handler_setup()
2597 for (i = 0; i < master->ncontrols; i++) { in __v4l2_ctrl_handler_setup()
2598 if (master->cluster[i]) { in __v4l2_ctrl_handler_setup()
2599 cur_to_new(master->cluster[i]); in __v4l2_ctrl_handler_setup()
2600 master->cluster[i]->is_new = 1; in __v4l2_ctrl_handler_setup()
2601 master->cluster[i]->done = true; in __v4l2_ctrl_handler_setup()
2604 ret = call_op(master, s_ctrl); in __v4l2_ctrl_handler_setup()
2620 mutex_lock(hdl->lock); in v4l2_ctrl_handler_setup()
2622 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_setup()
2632 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY)) in log_ctrl()
2634 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) in log_ctrl()
2637 pr_info("%s%s%s: ", prefix, colon, ctrl->name); in log_ctrl()
2639 ctrl->type_ops->log(ctrl); in log_ctrl()
2641 if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE | in log_ctrl()
2644 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) in log_ctrl()
2646 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED) in log_ctrl()
2648 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) in log_ctrl()
2667 if (len && prefix[len - 1] != ' ') in v4l2_ctrl_handler_log_status()
2669 mutex_lock(hdl->lock); in v4l2_ctrl_handler_log_status()
2670 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_log_status()
2671 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED)) in v4l2_ctrl_handler_log_status()
2673 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_log_status()
2681 if (hdl->error) in v4l2_ctrl_new_fwnode_properties()
2682 return hdl->error; in v4l2_ctrl_new_fwnode_properties()
2684 if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) { in v4l2_ctrl_new_fwnode_properties()
2687 switch (p->orientation) { in v4l2_ctrl_new_fwnode_properties()
2698 return -EINVAL; in v4l2_ctrl_new_fwnode_properties()
2704 return hdl->error; in v4l2_ctrl_new_fwnode_properties()
2707 if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET) { in v4l2_ctrl_new_fwnode_properties()
2710 p->rotation, p->rotation, 1, in v4l2_ctrl_new_fwnode_properties()
2711 p->rotation)) in v4l2_ctrl_new_fwnode_properties()
2712 return hdl->error; in v4l2_ctrl_new_fwnode_properties()
2715 return hdl->error; in v4l2_ctrl_new_fwnode_properties()