blob: b56885c148396a845e62464d38aed2d6832f6625 [file] [log] [blame]
Erik Gilling7ad530b2013-02-28 16:42:57 -08001/*
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 Gilling01544172013-02-28 16:43:10 -080017#include <linux/kref.h>
Erik Gilling97a84842013-02-28 16:42:59 -080018#include <linux/ktime.h>
Erik Gilling7ad530b2013-02-28 16:42:57 -080019#include <linux/list.h>
20#include <linux/spinlock.h>
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020021#include <linux/fence.h>
Erik Gilling7ad530b2013-02-28 16:42:57 -080022
Gustavo Padovan460bfc42016-04-28 10:46:57 -030023#include <linux/sync_file.h>
24#include <uapi/linux/sync_file.h>
Colin Cross64907b92014-02-17 13:58:32 -080025
Erik Gilling7ad530b2013-02-28 16:42:57 -080026struct sync_timeline;
Erik Gilling7ad530b2013-02-28 16:42:57 -080027
28/**
29 * struct sync_timeline_ops - sync object implementation ops
Masanari Iida4e20eff2013-10-31 14:20:25 +090030 * @driver_name: name of the implementation
Erik Gilling7ad530b2013-02-28 16:42:57 -080031 * @has_signaled: returns:
32 * 1 if pt has signaled
33 * 0 if pt has not signaled
34 * <0 on error
Erik Gillingdbd52392013-02-28 16:43:21 -080035 * @timeline_value_str: fill str with the value of the sync_timeline's counter
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020036 * @fence_value_str: fill str with the value of the fence
Erik Gilling7ad530b2013-02-28 16:42:57 -080037 */
38struct sync_timeline_ops {
39 const char *driver_name;
40
41 /* required */
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020042 int (*has_signaled)(struct fence *fence);
Erik Gilling7ad530b2013-02-28 16:42:57 -080043
Erik Gilling79ba1522013-02-28 16:43:02 -080044 /* optional */
Erik Gillingdbd52392013-02-28 16:43:21 -080045 void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
46 int size);
47
48 /* optional */
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020049 void (*fence_value_str)(struct fence *fence, char *str, int size);
Erik Gilling7ad530b2013-02-28 16:42:57 -080050};
51
52/**
53 * struct sync_timeline - sync object
Erik Gillingc5b86b72013-02-28 16:43:11 -080054 * @kref: reference count on fence.
Masanari Iida4e20eff2013-10-31 14:20:25 +090055 * @ops: ops that define the implementation of the sync_timeline
Erik Gilling7ad530b2013-02-28 16:42:57 -080056 * @name: name of the sync_timeline. Useful for debugging
Masanari Iida4e20eff2013-10-31 14:20:25 +090057 * @destroyed: set when sync_timeline is destroyed
Erik Gilling7ad530b2013-02-28 16:42:57 -080058 * @child_list_head: list of children sync_pts for this sync_timeline
59 * @child_list_lock: lock protecting @child_list_head, destroyed, and
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020060 * fence.status
Erik Gilling7ad530b2013-02-28 16:42:57 -080061 * @active_list_head: list of active (unsignaled/errored) sync_pts
Erik Gillingaf7582f2013-02-28 16:43:00 -080062 * @sync_timeline_list: membership in global sync_timeline_list
Erik Gilling7ad530b2013-02-28 16:42:57 -080063 */
64struct sync_timeline {
Erik Gillingc5b86b72013-02-28 16:43:11 -080065 struct kref kref;
Erik Gilling7ad530b2013-02-28 16:42:57 -080066 const struct sync_timeline_ops *ops;
67 char name[32];
68
69 /* protected by child_list_lock */
70 bool destroyed;
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020071 int context, value;
Erik Gilling7ad530b2013-02-28 16:42:57 -080072
73 struct list_head child_list_head;
74 spinlock_t child_list_lock;
75
76 struct list_head active_list_head;
Erik Gillingaf7582f2013-02-28 16:43:00 -080077
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020078#ifdef CONFIG_DEBUG_FS
Erik Gillingaf7582f2013-02-28 16:43:00 -080079 struct list_head sync_timeline_list;
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020080#endif
Erik Gilling7ad530b2013-02-28 16:42:57 -080081};
82
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020083static inline struct sync_timeline *fence_parent(struct fence *fence)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020084{
Gustavo Padovanb55b54b2016-01-21 10:49:21 -020085 return container_of(fence->lock, struct sync_timeline,
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020086 child_list_lock);
87}
Erik Gilling7ad530b2013-02-28 16:42:57 -080088
Erik Gilling7ad530b2013-02-28 16:42:57 -080089/*
90 * API for sync_timeline implementers
91 */
92
93/**
94 * sync_timeline_create() - creates a sync object
Masanari Iida4e20eff2013-10-31 14:20:25 +090095 * @ops: specifies the implementation ops for the object
Erik Gilling7ad530b2013-02-28 16:42:57 -080096 * @size: size to allocate for this obj
97 * @name: sync_timeline name
98 *
Masanari Iida4e20eff2013-10-31 14:20:25 +090099 * Creates a new sync_timeline which will use the implementation specified by
100 * @ops. @size bytes will be allocated allowing for implementation specific
Gustavo Padovan9b323812016-01-21 10:49:14 -0200101 * data to be kept after the generic sync_timeline struct. Returns the
102 * sync_timeline object or NULL in case of error.
Erik Gilling7ad530b2013-02-28 16:42:57 -0800103 */
104struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
105 int size, const char *name);
106
107/**
Masanari Iida4e20eff2013-10-31 14:20:25 +0900108 * sync_timeline_destroy() - destroys a sync object
Erik Gilling7ad530b2013-02-28 16:42:57 -0800109 * @obj: sync_timeline to destroy
110 *
Masanari Iida4e20eff2013-10-31 14:20:25 +0900111 * 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 Padovanb55b54b2016-01-21 10:49:21 -0200113 * fences are freed.
Erik Gilling7ad530b2013-02-28 16:42:57 -0800114 */
115void 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 Padovanb55b54b2016-01-21 10:49:21 -0200121 * A sync implementation should call this any time one of it's fences
Erik Gilling7ad530b2013-02-28 16:42:57 -0800122 * has signaled or has an error condition.
123 */
124void sync_timeline_signal(struct sync_timeline *obj);
125
126/**
127 * sync_pt_create() - creates a sync pt
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200128 * @parent: fence's parent sync_timeline
Erik Gilling7ad530b2013-02-28 16:42:57 -0800129 * @size: size to allocate for this pt
130 *
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200131 * Creates a new fence as a child of @parent. @size bytes will be
Masanari Iida4e20eff2013-10-31 14:20:25 +0900132 * allocated allowing for implementation specific data to be kept after
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200133 * the generic sync_timeline struct. Returns the fence object or
Gustavo Padovan9b323812016-01-21 10:49:14 -0200134 * NULL in case of error.
Erik Gilling7ad530b2013-02-28 16:42:57 -0800135 */
Gustavo Padovanb55b54b2016-01-21 10:49:21 -0200136struct fence *sync_pt_create(struct sync_timeline *parent, int size);
Erik Gilling7ad530b2013-02-28 16:42:57 -0800137
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200138#ifdef CONFIG_DEBUG_FS
139
Joe Perchesd30649a2015-08-10 14:51:16 -0700140void sync_timeline_debug_add(struct sync_timeline *obj);
141void sync_timeline_debug_remove(struct sync_timeline *obj);
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200142void sync_file_debug_add(struct sync_file *fence);
143void sync_file_debug_remove(struct sync_file *fence);
Joe Perchesd30649a2015-08-10 14:51:16 -0700144void sync_dump(void);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200145
146#else
147# define sync_timeline_debug_add(obj)
148# define sync_timeline_debug_remove(obj)
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -0200149# define sync_file_debug_add(fence)
150# define sync_file_debug_remove(fence)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200151# define sync_dump()
152#endif
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +0200153
Erik Gilling7ad530b2013-02-28 16:42:57 -0800154#endif /* _LINUX_SYNC_H */