Show a patch.

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

{
    "id": 18644,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/18644/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/18644/",
    "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": "<20230522083546.2465448-3-chenghaoyang@google.com>",
    "date": "2023-05-22T08:35:07",
    "name": "[libcamera-devel,v6,2/3] libcamera: Add UdmaHeap if DmaHeap is not valid",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "0ad7391e647d62c64dd3da52fed264ae8a995ad6",
    "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/18644/mbox/",
    "series": [
        {
            "id": 3883,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3883/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3883",
            "date": "2023-05-22T08:35:05",
            "name": "Add HeapAllocator",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/3883/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/18644/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/18644/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 726F4C31E9\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 May 2023 08:35:58 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5447D627DC;\n\tMon, 22 May 2023 10:35:57 +0200 (CEST)",
            "from mail-pl1-x630.google.com (mail-pl1-x630.google.com\n\t[IPv6:2607:f8b0:4864:20::630])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 49FF4627DC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 10:35:55 +0200 (CEST)",
            "by mail-pl1-x630.google.com with SMTP id\n\td9443c01a7336-1afbc02c602so2137355ad.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 May 2023 01:35:55 -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\th1-20020a170902f54100b001a980a23804sm4321253plf.4.2023.05.22.01.35.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 22 May 2023 01:35:53 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1684744557;\n\tbh=zUzbFMtsdXvvxDXM+ui/p1b/35MGxQs9X2/3noCu2wo=;\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=htbd1cybnM7nXEc6S4gg+3mP4G8v9wHyfHYecwPorr3fwACx71+TzQCDTLrudLj8G\n\trhqQUe/2j7WpPrw8ub8aT5W0elOihB2rQEc13qIRklmlQkSjORmN22WlGjML5dw+Oy\n\tnjX5aNEpriJmMOqGK2BuelCbU0j/gKa0043FGmDBTihrIQGyzGSMDmT6/DXz17IuR7\n\tEfX4+cZ0gNJ0YXxgF546uvYI9LUrAfV2CEGxjeC2RwDNKztdnxDPqLHxG7Jtylq438\n\t6AVMZhj/Ym5ycem/DTdBLiEropHrr2QaLVwn00RZRAzA8sqVCWVx5t17EXHZmvhlOO\n\tdSEzKdfvSDucA==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google; t=1684744553; x=1687336553;\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=JouvgO2fyVzHl6E/gHYv6bTHugQHpSDy2GAoLY5wuro=;\n\tb=OGa94fnpm256BRVgFyBkWOWz1KziCko/FZNW5CCJ0XGTaWWTGAeDZuvHkhvH6SvlQQ\n\tLQjwor9P3/0Kyf1I7Esw8ym+S7o063GJFEc6ITxYxCEgY4O5JMxDXBY1njxl9PWAzPod\n\tLZHQ41E5b5UOskxG89MtoIn8M5Zs45F0oiIrU="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"OGa94fnp\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1684744553; x=1687336553;\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=JouvgO2fyVzHl6E/gHYv6bTHugQHpSDy2GAoLY5wuro=;\n\tb=QUrLiOk+7QFEAqPn471u12Dskvr9S/lqbw9giMLRerBgwwleaqA8OGSthBb4ZjJ266\n\t6eG7+VH1tQcieQAIFzQ3H6rFKW6ZHWr4qNNTqDL7XJPp/jM+DJaS1e9vB4gSRgGoKwcp\n\tkDWvNs7pBQw4LdLCbpH6XIeWLW8NW+v+uQFOy/mmUfYH9+ir7IHa9CVQZPX/AGUZgcy5\n\tqrx/VGdP8Id8i+Gv5sLI8Kw5HrJyJYKd1Kaqy6Zisc4s2PHs3QXaZbixj6BD99o3/lH4\n\tX5ptRPCcpcUdLkNWRhyI8PNUjZaIoiC7ieaWxtEh6ZHehzfuI/aGTT38TQrzWKsCs44T\n\tvBNg==",
        "X-Gm-Message-State": "AC+VfDxSYKCZuiXYLh8MA+5lCq4QUgLKOSe0yxO4Ltk/PFHJJ0zMe1Sy\n\twRGvQdEKo/TMTMAqswNwV4+9n9Da1Y54rngYiPo=",
        "X-Google-Smtp-Source": "ACHHUZ6d9Xl3FgOKz4KqrP+j0vdF3zSqKxQyoPasAB85dR9rzVxXCRGNKto9RCln80d9qwkuRykO9Q==",
        "X-Received": "by 2002:a17:903:2343:b0:1ae:35b8:d5ae with SMTP id\n\tc3-20020a170903234300b001ae35b8d5aemr11504092plh.19.1684744553616; \n\tMon, 22 May 2023 01:35:53 -0700 (PDT)",
        "X-Google-Original-From": "Harvey Yang <chenghaoyang@google.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 22 May 2023 08:35:07 +0000",
        "Message-ID": "<20230522083546.2465448-3-chenghaoyang@google.com>",
        "X-Mailer": "git-send-email 2.40.1.698.g37aff9b760-goog",
        "In-Reply-To": "<20230522083546.2465448-1-chenghaoyang@google.com>",
        "References": "<20230522083546.2465448-1-chenghaoyang@google.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v6 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 | 100 +++++++++++++++++++++++++++++++\n 1 file changed, 100 insertions(+)",
    "diff": "diff --git a/src/libcamera/heap_allocator.cpp b/src/libcamera/heap_allocator.cpp\nindex 69f65062..8f99f590 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@@ -54,6 +58,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@@ -65,6 +77,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@@ -105,9 +118,96 @@ 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+\t} else {\n+\t\tLOG(HeapAllocator, Info) << \"Using UdmaHeap allocator\";\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",
        "v6",
        "2/3"
    ]
}