[{"id":34391,"web_url":"https://patchwork.libcamera.org/comment/34391/","msgid":"<20250530100022.GT12492@pendragon.ideasonboard.com>","date":"2025-05-30T10:00:22","subject":"Re: [PATCH v4] apps: cam: Skip non-display GPUs","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Fri, May 30, 2025 at 11:08:15AM +0200, Milan Zamazal wrote:\n> Device::openCard() in the cam DRM helpers looks for a /dev/dri/card*\n> device that can be opened and that doesn't fail when asked about\n> DRM_CAP_DUMB_BUFFER capability (regardless whether the capability is\n> supported by the device).\n> \n> There can be matching devices that are not display devices.  This can\n> lead to selection of such a device and inability to use KMS output with\n> `cam' application.  The ultimate goal is to display something on the\n> device and later the KMS sink will fail if there is no connector\n> attached to the device (although it can actually fail earlier, when\n> trying to set DRM_CLIENT_CAP_ATOMIC capability if this is not\n> supported).\n> \n> Let's avoid selecting devices without connectors, CRTCs or encoders.\n> The added check makes the original check for DRM_CAP_DUMB_BUFFER API\n> most likely unnecessary, let's remove it.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Reviewed-by: Mattijs Korpershoek <mkorpershoek@kernel.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nPushed, thank you.\n\n> ---\n>  src/apps/cam/drm.cpp | 25 +++++++++++++++----------\n>  1 file changed, 15 insertions(+), 10 deletions(-)\n> \n> diff --git a/src/apps/cam/drm.cpp b/src/apps/cam/drm.cpp\n> index 47bbb6b05..f4b470976 100644\n> --- a/src/apps/cam/drm.cpp\n> +++ b/src/apps/cam/drm.cpp\n> @@ -450,8 +450,6 @@ int Device::openCard()\n>  \t}\n>  \n>  \tfor (struct dirent *res; (res = readdir(folder));) {\n> -\t\tuint64_t cap;\n> -\n>  \t\tif (strncmp(res->d_name, \"card\", 4))\n>  \t\t\tcontinue;\n>  \n> @@ -465,15 +463,22 @@ int Device::openCard()\n>  \t\t}\n>  \n>  \t\t/*\n> -\t\t * Skip devices that don't support the modeset API, to avoid\n> -\t\t * selecting a DRM device corresponding to a GPU. There is no\n> -\t\t * modeset capability, but the kernel returns an error for most\n> -\t\t * caps if mode setting isn't support by the driver. The\n> -\t\t * DRM_CAP_DUMB_BUFFER capability is one of those, other would\n> -\t\t * do as well. The capability value itself isn't relevant.\n> +\t\t * Skip non-display devices. While this could in theory be done\n> +\t\t * by checking for support of the mode setting API, some\n> +\t\t * out-of-tree render-only GPU drivers (namely powervr)\n> +\t\t * incorrectly set the DRIVER_MODESET driver feature. Check for\n> +\t\t * the presence of at least one CRTC, encoder and connector\n> +\t\t * instead.\n>  \t\t */\n> -\t\tret = drmGetCap(fd_, DRM_CAP_DUMB_BUFFER, &cap);\n> -\t\tif (ret < 0) {\n> +\t\tstd::unique_ptr<drmModeRes, decltype(&drmModeFreeResources)> resources{\n> +\t\t\tdrmModeGetResources(fd_),\n> +\t\t\t&drmModeFreeResources\n> +\t\t};\n> +\t\tif (!resources ||\n> +\t\t    resources->count_connectors <= 0 ||\n> +\t\t    resources->count_crtcs <= 0 ||\n> +\t\t    resources->count_encoders <= 0) {\n> +\t\t\tresources.reset();\n>  \t\t\tdrmClose(fd_);\n>  \t\t\tfd_ = -1;\n>  \t\t\tcontinue;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A9E11C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 30 May 2025 10:00:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4422468DAC;\n\tFri, 30 May 2025 12:00:31 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 43D6468D9D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 30 May 2025 12:00:29 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4593A82E;\n\tFri, 30 May 2025 12:00:01 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ftB9xqQ1\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1748599201;\n\tbh=imOXtA1CSX5Fu+l3EzXmOceFRHhJY4J9Dm7A075ZdXg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ftB9xqQ1xZBdPK99PtGm+OBpFwTolWxxdKP6QWDAr7cTbsguztw7rQC/EeAj91ewQ\n\tPA9BfMQvus5zaFyfaBK1NIoXvtUq3r6l1KVWVO7fSJLgk7cZ4MnlW2UCQN0CQ4XU6K\n\tztCBmvslttpAmUlAopV+bPOxbVOZF+utXi/lC9m4=","Date":"Fri, 30 May 2025 13:00:22 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tMattijs Korpershoek <mkorpershoek@kernel.org>","Subject":"Re: [PATCH v4] apps: cam: Skip non-display GPUs","Message-ID":"<20250530100022.GT12492@pendragon.ideasonboard.com>","References":"<20250530090815.18587-1-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250530090815.18587-1-mzamazal@redhat.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]