summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/i915/i915_active_types.h
blob: 021167f0004d63cbcbab4ede0fc86176534abaed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * SPDX-License-Identifier: MIT
 *
 * Copyright © 2019 Intel Corporation
 */

#ifndef _I915_ACTIVE_TYPES_H_
#define _I915_ACTIVE_TYPES_H_

#include <linux/atomic.h>
#include <linux/dma-fence.h>
#include <linux/llist.h>
#include <linux/mutex.h>
#include <linux/rbtree.h>
#include <linux/rcupdate.h>
#include <linux/workqueue.h>

#include "i915_utils.h"

struct drm_i915_private;
struct i915_active_request;
struct i915_request;

typedef void (*i915_active_retire_fn)(struct i915_active_request *,
				      struct i915_request *);

struct i915_active_request {
	struct i915_request __rcu *request;
	struct list_head link;
	i915_active_retire_fn retire;
#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
	/*
	 * Incorporeal!
	 *
	 * Updates to the i915_active_request must be serialised under a lock
	 * to ensure that the timeline is ordered. Normally, this is the
	 * timeline->mutex, but another mutex may be used so long as it is
	 * done so consistently.
	 *
	 * For lockdep tracking of the above, we store the lock we intend
	 * to always use for updates of this i915_active_request during
	 * construction and assert that is held on every update.
	 */
	struct mutex *lock;
#endif
};

struct active_node;

#define I915_ACTIVE_MAY_SLEEP BIT(0)

#define __i915_active_call __aligned(4)
#define i915_active_may_sleep(fn) ptr_pack_bits(&(fn), I915_ACTIVE_MAY_SLEEP, 2)

struct i915_active {
	struct drm_i915_private *i915;

	struct active_node *cache;
	struct rb_root tree;
	struct mutex mutex;
	atomic_t count;

	/* Preallocated "exclusive" node */
	struct dma_fence __rcu *excl;
	struct dma_fence_cb excl_cb;

	unsigned long flags;
#define I915_ACTIVE_RETIRE_SLEEPS BIT(0)
#define I915_ACTIVE_GRAB_BIT 1

	int (*active)(struct i915_active *ref);
	void (*retire)(struct i915_active *ref);

	struct work_struct work;

	struct llist_head preallocated_barriers;
};

#endif /* _I915_ACTIVE_TYPES_H_ */