2016-09-09 13:11:41 +00:00
|
|
|
/*
|
2018-11-29 01:30:51 +00:00
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
2016-09-09 13:11:41 +00:00
|
|
|
* i915_sw_fence.h - library routines for N:M synchronisation points
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _I915_SW_FENCE_H_
|
|
|
|
#define _I915_SW_FENCE_H_
|
|
|
|
|
2019-03-22 09:23:25 +00:00
|
|
|
#include <linux/dma-fence.h>
|
2016-09-09 13:11:41 +00:00
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/kref.h>
|
|
|
|
#include <linux/notifier.h> /* for NOTIFY_DONE */
|
|
|
|
#include <linux/wait.h>
|
|
|
|
|
|
|
|
struct completion;
|
2019-08-11 08:06:32 +00:00
|
|
|
struct dma_resv;
|
2016-09-09 13:11:41 +00:00
|
|
|
|
|
|
|
struct i915_sw_fence {
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
unsigned long flags;
|
|
|
|
atomic_t pending;
|
2019-08-17 23:25:11 +00:00
|
|
|
int error;
|
2016-09-09 13:11:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define I915_SW_FENCE_CHECKED_BIT 0 /* used internally for DAG checking */
|
|
|
|
#define I915_SW_FENCE_PRIVATE_BIT 1 /* available for use by owner */
|
|
|
|
#define I915_SW_FENCE_MASK (~3)
|
|
|
|
|
|
|
|
enum i915_sw_fence_notify {
|
|
|
|
FENCE_COMPLETE,
|
|
|
|
FENCE_FREE
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int (*i915_sw_fence_notify_t)(struct i915_sw_fence *,
|
|
|
|
enum i915_sw_fence_notify state);
|
|
|
|
#define __i915_sw_fence_call __aligned(4)
|
|
|
|
|
2016-11-14 20:40:56 +00:00
|
|
|
void __i915_sw_fence_init(struct i915_sw_fence *fence,
|
|
|
|
i915_sw_fence_notify_t fn,
|
|
|
|
const char *name,
|
|
|
|
struct lock_class_key *key);
|
|
|
|
#ifdef CONFIG_LOCKDEP
|
|
|
|
#define i915_sw_fence_init(fence, fn) \
|
|
|
|
do { \
|
|
|
|
static struct lock_class_key __key; \
|
|
|
|
\
|
|
|
|
__i915_sw_fence_init((fence), (fn), #fence, &__key); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define i915_sw_fence_init(fence, fn) \
|
|
|
|
__i915_sw_fence_init((fence), (fn), NULL, NULL)
|
|
|
|
#endif
|
|
|
|
|
2016-11-25 13:17:18 +00:00
|
|
|
#ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
|
|
|
|
void i915_sw_fence_fini(struct i915_sw_fence *fence);
|
|
|
|
#else
|
|
|
|
static inline void i915_sw_fence_fini(struct i915_sw_fence *fence) {}
|
|
|
|
#endif
|
|
|
|
|
2016-09-09 13:11:41 +00:00
|
|
|
void i915_sw_fence_commit(struct i915_sw_fence *fence);
|
|
|
|
|
|
|
|
int i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence,
|
|
|
|
struct i915_sw_fence *after,
|
2017-06-20 10:06:13 +00:00
|
|
|
wait_queue_entry_t *wq);
|
2016-10-28 12:58:25 +00:00
|
|
|
int i915_sw_fence_await_sw_fence_gfp(struct i915_sw_fence *fence,
|
|
|
|
struct i915_sw_fence *after,
|
|
|
|
gfp_t gfp);
|
2019-03-22 09:23:25 +00:00
|
|
|
|
|
|
|
struct i915_sw_dma_fence_cb {
|
|
|
|
struct dma_fence_cb base;
|
|
|
|
struct i915_sw_fence *fence;
|
|
|
|
};
|
|
|
|
|
|
|
|
int __i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
|
|
|
|
struct dma_fence *dma,
|
|
|
|
struct i915_sw_dma_fence_cb *cb);
|
2016-09-09 13:11:41 +00:00
|
|
|
int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
|
2016-10-25 12:00:45 +00:00
|
|
|
struct dma_fence *dma,
|
2016-09-09 13:11:41 +00:00
|
|
|
unsigned long timeout,
|
|
|
|
gfp_t gfp);
|
2019-03-22 09:23:25 +00:00
|
|
|
|
2016-09-09 13:11:41 +00:00
|
|
|
int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,
|
2019-08-11 08:06:32 +00:00
|
|
|
struct dma_resv *resv,
|
2016-10-25 12:00:45 +00:00
|
|
|
const struct dma_fence_ops *exclude,
|
2016-09-09 13:11:41 +00:00
|
|
|
bool write,
|
|
|
|
unsigned long timeout,
|
|
|
|
gfp_t gfp);
|
|
|
|
|
2019-03-01 17:09:00 +00:00
|
|
|
void i915_sw_fence_await(struct i915_sw_fence *fence);
|
|
|
|
void i915_sw_fence_complete(struct i915_sw_fence *fence);
|
|
|
|
|
2016-11-25 13:17:17 +00:00
|
|
|
static inline bool i915_sw_fence_signaled(const struct i915_sw_fence *fence)
|
|
|
|
{
|
|
|
|
return atomic_read(&fence->pending) <= 0;
|
|
|
|
}
|
|
|
|
|
2016-09-09 13:11:41 +00:00
|
|
|
static inline bool i915_sw_fence_done(const struct i915_sw_fence *fence)
|
|
|
|
{
|
|
|
|
return atomic_read(&fence->pending) < 0;
|
|
|
|
}
|
|
|
|
|
2016-10-28 12:58:25 +00:00
|
|
|
static inline void i915_sw_fence_wait(struct i915_sw_fence *fence)
|
|
|
|
{
|
|
|
|
wait_event(fence->wait, i915_sw_fence_done(fence));
|
|
|
|
}
|
|
|
|
|
2019-08-17 23:25:11 +00:00
|
|
|
static inline void
|
|
|
|
i915_sw_fence_set_error_once(struct i915_sw_fence *fence, int error)
|
|
|
|
{
|
|
|
|
cmpxchg(&fence->error, 0, error);
|
|
|
|
}
|
|
|
|
|
2016-09-09 13:11:41 +00:00
|
|
|
#endif /* _I915_SW_FENCE_H_ */
|