xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_vinstr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * (C) COPYRIGHT 2015-2018, 2020-2021 ARM Limited. All rights reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This program is free software and is provided to you under the terms of the
7*4882a593Smuzhiyun  * GNU General Public License version 2 as published by the Free Software
8*4882a593Smuzhiyun  * Foundation, and any use by you of this program is subject to the terms
9*4882a593Smuzhiyun  * of such GNU license.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful,
12*4882a593Smuzhiyun  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*4882a593Smuzhiyun  * GNU General Public License for more details.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
17*4882a593Smuzhiyun  * along with this program; if not, you can access it online at
18*4882a593Smuzhiyun  * http://www.gnu.org/licenses/gpl-2.0.html.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  * Vinstr, used to provide an ioctl for userspace access to periodic hardware
24*4882a593Smuzhiyun  * counters.
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifndef _KBASE_VINSTR_H_
28*4882a593Smuzhiyun #define _KBASE_VINSTR_H_
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun struct kbase_vinstr_context;
31*4882a593Smuzhiyun struct kbase_hwcnt_virtualizer;
32*4882a593Smuzhiyun struct kbase_ioctl_hwcnt_reader_setup;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /**
35*4882a593Smuzhiyun  * kbase_vinstr_init() - Initialise a vinstr context.
36*4882a593Smuzhiyun  * @hvirt:    Non-NULL pointer to the hardware counter virtualizer.
37*4882a593Smuzhiyun  * @out_vctx: Non-NULL pointer to where the pointer to the created vinstr
38*4882a593Smuzhiyun  *            context will be stored on success.
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  * On creation, the suspend count of the context will be 0.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * Return: 0 on success, else error code.
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun int kbase_vinstr_init(
45*4882a593Smuzhiyun 	struct kbase_hwcnt_virtualizer *hvirt,
46*4882a593Smuzhiyun 	struct kbase_vinstr_context **out_vctx);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /**
49*4882a593Smuzhiyun  * kbase_vinstr_term() - Terminate a vinstr context.
50*4882a593Smuzhiyun  * @vctx: Pointer to the vinstr context to be terminated.
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun void kbase_vinstr_term(struct kbase_vinstr_context *vctx);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /**
55*4882a593Smuzhiyun  * kbase_vinstr_suspend() - Increment the suspend count of the context.
56*4882a593Smuzhiyun  * @vctx: Non-NULL pointer to the vinstr context to be suspended.
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * After this function call returns, it is guaranteed that all timers and
59*4882a593Smuzhiyun  * workers in vinstr will be cancelled, and will not be re-triggered until
60*4882a593Smuzhiyun  * after the context has been resumed. In effect, this means no new counter
61*4882a593Smuzhiyun  * dumps will occur for any existing or subsequently added periodic clients.
62*4882a593Smuzhiyun  */
63*4882a593Smuzhiyun void kbase_vinstr_suspend(struct kbase_vinstr_context *vctx);
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /**
66*4882a593Smuzhiyun  * kbase_vinstr_resume() - Decrement the suspend count of the context.
67*4882a593Smuzhiyun  * @vctx: Non-NULL pointer to the vinstr context to be resumed.
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  * If a call to this function decrements the suspend count from 1 to 0, then
70*4882a593Smuzhiyun  * normal operation of vinstr will be resumed (i.e. counter dumps will once
71*4882a593Smuzhiyun  * again be automatically triggered for all periodic clients).
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * It is only valid to call this function one time for each prior returned call
74*4882a593Smuzhiyun  * to kbase_vinstr_suspend.
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun void kbase_vinstr_resume(struct kbase_vinstr_context *vctx);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun  * kbase_vinstr_hwcnt_reader_setup() - Set up a new hardware counter reader
80*4882a593Smuzhiyun  *                                     client.
81*4882a593Smuzhiyun  * @vinstr_ctx: Non-NULL pointer to the vinstr context.
82*4882a593Smuzhiyun  * @setup:      Non-NULL pointer to the hwcnt reader configuration.
83*4882a593Smuzhiyun  *
84*4882a593Smuzhiyun  * Return: file descriptor on success, else a (negative) error code.
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun int kbase_vinstr_hwcnt_reader_setup(
87*4882a593Smuzhiyun 	struct kbase_vinstr_context *vinstr_ctx,
88*4882a593Smuzhiyun 	struct kbase_ioctl_hwcnt_reader_setup *setup);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun #endif /* _KBASE_VINSTR_H_ */
91