From patchwork Fri Jul 25 10:33:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23954 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2676CC3237 for ; Fri, 25 Jul 2025 10:34:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C0712690B2; Fri, 25 Jul 2025 12:33:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="h98uesZN"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 58F7869071 for ; Fri, 25 Jul 2025 12:33:57 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 791F878E; Fri, 25 Jul 2025 12:33:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439597; bh=OyxdGg/MnzknpPmqu3CZEm0TiSWf8wMZKkhjSJR7zsc=; h=From:Subject:Date:To:Cc:From; b=h98uesZNtFBp/IaoVrEU0DXOXd+QxE65YFa9k56LEFQ/C1O1UkoyW1RQrYTYJ9IXF Liz7nPFWgbyfZKqDaJWibqoSb735JehC7KbEEaDQaRhuILePdRjbOK02+B8h2Yu7vT nKmQGcdK2f3Zj/kbzN/cLDwUlBGNYUnT21JV9RG8= From: Jacopo Mondi Subject: [PATCH 0/9] libcamera: Support for multi-context operations Date: Fri, 25 Jul 2025 12:33:45 +0200 Message-Id: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIldg2gC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI1MDcyMT3dzSnJLM5Py8ktSKEt0U8zQLE1Mzo6S0JHMloJaCotS0zAqwcdG xtbUAmvKHEF4AAAA= X-Change-ID: 20250724-multicontext-d7f84562bfb7 To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3073; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=OyxdGg/MnzknpPmqu3CZEm0TiSWf8wMZKkhjSJR7zsc=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12Th7TKVXBBA/c9Qhk7D9tokzC/FXyURN5tm pr5UDrYILCJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdkwAKCRByNAaPFqFW PPDvD/97Q8WD07iQqKwo3JPnS0m7LY6QE5WVywUsuv2BK4RbtsqvcE20H7MWhL2b0GziKNA69PB HjjXF9t+90VwWFs/ju1IK7h0YwUfVHRE/+D/I+GkT6Qv+yGAZ6+jdpZ75JknfVj4ORX/xkPM7EU FUXNWGTRtf6WliUdRke0UM+get0kyYhVnXR2b0yw6tD1dkGbigsS+hqShFnyNPBUYMj8ij9P/iL YwDziVWBDtzjnLJuytUfLJvkLvxtB6PzHAzcz6aNr7/z674jUeY1GxSzo1DPd9lNWwSMvuRn1Vf DwwjQH5I8w19qjhNdrjA1XNP6SWGmRDGKA15WhgzUs+++DbPfZ4ZM+g5o7TS5CAYBO+VlZMok7H sSwEOcI8kcY96CEh3q8rSzmmMR6ZL/2i+dk4MQTzUpc3cAywY3h8xcS1fRkp7iynU2G/bi21a8R WSqW/Xm8etYC28lQ/zqOH0jBo7uiq75vF0yOCo0240jskYT36QCJftzdaP5/qsKzR6PC0Aa/Ag+ 9SLs28PyndwTJ7H1fyccMDQ1pq9S2alklQBz8UA72fXbfD1awkCY6Oan633BRxrIJqGbDCCoovb ZKA/y/O/zOQ7brEGYgOWxbOGsZIVPdYUkAR9bqXag2/QUHYWF/38F9i9o3pDP0gtfscOSpIUyuv tYwXwAQHNugT0mg== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Support for multi-context operations has been introduced in the Linux kernel by patch series https://patchwork.linuxtv.org/project/linux-media/list/?series=17092 This series adds support in libcamera for operating a media device using multi-context support. The key design point is around the unique ownership of a media device. Currently the MediaDevice class allows a single user to "acquire" and "lock" it for exclusive use, to avoid concurrently running instances of libcamera to operate the same media graph. With multi-context support this constraint is not valid anymore, and a media device that supports multi-context operations can be operated as many times as the kernel driver allows to. To represent this, introduce a SharedMediaDevice class that derives from MediaDevice and that implements the "acquire" and "lock" operations as nop. Also introduce a MediaContext class that can be created both from a MediaDevice and from a SharedMediaDevice and that allows to bind devices together. MediaContext created from MediaDevice implements binding as a nop. This is not an issue as a single instance of a MediaDevice can be created and hence bindings is effectively only called once. A MediaContext created from a SharedMediaDevice allows instead to perform proper binding of devices and create an isolated execution context. Tested on Pi5 both with the multi-context kernel support series applied and without to validate that the series doesn't break existing users and can be used on both multi-context aware systems and context unaware ones. Signed-off-by: Jacopo Mondi --- Jacopo Mondi (9): include: linux: Update media.h with media flags include: linux: videodev2: Add BIND_CONTEXT include: linux: v4l2-subdev: Add SUBDEV_BIND_CONTEXT libcamera: v4l2_videodevice: Add bind context libcamera: v4l2_subdevice: Add bind context libcamera: media-device: Introduce SharedMediaDevice libcamera: media-device: Introduce MediaContext [DNI] libcamera: rpi/pisp: Bind devices in a context [DNI]: rpi/pisp: Set format and bind ISP subdev include/libcamera/internal/media_device.h | 62 +++++- include/libcamera/internal/v4l2_subdevice.h | 2 + include/libcamera/internal/v4l2_videodevice.h | 2 + include/linux/media.h | 6 +- include/linux/v4l2-subdev.h | 11 ++ include/linux/videodev2.h | 10 + src/libcamera/device_enumerator.cpp | 8 +- src/libcamera/media_device.cpp | 274 ++++++++++++++++++++++++++ src/libcamera/pipeline/rpi/pisp/pisp.cpp | 72 ++++++- src/libcamera/v4l2_subdevice.cpp | 18 ++ src/libcamera/v4l2_videodevice.cpp | 18 ++ 11 files changed, 472 insertions(+), 11 deletions(-) --- base-commit: b65df7e7554b45e2d3d7fdb5b37c2ab7df3db4fe change-id: 20250724-multicontext-d7f84562bfb7 Best regards,