Patch Detail
Show a patch.
GET /api/1.1/patches/18637/?format=api
{ "id": 18637, "url": "https://patchwork.libcamera.org/api/1.1/patches/18637/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18637/", "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": "<20230516080459.711347-3-chenghaoyang@google.com>", "date": "2023-05-16T08:03:18", "name": "[libcamera-devel,v5,2/3] libcamera: Add UdmaHeap if DmaHeap is not valid", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "a66d5a3b5a272c9515d110ea72a5832a3668204b", "submitter": { "id": 117, "url": "https://patchwork.libcamera.org/api/1.1/people/117/?format=api", "name": "Cheng-Hao Yang", "email": "chenghaoyang@chromium.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18637/mbox/", "series": [ { "id": 3879, "url": "https://patchwork.libcamera.org/api/1.1/series/3879/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3879", "date": "2023-05-16T08:03:16", "name": "Add HeapAllocator", "version": 5, "mbox": "https://patchwork.libcamera.org/series/3879/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18637/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18637/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 F3461C3284\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 16 May 2023 08:05:11 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3260162865;\n\tTue, 16 May 2023 10:05:11 +0200 (CEST)", "from mail-pg1-x536.google.com (mail-pg1-x536.google.com\n\t[IPv6:2607:f8b0:4864:20::536])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F08E627DC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 May 2023 10:05:09 +0200 (CEST)", "by mail-pg1-x536.google.com with SMTP id\n\t41be03b00d2f7-52cb78647ecso8702367a12.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 16 May 2023 01:05:09 -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\tkd14-20020a17090b348e00b00252df595c01sm996881pjb.52.2023.05.16.01.05.06\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 16 May 2023 01:05:07 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684224311;\n\tbh=hp6AasDtyYXfBbyBlBaboF2P3cxvD6pPwbnACzMoONU=;\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=QUqjfzIHgiRWGX62z6r7zjUCa4ifdR0GKYwcB8KGQ87QU+uL7BukkXcA6oguHNUpS\n\t3xcswOw3h2ymfKJHav6fTRN5ed7l/h/eYiX9vUJYzzj7Icl8EeuiprV9le35owO2+F\n\tfSUVgJHmHFGfWbfTyg4dND18bhTxwF7ckAFZVS7j6v/PBWf0orM8bYmjZXYWtHASbI\n\tpbDOfk8Mu4qPv/Vz9hi0g9Pp5vMtGWmP5VToeWZOCu+hfLTouq8mjratRYz5NLlLdX\n\tNCH/RmX6EFO+OXIrk8qm/bKdYLqwfrAV9QwNJ8lQ1iJtQ7Jt391gXicJOD7/SyTFi3\n\tX/UP7gNghNbdQ==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1684224307; x=1686816307;\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=3fBg1wkczRxbLUVCBAHdLdU8OPNKRAjOXjhoze11edA=;\n\tb=lNy+pn7N9zfLZEN701Mqna66VxB3bIkAUOd1BkOMiQex2nmlew3lRrmQfLjDz2R6iS\n\tErimenBtee8ZhMrNOXLoyY9jH9PnEPiNLFtUWzqS+9HloKaJ2aSW3YGcp13V9QEKEjlu\n\tew1YbII5EYd9fSNh+37TbI5bdz2vxIPQLOLfY=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"lNy+pn7N\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1684224307; x=1686816307;\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=3fBg1wkczRxbLUVCBAHdLdU8OPNKRAjOXjhoze11edA=;\n\tb=DBRvrlqC6HyMEA6T/Ml9BSu+o4z9Gws+RPQENNvHSQraHKUYpYGm3ixMiiUkTscsZ3\n\tGNd8CuAqAN2dY7Zetf+t5HtqaJXvZcKl90aSNmal82DivdWMG1zEId3AwQcFG+p/kXAy\n\tb8MVWXp/e6niR9JjTnTv6PWxRkNt46leRa+fXWsG7mYIgRth30wgfAACDIME3S3OO/Od\n\tOFNTB1aPiNd6zTRxSQjrxSrflaFguSqgI3CQABr2JyvJqQFQ9KYrZ91FEKCq3JmvnS/1\n\tigkT6sGWGM4sZ+4pIYYom9MUb1aMLjGj4D27GrwyD3D8scu5H+vuSpvWy7u+evzqxC2U\n\tevXg==", "X-Gm-Message-State": "AC+VfDxpIarxORDQ3MOvbgu5ZCQ/1VWzS+0QsNw/LT8jbVpzGvd+5S3o\n\tOk5dZZd2RZwdAIPgObPnYkioEDzXCUDMqb/3m3MdCg==", "X-Google-Smtp-Source": "ACHHUZ6Yc11jgLnWuruTCJojhSH2lrQwguDW6Bn5NnOgwMMjK9LqunMXye3FZNdaYGd62XVSM93PgQ==", "X-Received": "by 2002:a17:90a:880b:b0:250:484e:355f with SMTP id\n\ts11-20020a17090a880b00b00250484e355fmr32134459pjn.49.1684224307625; \n\tTue, 16 May 2023 01:05:07 -0700 (PDT)", "X-Google-Original-From": "Harvey Yang <chenghaoyang@google.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 16 May 2023 08:03:18 +0000", "Message-ID": "<20230516080459.711347-3-chenghaoyang@google.com>", "X-Mailer": "git-send-email 2.40.1.606.ga4b1b128d6-goog", "In-Reply-To": "<20230516080459.711347-1-chenghaoyang@google.com>", "References": "<20230516080459.711347-1-chenghaoyang@google.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 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": "Cheng-Hao Yang <chenghaoyang@chromium.org>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Cheng-Hao Yang <chenghaoyang@chromium.org>\n\nIf 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 | 106 +++++++++++++++++++++++++++++++\n 1 file changed, 106 insertions(+)", "diff": "diff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp\nindex e9476de5..682a7e01 100644\n--- a/src/libcamera/heap_allocator.cpp\n+++ b/src/libcamera/heap_allocator.cpp\n@@ -10,10 +10,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@@ -52,6 +56,14 @@ public:\n \tUniqueFD alloc(const char *name, std::size_t size) override;\n };\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 DmaHeap::DmaHeap()\n {\n \tfor (const char *name : dmaHeapNames) {\n@@ -103,9 +115,103 @@ UniqueFD DmaHeap::alloc(const char *name, std::size_t size)\n \treturn allocFd;\n }\n \n+UdmaHeap::UdmaHeap()\n+{\n+\tint ret = ::open(\"/dev/udmabuf\", O_RDWR, 0);\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+\n+\t\tif (ret == EACCES) {\n+\t\t\tLOG(HeapAllocator, Info)\n+\t\t\t\t<< \"UdmaHeap: Consider making /dev/udmabuf accessible by the video group\";\n+\t\t\tLOG(HeapAllocator, Info)\n+\t\t\t\t<< \"UdmaHeap: Alternatively, add your user to the kvm group.\";\n+\t\t}\n+\n+\t} else {\n+\t\thandle_ = UniqueFD(ret);\n+\t}\n+}\n+\n+UdmaHeap::~UdmaHeap() = default;\n+\n+UniqueFD UdmaHeap::alloc(const char *name, std::size_t size)\n+{\n+\tif (!isValid()) {\n+\t\tLOG(HeapAllocator, Fatal) << \"UdmaHeap: Allocation attempted without allocator\" << name;\n+\t\treturn {};\n+\t}\n+\n+\tint ret;\n+\n+\tret = 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+\t/* The underlying memfd is kept as as a reference in the kernel */\n+\tUniqueFD uDma(ret);\n+\n+\tif (create.size != size)\n+\t\tLOG(HeapAllocator, Warning)\n+\t\t\t<< \"UdmaHeap allocated \" << create.size << \" bytes instead of \"\n+\t\t\t<< size << \" bytes\";\n+\n+\t/* Fail if not suitable, the allocation will be free'd by UniqueFD */\n+\tif (create.size < size)\n+\t\treturn {};\n+\n+\tLOG(HeapAllocator, Debug) << \"UdmaHeap allocated \" << create.size << \" bytes\";\n+\n+\treturn uDma;\n+}\n+\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", "v5", "2/3" ] }