[{"id":11422,"web_url":"https://patchwork.libcamera.org/comment/11422/","msgid":"<CAEmqJPpP_9eQ1-caegkserW9wwYiRzhHFpZaU=4rYthwYGnJkw@mail.gmail.com>","date":"2020-07-17T06:22:19","subject":"Re: [libcamera-devel] [PATCH v3 2/2] libcamera: pipeline: ipa:\n\traspberrypi: Use dma heap allocs for LS tables","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Laurent,\n\nThank you for the changes.\n\nOn Fri, 17 Jul 2020 at 01:15, Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> From: Naushir Patuck <naush@raspberrypi.com>\n>\n> Remove use of vcsm allocations and replace with dma heap allocations.\n> The pipeline handler now passes the fd of the allocation over to the IPA\n> instead of the raw pointer.\n>\n> Also use libcamera::FileDescriptor for fd lifetime management.\n>\n> This commit must be built alongside the accompanying BCM2835 ISP kernel\n> driver changes at https://github.com/raspberrypi/linux/pull/3715.\n> Otherwise a mismatch will cause undefined behavior.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n> ---\n>  include/linux/bcm2835-isp.h                   |   4 +-\n>  include/linux/vc_sm_cma_ioctl.h               | 135 ----------------\n>  src/ipa/raspberrypi/raspberrypi.cpp           |  28 +++-\n>  .../pipeline/raspberrypi/dma_heaps.cpp        |  84 ++++++++++\n>  .../pipeline/raspberrypi/dma_heaps.h          |  31 ++++\n>  .../pipeline/raspberrypi/meson.build          |   1 +\n>  .../pipeline/raspberrypi/raspberrypi.cpp      |  49 ++----\n>  src/libcamera/pipeline/raspberrypi/vcsm.h     | 149 ------------------\n>  8 files changed, 154 insertions(+), 327 deletions(-)\n>  delete mode 100644 include/linux/vc_sm_cma_ioctl.h\n>  create mode 100644 src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n>  create mode 100644 src/libcamera/pipeline/raspberrypi/dma_heaps.h\n>  delete mode 100644 src/libcamera/pipeline/raspberrypi/vcsm.h\n>\n> diff --git a/include/linux/bcm2835-isp.h b/include/linux/bcm2835-isp.h\n> index e7afc367fd76..45abb681517e 100644\n> --- a/include/linux/bcm2835-isp.h\n> +++ b/include/linux/bcm2835-isp.h\n> @@ -108,7 +108,7 @@ enum bcm2835_isp_gain_format {\n>   * @grid_stride:       Row to row distance (in grid cells) between grid cells\n>   *                     in the same horizontal location.\n>   * @grid_height:       Height of lens shading tables in grid cells.\n> - * @mem_handle_table:  Memory handle to the tables.\n> + * @dmabuf:            dmabuf file handle containing the table.\n>   * @ref_transform:     Reference transform - unsupported, please pass zero.\n>   * @corner_sampled:    Whether the gains are sampled at the corner points\n>   *                     of the grid cells or in the cell centres.\n> @@ -120,7 +120,7 @@ struct bcm2835_isp_lens_shading {\n>         __u32 grid_width;\n>         __u32 grid_stride;\n>         __u32 grid_height;\n> -       __u32 mem_handle_table;\n> +       __s32 dmabuf;\n>         __u32 ref_transform;\n>         __u32 corner_sampled;\n>         __u32 gain_format;\n> diff --git a/include/linux/vc_sm_cma_ioctl.h b/include/linux/vc_sm_cma_ioctl.h\n> deleted file mode 100644\n> index 21b8758ea03f..000000000000\n> --- a/include/linux/vc_sm_cma_ioctl.h\n> +++ /dev/null\n> @@ -1,135 +0,0 @@\n> -/*\n> -Copyright (c) 2012, Broadcom Europe Ltd\n> -All rights reserved.\n> -\n> -Redistribution and use in source and binary forms, with or without\n> -modification, are permitted provided that the following conditions are met:\n> -    * Redistributions of source code must retain the above copyright\n> -      notice, this list of conditions and the following disclaimer.\n> -    * Redistributions in binary form must reproduce the above copyright\n> -      notice, this list of conditions and the following disclaimer in the\n> -      documentation and/or other materials provided with the distribution.\n> -    * Neither the name of the copyright holder nor the\n> -      names of its contributors may be used to endorse or promote products\n> -      derived from this software without specific prior written permission.\n> -\n> -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n> -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n> -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n> -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY\n> -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n> -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n> -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n> -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n> -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n> -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n> -*/\n> -\n> -/*\n> - * Copyright 2019 Raspberry Pi (Trading) Ltd.  All rights reserved.\n> - *\n> - * Based on vmcs_sm_ioctl.h Copyright Broadcom Corporation.\n> - */\n> -\n> -#ifndef __VC_SM_CMA_IOCTL_H\n> -#define __VC_SM_CMA_IOCTL_H\n> -\n> -/* ---- Include Files ---------------------------------------------------- */\n> -\n> -#include <linux/types.h>       /* Needed for standard types */\n> -\n> -#include <linux/ioctl.h>\n> -\n> -/* ---- Constants and Types ---------------------------------------------- */\n> -\n> -#define VC_SM_CMA_RESOURCE_NAME               32\n> -#define VC_SM_CMA_RESOURCE_NAME_DEFAULT       \"sm-host-resource\"\n> -\n> -/* Type define used to create unique IOCTL number */\n> -#define VC_SM_CMA_MAGIC_TYPE                  'J'\n> -\n> -/* IOCTL commands on /dev/vc-sm-cma */\n> -enum vc_sm_cma_cmd_e {\n> -       VC_SM_CMA_CMD_ALLOC = 0x5A,     /* Start at 0x5A arbitrarily */\n> -\n> -       VC_SM_CMA_CMD_IMPORT_DMABUF,\n> -\n> -       VC_SM_CMA_CMD_CLEAN_INVALID2,\n> -\n> -       VC_SM_CMA_CMD_LAST      /* Do not delete */\n> -};\n> -\n> -/* Cache type supported, conveniently matches the user space definition in\n> - * user-vcsm.h.\n> - */\n> -enum vc_sm_cma_cache_e {\n> -       VC_SM_CMA_CACHE_NONE,\n> -       VC_SM_CMA_CACHE_HOST,\n> -       VC_SM_CMA_CACHE_VC,\n> -       VC_SM_CMA_CACHE_BOTH,\n> -};\n> -\n> -/* IOCTL Data structures */\n> -struct vc_sm_cma_ioctl_alloc {\n> -       /* user -> kernel */\n> -       __u32 size;\n> -       __u32 num;\n> -       __u32 cached;           /* enum vc_sm_cma_cache_e */\n> -       __u32 pad;\n> -       __u8 name[VC_SM_CMA_RESOURCE_NAME];\n> -\n> -       /* kernel -> user */\n> -       __s32 handle;\n> -       __u32 vc_handle;\n> -       __u64 dma_addr;\n> -};\n> -\n> -struct vc_sm_cma_ioctl_import_dmabuf {\n> -       /* user -> kernel */\n> -       __s32 dmabuf_fd;\n> -       __u32 cached;           /* enum vc_sm_cma_cache_e */\n> -       __u8 name[VC_SM_CMA_RESOURCE_NAME];\n> -\n> -       /* kernel -> user */\n> -       __s32 handle;\n> -       __u32 vc_handle;\n> -       __u32 size;\n> -       __u32 pad;\n> -       __u64 dma_addr;\n> -};\n> -\n> -/*\n> - * Cache functions to be set to struct vc_sm_cma_ioctl_clean_invalid2\n> - * invalidate_mode.\n> - */\n> -#define VC_SM_CACHE_OP_NOP       0x00\n> -#define VC_SM_CACHE_OP_INV       0x01\n> -#define VC_SM_CACHE_OP_CLEAN     0x02\n> -#define VC_SM_CACHE_OP_FLUSH     0x03\n> -\n> -struct vc_sm_cma_ioctl_clean_invalid2 {\n> -       __u32 op_count;\n> -       __u32 pad;\n> -       struct vc_sm_cma_ioctl_clean_invalid_block {\n> -               __u32 invalidate_mode;\n> -               __u32 block_count;\n> -               void *  /*__user */start_address;\n> -               __u32 block_size;\n> -               __u32 inter_block_stride;\n> -       } s[0];\n> -};\n> -\n> -/* IOCTL numbers */\n> -#define VC_SM_CMA_IOCTL_MEM_ALLOC\\\n> -       _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_ALLOC,\\\n> -        struct vc_sm_cma_ioctl_alloc)\n> -\n> -#define VC_SM_CMA_IOCTL_MEM_IMPORT_DMABUF\\\n> -       _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_IMPORT_DMABUF,\\\n> -        struct vc_sm_cma_ioctl_import_dmabuf)\n> -\n> -#define VC_SM_CMA_IOCTL_MEM_CLEAN_INVALID2\\\n> -       _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_CLEAN_INVALID2,\\\n> -        struct vc_sm_cma_ioctl_clean_invalid2)\n> -\n> -#endif /* __VC_SM_CMA_IOCTL_H */\n> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\n> index 2fcbc782f8b8..7bd0488089e8 100644\n> --- a/src/ipa/raspberrypi/raspberrypi.cpp\n> +++ b/src/ipa/raspberrypi/raspberrypi.cpp\n> @@ -15,6 +15,7 @@\n>  #include <libcamera/buffer.h>\n>  #include <libcamera/control_ids.h>\n>  #include <libcamera/controls.h>\n> +#include <libcamera/file_descriptor.h>\n>  #include <libcamera/ipa/ipa_interface.h>\n>  #include <libcamera/ipa/ipa_module_info.h>\n>  #include <libcamera/ipa/raspberrypi.h>\n> @@ -65,12 +66,14 @@ public:\n>         IPARPi()\n>                 : lastMode_({}), controller_(), controllerInit_(false),\n>                   frame_count_(0), check_count_(0), hide_count_(0),\n> -                 mistrust_count_(0), lsTableHandle_(0), lsTable_(nullptr)\n> +                 mistrust_count_(0), lsTable_(nullptr)\n>         {\n>         }\n>\n>         ~IPARPi()\n>         {\n> +               if (lsTable_)\n> +                       munmap(lsTable_, MAX_LS_GRID_SIZE);\n>         }\n>\n>         int init(const IPASettings &settings) override;\n> @@ -139,7 +142,7 @@ private:\n>         /* How many frames we should avoid running control algos on. */\n>         unsigned int mistrust_count_;\n>         /* LS table allocation passed in from the pipeline handler. */\n> -       uint32_t lsTableHandle_;\n> +       FileDescriptor lsTableHandle_;\n>         void *lsTable_;\n>  };\n>\n> @@ -280,8 +283,23 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n>\n>         /* Store the lens shading table pointer and handle if available. */\n>         if (ipaConfig.operation & RPI_IPA_CONFIG_LS_TABLE) {\n> -               lsTable_ = reinterpret_cast<void *>(ipaConfig.data[0]);\n> -               lsTableHandle_ = ipaConfig.data[1];\n> +               /* Remove any previous table, if there was one. */\n> +               if (lsTable_) {\n> +                       munmap(lsTable_, MAX_LS_GRID_SIZE);\n> +                       lsTable_ = nullptr;\n> +               }\n> +\n> +               /* Map the LS table buffer into user space. */\n> +               lsTableHandle_ = FileDescriptor(ipaConfig.data[0]);\n> +               if (lsTableHandle_.isValid()) {\n> +                       lsTable_ = mmap(nullptr, MAX_LS_GRID_SIZE, PROT_READ | PROT_WRITE,\n> +                                       MAP_SHARED, lsTableHandle_.fd(), 0);\n> +\n> +                       if (lsTable_ == MAP_FAILED) {\n> +                               LOG(IPARPI, Error) << \"dmaHeap mmap failure for LS table.\";\n> +                               lsTable_ = nullptr;\n> +                       }\n> +               }\n>         }\n>  }\n>\n> @@ -1030,7 +1048,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)\n>                 .grid_width = w,\n>                 .grid_stride = w,\n>                 .grid_height = h,\n> -               .mem_handle_table = lsTableHandle_,\n> +               .dmabuf = lsTableHandle_.fd(),\n>                 .ref_transform = 0,\n>                 .corner_sampled = 1,\n>                 .gain_format = GAIN_FORMAT_U4P10\n> diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> new file mode 100644\n> index 000000000000..6769c04640f1\n> --- /dev/null\n> +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.cpp\n> @@ -0,0 +1,84 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * dma_heaps.h - Helper class for dma-heap allocations.\n> + */\n> +\n> +#include \"dma_heaps.h\"\n> +\n> +#include <fcntl.h>\n> +#include <linux/dma-buf.h>\n> +#include <linux/dma-heap.h>\n> +#include <sys/ioctl.h>\n> +#include <unistd.h>\n> +\n> +#include \"libcamera/internal/log.h\"\n> +\n> +/*\n> + * /dev/dma-heap/linux,cma is the dma-heap allocator, which allows dmaheap-cma\n> + * to only have to worry about importing.\n> + *\n> + * Annoyingly, should the cma heap size be specified on the kernel command line\n> + * instead of DT, the heap gets named \"reserved\" instead.\n> + */\n> +#define DMA_HEAP_CMA_NAME \"/dev/dma_heap/linux,cma\"\n> +#define DMA_HEAP_CMA_ALT_NAME \"/dev/dma_heap/reserved\"\n> +\n> +namespace libcamera {\n> +\n> +LOG_DECLARE_CATEGORY(RPI)\n> +\n> +namespace RPi {\n> +\n> +DmaHeap::DmaHeap()\n> +{\n> +       dmaHeapHandle_ = ::open(DMA_HEAP_CMA_NAME, O_RDWR, 0);\n> +       if (dmaHeapHandle_ == -1) {\n> +               dmaHeapHandle_ = ::open(DMA_HEAP_CMA_ALT_NAME, O_RDWR, 0);\n> +               if (dmaHeapHandle_ == -1) {\n> +                       LOG(RPI, Error) << \"Could not open dmaHeap device\";\n> +               }\n> +       }\n> +}\n> +\n> +DmaHeap::~DmaHeap()\n> +{\n> +       if (dmaHeapHandle_)\n> +               ::close(dmaHeapHandle_);\n> +}\n> +\n> +FileDescriptor DmaHeap::alloc(const char *name, std::size_t size)\n> +{\n> +       int ret;\n> +\n> +       if (!name)\n> +               return FileDescriptor();\n> +\n> +       struct dma_heap_allocation_data alloc = {};\n> +\n> +       alloc.len = size;\n> +       alloc.fd_flags = O_CLOEXEC | O_RDWR;\n> +\n> +       ret = ::ioctl(dmaHeapHandle_, DMA_HEAP_IOCTL_ALLOC, &alloc);\n> +\n> +       if (ret < 0) {\n> +               LOG(RPI, Error) << \"dmaHeap allocation failure for \"\n> +                               << name;\n> +               return FileDescriptor();\n> +       }\n> +\n> +       ret = ::ioctl(alloc.fd, DMA_BUF_SET_NAME, name);\n> +       if (ret < 0) {\n> +               LOG(RPI, Error) << \"dmaHeap naming failure for \"\n> +                               << name;\n> +               ::close(alloc.fd);\n> +               return FileDescriptor();\n> +       }\n> +\n> +       return FileDescriptor(std::move(alloc.fd));\n> +}\n> +\n> +} /* namespace RPi */\n> +\n> +} /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/raspberrypi/dma_heaps.h b/src/libcamera/pipeline/raspberrypi/dma_heaps.h\n> new file mode 100644\n> index 000000000000..ae6be1135f17\n> --- /dev/null\n> +++ b/src/libcamera/pipeline/raspberrypi/dma_heaps.h\n> @@ -0,0 +1,31 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * dma_heaps.h - Helper class for dma-heap allocations.\n> + */\n> +#ifndef __LIBCAMERA_PIPELINE_RASPBERRYPI_DMA_HEAPS_H__\n> +#define __LIBCAMERA_PIPELINE_RASPBERRYPI_DMA_HEAPS_H__\n> +\n> +#include <libcamera/file_descriptor.h>\n> +\n> +namespace libcamera {\n> +\n> +namespace RPi {\n> +\n> +class DmaHeap\n> +{\n> +public:\n> +       DmaHeap();\n> +       ~DmaHeap();\n> +       FileDescriptor alloc(const char *name, std::size_t size);\n> +\n> +private:\n> +       int dmaHeapHandle_;\n> +};\n> +\n> +} /* namespace RPi */\n> +\n> +} /* namespace libcamera */\n> +\n> +#endif /* __LIBCAMERA_PIPELINE_RASPBERRYPI_DMA_HEAPS_H__ */\n> diff --git a/src/libcamera/pipeline/raspberrypi/meson.build b/src/libcamera/pipeline/raspberrypi/meson.build\n> index dcfe07c5b720..ae0aed3b5234 100644\n> --- a/src/libcamera/pipeline/raspberrypi/meson.build\n> +++ b/src/libcamera/pipeline/raspberrypi/meson.build\n> @@ -1,6 +1,7 @@\n>  # SPDX-License-Identifier: CC0-1.0\n>\n>  libcamera_sources += files([\n> +    'dma_heaps.cpp',\n>      'raspberrypi.cpp',\n>      'staggered_ctrl.cpp',\n>  ])\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 718749af5a6e..bf1c77144f85 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -13,6 +13,7 @@\n>\n>  #include <libcamera/camera.h>\n>  #include <libcamera/control_ids.h>\n> +#include <libcamera/file_descriptor.h>\n>  #include <libcamera/formats.h>\n>  #include <libcamera/ipa/raspberrypi.h>\n>  #include <libcamera/logging.h>\n> @@ -31,8 +32,8 @@\n>  #include \"libcamera/internal/v4l2_controls.h\"\n>  #include \"libcamera/internal/v4l2_videodevice.h\"\n>\n> +#include \"dma_heaps.h\"\n>  #include \"staggered_ctrl.h\"\n> -#include \"vcsm.h\"\n>\n>  namespace libcamera {\n>\n> @@ -286,24 +287,11 @@ class RPiCameraData : public CameraData\n>  {\n>  public:\n>         RPiCameraData(PipelineHandler *pipe)\n> -               : CameraData(pipe), sensor_(nullptr), lsTable_(nullptr),\n> -                 state_(State::Stopped), dropFrame_(false), ispOutputCount_(0)\n> +               : CameraData(pipe), sensor_(nullptr), state_(State::Stopped),\n> +                 dropFrame_(false), ispOutputCount_(0)\n>         {\n>         }\n>\n> -       ~RPiCameraData()\n> -       {\n> -               /*\n> -                * Free the LS table if we have allocated one. Another\n> -                * allocation will occur in applyLS() with the appropriate\n> -                * size.\n> -                */\n> -               if (lsTable_) {\n> -                       vcsm_.free(lsTable_);\n> -                       lsTable_ = nullptr;\n> -               }\n> -       }\n> -\n>         void frameStarted(uint32_t sequence);\n>\n>         int loadIPA();\n> @@ -329,9 +317,9 @@ public:\n>         /* Buffers passed to the IPA. */\n>         std::vector<IPABuffer> ipaBuffers_;\n>\n> -       /* VCSM allocation helper. */\n> -       ::RPi::Vcsm vcsm_;\n> -       void *lsTable_;\n> +       /* DMAHEAP allocation helper. */\n> +       RPi::DmaHeap dmaHeap_;\n> +       FileDescriptor lsTable_;\n>\n>         RPi::StaggeredCtrl staggeredCtrl_;\n>         uint32_t expectedSequence_;\n> @@ -1142,26 +1130,15 @@ int RPiCameraData::configureIPA()\n>         entityControls.emplace(0, unicam_[Unicam::Image].dev()->controls());\n>         entityControls.emplace(1, isp_[Isp::Input].dev()->controls());\n>\n> -       /* Allocate the lens shading table via vcsm and pass to the IPA. */\n> -       if (!lsTable_) {\n> -               lsTable_ = vcsm_.alloc(\"ls_grid\", MAX_LS_GRID_SIZE);\n> -               uintptr_t ptr = reinterpret_cast<uintptr_t>(lsTable_);\n> -\n> -               if (!lsTable_)\n> +       /* Allocate the lens shading table via dmaHeap and pass to the IPA. */\n> +       if (!lsTable_.isValid()) {\n> +               lsTable_ = dmaHeap_.alloc(\"ls_grid\", MAX_LS_GRID_SIZE);\n> +               if (!lsTable_.isValid())\n>                         return -ENOMEM;\n>\n> -               /*\n> -                * The vcsm allocation will always be in the memory region\n> -                * < 32-bits to allow Videocore to access the memory.\n> -                *\n> -                * \\todo Sending a pointer to the IPA is a workaround for\n> -                * vc_sm_cma not yet supporting dmabuf. This will not work with\n> -                * IPA module isolation and should be reworked when vc_sma_cma\n> -                * will permit.\n> -                */\n> +               /* Allow the IPA to mmap the LS table via the file descriptor. */\n>                 ipaConfig.operation = RPI_IPA_CONFIG_LS_TABLE;\n> -               ipaConfig.data = { static_cast<uint32_t>(ptr & 0xffffffff),\n> -                                  vcsm_.getVCHandle(lsTable_) };\n> +               ipaConfig.data = { static_cast<unsigned int>(lsTable_.fd()) };\n>         }\n>\n>         CameraSensorInfo sensorInfo = {};\n> diff --git a/src/libcamera/pipeline/raspberrypi/vcsm.h b/src/libcamera/pipeline/raspberrypi/vcsm.h\n> deleted file mode 100644\n> index bebe86a76450..000000000000\n> --- a/src/libcamera/pipeline/raspberrypi/vcsm.h\n> +++ /dev/null\n> @@ -1,149 +0,0 @@\n> -/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> -/*\n> - * Copyright (C) 2019, Raspberry Pi (Trading) Limited\n> - *\n> - * vcsm.h - Helper class for vcsm allocations.\n> - */\n> -#ifndef __LIBCAMERA_PIPELINE_RASPBERRYPI_VCSM_H__\n> -#define __LIBCAMERA_PIPELINE_RASPBERRYPI_VCSM_H__\n> -\n> -#include <iostream>\n> -#include <mutex>\n> -\n> -#include <fcntl.h>\n> -#include <linux/vc_sm_cma_ioctl.h>\n> -#include <sys/ioctl.h>\n> -#include <sys/mman.h>\n> -#include <unistd.h>\n> -\n> -namespace RPi {\n> -\n> -#define VCSM_CMA_DEVICE_NAME \"/dev/vcsm-cma\"\n> -\n> -class Vcsm\n> -{\n> -public:\n> -       Vcsm()\n> -       {\n> -               vcsmHandle_ = ::open(VCSM_CMA_DEVICE_NAME, O_RDWR, 0);\n> -               if (vcsmHandle_ == -1) {\n> -                       std::cerr << \"Could not open vcsm device: \"\n> -                                 << VCSM_CMA_DEVICE_NAME;\n> -               }\n> -       }\n> -\n> -       ~Vcsm()\n> -       {\n> -               /* Free all existing allocations. */\n> -               auto it = allocMap_.begin();\n> -               while (it != allocMap_.end())\n> -                       it = remove(it->first);\n> -\n> -               if (vcsmHandle_)\n> -                       ::close(vcsmHandle_);\n> -       }\n> -\n> -       void *alloc(const char *name, unsigned int size,\n> -                   vc_sm_cma_cache_e cache = VC_SM_CMA_CACHE_NONE)\n> -       {\n> -               unsigned int pageSize = getpagesize();\n> -               void *user_ptr;\n> -               int ret;\n> -\n> -               if (!name)\n> -                       return nullptr;\n> -\n> -               /* Ask for page aligned allocation. */\n> -               size = (size + pageSize - 1) & ~(pageSize - 1);\n> -\n> -               struct vc_sm_cma_ioctl_alloc alloc;\n> -               memset(&alloc, 0, sizeof(alloc));\n> -               alloc.size = size;\n> -               alloc.num = 1;\n> -               alloc.cached = cache;\n> -               alloc.handle = 0;\n> -               memcpy(alloc.name, name, 32);\n> -\n> -               ret = ::ioctl(vcsmHandle_, VC_SM_CMA_IOCTL_MEM_ALLOC, &alloc);\n> -\n> -               if (ret < 0 || alloc.handle < 0) {\n> -                       std::cerr << \"vcsm allocation failure for \"\n> -                                 << name << std::endl;\n> -                       return nullptr;\n> -               }\n> -\n> -               /* Map the buffer into user space. */\n> -               user_ptr = ::mmap(0, alloc.size, PROT_READ | PROT_WRITE,\n> -                                 MAP_SHARED, alloc.handle, 0);\n> -\n> -               if (user_ptr == MAP_FAILED) {\n> -                       std::cerr << \"vcsm mmap failure for \" << name << std::endl;\n> -                       ::close(alloc.handle);\n> -                       return nullptr;\n> -               }\n> -\n> -               std::lock_guard<std::mutex> lock(lock_);\n> -               allocMap_.emplace(user_ptr, AllocInfo(alloc.handle,\n> -                                                     alloc.size, alloc.vc_handle));\n> -\n> -               return user_ptr;\n> -       }\n> -\n> -       void free(void *user_ptr)\n> -       {\n> -               std::lock_guard<std::mutex> lock(lock_);\n> -               remove(user_ptr);\n> -       }\n> -\n> -       unsigned int getVCHandle(void *user_ptr)\n> -       {\n> -               std::lock_guard<std::mutex> lock(lock_);\n> -               auto it = allocMap_.find(user_ptr);\n> -               if (it != allocMap_.end())\n> -                       return it->second.vcHandle;\n> -\n> -               return 0;\n> -       }\n> -\n> -private:\n> -       struct AllocInfo {\n> -               AllocInfo(int handle_, int size_, int vcHandle_)\n> -                       : handle(handle_), size(size_), vcHandle(vcHandle_)\n> -               {\n> -               }\n> -\n> -               int handle;\n> -               int size;\n> -               uint32_t vcHandle;\n> -       };\n> -\n> -       /* Map of all allocations that have been requested. */\n> -       using AllocMap = std::map<void *, AllocInfo>;\n> -\n> -       AllocMap::iterator remove(void *user_ptr)\n> -       {\n> -               auto it = allocMap_.find(user_ptr);\n> -               if (it != allocMap_.end()) {\n> -                       int handle = it->second.handle;\n> -                       int size = it->second.size;\n> -                       ::munmap(user_ptr, size);\n> -                       ::close(handle);\n> -                       /*\n> -                        * Remove the allocation from the map. This returns\n> -                        * an iterator to the next element.\n> -                        */\n> -                       it = allocMap_.erase(it);\n> -               }\n> -\n> -               /* Returns an iterator to the next element. */\n> -               return it;\n> -       }\n> -\n> -       AllocMap allocMap_;\n> -       int vcsmHandle_;\n> -       std::mutex lock_;\n> -};\n> -\n> -} /* namespace RPi */\n> -\n> -#endif /* __LIBCAMERA_PIPELINE_RASPBERRYPI_VCSM_H__ */\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","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 3334DBD792\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jul 2020 06:22:40 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9F9156053B;\n\tFri, 17 Jul 2020 08:22:39 +0200 (CEST)","from mail-lj1-x242.google.com (mail-lj1-x242.google.com\n\t[IPv6:2a00:1450:4864:20::242])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 454C06039F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jul 2020 08:22:37 +0200 (CEST)","by mail-lj1-x242.google.com with SMTP id q7so11383759ljm.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 16 Jul 2020 23:22:37 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"DA0M7Wiw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=Y+zOc20EiUE+fEMhQx9Vztf9Rny1180fs+C+LxTyc6A=;\n\tb=DA0M7WiwbuBYuwDi1gypmxuuZWpkm/JW/6UvvcpdUeQonmiwo7AUmFu3kbHgUjhgLr\n\tOLCcuhJj0vnVJJ7ono9NBrwdUPsgpzKa+Hj7YeuByvlsFhyoRog9qf00sjDKuarMYfVz\n\tvQEvBoHpk+kH4hLmCLKvotBX+zhpyhRpeIs1IZcU8zi1S9Vk2U9OA6IQiOw3OeJHwY+N\n\tat8fHeIeJCD1OA1hrnhmyI11UnTIDw43WeheWoBNDxRuXqoXpnoTLNcKm7Zc0dA5jIvX\n\tnhVsO5Q0I4GdP9nazLSoueA3kG2vuYaIZVrCkyze9x4h7kkdjB0Vrfio7LMvpLtmtcv1\n\tqHFg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=Y+zOc20EiUE+fEMhQx9Vztf9Rny1180fs+C+LxTyc6A=;\n\tb=HfJWvbGLZ4r4DPp0Wl/6xOjDhAr7tT2lPH0mQHKUiZPiudee02RokLoa+bBju9sLQj\n\tTqN7Ywayka3AgN0fDuny/E6HQX+paCNAJ8ybWVHd6dI+Hf58mTs6x3hQvQwHGl7cbx8j\n\tAjjKwQIRsJux3tAW4vD8SvPLvSUcQdBmUmxSdXbm8amOPXL467Am3ORfjc+0nWSwQUM6\n\tLDEh0RwcyQD9zXmndH2zl2hR+fCqDfRlkecf0NkKKK9E1XN+xFOgDoqXbSA0CISpAM4X\n\tnOpugIky6eg7fOaAS3BSJZI5urJXNUcRM5+sH7pKO6sJJnwUbJINW9tumlo61X3qWRdV\n\tfqjw==","X-Gm-Message-State":"AOAM533rWmGi3tpGcCsSkdYP5WyI/p2AhHI6tfgRkA8gPdWXYwp9J0dm\n\tKv+VixxIc2nIKylVH6PjZItCEFDbza+nZ5XeuPbEIw==","X-Google-Smtp-Source":"ABdhPJzeKUPx1UfJJyU1LIOv5u5CcVMiNPDVVpTP2ypIRyIPfzKTuF3m0r8pL7OzRQDvNZlAcyvGasPmaMAOLMTolu4=","X-Received":"by 2002:a2e:88c3:: with SMTP id a3mr3623554ljk.112.1594966955718;\n\tThu, 16 Jul 2020 23:22:35 -0700 (PDT)","MIME-Version":"1.0","References":"<20200717001518.20285-1-laurent.pinchart@ideasonboard.com>\n\t<20200717001518.20285-3-laurent.pinchart@ideasonboard.com>","In-Reply-To":"<20200717001518.20285-3-laurent.pinchart@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 17 Jul 2020 07:22:19 +0100","Message-ID":"<CAEmqJPpP_9eQ1-caegkserW9wwYiRzhHFpZaU=4rYthwYGnJkw@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 2/2] libcamera: pipeline: ipa:\n\traspberrypi: Use dma heap allocs for LS tables","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]