xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/hwcnt/backend/mali_kbase_hwcnt_backend.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2018, 2020-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 /*
23  * Virtual interface for hardware counter backends.
24  */
25 
26 #ifndef _KBASE_HWCNT_BACKEND_H_
27 #define _KBASE_HWCNT_BACKEND_H_
28 
29 #include <linux/types.h>
30 
31 struct kbase_hwcnt_metadata;
32 struct kbase_hwcnt_enable_map;
33 struct kbase_hwcnt_dump_buffer;
34 
35 /*
36  * struct kbase_hwcnt_backend_info - Opaque pointer to information used to
37  *                                   create an instance of a hardware counter
38  *                                   backend.
39  */
40 struct kbase_hwcnt_backend_info;
41 
42 /*
43  * struct kbase_hwcnt_backend - Opaque pointer to a hardware counter
44  *                              backend, used to perform dumps.
45  */
46 struct kbase_hwcnt_backend;
47 
48 /*
49  * typedef kbase_hwcnt_backend_metadata_fn - Get the immutable hardware counter
50  *                                           metadata that describes the layout
51  *                                           of the counter data structures.
52  * @info:        Non-NULL pointer to backend info.
53  *
54  * Multiple calls to this function with the same info are guaranteed to return
55  * the same metadata object each time.
56  *
57  * Return: Non-NULL pointer to immutable hardware counter metadata.
58  */
59 typedef const struct kbase_hwcnt_metadata *
60 kbase_hwcnt_backend_metadata_fn(const struct kbase_hwcnt_backend_info *info);
61 
62 /**
63  * typedef kbase_hwcnt_backend_init_fn - Initialise a counter backend.
64  * @info:        Non-NULL pointer to backend info.
65  * @out_backend: Non-NULL pointer to where backend is stored on success.
66  *
67  * All uses of the created hardware counter backend must be externally
68  * synchronised.
69  *
70  * Return: 0 on success, else error code.
71  */
72 typedef int kbase_hwcnt_backend_init_fn(const struct kbase_hwcnt_backend_info *info,
73 					struct kbase_hwcnt_backend **out_backend);
74 
75 /**
76  * typedef kbase_hwcnt_backend_term_fn - Terminate a counter backend.
77  * @backend: Pointer to backend to be terminated.
78  */
79 typedef void kbase_hwcnt_backend_term_fn(struct kbase_hwcnt_backend *backend);
80 
81 /**
82  * typedef kbase_hwcnt_backend_timestamp_ns_fn - Get the current backend
83  *                                               timestamp.
84  * @backend: Non-NULL pointer to backend.
85  *
86  * Return: Backend timestamp in nanoseconds.
87  */
88 typedef u64 kbase_hwcnt_backend_timestamp_ns_fn(struct kbase_hwcnt_backend *backend);
89 
90 /**
91  * typedef kbase_hwcnt_backend_dump_enable_fn - Start counter dumping with the
92  *                                              backend.
93  * @backend:    Non-NULL pointer to backend.
94  * @enable_map: Non-NULL pointer to enable map specifying enabled counters.
95  *
96  * The enable_map must have been created using the interface's metadata.
97  * If the backend has already been enabled, an error is returned.
98  *
99  * May be called in an atomic context.
100  *
101  * Return: 0 on success, else error code.
102  */
103 typedef int kbase_hwcnt_backend_dump_enable_fn(struct kbase_hwcnt_backend *backend,
104 					       const struct kbase_hwcnt_enable_map *enable_map);
105 
106 /**
107  * typedef kbase_hwcnt_backend_dump_enable_nolock_fn - Start counter dumping
108  *                                                     with the backend.
109  * @backend:    Non-NULL pointer to backend.
110  * @enable_map: Non-NULL pointer to enable map specifying enabled counters.
111  *
112  * Exactly the same as kbase_hwcnt_backend_dump_enable_fn(), except must be
113  * called in an atomic context with the spinlock documented by the specific
114  * backend interface held.
115  *
116  * Return: 0 on success, else error code.
117  */
118 typedef int
119 kbase_hwcnt_backend_dump_enable_nolock_fn(struct kbase_hwcnt_backend *backend,
120 					  const struct kbase_hwcnt_enable_map *enable_map);
121 
122 /**
123  * typedef kbase_hwcnt_backend_dump_disable_fn - Disable counter dumping with
124  *                                               the backend.
125  * @backend: Non-NULL pointer to backend.
126  *
127  * If the backend is already disabled, does nothing.
128  * Any undumped counter values since the last dump get will be lost.
129  */
130 typedef void kbase_hwcnt_backend_dump_disable_fn(struct kbase_hwcnt_backend *backend);
131 
132 /**
133  * typedef kbase_hwcnt_backend_dump_clear_fn - Reset all the current undumped
134  *                                             counters.
135  * @backend: Non-NULL pointer to backend.
136  *
137  * If the backend is not enabled, returns an error.
138  *
139  * Return: 0 on success, else error code.
140  */
141 typedef int kbase_hwcnt_backend_dump_clear_fn(struct kbase_hwcnt_backend *backend);
142 
143 /**
144  * typedef kbase_hwcnt_backend_dump_request_fn - Request an asynchronous counter
145  *                                               dump.
146  * @backend: Non-NULL pointer to backend.
147  * @dump_time_ns: Non-NULL pointer where the timestamp of when the dump was
148  *                requested will be written out to on success.
149  *
150  * If the backend is not enabled or another dump is already in progress,
151  * returns an error.
152  *
153  * Return: 0 on success, else error code.
154  */
155 typedef int kbase_hwcnt_backend_dump_request_fn(struct kbase_hwcnt_backend *backend,
156 						u64 *dump_time_ns);
157 
158 /**
159  * typedef kbase_hwcnt_backend_dump_wait_fn - Wait until the last requested
160  *                                            counter dump has completed.
161  * @backend: Non-NULL pointer to backend.
162  *
163  * If the backend is not enabled, returns an error.
164  *
165  * Return: 0 on success, else error code.
166  */
167 typedef int kbase_hwcnt_backend_dump_wait_fn(struct kbase_hwcnt_backend *backend);
168 
169 /**
170  * typedef kbase_hwcnt_backend_dump_get_fn - Copy or accumulate enable the
171  *                                           counters dumped after the last dump
172  *                                           request into the dump buffer.
173  * @backend:     Non-NULL pointer to backend.
174  * @dump_buffer: Non-NULL pointer to destination dump buffer.
175  * @enable_map:  Non-NULL pointer to enable map specifying enabled values.
176  * @accumulate:  True if counters should be accumulated into dump_buffer, rather
177  *               than copied.
178  *
179  * The resultant contents of the dump buffer are only well defined if a prior
180  * call to dump_wait returned successfully, and a new dump has not yet been
181  * requested by a call to dump_request.
182  *
183  * Return: 0 on success, else error code.
184  */
185 typedef int kbase_hwcnt_backend_dump_get_fn(struct kbase_hwcnt_backend *backend,
186 					    struct kbase_hwcnt_dump_buffer *dump_buffer,
187 					    const struct kbase_hwcnt_enable_map *enable_map,
188 					    bool accumulate);
189 
190 /**
191  * struct kbase_hwcnt_backend_interface - Hardware counter backend virtual
192  *                                        interface.
193  * @info:               Immutable info used to initialise an instance of the
194  *                      backend.
195  * @metadata:           Function ptr to get the immutable hardware counter
196  *                      metadata.
197  * @init:               Function ptr to initialise an instance of the backend.
198  * @term:               Function ptr to terminate an instance of the backend.
199  * @timestamp_ns:       Function ptr to get the current backend timestamp.
200  * @dump_enable:        Function ptr to enable dumping.
201  * @dump_enable_nolock: Function ptr to enable dumping while the
202  *                      backend-specific spinlock is already held.
203  * @dump_disable:       Function ptr to disable dumping.
204  * @dump_clear:         Function ptr to clear counters.
205  * @dump_request:       Function ptr to request a dump.
206  * @dump_wait:          Function ptr to wait until dump to complete.
207  * @dump_get:           Function ptr to copy or accumulate dump into a dump
208  *                      buffer.
209  */
210 struct kbase_hwcnt_backend_interface {
211 	const struct kbase_hwcnt_backend_info *info;
212 	kbase_hwcnt_backend_metadata_fn *metadata;
213 	kbase_hwcnt_backend_init_fn *init;
214 	kbase_hwcnt_backend_term_fn *term;
215 	kbase_hwcnt_backend_timestamp_ns_fn *timestamp_ns;
216 	kbase_hwcnt_backend_dump_enable_fn *dump_enable;
217 	kbase_hwcnt_backend_dump_enable_nolock_fn *dump_enable_nolock;
218 	kbase_hwcnt_backend_dump_disable_fn *dump_disable;
219 	kbase_hwcnt_backend_dump_clear_fn *dump_clear;
220 	kbase_hwcnt_backend_dump_request_fn *dump_request;
221 	kbase_hwcnt_backend_dump_wait_fn *dump_wait;
222 	kbase_hwcnt_backend_dump_get_fn *dump_get;
223 };
224 
225 #endif /* _KBASE_HWCNT_BACKEND_H_ */
226