From patchwork Thu Aug 27 08:20:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9404 X-Patchwork-Delegate: jacopo@jmondi.org 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 55191BF01C for ; Thu, 27 Aug 2020 08:17:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 359A8628F7; Thu, 27 Aug 2020 10:17:00 +0200 (CEST) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2322D60379 for ; Thu, 27 Aug 2020 10:16:59 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 63C36240006; Thu, 27 Aug 2020 08:16:58 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org, Dave Stevenson , Naushir Patuck Date: Thu, 27 Aug 2020 10:20:36 +0200 Message-Id: <20200827082038.40758-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200827082038.40758-1-jacopo@jmondi.org> References: <20200827082038.40758-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] libcamera: raspberrypi: dma_heaps: Add open/close 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The dma_heaps device is opened in the class constructor, making it impossible (or rather ugly) to catch errors before the allocator gets actually used. Provide an open() and a close() method to allow users to catch errors earlier. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- .../pipeline/raspberrypi/dma_heaps.cpp | 22 ++++++++++++++++--- .../pipeline/raspberrypi/dma_heaps.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp index 6769c04640f1..739f05d3d4d8 100644 --- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp @@ -32,20 +32,36 @@ LOG_DECLARE_CATEGORY(RPI) namespace RPi { DmaHeap::DmaHeap() + : dmaHeapHandle_(-1) +{ +} + +DmaHeap::~DmaHeap() +{ + close(); +} + +int DmaHeap::open() { dmaHeapHandle_ = ::open(DMA_HEAP_CMA_NAME, O_RDWR, 0); if (dmaHeapHandle_ == -1) { dmaHeapHandle_ = ::open(DMA_HEAP_CMA_ALT_NAME, O_RDWR, 0); if (dmaHeapHandle_ == -1) { LOG(RPI, Error) << "Could not open dmaHeap device"; + return dmaHeapHandle_; } } + + return 0; } -DmaHeap::~DmaHeap() +void DmaHeap::close() { - if (dmaHeapHandle_) - ::close(dmaHeapHandle_); + if (dmaHeapHandle_ < 0) + return; + + ::close(dmaHeapHandle_); + dmaHeapHandle_ = -1; } FileDescriptor DmaHeap::alloc(const char *name, std::size_t size) diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.h b/src/libcamera/pipeline/raspberrypi/dma_heaps.h index ae6be1135f17..3e17993097ef 100644 --- a/src/libcamera/pipeline/raspberrypi/dma_heaps.h +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.h @@ -18,6 +18,8 @@ class DmaHeap public: DmaHeap(); ~DmaHeap(); + int open(); + void close(); FileDescriptor alloc(const char *name, std::size_t size); private: