| /* |
| * include/linux/sync.h |
| * |
| * Copyright (C) 2012 Google, Inc. |
| * |
| * 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 _LINUX_SYNC_H |
| #define _LINUX_SYNC_H |
| |
| #include <linux/types.h> |
| #include <linux/kref.h> |
| #include <linux/ktime.h> |
| #include <linux/list.h> |
| #include <linux/spinlock.h> |
| #include <linux/fence.h> |
| |
| #include <linux/sync_file.h> |
| #include <uapi/linux/sync_file.h> |
| |
| /** |
| * struct sync_timeline - sync object |
| * @kref: reference count on fence. |
| * @drv_name: drv_name of the driver using the sync_timeline |
| * @name: name of the sync_timeline. Useful for debugging |
| * @destroyed: set when sync_timeline is destroyed |
| * @child_list_head: list of children sync_pts for this sync_timeline |
| * @child_list_lock: lock protecting @child_list_head, destroyed, and |
| * fence.status |
| * @active_list_head: list of active (unsignaled/errored) sync_pts |
| * @sync_timeline_list: membership in global sync_timeline_list |
| */ |
| struct sync_timeline { |
| struct kref kref; |
| char drv_name[32]; |
| char name[32]; |
| |
| /* protected by child_list_lock */ |
| bool destroyed; |
| int context, value; |
| |
| struct list_head child_list_head; |
| spinlock_t child_list_lock; |
| |
| struct list_head active_list_head; |
| |
| #ifdef CONFIG_DEBUG_FS |
| struct list_head sync_timeline_list; |
| #endif |
| }; |
| |
| static inline struct sync_timeline *fence_parent(struct fence *fence) |
| { |
| return container_of(fence->lock, struct sync_timeline, |
| child_list_lock); |
| } |
| |
| /** |
| * struct sync_pt - sync_pt object |
| * @base: base fence object |
| * @child_list: sync timeline child's list |
| * @active_list: sync timeline active child's list |
| */ |
| struct sync_pt { |
| struct fence base; |
| struct list_head child_list; |
| struct list_head active_list; |
| }; |
| |
| extern const struct fence_ops timeline_fence_ops; |
| |
| static inline struct sync_pt *fence_to_sync_pt(struct fence *fence) |
| { |
| if (fence->ops != &timeline_fence_ops) |
| return NULL; |
| return container_of(fence, struct sync_pt, base); |
| } |
| |
| /* |
| * API for sync_timeline implementers |
| */ |
| |
| /** |
| * sync_timeline_create() - creates a sync object |
| * @drv_name: sync_timeline driver name |
| * @name: sync_timeline name |
| * |
| * Creates a new sync_timeline. Returns the sync_timeline object or NULL in |
| * case of error. |
| */ |
| struct sync_timeline *sync_timeline_create(const char *drv_name, |
| const char *name); |
| |
| /** |
| * sync_timeline_destroy() - destroys a sync object |
| * @obj: sync_timeline to destroy |
| * |
| * A sync implementation should call this when the @obj is going away |
| * (i.e. module unload.) @obj won't actually be freed until all its children |
| * fences are freed. |
| */ |
| void sync_timeline_destroy(struct sync_timeline *obj); |
| |
| /** |
| * sync_timeline_signal() - signal a status change on a sync_timeline |
| * @obj: sync_timeline to signal |
| * @inc: num to increment on timeline->value |
| * |
| * A sync implementation should call this any time one of it's fences |
| * has signaled or has an error condition. |
| */ |
| void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc); |
| |
| /** |
| * sync_pt_create() - creates a sync pt |
| * @parent: fence's parent sync_timeline |
| * @size: size to allocate for this pt |
| * @inc: value of the fence |
| * |
| * Creates a new sync_pt as a child of @parent. @size bytes will be |
| * allocated allowing for implementation specific data to be kept after |
| * the generic sync_timeline struct. Returns the sync_pt object or |
| * NULL in case of error. |
| */ |
| struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size, |
| unsigned int inc); |
| |
| #ifdef CONFIG_DEBUG_FS |
| |
| void sync_timeline_debug_add(struct sync_timeline *obj); |
| void sync_timeline_debug_remove(struct sync_timeline *obj); |
| void sync_file_debug_add(struct sync_file *fence); |
| void sync_file_debug_remove(struct sync_file *fence); |
| void sync_dump(void); |
| |
| #else |
| # define sync_timeline_debug_add(obj) |
| # define sync_timeline_debug_remove(obj) |
| # define sync_file_debug_add(fence) |
| # define sync_file_debug_remove(fence) |
| # define sync_dump() |
| #endif |
| |
| #endif /* _LINUX_SYNC_H */ |