From patchwork Wed Jun 1 15:23:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Curtin X-Patchwork-Id: 16125 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 3AFA0BD160 for ; Wed, 1 Jun 2022 15:24:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 45AA665631; Wed, 1 Jun 2022 17:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654097046; bh=+nqydM/I3LJFyuwAsgvXcD4TJ38CwGqMQO06dQ3NNek=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=zT9qwF1ckK4CmyXZAwjzxcExX2ctD6PPcKl9PXzpKsFzNGSsfkmDqFYKXbDwtculc iLRrkeh+cXDCHzF+QoImsExP6aMOMuNG+9RkoqaBvzCuJP5HO4wAKbyqjallhEJovN FUS5XBFXjInbVJ3iWUCu9XvpSUVdk8Jz201AUaWxIOn509WZMamlBwgHd+1hNC1eUS U5/S1P6R12jdDwR38Go7lv595/CNI2xpPzIcsKLT55fKzZL8VVXUq3owB3pMETxot6 gtlKj0jW/LcubdfFKwUZhkn6X3GsM0ZHwldTWK7gWYRGVQpMNc+Opaz7rk419k9Mny mTaV3CBfqqyZw== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6262260413 for ; Wed, 1 Jun 2022 17:24:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="jNEMPi8o"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654097043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S+2Wo+NuuCWLNXxzZOOcYeGSU7isVTl4gCUJThsNYcM=; b=jNEMPi8otviL3EJVXmaLotVF7VKH0xlRVohWCis5KjovTiwo33/8u3/kVJW2X1XDd30Zjh UFHu+BcxpFCiEfkOdJalpoE6Ib60WYtEUCqa89nf370EZF5Ptk0Px5IZMBpusO8h/iNl06 030GFqufAyT8Gue1oYnHr22Fvd/sFng= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-595-d8n_Fh_qOnip1C4wYEDqQg-1; Wed, 01 Jun 2022 11:24:02 -0400 X-MC-Unique: d8n_Fh_qOnip1C4wYEDqQg-1 Received: by mail-wm1-f72.google.com with SMTP id l34-20020a05600c1d2200b003973a50c1e4so1303706wms.2 for ; Wed, 01 Jun 2022 08:24:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=S+2Wo+NuuCWLNXxzZOOcYeGSU7isVTl4gCUJThsNYcM=; b=IqY6Usk0/gcxBJhpjkec4wiRfpUySGa2bsSAvzH8URaztg1bQuuF2hl09bieadUl5Z AgK1Do2p1Drohiph6UHX74gVrh8e/YCBOHFPLU/u1UU7FPQeC8aqjnkFvZBN7f42hzcH Xwa6SOoeWGeDEmMMcUH9ztv6bv7TW6VkyX7pdwLr9av2raOajScAuKI0KmuonHkXw5cC s7ZmNd91JnZwMuRZkqieQ7CeTMQJ9/cVcUYmgsMlVqFaqg84S26/D32y1L+NnkEtVBYy KQVvaUcB+eN1NKgbMDi0ttMMgGjVKx0Wk1z62NeeKHRKOf6j2cHUDUjr8FCB0WM+Kp4k aTJQ== X-Gm-Message-State: AOAM533Q+pHxCE10oRAUOyS9rYPTiKB0kfyiD/AsEOyttnskXY4SOXaq ezkwvNe4+UM+4VkmP5h5YfwtPoH9wtjcxhM4xrp47rUGvmay+itWuxNmucX7lxD5L7tQ9q+eItM jSRPCB8BaGiWobc194aAj8gITyz4RX4PKunjkG2ifp8lWBXy8ppMcTX8jCbhhfqJyzWXnV4qu9y D8GSVXoKaX X-Received: by 2002:a7b:ce94:0:b0:397:82a5:dd05 with SMTP id q20-20020a7bce94000000b0039782a5dd05mr27477474wmj.161.1654097040405; Wed, 01 Jun 2022 08:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXhzm5GWUYv1JWYVgFsZipRCQVESFu2WtCiTNoI3JbuGAQcsN5oZ1ETaHSNbQWMpKxTdO3BA== X-Received: by 2002:a7b:ce94:0:b0:397:82a5:dd05 with SMTP id q20-20020a7bce94000000b0039782a5dd05mr27477455wmj.161.1654097040177; Wed, 01 Jun 2022 08:24:00 -0700 (PDT) Received: from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340]) by smtp.gmail.com with ESMTPSA id j26-20020a05600c1c1a00b003973e27b789sm7730487wms.27.2022.06.01.08.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 08:23:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Jun 2022 16:23:45 +0100 Message-Id: <20220601152345.37753-1-ecurtin@redhat.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH] cam: drm: Support /dev/dri cards other than 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: , X-Patchwork-Original-From: Eric Curtin via libcamera-devel From: Eric Curtin Reply-To: Eric Curtin Cc: Ian Mullins Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Existing code is hardcoded to card0. Since recent fedora upgrades, we have noticed on more than one machine that card1 is present as the lowest numbered device, could theoretically be higher. This technique tries every file starting with card and continue only when we have successfully opened one. These devices with card1 as the lowest device were simply failing when they do not see a /dev/dri/card0 file present. Reported-by: Ian Mullins Signed-off-by: Eric Curtin --- src/cam/drm.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp index 42c5a3b1..5a322819 100644 --- a/src/cam/drm.cpp +++ b/src/cam/drm.cpp @@ -8,6 +8,7 @@ #include "drm.h" #include +#include #include #include #include @@ -393,8 +394,10 @@ Device::~Device() int Device::init() { - constexpr size_t NODE_NAME_MAX = sizeof("/dev/dri/card255"); - char name[NODE_NAME_MAX]; + constexpr size_t DIR_NAME_MAX = sizeof("/dev/dri/"); + constexpr size_t BASE_NAME_MAX = sizeof("card255"); + constexpr size_t NODE_NAME_MAX = DIR_NAME_MAX + BASE_NAME_MAX - 1; + char name[NODE_NAME_MAX] = "/dev/dri/"; int ret; /* @@ -404,14 +407,28 @@ int Device::init() * from drmOpen() is of no practical use as any modern system will * handle that through udev or an equivalent component. */ - snprintf(name, sizeof(name), "/dev/dri/card%u", 0); - fd_ = open(name, O_RDWR | O_CLOEXEC); - if (fd_ < 0) { - ret = -errno; - std::cerr - << "Failed to open DRM/KMS device " << name << ": " - << strerror(-ret) << std::endl; - return ret; + DIR *folder = opendir(name); + if (folder) { + for (struct dirent *res; (res = readdir(folder));) { + if (strlen(res->d_name) > 4 && + !strncmp(res->d_name, "card", 4)) { + memcpy(name + DIR_NAME_MAX - 1, res->d_name, + BASE_NAME_MAX); + fd_ = open(name, O_RDWR | O_CLOEXEC); + if (fd_ < 0) { + ret = -errno; + std::cerr + << "Failed to open DRM/KMS device " + << name << ": " + << strerror(-ret) << std::endl; + continue; + } + + break; + } + } + + closedir(folder); } /*