From patchwork Thu Aug 26 11:25:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13505 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 62040BD87C for ; Thu, 26 Aug 2021 11:25:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14FC2688E5; Thu, 26 Aug 2021 13:25:57 +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="dDT5kqFK"; dkim-atps=neutral Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E0A268919 for ; Thu, 26 Aug 2021 13:25:54 +0200 (CEST) Received: by mail-pg1-x52a.google.com with SMTP id x4so2823140pgh.1 for ; Thu, 26 Aug 2021 04:25:54 -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=7WvogKrN3bFtWOlOa6LHh6IQxO3Sjs4Hr9+xtUUr+hI=; b=dDT5kqFKNx271UQC7hby897M1T4YQEDUUrEX0Liz3Lp7Pwg7TE34bDxcwgADFSNror 5YAkHfcft890/ksNF+8kbej6sI6yYVuQC0ju5a7+esw3Q9/rJaemYb+Vt6n60xuAn5pX iy3yJr9v7GFjHGUA9XIAzjFkCpww0js7XJ9zs= 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=7WvogKrN3bFtWOlOa6LHh6IQxO3Sjs4Hr9+xtUUr+hI=; b=KFbRYcuj9eqaSOn2qaiVBchCgK9iVzkhjqL9poanx7AKgdmUAfa3MafeDe6Lh+PkBV OUNgdUYvEW7jbUcNUCXQfRTu8mtmhavobon9Jbl2OF3motwEULvVt5XSve9T5/aACXKc H+NJIcYY+rJFa79B+//pJ40fXcZKA+Cr03EKZHRAQjs7lFESOt9LdovtKU39e6CPx/o8 TfqTvj8kSqnrcoygmtKM1wLMtzv1dtRpJtoO5+bhwrvplDx4d7ryTUvJ9LEDjuTBb/Yw /1PF/Jc32no0MHP9GlL4NInIpbm2SDIVhit12NsemF/4I9FxeRVD9m0+EpxwHr3JLIDC flrg== X-Gm-Message-State: AOAM5335wH+qiizTWJnsOsKn+TCC2vFW3hfr97a3qoL831fL4gBmtjvj t9107rL544ZLQyMQCEWG8u4th9oQib889w== X-Google-Smtp-Source: ABdhPJxnp/20qjd+05zyuyDFVWalGUnU4fTB2Yu/sdqa/ipd9sTJfPU/9haaYuY25Bn96bHoq3s+xQ== X-Received: by 2002:a62:7b50:0:b029:3cd:e227:3486 with SMTP id w77-20020a627b500000b02903cde2273486mr3372294pfc.74.1629977152810; Thu, 26 Aug 2021 04:25:52 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:a5bc:b3dd:7208:bec1]) by smtp.gmail.com with ESMTPSA id s29sm3472057pgl.38.2021.08.26.04.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 04:25:52 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Aug 2021 20:25:34 +0900 Message-Id: <20210826112539.170694-5-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210826112539.170694-1-hiroh@chromium.org> References: <20210826112539.170694-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/9] 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. The mapped IPABuffer is represented and managed as MappedFrameBuffer. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/ipa/rkisp1/rkisp1.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 06fb9640..046816e0 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,22 +161,13 @@ 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; + MappedFrameBuffer mappedBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite); + if (!mappedBuffer.isValid()) { LOG(IPARkISP1, Fatal) << "Failed to mmap buffer: " - << strerror(-ret); + << strerror(mappedBuffer.error()); } + + mappedBuffers_.emplace(buffer.id, std::move(mappedBuffer)); } } @@ -186,8 +178,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 +191,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event) unsigned int bufferId = event.bufferId; const rkisp1_stat_buffer *stats = - static_cast(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_.at(bufferId).maps()[0].data()); updateStatistics(frame, stats); break; @@ -210,7 +202,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event) unsigned int bufferId = event.bufferId; rkisp1_params_cfg *params = - static_cast(buffersMemory_[bufferId]); + reinterpret_cast( + mappedBuffers_.at(bufferId).maps()[0].data()); queueRequest(frame, params, event.controls); break;