blob: 05e33f937ad0efc83c5627772ebbe4a83e28bb3f [file] [log] [blame]
Erik Gilling7ad530b2013-02-28 16:42:57 -08001/*
Gustavo Padovane912c882016-08-11 12:26:42 -03002 * Sync File validation framework and debug infomation
Erik Gilling7ad530b2013-02-28 16:42:57 -08003 *
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
Erik Gilling7ad530b2013-02-28 16:42:57 -080016#include <linux/list.h>
Chris Wilsonf1e8c672017-06-29 22:12:53 +010017#include <linux/rbtree.h>
Erik Gilling7ad530b2013-02-28 16:42:57 -080018#include <linux/spinlock.h>
Chris Wilsonf54d1862016-10-25 13:00:45 +010019#include <linux/dma-fence.h>
Erik Gilling7ad530b2013-02-28 16:42:57 -080020
Gustavo Padovan460bfc42016-04-28 10:46:57 -030021#include <linux/sync_file.h>
22#include <uapi/linux/sync_file.h>
Colin Cross64907b92014-02-17 13:58:32 -080023
Erik Gilling7ad530b2013-02-28 16:42:57 -080024/**
25 * struct sync_timeline - sync object
Erik Gillingc5b86b72013-02-28 16:43:11 -080026 * @kref: reference count on fence.
Erik Gilling7ad530b2013-02-28 16:42:57 -080027 * @name: name of the sync_timeline. Useful for debugging
Chris Wilsond3862e42017-06-29 22:05:32 +010028 * @lock: lock protecting @pt_list and @value
Chris Wilsonf1e8c672017-06-29 22:12:53 +010029 * @pt_tree: rbtree of active (unsignaled/errored) sync_pts
Chris Wilsond3862e42017-06-29 22:05:32 +010030 * @pt_list: list of active (unsignaled/errored) sync_pts
Erik Gillingaf7582f2013-02-28 16:43:00 -080031 * @sync_timeline_list: membership in global sync_timeline_list
Erik Gilling7ad530b2013-02-28 16:42:57 -080032 */
33struct sync_timeline {
Erik Gillingc5b86b72013-02-28 16:43:11 -080034 struct kref kref;
Erik Gilling7ad530b2013-02-28 16:42:57 -080035 char name[32];
36
Chris Wilsond3862e42017-06-29 22:05:32 +010037 /* protected by lock */
Linus Torvalds731c7d32016-08-01 21:44:08 -040038 u64 context;
39 int value;
Erik Gilling7ad530b2013-02-28 16:42:57 -080040
Chris Wilsonf1e8c672017-06-29 22:12:53 +010041 struct rb_root pt_tree;
Chris Wilsond3862e42017-06-29 22:05:32 +010042 struct list_head pt_list;
43 spinlock_t lock;
Erik Gillingaf7582f2013-02-28 16:43:00 -080044
45 struct list_head sync_timeline_list;
Erik Gilling7ad530b2013-02-28 16:42:57 -080046};
47
Chris Wilsonf54d1862016-10-25 13:00:45 +010048static inline struct sync_timeline *dma_fence_parent(struct dma_fence *fence)
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020049{
Chris Wilsond3862e42017-06-29 22:05:32 +010050 return container_of(fence->lock, struct sync_timeline, lock);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020051}
Erik Gilling7ad530b2013-02-28 16:42:57 -080052
Gustavo Padovan0431b902016-05-31 16:59:04 -030053/**
54 * struct sync_pt - sync_pt object
55 * @base: base fence object
Chris Wilsond3862e42017-06-29 22:05:32 +010056 * @link: link on the sync timeline's list
Chris Wilsonf1e8c672017-06-29 22:12:53 +010057 * @node: node in the sync timeline's tree
Gustavo Padovan0431b902016-05-31 16:59:04 -030058 */
59struct sync_pt {
Chris Wilsonf54d1862016-10-25 13:00:45 +010060 struct dma_fence base;
Chris Wilsond3862e42017-06-29 22:05:32 +010061 struct list_head link;
Chris Wilsonf1e8c672017-06-29 22:12:53 +010062 struct rb_node node;
Gustavo Padovan0431b902016-05-31 16:59:04 -030063};
64
Gustavo Padovan1867a232016-05-31 16:59:05 -030065extern const struct file_operations sw_sync_debugfs_fops;
66
Joe Perchesd30649a2015-08-10 14:51:16 -070067void sync_timeline_debug_add(struct sync_timeline *obj);
68void sync_timeline_debug_remove(struct sync_timeline *obj);
Gustavo Padovand7fdb0a2016-01-21 10:49:19 -020069void sync_file_debug_add(struct sync_file *fence);
70void sync_file_debug_remove(struct sync_file *fence);
Joe Perchesd30649a2015-08-10 14:51:16 -070071void sync_dump(void);
Maarten Lankhorst0f0d8402014-07-01 12:57:31 +020072
Erik Gilling7ad530b2013-02-28 16:42:57 -080073#endif /* _LINUX_SYNC_H */