Merge branch 'for-linus' of git://git.kernel.dk/linux-block
[deliverable/linux.git] / drivers / staging / android / sync.h
CommitLineData
7ad530bf
EG
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>
01544170 17#include <linux/kref.h>
97a84843 18#include <linux/ktime.h>
7ad530bf
EG
19#include <linux/list.h>
20#include <linux/spinlock.h>
0f0d8406 21#include <linux/fence.h>
7ad530bf 22
460bfc41
GP
23#include <linux/sync_file.h>
24#include <uapi/linux/sync_file.h>
64907b94 25
7ad530bf 26struct sync_timeline;
7ad530bf
EG
27
28/**
29 * struct sync_timeline_ops - sync object implementation ops
4e20effa 30 * @driver_name: name of the implementation
7ad530bf
EG
31 * @has_signaled: returns:
32 * 1 if pt has signaled
33 * 0 if pt has not signaled
34 * <0 on error
dbd52390 35 * @timeline_value_str: fill str with the value of the sync_timeline's counter
b55b54b5 36 * @fence_value_str: fill str with the value of the fence
7ad530bf
EG
37 */
38struct sync_timeline_ops {
39 const char *driver_name;
40
7ad530bf 41 /* required */
b55b54b5 42 int (*has_signaled)(struct fence *fence);
7ad530bf 43
dbd52390
EG
44 /* optional */
45 void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
46 int size);
47
48 /* optional */
b55b54b5 49 void (*fence_value_str)(struct fence *fence, char *str, int size);
7ad530bf
EG
50};
51
52/**
53 * struct sync_timeline - sync object
c5b86b74 54 * @kref: reference count on fence.
4e20effa 55 * @ops: ops that define the implementation of the sync_timeline
7ad530bf 56 * @name: name of the sync_timeline. Useful for debugging
4e20effa 57 * @destroyed: set when sync_timeline is destroyed
7ad530bf
EG
58 * @child_list_head: list of children sync_pts for this sync_timeline
59 * @child_list_lock: lock protecting @child_list_head, destroyed, and
b55b54b5 60 * fence.status
7ad530bf 61 * @active_list_head: list of active (unsignaled/errored) sync_pts
af7582f2 62 * @sync_timeline_list: membership in global sync_timeline_list
7ad530bf
EG
63 */
64struct sync_timeline {
c5b86b74 65 struct kref kref;
7ad530bf
EG
66 const struct sync_timeline_ops *ops;
67 char name[32];
68
69 /* protected by child_list_lock */
70 bool destroyed;
0f0d8406 71 int context, value;
7ad530bf
EG
72
73 struct list_head child_list_head;
74 spinlock_t child_list_lock;
75
76 struct list_head active_list_head;
af7582f2 77
0f0d8406 78#ifdef CONFIG_DEBUG_FS
af7582f2 79 struct list_head sync_timeline_list;
0f0d8406 80#endif
7ad530bf
EG
81};
82
b55b54b5 83static inline struct sync_timeline *fence_parent(struct fence *fence)
0f0d8406 84{
b55b54b5 85 return container_of(fence->lock, struct sync_timeline,
0f0d8406
ML
86 child_list_lock);
87}
97a84843 88
7ad530bf
EG
89/*
90 * API for sync_timeline implementers
91 */
92
93/**
94 * sync_timeline_create() - creates a sync object
4e20effa 95 * @ops: specifies the implementation ops for the object
7ad530bf
EG
96 * @size: size to allocate for this obj
97 * @name: sync_timeline name
98 *
4e20effa
MI
99 * Creates a new sync_timeline which will use the implementation specified by
100 * @ops. @size bytes will be allocated allowing for implementation specific
9b32381c
GP
101 * data to be kept after the generic sync_timeline struct. Returns the
102 * sync_timeline object or NULL in case of error.
7ad530bf
EG
103 */
104struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
105 int size, const char *name);
106
107/**
4e20effa 108 * sync_timeline_destroy() - destroys a sync object
7ad530bf
EG
109 * @obj: sync_timeline to destroy
110 *
4e20effa
MI
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
b55b54b5 113 * fences are freed.
7ad530bf
EG
114 */
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 *
b55b54b5 121 * A sync implementation should call this any time one of it's fences
7ad530bf
EG
122 * 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
b55b54b5 128 * @parent: fence's parent sync_timeline
7ad530bf
EG
129 * @size: size to allocate for this pt
130 *
b55b54b5 131 * Creates a new fence as a child of @parent. @size bytes will be
4e20effa 132 * allocated allowing for implementation specific data to be kept after
b55b54b5 133 * the generic sync_timeline struct. Returns the fence object or
9b32381c 134 * NULL in case of error.
7ad530bf 135 */
b55b54b5 136struct fence *sync_pt_create(struct sync_timeline *parent, int size);
7ad530bf 137
0f0d8406
ML
138#ifdef CONFIG_DEBUG_FS
139
d30649a8
JP
140void sync_timeline_debug_add(struct sync_timeline *obj);
141void sync_timeline_debug_remove(struct sync_timeline *obj);
d7fdb0ae
GP
142void sync_file_debug_add(struct sync_file *fence);
143void sync_file_debug_remove(struct sync_file *fence);
d30649a8 144void sync_dump(void);
0f0d8406
ML
145
146#else
147# define sync_timeline_debug_add(obj)
148# define sync_timeline_debug_remove(obj)
d7fdb0ae
GP
149# define sync_file_debug_add(fence)
150# define sync_file_debug_remove(fence)
0f0d8406
ML
151# define sync_dump()
152#endif
0f0d8406 153
7ad530bf 154#endif /* _LINUX_SYNC_H */
This page took 0.447578 seconds and 5 git commands to generate.