1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 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 * 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 <uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h> 30 31 struct kbase_kinstr_prfcnt_context; 32 struct kbase_hwcnt_virtualizer; 33 struct kbase_ioctl_hwcnt_reader_setup; 34 struct kbase_ioctl_kinstr_prfcnt_enum_info; 35 union kbase_ioctl_kinstr_prfcnt_setup; 36 37 /** 38 * kbase_kinstr_prfcnt_init() - Initialize a kinstr_prfcnt context. 39 * @hvirt: Non-NULL pointer to the hardware counter virtualizer. 40 * @out_kinstr_ctx: Non-NULL pointer to where the pointer to the created 41 * kinstr_prfcnt context will be stored on success. 42 * 43 * On creation, the suspend count of the context will be 0. 44 * 45 * Return: 0 on success, else error code. 46 */ 47 int kbase_kinstr_prfcnt_init( 48 struct kbase_hwcnt_virtualizer *hvirt, 49 struct kbase_kinstr_prfcnt_context **out_kinstr_ctx); 50 51 /** 52 * kbase_kinstr_prfcnt_term() - Terminate a kinstr_prfcnt context. 53 * @kinstr_ctx: Pointer to the kinstr_prfcnt context to be terminated. 54 */ 55 void kbase_kinstr_prfcnt_term(struct kbase_kinstr_prfcnt_context *kinstr_ctx); 56 57 /** 58 * kbase_kinstr_prfcnt_suspend() - Increment the suspend count of the context. 59 * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context to be suspended. 60 * 61 * After this function call returns, it is guaranteed that all timers and 62 * workers in kinstr_prfcnt will be canceled, and will not be re-triggered until 63 * after the context has been resumed. In effect, this means no new counter 64 * dumps will occur for any existing or subsequently added periodic clients. 65 */ 66 void kbase_kinstr_prfcnt_suspend(struct kbase_kinstr_prfcnt_context *kinstr_ctx); 67 68 /** 69 * kbase_kinstr_prfcnt_resume() - Decrement the suspend count of the context. 70 * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context to be resumed. 71 * 72 * If a call to this function decrements the suspend count from 1 to 0, then 73 * normal operation of kinstr_prfcnt will be resumed (i.e. counter dumps will once 74 * again be automatically triggered for all periodic clients). 75 * 76 * It is only valid to call this function one time for each prior returned call 77 * to kbase_kinstr_prfcnt_suspend. 78 */ 79 void kbase_kinstr_prfcnt_resume(struct kbase_kinstr_prfcnt_context *kinstr_ctx); 80 81 #if MALI_KERNEL_TEST_API 82 /** 83 * kbasep_kinstr_prfcnt_get_block_info_list() - Get list of all block types 84 * with their information. 85 * @metadata: Non-NULL pointer to the hardware counter metadata. 86 * @block_set: Which SET the blocks will represent. 87 * @item_arr: Non-NULL pointer to array of enumeration items to populate. 88 * @arr_idx: Non-NULL pointer to index of array @item_arr. 89 * 90 * Populate list of counter blocks with information for enumeration. 91 * 92 * Return: 0 on success, else error code. 93 */ 94 int kbasep_kinstr_prfcnt_get_block_info_list(const struct kbase_hwcnt_metadata *metadata, 95 size_t block_set, struct prfcnt_enum_item *item_arr, 96 size_t *arr_idx); 97 98 /** 99 * kbasep_kinstr_prfcnt_get_sample_md_count() - Get count of sample 100 * metadata items. 101 * @metadata: Non-NULL pointer to the hardware counter metadata. 102 * 103 * Return: Number of metadata items for available blocks in each sample. 104 */ 105 size_t kbasep_kinstr_prfcnt_get_sample_md_count(const struct kbase_hwcnt_metadata *metadata); 106 107 /** 108 * kbasep_kinstr_prfcnt_set_block_meta_items() - Populate a sample's block meta 109 * item array. 110 * @dst: Non-NULL pointer to the sample's dump buffer object. 111 * @block_meta_base: Non-NULL double pointer to the start of the block meta 112 * data items. 113 * @base_addr: Address of allocated pages for array of samples. Used 114 * to calculate offset of block values. 115 * @counter_set: The SET which blocks represent. 116 * 117 * Return: 0 on success, else error code. 118 */ 119 int kbasep_kinstr_prfcnt_set_block_meta_items(struct kbase_hwcnt_dump_buffer *dst, 120 struct prfcnt_metadata **block_meta_base, 121 u64 base_addr, u8 counter_set); 122 #endif /* MALI_KERNEL_TEST_API */ 123 124 /** 125 * kbase_kinstr_prfcnt_enum_info - Enumerate performance counter information. 126 * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context. 127 * @enum_info: Non-NULL pointer to the enumeration information. 128 * 129 * Enumerate which counter blocks and banks exist, and what counters are 130 * available within them. 131 * 132 * Return: 0 on success, else error code. 133 */ 134 int kbase_kinstr_prfcnt_enum_info( 135 struct kbase_kinstr_prfcnt_context *kinstr_ctx, 136 struct kbase_ioctl_kinstr_prfcnt_enum_info *enum_info); 137 138 /** 139 * kbase_kinstr_prfcnt_setup() - Set up a new hardware counter reader client. 140 * @kinstr_ctx: Non-NULL pointer to the kinstr_prfcnt context. 141 * @setup: Non-NULL pointer to the hwcnt reader configuration. 142 * 143 * Start a session between a user client and the kinstr_prfcnt component. 144 * A file descriptor shall be provided to the client as a handle to the 145 * hardware counter reader client that represents the session. 146 * 147 * Return: file descriptor on success, else error code. 148 */ 149 int kbase_kinstr_prfcnt_setup(struct kbase_kinstr_prfcnt_context *kinstr_ctx, 150 union kbase_ioctl_kinstr_prfcnt_setup *setup); 151 152 #endif /* _KBASE_KINSTR_PRFCNT_H_ */ 153