{"id":397,"url":"https://patchwork.libcamera.org/api/1.1/patches/397/?format=json","web_url":"https://patchwork.libcamera.org/patch/397/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20190125213703.6148-1-laurent.pinchart@ideasonboard.com>","date":"2019-01-25T21:37:03","name":"[libcamera-devel] libcamera: media_device: Fallback to legacy ioctls on older kernels","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c5c1894610d5098c5c7635d388fadedb1c386690","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/397/mbox/","series":[{"id":136,"url":"https://patchwork.libcamera.org/api/1.1/series/136/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=136","date":"2019-01-25T21:37:03","name":"[libcamera-devel] libcamera: media_device: Fallback to legacy ioctls on older kernels","version":1,"mbox":"https://patchwork.libcamera.org/series/136/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/397/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/397/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4BF1960C65\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 22:37:08 +0100 (CET)","from pendragon.lan (unknown\n\t[IPv6:2a02:a03f:3c6a:b300:cba4:9bfe:2eae:a6b4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AAAD9325\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 22:37:07 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1548452227;\n\tbh=Vdo882y4gOlTUPBUFMKvF4nHiy4YqxgJmpGvgJHhw9A=;\n\th=From:To:Subject:Date:From;\n\tb=DojmP4mkxuez/Yqu5RAGFmuQWKZX6Po+kyHz0r5YqGOOCehRfIB6GjbWOFFlE4Rnq\n\t3jj/Pi78N5MipH438979z9lUOsbVfbWY8oroZ0iwQlSlxLaea0So2Pdso6aS8HPRrl\n\tZFN5IIwRuQszmaxPLoGSEy5p6Af566U6Lr7KoZxc=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 25 Jan 2019 23:37:03 +0200","Message-Id":"<20190125213703.6148-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.19.2","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] libcamera: media_device: Fallback to\n\tlegacy ioctls on older kernels","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Fri, 25 Jan 2019 21:37:08 -0000"},"content":"Prior to kernel v4.19, the MEDIA_IOC_G_TOPOLOGY ioctl didn't expose\nentity flags. Fallback to calling MEDIA_IOC_ENUM_ENTITIES for each\nentity to retrieve the flags in that case.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/media_device.h |  3 ++\n src/libcamera/media_device.cpp       | 44 ++++++++++++++++++++++++++--\n 2 files changed, 44 insertions(+), 3 deletions(-)","diff":"diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 27a2b46a4392..31413b9e4605 100644\n--- a/src/libcamera/include/media_device.h\n+++ b/src/libcamera/include/media_device.h\n@@ -56,6 +56,8 @@ private:\n \tstd::string driver_;\n \tstd::string deviceNode_;\n \tstd::string model_;\n+\tunsigned int version_;\n+\n \tint fd_;\n \tbool valid_;\n \tbool acquired_;\n@@ -72,6 +74,7 @@ private:\n \tbool populateEntities(const struct media_v2_topology &topology);\n \tbool populatePads(const struct media_v2_topology &topology);\n \tbool populateLinks(const struct media_v2_topology &topology);\n+\tvoid fixupEntity(struct media_v2_entity *entity);\n \n \tfriend int MediaLink::setEnabled(bool enable);\n \tint setupLink(const MediaLink *link, unsigned int flags);\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex be81bd8c4c23..715ba8263436 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -167,6 +167,7 @@ int MediaDevice::open()\n \n \tdriver_ = info.driver;\n \tmodel_ = info.model;\n+\tversion_ = info.media_version;\n \n \treturn 0;\n }\n@@ -553,20 +554,24 @@ bool MediaDevice::populateEntities(const struct media_v2_topology &topology)\n \t\t\t\t\t\t(topology.ptr_entities);\n \n \tfor (unsigned int i = 0; i < topology.num_entities; ++i) {\n+\t\tstruct media_v2_entity *ent = &mediaEntities[i];\n+\n+\t\tfixupEntity(ent);\n+\n \t\t/*\n \t\t * Find the interface linked to this entity to get the device\n \t\t * node major and minor numbers.\n \t\t */\n \t\tstruct media_v2_interface *iface =\n-\t\t\tfindInterface(topology, mediaEntities[i].id);\n+\t\t\tfindInterface(topology, ent->id);\n \n \t\tMediaEntity *entity;\n \t\tif (iface)\n-\t\t\tentity = new MediaEntity(this, &mediaEntities[i],\n+\t\t\tentity = new MediaEntity(this, ent,\n \t\t\t\t\t\t iface->devnode.major,\n \t\t\t\t\t\t iface->devnode.minor);\n \t\telse\n-\t\t\tentity = new MediaEntity(this, &mediaEntities[i]);\n+\t\t\tentity = new MediaEntity(this, ent);\n \n \t\tif (!addObject(entity)) {\n \t\t\tdelete entity;\n@@ -657,6 +662,39 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n \treturn true;\n }\n \n+/**\n+ * \\brief Fixup entity information using legacy API\n+ * \\param[in] entity The entity\n+ *\n+ * This function is used as a fallback to query entity information using the\n+ * legacy MEDIA_IOC_ENUM_ENTITIES ioctl when running on a kernel version that\n+ * doesn't provide all the information needed through the MEDIA_IOC_G_TOPOLOGY\n+ * ioctl.\n+ */\n+void MediaDevice::fixupEntity(struct media_v2_entity *entity)\n+{\n+\t/*\n+\t * The media_v2_entity structure was missing the flag field before\n+\t * v4.19.\n+\t */\n+\tif (MEDIA_V2_ENTITY_HAS_FLAGS(version_))\n+\t\treturn;\n+\n+\tstruct media_entity_desc desc = {};\n+\tdesc.id = entity->id;\n+\n+\tint ret = ioctl(fd_, MEDIA_IOC_ENUM_ENTITIES, &desc);\n+\tif (ret < 0) {\n+\t\tret = -errno;\n+\t\tLOG(MediaDevice, Debug)\n+\t\t\t<< \"Failed to retrieve information for entity \"\n+\t\t\t<< entity->id << \": \" << strerror(-ret);\n+\t\treturn;\n+\t}\n+\n+\tentity->flags = desc.flags;\n+}\n+\n /**\n  * \\brief Apply \\a flags to a link between two pads\n  * \\param link The link to apply flags to\n","prefixes":["libcamera-devel"]}