staging: vc04_services: Add new vc-sm-cma driver
authorDave Stevenson <dave.stevenson@raspberrypi.org>
Tue, 25 Sep 2018 09:27:11 +0000 (10:27 +0100)
committerpopcornmix <popcornmix@gmail.com>
Wed, 1 Jul 2020 15:32:51 +0000 (16:32 +0100)
commitb6c66856c22c9eef5f033e5da3702ce92451a365
tree5a9785c4d487cf760287cfaf51c1604eca493ecf
parentd780d7aa38800844bc66b32b2936c4b941f62660
staging: vc04_services: Add new vc-sm-cma driver

This new driver allows contiguous memory blocks to be imported
into the VideoCore VPU memory map, and manages the lifetime of
those objects, only releasing the source dmabuf once the VPU has
confirmed it has finished with it.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Correct DMA configuration.

Now that VCHIQ is setting up the DMA configuration as our
parent device, don't try to configure it during probe.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Use a void* pointer as the handle within the kernel

The driver was using an unsigned int as the handle to the outside world,
and doing a nasty cast to the struct dmabuf when handed it back.
This breaks badly with a 64 bit kernel where the pointer doesn't fit
in an unsigned int.

Switch to using a void* within the kernel. Reality is that it is
a struct dma_buf*, but advertising it as such to other drivers seems
to encourage the use of it as such, and I'm not sure on the implications
of that.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Fix up for 64bit builds

There were a number of logging lines that were using
inappropriate formatting under 64bit kernels.

The kernel_id field passed to/from the VPU was being
abused for storing the struct vc_sm_buffer *.
This breaks with 64bit kernels, so change to using an IDR.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc_sm_cma: Remove erroneous misc_deregister

Code from the misc /dev node was still present in
bcm2835_vc_sm_cma_remove, which caused a NULL deref.
Remove it.

See #2885.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Remove the debugfs directory on remove

Without removing that, reloading the driver fails.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Use devm_ allocs for sm_state.

Use managed allocations for sm_state, removing reliance on
manual management.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Don't fail if debugfs calls fail.

Return codes from debugfs calls should never alter the
flow of the main code.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Ensure mutex and idr are destroyed

map_lock and kernelid_map are created in probe, but not released
in release should the vcsm service not connect (eg running the
cutdown firmware).

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Remove obsolete comment and make function static

Removes obsolete comment about wanting to pass a function
pointer into mmal-vchiq as we now do.
As the function is passed as a function pointer, the function itself
can be static.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Add in allocation for VPU requests.

Module has to change from tristate to bool as all CMA functions
are boolean.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Update TODO.

The driver is already a platform driver, so that can be
deleted from the TODO.
There are no known issues that need to be resolved.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Add in userspace allocation API

Replacing the functionality from the older vc-sm driver,
add in a userspace API that allows allocation of buffers,
and importing of dma-bufs.
The driver hands out dma-buf fds, therefore much of the
handling around lifespan and odd mmaps from the old driver
goes away.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vcsm-cma: Add cache control ioctls

The old driver allowed for direct cache manipulation and that
was used by various clients. Replicate here.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vcsm-cma: Alter dev node permissions to 0666

Until the udev rules are updated, open up access to this node by
default.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vcsm-cma: Drop logging level on messages in vc_sm_release_resource

They weren't errors but were logged as such.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vcsm-cma: Fixup the alloc code handling of kernel_id

The allocation code had been copied in from an old branch prior
to having added the IDR for 64bit support. It was therefore pushing
a pointer into the kernel_id field instead of an IDR handle, the
lookup therefore failed, and we never released the buffer.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vcsm-cma: Remove cache manipulation ioctl from ARM64

The cache flushing ioctls are used by the Pi3 HEVC hw-assisted
decoder as it needs finer grained flushing control than dma_ops
allow.
These cache calls are not present for ARM64, therefore disable
them. We are not actively supporting 64bit kernels at present,
and the use case of the HEVC decoder is fairly limited.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vcsm-cma: Rework to use dma APIs, not CMA

Due to a misunderstanding of the DMA mapping APIs, I made
the wrong decision on how to implement this.

Rework to use dma_alloc_coherent instead of the CMA
API. This also allows it to be built as a module easily.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc-sm-cma: Fix the few remaining coding style issues

Fix a few minor checkpatch complaints to make the driver clean

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
staging: vc04_services: fix compiling in separate directory

The vc04_services Makefiles do not respect the O=path argument
correctly: include paths in CFLAGS are given relatively to object path,
not source path. Compiling in a separate directory yields #include
errors.

Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
vc-sm-cma: Fix compatibility ioctl

This code path hasn't been used previously.
Fixed up after testing with kodi on 32-bit userland and 64-bit kernel

Signed-off-by: popcornmix <popcornmix@gmail.com>
14 files changed:
drivers/staging/vc04_services/Kconfig
drivers/staging/vc04_services/Makefile
drivers/staging/vc04_services/bcm2835-camera/Makefile
drivers/staging/vc04_services/vc-sm-cma/Kconfig [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/Makefile [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/TODO [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/vc_sm.c [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/vc_sm.h [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.h [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/vc_sm_defs.h [new file with mode: 0644]
drivers/staging/vc04_services/vc-sm-cma/vc_sm_knl.h [new file with mode: 0644]
drivers/staging/vc04_services/vchiq-mmal/Makefile
include/linux/broadcom/vc_sm_cma_ioctl.h [new file with mode: 0644]