Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * include/linux/sync.h |
| 3 | * |
| 4 | * Copyright (C) 2012 Google, Inc. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #ifndef _LINUX_SYNC_H |
| 14 | #define _LINUX_SYNC_H |
| 15 | |
| 16 | #include <linux/types.h> |
Erik Gilling | 0154417 | 2013-02-28 16:43:10 -0800 | [diff] [blame] | 17 | #include <linux/kref.h> |
Erik Gilling | 97a8484 | 2013-02-28 16:42:59 -0800 | [diff] [blame] | 18 | #include <linux/ktime.h> |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 19 | #include <linux/list.h> |
| 20 | #include <linux/spinlock.h> |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 21 | #include <linux/fence.h> |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 22 | |
Gustavo Padovan | 460bfc4 | 2016-04-28 10:46:57 -0300 | [diff] [blame^] | 23 | #include <linux/sync_file.h> |
| 24 | #include <uapi/linux/sync_file.h> |
Colin Cross | 64907b9 | 2014-02-17 13:58:32 -0800 | [diff] [blame] | 25 | |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 26 | struct sync_timeline; |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * struct sync_timeline_ops - sync object implementation ops |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 30 | * @driver_name: name of the implementation |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 31 | * @has_signaled: returns: |
| 32 | * 1 if pt has signaled |
| 33 | * 0 if pt has not signaled |
| 34 | * <0 on error |
Erik Gilling | dbd5239 | 2013-02-28 16:43:21 -0800 | [diff] [blame] | 35 | * @timeline_value_str: fill str with the value of the sync_timeline's counter |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 36 | * @fence_value_str: fill str with the value of the fence |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 37 | */ |
| 38 | struct sync_timeline_ops { |
| 39 | const char *driver_name; |
| 40 | |
| 41 | /* required */ |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 42 | int (*has_signaled)(struct fence *fence); |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 43 | |
Erik Gilling | 79ba152 | 2013-02-28 16:43:02 -0800 | [diff] [blame] | 44 | /* optional */ |
Erik Gilling | dbd5239 | 2013-02-28 16:43:21 -0800 | [diff] [blame] | 45 | void (*timeline_value_str)(struct sync_timeline *timeline, char *str, |
| 46 | int size); |
| 47 | |
| 48 | /* optional */ |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 49 | void (*fence_value_str)(struct fence *fence, char *str, int size); |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * struct sync_timeline - sync object |
Erik Gilling | c5b86b7 | 2013-02-28 16:43:11 -0800 | [diff] [blame] | 54 | * @kref: reference count on fence. |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 55 | * @ops: ops that define the implementation of the sync_timeline |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 56 | * @name: name of the sync_timeline. Useful for debugging |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 57 | * @destroyed: set when sync_timeline is destroyed |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 58 | * @child_list_head: list of children sync_pts for this sync_timeline |
| 59 | * @child_list_lock: lock protecting @child_list_head, destroyed, and |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 60 | * fence.status |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 61 | * @active_list_head: list of active (unsignaled/errored) sync_pts |
Erik Gilling | af7582f | 2013-02-28 16:43:00 -0800 | [diff] [blame] | 62 | * @sync_timeline_list: membership in global sync_timeline_list |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 63 | */ |
| 64 | struct sync_timeline { |
Erik Gilling | c5b86b7 | 2013-02-28 16:43:11 -0800 | [diff] [blame] | 65 | struct kref kref; |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 66 | const struct sync_timeline_ops *ops; |
| 67 | char name[32]; |
| 68 | |
| 69 | /* protected by child_list_lock */ |
| 70 | bool destroyed; |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 71 | int context, value; |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 72 | |
| 73 | struct list_head child_list_head; |
| 74 | spinlock_t child_list_lock; |
| 75 | |
| 76 | struct list_head active_list_head; |
Erik Gilling | af7582f | 2013-02-28 16:43:00 -0800 | [diff] [blame] | 77 | |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 78 | #ifdef CONFIG_DEBUG_FS |
Erik Gilling | af7582f | 2013-02-28 16:43:00 -0800 | [diff] [blame] | 79 | struct list_head sync_timeline_list; |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 80 | #endif |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 83 | static inline struct sync_timeline *fence_parent(struct fence *fence) |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 84 | { |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 85 | return container_of(fence->lock, struct sync_timeline, |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 86 | child_list_lock); |
| 87 | } |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 88 | |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 89 | /* |
| 90 | * API for sync_timeline implementers |
| 91 | */ |
| 92 | |
| 93 | /** |
| 94 | * sync_timeline_create() - creates a sync object |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 95 | * @ops: specifies the implementation ops for the object |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 96 | * @size: size to allocate for this obj |
| 97 | * @name: sync_timeline name |
| 98 | * |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 99 | * Creates a new sync_timeline which will use the implementation specified by |
| 100 | * @ops. @size bytes will be allocated allowing for implementation specific |
Gustavo Padovan | 9b32381 | 2016-01-21 10:49:14 -0200 | [diff] [blame] | 101 | * data to be kept after the generic sync_timeline struct. Returns the |
| 102 | * sync_timeline object or NULL in case of error. |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 103 | */ |
| 104 | struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops, |
| 105 | int size, const char *name); |
| 106 | |
| 107 | /** |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 108 | * sync_timeline_destroy() - destroys a sync object |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 109 | * @obj: sync_timeline to destroy |
| 110 | * |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 111 | * A sync implementation should call this when the @obj is going away |
| 112 | * (i.e. module unload.) @obj won't actually be freed until all its children |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 113 | * fences are freed. |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 114 | */ |
| 115 | void sync_timeline_destroy(struct sync_timeline *obj); |
| 116 | |
| 117 | /** |
| 118 | * sync_timeline_signal() - signal a status change on a sync_timeline |
| 119 | * @obj: sync_timeline to signal |
| 120 | * |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 121 | * A sync implementation should call this any time one of it's fences |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 122 | * has signaled or has an error condition. |
| 123 | */ |
| 124 | void sync_timeline_signal(struct sync_timeline *obj); |
| 125 | |
| 126 | /** |
| 127 | * sync_pt_create() - creates a sync pt |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 128 | * @parent: fence's parent sync_timeline |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 129 | * @size: size to allocate for this pt |
| 130 | * |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 131 | * Creates a new fence as a child of @parent. @size bytes will be |
Masanari Iida | 4e20eff | 2013-10-31 14:20:25 +0900 | [diff] [blame] | 132 | * allocated allowing for implementation specific data to be kept after |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 133 | * the generic sync_timeline struct. Returns the fence object or |
Gustavo Padovan | 9b32381 | 2016-01-21 10:49:14 -0200 | [diff] [blame] | 134 | * NULL in case of error. |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 135 | */ |
Gustavo Padovan | b55b54b | 2016-01-21 10:49:21 -0200 | [diff] [blame] | 136 | struct fence *sync_pt_create(struct sync_timeline *parent, int size); |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 137 | |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 138 | #ifdef CONFIG_DEBUG_FS |
| 139 | |
Joe Perches | d30649a | 2015-08-10 14:51:16 -0700 | [diff] [blame] | 140 | void sync_timeline_debug_add(struct sync_timeline *obj); |
| 141 | void sync_timeline_debug_remove(struct sync_timeline *obj); |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 142 | void sync_file_debug_add(struct sync_file *fence); |
| 143 | void sync_file_debug_remove(struct sync_file *fence); |
Joe Perches | d30649a | 2015-08-10 14:51:16 -0700 | [diff] [blame] | 144 | void sync_dump(void); |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 145 | |
| 146 | #else |
| 147 | # define sync_timeline_debug_add(obj) |
| 148 | # define sync_timeline_debug_remove(obj) |
Gustavo Padovan | d7fdb0a | 2016-01-21 10:49:19 -0200 | [diff] [blame] | 149 | # define sync_file_debug_add(fence) |
| 150 | # define sync_file_debug_remove(fence) |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 151 | # define sync_dump() |
| 152 | #endif |
Maarten Lankhorst | 0f0d840 | 2014-07-01 12:57:31 +0200 | [diff] [blame] | 153 | |
Erik Gilling | 7ad530b | 2013-02-28 16:42:57 -0800 | [diff] [blame] | 154 | #endif /* _LINUX_SYNC_H */ |