From patchwork Wed Aug 20 13:23:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 24165 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 CC8CFBD87C for ; Wed, 20 Aug 2025 13:23:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B653692E2; Wed, 20 Aug 2025 15:23:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VzwY3Oxk"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BEDFE613DC for ; Wed, 20 Aug 2025 15:23:36 +0200 (CEST) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F2D2E6AF; Wed, 20 Aug 2025 15:22:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1755696158; bh=Nebbj17QuCZG3Z+0s6BmxZL9+rWBI0LNI2lJDPXvC9M=; h=From:To:Cc:Subject:Date:From; b=VzwY3OxkI/6uvijdLdbbyx9XxgOkKs1TYcUKaDrCjPGS1AA2y3RMh8i7yEi+gFRNQ qtI5ErVejQm9UmBB/XRY1L7O/jhBJ7X30mrhGnI+ZUF/OsnpJp6b5MppbCXhbviKZN 93XiNVUkVufMcyOsq1ZEHBDd+oUt7yjzhBKWjp/U= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: dan.scally@ideasonboard.com Subject: [PATCH 0/3] Fix fast-booting device enumeration problems Date: Wed, 20 Aug 2025 14:23:13 +0100 Message-ID: <20250820132316.1033443-1-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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" Hello all At present, a CameraManager that is created before the device nodes for subdev entities in a media graph have been created (for example, because some subdev drivers have not yet probed and so the v4l2-async framework hasn't called for them to be built yet) will never match any pipeline handlers for that media device. This is because the MediaDevice populates itself with entities, interfaces, pads and links but ignores the fact that the interfaces for the subdev entities are missing. When DeviceEnumeratorUdev:: populateMediaDevice() is called, the entity's major and minor numbers are checked, seen to be zero (as they come from the missing interfaces) and then the entity is simply ignored rather than treated as dependencies that need to be watched for. The MediaDevice is added through DeviceEnumerator::addDevice() to be checked against the pipeline handler's match() functions. When the device nodes for the subdevices are eventually detected as v4l2-async completes they are simply placed onto a list of orphaned nodes and ignored. To remedy the problem this set checks for missing interfaces during MediaDevice::populate() and if it sees some are missing, allows the MediaDevice to be created successfully but leaves the isValid() flag false. DeviceEnumeratorUdev is updated to check isValid() and when it is false, defers the creation of MediaEntity / MediaPad / MediaLink objects. Each time udevNotify() is triggered by a new device MediaDevice::populate() is checked again for each deferred MediaDevice, and once the missing interfaces are found in the topology the other objects are created, dependencies resolved and the MediaDevice added as normal. There may be a better way of receiving notice from the kernel that the media graph is fully complete and ready to be parsed; at the moment we rely on the reported topology version number becoming stable across two iterations of a loop that checks MEDIA_IOC_G_TOPOLOGY, but that's not sufficient to avoid this issue. Thanks Dan Daniel Scally (3): libcamera: media_device: Expand return values for populateEntities() libcamera: device_enumerator_udev: Add initMediaDevice() libcamera: device_enumerator_udev: Defer invalid media devices .../internal/device_enumerator_udev.h | 3 + include/libcamera/internal/media_device.h | 2 +- src/libcamera/device_enumerator.cpp | 2 +- src/libcamera/device_enumerator_udev.cpp | 85 ++++++++++++++----- src/libcamera/media_device.cpp | 27 +++--- 5 files changed, 85 insertions(+), 34 deletions(-)