From patchwork Sat Jan 13 14:22:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 19395 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 65693C328C for ; Sat, 13 Jan 2024 14:22:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17F72628B7; Sat, 13 Jan 2024 15:22:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1705155765; bh=qEK+s2Qrke44/RPeyE0f4TZVE7NY+YtoJdoGhkJlTu4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=W5uCtlPTVuYEHPNJZi/Dsf7I4fz/OEZ9rm++tmpL2ylZqaB9jasaRp18oFy4OHvmd Irn3yGZBTK6jlHVHrGs14m8WWm2THzDS1LqhDXQbedTr2DGgucAixu528wUAKEstFn kPPxG4UJLnrXwiCSchdHC0SIxwXx1RIyhzzypfb2OUH6aAW21YahCrCbV4/V/I9VY1 Z13QfD18oK13JI67h5mx83TTT2Hi72oh68ycEo/jTEgqFIQNS1S1ubHChH+lYOawKX mjmEms1TU/qrwqJlXsjBLnnJLSfHsoeAECI0OQ4VAJx/yavsmsRpSuqr8z6gtOmoDc ERGHIbx9ZGLng== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1D127628B7 for ; Sat, 13 Jan 2024 15:22:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="S96MsB0u"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705155761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZJXgz4PaVpQMdyy9EXG54yJisYoI7RdmKq6n90BOzkk=; b=S96MsB0uaaWSgSTTB4sjCq5dL64HhrpxiQeSeo6VuE75ItGfCEVWytKXNrZuReudtILfKC LBkeUJE/GYvJ8h00Pzim03JKQ6+yzHSm2QZT3OJqnJhFg3K4Q2Eo/yeNXitHpuylo7tWrW Z94YrwRQH/BMtd2TPUI8m8mG5za40mg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-QSHKST5RONi7KCRO2Ec7rw-1; Sat, 13 Jan 2024 09:22:34 -0500 X-MC-Unique: QSHKST5RONi7KCRO2Ec7rw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6714982A6C0; Sat, 13 Jan 2024 14:22:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57D823C25; Sat, 13 Jan 2024 14:22:31 +0000 (UTC) To: libcamera-devel@lists.libcamera.org, Andrey Konovalov Date: Sat, 13 Jan 2024 15:22:03 +0100 Message-ID: <20240113142218.28063-4-hdegoede@redhat.com> In-Reply-To: <20240113142218.28063-1-hdegoede@redhat.com> References: <20240113142218.28063-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH v2 03/18] libcamera: dma_heaps: extend DmaHeap class to support system heap X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Hans de Goede via libcamera-devel From: Hans de Goede Reply-To: Hans de Goede Cc: Maxime Ripard , g.martti@gmail.com, t.langendam@gmail.com, srinivas.kandagatla@linaro.org, Pavel Machek , Bryan O'Donoghue , admin@dennisbonke.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Andrey Konovalov Add an argument to the constructor to specify dma heaps type(s) 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 Signed-off-by: Hans de Goede Tested-by: Bryan O'Donoghue # sc8280xp Lenovo x13s Tested-by: Pavel Machek --- include/libcamera/internal/dma_heaps.h | 12 +++++++- src/libcamera/dma_heaps.cpp | 39 +++++++++++++++----------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/dma_heaps.h b/include/libcamera/internal/dma_heaps.h index cff8f140..22aa1007 100644 --- a/include/libcamera/internal/dma_heaps.h +++ b/include/libcamera/internal/dma_heaps.h @@ -9,6 +9,7 @@ #include +#include #include namespace libcamera { @@ -16,7 +17,14 @@ namespace libcamera { class DmaHeap { public: - DmaHeap(); + enum class DmaHeapFlag { + Cma = (1 << 0), + System = (1 << 1), + }; + + using DmaHeapFlags = Flags; + + DmaHeap(DmaHeapFlags flags = DmaHeapFlag::Cma); ~DmaHeap(); bool isValid() const { return dmaHeapHandle_.isValid(); } UniqueFD alloc(const char *name, std::size_t size); @@ -25,4 +33,6 @@ private: UniqueFD dmaHeapHandle_; }; +LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaHeap::DmaHeapFlag) + } /* namespace libcamera */ diff --git a/src/libcamera/dma_heaps.cpp b/src/libcamera/dma_heaps.cpp index 7444d9c2..177de31b 100644 --- a/src/libcamera/dma_heaps.cpp +++ b/src/libcamera/dma_heaps.cpp @@ -16,6 +16,8 @@ #include "libcamera/internal/dma_heaps.h" +namespace libcamera { + /* * /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 @@ * 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 heapNames = { - "/dev/dma_heap/linux,cma", - "/dev/dma_heap/reserved" +static constexpr std::array, 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") }; -namespace libcamera { - LOG_DEFINE_CATEGORY(DmaHeap) -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; + } + + LOG(DmaHeap, Debug) << "Using " << name.second; + dmaHeapHandle_ = UniqueFD(ret); + break; + } } if (!dmaHeapHandle_.isValid())