From patchwork Tue Dec 10 09:42:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901133 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 55DF12343AB for ; Tue, 10 Dec 2024 09:42:43 +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=1733823765; cv=none; b=EqsLh6lSvGWvaHQXsiA1wt95G5u1X3+eocaZ084G5G77lb7DVrhx+6N2yV4+OsZhn9qfx2App+1TdkhhA+fViGNPqyfqags7srEiinc9xVYG3AK/GWYEMtXJLituEOHfrNheeWRAN6BWBjqLqkkQbAZ/xVOj58+D5NBt1EPaOxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823765; c=relaxed/simple; bh=rmwFzpOA42dIRXNsU2drW2dWyEvkHqz3gtgDji2Och0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BDtt0Gi35qpBduRdwtGAI9DsxdojqahX8uLSPZdqgVt9TJhwu0e6b7shV7Znu0rCZZybNk3PIqW06w3Me0hvH7qjEkAdYTxzzAag9wvSWwJaBhlANBzAcpw9+UpCj4GWBoQhyrsUfGWer4fTEK/i4z6KeyH4IlJAn1CiMKY50SA= 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=g0ZcH7lg; 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="g0ZcH7lg" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d87ab49423so52343806d6.0 for ; Tue, 10 Dec 2024 01:42:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823762; x=1734428562; 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=mgd78hYMarmsibCfxN09wNv5VkU7Kl0GIxvAEFpsb+k=; b=g0ZcH7lgdUKw3HuKI6e6x0CocS+EEmi8/0aZiOK6E7N7SuqVCkgmDKlG39cWCCNTiY Hs7v7KP3GEXtVOPu8YpXPE+vSazCyN3b8EQJCpU7gDexXouh94cdpiH+qCS2iIDu+sh2 RFSB1h7BgEI22lGPLYDMEAUL8VOTCC6aiU8T4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823762; x=1734428562; 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=mgd78hYMarmsibCfxN09wNv5VkU7Kl0GIxvAEFpsb+k=; b=OqwpO0UKckZC2GRyCibyS8M8iewKy/zR7U1SAxeV2Apf1p4l2mYKjUnwMA4QQguqo+ WGH1OK0z75qv2z3RYFut7unUA3+OS/ZbBHr6xbI1XgYGLiNd2AHsrK8yRcRNSFKF2mA/ VXcO5cEi3CY+X4ByJmJOBXmw5LRJZaemuxFxZUT7tUEP4zXrAFSFleDT03kfQi+n7lUC KgNaIFwfW7OMkC9p1BZNEEmN3kRIIHYvvJEO7OOapAHofpAgwFZwOTReJFWpacV58n1D 2/nTecuDh3hVirPZeuFoPE6I3kl1FGo5+8gVkuLolpCjXtXJnnRHu1AQL9uTJjlfoz25 QOig== X-Forwarded-Encrypted: i=1; AJvYcCUTwWxVL2yztYNkJI4Dgt4XmSkNt2qVrHEW6zky3VZ4Pq0fJvaBIuL1W4j2OEi0BITv8OGfoTsi1cpk+g==@vger.kernel.org X-Gm-Message-State: AOJu0YynN7MikS99OdMagw/grgGRar17LFPoiV36+PjS3ehYkmMgtBm7 TXJyjE2rRkp+B0s2FIoK7h7iaCdk/KtkNvTJYqxUaFaVoFXc2OZ+yWyowlBT+g== X-Gm-Gg: ASbGncuc/JnqLwmcxo4R8a/1fwGdCZBCaPLdzNeHB/8dBb6j0iTdRGN+HFXmCdxki39 wJRHrR5Ld57/zSsrXTI8JcK2FTUYMrQquL6JEjZ/t/giPDtFp7e42ki1ok1RUBZxW69nT5o0c/k 06AhEqamJbwfVPpABszbTo248XUPTNRni5EwuScVamQD2VDE3OkwZWQG5jAn4MRMBZyEj0OC0d2 /oquB86PoIu3WCSRE/zbGvzoSR0ib+5nIQGtALvXPG7BF74GJqtamZYHVs5c5mPcOuPLm7NX807 kjcJNcXxOIRqm+wi+i8aMz5boNza X-Google-Smtp-Source: AGHT+IEoHdjAOUrtfazsH3n6Y31nFhgn307yyWvBWJlDV472zk6B1DrShdvegUY+dN1ioRJHlGD/zg== X-Received: by 2002:a05:6214:c25:b0:6d1:7433:3670 with SMTP id 6a1803df08f44-6d91e2d3799mr68330476d6.4.1733823762206; Tue, 10 Dec 2024 01:42:42 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:41 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:37 +0000 Subject: [PATCH v16 01/18] media: uvcvideo: Fix event flags in uvc_ctrl_send_events Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-1-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , Sakari Ailus , Hans Verkuil Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org, Yunke Cao 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 slave ctrls when the master changes") Reviewed-by: Laurent Pinchart Tested-by: Yunke Cao 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_ctrl.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 *handle, { struct uvc_control_mapping *mapping; struct uvc_control *ctrl; - u32 changes = V4L2_EVENT_CTRL_CH_VALUE; unsigned int i; unsigned int j; for (i = 0; i < xctrls_count; ++i) { - ctrl = uvc_find_control(handle->chain, xctrls[i].id, &mapping); + u32 changes = V4L2_EVENT_CTRL_CH_VALUE; + ctrl = 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; From patchwork Tue Dec 10 09:42:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901134 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 32C282343B1 for ; Tue, 10 Dec 2024 09:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823766; cv=none; b=kzIBpSLhzsNou/DUzZDC7wzmLp/LPj7sY1m8tatbS5OyY5cU5x5XFnpzrNrX8n/p+kqCF/dkqyVSE4z4LZ9HEpDKN5mFGNuYjpOlw1k5vjq1pNGwHD1H7AVo+Z+W1UTUv6vBuEyYK2xlJl5ez9Qi/6dfxMAGNi4EYGo6dSNndAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823766; c=relaxed/simple; bh=mSr7Gvae8SyDIcFX3igGruNP0QzUB8T910r8ssCG2qo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ub05dzseVKzCgMmrnto1Bt2Fu38ZNvD28YC1jZqZ9ib8wtI1r0QX0gyZQjUm3YKTOAnX2hTVQdAqpWO0/t2OYkuJ8XXn4tbEJR01Hdt6/877uAUH75LJzObcur5oYcyB8EFpGC2UxFhSlbswGN4pPfnoGc9duAl3hR4FxY2/enY= 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=h8WzHBDz; arc=none smtp.client-ip=209.85.222.179 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="h8WzHBDz" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7b68e73188cso435494985a.0 for ; Tue, 10 Dec 2024 01:42:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823763; x=1734428563; 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=HwpWIJ+QJD5X+8ABcKOk5KEH3gUKj+thJplDDZ9yydE=; b=h8WzHBDzvkRCFSEKhR9I0QeacLfbtVypZa7WsGwjotuo2JFtHzosFrY93IuXD/PZe4 IzoFc0bLCHpN3VIAAk/+yd1+jeM6o2fqG0m9mGBjm65WYBF7qJSwdyO/1IlVzWLetrE5 5b5D30x6ducuS/Wo8JNAEnqDDx5zAdMvYS0Zc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823763; x=1734428563; 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=HwpWIJ+QJD5X+8ABcKOk5KEH3gUKj+thJplDDZ9yydE=; b=LZ8JzIbniYu1M3PDhHTBPrbq/j4uJYKJPY3gLDjrVaBqBCbeeNdKEdm9sRFJXhTQE1 6cObCqDUm778Z6ugYa019xKOB4c8OCOcqo1NdZDCgcJX7BsgEXRj2l+Y+zD96gQxw5pw mMOwfZqu6qS+tMN8c4bSINXLPCzFU4qlPJCzfM4qkTLF3byVsXLVQAgHnm6kmZnF2SaP 0dc2JvAX+l+SEWWhoVopSYXP1j/NFZcPiqRbxWZrD/w151dUNEBAUamihbF/lgAZGzQo 7pcQzJj8lc9zYHct8KpP00Kc46eTPvDPCOS89fec7lPRYxvoUw4+RoEb5r0cIKurj4pY RAkA== X-Forwarded-Encrypted: i=1; AJvYcCXrKCCCQzDHHLnx9hGrlBOjFFFYNkoyXl1X6OerC9jghnyb3WV8TOd6zuTUJCqFqYhV5i4bcfWb1uWKeg==@vger.kernel.org X-Gm-Message-State: AOJu0YzcwafjJyvxbM2VG8r2LP9JH668P2vZLjPt8Yu4Ds+mfYxTM2wP AfZzswI2ixwi+aBdPTWhKv+x8TM5+kKkKknTQO82lR538dKS1DRDZ/Y3qhUwuQ== X-Gm-Gg: ASbGnctRwFT2jMgNQhwC1h3gmBwAF94LrckZzfrtopyv5CzfESINav9gOZn9qBIb+bH DnOtHWhPWne98O9BBozA/VZBu/7vm1zM6fLs3l6uLmZulB34LMdVS1wfRHG/pX3nN18ZboJwVb6 5roR22xZmZ+ncVul/lZhq43VEmZZyUpJM1rWTnz0hjzGTDPCPAJOA5qNJuQT45OnODBErPASHbL TE7Wc6B7jojZImUhUT2i5K8am7dzdBsNdU7DHi/BSaScYTd+H6SjhwMTPS4S6AbL2N6/u9CYFv+ V+apYN5dEPOBZV9oRsltm/G7ZA34 X-Google-Smtp-Source: AGHT+IFa2TEpe2Qesl7yI5CyQNIsC6eMEK14b9r7ylhftJYRY2kreBYXeuXMKDreeRGeTp879aRXJw== X-Received: by 2002:a05:620a:448b:b0:7b6:604c:f334 with SMTP id af79cd13be357-7b6dcec6bfemr561814385a.55.1733823763159; Tue, 10 Dec 2024 01:42:43 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:42 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:38 +0000 Subject: [PATCH v16 02/18] media: v4l2_ctrl: Add V4L2_CTRL_TYPE_RECT Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-2-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Tested-by: Yunke Cao 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/Documentation/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_ctrl_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 *ctrl) 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 = ptr.p + idx * ctrl->elem_size; unsigned int i; @@ -1172,6 +1177,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, return -EINVAL; break; + case V4L2_CTRL_TYPE_RECT: + rect = 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_ctrl_handler *hdl, case V4L2_CTRL_TYPE_AREA: elem_size = sizeof(struct v4l2_area); break; + case V4L2_CTRL_TYPE_RECT: + elem_size = sizeof(struct v4l2_rect); + break; default: if (type < V4L2_CTRL_COMPOUND_TYPES) elem_size = 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 = 0x0101, V4L2_CTRL_TYPE_U32 = 0x0102, V4L2_CTRL_TYPE_AREA = 0x0106, + V4L2_CTRL_TYPE_RECT = 0x0107, V4L2_CTRL_TYPE_HDR10_CLL_INFO = 0x0110, V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY = 0x0111, From patchwork Tue Dec 10 09:42:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901136 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 140BD2343DA for ; Tue, 10 Dec 2024 09:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823769; cv=none; b=gyJWQ0A/BZ3Pg6csvVX5Jl/wSrQuhpg8fTlWhRfeI0AjYjkYcTMOdKhGbdApSzNNsefFBrC9Ol6Ji1edTjCnuUFxXTmu7HyCCIoRZ7dLW+CmW0w12rIomSZ322kjWPhwpdkZhFUfdqNU05lGubr9PRW0rMcQZSwkIA/+pEFqu8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823769; c=relaxed/simple; bh=hRXGdIGbTI2YB1HYZWU7dqZqGD2NjOESoH3kkBmtgfM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nykUeEkBaYreR2TxsN+tDBMxqeQUMSt0RdSi4bAS3Gzu2itd8UhsXsgKR97fR2vm1KwT7jf4xZltt9E4WCroOy2fTsmHvBiQILLYglE4QF7nqhSgzR4s4j8WCNPlKuxNQTGOhUXPfjs77ss85ftN6Isc4szVGfh6eJ7xkYjSIZA= 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=XL2mMr7g; arc=none smtp.client-ip=209.85.222.176 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="XL2mMr7g" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b15d7b7a32so368558085a.1 for ; Tue, 10 Dec 2024 01:42:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823765; x=1734428565; 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=p6ThprH3RJFEIOmz2KNW6/UEBeFhYx/tQ+j/vnjRjiI=; b=XL2mMr7gdPRdo7jm4K1qssy6sxKHIjAIlpj2NWjfrU2gZjlAkripV8RwH1/mL2L5hK qXtnzL2QlhBIWvLghY4wHmfpa810i+sXyq0vPIPc47xxUcUreLQF2q+GtHnh51boNcVu MnRf9wWIhE1lGJbQkdjtC4kk6KIOSxE9S6Ji4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823765; x=1734428565; 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=p6ThprH3RJFEIOmz2KNW6/UEBeFhYx/tQ+j/vnjRjiI=; b=tYWRjsEiBLxy40bFQz5bmFC2tmQIv9TCXKHswGlcGu2RZM5+YsUC6VfX3MkbL/dX3D bgmvBk3Na+yHIeOqCy8O/SvDp4mrFqaRjTVkNMGi0w6wH7FEu3nHXJ0EEuaVvVL6t3gm n1QBFa29KQ3FY3wlPGMJpgbLwfMFtIDe8Wmewts1qCt8Vc0bCn+LI2zEnwd94zs9BWgL NVjsQQzIrhln/+cWBXws2wk2qf5bqbws+lkzXNtvUo0+lTbwfnlqjTKtuEv2bl7NfBPa MfT2Xf8EBkauzFNrr+wphDOft7O4GSh0TxT23aJylFzfloCY+I2fFih1sL3T4g5z6rTJ NGjw== X-Forwarded-Encrypted: i=1; AJvYcCXB72EEHAChTF/fyOHqIEuPOdWdrM8NrUmW0IAjo91PxTJ5ZjL+FmLhs+Er2rw4sDh6FRD/2Lmi8lLe7g==@vger.kernel.org X-Gm-Message-State: AOJu0Yzu+nQlJvwBhpCWh2ssffuDMVAgzvQlDF9z6Ugh/4d2RuytwkIH Lzqlzix9I58ouS2uXVFgNevxZ+TqLSNK0FFt/nrhiJs0qnGoyODvfNUoxhL7ZQ== X-Gm-Gg: ASbGncsUd7PechicYmJ9bvYaqjAhEWuxynjkZjph2r5HYSpwb3w6FIXv0Z8KskfjXjg YE2PzW6wp8wCJPYTEj3vL8LMH58jiYtPieuHA71CIa+ZVFgctWTAGSywluh/KJ78r6pljzk7nGk Onp22mb8cEhmCKud6Y31F4GT2Qr45Aj8aQLZA3BJtIx8u1+JjVMcivhQFshZnlnMLodlraTWycV hjcngYC7SgSb2clRRRifxd5/beWNTeNfpFIiI7374cWRmRyn6OVw0TKNjwi1E9EZQzOird4rhiM Pf7AUKdkLYlu3GOBnB+qzIzoVV5r X-Google-Smtp-Source: AGHT+IE8KJtS3tAAh/5noJmxNQYPUDI9sAZE+6jdGsqEt5//zqvoWpUdFq149mcin+dkDWHICoT1eQ== X-Received: by 2002:a05:6214:21ea:b0:6d8:8480:27e with SMTP id 6a1803df08f44-6d8e7125d1emr207267976d6.11.1733823764806; Tue, 10 Dec 2024 01:42:44 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:44 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:39 +0000 Subject: [PATCH v16 03/18] media: v4l2-ctrls: add support for V4L2_CTRL_WHICH_MIN/MAX_VAL Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-3-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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: 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 Tested-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 value 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 maximum + 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. - 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. 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/Documentation/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. Return Value ============ 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 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 = 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)); v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx214_ctrl_ops, &props); 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) 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)); 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)); + 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, struct v4l2_ctrl *ctrl) return ptr_to_user(c, ctrl, ctrl->p_new); } +/* 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 value */ 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 = i; if (cs->which && - cs->which != V4L2_CTRL_WHICH_DEF_VAL && - cs->which != V4L2_CTRL_WHICH_REQUEST_VAL && + (cs->which < V4L2_CTRL_WHICH_DEF_VAL || + cs->which > V4L2_CTRL_WHICH_MAX_VAL) && V4L2_CTRL_ID2WHICH(id) != 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; } + if (!(ctrl->flags & V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX) && + (cs->which == V4L2_CTRL_WHICH_MIN_VAL || + cs->which == 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 = true; if (ctrl->cluster[0] != 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 == 0 || which == V4L2_CTRL_WHICH_DEF_VAL || - which == V4L2_CTRL_WHICH_REQUEST_VAL) + if (which == 0 || (which >= V4L2_CTRL_WHICH_DEF_VAL && + which <= 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 = helper; int ret; int i, j; - bool is_default, is_request; + bool is_default, is_request, is_min, is_max; is_default = (cs->which == V4L2_CTRL_WHICH_DEF_VAL); is_request = (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL); + is_min = (cs->which == V4L2_CTRL_WHICH_MIN_VAL); + is_max = (cs->which == V4L2_CTRL_WHICH_MAX_VAL); cs->error_idx = cs->count; cs->which = V4L2_CTRL_ID2WHICH(cs->which); @@ -432,13 +459,14 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl, /* * 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 = 0; j < master->ncontrols; j++) @@ -467,6 +495,10 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl, ret = -ENOMEM; else if (is_request && ref->p_req_valid) ret = req_to_user(cs->controls + idx, ref); + else if (is_min) + ret = min_to_user(cs->controls + idx, ref->ctrl); + else if (is_max) + ret = max_to_user(cs->controls + idx, ref->ctrl); else if (is_volatile) ret = new_to_user(cs->controls + idx, ref->ctrl); else @@ -564,9 +596,11 @@ int try_set_ext_ctrls_common(struct v4l2_fh *fh, cs->error_idx = cs->count; - /* Default value cannot be changed */ - if (cs->which == V4L2_CTRL_WHICH_DEF_VAL) { - dprintk(vdev, "%s: cannot change default value\n", + /* Default/minimum/maximum values cannot be changed */ + if (cs->which == V4L2_CTRL_WHICH_DEF_VAL || + cs->which == V4L2_CTRL_WHICH_MIN_VAL || + cs->which == 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, } } -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 = 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 = 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 from_idx, + u32 which, union v4l2_ctrl_ptr ptr) { unsigned int i; u32 tot_elems = ctrl->elems; u32 elems = tot_elems - from_idx; + s64 value; - if (from_idx >= tot_elems) + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + value = ctrl->default_value; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + value = ctrl->maximum; + break; + case V4L2_CTRL_WHICH_MIN_VAL: + value = ctrl->minimum; + break; + default: return; + } switch (ctrl->type) { case V4L2_CTRL_TYPE_STRING: + if (which == V4L2_CTRL_WHICH_DEF_VAL) + value = ctrl->minimum; + for (i = from_idx; i < tot_elems; i++) { unsigned int offset = i * ctrl->elem_size; - memset(ptr.p_char + offset, ' ', ctrl->minimum); - ptr.p_char[offset + ctrl->minimum] = '\0'; + memset(ptr.p_char + offset, ' ', value); + ptr.p_char[offset + value] = '\0'; } break; case V4L2_CTRL_TYPE_INTEGER64: - if (ctrl->default_value) { + if (value) { for (i = from_idx; i < tot_elems; i++) - ptr.p_s64[i] = ctrl->default_value; + ptr.p_s64[i] = 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 *ctrl, 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 = from_idx; i < tot_elems; i++) - ptr.p_s32[i] = ctrl->default_value; + ptr.p_s32[i] = 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 *ctrl, 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 = from_idx; i < tot_elems; i++) - ptr.p_u16[i] = ctrl->default_value; + ptr.p_u16[i] = 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 = from_idx; i < tot_elems; i++) - ptr.p_u32[i] = ctrl->default_value; + ptr.p_u32[i] = value; } else { memset(ptr.p_u32 + from_idx, 0, elems * sizeof(u32)); } break; default: - for (i = from_idx; i < tot_elems; i++) - std_init_compound(ctrl, i, ptr); + for (i = 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); +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 = ctrl->p_cur; @@ -1296,6 +1362,8 @@ EXPORT_SYMBOL(v4l2_ctrl_type_op_validate); static const struct v4l2_ctrl_type_ops std_type_ops = { .equal = v4l2_ctrl_type_op_equal, .init = v4l2_ctrl_type_op_init, + .minimum = v4l2_ctrl_type_op_minimum, + .maximum = v4l2_ctrl_type_op_maximum, .log = v4l2_ctrl_type_op_log, .validate = v4l2_ctrl_type_op_validate, }; @@ -1768,7 +1836,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_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_ctrl_handler *hdl, break; } + if (type < V4L2_CTRL_COMPOUND_TYPES && + type != V4L2_CTRL_TYPE_BUTTON && + type != V4L2_CTRL_TYPE_CTRL_CLASS && + type != V4L2_CTRL_TYPE_STRING) + flags |= V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + /* Sanity checks */ if (id == 0 || name == NULL || !elem_size || id >= V4L2_CID_PRIVATE_BASE || @@ -1900,6 +1977,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, handler_set_err(hdl, -ERANGE); return NULL; } + err = 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_ctrl_handler *hdl, if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) sz_extra += elem_size; + if (type >= V4L2_CTRL_COMPOUND_TYPES && p_min.p_const) + sz_extra += elem_size; + if (type >= V4L2_CTRL_COMPOUND_TYPES && p_max.p_const) + sz_extra += elem_size; ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL); if (ctrl == NULL) { @@ -2006,6 +2088,22 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, memcpy(ctrl->p_def.p, p_def.p_const, elem_size); } + if (flags & V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX) { + void *ptr = ctrl->p_def.p; + + if (p_min.p_const) { + ptr += elem_size; + ctrl->p_min.p = ptr; + memcpy(ctrl->p_min.p, p_min.p_const, elem_size); + } + + if (p_max.p_const) { + ptr += elem_size; + ctrl->p_max.p = 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); @@ -2056,7 +2154,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_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 = 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); @@ -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); @@ -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); } 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 v4l2_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); @@ -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); 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 == VIDIOC_S_EXT_CTRLS || ioctl == VIDIOC_TRY_EXT_CTRLS) { c->error_idx = 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->elems. + * @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; 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, thanks - * 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_create() + * to convert a pointer to a const union v4l2_ctrl_ptr. + * Use v4l2_ctrl_ptr_create(NULL) if you want the default, minimum or maximum + * 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 just 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); /** * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. 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 enum v4l2_ctrl_type { V4L2_CTRL_TYPE_INTEGER = 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 /* Query flags, to be ORed with the control ID */ #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 From patchwork Tue Dec 10 09:42:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901135 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (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 302BD210F69 for ; Tue, 10 Dec 2024 09:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823769; cv=none; b=JKlvaIlYwJGku7oS52t09ZDHmvzmCmhDH6IQ4yFzKPgeJ0gCIoqfyWIvanVlqXR6aLG0i9WFXfTFgnMnR7tneDD4g0f6yeb/AI/qnQQUuYB7PR1fJqp0TXWxBYkkjLdk17OZRDFnXKbpEoSQlP+O3NVQeahddzVIj47N6q5VOhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823769; c=relaxed/simple; bh=K0DZI4UBFz6Q1LavHWAO5fp1PzEV7p8YAKo5Gp+ADQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oRut+HVMtII+hhIe8DXdetFBWjcQ6ExlYNLSXZfTJcg35xyEG49WiL49+YS/4eLtraw0aD74xgjBcnpuw6QrcQGAmhI8p76+f8ZVt06yXLdqWImkzHk1m/fGoNw+KtzLnBoBcn/mLHmCcFmshLtJ5QYk4OW7nlyABNplPBwPzak= 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=ODvp8bFM; arc=none smtp.client-ip=209.85.219.41 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="ODvp8bFM" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-6d888c38841so42072676d6.3 for ; Tue, 10 Dec 2024 01:42:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823766; x=1734428566; 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=mf5LuVEPO74SAkZYBzrIXfOzplKA9uICYltmS7j18Lk=; b=ODvp8bFMPzJS7ZzEPtMgocFmFvOqb1zUnnsB2AiH7hD71egqUt7xXD/HwGUR3Fi6V2 xFomojbgsFPEHVhB8PQnoqpNwcWZhyeNl1xxCVjZLgORVxV7PHia+dJXP1IfsJvslTgh f42AaaoW03IubAZKLrZMs6qHMqE4ygKvXhqZ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823766; x=1734428566; 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=mf5LuVEPO74SAkZYBzrIXfOzplKA9uICYltmS7j18Lk=; b=ar1SuroYAVlUHCSshKMLMKSve9hdcFtw91lYXJzcqH9PH00fxdNLiJJo1e2EYr1vWM Y1SK3PQYbevgkW/MqnEFuffxRh0h5D4LdYQWpbNJygeALTPmCze8IdAivx0M3iQrc4bE mROPpZPI/szpOGJdcsRR8sjQCrzxEZr62t8HQf8A+LhEjr8TXs67P2YfXk+o8v34bfkb bfH05Omhgdz5VI+2kTsnlCKM5a3KuDj3iNXFb1WDoAas+ygydQBt/tekJ0pmoFiUc4Zs GiY0DxFr5PdKBNwj9F0DgJKIRfemi4ld64dPNrIOdCaOHCtJw0v5fOMswuKfQBWCh718 hktQ== X-Forwarded-Encrypted: i=1; AJvYcCXzLcmoc/WNqZetuNk+u2HhqdrP/Bc5MU7IOneY04UnHP61L5SqHuIQN7ovtg6xINNHVMTODnmEOFn1Eg==@vger.kernel.org X-Gm-Message-State: AOJu0YzG930nBoKDZhUFBmXtC9FebCc954imogdXCEl/U/M1IR3Km4b8 vQ7eBW2rmrO4uCN+8xA3ryHI4MUkO8sXNawaOxnX8w5b79yqmpeBJJLScbhl0A== X-Gm-Gg: ASbGncu9yH4u1+/R6VRMfCMyRkvV2UweVVjX3+5CFJpx3H1s9jnjEDBoTpglKyVsar/ YDgrclkiOeFqiPGS00MVGYP7LBP1Hx0PNOTog6SKJfPX+AO4ZwVAu0VN1AgGrqTcxIP3FJf5Zxs BiIp2oqMnWZjROdeby8+kSpy3tiQ+wJeM0NdyoCFd0Ng5Xwr9h/qhRTpmk34IO5ZOt76dpkQ4po CJuOrZ7jKAElCssQoQgV0Tft/gfauQAHVjwQkBsmQrV1GAV4zrU9/E19YkuSJPu662b6TVMThOr Nx2QwCvQjtxizixXvprmg/TodCwh X-Google-Smtp-Source: AGHT+IGT4gzfITvLDwHStH5Rg/t89JsU98DuOgF0s+ypUy2x7EUDyd1LNn2KVDFdffsHdPjaiYA0UA== X-Received: by 2002:a05:6214:76b:b0:6d8:8165:ef21 with SMTP id 6a1803df08f44-6d8e727e5f5mr249233116d6.49.1733823766038; Tue, 10 Dec 2024 01:42:46 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:45 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:40 +0000 Subject: [PATCH v16 04/18] media: vivid: Add a rectangle control Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-4-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Tested-by: Yunke Cao 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) #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_int32 = { .step = 1, }; +static const struct v4l2_rect rect_def = { + .top = 100, + .left = 200, + .width = 300, + .height = 400, +}; + +static const struct v4l2_rect rect_min = { + .top = 0, + .left = 0, + .width = 1, + .height = 1, +}; + +static const struct v4l2_rect rect_max = { + .top = 0, + .left = 0, + .width = 1000, + .height = 2000, +}; + +static const struct v4l2_ctrl_config vivid_ctrl_rect = { + .ops = &vivid_user_gen_ctrl_ops, + .id = VIVID_CID_RECT, + .name = "Rect", + .type = V4L2_CTRL_TYPE_RECT, + .flags = V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX, + .p_def.p_const = &rect_def, + .p_min.p_const = &rect_min, + .p_max.p_const = &rect_max, +}; + /* Framebuffer Controls */ 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 = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL); dev->ro_int32 = 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); From patchwork Tue Dec 10 09:42:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901137 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 42A752153D4 for ; Tue, 10 Dec 2024 09:42:55 +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=1733823777; cv=none; b=jSrAl4MoW2m7F/WKKiaTqTDtb7ZbyjsZJyxFcvKsH43k+DmuztjXyCDxQs9uVZbRFUiLX9bwjC3cPVcsxOsiSv8zF0PX5T4oDSlNBcx/gVrpfxwv06jlh2pmTGHU/wCCeGXp5qIWRePUwF0Kh/QhTQAsJkEITkW8pXrK1e+QfCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823777; c=relaxed/simple; bh=gv8rUdmSV4UR2dPzdenPsbmaBxNvhydo09k/zl6tPLc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sfhaQ0gWiAqwPE80cDsGIsEwN3w3DbRz1BDlzFQwfzG6Z6dJOxvGRNyO5tIJ12EGXv1Wx77IC14vHCMP2xu9UBQ36TSRmYmb81Z9hREPFyLwG+gR5VFzDrb8Nn+rgX5fU08on/IrTPf+pFdYIsBNYJSIS1yhLDTqDXHhwqc+cpA= 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=FEX1WuAf; 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="FEX1WuAf" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7b6e4d38185so15915585a.0 for ; Tue, 10 Dec 2024 01:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823774; x=1734428574; 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=aay2950jnBOP0EyAzMLsHhQ9XSwerGPpxxvrerX51do=; b=FEX1WuAfF3HIY3dJGLy7KNWvB6n58yuCwwEFIg6zmlg6mkcUJQAVL9611dzHZSETpr dEOr0dJnzNjDqtN4WxiUHCUbygE72h3pcNAdnh84vfsQtqbLg3DyDkgVgZE+UFBg45fv 2gHI21Bl6sVnZc9YPiZAPB8PLWqrH3hfL797s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823774; x=1734428574; 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=aay2950jnBOP0EyAzMLsHhQ9XSwerGPpxxvrerX51do=; b=WqtoxPZL/kVrX+DX3HTE1S96F9Mh+TkptE8dVD4vWMixXulAceEYt6ps/hORNAyu7r O4MzleE2l4oN9C6ISQeLmBC6/XjfsAlHTm2kdwGz65jIX1RHde9krFS+YVdxCzeMRB+5 trDelRKLQWDXBSJxpEB2Ue4cCeCmuK3dhnrru2hzcsOvMLBSEYddiKnT0YILR4v12Uth hYLjjyx8yrIbLhs/YEokHtk434EDZREIEz9/Q3KdCmyDJk2c/F8AVz0SJB3U1Oip8x+9 1WV2ZMNejtOH571rHDq1JWqX/ytTNx3q9PJY4R02+NYq7hLpBlAI+iWqvWBM6epDDeKO f1Bg== X-Forwarded-Encrypted: i=1; AJvYcCU1lbdJ56j4DTBDO71bgsF21LSYITcug35zP935bmD0Nht3jZl9kJHV8QXB9Bp4lXb59cSr+nc5w5BsTA==@vger.kernel.org X-Gm-Message-State: AOJu0YyhDMoqC12XIYD/JZgYlhgMleARdhrH37Kvzv7wSm8aSV6/Bpcc MTTWutjF7Qz3ChIhcdnwp/WKvuo8LZygltRPcc98cGZuX+Y/FYsNjjOIc7uaAg== X-Gm-Gg: ASbGncsnIRuJDs9RljNT87CddxhUlgZaeVpiHFcibfvIks/3GE95oTKlZNH4cQdqKFs lhlmgIE4iusB/hLarjDq0Ds3m5jHdx6X8ufyH0rEJWY7sz8H+nBymDXFUy1tRkb6/nJWOibgGpZ /ahx7qeFosbw0HCTHYn/qt6oTAJdm+/ySNzx4QKMyyzAEgnl2YtFGIm8pwRni40DBYJztb4eBPt 8LSl0HicfAfis+CK14q3fA1QqrFILrulNKrFTTXhjFWXkh0YMmrhGo4JgZUeR5qeLjEy1tk57X6 DV/bMlEUFOk2cDapIywe+OxgVtkc X-Google-Smtp-Source: AGHT+IHvsVSX4cF7Uq+tXoU3l7S6TpqvBBTt/QzYkHDT411ehQjvH1Xv2+t0pEkiDu6zBFsC1FpPbA== X-Received: by 2002:a05:620a:2905:b0:7b6:d241:d4ae with SMTP id af79cd13be357-7b6dcebc84fmr718784185a.42.1733823767088; Tue, 10 Dec 2024 01:42:47 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:46 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:41 +0000 Subject: [PATCH v16 05/18] media: uvcvideo: Handle uvc menu translation inside uvc_get_le_value Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-5-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 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(). Reviewed-by: Hans de Goede Tested-by: Yunke Cao 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_ctrl.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] &= ~(1 << (bit & 7)); } +static s32 uvc_menu_to_v4l2_menu(struct uvc_control_mapping *mapping, s32 val) +{ + unsigned int i; + + for (i = 0; BIT(i) <= mapping->menu_mask; ++i) { + u32 menu_value; + + if (!test_bit(i, &mapping->menu_mask)) + continue; + + menu_value = uvc_mapping_get_menu_value(mapping, i); + + if (menu_value == 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 == UVC_CTRL_DATA_TYPE_SIGNED) value |= -(value & (1 << (mapping->size - 1))); + /* If it is a menu, convert from uvc to v4l2. */ + if (mapping->v4l2_type != 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; } @@ -1060,32 +1089,6 @@ static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain, return 0; } -static s32 __uvc_ctrl_get_value(struct uvc_control_mapping *mapping, - const u8 *data) -{ - s32 value = mapping->get(mapping, UVC_GET_CUR, data); - - if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { - unsigned int i; - - for (i = 0; BIT(i) <= mapping->menu_mask; ++i) { - u32 menu_value; - - if (!test_bit(i, &mapping->menu_mask)) - continue; - - menu_value = uvc_mapping_get_menu_value(mapping, i); - - if (menu_value == value) { - value = 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 *chain, if (ret < 0) return ret; - *value = __uvc_ctrl_get_value(mapping, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + *value = mapping->get(mapping, UVC_GET_CUR, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); return 0; } @@ -1287,7 +1290,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, { struct uvc_control_mapping *master_map = NULL; struct uvc_control *master_ctrl = NULL; - unsigned int i; memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); v4l2_ctrl->id = mapping->id; @@ -1330,21 +1332,6 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->minimum = ffs(mapping->menu_mask) - 1; v4l2_ctrl->maximum = fls(mapping->menu_mask) - 1; v4l2_ctrl->step = 1; - - for (i = 0; BIT(i) <= mapping->menu_mask; ++i) { - u32 menu_value; - - if (!test_bit(i, &mapping->menu_mask)) - continue; - - menu_value = uvc_mapping_get_menu_value(mapping, i); - - if (menu_value == v4l2_ctrl->default_value) { - v4l2_ctrl->default_value = i; - break; - } - } - return 0; case V4L2_CTRL_TYPE_BOOLEAN: @@ -1592,7 +1579,7 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, ctrl->handle = NULL; list_for_each_entry(mapping, &ctrl->info.mappings, list) { - s32 value = __uvc_ctrl_get_value(mapping, data); + s32 value = mapping->get(mapping, UVC_GET_CUR, data); /* * handle may be NULL here if the device sends auto-update From patchwork Tue Dec 10 09:42:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901138 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (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 E7E9B2153CC for ; Tue, 10 Dec 2024 09:42:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823778; cv=none; b=I9l6257Yg+aDTt+MVvpc83BgYu/k0Ha3hW0IWF6blYY0n2axF3P3R8dTKL0ACrbw7PC0w4YJGB+R3kgUkECAZ3swUhjtrLZNMhDCUNG95k6Iubt+MUkxq8AYw1Whix+KiO0rMPt0tnY37ixx+Sl7vDGaX1xA3cbHSjXsMNLPKXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823778; c=relaxed/simple; bh=u449lsO4Hxwuzsi+uevB0tOEaOX42zxpyNVYt6QiE+Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pjGRvWgJmc9wkv+tGRguZENpTblghnokdC31M97r3rm1pKtHyyBziXulk1vvAwTKFhVal/jS7dLT/R1rl7v/6+1rJoVFxpmoJ7xIX+boysrOpgLu8usisc1zR+/iRt/fJwOq5/KUw0zPalOcN20Q5dALdBHtnjX4ldaJpK3aYAA= 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=PLz7bCwU; arc=none smtp.client-ip=209.85.160.175 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="PLz7bCwU" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-46753242ef1so34989241cf.1 for ; Tue, 10 Dec 2024 01:42:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823776; x=1734428576; 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=CWfbsZInLShg4gyqs0rpMPp74K9ThJEcDiTxSB3xYgo=; b=PLz7bCwUPOjzxNjoeP4Zhx6RcnEpz6azTb0zg1/H5aVLr5fPrUKaZbzYNebuPZQrmO /AtSsiJY7cUyiCcvMXyR0aG/m9OoQ7PHBiyMOQcsDsvCdaKgF/+qiAdbmDJG9466jo5Z 7Gft6p6Y5qQHem+zOsHlvz9CzAuiqG7kb39xE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823776; x=1734428576; 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=CWfbsZInLShg4gyqs0rpMPp74K9ThJEcDiTxSB3xYgo=; b=qiDVB1VIkXLhDw7fvhxaLULjmKhmb07fdFBtEw7ti+js/3MMWEtSF9q4WK/1n4Ggj5 5dNOG7bNgUnTybOxJNiy8AhVIfb6Z0cwJVQfXtcf5++LmNUoZPa07GSPRA6R2H+oKYBV mAfscFA7z7p3xRfRUt6aOvPs2bF+4HBoKSQUaholk8m9RFPfHGCNa03mWnFbZXyNDQ85 yPiei8meC1Adv9Q0IN2FAgNFBSU1rolPpeAf2YpX009UFxHCqZ2TTezauZDEvknSx+Wj o/Q0Op6CpkiGV0hNwXkyXd2ENr+STiFI1xoYVicotJZTbzh/Pk4Iuq83nY9nJQ2F5mMH KpNw== X-Forwarded-Encrypted: i=1; AJvYcCWzSZ6jNgv/GLT7Q0ewoWFHOpM950I/nOj7kLxhPYBoOtx2+8gLSaNQEhO/aTNxE33el692sSNJhostFA==@vger.kernel.org X-Gm-Message-State: AOJu0YwrYFyUautaVfko5U4KXsVtZywIQf9lzaKR7mjJAwuBtM1LApEw 96IwzjZI4xjU5umvhoNXLJTPI1x1zegOtYhJC6c0/Mqf6hdGYp/21xJgu+IRhQ== X-Gm-Gg: ASbGnctiqSFvJtyJSPeqd7gKaHbLAfn/q7XcSSnm/dYby42MvuF4OXmPtEGcz0ICB/B ZGAaauwTQu2TlAzVlekzCEhM5cTKgs00EAZA/vs3jV7HqRr1hRwhLHwgiqJsKH4uTj0Fsal6wnX p8Wwx13ytcGXM+0EtmtCjgFpxJSuGd+OW4dSa55E4RWzyiKt+8R4mm+0TGcpI0ne6jRm/gAYJ7o q5Huz32TDkR/Y7O/oLrEpZUeq/uLApgGuErvuhDJQP5y5kG2/Obc/dGzJMJHx4NzUEnLzVdbg+X rROh5kijiMmpf/ZGpBmLU1j35rBl X-Google-Smtp-Source: AGHT+IGuOmp0WbqkpDp2dV3LPmaXUEWbDVLaY4faBYplusjjW5QMSEy+Ggl5P5GPgFHXeQMWUS+EDg== X-Received: by 2002:a05:6214:5087:b0:6d8:8d16:7cf3 with SMTP id 6a1803df08f44-6d91e43ce55mr65152556d6.40.1733823775842; Tue, 10 Dec 2024 01:42:55 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:54 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:42 +0000 Subject: [PATCH v16 06/18] media: uvcvideo: Handle uvc menu translation inside uvc_set_le_value Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-6-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 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. Reviewed-by: Hans de Goede Tested-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 77f7058ec966..987a9700bed9 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -939,14 +939,22 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping, int offset = mapping->offset; u8 mask; - /* - * According to the v4l2 spec, writing any value to a button control - * should result in the action belonging to the button control being - * triggered. UVC devices however want to see a 1 written -> override - * value. - */ - if (mapping->v4l2_type == V4L2_CTRL_TYPE_BUTTON) + switch (mapping->v4l2_type) { + case V4L2_CTRL_TYPE_MENU: + value = uvc_mapping_get_menu_value(mapping, value); + break; + case V4L2_CTRL_TYPE_BUTTON: + /* + * According to the v4l2 spec, writing any value to a button + * control should result in the action belonging to the button + * control being triggered. UVC devices however want to see a 1 + * written -> override value. + */ value = -1; + break; + default: + break; + } data += offset / 8; offset &= 7; @@ -1988,23 +1996,23 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (!test_bit(xctrl->value, &mapping->menu_mask)) return -EINVAL; - value = 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 == UVC_CTRL_DATA_TYPE_BITMASK) { + int val = uvc_mapping_get_menu_value(mapping, + xctrl->value); if (!ctrl->cached) { ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) return ret; } - if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & value)) + if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & val)) return -EINVAL; } - + value = xctrl->value; break; default: From patchwork Tue Dec 10 09:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901139 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 9A6E22153DD for ; Tue, 10 Dec 2024 09:42:57 +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=1733823779; cv=none; b=U0I0lBHjPPvXaP06To1q8ztmLofVjqEmF3LE0yu+dnhSCQ0+UtiAyTA7OQT5nmD9WFpasU2XRb1vHwDoEgtxRM0B71uGeeZtoGQM/8mw4bJvzVN+FSnWQexMNUxGMj8MKcl17PkO8N++h5nIesAhbJ7eBXIPTVyMKxt0h0P8ZkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823779; c=relaxed/simple; bh=GtKZpTsdb2dvroqPwQk6P+D+VqxjXsWA4K0LgOtCk+w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TVVkfCZc9xZbI/g1xswUWNARfFBS9m68gWfONVARB3S47xdfLVqPCUsw6GT+G0829DhV3YLAxOKhwAZCRy9Yvx6hd3hSEszU+qTIFDKbVbvkfZzke1eSUrZGi4QVC+zAeJKDV40989uxXCqwmrCCY3QP5kqfyC2iFq+SmYuSyGg= 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=ZBVm9jsu; 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="ZBVm9jsu" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6d89a727a19so56024256d6.0 for ; Tue, 10 Dec 2024 01:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823776; x=1734428576; 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=rUxdbTzsjHBE16Atfsk1TxmxgMhTKgD4TgYnLbGJtwM=; b=ZBVm9jsuunPVsO/Npib35CfvTPs3OhsMfqN+toWkr/11DzcCrRPTqAMtzETwgq4uaB FeQJ+WyEYzwjy2rdrHy+57nb6dElitH9qoD8haPbmlEA3jNDZEu+NdIEdVubkKtZQanf uM1qvnkk5BJ6RKGAvhd6bg2yxMwqvuF8KUefw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823776; x=1734428576; 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=rUxdbTzsjHBE16Atfsk1TxmxgMhTKgD4TgYnLbGJtwM=; b=gqQriU8rcUjHRQbY7QADoYMWI78qPEsZL6gU6XvXIU3lNYMCcV92DjM9tXVUNLn8CH qWfGRvFI3ycxsLtPQtQ2omOSoXqhac3029u6I2LqNfYTh4taI8/syhozipDbNPPOyzQe yN0ueGuc2uNzFVNL6w2OYRUEIFa36HwnyruGWiHR1VGGgfMislEfyFvwOBLBekIpPFh1 476ZOkla4cuNACJ47s9nU/WjVxf4CcLe3dM1YHLZA7/K34kb1UkgQ+GSEseiC24gXkUc wGseaWRa39+bUzcRXCVwY5cLmYwl9WCYfWy1UxrsnPT14d40kH51jKkaEU1fhRc9EN2I skaA== X-Forwarded-Encrypted: i=1; AJvYcCXlwtQRl35gaMO4OIzOy/RU2lM0AtI5yqu3mfiWsad2vPrn8y3JSK9RReiO0BSryU4D0R9eCAm2QSeCTg==@vger.kernel.org X-Gm-Message-State: AOJu0YwW8pRc6nzB4z8vN2kKOSedh5RM7RlfrjMctAx66a5Q581f0vjP 5ymHv/Wewk1XfD+rj4OOFaM4qebN9TWnIDr5iThPgKy8uy3sGh/RmTTi4cxHLQ== X-Gm-Gg: ASbGncs90vjM+gWvRc6yjSfFtZdo0ZecH18xVgLr7DeSKghsWBEMXAyuA7FvHIjmUJn k8Lt7SP0F3bSHZC+z7MhMCEl7+UhGY06cCxh+VKhy/koRqGY+fMd5Sm1pNZmTD7NzKbMTkc0wf7 fNjKd8rY8DtiH5jnZv/cLtQifjdNFuu7VWBtMdelWQIyRT77uXHlR8oBKzh/UrfU2b++lCmZoyu oArXpJ81E4+QQHzbMMHnHXQRLGmYz+G9dVQOYo2QxjDfKcTI9tObV34IKuYaFnV0sYUXCkuBeA7 X+158n6O6QXEzfnxeJjJ90g5LVit X-Google-Smtp-Source: AGHT+IFR79c6AfufLGPoblEmwJJEzbibgTXgjSFkUykGZ8Cp3S6Wc8BlYkoUbuSlrw6WDQWkP0jUow== X-Received: by 2002:ad4:5c49:0:b0:6d9:dd:5c5a with SMTP id 6a1803df08f44-6d9213c2296mr47786416d6.23.1733823776610; Tue, 10 Dec 2024 01:42:56 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:56 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:43 +0000 Subject: [PATCH v16 07/18] media: uvcvideo: refactor uvc_ioctl_g_ext_ctrls Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-7-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 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. Reviewed-by: Hans de Goede Tested-by: Yunke Cao 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_ctrl.c index 987a9700bed9..12ce7e38d6f6 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1908,8 +1908,8 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, return ret; } -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; @@ -1921,7 +1921,22 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, if (ctrl == NULL) return -EINVAL; - 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 = uvc_ctrl_populate_cache(chain, ctrl); + + if (ret < 0) + return ret; + } + xctrl->value = mapping->get(mapping, UVC_GET_DEF, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); + return 0; + } + + return -EINVAL; } int uvc_ctrl_set(struct uvc_fh *handle, diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.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 = handle->chain; struct v4l2_ext_control *ctrl = ctrls->controls; unsigned int i; + u32 which; int ret; + switch (ctrls->which) { + case V4L2_CTRL_WHICH_DEF_VAL: + case V4L2_CTRL_WHICH_CUR_VAL: + which = ctrls->which; + break; + default: + which = V4L2_CTRL_WHICH_CUR_VAL; + } + ret = uvc_ctrl_check_access(chain, ctrls, VIDIOC_G_EXT_CTRLS); if (ret < 0) return ret; - if (ctrls->which == V4L2_CTRL_WHICH_DEF_VAL) { - for (i = 0; i < ctrls->count; ++ctrl, ++i) { - struct v4l2_queryctrl qc = { .id = ctrl->id }; - - ret = uvc_query_v4l2_ctrl(chain, &qc); - if (ret < 0) { - ctrls->error_idx = i; - return ret; - } - - ctrl->value = qc.default_value; - } - - return 0; - } - ret = uvc_ctrl_begin(chain); if (ret < 0) return ret; for (i = 0; i < ctrls->count; ++ctrl, ++i) { - ret = uvc_ctrl_get(chain, ctrl); + ret = uvc_ctrl_get(chain, which, ctrl); if (ret < 0) { uvc_ctrl_rollback(handle); ctrls->error_idx = i; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.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 *handle) return __uvc_ctrl_commit(handle, 1, NULL); } -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); 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, From patchwork Tue Dec 10 09:42:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901140 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 8EC422153E8 for ; Tue, 10 Dec 2024 09:42:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823780; cv=none; b=DCRaxgXPQMxN5LvTVCP14ZNXwHhU5j6N0iuG+mNVQWrZa17YNQzhm+cUPP8jcWSstbicZQFbd9suVCvA2hUpfn5+Qf1elziArEgzcmX6GrgjbiVIkm3HNpd6G2Wky9KF59AjYG/NzRaVYq11NFW41F7ugnVN89KnEtvy3bynX1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823780; c=relaxed/simple; bh=7tx9tY1TZ7Mz0s7zOjD3n2wpSrIQUzX0lYUD2DrQrH8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eeCxhWSjQoie5hDzEWAUMpOSsLhSZmTlsI+IChV4435rMDCZ0hLQ+rLtnDvm6c4uGFgvAS9gHLmyHXWB4l326fe3Jcjirrf1G6X/X55MBhF3YvHtDDdrPIR63HsvCAfdn1JgTAM8TRt7nqcvHByWypOV++w1y3GE6dKtLzzPDyI= 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=euKxpdUE; arc=none smtp.client-ip=209.85.222.181 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="euKxpdUE" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b1b224f6c6so567150485a.3 for ; Tue, 10 Dec 2024 01:42:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823777; x=1734428577; 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=L0JByQfuAg+uD0hv4jRjMFUtllhDg1QrDpBOUHpuPvE=; b=euKxpdUEsJYHEKCJGkqnp1gCNHgT167YD9udhT/UygtsJyV1glI6qwyugzxU2y/GWI PHfG29ebCrVh3G4OCRM7Mgg2WEI/jip3dl/a/TMZ+n9CxAqBxbhs4hymXrggUpd5CtuC hCIrHihTL/1+yC7ms9c+CvkThFkodQ7jlBYu4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823777; x=1734428577; 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=L0JByQfuAg+uD0hv4jRjMFUtllhDg1QrDpBOUHpuPvE=; b=AJJw/fNeyXbqqoYfIMo8e4qtkRtNa1hbEMiINY9U2IWI3mho7ZUjVagVLFevQv2J// FRR6OIy0tflEHK4Y5epNtqDLtrP2pPPPlfGPx8RNRgNJyEzDP5IhbjY9t0x3lZUzxQXf pxiKZqCpt1kUAoZEZmrNocd1DaJpcjAW3Wwn3tyzjhDmQlGWIN0F0PSygUZMR0WI9USk zFEjQOY3g3z+KIVHCX7TEXn2Y3vws5yFTJae+7m1vIA1NZ/bv3DvZ0aJGL6C5vJpu3qm WAAwDHxXmB/X9maXD3M/ROEMBIdTlJvI/5PZmslA32/NQnksa5H+Hk0onrkHpTA37q03 xisQ== X-Forwarded-Encrypted: i=1; AJvYcCUH6xixUJ+8qAInEvYFTcarSmCNxRR99rD6JnF/BERL+W2B497uuyPXEKj/UIZgdV1BuARS6bJNWU492g==@vger.kernel.org X-Gm-Message-State: AOJu0YyhMPzbD2sAnC55rllU1TysuwX+b1sDVyWpV1yup1XYJB4PLHg2 A3H25lF7C6HvXDDAV5uyqWhdR1sHO1ZPEZrHOlagO+AAhnI2gIyTOpLp2Nux4lwRrPrGwPSrWXo = X-Gm-Gg: ASbGncuU1ayGVziWpP0Ka01Ea7At4MAjGVCStU3OPLRjRNakRulfSj9+4Afz5M6tZYP PgLRkxQrfYBxk4sJeUK1YYmc9XMen8CMcKvA08SEM9DEXXYy4t4lhEkJlW7TOm7Mwd8ZUAqHcy5 mmw0AU7FD4s5yC5nGP+OkQBoZbH3CXG4b1dzEqYMk0Zk6Q4cpwznNCabN53GBlyuIS90hanct20 WFnAU6d8xJvYisp7Bd6oHzvefqr0cH8ANgLtn0kKWXkTLdWOsLb4rT0tdaJLFu8TY9Mcbmk3MOz L33V6pNGPvILQJG/UrQDVB7xT0A+ X-Google-Smtp-Source: AGHT+IExR45IaZ1efaic3FpvsqoapdjA78ZUgUcbHZEtkDM1i3ZvkPfWr958oENOEkerIrjSg+Bv6g== X-Received: by 2002:a05:620a:1922:b0:7b6:d910:5b1a with SMTP id af79cd13be357-7b6dce94fa9mr608857985a.42.1733823777521; Tue, 10 Dec 2024 01:42:57 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:56 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:44 +0000 Subject: [PATCH v16 08/18] media: uvcvideo: uvc_ioctl_(g|s)_ext_ctrls: handle NoP case Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-8-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 If nothing needs to be done. Exit early. Reviewed-by: Hans de Goede Tested-by: Yunke Cao 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_v4l2.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, void *fh, u32 which; int ret; + 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 *handle, unsigned int i; int ret; + if (!ctrls->count) + return 0; + ret = uvc_ctrl_check_access(chain, ctrls, ioctl); if (ret < 0) return ret; From patchwork Tue Dec 10 09:42:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901141 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 3343F2153D0 for ; Tue, 10 Dec 2024 09:42:59 +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=1733823781; cv=none; b=lD6yqBXUscEa6LpOmSM0ZpjTTeEOKVvZLRQ4fiYSLyEDRxCyZhWgtuVd4//zA+m6HL0RHAgtPDVUT3PUcikoNH6y7g/oOoXgf6qfvYHicbDNpxajpqWu3/SX+4tPGh+EkPZV5KXVlRkGQq94TlMJYig8EJMmmsKD9QrvAW99B4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823781; c=relaxed/simple; bh=4xbVKX6i7so/xLpTZa/XjbZr4+Bsicj6dDAFUgCiOPQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sWTAvDKQESgHEYSp2A48By0dn7F7h1RFhKlyR1uEcSBZSvKAAk+dUXl5zcQ3gt4l8rAt9enepAFbwWbGaIb8pkfPfQAvHH4j4+skR9e6m6zu+QlYr6e/9ZBkr2lR3ymGmvY6wBrzaOU7sU2UnVRIO9cXLq4t6WPFbANQ+BWpvVM= 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=GQNS8Reu; 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="GQNS8Reu" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6d87ab49423so52345226d6.0 for ; Tue, 10 Dec 2024 01:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823778; x=1734428578; 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=BFj66RyTk6sqT9V9Y9d3LeaKrBJRM9mSw2F5nWt5/Tw=; b=GQNS8ReuQ4z/uRrHUQbCHlnTcr1i9t3zuY5UUu6cFFBl5i1dGCWj8gt8iRim4oRu0r OVurlvRPnUgZ7yTfpR03E+D+cTFHyG5TNcU8uHsshoOuJXdYFeD7+t5eOd/5ZdlMV9Kd i++09WD2ybdh1VD9/lN6w8dQMQ4cBgXIG03tE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823778; x=1734428578; 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=BFj66RyTk6sqT9V9Y9d3LeaKrBJRM9mSw2F5nWt5/Tw=; b=p3unoPMm8bkxGRH7Lxy1dCBgVQMNVsYMaz57i2HM7igp/pSFByjRLjXC/uv/fJjh7g NvCyy1r92K8+5T/UmhcZ5f2AKgVHn9YB1MQ4KIQZ6WxpPvhuZTgwnm9/if8E+26EYZ8Y afKpaH0uMZ15I3za23ODZKwr0m6g+btjm+TGsIDpEGI4pEBDNRJKszS8Jv+rdvMxbc3c l8XPkHkZ9gScPVGgwa4LfMrVbzJj4ESw9YzDYYaNZbLD5y7RQLkjF1tZvnxvoPtOAoYm kGptcqczYT9dGXQAObcLz+uP73zvA55oC9J1xD14hpI8yNFdc/BT0av0m8rNFbXY2nYP 12Qg== X-Forwarded-Encrypted: i=1; AJvYcCX2FDODkSIAocxCBCdtE3eL5yGspvGecSLbzoLKwG1xNQIimd+rLIMZI7vuYikL5tM/++CPVpLzwDf/Kw==@vger.kernel.org X-Gm-Message-State: AOJu0Ywa1V0RW7jxuXu3VLph7h4FNNQ5cM47J51y2RgowdLMjQ1NfGVm tTz5Ih/v6881RhfcGkmYT82ztO43VbjAPKXlIrATQ4Mj1ykKFFiY6DMCDZ8M4w== X-Gm-Gg: ASbGnctMWRwVJWsaOoTADHrsD5VCrhhqhw5QTNTK8R4ShxulroOtZwKdNYQDtUy/qQP 4ndlgz9qKt0OGVNHHYXtt0S14gRTdasePMOramjORklANjovvZ9fpFnjo9WwvVgV0l8x17ddzsI qOjhl6YGXMJUaFbl34spscOapcjfYvsBBm8N/oEnUGGqDagSQ+CCtPwP8JcqL5SNKpbAAAqGbzC 8MLrotWy+X8iCbziaUd+41Qsax/QFoN03YQczK6OQesNaB9hrAg/NJOWRl7zK8Cqpoef3MoFWua has2eBw07XOk8U9HXJzJUiSzo3yr X-Google-Smtp-Source: AGHT+IHYM3HgfWV26yqIYegG7eG1m3LG+GjVuVqNl6AyxQo8dS/maLswppMMcvwBORh7NXSiVEHMOA== X-Received: by 2002:a05:6214:d8d:b0:6d4:1f6d:695f with SMTP id 6a1803df08f44-6d91e2d2d35mr80814336d6.2.1733823778212; Tue, 10 Dec 2024 01:42:58 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:57 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:45 +0000 Subject: [PATCH v16 09/18] media: uvcvideo: Support any size for mapping get/set Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-9-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 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 Reviewed-by: Yunke Cao Reviewed-by: Hans de Goede Tested-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 181 +++++++++++++++++++++++++++------------ drivers/media/usb/uvc/uvcvideo.h | 8 +- 2 files changed, 130 insertions(+), 59 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 12ce7e38d6f6..8fc83961c76e 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[] = { static const int exposure_auto_mapping[] = { 2, 1, 4, 8 }; +static s32 uvc_mapping_get_s32(struct uvc_control_mapping *mapping, + u8 query, const void *data_in) +{ + s32 data_out = 0; + + 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 userspace 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_mapping *mapping, u32 idx) return v4l2_ctrl_get_menu(mapping->id)[idx]; } -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 = (s8)data[0]; + u8 value = ((u8 *)uvc_in)[2]; + s8 sign = ((s8 *)uvc_in)[0]; + s32 *out = v4l2_out; + + if (WARN_ON(v4l2_size != sizeof(s32))) + return -EINVAL; switch (query) { case UVC_GET_CUR: - return (zoom == 0) ? 0 : (zoom > 0 ? data[2] : -data[2]); + *out = (sign == 0) ? 0 : (sign > 0 ? value : -value); + return 0; case UVC_GET_MIN: case UVC_GET_MAX: case UVC_GET_RES: case UVC_GET_DEF: default: - return data[2]; + *out = value; + return 0; } } -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] = value == 0 ? 0 : (value > 0) ? 1 : 0xff; - data[2] = min((int)abs(value), 0xff); + u8 *out = uvc_out; + s32 value; + + if (WARN_ON(v4l2_size != sizeof(s32))) + return -EINVAL; + + value = *(u32 *)v4l2_in; + out[0] = value == 0 ? 0 : (value > 0) ? 1 : 0xff; + out[2] = min_t(int, abs(value), 0xff); + + return 0; } -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 = mapping->offset / 8; - s8 rel = (s8)data[first]; + u8 value = ((u8 *)uvc_in)[first + 1]; + s8 sign = ((s8 *)uvc_in)[first]; + s32 *out = v4l2_out; + + if (WARN_ON(v4l2_size != sizeof(s32))) + return -EINVAL; switch (query) { case UVC_GET_CUR: - return (rel == 0) ? 0 : (rel > 0 ? data[first+1] - : -data[first+1]); + *out = (sign == 0) ? 0 : (sign > 0 ? value : -value); + return 0; case UVC_GET_MIN: - return -data[first+1]; + *out = -value; + return 0; case UVC_GET_MAX: case UVC_GET_RES: case UVC_GET_DEF: default: - return data[first+1]; + *out = value; + return 0; } } -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 = mapping->offset / 8; + u8 *out = uvc_out; + s32 value; + + if (WARN_ON(v4l2_size != sizeof(s32))) + return -EINVAL; + + value = *(u32 *)v4l2_in; + out[first] = value == 0 ? 0 : (value > 0) ? 1 : 0xff; + out[first + 1] = min_t(int, abs(value), 0xff); - data[first] = value == 0 ? 0 : (value > 0) ? 1 : 0xff; - data[first+1] = min_t(int, abs(value), 0xff); + return 0; } static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { @@ -887,14 +938,20 @@ static s32 uvc_menu_to_v4l2_menu(struct uvc_control_mapping *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 = mapping->size; int offset = mapping->offset; + int bits = mapping->size; + const u8 *data = uvc_in; + s32 *out = v4l2_out; s32 value = 0; u8 mask; + if (WARN_ON(v4l2_size != sizeof(s32))) + return -EINVAL; + data += offset / 8; offset &= 7; mask = ((1LL << bits) - 1) << offset; @@ -916,29 +973,41 @@ static s32 uvc_get_le_value(struct uvc_control_mapping *mapping, value |= -(value & (1 << (mapping->size - 1))); /* If it is a menu, convert from uvc to v4l2. */ - if (mapping->v4l2_type != V4L2_CTRL_TYPE_MENU) - return value; + if (mapping->v4l2_type != V4L2_CTRL_TYPE_MENU) { + *out = value; + return 0; + } switch (query) { case UVC_GET_CUR: case UVC_GET_DEF: - return uvc_menu_to_v4l2_menu(mapping, value); + *out = uvc_menu_to_v4l2_menu(mapping, value); + return 0; } - return value; + *out = value; + return 0; } /* * 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 = mapping->size; int offset = mapping->offset; + int bits = mapping->size; + u8 *data = uvc_out; + s32 value; u8 mask; + if (WARN_ON(v4l2_size != sizeof(s32))) + return -EINVAL; + + value = *(s32 *)v4l2_in; + switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_MENU: value = uvc_mapping_get_menu_value(mapping, value); @@ -966,6 +1035,8 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping, bits -= 8 - offset; offset = 0; } + + return 0; } /* ------------------------------------------------------------------------ @@ -1147,8 +1218,8 @@ static int __uvc_ctrl_get(struct uvc_video_chain *chain, if (ret < 0) return ret; - *value = mapping->get(mapping, UVC_GET_CUR, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + *value = uvc_mapping_get_s32(mapping, UVC_GET_CUR, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); return 0; } @@ -1281,12 +1352,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)); 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)); return ~0; } @@ -1331,8 +1402,8 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, } if (ctrl->info.flags & UVC_CTRL_FLAG_GET_DEF) { - v4l2_ctrl->default_value = mapping->get(mapping, UVC_GET_DEF, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); + v4l2_ctrl->default_value = uvc_mapping_get_s32(mapping, + UVC_GET_DEF, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); } switch (mapping->v4l2_type) { @@ -1365,16 +1436,16 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, } if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) - v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + v4l2_ctrl->minimum = uvc_mapping_get_s32(mapping, UVC_GET_MIN, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) - v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + v4l2_ctrl->maximum = uvc_mapping_get_s32(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) - v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + v4l2_ctrl->step = uvc_mapping_get_s32(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); return 0; } @@ -1587,7 +1658,7 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, ctrl->handle = NULL; list_for_each_entry(mapping, &ctrl->info.mappings, list) { - s32 value = mapping->get(mapping, UVC_GET_CUR, data); + s32 value = uvc_mapping_get_s32(mapping, UVC_GET_CUR, data); /* * handle may be NULL here if the device sends auto-update @@ -1931,8 +2002,8 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, if (ret < 0) return ret; } - xctrl->value = mapping->get(mapping, UVC_GET_DEF, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); + xctrl->value = uvc_mapping_get_s32(mapping, UVC_GET_DEF, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); return 0; } @@ -1969,12 +2040,12 @@ int uvc_ctrl_set(struct uvc_fh *handle, return ret; } - min = mapping->get(mapping, UVC_GET_MIN, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); - max = mapping->get(mapping, UVC_GET_MAX, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); - step = mapping->get(mapping, UVC_GET_RES, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + min = uvc_mapping_get_s32(mapping, UVC_GET_MIN, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + max = uvc_mapping_get_s32(mapping, UVC_GET_MAX, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + step = uvc_mapping_get_s32(mapping, UVC_GET_RES, + uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); if (step == 0) step = 1; @@ -2053,8 +2124,8 @@ int uvc_ctrl_set(struct uvc_fh *handle, ctrl->info.size); } - 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)); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) ctrl->handle = handle; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.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); }; struct uvc_control { From patchwork Tue Dec 10 09:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901142 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 08A48215768 for ; Tue, 10 Dec 2024 09:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823781; cv=none; b=bpvMX/E5MVwlA4MSymB581w4WFm7yRjx8TzZvIPNeisI92Dt/iMiQOqyTSlIV6/2B960VRJhtn2HqcA5mVIAY4zPwM2B9Tiy1V1DcSjoZn7kNv072A86lzLfHDlCV1xKg+XLNFXz6iHzM90XZsKT0eAcwfKgQkjmFHWqyk6l7vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823781; c=relaxed/simple; bh=Vz8bAvwdEEadzQqCLWQ4ZMfQ2c7Ovu4YJ7E9TC+hlEY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N831yCCjMqtM5veecJdgDTpeEa0jBrkjKIdYuNq+CkWBgT1yAF3p7Q1RNEJ557yvcP/WafWyCAF2SzMHh0bjM6YORMZUyJoVht4iB9rJmLtW9ar4dzQHuguLyMiODLjUjVwBQzWqDbm6a7BtNHhdai2jyOHMTAemjjmok5tpdGA= 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=Hi3wrvQd; arc=none smtp.client-ip=209.85.222.181 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="Hi3wrvQd" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b6d63ab374so104646885a.3 for ; Tue, 10 Dec 2024 01:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823779; x=1734428579; 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=oZ3g5bZEuxcEXI8DiQzHarhSV0V4/CTEhxMXIFDKmOg=; b=Hi3wrvQd/xabDE9mn/qqoC5AginiI1GwZC1B+5dQL6IFuUelPjhfuQcRKMEuOjit36 Ai6qtTiDHcJLENTCxh9Mc5PFq3nIT4esI8pgG9OtJZemwtHUogW/1X4AhhHvjXwZGt3Z b5gnpkvCbD0Ze9VKCIhN49OYxuVvlONSDIGdI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823779; x=1734428579; 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=oZ3g5bZEuxcEXI8DiQzHarhSV0V4/CTEhxMXIFDKmOg=; b=M8vjUuKQqi9C+omt5pYAMG5HqPEIp+euPTiVgX1lOsG4fC97Ik8DZGBc/ey54q+YtP dxBJW1rsAayvnUA5Pg4qDDC3xagA8I50JvbhM26y+Q8nNP8x37asXd+ApO3dljqFqWfq 3JROZlOIFO9VUDn+NdNN3BKCZ4KkVcVElRcldWgAu51NglvBJLXunbB4iffHE0mSPSF0 dwlMPrR1GWx7BL0eszIGickWnNC8/XSSm/C6yhG8/zb54lsrq2VcZkGWTo9fKK1/EVei 9boDd7PoW0zgaaWjFKsVqSvaQVsFEacN2Fkm496tJGIJdyy6HeuIAOweVUsm+gyHZLSe cylw== X-Forwarded-Encrypted: i=1; AJvYcCUVbIH82X18lNIsMNjeInFtQ+0oq/7lTErv6A5ipFolT3SBBIxM98I4Gd0tRMIRFq3nKqjCyP8povVu9w==@vger.kernel.org X-Gm-Message-State: AOJu0Yx5SYv2aDBqM4imFti3zpusxAhgsvDCPoX/H6MBh8HR16JOBgsh RMq3ZnSn9hBLH1F6Zr8DvaIGwRVJCjvT2J2ZnM/Ja4e0R4t3umg0MCSmmVoWNw== X-Gm-Gg: ASbGncvMdl8gbY1b3V8oHJPx3U7ZHthv5oWT2/vaiOrkxYLwTs4RJoKt1Nfm2kvJPiA WorLfrdAeQZn1bm8Jv5nqS1CW8+i8CUUPNmMbDr6KEg/4xLmoqaJfeagJ8YTkjDAOZKevTAR8t4 5K9xknddyUjtyXel5PhGrq465wjgHxKzXNslq9nXbkCc2IeBc+Ijbtjv+3eAp0DbvMFKL1nrsaE qc3DylH1zVfIO8VUiI7nMyBaFKlF2/y8OhgZBl2L3qc+zqIRpChOCn4LR6HrWDwslG6EDNa5n0A TigStowwC13jX+C0d5gyY0oL5aza X-Google-Smtp-Source: AGHT+IF8U35izwV/nHX+p4seSA3KTbcuZ18YbCP8LguOy+GNHTGswMHJMWEvV2Qr2+rCQLe2Ra6Apw== X-Received: by 2002:a05:6214:490:b0:6d4:22fc:ce3e with SMTP id 6a1803df08f44-6d8e71dad68mr241873486d6.44.1733823779121; Tue, 10 Dec 2024 01:42:59 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:58 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:46 +0000 Subject: [PATCH v16 10/18] media: uvcvideo: Factor out clamping from uvc_ctrl_set Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-10-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Move the logic to a separated function. Do not expect any change. This is a preparation for supporting compound controls. Reviewed-by: Yunke Cao Reviewed-by: Hans de Goede Tested-by: Yunke Cao 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_ctrl.c index 8fc83961c76e..4d0307b28fa8 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2010,28 +2010,17 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, return -EINVAL; } -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 = handle->chain; - struct uvc_control *ctrl; - struct uvc_control_mapping *mapping; - s32 value; + s32 value = *value_in_out; u32 step; s32 min; s32 max; int ret; - if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >= 0) - return -EACCES; - - ctrl = uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl == 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) { @@ -2049,14 +2038,13 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (step == 0) step = 1; - xctrl->value = min + DIV_ROUND_CLOSEST((u32)(xctrl->value - min), - step) * step; + value = min + DIV_ROUND_CLOSEST((u32)(value - min), step) * step; if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED) - xctrl->value = clamp(xctrl->value, min, max); + value = clamp(value, min, max); else - xctrl->value = clamp_t(u32, xctrl->value, min, max); - value = xctrl->value; - break; + value = clamp_t(u32, value, min, max); + *value_in_out = value; + return 0; case V4L2_CTRL_TYPE_BITMASK: if (!ctrl->cached) { @@ -2065,21 +2053,20 @@ int uvc_ctrl_set(struct uvc_fh *handle, return ret; } - xctrl->value &= uvc_get_ctrl_bitmap(ctrl, mapping); - value = xctrl->value; - break; + value &= uvc_get_ctrl_bitmap(ctrl, mapping); + *value_in_out = value; + return 0; case V4L2_CTRL_TYPE_BOOLEAN: - xctrl->value = clamp(xctrl->value, 0, 1); - value = xctrl->value; - break; + *value_in_out = clamp(value, 0, 1); + return 0; 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; - if (!test_bit(xctrl->value, &mapping->menu_mask)) + if (!test_bit(value, &mapping->menu_mask)) return -EINVAL; /* @@ -2087,8 +2074,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, * UVC controls that support it. */ if (mapping->data_type == UVC_CTRL_DATA_TYPE_BITMASK) { - int val = uvc_mapping_get_menu_value(mapping, - xctrl->value); + int val = uvc_mapping_get_menu_value(mapping, value); if (!ctrl->cached) { ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) @@ -2098,14 +2084,34 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (!(uvc_get_ctrl_bitmap(ctrl, mapping) & val)) return -EINVAL; } - value = xctrl->value; - break; + return 0; default: - value = xctrl->value; - break; + return 0; } + return 0; +} + +int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl) +{ + struct uvc_video_chain *chain = handle->chain; + struct uvc_control_mapping *mapping; + struct uvc_control *ctrl; + int ret; + + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >= 0) + return -EACCES; + + ctrl = uvc_find_control(chain, xctrl->id, &mapping); + if (!ctrl) + return -EINVAL; + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) + return -EACCES; + + ret = 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 @@ -2124,7 +2130,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, ctrl->info.size); } - uvc_mapping_set_s32(mapping, value, + uvc_mapping_set_s32(mapping, xctrl->value, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) From patchwork Tue Dec 10 09:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901143 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (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 06729215792 for ; Tue, 10 Dec 2024 09:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823784; cv=none; b=FyUTYYV2MixITBQA5v/Dex5hW+5WT7A5pFyq8PASSx6dVTGPcAFnsGLK4nQOqpdax0wCJm/CkRNCwHyo3V4gFhEtLentwVVzfY4Ts0hWTxCjVABlxn7oGZOuCveNNPqXuYB3ETojzp+Hl95TQ48ZNC7X8BlLYVsDGJsmVchlu3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823784; c=relaxed/simple; bh=syU3SP1UFRBOFzSKFIOQYfVKkT7l3MfLBIScrqiIV0w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gt+zgEAp+hn7MVHO3mOuO8tRG/ja1Q4JZRZ1/ya2uA74t+r6cn5Edn3DXr/LG8ACczH5PXkXx5CCtxTem4k/N0ZhnGcz3EsSyiVWU9E2trcVxJWBqVl7O4Un6vEL4aZs24RlxDVJxn6hKUTWSBdfLfJ02Xo7A+gK5e19WdGeAjw= 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=UsPZUy+A; arc=none smtp.client-ip=209.85.160.175 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="UsPZUy+A" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-46779ae3139so3659191cf.2 for ; Tue, 10 Dec 2024 01:43:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823780; x=1734428580; 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=Bkn1FTenh9IoogHBbEytCPJjCzMA63zFkclq+5ZFIRM=; b=UsPZUy+A9GjVyL3fq9jfxdpCwETI14p7exqgCsThobYcx9QDEdfXE9O2kPpShQKkkI Z7lj1KfoiU41aYQ4hk5UhubusPVqsS8UU/emiRSQcOtelMJj7jdZGAxEENcuojQ9wu1X mJSSdFiSDAI9C87zglX19w0dS8zRJ0T0o5RmQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823780; x=1734428580; 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=Bkn1FTenh9IoogHBbEytCPJjCzMA63zFkclq+5ZFIRM=; b=bUZEMjO6HYMkzYWmIZwco8eTv37kXf7AsPhP8qe/ImFuWYLzEeweFsQ/QYJw8UBt++ EE3DBRZCxXjHxe1boMDDjGYBRP9WQ+wySFvqzfgMCrcRD2GPP8Y5oi/BmEgVjYrdfJ/P XkXQQjls5T3cYHFPfc+Ah0sr1U7G1A9sn3eWFoDy/OlzlABKVDeZxYkc3z92dKaTi+LP +/iIiCt5A7FqNUfC/8Bi/nqnsM8GcGzaGKyh3Rr9o6MQJB4DiskGXMNsEt71tEHhQsAI iAz3h1D0g8IVAgLwJt9uHZfsh10ZjsBiXPbGrW7SBXCU3KkmtGdxwkFGGUbymuVy5R62 Mm7Q== X-Forwarded-Encrypted: i=1; AJvYcCVP73e5lzK4jkFj4fC0QOqTnKNDbxY2CSaEm3zs2ZRDCOQwgkY/LslDvRD/pRYIAFD2vv3k+03ysqO0Cw==@vger.kernel.org X-Gm-Message-State: AOJu0YxajfdMIr7ILOzaSmdeU+6SUs9EIb3C+EtLw3FDEoVGh5ph2Km5 ydIRTvVtM98ZoJftbOHpou3e++ndz24r+2yWlTHWmvJbtEg/mwdat2o81kAAtQ== X-Gm-Gg: ASbGncttWRD1uuZiOvgYt/ZDjVyb3FBZ14K5n7/kkMiTT57aYbSgq40lo75XOHr96Fc ZAkxArk0D1U9DbwW9VOcuLfIZQMaCU0lVYx9WyH2ogn4Azl/tOLUHVSFrFQo0xr27emo3hwLkyu 8QRrrGyKSZHLOUZQw7y2RYA/1FCNnCkkTw6l4lq/DIK6lLu9CKj1JNpax18esoUeut9REXo9NEA QPnmk5tBPbBf/Xyt9RrEr5eN65dPet3hsAVdvjkegZbGMLnRxd49YA+epo+J4teKZyGzW2/EkJs N6N4y3E/nA1wNvhtYXZo1ax1xjf/ X-Google-Smtp-Source: AGHT+IGXUszI74qq0e9uoefo1xO0lmDcF16DFHbJ0I0zOd9Bd+fviDJXHggCHAlkl2mjD7gP0nC2NA== X-Received: by 2002:a05:6214:4009:b0:6d8:9065:2033 with SMTP id 6a1803df08f44-6d91e435246mr52366936d6.31.1733823779986; Tue, 10 Dec 2024 01:42:59 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:42:59 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:47 +0000 Subject: [PATCH v16 11/18] media: uvcvideo: add support for compound controls Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-11-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Tested-by: Yunke Cao Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 212 +++++++++++++++++++++++++++++++++------ drivers/media/usb/uvc/uvcvideo.h | 5 + 2 files changed, 189 insertions(+), 28 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4d0307b28fa8..794d5c365352 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[] = { static const int exposure_auto_mapping[] = { 2, 1, 4, 8 }; +static bool uvc_ctrl_mapping_is_compound(struct uvc_control_mapping *mapping) +{ + return mapping->v4l2_type >= V4L2_CTRL_COMPOUND_TYPES; +} + static s32 uvc_mapping_get_s32(struct uvc_control_mapping *mapping, u8 query, const void *data_in) { @@ -1055,7 +1060,7 @@ static int uvc_entity_match_guid(const struct uvc_entity *entity, 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; @@ -1070,14 +1075,16 @@ static void __uvc_find_control(struct uvc_entity *entity, u32 v4l2_id, continue; list_for_each_entry(map, &ctrl->info.mappings, list) { - if ((map->id == v4l2_id) && !next) { + if (map->id == v4l2_id && !next && !next_compound) { *control = ctrl; *mapping = map; return; } if ((*mapping == NULL || (*mapping)->id > map->id) && - (map->id > v4l2_id) && next) { + (map->id > v4l2_id) && + (uvc_ctrl_mapping_is_compound(map) ? + next_compound : next)) { *control = ctrl; *mapping = map; } @@ -1091,6 +1098,7 @@ static struct uvc_control *uvc_find_control(struct uvc_video_chain *chain, struct uvc_control *ctrl = NULL; struct uvc_entity *entity; int next = v4l2_id & V4L2_CTRL_FLAG_NEXT_CTRL; + int next_compound = v4l2_id & V4L2_CTRL_FLAG_NEXT_COMPOUND; *mapping = NULL; @@ -1099,12 +1107,13 @@ static struct uvc_control *uvc_find_control(struct uvc_video_chain *chain, /* 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; } - if (ctrl == NULL && !next) + if (!ctrl && !next && !next_compound) uvc_dbg(chain->dev, CONTROL, "Control 0x%08x not found\n", v4l2_id); @@ -1227,7 +1236,8 @@ static int __uvc_ctrl_get(struct uvc_video_chain *chain, static int __uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, u32 found_id) { - bool find_next = req_id & V4L2_CTRL_FLAG_NEXT_CTRL; + bool find_next = req_id & + (V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND); unsigned int i; req_id &= V4L2_CTRL_ID_MASK; @@ -1317,10 +1327,12 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, } __uvc_find_control(ctrl->entity, mapping->master_id, &master_map, - &master_ctrl, 0); + &master_ctrl, 0, 0); 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; ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); if (ret >= 0 && val != mapping->master_manual) @@ -1384,10 +1396,15 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 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 = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + int ret; + + if (WARN_ON(uvc_ctrl_mapping_is_compound(master_map))) + return -EIO; + + ret = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); if (ret < 0) return ret; @@ -1395,6 +1412,15 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; } + if (v4l2_ctrl->type >= V4L2_CTRL_COMPOUND_TYPES) { + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD; + v4l2_ctrl->default_value = 0; + v4l2_ctrl->minimum = 0; + v4l2_ctrl->maximum = 0; + v4l2_ctrl->step = 0; + return 0; + } + if (!ctrl->cached) { int ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) @@ -1635,11 +1661,12 @@ static void uvc_ctrl_send_slave_event(struct uvc_video_chain *chain, u32 changes = V4L2_EVENT_CTRL_CH_FLAGS; s32 val = 0; - __uvc_find_control(master->entity, slave_id, &mapping, &ctrl, 0); + __uvc_find_control(master->entity, slave_id, &mapping, &ctrl, 0, 0); if (ctrl == NULL) return; - if (__uvc_ctrl_get(chain, ctrl, mapping, &val) == 0) + if (uvc_ctrl_mapping_is_compound(mapping) || + __uvc_ctrl_get(chain, ctrl, mapping, &val) == 0) changes |= V4L2_EVENT_CTRL_CH_VALUE; uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes); @@ -1658,7 +1685,12 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, ctrl->handle = NULL; list_for_each_entry(mapping, &ctrl->info.mappings, list) { - s32 value = uvc_mapping_get_s32(mapping, UVC_GET_CUR, data); + s32 value; + + if (uvc_ctrl_mapping_is_compound(mapping)) + value = 0; + else + value = uvc_mapping_get_s32(mapping, UVC_GET_CUR, data); /* * handle may be NULL here if the device sends auto-update @@ -1744,6 +1776,7 @@ static void uvc_ctrl_send_events(struct uvc_fh *handle, for (i = 0; i < xctrls_count; ++i) { u32 changes = V4L2_EVENT_CTRL_CH_VALUE; + s32 value; ctrl = uvc_find_control(handle->chain, xctrls[i].id, &mapping); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) @@ -1768,6 +1801,10 @@ static void uvc_ctrl_send_events(struct uvc_fh *handle, slave_id); } + if (uvc_ctrl_mapping_is_compound(mapping)) + value = 0; + else + value = xctrls[i].value; /* * If the master is being modified in the same transaction * flags may change too. @@ -1778,7 +1815,7 @@ static void uvc_ctrl_send_events(struct uvc_fh *handle, changes |= V4L2_EVENT_CTRL_CH_FLAGS; uvc_ctrl_send_event(handle->chain, handle, ctrl, mapping, - xctrls[i].value, changes); + value, changes); } } @@ -1810,7 +1847,8 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems) u32 changes = V4L2_EVENT_CTRL_CH_FLAGS; s32 val = 0; - if (__uvc_ctrl_get(handle->chain, ctrl, mapping, &val) == 0) + if (uvc_ctrl_mapping_is_compound(mapping) || + __uvc_ctrl_get(handle->chain, ctrl, mapping, &val) == 0) changes |= V4L2_EVENT_CTRL_CH_VALUE; uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, val, @@ -1943,7 +1981,7 @@ static int uvc_ctrl_find_ctrl_idx(struct uvc_entity *entity, for (i = 0; i < ctrls->count; i++) { __uvc_find_control(entity, ctrls->controls[i].id, &mapping, - &ctrl_found, 0); + &ctrl_found, 0, 0); if (uvc_control == ctrl_found) return i; } @@ -1979,19 +2017,64 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, return ret; } -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) >= 0) - return -EACCES; + u8 *data __free(kfree) = NULL; + size_t size; + u8 query; + int ret; + int id; - ctrl = uvc_find_control(chain, xctrl->id, &mapping); - if (ctrl == NULL) + switch (which) { + case V4L2_CTRL_WHICH_CUR_VAL: + ret = __uvc_ctrl_load_cur(chain, ctrl); + if (ret < 0) + return ret; + id = UVC_CTRL_DATA_CURRENT; + query = UVC_GET_CUR; + break; + case V4L2_CTRL_WHICH_DEF_VAL: + ret = uvc_ctrl_populate_cache(chain, ctrl); + if (ret < 0) + return ret; + id = UVC_CTRL_DATA_DEF; + query = UVC_GET_DEF; + break; + default: return -EINVAL; + } + + size = DIV_ROUND_UP(mapping->size, 8); + if (xctrl->size < size) { + xctrl->size = size; + return -ENOSPC; + } + + data = kmalloc(size, GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret = mapping->get(mapping, query, uvc_ctrl_data(ctrl, id), size, data); + if (ret < 0) + return ret; + + /* + * v4l2_ext_control does not have enough room to fit a compound control. + * Instead, the value is in the user memory at xctrl->ptr. The v4l2 + * ioctl helper does not copy it for us. + */ + return copy_to_user(xctrl->ptr, data, size) ? -EFAULT : 0; +} +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); @@ -2010,6 +2093,33 @@ int uvc_ctrl_get(struct uvc_video_chain *chain, u32 which, return -EINVAL; } +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) >= 0) + return -EACCES; + + ctrl = 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, @@ -2093,6 +2203,42 @@ static int uvc_ctrl_clamp(struct uvc_video_chain *chain, return 0; } +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) = NULL; + size_t size; + + size = DIV_ROUND_UP(mapping->size, 8); + if (xctrl->size != size) + return -EINVAL; + + /* + * v4l2_ext_control does not have enough room to fit a compound control. + * Instead, the value is in the user memory at xctrl->ptr. The v4l2 + * ioctl helper does not copy it for us. + */ + data = 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 = handle->chain; @@ -2130,8 +2276,9 @@ int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl) ctrl->info.size); } - uvc_mapping_set_s32(mapping, xctrl->value, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); + ret = uvc_mapping_set_xctrl(ctrl, mapping, xctrl); + if (ret) + return ret; if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) ctrl->handle = handle; @@ -2509,6 +2656,7 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, struct uvc_control_mapping *map; unsigned int size; unsigned int i; + int ret; /* * Most mappings come from static kernel data, and need to be duplicated. @@ -2549,6 +2697,12 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, goto err_nomem; } + if (uvc_ctrl_mapping_is_compound(map)) + if (WARN_ON(!map->set || !map->get)) { + ret = -EIO; + goto free_mem; + } + if (map->get == NULL) map->get = uvc_get_le_value; if (map->set == NULL) @@ -2570,11 +2724,13 @@ static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, return 0; err_nomem: + ret = -ENOMEM; +free_mem: kfree(map->menu_names); kfree(map->menu_mapping); kfree(map->name); kfree(map); - return -ENOMEM; + return ret; } int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.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; + /* + * 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; From patchwork Tue Dec 10 09:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901144 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 1B32E234975 for ; Tue, 10 Dec 2024 09:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823784; cv=none; b=cpPmLXrqqsZs4f2Yq6lZFlpYLCjXqHwSuudhXMS8zwzurt76ZOl+J31RgYuch5zVTOpmquqHaxDoFqlutyZe8G1ClCrzoi5Y+qCFMTbR17oJasm3xtvAEJzUftMiaHjy3+CGFWkwzMq/MSzkfguB2x3gGlwXxsaV8qHOQqaP4lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823784; c=relaxed/simple; bh=mfhLeffdilkffQ88aag3azfnh854oo6y05hzwCztGkw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f9quHHm/xnbnZQJz/JIXMlfBss0zeCn7hx12IWlwIlH3dnP/jKsota8oyPb5KgKQonfQ9YnQlx6kyaYioI2DjWtOJY+QODXgt+Ohki5W8YdrfLh0XdAZSOpovo7LdXpXQiWXD+cgrEmQwL4NcaqN/Ey+2WDKUK3cSc+GIAGo3pU= 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=O72uzeY5; arc=none smtp.client-ip=209.85.219.49 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="O72uzeY5" Received: by mail-qv1-f49.google.com with SMTP id 6a1803df08f44-6d87fffeb13so44133656d6.1 for ; Tue, 10 Dec 2024 01:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823781; x=1734428581; 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=eiwmj5eM7vigYSm+9Mmo6PKLcpfGimwewDBerK/2fr0=; b=O72uzeY53Yi6lleNdRtJidpfbwDOzxdynO0L/BsPrPv87OikiG42McrjVtYFJWzVcB 77sIWPYueOeHX47wVAqTSwekCDTdnwdIYN0NwweRR6JrqtpZMprN3Em22rcewls/NlpK vpxJ6qI/vhv53qDDB1E1AjUzrN4hN1NU6el2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823781; x=1734428581; 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=eiwmj5eM7vigYSm+9Mmo6PKLcpfGimwewDBerK/2fr0=; b=jJLmiZ7Qq0CCzjQK7Y12l3ur1Oq+1lYv7ebMYbEr8U1/ybbAx9My5MDUUGiP4R43qv HwFgK+t2krxN3mdgnQZO88TjZY4Zj+AB9GoNQYmcumGOI9BTr2ZB5AuPwyBztvlEsgN0 cxRaKwH4WMdzRAMud3jzlbqg5ZRUea+aNgazrvi/aYamdokxJMsNvj/F9CieZZ4iBVjw WxT8unc0Tvjdc5jiSo83yTgG9u5F6eY77pHayz2yBQCWqYg/NCpF5NUqdU4cQo0DYEK+ ZWa2lvFed6OJIYLdSELv0rxv412vJisvqBNum8fd8qv+Za/RyOifDrR+W2TK0bAWrvTr r+uw== X-Forwarded-Encrypted: i=1; AJvYcCXZbeqOAQb0mpXBBraoTxBdzgaNT5Dd5EN0MbI/XVyiZ0aAySsmJjElGHkd/yTez14u0PcXMWDXGvsRMg==@vger.kernel.org X-Gm-Message-State: AOJu0YyLUHpA8Gxme8aUhK2DFqgI2+B7Twb67ZW47VCad7YBbr/seF9n vpfXIJeL+Wo7fitmeR6Al+IqwK3gKkM5YRfA73RZxCsFsJFCLQwwHGui0GIHng== X-Gm-Gg: ASbGncuuBnNeFkk225wckVZixI8Ke3slLXy5LqVEYDsVVJx3Ge6O0bA2EjaCyeYI6nd F7POcmLNCUBgrxw/1AShCbrVi7iopaXBikYhdXrlPqbjSZvYu84tOQ/zYmJOrD9zq8lFU3UUE7W WsCt8dsxUPj7GpRarPRWteLjgaywgk0w8Ua9wLYc4u4RAJxIOtWvStW4xd0VfQbUqWQmqp2pize C8a87yuNZebWT6KHfk+Io2LFmUt6efCnR3s8CNPKA3ZLua4hh/Q+FRa1rQALS7QY87KalkEfEDP RAPdfPV65GPKxxWA32Lb5Zv0zQhb X-Google-Smtp-Source: AGHT+IHpra8NicNX39bLjc8qG29QdCb3vJ/1EaZ3tqQYIlrU6vu2eVYCAwoAIvz2bnvNzvbnqJSOJg== X-Received: by 2002:a05:6214:20aa:b0:6d8:7fe2:8b1e with SMTP id 6a1803df08f44-6d8e741e814mr204079766d6.48.1733823781235; Tue, 10 Dec 2024 01:43:01 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:00 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:48 +0000 Subject: [PATCH v16 12/18] media: uvcvideo: Factor out query_boundaries from query_ctrl Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-12-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Split the function in two parts. queryctrl_boundaries will be used in future patches. No functional change expected from this patch. Reviewed-by: Yunke Cao Tested-by: Yunke Cao Reviewed-by: Hans de Goede 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_ctrl.c index 794d5c365352..785af382103b 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1374,53 +1374,11 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *ctrl, return ~0; } -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 = NULL; - struct uvc_control *master_ctrl = NULL; - - memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); - v4l2_ctrl->id = mapping->id; - v4l2_ctrl->type = mapping->v4l2_type; - strscpy(v4l2_ctrl->name, uvc_map_get_name(mapping), - sizeof(v4l2_ctrl->name)); - v4l2_ctrl->flags = 0; - - if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) - v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; - if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) - v4l2_ctrl->flags |= 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 = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); - if (ret < 0) - return ret; - - if (val != mapping->master_manual) - v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; - } - - if (v4l2_ctrl->type >= V4L2_CTRL_COMPOUND_TYPES) { - v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD; - v4l2_ctrl->default_value = 0; - v4l2_ctrl->minimum = 0; - v4l2_ctrl->maximum = 0; - v4l2_ctrl->step = 0; - return 0; - } - if (!ctrl->cached) { int ret = uvc_ctrl_populate_cache(chain, ctrl); if (ret < 0) @@ -1464,18 +1422,74 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) v4l2_ctrl->minimum = uvc_mapping_get_s32(mapping, UVC_GET_MIN, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); + else + v4l2_ctrl->minimum = 0; if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX) v4l2_ctrl->maximum = uvc_mapping_get_s32(mapping, UVC_GET_MAX, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); + else + v4l2_ctrl->maximum = 0; if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) v4l2_ctrl->step = uvc_mapping_get_s32(mapping, UVC_GET_RES, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); + else + v4l2_ctrl->step = 0; return 0; } +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 = NULL; + struct uvc_control *master_ctrl = NULL; + + memset(v4l2_ctrl, 0, sizeof(*v4l2_ctrl)); + v4l2_ctrl->id = mapping->id; + v4l2_ctrl->type = mapping->v4l2_type; + strscpy(v4l2_ctrl->name, uvc_map_get_name(mapping), + sizeof(v4l2_ctrl->name)); + v4l2_ctrl->flags = 0; + + if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR)) + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) + v4l2_ctrl->flags |= 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 = __uvc_ctrl_get(chain, master_ctrl, master_map, &val); + if (ret < 0) + return ret; + + if (val != mapping->master_manual) + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + } + + if (v4l2_ctrl->type >= V4L2_CTRL_COMPOUND_TYPES) { + v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD; + v4l2_ctrl->default_value = 0; + v4l2_ctrl->minimum = 0; + v4l2_ctrl->maximum = 0; + v4l2_ctrl->step = 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) { From patchwork Tue Dec 10 09:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901145 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 09833238723 for ; Tue, 10 Dec 2024 09:43:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823785; cv=none; b=bfds+qN3K8EBPIbVKMlHChe2kQzKiNiCtr+DezrjgKqsK/XQh+CZwEabpILIy+q3KJpxVBZO4qn+EACWH/Tlq+MMSQIxl1VLCuuRofvXUnMAQQNCwZe8pt4bk1TXvnmvf/Bpb5TXunE2eWE70vfICpWr9lrHY5X+crJNGxFAYME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823785; c=relaxed/simple; bh=1mIhj0L3S8RyfekH5P2w4xxehFGRoAkXfDpeUyyJAW0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NfVb1DN7C4/XbnOgGRWxwz0XfnmuIVXEjmuy7wiqnVmj29IofOnNEUnw3sO4pFUJG6+tDlzF6x9n1Ev8VmCm/t6UX/+MT5SAnnDWA5J9TTPqsYMJvUQQX3MwzNV+2fYueJCHQ+BTym/NWbMJxe3X6OcQsVQxiCODboaVaFwmI/c= 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=RZwodfJl; arc=none smtp.client-ip=209.85.219.54 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="RZwodfJl" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6d8fd060e27so24753986d6.1 for ; Tue, 10 Dec 2024 01:43:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823782; x=1734428582; 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=ggsRkdgdY3jtYJRW9AvbLuVLQMJV/njoy22w/Cmb86g=; b=RZwodfJl/FxoCS42F31/3xCxxldV0O0D7atlhbxv+0nQucx5VbcRY9RXFFn0lcjAuG FnjOkJsXOz6AuKElciSCcRWMLZn6lSNQDHPKBOpW60aEq1U/qTOnWNoxIlCz76VO5fLC Dk/PpllIuwWx594pRIJHS3bq85My8Ziuu7ohc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823782; x=1734428582; 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=ggsRkdgdY3jtYJRW9AvbLuVLQMJV/njoy22w/Cmb86g=; b=J2Xe5BPpZE3zJAZ7WEO5uMtiDALMR4ADVNZ7cIIHvt/NcnMyBUf/Z3QFY1yrWxo+HX IKV7AWNZhYU1sSMo8H5mCrDnOZ9PYiZgXnWNBrkXrzAJPCRVS+OY8hfMVW/TNMpNKVEn KBh8w9c3WZ0ppeXpOj9arYNhOoja+QxOwe7GeWHk9iOsxg3Bm+iExCuQwEJ3VsQRVgGz apWBjnlEOhtGpTTj7KSXwH+dkjZwJqTlboFuM9/x5GRLJMimVV9/dSGenJHLDVU2G/gs vxdyUeuvxTlMR6g7d6nlkoEE7q1kRkKkWtGOJ7OxXXTdghfHUePaRuMykxA68JBsXsdH tjZg== X-Forwarded-Encrypted: i=1; AJvYcCXc4ec4c5GzNxuDq1glXZuFIoeGlTvT8WK5BvCdOEgf7mTvK/rxJ7ejZMdls3d/O5wAYedPMikpu9imng==@vger.kernel.org X-Gm-Message-State: AOJu0YxUsrBjGLll2MPGwC0f58dKhmMTjQX/UiH4TJkJiWesFiFuNN2L XhVZ6xSBtifYOShzc+wBMK5/NG/9XybhfePn2k/M5oIQYjVWB9xpwVpZpaTgkg== X-Gm-Gg: ASbGnct7rhrVokXdkF05spI4leKqP52hwErD725tTJO46axPuD0h8E89KdV4I6Yhj3T qybPSKRhQp+f+iGCpGcv5dPSd44VCoq3CHJ3C2y9B9xoB8l3ar+Y7BlLF46xsySaqysac2Jir1A JOQPSv7TRFfr/E7jgkuACCWP/cnj7IR28b7awAuDF9qtqZ3trCe5XdRaTPy3o+0OM42yNj/FecJ ydfIrbtdK1Sl2M+bF5Gf3r+jA6NNwASS+AkMUi+IeFasNetlAmCXWclYYDHonRCWIbFzfd0M3FQ RAVJby8XAjhFBntJaubDbR9W0qdT X-Google-Smtp-Source: AGHT+IFWNgHEkkw0X3lGHyza0LOLXXjjNZr+apm6ApxDr5Cb85UBasRKklbmAAOPnhUreGFehC1jXg== X-Received: by 2002:a05:6214:29e9:b0:6d8:7e03:c434 with SMTP id 6a1803df08f44-6d8e7118423mr255304156d6.20.1733823781973; Tue, 10 Dec 2024 01:43:01 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:01 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:49 +0000 Subject: [PATCH v16 13/18] media: uvcvideo: support V4L2_CTRL_WHICH_MIN/MAX_VAL Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-13-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Tested-by: Yunke Cao Reviewed-by: Hans de Goede 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_ctrl.c index 785af382103b..14aa9619fbf1 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1277,6 +1277,37 @@ static int uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, return 0; } +static bool uvc_ctrl_is_readable(u32 which, struct uvc_control *ctrl, + struct uvc_control_mapping *mapping) +{ + if (which == V4L2_CTRL_WHICH_CUR_VAL) + return !!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR); + + if (which == 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 == V4L2_CTRL_WHICH_MIN_VAL) + return !!(ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN); + + if (which == 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). @@ -1295,7 +1326,6 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, struct uvc_control *master_ctrl = NULL; struct uvc_control_mapping *mapping; struct uvc_control *ctrl; - bool read = ioctl == VIDIOC_G_EXT_CTRLS; s32 val; int ret; int i; @@ -1307,10 +1337,10 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, if (!ctrl) return -EINVAL; - if (!(ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) && read) - return -EACCES; + if (ioctl == VIDIOC_G_EXT_CTRLS) + return uvc_ctrl_is_readable(ctrls->which, ctrl, mapping); - if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR) && !read) + if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) return -EACCES; if (ioctl != VIDIOC_S_EXT_CTRLS || !mapping->master_id) @@ -1459,6 +1489,9 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY; if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) v4l2_ctrl->flags |= 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 |= V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; if (mapping->master_id) __uvc_find_control(ctrl->entity, mapping->master_id, @@ -2045,16 +2078,18 @@ static int uvc_mapping_get_xctrl_compound(struct uvc_video_chain *chain, switch (which) { case V4L2_CTRL_WHICH_CUR_VAL: - ret = __uvc_ctrl_load_cur(chain, ctrl); - if (ret < 0) - return ret; id = UVC_CTRL_DATA_CURRENT; query = UVC_GET_CUR; break; + case V4L2_CTRL_WHICH_MIN_VAL: + id = UVC_CTRL_DATA_MIN; + query = UVC_GET_MIN; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + id = UVC_CTRL_DATA_MAX; + query = UVC_GET_MAX; + break; case V4L2_CTRL_WHICH_DEF_VAL: - ret = uvc_ctrl_populate_cache(chain, ctrl); - if (ret < 0) - return ret; id = UVC_CTRL_DATA_DEF; query = UVC_GET_DEF; break; @@ -2072,6 +2107,14 @@ static int uvc_mapping_get_xctrl_compound(struct uvc_video_chain *chain, if (!data) return -ENOMEM; + if (which == V4L2_CTRL_WHICH_CUR_VAL) + ret = __uvc_ctrl_load_cur(chain, ctrl); + else + ret = uvc_ctrl_populate_cache(chain, ctrl); + + if (ret < 0) + return ret; + ret = mapping->get(mapping, query, uvc_ctrl_data(ctrl, id), size, data); if (ret < 0) return ret; @@ -2089,22 +2132,37 @@ 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; + 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 = uvc_ctrl_populate_cache(chain, ctrl); + case V4L2_CTRL_WHICH_MIN_VAL: + case V4L2_CTRL_WHICH_MAX_VAL: + break; + default: + return -EINVAL; + } - if (ret < 0) - return ret; - } - xctrl->value = uvc_mapping_get_s32(mapping, UVC_GET_DEF, - uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF)); - return 0; + ret = __uvc_queryctrl_boundaries(chain, ctrl, mapping, &qc); + if (ret < 0) + return ret; + + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + xctrl->value = qc.default_value; + break; + case V4L2_CTRL_WHICH_MIN_VAL: + xctrl->value = qc.minimum; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + xctrl->value = qc.maximum; + break; } - return -EINVAL; + return 0; } 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_v4l2.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, void *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 = ctrls->which; break; default: From patchwork Tue Dec 10 09:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901146 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 6BB7D23875C for ; Tue, 10 Dec 2024 09:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823786; cv=none; b=OR8CUXJZJQ67m6zmmGQZ0U4faqVGRuuAGda1UACJ9CNkcWp7cJMl8JaINJmAJESI7KBfsdJXCAbV3emUapodB+5KRLt1udARpF8urEP5Q0JbuRhXh7VJt7ayk1U2LP6AF+2f/CpRJm90c8kzn8AWGva24CA4pFdb0IhqlYQhDSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823786; c=relaxed/simple; bh=yqji/xzHYuOsoD1S6Hj7O2pucPqwN31k/pN+iJwwrO4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DJzDQ7xssgDBBfVhuja+fccF7Yb91LOOAspVWJyiDo2OvcLdJE8OKhvJr2Sf4s6kdko7WaUOo0yhiRCOPqgZBIZRbaIHuGClQzDL6elfnHuaXcmymB+TBMXF/w5dy3vFzRVEXLqoc6Mvg3owRjyvW0Ceid0YlLyJAoZwUHloihs= 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=bxXFqYYo; arc=none smtp.client-ip=209.85.222.181 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="bxXFqYYo" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b6da2d7884so111336185a.1 for ; Tue, 10 Dec 2024 01:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823783; x=1734428583; 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=S4DLEGpbxISaKGwkcSnN6qP20jbOjfnGAGZ1UU5NuHw=; b=bxXFqYYoqvjs5zW7e4ZRCQ/k4PuhewxRGQKvY+oXka+LKcTijAqk4YXRg7VKky9gjb 3iDRnTuzjl4716iI1vo+HJGFVb6phuQUsuLgbPSdivtp3be9Xd5KJP0bJz4HAWloMXfL J91+4uKvkFHvwJSYRC65t2nnQG5via4HM7RXs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823783; x=1734428583; 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=S4DLEGpbxISaKGwkcSnN6qP20jbOjfnGAGZ1UU5NuHw=; b=P9evEGM9thNZt+mOiSfljkNiDrnYt/R+ikHngPJq+PJ0i2wYPN1tDbJMAk1oZrwjhR CqCkOjH9o9nsWQ1afCVraBgdQlqyxgzU7RRI9TAvzduNhS8f0YI0FDkyz+fvPCDo/qUu cJC4CZD5OnHfdNxYkdpOyfAJrMZ9dPuyEw6Orr54Vt1aujbRAbGN9jbydb46g9VIzTyO 9whayit0xyAncxRzjt4S6rPZTt1PtN34QFa9ROYm1gDkN1WJVWVS3DE5akbIH+MPB6BG C9+Vs82eLbkzVKIW5yegDS0gkDx3XQbG/VfAYyouVkIpWfm0DqSRsJLVuOvt3PIMVJka WfYA== X-Forwarded-Encrypted: i=1; AJvYcCWDCsSjdpWPk//mpN4WvhnbZXEp3vnr3E0PZrOGXyc+8xaDrKh1pZoKNaUQJ9/GRmhf+oeTKLcTtgRKGg==@vger.kernel.org X-Gm-Message-State: AOJu0YyX63nz1JvrQ2vymT/QfR0fEEhfDxhqiZ1t6hMBVYHt2UMjz9gP PYQmiOfBWr4a6m2hsKzelKAeKznnYL8E4htG40UINGlCTm3G/wl6wLSWmsfsXA== X-Gm-Gg: ASbGncvufZOf3wL05JFyEZhrNJmM9Z+cA8KXssdakrAAN3TYA3BVLsQfxTxZuC9g4T3 JnLznN2Dp2zskrWwd7LQ9ZmxYGQKs82fAFddWLh9d/HhnxInaQBcmXWlBdIOM373rRwP3hWoDi+ fClA3wcOgjVss6V/vC6KunV+p9ot2R/clTns1AslB2SqMVmw/kbluMJdSuBkhELJRO6P8CXVQM+ E0mS/3MlmkkRHwtTpQ2zra5oi2MpiIdzI7kZ5cUjJaLdU46QQyVjfyy3bqbN7r7g3E6zZsFfgEf owCIQmfGSUjzD2mcKo4XOPVS8vfq X-Google-Smtp-Source: AGHT+IGDLwVPsYRL6IYDVi5Q+ZWF5oyLjYiYvYAuxK4fkpF2rSBiWjqmp7rVZEHZCpZBZUq7IJEJPQ== X-Received: by 2002:a05:6214:e6b:b0:6d8:848e:76c8 with SMTP id 6a1803df08f44-6d91e442686mr68091406d6.42.1733823783400; Tue, 10 Dec 2024 01:43:03 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:02 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:50 +0000 Subject: [PATCH v16 14/18] media: uvcvideo: let v4l2_query_v4l2_ctrl() work with v4l2_query_ext_ctrl Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-14-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 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. Reviewed-by: Yunke Cao Tested-by: Yunke Cao Reviewed-by: Hans de Goede 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_ctrl.c index 14aa9619fbf1..58bd42191f3e 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1259,7 +1259,8 @@ static int __uvc_query_v4l2_class(struct uvc_video_chain *chain, u32 req_id, } 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; @@ -1407,7 +1408,7 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *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 v4l2_query_ext_ctrl *v4l2_ctrl) { if (!ctrl->cached) { int ret = uvc_ctrl_populate_cache(chain, ctrl); @@ -1473,7 +1474,7 @@ static int __uvc_queryctrl_boundaries(struct uvc_video_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 = NULL; struct uvc_control *master_ctrl = NULL; @@ -1511,6 +1512,9 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; } + v4l2_ctrl->elem_size = sizeof(s32); + v4l2_ctrl->elems = 1; + if (v4l2_ctrl->type >= V4L2_CTRL_COMPOUND_TYPES) { v4l2_ctrl->flags |= V4L2_CTRL_FLAG_HAS_PAYLOAD; v4l2_ctrl->default_value = 0; @@ -1524,7 +1528,7 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, } 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; @@ -1650,7 +1654,7 @@ static void uvc_ctrl_fill_event(struct uvc_video_chain *chain, struct uvc_control_mapping *mapping, s32 value, u32 changes) { - struct v4l2_queryctrl v4l2_ctrl; + struct v4l2_query_ext_ctrl v4l2_ctrl; __uvc_query_v4l2_ctrl(chain, ctrl, mapping, &v4l2_ctrl); @@ -2132,7 +2136,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; switch (which) { @@ -2146,19 +2150,19 @@ static int uvc_mapping_get_xctrl_std(struct uvc_video_chain *chain, return -EINVAL; } - ret = __uvc_queryctrl_boundaries(chain, ctrl, mapping, &qc); + ret = __uvc_queryctrl_boundaries(chain, ctrl, mapping, &qec); if (ret < 0) return ret; switch (which) { case V4L2_CTRL_WHICH_DEF_VAL: - xctrl->value = qc.default_value; + xctrl->value = qec.default_value; break; case V4L2_CTRL_WHICH_MIN_VAL: - xctrl->value = qc.minimum; + xctrl->value = qec.minimum; break; case V4L2_CTRL_WHICH_MAX_VAL: - xctrl->value = qc.maximum; + xctrl->value = qec.maximum; break; } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.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, void *fh, unsigned int input) return ret; } -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 = fh; struct uvc_video_chain *chain = handle->chain; - return uvc_query_v4l2_ctrl(chain, qc); + return uvc_query_v4l2_ctrl(chain, qec); } -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 = fh; struct uvc_video_chain *chain = handle->chain; - struct v4l2_queryctrl qc = { qec->id }; + struct v4l2_query_ext_ctrl qec = { qc->id }; int ret; - ret = uvc_query_v4l2_ctrl(chain, &qc); + ret = uvc_query_v4l2_ctrl(chain, &qec); if (ret) return ret; - qec->id = qc.id; - qec->type = qc.type; - strscpy(qec->name, qc.name, sizeof(qec->name)); - qec->minimum = qc.minimum; - qec->maximum = qc.maximum; - qec->step = qc.step; - qec->default_value = qc.default_value; - qec->flags = qc.flags; - qec->elem_size = 4; - qec->elems = 1; - qec->nr_of_dims = 0; - memset(qec->dims, 0, sizeof(qec->dims)); - memset(qec->reserved, 0, sizeof(qec->reserved)); + qc->id = qec.id; + qc->type = qec.type; + strscpy(qc->name, qec.name, sizeof(qc->name)); + qc->minimum = qec.minimum; + qc->maximum = qec.maximum; + qc->step = qec.step; + qc->default_value = qec.default_value; + qc->flags = qec.flags; return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.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; 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); From patchwork Tue Dec 10 09:42:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901147 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 405CE3DABFB for ; Tue, 10 Dec 2024 09:43:05 +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=1733823787; cv=none; b=dv+3BZdGX7aDl7/4KQwrk4ITHra7IXxfpt7s2mijwLSvNKLpwbH+GmwHYkK8ALcnrfigzExINow174xqRt2Gkuu1keUPvCDO/H6Y2rJx1hM6XhKUIDWbQn+UH99mZCSnT00HpgJL/FBb9YFkZk+UOXoOBF+5KJfw60jDbDK1v+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823787; c=relaxed/simple; bh=j6w/ehoFFcMfXU0GvWdVutVl4sbMYNCORCUrUbyVXPY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KrcRsVYy0h9i46eTm+EaTaQ90swYEq5V9TRSULcVPVUJYOTr6+cyS2vsU1kQ+4FUqYhVrOkah9EmQM0LhtrV/DZSwOgM4R+BSHQontq99/8PfyAOuj7vMxmTRkbPekllExd6KlbbwlT9LNXKNACYaOJsICVQdIXyStEBjRiOcSE= 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=ZmVpE196; 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="ZmVpE196" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d87ab49423so52345926d6.0 for ; Tue, 10 Dec 2024 01:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823784; x=1734428584; 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=teneHbxdymYBZ2TJXTz4C2Fnz+shby6Rz+Rw9UldIMg=; b=ZmVpE196GIYFHl4MJlQhv9glMEJv9th6z+yPxbzztGBiJJQkXBOOX1XRzNKireLXKb wAM0WZza2M0qYQb7xLfW48t6y0Oux4ZiWFmD787urHOyfsOeIojmPIxsK012jU+vxVVv jUd9GlZ1PeqxOCMx1PGg69/Z5M1/JlQPCEkfM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823784; x=1734428584; 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=teneHbxdymYBZ2TJXTz4C2Fnz+shby6Rz+Rw9UldIMg=; b=Q3giEMlJs0mCtK8+RCshkelZWT/LBXriX6blq2mEABHMPXjuPNU9al8GYIPimoPspE y+hznUYVa4sigaK36g5KR/vFUK7Fdn1EoeTGjlmm0oAqbnPZGfvLyHmcVdn1n6146aSh TmDPbOG1g+IihxifB7OJTEKyJNOayNlOXycwX0QmhaiMvSMCiOiVzvx2kosUjJqwWh48 9BY69sV+XmEomxNuLbyv+LRFbI5TJKL+g6fvC8PutKWNcqcbpGDHexFFG+bnrU7u5sSV IyvFj8rhzetshnz8uh0Huz+ZtCfW/YSlnguJXHZ+wVDbo3iX1h10IdfVVJ00TpCuT+qG pu6Q== X-Forwarded-Encrypted: i=1; AJvYcCUTyRxYRAHWi0tU/ZwmVBAjr9fi6XVKW8MOrA6JPL+tz1XzFtfzmBM/MhEeVuyywZjluRo3T/Enm5negQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxlDC7lo9l1lR956tQ84gb/fJZuHDxRmTWb1M1/vib9H96gNuzP phbvbB463wCLqec4BWQecnTmgFBc8GKL2VXGnTZvbYNicP7IwB/jRs5wUs6Ksg== X-Gm-Gg: ASbGncsTYHeF6DWgSnJdcEu1QL24kwNlkaNNcUv+C0Y8/NeAL7pQyIgq39Z7uQ8AnwP OwbeTY0asi857i2KGs5NiqIjKg9yndn9rwZvtDUxI2XPMkQTmUjIhzsQZQdZWuvoLCxAYFglpL6 7glUBEPU3ddT6RIrJR/DwP5HX+0SSp6SisWoYv5b0x3CyE1gm4odWPOYagf4t0tpi6zoajD4E3t qIXhl1K900wH4sKD/maGqQ3uOXK9YNjobFC3bOBgxyBElewtR2GLLB2Fyk4IiHxXcmQq7+x1lek 7K/gtC+nOFPH8iI4Wl+JjvH3URVk X-Google-Smtp-Source: AGHT+IHPeSY10FnNmsQEJGreViToMkX+83gWAxGpMBUhrfxnm5Cs2DpKJx49CNRZNU1nYkGjkjlubQ== X-Received: by 2002:ad4:5c49:0:b0:6cb:99db:bdd5 with SMTP id 6a1803df08f44-6d91e40b5b5mr67741986d6.39.1733823784162; Tue, 10 Dec 2024 01:43:04 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:03 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:51 +0000 Subject: [PATCH v16 15/18] media: uvcvideo: Introduce uvc_mapping_v4l2_size Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-15-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Centralize the calculation for the v4l2_size of a mapping. Reviewed-by: Yunke Cao Tested-by: Yunke Cao Reviewed-by: Hans de Goede 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_ctrl.c index 58bd42191f3e..dd6129becf58 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1471,6 +1471,14 @@ static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain, return 0; } +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, @@ -1512,7 +1520,7 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, v4l2_ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; } - v4l2_ctrl->elem_size = sizeof(s32); + v4l2_ctrl->elem_size = uvc_mapping_v4l2_size(mapping); v4l2_ctrl->elems = 1; if (v4l2_ctrl->type >= V4L2_CTRL_COMPOUND_TYPES) { @@ -2101,7 +2109,7 @@ static int uvc_mapping_get_xctrl_compound(struct uvc_video_chain *chain, return -EINVAL; } - size = DIV_ROUND_UP(mapping->size, 8); + size = uvc_mapping_v4l2_size(mapping); if (xctrl->size < size) { xctrl->size = size; return -ENOSPC; @@ -2284,9 +2292,8 @@ static int uvc_mapping_set_xctrl_compound(struct uvc_control *ctrl, struct v4l2_ext_control *xctrl) { u8 *data __free(kfree) = NULL; - size_t size; + size_t size = uvc_mapping_v4l2_size(mapping); - size = DIV_ROUND_UP(mapping->size, 8); if (xctrl->size != size) return -EINVAL; From patchwork Tue Dec 10 09:42:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901150 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 299C1237A4D for ; Tue, 10 Dec 2024 09:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823795; cv=none; b=IROEStX/6LV2WxHi/aQj8ZkGj6BHx+qCUTWAkqD6XKRI+pDnQTjGbYAUC/oA+lWiFRe971yuaBGIjfvksQhObwH9bNslSRBp9Ykz7pm355eFpRGTYbuHw4xSRFinFyNOtuXo9MtmsWQ+Jtjfd76ku1O4lINY2LuuvTFR5rM0ADg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823795; c=relaxed/simple; bh=HCkd9QY2OfGozb/+L9hVVayAr5QQOjRc9Dn84hpf1DE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tvr0RUXtB9TrCUnO3co1UAMjl2mz3cml3pWPK/hCj/6IGFF4oeDiS2+t/WxL9iVFs6b3B0quJ5uwuTGvV/TiGOQs2T3k9bnB6hIdTrpfNZ2UhFJO9o35lw7AQhNEH0P9KFUcdSifRIpNPY9L4sbpYR4la2sl+e/edSOHJocAMJQ= 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=X7SF+lDz; arc=none smtp.client-ip=209.85.219.42 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="X7SF+lDz" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6d87fffeb13so44134916d6.1 for ; Tue, 10 Dec 2024 01:43:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823793; x=1734428593; 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=OHxayE4k42tgzCvBKbSWRnUHa8HIxT/un4VmPqqRwYk=; b=X7SF+lDz6MlNUHuAcXYN3JW/5Sv0DP77lsEtWLll/i75RbsNmLGGxt7OzyZl6BO7Np sfT654aLtUBMjISTP9sq5TVvqUAjgP6lVwVzGbQCfA/sbnbF/Q0uv56iQEM5nZbyX6v1 07tqyifhnyzEiL1hrDpP/zv8IISPW98lt+RPc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823793; x=1734428593; 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=OHxayE4k42tgzCvBKbSWRnUHa8HIxT/un4VmPqqRwYk=; b=gc17oTJtI2K3iBoU13EcvMcjIsFgFzHfh1EkbWod/AvSSI0khIjbtgFesw+ubDbo+M ubyVBwF1PUre5X9tIE6DgTcWIfQzgxboJ7ip/7wmksMpru8XG/kjitcVXTYmRpMgl6Dx 6XBETu5qsUfl2CXfeffUMHo8eJObi/dXCwATCge5W0xBw6j5+Lzr8XylW7T+8upMoFsz LvIHrECPt06FjfZ9mjprpSg0EMwlnhoppx7yXRP0d2WZXaEA0ENHmJ8PQuTGHtc6ueF6 R/mF90ElNTbzK3oM3F03aN/yublug4dLVPEimipIiZ76fuQmrwT8iorZXBZKhz4jBkre +N+g== X-Forwarded-Encrypted: i=1; AJvYcCW8DMXa6jH2tRRE0dm2RY93B8AWYy6NevdvOy2lFQcVvnlh6pSVNOYMbQ9Uvjcx2vB8SidaYycWwVRqnA==@vger.kernel.org X-Gm-Message-State: AOJu0YykYOPhRdRYyvnnL41ifYF0LEiAH6PGkZ0JBmZsDmKVbEYSQyO4 gc0QNgnE4MXJKc/5y5YUWPD1dYFxfHCgalr1b2lfRj9jV+VZBvjRo2/h6CPgzA== X-Gm-Gg: ASbGncuqgZ678e6D1eupJrBTkI8F6nujtilnEAVXc7KLf5PsjoIZgfPilDZzAf254Rr dAAEJhSJRd8Jt6RIaSc4WxGhL4wQIMrV5dDlMFjc1zLdmsGnQ1Dl89QrtFJ5BBC7A3NrRDk9BWU mRbT39HBrEEju6npGGfjdggczSDyxVproWXQD8IJV4lefni4T88UWGUAsYt1fKQiJSdjkcQHyRA v0uK1iuAOwH7jpU9o4oOKygCqpfJF8z5K6exFjTFA4hmVkJqlBkZ+CPr8Bh+L68gfQePs8bB195 8X7QA6I1HoqpXizINWSSI/SnBDPs X-Google-Smtp-Source: AGHT+IEdReo0MRnNlTyTmOkuTUdcKCx+CoS8N4Bbe9AR14bTkRgBndNrGwfcStRIkm86B2Q5mtIIRQ== X-Received: by 2002:a05:6214:f62:b0:6d8:a148:9ac9 with SMTP id 6a1803df08f44-6d8e73be7c3mr272587766d6.30.1733823785070; Tue, 10 Dec 2024 01:43:05 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:04 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:52 +0000 Subject: [PATCH v16 16/18] media: uvcvideo: Add sanity check to uvc_ioctl_xu_ctrl_map Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-16-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Do not process unknown data types. Tested-by: Yunke Cao Reviewed-by: Hans de Goede 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_v4l2.c index 5000c74271e0..0d9d056f1bbe 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_chain *chain, struct uvc_control_mapping *map; int ret; + if (xmap->data_type > UVC_CTRL_DATA_TYPE_BITMASK) { + uvc_dbg(chain->dev, CONTROL, + "Unsupported UVC data type %u\n", xmap->data_type); + return -EINVAL; + } + map = kzalloc(sizeof(*map), GFP_KERNEL); if (map == NULL) return -ENOMEM; From patchwork Tue Dec 10 09:42:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901148 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 ED2F42253F7 for ; Tue, 10 Dec 2024 09:43:06 +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=1733823789; cv=none; b=reQh3xat5q7mD1Hyfx5t23dptXUBEulJcs2Q4j/69HoiEHuJFIBwwKKuFY+ckirv8O62msvEjw4gTBeUq8+xdRWrIRM7ps0UFFbcltJlQ86GyvnGTD1Q2PTEoNHJSFWdE7M9T/TEw4qPYwvVtXx08mCK9Ml9lZPoRZqlrgSwNHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823789; c=relaxed/simple; bh=HryVrfF4ja+UE4Nf++7Oms3/m6HrslBSeTxh251rrlM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KE9XtMey66Xnpxc7TII/ITVNeOXKXXaE4hEYDYaxiIKpuUP9oAkvUy+mmOnD6m0GjGtCD74TfS2WWmRpN0JpfXPHcY0tiaNhJUjYeCSyyccrSr+hq6PrNpZqHyF5Df0SaPAZHv9X9DMsXYJl/pI4GHSZDRbz8kzmiQ03xQR8omY= 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=f0af1yjh; 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="f0af1yjh" Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6d8fa32d3d6so36791586d6.2 for ; Tue, 10 Dec 2024 01:43:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823786; x=1734428586; 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=2aUprzMfZUWIyjxGkmKCAmM/uBFiYLCsY67DDg7bs5I=; b=f0af1yjhXQk3n/QhWxnOwXAk86JDvwdsC9G9REOtCneE3HR/fvHr1WL8vb5MtzQx5i 5ippmVTwnw9GX7WqHldvZKeLNIh7HBknE99q2rjkl2kcXVT9N48dlKLc1XPT89ZdClu/ rTIYfahCmL4h6JthpJ8p6q/VB8Gd52FDYYjAM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823786; x=1734428586; 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=2aUprzMfZUWIyjxGkmKCAmM/uBFiYLCsY67DDg7bs5I=; b=CuS9JVnSV5IWL6Bv0dhT6Nou/uiHdwF8z2W+tKeVrpuQ8c1HIXrLa2dz7foq8L7qCp ksTZ83QGIEUtnztQXYP0OLG0v38Guv9ClLc/jmzvDiRb8BBRiv1JRS9HmKQzJ0d6qwAc XZuaK7xjTeJgSkdLsMjrdfLddqRX6ZEFp7a3dsfDtNbCexLXh0ZUKtEMurnt2wQ4mpG7 1jy2w1z1yJKtgM5VxDvIyiFTzrHFSTGSzLg4nOF8qPFtBReqLI5GMNDwAyxyqBLXhzFu QOG/RkwA80ykUMOwirCASbMX5enH2Lz8njBNcHyH4bdyfuLzoa6NlbapP8tdiGTNcRg/ 8V5w== X-Forwarded-Encrypted: i=1; AJvYcCX0a7BYF2MVa4WA8hx+VoXZ9YX6V/krworS4OtSZL3tPyKXD3ZcsBuoP4wm3QjSIMv2NnfQnQfI8llPHA==@vger.kernel.org X-Gm-Message-State: AOJu0YwVS358v1F4wXyif3AN87nEUkw6UqyId5skubnVrHDDOGEz5qwL a2Xf7gUkTY5ttokEp2ZXztSXKbSDJlqBL6lvGXSDGXZu1iOtb3uXzYlBqd7jew== X-Gm-Gg: ASbGncvpLe7lqVIYihGgyrmJZM0qkUmkNU4J7f9FDsQFPynH84Ep5JUj9ADo0A1bT7f C6P+TaeRZn7Nz/2Bs6CJ2nUJCD5Y2paMdj71iE+yNO+l0vCklSHypbMHN5BZPlQ+ZRV9P5nhcCj hQROWmmbaHEU+CcZbsM30VktGaMK6e6ciTXGvKOSucMZ4zGgEvVY9xw6V22FxI1ckfcyVnWSikt 7oMghPDEpbU+WXoW/2hWGjoc1eagD3EmVZ/lotSHAQwLUi3CpHhQBLKsDfwCjugGPHG9DBBjRwv FPsiGieneYA5yQWrdQ/nnkAb2QSM X-Google-Smtp-Source: AGHT+IEV5cazRGN6FSky6OmAJjjskESsyqTGoGeNqQvsriM6DHVN+Snh/fT73/JwaEBDp9NXdAYkiw== X-Received: by 2002:a05:6214:f06:b0:6d8:ab7e:e55e with SMTP id 6a1803df08f44-6d91e40b22amr56041826d6.34.1733823785890; Tue, 10 Dec 2024 01:43:05 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:05 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:53 +0000 Subject: [PATCH v16 17/18] media: uvcvideo: implement UVC v1.5 ROI Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-17-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Reviewed-by: Yunke Cao Tested-by: Yunke Cao Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda Signed-off-by: Ricardo Ribalda --- 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 | 7 ++++ 5 files changed, 109 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index dd6129becf58..86ea24b10b54 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[] = { .flags = 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 ‘Auto Detect and Track’ and/or + * ‘Image Stabilization’ bit have been set." + * 4.2.2.1.20 Digital Region of Interest (ROI) Control + */ + { + .entity = UVC_GUID_UVC_CAMERA, + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, + .index = 21, + .size = 10, + .flags = 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, + }, }; static const u32 uvc_control_classes[] = { @@ -603,6 +621,44 @@ static const struct uvc_control_mapping *uvc_ctrl_filter_plf_mapping( return out_mapping; } +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 = uvc_in; + struct v4l2_rect *v4l2_rect = v4l2_out; + + if (WARN_ON(v4l2_size != sizeof(struct v4l2_rect))) + return -EINVAL; + + if (uvc_rect->left > uvc_rect->right || + uvc_rect->top > uvc_rect->bottom) + return -EIO; + + v4l2_rect->top = uvc_rect->top; + v4l2_rect->left = uvc_rect->left; + v4l2_rect->height = uvc_rect->bottom - uvc_rect->top + 1; + v4l2_rect->width = uvc_rect->right - uvc_rect->left + 1; + + return 0; +} + +static int uvc_set_rect(struct uvc_control_mapping *mapping, size_t v4l2_size, + const void *v4l2_in, void *uvc_out) +{ + struct uvc_rect *uvc_rect = uvc_out; + const struct v4l2_rect *v4l2_rect = v4l2_in; + + if (WARN_ON(v4l2_size != sizeof(struct v4l2_rect))) + return -EINVAL; + + uvc_rect->top = min(0xffff, v4l2_rect->top); + uvc_rect->left = min(0xffff, v4l2_rect->left); + uvc_rect->bottom = min(0xffff, v4l2_rect->top + v4l2_rect->height - 1); + uvc_rect->right = min(0xffff, v4l2_rect->left + v4l2_rect->width - 1); + + return 0; +} + static const struct uvc_control_mapping uvc_ctrl_mappings[] = { { .id = V4L2_CID_BRIGHTNESS, @@ -897,6 +953,28 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, .filter_mapping = uvc_ctrl_filter_plf_mapping, }, + { + .id = V4L2_CID_UVC_REGION_OF_INTEREST_RECT, + .entity = UVC_GUID_UVC_CAMERA, + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, + .size = sizeof(struct uvc_rect) * 8, + .offset = 0, + .v4l2_type = V4L2_CTRL_TYPE_RECT, + .data_type = UVC_CTRL_DATA_TYPE_RECT, + .get = uvc_get_rect, + .set = uvc_set_rect, + .name = "Region Of Interest Rectangle", + }, + { + .id = V4L2_CID_UVC_REGION_OF_INTEREST_AUTO, + .entity = UVC_GUID_UVC_CAMERA, + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, + .size = 16, + .offset = 64, + .v4l2_type = V4L2_CTRL_TYPE_BITMASK, + .data_type = UVC_CTRL_DATA_TYPE_BITMASK, + .name = "Region Of Interest Auto Controls", + }, }; /* ------------------------------------------------------------------------ @@ -1473,6 +1551,9 @@ static int __uvc_queryctrl_boundaries(struct uvc_video_chain *chain, static size_t uvc_mapping_v4l2_size(struct uvc_control_mapping *mapping) { + if (mapping->v4l2_type == V4L2_CTRL_TYPE_RECT) + return sizeof(struct v4l2_rect); + if (uvc_ctrl_mapping_is_compound(mapping)) return DIV_ROUND_UP(mapping->size, 8); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 8aca1a2fe587..17b79108599f 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -538,6 +538,13 @@ struct uvc_device_info { u16 uvc_version; }; +struct uvc_rect { + u16 top; + u16 left; + u16 bottom; + u16 right; +} __packed; + struct uvc_status_streaming { u8 button; } __packed; 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 /* 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 /* Control flags */ #define UVC_CTRL_FLAG_SET_CUR (1 << 0) @@ -38,6 +39,18 @@ #define UVC_MENU_NAME_LEN 32 +/* 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-controls.h index 974fd254e573..72e32814ea83 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) +/* + * 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 */ From patchwork Tue Dec 10 09:42:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13901149 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 D52C9237A35 for ; Tue, 10 Dec 2024 09:43:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823791; cv=none; b=OrjjzEWVOR0WzUrA9nP8RRSpgRgC+THkEWJAIg7Zj7WwBSOdWMLBDJsx3kjb/OA5eF2Q/2uyUPkombKocHWSN7EP/xkNDEaL2gDWn+YR6znacWvDk2OPPB0qf487QViPFIBpWeBpfdJSzDdHkRyqi0b+bwmXIM6maej+LeyE1pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733823791; c=relaxed/simple; bh=fKDUU4+a+tgFts82eq+chwHIWurrBXbxHGkI4O6ed0U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aEEMDpLPrdWfjMf1nGNJArU7b9IiNRQJy1w0m3bT3F77RiOnvw7CHUqOp7hlIICUPyDq1InNU67iQkP9wruC/8rNrehVkp+5mFXJykFcsSdLynVokecBbdyNoZbilas1Q8w+5rLJDsHy8y1klZcI89BJd4B8PZxHjH7k8r7J7A0= 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=jEQOMHTH; arc=none smtp.client-ip=209.85.219.54 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="jEQOMHTH" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6d922db2457so3775536d6.3 for ; Tue, 10 Dec 2024 01:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733823788; x=1734428588; 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=LcSM+HEV8BWvpd8XLVPPgYNPK82Sc3PIhfJhk9lYWic=; b=jEQOMHTHW1SSFfR671K5xpr4OpCloXT+RjDqJUcusgkoguVlj8sWmMNeXDbIOJYtnZ ahVbqTSGc2yhv6ZVxR5c5MCLt4RAlai6IiYHko1Fi06muXVGCevHsEWv/Qw9N53V5rUz 81TpCVmiBwXwd2e1uujtZvRgJxhXADAx/36Po= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733823788; x=1734428588; 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=LcSM+HEV8BWvpd8XLVPPgYNPK82Sc3PIhfJhk9lYWic=; b=ZkZv8QnEL5VrBT81YE82UQdXqPlZ58YeUm8uxoe/X86rnSG2XgdhjyJHrqvI5iZXjJ 4RA+GvskCOI4uZkx+lQutH6bwaWe8mE5g3HxlRxIpiTyAGr8bR5EtpTvhcnUDS+rABcM WmL39AWk9rt1BIILcKxlHu8KRJJUZ6ST7php48/qocny4qGUmDUWVT9jvNYVtPgirF+C 4rywb73TK2tJrVQUradx62jdUKHjprl+OgeRrgbOyXXCRVV1cRiRFGSPCudIjtfsJRw/ APBNr2dpQ+TTKIRKicNQb3QUklP2qtkNqfOpz28Uw7j8+jWqfz97uDlWZB2+1wOe4/0Y vHuw== X-Forwarded-Encrypted: i=1; AJvYcCX+XBu9DqmqxVWe1pXA3uW8llodHWclQf4akHpV/0Qe45TnoqLGU5CR6UbyMOoK2RZed4F86l7KX1RdHA==@vger.kernel.org X-Gm-Message-State: AOJu0YwlHir1Gsv7d0E8jcmsMCdUraGQrJxEDxGlwjVG+O2NRh9jwV7i h2N3Xu6NMD7SLuh5utNylsDa0j35AMvQWhzI1/1vCjzEpceaF2aUoU282jyfrQ== X-Gm-Gg: ASbGncuJ6KsF/y5hwLGtbTTP7yZ5l6/Vz7L2zo71dKYnlVPM5zstx91kHZ/zIerMDxK c2MKEl1AGWySR4RdG36ZFvT2MLeBD6DahKoTrwELoz7nF7Er3wxdX/SF5O+rZMlVNXLm3h8NUYv mcZWpTgxFEv0F+ioyGobj9xlCjOuKSvo/WtY7S7KVdShB9jsMHhcLIH4NOqnCpWhEXeFGLXB5yl 6kozEgaz7F0gZHBqDzOaa8olOENbLNr9sLRBK3TUARr/svWxga2VF4hB3+itGdZc4Cy7sF+Ydny JX6v8wQ43Rci86tfUlQIwo2nP7P8 X-Google-Smtp-Source: AGHT+IFtCAY1FI+TINr0gaxNPy0pUOg439RuOUTCEezTgC51c5iK/b9dchgVcUIE8AI0mMGMWG8sDg== X-Received: by 2002:a05:6214:e6b:b0:6d4:1dc0:2620 with SMTP id 6a1803df08f44-6d91e4465a0mr64808496d6.40.1733823787859; Tue, 10 Dec 2024 01:43:07 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d92f7c2bc1sm773326d6.83.2024.12.10.01.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 01:43:06 -0800 (PST) From: Ricardo Ribalda Date: Tue, 10 Dec 2024 09:42:54 +0000 Subject: [PATCH v16 18/18] media: uvcvideo: document UVC v1.5 ROI Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241210-uvc-roi-v16-18-e8201f7e8e57@chromium.org> References: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> In-Reply-To: <20241210-uvc-roi-v16-0-e8201f7e8e57@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans de Goede , 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 Tested-by: Yunke Cao Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- .../userspace-api/media/drivers/uvcvideo.rst | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Documentation/userspace-api/media/drivers/uvcvideo.rst b/Documentation/userspace-api/media/drivers/uvcvideo.rst index a290f9fadae9..dbb30ad389ae 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 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 using 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 interest + 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 region + 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 region 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.