kgsl_timeline.h 3.75 KB
Newer Older
1
2
/* SPDX-License-Identifier: GPL-2.0-only */
/*
3
 * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 */

#ifndef __KGSL_TIMELINE_H
#define __KGSL_TIMELINE_H

/**
 * struct kgsl_timeline - Container for a timeline object
 */
struct kgsl_timeline {
	/** @context: dma-fence timeline context */
	u64 context;
	/** @id: Timeline identifier */
	int id;
	/** @value: Current value of the timeline */
	u64 value;
19
20
21
	/** @fence_lock: Lock to protect @fences */
	spinlock_t fence_lock;
	/** @lock: Lock to use for locking each fence in @fences */
22
23
24
25
26
27
28
	spinlock_t lock;
	/** @ref: Reference count for the struct */
	struct kref ref;
	/** @fences: sorted list of active fences */
	struct list_head fences;
	/** @name: Name of the timeline for debugging */
	const char name[32];
29
30
	/** @dev_priv: pointer to the owning device instance */
	struct kgsl_device_private *dev_priv;
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
};

/**
 * kgsl_timeline_signal - Signal the timeline
 * @timeline: Pointer to a timeline container
 * @seqno: Seqeuence number to signal
 *
 * Advance @timeline to sequence number @seqno and signal any fences that might
 * have expired.
 */
void kgsl_timeline_signal(struct kgsl_timeline *timeline, u64 seqno);

/**
 * kgsl_timeline_destroy - Timeline destroy callback
 * @kref: Refcount pointer for the timeline
 *
 * Reference count callback for the timeline called when the all the object
 * references have been released.
 */
void kgsl_timeline_destroy(struct kref *kref);

/**
 * kgsl_timeline_fence_alloc - Allocate a new fence on a timeline
 * @timeline: Pointer to a timeline container
 * @seqno: Sequence number for the new fence to wait for
 *
 * Create and return a new fence on the timeline that will expire when the
 * timeline value is greater or equal to @seqno.
 * Return: A pointer to the newly created fence
 */
struct dma_fence *kgsl_timeline_fence_alloc(struct kgsl_timeline *timeline,
		u64 seqno);

/**
 * kgsl_timeline_by_id - Look up a timeline by an id
 * @device: A KGSL device handle
 * @id: Lookup identifier
 *
 * Find and return the timeline associated with identifer @id.
 * Return: A pointer to a timeline or PTR_ERR() encoded error on failure.
 */
struct kgsl_timeline *kgsl_timeline_by_id(struct kgsl_device *device,
		u32 id);

/**
 * kgsl_timeline_get - Get a reference to an existing timeline
 * @timeline: Pointer to a timeline container
 *
 * Get a new reference to the timeline and return the pointer back to the user.
 * Return: The pointer to the timeline or PTR_ERR encoded error on failure
 */
struct kgsl_timeline *kgsl_timeline_get(struct kgsl_timeline *timeline);

/**
 * kgsl_timeline_put - Release a reference to a timeline
 * @timeline: Pointer to a timeline container
 *
 * Release a reference to a timeline and destroy it if there are no other
 * references
 */
static inline void kgsl_timeline_put(struct kgsl_timeline *timeline)
{
	if (!IS_ERR_OR_NULL(timeline))
		kref_put(&timeline->ref, kgsl_timeline_destroy);
}

/**
 * kgsl_timelines_to_fence_array - Return a dma-fence array of timeline fences
 * @device: A KGSL device handle
 * @timelines: Userspace pointer to an array of &struct kgsl_timeline_val
 * @count: Number of entries in @timelines
 * @usize: Size of each entry in @timelines
 * @any: True if the fence should expire on any timeline expiring or false if it
 * should wait until all timelines have expired
 *
 * Give a list of &struct kgsl_timeline_val entries, create a dma-fence-array
 * containing fences for each timeline/seqno pair. If @any is set the
 * dma-fence-array will be set to expire if any of the encapsulated timeline
 * fences expire.  If @any is false, then the fence will wait for ALL of the
 * encapsulated timeline fences to expire.
 */
struct dma_fence *kgsl_timelines_to_fence_array(struct kgsl_device *device,
113
		u64 timelines, u32 count, u64 usize, bool any);
114
115

#endif