xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2015-2022 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 #if !defined(_KBASE_TIMELINE_H)
23 #define _KBASE_TIMELINE_H
24 
25 #include <mali_kbase.h>
26 
27 /*****************************************************************************/
28 
29 struct kbase_timeline;
30 
31 /**
32  * kbase_timeline_init - initialize timeline infrastructure in kernel
33  * @timeline:       Newly created instance of kbase_timeline will be stored in
34  *                  this pointer.
35  * @timeline_flags: Timeline status will be written to this variable when a
36  *                  client is attached/detached. The variable must be valid
37  *                  while timeline instance is valid.
38  * Return: zero on success, negative number on error
39  */
40 int kbase_timeline_init(struct kbase_timeline **timeline,
41 	atomic_t *timeline_flags);
42 
43 /**
44  * kbase_timeline_term - terminate timeline infrastructure in kernel
45  *
46  * @timeline:     Timeline instance to be terminated. It must be previously created
47  *                with kbase_timeline_init().
48  */
49 void kbase_timeline_term(struct kbase_timeline *timeline);
50 
51 /**
52  * kbase_timeline_io_acquire - acquire timeline stream file descriptor
53  * @kbdev:     Kbase device
54  * @flags:     Timeline stream flags
55  *
56  * This descriptor is meant to be used by userspace timeline to gain access to
57  * kernel timeline stream. This stream is later broadcasted by user space to the
58  * timeline client.
59  * Only one entity can own the descriptor at any given time. Descriptor shall be
60  * closed if unused. If descriptor cannot be obtained (i.e. when it is already
61  * being used) return will be a negative value.
62  *
63  * Return: file descriptor on success, negative number on error
64  */
65 int kbase_timeline_io_acquire(struct kbase_device *kbdev, u32 flags);
66 
67 /**
68  * kbase_timeline_streams_flush - flush timeline streams.
69  * @timeline:     Timeline instance
70  *
71  * Function will flush pending data in all timeline streams.
72  *
73  * Return: Zero on success, errno on failure.
74  */
75 int kbase_timeline_streams_flush(struct kbase_timeline *timeline);
76 
77 /**
78  * kbase_timeline_streams_body_reset - reset timeline body streams.
79  * @timeline:     Timeline instance
80  *
81  * Function will discard pending data in all timeline body streams.
82  */
83 void kbase_timeline_streams_body_reset(struct kbase_timeline *timeline);
84 
85 /**
86  * kbase_timeline_post_kbase_context_create - Inform timeline that a new KBase
87  *                                            Context has been created.
88  * @kctx:    KBase Context
89  */
90 void kbase_timeline_post_kbase_context_create(struct kbase_context *kctx);
91 
92 /**
93  * kbase_timeline_pre_kbase_context_destroy - Inform timeline that a KBase
94  *                                            Context is about to be destroyed.
95  * @kctx:    KBase Context
96  */
97 void kbase_timeline_pre_kbase_context_destroy(struct kbase_context *kctx);
98 
99 /**
100  * kbase_timeline_post_kbase_context_destroy - Inform timeline that a KBase
101  *                                             Context has been destroyed.
102  * @kctx:    KBase Context
103  *
104  * Should be called immediately before the memory is freed, and the context ID
105  * and kbdev pointer should still be valid.
106  */
107 void kbase_timeline_post_kbase_context_destroy(struct kbase_context *kctx);
108 
109 #if MALI_UNIT_TEST
110 
111 /**
112  * kbase_timeline_stats - read timeline stream statistics
113  * @timeline:        Timeline instance
114  * @bytes_collected: Will hold number of bytes read by the user
115  * @bytes_generated: Will hold number of bytes generated by trace points
116  */
117 void kbase_timeline_stats(struct kbase_timeline *timeline, u32 *bytes_collected, u32 *bytes_generated);
118 #endif /* MALI_UNIT_TEST */
119 
120 /**
121  * kbase_timeline_io_debugfs_init - Add a debugfs entry for reading timeline stream data
122  *
123  * @kbdev: An instance of the GPU platform device, allocated from the probe
124  *         method of the driver.
125  */
126 void kbase_timeline_io_debugfs_init(struct kbase_device *kbdev);
127 
128 #endif /* _KBASE_TIMELINE_H */
129