Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 1 | /* 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 Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/errno.h> |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 18 | #include <linux/mutex.h> |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 19 | |
Clarence Ip | 78a04ed | 2016-10-04 15:57:45 -0400 | [diff] [blame] | 20 | #ifndef CHAR_BIT |
| 21 | #define CHAR_BIT 8 /* define this if limits.h not available */ |
| 22 | #endif |
| 23 | |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 24 | #ifdef CONFIG_SYNC |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 25 | /** |
| 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 | */ |
| 34 | void *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 | */ |
| 44 | void 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 | */ |
| 54 | int sde_sync_wait(void *fence, long timeout_ms); |
Clarence Ip | 78a04ed | 2016-10-04 15:57:45 -0400 | [diff] [blame] | 55 | |
| 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 | */ |
| 63 | uint32_t sde_sync_get_name_prefix(void *fence); |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 64 | #else |
| 65 | static inline void *sde_sync_get(uint64_t fd) |
| 66 | { |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | static inline void sde_sync_put(void *fence) |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | static inline int sde_sync_wait(void *fence, long timeout_ms) |
| 75 | { |
| 76 | return 0; |
| 77 | } |
Clarence Ip | 78a04ed | 2016-10-04 15:57:45 -0400 | [diff] [blame] | 78 | |
| 79 | static inline uint32_t sde_sync_get_name_prefix(void *fence) |
| 80 | { |
| 81 | return 0x0; |
| 82 | } |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 83 | #endif |
| 84 | |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 85 | /** |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 86 | * 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 Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 91 | * @fence_lock: Mutex object to protect local fence variables |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 92 | */ |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 93 | struct sde_fence { |
| 94 | void *timeline; |
| 95 | void *dev; |
| 96 | int32_t commit_count; |
| 97 | int32_t done_count; |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 98 | 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 Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 107 | * Returns: Zero on success |
| 108 | */ |
| 109 | int sde_fence_init(void *dev, |
| 110 | struct sde_fence *fence, |
Clarence Ip | 9a74a44 | 2016-08-25 18:29:03 -0400 | [diff] [blame] | 111 | const char *name); |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 112 | |
| 113 | /** |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 114 | * sde_fence_deinit - deinit fence container |
| 115 | * @fence: Pointer fence container |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 116 | */ |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 117 | void sde_fence_deinit(struct sde_fence *fence); |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 118 | |
| 119 | /** |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 120 | * sde_fence_prepare - prepare to return fences for current commit |
| 121 | * @fence: Pointer fence container |
| 122 | * Returns: Zero on success |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 123 | */ |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 124 | int 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 Ip | 9a74a44 | 2016-08-25 18:29:03 -0400 | [diff] [blame] | 130 | * @offset: Fence signal commit offset, e.g., +1 to signal on next commit |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 131 | * Returns: Zero on success |
| 132 | */ |
Clarence Ip | 9a74a44 | 2016-08-25 18:29:03 -0400 | [diff] [blame] | 133 | int sde_fence_create(struct sde_fence *fence, uint64_t *val, int offset); |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 134 | |
| 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 | */ |
| 140 | void sde_fence_signal(struct sde_fence *fence, bool is_error); |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 141 | #else |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 142 | static inline int sde_fence_init(void *dev, |
| 143 | struct sde_fence *fence, |
Dhaval Patel | 48f2d0f | 2016-09-27 16:39:12 -0700 | [diff] [blame] | 144 | const char *name) |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 145 | { |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 146 | /* do nothing */ |
Dhaval Patel | 48f2d0f | 2016-09-27 16:39:12 -0700 | [diff] [blame] | 147 | return 0; |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 150 | static inline void sde_fence_deinit(struct sde_fence *fence) |
| 151 | { |
| 152 | /* do nothing */ |
| 153 | } |
| 154 | |
| 155 | static inline void sde_fence_prepare(struct sde_fence *fence) |
| 156 | { |
| 157 | /* do nothing */ |
| 158 | } |
| 159 | |
| 160 | static inline int sde_fence_get(struct sde_fence *fence, uint64_t *val) |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 161 | { |
| 162 | return -EINVAL; |
| 163 | } |
| 164 | |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 165 | static inline void sde_fence_signal(struct sde_fence *fence, bool is_error) |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 166 | { |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 167 | /* do nothing */ |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 168 | } |
Dhaval Patel | 48f2d0f | 2016-09-27 16:39:12 -0700 | [diff] [blame] | 169 | |
| 170 | static inline int sde_fence_create(struct sde_fence *fence, uint64_t *val, |
| 171 | int offset) |
| 172 | { |
| 173 | return 0; |
| 174 | } |
Clarence Ip | ea16954 | 2016-06-02 17:04:11 -0400 | [diff] [blame] | 175 | #endif /* IS_ENABLED(CONFIG_SW_SYNC) */ |
Clarence Ip | 6213210 | 2016-06-09 13:30:07 -0400 | [diff] [blame] | 176 | |
Clarence Ip | ae4e60c | 2016-06-26 22:44:04 -0400 | [diff] [blame] | 177 | #endif /* _SDE_FENCE_H_ */ |