xref: /linux-6.15/drivers/dma-buf/sync_debug.h (revision 70e67aae)
135538d78SGustavo Padovan /*
235538d78SGustavo Padovan  * Sync File validation framework and debug infomation
335538d78SGustavo Padovan  *
435538d78SGustavo Padovan  * Copyright (C) 2012 Google, Inc.
535538d78SGustavo Padovan  *
635538d78SGustavo Padovan  * This program is distributed in the hope that it will be useful,
735538d78SGustavo Padovan  * but WITHOUT ANY WARRANTY; without even the implied warranty of
835538d78SGustavo Padovan  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
935538d78SGustavo Padovan  * GNU General Public License for more details.
1035538d78SGustavo Padovan  *
1135538d78SGustavo Padovan  */
1235538d78SGustavo Padovan 
1335538d78SGustavo Padovan #ifndef _LINUX_SYNC_H
1435538d78SGustavo Padovan #define _LINUX_SYNC_H
1535538d78SGustavo Padovan 
1635538d78SGustavo Padovan #include <linux/list.h>
17f1e8c671SChris Wilson #include <linux/rbtree.h>
1835538d78SGustavo Padovan #include <linux/spinlock.h>
19f54d1867SChris Wilson #include <linux/dma-fence.h>
2035538d78SGustavo Padovan 
2135538d78SGustavo Padovan #include <linux/sync_file.h>
2235538d78SGustavo Padovan #include <uapi/linux/sync_file.h>
2335538d78SGustavo Padovan 
2435538d78SGustavo Padovan /**
2535538d78SGustavo Padovan  * struct sync_timeline - sync object
2635538d78SGustavo Padovan  * @kref:		reference count on fence.
2735538d78SGustavo Padovan  * @name:		name of the sync_timeline. Useful for debugging
28d3862e44SChris Wilson  * @lock:		lock protecting @pt_list and @value
29f1e8c671SChris Wilson  * @pt_tree:		rbtree of active (unsignaled/errored) sync_pts
30d3862e44SChris Wilson  * @pt_list:		list of active (unsignaled/errored) sync_pts
3135538d78SGustavo Padovan  * @sync_timeline_list:	membership in global sync_timeline_list
3235538d78SGustavo Padovan  */
3335538d78SGustavo Padovan struct sync_timeline {
3435538d78SGustavo Padovan 	struct kref		kref;
3535538d78SGustavo Padovan 	char			name[32];
3635538d78SGustavo Padovan 
37d3862e44SChris Wilson 	/* protected by lock */
3835538d78SGustavo Padovan 	u64			context;
3935538d78SGustavo Padovan 	int			value;
4035538d78SGustavo Padovan 
41f1e8c671SChris Wilson 	struct rb_root		pt_tree;
42d3862e44SChris Wilson 	struct list_head	pt_list;
43d3862e44SChris Wilson 	spinlock_t		lock;
4435538d78SGustavo Padovan 
4535538d78SGustavo Padovan 	struct list_head	sync_timeline_list;
4635538d78SGustavo Padovan };
4735538d78SGustavo Padovan 
dma_fence_parent(struct dma_fence * fence)48f54d1867SChris Wilson static inline struct sync_timeline *dma_fence_parent(struct dma_fence *fence)
4935538d78SGustavo Padovan {
50d3862e44SChris Wilson 	return container_of(fence->lock, struct sync_timeline, lock);
5135538d78SGustavo Padovan }
5235538d78SGustavo Padovan 
5335538d78SGustavo Padovan /**
5435538d78SGustavo Padovan  * struct sync_pt - sync_pt object
5535538d78SGustavo Padovan  * @base: base fence object
56d3862e44SChris Wilson  * @link: link on the sync timeline's list
57f1e8c671SChris Wilson  * @node: node in the sync timeline's tree
58*70e67aaeSRob Clark  * @deadline: the earliest fence deadline hint
5935538d78SGustavo Padovan  */
6035538d78SGustavo Padovan struct sync_pt {
61f54d1867SChris Wilson 	struct dma_fence base;
62d3862e44SChris Wilson 	struct list_head link;
63f1e8c671SChris Wilson 	struct rb_node node;
64*70e67aaeSRob Clark 	ktime_t deadline;
6535538d78SGustavo Padovan };
6635538d78SGustavo Padovan 
6735538d78SGustavo Padovan extern const struct file_operations sw_sync_debugfs_fops;
6835538d78SGustavo Padovan 
6935538d78SGustavo Padovan void sync_timeline_debug_add(struct sync_timeline *obj);
7035538d78SGustavo Padovan void sync_timeline_debug_remove(struct sync_timeline *obj);
7135538d78SGustavo Padovan void sync_file_debug_add(struct sync_file *fence);
7235538d78SGustavo Padovan void sync_file_debug_remove(struct sync_file *fence);
7335538d78SGustavo Padovan 
7435538d78SGustavo Padovan #endif /* _LINUX_SYNC_H */
75