Patch Detail
Show a patch.
GET /api/patches/399/?format=api
{ "id": 399, "url": "https://patchwork.libcamera.org/api/patches/399/?format=api", "web_url": "https://patchwork.libcamera.org/patch/399/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190125230942.17521-1-laurent.pinchart@ideasonboard.com>", "date": "2019-01-25T23:09:42", "name": "[libcamera-devel,v3] libcamera: media_device: Fallback to legacy ioctls on older kernels", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "2f24494cdb55a86c1985dd8acf996c21291f0f2f", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/399/mbox/", "series": [ { "id": 138, "url": "https://patchwork.libcamera.org/api/series/138/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=138", "date": "2019-01-25T23:09:42", "name": "[libcamera-devel,v3] libcamera: media_device: Fallback to legacy ioctls on older kernels", "version": 3, "mbox": "https://patchwork.libcamera.org/series/138/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/399/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/399/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 7A59860B1B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 26 Jan 2019 00:09:47 +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 11660325\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 26 Jan 2019 00:09:47 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1548457787;\n\tbh=QGnQMcKT1mEKnzAg9c88RrdT96SmHpyQlnjBjWea/UI=;\n\th=From:To:Subject:Date:From;\n\tb=Y6SoZI2wo8vIGP+ZGHCHavLjNQsDlsP0rLDvogqf50CMw9pP/fxnWPSLIUsxlH6xj\n\tPV4fDijGnDudx/eMzWWfw+c+zTKExvcEvp+Zdpl1rV/lThAcv1J4XPnuFyKJMTcjdS\n\tSKCK6l+LOhA9BKe3F2IJz9Mk5JcCzypFYfAAyf6w=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 26 Jan 2019 01:09:42 +0200", "Message-Id": "<20190125230942.17521-1-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.19.2", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3] 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 23:09:47 -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>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\nChanges since v1:\n\n- Move MEDIA_V2_ENTITY_HAS_FLAGS() test to populateEntities()\n- Rename fixupEntity() to fixupEntityFlag()\n---\n src/libcamera/include/media_device.h | 3 ++\n src/libcamera/media_device.cpp | 41 ++++++++++++++++++++++++++--\n 2 files changed, 41 insertions(+), 3 deletions(-)", "diff": "diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 27a2b46a4392..9f038093b2b2 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 fixupEntityFlags(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..a4995b996601 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,29 @@ 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\t/*\n+\t\t * The media_v2_entity structure was missing the flag field before\n+\t\t * v4.19.\n+\t\t */\n+\t\tif (!MEDIA_V2_ENTITY_HAS_FLAGS(version_))\n+\t\t\tfixupEntityFlags(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 +667,31 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology)\n \treturn true;\n }\n \n+/**\n+ * \\brief Fixup entity flags using legacy API\n+ * \\param[in] entity The entity\n+ *\n+ * This function is used as a fallback to query entity flags using the legacy\n+ * MEDIA_IOC_ENUM_ENTITIES ioctl when running on a kernel version that doesn't\n+ * provide them through the MEDIA_IOC_G_TOPOLOGY ioctl.\n+ */\n+void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)\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", "v3" ] }