Patch Detail
Show a patch.
GET /api/patches/18922/?format=api
{ "id": 18922, "url": "https://patchwork.libcamera.org/api/patches/18922/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18922/", "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": "<20230802065449.2904457-3-chenghaoyang@chromium.org>", "date": "2023-08-02T06:51:44", "name": "[libcamera-devel,v7,2/3] libcamera: Add UdmaHeap if DmaHeap is not valid", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6ade8b8c9eb8b9b51507e909a5c17a945af099f9", "submitter": { "id": 117, "url": "https://patchwork.libcamera.org/api/people/117/?format=api", "name": "Cheng-Hao Yang", "email": "chenghaoyang@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18922/mbox/", "series": [ { "id": 4000, "url": "https://patchwork.libcamera.org/api/series/4000/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4000", "date": "2023-08-02T06:51:42", "name": "Add HeapAllocator", "version": 7, "mbox": "https://patchwork.libcamera.org/series/4000/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18922/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18922/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 C429FBDCBF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 2 Aug 2023 06:55:05 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 73689627EB;\n\tWed, 2 Aug 2023 08:55:05 +0200 (CEST)", "from mail-pf1-x436.google.com (mail-pf1-x436.google.com\n\t[IPv6:2607:f8b0:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 856AB627EE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 2 Aug 2023 08:55:01 +0200 (CEST)", "by mail-pf1-x436.google.com with SMTP id\n\td2e1a72fcca58-686ba29ccb1so410645b3a.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 01 Aug 2023 23:55:01 -0700 (PDT)", "from chenghaoyang-low.c.googlers.com.com\n\t(27.247.221.35.bc.googleusercontent.com. [35.221.247.27])\n\tby smtp.gmail.com with ESMTPSA id\n\td14-20020aa7868e000000b0065980654baasm9142154pfo.130.2023.08.01.23.54.58\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 01 Aug 2023 23:54:59 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1690959305;\n\tbh=vqo7+QhOPbQhtAzNZWEISoB9rGYX5iYooUeCBKzyYQM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=jN6N73YrgouZJ4pURwJWv8rEPfUq0aS1PZwlRmDA5eV5WgrzGTNOK9qKdIo4Zmkmi\n\t/DIfWWC8K9snJcMKCZTpFDI7b3l1wvG/WeaA+GjLC4aoRPT903TGiacn4VWodxR6U2\n\tUAiXRBHj4Cz2wJFr/JjXDs8aBUO67Ikf/yXrRmn7hvjarkXGzuxYyDAr4FYnfmNl53\n\t1httRxm470tuXZ5igu2qa/q4SuDRJhkwNiq5Lbg3l8xLXSsc/4PM4nqBJf08twiRGr\n\taXs7UYpo0LCBvc3O5BSdYFAU1RmETbMpXRtvm6jJAK/eWgmB650eoGw1vtCCjZXAMi\n\thHjKBrwRCjjlg==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1690959299; x=1691564099;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=of3V24Swk733umJsa+sZgpEEgBy/JwWUEV6egzUd+Dc=;\n\tb=YDS/NHiVK0uVbk7YW+LnucSteEdZJa+RShDttUQT2dO9q/1D2ySumgKfuKSJN7gtAz\n\tE/zLlc3V3nZHGqCTCSCk9qD0c4lon0RX8e8vUIrWBAE19eX/R9v3yDMREoIYa51dtEYs\n\tbEThX44BKrNHrUxA9VkJXLbE6N4ezH74YIoZ8=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"YDS/NHiV\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1690959299; x=1691564099;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=of3V24Swk733umJsa+sZgpEEgBy/JwWUEV6egzUd+Dc=;\n\tb=PXUwPrwcb9EynKMtTRQZ3BqbgstkOytvPeZAeDoK4gu55QIT5Yawt+BqW/3tftZ/IN\n\tcT7RezMzyw978mKYzNBxLK/Ef24BEhhczSg6B86WGdBvy2H+d2yarogNkPQUpFtjj9De\n\t78oRr+9sBZ3WSsVFkTWEsCCV7ujns4cerLH8GSEOxUDvWd8Tqx/+gpsJJG0+rtpr2x2T\n\tQQnd80t3/KoDYtZCyeLamI9gMIcvXhJVDvOdDHC9KL5HiMEtivlWgaG6movNTcX+dijC\n\tu5O7vhmT7BdWQPDA2fopYrdwCx0bumAJ22ElSRC72BRBlD6uz+fN0921/ZQv5EGXLxGt\n\t2UFg==", "X-Gm-Message-State": "ABy/qLZE4qcZb1HB7TQqp4JvNbjHBy110cu3DK1etpqiQ7t8eTLWA9pJ\n\tQpglo9MarAdYIIN1p9DqoEW2HjRWjLQcJy4X72E=", "X-Google-Smtp-Source": "APBJJlHDuoDsIoW7ncjvKQV4ldP9pVHlqq+5Yt6U8p5kIzXOc4rkQlro/cZVRCc7tjL4Eomv+0epLg==", "X-Received": "by 2002:a05:6a00:2e8d:b0:667:d0ff:6a0f with SMTP id\n\tfd13-20020a056a002e8d00b00667d0ff6a0fmr18247228pfb.5.1690959299430; \n\tTue, 01 Aug 2023 23:54:59 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 2 Aug 2023 06:51:44 +0000", "Message-ID": "<20230802065449.2904457-3-chenghaoyang@chromium.org>", "X-Mailer": "git-send-email 2.41.0.585.gd2178a4bd4-goog", "In-Reply-To": "<20230802065449.2904457-1-chenghaoyang@chromium.org>", "References": "<20230802065449.2904457-1-chenghaoyang@chromium.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v7 2/3] libcamera: Add UdmaHeap if DmaHeap\n\tis not valid", "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": "Harvey Yang via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Harvey Yang <chenghaoyang@chromium.org>", "Cc": "Harvey Yang <chenghaoyang@chromium.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "If DmaHeap is not valid, fall back to UdmaHeap to allocate buffers.\n\nSigned-off-by: Harvey Yang <chenghaoyang@chromium.org>\n---\n src/libcamera/heap_allocator.cpp | 105 +++++++++++++++++++++++++++++++\n 1 file changed, 105 insertions(+)", "diff": "diff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp\nindex 2a825d93..1caa1469 100644\n--- a/src/libcamera/heap_allocator.cpp\n+++ b/src/libcamera/heap_allocator.cpp\n@@ -11,10 +11,14 @@\n #include <array>\n #include <fcntl.h>\n #include <sys/ioctl.h>\n+#include <sys/mman.h>\n+#include <sys/stat.h>\n+#include <sys/types.h>\n #include <unistd.h>\n \n #include <linux/dma-buf.h>\n #include <linux/dma-heap.h>\n+#include <linux/udmabuf.h>\n \n #include <libcamera/base/log.h>\n \n@@ -84,6 +88,18 @@ public:\n \tUniqueFD alloc(const char *name, std::size_t size) override;\n };\n \n+/**\n+ * \\class UdmaHeap\n+ * \\brief The derived class of Heap with Udmabuf implementation\n+ */\n+class UdmaHeap : public Heap\n+{\n+public:\n+\tUdmaHeap();\n+\t~UdmaHeap();\n+\tUniqueFD alloc(const char *name, std::size_t size) override;\n+};\n+\n /**\n * \\brief Construct a DmaHeap with a list of |dmaHeapNames|\n */\n@@ -98,6 +114,7 @@ DmaHeap::DmaHeap()\n \t\t\tcontinue;\n \t\t}\n \n+\t\tLOG(HeapAllocator, Info) << \"Using DmaHeap allocator\";\n \t\thandle_ = UniqueFD(ret);\n \t\tbreak;\n \t}\n@@ -138,6 +155,92 @@ UniqueFD DmaHeap::alloc(const char *name, std::size_t size)\n \treturn allocFd;\n }\n \n+/**\n+ * \\brief Construct a UdmaHeap with `/udev/udmabuf`.\n+ */\n+UdmaHeap::UdmaHeap()\n+{\n+\tint ret = ::open(\"/dev/udmabuf\", O_RDWR);\n+\tif (ret < 0) {\n+\t\tret = errno;\n+\t\tLOG(HeapAllocator, Error)\n+\t\t\t<< \"UdmaHeap failed to open allocator: \" << strerror(ret);\n+\t\treturn;\n+\t}\n+\n+\tLOG(HeapAllocator, Info) << \"Using UdmaHeap allocator\";\n+\thandle_ = UniqueFD(ret);\n+}\n+\n+UdmaHeap::~UdmaHeap() = default;\n+\n+UniqueFD UdmaHeap::alloc(const char *name, std::size_t size)\n+{\n+\tint ret = memfd_create(name, MFD_ALLOW_SEALING);\n+\tif (ret < 0) {\n+\t\tret = errno;\n+\t\tLOG(HeapAllocator, Error)\n+\t\t\t<< \"UdmaHeap failed to allocate memfd storage: \"\n+\t\t\t<< strerror(ret);\n+\t\treturn {};\n+\t}\n+\n+\tUniqueFD memfd(ret);\n+\n+\tret = ftruncate(memfd.get(), size);\n+\tif (ret < 0) {\n+\t\tret = errno;\n+\t\tLOG(HeapAllocator, Error)\n+\t\t\t<< \"UdmaHeap failed to set memfd size: \" << strerror(ret);\n+\t\treturn {};\n+\t}\n+\n+\t/* UdmaHeap Buffers *must* have the F_SEAL_SHRINK seal */\n+\tret = fcntl(memfd.get(), F_ADD_SEALS, F_SEAL_SHRINK);\n+\tif (ret < 0) {\n+\t\tret = errno;\n+\t\tLOG(HeapAllocator, Error)\n+\t\t\t<< \"UdmaHeap failed to seal the memfd: \" << strerror(ret);\n+\t\treturn {};\n+\t}\n+\n+\tstruct udmabuf_create create;\n+\n+\tcreate.memfd = memfd.get();\n+\tcreate.flags = UDMABUF_FLAGS_CLOEXEC;\n+\tcreate.offset = 0;\n+\tcreate.size = size;\n+\n+\tret = ::ioctl(handle_.get(), UDMABUF_CREATE, &create);\n+\tif (ret < 0) {\n+\t\tret = errno;\n+\t\tLOG(HeapAllocator, Error)\n+\t\t\t<< \"UdmaHeap failed to allocate \" << size << \" bytes: \"\n+\t\t\t<< strerror(ret);\n+\t\treturn {};\n+\t}\n+\n+\tif (create.size < size) {\n+\t\tLOG(HeapAllocator, Error)\n+\t\t\t<< \"UdmaHeap allocated \" << create.size << \" bytes instead of \"\n+\t\t\t<< size << \" bytes\";\n+\t\treturn {};\n+\t}\n+\n+\tif (create.size != size)\n+\t\tLOG(HeapAllocator, Warning)\n+\t\t\t<< \"UdmaHeap allocated \" << create.size << \" bytes, \"\n+\t\t\t<< \"which is greater than requested : \" << size << \" bytes\";\n+\n+\t/* Fail if not suitable, the allocation will be free'd by UniqueFD */\n+\tLOG(HeapAllocator, Debug) << \"UdmaHeap allocated \" << create.size << \" bytes\";\n+\n+\t/* The underlying memfd is kept as as a reference in the kernel */\n+\tUniqueFD uDma(ret);\n+\n+\treturn uDma;\n+}\n+\n /**\n * \\class HeapAllocator\n * \\brief The allocator that allocates heap buffers\n@@ -160,6 +263,8 @@ UniqueFD DmaHeap::alloc(const char *name, std::size_t size)\n HeapAllocator::HeapAllocator()\n {\n \theap_ = std::make_unique<DmaHeap>();\n+\tif (!isValid())\n+\t\theap_ = std::make_unique<UdmaHeap>();\n }\n \n HeapAllocator::~HeapAllocator() = default;\n", "prefixes": [ "libcamera-devel", "v7", "2/3" ] }