]> git.ipfire.org Git - thirdparty/openwrt.git/blob
c93d62f1d09a5875885547b23fce0128e078840c
[thirdparty/openwrt.git] /
1 From 7f4b118a4d4550a34ba21baff6b04ec9ea178a23 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Tue, 25 Sep 2018 16:07:55 +0100
4 Subject: [PATCH 0251/1085] staging: mmal-vchiq: Use vc-sm-cma to support zero
5 copy
6
7 With the vc-sm-cma driver we can support zero copy of buffers between
8 the kernel and VPU. Add this support to mmal-vchiq.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11
12 vc-sm-cma: fixed kbuild problem
13
14 error logs:
15 drivers/staging/vc04_services/vc-sm-cma/Kconfig:1:error: recursive dependency detected!
16 drivers/staging/vc04_services/vc-sm-cma/Kconfig:1: symbol BCM_VC_SM_CMA is selected by BCM2835_VCHIQ_MMAL
17 drivers/staging/vc04_services/vchiq-mmal/Kconfig:1: symbol BCM2835_VCHIQ_MMAL depends on BCM2835_VCHIQ
18 drivers/staging/vc04_services/Kconfig:14: symbol BCM2835_VCHIQ is selected by BCM_VC_SM_CMA
19 For a resolution refer to Documentation/kbuild/kconfig-language.rst
20 subsection "Kconfig recursive dependency limitations"
21
22 Tested-by: make ARCH=arm64 bcm2711_defconfig
23 Test platform: fedora 33
24 Branch: rpi-5.10.y
25 ---
26 .../staging/vc04_services/vchiq-mmal/Kconfig | 3 +-
27 .../vc04_services/vchiq-mmal/mmal-common.h | 4 ++
28 .../vc04_services/vchiq-mmal/mmal-vchiq.c | 66 ++++++++++++++++++-
29 .../vc04_services/vchiq-mmal/mmal-vchiq.h | 1 +
30 4 files changed, 71 insertions(+), 3 deletions(-)
31
32 --- a/drivers/staging/vc04_services/vchiq-mmal/Kconfig
33 +++ b/drivers/staging/vc04_services/vchiq-mmal/Kconfig
34 @@ -1,6 +1,7 @@
35 config BCM2835_VCHIQ_MMAL
36 tristate "BCM2835 MMAL VCHIQ service"
37 - depends on BCM2835_VCHIQ
38 + select BCM2835_VCHIQ
39 + select BCM_VC_SM_CMA
40 help
41 Enables the MMAL API over VCHIQ interface as used for the
42 majority of the multimedia services on VideoCore.
43 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-common.h
44 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-common.h
45 @@ -50,6 +50,10 @@ struct mmal_buffer {
46
47 struct mmal_msg_context *msg_context;
48
49 + struct dma_buf *dma_buf;/* Exported dmabuf fd from videobuf2 */
50 + void *vcsm_handle; /* VCSM handle having imported the dmabuf */
51 + u32 vc_handle; /* VC handle to that dmabuf */
52 +
53 u32 cmd; /* MMAL command. 0=data. */
54 unsigned long length;
55 u32 mmal_flags;
56 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
57 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
58 @@ -27,9 +27,12 @@
59
60 #include "../include/linux/raspberrypi/vchiq.h"
61 #include "mmal-common.h"
62 +#include "mmal-parameters.h"
63 #include "mmal-vchiq.h"
64 #include "mmal-msg.h"
65
66 +#include "../vc-sm-cma/vc_sm_knl.h"
67 +
68 /*
69 * maximum number of components supported.
70 * This matches the maximum permitted by default on the VPU
71 @@ -416,8 +419,13 @@ buffer_from_host(struct vchiq_mmal_insta
72
73 /* buffer header */
74 m.u.buffer_from_host.buffer_header.cmd = 0;
75 - m.u.buffer_from_host.buffer_header.data =
76 - (u32)(unsigned long)buf->buffer;
77 + if (port->zero_copy) {
78 + m.u.buffer_from_host.buffer_header.data = buf->vc_handle;
79 + } else {
80 + m.u.buffer_from_host.buffer_header.data =
81 + (u32)(unsigned long)buf->buffer;
82 + }
83 +
84 m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
85 if (port->type == MMAL_PORT_TYPE_OUTPUT) {
86 m.u.buffer_from_host.buffer_header.length = 0;
87 @@ -583,6 +591,22 @@ static void buffer_to_host_cb(struct vch
88
89 msg_context->u.bulk.status = msg->h.status;
90
91 + } else if (msg->u.buffer_from_host.is_zero_copy) {
92 + /*
93 + * Zero copy buffer, so nothing to do.
94 + * Copy buffer info and make callback.
95 + */
96 + msg_context->u.bulk.buffer_used =
97 + msg->u.buffer_from_host.buffer_header.length;
98 + msg_context->u.bulk.mmal_flags =
99 + msg->u.buffer_from_host.buffer_header.flags;
100 + msg_context->u.bulk.dts =
101 + msg->u.buffer_from_host.buffer_header.dts;
102 + msg_context->u.bulk.pts =
103 + msg->u.buffer_from_host.buffer_header.pts;
104 + msg_context->u.bulk.cmd =
105 + msg->u.buffer_from_host.buffer_header.cmd;
106 +
107 } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
108 /* empty buffer */
109 if (msg->u.buffer_from_host.buffer_header.flags &
110 @@ -1528,6 +1552,9 @@ int vchiq_mmal_port_parameter_set(struct
111
112 mutex_unlock(&instance->vchiq_mutex);
113
114 + if (parameter == MMAL_PARAMETER_ZERO_COPY && !ret)
115 + port->zero_copy = !!(*(bool *)value);
116 +
117 return ret;
118 }
119 EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_set);
120 @@ -1696,6 +1723,31 @@ int vchiq_mmal_submit_buffer(struct vchi
121 unsigned long flags = 0;
122 int ret;
123
124 + /*
125 + * We really want to do this in mmal_vchi_buffer_init but can't as
126 + * videobuf2 won't let us have the dmabuf there.
127 + */
128 + if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) {
129 + pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf);
130 + ret = vc_sm_cma_import_dmabuf(buffer->dma_buf,
131 + &buffer->vcsm_handle);
132 + if (ret) {
133 + pr_err("%s: vc_sm_import_dmabuf_fd failed, ret %d\n",
134 + __func__, ret);
135 + return ret;
136 + }
137 +
138 + buffer->vc_handle = vc_sm_cma_int_handle(buffer->vcsm_handle);
139 + if (!buffer->vc_handle) {
140 + pr_err("%s: vc_sm_int_handle failed %d\n",
141 + __func__, ret);
142 + vc_sm_cma_free(buffer->vcsm_handle);
143 + return ret;
144 + }
145 + pr_debug("%s: import dmabuf %p - got vc handle %08X\n",
146 + __func__, buffer->dma_buf, buffer->vc_handle);
147 + }
148 +
149 ret = buffer_from_host(instance, port, buffer);
150 if (ret == -EINVAL) {
151 /* Port is disabled. Queue for when it is enabled. */
152 @@ -1729,6 +1781,16 @@ int mmal_vchi_buffer_cleanup(struct mmal
153 release_msg_context(msg_context);
154 buf->msg_context = NULL;
155
156 + if (buf->vcsm_handle) {
157 + int ret;
158 +
159 + pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__,
160 + buf->vcsm_handle);
161 + ret = vc_sm_cma_free(buf->vcsm_handle);
162 + if (ret)
163 + pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret);
164 + buf->vcsm_handle = 0;
165 + }
166 return 0;
167 }
168 EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup);
169 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
170 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
171 @@ -49,6 +49,7 @@ typedef void (*vchiq_mmal_buffer_cb)(
172
173 struct vchiq_mmal_port {
174 bool enabled;
175 + u32 zero_copy:1;
176 u32 handle;
177 u32 type; /* port type, cached to use on port info set */
178 u32 index; /* port index, cached to use on port info set */