{"id":16255,"url":"https://patchwork.libcamera.org/api/patches/16255/?format=json","web_url":"https://patchwork.libcamera.org/patch/16255/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220616214551.43630-1-ecurtin@redhat.com>","date":"2022-06-16T21:45:52","name":"[libcamera-devel,v5] cam: drm: Support /dev/dri cards other than 0","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"c50ca672d1de0d80363d8846160f79e188420b93","submitter":{"id":101,"url":"https://patchwork.libcamera.org/api/people/101/?format=json","name":"Eric Curtin","email":"ecurtin@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16255/mbox/","series":[{"id":3184,"url":"https://patchwork.libcamera.org/api/series/3184/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3184","date":"2022-06-16T21:45:52","name":"[libcamera-devel,v5] cam: drm: Support /dev/dri cards other than 0","version":5,"mbox":"https://patchwork.libcamera.org/series/3184/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16255/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16255/checks/","tags":{},"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 631F5BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 16 Jun 2022 21:50:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9D03E65635;\n\tThu, 16 Jun 2022 23:50:50 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 356D8600F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Jun 2022 23:50:49 +0200 (CEST)","from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-642-dl5OChZ1N_idHkZN9Z_6IA-1; Thu, 16 Jun 2022 17:50:45 -0400","by mail-wm1-f72.google.com with SMTP id\n\tv125-20020a1cac83000000b0039c832fbd02so1706113wme.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Jun 2022 14:50:44 -0700 (PDT)","from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tl3-20020a5d5263000000b0020ff7246934sm2743998wrc.95.2022.06.16.14.50.42\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 16 Jun 2022 14:50:42 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655416250;\n\tbh=XXisAqophaX41zQ3wKFENlm9rR98ixYqCcVtvGB1lYQ=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=e/TJ4IGhxQ2FroePKMHrh5o0NjvUbB0H2XLnE61fLY5ZWzAFJgaLMj2Ry8jZarMcI\n\tRdyr88gIse5Hzu0R7/z+y56fkndARR//ygu6kLY7dlfk6HnG2m24RhuqX25khxQ9BV\n\t+0jjQCimNFSSDx/IZxywLmguULkqhs1QSmmdH4KKebVBMg7zOG7AOC6bXTCoh1nzXt\n\tXT9TRcjDCR8Fxnx1Nrj5IBecg2yOjxaEDkq2PZEXLpvbi3k20Gik0kHR32Ceh3xEdU\n\tYM+5MIhK7XR3iwLKmv4ghlsER3r5hHXsS9ArTvHakCQEobLNp89PCFS9a/+JnRytcl\n\tNzUhqip0os7lA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1655416248;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding;\n\tbh=dYygmMS+INX72Q6FKkLNuh8UB1FFiQwARL9yH7EzZ2g=;\n\tb=YL61fQ2c/Wa+frheW4ujiFNzkblZ3pkzSDBYs85AMWCOjOSvVIuamGlk+6EhuM5e/JybqZ\n\tSM+ECx8/nriCAg/d+WmbXf0UDJAq7jPmvfEm6tmdRQOz0OGu+OdcdVggw/ugWISQKk2j7G\n\tQv2q2PHS5eW8vZ4Di87iitYHJe8JTCQ="],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"YL61fQ2c\"; \n\tdkim-atps=neutral","relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"],"X-MC-Unique":"dl5OChZ1N_idHkZN9Z_6IA-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=dYygmMS+INX72Q6FKkLNuh8UB1FFiQwARL9yH7EzZ2g=;\n\tb=4JMtYHWW6qQ3ghthN25V5N+Hn+HRm1e6TcEutvFJYOXNpGUePJvQWLHWA4mbLLXgGn\n\tg5TB2/J/BkTYdJ4SzzSf22T+pdqyd+rMNLJTW/9mU8/K74uQQPa1CE0zUR9MxpqH6yTa\n\tVt3WPCURcf7uVUpDqNgEpNBgXTsrDCgSauEabwNnYAfuxNQU6/D/iLQH7928etAwrrZ0\n\tA1Jp9IZI05WcbfcYKm55/8AiwCYXERHOXP2BVv11fPUmS1e1VdQOgifyIzdsTRraaB3X\n\t/IMdZnLvE3cziG/aB4EmxzatNLCCbJIz1ZrUupyqmrdSKxiw+Ye+SnXEj7TfTVcBncKM\n\tqXmA==","X-Gm-Message-State":"AJIora8Q7xw+DZ22EqyzeNGzCUcd5vooAgy3jrxMRob/QB5RpZmZv0ku\n\t6gRiSOUldFKY752u+KjFkCCiEeKq+Xg2d9qyRUopfVb+JoSzVLs52GDn3/76FfL/HBkQjWSRaGM\n\tSWLkAJs1DDdeQW6EjnE6vpBXeGfAfNMsHbLClbUBqiQHgH9TJDBRBMYCQGLnemxh8eOlKGKcjBc\n\tEM9BVvswcg","X-Received":["by 2002:a5d:6887:0:b0:21a:33c1:eea7 with SMTP id\n\th7-20020a5d6887000000b0021a33c1eea7mr5039150wru.49.1655416243571; \n\tThu, 16 Jun 2022 14:50:43 -0700 (PDT)","by 2002:a5d:6887:0:b0:21a:33c1:eea7 with SMTP id\n\th7-20020a5d6887000000b0021a33c1eea7mr5039131wru.49.1655416243299; \n\tThu, 16 Jun 2022 14:50:43 -0700 (PDT)"],"X-Google-Smtp-Source":"AGRyM1vCr9SS9AWIBuQVmAwczrkP+yBKGxdHDyAQiBqU5Mrz4mY8careDAyEkID4E/INeN5khiKfvA==","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 16 Jun 2022 22:45:52 +0100","Message-Id":"<20220616214551.43630-1-ecurtin@redhat.com>","X-Mailer":"git-send-email 2.35.3","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","Subject":"[libcamera-devel] [PATCH v5] cam: drm: Support /dev/dri cards other\n\tthan 0","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>","From":"Eric Curtin via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Eric Curtin <ecurtin@redhat.com>","Cc":"Ian Mullins <imullins@redhat.com>,\n\tJavier Martinez Canillas <fmartine@redhat.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Existing code is hardcoded to card0. Since recent fedora upgrades, we\nhave noticed on more than one machine that card1 is present as the\nlowest numbered device, could theoretically be higher. This technique\ntries every file starting with card and continue only when we have\nsuccessfully opened one. These devices with card1 as the lowest device\nwere simply failing when they do not see a /dev/dri/card0 file present.\n\nReported-by: Ian Mullins <imullins@redhat.com>\nTested-by: Ian Mullins <imullins@redhat.com>\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\n---\nChanges in v5:\n- Split into openCard function\n- ret initialized to -ENOENT, in case directory is open with no card*\n- Add another string to simplify\n\nChanges in v4:\n- added Tested-by tag\n- std::stringified things\n- changed if conditions to reduce indentations\n- constexpr sizes now don't include null terminator\n- just return -ENOENT if no device was successfully opened.\n\nChanges in v3:\n- switch back to memcpy, strncpy causing false compiler issue\n\nChanges in v2:\n- return if no valid card found, or directory could not be opened etc.\n- memcpy to strncpy for safety\n- only adjust the numerical bytes for each iteration of loop since\n  /dev/dri/card won't change\n- initialize ret to zero\n---\n src/cam/drm.cpp | 62 ++++++++++++++++++++++++++++++++++++-------------\n src/cam/drm.h   |  2 +-\n 2 files changed, 47 insertions(+), 17 deletions(-)","diff":"diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp\nindex 42c5a3b1..39c19aa8 100644\n--- a/src/cam/drm.cpp\n+++ b/src/cam/drm.cpp\n@@ -8,6 +8,7 @@\n #include \"drm.h\"\n \n #include <algorithm>\n+#include <dirent.h>\n #include <errno.h>\n #include <fcntl.h>\n #include <iostream>\n@@ -391,26 +392,55 @@ Device::~Device()\n \t\tdrmClose(fd_);\n }\n \n-int Device::init()\n+int Device::openCard()\n {\n-\tconstexpr size_t NODE_NAME_MAX = sizeof(\"/dev/dri/card255\");\n-\tchar name[NODE_NAME_MAX];\n-\tint ret;\n+\tconst std::string dirName = \"/dev/dri/\";\n+\tint ret = -ENOENT;\n \n \t/*\n-\t * Open the first DRM/KMS device. The libdrm drmOpen*() functions\n-\t * require either a module name or a bus ID, which we don't have, so\n-\t * bypass them. The automatic module loading and device node creation\n-\t * from drmOpen() is of no practical use as any modern system will\n-\t * handle that through udev or an equivalent component.\n-\t */\n-\tsnprintf(name, sizeof(name), \"/dev/dri/card%u\", 0);\n-\tfd_ = open(name, O_RDWR | O_CLOEXEC);\n-\tif (fd_ < 0) {\n+         * Open the first DRM/KMS device beginning with /dev/dri/card. The\n+         * libdrm drmOpen*() functions require either a module name or a bus ID,\n+         * which we don't have, so bypass them. The automatic module loading and\n+         * device node creation from drmOpen() is of no practical use as any\n+         * modern system will handle that through udev or an equivalent\n+         * component.\n+         */\n+\tDIR *folder = opendir(dirName.c_str());\n+\tif (!folder) {\n \t\tret = -errno;\n-\t\tstd::cerr\n-\t\t\t<< \"Failed to open DRM/KMS device \" << name << \": \"\n-\t\t\t<< strerror(-ret) << std::endl;\n+\t\tstd::cerr << \"Failed to open \" << dirName\n+\t\t\t  << \" directory: \" << strerror(-ret) << std::endl;\n+\t\treturn ret;\n+\t}\n+\n+\tfor (struct dirent *res; (res = readdir(folder));) {\n+\t\tif (strncmp(res->d_name, \"card\", 4)) {\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tconst std::string devName = dirName + res->d_name;\n+\t\tfd_ = open(devName.c_str(), O_RDWR | O_CLOEXEC);\n+\t\tif (fd_ >= 0) {\n+\t\t\tret = 0;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tret = -errno;\n+\t\tstd::cerr << \"Failed to open DRM/KMS device \" << devName << \": \"\n+\t\t\t  << strerror(-ret) << std::endl;\n+\t}\n+\n+\tclosedir(folder);\n+\n+\treturn ret;\n+}\n+\n+int Device::init()\n+{\n+\tint ret = openCard();\n+\tif (ret < 0) {\n+\t\tstd::cerr << \"Failed to open any DRM/KMS device: \"\n+\t\t\t  << strerror(-ret) << std::endl;\n \t\treturn ret;\n \t}\n \ndiff --git a/src/cam/drm.h b/src/cam/drm.h\nindex de57e445..1817d053 100644\n--- a/src/cam/drm.h\n+++ b/src/cam/drm.h\n@@ -312,7 +312,7 @@ private:\n \tDevice &operator=(const Device &&) = delete;\n \n \tint getResources();\n-\n+\tint openCard();\n \tvoid drmEvent();\n \tstatic void pageFlipComplete(int fd, unsigned int sequence,\n \t\t\t\t     unsigned int tv_sec, unsigned int tv_usec,\n","prefixes":["libcamera-devel","v5"]}