summaryrefslogtreecommitdiff
path: root/dvalin/kernel/drivers/gpu/arm/midgard/mali_kbase_hwcnt_backend.h
blob: b7aa0e1fa8e9468637a0f631d40ef07867703e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 *
 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU licence.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 * SPDX-License-Identifier: GPL-2.0
 *
 */

/*
 * Virtual interface for hardware counter backends.
 */

#ifndef _KBASE_HWCNT_BACKEND_H_
#define _KBASE_HWCNT_BACKEND_H_

#include <linux/types.h>

struct kbase_hwcnt_metadata;
struct kbase_hwcnt_enable_map;
struct kbase_hwcnt_dump_buffer;

/*
 * struct kbase_hwcnt_backend_info - Opaque pointer to information used to
 *                                   create an instance of a hardware counter
 *                                   backend.
 */
struct kbase_hwcnt_backend_info;

/*
 * struct kbase_hwcnt_backend_info - Opaque pointer to a hardware counter
 *                                   backend, used to perform dumps.
 */
struct kbase_hwcnt_backend;

/**
 * typedef kbase_hwcnt_backend_init_fn - Initialise a counter backend.
 * @info:        Non-NULL pointer to backend info.
 * @out_backend: Non-NULL pointer to where backend is stored on success.
 *
 * All uses of the created hardware counter backend must be externally
 * synchronised.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_init_fn)(
	const struct kbase_hwcnt_backend_info *info,
	struct kbase_hwcnt_backend **out_backend);

/**
 * typedef kbase_hwcnt_backend_term_fn - Terminate a counter backend.
 * @backend: Pointer to backend to be terminated.
 */
typedef void (*kbase_hwcnt_backend_term_fn)(
	struct kbase_hwcnt_backend *backend);

/**
 * typedef kbase_hwcnt_backend_timestamp_ns_fn - Get the current backend
 *                                               timestamp.
 * @backend: Non-NULL pointer to backend.
 *
 * Return: Backend timestamp in nanoseconds.
 */
typedef u64 (*kbase_hwcnt_backend_timestamp_ns_fn)(
	struct kbase_hwcnt_backend *backend);

/**
 * typedef kbase_hwcnt_backend_dump_enable_fn - Start counter dumping with the
 *                                              backend.
 * @backend:    Non-NULL pointer to backend.
 * @enable_map: Non-NULL pointer to enable map specifying enabled counters.
 *
 * The enable_map must have been created using the interface's metadata.
 * If the backend has already been enabled, an error is returned.
 *
 * May be called in an atomic context.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_dump_enable_fn)(
	struct kbase_hwcnt_backend *backend,
	const struct kbase_hwcnt_enable_map *enable_map);

/**
 * typedef kbase_hwcnt_backend_dump_enable_nolock_fn - Start counter dumping
 *                                                     with the backend.
 * @backend:    Non-NULL pointer to backend.
 * @enable_map: Non-NULL pointer to enable map specifying enabled counters.
 *
 * Exactly the same as kbase_hwcnt_backend_dump_enable_fn(), except must be
 * called in an atomic context with the spinlock documented by the specific
 * backend interface held.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_dump_enable_nolock_fn)(
	struct kbase_hwcnt_backend *backend,
	const struct kbase_hwcnt_enable_map *enable_map);

/**
 * typedef kbase_hwcnt_backend_dump_disable_fn - Disable counter dumping with
 *                                               the backend.
 * @backend: Non-NULL pointer to backend.
 *
 * If the backend is already disabled, does nothing.
 * Any undumped counter values since the last dump get will be lost.
 */
typedef void (*kbase_hwcnt_backend_dump_disable_fn)(
	struct kbase_hwcnt_backend *backend);

/**
 * typedef kbase_hwcnt_backend_dump_clear_fn - Reset all the current undumped
 *                                             counters.
 * @backend: Non-NULL pointer to backend.
 *
 * If the backend is not enabled, returns an error.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_dump_clear_fn)(
	struct kbase_hwcnt_backend *backend);

/**
 * typedef kbase_hwcnt_backend_dump_request_fn - Request an asynchronous counter
 *                                               dump.
 * @backend: Non-NULL pointer to backend.
 *
 * If the backend is not enabled or another dump is already in progress,
 * returns an error.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_dump_request_fn)(
	struct kbase_hwcnt_backend *backend);

/**
 * typedef kbase_hwcnt_backend_dump_wait_fn - Wait until the last requested
 *                                            counter dump has completed.
 * @backend: Non-NULL pointer to backend.
 *
 * If the backend is not enabled, returns an error.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_dump_wait_fn)(
	struct kbase_hwcnt_backend *backend);

/**
 * typedef kbase_hwcnt_backend_dump_get_fn - Copy or accumulate enable the
 *                                           counters dumped after the last dump
 *                                           request into the dump buffer.
 * @backend:     Non-NULL pointer to backend.
 * @dump_buffer: Non-NULL pointer to destination dump buffer.
 * @enable_map:  Non-NULL pointer to enable map specifying enabled values.
 * @accumulate:  True if counters should be accumulated into dump_buffer, rather
 *               than copied.
 *
 * If the backend is not enabled, returns an error.
 * If a dump is in progress (i.e. dump_wait has not yet returned successfully)
 * then the resultant contents of the dump buffer will be undefined.
 *
 * Return: 0 on success, else error code.
 */
typedef int (*kbase_hwcnt_backend_dump_get_fn)(
	struct kbase_hwcnt_backend *backend,
	struct kbase_hwcnt_dump_buffer *dump_buffer,
	const struct kbase_hwcnt_enable_map *enable_map,
	bool accumulate);

/**
 * struct kbase_hwcnt_backend_interface - Hardware counter backend virtual
 *                                        interface.
 * @metadata:           Immutable hardware counter metadata.
 * @info:               Immutable info used to initialise an instance of the
 *                      backend.
 * @init:               Function ptr to initialise an instance of the backend.
 * @term:               Function ptr to terminate an instance of the backend.
 * @timestamp_ns:       Function ptr to get the current backend timestamp.
 * @dump_enable:        Function ptr to enable dumping.
 * @dump_enable_nolock: Function ptr to enable dumping while the
 *                      backend-specific spinlock is already held.
 * @dump_disable:       Function ptr to disable dumping.
 * @dump_clear:         Function ptr to clear counters.
 * @dump_request:       Function ptr to request a dump.
 * @dump_wait:          Function ptr to wait until dump to complete.
 * @dump_get:           Function ptr to copy or accumulate dump into a dump
 *                      buffer.
 */
struct kbase_hwcnt_backend_interface {
	const struct kbase_hwcnt_metadata *metadata;
	const struct kbase_hwcnt_backend_info *info;
	kbase_hwcnt_backend_init_fn init;
	kbase_hwcnt_backend_term_fn term;
	kbase_hwcnt_backend_timestamp_ns_fn timestamp_ns;
	kbase_hwcnt_backend_dump_enable_fn dump_enable;
	kbase_hwcnt_backend_dump_enable_nolock_fn dump_enable_nolock;
	kbase_hwcnt_backend_dump_disable_fn dump_disable;
	kbase_hwcnt_backend_dump_clear_fn dump_clear;
	kbase_hwcnt_backend_dump_request_fn dump_request;
	kbase_hwcnt_backend_dump_wait_fn dump_wait;
	kbase_hwcnt_backend_dump_get_fn dump_get;
};

#endif /* _KBASE_HWCNT_BACKEND_H_ */