xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_kinstr_prfcnt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2021-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  * Kinstr_prfcnt, used to provide an ioctl for userspace access to
24  * performance counters.
25  */
26 #ifndef _KBASE_KINSTR_PRFCNT_H_
27 #define _KBASE_KINSTR_PRFCNT_H_
28 
29 #include "hwcnt/mali_kbase_hwcnt_types.h"
30 #include <uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h>
31 
32 struct kbase_kinstr_prfcnt_context;
33 struct kbase_kinstr_prfcnt_client;
34 struct kbase_hwcnt_virtualizer;
35 struct kbase_ioctl_hwcnt_reader_setup;
36 struct kbase_ioctl_kinstr_prfcnt_enum_info;
37 union kbase_ioctl_kinstr_prfcnt_setup;
38 
39 /**
40  * kbase_kinstr_prfcnt_init() - Initialize a kinstr_prfcnt context.
41  * @hvirt:          Non-NULL pointer to the hardware counter virtualizer.
42  * @out_kinstr_ctx: Non-NULL pointer to where the pointer to the created
43  *                  kinstr_prfcnt context will be stored on success.
44  *
45  * On creation, the suspend count of the context will be 0.
46  *
47  * Return: 0 on success, else error code.
48  */
49 int kbase_kinstr_prfcnt_init(
50 	struct kbase_hwcnt_virtualizer *hvirt,
51 	struct kbase_kinstr_prfcnt_context **out_kinstr_ctx);
52 
53 /**
54  * kbase_kinstr_prfcnt_term() - Terminate a kinstr_prfcnt context.
55  * @kinstr_ctx: Pointer to the kinstr_prfcnt context to be terminated.
56  */
57 void kbase_kinstr_prfcnt_term(struct kbase_kinstr_prfcnt_context *kinstr_ctx);
58 
59 /**
60  * kbase_kinstr_prfcnt_suspend() - Increment the suspend count of the context.
61  * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context to be suspended.
62  *
63  * After this function call returns, it is guaranteed that all timers and
64  * workers in kinstr_prfcnt will be canceled, and will not be re-triggered until
65  * after the context has been resumed. In effect, this means no new counter
66  * dumps will occur for any existing or subsequently added periodic clients.
67  */
68 void kbase_kinstr_prfcnt_suspend(struct kbase_kinstr_prfcnt_context *kinstr_ctx);
69 
70 /**
71  * kbase_kinstr_prfcnt_resume() - Decrement the suspend count of the context.
72  * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context to be resumed.
73  *
74  * If a call to this function decrements the suspend count from 1 to 0, then
75  * normal operation of kinstr_prfcnt will be resumed (i.e. counter dumps will once
76  * again be automatically triggered for all periodic clients).
77  *
78  * It is only valid to call this function one time for each prior returned call
79  * to kbase_kinstr_prfcnt_suspend.
80  */
81 void kbase_kinstr_prfcnt_resume(struct kbase_kinstr_prfcnt_context *kinstr_ctx);
82 
83 /**
84  * kbasep_kinstr_prfcnt_get_block_info_list() - Get list of all block types
85  *                                              with their information.
86  * @metadata:  Non-NULL pointer to the hardware counter metadata.
87  * @block_set: Which SET the blocks will represent.
88  * @item_arr:  Non-NULL pointer to array of enumeration items to populate.
89  * @arr_idx:   Non-NULL pointer to index of array @item_arr.
90  *
91  * Populate list of counter blocks with information for enumeration.
92  *
93  * Return: 0 on success, else error code.
94  */
95 int kbasep_kinstr_prfcnt_get_block_info_list(const struct kbase_hwcnt_metadata *metadata,
96 					     size_t block_set, struct prfcnt_enum_item *item_arr,
97 					     size_t *arr_idx);
98 
99 /**
100  * kbasep_kinstr_prfcnt_get_sample_md_count() - Get count of sample
101  *                                              metadata items.
102  * @metadata:   Non-NULL pointer to the hardware counter metadata.
103  * @enable_map: Non-NULL pointer to the map of enabled counters.
104  *
105  * Return: Number of metadata items for available blocks in each sample.
106  */
107 size_t kbasep_kinstr_prfcnt_get_sample_md_count(const struct kbase_hwcnt_metadata *metadata,
108 						struct kbase_hwcnt_enable_map *enable_map);
109 
110 /**
111  * kbasep_kinstr_prfcnt_set_block_meta_items() - Populate a sample's block meta
112  *                                               item array.
113  * @enable_map:      Non-NULL pointer to the map of enabled counters.
114  * @dst:             Non-NULL pointer to the sample's dump buffer object.
115  * @block_meta_base: Non-NULL double pointer to the start of the block meta
116  *                   data items.
117  * @base_addr:       Address of allocated pages for array of samples. Used
118  *                   to calculate offset of block values.
119  * @counter_set:     The SET which blocks represent.
120  *
121  * Return: 0 on success, else error code.
122  */
123 int kbasep_kinstr_prfcnt_set_block_meta_items(struct kbase_hwcnt_enable_map *enable_map,
124 					      struct kbase_hwcnt_dump_buffer *dst,
125 					      struct prfcnt_metadata **block_meta_base,
126 					      u8 *base_addr, u8 counter_set);
127 
128 /**
129  * kbasep_kinstr_prfcnt_client_create() - Create a kinstr_prfcnt client.
130  *                                        Does not attach to the kinstr_prfcnt
131  *                                        context.
132  * @kinstr_ctx: Non-NULL pointer to kinstr_prfcnt context.
133  * @setup:      Non-NULL pointer to hardware counter ioctl setup structure.
134  * @out_vcli:   Non-NULL pointer to where created client will be stored on
135  *              success.
136  * @req_arr:    Non-NULL pointer to array of request items for client session.
137  *
138  * Return: 0 on success, else error code.
139  */
140 int kbasep_kinstr_prfcnt_client_create(struct kbase_kinstr_prfcnt_context *kinstr_ctx,
141 				       union kbase_ioctl_kinstr_prfcnt_setup *setup,
142 				       struct kbase_kinstr_prfcnt_client **out_vcli,
143 				       struct prfcnt_request_item *req_arr);
144 
145 /**
146  * kbasep_kinstr_prfcnt_cmd() - Execute command for a client session.
147  * @cli:         Non-NULL pointer to kinstr_prfcnt client.
148  * @control_cmd: Control command to execute.
149  *
150  * Return: 0 on success, else error code.
151  */
152 int kbasep_kinstr_prfcnt_cmd(struct kbase_kinstr_prfcnt_client *cli,
153 			     struct prfcnt_control_cmd *control_cmd);
154 
155 /**
156  * kbasep_kinstr_prfcnt_client_destroy() - Destroy a kinstr_prfcnt client.
157  * @cli: kinstr_prfcnt client. Must not be attached to a kinstr_prfcnt context.
158  */
159 void kbasep_kinstr_prfcnt_client_destroy(struct kbase_kinstr_prfcnt_client *cli);
160 
161 /**
162  * kbase_kinstr_prfcnt_enum_info - Enumerate performance counter information.
163  * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context.
164  * @enum_info:  Non-NULL pointer to the enumeration information.
165  *
166  * Enumerate which counter blocks and banks exist, and what counters are
167  * available within them.
168  *
169  * Return: 0 on success, else error code.
170  */
171 int kbase_kinstr_prfcnt_enum_info(
172 	struct kbase_kinstr_prfcnt_context *kinstr_ctx,
173 	struct kbase_ioctl_kinstr_prfcnt_enum_info *enum_info);
174 
175 /**
176  * kbase_kinstr_prfcnt_setup() - Set up a new hardware counter reader client.
177  * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context.
178  * @setup:      Non-NULL pointer to the hwcnt reader configuration.
179  *
180  * Start a session between a user client and the kinstr_prfcnt component.
181  * A file descriptor shall be provided to the client as a handle to the
182  * hardware counter reader client that represents the session.
183  *
184  * Return: file descriptor on success, else error code.
185  */
186 int kbase_kinstr_prfcnt_setup(struct kbase_kinstr_prfcnt_context *kinstr_ctx,
187 			      union kbase_ioctl_kinstr_prfcnt_setup *setup);
188 
189 #endif /* _KBASE_KINSTR_PRFCNT_H_ */
190