blob: b5980b4e5b322cd03a0f229e5446a6b6fe3960e6 [file] [log] [blame]
Clarence Ipae4e60c2016-06-26 22:44:04 -04001/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _SDE_FENCE_H_
14#define _SDE_FENCE_H_
15
Clarence Ip62132102016-06-09 13:30:07 -040016#include <linux/kernel.h>
17#include <linux/errno.h>
Clarence Ipea169542016-06-02 17:04:11 -040018#include <linux/mutex.h>
Clarence Ipae4e60c2016-06-26 22:44:04 -040019
Clarence Ip78a04ed2016-10-04 15:57:45 -040020#ifndef CHAR_BIT
21#define CHAR_BIT 8 /* define this if limits.h not available */
22#endif
23
Clarence Ip62132102016-06-09 13:30:07 -040024#ifdef CONFIG_SYNC
Clarence Ipae4e60c2016-06-26 22:44:04 -040025/**
26 * sde_sync_get - Query sync fence object from a file handle
27 *
28 * On success, this function also increments the refcount of the sync fence
29 *
30 * @fd: Integer sync fence handle
31 *
32 * Return: Pointer to sync fence object, or NULL
33 */
34void *sde_sync_get(uint64_t fd);
35
36/**
37 * sde_sync_put - Releases a sync fence object acquired by @sde_sync_get
38 *
39 * This function decrements the sync fence's reference count; the object will
40 * be released if the reference count goes to zero.
41 *
42 * @fence: Pointer to sync fence
43 */
44void sde_sync_put(void *fence);
45
46/**
47 * sde_sync_wait - Query sync fence object from a file handle
48 *
49 * @fence: Pointer to sync fence
50 * @timeout_ms: Time to wait, in milliseconds. Waits forever if timeout_ms < 0
51 *
52 * Return: Zero on success, or -ETIME on timeout
53 */
54int sde_sync_wait(void *fence, long timeout_ms);
Clarence Ip78a04ed2016-10-04 15:57:45 -040055
56/**
57 * sde_sync_get_name_prefix - get integer representation of fence name prefix
58 * @fence: Pointer to opaque fence structure
59 *
60 * Return: 32-bit integer containing first 4 characters of fence name,
61 * big-endian notation
62 */
63uint32_t sde_sync_get_name_prefix(void *fence);
Clarence Ip62132102016-06-09 13:30:07 -040064#else
65static inline void *sde_sync_get(uint64_t fd)
66{
67 return NULL;
68}
69
70static inline void sde_sync_put(void *fence)
71{
72}
73
74static inline int sde_sync_wait(void *fence, long timeout_ms)
75{
76 return 0;
77}
Clarence Ip78a04ed2016-10-04 15:57:45 -040078
79static inline uint32_t sde_sync_get_name_prefix(void *fence)
80{
81 return 0x0;
82}
Clarence Ipae4e60c2016-06-26 22:44:04 -040083#endif
84
Clarence Ip62132102016-06-09 13:30:07 -040085/**
Clarence Ipea169542016-06-02 17:04:11 -040086 * struct sde_fence - output fence container structure
87 * @timeline: Pointer to fence timeline
88 * @dev: Pointer to drm device structure
89 * @commit_count: Number of detected commits since bootup
90 * @done_count: Number of completed commits since bootup
Clarence Ipea169542016-06-02 17:04:11 -040091 * @fence_lock: Mutex object to protect local fence variables
Clarence Ip62132102016-06-09 13:30:07 -040092 */
Clarence Ipea169542016-06-02 17:04:11 -040093struct sde_fence {
94 void *timeline;
95 void *dev;
96 int32_t commit_count;
97 int32_t done_count;
Clarence Ipea169542016-06-02 17:04:11 -040098 struct mutex fence_lock;
99};
100
101#if IS_ENABLED(CONFIG_SW_SYNC)
102/**
103 * sde_fence_init - initialize fence object
104 * @dev: Pointer to drm device structure
105 * @fence: Pointer to crtc fence object
106 * @name: Timeline name
Clarence Ipea169542016-06-02 17:04:11 -0400107 * Returns: Zero on success
108 */
109int sde_fence_init(void *dev,
110 struct sde_fence *fence,
Clarence Ip9a74a442016-08-25 18:29:03 -0400111 const char *name);
Clarence Ip62132102016-06-09 13:30:07 -0400112
113/**
Clarence Ipea169542016-06-02 17:04:11 -0400114 * sde_fence_deinit - deinit fence container
115 * @fence: Pointer fence container
Clarence Ip62132102016-06-09 13:30:07 -0400116 */
Clarence Ipea169542016-06-02 17:04:11 -0400117void sde_fence_deinit(struct sde_fence *fence);
Clarence Ip62132102016-06-09 13:30:07 -0400118
119/**
Clarence Ipea169542016-06-02 17:04:11 -0400120 * sde_fence_prepare - prepare to return fences for current commit
121 * @fence: Pointer fence container
122 * Returns: Zero on success
Clarence Ip62132102016-06-09 13:30:07 -0400123 */
Clarence Ipea169542016-06-02 17:04:11 -0400124int sde_fence_prepare(struct sde_fence *fence);
125
126/**
127 * sde_fence_create - create output fence object
128 * @fence: Pointer fence container
129 * @val: Pointer to output value variable, fence fd will be placed here
Clarence Ip9a74a442016-08-25 18:29:03 -0400130 * @offset: Fence signal commit offset, e.g., +1 to signal on next commit
Clarence Ipea169542016-06-02 17:04:11 -0400131 * Returns: Zero on success
132 */
Clarence Ip9a74a442016-08-25 18:29:03 -0400133int sde_fence_create(struct sde_fence *fence, uint64_t *val, int offset);
Clarence Ipea169542016-06-02 17:04:11 -0400134
135/**
136 * sde_fence_signal - advance fence timeline to signal outstanding fences
137 * @fence: Pointer fence container
138 * @is_error: Set to non-zero if the commit didn't complete successfully
139 */
140void sde_fence_signal(struct sde_fence *fence, bool is_error);
Clarence Ip62132102016-06-09 13:30:07 -0400141#else
Clarence Ipea169542016-06-02 17:04:11 -0400142static inline int sde_fence_init(void *dev,
143 struct sde_fence *fence,
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700144 const char *name)
Clarence Ip62132102016-06-09 13:30:07 -0400145{
Clarence Ipea169542016-06-02 17:04:11 -0400146 /* do nothing */
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700147 return 0;
Clarence Ip62132102016-06-09 13:30:07 -0400148}
149
Clarence Ipea169542016-06-02 17:04:11 -0400150static inline void sde_fence_deinit(struct sde_fence *fence)
151{
152 /* do nothing */
153}
154
155static inline void sde_fence_prepare(struct sde_fence *fence)
156{
157 /* do nothing */
158}
159
160static inline int sde_fence_get(struct sde_fence *fence, uint64_t *val)
Clarence Ip62132102016-06-09 13:30:07 -0400161{
162 return -EINVAL;
163}
164
Clarence Ipea169542016-06-02 17:04:11 -0400165static inline void sde_fence_signal(struct sde_fence *fence, bool is_error)
Clarence Ip62132102016-06-09 13:30:07 -0400166{
Clarence Ipea169542016-06-02 17:04:11 -0400167 /* do nothing */
Clarence Ip62132102016-06-09 13:30:07 -0400168}
Dhaval Patel48f2d0f2016-09-27 16:39:12 -0700169
170static inline int sde_fence_create(struct sde_fence *fence, uint64_t *val,
171 int offset)
172{
173 return 0;
174}
Clarence Ipea169542016-06-02 17:04:11 -0400175#endif /* IS_ENABLED(CONFIG_SW_SYNC) */
Clarence Ip62132102016-06-09 13:30:07 -0400176
Clarence Ipae4e60c2016-06-26 22:44:04 -0400177#endif /* _SDE_FENCE_H_ */