1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013-2016 Red Hat
7 #ifndef __MSM_FENCE_H__
8 #define __MSM_FENCE_H__
13 * struct msm_fence_context - fence context for gpu
15 * Each ringbuffer has a single fence context, with the GPU writing an
16 * incrementing fence seqno at the end of each submit
18 struct msm_fence_context {
19 struct drm_device *dev;
20 /** name: human readable name for fence timeline */
22 /** context: see dma_fence_context_alloc() */
24 /** index: similar to context, but local to msm_fence_context's */
30 * Last assigned fence, incremented each time a fence is created
31 * on this fence context. If last_fence == completed_fence,
32 * there is no remaining pending work
39 * The last completed fence, updated from the CPU after interrupt
42 uint32_t completed_fence;
47 * The address that the GPU directly writes with completed fence
48 * seqno. This can be ahead of completed_fence. We can peek at
49 * this to see if a fence has already signaled but the CPU hasn't
50 * gotten around to handling the irq and updating completed_fence
52 volatile uint32_t *fenceptr;
57 struct msm_fence_context * msm_fence_context_alloc(struct drm_device *dev,
58 volatile uint32_t *fenceptr, const char *name);
59 void msm_fence_context_free(struct msm_fence_context *fctx);
61 bool msm_fence_completed(struct msm_fence_context *fctx, uint32_t fence);
62 void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence);
64 struct dma_fence * msm_fence_alloc(struct msm_fence_context *fctx);
67 fence_before(uint32_t a, uint32_t b)
69 return (int32_t)(a - b) < 0;
73 fence_after(uint32_t a, uint32_t b)
75 return (int32_t)(a - b) > 0;