From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 432A119D088 for ; Thu, 14 Nov 2024 19:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611448; cv=none; b=tHbrK7TOESI9cM0tk3qYRcqxsiEmuL3wRkChEf5vxCPpsjA0p9BdFMNs+BKKZj9KbaNyhtXpDs3nZ3B9CyZMr3OreZjVVAP13/+xzjcEg9H0+nldQdfaMuTufHpOppW1mtBirxAX8TqIe48cbWILAvq9s0P10W99DEZ9GgDcebo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611448; c=relaxed/simple; bh=SC8L6uuUf+/qQ8Ex1Sbi6Yirs91l4EQxu1/mHdLrT3c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d+cE13oBm4zlt9h7Kzg+QJtv/s+814ad0jYyMJ67eGM0Q+i4eNBS3Hqj899nzAkx+upgOnhLrWdbvLxZ0T8PV7smtMvMRIUsyyLDZ4gE7NWvoqbKELd1y9aAIHacS1UA0tv95OPdMVO/KcfDGBxPb8UqDWr3jnlyr3u1NeSR8pk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=FNTxAIjg; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FNTxAIjg" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6cd7a2ed34bso5340196d6.2 for ; Thu, 14 Nov 2024 11:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611446; x=1732216246; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=g3mKyz8dYUWXDVhEiyfGTODSac7INNAwm9mfRIbHOA8=; b=FNTxAIjg+AKMOAkmRibmn0/OK/f/baVvp9f4agC+dyHYJbjbXK5zv1OzAJ+fq1Qd6N mo//d+fWUNdUaRr5iXKX0vRUCTGeca4QEZekiE9OVxvqjsKSuqy4pWDCarrmAHZoCBZr TfsVzdewDr3Q37NLZ7qFRuesouMnk/cOmxJG4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611446; x=1732216246; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g3mKyz8dYUWXDVhEiyfGTODSac7INNAwm9mfRIbHOA8=; b=e+7Dy57QgjhUNOLFJxG+Su2ydwTyJ4FT9iSoQDZ2N1S7T78VthBw+VYVPZDGA+Xg8J +pFn46dQ0wyls4hXr1Hx+J9GriIjR1lcV0eWK+OuH5kp6MFzDsBPRVj3FDSTzAh1XHZS XDx1uwzLsRbGwUuJXpNAJgiJtxTdP7JWawdt2Bl5cOg19CG6/BozCHv5AZZmlrh+fKf6 6X3SEl5S4ohgNpjtCVCV0ICvWuBHlA/GUOfYa4JKNZHtyCnKuYabji575jczWltGsSqq o4Gvmtk7FEAihD0+0rgcS/x3yO7zCDXMHd5+aKcuVshJCCwamF9SLERU07PFxqWNG7Cq h3HQ== X-Forwarded-Encrypted: i=1; AJvYcCUlLOc60o67rEqmnB4CV1zw8Aa4zaCbdJ5gugcqYeQQkAT9bNHU2eGcw5PHHL8ttsIPDsfU0eZz61aDKqo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzx6zd4inmS14xbGOXQ0QDt9ucELtCF/hWqt0jA7yBm3x7h7Xuc Hwo4hYw49hKpEqeLE+2Esxeq5jHN8x7Y2j/mfaW5x494ndZe5xDN/nfa316IXg== X-Google-Smtp-Source: AGHT+IFboiersPw9AuVt765dOS55ZVKctVly2CX95Gh3rA/va9J1s5reVsHiqKvLb+PaK3c6MG2r2A== X-Received: by 2002:a0c:fb09:0:b0:6d3:f904:5359 with SMTP id 6a1803df08f44-6d3f90454f5mr10161666d6.33.1731611446042; Thu, 14 Nov 2024 11:10:46 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:45 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:30 +0000 Subject: [PATCH v15 01/19] media: uvcvideo: Fix event flags in uvc_ctrl_send_events Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-1-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org X-Mailer: b4 0.13.0 If there is an event that needs the V4L2_EVENT_CTRL_CH_FLAGS flag, all the following events will have that flag, regardless if they need it or not. This is because we keep using the same variable all the time and we do not reset its original value. Cc: stable@vger.kernel.org Fixes: 805e9b4a06bf ("[media] uvcvideo: Send control change events for slav= e ctrls when the master changes") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 4fe26e82e3d1..bab9fdac98e6 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1673,13 +1673,13 @@ static void uvc_ctrl_send_events(struct uvc_fh *han= dle, { struct uvc_control_mapping *mapping; struct uvc_control *ctrl; - u32 changes =3D V4L2_EVENT_CTRL_CH_VALUE; unsigned int i; unsigned int j; =20 for (i =3D 0; i < xctrls_count; ++i) { - ctrl =3D uvc_find_control(handle->chain, xctrls[i].id, &mapping); + u32 changes =3D V4L2_EVENT_CTRL_CH_VALUE; =20 + ctrl =3D uvc_find_control(handle->chain, xctrls[i].id, &mapping); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) /* Notification will be sent from an Interrupt event. */ continue; --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8452F1A3AB9 for ; Thu, 14 Nov 2024 19:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611451; cv=none; b=EWuHb6DAQQ1soCLOTlz4FfRAPvQJugusyc4/Ieydhqe/HF3J8KfNpjn1vApCxL6+5IdApiyncLk8Uevomrm+GOX0igtT82rcrHhozJriyMiG+1Ma4KvuOIYZfV4rJPYD/U+who66SfzYl2iIVRn3zCuEHo+OC8CIxzNxfIxnppE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611451; c=relaxed/simple; bh=HxxCa8aCZqw7+XgedrXryM3g+ejWKITG5YuSOaGTAys=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I6ESn8ZI47x/3yBHfFOOlFBUhgh4d27BXaX2Cd2bJqdLuPhD7C6x2wF7vFoygeakC/2ItIGcTHPsKCZay47b/m7awmXVglve5h6xgwaahKTq0+e27Aj+ZzPwyhpg/z1ulqVIbgGSIJ8ASJTKeiHmXQFSDufJFiKM/zrUOfyip04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=e+YQAeE0; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="e+YQAeE0" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d382664fadso5469496d6.2 for ; Thu, 14 Nov 2024 11:10:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611448; x=1732216248; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1HI5lZXxKp42G1HCdhF2Z7i3opylcCsNhfoyIRTMS9o=; b=e+YQAeE0PLo4F9YV3TD5LJIvY1VTrmme8XYxDMNERysNMNkGySY2lHKmFW7fNSjvV0 Z91JUB1DM1GIs909S9FyvXqyanWhFAXctr+aTQfFMCFCXcqvuTP4evGstko+WJp88K5w 3xegb1di8HLTGCB8+i2YoT6dFxHNIxFd9ROJQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611448; x=1732216248; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1HI5lZXxKp42G1HCdhF2Z7i3opylcCsNhfoyIRTMS9o=; b=QN096kMw/Ml+IyCGynIq95P6hhoklS6IZhCuy5qm0yBKq98OBNtUf3pgd0QVRkgBLo 9W4ZqIo5Nlb8YxcH/Ydl6+WBtxpuJ7fEcGsnrhfz1vhzbcAA4W9Cdz9rGMu8MuF5L1Hw 3cmOl4V8vnyunyEH8r4c/HI1GcPWRm5CxC91akEzLLAwKu0GRULisyLFTBZHdpis6aMK kxL/ij2WLZWNps1WOGTNOI/xkAJr2As4WAkRz2faSO0+RNvbf92Joiz9wW+Dt4r/HFlS 2sXKWB2CewXhc3si+7PjKygkCQHacBhHEodBHltpnLa5wdeBQnL4wJ8Pv0np+5ip2Kgj D+lg== X-Forwarded-Encrypted: i=1; AJvYcCW7HoIg8DbHMJrH/hKjBUauYU80JITGoD+Xd2D1KVGUxdmj2mW/7Cum9HUiRG8vaOfqVH+mhDhWFgx7OeY=@vger.kernel.org X-Gm-Message-State: AOJu0YzFmHTIcA6hVzNRWHcJCCkDxx4vLtPyB+VaetWMviBUcvpALu92 mTzs4pr7Cn6od/DqN7IlZGug8FdtzMsivnMHBvlWoihyiDbjhQ1M3iOtFBlGmg== X-Google-Smtp-Source: AGHT+IG2l3VxNXtNXIcocUyYR/QdBi0pnQ7Ege9NiZqMMQCPuL9w1s2C20GN87XZMBlYsQpbVArMSQ== X-Received: by 2002:a05:6214:3bc7:b0:6d3:9b88:db62 with SMTP id 6a1803df08f44-6d3d00bfd7dmr154515706d6.17.1731611446897; Thu, 14 Nov 2024 11:10:46 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:46 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:31 +0000 Subject: [PATCH v15 02/19] media: v4l2_ctrl: Add V4L2_CTRL_TYPE_RECT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-2-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao , Sergey Senozhatsky , Daniel Scally , Hans Verkuil X-Mailer: b4 0.13.0 From: Yunke Cao Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls. Reviewed-by: Laurent Pinchart Reviewed-by: Ricardo Ribalda Reviewed-by: Sergey Senozhatsky Reviewed-by: Daniel Scally Signed-off-by: Yunke Cao Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- .../userspace-api/media/v4l/vidioc-g-ext-ctrls.rst | 4 ++++ .../userspace-api/media/v4l/vidioc-queryctrl.rst | 7 +++++++ .../userspace-api/media/videodev2.h.rst.exceptions | 1 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 16 ++++++++++++= +++- include/media/v4l2-ctrls.h | 2 ++ include/uapi/linux/videodev2.h | 2 ++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst b= /Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst index 4d56c0528ad7..b74a74ac06fc 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst @@ -199,6 +199,10 @@ still cause this situation. - ``p_area`` - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is of type ``V4L2_CTRL_TYPE_AREA``. + * - struct :c:type:`v4l2_rect` * + - ``p_rect`` + - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is + of type ``V4L2_CTRL_TYPE_RECT``. * - struct :c:type:`v4l2_ctrl_h264_sps` * - ``p_h264_sps`` - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this = control is diff --git a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst b/D= ocumentation/userspace-api/media/v4l/vidioc-queryctrl.rst index 4d38acafe8e1..56d5c8b0b88b 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst @@ -441,6 +441,13 @@ See also the examples in :ref:`control`. - n/a - A struct :c:type:`v4l2_area`, containing the width and the height of a rectangular area. Units depend on the use case. + * - ``V4L2_CTRL_TYPE_RECT`` + - n/a + - n/a + - n/a + - A struct :c:type:`v4l2_rect`, containing a rectangle described by + the position of its top-left corner, the width and the height. Units + depend on the use case. * - ``V4L2_CTRL_TYPE_H264_SPS`` - n/a - n/a diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b= /Documentation/userspace-api/media/videodev2.h.rst.exceptions index 429b5cdf05c3..3cf1380b52b0 100644 --- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions +++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions @@ -150,6 +150,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ct= rl_type` replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type` +replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type` diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2= -core/v4l2-ctrls-core.c index eeab6a5eb7ba..4c8744c8cd96 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -370,7 +370,11 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctr= l) case V4L2_CTRL_TYPE_AV1_FILM_GRAIN: pr_cont("AV1_FILM_GRAIN"); break; - + case V4L2_CTRL_TYPE_RECT: + pr_cont("%ux%u@%dx%d", + ptr.p_rect->width, ptr.p_rect->height, + ptr.p_rect->left, ptr.p_rect->top); + break; default: pr_cont("unknown type %d", ctrl->type); break; @@ -815,6 +819,7 @@ static int std_validate_compound(const struct v4l2_ctrl= *ctrl, u32 idx, struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering; struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params; struct v4l2_area *area; + struct v4l2_rect *rect; void *p =3D ptr.p + idx * ctrl->elem_size; unsigned int i; =20 @@ -1172,6 +1177,12 @@ static int std_validate_compound(const struct v4l2_c= trl *ctrl, u32 idx, return -EINVAL; break; =20 + case V4L2_CTRL_TYPE_RECT: + rect =3D p; + if (!rect->width || !rect->height) + return -EINVAL; + break; + default: return -EINVAL; } @@ -1872,6 +1883,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ct= rl_handler *hdl, case V4L2_CTRL_TYPE_AREA: elem_size =3D sizeof(struct v4l2_area); break; + case V4L2_CTRL_TYPE_RECT: + elem_size =3D sizeof(struct v4l2_rect); + break; default: if (type < V4L2_CTRL_COMPOUND_TYPES) elem_size =3D sizeof(s32); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 59679a42b3e7..b0db167a3ac4 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -56,6 +56,7 @@ struct video_device; * @p_av1_tile_group_entry: Pointer to an AV1 tile group entry structure. * @p_av1_frame: Pointer to an AV1 frame structure. * @p_av1_film_grain: Pointer to an AV1 film grain structure. + * @p_rect: Pointer to a rectangle. * @p: Pointer to a compound value. * @p_const: Pointer to a constant compound value. */ @@ -89,6 +90,7 @@ union v4l2_ctrl_ptr { struct v4l2_ctrl_av1_tile_group_entry *p_av1_tile_group_entry; struct v4l2_ctrl_av1_frame *p_av1_frame; struct v4l2_ctrl_av1_film_grain *p_av1_film_grain; + struct v4l2_rect *p_rect; void *p; const void *p_const; }; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index e7c4dce39007..c1c2ae150d30 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1859,6 +1859,7 @@ struct v4l2_ext_control { __s32 __user *p_s32; __s64 __user *p_s64; struct v4l2_area __user *p_area; + struct v4l2_rect __user *p_rect; struct v4l2_ctrl_h264_sps __user *p_h264_sps; struct v4l2_ctrl_h264_pps __user *p_h264_pps; struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix; @@ -1929,6 +1930,7 @@ enum v4l2_ctrl_type { V4L2_CTRL_TYPE_U16 =3D 0x0101, V4L2_CTRL_TYPE_U32 =3D 0x0102, V4L2_CTRL_TYPE_AREA =3D 0x0106, + V4L2_CTRL_TYPE_RECT =3D 0x0107, =20 V4L2_CTRL_TYPE_HDR10_CLL_INFO =3D 0x0110, V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY =3D 0x0111, --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08E3119F115 for ; Thu, 14 Nov 2024 19:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611451; cv=none; b=HFJrfQuTFPTHQzG1thzN6u0TNBFqEnXkhqaHiN2pDn5iPm4uAbnFGFK+smyb+sufIIwcBgj9kOHMTS9SNn8Hsv8o+aSiSDTsRbeUz5OEb9Ql5C8dvR6LGBFbPXbjuZ+FSeOSaDQ8Pe1Js9RRXFiDJl6hVD09HAyy5Uv9S0OGFsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611451; c=relaxed/simple; bh=UYqmDYSRM45RrMYLdKAGuJZQsXVdmxTn5VBRrCL3DkA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HquukzF3OPRwkhA/Fdcq9eXoHRwpacCpeUA4fAf/G5REmvJ0OUOb2OhpFRGda2Qly8begaxIeQXvVAshlFQ4nFUd2ZOwX0+RHpljb90iI7TXSTVSlln8cwjvJ/qX+W3nMWI5m8smSjb5xs0KdcKK5l0c3if8zInHtgWZtii3fuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=H/CfJtWv; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="H/CfJtWv" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d3f5fd139cso3966966d6.2 for ; Thu, 14 Nov 2024 11:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611448; x=1732216248; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SIEI9lOfs+bzPcK/C41IbD2ivUvc8o2wxWUbZzCDwRI=; b=H/CfJtWvB43Po4UpxlNnGQfAyAsHXpWqhAz42n8SiQ9EfIDLEDz14UO2GNlh1aKbmH SeAGSCUF7FP4CYbby5XxNPgaFTUUcSuju03VHToqm8SaY50l8MxbzaSC53PMrcY7PvRy 8eY42l+AU+gt4W6RtgTkwM5omS6Pu9v+av4IQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611448; x=1732216248; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SIEI9lOfs+bzPcK/C41IbD2ivUvc8o2wxWUbZzCDwRI=; b=N/BqZS5N8MnAFQoZYcleEEKFdD3mybzgSPCkyg0WSbzGW7SJR9MyVv/aq73ZSmch6L aYswWg1WyEOfghImuoDxlmiOjq7zuPjw8cpk8U0oKCLXDX1lMoAmaN0r8o2YZ0v4Awvh TKmUVvCc8gtr1bRxsazAQUIa1hSATPYJIgYviVKr3yqH3AEiAukkIW9PpNTVjgCGIPhQ 5q6Vi4LCBp4U1If63GoLUhSfuj+S/2IL3qv84lkk0WNgf6x1R//F9aKnx+Pp9RxUDnAs xARd7y2BfRxA08i6iXoyqVv9d2CgW4Enx0YV54iSkSLoY2TCzPZhgHejZ9UjQJ+l9U1b oTVg== X-Forwarded-Encrypted: i=1; AJvYcCVPEqTgeNosHEvl+etPD/JoSArY7udYIUOmvDTsx3z7MfizGorxNpfOhKxHfyiib5BfescGATbpI2HW0pA=@vger.kernel.org X-Gm-Message-State: AOJu0YyHFm+dNktt24FTvAVBhSeQb+VXW1q/qSkkcgXEWRTa/oWgC+Qi tp63CMYnBNAtb96ZHWvkvndPKsmOahE7DLaJb2T2U1DjoKDksocPPFxiPaV5pw== X-Google-Smtp-Source: AGHT+IGBZ0Zs3F0vGo2Kfk7kybk38534C/ous9PQr2m3WH4T1AdeIQd+XBtNQgnTVRterfh0isoAQw== X-Received: by 2002:a05:6214:46a1:b0:6cb:f79a:cb38 with SMTP id 6a1803df08f44-6d39e107cfcmr371927836d6.5.1731611447762; Thu, 14 Nov 2024 11:10:47 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:47 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:32 +0000 Subject: [PATCH v15 03/19] media: v4l2-ctrls: add support for V4L2_CTRL_WHICH_MIN/MAX_VAL Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-3-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao , Hans Verkuil X-Mailer: b4 0.13.0 From: Hans Verkuil Add the capability of retrieving the min and max values of a compound control. [Ricardo: Added static to v4l2_ctrl_type_op_(maximum|minimum) proto] [Ricardo: Fix documentation] Signed-off-by: Hans Verkuil Signed-off-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- .../userspace-api/media/v4l/vidioc-g-ext-ctrls.rst | 22 ++- .../userspace-api/media/v4l/vidioc-queryctrl.rst | 9 +- .../userspace-api/media/videodev2.h.rst.exceptions | 3 + drivers/media/i2c/imx214.c | 4 +- drivers/media/platform/qcom/venus/venc_ctrls.c | 9 +- drivers/media/v4l2-core/v4l2-ctrls-api.c | 54 ++++++-- drivers/media/v4l2-core/v4l2-ctrls-core.c | 151 +++++++++++++++++= ---- drivers/media/v4l2-core/v4l2-ioctl.c | 4 +- include/media/v4l2-ctrls.h | 36 ++++- include/uapi/linux/videodev2.h | 3 + 10 files changed, 247 insertions(+), 48 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst b= /Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst index b74a74ac06fc..b8698b85bd80 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst @@ -338,14 +338,26 @@ still cause this situation. - Which value of the control to get/set/try. * - :cspan:`2` ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current val= ue of the control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default - value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that - these controls have to be retrieved from a request or tried/set for - a request. In the latter case the ``request_fd`` field contains the + value of the control, ``V4L2_CTRL_WHICH_MIN_VAL`` will return the minimum + value of the control, and ``V4L2_CTRL_WHICH_MAX_VAL`` will return the max= imum + value of the control. ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that + the control value has to be retrieved from a request or tried/set for + a request. In that case the ``request_fd`` field contains the file descriptor of the request that should be used. If the device does not support requests, then ``EACCES`` will be returned. =20 - When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only - get the default value of the control, you cannot set or try it. + When using ``V4L2_CTRL_WHICH_DEF_VAL``, ``V4L2_CTRL_WHICH_MIN_VAL`` + or ``V4L2_CTRL_WHICH_MAX_VAL`` be aware that you can only get the + default/minimum/maximum value of the control, you cannot set or try it. + + Whether a control supports querying the minimum and maximum values using + ``V4L2_CTRL_WHICH_MIN_VAL`` and ``V4L2_CTRL_WHICH_MAX_VAL`` is indicated + by the ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` flag. Most non-compound + control types support this. For controls with compound types, the + definition of minimum/maximum values are provided by + the control documentation. If a compound control does not document the + meaning of minimum/maximum value, then querying the minimum or maximum + value will result in the error code -EINVAL. =20 For backwards compatibility you can also use a control class here (see :ref:`ctrl-class`). In that case all controls have to diff --git a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst b/D= ocumentation/userspace-api/media/v4l/vidioc-queryctrl.rst index 56d5c8b0b88b..3549417c7feb 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst @@ -447,7 +447,10 @@ See also the examples in :ref:`control`. - n/a - A struct :c:type:`v4l2_rect`, containing a rectangle described by the position of its top-left corner, the width and the height. Units - depend on the use case. + depend on the use case. Support for ``V4L2_CTRL_WHICH_MIN_VAL`` and + ``V4L2_CTRL_WHICH_MAX_VAL`` is optional and depends on the + ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` flag. See the documentation of + the specific control on how to interpret the minimum and maximum values. * - ``V4L2_CTRL_TYPE_H264_SPS`` - n/a - n/a @@ -664,6 +667,10 @@ See also the examples in :ref:`control`. ``dims[0]``. So setting the control with a differently sized array will change the ``elems`` field when the control is queried afterwards. + * - ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` + - 0x1000 + - This control supports getting minimum and maximum values using + vidioc_g_ext_ctrls with V4L2_CTRL_WHICH_MIN/MAX_VAL. =20 Return Value =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b= /Documentation/userspace-api/media/videodev2.h.rst.exceptions index 3cf1380b52b0..35d3456cc812 100644 --- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions +++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions @@ -396,6 +396,7 @@ replace define V4L2_CTRL_FLAG_HAS_PAYLOAD control-flags replace define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE control-flags replace define V4L2_CTRL_FLAG_MODIFY_LAYOUT control-flags replace define V4L2_CTRL_FLAG_DYNAMIC_ARRAY control-flags +replace define V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX control-flags =20 replace define V4L2_CTRL_FLAG_NEXT_CTRL control replace define V4L2_CTRL_FLAG_NEXT_COMPOUND control @@ -570,6 +571,8 @@ ignore define V4L2_CTRL_DRIVER_PRIV ignore define V4L2_CTRL_MAX_DIMS ignore define V4L2_CTRL_WHICH_CUR_VAL ignore define V4L2_CTRL_WHICH_DEF_VAL +ignore define V4L2_CTRL_WHICH_MIN_VAL +ignore define V4L2_CTRL_WHICH_MAX_VAL ignore define V4L2_CTRL_WHICH_REQUEST_VAL ignore define V4L2_OUT_CAP_CUSTOM_TIMINGS ignore define V4L2_CID_MAX_CTRLS diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c index 4962cfe7c83d..b0439005ec71 100644 --- a/drivers/media/i2c/imx214.c +++ b/drivers/media/i2c/imx214.c @@ -774,7 +774,9 @@ static int imx214_ctrls_init(struct imx214 *imx214) imx214->unit_size =3D v4l2_ctrl_new_std_compound(ctrl_hdlr, NULL, V4L2_CID_UNIT_CELL_SIZE, - v4l2_ctrl_ptr_create((void *)&unit_size)); + v4l2_ctrl_ptr_create((void *)&unit_size), + v4l2_ctrl_ptr_create(NULL), + v4l2_ctrl_ptr_create(NULL)); =20 v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx214_ctrl_ops, &props); =20 diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media= /platform/qcom/venus/venc_ctrls.c index 51801a962ed2..4d36c44f9d44 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -662,11 +662,16 @@ int venc_ctrl_init(struct venus_inst *inst) =20 v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_COLORIMETRY_HDR10_CLL_INFO, - v4l2_ctrl_ptr_create(&p_hdr10_cll)); + v4l2_ctrl_ptr_create(&p_hdr10_cll), + v4l2_ctrl_ptr_create(NULL), + v4l2_ctrl_ptr_create(NULL)); =20 v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY, - v4l2_ctrl_ptr_create((void *)&p_hdr10_mastering)); + v4l2_ctrl_ptr_create((void *)&p_hdr10_mastering), + v4l2_ctrl_ptr_create(NULL), + v4l2_ctrl_ptr_create(NULL)); + =20 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE, diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-= core/v4l2-ctrls-api.c index 95a2202879d8..c61f3ec09d24 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-api.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c @@ -94,6 +94,22 @@ static int def_to_user(struct v4l2_ext_control *c, struc= t v4l2_ctrl *ctrl) return ptr_to_user(c, ctrl, ctrl->p_new); } =20 +/* Helper function: copy the minimum control value back to the caller */ +static int min_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) +{ + ctrl->type_ops->minimum(ctrl, 0, ctrl->p_new); + + return ptr_to_user(c, ctrl, ctrl->p_new); +} + +/* Helper function: copy the maximum control value back to the caller */ +static int max_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) +{ + ctrl->type_ops->maximum(ctrl, 0, ctrl->p_new); + + return ptr_to_user(c, ctrl, ctrl->p_new); +} + /* Helper function: copy the caller-provider value as the new control valu= e */ static int user_to_new(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) { @@ -229,8 +245,8 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *= hdl, cs->error_idx =3D i; =20 if (cs->which && - cs->which !=3D V4L2_CTRL_WHICH_DEF_VAL && - cs->which !=3D V4L2_CTRL_WHICH_REQUEST_VAL && + (cs->which < V4L2_CTRL_WHICH_DEF_VAL || + cs->which > V4L2_CTRL_WHICH_MAX_VAL) && V4L2_CTRL_ID2WHICH(id) !=3D cs->which) { dprintk(vdev, "invalid which 0x%x or control id 0x%x\n", @@ -259,6 +275,15 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler = *hdl, return -EINVAL; } =20 + if (!(ctrl->flags & V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX) && + (cs->which =3D=3D V4L2_CTRL_WHICH_MIN_VAL || + cs->which =3D=3D V4L2_CTRL_WHICH_MAX_VAL)) { + dprintk(vdev, + "invalid which 0x%x or control id 0x%x\n", + cs->which, id); + return -EINVAL; + } + if (ctrl->cluster[0]->ncontrols > 1) have_clusters =3D true; if (ctrl->cluster[0] !=3D ctrl) @@ -368,8 +393,8 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *= hdl, */ static int class_check(struct v4l2_ctrl_handler *hdl, u32 which) { - if (which =3D=3D 0 || which =3D=3D V4L2_CTRL_WHICH_DEF_VAL || - which =3D=3D V4L2_CTRL_WHICH_REQUEST_VAL) + if (which =3D=3D 0 || (which >=3D V4L2_CTRL_WHICH_DEF_VAL && + which <=3D V4L2_CTRL_WHICH_MAX_VAL)) return 0; return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL; } @@ -389,10 +414,12 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler = *hdl, struct v4l2_ctrl_helper *helpers =3D helper; int ret; int i, j; - bool is_default, is_request; + bool is_default, is_request, is_min, is_max; =20 is_default =3D (cs->which =3D=3D V4L2_CTRL_WHICH_DEF_VAL); is_request =3D (cs->which =3D=3D V4L2_CTRL_WHICH_REQUEST_VAL); + is_min =3D (cs->which =3D=3D V4L2_CTRL_WHICH_MIN_VAL); + is_max =3D (cs->which =3D=3D V4L2_CTRL_WHICH_MAX_VAL); =20 cs->error_idx =3D cs->count; cs->which =3D V4L2_CTRL_ID2WHICH(cs->which); @@ -432,13 +459,14 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler = *hdl, =20 /* * g_volatile_ctrl will update the new control values. - * This makes no sense for V4L2_CTRL_WHICH_DEF_VAL and + * This makes no sense for V4L2_CTRL_WHICH_DEF_VAL, + * V4L2_CTRL_WHICH_MIN_VAL, V4L2_CTRL_WHICH_MAX_VAL and * V4L2_CTRL_WHICH_REQUEST_VAL. In the case of requests * it is v4l2_ctrl_request_complete() that copies the * volatile controls at the time of request completion * to the request, so you don't want to do that again. */ - if (!is_default && !is_request && + if (!is_default && !is_request && !is_min && !is_max && ((master->flags & V4L2_CTRL_FLAG_VOLATILE) || (master->has_volatiles && !is_cur_manual(master)))) { for (j =3D 0; j < master->ncontrols; j++) @@ -467,6 +495,10 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *= hdl, ret =3D -ENOMEM; else if (is_request && ref->p_req_valid) ret =3D req_to_user(cs->controls + idx, ref); + else if (is_min) + ret =3D min_to_user(cs->controls + idx, ref->ctrl); + else if (is_max) + ret =3D max_to_user(cs->controls + idx, ref->ctrl); else if (is_volatile) ret =3D new_to_user(cs->controls + idx, ref->ctrl); else @@ -564,9 +596,11 @@ int try_set_ext_ctrls_common(struct v4l2_fh *fh, =20 cs->error_idx =3D cs->count; =20 - /* Default value cannot be changed */ - if (cs->which =3D=3D V4L2_CTRL_WHICH_DEF_VAL) { - dprintk(vdev, "%s: cannot change default value\n", + /* Default/minimum/maximum values cannot be changed */ + if (cs->which =3D=3D V4L2_CTRL_WHICH_DEF_VAL || + cs->which =3D=3D V4L2_CTRL_WHICH_MIN_VAL || + cs->which =3D=3D V4L2_CTRL_WHICH_MAX_VAL) { + dprintk(vdev, "%s: cannot change default/min/max value\n", video_device_node_name(vdev)); return -EINVAL; } diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2= -core/v4l2-ctrls-core.c index 4c8744c8cd96..d510ca67e815 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -182,29 +182,66 @@ static void std_init_compound(const struct v4l2_ctrl = *ctrl, u32 idx, } } =20 -void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, +static void std_min_compound(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr) +{ + void *p =3D ptr.p + idx * ctrl->elem_size; + + if (ctrl->p_min.p_const) + memcpy(p, ctrl->p_min.p_const, ctrl->elem_size); + else + memset(p, 0, ctrl->elem_size); +} + +static void std_max_compound(const struct v4l2_ctrl *ctrl, u32 idx, union v4l2_ctrl_ptr ptr) +{ + void *p =3D ptr.p + idx * ctrl->elem_size; + + if (ctrl->p_max.p_const) + memcpy(p, ctrl->p_max.p_const, ctrl->elem_size); + else + memset(p, 0, ctrl->elem_size); +} + +static void __v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 fro= m_idx, + u32 which, union v4l2_ctrl_ptr ptr) { unsigned int i; u32 tot_elems =3D ctrl->elems; u32 elems =3D tot_elems - from_idx; + s64 value; =20 - if (from_idx >=3D tot_elems) + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + value =3D ctrl->default_value; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + value =3D ctrl->maximum; + break; + case V4L2_CTRL_WHICH_MIN_VAL: + value =3D ctrl->minimum; + break; + default: return; + } =20 switch (ctrl->type) { case V4L2_CTRL_TYPE_STRING: + if (which =3D=3D V4L2_CTRL_WHICH_DEF_VAL) + value =3D ctrl->minimum; + for (i =3D from_idx; i < tot_elems; i++) { unsigned int offset =3D i * ctrl->elem_size; =20 - memset(ptr.p_char + offset, ' ', ctrl->minimum); - ptr.p_char[offset + ctrl->minimum] =3D '\0'; + memset(ptr.p_char + offset, ' ', value); + ptr.p_char[offset + value] =3D '\0'; } break; case V4L2_CTRL_TYPE_INTEGER64: - if (ctrl->default_value) { + if (value) { for (i =3D from_idx; i < tot_elems; i++) - ptr.p_s64[i] =3D ctrl->default_value; + ptr.p_s64[i] =3D value; } else { memset(ptr.p_s64 + from_idx, 0, elems * sizeof(s64)); } @@ -214,9 +251,9 @@ void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctr= l, u32 from_idx, case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_BOOLEAN: - if (ctrl->default_value) { + if (value) { for (i =3D from_idx; i < tot_elems; i++) - ptr.p_s32[i] =3D ctrl->default_value; + ptr.p_s32[i] =3D value; } else { memset(ptr.p_s32 + from_idx, 0, elems * sizeof(s32)); } @@ -226,32 +263,61 @@ void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *c= trl, u32 from_idx, memset(ptr.p_s32 + from_idx, 0, elems * sizeof(s32)); break; case V4L2_CTRL_TYPE_U8: - memset(ptr.p_u8 + from_idx, ctrl->default_value, elems); + memset(ptr.p_u8 + from_idx, value, elems); break; case V4L2_CTRL_TYPE_U16: - if (ctrl->default_value) { + if (value) { for (i =3D from_idx; i < tot_elems; i++) - ptr.p_u16[i] =3D ctrl->default_value; + ptr.p_u16[i] =3D value; } else { memset(ptr.p_u16 + from_idx, 0, elems * sizeof(u16)); } break; case V4L2_CTRL_TYPE_U32: - if (ctrl->default_value) { + if (value) { for (i =3D from_idx; i < tot_elems; i++) - ptr.p_u32[i] =3D ctrl->default_value; + ptr.p_u32[i] =3D value; } else { memset(ptr.p_u32 + from_idx, 0, elems * sizeof(u32)); } break; default: - for (i =3D from_idx; i < tot_elems; i++) - std_init_compound(ctrl, i, ptr); + for (i =3D from_idx; i < tot_elems; i++) { + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + std_init_compound(ctrl, i, ptr); + break; + case V4L2_CTRL_WHICH_MAX_VAL: + std_max_compound(ctrl, i, ptr); + break; + case V4L2_CTRL_WHICH_MIN_VAL: + std_min_compound(ctrl, i, ptr); + break; + } + } break; } } + +void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, + union v4l2_ctrl_ptr ptr) +{ + __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_DEF_VAL, ptr); +} EXPORT_SYMBOL(v4l2_ctrl_type_op_init); =20 +static void v4l2_ctrl_type_op_minimum(const struct v4l2_ctrl *ctrl, + u32 from_idx, union v4l2_ctrl_ptr ptr) +{ + __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_MIN_VAL, ptr); +} + +static void v4l2_ctrl_type_op_maximum(const struct v4l2_ctrl *ctrl, + u32 from_idx, union v4l2_ctrl_ptr ptr) +{ + __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_MAX_VAL, ptr); +} + void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl) { union v4l2_ctrl_ptr ptr =3D ctrl->p_cur; @@ -1296,6 +1362,8 @@ EXPORT_SYMBOL(v4l2_ctrl_type_op_validate); static const struct v4l2_ctrl_type_ops std_type_ops =3D { .equal =3D v4l2_ctrl_type_op_equal, .init =3D v4l2_ctrl_type_op_init, + .minimum =3D v4l2_ctrl_type_op_minimum, + .maximum =3D v4l2_ctrl_type_op_maximum, .log =3D v4l2_ctrl_type_op_log, .validate =3D v4l2_ctrl_type_op_validate, }; @@ -1768,7 +1836,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_c= trl_handler *hdl, s64 min, s64 max, u64 step, s64 def, const u32 dims[V4L2_CTRL_MAX_DIMS], u32 elem_size, u32 flags, const char * const *qmenu, - const s64 *qmenu_int, const union v4l2_ctrl_ptr p_def, + const s64 *qmenu_int, + const union v4l2_ctrl_ptr p_def, + const union v4l2_ctrl_ptr p_min, + const union v4l2_ctrl_ptr p_max, void *priv) { struct v4l2_ctrl *ctrl; @@ -1892,6 +1963,12 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_c= trl_handler *hdl, break; } =20 + if (type < V4L2_CTRL_COMPOUND_TYPES && + type !=3D V4L2_CTRL_TYPE_BUTTON && + type !=3D V4L2_CTRL_TYPE_CTRL_CLASS && + type !=3D V4L2_CTRL_TYPE_STRING) + flags |=3D V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + /* Sanity checks */ if (id =3D=3D 0 || name =3D=3D NULL || !elem_size || id >=3D V4L2_CID_PRIVATE_BASE || @@ -1900,6 +1977,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ct= rl_handler *hdl, handler_set_err(hdl, -ERANGE); return NULL; } + err =3D check_range(type, min, max, step, def); if (err) { handler_set_err(hdl, err); @@ -1941,6 +2019,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_c= trl_handler *hdl, =20 if (type >=3D V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) sz_extra +=3D elem_size; + if (type >=3D V4L2_CTRL_COMPOUND_TYPES && p_min.p_const) + sz_extra +=3D elem_size; + if (type >=3D V4L2_CTRL_COMPOUND_TYPES && p_max.p_const) + sz_extra +=3D elem_size; =20 ctrl =3D kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL); if (ctrl =3D=3D NULL) { @@ -2006,6 +2088,22 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_c= trl_handler *hdl, memcpy(ctrl->p_def.p, p_def.p_const, elem_size); } =20 + if (flags & V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX) { + void *ptr =3D ctrl->p_def.p; + + if (p_min.p_const) { + ptr +=3D elem_size; + ctrl->p_min.p =3D ptr; + memcpy(ctrl->p_min.p, p_min.p_const, elem_size); + } + + if (p_max.p_const) { + ptr +=3D elem_size; + ctrl->p_max.p =3D ptr; + memcpy(ctrl->p_max.p, p_max.p_const, elem_size); + } + } + ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); cur_to_new(ctrl); =20 @@ -2056,7 +2154,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ct= rl_handler *hdl, type, min, max, is_menu ? cfg->menu_skip_mask : step, def, cfg->dims, cfg->elem_size, - flags, qmenu, qmenu_int, cfg->p_def, priv); + flags, qmenu, qmenu_int, cfg->p_def, cfg->p_min, + cfg->p_max, priv); if (ctrl) ctrl->is_private =3D cfg->is_private; return ctrl; @@ -2081,7 +2180,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_= handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, min, max, step, def, NULL, 0, - flags, NULL, NULL, ptr_null, NULL); + flags, NULL, NULL, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std); =20 @@ -2114,7 +2214,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_= ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, 0, max, mask, def, NULL, 0, - flags, qmenu, qmenu_int, ptr_null, NULL); + flags, qmenu, qmenu_int, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); =20 @@ -2146,7 +2247,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct= v4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, 0, max, mask, def, NULL, 0, - flags, qmenu, NULL, ptr_null, NULL); + flags, qmenu, NULL, ptr_null, ptr_null, + ptr_null, NULL); =20 } EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items); @@ -2154,7 +2256,9 @@ EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items); /* Helper function for standard compound controls */ struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_ops *ops, u32 id, - const union v4l2_ctrl_ptr p_def) + const union v4l2_ctrl_ptr p_def, + const union v4l2_ctrl_ptr p_min, + const union v4l2_ctrl_ptr p_max) { const char *name; enum v4l2_ctrl_type type; @@ -2168,7 +2272,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v= 4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, min, max, step, def, NULL, 0, - flags, NULL, NULL, p_def, NULL); + flags, NULL, NULL, p_def, p_min, p_max, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std_compound); =20 @@ -2192,7 +2296,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_= ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, 0, max, 0, def, NULL, 0, - flags, NULL, qmenu_int, ptr_null, NULL); + flags, NULL, qmenu_int, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_int_menu); =20 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core= /v4l2-ioctl.c index 0304daa8471d..bfdba96e938c 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -893,7 +893,9 @@ static bool check_ext_ctrls(struct v4l2_ext_controls *c= , unsigned long ioctl) return false; break; case V4L2_CTRL_WHICH_DEF_VAL: - /* Default value cannot be changed */ + case V4L2_CTRL_WHICH_MIN_VAL: + case V4L2_CTRL_WHICH_MAX_VAL: + /* Default, minimum or maximum value cannot be changed */ if (ioctl =3D=3D VIDIOC_S_EXT_CTRLS || ioctl =3D=3D VIDIOC_TRY_EXT_CTRLS) { c->error_idx =3D c->count; diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index b0db167a3ac4..9ed7be1e696f 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -133,6 +133,8 @@ struct v4l2_ctrl_ops { * * @equal: return true if all ctrl->elems array elements are equal. * @init: initialize the value for array elements from from_idx to ctrl->e= lems. + * @minimum: set the value to the minimum value of the control. + * @maximum: set the value to the maximum value of the control. * @log: log the value. * @validate: validate the value for ctrl->new_elems array elements. * Return 0 on success and a negative value otherwise. @@ -142,6 +144,10 @@ struct v4l2_ctrl_type_ops { union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2); void (*init)(const struct v4l2_ctrl *ctrl, u32 from_idx, union v4l2_ctrl_ptr ptr); + void (*minimum)(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr); + void (*maximum)(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr); void (*log)(const struct v4l2_ctrl *ctrl); int (*validate)(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr); }; @@ -247,6 +253,12 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl = *ctrl, void *priv); * @p_def: The control's default value represented via a union which * provides a standard way of accessing control types * through a pointer (for compound controls only). + * @p_min: The control's minimum value represented via a union which + * provides a standard way of accessing control types + * through a pointer (for compound controls only). + * @p_max: The control's maximum value represented via a union which + * provides a standard way of accessing control types + * through a pointer (for compound controls only). * @p_cur: The control's current value represented via a union which * provides a standard way of accessing control types * through a pointer. @@ -306,6 +318,8 @@ struct v4l2_ctrl { } cur; =20 union v4l2_ctrl_ptr p_def; + union v4l2_ctrl_ptr p_min; + union v4l2_ctrl_ptr p_max; union v4l2_ctrl_ptr p_new; union v4l2_ctrl_ptr p_cur; }; @@ -425,6 +439,8 @@ struct v4l2_ctrl_handler { * @step: The control's step value for non-menu controls. * @def: The control's default value. * @p_def: The control's default value for compound controls. + * @p_min: The control's minimum value for compound controls. + * @p_max: The control's maximum value for compound controls. * @dims: The size of each dimension. * @elem_size: The size in bytes of the control. * @flags: The control's flags. @@ -454,6 +470,8 @@ struct v4l2_ctrl_config { u64 step; s64 def; union v4l2_ctrl_ptr p_def; + union v4l2_ctrl_ptr p_min; + union v4l2_ctrl_ptr p_max; u32 dims[V4L2_CTRL_MAX_DIMS]; u32 elem_size; u32 flags; @@ -723,17 +741,25 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct= v4l2_ctrl_handler *hdl, * @ops: The control ops. * @id: The control ID. * @p_def: The control's default value. + * @p_min: The control's minimum value. + * @p_max: The control's maximum value. * - * Sames as v4l2_ctrl_new_std(), but with support to compound controls, th= anks - * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a - * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the - * compound control should be all zeroes. + * Same as v4l2_ctrl_new_std(), but with support for compound controls. + * To fill in the @p_def, @p_min and @p_max fields, use v4l2_ctrl_ptr_crea= te() + * to convert a pointer to a const union v4l2_ctrl_ptr. + * Use v4l2_ctrl_ptr_create(NULL) if you want the default, minimum or maxi= mum + * value of the compound control to be all zeroes. + * If the compound control does not set the ``V4L2_CTRL_FLAG_HAS_WHICH_MIN= _MAX`` + * flag, then it does not has minimum and maximum values. In that case jus= t use + * v4l2_ctrl_ptr_create(NULL) for the @p_min and @p_max arguments. * */ struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_ops *ops, u32 id, - const union v4l2_ctrl_ptr p_def); + const union v4l2_ctrl_ptr p_def, + const union v4l2_ctrl_ptr p_min, + const union v4l2_ctrl_ptr p_max); =20 /** * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu cont= rol. diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index c1c2ae150d30..c8cb2796130f 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1912,6 +1912,8 @@ struct v4l2_ext_controls { #define V4L2_CTRL_WHICH_CUR_VAL 0 #define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000 #define V4L2_CTRL_WHICH_REQUEST_VAL 0x0f010000 +#define V4L2_CTRL_WHICH_MIN_VAL 0x0f020000 +#define V4L2_CTRL_WHICH_MAX_VAL 0x0f030000 =20 enum v4l2_ctrl_type { V4L2_CTRL_TYPE_INTEGER =3D 1, @@ -2019,6 +2021,7 @@ struct v4l2_querymenu { #define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE 0x0200 #define V4L2_CTRL_FLAG_MODIFY_LAYOUT 0x0400 #define V4L2_CTRL_FLAG_DYNAMIC_ARRAY 0x0800 +#define V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX 0x1000 =20 /* Query flags, to be ORed with the control ID */ #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C6811A76B5 for ; Thu, 14 Nov 2024 19:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611452; cv=none; b=I7cD+fwe4oZszhdbneU3mpDUjqOmmMOZsMiQICgjsQFicXiI1CmZx5f1DXUcGF4iBa3W/PwPAal1luPk3k2zWez/a6+Am2pJngi1YQGAB6vrEXmtDr14EwbwZfE7fKx1GlNSWwqx8+xjbq703ze7xu7lLIyVnUkTONTqnIouG/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611452; c=relaxed/simple; bh=891vgr8ZfTyBnkF2hdx6x/M+sg6ZKCMBjz6/1SYlOIY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GW+gMUNVPw/CP1XSjqqf8o80RFQ9uaI0DDTKKAj7E/GowYTVAtSiV8XH1javLl3DSU/HI641SprintGkThWR60gSoeF3tT1gP899S/eIiSvrWnlyxvl7iV7r5kb0kN7CUAAjrKgQ+iHB4I6vXK1WcSELTCiujeLKMazd+n+DTrg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Tg3svBF9; arc=none smtp.client-ip=209.85.222.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Tg3svBF9" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-7b15467f383so60531985a.3 for ; Thu, 14 Nov 2024 11:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611449; x=1732216249; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=69mn13H1PoKT9uFw0cFCsSqSTFJ/p7+Sw2nsU0oDXCo=; b=Tg3svBF9/IZyK6wj1cqMuySbmmqZm8zAft/J3IRBICwjFpKe/cNBe1tkSInM1J2fNZ qoxy5iVT43v1lIipA/XOxTz4pntAEVl0ZPEFIicGtTXoGBj2p68sUhEVD3B6TI7ntibl gYJXboqRQ3e6SWdGteUmqTij297V2mzqsBBYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611449; x=1732216249; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=69mn13H1PoKT9uFw0cFCsSqSTFJ/p7+Sw2nsU0oDXCo=; b=a1H/fTeEsTP530tNLfXybAE9hojgasINzhJ5l1WtFuTEHXWbcatHr7keqBKpti58GV knG6N0BLVMg3qxqnCMSMtbSRCcgwGY+eCLcZMgWFuANQquxs9hi6NEDo09kAvXcSxA0U qOro+aCE9kY2w3upV+WZ2VjkoLZuPjvaPddo/5eT/3seTn5AbfDr5MqtxhZOcN2sTOfU 7CBuKDs8/ymxkYV1HRRrkJhZiUrxyXpaDdKcntzcN8HovOP+52rAfKKyxe5sBt93y4Fq iUauqM8z2gvidZ3U1rNPYvCt92MzP1ShiHJkXJIfkGV7h1SD2WH+yIyCRzBPc2zgE+dX eWvg== X-Forwarded-Encrypted: i=1; AJvYcCWSrFO6jkEdggh4XmAdNrxiCg3guyvp/XS3Krny4z3Vasg3EL/bPGwZ0QBOwoyccxpManfnJySWQw+Tu3E=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1CtUFDdugiRwv2Pi+8rKd1RWSIHhgn2Lb4kSCM+8JySSvXi7e wmyFGVr14Y+oZcQTc5TN7KUCyh1ghAM+AHMqDf2F+sqnOjQU9gnKZbpAh8xvBA== X-Google-Smtp-Source: AGHT+IF0l8bNoHEVEJoX/hMNb/j5aEKx9CFbpJx4t69EN9a8/Orafd02Wytr+RNNBbEhefyTuVpv4w== X-Received: by 2002:a05:6214:448c:b0:6cb:d376:2b27 with SMTP id 6a1803df08f44-6d3dd060784mr99646816d6.29.1731611449136; Thu, 14 Nov 2024 11:10:49 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:48 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:33 +0000 Subject: [PATCH v15 04/19] media: vivid: Add a rectangle control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-4-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao , Hans Verkuil X-Mailer: b4 0.13.0 From: Yunke Cao This control represents a generic read/write rectangle. It supports V4L2_CTRL_WHICH_MIN/MAX_VAL. Signed-off-by: Yunke Cao Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/test-drivers/vivid/vivid-ctrls.c | 34 ++++++++++++++++++++++= ++++ 1 file changed, 34 insertions(+) diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c b/drivers/media= /test-drivers/vivid/vivid-ctrls.c index 2b5c8fbcd0a2..57346b714534 100644 --- a/drivers/media/test-drivers/vivid/vivid-ctrls.c +++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c @@ -37,6 +37,7 @@ #define VIVID_CID_U8_PIXEL_ARRAY (VIVID_CID_CUSTOM_BASE + 14) #define VIVID_CID_S32_ARRAY (VIVID_CID_CUSTOM_BASE + 15) #define VIVID_CID_S64_ARRAY (VIVID_CID_CUSTOM_BASE + 16) +#define VIVID_CID_RECT (VIVID_CID_CUSTOM_BASE + 17) =20 #define VIVID_CID_VIVID_BASE (0x00f00000 | 0xf000) #define VIVID_CID_VIVID_CLASS (0x00f00000 | 1) @@ -360,6 +361,38 @@ static const struct v4l2_ctrl_config vivid_ctrl_ro_int= 32 =3D { .step =3D 1, }; =20 +static const struct v4l2_rect rect_def =3D { + .top =3D 100, + .left =3D 200, + .width =3D 300, + .height =3D 400, +}; + +static const struct v4l2_rect rect_min =3D { + .top =3D 0, + .left =3D 0, + .width =3D 1, + .height =3D 1, +}; + +static const struct v4l2_rect rect_max =3D { + .top =3D 0, + .left =3D 0, + .width =3D 1000, + .height =3D 2000, +}; + +static const struct v4l2_ctrl_config vivid_ctrl_rect =3D { + .ops =3D &vivid_user_gen_ctrl_ops, + .id =3D VIVID_CID_RECT, + .name =3D "Rect", + .type =3D V4L2_CTRL_TYPE_RECT, + .flags =3D V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX, + .p_def.p_const =3D &rect_def, + .p_min.p_const =3D &rect_min, + .p_max.p_const =3D &rect_max, +}; + /* Framebuffer Controls */ =20 static int vivid_fb_s_ctrl(struct v4l2_ctrl *ctrl) @@ -1685,6 +1718,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool= show_ccs_cap, dev->int_menu =3D v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu= , NULL); dev->ro_int32 =3D v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_ro_int32= , NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL); + v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_rect, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_dyn_array, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL); --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AF471A9B3A for ; Thu, 14 Nov 2024 19:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611453; cv=none; b=nNz8bUgNDPXoWnFVUhWu92UYuG5TuowJWk0gNdnNijnFDfJda0o2V8ScJMXa9Cfii2AHQIS9AI8kaki5DX1hztTxh5dPGyF/m9bdkW4DebDKsvXA+NXtqLZHY1eBmtyjeJyeXUy76TQSeHDxAieyvjj7DKTIR28y07cmJeEgHdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611453; c=relaxed/simple; bh=gIGmVdezcCcJeNLxtrKhKX+oRcR324CxjSWZAh2pVoE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q8/757bHnJGVP0yCg5Gr2dy+azLQhcshb6qyNpy8JcOV4yFLJsdHBgW6Z7v5J0I6btl9IqD+EYrZagMoo/2IAXOF9dN0KFdW8pS4ueIgZvisMjB7Kc4bX7jBB2WVAtF8w20TqUnqeP6pgpKkzbFbPH1FaIp0JO05NohFADhjCVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=aC7ulpuQ; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aC7ulpuQ" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6d382664fadso5469806d6.2 for ; Thu, 14 Nov 2024 11:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611450; x=1732216250; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MoXFoTS1UHIpxTLyzT+33q7ydl+EE4ZnWBq8pnFccEU=; b=aC7ulpuQG0XZS4qz5WFOxUwUfF4c59+hF9Cjip0ZBecegc/Rk+yQxckchI6enBAgLV Kdq8gVBLvlBMQKdtqLKVsYZKCDiC+1Aks7oC5MEnpPrSS9putOClQ2VCOtmHjYXyjIeH 0QejeX4Bt1Y/9MNPCCg5vth/BU0WfCM1t8pH4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611450; x=1732216250; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MoXFoTS1UHIpxTLyzT+33q7ydl+EE4ZnWBq8pnFccEU=; b=JM7386FMBUPU39kJxi9wmZIB9ru8RnEKWLTjhIoTaKSme6TvcT/i5ogWJVozYuAQuE 3V+t8lPFav+8CEE6aCNvrAm3x/Vmd+T8dhN0mmiEgT4xrddqwztQcPhI4ZJJRzoTMkmj YkRuveajakkq+TmVlGczvT2qNm4A+VcmBPUSfbq7R5yUFObh2mkaZGlHgYWigfLpWSPy +F2llsh1bpWGeA6G8veVikjfnfJYbfP7ckNWTRpaTxgfVx/vT/AoNLcfWcKiQQCiNOVW S5EexEzYkLyvGSW69dNc62CuU+VpHSs0T29bMJcV1AgwECZdvRf6en44fs0LLeo2R9Qe v+1A== X-Forwarded-Encrypted: i=1; AJvYcCWvjusJrfa27T2yIVC4YSNxGt7XVTkjfbJEFtsrgZh+DrdTUqwQkTyBkSQI9uCF3WyzQO6EHkHBBpB+GiQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzDiJrmTfIz0f7APurfZMZNq1o6eDDjHi0Hj3DmK5I5XXd2tjvk WX3MGXt6kshA5SB5lcxGOW7P2q+Jbi4oG+kz4AOLGmVj9WfozP9h/zbrM6fzow== X-Google-Smtp-Source: AGHT+IH3AHUKa3QYBAA2tT0n3IAU/U0FsAiEeXPgr/F9Ta/r6uwiQZR+OH0yIoOUcs7eU1U6UG1g4A== X-Received: by 2002:a05:6214:458c:b0:6cb:edd7:ac32 with SMTP id 6a1803df08f44-6d3d00be928mr154115866d6.12.1731611449903; Thu, 14 Nov 2024 11:10:49 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:49 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:34 +0000 Subject: [PATCH v15 05/19] media: uvcvideo: Handle uvc menu translation inside uvc_get_le_value Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-5-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 map->get() gets a value from an uvc_control in "UVC format" and converts it to a value that can be consumed by v4l2. Instead of using a special get function for V4L2_CTRL_TYPE_MENU, we were converting from uvc_get_le_value in two different places. Move the conversion to uvc_get_le_value(). Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 77 +++++++++++++++++-------------------= ---- 1 file changed, 32 insertions(+), 45 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index bab9fdac98e6..77f7058ec966 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -862,6 +862,25 @@ static inline void uvc_clear_bit(u8 *data, int bit) data[bit >> 3] &=3D ~(1 << (bit & 7)); } =20 +static s32 uvc_menu_to_v4l2_menu(struct uvc_control_mapping *mapping, s32 = val) +{ + unsigned int i; + + for (i =3D 0; BIT(i) <=3D mapping->menu_mask; ++i) { + u32 menu_value; + + if (!test_bit(i, &mapping->menu_mask)) + continue; + + menu_value =3D uvc_mapping_get_menu_value(mapping, i); + + if (menu_value =3D=3D val) + return i; + } + + return val; +} + /* * Extract the bit string specified by mapping->offset and mapping->size * from the little-endian data stored at 'data' and return the result as @@ -896,6 +915,16 @@ static s32 uvc_get_le_value(struct uvc_control_mapping= *mapping, if (mapping->data_type =3D=3D UVC_CTRL_DATA_TYPE_SIGNED) value |=3D -(value & (1 << (mapping->size - 1))); =20 + /* If it is a menu, convert from uvc to v4l2. */ + if (mapping->v4l2_type !=3D V4L2_CTRL_TYPE_MENU) + return value; + + switch (query) { + case UVC_GET_CUR: + case UVC_GET_DEF: + return uvc_menu_to_v4l2_menu(mapping, value); + } + return value; } =20 @@ -1060,32 +1089,6 @@ static int uvc_ctrl_populate_cache(struct uvc_video_= chain *chain, return 0; } =20 -static s32 __uvc_ctrl_get_value(struct uvc_control_mapping *mapping, - const u8 *data) -{ - s32 value =3D mapping->get(mapping, UVC_GET_CUR, data); - - if (mapping->v4l2_type =3D=3D V4L2_CTRL_TYPE_MENU) { - unsigned int i; - - for (i =3D 0; BIT(i) <=3D mapping->menu_mask; ++i) { - u32 menu_value; - - if (!test_bit(i, &mapping->menu_mask)) - continue; - - menu_value =3D uvc_mapping_get_menu_value(mapping, i); - - if (menu_value =3D=3D value) { - value =3D i; - break; - } - } - } - - return value; -} - static int __uvc_ctrl_load_cur(struct uvc_video_chain *chain, struct uvc_control *ctrl) { @@ -1136,8 +1139,8 @@ static int __uvc_ctrl_get(struct uvc_video_chain *cha= in, if (ret < 0) return ret; =20 - *value =3D __uvc_ctrl_get_value(mapping, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + *value =3D mapping->get(mapping, UVC_GET_CUR, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); =20 return 0; } @@ -1287,7 +1290,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_cha= in *chain, { struct uvc_control_mapping *master_map =3D NULL; struct uvc_control *master_ctrl =3D NULL; - unsigned int i; =20 memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); v4l2_ctrl->id =3D mapping->id; @@ -1330,21 +1332,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_ch= ain *chain, v4l2_ctrl->minimum =3D ffs(mapping->menu_mask) - 1; v4l2_ctrl->maximum =3D fls(mapping->menu_mask) - 1; v4l2_ctrl->step =3D 1; - - for (i =3D 0; BIT(i) <=3D mapping->menu_mask; ++i) { - u32 menu_value; - - if (!test_bit(i, &mapping->menu_mask)) - continue; - - menu_value =3D uvc_mapping_get_menu_value(mapping, i); - - if (menu_value =3D=3D v4l2_ctrl->default_value) { - v4l2_ctrl->default_value =3D i; - break; - } - } - return 0; =20 case V4L2_CTRL_TYPE_BOOLEAN: @@ -1592,7 +1579,7 @@ void uvc_ctrl_status_event(struct uvc_video_chain *ch= ain, ctrl->handle =3D NULL; =20 list_for_each_entry(mapping, &ctrl->info.mappings, list) { - s32 value =3D __uvc_ctrl_get_value(mapping, data); + s32 value =3D mapping->get(mapping, UVC_GET_CUR, data); =20 /* * handle may be NULL here if the device sends auto-update --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FA471A9B4F for ; Thu, 14 Nov 2024 19:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611453; cv=none; b=pnbVSbaNIh+GQvjC8U6Vzow90DIB7vWz6Qk6LSdS5msR6SK3ofD1/wePrjuXBszCS24t3cAytANQT5cRAwQjuPklWdxBFuMzVPzL27UVkhHFaP+xh4/cdyQmOrZspd4HAASeLaABOcyn6bW/fmrTg0NVudoZji3yUzm3j/snE8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611453; c=relaxed/simple; bh=rPQhRflph/OInqLTKMInrEsUWj88dYYh+206vtmsiRg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rsRYOLIGkx9Dl4CwWhneLdB073Kqu9CE1C92/uNE2bvCFEmRhlT1QjhWNBaWCwXBPczjNCE3ojI0vR4yaD6pCTos6r8lcchjsiDuhZrukhCIRfJP1C6wU+tD5J6nWO3EsnKn9pRXTV9c2ybvIZ+eSJbMZ4FMUCQpcJtfjpv9610= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ab3VSkGU; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ab3VSkGU" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d3f3cc0585so4779466d6.1 for ; Thu, 14 Nov 2024 11:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611450; x=1732216250; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pH1OuQ5/XwP0NAJGYmmTzFwWtNbM3f5Um97UBRgql50=; b=ab3VSkGUm3iJRXFp1KRbrezr7zk52+k68rw9vHTgPmR2Gni5OPfY1vcE0T+hsOTYna fJTDnSY++el4Pvs6+5XSPbGSUOOmJ+G/rmfyn11LjOz+r7a6dqEy0iBNYSRuGzhqzcmq qejw3zByGrFr23waC5XaABSh3r7lbzoJKGP8Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611450; x=1732216250; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pH1OuQ5/XwP0NAJGYmmTzFwWtNbM3f5Um97UBRgql50=; b=Jt8oIVrbYgj78h6QpMuODdL9zy4GdoPYyYo+0Q6ysUAp0Y/eViePFHMiLQ/LeX2QKe fSMjvxayToF9wzVo5iweD4gLvPA0HLai7/+MEHjPOdr9jvDIw2VYCOeKKhqtCOQQJdW4 +5yu+YcyCqVAiKFBs/h/wY+6FaLuPKNCLDf/ioLO4GUh/zNhbHPsAo1SJ30X+nYrnTiB 5nNHGu+lbhgTgleti51yUejPEB673trf6EaTEy6rkKyUkarvg59XRPIbaD9dQidDMfDp Kd5V+UiN5pznXhThEFqhCv4UBaL58VFrq4Xn1ZVWlIT0/jqT773HlgsQB2s2yy0z2XPQ Mn2g== X-Forwarded-Encrypted: i=1; AJvYcCU8BlurClMT+M7KnIcXzlHSZ5ZYaOgdiK0EB+qhhCuZSJzUv31UUF8vty7sdjREzr9vSsZuUy1QWno2Zlk=@vger.kernel.org X-Gm-Message-State: AOJu0YxPLiNrF2WbyoRczMktTwR430VkMViyOJsEYF5ESbR/OBUM3iWp 7k/FCcuYrRClwMcpFDEb0bK+jvViHL8t679FVIq0shwMG/9I1pk7QliFe2x4wQ== X-Google-Smtp-Source: AGHT+IFTGsrShBjgM848OqL1CfPKk91R3Op/+31v6HbDQXfgIAqpr7uyzdwQGXGarOa1YbiIhfrByw== X-Received: by 2002:a05:6214:4347:b0:6ce:266a:85d5 with SMTP id 6a1803df08f44-6d39e14f151mr369822306d6.20.1731611450688; Thu, 14 Nov 2024 11:10:50 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:50 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:35 +0000 Subject: [PATCH v15 06/19] media: uvcvideo: Handle uvc menu translation inside uvc_set_le_value Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-6-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Be consistent with uvc_get_le_value() and do the menu translation there. Note that in this case, the refactor does not provide much... but consistency is a nice feature. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 77f7058ec966..c975e0ab479b 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -939,6 +939,8 @@ static void uvc_set_le_value(struct uvc_control_mapping= *mapping, int offset =3D mapping->offset; u8 mask; =20 + if (mapping->v4l2_type =3D=3D V4L2_CTRL_TYPE_MENU) + value =3D uvc_mapping_get_menu_value(mapping, value); /* * According to the v4l2 spec, writing any value to a button control * should result in the action belonging to the button control being @@ -1988,23 +1990,23 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (!test_bit(xctrl->value, &mapping->menu_mask)) return -EINVAL; =20 - value =3D uvc_mapping_get_menu_value(mapping, xctrl->value); - /* * Valid menu indices are reported by the GET_RES request for * UVC controls that support it. */ if (mapping->data_type =3D=3D UVC_CTRL_DATA_TYPE_BITMASK) { + int val =3D uvc_mapping_get_menu_value(mapping, + xctrl->value); if (!ctrl->cached) { ret =3D uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) return ret; } =20 - if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & value)) + if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & val)) return -EINVAL; } - + value =3D xctrl->value; break; =20 default: --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF6811AB6DD for ; Thu, 14 Nov 2024 19:10:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611455; cv=none; b=Ntt8/RB3zWwiXetBFkAp0in6DTGp7b0gP6XQuhi7DmFTwQZ/wvdtQioI+Y88F3Lv6fPt+qQgjnUCZ3bEjbchGYQ9/XkhNM74hpEuo3VUQQIgkWdvsGWT29uI3bx84/CaY7ZWZqx+gMpsfeKYyQwE+jifaItgfzpmTy3Dt2Yk1rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611455; c=relaxed/simple; bh=aivOJ+nhVk++XVwDmChI0xJhucq0gzquyrqV4wPEJLY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dU40iwxRJejNJvXzqxeXgb8EfODLiQhEexaD15kMtTOlELo/t9Niw1Jv9P0evUZQnvWA6TpmLiLlco7I3JpR0g2GiHexYRaK5cWmBgfnd9dE4ldeK+OmFbPwraihwteHJEcJSsw3RThKv46RwyYbOmefiuRB3hh1/lYfYTopvTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=eBPAhNmN; arc=none smtp.client-ip=209.85.219.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eBPAhNmN" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6d3f8a4be8bso2841066d6.3 for ; Thu, 14 Nov 2024 11:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611452; x=1732216252; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=m+t1HpWfn8XfUwUDY3vH72Vh4+vht6oJzl9J9rxV/wc=; b=eBPAhNmNsSwVZ94pu5nOo4lOfzYmOLM1QEEKY3nY+RfWv84+ddl+r1FTpPvf6XzWQv ThHaIxfa50grt3WXmr96eIZDIMQgkVV9PuFR3i6angOfe48YZyhdChMuOAI72ySshzim Yfz2sb55cuwFP7AuGcgyMQlV766Wn2AmuoL3o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611452; x=1732216252; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m+t1HpWfn8XfUwUDY3vH72Vh4+vht6oJzl9J9rxV/wc=; b=oTGGpYdhismdGQUYSIrjr2Zgmbymu8GnilBM41HTd+CqbQhxnZtu8MMqpGOpCCONVb L/nHrLKjYEZWoCiK1e8kCNINfyF+C/5iaXLXx3G5vugQ+dunnZBIL7Yxeb9Uw+z8G7n9 f0aBzFJp07GlfgITUeFDzobWQ5O0nteRuZPZ+SbfYOv59u3ztRNR1vMram5SR/Zrc+1d 44MrmdYgGeshbnCLLjFohVSxfXOr+yKLo5wvHjVs0baBtx+mxQ00qP3V8JDNlXcXAnSd JH0TETyS/XGypl2pvOmgH9RsipurLG2yEpHh1uywasTeI99fuxG8P5jn68rFr1JYxnAB u7pA== X-Forwarded-Encrypted: i=1; AJvYcCWHBliXWXv6hjha/BZA4c4HJQMZlsq5GYyqJrYWDA2s0+r01p4Sr2hX8rJmWEevaiYooQvRYBCV3hfEzUo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxb532NUYK7nZfGuNTFWBKDuxHdpshdMimiRnpnsFR3XOtZDX8y b9aNUXF+HoJ1bZhwGgNE4SCm7yYcAfsUVIWF3LsVtUJJSrFWQwKtf4h8rWfQklGDlyy5Pwy6E+A = X-Google-Smtp-Source: AGHT+IEex+DoUGm8txDsQ+O5LFK9oysSR8094coj0M6PtiSGgzitE5xIRuCfwOw8ppjTuKj2ETwuhQ== X-Received: by 2002:a0c:f413:0:b0:6d3:5187:bcf8 with SMTP id 6a1803df08f44-6d3edcdc541mr30747576d6.17.1731611451781; Thu, 14 Nov 2024 11:10:51 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:51 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:36 +0000 Subject: [PATCH v15 07/19] media: uvcvideo: refactor uvc_ioctl_g_ext_ctrls Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-7-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 We want to support fetching the min and max values with g_ext_ctrls, this patch is a preparation for that. Instead of abusing uvc_query_v4l2_ctrl(), add an extra parameter to uvc_ctrl_get, so it can support fetching the default value. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 21 ++++++++++++++++++--- drivers/media/usb/uvc/uvc_v4l2.c | 28 +++++++++++----------------- drivers/media/usb/uvc/uvcvideo.h | 3 ++- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index c975e0ab479b..d6afa131a5e1 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1902,8 +1902,8 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int roll= back, return ret; } =20 -int uvc_ctrl_get(struct uvc_video_chain *chain, - struct v4l2_ext_control *xctrl) +int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, + struct v4l2_ext_control *xctrl) { struct uvc_control *ctrl; struct uvc_control_mapping *mapping; @@ -1915,7 +1915,22 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, if (ctrl =3D=3D NULL) return -EINVAL; =20 - return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); + switch (which) { + case V4L2_CTRL_WHICH_CUR_VAL: + return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); + case V4L2_CTRL_WHICH_DEF_VAL: + if (!ctrl->cached) { + int ret =3D uvc_ctrl_populate_cache(chain, ctrl); + + if (ret < 0) + return ret; + } + xctrl->value =3D mapping->get(mapping, UVC_GET_DEF, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); + return 0; + } + + return -EINVAL; } =20 int uvc_ctrl_set(struct uvc_fh *handle, diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 97c5407f6603..02fd5cbc3474 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1078,34 +1078,28 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file,= void *fh, struct uvc_video_chain *chain =3D handle->chain; struct v4l2_ext_control *ctrl =3D ctrls->controls; unsigned int i; + u32 which; int ret; =20 + switch (ctrls->which) { + case V4L2_CTRL_WHICH_DEF_VAL: + case V4L2_CTRL_WHICH_CUR_VAL: + which =3D ctrls->which; + break; + default: + which =3D V4L2_CTRL_WHICH_CUR_VAL; + } + ret =3D uvc_ctrl_check_access(chain, ctrls, VIDIOC_G_EXT_CTRLS); if (ret < 0) return ret; =20 - if (ctrls->which =3D=3D V4L2_CTRL_WHICH_DEF_VAL) { - for (i =3D 0; i < ctrls->count; ++ctrl, ++i) { - struct v4l2_queryctrl qc =3D { .id =3D ctrl->id }; - - ret =3D uvc_query_v4l2_ctrl(chain, &qc); - if (ret < 0) { - ctrls->error_idx =3D i; - return ret; - } - - ctrl->value =3D qc.default_value; - } - - return 0; - } - ret =3D uvc_ctrl_begin(chain); if (ret < 0) return ret; =20 for (i =3D 0; i < ctrls->count; ++ctrl, ++i) { - ret =3D uvc_ctrl_get(chain, ctrl); + ret =3D uvc_ctrl_get(chain, which, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); ctrls->error_idx =3D i; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 07f9921d83f2..6ebaabd11443 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -788,7 +788,8 @@ static inline int uvc_ctrl_rollback(struct uvc_fh *hand= le) return __uvc_ctrl_commit(handle, 1, NULL); } =20 -int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *x= ctrl); +int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, + struct v4l2_ext_control *xctrl); int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl); int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, const struct v4l2_ext_controls *ctrls, --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBA241AC448 for ; Thu, 14 Nov 2024 19:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611455; cv=none; b=OBe2qxLjEPY31C6qORwEqELr/2KzplAwPte3KEKOYYtIx16a5z2a1rqSpm9Y+xqiKLaeOnUCI4LQnoQk7+6zaKb29OTxDeOpNWK9vDvt98TbuqcIyC9JpI41YoZl+r1segJjXVWTksSK/D0qA4iIvz00NmyTVQeIwrzrLPaPQZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611455; c=relaxed/simple; bh=WuLUGkHs5rzPTrMYeFD9MhMpg+rW/hjaacAF210Zlvc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HIDa6SXEUxZ1NuVmW8tCpzN5m1noUV3ZKis4b/wVrLJyaA4DqtuplkWVdmcfcPUVTHBCRfO0Cu6Z5G4T6gqyGLWNUP9LsUalWjKfmj7A7ZGLE9WQbzCmbkORNLfZ1eAoKtAQJxwr2N16BnACqJ7muJ6cK+bg4gVZD7yIlDu+zp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Wi9nDRUG; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Wi9nDRUG" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6d3f733bbfbso3482926d6.0 for ; Thu, 14 Nov 2024 11:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611452; x=1732216252; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Agd78fl9Wg05tfWj8TXE/qjuiAxKCZ/bzWF7jfaD9AQ=; b=Wi9nDRUGygxIy2h9iFUZPS+/9jSzndUdZMiRzz6bYdKMnxYrBb6yIH5vJa1GlWYoBs yhxx5EvC2TLKr+zVmJMmC2RVL0fggmukurTKf1TxAJMUtGshTxECtjRooJztzGmeW8gR c8FxR+GjREE6aCViOLxKaUirTgg5gIPpMcXzo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611452; x=1732216252; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Agd78fl9Wg05tfWj8TXE/qjuiAxKCZ/bzWF7jfaD9AQ=; b=MsI62i8its1hNW+I27PavCUOcYFouJlXJpvk0v8jsAb12L2M8C7BpvlRzrbvzyKGlL lMVgV0eMW6hkc/Uz3TAPZQRoVW3VeRXM1Z3/1B3Ss5sQeBCwQZ9KO5IkNHGetPCcjP6P FyVOALePwEaY8ozLmonSOBcE6qOTRX698qegdHOhc8WAuRgm/WNmc6ZLO0ioLvRRkD+S fAhPXuxleTu80PpxMISHsriMYb84bhCTVKdHgnXGbFY4sEaMfsfumA6kCictMh9aMeB3 s9GbMpEF0VlKs2+Jtmg6RMkF4yirTvMZbXVfRTdiq3gN4QriarD07RsIQDW+xIFiYc+f 0I/w== X-Forwarded-Encrypted: i=1; AJvYcCX11jGBOV6ZvDDkcLfZADr/My5zDOFPXO02p+u9RZD5yplVYOBNFC4pPl9QEwY9iWbWuh9ZYOZG1NbJylU=@vger.kernel.org X-Gm-Message-State: AOJu0YylrOWlk8EDbdTHijWA5dZ6gvkmkgDqbwfIoms54Ybm6Z45Wk63 Pb3ZStZwvOf62rZ+8d/ARnp2YXf5+1dVs+Oqg0xsdIkjdLzBDCjylrRnwMa4iA== X-Google-Smtp-Source: AGHT+IGfGZ77XmRsvM5pDShNqOVcnKjpwCHBu8ODcL423ifRxyF1TlWSXvxwnSO8pYYbWRznBIZQ6g== X-Received: by 2002:a05:6214:418e:b0:6cb:e632:a059 with SMTP id 6a1803df08f44-6d39e1f66b9mr323111656d6.49.1731611452695; Thu, 14 Nov 2024 11:10:52 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:52 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:37 +0000 Subject: [PATCH v15 08/19] media: uvcvideo: uvc_ioctl_(g|s)_ext_ctrls: handle NoP case Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-8-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 If nothing needs to be done. Exit early. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 02fd5cbc3474..65dbb53b1e75 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1081,6 +1081,9 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, v= oid *fh, u32 which; int ret; =20 + if (!ctrls->count) + return 0; + switch (ctrls->which) { case V4L2_CTRL_WHICH_DEF_VAL: case V4L2_CTRL_WHICH_CUR_VAL: @@ -1121,6 +1124,9 @@ static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *h= andle, unsigned int i; int ret; =20 + if (!ctrls->count) + return 0; + ret =3D uvc_ctrl_check_access(chain, ctrls, ioctl); if (ret < 0) return ret; --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE6741AD403 for ; Thu, 14 Nov 2024 19:10:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611457; cv=none; b=HtjVNu+KicXScksqYEMX6r2TcS/Rh8AoXlGoQ7RCfoBKp+9vEuZrOuIdO4z4udI17qG6C6+JXHqeOqVkTEdFQDckI2ql9T9g2AgaSaLeZ5361GwKglDVc23qGVb5WrdEHhGJL2LlF+SgyznnxcsvDrhShfygQCuCQehKqYn4xYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611457; c=relaxed/simple; bh=CcDWrBfsaMLxkzXmP4x1HP5oXQZtluzal3euucPdDoc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EbQ4AeAO/7yS1U6OINo7UZ0swncdRE7s7zxZGD4Pb72yrDQa3MGdz7pUwu/dCm+BHDaegiwHHz2AV3MaVeQ1l4rrFMvn+RImryxysnSMrL4xozrbUMKI4onMEE0jq53Z2iJuWpnsU+BrV+BsCLFOqdxBYbk8Mi4jFAfaZpnygNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=RFM9QTve; arc=none smtp.client-ip=209.85.219.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RFM9QTve" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6cbceb321b3so6653396d6.3 for ; Thu, 14 Nov 2024 11:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611454; x=1732216254; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=k5QFrzTYHuM008uMGaRoTWTjBfLTnP/MUjY+9LgVTI4=; b=RFM9QTvekcWD8TDCh+zuKEBNy31fMIWieLNlEMuHiDGiFYx0gNn8Un65P3B3fIMAxq iZnc+wsalCu8opeSSneP6Ovjoz1e6tw1BX7TyIbMS0SOcA8r2W8f5REqrOmmZEMDowVK tKsyDG4/L5fXdclTvWKDUDAVMPe1gjVQUith0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611454; x=1732216254; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k5QFrzTYHuM008uMGaRoTWTjBfLTnP/MUjY+9LgVTI4=; b=ocmm7BaQfs0EYqj+7/4IxwNrI4k5MqDJ9Z1aQMUYNeHdY2qLNio27jPGwtDbjqLaiS remedhAhpBguxQ+g7XBS8rOh4ufqXG8gKJ2gogSzVs1Nv/9S5ZIVElpu8/NNiwyJSnCx cPCGshl72uGDyngTxUoz7hdCn5sgOFGQaToQYpj6qFpwZ9Ixz5ynvwa7YiSt6paAwkPG vXkkimEpTAZjt45QjZ5+Pj9davUqSeFnvdLlpgKuXQC8/AvwryrXtCu+jydbx4A3/GCJ vBUxE+94owDAVwRkP4D6fjJ8iEAyLeeTBv0SUjEqaYeytKjl4y0OxOfM1hu3KLh1QPEa Huiw== X-Forwarded-Encrypted: i=1; AJvYcCVzZEVPveYsyxI6vPR0LlqFPJUE3qIidxOmYOAiREeO8jERjPIUmw2KsBPexsapN3ggu2U+owpByG+J3os=@vger.kernel.org X-Gm-Message-State: AOJu0YziLmrK9/aM7BgPC7aP8zXq0HMM3PPb2iS/VB1bXs6GHlcApXV9 wL+EO27En3t5LHCYAWSZXTYw+NVTyMkk2HSH7y6YcEM1lU+hsArHAT3lx7Vajg== X-Google-Smtp-Source: AGHT+IHc1mJ8L1dvVSev0Kq3FueJOT58g/fRCjBWmQ8lVDbmTXKfbuzypNjXpgw3Yse3KOc/8nvo4g== X-Received: by 2002:a05:6214:310d:b0:6ce:26c3:c6e6 with SMTP id 6a1803df08f44-6d39e1ca982mr344624376d6.40.1731611453649; Thu, 14 Nov 2024 11:10:53 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:53 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:38 +0000 Subject: [PATCH v15 09/19] media: uvcvideo: Support any size for mapping get/set Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-9-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Right now, we only support mappings for v4l2 controls with a max size of s32. This patch modifies the prototype of get/set so it can support any size. This is done to prepare for compound controls. Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 183 +++++++++++++++++++++++++++--------= ---- drivers/media/usb/uvc/uvcvideo.h | 8 +- 2 files changed, 130 insertions(+), 61 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index d6afa131a5e1..6d5167eb368d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -367,6 +367,22 @@ static const u32 uvc_control_classes[] =3D { =20 static const int exposure_auto_mapping[] =3D { 2, 1, 4, 8 }; =20 +static s32 uvc_mapping_get_s32(struct uvc_control_mapping *mapping, + u8 query, const void *data_in) +{ + s32 data_out; + + mapping->get(mapping, query, data_in, sizeof(data_out), &data_out); + + return data_out; +} + +static void uvc_mapping_set_s32(struct uvc_control_mapping *mapping, + s32 data_in, void *data_out) +{ + mapping->set(mapping, sizeof(data_in), &data_in, data_out); +} + /* * This function translates the V4L2 menu index @idx, as exposed to usersp= ace as * the V4L2 control value, to the corresponding UVC control value used by = the @@ -405,58 +421,93 @@ uvc_mapping_get_menu_name(const struct uvc_control_ma= pping *mapping, u32 idx) return v4l2_ctrl_get_menu(mapping->id)[idx]; } =20 -static s32 uvc_ctrl_get_zoom(struct uvc_control_mapping *mapping, - u8 query, const u8 *data) +static int uvc_ctrl_get_zoom(struct uvc_control_mapping *mapping, u8 query, + const void *uvc_in, size_t v4l2_size, + void *v4l2_out) { - s8 zoom =3D (s8)data[0]; + u8 value =3D ((u8 *)uvc_in)[2]; + s8 sign =3D ((s8 *)uvc_in)[0]; + s32 *out =3D v4l2_out; + + if (WARN_ON(v4l2_size !=3D sizeof(s32))) + return -EINVAL; =20 switch (query) { case UVC_GET_CUR: - return (zoom =3D=3D 0) ? 0 : (zoom > 0 ? data[2] : -data[2]); + *out =3D (sign =3D=3D 0) ? 0 : (sign > 0 ? value : -value); + return 0; =20 case UVC_GET_MIN: case UVC_GET_MAX: case UVC_GET_RES: case UVC_GET_DEF: default: - return data[2]; + *out =3D value; + return 0; } } =20 -static void uvc_ctrl_set_zoom(struct uvc_control_mapping *mapping, - s32 value, u8 *data) +static int uvc_ctrl_set_zoom(struct uvc_control_mapping *mapping, + size_t v4l2_size, const void *v4l2_in, + void *uvc_out) { - data[0] =3D value =3D=3D 0 ? 0 : (value > 0) ? 1 : 0xff; - data[2] =3D min((int)abs(value), 0xff); + u8 *out =3D uvc_out; + s32 value; + + if (WARN_ON(v4l2_size !=3D sizeof(s32))) + return -EINVAL; + + value =3D *(u32 *)v4l2_in; + out[0] =3D value =3D=3D 0 ? 0 : (value > 0) ? 1 : 0xff; + out[2] =3D min_t(int, abs(value), 0xff); + + return 0; } =20 -static s32 uvc_ctrl_get_rel_speed(struct uvc_control_mapping *mapping, - u8 query, const u8 *data) +static int uvc_ctrl_get_rel_speed(struct uvc_control_mapping *mapping, + u8 query, const void *uvc_in, + size_t v4l2_size, void *v4l2_out) { unsigned int first =3D mapping->offset / 8; - s8 rel =3D (s8)data[first]; + u8 value =3D ((u8 *)uvc_in)[first + 1]; + s8 sign =3D ((s8 *)uvc_in)[first]; + s32 *out =3D v4l2_out; + + if (WARN_ON(v4l2_size !=3D sizeof(s32))) + return -EINVAL; =20 switch (query) { case UVC_GET_CUR: - return (rel =3D=3D 0) ? 0 : (rel > 0 ? data[first+1] - : -data[first+1]); + *out =3D (sign =3D=3D 0) ? 0 : (sign > 0 ? value : -value); + return 0; case UVC_GET_MIN: - return -data[first+1]; + *out =3D -value; + return 0; case UVC_GET_MAX: case UVC_GET_RES: case UVC_GET_DEF: default: - return data[first+1]; + *out =3D value; + return 0; } } =20 -static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, - s32 value, u8 *data) +static int uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, + size_t v4l2_size, const void *v4l2_in, + void *uvc_out) { unsigned int first =3D mapping->offset / 8; + u8 *out =3D uvc_out; + s32 value; + + if (WARN_ON(v4l2_size !=3D sizeof(s32))) + return -EINVAL; =20 - data[first] =3D value =3D=3D 0 ? 0 : (value > 0) ? 1 : 0xff; - data[first+1] =3D min_t(int, abs(value), 0xff); + value =3D *(u32 *)v4l2_in; + out[first] =3D value =3D=3D 0 ? 0 : (value > 0) ? 1 : 0xff; + out[first + 1] =3D min_t(int, abs(value), 0xff); + + return 0; } =20 static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limite= d =3D { @@ -887,14 +938,20 @@ static s32 uvc_menu_to_v4l2_menu(struct uvc_control_m= apping *mapping, s32 val) * a signed 32bit integer. Sign extension will be performed if the mapping * references a signed data type. */ -static s32 uvc_get_le_value(struct uvc_control_mapping *mapping, - u8 query, const u8 *data) +static int uvc_get_le_value(struct uvc_control_mapping *mapping, + u8 query, const void *uvc_in, size_t v4l2_size, + void *v4l2_out) { - int bits =3D mapping->size; int offset =3D mapping->offset; + int bits =3D mapping->size; + const u8 *data =3D uvc_in; + s32 *out =3D v4l2_out; s32 value =3D 0; u8 mask; =20 + if (WARN_ON(v4l2_size !=3D sizeof(s32))) + return -EINVAL; + data +=3D offset / 8; offset &=3D 7; mask =3D ((1LL << bits) - 1) << offset; @@ -916,29 +973,40 @@ static s32 uvc_get_le_value(struct uvc_control_mappin= g *mapping, value |=3D -(value & (1 << (mapping->size - 1))); =20 /* If it is a menu, convert from uvc to v4l2. */ - if (mapping->v4l2_type !=3D V4L2_CTRL_TYPE_MENU) - return value; + if (mapping->v4l2_type !=3D V4L2_CTRL_TYPE_MENU) { + *out =3D value; + return 0; + } =20 switch (query) { case UVC_GET_CUR: case UVC_GET_DEF: - return uvc_menu_to_v4l2_menu(mapping, value); + *out =3D uvc_menu_to_v4l2_menu(mapping, value); + return 0; } =20 - return value; + *out =3D value; + return 0; } =20 /* * Set the bit string specified by mapping->offset and mapping->size * in the little-endian data stored at 'data' to the value 'value'. */ -static void uvc_set_le_value(struct uvc_control_mapping *mapping, - s32 value, u8 *data) +static int uvc_set_le_value(struct uvc_control_mapping *mapping, + size_t v4l2_size, const void *v4l2_in, + void *uvc_out) { - int bits =3D mapping->size; int offset =3D mapping->offset; + int bits =3D mapping->size; + u8 *data =3D uvc_out; + s32 value; u8 mask; =20 + if (WARN_ON(v4l2_size !=3D sizeof(s32))) + return -EINVAL; + + value =3D *(s32 *)v4l2_in; if (mapping->v4l2_type =3D=3D V4L2_CTRL_TYPE_MENU) value =3D uvc_mapping_get_menu_value(mapping, value); /* @@ -960,6 +1028,8 @@ static void uvc_set_le_value(struct uvc_control_mappin= g *mapping, bits -=3D 8 - offset; offset =3D 0; } + + return 0; } =20 /* ------------------------------------------------------------------------ @@ -1141,8 +1211,8 @@ static int __uvc_ctrl_get(struct uvc_video_chain *cha= in, if (ret < 0) return ret; =20 - *value =3D mapping->get(mapping, UVC_GET_CUR, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + *value =3D uvc_mapping_get_s32(mapping, UVC_GET_CUR, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); =20 return 0; } @@ -1275,12 +1345,12 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *= ctrl, * as supported. */ if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) - return mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + return uvc_mapping_get_s32(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); =20 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) - return mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + return uvc_mapping_get_s32(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); =20 return ~0; } @@ -1324,10 +1394,9 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_ch= ain *chain, return ret; } =20 - if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) { - v4l2_ctrl->default_value =3D mapping->get(mapping, UVC_GET_DEF, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); - } + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) + v4l2_ctrl->default_value =3D uvc_mapping_get_s32(mapping, + UVC_GET_DEF, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); =20 switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_MENU: @@ -1359,16 +1428,16 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_c= hain *chain, } =20 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) - v4l2_ctrl->minimum =3D mapping->get(mapping, UVC_GET_MIN, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + v4l2_ctrl->minimum =3D uvc_mapping_get_s32(mapping, UVC_GET_MIN, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); =20 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) - v4l2_ctrl->maximum =3D mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + v4l2_ctrl->maximum =3D uvc_mapping_get_s32(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); =20 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) - v4l2_ctrl->step =3D mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + v4l2_ctrl->step =3D uvc_mapping_get_s32(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); =20 return 0; } @@ -1581,7 +1650,7 @@ void uvc_ctrl_status_event(struct uvc_video_chain *ch= ain, ctrl->handle =3D NULL; =20 list_for_each_entry(mapping, &ctrl->info.mappings, list) { - s32 value =3D mapping->get(mapping, UVC_GET_CUR, data); + s32 value =3D uvc_mapping_get_s32(mapping, UVC_GET_CUR, data); =20 /* * handle may be NULL here if the device sends auto-update @@ -1925,8 +1994,8 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 w= hich, if (ret < 0) return ret; } - xctrl->value =3D mapping->get(mapping, UVC_GET_DEF, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); + xctrl->value =3D uvc_mapping_get_s32(mapping, UVC_GET_DEF, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); return 0; } =20 @@ -1963,12 +2032,12 @@ int uvc_ctrl_set(struct uvc_fh *handle, return ret; } =20 - min =3D mapping->get(mapping, UVC_GET_MIN, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); - max =3D mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); - step =3D mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + min =3D uvc_mapping_get_s32(mapping, UVC_GET_MIN, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + max =3D uvc_mapping_get_s32(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + step =3D uvc_mapping_get_s32(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); if (step =3D=3D 0) step =3D 1; =20 @@ -2047,8 +2116,8 @@ int uvc_ctrl_set(struct uvc_fh *handle, ctrl->info.size); } =20 - mapping->set(mapping, value, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + uvc_mapping_set_s32(mapping, value, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); =20 if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) ctrl->handle =3D handle; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 6ebaabd11443..3d32a56c5ff8 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -131,10 +131,10 @@ struct uvc_control_mapping { const struct uvc_control_mapping *(*filter_mapping) (struct uvc_video_chain *chain, struct uvc_control *ctrl); - s32 (*get)(struct uvc_control_mapping *mapping, u8 query, - const u8 *data); - void (*set)(struct uvc_control_mapping *mapping, s32 value, - u8 *data); + int (*get)(struct uvc_control_mapping *mapping, u8 query, + const void *uvc_in, size_t v4l2_size, void *v4l2_out); + int (*set)(struct uvc_control_mapping *mapping, size_t v4l2_size, + const void *v4l2_in, void *uvc_out); }; =20 struct uvc_control { --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 059AF1AF0AB for ; Thu, 14 Nov 2024 19:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611457; cv=none; b=L+q2zQHqFnggizzCki30b8X38PSlzdnKGms5+Lliu7JNX+BXanea5Kc4f1hsgMbsvDZUAXGgbA69sT8La6/l0P5nbCYW7XtKbHzSUJJJWcEsprAxDqhujRWksAzl2ffujrRD09Gbe/xWh8E/FRLMyDoIAXMXqvMHNqZSf7cblAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611457; c=relaxed/simple; bh=eEpxjAmbwD3Lt+gRDs1Am6dF+cKdoldhzE/k4zEeBtQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nsu97MHwM8gR1+wKOobixMtG8xywFP0c2OuvzlCGemip5vCm4gDoevM+ol0RHVCIfBEuPXbjZgAzZfNXxug0Rd0UAL2GpzrTcJMaLUtORu8W/OOGCA7bKSjVaqaOiPnTh6Fui1BAxosbEqQJVg+lKbzH5SbbpLG7TARLUDiCbf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=njsaxu8/; arc=none smtp.client-ip=209.85.219.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="njsaxu8/" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d3f64df14aso4105956d6.1 for ; Thu, 14 Nov 2024 11:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611455; x=1732216255; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zJbE2HWSb90CvyoZHkq71MDXLaiW+wPC8fPWnyVZD4E=; b=njsaxu8/gMz6dHHEwUP5vhf4ogLr9un9Am0HdzZG7ldwhAcb5jLWLGLD3XyQh+RqhJ Ltj0oLG4rnLlhFPYZzog3me/SgItAqOpR7uFCjbev2ZYgUrafyhTsiMZgXAENFnWzegW upFYjZ4jrkGwIRxpPa9sKfl7iZ/40XCkXgmWM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611455; x=1732216255; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zJbE2HWSb90CvyoZHkq71MDXLaiW+wPC8fPWnyVZD4E=; b=jM/81UqpHUcnQAm3RKGrihtXJRpOY1teOrdnVSdFmJxZIYW7N2HFY05rLpZm2E5gW7 cYNDX36jNB4gg5zeyMn311QDdrwNrRSqit/dYQLSGGrIixArHrl+ll0rNfCM08aug5t5 zl5Qdo231jFrEZmlUzLQgILB/cHVPMLKFjT02tgLT2VbP95fAia12nWPQAa0AtRVhBQ7 VV1ib5jO+vCYir9a6BZHr1fwAFP8DVrsGmSjloZZmW1JUaqXT4kqHyjVw4QVzVLjisNm pIdC5VC86iWkjmf+FwMY/1bAmCclxI4k10CDeoQvT/PGqxuZXuH//4wAOaO+Rfz66Lqq QIHQ== X-Forwarded-Encrypted: i=1; AJvYcCWpyZrJik3PQ74KyvuH/3uTNPvUpWLmywTWdvAFH4es6dLuJLn0RkwTHZYRDKx4Yk3TQ8WvRKmigezusl4=@vger.kernel.org X-Gm-Message-State: AOJu0YxI8zfju2W0OFWh2jqHDQ7x8v5Nqj6+YpkhpelklByy234UguMj wn8qbFsge6v/039cvnOE2Ma9/H8qCv2uheN+rEJMeFmiyoZ4pcndgvUAF/Tamw== X-Google-Smtp-Source: AGHT+IEvcPAJuJO2mAlNO/pEgGAbnA4uxX9GYiqUlzz3FMhGvdAEvXWG55u9OyHeUYdgEK9DLzdemw== X-Received: by 2002:a0c:9e81:0:b0:6d3:fa75:e9ed with SMTP id 6a1803df08f44-6d3fa75ec86mr4480876d6.41.1731611455074; Thu, 14 Nov 2024 11:10:55 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:54 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:39 +0000 Subject: [PATCH v15 10/19] media: uvcvideo: Factor out clamping from uvc_ctrl_set Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-10-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Move the logic to a separated function. Do not expect any change. This is a preparation for supporting compound controls. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 82 +++++++++++++++++++++---------------= ---- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 6d5167eb368d..893d12cd3f90 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2002,28 +2002,17 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32= which, return -EINVAL; } =20 -int uvc_ctrl_set(struct uvc_fh *handle, - struct v4l2_ext_control *xctrl) +static int uvc_ctrl_clamp(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + s32 *value_in_out) { - struct uvc_video_chain *chain =3D handle->chain; - struct uvc_control *ctrl; - struct uvc_control_mapping *mapping; - s32 value; + s32 value =3D *value_in_out; u32 step; s32 min; s32 max; int ret; =20 - if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >=3D 0) - return -EACCES; - - ctrl =3D uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl =3D=3D NULL) - return -EINVAL; - if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) - return -EACCES; - - /* Clamp out of range values. */ switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_INTEGER: if (!ctrl->cached) { @@ -2041,14 +2030,13 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (step =3D=3D 0) step =3D 1; =20 - xctrl->value =3D min + DIV_ROUND_CLOSEST((u32)(xctrl->value - min), - step) * step; + value =3D min + DIV_ROUND_CLOSEST((u32)(value - min), step) * step; if (mapping->data_type =3D=3D UVC_CTRL_DATA_TYPE_SIGNED) - xctrl->value =3D clamp(xctrl->value, min, max); + value =3D clamp(value, min, max); else - xctrl->value =3D clamp_t(u32, xctrl->value, min, max); - value =3D xctrl->value; - break; + value =3D clamp_t(u32, value, min, max); + *value_in_out =3D value; + return 0; =20 case V4L2_CTRL_TYPE_BITMASK: if (!ctrl->cached) { @@ -2057,21 +2045,20 @@ int uvc_ctrl_set(struct uvc_fh *handle, return ret; } =20 - xctrl->value &=3D uvc_get_ctrl_bitmap(ctrl, mapping); - value =3D xctrl->value; - break; + value &=3D uvc_get_ctrl_bitmap(ctrl, mapping); + *value_in_out =3D value; + return 0; =20 case V4L2_CTRL_TYPE_BOOLEAN: - xctrl->value =3D clamp(xctrl->value, 0, 1); - value =3D xctrl->value; - break; + *value_in_out =3D clamp(value, 0, 1); + return 0; =20 case V4L2_CTRL_TYPE_MENU: - if (xctrl->value < (ffs(mapping->menu_mask) - 1) || - xctrl->value > (fls(mapping->menu_mask) - 1)) + if (value < (ffs(mapping->menu_mask) - 1) || + value > (fls(mapping->menu_mask) - 1)) return -ERANGE; =20 - if (!test_bit(xctrl->value, &mapping->menu_mask)) + if (!test_bit(value, &mapping->menu_mask)) return -EINVAL; =20 /* @@ -2079,8 +2066,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, * UVC controls that support it. */ if (mapping->data_type =3D=3D UVC_CTRL_DATA_TYPE_BITMASK) { - int val =3D uvc_mapping_get_menu_value(mapping, - xctrl->value); + int val =3D uvc_mapping_get_menu_value(mapping, value); if (!ctrl->cached) { ret =3D uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) @@ -2090,14 +2076,34 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & val)) return -EINVAL; } - value =3D xctrl->value; - break; + return 0; =20 default: - value =3D xctrl->value; - break; + return 0; } =20 + return 0; +} + +int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl) +{ + struct uvc_video_chain *chain =3D handle->chain; + struct uvc_control_mapping *mapping; + struct uvc_control *ctrl; + int ret; + + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >=3D 0) + return -EACCES; + + ctrl =3D uvc_find_control(chain, xctrl->id, &mapping); + if (!ctrl) + return -EINVAL; + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) + return -EACCES; + + ret =3D uvc_ctrl_clamp(chain, ctrl, mapping, &xctrl->value); + if (ret) + return ret; /* * If the mapping doesn't span the whole UVC control, the current value * needs to be loaded from the device to perform the read-modify-write @@ -2116,7 +2122,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, ctrl->info.size); } =20 - uvc_mapping_set_s32(mapping, value, + uvc_mapping_set_s32(mapping, xctrl->value, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); =20 if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAF2319F13C for ; Thu, 14 Nov 2024 19:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611459; cv=none; b=WnAOEhwi+6z4W+5dvudmgj1bKJfYHFG6T5Lwg8Eff8Cxclb3M5vun2SDS2MtxpfNejW+CeYquAXTv53q7CnXKeAs/yVfbP5hLTV0FnCjWbrer44bvbI4wWVz6+1vKGSuGOQOH8/LaaKZB4uG+8xZhETFcEt6kjO7bMW9G0JP8Jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611459; c=relaxed/simple; bh=oq440kgPkAQhG9oi3yrxId3dsdrPC0s/a6e3SBTmY9I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sqKHFoF5DwW5OVhuhxSZ86tWJNucL8zgbWxw6n+6/tf9acv9W5agUcpjHgdYmmHqwDgBbL7oj5iNOXIeIz/x0MjJV5wG+7iUas9TtgeVmF/jqApDbBQkBh64arAz4RW0p8O2e930HHOH6m9GoRj6KyQn/DwFFSV5ltSuM5kFKnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=V+9cYduD; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V+9cYduD" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b1b224f6c6so57330085a.3 for ; Thu, 14 Nov 2024 11:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611456; x=1732216256; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fUNPuZP1461Q7ZURisQrbqS4YW2rP86ATE8dHXg5UnY=; b=V+9cYduD+mDiLI0Nwaf79aQzvIEKTxZjYvlbsJXn0KPQxwMlgtt9VZMjS1qNNoB6fe rF8NsUEoQeOM7u5xTHvujy42SEcMNUeim273T8x6DyyCXy4vkhepEbt998NkXK2/yl7A pOcIfb7VB9d+XGrmXAbqZpsgEDrRjB3jlDY1Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611456; x=1732216256; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fUNPuZP1461Q7ZURisQrbqS4YW2rP86ATE8dHXg5UnY=; b=Y5zeVH3ZVxYXvEHGrIvLg/yeQYsdBRr06TrNPyqMT9l+d6EGoT4I6DNzJ1+hpRiHi0 pCXBL/wmlTC75kw6WsdOrmjtoTbHwygovgOVxREoif7O0BjXaJWWCFRDZ92Ra3luXBFY T/OUSnTA831LS5YDFWCUtL9fpHGbcwMIrKCwyn/N2ccqzQi/nmdJvXpjLZZdAIVT8UPA vGKVXeTxjDKpwdKqMfAZqbdyjt6sQiYmR6C+0MYYtu0Er4ka2TTaqoInXPT0PUZbFtm4 XjkwvBbvtrdxjMgHVs6YHtrKzfuyU5NTesZQBomGeqfMP/sR8QxdawepOHdhsNV40wTB hrrQ== X-Forwarded-Encrypted: i=1; AJvYcCVfn78/HcHtSy4drolkaZgyEskNtxV9Ran3EjIBjEM5RDnM3e88LkBfGdqx5sU/AS56OTR0AuVTQo83KQo=@vger.kernel.org X-Gm-Message-State: AOJu0YwdSxIzgccCfW4TAsbACvktvqRz5lBwP7fR5Xn4jOy4661P5mv4 JId0/XdHZMEc8zrbubfP99+J28lUAjB0a2nsMXN2kp9Q+ERaXMHVyMvoZ0a2Wg== X-Google-Smtp-Source: AGHT+IG+L7MCCPunuQpdTHZAW3SSa7WlJBojBgUUn00gVEvYkzaXDKwAyHGPjRtQlCsfjqSPt192lw== X-Received: by 2002:a05:6214:398e:b0:6cb:832e:9267 with SMTP id 6a1803df08f44-6d3edca403emr33642486d6.7.1731611455939; Thu, 14 Nov 2024 11:10:55 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:55 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:40 +0000 Subject: [PATCH v15 11/19] media: uvcvideo: add support for compound controls Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-11-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao X-Mailer: b4 0.13.0 From: Yunke Cao This patch adds support for compound controls. This is required to support controls that cannot be represented with a s64 data, such as the Region of Interest. Signed-off-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 224 ++++++++++++++++++++++++++++++++---= ---- drivers/media/usb/uvc/uvcvideo.h | 5 + 2 files changed, 192 insertions(+), 37 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 893d12cd3f90..e51cd0a2228a 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -367,6 +367,11 @@ static const u32 uvc_control_classes[] =3D { =20 static const int exposure_auto_mapping[] =3D { 2, 1, 4, 8 }; =20 +static bool uvc_ctrl_mapping_is_compound(struct uvc_control_mapping *mappi= ng) +{ + return mapping->v4l2_type >=3D V4L2_CTRL_COMPOUND_TYPES; +} + static s32 uvc_mapping_get_s32(struct uvc_control_mapping *mapping, u8 query, const void *data_in) { @@ -1048,7 +1053,7 @@ static int uvc_entity_match_guid(const struct uvc_ent= ity *entity, =20 static void __uvc_find_control(struct uvc_entity *entity, u32 v4l2_id, struct uvc_control_mapping **mapping, struct uvc_control **control, - int next) + int next, int next_compound) { struct uvc_control *ctrl; struct uvc_control_mapping *map; @@ -1063,14 +1068,16 @@ static void __uvc_find_control(struct uvc_entity *e= ntity, u32 v4l2_id, continue; =20 list_for_each_entry(map, &ctrl->info.mappings, list) { - if ((map->id =3D=3D v4l2_id) && !next) { + if (map->id =3D=3D v4l2_id && !next && !next_compound) { *control =3D ctrl; *mapping =3D map; return; } =20 if ((*mapping =3D=3D NULL || (*mapping)->id > map->id) && - (map->id > v4l2_id) && next) { + (map->id > v4l2_id) && + (uvc_ctrl_mapping_is_compound(map) ? + next_compound : next)) { *control =3D ctrl; *mapping =3D map; } @@ -1084,6 +1091,7 @@ static struct uvc_control *uvc_find_control(struct uv= c_video_chain *chain, struct uvc_control *ctrl =3D NULL; struct uvc_entity *entity; int next =3D v4l2_id & V4L2_CTRL_FLAG_NEXT_CTRL; + int next_compound =3D v4l2_id & V4L2_CTRL_FLAG_NEXT_COMPOUND; =20 *mapping =3D NULL; =20 @@ -1092,12 +1100,13 @@ static struct uvc_control *uvc_find_control(struct = uvc_video_chain *chain, =20 /* Find the control. */ list_for_each_entry(entity, &chain->entities, chain) { - __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next); - if (ctrl && !next) + __uvc_find_control(entity, v4l2_id, mapping, &ctrl, next, + next_compound); + if (ctrl && !next && !next_compound) return ctrl; } =20 - if (ctrl =3D=3D NULL && !next) + if (!ctrl && !next && !next_compound) uvc_dbg(chain->dev, CONTROL, "Control 0x%08x not found\n", v4l2_id); =20 @@ -1220,7 +1229,8 @@ static int __uvc_ctrl_get(struct uvc_video_chain *cha= in, static int __uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_i= d, u32 found_id) { - bool find_next =3D req_id & V4L2_CTRL_FLAG_NEXT_CTRL; + bool find_next =3D req_id & + (V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND); unsigned int i; =20 req_id &=3D V4L2_CTRL_ID_MASK; @@ -1310,10 +1320,12 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *= chain, u32 v4l2_id, } =20 __uvc_find_control(ctrl->entity, mapping->master_id, &master_map, - &master_ctrl, 0); + &master_ctrl, 0, 0); =20 if (!master_ctrl || !(master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) return 0; + if (WARN_ON(uvc_ctrl_mapping_is_compound(master_map))) + return -EIO; =20 ret =3D __uvc_ctrl_get(chain, master_ctrl, master_map, &val); if (ret >=3D 0 && val !=3D mapping->master_manual) @@ -1377,10 +1389,15 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_c= hain *chain, =20 if (mapping->master_id) __uvc_find_control(ctrl->entity, mapping->master_id, - &master_map, &master_ctrl, 0); + &master_map, &master_ctrl, 0, 0); if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) { s32 val; - int ret =3D __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + int ret; + + if (WARN_ON(uvc_ctrl_mapping_is_compound(master_map))) + return -EIO; + + ret =3D __uvc_ctrl_get(chain, master_ctrl, master_map, &val); if (ret < 0) return ret; =20 @@ -1388,6 +1405,15 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_ch= ain *chain, v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_INACTIVE; } =20 + if (v4l2_ctrl->type >=3D V4L2_CTRL_COMPOUND_TYPES) { + v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_HAS_PAYLOAD; + v4l2_ctrl->default_value =3D 0; + v4l2_ctrl->minimum =3D 0; + v4l2_ctrl->maximum =3D 0; + v4l2_ctrl->step =3D 0; + return 0; + } + if (!ctrl->cached) { int ret =3D uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) @@ -1627,11 +1653,12 @@ static void uvc_ctrl_send_slave_event(struct uvc_vi= deo_chain *chain, u32 changes =3D V4L2_EVENT_CTRL_CH_FLAGS; s32 val =3D 0; =20 - __uvc_find_control(master->entity, slave_id, &mapping, &ctrl, 0); + __uvc_find_control(master->entity, slave_id, &mapping, &ctrl, 0, 0); if (ctrl =3D=3D NULL) return; =20 - if (__uvc_ctrl_get(chain, ctrl, mapping, &val) =3D=3D 0) + if (uvc_ctrl_mapping_is_compound(mapping) || + __uvc_ctrl_get(chain, ctrl, mapping, &val) =3D=3D 0) changes |=3D V4L2_EVENT_CTRL_CH_VALUE; =20 uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes); @@ -1650,7 +1677,12 @@ void uvc_ctrl_status_event(struct uvc_video_chain *c= hain, ctrl->handle =3D NULL; =20 list_for_each_entry(mapping, &ctrl->info.mappings, list) { - s32 value =3D uvc_mapping_get_s32(mapping, UVC_GET_CUR, data); + s32 value; + + if (uvc_ctrl_mapping_is_compound(mapping)) + value =3D 0; + else + value =3D uvc_mapping_get_s32(mapping, UVC_GET_CUR, data); =20 /* * handle may be NULL here if the device sends auto-update @@ -1736,6 +1768,7 @@ static void uvc_ctrl_send_events(struct uvc_fh *handl= e, =20 for (i =3D 0; i < xctrls_count; ++i) { u32 changes =3D V4L2_EVENT_CTRL_CH_VALUE; + s32 value; =20 ctrl =3D uvc_find_control(handle->chain, xctrls[i].id, &mapping); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) @@ -1760,6 +1793,10 @@ static void uvc_ctrl_send_events(struct uvc_fh *hand= le, slave_id); } =20 + if (uvc_ctrl_mapping_is_compound(mapping)) + value =3D 0; + else + value =3D xctrls[i].value; /* * If the master is being modified in the same transaction * flags may change too. @@ -1770,7 +1807,7 @@ static void uvc_ctrl_send_events(struct uvc_fh *handl= e, changes |=3D V4L2_EVENT_CTRL_CH_FLAGS; =20 uvc_ctrl_send_event(handle->chain, handle, ctrl, mapping, - xctrls[i].value, changes); + value, changes); } } =20 @@ -1802,7 +1839,8 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_= event *sev, unsigned elems) u32 changes =3D V4L2_EVENT_CTRL_CH_FLAGS; s32 val =3D 0; =20 - if (__uvc_ctrl_get(handle->chain, ctrl, mapping, &val) =3D=3D 0) + if (uvc_ctrl_mapping_is_compound(mapping) || + __uvc_ctrl_get(handle->chain, ctrl, mapping, &val) =3D=3D 0) changes |=3D V4L2_EVENT_CTRL_CH_VALUE; =20 uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, val, @@ -1935,7 +1973,7 @@ static int uvc_ctrl_find_ctrl_idx(struct uvc_entity *= entity, =20 for (i =3D 0; i < ctrls->count; i++) { __uvc_find_control(entity, ctrls->controls[i].id, &mapping, - &ctrl_found, 0); + &ctrl_found, 0, 0); if (uvc_control =3D=3D ctrl_found) return i; } @@ -1971,19 +2009,59 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int ro= llback, return ret; } =20 -int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, - struct v4l2_ext_control *xctrl) +static int uvc_mapping_get_xctrl_compound(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + u32 which, + struct v4l2_ext_control *xctrl) { - struct uvc_control *ctrl; - struct uvc_control_mapping *mapping; - - if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >=3D 0) - return -EACCES; + u8 *data __free(kfree) =3D NULL; + size_t size; + u8 query; + int ret; + int id; =20 - ctrl =3D uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl =3D=3D NULL) + switch (which) { + case V4L2_CTRL_WHICH_CUR_VAL: + ret =3D __uvc_ctrl_load_cur(chain, ctrl); + if (ret < 0) + return ret; + id =3D UVC_CTRL_DATA_CURRENT; + query =3D UVC_GET_CUR; + break; + case V4L2_CTRL_WHICH_DEF_VAL: + ret =3D uvc_ctrl_populate_cache(chain, ctrl); + if (ret < 0) + return ret; + id =3D UVC_CTRL_DATA_DEF; + query =3D UVC_GET_DEF; + break; + default: return -EINVAL; + } + + size =3D DIV_ROUND_UP(mapping->size, 8); + if (xctrl->size < size) { + xctrl->size =3D size; + return -ENOSPC; + } + + data =3D kmalloc(size, GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret =3D mapping->get(mapping, query, uvc_ctrl_data(ctrl, id), size, data); + if (ret < 0) + return ret; + + return copy_to_user(xctrl->ptr, data, size) ? -EFAULT : 0; +} =20 +static int uvc_mapping_get_xctrl_std(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + u32 which, struct v4l2_ext_control *xctrl) +{ switch (which) { case V4L2_CTRL_WHICH_CUR_VAL: return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); @@ -2002,6 +2080,33 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 = which, return -EINVAL; } =20 +static int uvc_mapping_get_xctrl(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + u32 which, struct v4l2_ext_control *xctrl) +{ + if (uvc_ctrl_mapping_is_compound(mapping)) + return uvc_mapping_get_xctrl_compound(chain, ctrl, mapping, + which, xctrl); + return uvc_mapping_get_xctrl_std(chain, ctrl, mapping, which, xctrl); +} + +int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, + struct v4l2_ext_control *xctrl) +{ + struct uvc_control *ctrl; + struct uvc_control_mapping *mapping; + + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >=3D 0) + return -EACCES; + + ctrl =3D uvc_find_control(chain, xctrl->id, &mapping); + if (!ctrl) + return -EINVAL; + + return uvc_mapping_get_xctrl(chain, ctrl, mapping, which, xctrl); +} + static int uvc_ctrl_clamp(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -2085,6 +2190,37 @@ static int uvc_ctrl_clamp(struct uvc_video_chain *ch= ain, return 0; } =20 +static int uvc_mapping_set_xctrl_compound(struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + struct v4l2_ext_control *xctrl) +{ + u8 *data __free(kfree) =3D NULL; + size_t size; + + size =3D DIV_ROUND_UP(mapping->size, 8); + if (xctrl->size !=3D size) + return -EINVAL; + + data =3D memdup_user(xctrl->ptr, size); + if (IS_ERR(data)) + return PTR_ERR(data); + + return mapping->set(mapping, size, data, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); +} + +static int uvc_mapping_set_xctrl(struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + struct v4l2_ext_control *xctrl) +{ + if (uvc_ctrl_mapping_is_compound(mapping)) + return uvc_mapping_set_xctrl_compound(ctrl, mapping, xctrl); + + uvc_mapping_set_s32(mapping, xctrl->value, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + return 0; +} + int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl) { struct uvc_video_chain *chain =3D handle->chain; @@ -2122,8 +2258,9 @@ int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_e= xt_control *xctrl) ctrl->info.size); } =20 - uvc_mapping_set_s32(mapping, xctrl->value, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + ret =3D uvc_mapping_set_xctrl(ctrl, mapping, xctrl); + if (ret) + return ret; =20 if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) ctrl->handle =3D handle; @@ -2501,6 +2638,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_ch= ain *chain, struct uvc_control_mapping *map; unsigned int size; unsigned int i; + int ret; =20 /* * Most mappings come from static kernel data, and need to be duplicated. @@ -2518,8 +2656,10 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_c= hain *chain, /* For UVCIOC_CTRL_MAP custom control */ if (mapping->name) { map->name =3D kstrdup(mapping->name, GFP_KERNEL); - if (!map->name) - goto err_nomem; + if (!map->name) { + ret =3D -ENOMEM; + goto free_mem; + } } =20 INIT_LIST_HEAD(&map->ev_subs); @@ -2529,21 +2669,31 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_= chain *chain, * fls(mapping->menu_mask); map->menu_mapping =3D kmemdup(mapping->menu_mapping, size, GFP_KERNEL); - if (!map->menu_mapping) - goto err_nomem; + if (!map->menu_mapping) { + ret =3D -ENOMEM; + goto free_mem; + } } if (mapping->menu_names && mapping->menu_mask) { size =3D sizeof(mapping->menu_names[0]) * fls(mapping->menu_mask); map->menu_names =3D kmemdup(mapping->menu_names, size, GFP_KERNEL); - if (!map->menu_names) - goto err_nomem; + if (!map->menu_names) { + ret =3D -ENOMEM; + goto free_mem; + } } =20 - if (map->get =3D=3D NULL) + if (uvc_ctrl_mapping_is_compound(map)) + if (WARN_ON(!map->set || !map->get)) { + ret =3D -EIO; + goto free_mem; + } + + if (!map->get) map->get =3D uvc_get_le_value; - if (map->set =3D=3D NULL) + if (!map->set) map->set =3D uvc_set_le_value; =20 for (i =3D 0; i < ARRAY_SIZE(uvc_control_classes); i++) { @@ -2561,12 +2711,12 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_= chain *chain, =20 return 0; =20 -err_nomem: +free_mem: kfree(map->menu_names); kfree(map->menu_mapping); kfree(map->name); kfree(map); - return -ENOMEM; + return ret; } =20 int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 3d32a56c5ff8..f429f325433b 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -115,7 +115,12 @@ struct uvc_control_mapping { u8 entity[16]; u8 selector; =20 + /* + * Size of the control data in the payload of the UVC control GET and + * SET requests, expressed in bits. + */ u8 size; + u8 offset; enum v4l2_ctrl_type v4l2_type; u32 data_type; --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAF7419F42F for ; Thu, 14 Nov 2024 19:10:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611460; cv=none; b=c5fPpj8U976eDkuQFrXIGP0XBCVZmmsEjtd2WbuN7XifUNK7MIcNu7hqrZ/J2poX7I9FTNvzWiTBvHy5JoF9lfHdo1ipN3cpQ6PtxUmZ1vqCSCaWIkFyK5jz0oFrUD/PvT8vLk03kANcTuQZMISTv4UX2mc/RMxwxm7G8YIXdbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611460; c=relaxed/simple; bh=GTSzb2cA6iQFUD2LVLPdIY84kmKQY+ou4DnZ+2EhUOw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l4MXGeuS4Gd04CsMjL2gk/bw/Y9zwZSOXqErAAtmid6/lp96KR84GKpDftRjc1dMB9momjSHle+tqNkz44uulC54UmWlynWsHKQoWk8IdVd/kYIkSPJ8R9lSjHfVsRd2Yx05AamTJbp3VSm+Qn7XbPQGsUlWjnnzJAI+dykREII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Gqi+yGAh; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Gqi+yGAh" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6d382664fadso5471226d6.2 for ; Thu, 14 Nov 2024 11:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611457; x=1732216257; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5zASJkExVzt3mz1dGZGb6YpVtR37par5ZxSQfpFLGtY=; b=Gqi+yGAhM2LqdtHWH811XnV+hAqDqK5dwBNWbFA8SUVMz55DsV2uRyAX4qJ4VQ/Zk/ OssuyR/KQhjnquiGC39u+FJF3jPNLWfaogRk6HyvB4cMzx60GuVwBx2YSjsACRbWuaSv mEUpapUskK6RkyHM4Xm1v0Mmlj6CSP8UletCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611457; x=1732216257; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5zASJkExVzt3mz1dGZGb6YpVtR37par5ZxSQfpFLGtY=; b=Cn0dimkbhqBvStVPCUAHbe24/9BXi6SN+XH/2PEgPs5gK8RsG7QExPTvhicFgbR22B 9lL3dnSaMOUG1QTWsYOjRNsVVbsgWUZIxgDdwSTOMgtHun2A06sXUKFqKYp507i5YhDK EBMh2xfE8+fffLj1NPU3DPO+QpER82MZC0omnVBfj2CcvepWJVlvL2LExkMPgU0uUOLc AePbD41+i3PyTMMoQMNHjD+B0uspW6yKl/xejJJQHfuaHM8+a0+S0066JwV5/5GfzXrI tPESvfrTizIs1KpZ+6Ob9rp0ej4vFMksQkgGgXwY3yPQ29kE+iHxdlbeICdDtG8Dk+P1 icvA== X-Forwarded-Encrypted: i=1; AJvYcCWQ/fN/dVTjSd/j2On2jMafiaQ2AwPHFrPcKC/eJv4GGWUq/N8T/kV8SwgN57dKdiNKmkVDqQCCofXYypM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1oW6HQSDsheJfq5gQ64hawyCuhTIUqDI3qgTJRpE2ODDH/jb1 ymenfl8EOLdiXL8xhYp6IznvUzQng0MBob9qs8eULNbbQqeZibyk723R0av0Uw== X-Google-Smtp-Source: AGHT+IFwQipG5MnSIrGPPQp4Ve+16Xv+jGuSrD7kyFyzdHnlGC/qJY1Unw7LCbkK+PWogHsT4KSLpQ== X-Received: by 2002:a05:6214:118b:b0:6d3:dcce:a2d3 with SMTP id 6a1803df08f44-6d3dccea322mr96855556d6.47.1731611456783; Thu, 14 Nov 2024 11:10:56 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:56 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:41 +0000 Subject: [PATCH v15 12/19] media: uvcvideo: Factor out query_boundaries from query_ctrl Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-12-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Split the function in two parts. queryctrl_boundaries will be used in future patches. No functional change expected from this patch. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 106 ++++++++++++++++++++++-------------= ---- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index e51cd0a2228a..b591d7fddc37 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1367,53 +1367,11 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *= ctrl, return ~0; } =20 -static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, - struct uvc_control *ctrl, - struct uvc_control_mapping *mapping, - struct v4l2_queryctrl *v4l2_ctrl) +static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + struct v4l2_queryctrl *v4l2_ctrl) { - struct uvc_control_mapping *master_map =3D NULL; - struct uvc_control *master_ctrl =3D NULL; - - memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); - v4l2_ctrl->id =3D mapping->id; - v4l2_ctrl->type =3D mapping->v4l2_type; - strscpy(v4l2_ctrl->name, uvc_map_get_name(mapping), - sizeof(v4l2_ctrl->name)); - v4l2_ctrl->flags =3D 0; - - if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) - v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_WRITE_ONLY; - if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) - v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; - - if (mapping->master_id) - __uvc_find_control(ctrl->entity, mapping->master_id, - &master_map, &master_ctrl, 0, 0); - if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) { - s32 val; - int ret; - - if (WARN_ON(uvc_ctrl_mapping_is_compound(master_map))) - return -EIO; - - ret =3D __uvc_ctrl_get(chain, master_ctrl, master_map, &val); - if (ret < 0) - return ret; - - if (val !=3D mapping->master_manual) - v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_INACTIVE; - } - - if (v4l2_ctrl->type >=3D V4L2_CTRL_COMPOUND_TYPES) { - v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_HAS_PAYLOAD; - v4l2_ctrl->default_value =3D 0; - v4l2_ctrl->minimum =3D 0; - v4l2_ctrl->maximum =3D 0; - v4l2_ctrl->step =3D 0; - return 0; - } - if (!ctrl->cached) { int ret =3D uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) @@ -1456,18 +1414,74 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_c= hain *chain, if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) v4l2_ctrl->minimum =3D uvc_mapping_get_s32(mapping, UVC_GET_MIN, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + else + v4l2_ctrl->minimum =3D 0; =20 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) v4l2_ctrl->maximum =3D uvc_mapping_get_s32(mapping, UVC_GET_MAX, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + else + v4l2_ctrl->maximum =3D 0; =20 if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) v4l2_ctrl->step =3D uvc_mapping_get_s32(mapping, UVC_GET_RES, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + else + v4l2_ctrl->step =3D 0; =20 return 0; } =20 +static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, + struct uvc_control *ctrl, + struct uvc_control_mapping *mapping, + struct v4l2_queryctrl *v4l2_ctrl) +{ + struct uvc_control_mapping *master_map =3D NULL; + struct uvc_control *master_ctrl =3D NULL; + + memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); + v4l2_ctrl->id =3D mapping->id; + v4l2_ctrl->type =3D mapping->v4l2_type; + strscpy(v4l2_ctrl->name, uvc_map_get_name(mapping), + sizeof(v4l2_ctrl->name)); + v4l2_ctrl->flags =3D 0; + + if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) + v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_WRITE_ONLY; + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) + v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + + if (mapping->master_id) + __uvc_find_control(ctrl->entity, mapping->master_id, + &master_map, &master_ctrl, 0, 0); + if (master_ctrl && (master_ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) { + s32 val; + int ret; + + if (WARN_ON(uvc_ctrl_mapping_is_compound(master_map))) + return -EIO; + + ret =3D __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + if (ret < 0) + return ret; + + if (val !=3D mapping->master_manual) + v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_INACTIVE; + } + + if (v4l2_ctrl->type >=3D V4L2_CTRL_COMPOUND_TYPES) { + v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_HAS_PAYLOAD; + v4l2_ctrl->default_value =3D 0; + v4l2_ctrl->minimum =3D 0; + v4l2_ctrl->maximum =3D 0; + v4l2_ctrl->step =3D 0; + return 0; + } + + return __uvc_queryctrl_boundaries(chain, ctrl, mapping, v4l2_ctrl); +} + int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct v4l2_queryctrl *v4l2_ctrl) { --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5D631B0F25 for ; Thu, 14 Nov 2024 19:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611461; cv=none; b=C/vJzugRgHC9bAZQZ+1HqGeNWnpOG/4WnMuHBRaMBqzO78eNcs50VgxU17oatx4+ND19KSEBzGVIZa5vExmz4LUbg389E1hB7LxqaSfk+c4Qp7a+ut4/bhO6XyppG31SqGROdDe+3MLZd9/oDQLy00R40IqCAgZlck29UJdWQ7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611461; c=relaxed/simple; bh=4aYM1mbytyfhEDw5uHRi4COv7820Z421epIB62xgYEY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PiVMImGC8tJPcrkygiHFaqk/oFNE017fUd0kMgXpDN52N9znD8BWs1Cqt3GN61IYem49QSCBiizB7tRoTMp3SBAvxmhXPFf+Euaqrz3xM6xL+D3VW0KymAo3ppJ9CZ9cua5C1GlNHfH8Mdpz/3Iy+LJe7bDtGEY0z4x/INBbobs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ALzoruBC; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ALzoruBC" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6cbe3e99680so5371316d6.3 for ; Thu, 14 Nov 2024 11:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611457; x=1732216257; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Z8MY237UnOQ4N6VPhfi4yBpSwxWA8VpuxHQS0Imk3bI=; b=ALzoruBCqhIzyK0bOZD085jdLnGIFt9QThX8E1RJ6DGqnD/7dFuMeGmogBdf/TvY7K 4JkX2v3nx8Dd1Y0flbjE8C4OS284bWzGQfh/5iNsHUcYF6NDrbF/vLAKiX3EhsuySFwl 0wlldB1YmM6Mwa3PgA0sPDftEthJVMXuLVKic= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611457; x=1732216257; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z8MY237UnOQ4N6VPhfi4yBpSwxWA8VpuxHQS0Imk3bI=; b=jvi4/eSpak4sAa2emmvPBO1pMukg8fYhKuG8CwO7wGRtA47acdpF0Z3BBTUQP6uPZx phzE0FHDNHFtNS/2uecEHoUPFh2cOGadHU2W/IMqe1Jjc6Rwlhi0WR0WF1VkyBCRcqHm F6DmS29D0rELj497JyIc3wQ/orOf3kCASzMENW4Bos6SQF8az9m5FLX6Dgh4TRDIZKFv XLQJf0noi241MJZTeS2uFKlK63lA/uPit4qyGw7EHoai1l1zM0H7TPNjJFnuQbaCoLKK c5dSYn8jLg4/uHoG1acGIO4tJ+Lyo99fGxObhAl1FiMHiGtt+o9pQ+sHrYkQ4EzO6PMd diDQ== X-Forwarded-Encrypted: i=1; AJvYcCVZ7SjdhWSUJR/8f/QmI/2EVBZ4qjprsm9sx5OJYvN+bq4vdjNivrYYf+Ff0dZ83Hxo+UjOmD7dz9TQAEA=@vger.kernel.org X-Gm-Message-State: AOJu0YwYcrspRQ21symNCq0ESIFQ4nKnuDeTY12dXN49h9vuiL5oXyW9 S7OsQnv7kpp+H4L7P3Y8FqP135/gPtpdLiDyp85vmvZtL2P+EGr4egbfgOVZMg== X-Google-Smtp-Source: AGHT+IHOpcHqAe4+KizmjW3hadP4zp2qAPzG6XrwFdFi5tBVwuyu9biAEH+KtWKsGqgG0uqhKgvgUA== X-Received: by 2002:a05:6214:540e:b0:6cb:afe7:1403 with SMTP id 6a1803df08f44-6d39e2006bcmr322753126d6.48.1731611457638; Thu, 14 Nov 2024 11:10:57 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:57 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:42 +0000 Subject: [PATCH v15 13/19] media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-13-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao X-Mailer: b4 0.13.0 From: Yunke Cao Add support for V4L2_CTRL_WHICH_MIN/MAX_VAL in uvc driver. It is needed for the V4L2_CID_UVC_REGION_OF_INTEREST_RECT control. Signed-off-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 96 ++++++++++++++++++++++++++++++++----= ---- drivers/media/usb/uvc/uvc_v4l2.c | 2 + 2 files changed, 79 insertions(+), 19 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index b591d7fddc37..0dae5e8c3ca0 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1270,6 +1270,37 @@ static int uvc_query_v4l2_class(struct uvc_video_cha= in *chain, u32 req_id, return 0; } =20 +static bool uvc_ctrl_is_readable(u32 which, struct uvc_control *ctrl, + struct uvc_control_mapping *mapping) +{ + if (which =3D=3D V4L2_CTRL_WHICH_CUR_VAL) + return !!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR); + + if (which =3D=3D V4L2_CTRL_WHICH_DEF_VAL) + return !!(ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF); + + /* Types with implicit boundaries. */ + switch (mapping->v4l2_type) { + case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_BOOLEAN: + case V4L2_CTRL_TYPE_BUTTON: + return true; + case V4L2_CTRL_TYPE_BITMASK: + return (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) || + (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX); + default: + break; + } + + if (which =3D=3D V4L2_CTRL_WHICH_MIN_VAL) + return !!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN); + + if (which =3D=3D V4L2_CTRL_WHICH_MAX_VAL) + return !!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX); + + return false; +} + /* * Check if control @v4l2_id can be accessed by the given control @ioctl * (VIDIOC_G_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS or VIDIOC_S_EXT_CTRLS). @@ -1288,7 +1319,6 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *ch= ain, u32 v4l2_id, struct uvc_control *master_ctrl =3D NULL; struct uvc_control_mapping *mapping; struct uvc_control *ctrl; - bool read =3D ioctl =3D=3D VIDIOC_G_EXT_CTRLS; s32 val; int ret; int i; @@ -1300,10 +1330,10 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *= chain, u32 v4l2_id, if (!ctrl) return -EINVAL; =20 - if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) && read) - return -EACCES; + if (ioctl =3D=3D VIDIOC_G_EXT_CTRLS) + return uvc_ctrl_is_readable(ctrls->which, ctrl, mapping); =20 - if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read) + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) return -EACCES; =20 if (ioctl !=3D VIDIOC_S_EXT_CTRLS || !mapping->master_id) @@ -1451,6 +1481,9 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_cha= in *chain, v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_WRITE_ONLY; if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) && + (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN)) + v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; =20 if (mapping->master_id) __uvc_find_control(ctrl->entity, mapping->master_id, @@ -2037,16 +2070,18 @@ static int uvc_mapping_get_xctrl_compound(struct uv= c_video_chain *chain, =20 switch (which) { case V4L2_CTRL_WHICH_CUR_VAL: - ret =3D __uvc_ctrl_load_cur(chain, ctrl); - if (ret < 0) - return ret; id =3D UVC_CTRL_DATA_CURRENT; query =3D UVC_GET_CUR; break; + case V4L2_CTRL_WHICH_MIN_VAL: + id =3D UVC_CTRL_DATA_MIN; + query =3D UVC_GET_MIN; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + id =3D UVC_CTRL_DATA_MAX; + query =3D UVC_GET_MAX; + break; case V4L2_CTRL_WHICH_DEF_VAL: - ret =3D uvc_ctrl_populate_cache(chain, ctrl); - if (ret < 0) - return ret; id =3D UVC_CTRL_DATA_DEF; query =3D UVC_GET_DEF; break; @@ -2064,6 +2099,14 @@ static int uvc_mapping_get_xctrl_compound(struct uvc= _video_chain *chain, if (!data) return -ENOMEM; =20 + if (which =3D=3D V4L2_CTRL_WHICH_CUR_VAL) + ret =3D __uvc_ctrl_load_cur(chain, ctrl); + else + ret =3D uvc_ctrl_populate_cache(chain, ctrl); + + if (ret < 0) + return ret; + ret =3D mapping->get(mapping, query, uvc_ctrl_data(ctrl, id), size, data); if (ret < 0) return ret; @@ -2076,22 +2119,37 @@ static int uvc_mapping_get_xctrl_std(struct uvc_vid= eo_chain *chain, struct uvc_control_mapping *mapping, u32 which, struct v4l2_ext_control *xctrl) { + struct v4l2_queryctrl qc; + int ret; + switch (which) { case V4L2_CTRL_WHICH_CUR_VAL: return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value); case V4L2_CTRL_WHICH_DEF_VAL: - if (!ctrl->cached) { - int ret =3D uvc_ctrl_populate_cache(chain, ctrl); + case V4L2_CTRL_WHICH_MIN_VAL: + case V4L2_CTRL_WHICH_MAX_VAL: + break; + default: + return -EINVAL; + } =20 - if (ret < 0) - return ret; - } - xctrl->value =3D uvc_mapping_get_s32(mapping, UVC_GET_DEF, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); - return 0; + ret =3D __uvc_queryctrl_boundaries(chain, ctrl, mapping, &qc); + if (ret < 0) + return ret; + + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + xctrl->value =3D qc.default_value; + break; + case V4L2_CTRL_WHICH_MIN_VAL: + xctrl->value =3D qc.minimum; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + xctrl->value =3D qc.maximum; + break; } =20 - return -EINVAL; + return 0; } =20 static int uvc_mapping_get_xctrl(struct uvc_video_chain *chain, diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 65dbb53b1e75..7e284770149d 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1087,6 +1087,8 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, v= oid *fh, switch (ctrls->which) { case V4L2_CTRL_WHICH_DEF_VAL: case V4L2_CTRL_WHICH_CUR_VAL: + case V4L2_CTRL_WHICH_MAX_VAL: + case V4L2_CTRL_WHICH_MIN_VAL: which =3D ctrls->which; break; default: --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 903D41A08CB for ; Thu, 14 Nov 2024 19:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611461; cv=none; b=rZxWllTZyb7+9FdmqdZpc10JqsTOq2Nq8VzwByOlNeXhHJS4/Yd9towAWngRcUPAAcaKuzJp1gmrAwtf+K2OMgZDF9fi5S1f73JssNfKHG6mVjXxiqDGPWUdvibM+Kt0zLT7D9IyZEIXCoTvG2XRHbSLajgMg3JwdHYppY+FdG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611461; c=relaxed/simple; bh=EY5Eo52MkamV+RiJa+5OacEJMnFkljSo2OxdtrPOeRg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RWs6JuFNKRF5A+YsuCDFUjmV0KkPXv+5KWFXEDWPev+KUqMPfaEB9GQT1ynidndVM5YraeONVXmX4JGhKmC2OucxiYmlP1dU2dcwNFKyCIGEG/XqLR9L/qouzbTr7cPW+N+Y7FZLQKv/Q6bFkrSTFtVhdGZL8qaR6Hw4DVJFiuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=OqYSFX5P; arc=none smtp.client-ip=209.85.161.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OqYSFX5P" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5ee763f9779so546639eaf.1 for ; Thu, 14 Nov 2024 11:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611458; x=1732216258; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uFp+1e8oNM+DJbAtPSv+MyzrHN+BGnrJgCSNAWaI55I=; b=OqYSFX5P2wbtV/NYx1TnDFjnHWAAfLhTbsi2V6xwUnSHtvGPLOS6mdd1lTA0pd616G VqbP98GAxYOHGCtmHW3CoegmtVdFFS5oETPSd7gGGeriK9lmA6LlrIElX+fVe1DHFdQf MseJWhdlOxsZpyplHjHJ6HAkM84Z1yE7OG2BA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611458; x=1732216258; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uFp+1e8oNM+DJbAtPSv+MyzrHN+BGnrJgCSNAWaI55I=; b=PC3hoA2C9+lvwKQxgBVL0l9rL4IlymKhhm7hQE5y4mVMQ+2lLH6ri6phwzNXqis9Ok CeeK4F4pDEWkedczxkczofk/4sBjBtAjA409xGsDQKkiG+QdtKbkraXeJvbC9vhBPky/ pYlN/K836aWCQOCP5Tg1l0b2kxbT4QMOCrj0f21dtIFwdLWXT7zZRJbz8R1S9CKiszUT pxLq3rDZsmyIZkkBr4329dT7gEZLQUqcZske3xHuNwOEzjUS+EItcO/V19+A3nOJgf/i bLjfkM46gMgnyhZrlwTYdMVV/5gUjm7OdEHPy4lruS/wqGEtYEZEETBXnZVf7Yekd0ye 1X+g== X-Forwarded-Encrypted: i=1; AJvYcCXJfMHcI/Atr26gFaSozEY8qihC5e+xyqF+5twNkHTKiPTNC7++qw198Y67YpmzlomAO1IqxWRqJDC7qp8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxqv//bulaiTDolcGE02xwgkx56HvJQUSNQzlRJH4xQTa4gcU0/ GB3MKu9hGqWrUrMGQRb+KRboM9tZ47fvv5XKyASvWBP2s0sQ9aJGTLNm/HWUEA== X-Google-Smtp-Source: AGHT+IFNvD+gf1x55TT4Tlp5DIkK4UJiITK817j7zFhtUPdS3c13ovbIzET8/U/C8Kmf0gEGTY4ncg== X-Received: by 2002:a05:6359:5197:b0:1c3:e003:bddb with SMTP id e5c5f4694b2df-1c6cd2a3094mr13550655d.22.1731611458448; Thu, 14 Nov 2024 11:10:58 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:58 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:43 +0000 Subject: [PATCH v15 14/19] media: uvcvideo: Use the camera to clamp compound controls Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-14-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Compound controls cannot e reliable clamped. There is plenty of space for interpretation for the device manufacturer. When we write a compound control, let the camera do the clamping and return back to the user the value used by the device. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 0dae5e8c3ca0..72ed7dc9cfc1 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2339,6 +2339,18 @@ int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_= ext_control *xctrl) =20 ctrl->dirty =3D 1; ctrl->modified =3D 1; + + /* + * Compound controls cannot reliable clamp the value when they are + * written to the device. Let the device do the clamping and read back + * the value that the device is using. We do not need to return an + * error if this fails. + */ + if (uvc_ctrl_mapping_is_compound(mapping) && + uvc_ctrl_is_readable(V4L2_CTRL_WHICH_CUR_VAL, ctrl, mapping)) + uvc_mapping_get_xctrl_compound(chain, ctrl, mapping, + V4L2_CTRL_WHICH_CUR_VAL, xctrl); + return 0; } =20 --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07F0F1B21AE for ; Thu, 14 Nov 2024 19:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611463; cv=none; b=j8onCYWxO4/GVtTbnm2pcLs1yYs6WfDYGwPv7qXrv1kAPexVJ6b7iooxiX05uFlDTG47/Eh39pziscbbVRxSxz3FqTcAigP2GBy44I2uFqoxPNuQyud6T1AnJ6hdOCL0f4szZbeDs5QSNVazGOZItvhuR3+XBKKjhiDMXCrX1c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611463; c=relaxed/simple; bh=n/4Gw/F5XfVHHXJLIJrOKVEwWJwN5RkWXSV5JexAt0E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FzccvwIn55Iz/z1OW/L/jvdOqdO2DXDjGVi1HiLfDNnLWqMgbYViWton6hZ06YkSVU2DxhvrfSFVktxR5WunhXWlpRqC8zp4sePQ4rVfdZm+443N+PyakFD7fiujIb9QqPk3+fO3/SkaQI46APNdBCtuOxVFE70Y2wctLBOPco0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=JSmZXy4k; arc=none smtp.client-ip=209.85.219.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JSmZXy4k" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6d3f7febc1dso3531336d6.1 for ; Thu, 14 Nov 2024 11:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611460; x=1732216260; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JZTsTBSX3xSqfbyzm7VG5yBnJ19hpAWauNKzKGES8go=; b=JSmZXy4kQh2zencrvQY7/jlz/S/7ZaxKpkQfuaocOeddYHz6+FpY5yiwkk7m0agnYg 0yOFxOEPVTxWUTrqCwoWcOFRVxyRlU1gLEda6BMLe/nU/HH1GXPwkPCQ9A939scyAwEV 3A8NmFeNbB+5YpLZe1avkCXCfC07i5qtrinUg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611460; x=1732216260; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JZTsTBSX3xSqfbyzm7VG5yBnJ19hpAWauNKzKGES8go=; b=cPcALDQEQiGS3X14lO9l0RCl9KBaDpme72RI65LUbuCOOTmyvXW/QEBzz5tlHBh1eI UT2ix8s1LbyfxBbyM1quTZ1DC4EhKlVBqhunhjLaXN4+egYM9DhZXd2Bw+bL3ybxnfnD W/VbZCCoHsNjDeE9e7gMFFgMRSmyIk7azNp/NW/kRLzeTU6DYv7rQ4f6j/U3iWbbRkfo IokutdhrKyKWoyEC8OiO9IG7EM2DQIJ2oX+5L8zoph8PRnlP5DSk5wxbScYw2F4czVqX 3QOYnAujkSV238VX0sC0rFIUIuNFpVMMhkSbH3ur0z8T+Q/U3PYeL7ejxpAkrpuYcBoX 8IAA== X-Forwarded-Encrypted: i=1; AJvYcCU7nD0xjL2qylPzhKILb1G9yhx+1tVEMmiVapa4pt1F07ENn4gSGJ2edgT0OebTkOOTAmN+Q/f5joAamYA=@vger.kernel.org X-Gm-Message-State: AOJu0YzM31oL3Ignf7Y82QMRodnl5gfcAoZaQI/cG1AwRECZnXR/QIcE zAUz2Ri4SHPH0bEKPJpbpr3mOX6joDQ14/uQMv7pt2bZlpDuTiMwn/0uxxb3gg== X-Google-Smtp-Source: AGHT+IFYqBJZtMtZqxRLn7uD+s+ZXDgMbRIudST+4D8WH8SdJFFNexVMkL2sBDlUhnEMyT9YcUtkFQ== X-Received: by 2002:a05:6214:3bc2:b0:6d3:941a:2274 with SMTP id 6a1803df08f44-6d3edcfbae4mr40292716d6.22.1731611459925; Thu, 14 Nov 2024 11:10:59 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:10:59 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:44 +0000 Subject: [PATCH v15 15/19] media: uvcvideo: let v4l2_query_v4l2_ctrl() work with v4l2_query_ext_ctrl Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-15-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 v4l2_query_ext_ctrl contains information that is missing in v4l2_queryctrl, like elem_size and elems. With this change we can handle all the element_size information inside uvc_ctrl.c. Now that we are at it, remove the memset of the reserved fields, the v4l2 ioctl handler should do that for us. There is no functional change expected from this change. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 24 ++++++++++++++---------- drivers/media/usb/uvc/uvc_v4l2.c | 35 +++++++++++++++-------------------- drivers/media/usb/uvc/uvcvideo.h | 2 +- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 72ed7dc9cfc1..1bc019138995 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1252,7 +1252,8 @@ static int __uvc_query_v4l2_class(struct uvc_video_ch= ain *chain, u32 req_id, } =20 static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, - u32 found_id, struct v4l2_queryctrl *v4l2_ctrl) + u32 found_id, + struct v4l2_query_ext_ctrl *v4l2_ctrl) { int idx; =20 @@ -1400,7 +1401,7 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *ct= rl, static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, - struct v4l2_queryctrl *v4l2_ctrl) + struct v4l2_query_ext_ctrl *v4l2_ctrl) { if (!ctrl->cached) { int ret =3D uvc_ctrl_populate_cache(chain, ctrl); @@ -1465,7 +1466,7 @@ static int __uvc_queryctrl_boundaries(struct uvc_vide= o_chain *chain, static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, - struct v4l2_queryctrl *v4l2_ctrl) + struct v4l2_query_ext_ctrl *v4l2_ctrl) { struct uvc_control_mapping *master_map =3D NULL; struct uvc_control *master_ctrl =3D NULL; @@ -1503,6 +1504,9 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_cha= in *chain, v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_INACTIVE; } =20 + v4l2_ctrl->elem_size =3D sizeof(s32); + v4l2_ctrl->elems =3D 1; + if (v4l2_ctrl->type >=3D V4L2_CTRL_COMPOUND_TYPES) { v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_HAS_PAYLOAD; v4l2_ctrl->default_value =3D 0; @@ -1516,7 +1520,7 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_cha= in *chain, } =20 int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, - struct v4l2_queryctrl *v4l2_ctrl) + struct v4l2_query_ext_ctrl *v4l2_ctrl) { struct uvc_control *ctrl; struct uvc_control_mapping *mapping; @@ -1642,7 +1646,7 @@ static void uvc_ctrl_fill_event(struct uvc_video_chai= n *chain, struct uvc_control_mapping *mapping, s32 value, u32 changes) { - struct v4l2_queryctrl v4l2_ctrl; + struct v4l2_query_ext_ctrl v4l2_ctrl; =20 __uvc_query_v4l2_ctrl(chain, ctrl, mapping, &v4l2_ctrl); =20 @@ -2119,7 +2123,7 @@ static int uvc_mapping_get_xctrl_std(struct uvc_video= _chain *chain, struct uvc_control_mapping *mapping, u32 which, struct v4l2_ext_control *xctrl) { - struct v4l2_queryctrl qc; + struct v4l2_query_ext_ctrl qec; int ret; =20 switch (which) { @@ -2133,19 +2137,19 @@ static int uvc_mapping_get_xctrl_std(struct uvc_vid= eo_chain *chain, return -EINVAL; } =20 - ret =3D __uvc_queryctrl_boundaries(chain, ctrl, mapping, &qc); + ret =3D __uvc_queryctrl_boundaries(chain, ctrl, mapping, &qec); if (ret < 0) return ret; =20 switch (which) { case V4L2_CTRL_WHICH_DEF_VAL: - xctrl->value =3D qc.default_value; + xctrl->value =3D qec.default_value; break; case V4L2_CTRL_WHICH_MIN_VAL: - xctrl->value =3D qc.minimum; + xctrl->value =3D qec.minimum; break; case V4L2_CTRL_WHICH_MAX_VAL: - xctrl->value =3D qc.maximum; + xctrl->value =3D qec.maximum; break; } =20 diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 7e284770149d..5000c74271e0 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1014,40 +1014,35 @@ static int uvc_ioctl_s_input(struct file *file, voi= d *fh, unsigned int input) return ret; } =20 -static int uvc_ioctl_queryctrl(struct file *file, void *fh, - struct v4l2_queryctrl *qc) +static int uvc_ioctl_query_ext_ctrl(struct file *file, void *fh, + struct v4l2_query_ext_ctrl *qec) { struct uvc_fh *handle =3D fh; struct uvc_video_chain *chain =3D handle->chain; =20 - return uvc_query_v4l2_ctrl(chain, qc); + return uvc_query_v4l2_ctrl(chain, qec); } =20 -static int uvc_ioctl_query_ext_ctrl(struct file *file, void *fh, - struct v4l2_query_ext_ctrl *qec) +static int uvc_ioctl_queryctrl(struct file *file, void *fh, + struct v4l2_queryctrl *qc) { struct uvc_fh *handle =3D fh; struct uvc_video_chain *chain =3D handle->chain; - struct v4l2_queryctrl qc =3D { qec->id }; + struct v4l2_query_ext_ctrl qec =3D { qc->id }; int ret; =20 - ret =3D uvc_query_v4l2_ctrl(chain, &qc); + ret =3D uvc_query_v4l2_ctrl(chain, &qec); if (ret) return ret; =20 - qec->id =3D qc.id; - qec->type =3D qc.type; - strscpy(qec->name, qc.name, sizeof(qec->name)); - qec->minimum =3D qc.minimum; - qec->maximum =3D qc.maximum; - qec->step =3D qc.step; - qec->default_value =3D qc.default_value; - qec->flags =3D qc.flags; - qec->elem_size =3D 4; - qec->elems =3D 1; - qec->nr_of_dims =3D 0; - memset(qec->dims, 0, sizeof(qec->dims)); - memset(qec->reserved, 0, sizeof(qec->reserved)); + qc->id =3D qec.id; + qc->type =3D qec.type; + strscpy(qc->name, qec.name, sizeof(qc->name)); + qc->minimum =3D qec.minimum; + qc->maximum =3D qec.maximum; + qc->step =3D qec.step; + qc->default_value =3D qec.default_value; + qc->flags =3D qec.flags; =20 return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index f429f325433b..8aca1a2fe587 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -766,7 +766,7 @@ void uvc_status_put(struct uvc_device *dev); extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; =20 int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, - struct v4l2_queryctrl *v4l2_ctrl); + struct v4l2_query_ext_ctrl *v4l2_ctrl); int uvc_query_v4l2_menu(struct uvc_video_chain *chain, struct v4l2_querymenu *query_menu); =20 --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5AED1B3928 for ; Thu, 14 Nov 2024 19:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611463; cv=none; b=O/gp4WYgDkcE1/9KBOlUwHSsjVkVpqY11sIxm2tXFS/VTAurkOe8ldCWWD2oInYwu8+utUtr512OQfHRBrTHw9XKRtH2IxOgKGlTT+O84GLZZOa8qzMwqfbt6/To4ApQs8f9Pz6ccNtM754m7CmejsIJepaq6bkvpScjKFeO7aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611463; c=relaxed/simple; bh=Z9uDVvItoljuKYfunavqY95I9UqlcIp6s4l6b4f5U+s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u69HjTPfKTyKzF8JPV2zEaN2sTQy2aERmUY8oW6suCSI7fDZTQoAR067WX+Fhl6/VXM7SlW+wjsDR2CqI3Q3IKXMnDv+ALIkVx/dwbZGEZUyANONzLxS1jNagrmWx6P/qYKKIQoiu4sqS1XBuGYMLNWjAEVfOKkK/2qzU6/cTBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=lMEET6M6; arc=none smtp.client-ip=209.85.210.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="lMEET6M6" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-718123ec383so515907a34.3 for ; Thu, 14 Nov 2024 11:11:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611461; x=1732216261; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gBJrp7mg23fLq0H3uAUw+Zj5QMkIuMcISNIeTGg09NQ=; b=lMEET6M6y6+UZil4eqnYPfySGNnG4eIaQM0VKqVp+ea34cbS2IdDtYJp97f1KanE1g H2aRW94TK26jf/Soz/uM5L/RE4OqxZGoy1b3L08Qit3WDTFAh6GY22gCZz+0EfFEwg3f kJlAFX1EiubEjJfe2cu5xXfyda/nAhB13v3TI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611461; x=1732216261; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gBJrp7mg23fLq0H3uAUw+Zj5QMkIuMcISNIeTGg09NQ=; b=w8K8sgOwYmNwqVbpChNZOA02TVObXrpj6rbkId8PjJTszWX4jCyUmAUmAGaN/ky436 ujvDsDYvmTOcqPsZMSa5BikxA43GwB5UOKbEBmg181U7bvcsP5Y2wxfFllxJjzM0TX7j K9/D99FvLUBkLVt6IaV3/jsnlLw9UXvm2Nt3B/G+CIor+myXCJd0gszFDglUJhAHv/6o LDM3iC2c2Gankwb6Ce50e5kz6YKOwqkaVim+84D3mKSALUlM7dMuWtwOYea3MP9RMP8d kWdvu0xWLkBjexm4dTfDoqifKj/v9z6FM4ycvxO8D6FrczSteCBzKo9rt88t3f2Bkb+Q eQkw== X-Forwarded-Encrypted: i=1; AJvYcCVdBrzbWMSPeANa+G1taP2D4tPNZY9yIiuPn6M1OX50ujkuqPuhMmLdxM6s0YJS6u7cVdrEY1o3fU6uUCQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxGejw8lVcUpzyxTAoZAAWbXtDQK7rYxZg5v8Q+47YGxW9LFMYb 0YN2ptDhW8C4c2O1LXEGRRipHACvha19MBx4xu+uJui0XZcLVoaAp3z4Wlhlkw== X-Google-Smtp-Source: AGHT+IFNVlvDBjAW1cRege8knW5DelZl6pBdMLjl5E5lB/Wc9jyTp/KkdgXqMEneu89a9XWemF/hGg== X-Received: by 2002:a05:6358:c83:b0:1c3:7157:2868 with SMTP id e5c5f4694b2df-1c6cd108afdmr31228355d.20.1731611460947; Thu, 14 Nov 2024 11:11:00 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:11:00 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:45 +0000 Subject: [PATCH v15 16/19] media: uvcvideo: Introduce uvc_mapping_v4l2_size Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-16-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Centralize the calculation for the v4l2_size of a mapping. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 1bc019138995..f262e05ad3a8 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1463,6 +1463,14 @@ static int __uvc_queryctrl_boundaries(struct uvc_vid= eo_chain *chain, return 0; } =20 +static size_t uvc_mapping_v4l2_size(struct uvc_control_mapping *mapping) +{ + if (uvc_ctrl_mapping_is_compound(mapping)) + return DIV_ROUND_UP(mapping->size, 8); + + return sizeof(s32); +} + static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, struct uvc_control *ctrl, struct uvc_control_mapping *mapping, @@ -1504,7 +1512,7 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_cha= in *chain, v4l2_ctrl->flags |=3D V4L2_CTRL_FLAG_INACTIVE; } =20 - v4l2_ctrl->elem_size =3D sizeof(s32); + v4l2_ctrl->elem_size =3D uvc_mapping_v4l2_size(mapping); v4l2_ctrl->elems =3D 1; =20 if (v4l2_ctrl->type >=3D V4L2_CTRL_COMPOUND_TYPES) { @@ -2093,7 +2101,7 @@ static int uvc_mapping_get_xctrl_compound(struct uvc_= video_chain *chain, return -EINVAL; } =20 - size =3D DIV_ROUND_UP(mapping->size, 8); + size =3D uvc_mapping_v4l2_size(mapping); if (xctrl->size < size) { xctrl->size =3D size; return -ENOSPC; @@ -2271,9 +2279,8 @@ static int uvc_mapping_set_xctrl_compound(struct uvc_= control *ctrl, struct v4l2_ext_control *xctrl) { u8 *data __free(kfree) =3D NULL; - size_t size; + size_t size =3D uvc_mapping_v4l2_size(mapping); =20 - size =3D DIV_ROUND_UP(mapping->size, 8); if (xctrl->size !=3D size) return -EINVAL; =20 --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84EBF1B3940 for ; Thu, 14 Nov 2024 19:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611464; cv=none; b=B4keUBxpxcPnNcG6MELdEVB4pf4gfL3mPGcSwqErL3xcSWnNce1YnzfQ60OGJyHAsM3tbZi8BG/n3aDhpBDXX1op758/7ZUqHSZS/GI2gZRg8snrqdPYcj0ou12fHgBBZO0BneeQbAO//B6Ur6Zi4Iato3r88Go6wDYPF0WyLP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611464; c=relaxed/simple; bh=k4uDTu8QR04JKFyNIWvlkLGzbPquiHwpezPKOuusA5Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eKBiQVSABMid584vtpzfoqWhAQf6S4oGKIaZ/GTv6dQiRUEQPBC4CyThMlAuskbFvkVlN2KLl6sYu58Mz2jwqLdUCZFEFU2EFtRVA2UU7QsRC3ANxKdTHHMjI61jnRqiOW1x4w75kiuLr6jdS8VUea3QOuu34fa8Rem4xW5gfag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=g1TOtMXc; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="g1TOtMXc" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b13bf566c0so52189485a.3 for ; Thu, 14 Nov 2024 11:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611461; x=1732216261; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W7E0huVHEFwjCBRTjS+ylKmb8Bs68bY9XRKBoQt8QA8=; b=g1TOtMXcFxhUxMNeF/MUlcxXweZKbgYCFpexSiqJVvO6n4qcvJ5kdxppqgdu+nE6pt b+0FkGloSQ86ZdpbfQOQlR4vLfrUuYOXMso/AGttoV6gnIllxz7es2VL/teRSy3xX45n cbi15V/9Z1MjlRopVTgX8EqaX0OhD7v3lRvC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611461; x=1732216261; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W7E0huVHEFwjCBRTjS+ylKmb8Bs68bY9XRKBoQt8QA8=; b=qdc2zSsW+l3NthXnszUt14lQj0vy4eYuEVcgYUMMnJhSR6xVfrlm8yQePUeMjg/uwI qb/dZlRlp9pScErSmDItk4ZxpM2rD5OzyvWqj9jLmjlHtAYKfAJLueJXq8Wp2P477tTf 6bP7iHGq3KZwLs84y7TDSYuzmdD+s/OaxVZ+04tpdOBqiTsFkKrMuNFSX0nXKj8qzZy+ hE7PiF5zp8pzXladagNTh5q1NR32yZrXbFjVdDUb7aX1oB/OTXjBcc3PNgPmW2SqjkUR 0VRpa8VRmzAQgDZb9lVOjrx9dIqFVIXVY5FJLU+pDg5d1d5/WkO97gkrahkuEvNEkSBu cKMw== X-Forwarded-Encrypted: i=1; AJvYcCVGxyKR94tqZSp10GoxywlTQmqJTVWfzi0gB12psq5yJ2BcrzYKBUyGzZHTMCF+T/97cwGcVO12MkDdR0Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3gOZ2gxGo/3qVWPKEWOjYsy8fgPuHWMn+JO7bGEA1Jsa005Fl zrZ3NOO0oqqE/1PfIBHX9iynFA8H6++2qxyPWE3QE2S8Lt61Wc95EsY0lQF66Q== X-Google-Smtp-Source: AGHT+IGZMIzlcVDne/EBA7zSnMfQWXO3fs22rn5PFrTiSjbHbo9hkBJ1di5xITi8OVdVSgzseLvdGw== X-Received: by 2002:a05:6214:4909:b0:6d3:f73c:4430 with SMTP id 6a1803df08f44-6d3f73c6993mr22012796d6.26.1731611461706; Thu, 14 Nov 2024 11:11:01 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:11:01 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:46 +0000 Subject: [PATCH v15 17/19] media: uvcvideo: Add sanity check to uvc_ioctl_xu_ctrl_map Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-17-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Do not process unknown data types. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 5000c74271e0..4c88dab15554 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -106,6 +106,12 @@ static int uvc_ioctl_xu_ctrl_map(struct uvc_video_chai= n *chain, struct uvc_control_mapping *map; int ret; =20 + if (xmap->data_type > UVC_CTRL_DATA_TYPE_BITMASK) { + uvc_dbg(chain->dev, CONTROL, + "Unsupported UVC data type %u\n", xmap->data_type); + return -ENOTTY; + } + map =3D kzalloc(sizeof(*map), GFP_KERNEL); if (map =3D=3D NULL) return -ENOMEM; --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C4011B4F02 for ; Thu, 14 Nov 2024 19:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611465; cv=none; b=CWAwNIYm4QXC6N8hVwyEHjKNY0vRMOed9tTwjNWaHGty3o1XhuvCREdPsOVJWjD/sQXbwAjNNr8O7nltaYkKrICedBmWfclUcWGiEbBiXQGciY5Li2UI1Q/Md2X32v3r6VyOskQVdbGk0RACUdfifg+z7MuqmP+cx5zeP6Ea4ZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611465; c=relaxed/simple; bh=G5/w2LpBfII/nbK2O7RqW+iuApIAiWZ+5waBhl2Gw9s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b2HOV4DrtibRVtID3hmkO2QMMEp/pvuel85rWcCuw4VJnGBOvpPP+WvtaDN9djnUqisx0niNe60wJYRk3E+7YXeSRxV1wBHYnjVuA0vS7wXfT8pDSEviqunHheI5xSlk0r8o9s9eCzKNteyD9dZgAF7awyUq/NnjR+SZ3TocxCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=S/gNryTz; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="S/gNryTz" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7b35b1ca0c2so116257485a.0 for ; Thu, 14 Nov 2024 11:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611462; x=1732216262; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UcG3FhcuZvbG2+NnY7etdL0t4ZcduW99Sq/T3Mxk4/I=; b=S/gNryTzOns6I0sSuG8FgXJGCWOl6Q6wIc9olx9B+Hcw87xRgQjKHebbApc179VntG vQjqfBaPS4XJgzqnto4BucktBakgR3OGZVJYt5QwiDa0rEzOWKehkB8AXvW9fRoN4HHt Oyg/9ngVUH5EEZSEmA3ywN+VlWtFQZaT5cm2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611462; x=1732216262; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UcG3FhcuZvbG2+NnY7etdL0t4ZcduW99Sq/T3Mxk4/I=; b=nIyowi6eO6pJauGR6RnDUNxQI8yuS61Kg+9BnE3iNB06QyXqroIiF9eW4h6cr+jsAa DiRJn3PHA/122kQUNgnWw1GJ2PWAVggt4y1ugmsfnegY/76VzEYq3UpUP22zt5Kom3Fd dppxzsqhupBUgZDTekaeygAdz6x9/prXOtfc3QGqygH7nuuRylZLAdQSnx8Cgfyzg/ER k3TpoJx60p0m3NibdeB6qZeQ84BVdbQjRrmYydtent3vafimz+7P4QgKAlVn3zd4QsXI gk9MaNtKAQRYu0AWIiByWaVpnOcdhjAj/hXAUfce2SpyTLk5ZvQdGm1TvDAlAtFsjZPi Nr0Q== X-Forwarded-Encrypted: i=1; AJvYcCW8fWlgz4DusKw7aiLLRmFGQjLYK5k1Ha9B7AqjGzROvPZJR9riJ0wfWHcIW8njwdtOLNN9DhxbBTgd0SM=@vger.kernel.org X-Gm-Message-State: AOJu0Yziv8RXDp8N2ufDQRg+jJyOvuOLO2vSQTMaeiRz+7i93IMpHcma 9CvIixnetROpllo/eFq6efCAj4qgUXIl/pw8+BLDnikeeChECq1LzKRBYl9kyA== X-Google-Smtp-Source: AGHT+IHuR1WrTlDipWbGX/ArVVt+6TY3Oto5+lhHEishv/BK6dw2+cEm5UP4ltJavxeCNCbGdQOA4A== X-Received: by 2002:ad4:5742:0:b0:6d3:5bcc:485c with SMTP id 6a1803df08f44-6d3e8dbbffcmr70212226d6.0.1731611462443; Thu, 14 Nov 2024 11:11:02 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:11:02 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:47 +0000 Subject: [PATCH v15 18/19] media: uvcvideo: implement UVC v1.5 ROI Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-18-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao X-Mailer: b4 0.13.0 From: Yunke Cao Implement support for ROI as described in UVC 1.5: 4.2.2.1.20 Digital Region of Interest (ROI) Control ROI control is implemented using V4L2 control API as two UVC-specific controls: V4L2_CID_UVC_REGION_OF_INTEREST_RECT and V4L2_CID_UVC_REGION_OF_INTEREST_AUTO. Reviewed-by: Ricardo Ribalda Signed-off-by: Yunke Cao --- drivers/media/usb/uvc/uvc_ctrl.c | 81 ++++++++++++++++++++++++++++++++++= ++++ drivers/media/usb/uvc/uvcvideo.h | 7 ++++ include/uapi/linux/usb/video.h | 1 + include/uapi/linux/uvcvideo.h | 13 ++++++ include/uapi/linux/v4l2-controls.h | 9 +++++ 5 files changed, 111 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index f262e05ad3a8..5b619ef40dd3 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -358,6 +358,24 @@ static const struct uvc_control_info uvc_ctrls[] =3D { .flags =3D UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_AUTO_UPDATE, }, + /* + * UVC_CTRL_FLAG_AUTO_UPDATE is needed because the RoI may get updated + * by sensors. + * "This RoI should be the same as specified in most recent SET_CUR + * except in the case where the =E2=80=98Auto Detect and Track=E2=80=99 a= nd/or + * =E2=80=98Image Stabilization=E2=80=99 bit have been set." + * 4.2.2.1.20 Digital Region of Interest (ROI) Control + */ + { + .entity =3D UVC_GUID_UVC_CAMERA, + .selector =3D UVC_CT_REGION_OF_INTEREST_CONTROL, + .index =3D 21, + .size =3D 10, + .flags =3D UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR + | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX + | UVC_CTRL_FLAG_GET_DEF + | UVC_CTRL_FLAG_AUTO_UPDATE, + }, }; =20 static const u32 uvc_control_classes[] =3D { @@ -603,6 +621,44 @@ static const struct uvc_control_mapping *uvc_ctrl_filt= er_plf_mapping( return out_mapping; } =20 +static int uvc_get_rect(struct uvc_control_mapping *mapping, u8 query, + const void *uvc_in, size_t v4l2_size, void *v4l2_out) +{ + const struct uvc_rect *uvc_rect =3D uvc_in; + struct v4l2_rect *v4l2_rect =3D v4l2_out; + + if (WARN_ON(v4l2_size !=3D sizeof(struct v4l2_rect))) + return -EINVAL; + + if (uvc_rect->left > uvc_rect->right || + uvc_rect->top > uvc_rect->bottom) + return -EIO; + + v4l2_rect->top =3D uvc_rect->top; + v4l2_rect->left =3D uvc_rect->left; + v4l2_rect->height =3D uvc_rect->bottom - uvc_rect->top + 1; + v4l2_rect->width =3D uvc_rect->right - uvc_rect->left + 1; + + return 0; +} + +static int uvc_set_rect(struct uvc_control_mapping *mapping, size_t v4l2_s= ize, + const void *v4l2_in, void *uvc_out) +{ + struct uvc_rect *uvc_rect =3D uvc_out; + const struct v4l2_rect *v4l2_rect =3D v4l2_in; + + if (WARN_ON(v4l2_size !=3D sizeof(struct v4l2_rect))) + return -EINVAL; + + uvc_rect->top =3D max(0xffff, v4l2_rect->top); + uvc_rect->left =3D max(0xffff, v4l2_rect->left); + uvc_rect->bottom =3D max(0xffff, v4l2_rect->height + v4l2_rect->top - 1); + uvc_rect->right =3D max(0xffff, v4l2_rect->width + v4l2_rect->left - 1); + + return 0; +} + static const struct uvc_control_mapping uvc_ctrl_mappings[] =3D { { .id =3D V4L2_CID_BRIGHTNESS, @@ -897,6 +953,28 @@ static const struct uvc_control_mapping uvc_ctrl_mappi= ngs[] =3D { .selector =3D UVC_PU_POWER_LINE_FREQUENCY_CONTROL, .filter_mapping =3D uvc_ctrl_filter_plf_mapping, }, + { + .id =3D V4L2_CID_UVC_REGION_OF_INTEREST_RECT, + .entity =3D UVC_GUID_UVC_CAMERA, + .selector =3D UVC_CT_REGION_OF_INTEREST_CONTROL, + .size =3D sizeof(struct uvc_rect) * 8, + .offset =3D 0, + .v4l2_type =3D V4L2_CTRL_TYPE_RECT, + .data_type =3D UVC_CTRL_DATA_TYPE_RECT, + .get =3D uvc_get_rect, + .set =3D uvc_set_rect, + .name =3D "Region Of Interest Rectangle", + }, + { + .id =3D V4L2_CID_UVC_REGION_OF_INTEREST_AUTO, + .entity =3D UVC_GUID_UVC_CAMERA, + .selector =3D UVC_CT_REGION_OF_INTEREST_CONTROL, + .size =3D 16, + .offset =3D 64, + .v4l2_type =3D V4L2_CTRL_TYPE_BITMASK, + .data_type =3D UVC_CTRL_DATA_TYPE_BITMASK, + .name =3D "Region Of Interest Auto Controls", + }, }; =20 /* ------------------------------------------------------------------------ @@ -1465,6 +1543,9 @@ static int __uvc_queryctrl_boundaries(struct uvc_vide= o_chain *chain, =20 static size_t uvc_mapping_v4l2_size(struct uvc_control_mapping *mapping) { + if (mapping->v4l2_type =3D=3D V4L2_CTRL_TYPE_RECT) + return sizeof(struct v4l2_rect); + if (uvc_ctrl_mapping_is_compound(mapping)) return DIV_ROUND_UP(mapping->size, 8); =20 diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 8aca1a2fe587..d910a5e5b514 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -294,6 +294,13 @@ struct uvc_streaming_header { u8 bTriggerUsage; }; =20 +struct uvc_rect { + u16 top; + u16 left; + u16 bottom; + u16 right; +} __packed; + enum uvc_buffer_state { UVC_BUF_STATE_IDLE =3D 0, UVC_BUF_STATE_QUEUED =3D 1, diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h index 2ff0e8a3a683..2afb4420e6c4 100644 --- a/include/uapi/linux/usb/video.h +++ b/include/uapi/linux/usb/video.h @@ -104,6 +104,7 @@ #define UVC_CT_ROLL_ABSOLUTE_CONTROL 0x0f #define UVC_CT_ROLL_RELATIVE_CONTROL 0x10 #define UVC_CT_PRIVACY_CONTROL 0x11 +#define UVC_CT_REGION_OF_INTEREST_CONTROL 0x14 =20 /* A.9.5. Processing Unit Control Selectors */ #define UVC_PU_CONTROL_UNDEFINED 0x00 diff --git a/include/uapi/linux/uvcvideo.h b/include/uapi/linux/uvcvideo.h index f86185456dc5..cbe15bca9569 100644 --- a/include/uapi/linux/uvcvideo.h +++ b/include/uapi/linux/uvcvideo.h @@ -16,6 +16,7 @@ #define UVC_CTRL_DATA_TYPE_BOOLEAN 3 #define UVC_CTRL_DATA_TYPE_ENUM 4 #define UVC_CTRL_DATA_TYPE_BITMASK 5 +#define UVC_CTRL_DATA_TYPE_RECT 6 =20 /* Control flags */ #define UVC_CTRL_FLAG_SET_CUR (1 << 0) @@ -38,6 +39,18 @@ =20 #define UVC_MENU_NAME_LEN 32 =20 +/* V4L2 driver-specific controls */ +#define V4L2_CID_UVC_REGION_OF_INTEREST_RECT (V4L2_CID_USER_UVC_BASE + 1) +#define V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (V4L2_CID_USER_UVC_BASE + 2) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE (1 << 0) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS (1 << 1) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE (1 << 2) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS (1 << 3) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT (1 << 4) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK (1 << 5) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION (1 << 6) +#define V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY (1 << 7) + struct uvc_menu_info { __u32 value; __u8 name[UVC_MENU_NAME_LEN]; diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-c= ontrols.h index 974fd254e573..6c91d6fa4708 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -215,6 +215,13 @@ enum v4l2_colorfx { */ #define V4L2_CID_USER_THP7312_BASE (V4L2_CID_USER_BASE + 0x11c0) =20 +/* + * The base for the uvc driver controls. + * See linux/uvcvideo.h for the list of controls. + * We reserve 64 controls for this driver. + */ +#define V4L2_CID_USER_UVC_BASE (V4L2_CID_USER_BASE + 0x11e0) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ @@ -1089,6 +1096,8 @@ enum v4l2_auto_focus_range { =20 #define V4L2_CID_HDR_SENSOR_MODE (V4L2_CID_CAMERA_CLASS_BASE+36) =20 +/* CAMERA-class private control IDs */ + /* FM Modulator class control IDs */ =20 #define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) --=20 2.47.0.338.g60cca15819-goog From nobody Sat Nov 23 02:26:58 2024 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 387011B5EA4 for ; Thu, 14 Nov 2024 19:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611466; cv=none; b=WVp6AHyQFb3VwXRIvv9ekyMiOsBVZ5uTMsLZ7d+yF1sz69yLRDGdM0RG6QaK551cBEEq/m/1I9bK5d7cRoUZsid2UUez6HsA+DRNgyDmn7pcUztbflIO4bkeRihhddG93JdbU2hnixJznA0JGYKTQv7fBAKYCzeQ16DppUIN+ds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731611466; c=relaxed/simple; bh=PhTJre4pPGmMPPsN/T9S6uvenShngpY+QklJsyJGE5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PByNDvywMIk91Eb7NP3OftiOPJ43kqu7F5ZwBAhXSyYANoqfhtrMfKiiHnAOKCU5SP5wqj5FdAyp8BOAoUrS7SaaDMVVI4z3dz6IBUSxqnf1DtdS2Wj3sEu3Qf7vcpvKwn2m4+m6sVZAKkKFjTd/jUXbsqqZdZwPr3HC8ZBWGJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=R/z23kPf; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="R/z23kPf" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6cbcc2bd800so8431896d6.0 for ; Thu, 14 Nov 2024 11:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731611463; x=1732216263; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=FBavzk6Bw3Trxv3crngVWykxkJCeHnNA55ffm7Fp7P0=; b=R/z23kPf0JUQl/xmFpzO8ohew7Ldo6lxXE5EYQY4LuLA/4Xq+AIJxGOMqDnMAt/0Ru RSTQghh7Q+dyA09g4ETaziFV4CuVmHcz34IWIdVgeLymPuFWMTKba2IU+XiqhhJMoDU7 z3keOHAGn2xIqBvxqdRDPmbR0vBAUE9xqA/J4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731611463; x=1732216263; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FBavzk6Bw3Trxv3crngVWykxkJCeHnNA55ffm7Fp7P0=; b=JSBON2aSQCliAEe74dbUh6473wA/LVoiSbiTI1QuKjBXN07u+exwe0AcwzZCywNG6w E1k7D+4norwbLpiVqJMYuvfuExlOvJkS4XLY+OLUXuig+T5qOckPYEeD6l0YxFfz2bd9 tFXira4vx8x/VFJboHtG+L5HkT5Vv6Wq5q7Qk0i0XegA1/EkLhXtpr2F9biODZEQmvH3 5d/eWgoVFu4xZFnDbArZTn2i83F3GBv5udaCt9iC1PrjT0Q7Oi6Ctw/CilI++kQQaJN9 WhVulsuemv8mt98USDqLkZFGOB2nVmNOcUtecsKEL3h0+efxC5bTWer9nBZNgF6AbcUV s/mg== X-Forwarded-Encrypted: i=1; AJvYcCXCvRzgsWlLrm/j8EDkOlUp5VM3UDY74RnOaCkbz5rrCCSJxhoh3IDpZM9dxoI3TaeT64Uh5DnJm7k/vmw=@vger.kernel.org X-Gm-Message-State: AOJu0YxbjGDBBrAlvrpczJvK/kILBT8TBEfiMt7KNKwJpRpQSEOfRAHx kPOeK75GkWIXbAd8xc6qnDvMmQ72kWhLsjAFb/dySJNLvYwpZ5AqrgOV7Nguqg== X-Google-Smtp-Source: AGHT+IFgscBZYIINazB1el1lgvgswMvG66EcNip964hXIqQxn60chcRbTUwj3BXMFDmkJzGj5Aze5A== X-Received: by 2002:a05:6214:5d8d:b0:6cb:f72e:4eb9 with SMTP id 6a1803df08f44-6d3fac30859mr3276576d6.11.1731611463343; Thu, 14 Nov 2024 11:11:03 -0800 (PST) Received: from denia.c.googlers.com (189.216.85.34.bc.googleusercontent.com. [34.85.216.189]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3ee7cc7e1sm8857766d6.53.2024.11.14.11.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2024 11:11:02 -0800 (PST) From: Ricardo Ribalda Date: Thu, 14 Nov 2024 19:10:48 +0000 Subject: [PATCH v15 19/19] media: uvcvideo: document UVC v1.5 ROI Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241114-uvc-roi-v15-19-64cfeb56b6f8@chromium.org> References: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> In-Reply-To: <20241114-uvc-roi-v15-0-64cfeb56b6f8@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Ricardo Ribalda , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Yunke Cao , Sergey Senozhatsky X-Mailer: b4 0.13.0 From: Yunke Cao Added documentation of V4L2_CID_UVC_REGION_OF_INTEREST_RECT and V4L2_CID_UVC_REGION_OF_INTEREST_AUTO. An example of a userspace implementing this feature can be found at: https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/release= -R121-15699.B/camera/hal/usb/ Reviewed-by: Ricardo Ribalda Reviewed-by: Sergey Senozhatsky Signed-off-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- .../userspace-api/media/drivers/uvcvideo.rst | 64 ++++++++++++++++++= ++++ 1 file changed, 64 insertions(+) diff --git a/Documentation/userspace-api/media/drivers/uvcvideo.rst b/Docum= entation/userspace-api/media/drivers/uvcvideo.rst index a290f9fadae9..1cdcd45907a3 100644 --- a/Documentation/userspace-api/media/drivers/uvcvideo.rst +++ b/Documentation/userspace-api/media/drivers/uvcvideo.rst @@ -181,6 +181,7 @@ Argument: struct uvc_xu_control_mapping UVC_CTRL_DATA_TYPE_BOOLEAN Boolean UVC_CTRL_DATA_TYPE_ENUM Enumeration UVC_CTRL_DATA_TYPE_BITMASK Bitmask + UVC_CTRL_DATA_TYPE_RECT Rectangular area =20 =20 UVCIOC_CTRL_QUERY - Query a UVC XU control @@ -255,3 +256,66 @@ Argument: struct uvc_xu_control_query __u8 query Request code to send to the device __u16 size Control data size (in bytes) __u8 *data Control value + + +Driver-specific V4L2 controls +----------------------------- + +The uvcvideo driver implements the following UVC-specific controls: + +``V4L2_CID_UVC_REGION_OF_INTEREST_RECT (struct)`` + This control determines the region of interest (ROI). ROI is a + rectangular area represented by a struct :c:type:`v4l2_rect`. The + rectangle is in global sensor coordinates and pixel units. It is + independent of the field of view, not impacted by any cropping or + scaling. + + Use ``V4L2_CTRL_WHICH_MIN_VAL`` and ``V4L2_CTRL_WHICH_MAX_VAL`` to query + the range of rectangle sizes. + + Setting a ROI allows the camera to optimize the capture for the region. + The value of ``V4L2_CID_REGION_OF_INTEREST_AUTO`` control determines + the detailed behavior. + + An example of use of this control, can be found in the: + `Chrome OS USB camera HAL. + ` + + +``V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (bitmask)`` + This determines which, if any, on-board features should track to the + Region of Interest specified by the current value of + ``V4L2_CID_UVD__REGION_OF_INTEREST_RECT``. + + Max value is a mask indicating all supported Auto Controls. + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE`` + - Setting this bit causes automatic exposure to track the region of + interest instead of the whole image. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS`` + - Setting this bit causes automatic iris to track the region of inte= rest + instead of the whole image. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE`` + - Setting this bit causes automatic white balance to track the region + of interest instead of the whole image. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS`` + - Setting this bit causes automatic focus adjustment to track the re= gion + of interest instead of the whole image. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT`` + - Setting this bit causes automatic face detection to track the regi= on of + interest instead of the whole image. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK`` + - Setting this bit enables automatic face detection and tracking. The + current value of ``V4L2_CID_REGION_OF_INTEREST_RECT`` may be updated by + the driver. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION`` + - Setting this bit enables automatic image stabilization. The + current value of ``V4L2_CID_REGION_OF_INTEREST_RECT`` may be updated by + the driver. + * - ``V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY`` + - Setting this bit enables automatically capture the specified region + with higher quality if possible. --=20 2.47.0.338.g60cca15819-goog