From patchwork Tue Sep 27 23:26:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17445 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 575C4C0DA4 for ; Tue, 27 Sep 2022 23:26:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5D0D262277; Wed, 28 Sep 2022 01:26:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1664321192; bh=oj3cZdMTPHw9yU7SRK5wjOpJ87eaJ6nHxR+d8lh95k0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OETHC4jUJAD6+GiPox7VpASIk3e/RQrsYEaO5+b8j8ejEk/32LMc36mkC7eA0zrOO np3uBcLnmvqAccNsRSOy2457VIZfEHCuvl2o3w3CK9mC/7azoSMWBRrNTcjKvoPKI8 Y9fQPaHIEEpg3Zf9yDxClyQYHgDdMZwNVwZHAAEWV7m3XbCs8wkKqICs7WK6lNRfEX VbyJ108bNfXfRxxUQpQ3VAQukxrCdkbB3flO3KqzCYDsUsxsslmFW2Iry+hVZXxxPN YIj+wA7EYodTIRvSID/xRsXBsJcSS7ZkDRj7SqH3jE3x2c07JhiWKb2Izu937qwRtO QFHbFn0cHuoYw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 604BF61F78 for ; Wed, 28 Sep 2022 01:26:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Tf2B2x7C"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B058D47C; Wed, 28 Sep 2022 01:26:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664321189; bh=oj3cZdMTPHw9yU7SRK5wjOpJ87eaJ6nHxR+d8lh95k0=; h=From:To:Cc:Subject:Date:From; b=Tf2B2x7CVAo72OdoLHMYg97Gc6SEtrLV/gXgFs6TogqnMgwdjy5jlsSEWte4K5Igt OfLY1NjnT92LTDBTdF7zUFpTHCw7IPsJ2wsAE1GGIhzZ4HbozfG6oVFP0pP9RxPRYu otdS9jO5cpm9liQsVcyiVQWyVqvbBDxiEKHvJ5IQ= To: libcamera-devel@lists.libcamera.org Date: Wed, 28 Sep 2022 02:26:28 +0300 Message-Id: <20220927232628.7544-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] cam: drm: Skip DRM devices not capable of supporting the atomic API 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The DRM helper picks the first DRM card that it can open. On platforms that have a standalone GPU, this risks selecting a device corresponding to the GPU instead of the display controller. Fix this by skipping devices that don't support the KMS atomic API. Some legacy display controllers would be skipped as well, but libcamera doesn't run on those systems anyway, and the DRM helper doesn't support the legacy KMS modeset API in any case. Signed-off-by: Laurent Pinchart Reviewed-by: Eric Curtin --- src/cam/drm.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp index b0602c942853..b2a6b0bba9e8 100644 --- a/src/cam/drm.cpp +++ b/src/cam/drm.cpp @@ -430,7 +430,8 @@ int Device::init() int Device::openCard() { const std::string dirName = "/dev/dri/"; - int ret = -ENOENT; + bool found = false; + int ret; /* * Open the first DRM/KMS device beginning with /dev/dri/card. The @@ -449,24 +450,38 @@ int Device::openCard() } for (struct dirent *res; (res = readdir(folder));) { + uint64_t cap; + if (strncmp(res->d_name, "card", 4)) continue; const std::string devName = dirName + res->d_name; fd_ = open(devName.c_str(), O_RDWR | O_CLOEXEC); - if (fd_ >= 0) { - ret = 0; - break; + if (fd_ < 0) { + ret = -errno; + std::cerr << "Failed to open DRM/KMS device " << devName << ": " + << strerror(-ret) << std::endl; + continue; } - ret = -errno; - std::cerr << "Failed to open DRM/KMS device " << devName << ": " - << strerror(-ret) << std::endl; + /* + * Skip devices that don't support the atomic API, to avoid + * selecting a DRM device corresponding to a GPU. + */ + ret = drmGetCap(fd_, DRM_CLIENT_CAP_ATOMIC, &cap); + if (ret < 0) { + drmClose(fd_); + fd_ = -1; + continue; + } + + found = true; + break; } closedir(folder); - return ret; + return found ? 0 : -ENOENT; } int Device::getResources()