{"id":19485,"url":"https://patchwork.libcamera.org/api/1.1/patches/19485/?format=json","web_url":"https://patchwork.libcamera.org/patch/19485/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240214170122.60754-3-hdegoede@redhat.com>","date":"2024-02-14T17:01:06","name":"[v3,02/16] libcamera: internal: Move dma_heaps.[h, cpp] to common directories","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e78e24d04cb9983c5794f9a6d634d04c3ba0a2b0","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/1.1/people/102/?format=json","name":"Hans de Goede","email":"hdegoede@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19485/mbox/","series":[{"id":4167,"url":"https://patchwork.libcamera.org/api/1.1/series/4167/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4167","date":"2024-02-14T17:01:04","name":"libcamera: introduce Software ISP and Software IPA","version":3,"mbox":"https://patchwork.libcamera.org/series/4167/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19485/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19485/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 EB03FC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 14 Feb 2024 17:01:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E544E6280E;\n\tWed, 14 Feb 2024 18:01:41 +0100 (CET)","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 33E4262804\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 14 Feb 2024 18:01:40 +0100 (CET)","from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n\t[66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-554-uK2ll2CMO5C1xnHXXuzJAg-1; Wed, 14 Feb 2024 12:01:35 -0500","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6])\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 E72F984AE49;\n\tWed, 14 Feb 2024 17:01:34 +0000 (UTC)","from localhost.localdomain (unknown [10.39.192.30])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 6B5432166B5D;\n\tWed, 14 Feb 2024 17:01:33 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"e99/vFIy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1707930099;\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=896USHQR0ZH52rY8TYEme6x62Z3Zb6Krso37IJJppyA=;\n\tb=e99/vFIyYm2goNOMbq8uiZ0b+nMDhrPAabzfamAi10Esz6i1lUphSsBje/dCHygy+toKcE\n\tyaO5/vzjTe7PXrH/AMrU0obiLa3d6172Vw8sH7TGJSI10/lFmaUTsFCb9JslNUx2uhjf5F\n\tC6yr3TsqewCvDoW4PqBKGrypjQCdRv4=","X-MC-Unique":"uK2ll2CMO5C1xnHXXuzJAg-1","From":"Hans de Goede <hdegoede@redhat.com>","To":"libcamera-devel@lists.libcamera.org","Subject":"[PATCH v3 02/16] libcamera: internal: Move dma_heaps.[h,\n\tcpp] to common directories","Date":"Wed, 14 Feb 2024 18:01:06 +0100","Message-ID":"<20240214170122.60754-3-hdegoede@redhat.com>","In-Reply-To":"<20240214170122.60754-1-hdegoede@redhat.com>","References":"<20240214170122.60754-1-hdegoede@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.11.54.6","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>","Cc":"Maxime Ripard <mripard@redhat.com>, Pavel Machek <pavel@ucw.cz>,\n\tBryan O'Donoghue <bryan.odonoghue@linaro.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Andrey Konovalov <andrey.konovalov@linaro.org>\n\nDmaHeap class is useful outside the RPi pipeline handler too.\n\nMove dma_heaps.h and dma_heaps.cpp to common directories. Update\nthe build files and RPi vc4 pipeline handler accordingly.\n\nTested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s\nTested-by: Pavel Machek <pavel@ucw.cz>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Pavel Machek <pavel@ucw.cz>\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\nSigned-off-by: Hans de Goede <hdegoede@redhat.com>\n---\n .../libcamera/internal}/dma_heaps.h           |   4 -\n include/libcamera/internal/meson.build        |   1 +\n src/libcamera/dma_heaps.cpp                   | 127 ++++++++++++++++++\n src/libcamera/meson.build                     |   1 +\n src/libcamera/pipeline/rpi/vc4/dma_heaps.cpp  |  90 -------------\n src/libcamera/pipeline/rpi/vc4/meson.build    |   1 -\n src/libcamera/pipeline/rpi/vc4/vc4.cpp        |   5 +-\n 7 files changed, 131 insertions(+), 98 deletions(-)\n rename {src/libcamera/pipeline/rpi/vc4 => include/libcamera/internal}/dma_heaps.h (92%)\n create mode 100644 src/libcamera/dma_heaps.cpp\n delete mode 100644 src/libcamera/pipeline/rpi/vc4/dma_heaps.cpp","diff":"diff --git a/src/libcamera/pipeline/rpi/vc4/dma_heaps.h b/include/libcamera/internal/dma_heaps.h\nsimilarity index 92%\nrename from src/libcamera/pipeline/rpi/vc4/dma_heaps.h\nrename to include/libcamera/internal/dma_heaps.h\nindex 0a4a8d86..cff8f140 100644\n--- a/src/libcamera/pipeline/rpi/vc4/dma_heaps.h\n+++ b/include/libcamera/internal/dma_heaps.h\n@@ -13,8 +13,6 @@\n \n namespace libcamera {\n \n-namespace RPi {\n-\n class DmaHeap\n {\n public:\n@@ -27,6 +25,4 @@ private:\n \tUniqueFD dmaHeapHandle_;\n };\n \n-} /* namespace RPi */\n-\n } /* namespace libcamera */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 7f1f3440..33eb0fb3 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -25,6 +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     'formats.h',\n     'framebuffer.h',\n     'ipa_manager.h',\ndiff --git a/src/libcamera/dma_heaps.cpp b/src/libcamera/dma_heaps.cpp\nnew file mode 100644\nindex 00000000..38ef175a\n--- /dev/null\n+++ b/src/libcamera/dma_heaps.cpp\n@@ -0,0 +1,127 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2020, Raspberry Pi Ltd\n+ *\n+ * dma_heaps.h - 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 CMA dma-heap allocator\n+ */\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+static constexpr std::array<const char *, 2> heapNames = {\n+\t\"/dev/dma_heap/linux,cma\",\n+\t\"/dev/dma_heap/reserved\"\n+};\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(DmaHeap)\n+\n+/**\n+ * \\class DmaHeap\n+ * \\brief Helper class for CMA dma-heap allocations\n+ */\n+\n+/**\n+ * \\brief Construct a DmaHeap that owns a CMA dma-heap file descriptor\n+ *\n+ * Goes through the internal list of possible names of the CMA dma-heap devices\n+ * until a CMA dma-heap device is successfully opened. If it fails to open any\n+ * dma-heap device, an invalid DmaHeap object is constructed. A valid DmaHeap\n+ * object owns a wrapped dma-heap file descriptor.\n+ *\n+ * Please check the new DmaHeap object with \\ref DmaHeap::isValid before using it.\n+ */\n+DmaHeap::DmaHeap()\n+{\n+\tfor (const char *name : heapNames) {\n+\t\tint ret = ::open(name, 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 \" << name << \": \"\n+\t\t\t\t<< strerror(ret);\n+\t\t\tcontinue;\n+\t\t}\n+\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+ * Destroying a DmaHeap instance which owns a wrapped dma-heap file descriptor\n+ * closes the descriptor automatically.\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+ * \\return The \\ref UniqueFD of the allocated buffer\n+ *\n+ * Allocates a dma-buf with read/write access.\n+ * If the allocation fails returns invalid UniqueFD.\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 45f63e93..3c5e43df 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -17,6 +17,7 @@ libcamera_sources = files([\n     'delayed_controls.cpp',\n     'device_enumerator.cpp',\n     'device_enumerator_sysfs.cpp',\n+    'dma_heaps.cpp',\n     'fence.cpp',\n     'formats.cpp',\n     'framebuffer.cpp',\ndiff --git a/src/libcamera/pipeline/rpi/vc4/dma_heaps.cpp b/src/libcamera/pipeline/rpi/vc4/dma_heaps.cpp\ndeleted file mode 100644\nindex 317b1fc1..00000000\n--- a/src/libcamera/pipeline/rpi/vc4/dma_heaps.cpp\n+++ /dev/null\n@@ -1,90 +0,0 @@\n-/* SPDX-License-Identifier: LGPL-2.1-or-later */\n-/*\n- * Copyright (C) 2020, Raspberry Pi Ltd\n- *\n- * dma_heaps.h - Helper class for dma-heap allocations.\n- */\n-\n-#include \"dma_heaps.h\"\n-\n-#include <array>\n-#include <fcntl.h>\n-#include <linux/dma-buf.h>\n-#include <linux/dma-heap.h>\n-#include <sys/ioctl.h>\n-#include <unistd.h>\n-\n-#include <libcamera/base/log.h>\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-static constexpr std::array<const char *, 2> heapNames = {\n-\t\"/dev/dma_heap/linux,cma\",\n-\t\"/dev/dma_heap/reserved\"\n-};\n-\n-namespace libcamera {\n-\n-LOG_DECLARE_CATEGORY(RPI)\n-\n-namespace RPi {\n-\n-DmaHeap::DmaHeap()\n-{\n-\tfor (const char *name : heapNames) {\n-\t\tint ret = ::open(name, O_RDWR | O_CLOEXEC, 0);\n-\t\tif (ret < 0) {\n-\t\t\tret = errno;\n-\t\t\tLOG(RPI, Debug) << \"Failed to open \" << name << \": \"\n-\t\t\t\t\t<< strerror(ret);\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\tdmaHeapHandle_ = UniqueFD(ret);\n-\t\tbreak;\n-\t}\n-\n-\tif (!dmaHeapHandle_.isValid())\n-\t\tLOG(RPI, Error) << \"Could not open any dmaHeap device\";\n-}\n-\n-DmaHeap::~DmaHeap() = default;\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(RPI, Error) << \"dmaHeap allocation failure for \"\n-\t\t\t\t<< 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(RPI, Error) << \"dmaHeap naming failure for \"\n-\t\t\t\t<< name;\n-\t\treturn {};\n-\t}\n-\n-\treturn allocFd;\n-}\n-\n-} /* namespace RPi */\n-\n-} /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/rpi/vc4/meson.build b/src/libcamera/pipeline/rpi/vc4/meson.build\nindex cdb049c5..386e2296 100644\n--- a/src/libcamera/pipeline/rpi/vc4/meson.build\n+++ b/src/libcamera/pipeline/rpi/vc4/meson.build\n@@ -1,7 +1,6 @@\n # SPDX-License-Identifier: CC0-1.0\n \n libcamera_sources += files([\n-    'dma_heaps.cpp',\n     'vc4.cpp',\n ])\n \ndiff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\nindex a52f0e7a..3e7d2af4 100644\n--- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n+++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp\n@@ -12,12 +12,11 @@\n #include <libcamera/formats.h>\n \n #include \"libcamera/internal/device_enumerator.h\"\n+#include \"libcamera/internal/dma_heaps.h\"\n \n #include \"../common/pipeline_base.h\"\n #include \"../common/rpi_stream.h\"\n \n-#include \"dma_heaps.h\"\n-\n using namespace std::chrono_literals;\n \n namespace libcamera {\n@@ -87,7 +86,7 @@ public:\n \tRPi::Device<Isp, 4> isp_;\n \n \t/* DMAHEAP allocation helper. */\n-\tRPi::DmaHeap dmaHeap_;\n+\tDmaHeap dmaHeap_;\n \tSharedFD lsTable_;\n \n \tstruct Config {\n","prefixes":["v3","02/16"]}