{"id":13505,"url":"https://patchwork.libcamera.org/api/1.1/patches/13505/?format=json","web_url":"https://patchwork.libcamera.org/patch/13505/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210826112539.170694-5-hiroh@chromium.org>","date":"2021-08-26T11:25:34","name":"[libcamera-devel,v3,4/9] ipa: rkisp1: Use offset in mapping IPABuffer","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"eafe6bb939dd24b11a790de4e95e73db77eecfdf","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13505/mbox/","series":[{"id":2398,"url":"https://patchwork.libcamera.org/api/1.1/series/2398/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2398","date":"2021-08-26T11:25:30","name":"Add offset to FrameBuffer::Plane","version":3,"mbox":"https://patchwork.libcamera.org/series/2398/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13505/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13505/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 62040BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 26 Aug 2021 11:25:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 14FC2688E5;\n\tThu, 26 Aug 2021 13:25:57 +0200 (CEST)","from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com\n\t[IPv6:2607:f8b0:4864:20::52a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E0A268919\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 13:25:54 +0200 (CEST)","by mail-pg1-x52a.google.com with SMTP id x4so2823140pgh.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 Aug 2021 04:25:54 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:a5bc:b3dd:7208:bec1])\n\tby smtp.gmail.com with ESMTPSA id\n\ts29sm3472057pgl.38.2021.08.26.04.25.51\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 26 Aug 2021 04:25:52 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"dDT5kqFK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=7WvogKrN3bFtWOlOa6LHh6IQxO3Sjs4Hr9+xtUUr+hI=;\n\tb=dDT5kqFKNx271UQC7hby897M1T4YQEDUUrEX0Liz3Lp7Pwg7TE34bDxcwgADFSNror\n\t5YAkHfcft890/ksNF+8kbej6sI6yYVuQC0ju5a7+esw3Q9/rJaemYb+Vt6n60xuAn5pX\n\tiy3yJr9v7GFjHGUA9XIAzjFkCpww0js7XJ9zs=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=7WvogKrN3bFtWOlOa6LHh6IQxO3Sjs4Hr9+xtUUr+hI=;\n\tb=KFbRYcuj9eqaSOn2qaiVBchCgK9iVzkhjqL9poanx7AKgdmUAfa3MafeDe6Lh+PkBV\n\tOUNgdUYvEW7jbUcNUCXQfRTu8mtmhavobon9Jbl2OF3motwEULvVt5XSve9T5/aACXKc\n\tH+NJIcYY+rJFa79B+//pJ40fXcZKA+Cr03EKZHRAQjs7lFESOt9LdovtKU39e6CPx/o8\n\tTfqTvj8kSqnrcoygmtKM1wLMtzv1dtRpJtoO5+bhwrvplDx4d7ryTUvJ9LEDjuTBb/Yw\n\t/1PF/Jc32no0MHP9GlL4NInIpbm2SDIVhit12NsemF/4I9FxeRVD9m0+EpxwHr3JLIDC\n\tflrg==","X-Gm-Message-State":"AOAM5335wH+qiizTWJnsOsKn+TCC2vFW3hfr97a3qoL831fL4gBmtjvj\n\tt9107rL544ZLQyMQCEWG8u4th9oQib889w==","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\n\tw77-20020a627b500000b02903cde2273486mr3372294pfc.74.1629977152810; \n\tThu, 26 Aug 2021 04:25:52 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 4/9] ipa: rkisp1: Use offset in mapping\n\tIPABuffer","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"IPABuffer is represented by FrameBuffer. FrameBuffer::Plane has\nnow an offset. This uses the offset variable to map the IPABuffer.\nThe mapped IPABuffer is represented and managed as MappedFrameBuffer.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/ipa/rkisp1/rkisp1.cpp | 33 +++++++++++++--------------------\n 1 file changed, 13 insertions(+), 20 deletions(-)","diff":"diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\nindex 06fb9640..046816e0 100644\n--- a/src/ipa/rkisp1/rkisp1.cpp\n+++ b/src/ipa/rkisp1/rkisp1.cpp\n@@ -10,7 +10,6 @@\n #include <queue>\n #include <stdint.h>\n #include <string.h>\n-#include <sys/mman.h>\n \n #include <linux/rkisp1-config.h>\n #include <linux/v4l2-controls.h>\n@@ -24,6 +23,8 @@\n #include <libcamera/ipa/rkisp1_ipa_interface.h>\n #include <libcamera/request.h>\n \n+#include <libcamera/internal/mapped_framebuffer.h>\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(IPARkISP1)\n@@ -54,7 +55,7 @@ private:\n \tvoid metadataReady(unsigned int frame, unsigned int aeState);\n \n \tstd::map<unsigned int, FrameBuffer> buffers_;\n-\tstd::map<unsigned int, void *> buffersMemory_;\n+\tstd::map<unsigned int, MappedFrameBuffer> mappedBuffers_;\n \n \tControlInfoMap ctrls_;\n \n@@ -160,22 +161,13 @@ void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers)\n \t\t\t\t\t     std::forward_as_tuple(buffer.planes));\n \t\tconst FrameBuffer &fb = elem.first->second;\n \n-\t\t/*\n-\t\t * \\todo Provide a helper to mmap() buffers (possibly exposed\n-\t\t * to applications).\n-\t\t */\n-\t\tbuffersMemory_[buffer.id] = mmap(NULL,\n-\t\t\t\t\t\t fb.planes()[0].length,\n-\t\t\t\t\t\t PROT_READ | PROT_WRITE,\n-\t\t\t\t\t\t MAP_SHARED,\n-\t\t\t\t\t\t fb.planes()[0].fd.fd(),\n-\t\t\t\t\t\t 0);\n-\n-\t\tif (buffersMemory_[buffer.id] == MAP_FAILED) {\n-\t\t\tint ret = -errno;\n+\t\tMappedFrameBuffer mappedBuffer(&fb, MappedFrameBuffer::MapFlag::ReadWrite);\n+\t\tif (!mappedBuffer.isValid()) {\n \t\t\tLOG(IPARkISP1, Fatal) << \"Failed to mmap buffer: \"\n-\t\t\t\t\t      << strerror(-ret);\n+\t\t\t\t\t      << strerror(mappedBuffer.error());\n \t\t}\n+\n+\t\tmappedBuffers_.emplace(buffer.id, std::move(mappedBuffer));\n \t}\n }\n \n@@ -186,8 +178,7 @@ void IPARkISP1::unmapBuffers(const std::vector<unsigned int> &ids)\n \t\tif (fb == buffers_.end())\n \t\t\tcontinue;\n \n-\t\tmunmap(buffersMemory_[id], fb->second.planes()[0].length);\n-\t\tbuffersMemory_.erase(id);\n+\t\tmappedBuffers_.erase(id);\n \t\tbuffers_.erase(id);\n \t}\n }\n@@ -200,7 +191,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event)\n \t\tunsigned int bufferId = event.bufferId;\n \n \t\tconst rkisp1_stat_buffer *stats =\n-\t\t\tstatic_cast<rkisp1_stat_buffer *>(buffersMemory_[bufferId]);\n+\t\t\treinterpret_cast<rkisp1_stat_buffer *>(\n+\t\t\t\tmappedBuffers_.at(bufferId).maps()[0].data());\n \n \t\tupdateStatistics(frame, stats);\n \t\tbreak;\n@@ -210,7 +202,8 @@ void IPARkISP1::processEvent(const RkISP1Event &event)\n \t\tunsigned int bufferId = event.bufferId;\n \n \t\trkisp1_params_cfg *params =\n-\t\t\tstatic_cast<rkisp1_params_cfg *>(buffersMemory_[bufferId]);\n+\t\t\treinterpret_cast<rkisp1_params_cfg *>(\n+\t\t\t\tmappedBuffers_.at(bufferId).maps()[0].data());\n \n \t\tqueueRequest(frame, params, event.controls);\n \t\tbreak;\n","prefixes":["libcamera-devel","v3","4/9"]}