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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _SDE_FENCE_H_
#define _SDE_FENCE_H_
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/mutex.h>
#ifndef CHAR_BIT
#define CHAR_BIT 8 /* define this if limits.h not available */
#endif
#ifdef CONFIG_SYNC
/**
* sde_sync_get - Query sync fence object from a file handle
*
* On success, this function also increments the refcount of the sync fence
*
* @fd: Integer sync fence handle
*
* Return: Pointer to sync fence object, or NULL
*/
void *sde_sync_get(uint64_t fd);
/**
* sde_sync_put - Releases a sync fence object acquired by @sde_sync_get
*
* This function decrements the sync fence's reference count; the object will
* be released if the reference count goes to zero.
*
* @fence: Pointer to sync fence
*/
void sde_sync_put(void *fence);
/**
* sde_sync_wait - Query sync fence object from a file handle
*
* @fence: Pointer to sync fence
* @timeout_ms: Time to wait, in milliseconds. Waits forever if timeout_ms < 0
*
* Return: Zero on success, or -ETIME on timeout
*/
int sde_sync_wait(void *fence, long timeout_ms);
/**
* sde_sync_get_name_prefix - get integer representation of fence name prefix
* @fence: Pointer to opaque fence structure
*
* Return: 32-bit integer containing first 4 characters of fence name,
* big-endian notation
*/
uint32_t sde_sync_get_name_prefix(void *fence);
#else
static inline void *sde_sync_get(uint64_t fd)
{
return NULL;
}
static inline void sde_sync_put(void *fence)
{
}
static inline int sde_sync_wait(void *fence, long timeout_ms)
{
return 0;
}
static inline uint32_t sde_sync_get_name_prefix(void *fence)
{
return 0x0;
}
#endif
/**
* struct sde_fence - output fence container structure
* @timeline: Pointer to fence timeline
* @commit_count: Number of detected commits since bootup
* @done_count: Number of completed commits since bootup
* @drm_id: ID number of owning DRM Object
* @fence_lock: Mutex object to protect local fence variables
*/
struct sde_fence {
void *timeline;
int32_t commit_count;
int32_t done_count;
uint32_t drm_id;
struct mutex fence_lock;
};
#if IS_ENABLED(CONFIG_SW_SYNC)
/**
* sde_fence_init - initialize fence object
* @fence: Pointer to crtc fence object
* @drm_id: ID number of owning DRM Object
* @name: Timeline name
* Returns: Zero on success
*/
int sde_fence_init(struct sde_fence *fence,
const char *name,
uint32_t drm_id);
/**
* sde_fence_deinit - deinit fence container
* @fence: Pointer fence container
*/
void sde_fence_deinit(struct sde_fence *fence);
/**
* sde_fence_prepare - prepare to return fences for current commit
* @fence: Pointer fence container
* Returns: Zero on success
*/
int sde_fence_prepare(struct sde_fence *fence);
/**
* sde_fence_create - create output fence object
* @fence: Pointer fence container
* @val: Pointer to output value variable, fence fd will be placed here
* @offset: Fence signal commit offset, e.g., +1 to signal on next commit
* Returns: Zero on success
*/
int sde_fence_create(struct sde_fence *fence, uint64_t *val, int offset);
/**
* sde_fence_signal - advance fence timeline to signal outstanding fences
* @fence: Pointer fence container
* @is_error: Set to non-zero if the commit didn't complete successfully
*/
void sde_fence_signal(struct sde_fence *fence, bool is_error);
#else
static inline int sde_fence_init(struct sde_fence *fence,
const char *name,
uint32_t drm_id)
{
/* do nothing */
return 0;
}
static inline void sde_fence_deinit(struct sde_fence *fence)
{
/* do nothing */
}
static inline void sde_fence_prepare(struct sde_fence *fence)
{
/* do nothing */
}
static inline int sde_fence_get(struct sde_fence *fence, uint64_t *val)
{
return -EINVAL;
}
static inline void sde_fence_signal(struct sde_fence *fence, bool is_error)
{
/* do nothing */
}
static inline int sde_fence_create(struct sde_fence *fence, uint64_t *val,
int offset)
{
return 0;
}
#endif /* IS_ENABLED(CONFIG_SW_SYNC) */
#endif /* _SDE_FENCE_H_ */
|