Skip to content

Commit f04cd68

Browse files
6by9popcornmix
authored andcommitted
staging: mmal-vchiq: Use vc-sm-cma to support zero copy
With the vc-sm-cma driver we can support zero copy of buffers between the kernel and VPU. Add this support to mmal-vchiq. Signed-off-by: Dave Stevenson <[email protected]> vc-sm-cma: fixed kbuild problem error logs: drivers/staging/vc04_services/vc-sm-cma/Kconfig:1:error: recursive dependency detected! drivers/staging/vc04_services/vc-sm-cma/Kconfig:1: symbol BCM_VC_SM_CMA is selected by BCM2835_VCHIQ_MMAL drivers/staging/vc04_services/vchiq-mmal/Kconfig:1: symbol BCM2835_VCHIQ_MMAL depends on BCM2835_VCHIQ drivers/staging/vc04_services/Kconfig:14: symbol BCM2835_VCHIQ is selected by BCM_VC_SM_CMA For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" Tested-by: make ARCH=arm64 bcm2711_defconfig Test platform: fedora 33 Branch: rpi-5.10.y
1 parent 4fc5cbe commit f04cd68

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

drivers/staging/vc04_services/vchiq-mmal/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
config BCM2835_VCHIQ_MMAL
22
tristate "BCM2835 MMAL VCHIQ service"
3-
depends on BCM2835_VCHIQ
3+
select BCM2835_VCHIQ
4+
select BCM_VC_SM_CMA
45
help
56
Enables the MMAL API over VCHIQ interface as used for the
67
majority of the multimedia services on VideoCore.

drivers/staging/vc04_services/vchiq-mmal/mmal-common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ struct mmal_buffer {
5050

5151
struct mmal_msg_context *msg_context;
5252

53+
struct dma_buf *dma_buf;/* Exported dmabuf fd from videobuf2 */
54+
void *vcsm_handle; /* VCSM handle having imported the dmabuf */
55+
u32 vc_handle; /* VC handle to that dmabuf */
56+
5357
u32 cmd; /* MMAL command. 0=data. */
5458
unsigned long length;
5559
u32 mmal_flags;

drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
#include "../include/linux/raspberrypi/vchiq.h"
2929
#include "../interface/vchiq_arm/vchiq_arm.h"
3030
#include "mmal-common.h"
31+
#include "mmal-parameters.h"
3132
#include "mmal-vchiq.h"
3233
#include "mmal-msg.h"
3334

35+
#include "../vc-sm-cma/vc_sm_knl.h"
36+
3437
/*
3538
* maximum number of components supported.
3639
* This matches the maximum permitted by default on the VPU
@@ -417,8 +420,13 @@ buffer_from_host(struct vchiq_mmal_instance *instance,
417420

418421
/* buffer header */
419422
m.u.buffer_from_host.buffer_header.cmd = 0;
420-
m.u.buffer_from_host.buffer_header.data =
421-
(u32)(unsigned long)buf->buffer;
423+
if (port->zero_copy) {
424+
m.u.buffer_from_host.buffer_header.data = buf->vc_handle;
425+
} else {
426+
m.u.buffer_from_host.buffer_header.data =
427+
(u32)(unsigned long)buf->buffer;
428+
}
429+
422430
m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
423431
if (port->type == MMAL_PORT_TYPE_OUTPUT) {
424432
m.u.buffer_from_host.buffer_header.length = 0;
@@ -584,6 +592,22 @@ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
584592

585593
msg_context->u.bulk.status = msg->h.status;
586594

595+
} else if (msg->u.buffer_from_host.is_zero_copy) {
596+
/*
597+
* Zero copy buffer, so nothing to do.
598+
* Copy buffer info and make callback.
599+
*/
600+
msg_context->u.bulk.buffer_used =
601+
msg->u.buffer_from_host.buffer_header.length;
602+
msg_context->u.bulk.mmal_flags =
603+
msg->u.buffer_from_host.buffer_header.flags;
604+
msg_context->u.bulk.dts =
605+
msg->u.buffer_from_host.buffer_header.dts;
606+
msg_context->u.bulk.pts =
607+
msg->u.buffer_from_host.buffer_header.pts;
608+
msg_context->u.bulk.cmd =
609+
msg->u.buffer_from_host.buffer_header.cmd;
610+
587611
} else if (msg->u.buffer_from_host.buffer_header.length == 0) {
588612
/* empty buffer */
589613
if (msg->u.buffer_from_host.buffer_header.flags &
@@ -1530,6 +1554,9 @@ int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
15301554

15311555
mutex_unlock(&instance->vchiq_mutex);
15321556

1557+
if (parameter == MMAL_PARAMETER_ZERO_COPY && !ret)
1558+
port->zero_copy = !!(*(bool *)value);
1559+
15331560
return ret;
15341561
}
15351562
EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_set);
@@ -1698,6 +1725,31 @@ int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
16981725
unsigned long flags = 0;
16991726
int ret;
17001727

1728+
/*
1729+
* We really want to do this in mmal_vchi_buffer_init but can't as
1730+
* videobuf2 won't let us have the dmabuf there.
1731+
*/
1732+
if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) {
1733+
pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf);
1734+
ret = vc_sm_cma_import_dmabuf(buffer->dma_buf,
1735+
&buffer->vcsm_handle);
1736+
if (ret) {
1737+
pr_err("%s: vc_sm_import_dmabuf_fd failed, ret %d\n",
1738+
__func__, ret);
1739+
return ret;
1740+
}
1741+
1742+
buffer->vc_handle = vc_sm_cma_int_handle(buffer->vcsm_handle);
1743+
if (!buffer->vc_handle) {
1744+
pr_err("%s: vc_sm_int_handle failed %d\n",
1745+
__func__, ret);
1746+
vc_sm_cma_free(buffer->vcsm_handle);
1747+
return ret;
1748+
}
1749+
pr_debug("%s: import dmabuf %p - got vc handle %08X\n",
1750+
__func__, buffer->dma_buf, buffer->vc_handle);
1751+
}
1752+
17011753
ret = buffer_from_host(instance, port, buffer);
17021754
if (ret == -EINVAL) {
17031755
/* Port is disabled. Queue for when it is enabled. */
@@ -1731,6 +1783,16 @@ int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf)
17311783
release_msg_context(msg_context);
17321784
buf->msg_context = NULL;
17331785

1786+
if (buf->vcsm_handle) {
1787+
int ret;
1788+
1789+
pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__,
1790+
buf->vcsm_handle);
1791+
ret = vc_sm_cma_free(buf->vcsm_handle);
1792+
if (ret)
1793+
pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret);
1794+
buf->vcsm_handle = 0;
1795+
}
17341796
return 0;
17351797
}
17361798
EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup);

drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef void (*vchiq_mmal_buffer_cb)(struct vchiq_mmal_instance *instance,
4949

5050
struct vchiq_mmal_port {
5151
bool enabled;
52+
u32 zero_copy:1;
5253
u32 handle;
5354
u32 type; /* port type, cached to use on port info set */
5455
u32 index; /* port index, cached to use on port info set */

0 commit comments

Comments
 (0)