From patchwork Mon Aug 23 13:12:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13448 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 9D96BBD87C for ; Mon, 23 Aug 2021 13:12:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65F44688D2; Mon, 23 Aug 2021 15:12:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gz6wmSwq"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6A51D688A3 for ; Mon, 23 Aug 2021 15:12:43 +0200 (CEST) Received: by mail-pf1-x42c.google.com with SMTP id t13so15331087pfl.6 for ; Mon, 23 Aug 2021 06:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WBeECzFwDoKtSJgAd7bs4ycayuxrXnEKLo1XxSC+/qI=; b=gz6wmSwqQ1UCLjtELzAPepIrOGRtxN1M01/9bTzCb20KcYynoF0U5J0kuIxnoTPTG0 bS99Y2V6B8dF7ygXJiB8AKbCpu4rTUM5NTRq6SpTIqLmqcdUeCPKjOhNx7fDjlxFQNw8 hMxH2gWQYVmHQhQVUs3OrtK+r3ryQnuMvCmnE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WBeECzFwDoKtSJgAd7bs4ycayuxrXnEKLo1XxSC+/qI=; b=s+KFv0bVz08XMok/75MyzH/b2zy0ZTOYWSC6l9xElmUA0OKxXxaSjkR2fHI0Ao1EsH XBjmQayxpAeuvYAhdjEFu6n8ZiZmPs8xMA+OifsJIBQJdwb26JDQE/5lbB8ui8+mcbcU GCi49RhN63iKyVACYwbBGJU5b9jj0U01QALmnNGD4pYVAwkLDRfYmCwG4FKWQeqh1drF L6F5gkyoSJvLki57VMPdRplEkb2K0lJAoy0v0mDbGbiqrKPhJ++bNwqbfXrK719dTfOg SQJqfQPxOSYuwq/A2NhxIfjI9qS1zGcJhfz18oUdRdN1Z6fVNCJNotTmIGDW9Dkz4JT6 utXQ== X-Gm-Message-State: AOAM530Df7mZIPSr7ReC55sN0DGCFcHLVZa4cshNf24hGqOAXu85dNJM JuCGwod5WmybUsDt5pscLQpETBzp57aUQQ== X-Google-Smtp-Source: ABdhPJzlT/JaKRe58XnO8LQj4bjnhAY/3pfN70HJRl1kJoLcI7ocoz4zH5qq6tN2nKRflv/w4qtB8w== X-Received: by 2002:a63:d607:: with SMTP id q7mr32144408pgg.268.1629724361779; Mon, 23 Aug 2021 06:12:41 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:184e:5d20:8fcb:dfcd]) by smtp.gmail.com with ESMTPSA id j4sm18596891pgi.6.2021.08.23.06.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Aug 2021 06:12:41 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Aug 2021 22:12:16 +0900 Message-Id: <20210823131221.1034059-6-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210823131221.1034059-1-hiroh@chromium.org> References: <20210823131221.1034059-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 05/10] ipa: rkisp1: Use offset in mapping IPABuffer 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" IPABuffer is represented by FrameBuffer. FrameBuffer::Plane has now an offset. This uses the offset variable to map the IPABuffer. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- .../libcamera/internal/mapped_framebuffer.h | 1 + src/ipa/rkisp1/rkisp1.cpp | 31 +++++++------------ src/libcamera/mapped_framebuffer.cpp | 7 +++++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h index 42479541..ee0583d0 100644 --- a/include/libcamera/internal/mapped_framebuffer.h +++ b/include/libcamera/internal/mapped_framebuffer.h @@ -55,6 +55,7 @@ public: using MapFlags = Flags; + MappedFrameBuffer(); MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags); }; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 06fb9640..54cf2885 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -24,6 +23,8 @@ #include #include +#include + namespace libcamera { LOG_DEFINE_CATEGORY(IPARkISP1) @@ -54,7 +55,7 @@ private: void metadataReady(unsigned int frame, unsigned int aeState); std::map buffers_; - std::map buffersMemory_; + std::map mappedBuffers_; ControlInfoMap ctrls_; @@ -160,21 +161,10 @@ void IPARkISP1::mapBuffers(const std::vector &buffers) std::forward_as_tuple(buffer.planes)); const FrameBuffer &fb = elem.first->second; - /* - * \todo Provide a helper to mmap() buffers (possibly exposed - * to applications). - */ - buffersMemory_[buffer.id] = mmap(NULL, - fb.planes()[0].length, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fb.planes()[0].fd.fd(), - 0); - - if (buffersMemory_[buffer.id] == MAP_FAILED) { - int ret = -errno; + mappedBuffers_[buffer.id] = MappedFrameBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite); + if (!mappedBuffers_[buffer.id].isValid()) { LOG(IPARkISP1, Fatal) << "Failed to mmap buffer: " - << strerror(-ret); + << strerror(mappedBuffers_[buffer.id].error()); } } } @@ -186,8 +176,7 @@ void IPARkISP1::unmapBuffers(const std::vector &ids) if (fb == buffers_.end()) continue; - munmap(buffersMemory_[id], fb->second.planes()[0].length); - buffersMemory_.erase(id); + mappedBuffers_.erase(id); buffers_.erase(id); } } @@ -200,7 +189,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event) unsigned int bufferId = event.bufferId; const rkisp1_stat_buffer *stats = - static_cast(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_[bufferId].maps()[0].data()); updateStatistics(frame, stats); break; @@ -210,7 +200,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event) unsigned int bufferId = event.bufferId; rkisp1_params_cfg *params = - static_cast(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_[bufferId].maps()[0].data()); queueRequest(frame, params, event.controls); break; diff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp index 03425dea..34d9564d 100644 --- a/src/libcamera/mapped_framebuffer.cpp +++ b/src/libcamera/mapped_framebuffer.cpp @@ -168,6 +168,13 @@ MappedBuffer::~MappedBuffer() * \brief A bitwise combination of MappedFrameBuffer::MapFlag values */ +/** + * \brief Construct an empty MappedFrameBuffer + */ +MappedFrameBuffer::MappedFrameBuffer() + : MappedBuffer() +{ +} /** * \brief Map all planes of a FrameBuffer * \param[in] buffer FrameBuffer to be mapped