xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_hwaccess_instr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2014-2015, 2017-2018, 2020-2021 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  * HW Access instrumentation common APIs
24  */
25 
26 #ifndef _KBASE_HWACCESS_INSTR_H_
27 #define _KBASE_HWACCESS_INSTR_H_
28 
29 #include <backend/gpu/mali_kbase_instr_defs.h>
30 
31 /**
32  * struct kbase_instr_hwcnt_enable - Enable hardware counter collection.
33  * @dump_buffer:       GPU address to write counters to.
34  * @dump_buffer_bytes: Size in bytes of the buffer pointed to by dump_buffer.
35  * @fe_bm:             counters selection bitmask (Front End).
36  * @shader_bm:         counters selection bitmask (Shader).
37  * @tiler_bm:          counters selection bitmask (Tiler).
38  * @mmu_l2_bm:         counters selection bitmask (MMU_L2).
39  * @counter_set:       the performance counter set to use.
40  */
41 struct kbase_instr_hwcnt_enable {
42 	u64 dump_buffer;
43 	u64 dump_buffer_bytes;
44 	u32 fe_bm;
45 	u32 shader_bm;
46 	u32 tiler_bm;
47 	u32 mmu_l2_bm;
48 	u8 counter_set;
49 };
50 
51 /**
52  * kbase_instr_hwcnt_enable_internal() - Enable HW counters collection
53  * @kbdev:	Kbase device
54  * @kctx:	Kbase context
55  * @enable:	HW counter setup parameters
56  *
57  * Context: might sleep, waiting for reset to complete
58  *
59  * Return: 0 on success
60  */
61 int kbase_instr_hwcnt_enable_internal(struct kbase_device *kbdev,
62 				struct kbase_context *kctx,
63 				struct kbase_instr_hwcnt_enable *enable);
64 
65 /**
66  * kbase_instr_hwcnt_disable_internal() - Disable HW counters collection
67  * @kctx: Kbase context
68  *
69  * Context: might sleep, waiting for an ongoing dump to complete
70  *
71  * Return: 0 on success
72  */
73 int kbase_instr_hwcnt_disable_internal(struct kbase_context *kctx);
74 
75 /**
76  * kbase_instr_hwcnt_request_dump() - Request HW counter dump from GPU
77  * @kctx:	Kbase context
78  *
79  * Caller must either wait for kbase_instr_hwcnt_dump_complete() to return true,
80  * of call kbase_instr_hwcnt_wait_for_dump().
81  *
82  * Return: 0 on success
83  */
84 int kbase_instr_hwcnt_request_dump(struct kbase_context *kctx);
85 
86 /**
87  * kbase_instr_hwcnt_wait_for_dump() - Wait until pending HW counter dump has
88  *				       completed.
89  * @kctx:	Kbase context
90  *
91  * Context: will sleep, waiting for dump to complete
92  *
93  * Return: 0 on success
94  */
95 int kbase_instr_hwcnt_wait_for_dump(struct kbase_context *kctx);
96 
97 /**
98  * kbase_instr_hwcnt_dump_complete - Tell whether the HW counters dump has
99  *				     completed
100  * @kctx:	Kbase context
101  * @success:	Set to true if successful
102  *
103  * Context: does not sleep.
104  *
105  * Return: true if the dump is complete
106  */
107 bool kbase_instr_hwcnt_dump_complete(struct kbase_context *kctx,
108 						bool * const success);
109 
110 /**
111  * kbase_instr_hwcnt_clear() - Clear HW counters
112  * @kctx:	Kbase context
113  *
114  * Context: might sleep, waiting for reset to complete
115  *
116  * Return: 0 on success
117  */
118 int kbase_instr_hwcnt_clear(struct kbase_context *kctx);
119 
120 /**
121  * kbase_instr_backend_init() - Initialise the instrumentation backend
122  * @kbdev:	Kbase device
123  *
124  * This function should be called during driver initialization.
125  *
126  * Return: 0 on success
127  */
128 int kbase_instr_backend_init(struct kbase_device *kbdev);
129 
130 /**
131  * kbase_instr_backend_term() - Terminate the instrumentation backend
132  * @kbdev:	Kbase device
133  *
134  * This function should be called during driver termination.
135  */
136 void kbase_instr_backend_term(struct kbase_device *kbdev);
137 
138 #ifdef CONFIG_MALI_PRFCNT_SET_SELECT_VIA_DEBUG_FS
139 /**
140  * kbase_instr_backend_debugfs_init() - Add a debugfs entry for the
141  *                                      hardware counter set.
142  * @kbdev: kbase device
143  */
144 void kbase_instr_backend_debugfs_init(struct kbase_device *kbdev);
145 #endif
146 
147 /**
148  * kbase_instr_hwcnt_on_unrecoverable_error() - JM HWC instr backend function
149  *                                              called when unrecoverable errors
150  *                                              are detected.
151  * @kbdev: Kbase device
152  *
153  * This should be called on encountering errors that can only be recovered from
154  * with reset, or that may put HWC logic in state that could result in hang. For
155  * example, when HW becomes unresponsive.
156  *
157  * Caller requires kbdev->hwaccess_lock held.
158  */
159 void kbase_instr_hwcnt_on_unrecoverable_error(struct kbase_device *kbdev);
160 
161 /**
162  * kbase_instr_hwcnt_on_before_reset() - JM HWC instr backend function to be
163  *                                       called immediately before a reset.
164  *                                       Takes us out of the unrecoverable
165  *                                       error state, if we were in it.
166  * @kbdev: Kbase device
167  */
168 void kbase_instr_hwcnt_on_before_reset(struct kbase_device *kbdev);
169 
170 #endif /* _KBASE_HWACCESS_INSTR_H_ */
171