From 3e7aa49344ad5233f644703559898572b57f9613 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Wed, 15 Jul 2020 10:39:11 +0100 Subject: libcamera: pipeline: ipa: raspberrypi: Use dma heap allocs for LS tables Remove use of vcsm allocations and replace with dma heap allocations. The pipeline handler now passes the fd of the allocation over to the IPA instead of the raw pointer. Also use libcamera::FileDescriptor for fd lifetime management. This commit must be built alongside the accompanying BCM2835 ISP kernel driver changes at https://github.com/raspberrypi/linux/pull/3715. Otherwise a mismatch will cause undefined behavior. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/ipa/raspberrypi/raspberrypi.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/ipa/raspberrypi/raspberrypi.cpp') diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index 2fcbc782..7bd04880 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -65,12 +66,14 @@ public: IPARPi() : lastMode_({}), controller_(), controllerInit_(false), frame_count_(0), check_count_(0), hide_count_(0), - mistrust_count_(0), lsTableHandle_(0), lsTable_(nullptr) + mistrust_count_(0), lsTable_(nullptr) { } ~IPARPi() { + if (lsTable_) + munmap(lsTable_, MAX_LS_GRID_SIZE); } int init(const IPASettings &settings) override; @@ -139,7 +142,7 @@ private: /* How many frames we should avoid running control algos on. */ unsigned int mistrust_count_; /* LS table allocation passed in from the pipeline handler. */ - uint32_t lsTableHandle_; + FileDescriptor lsTableHandle_; void *lsTable_; }; @@ -280,8 +283,23 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo, /* Store the lens shading table pointer and handle if available. */ if (ipaConfig.operation & RPI_IPA_CONFIG_LS_TABLE) { - lsTable_ = reinterpret_cast(ipaConfig.data[0]); - lsTableHandle_ = ipaConfig.data[1]; + /* Remove any previous table, if there was one. */ + if (lsTable_) { + munmap(lsTable_, MAX_LS_GRID_SIZE); + lsTable_ = nullptr; + } + + /* Map the LS table buffer into user space. */ + lsTableHandle_ = FileDescriptor(ipaConfig.data[0]); + if (lsTableHandle_.isValid()) { + lsTable_ = mmap(nullptr, MAX_LS_GRID_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, lsTableHandle_.fd(), 0); + + if (lsTable_ == MAP_FAILED) { + LOG(IPARPI, Error) << "dmaHeap mmap failure for LS table."; + lsTable_ = nullptr; + } + } } } @@ -1030,7 +1048,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls) .grid_width = w, .grid_stride = w, .grid_height = h, - .mem_handle_table = lsTableHandle_, + .dmabuf = lsTableHandle_.fd(), .ref_transform = 0, .corner_sampled = 1, .gain_format = GAIN_FORMAT_U4P10 -- cgit v1.2.1