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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct sync_timeline_ops - sync object implementation ops
|
2013-10-30 23:20:25 -06:00
|
|
|
* @driver_name: name of the implementation
|
2013-02-28 17:42:57 -07:00
|
|
|
* @has_signaled: returns:
|
|
|
|
* 1 if pt has signaled
|
|
|
|
* 0 if pt has not signaled
|
|
|
|
* <0 on error
|
2013-02-28 17:43:21 -07:00
|
|
|
* @timeline_value_str: fill str with the value of the sync_timeline's counter
|
2016-01-21 05:49:21 -07:00
|
|
|
* @fence_value_str: fill str with the value of the fence
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
|
|
|
struct sync_timeline_ops {
|
|
|
|
const char *driver_name;
|
|
|
|
|
|
|
|
/* required */
|
2016-01-21 05:49:21 -07:00
|
|
|
int (*has_signaled)(struct fence *fence);
|
2013-02-28 17:42:57 -07:00
|
|
|
|
2013-02-28 17:43:21 -07:00
|
|
|
/* optional */
|
|
|
|
void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
|
|
|
|
int size);
|
|
|
|
|
|
|
|
/* optional */
|
2016-01-21 05:49:21 -07:00
|
|
|
void (*fence_value_str)(struct fence *fence, char *str, int size);
|
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.
|
2013-10-30 23:20:25 -06:00
|
|
|
* @ops: ops that define the implementation of 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;
|
2013-02-28 17:42:57 -07:00
|
|
|
const struct sync_timeline_ops *ops;
|
|
|
|
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
|
|
|
|
2013-02-28 17:42:57 -07:00
|
|
|
/*
|
|
|
|
* API for sync_timeline implementers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sync_timeline_create() - creates a sync object
|
2013-10-30 23:20:25 -06:00
|
|
|
* @ops: specifies the implementation ops for the object
|
2013-02-28 17:42:57 -07:00
|
|
|
* @size: size to allocate for this obj
|
|
|
|
* @name: sync_timeline name
|
|
|
|
*
|
2013-10-30 23:20:25 -06:00
|
|
|
* Creates a new sync_timeline which will use the implementation specified by
|
|
|
|
* @ops. @size bytes will be allocated allowing for implementation specific
|
2016-01-21 05:49:14 -07:00
|
|
|
* data to be kept after the generic sync_timeline struct. Returns the
|
|
|
|
* sync_timeline object or NULL in case of error.
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
|
|
|
struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
|
|
|
|
int size, const char *name);
|
|
|
|
|
|
|
|
/**
|
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-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.
|
|
|
|
*/
|
|
|
|
void sync_timeline_signal(struct sync_timeline *obj);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-01-21 05:49:21 -07:00
|
|
|
* Creates a new fence 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-01-21 05:49:21 -07:00
|
|
|
* the generic sync_timeline struct. Returns the fence object or
|
2016-01-21 05:49:14 -07:00
|
|
|
* NULL in case of error.
|
2013-02-28 17:42:57 -07:00
|
|
|
*/
|
2016-01-21 05:49:21 -07:00
|
|
|
struct fence *sync_pt_create(struct sync_timeline *parent, int size);
|
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 */
|