2013-02-28 17:42:57 -07:00
|
|
|
/*
|
|
|
|
* 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>
|
2013-02-28 17:43:10 -07:00
|
|
|
#include <linux/kref.h>
|
2013-02-28 17:42:59 -07:00
|
|
|
#include <linux/ktime.h>
|
2013-02-28 17:42:57 -07:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
2014-07-01 04:57:31 -06:00
|
|
|
#include <linux/fence.h>
|
2013-02-28 17:42:57 -07:00
|
|
|
|
2016-04-28 07:46:57 -06:00
|
|
|
#include <linux/sync_file.h>
|
|
|
|
#include <uapi/linux/sync_file.h>
|
2014-02-17 14:58:32 -07:00
|
|
|
|
2013-02-28 17:42:57 -07:00
|
|
|
/**
|
|
|
|
* struct sync_timeline - sync object
|
2013-02-28 17:43:11 -07:00
|
|
|
* @kref: reference count on fence.
|
2016-05-31 13:58:58 -06:00
|
|
|
* @drv_name: drv_name of the driver using the sync_timeline
|
2013-02-28 17:42:57 -07:00
|
|
|
* @name: name of the sync_timeline. Useful for debugging
|
2013-10-30 23:20:25 -06:00
|
|
|
* @destroyed: set when sync_timeline is destroyed
|
2013-02-28 17:42:57 -07:00
|
|
|
* @child_list_head: list of children sync_pts for this sync_timeline
|
|
|
|
* @child_list_lock: lock protecting @child_list_head, destroyed, and
|
2016-01-21 05:49:21 -07:00
|
|
|
* fence.status
|
2013-02-28 17:42:57 -07:00
|
|
|
* @active_list_head: list of active (unsignaled/errored) sync_pts
|
2013-02-28 17:43:00 -07:00
|
|
|
* @sync_timeline_list: membership in global sync_timeline_list
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
|
|
|
struct sync_timeline {
|
2013-02-28 17:43:11 -07:00
|
|
|
struct kref kref;
|
2016-05-31 13:58:58 -06:00
|
|
|
char drv_name[32];
|
2013-02-28 17:42:57 -07:00
|
|
|
char name[32];
|
|
|
|
|
|
|
|
/* protected by child_list_lock */
|
|
|
|
bool destroyed;
|
2014-07-01 04:57:31 -06:00
|
|
|
int context, value;
|
2013-02-28 17:42:57 -07:00
|
|
|
|
|
|
|
struct list_head child_list_head;
|
|
|
|
spinlock_t child_list_lock;
|
|
|
|
|
|
|
|
struct list_head active_list_head;
|
2013-02-28 17:43:00 -07:00
|
|
|
|
2014-07-01 04:57:31 -06:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
2013-02-28 17:43:00 -07:00
|
|
|
struct list_head sync_timeline_list;
|
2014-07-01 04:57:31 -06:00
|
|
|
#endif
|
2013-02-28 17:42:57 -07:00
|
|
|
};
|
|
|
|
|
2016-01-21 05:49:21 -07:00
|
|
|
static inline struct sync_timeline *fence_parent(struct fence *fence)
|
2014-07-01 04:57:31 -06:00
|
|
|
{
|
2016-01-21 05:49:21 -07:00
|
|
|
return container_of(fence->lock, struct sync_timeline,
|
2014-07-01 04:57:31 -06:00
|
|
|
child_list_lock);
|
|
|
|
}
|
2013-02-28 17:42:59 -07:00
|
|
|
|
2016-05-31 13:59:04 -06:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2013-02-28 17:42:57 -07:00
|
|
|
/*
|
|
|
|
* API for sync_timeline implementers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sync_timeline_create() - creates a sync object
|
2016-05-31 13:58:58 -06:00
|
|
|
* @drv_name: sync_timeline driver name
|
2013-02-28 17:42:57 -07:00
|
|
|
* @name: sync_timeline name
|
|
|
|
*
|
2016-05-31 13:59:03 -06:00
|
|
|
* Creates a new sync_timeline. Returns the sync_timeline object or NULL in
|
2016-05-31 13:58:58 -06:00
|
|
|
* case of error.
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
2016-05-31 13:59:03 -06:00
|
|
|
struct sync_timeline *sync_timeline_create(const char *drv_name,
|
2016-05-31 13:58:58 -06:00
|
|
|
const char *name);
|
2013-02-28 17:42:57 -07:00
|
|
|
|
|
|
|
/**
|
2013-10-30 23:20:25 -06:00
|
|
|
* sync_timeline_destroy() - destroys a sync object
|
2013-02-28 17:42:57 -07:00
|
|
|
* @obj: sync_timeline to destroy
|
|
|
|
*
|
2013-10-30 23:20:25 -06:00
|
|
|
* 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
|
2016-01-21 05:49:21 -07:00
|
|
|
* fences are freed.
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
|
|
|
void sync_timeline_destroy(struct sync_timeline *obj);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sync_timeline_signal() - signal a status change on a sync_timeline
|
|
|
|
* @obj: sync_timeline to signal
|
2016-05-31 13:58:56 -06:00
|
|
|
* @inc: num to increment on timeline->value
|
2013-02-28 17:42:57 -07:00
|
|
|
*
|
2016-01-21 05:49:21 -07:00
|
|
|
* A sync implementation should call this any time one of it's fences
|
2013-02-28 17:42:57 -07:00
|
|
|
* has signaled or has an error condition.
|
|
|
|
*/
|
2016-05-31 13:58:56 -06:00
|
|
|
void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc);
|
2013-02-28 17:42:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sync_pt_create() - creates a sync pt
|
2016-01-21 05:49:21 -07:00
|
|
|
* @parent: fence's parent sync_timeline
|
2013-02-28 17:42:57 -07:00
|
|
|
* @size: size to allocate for this pt
|
2016-05-31 13:58:56 -06:00
|
|
|
* @inc: value of the fence
|
2013-02-28 17:42:57 -07:00
|
|
|
*
|
2016-05-31 13:59:04 -06:00
|
|
|
* Creates a new sync_pt as a child of @parent. @size bytes will be
|
2013-10-30 23:20:25 -06:00
|
|
|
* allocated allowing for implementation specific data to be kept after
|
2016-05-31 13:59:04 -06:00
|
|
|
* the generic sync_timeline struct. Returns the sync_pt object or
|
2016-01-21 05:49:14 -07:00
|
|
|
* NULL in case of error.
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
2016-05-31 13:59:04 -06:00
|
|
|
struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size,
|
|
|
|
unsigned int inc);
|
2013-02-28 17:42:57 -07:00
|
|
|
|
2014-07-01 04:57:31 -06:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
|
2015-08-10 15:51:16 -06:00
|
|
|
void sync_timeline_debug_add(struct sync_timeline *obj);
|
|
|
|
void sync_timeline_debug_remove(struct sync_timeline *obj);
|
2016-01-21 05:49:19 -07:00
|
|
|
void sync_file_debug_add(struct sync_file *fence);
|
|
|
|
void sync_file_debug_remove(struct sync_file *fence);
|
2015-08-10 15:51:16 -06:00
|
|
|
void sync_dump(void);
|
2014-07-01 04:57:31 -06:00
|
|
|
|
|
|
|
#else
|
|
|
|
# define sync_timeline_debug_add(obj)
|
|
|
|
# define sync_timeline_debug_remove(obj)
|
2016-01-21 05:49:19 -07:00
|
|
|
# define sync_file_debug_add(fence)
|
|
|
|
# define sync_file_debug_remove(fence)
|
2014-07-01 04:57:31 -06:00
|
|
|
# define sync_dump()
|
|
|
|
#endif
|
|
|
|
|
2013-02-28 17:42:57 -07:00
|
|
|
#endif /* _LINUX_SYNC_H */
|