Patch Detail
Show a patch.
GET /api/patches/20190/?format=api
{ "id": 20190, "url": "https://patchwork.libcamera.org/api/patches/20190/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20190/", "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": "<20240603111259.54321-2-hdegoede@redhat.com>", "date": "2024-06-03T11:12:57", "name": "[v3,1/3] libcamera: Rename DmaHeap class to DmaBufAllocator", "commit_ref": "447da4a11f06f0d950fe75c20c7bb9f5d5408880", "pull_url": null, "state": "accepted", "archived": false, "hash": "ef990e7e2f99ead308d908888d43378bbc5d47dc", "submitter": { "id": 102, "url": "https://patchwork.libcamera.org/api/people/102/?format=api", "name": "Hans de Goede", "email": "hdegoede@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20190/mbox/", "series": [ { "id": 4352, "url": "https://patchwork.libcamera.org/api/series/4352/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4352", "date": "2024-06-03T11:12:56", "name": "libcamera: dma_buffer_allocator: Add support for using udmabuf to alloc dma-buffers", "version": 3, "mbox": "https://patchwork.libcamera.org/series/4352/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20190/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20190/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 535C9BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 3 Jun 2024 11:13:15 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5D71D634DA;\n\tMon, 3 Jun 2024 13:13:14 +0200 (CEST)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F1AB4634D4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 3 Jun 2024 13:13:09 +0200 (CEST)", "from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-428-6RJuC_jVMyaRpqvjipnvIQ-1;\n\tMon, 03 Jun 2024 07:13:03 -0400", "from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mimecast-mx02.redhat.com (Postfix) with ESMTPS id A85D33806703;\n\tMon, 3 Jun 2024 11:13:02 +0000 (UTC)", "from x1.localdomain.com (unknown [10.39.193.39])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 8F1A72870;\n\tMon, 3 Jun 2024 11:13:01 +0000 (UTC)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"Cv+6fk8N\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1717413188;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=7V+BzSGggSPMDiPg8WVdHhZsPuiD3di1IdKyySBk/CM=;\n\tb=Cv+6fk8NEJC/shTrbzGFznsw0Gb3NLhk/Z6f576mWKLO0ekEwqRDUf+GECbsSVcaSFcZ19\n\t49j8ooHG6TV+87bN/Ci5NbITnfXYBtq9RoHL/glUJRB1qqbAotWv3C+azinx7oMuKaNyZm\n\tZ67Yk1K/3iXJkL3Pg7RdsQWCku+gAco=", "X-MC-Unique": "6RJuC_jVMyaRpqvjipnvIQ-1", "From": "Hans de Goede <hdegoede@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Maxime Ripard <mripard@redhat.com>, Milan Zamazal <mzamazal@redhat.com>, \n\tHans de Goede <hdegoede@redhat.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>", "Subject": "[PATCH v3 1/3] libcamera: Rename DmaHeap class to DmaBufAllocator", "Date": "Mon, 3 Jun 2024 13:12:57 +0200", "Message-ID": "<20240603111259.54321-2-hdegoede@redhat.com>", "In-Reply-To": "<20240603111259.54321-1-hdegoede@redhat.com>", "References": "<20240603111259.54321-1-hdegoede@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.11.54.5", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Users of the DmaHeap class really just want some way to allocate\ndma-buffers from userspace. This can also be done by using /dev/udmabuf\ninstead of using /dev/dma_heap/*.\n\nRename DmaHeap class to DmaBufAllocator in preparation of adding\n/dev/udmabuf support.\n\nAnd update the DmaHeap class docs to match including replacing references\nto \"dma-heap type\" with \"dma-buf provider\".\n\nThis is a pure automated rename on the code ('s/DmaHeap/DmaBufAllocator/')\n+ file renames + doc updates. There are no functional changes.\n\nThe DmaBufAllocator objects in vc4.cpp and software_isp.cpp are left named\ndmaHeap_ to keep the changes to those 2 files to a minimum.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # Lenovo-x13s\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\nChanges in v3:\n- Wrap comments and error message logging at 80 chars\n\nChanges in v2:\n- New patch in v2 of this series\n---\n .../libcamera/internal/dma_buf_allocator.h | 38 ++++\n include/libcamera/internal/dma_heaps.h | 38 ----\n include/libcamera/internal/meson.build | 2 +-\n .../internal/software_isp/software_isp.h | 4 +-\n src/libcamera/dma_buf_allocator.cpp | 162 +++++++++++++++++\n src/libcamera/dma_heaps.cpp | 165 ------------------\n src/libcamera/meson.build | 2 +-\n src/libcamera/pipeline/rpi/vc4/vc4.cpp | 4 +-\n src/libcamera/software_isp/software_isp.cpp | 5 +-\n 9 files changed, 209 insertions(+), 211 deletions(-)\n create mode 100644 include/libcamera/internal/dma_buf_allocator.h\n delete mode 100644 include/libcamera/internal/dma_heaps.h\n create mode 100644 src/libcamera/dma_buf_allocator.cpp\n delete mode 100644 src/libcamera/dma_heaps.cpp", "diff": "diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h\nnew file mode 100644\nindex 00000000..a881042e\n--- /dev/null\n+++ b/include/libcamera/internal/dma_buf_allocator.h\n@@ -0,0 +1,38 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Raspberry Pi Ltd\n+ *\n+ * Helper class for dma-buf allocations.\n+ */\n+\n+#pragma once\n+\n+#include <stddef.h>\n+\n+#include <libcamera/base/flags.h>\n+#include <libcamera/base/unique_fd.h>\n+\n+namespace libcamera {\n+\n+class DmaBufAllocator\n+{\n+public:\n+\tenum class DmaBufAllocatorFlag {\n+\t\tCmaHeap = 1 << 0,\n+\t\tSystemHeap = 1 << 1,\n+\t};\n+\n+\tusing DmaBufAllocatorFlags = Flags<DmaBufAllocatorFlag>;\n+\n+\tDmaBufAllocator(DmaBufAllocatorFlags flags = DmaBufAllocatorFlag::CmaHeap);\n+\t~DmaBufAllocator();\n+\tbool isValid() const { return providerHandle_.isValid(); }\n+\tUniqueFD alloc(const char *name, std::size_t size);\n+\n+private:\n+\tUniqueFD providerHandle_;\n+};\n+\n+LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaBufAllocator::DmaBufAllocatorFlag)\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/dma_heaps.h b/include/libcamera/internal/dma_heaps.h\ndeleted file mode 100644\nindex f0a8aa5d..00000000\n--- a/include/libcamera/internal/dma_heaps.h\n+++ /dev/null\n@@ -1,38 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2020, Raspberry Pi Ltd\n- *\n- * Helper class for dma-heap allocations.\n- */\n-\n-#pragma once\n-\n-#include <stddef.h>\n-\n-#include <libcamera/base/flags.h>\n-#include <libcamera/base/unique_fd.h>\n-\n-namespace libcamera {\n-\n-class DmaHeap\n-{\n-public:\n-\tenum class DmaHeapFlag {\n-\t\tCma = 1 << 0,\n-\t\tSystem = 1 << 1,\n-\t};\n-\n-\tusing DmaHeapFlags = Flags<DmaHeapFlag>;\n-\n-\tDmaHeap(DmaHeapFlags flags = DmaHeapFlag::Cma);\n-\t~DmaHeap();\n-\tbool isValid() const { return dmaHeapHandle_.isValid(); }\n-\tUniqueFD alloc(const char *name, std::size_t size);\n-\n-private:\n-\tUniqueFD dmaHeapHandle_;\n-};\n-\n-LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaHeap::DmaHeapFlag)\n-\n-} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 160fdc37..9713ea1c 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -25,7 +25,7 @@ libcamera_internal_headers = files([\n 'device_enumerator.h',\n 'device_enumerator_sysfs.h',\n 'device_enumerator_udev.h',\n- 'dma_heaps.h',\n+ 'dma_buf_allocator.h',\n 'formats.h',\n 'framebuffer.h',\n 'ipa_manager.h',\ndiff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h\nindex 7e9fae6a..c5338c05 100644\n--- a/include/libcamera/internal/software_isp/software_isp.h\n+++ b/include/libcamera/internal/software_isp/software_isp.h\n@@ -27,7 +27,7 @@\n #include <libcamera/ipa/soft_ipa_proxy.h>\n \n #include \"libcamera/internal/camera_sensor.h\"\n-#include \"libcamera/internal/dma_heaps.h\"\n+#include \"libcamera/internal/dma_buf_allocator.h\"\n #include \"libcamera/internal/pipeline_handler.h\"\n #include \"libcamera/internal/shared_mem_object.h\"\n #include \"libcamera/internal/software_isp/debayer_params.h\"\n@@ -91,7 +91,7 @@ private:\n \tThread ispWorkerThread_;\n \tSharedMemObject<DebayerParams> sharedParams_;\n \tDebayerParams debayerParams_;\n-\tDmaHeap dmaHeap_;\n+\tDmaBufAllocator dmaHeap_;\n \n \tstd::unique_ptr<ipa::soft::IPAProxySoft> ipa_;\n };\ndiff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp\nnew file mode 100644\nindex 00000000..af512512\n--- /dev/null\n+++ b/src/libcamera/dma_buf_allocator.cpp\n@@ -0,0 +1,162 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2024, Red Hat Inc.\n+ * Copyright (C) 2020, Raspberry Pi Ltd\n+ *\n+ * Helper class for dma-buf allocations.\n+ */\n+\n+#include \"libcamera/internal/dma_buf_allocator.h\"\n+\n+#include <array>\n+#include <fcntl.h>\n+#include <sys/ioctl.h>\n+#include <unistd.h>\n+\n+#include <linux/dma-buf.h>\n+#include <linux/dma-heap.h>\n+\n+#include <libcamera/base/log.h>\n+\n+/**\n+ * \\file dma_buf_allocator.cpp\n+ * \\brief dma-buf allocator\n+ */\n+\n+namespace libcamera {\n+\n+#ifndef __DOXYGEN__\n+struct DmaBufAllocatorInfo {\n+\tDmaBufAllocator::DmaBufAllocatorFlag type;\n+\tconst char *deviceNodeName;\n+};\n+#endif\n+\n+static constexpr std::array<DmaBufAllocatorInfo, 3> providerInfos = { {\n+\t/*\n+\t * /dev/dma_heap/linux,cma is the CMA dma-heap. When the cma heap size is\n+\t * specified on the kernel command line, this gets renamed to \"reserved\".\n+\t */\n+\t{ DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap, \"/dev/dma_heap/linux,cma\" },\n+\t{ DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap, \"/dev/dma_heap/reserved\" },\n+\t{ DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap, \"/dev/dma_heap/system\" },\n+} };\n+\n+LOG_DEFINE_CATEGORY(DmaBufAllocator)\n+\n+/**\n+ * \\class DmaBufAllocator\n+ * \\brief Helper class for dma-buf allocations\n+ *\n+ * This class wraps a userspace dma-buf provider selected at construction time,\n+ * and exposes functions to allocate dma-buffers from this provider.\n+ *\n+ * Different providers may provide dma-buffers with different properties for\n+ * the underlying memory. Which providers are acceptable is specified through\n+ * the type argument passed to the DmaBufAllocator() constructor.\n+ */\n+\n+/**\n+ * \\enum DmaBufAllocator::DmaBufAllocatorFlag\n+ * \\brief Type of the dma-buf provider\n+ * \\var DmaBufAllocator::CmaHeap\n+ * \\brief Allocate from a CMA dma-heap, providing physically-contiguous memory\n+ * \\var DmaBufAllocator::SystemHeap\n+ * \\brief Allocate from the system dma-heap, using the page allocator\n+ */\n+\n+/**\n+ * \\typedef DmaBufAllocator::DmaBufAllocatorFlags\n+ * \\brief A bitwise combination of DmaBufAllocator::DmaBufAllocatorFlag values\n+ */\n+\n+/**\n+ * \\brief Construct a DmaBufAllocator of a given type\n+ * \\param[in] type The type(s) of the dma-buf providers to allocate from\n+ *\n+ * The dma-buf provider type is selected with the \\a type parameter, which\n+ * defaults to the CMA heap. If no provider of the given type can be accessed,\n+ * the constructed DmaBufAllocator instance is invalid as indicated by\n+ * the isValid() function.\n+ *\n+ * Multiple types can be selected by combining type flags, in which case\n+ * the constructed DmaBufAllocator will match one of the types. If multiple\n+ * requested types can work on the system, which provider is used is undefined.\n+ */\n+DmaBufAllocator::DmaBufAllocator(DmaBufAllocatorFlags type)\n+{\n+\tfor (const auto &info : providerInfos) {\n+\t\tif (!(type & info.type))\n+\t\t\tcontinue;\n+\n+\t\tint ret = ::open(info.deviceNodeName, O_RDWR | O_CLOEXEC, 0);\n+\t\tif (ret < 0) {\n+\t\t\tret = errno;\n+\t\t\tLOG(DmaBufAllocator, Debug)\n+\t\t\t\t<< \"Failed to open \" << info.deviceNodeName << \": \"\n+\t\t\t\t<< strerror(ret);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tLOG(DmaBufAllocator, Debug) << \"Using \" << info.deviceNodeName;\n+\t\tproviderHandle_ = UniqueFD(ret);\n+\t\tbreak;\n+\t}\n+\n+\tif (!providerHandle_.isValid())\n+\t\tLOG(DmaBufAllocator, Error) << \"Could not open any dma-buf provider\";\n+}\n+\n+/**\n+ * \\brief Destroy the DmaBufAllocator instance\n+ */\n+DmaBufAllocator::~DmaBufAllocator() = default;\n+\n+/**\n+ * \\fn DmaBufAllocator::isValid()\n+ * \\brief Check if the DmaBufAllocator instance is valid\n+ * \\return True if the DmaBufAllocator is valid, false otherwise\n+ */\n+\n+/**\n+ * \\brief Allocate a dma-buf from the DmaBufAllocator\n+ * \\param [in] name The name to set for the allocated buffer\n+ * \\param [in] size The size of the buffer to allocate\n+ *\n+ * Allocates a dma-buf with read/write access.\n+ *\n+ * If the allocation fails, return an invalid UniqueFD.\n+ *\n+ * \\return The UniqueFD of the allocated buffer\n+ */\n+UniqueFD DmaBufAllocator::alloc(const char *name, std::size_t size)\n+{\n+\tint ret;\n+\n+\tif (!name)\n+\t\treturn {};\n+\n+\tstruct dma_heap_allocation_data alloc = {};\n+\n+\talloc.len = size;\n+\talloc.fd_flags = O_CLOEXEC | O_RDWR;\n+\n+\tret = ::ioctl(providerHandle_.get(), DMA_HEAP_IOCTL_ALLOC, &alloc);\n+\tif (ret < 0) {\n+\t\tLOG(DmaBufAllocator, Error)\n+\t\t\t<< \"dma-heap allocation failure for \" << name;\n+\t\treturn {};\n+\t}\n+\n+\tUniqueFD allocFd(alloc.fd);\n+\tret = ::ioctl(allocFd.get(), DMA_BUF_SET_NAME, name);\n+\tif (ret < 0) {\n+\t\tLOG(DmaBufAllocator, Error)\n+\t\t\t<< \"dma-heap naming failure for \" << name;\n+\t\treturn {};\n+\t}\n+\n+\treturn allocFd;\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/dma_heaps.cpp b/src/libcamera/dma_heaps.cpp\ndeleted file mode 100644\nindex d4cb880b..00000000\n--- a/src/libcamera/dma_heaps.cpp\n+++ /dev/null\n@@ -1,165 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2020, Raspberry Pi Ltd\n- *\n- * Helper class for dma-heap allocations.\n- */\n-\n-#include \"libcamera/internal/dma_heaps.h\"\n-\n-#include <array>\n-#include <fcntl.h>\n-#include <sys/ioctl.h>\n-#include <unistd.h>\n-\n-#include <linux/dma-buf.h>\n-#include <linux/dma-heap.h>\n-\n-#include <libcamera/base/log.h>\n-\n-/**\n- * \\file dma_heaps.cpp\n- * \\brief dma-heap allocator\n- */\n-\n-namespace libcamera {\n-\n-/*\n- * /dev/dma_heap/linux,cma is the dma-heap allocator, which allows dmaheap-cma\n- * to only have to worry about importing.\n- *\n- * Annoyingly, should the cma heap size be specified on the kernel command line\n- * instead of DT, the heap gets named \"reserved\" instead.\n- */\n-\n-#ifndef __DOXYGEN__\n-struct DmaHeapInfo {\n-\tDmaHeap::DmaHeapFlag type;\n-\tconst char *deviceNodeName;\n-};\n-#endif\n-\n-static constexpr std::array<DmaHeapInfo, 3> heapInfos = { {\n-\t{ DmaHeap::DmaHeapFlag::Cma, \"/dev/dma_heap/linux,cma\" },\n-\t{ DmaHeap::DmaHeapFlag::Cma, \"/dev/dma_heap/reserved\" },\n-\t{ DmaHeap::DmaHeapFlag::System, \"/dev/dma_heap/system\" },\n-} };\n-\n-LOG_DEFINE_CATEGORY(DmaHeap)\n-\n-/**\n- * \\class DmaHeap\n- * \\brief Helper class for dma-heap allocations\n- *\n- * DMA heaps are kernel devices that provide an API to allocate memory from\n- * different pools called \"heaps\", wrap each allocated piece of memory in a\n- * dmabuf object, and return the dmabuf file descriptor to userspace. Multiple\n- * heaps can be provided by the system, with different properties for the\n- * underlying memory.\n- *\n- * This class wraps a DMA heap selected at construction time, and exposes\n- * functions to manage memory allocation.\n- */\n-\n-/**\n- * \\enum DmaHeap::DmaHeapFlag\n- * \\brief Type of the dma-heap\n- * \\var DmaHeap::Cma\n- * \\brief Allocate from a CMA dma-heap, providing physically-contiguous memory\n- * \\var DmaHeap::System\n- * \\brief Allocate from the system dma-heap, using the page allocator\n- */\n-\n-/**\n- * \\typedef DmaHeap::DmaHeapFlags\n- * \\brief A bitwise combination of DmaHeap::DmaHeapFlag values\n- */\n-\n-/**\n- * \\brief Construct a DmaHeap of a given type\n- * \\param[in] type The type(s) of the dma-heap(s) to allocate from\n- *\n- * The DMA heap type is selected with the \\a type parameter, which defaults to\n- * the CMA heap. If no heap of the given type can be accessed, the constructed\n- * DmaHeap instance is invalid as indicated by the isValid() function.\n- *\n- * Multiple types can be selected by combining type flags, in which case the\n- * constructed DmaHeap will match one of the types. If the system provides\n- * multiple heaps that match the requested types, which heap is used is\n- * undefined.\n- */\n-DmaHeap::DmaHeap(DmaHeapFlags type)\n-{\n-\tfor (const auto &info : heapInfos) {\n-\t\tif (!(type & info.type))\n-\t\t\tcontinue;\n-\n-\t\tint ret = ::open(info.deviceNodeName, O_RDWR | O_CLOEXEC, 0);\n-\t\tif (ret < 0) {\n-\t\t\tret = errno;\n-\t\t\tLOG(DmaHeap, Debug)\n-\t\t\t\t<< \"Failed to open \" << info.deviceNodeName << \": \"\n-\t\t\t\t<< strerror(ret);\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\tLOG(DmaHeap, Debug) << \"Using \" << info.deviceNodeName;\n-\t\tdmaHeapHandle_ = UniqueFD(ret);\n-\t\tbreak;\n-\t}\n-\n-\tif (!dmaHeapHandle_.isValid())\n-\t\tLOG(DmaHeap, Error) << \"Could not open any dmaHeap device\";\n-}\n-\n-/**\n- * \\brief Destroy the DmaHeap instance\n- */\n-DmaHeap::~DmaHeap() = default;\n-\n-/**\n- * \\fn DmaHeap::isValid()\n- * \\brief Check if the DmaHeap instance is valid\n- * \\return True if the DmaHeap is valid, false otherwise\n- */\n-\n-/**\n- * \\brief Allocate a dma-buf from the DmaHeap\n- * \\param [in] name The name to set for the allocated buffer\n- * \\param [in] size The size of the buffer to allocate\n- *\n- * Allocates a dma-buf with read/write access.\n- *\n- * If the allocation fails, return an invalid UniqueFD.\n- *\n- * \\return The UniqueFD of the allocated buffer\n- */\n-UniqueFD DmaHeap::alloc(const char *name, std::size_t size)\n-{\n-\tint ret;\n-\n-\tif (!name)\n-\t\treturn {};\n-\n-\tstruct dma_heap_allocation_data alloc = {};\n-\n-\talloc.len = size;\n-\talloc.fd_flags = O_CLOEXEC | O_RDWR;\n-\n-\tret = ::ioctl(dmaHeapHandle_.get(), DMA_HEAP_IOCTL_ALLOC, &alloc);\n-\tif (ret < 0) {\n-\t\tLOG(DmaHeap, Error) << \"dmaHeap allocation failure for \" << name;\n-\t\treturn {};\n-\t}\n-\n-\tUniqueFD allocFd(alloc.fd);\n-\tret = ::ioctl(allocFd.get(), DMA_BUF_SET_NAME, name);\n-\tif (ret < 0) {\n-\t\tLOG(DmaHeap, Error) << \"dmaHeap naming failure for \" << name;\n-\t\treturn {};\n-\t}\n-\n-\treturn allocFd;\n-}\n-\n-} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex a3b12bc1..89504cee 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -15,7 +15,7 @@ libcamera_sources = files([\n 'delayed_controls.cpp',\n 'device_enumerator.cpp',\n 'device_enumerator_sysfs.cpp',\n- 'dma_heaps.cpp',\n+ 'dma_buf_allocator.cpp',\n 'fence.cpp',\n 'formats.cpp',\n 'framebuffer.cpp',\ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex 37fb310f..4a89e35f 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -12,7 +12,7 @@\n #include <libcamera/formats.h>\n \n #include \"libcamera/internal/device_enumerator.h\"\n-#include \"libcamera/internal/dma_heaps.h\"\n+#include \"libcamera/internal/dma_buf_allocator.h\"\n \n #include \"../common/pipeline_base.h\"\n #include \"../common/rpi_stream.h\"\n@@ -86,7 +86,7 @@ public:\n \tRPi::Device<Isp, 4> isp_;\n \n \t/* DMAHEAP allocation helper. */\n-\tDmaHeap dmaHeap_;\n+\tDmaBufAllocator dmaHeap_;\n \tSharedFD lsTable_;\n \n \tstruct Config {\ndiff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp\nindex 0efe1d4e..034727c5 100644\n--- a/src/libcamera/software_isp/software_isp.cpp\n+++ b/src/libcamera/software_isp/software_isp.cpp\n@@ -66,7 +66,8 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)\n * handler\n */\n SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor)\n-\t: dmaHeap_(DmaHeap::DmaHeapFlag::Cma | DmaHeap::DmaHeapFlag::System)\n+\t: dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |\n+\t\t DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap)\n {\n \t/*\n \t * debayerParams_ must be initialized because the initial value is used for\n@@ -86,7 +87,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor)\n \t}\n \n \tif (!dmaHeap_.isValid()) {\n-\t\tLOG(SoftwareIsp, Error) << \"Failed to create DmaHeap object\";\n+\t\tLOG(SoftwareIsp, Error) << \"Failed to create DmaBufAllocator object\";\n \t\treturn;\n \t}\n \n", "prefixes": [ "v3", "1/3" ] }