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()
189 u32 tot_elems = ctrl->elems; in v4l2_ctrl_type_op_init()
190 u32 elems = tot_elems - from_idx; in v4l2_ctrl_type_op_init()
195 switch (ctrl->type) { in v4l2_ctrl_type_op_init()
198 unsigned int offset = i * ctrl->elem_size; in v4l2_ctrl_type_op_init()
200 memset(ptr.p_char + offset, ' ', ctrl->minimum); in v4l2_ctrl_type_op_init()
201 ptr.p_char[offset + ctrl->minimum] = '\0'; in v4l2_ctrl_type_op_init()
205 if (ctrl->default_value) { in v4l2_ctrl_type_op_init()
207 ptr.p_s64[i] = ctrl->default_value; in v4l2_ctrl_type_op_init()
217 if (ctrl->default_value) { in v4l2_ctrl_type_op_init()
219 ptr.p_s32[i] = ctrl->default_value; in v4l2_ctrl_type_op_init()
229 memset(ptr.p_u8 + from_idx, ctrl->default_value, elems); in v4l2_ctrl_type_op_init()
232 if (ctrl->default_value) { in v4l2_ctrl_type_op_init()
234 ptr.p_u16[i] = ctrl->default_value; in v4l2_ctrl_type_op_init()
240 if (ctrl->default_value) { in v4l2_ctrl_type_op_init()
242 ptr.p_u32[i] = ctrl->default_value; in v4l2_ctrl_type_op_init()
257 union v4l2_ctrl_ptr ptr = ctrl->p_cur; in v4l2_ctrl_type_op_log()
259 if (ctrl->is_array) { in v4l2_ctrl_type_op_log()
262 for (i = 0; i < ctrl->nr_of_dims; i++) in v4l2_ctrl_type_op_log()
263 pr_cont("[%u]", ctrl->dims[i]); in v4l2_ctrl_type_op_log()
267 switch (ctrl->type) { in v4l2_ctrl_type_op_log()
275 pr_cont("%s", ctrl->qmenu[*ptr.p_s32]); in v4l2_ctrl_type_op_log()
278 pr_cont("%lld", ctrl->qmenu_int[*ptr.p_s32]); in v4l2_ctrl_type_op_log()
372 pr_cont("unknown type %d", ctrl->type); in v4l2_ctrl_type_op_log()
381 * wrap-arounds.
386 if ((ctrl)->maximum >= 0 && \
387 val >= (ctrl)->maximum - (s32)((ctrl)->step / 2)) \
388 val = (ctrl)->maximum; \
390 val += (s32)((ctrl)->step / 2); \
392 (ctrl)->minimum, (ctrl)->maximum); \
393 offset = (val) - (ctrl)->minimum; \
394 offset = (ctrl)->step * (offset / (u32)(ctrl)->step); \
395 val = (ctrl)->minimum + offset; \
411 if (lf->flags & ~(V4L2_VP9_LOOP_FILTER_FLAG_DELTA_ENABLED | in validate_vp9_lf_params()
413 return -EINVAL; in validate_vp9_lf_params()
416 if (lf->level > GENMASK(5, 0)) in validate_vp9_lf_params()
417 return -EINVAL; in validate_vp9_lf_params()
419 if (lf->sharpness > GENMASK(2, 0)) in validate_vp9_lf_params()
420 return -EINVAL; in validate_vp9_lf_params()
422 for (i = 0; i < ARRAY_SIZE(lf->ref_deltas); i++) in validate_vp9_lf_params()
423 if (lf->ref_deltas[i] < -63 || lf->ref_deltas[i] > 63) in validate_vp9_lf_params()
424 return -EINVAL; in validate_vp9_lf_params()
426 for (i = 0; i < ARRAY_SIZE(lf->mode_deltas); i++) in validate_vp9_lf_params()
427 if (lf->mode_deltas[i] < -63 || lf->mode_deltas[i] > 63) in validate_vp9_lf_params()
428 return -EINVAL; in validate_vp9_lf_params()
437 if (quant->delta_q_y_dc < -15 || quant->delta_q_y_dc > 15 || in validate_vp9_quant_params()
438 quant->delta_q_uv_dc < -15 || quant->delta_q_uv_dc > 15 || in validate_vp9_quant_params()
439 quant->delta_q_uv_ac < -15 || quant->delta_q_uv_ac > 15) in validate_vp9_quant_params()
440 return -EINVAL; in validate_vp9_quant_params()
451 if (seg->flags & ~(V4L2_VP9_SEGMENTATION_FLAG_ENABLED | in validate_vp9_seg_params()
456 return -EINVAL; in validate_vp9_seg_params()
458 for (i = 0; i < ARRAY_SIZE(seg->feature_enabled); i++) { in validate_vp9_seg_params()
459 if (seg->feature_enabled[i] & in validate_vp9_seg_params()
461 return -EINVAL; in validate_vp9_seg_params()
464 for (i = 0; i < ARRAY_SIZE(seg->feature_data); i++) { in validate_vp9_seg_params()
467 for (j = 0; j < ARRAY_SIZE(seg->feature_data[j]); j++) { in validate_vp9_seg_params()
468 if (seg->feature_data[i][j] < -range[j] || in validate_vp9_seg_params()
469 seg->feature_data[i][j] > range[j]) in validate_vp9_seg_params()
470 return -EINVAL; in validate_vp9_seg_params()
481 if (hdr->tx_mode > V4L2_VP9_TX_MODE_SELECT) in validate_vp9_compressed_hdr()
482 return -EINVAL; in validate_vp9_compressed_hdr()
488 validate_vp9_frame(struct v4l2_ctrl_vp9_frame *frame) in validate_vp9_frame() argument
493 if (frame->flags & ~(V4L2_VP9_FRAME_FLAG_KEY_FRAME | in validate_vp9_frame()
503 return -EINVAL; in validate_vp9_frame()
505 if (frame->flags & V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT && in validate_vp9_frame()
506 frame->flags & V4L2_VP9_FRAME_FLAG_REFRESH_FRAME_CTX) in validate_vp9_frame()
507 return -EINVAL; in validate_vp9_frame()
509 if (frame->profile > V4L2_VP9_PROFILE_MAX) in validate_vp9_frame()
510 return -EINVAL; in validate_vp9_frame()
512 if (frame->reset_frame_context > V4L2_VP9_RESET_FRAME_CTX_ALL) in validate_vp9_frame()
513 return -EINVAL; in validate_vp9_frame()
515 if (frame->frame_context_idx >= V4L2_VP9_NUM_FRAME_CTX) in validate_vp9_frame()
516 return -EINVAL; in validate_vp9_frame()
519 * Profiles 0 and 1 only support 8-bit depth, profiles 2 and 3 only 10 in validate_vp9_frame()
522 if ((frame->profile < 2 && frame->bit_depth != 8) || in validate_vp9_frame()
523 (frame->profile >= 2 && in validate_vp9_frame()
524 (frame->bit_depth != 10 && frame->bit_depth != 12))) in validate_vp9_frame()
525 return -EINVAL; in validate_vp9_frame()
528 if ((frame->profile == 0 || frame->profile == 2) && in validate_vp9_frame()
529 (!(frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) || in validate_vp9_frame()
530 !(frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING))) in validate_vp9_frame()
531 return -EINVAL; in validate_vp9_frame()
534 if ((frame->profile == 1 || frame->profile == 3) && in validate_vp9_frame()
535 ((frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) && in validate_vp9_frame()
536 (frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING))) in validate_vp9_frame()
537 return -EINVAL; in validate_vp9_frame()
539 if (frame->interpolation_filter > V4L2_VP9_INTERP_FILTER_SWITCHABLE) in validate_vp9_frame()
540 return -EINVAL; in validate_vp9_frame()
546 if (frame->tile_cols_log2 > 6) in validate_vp9_frame()
547 return -EINVAL; in validate_vp9_frame()
549 if (frame->reference_mode > V4L2_VP9_REFERENCE_MODE_SELECT) in validate_vp9_frame()
550 return -EINVAL; in validate_vp9_frame()
552 ret = validate_vp9_lf_params(&frame->lf); in validate_vp9_frame()
556 ret = validate_vp9_quant_params(&frame->quant); in validate_vp9_frame()
560 ret = validate_vp9_seg_params(&frame->seg); in validate_vp9_frame()
564 zero_reserved(*frame); in validate_vp9_frame()
570 if (q->flags > GENMASK(2, 0)) in validate_av1_quantization()
571 return -EINVAL; in validate_av1_quantization()
573 if (q->delta_q_y_dc < -64 || q->delta_q_y_dc > 63 || in validate_av1_quantization()
574 q->delta_q_u_dc < -64 || q->delta_q_u_dc > 63 || in validate_av1_quantization()
575 q->delta_q_v_dc < -64 || q->delta_q_v_dc > 63 || in validate_av1_quantization()
576 q->delta_q_u_ac < -64 || q->delta_q_u_ac > 63 || in validate_av1_quantization()
577 q->delta_q_v_ac < -64 || q->delta_q_v_ac > 63 || in validate_av1_quantization()
578 q->delta_q_res > GENMASK(1, 0)) in validate_av1_quantization()
579 return -EINVAL; in validate_av1_quantization()
581 if (q->qm_y > GENMASK(3, 0) || in validate_av1_quantization()
582 q->qm_u > GENMASK(3, 0) || in validate_av1_quantization()
583 q->qm_v > GENMASK(3, 0)) in validate_av1_quantization()
584 return -EINVAL; in validate_av1_quantization()
594 if (s->flags > GENMASK(4, 0)) in validate_av1_segmentation()
595 return -EINVAL; in validate_av1_segmentation()
597 for (i = 0; i < ARRAY_SIZE(s->feature_data); i++) { in validate_av1_segmentation()
601 for (j = 0; j < ARRAY_SIZE(s->feature_data[j]); j++) { in validate_av1_segmentation()
605 if (s->feature_data[i][j] < -limit || in validate_av1_segmentation()
606 s->feature_data[i][j] > limit) in validate_av1_segmentation()
607 return -EINVAL; in validate_av1_segmentation()
609 if (s->feature_data[i][j] < 0 || s->feature_data[i][j] > limit) in validate_av1_segmentation()
610 return -EINVAL; in validate_av1_segmentation()
622 if (lf->flags > GENMASK(3, 0)) in validate_av1_loop_filter()
623 return -EINVAL; in validate_av1_loop_filter()
625 for (i = 0; i < ARRAY_SIZE(lf->level); i++) { in validate_av1_loop_filter()
626 if (lf->level[i] > GENMASK(5, 0)) in validate_av1_loop_filter()
627 return -EINVAL; in validate_av1_loop_filter()
630 if (lf->sharpness > GENMASK(2, 0)) in validate_av1_loop_filter()
631 return -EINVAL; in validate_av1_loop_filter()
633 for (i = 0; i < ARRAY_SIZE(lf->ref_deltas); i++) { in validate_av1_loop_filter()
634 if (lf->ref_deltas[i] < -64 || lf->ref_deltas[i] > 63) in validate_av1_loop_filter()
635 return -EINVAL; in validate_av1_loop_filter()
638 for (i = 0; i < ARRAY_SIZE(lf->mode_deltas); i++) { in validate_av1_loop_filter()
639 if (lf->mode_deltas[i] < -64 || lf->mode_deltas[i] > 63) in validate_av1_loop_filter()
640 return -EINVAL; in validate_av1_loop_filter()
650 if (cdef->damping_minus_3 > GENMASK(1, 0) || in validate_av1_cdef()
651 cdef->bits > GENMASK(1, 0)) in validate_av1_cdef()
652 return -EINVAL; in validate_av1_cdef()
654 for (i = 0; i < 1 << cdef->bits; i++) { in validate_av1_cdef()
655 if (cdef->y_pri_strength[i] > GENMASK(3, 0) || in validate_av1_cdef()
656 cdef->y_sec_strength[i] > 4 || in validate_av1_cdef()
657 cdef->uv_pri_strength[i] > GENMASK(3, 0) || in validate_av1_cdef()
658 cdef->uv_sec_strength[i] > 4) in validate_av1_cdef()
659 return -EINVAL; in validate_av1_cdef()
667 if (lr->lr_unit_shift > 3 || lr->lr_uv_shift > 1) in validate_av1_loop_restauration()
668 return -EINVAL; in validate_av1_loop_restauration()
677 if (fg->flags > GENMASK(4, 0)) in validate_av1_film_grain()
678 return -EINVAL; in validate_av1_film_grain()
680 if (fg->film_grain_params_ref_idx > GENMASK(2, 0) || in validate_av1_film_grain()
681 fg->num_y_points > 14 || in validate_av1_film_grain()
682 fg->num_cb_points > 10 || in validate_av1_film_grain()
683 fg->num_cr_points > GENMASK(3, 0) || in validate_av1_film_grain()
684 fg->grain_scaling_minus_8 > GENMASK(1, 0) || in validate_av1_film_grain()
685 fg->ar_coeff_lag > GENMASK(1, 0) || in validate_av1_film_grain()
686 fg->ar_coeff_shift_minus_6 > GENMASK(1, 0) || in validate_av1_film_grain()
687 fg->grain_scale_shift > GENMASK(1, 0)) in validate_av1_film_grain()
688 return -EINVAL; in validate_av1_film_grain()
690 if (!(fg->flags & V4L2_AV1_FILM_GRAIN_FLAG_APPLY_GRAIN)) in validate_av1_film_grain()
693 for (i = 1; i < fg->num_y_points; i++) in validate_av1_film_grain()
694 if (fg->point_y_value[i] <= fg->point_y_value[i - 1]) in validate_av1_film_grain()
695 return -EINVAL; in validate_av1_film_grain()
697 for (i = 1; i < fg->num_cb_points; i++) in validate_av1_film_grain()
698 if (fg->point_cb_value[i] <= fg->point_cb_value[i - 1]) in validate_av1_film_grain()
699 return -EINVAL; in validate_av1_film_grain()
701 for (i = 1; i < fg->num_cr_points; i++) in validate_av1_film_grain()
702 if (fg->point_cr_value[i] <= fg->point_cr_value[i - 1]) in validate_av1_film_grain()
703 return -EINVAL; in validate_av1_film_grain()
712 ret = validate_av1_quantization(&f->quantization); in validate_av1_frame()
715 ret = validate_av1_segmentation(&f->segmentation); in validate_av1_frame()
718 ret = validate_av1_loop_filter(&f->loop_filter); in validate_av1_frame()
721 ret = validate_av1_cdef(&f->cdef); in validate_av1_frame()
724 ret = validate_av1_loop_restauration(&f->loop_restoration); in validate_av1_frame()
728 if (f->flags & in validate_av1_frame()
749 return -EINVAL; in validate_av1_frame()
751 if (f->superres_denom > GENMASK(2, 0) + 9) in validate_av1_frame()
752 return -EINVAL; in validate_av1_frame()
759 if (s->flags & in validate_av1_sequence()
780 return -EINVAL; in validate_av1_sequence()
782 if (s->seq_profile == 1 && s->flags & V4L2_AV1_SEQUENCE_FLAG_MONO_CHROME) in validate_av1_sequence()
783 return -EINVAL; in validate_av1_sequence()
786 if (s->seq_profile > 2) in validate_av1_sequence()
787 return -EINVAL; in validate_av1_sequence()
815 void *p = ptr.p + idx * ctrl->elem_size; in std_validate_compound()
818 switch ((u32)ctrl->type) { in std_validate_compound()
822 switch (p_mpeg2_sequence->chroma_format) { in std_validate_compound()
828 return -EINVAL; in std_validate_compound()
835 switch (p_mpeg2_picture->intra_dc_precision) { in std_validate_compound()
842 return -EINVAL; in std_validate_compound()
845 switch (p_mpeg2_picture->picture_structure) { in std_validate_compound()
851 return -EINVAL; in std_validate_compound()
854 switch (p_mpeg2_picture->picture_coding_type) { in std_validate_compound()
860 return -EINVAL; in std_validate_compound()
870 if (p_fwht_params->version < V4L2_FWHT_VERSION) in std_validate_compound()
871 return -EINVAL; in std_validate_compound()
872 if (!p_fwht_params->width || !p_fwht_params->height) in std_validate_compound()
873 return -EINVAL; in std_validate_compound()
880 if (p_h264_sps->pic_order_cnt_type != 0) { in std_validate_compound()
881 p_h264_sps->log2_max_pic_order_cnt_lsb_minus4 = 0; in std_validate_compound()
882 } else if (p_h264_sps->pic_order_cnt_type != 1) { in std_validate_compound()
883 p_h264_sps->num_ref_frames_in_pic_order_cnt_cycle = 0; in std_validate_compound()
884 p_h264_sps->offset_for_non_ref_pic = 0; in std_validate_compound()
885 p_h264_sps->offset_for_top_to_bottom_field = 0; in std_validate_compound()
886 memset(&p_h264_sps->offset_for_ref_frame, 0, in std_validate_compound()
887 sizeof(p_h264_sps->offset_for_ref_frame)); in std_validate_compound()
891 p_h264_sps->chroma_format_idc = 1; in std_validate_compound()
892 p_h264_sps->bit_depth_luma_minus8 = 0; in std_validate_compound()
893 p_h264_sps->bit_depth_chroma_minus8 = 0; in std_validate_compound()
895 p_h264_sps->flags &= in std_validate_compound()
898 if (p_h264_sps->chroma_format_idc < 3) in std_validate_compound()
899 p_h264_sps->flags &= in std_validate_compound()
903 if (p_h264_sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY) in std_validate_compound()
904 p_h264_sps->flags &= in std_validate_compound()
910 * The H264 specification and well-known parser implementations in std_validate_compound()
911 * use profile-idc values directly, as that is clearer and in std_validate_compound()
914 if (p_h264_sps->profile_idc < 122 && in std_validate_compound()
915 p_h264_sps->chroma_format_idc > 1) in std_validate_compound()
916 return -EINVAL; in std_validate_compound()
918 if (p_h264_sps->profile_idc < 244 && in std_validate_compound()
919 p_h264_sps->chroma_format_idc > 2) in std_validate_compound()
920 return -EINVAL; in std_validate_compound()
921 if (p_h264_sps->chroma_format_idc > 3) in std_validate_compound()
922 return -EINVAL; in std_validate_compound()
924 if (p_h264_sps->bit_depth_luma_minus8 > 6) in std_validate_compound()
925 return -EINVAL; in std_validate_compound()
926 if (p_h264_sps->bit_depth_chroma_minus8 > 6) in std_validate_compound()
927 return -EINVAL; in std_validate_compound()
928 if (p_h264_sps->log2_max_frame_num_minus4 > 12) in std_validate_compound()
929 return -EINVAL; in std_validate_compound()
930 if (p_h264_sps->pic_order_cnt_type > 2) in std_validate_compound()
931 return -EINVAL; in std_validate_compound()
932 if (p_h264_sps->log2_max_pic_order_cnt_lsb_minus4 > 12) in std_validate_compound()
933 return -EINVAL; in std_validate_compound()
934 if (p_h264_sps->max_num_ref_frames > V4L2_H264_REF_LIST_LEN) in std_validate_compound()
935 return -EINVAL; in std_validate_compound()
941 if (p_h264_pps->num_slice_groups_minus1 > 7) in std_validate_compound()
942 return -EINVAL; in std_validate_compound()
943 if (p_h264_pps->num_ref_idx_l0_default_active_minus1 > in std_validate_compound()
944 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
945 return -EINVAL; in std_validate_compound()
946 if (p_h264_pps->num_ref_idx_l1_default_active_minus1 > in std_validate_compound()
947 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
948 return -EINVAL; in std_validate_compound()
949 if (p_h264_pps->weighted_bipred_idc > 2) in std_validate_compound()
950 return -EINVAL; in std_validate_compound()
953 * -(26 + QpBdOffset_y) to +25, inclusive, in std_validate_compound()
956 if (p_h264_pps->pic_init_qp_minus26 < -62 || in std_validate_compound()
957 p_h264_pps->pic_init_qp_minus26 > 25) in std_validate_compound()
958 return -EINVAL; in std_validate_compound()
959 if (p_h264_pps->pic_init_qs_minus26 < -26 || in std_validate_compound()
960 p_h264_pps->pic_init_qs_minus26 > 25) in std_validate_compound()
961 return -EINVAL; in std_validate_compound()
962 if (p_h264_pps->chroma_qp_index_offset < -12 || in std_validate_compound()
963 p_h264_pps->chroma_qp_index_offset > 12) in std_validate_compound()
964 return -EINVAL; in std_validate_compound()
965 if (p_h264_pps->second_chroma_qp_index_offset < -12 || in std_validate_compound()
966 p_h264_pps->second_chroma_qp_index_offset > 12) in std_validate_compound()
967 return -EINVAL; in std_validate_compound()
976 if (p_h264_pred_weights->luma_log2_weight_denom > 7) in std_validate_compound()
977 return -EINVAL; in std_validate_compound()
978 if (p_h264_pred_weights->chroma_log2_weight_denom > 7) in std_validate_compound()
979 return -EINVAL; in std_validate_compound()
985 if (p_h264_slice_params->slice_type != V4L2_H264_SLICE_TYPE_B) in std_validate_compound()
986 p_h264_slice_params->flags &= in std_validate_compound()
989 if (p_h264_slice_params->colour_plane_id > 2) in std_validate_compound()
990 return -EINVAL; in std_validate_compound()
991 if (p_h264_slice_params->cabac_init_idc > 2) in std_validate_compound()
992 return -EINVAL; in std_validate_compound()
993 if (p_h264_slice_params->disable_deblocking_filter_idc > 2) in std_validate_compound()
994 return -EINVAL; in std_validate_compound()
995 if (p_h264_slice_params->slice_alpha_c0_offset_div2 < -6 || in std_validate_compound()
996 p_h264_slice_params->slice_alpha_c0_offset_div2 > 6) in std_validate_compound()
997 return -EINVAL; in std_validate_compound()
998 if (p_h264_slice_params->slice_beta_offset_div2 < -6 || in std_validate_compound()
999 p_h264_slice_params->slice_beta_offset_div2 > 6) in std_validate_compound()
1000 return -EINVAL; in std_validate_compound()
1002 if (p_h264_slice_params->slice_type == V4L2_H264_SLICE_TYPE_I || in std_validate_compound()
1003 p_h264_slice_params->slice_type == V4L2_H264_SLICE_TYPE_SI) in std_validate_compound()
1004 p_h264_slice_params->num_ref_idx_l0_active_minus1 = 0; in std_validate_compound()
1005 if (p_h264_slice_params->slice_type != V4L2_H264_SLICE_TYPE_B) in std_validate_compound()
1006 p_h264_slice_params->num_ref_idx_l1_active_minus1 = 0; in std_validate_compound()
1008 if (p_h264_slice_params->num_ref_idx_l0_active_minus1 > in std_validate_compound()
1009 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
1010 return -EINVAL; in std_validate_compound()
1011 if (p_h264_slice_params->num_ref_idx_l1_active_minus1 > in std_validate_compound()
1012 (V4L2_H264_REF_LIST_LEN - 1)) in std_validate_compound()
1013 return -EINVAL; in std_validate_compound()
1020 if (p_h264_dec_params->nal_ref_idc > 3) in std_validate_compound()
1021 return -EINVAL; in std_validate_compound()
1024 &p_h264_dec_params->dpb[i]; in std_validate_compound()
1034 switch (p_vp8_frame->num_dct_parts) { in std_validate_compound()
1041 return -EINVAL; in std_validate_compound()
1043 zero_padding(p_vp8_frame->segment); in std_validate_compound()
1044 zero_padding(p_vp8_frame->lf); in std_validate_compound()
1045 zero_padding(p_vp8_frame->quant); in std_validate_compound()
1046 zero_padding(p_vp8_frame->entropy); in std_validate_compound()
1047 zero_padding(p_vp8_frame->coder_state); in std_validate_compound()
1053 if (!(p_hevc_sps->flags & V4L2_HEVC_SPS_FLAG_PCM_ENABLED)) { in std_validate_compound()
1054 p_hevc_sps->pcm_sample_bit_depth_luma_minus1 = 0; in std_validate_compound()
1055 p_hevc_sps->pcm_sample_bit_depth_chroma_minus1 = 0; in std_validate_compound()
1056 p_hevc_sps->log2_min_pcm_luma_coding_block_size_minus3 = 0; in std_validate_compound()
1057 p_hevc_sps->log2_diff_max_min_pcm_luma_coding_block_size = 0; in std_validate_compound()
1060 if (!(p_hevc_sps->flags & in std_validate_compound()
1062 p_hevc_sps->num_long_term_ref_pics_sps = 0; in std_validate_compound()
1068 if (!(p_hevc_pps->flags & in std_validate_compound()
1070 p_hevc_pps->diff_cu_qp_delta_depth = 0; in std_validate_compound()
1072 if (!(p_hevc_pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED)) { in std_validate_compound()
1073 p_hevc_pps->num_tile_columns_minus1 = 0; in std_validate_compound()
1074 p_hevc_pps->num_tile_rows_minus1 = 0; in std_validate_compound()
1075 memset(&p_hevc_pps->column_width_minus1, 0, in std_validate_compound()
1076 sizeof(p_hevc_pps->column_width_minus1)); in std_validate_compound()
1077 memset(&p_hevc_pps->row_height_minus1, 0, in std_validate_compound()
1078 sizeof(p_hevc_pps->row_height_minus1)); in std_validate_compound()
1080 p_hevc_pps->flags &= in std_validate_compound()
1084 if (p_hevc_pps->flags & in std_validate_compound()
1086 p_hevc_pps->pps_beta_offset_div2 = 0; in std_validate_compound()
1087 p_hevc_pps->pps_tc_offset_div2 = 0; in std_validate_compound()
1094 if (p_hevc_decode_params->num_active_dpb_entries > in std_validate_compound()
1096 return -EINVAL; in std_validate_compound()
1109 if (p_hdr10_mastering->display_primaries_x[i] < in std_validate_compound()
1111 p_hdr10_mastering->display_primaries_x[i] > in std_validate_compound()
1113 p_hdr10_mastering->display_primaries_y[i] < in std_validate_compound()
1115 p_hdr10_mastering->display_primaries_y[i] > in std_validate_compound()
1117 return -EINVAL; in std_validate_compound()
1120 if (p_hdr10_mastering->white_point_x < in std_validate_compound()
1122 p_hdr10_mastering->white_point_x > in std_validate_compound()
1124 p_hdr10_mastering->white_point_y < in std_validate_compound()
1126 p_hdr10_mastering->white_point_y > in std_validate_compound()
1128 return -EINVAL; in std_validate_compound()
1130 if (p_hdr10_mastering->max_display_mastering_luminance < in std_validate_compound()
1132 p_hdr10_mastering->max_display_mastering_luminance > in std_validate_compound()
1134 p_hdr10_mastering->min_display_mastering_luminance < in std_validate_compound()
1136 p_hdr10_mastering->min_display_mastering_luminance > in std_validate_compound()
1138 return -EINVAL; in std_validate_compound()
1140 /* The following restriction comes from ITU-T Rec. H.265 spec */ in std_validate_compound()
1141 if (p_hdr10_mastering->max_display_mastering_luminance == in std_validate_compound()
1143 p_hdr10_mastering->min_display_mastering_luminance == in std_validate_compound()
1145 return -EINVAL; in std_validate_compound()
1168 if (!area->width || !area->height) in std_validate_compound()
1169 return -EINVAL; in std_validate_compound()
1173 return -EINVAL; in std_validate_compound()
1186 switch ((u32)ctrl->type) { in std_validate_elem()
1195 if (ctrl->maximum >= 0 && val >= ctrl->maximum - (s64)(ctrl->step / 2)) in std_validate_elem()
1196 val = ctrl->maximum; in std_validate_elem()
1198 val += (s64)(ctrl->step / 2); in std_validate_elem()
1199 val = clamp_t(s64, val, ctrl->minimum, ctrl->maximum); in std_validate_elem()
1200 offset = val - ctrl->minimum; in std_validate_elem()
1201 do_div(offset, ctrl->step); in std_validate_elem()
1202 ptr.p_s64[idx] = ctrl->minimum + offset * ctrl->step; in std_validate_elem()
1217 if (ptr.p_s32[idx] < ctrl->minimum || ptr.p_s32[idx] > ctrl->maximum) in std_validate_elem()
1218 return -ERANGE; in std_validate_elem()
1220 (ctrl->menu_skip_mask & BIT_ULL(ptr.p_s32[idx]))) in std_validate_elem()
1221 return -EINVAL; in std_validate_elem()
1222 if (ctrl->type == V4L2_CTRL_TYPE_MENU && in std_validate_elem()
1223 ctrl->qmenu[ptr.p_s32[idx]][0] == '\0') in std_validate_elem()
1224 return -EINVAL; in std_validate_elem()
1228 ptr.p_s32[idx] &= ctrl->maximum; in std_validate_elem()
1237 idx *= ctrl->elem_size; in std_validate_elem()
1239 if (len < ctrl->minimum) in std_validate_elem()
1240 return -ERANGE; in std_validate_elem()
1241 if ((len - (u32)ctrl->minimum) % (u32)ctrl->step) in std_validate_elem()
1242 return -ERANGE; in std_validate_elem()
1256 switch ((u32)ctrl->type) { in v4l2_ctrl_type_op_validate()
1258 if (ctrl->maximum == 0xff && ctrl->minimum == 0 && ctrl->step == 1) in v4l2_ctrl_type_op_validate()
1262 if (ctrl->maximum == 0xffff && ctrl->minimum == 0 && ctrl->step == 1) in v4l2_ctrl_type_op_validate()
1266 if (ctrl->maximum == 0xffffffff && ctrl->minimum == 0 && ctrl->step == 1) in v4l2_ctrl_type_op_validate()
1272 memset(ptr.p_s32, 0, ctrl->new_elems * sizeof(s32)); in v4l2_ctrl_type_op_validate()
1276 for (i = 0; !ret && i < ctrl->new_elems; i++) in v4l2_ctrl_type_op_validate()
1294 ctrl->call_notify = 0; in v4l2_ctrl_notify()
1297 if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify)) in v4l2_ctrl_notify()
1299 ctrl->handler->notify = notify; in v4l2_ctrl_notify()
1300 ctrl->handler->notify_priv = priv; in v4l2_ctrl_notify()
1301 ctrl->call_notify = 1; in v4l2_ctrl_notify()
1312 memcpy(to.p, from.p_const, elems * ctrl->elem_size); in ptr_to_ptr()
1324 changed = ctrl->has_changed; in new_to_cur()
1326 if (ctrl->is_dyn_array) in new_to_cur()
1327 ctrl->elems = ctrl->new_elems; in new_to_cur()
1328 ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur, ctrl->elems); in new_to_cur()
1333 ctrl->flags &= in new_to_cur()
1335 if (!is_cur_manual(ctrl->cluster[0])) { in new_to_cur()
1336 ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; in new_to_cur()
1337 if (ctrl->cluster[0]->has_volatiles) in new_to_cur()
1338 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in new_to_cur()
1345 if (!ctrl->is_new) in new_to_cur()
1349 if (ctrl->call_notify && changed && ctrl->handler->notify) in new_to_cur()
1350 ctrl->handler->notify(ctrl, ctrl->handler->notify_priv); in new_to_cur()
1359 if (ctrl->is_dyn_array) in cur_to_new()
1360 ctrl->new_elems = ctrl->elems; in cur_to_new()
1361 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new, ctrl->new_elems); in cur_to_new()
1368 if (elems == ref->p_req_array_alloc_elems) in req_alloc_array()
1370 if (ref->ctrl->is_dyn_array && in req_alloc_array()
1371 elems < ref->p_req_array_alloc_elems) in req_alloc_array()
1374 tmp = kvmalloc(elems * ref->ctrl->elem_size, GFP_KERNEL); in req_alloc_array()
1377 ref->p_req_array_enomem = true; in req_alloc_array()
1380 ref->p_req_array_enomem = false; in req_alloc_array()
1381 kvfree(ref->p_req.p); in req_alloc_array()
1382 ref->p_req.p = tmp; in req_alloc_array()
1383 ref->p_req_array_alloc_elems = elems; in req_alloc_array()
1395 ctrl = ref->ctrl; in new_to_req()
1396 if (ctrl->is_array && !req_alloc_array(ref, ctrl->new_elems)) in new_to_req()
1399 ref->p_req_elems = ctrl->new_elems; in new_to_req()
1400 ptr_to_ptr(ctrl, ctrl->p_new, ref->p_req, ref->p_req_elems); in new_to_req()
1401 ref->p_req_valid = true; in new_to_req()
1412 ctrl = ref->ctrl; in cur_to_req()
1413 if (ctrl->is_array && !req_alloc_array(ref, ctrl->elems)) in cur_to_req()
1416 ref->p_req_elems = ctrl->elems; in cur_to_req()
1417 ptr_to_ptr(ctrl, ctrl->p_cur, ref->p_req, ctrl->elems); in cur_to_req()
1418 ref->p_req_valid = true; in cur_to_req()
1429 ctrl = ref->ctrl; in req_to_new()
1435 if (!ref->p_req_valid) { in req_to_new()
1436 if (ctrl->is_dyn_array) in req_to_new()
1437 ctrl->new_elems = ctrl->elems; in req_to_new()
1438 ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new, ctrl->new_elems); in req_to_new()
1443 if (!ctrl->is_array) { in req_to_new()
1444 ptr_to_ptr(ctrl, ref->p_req, ctrl->p_new, ctrl->new_elems); in req_to_new()
1449 if (WARN_ON(!ref->p_req_array_alloc_elems)) in req_to_new()
1450 return -ENOMEM; in req_to_new()
1452 if (!ctrl->is_dyn_array && in req_to_new()
1453 ref->p_req_elems != ctrl->p_array_alloc_elems) in req_to_new()
1454 return -ENOMEM; in req_to_new()
1458 * elements in ctrl->p_array. If so, attempt to realloc ctrl->p_array. in req_to_new()
1463 if (ref->p_req_elems > ctrl->p_array_alloc_elems) { in req_to_new()
1464 unsigned int sz = ref->p_req_elems * ctrl->elem_size; in req_to_new()
1465 void *old = ctrl->p_array; in req_to_new()
1469 return -ENOMEM; in req_to_new()
1470 memcpy(tmp, ctrl->p_new.p, ctrl->elems * ctrl->elem_size); in req_to_new()
1471 memcpy(tmp + sz, ctrl->p_cur.p, ctrl->elems * ctrl->elem_size); in req_to_new()
1472 ctrl->p_new.p = tmp; in req_to_new()
1473 ctrl->p_cur.p = tmp + sz; in req_to_new()
1474 ctrl->p_array = tmp; in req_to_new()
1475 ctrl->p_array_alloc_elems = ref->p_req_elems; in req_to_new()
1479 ctrl->new_elems = ref->p_req_elems; in req_to_new()
1480 ptr_to_ptr(ctrl, ref->p_req, ctrl->p_new, ctrl->new_elems); in req_to_new()
1491 return -ERANGE; in check_range()
1499 return -ERANGE; in check_range()
1503 return -ERANGE; in check_range()
1508 return -ERANGE; in check_range()
1512 return -EINVAL; in check_range()
1516 return -ERANGE; in check_range()
1526 if (hdl->error == 0) in handler_set_err()
1527 hdl->error = err; in handler_set_err()
1536 mutex_init(&hdl->_lock); in v4l2_ctrl_handler_init_class()
1537 hdl->lock = &hdl->_lock; in v4l2_ctrl_handler_init_class()
1538 lockdep_set_class_and_name(hdl->lock, key, name); in v4l2_ctrl_handler_init_class()
1539 INIT_LIST_HEAD(&hdl->ctrls); in v4l2_ctrl_handler_init_class()
1540 INIT_LIST_HEAD(&hdl->ctrl_refs); in v4l2_ctrl_handler_init_class()
1541 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8; in v4l2_ctrl_handler_init_class()
1542 hdl->buckets = kvcalloc(hdl->nr_of_buckets, sizeof(hdl->buckets[0]), in v4l2_ctrl_handler_init_class()
1544 hdl->error = hdl->buckets ? 0 : -ENOMEM; in v4l2_ctrl_handler_init_class()
1546 return hdl->error; in v4l2_ctrl_handler_init_class()
1557 if (hdl == NULL || hdl->buckets == NULL) in v4l2_ctrl_handler_free()
1562 mutex_lock(hdl->lock); in v4l2_ctrl_handler_free()
1564 list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) { in v4l2_ctrl_handler_free()
1565 list_del(&ref->node); in v4l2_ctrl_handler_free()
1566 if (ref->p_req_array_alloc_elems) in v4l2_ctrl_handler_free()
1567 kvfree(ref->p_req.p); in v4l2_ctrl_handler_free()
1571 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) { in v4l2_ctrl_handler_free()
1572 list_del(&ctrl->node); in v4l2_ctrl_handler_free()
1573 list_for_each_entry_safe(sev, next_sev, &ctrl->ev_subs, node) in v4l2_ctrl_handler_free()
1574 list_del(&sev->node); in v4l2_ctrl_handler_free()
1575 kvfree(ctrl->p_array); in v4l2_ctrl_handler_free()
1578 kvfree(hdl->buckets); in v4l2_ctrl_handler_free()
1579 hdl->buckets = NULL; in v4l2_ctrl_handler_free()
1580 hdl->cached = NULL; in v4l2_ctrl_handler_free()
1581 hdl->error = 0; in v4l2_ctrl_handler_free()
1582 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_free()
1583 mutex_destroy(&hdl->_lock); in v4l2_ctrl_handler_free()
1591 We just find the n-th private user control. It's O(N), but that should not
1598 id -= V4L2_CID_PRIVATE_BASE; in find_private_ref()
1599 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in find_private_ref()
1602 if (V4L2_CTRL_ID2WHICH(ref->ctrl->id) == V4L2_CTRL_CLASS_USER && in find_private_ref()
1603 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) { in find_private_ref()
1604 if (!ref->ctrl->is_int) in find_private_ref()
1608 id--; in find_private_ref()
1622 /* Old-style private controls need special handling */ in find_ref()
1625 bucket = id % hdl->nr_of_buckets; in find_ref()
1628 if (hdl->cached && hdl->cached->ctrl->id == id) in find_ref()
1629 return hdl->cached; in find_ref()
1632 ref = hdl->buckets ? hdl->buckets[bucket] : NULL; in find_ref()
1633 while (ref && ref->ctrl->id != id) in find_ref()
1634 ref = ref->next; in find_ref()
1637 hdl->cached = ref; /* cache it! */ in find_ref()
1647 mutex_lock(hdl->lock); in find_ref_lock()
1649 mutex_unlock(hdl->lock); in find_ref_lock()
1659 return ref ? ref->ctrl : NULL; in v4l2_ctrl_find()
1671 u32 id = ctrl->id; in handler_new_ref()
1673 int bucket = id % hdl->nr_of_buckets; /* which bucket to use */ in handler_new_ref()
1683 if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES && in handler_new_ref()
1686 return hdl->error; in handler_new_ref()
1688 if (hdl->error) in handler_new_ref()
1689 return hdl->error; in handler_new_ref()
1691 if (allocate_req && !ctrl->is_array) in handler_new_ref()
1692 size_extra_req = ctrl->elems * ctrl->elem_size; in handler_new_ref()
1695 return handler_set_err(hdl, -ENOMEM); in handler_new_ref()
1696 new_ref->ctrl = ctrl; in handler_new_ref()
1697 new_ref->from_other_dev = from_other_dev; in handler_new_ref()
1699 new_ref->p_req.p = &new_ref[1]; in handler_new_ref()
1701 INIT_LIST_HEAD(&new_ref->node); in handler_new_ref()
1703 mutex_lock(hdl->lock); in handler_new_ref()
1709 if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) { in handler_new_ref()
1710 list_add_tail(&new_ref->node, &hdl->ctrl_refs); in handler_new_ref()
1715 list_for_each_entry(ref, &hdl->ctrl_refs, node) { in handler_new_ref()
1716 if (ref->ctrl->id < id) in handler_new_ref()
1719 if (ref->ctrl->id == id) { in handler_new_ref()
1723 list_add(&new_ref->node, ref->node.prev); in handler_new_ref()
1729 new_ref->next = hdl->buckets[bucket]; in handler_new_ref()
1730 hdl->buckets[bucket] = new_ref; in handler_new_ref()
1733 if (ctrl->handler == hdl) { in handler_new_ref()
1735 * new_ref->ctrl is basically a cluster array with one in handler_new_ref()
1739 ctrl->cluster = &new_ref->ctrl; in handler_new_ref()
1740 ctrl->ncontrols = 1; in handler_new_ref()
1744 mutex_unlock(hdl->lock); in handler_new_ref()
1768 if (hdl->error) in v4l2_ctrl_new()
1882 handler_set_err(hdl, -ERANGE); in v4l2_ctrl_new()
1893 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new()
1898 * For now only support this for one-dimensional arrays only. in v4l2_ctrl_new()
1904 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new()
1929 handler_set_err(hdl, -ENOMEM); in v4l2_ctrl_new()
1933 INIT_LIST_HEAD(&ctrl->node); in v4l2_ctrl_new()
1934 INIT_LIST_HEAD(&ctrl->ev_subs); in v4l2_ctrl_new()
1935 ctrl->handler = hdl; in v4l2_ctrl_new()
1936 ctrl->ops = ops; in v4l2_ctrl_new()
1937 ctrl->type_ops = type_ops ? type_ops : &std_type_ops; in v4l2_ctrl_new()
1938 ctrl->id = id; in v4l2_ctrl_new()
1939 ctrl->name = name; in v4l2_ctrl_new()
1940 ctrl->type = type; in v4l2_ctrl_new()
1941 ctrl->flags = flags; in v4l2_ctrl_new()
1942 ctrl->minimum = min; in v4l2_ctrl_new()
1943 ctrl->maximum = max; in v4l2_ctrl_new()
1944 ctrl->step = step; in v4l2_ctrl_new()
1945 ctrl->default_value = def; in v4l2_ctrl_new()
1946 ctrl->is_string = !is_array && type == V4L2_CTRL_TYPE_STRING; in v4l2_ctrl_new()
1947 ctrl->is_ptr = is_array || type >= V4L2_CTRL_COMPOUND_TYPES || ctrl->is_string; in v4l2_ctrl_new()
1948 ctrl->is_int = !ctrl->is_ptr && type != V4L2_CTRL_TYPE_INTEGER64; in v4l2_ctrl_new()
1949 ctrl->is_array = is_array; in v4l2_ctrl_new()
1950 ctrl->is_dyn_array = !!(flags & V4L2_CTRL_FLAG_DYNAMIC_ARRAY); in v4l2_ctrl_new()
1951 ctrl->elems = elems; in v4l2_ctrl_new()
1952 ctrl->new_elems = elems; in v4l2_ctrl_new()
1953 ctrl->nr_of_dims = nr_of_dims; in v4l2_ctrl_new()
1955 memcpy(ctrl->dims, dims, nr_of_dims * sizeof(dims[0])); in v4l2_ctrl_new()
1956 ctrl->elem_size = elem_size; in v4l2_ctrl_new()
1958 ctrl->qmenu = qmenu; in v4l2_ctrl_new()
1960 ctrl->qmenu_int = qmenu_int; in v4l2_ctrl_new()
1961 ctrl->priv = priv; in v4l2_ctrl_new()
1962 ctrl->cur.val = ctrl->val = def; in v4l2_ctrl_new()
1965 if (ctrl->is_array) { in v4l2_ctrl_new()
1966 ctrl->p_array_alloc_elems = elems; in v4l2_ctrl_new()
1967 ctrl->p_array = kvzalloc(2 * elems * elem_size, GFP_KERNEL); in v4l2_ctrl_new()
1968 if (!ctrl->p_array) { in v4l2_ctrl_new()
1972 data = ctrl->p_array; in v4l2_ctrl_new()
1975 if (!ctrl->is_int) { in v4l2_ctrl_new()
1976 ctrl->p_new.p = data; in v4l2_ctrl_new()
1977 ctrl->p_cur.p = data + tot_ctrl_size; in v4l2_ctrl_new()
1979 ctrl->p_new.p = &ctrl->val; in v4l2_ctrl_new()
1980 ctrl->p_cur.p = &ctrl->cur.val; in v4l2_ctrl_new()
1984 if (ctrl->is_array) in v4l2_ctrl_new()
1985 ctrl->p_def.p = &ctrl[1]; in v4l2_ctrl_new()
1987 ctrl->p_def.p = ctrl->p_cur.p + tot_ctrl_size; in v4l2_ctrl_new()
1988 memcpy(ctrl->p_def.p, p_def.p_const, elem_size); in v4l2_ctrl_new()
1991 ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); in v4l2_ctrl_new()
1995 kvfree(ctrl->p_array); in v4l2_ctrl_new()
1999 mutex_lock(hdl->lock); in v4l2_ctrl_new()
2000 list_add_tail(&ctrl->node, &hdl->ctrls); in v4l2_ctrl_new()
2001 mutex_unlock(hdl->lock); in v4l2_ctrl_new()
2010 const char *name = cfg->name; in v4l2_ctrl_new_custom()
2011 const char * const *qmenu = cfg->qmenu; in v4l2_ctrl_new_custom()
2012 const s64 *qmenu_int = cfg->qmenu_int; in v4l2_ctrl_new_custom()
2013 enum v4l2_ctrl_type type = cfg->type; in v4l2_ctrl_new_custom()
2014 u32 flags = cfg->flags; in v4l2_ctrl_new_custom()
2015 s64 min = cfg->min; in v4l2_ctrl_new_custom()
2016 s64 max = cfg->max; in v4l2_ctrl_new_custom()
2017 u64 step = cfg->step; in v4l2_ctrl_new_custom()
2018 s64 def = cfg->def; in v4l2_ctrl_new_custom()
2021 v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step, in v4l2_ctrl_new_custom()
2029 WARN_ON(cfg->menu_skip_mask); in v4l2_ctrl_new_custom()
2031 qmenu = v4l2_ctrl_get_menu(cfg->id); in v4l2_ctrl_new_custom()
2033 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_custom()
2037 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->type_ops, cfg->id, name, in v4l2_ctrl_new_custom()
2039 is_menu ? cfg->menu_skip_mask : step, def, in v4l2_ctrl_new_custom()
2040 cfg->dims, cfg->elem_size, in v4l2_ctrl_new_custom()
2041 flags, qmenu, qmenu_int, cfg->p_def, priv); in v4l2_ctrl_new_custom()
2043 ctrl->is_private = cfg->is_private; in v4l2_ctrl_new_custom()
2048 /* Helper function for standard non-menu controls */
2061 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std()
2094 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu()
2120 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2126 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_menu_items()
2148 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_std_compound()
2172 handler_set_err(hdl, -EINVAL); in v4l2_ctrl_new_int_menu()
2193 if (hdl->error) in v4l2_ctrl_add_handler()
2194 return hdl->error; in v4l2_ctrl_add_handler()
2195 mutex_lock(add->lock); in v4l2_ctrl_add_handler()
2196 list_for_each_entry(ref, &add->ctrl_refs, node) { in v4l2_ctrl_add_handler()
2197 struct v4l2_ctrl *ctrl = ref->ctrl; in v4l2_ctrl_add_handler()
2199 /* Skip handler-private controls. */ in v4l2_ctrl_add_handler()
2200 if (ctrl->is_private) in v4l2_ctrl_add_handler()
2203 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) in v4l2_ctrl_add_handler()
2212 mutex_unlock(add->lock); in v4l2_ctrl_add_handler()
2219 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_TX) in v4l2_ctrl_radio_filter()
2221 if (V4L2_CTRL_ID2WHICH(ctrl->id) == V4L2_CTRL_CLASS_FM_RX) in v4l2_ctrl_radio_filter()
2223 switch (ctrl->id) { in v4l2_ctrl_radio_filter()
2244 /* The first control is the master control and it must not be NULL */ in v4l2_ctrl_cluster()
2250 controls[i]->cluster = controls; in v4l2_ctrl_cluster()
2251 controls[i]->ncontrols = ncontrols; in v4l2_ctrl_cluster()
2252 if (controls[i]->flags & V4L2_CTRL_FLAG_VOLATILE) in v4l2_ctrl_cluster()
2256 controls[0]->has_volatiles = has_volatiles; in v4l2_ctrl_cluster()
2263 struct v4l2_ctrl *master = controls[0]; in v4l2_ctrl_auto_cluster() local
2269 WARN_ON(manual_val < master->minimum || manual_val > master->maximum); in v4l2_ctrl_auto_cluster()
2270 WARN_ON(set_volatile && !has_op(master, g_volatile_ctrl)); in v4l2_ctrl_auto_cluster()
2271 master->is_auto = true; in v4l2_ctrl_auto_cluster()
2272 master->has_volatiles = set_volatile; in v4l2_ctrl_auto_cluster()
2273 master->manual_mode_value = manual_val; in v4l2_ctrl_auto_cluster()
2274 master->flags |= V4L2_CTRL_FLAG_UPDATE; in v4l2_ctrl_auto_cluster()
2276 if (!is_cur_manual(master)) in v4l2_ctrl_auto_cluster()
2282 controls[i]->flags |= flag; in v4l2_ctrl_auto_cluster()
2290 void update_from_auto_cluster(struct v4l2_ctrl *master) in update_from_auto_cluster() argument
2294 for (i = 1; i < master->ncontrols; i++) in update_from_auto_cluster()
2295 cur_to_new(master->cluster[i]); in update_from_auto_cluster()
2296 if (!call_op(master, g_volatile_ctrl)) in update_from_auto_cluster()
2297 for (i = 1; i < master->ncontrols; i++) in update_from_auto_cluster()
2298 if (master->cluster[i]) in update_from_auto_cluster()
2299 master->cluster[i]->is_new = 1; in update_from_auto_cluster()
2303 * Return non-zero if one or more of the controls in the cluster has a new
2306 static int cluster_changed(struct v4l2_ctrl *master) in cluster_changed() argument
2311 for (i = 0; i < master->ncontrols; i++) { in cluster_changed()
2312 struct v4l2_ctrl *ctrl = master->cluster[i]; in cluster_changed()
2318 if (ctrl->flags & V4L2_CTRL_FLAG_EXECUTE_ON_WRITE) { in cluster_changed()
2327 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) { in cluster_changed()
2328 ctrl->has_changed = false; in cluster_changed()
2332 if (ctrl->elems != ctrl->new_elems) in cluster_changed()
2335 ctrl_changed = !ctrl->type_ops->equal(ctrl, in cluster_changed()
2336 ctrl->p_cur, ctrl->p_new); in cluster_changed()
2337 ctrl->has_changed = ctrl_changed; in cluster_changed()
2338 changed |= ctrl->has_changed; in cluster_changed()
2346 * Must be called with ctrl->handler->lock held.
2348 int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master, in try_or_set_cluster() argument
2361 for (i = 0; i < master->ncontrols; i++) { in try_or_set_cluster()
2362 struct v4l2_ctrl *ctrl = master->cluster[i]; in try_or_set_cluster()
2367 if (!ctrl->is_new) { in try_or_set_cluster()
2375 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)) in try_or_set_cluster()
2376 return -EBUSY; in try_or_set_cluster()
2379 ret = call_op(master, try_ctrl); in try_or_set_cluster()
2382 if (ret || !set || !cluster_changed(master)) in try_or_set_cluster()
2384 ret = call_op(master, s_ctrl); in try_or_set_cluster()
2389 update_flag = is_cur_manual(master) != is_new_manual(master); in try_or_set_cluster()
2391 for (i = 0; i < master->ncontrols; i++) { in try_or_set_cluster()
2394 * contains volatile controls, then all non-master controls in try_or_set_cluster()
2399 if (i && update_flag && is_new_manual(master) && in try_or_set_cluster()
2400 master->has_volatiles && master->cluster[i]) in try_or_set_cluster()
2401 master->cluster[i]->has_changed = true; in try_or_set_cluster()
2403 new_to_cur(fh, master->cluster[i], ch_flags | in try_or_set_cluster()
2421 old = test_and_set_bit(4, &ctrl->flags); in v4l2_ctrl_activate()
2424 old = test_and_clear_bit(4, &ctrl->flags); in v4l2_ctrl_activate()
2437 lockdep_assert_held(ctrl->handler->lock); in __v4l2_ctrl_grab()
2441 old = test_and_set_bit(1, &ctrl->flags); in __v4l2_ctrl_grab()
2444 old = test_and_clear_bit(1, &ctrl->flags); in __v4l2_ctrl_grab()
2459 lockdep_assert_held(hdl->lock); in __v4l2_ctrl_handler_setup()
2461 list_for_each_entry(ctrl, &hdl->ctrls, node) in __v4l2_ctrl_handler_setup()
2462 ctrl->done = false; in __v4l2_ctrl_handler_setup()
2464 list_for_each_entry(ctrl, &hdl->ctrls, node) { in __v4l2_ctrl_handler_setup()
2465 struct v4l2_ctrl *master = ctrl->cluster[0]; in __v4l2_ctrl_handler_setup() local
2469 /* Skip button controls and read-only controls. */ in __v4l2_ctrl_handler_setup()
2470 if (ctrl->done || ctrl->type == V4L2_CTRL_TYPE_BUTTON || in __v4l2_ctrl_handler_setup()
2471 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)) in __v4l2_ctrl_handler_setup()
2474 for (i = 0; i < master->ncontrols; i++) { in __v4l2_ctrl_handler_setup()
2475 if (master->cluster[i]) { in __v4l2_ctrl_handler_setup()
2476 cur_to_new(master->cluster[i]); in __v4l2_ctrl_handler_setup()
2477 master->cluster[i]->is_new = 1; in __v4l2_ctrl_handler_setup()
2478 master->cluster[i]->done = true; in __v4l2_ctrl_handler_setup()
2481 ret = call_op(master, s_ctrl); in __v4l2_ctrl_handler_setup()
2497 mutex_lock(hdl->lock); in v4l2_ctrl_handler_setup()
2499 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_setup()
2509 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY)) in log_ctrl()
2511 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) in log_ctrl()
2514 pr_info("%s%s%s: ", prefix, colon, ctrl->name); in log_ctrl()
2516 ctrl->type_ops->log(ctrl); in log_ctrl()
2518 if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE | in log_ctrl()
2521 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) in log_ctrl()
2523 if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED) in log_ctrl()
2525 if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) in log_ctrl()
2544 if (len && prefix[len - 1] != ' ') in v4l2_ctrl_handler_log_status()
2546 mutex_lock(hdl->lock); in v4l2_ctrl_handler_log_status()
2547 list_for_each_entry(ctrl, &hdl->ctrls, node) in v4l2_ctrl_handler_log_status()
2548 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED)) in v4l2_ctrl_handler_log_status()
2550 mutex_unlock(hdl->lock); in v4l2_ctrl_handler_log_status()
2558 if (p->orientation != V4L2_FWNODE_PROPERTY_UNSET) { in v4l2_ctrl_new_fwnode_properties()
2561 switch (p->orientation) { in v4l2_ctrl_new_fwnode_properties()
2572 return -EINVAL; in v4l2_ctrl_new_fwnode_properties()
2578 return hdl->error; in v4l2_ctrl_new_fwnode_properties()
2581 if (p->rotation != V4L2_FWNODE_PROPERTY_UNSET) { in v4l2_ctrl_new_fwnode_properties()
2584 p->rotation, p->rotation, 1, in v4l2_ctrl_new_fwnode_properties()
2585 p->rotation)) in v4l2_ctrl_new_fwnode_properties()
2586 return hdl->error; in v4l2_ctrl_new_fwnode_properties()
2589 return hdl->error; in v4l2_ctrl_new_fwnode_properties()