Show a patch.

GET /api/1.1/patches/398/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 398,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/398/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/398/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20190125225247.16541-1-laurent.pinchart@ideasonboard.com>",
    "date": "2019-01-25T22:52:47",
    "name": "[libcamera-devel,v2] 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=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/398/mbox/",
    "series": [
        {
            "id": 137,
            "url": "https://patchwork.libcamera.org/api/1.1/series/137/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=137",
            "date": "2019-01-25T22:52:47",
            "name": "[libcamera-devel,v2] libcamera: media_device: Fallback to legacy ioctls on older kernels",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/137/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/398/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/398/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 4751F60B1B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 23:52:52 +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 C7EA7325\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 23:52:51 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1548456771;\n\tbh=kjYeYYdCy0gLiwmwyCDFzVmNR5LeGEHW7vAbWmvDYz8=;\n\th=From:To:Subject:Date:From;\n\tb=ZkFGwohMM7OF29ev8Hr5rulLXl/gEV2L0NVdB3OBV4ENK4CWyphtXWbWmFA9jw+7U\n\tWIDdIeD1v4hia56akvS+CsKfXh07b0bvGjjJMKo1OFWCviqocQ3VSoRY3ZyCZF/Cd3\n\tX2PpxCJNxwCrXm/qhRz2lnvVR8WbvLNZ83tRLBWQ=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 26 Jan 2019 00:52:47 +0200",
        "Message-Id": "<20190125225247.16541-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 v2] 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 22:52:52 -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---\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",
        "v2"
    ]
}