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 <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Naushir Patuck 2020-07-15 10:39:11 +01:00 committed by Laurent Pinchart
parent 3c02a808e8
commit 3e7aa49344
8 changed files with 154 additions and 327 deletions

View file

@ -15,6 +15,7 @@
#include <libcamera/buffer.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include <libcamera/file_descriptor.h>
#include <libcamera/ipa/ipa_interface.h>
#include <libcamera/ipa/ipa_module_info.h>
#include <libcamera/ipa/raspberrypi.h>
@ -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<void *>(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