Show a patch.

GET /api/1.1/patches/13302/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 13302,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/13302/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13302/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210811124015.2116188-2-hiroh@chromium.org>",
    "date": "2021-08-11T12:40:11",
    "name": "[libcamera-devel,RFC,1/5] libcamera: mapped_framebuffer: Return plane begin address by MappedBuffer::maps()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f15b67f8d065a9e572e258b76ad4b58768b5093f",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/1.1/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13302/mbox/",
    "series": [
        {
            "id": 2339,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2339/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2339",
            "date": "2021-08-11T12:40:10",
            "name": "MappedFrameBuffer::maps() returns the plane address",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2339/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13302/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13302/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 D18EFBD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 11 Aug 2021 12:40:27 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8233E68889;\n\tWed, 11 Aug 2021 14:40:27 +0200 (CEST)",
            "from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com\n\t[IPv6:2607:f8b0:4864:20::1033])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5BD1568887\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Aug 2021 14:40:26 +0200 (CEST)",
            "by mail-pj1-x1033.google.com with SMTP id\n\tmq2-20020a17090b3802b0290178911d298bso4625321pjb.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 11 Aug 2021 05:40:26 -0700 (PDT)",
            "from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:ba11:c25e:242c:485d])\n\tby smtp.gmail.com with ESMTPSA id\n\tp30sm15722876pfh.116.2021.08.11.05.40.23\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 11 Aug 2021 05:40:24 -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=\"hd6C0FON\"; 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=lQiq0GEAYbCg/uzaZZgmDr/dO8jHINNLWTeG67DI18o=;\n\tb=hd6C0FONK/vS5+HpPPYsf0mBhNkEnZOs8OJoiaB8gQa6oCCkczZfWDtstvpaUxR1gq\n\tznFicgImUqrbkmZegTm6T2uXqzFKeXSyDv11WTed2t6ZVYc1qJrd76ob3Hjm6tHe829J\n\tV/nmCyW3mb9tPYG1wGSq/VGBpaTLsEQVrvraU=",
        "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=lQiq0GEAYbCg/uzaZZgmDr/dO8jHINNLWTeG67DI18o=;\n\tb=K1/1+TvjcW0Gqx5VL4dIabxun2jck3TYyPM7CCVsVfb9xjvBpeerBmcePcCIjuW0TR\n\ti976kelDKPLAtrprSphvrR+6hBHiCuOUqmmTwveBfzClG0VDmoBTduZ4lRyTgfO6ourG\n\t73FY5klJtgK2s3pHhFHLFb52c5RAnUsv9kTJ+1B30c1w1lDGjwXPR9zneh39bzhxZuV0\n\tzIIAGoQM2MaoZ4Rl5mtXcKZJOylfvQmGyVNC0P9iZE44KRVF6ZxEosV0dN1jI7sPV4xL\n\tc8FwzfXjN4DOkkRODyIz9oo2Fsya8KkwHexvN8OUFnwjQFtZiFrzixpX9efwugSGjhLK\n\tYb5g==",
        "X-Gm-Message-State": "AOAM530iWXJP8XNJW7gKzXi5qaT4o3ly6Py3eE65C5XwgcpFrGufzeGw\n\tsOSJvxZ0pbWh7wDizcc1U4YgNda4/9sSng==",
        "X-Google-Smtp-Source": "ABdhPJxzuCIgI0O0Zdun4srfar6sya/FsJJ7LimAsUo9YpaSQDyd4MkYgMVEcnCYjBMLBN/9CLTzIA==",
        "X-Received": "by 2002:a17:90b:3014:: with SMTP id\n\thg20mr25539426pjb.140.1628685624641; \n\tWed, 11 Aug 2021 05:40:24 -0700 (PDT)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 11 Aug 2021 21:40:11 +0900",
        "Message-Id": "<20210811124015.2116188-2-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.32.0.605.g8dce9f2422-goog",
        "In-Reply-To": "<20210811124015.2116188-1-hiroh@chromium.org>",
        "References": "<20210811124015.2116188-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [RFC PATCH 1/5] libcamera: mapped_framebuffer:\n\tReturn plane begin address by MappedBuffer::maps()",
        "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": "MappedBuffer::maps() returns std::vector<MappedBuffer::Plane>.\nPlane has the address, but the address points the beginning of the\nbuffer containing the plane.\nThis makes the Plane point the beginning of the plane. So\nMappedBuffer::maps()[i].data() returns the address of i-th plane.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n .../libcamera/internal/mapped_framebuffer.h   |  4 +-\n src/libcamera/mapped_framebuffer.cpp          | 59 +++++++++++++++----\n 2 files changed, 52 insertions(+), 11 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/mapped_framebuffer.h b/include/libcamera/internal/mapped_framebuffer.h\nindex 3401a9fc..42479541 100644\n--- a/include/libcamera/internal/mapped_framebuffer.h\n+++ b/include/libcamera/internal/mapped_framebuffer.h\n@@ -30,12 +30,14 @@ public:\n \n \tbool isValid() const { return error_ == 0; }\n \tint error() const { return error_; }\n-\tconst std::vector<Plane> &maps() const { return maps_; }\n+\t/* \\todo rename to planes(). */\n+\tconst std::vector<Plane> &maps() const { return planes_; }\n \n protected:\n \tMappedBuffer();\n \n \tint error_;\n+\tstd::vector<Plane> planes_;\n \tstd::vector<Plane> maps_;\n \n private:\ndiff --git a/src/libcamera/mapped_framebuffer.cpp b/src/libcamera/mapped_framebuffer.cpp\nindex 2ebe9fdb..5d5b02f1 100644\n--- a/src/libcamera/mapped_framebuffer.cpp\n+++ b/src/libcamera/mapped_framebuffer.cpp\n@@ -9,6 +9,7 @@\n \n #include <errno.h>\n #include <sys/mman.h>\n+#include <unistd.h>\n \n #include <libcamera/base/log.h>\n \n@@ -79,6 +80,7 @@ MappedBuffer::MappedBuffer(MappedBuffer &&other)\n MappedBuffer &MappedBuffer::operator=(MappedBuffer &&other)\n {\n \terror_ = other.error_;\n+\tplanes_ = std::move(other.planes_);\n \tmaps_ = std::move(other.maps_);\n \tother.error_ = -ENOENT;\n \n@@ -127,10 +129,18 @@ MappedBuffer::~MappedBuffer()\n  */\n \n /**\n- * \\var MappedBuffer::maps_\n+ * \\var MappedBuffer::planes_\n  * \\brief Stores the internal mapped planes\n  *\n  * MappedBuffer derived classes shall store the mappings they create in this\n+ * vector which points the beginning of mapped plane addresses.\n+ */\n+\n+/**\n+ * \\var MappedBuffer::maps_\n+ * \\brief Stores the mapped buffer\n+ *\n+ * MappedBuffer derived classes shall store the mappings they create in this\n  * vector which is parsed during destruct to unmap any memory mappings which\n  * completed successfully.\n  */\n@@ -167,7 +177,8 @@ MappedBuffer::~MappedBuffer()\n  */\n MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n {\n-\tmaps_.reserve(buffer->planes().size());\n+\tASSERT(!buffer->planes().empty());\n+\tplanes_.reserve(buffer->planes().size());\n \n \tint mmapFlags = 0;\n \n@@ -177,18 +188,46 @@ MappedFrameBuffer::MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags)\n \tif (flags & MapFlag::Write)\n \t\tmmapFlags |= PROT_WRITE;\n \n+\tsize_t offset = 0;\n+\tint prevFd = -1;\n \tfor (const FrameBuffer::Plane &plane : buffer->planes()) {\n-\t\tvoid *address = mmap(nullptr, plane.length, mmapFlags,\n-\t\t\t\t     MAP_SHARED, plane.fd.fd(), 0);\n-\t\tif (address == MAP_FAILED) {\n-\t\t\terror_ = -errno;\n-\t\t\tLOG(Buffer, Error) << \"Failed to mmap plane: \"\n-\t\t\t\t\t   << strerror(-error_);\n-\t\t\tbreak;\n+\t\tconst int fd = plane.fd.fd();\n+\t\tif (prevFd != fd) {\n+\t\t\tconst size_t length = lseek(fd, 0, SEEK_END);\n+\t\t\tvoid *address = mmap(nullptr, length, mmapFlags,\n+\t\t\t\t\t     MAP_SHARED, fd, 0);\n+\t\t\tif (address == MAP_FAILED) {\n+\t\t\t\terror_ = -errno;\n+\t\t\t\tLOG(Buffer, Error) << \"Failed to mmap plane: \"\n+\t\t\t\t\t\t   << strerror(-error_);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tmaps_.emplace_back(static_cast<uint8_t *>(address),\n+\t\t\t\t\t   length);\n+\t\t\tprevFd = fd;\n \t\t}\n \n-\t\tmaps_.emplace_back(static_cast<uint8_t *>(address), plane.length);\n+\t\tASSERT(!maps_.empty());\n+\t\tuint8_t *buf = maps_.back().data();\n+\t\tconst size_t length = maps_.back().size();\n+\n+\t\t/*\n+\t\t * This offset calculation assumes planes are consecutive.\n+\t\t * \\todo remove this assumption once offset is introduced to\n+\t\t * FrameBuffer::Plane.\n+\t\t */\n+\t\tplanes_.emplace_back(buf + offset, plane.length);\n+\t\toffset += plane.length;\n+\n+\t\tif (offset > length) {\n+\t\t\tLOG(Buffer, Fatal)\n+\t\t\t\t<< \"plane length is too large: plane lengths=\"\n+\t\t\t\t<< offset << \", buffer length=\" << length;\n+\t\t\tbreak;\n+\t\t}\n \t}\n+\n+\tASSERT(maps_.size() == 1);\n }\n \n } /* namespace libcamera */\n",
    "prefixes": [
        "libcamera-devel",
        "RFC",
        "1/5"
    ]
}