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: From patchwork Thu Aug 27 08:20:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9405 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 7A575BDC71 for ; Thu, 27 Aug 2020 08:17:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 58BCE62901; Thu, 27 Aug 2020 10:17:02 +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 F18E060379 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 41B6E24000A; Thu, 27 Aug 2020 08:16:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org, Dave Stevenson , Naushir Patuck Date: Thu, 27 Aug 2020 10:20:37 +0200 Message-Id: <20200827082038.40758-3-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 2/3] libcamera: raspberrypi: dma_heaps: Be verbose on errors 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" Be a tad more verbose on failures in opening the dma_heaps allocator devices. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/raspberrypi/dma_heaps.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp index 739f05d3d4d8..500f1eac2eb8 100644 --- a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp @@ -45,9 +45,14 @@ int DmaHeap::open() { dmaHeapHandle_ = ::open(DMA_HEAP_CMA_NAME, O_RDWR, 0); if (dmaHeapHandle_ == -1) { + LOG(RPI, Error) << "Could not open dmaHeap device " + << DMA_HEAP_CMA_NAME << ": " + << strerror(errno); dmaHeapHandle_ = ::open(DMA_HEAP_CMA_ALT_NAME, O_RDWR, 0); if (dmaHeapHandle_ == -1) { - LOG(RPI, Error) << "Could not open dmaHeap device"; + LOG(RPI, Error) << "Could not open dmaHeap device " + << DMA_HEAP_CMA_ALT_NAME << ": " + << strerror(errno); return dmaHeapHandle_; } } From patchwork Thu Aug 27 08:20:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9406 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 A74C2BDC71 for ; Thu, 27 Aug 2020 08:17:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 76B9F628F3; Thu, 27 Aug 2020 10:17:05 +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 DC71962907 for ; Thu, 27 Aug 2020 10:17:00 +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 1F94124000B; Thu, 27 Aug 2020 08:16:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org, Dave Stevenson , Naushir Patuck Date: Thu, 27 Aug 2020 10:20:38 +0200 Message-Id: <20200827082038.40758-4-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 3/3] libcamera: raspberrypi: Fail on dmaHeaps_ open error 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" Provide an RPiCameraData::init() method where the dmaHeaps_ member is opened. This allows to fail earlier in case the allocator fails to open. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 42c9caa03e2e..38da45607d4b 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -291,6 +291,7 @@ public: { } + int init(); void frameStarted(uint32_t sequence); int loadIPA(); @@ -904,6 +905,8 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) return false; std::unique_ptr data = std::make_unique(this); + if (data->init()) + return false; /* Locate and open the unicam video streams. */ data->unicam_[Unicam::Embedded] = RPiStream("Unicam Embedded", unicam_->getEntityByName("unicam-embedded")); @@ -1084,6 +1087,11 @@ void PipelineHandlerRPi::freeBuffers(Camera *camera) stream->releaseBuffers(); } +int RPiCameraData::init() +{ + return dmaHeap_.open(); +} + void RPiCameraData::frameStarted(uint32_t sequence) { LOG(RPI, Debug) << "frame start " << sequence;