Skip to content

Commit 9ad59fe

Browse files
pH5lynxeye-dev
authored andcommitted
drm/etnaviv: submit support for in-fences
Loosely based on commit f0a42bb ("drm/msm: submit support for in-fences"). Unfortunately, struct drm_etnaviv_gem_submit doesn't have a flags field yet, so we have to extend the structure and trust that drm_ioctl will clear the flags for us if an older userspace only submits part of the struct. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com> Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org> Reviewed-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
1 parent bcdfb5e commit 9ad59fe

6 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎drivers/gpu/drm/etnaviv/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config DRM_ETNAVIV
55
depends on ARCH_MXC || ARCH_DOVE || (ARM && COMPILE_TEST)
66
depends on MMU
77
select SHMEM
8+
select SYNC_FILE
89
select TMPFS
910
select IOMMU_API
1011
select IOMMU_SUPPORT

‎drivers/gpu/drm/etnaviv/etnaviv_gem.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct etnaviv_gem_submit {
107107
u32 fence;
108108
unsigned int nr_bos;
109109
struct etnaviv_gem_submit_bo bos[0];
110+
u32 flags;
110111
};
111112

112113
int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,

‎drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* this program. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17+
#include <linux/dma-fence-array.h>
1718
#include <linux/reservation.h>
19+
#include <linux/sync_file.h>
1820
#include "etnaviv_cmdbuf.h"
1921
#include "etnaviv_drv.h"
2022
#include "etnaviv_gpu.h"
@@ -169,8 +171,10 @@ static int submit_fence_sync(const struct etnaviv_gem_submit *submit)
169171
for (i = 0; i < submit->nr_bos; i++) {
170172
struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj;
171173
bool write = submit->bos[i].flags & ETNA_SUBMIT_BO_WRITE;
174+
bool explicit = !(submit->flags & ETNA_SUBMIT_NO_IMPLICIT);
172175

173-
ret = etnaviv_gpu_fence_sync_obj(etnaviv_obj, context, write);
176+
ret = etnaviv_gpu_fence_sync_obj(etnaviv_obj, context, write,
177+
explicit);
174178
if (ret)
175179
break;
176180
}
@@ -303,6 +307,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
303307
struct etnaviv_gem_submit *submit;
304308
struct etnaviv_cmdbuf *cmdbuf;
305309
struct etnaviv_gpu *gpu;
310+
struct dma_fence *in_fence = NULL;
306311
void *stream;
307312
int ret;
308313

@@ -326,6 +331,11 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
326331
return -EINVAL;
327332
}
328333

334+
if (args->flags & ~ETNA_SUBMIT_FLAGS) {
335+
DRM_ERROR("invalid flags: 0x%x\n", args->flags);
336+
return -EINVAL;
337+
}
338+
329339
/*
330340
* Copy the command submission and bo array to kernel space in
331341
* one go, and do this outside of any locks.
@@ -371,6 +381,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
371381
goto err_submit_cmds;
372382
}
373383

384+
submit->flags = args->flags;
385+
374386
ret = submit_lookup_objects(submit, file, bos, args->nr_bos);
375387
if (ret)
376388
goto err_submit_objects;
@@ -385,6 +397,24 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
385397
goto err_submit_objects;
386398
}
387399

400+
if (args->flags & ETNA_SUBMIT_FENCE_FD_IN) {
401+
in_fence = sync_file_get_fence(args->fence_fd);
402+
if (!in_fence) {
403+
ret = -EINVAL;
404+
goto err_submit_objects;
405+
}
406+
407+
/*
408+
* Wait if the fence is from a foreign context, or if the fence
409+
* array contains any fence from a foreign context.
410+
*/
411+
if (!dma_fence_match_context(in_fence, gpu->fence_context)) {
412+
ret = dma_fence_wait(in_fence, true);
413+
if (ret)
414+
goto err_submit_objects;
415+
}
416+
}
417+
388418
ret = submit_fence_sync(submit);
389419
if (ret)
390420
goto err_submit_objects;
@@ -419,6 +449,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
419449
flush_workqueue(priv->wq);
420450

421451
err_submit_objects:
452+
if (in_fence)
453+
dma_fence_put(in_fence);
422454
submit_cleanup(submit);
423455

424456
err_submit_cmds:

‎drivers/gpu/drm/etnaviv/etnaviv_gpu.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ static struct dma_fence *etnaviv_gpu_fence_alloc(struct etnaviv_gpu *gpu)
10771077
}
10781078

10791079
int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj,
1080-
unsigned int context, bool exclusive)
1080+
unsigned int context, bool exclusive, bool explicit)
10811081
{
10821082
struct reservation_object *robj = etnaviv_obj->resv;
10831083
struct reservation_object_list *fobj;
@@ -1090,6 +1090,9 @@ int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj,
10901090
return ret;
10911091
}
10921092

1093+
if (explicit)
1094+
return 0;
1095+
10931096
/*
10941097
* If we have any shared fences, then the exclusive fence
10951098
* should be ignored as it will already have been signalled.

‎drivers/gpu/drm/etnaviv/etnaviv_gpu.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m);
183183
#endif
184184

185185
int etnaviv_gpu_fence_sync_obj(struct etnaviv_gem_object *etnaviv_obj,
186-
unsigned int context, bool exclusive);
186+
unsigned int context, bool exclusive, bool implicit);
187187

188188
void etnaviv_gpu_retire(struct etnaviv_gpu *gpu);
189189
int etnaviv_gpu_wait_fence_interruptible(struct etnaviv_gpu *gpu,

‎include/uapi/drm/etnaviv_drm.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ struct drm_etnaviv_gem_submit_bo {
154154
* one or more cmdstream buffers. This allows for conditional execution
155155
* (context-restore), and IB buffers needed for per tile/bin draw cmds.
156156
*/
157+
#define ETNA_SUBMIT_NO_IMPLICIT 0x0001
158+
#define ETNA_SUBMIT_FENCE_FD_IN 0x0002
159+
#define ETNA_SUBMIT_FLAGS (ETNA_SUBMIT_NO_IMPLICIT | \
160+
ETNA_SUBMIT_FENCE_FD_IN)
157161
#define ETNA_PIPE_3D 0x00
158162
#define ETNA_PIPE_2D 0x01
159163
#define ETNA_PIPE_VG 0x02
@@ -167,6 +171,8 @@ struct drm_etnaviv_gem_submit {
167171
__u64 bos; /* in, ptr to array of submit_bo's */
168172
__u64 relocs; /* in, ptr to array of submit_reloc's */
169173
__u64 stream; /* in, ptr to cmdstream */
174+
__u32 flags; /* in, mask of ETNA_SUBMIT_x */
175+
__s32 fence_fd; /* in, fence fd (see ETNA_SUBMIT_FENCE_FD_IN) */
170176
};
171177

172178
/* The normal way to synchronize with the GPU is just to CPU_PREP on

0 commit comments

Comments
 (0)