[{"id":612,"web_url":"https://patchwork.libcamera.org/comment/612/","msgid":"<20190125223926.GO4127@bigcity.dyn.berto.se>","date":"2019-01-25T22:39:26","subject":"Re: [libcamera-devel] [PATCH] libcamera: media_device: Fallback to\n\tlegacy ioctls on older kernels","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your patch.\n\nOn 2019-01-25 23:37:03 +0200, Laurent Pinchart wrote:\n> Prior to kernel v4.19, the MEDIA_IOC_G_TOPOLOGY ioctl didn't expose\n> entity flags. Fallback to calling MEDIA_IOC_ENUM_ENTITIES for each\n> entity to retrieve the flags in that case.\n> \n> Signed-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(-)\n> \n> diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\n> index 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);\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 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\nI would move the MEDIA_V2_ENTITY_HAS_FLAGS() check here so it's clear \nwhy the entity needs to be fixed-up. Also bike shedding on the name, \nmaybe fixupEntityFlags() ? With the check and with or without the name \nchange,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\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> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x141.google.com (mail-lf1-x141.google.com\n\t[IPv6:2a00:1450:4864:20::141])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E1B4560C65\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 23:39:44 +0100 (CET)","by mail-lf1-x141.google.com with SMTP id c16so8050317lfj.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 25 Jan 2019 14:39:44 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tk21-v6sm1698536ljc.15.2019.01.25.14.39.27\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tFri, 25 Jan 2019 14:39:27 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=o0bC8bY6S+RCLjEl5qXbcQCDtZEnVmum2ONgahyevQA=;\n\tb=OVCw9cDgQMzCPAw4+WNRNrQShNem1FqJhAT07gtbimYK+GLQopWlngyAF/efUSppOa\n\t/yeg0VlocSWcZrjVw9jBJCjGrLbZkk3apHIK8Df92c1l7SAyxH8g8oEaUPkJ8qrqEoI1\n\t0OiEFAYCLYtMSr5t0VsAtimG+yHU1unjSYPVfhlqXvcnXM0dqVa1yk40lMWDNLpZMGoi\n\tanrYJjaj/c9WRWfQVmN7bOqbT3J7mqM8oeHY5gLdC9Z/HXL5Wxpwt3RzH06aVLuoxTrw\n\t3SHtotD/YujT8hY6YqR6FnkAtUmIXlKwzW6Twhpg7vde0fpksLS+xXCgtEBmoWVyGvRa\n\t21/g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=o0bC8bY6S+RCLjEl5qXbcQCDtZEnVmum2ONgahyevQA=;\n\tb=rBzz6IwZwuAQCllLp3RyQ6PoABo0TX5JHi7jSMnGDVBOK2LOnZN6RofJFz8xYMZBBP\n\tURZexvX/KvGkVdyqo4w5MXODwrqAv8ay8fyth66O5wD2fwmdq9SqT1lyDZIOg6il48W3\n\ttnzlz1oNwBtHmD6VA9U6qJKqAuK6POPzG8M8AE8pYE1wgv+iTBqgsfEeUIq2umUd2ehB\n\twxbHRC160g+cHsVggLIqZ7F1ho8dqVRLUspnfJwmt0XZP/ssAdBCzlhFjz2Mrifdic+Y\n\toI3L/XOvUNYq6P6xrDLxTe3rnysyzpfbIxhEev+LA1POHY4SHoLxdcrbfcYXA9EtrAXx\n\t8ygA==","X-Gm-Message-State":"AJcUukd5dulKvJGSYCi9BirzhHtzKrrTDywgPPsGms4txD24f3HuInRE\n\taHccLH2lCpSryVkHHZ70+1/Gzg==","X-Google-Smtp-Source":"ALg8bN6fiKNx1/WWea0t2eA/Q9WUVYe/zQAFVZhnqFmus4EbcwM0cZCj1fYqSlClXIuyaoQNzoj2tg==","X-Received":"by 2002:a19:cc46:: with SMTP id\n\tc67mr9938100lfg.145.1548455968864; \n\tFri, 25 Jan 2019 14:39:28 -0800 (PST)","Date":"Fri, 25 Jan 2019 23:39:26 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190125223926.GO4127@bigcity.dyn.berto.se>","References":"<20190125213703.6148-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190125213703.6148-1-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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 22:39:45 -0000"}}]