xref: /openbmc/linux/drivers/gpu/drm/v3d/v3d_fence.c (revision ba61bb17)
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2017-2018 Broadcom */
3 
4 #include "v3d_drv.h"
5 
6 struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue queue)
7 {
8 	struct v3d_fence *fence;
9 
10 	fence = kzalloc(sizeof(*fence), GFP_KERNEL);
11 	if (!fence)
12 		return ERR_PTR(-ENOMEM);
13 
14 	fence->dev = &v3d->drm;
15 	fence->queue = queue;
16 	fence->seqno = ++v3d->queue[queue].emit_seqno;
17 	dma_fence_init(&fence->base, &v3d_fence_ops, &v3d->job_lock,
18 		       v3d->queue[queue].fence_context, fence->seqno);
19 
20 	return &fence->base;
21 }
22 
23 static const char *v3d_fence_get_driver_name(struct dma_fence *fence)
24 {
25 	return "v3d";
26 }
27 
28 static const char *v3d_fence_get_timeline_name(struct dma_fence *fence)
29 {
30 	struct v3d_fence *f = to_v3d_fence(fence);
31 
32 	if (f->queue == V3D_BIN)
33 		return "v3d-bin";
34 	else
35 		return "v3d-render";
36 }
37 
38 static bool v3d_fence_enable_signaling(struct dma_fence *fence)
39 {
40 	return true;
41 }
42 
43 const struct dma_fence_ops v3d_fence_ops = {
44 	.get_driver_name = v3d_fence_get_driver_name,
45 	.get_timeline_name = v3d_fence_get_timeline_name,
46 	.enable_signaling = v3d_fence_enable_signaling,
47 	/* Each of our fences gets signaled as complete by the IRQ
48 	 * handler, so we rely on the core's tracking of signaling.
49 	 */
50 	.signaled = NULL,
51 	.wait = dma_fence_default_wait,
52 	.release = dma_fence_free,
53 };
54