From patchwork Thu Nov 19 16:39:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 29044 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 EBC4AC3355 for ; Thu, 19 Nov 2026 16:40:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A2D56A942; Thu, 19 Nov 2026 17:40:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="scNB+cnC"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 940436A861 for ; Thu, 19 Nov 2026 17:39:54 +0100 (CET) Received: from [192.168.1.7] (unknown [93.65.100.155]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 61B8A1F10; Thu, 19 Nov 2026 17:37:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795106245; bh=PBHO3vFG4Ws1W1Tu0OCotZ37SqpKxRPTgwZHHe8mUdw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=scNB+cnCEE0LTZdnLNdcbVrKt2h52SdcITLrK1gyO0mra4p1Pxb3luArp3hZ9wRJC +gOjEV79uCzM6cS6yLQ6dEUSKKAcizgwIoAVvY+dCLArcesMedf1Qkms3BiGuvcpjC z8nungXxvGkjA5Ubu3bT2oLI3Zdi3Zn0k7huBsGA= From: Jacopo Mondi Date: Thu, 19 Nov 2026 17:39:46 +0100 Subject: [PATCH 4/6] libcamera: media_device: Store entities ids by devnum MIME-Version: 1.0 Message-Id: <20261119-multicontext-prep-v1-4-f68ea7ef960f@ideasonboard.com> References: <20261119-multicontext-prep-v1-0-f68ea7ef960f@ideasonboard.com> In-Reply-To: <20261119-multicontext-prep-v1-0-f68ea7ef960f@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4393; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=PBHO3vFG4Ws1W1Tu0OCotZ37SqpKxRPTgwZHHe8mUdw=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBq/yZYM/zzmb+s/Alj1pMNmkXH1kYgoqqf/YSaa Awa7Xq3t5mJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCav8mWAAKCRByNAaPFqFW PO2xD/4ye7IK+S5rf0xd2DDgxgMrKysqiCPRkEAz+N/UvRAi6DN2WxDjIxZFzpG87S0JIL1Qgi4 Oab32ncQlGO+6bcPsnoxzJ4r0DqXeSq5sOazUcclWyEpF1/5V36dD3n2/0RbgJnQzvoDJPSdrQR ISH7ekqU9zwlSQnRO7qaFXjMA76rw6xlVDlt5I72TVRe9/aSAtUX16xDrGkd209HNlzxWai5VRJ /4ThKqeq4w96yPRfur1ZcNoutHuXfpd5ZJO66HScxeVUq3742VbHNYyeFxNcxhXKAy77JEyzGcg gCceE6TZNism0FkXGIW2oTbLZLCp8KHE8W0qQWW79PYYQ7x3hIhomhjoDdHbdcOFaepufnzewi3 9ymziqdOhZ2nky150e+WKDnImcPcml7Wejatze2XIHP5fVU9nCevnptAu0IUbAI2efnz0MeL2Af AJPnj7nFTtL4epljmeF7eMlUr1M8nhb7JWZD3LMWASbNTpf8Wnx+1EuhGom+Ifu3GveV4l/SPjX C+cKLUIC2HevRKy/MHonVj+7iMQ/tcxl/qYf9mCgLFcAx8Bng09STpcGrR2CaXNB89c8pE7/ul+ u9sDAc9zrnXXjc72uj4Snbil2wUoR+laF2s1F5w0fSxhYNXB4vg/QcCX31a1AnTuskaCG2F/9HU CQZldGzqnx87ssg== 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" After the media topology has been queried and deemed to be stable, create a map of device numbers to entity ids. Multiple entities can have the same devnum as they refer to the same devnode, hence we map the devnum to a list of entities ids. Add two accessors to the MediaDevice class to: - Get all the devnums - Get the list of entities ids given a devnum These helpers will be used to de-couple the device enumerators from the MediaObject class hierarchy, specifically the devnode path injection that requires to know the entities' devnums. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/media_device.h | 21 +++++++++++++++ src/libcamera/media_device.cpp | 44 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index 8bab60343aad..6fd84de033b6 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -9,7 +9,9 @@ #include #include +#include #include +#include #include #include @@ -50,6 +52,17 @@ public: unsigned int version() const { return version_; } unsigned int hwRevision() const { return hwRevision_; } + const std::vector entitiesDevnums() const + { + return utils::map_keys(devnumsMap_); + } + + const std::list &entitiesIdsByDevNum(dev_t devnum) const + { + ASSERT(devnumsMap_.contains(devnum)); + return devnumsMap_.at(devnum); + } + const std::vector &entities() const { return entities_; } MediaEntity *getEntityByName(const std::string &name) const; MediaEntity *getEntityByName(const std::regex &name) const; @@ -128,6 +141,12 @@ private: delete[] links_; } + std::span entities() const + { + return { reinterpret_cast + (topology_.ptr_entities), topology_.num_entities }; + } + struct media_v2_topology topology_ = {}; private: @@ -137,6 +156,8 @@ private: struct media_v2_pad *pads_ = nullptr; } mediaV2Topology_; + std::map> devnumsMap_; + UniqueFD fd_; bool valid_; bool acquired_; diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index f9562aa18b80..6dd4bdcc49c7 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -238,6 +238,28 @@ int MediaDevice::populate() version = mediaV2Topology_.version(); } + /* + * Create a map of devnums to entity ids. It will be used to inject the + * entity devnode with the support of the device enumerators. + */ + for (const auto &ent : mediaV2Topology_.entities()) { + struct media_v2_interface *iface = + findInterface(mediaV2Topology_.topology_, ent.id); + if (!iface) + continue; + + dev_t devnum = makedev(iface->devnode.major, iface->devnode.minor); + + /* Multiple entities can refer to the same devnum. */ + auto it = devnumsMap_.find(devnum); + if (it == devnumsMap_.end()) { + devnumsMap_[devnum].push_back(ent.id); + continue; + } + + it->second.push_back(ent.id); + } + /* Populate entities, pads and links. */ if (populateEntities(mediaV2Topology_.topology_) && populatePads(mediaV2Topology_.topology_) && @@ -365,6 +387,28 @@ bool MediaDevice::match(const DeviceMatch &device) const * \return The MediaDevice hardware revision */ +/** + * \fn MediaDevice::entitiesDevnums() + * \brief Return the devnums for all entities in the MediaDevice + * + * devnums are created for each media entity which register a device node using + * mkdev(major, minor). + * + * \return A vector of devnums + */ + +/** + * \fn MediaDevice::entitiesIdsByDevNum(dev_t devnum) + * \brief Return a list of entities ids associated with \a devnum + * \param[in] devnum The device numer + * + * Return a list of media entities ids whose device node is associated with + * \a devnum. As multiple media entites can refer to the same device node + * return a list. + * + * \return A list of media entities ids + */ + /** * \fn MediaDevice::entities() * \brief Retrieve the list of entities in the media graph