about summary refs log tree commit diff
path: root/users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch
diff options
context:
space:
mode:
Diffstat (limited to 'users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch')
-rw-r--r--users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch144
1 files changed, 96 insertions, 48 deletions
diff --git a/users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch b/users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch
index de81924487..6e5ef9445a 100644
--- a/users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch
+++ b/users/flokli/ipu6-softisp/libcamera/0003-libcamera-dma_heaps-extend-DmaHeap-class-to-support-.patch
@@ -1,7 +1,7 @@
-From 6d5f3b0b54df4ff66079675a4c1f0f0b76778e22 Mon Sep 17 00:00:00 2001
+From 5df9bc3b2a3d86bcc8504896cc87d7fcb5aea3a4 Mon Sep 17 00:00:00 2001
 From: Andrey Konovalov <andrey.konovalov@linaro.org>
-Date: Wed, 10 Jan 2024 23:51:25 +0300
-Subject: [PATCH 03/25] libcamera: dma_heaps: extend DmaHeap class to support
+Date: Mon, 11 Mar 2024 15:15:07 +0100
+Subject: [PATCH 03/21] libcamera: dma_heaps: extend DmaHeap class to support
  system heap
 
 Add an argument to the constructor to specify dma heaps type(s)
@@ -9,17 +9,19 @@ to use. Can be DmaHeapFlag::Cma and/or DmaHeapFlag::System.
 By default DmaHeapFlag::Cma is used. If both DmaHeapFlag::Cma and
 DmaHeapFlag::System are set, CMA heap is tried first.
 
-Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
-Signed-off-by: Hans de Goede <hdegoede@redhat.com>
 Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # sc8280xp Lenovo x13s
 Tested-by: Pavel Machek <pavel@ucw.cz>
+Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
+Reviewed-by: Pavel Machek <pavel@ucw.cz>
+Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
 ---
- include/libcamera/internal/dma_heaps.h | 12 +++++++-
- src/libcamera/dma_heaps.cpp            | 39 +++++++++++++++-----------
- 2 files changed, 34 insertions(+), 17 deletions(-)
+ include/libcamera/internal/dma_heaps.h | 12 ++++-
+ src/libcamera/dma_heaps.cpp            | 67 ++++++++++++++++++++------
+ 2 files changed, 63 insertions(+), 16 deletions(-)
 
 diff --git a/include/libcamera/internal/dma_heaps.h b/include/libcamera/internal/dma_heaps.h
-index cff8f140..22aa1007 100644
+index cff8f140..80bf29e7 100644
 --- a/include/libcamera/internal/dma_heaps.h
 +++ b/include/libcamera/internal/dma_heaps.h
 @@ -9,6 +9,7 @@
@@ -36,8 +38,8 @@ index cff8f140..22aa1007 100644
  public:
 -	DmaHeap();
 +	enum class DmaHeapFlag {
-+		Cma = (1 << 0),
-+		System = (1 << 1),
++		Cma = 1 << 0,
++		System = 1 << 1,
 +	};
 +
 +	using DmaHeapFlags = Flags<DmaHeapFlag>;
@@ -54,68 +56,114 @@ index cff8f140..22aa1007 100644
 +
  } /* namespace libcamera */
 diff --git a/src/libcamera/dma_heaps.cpp b/src/libcamera/dma_heaps.cpp
-index 7444d9c2..177de31b 100644
+index 38ef175a..d0e33ce6 100644
 --- a/src/libcamera/dma_heaps.cpp
 +++ b/src/libcamera/dma_heaps.cpp
-@@ -16,6 +16,8 @@
+@@ -19,9 +19,11 @@
  
- #include "libcamera/internal/dma_heaps.h"
+ /**
+  * \file dma_heaps.cpp
+- * \brief CMA dma-heap allocator
++ * \brief dma-heap allocator
+  */
  
 +namespace libcamera {
 +
  /*
-  * /dev/dma-heap/linux,cma is the dma-heap allocator, which allows dmaheap-cma
+  * /dev/dma_heap/linux,cma is the dma-heap allocator, which allows dmaheap-cma
   * to only have to worry about importing.
-@@ -23,28 +25,33 @@
+@@ -29,42 +31,77 @@
   * Annoyingly, should the cma heap size be specified on the kernel command line
   * instead of DT, the heap gets named "reserved" instead.
   */
 -static constexpr std::array<const char *, 2> heapNames = {
 -	"/dev/dma_heap/linux,cma",
 -	"/dev/dma_heap/reserved"
-+static constexpr std::array<std::pair<DmaHeap::DmaHeapFlag, const char *>, 3> heapNames = {
-+	/* CMA heap names first */
-+	std::make_pair(DmaHeap::DmaHeapFlag::Cma, "/dev/dma_heap/linux,cma"),
-+	std::make_pair(DmaHeap::DmaHeapFlag::Cma, "/dev/dma_heap/reserved"),
-+	std::make_pair(DmaHeap::DmaHeapFlag::System, "/dev/dma_heap/system")
++
++/**
++ * \struct DmaHeapInfo
++ * \brief Tells what type of dma-heap the dma-heap represented by the device node name is
++ * \var DmaHeapInfo::flag
++ * \brief The type of the dma-heap
++ * \var DmaHeapInfo::name
++ * \brief The dma-heap's device node name
++ */
++struct DmaHeapInfo {
++	DmaHeap::DmaHeapFlag flag;
++	const char *name;
  };
  
 -namespace libcamera {
--
++static constexpr std::array<DmaHeapInfo, 3> heapInfos = {
++	{ /* CMA heap names first */
++	  { DmaHeap::DmaHeapFlag::Cma, "/dev/dma_heap/linux,cma" },
++	  { DmaHeap::DmaHeapFlag::Cma, "/dev/dma_heap/reserved" },
++	  { DmaHeap::DmaHeapFlag::System, "/dev/dma_heap/system" } }
++};
+ 
  LOG_DEFINE_CATEGORY(DmaHeap)
  
+ /**
+  * \class DmaHeap
+- * \brief Helper class for CMA dma-heap allocations
++ * \brief Helper class for dma-heap allocations
+  */
+ 
+ /**
+- * \brief Construct a DmaHeap that owns a CMA dma-heap file descriptor
++ * \enum DmaHeap::DmaHeapFlag
++ * \brief Type of the dma-heap
++ * \var DmaHeap::Cma
++ * \brief Allocate from a CMA dma-heap
++ * \var DmaHeap::System
++ * \brief Allocate from the system dma-heap
++ */
++
++/**
++ * \typedef DmaHeap::DmaHeapFlags
++ * \brief A bitwise combination of DmaHeap::DmaHeapFlag values
++ */
++
++/**
++ * \brief Construct a DmaHeap that owns a CMA or system dma-heap file descriptor
++ * \param [in] flags The type(s) of the dma-heap(s) to allocate from
+  *
+- * Goes through the internal list of possible names of the CMA dma-heap devices
+- * until a CMA dma-heap device is successfully opened. If it fails to open any
+- * dma-heap device, an invalid DmaHeap object is constructed. A valid DmaHeap
+- * object owns a wrapped dma-heap file descriptor.
++ * By default \a flags are set to DmaHeap::DmaHeapFlag::Cma. The constructor goes
++ * through the internal list of possible names of the CMA and system dma-heap devices
++ * until the dma-heap device of the requested type is successfully opened. If more
++ * than one dma-heap type is specified in flags the CMA heap is tried first. If it
++ * fails to open any dma-heap device an invalid DmaHeap object is constructed.
++ * A valid DmaHeap object owns a wrapped dma-heap file descriptor.
+  *
+  * Please check the new DmaHeap object with \ref DmaHeap::isValid before using it.
+  */
 -DmaHeap::DmaHeap()
 +DmaHeap::DmaHeap(DmaHeapFlags flags)
  {
 -	for (const char *name : heapNames) {
 -		int ret = ::open(name, O_RDWR | O_CLOEXEC, 0);
--		if (ret < 0) {
--			ret = errno;
--			LOG(DmaHeap, Debug) << "Failed to open " << name << ": "
--					<< strerror(ret);
--			continue;
--		}
-+	int ret;
- 
--		dmaHeapHandle_ = UniqueFD(ret);
--		break;
-+	for (const auto &name : heapNames) {
-+		if (flags & name.first) {
-+			ret = ::open(name.second, O_RDWR | O_CLOEXEC, 0);
-+			if (ret < 0) {
-+				ret = errno;
-+				LOG(DmaHeap, Debug) << "Failed to open " << name.second << ": "
-+						    << strerror(ret);
-+				continue;
-+			}
++	for (const auto &info : heapInfos) {
++		if (!(flags & info.flag))
++			continue;
 +
-+			LOG(DmaHeap, Debug) << "Using " << name.second;
-+			dmaHeapHandle_ = UniqueFD(ret);
-+			break;
-+		}
- 	}
++		int ret = ::open(info.name, O_RDWR | O_CLOEXEC, 0);
+ 		if (ret < 0) {
+ 			ret = errno;
+ 			LOG(DmaHeap, Debug)
+-				<< "Failed to open " << name << ": "
++				<< "Failed to open " << info.name << ": "
+ 				<< strerror(ret);
+ 			continue;
+ 		}
  
- 	if (!dmaHeapHandle_.isValid())
++		LOG(DmaHeap, Debug) << "Using " << info.name;
+ 		dmaHeapHandle_ = UniqueFD(ret);
+ 		break;
+ 	}
 -- 
-2.43.0
+2.43.2