Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef ARM_COMPUTE_TEST_HWC |
| 25 | #define ARM_COMPUTE_TEST_HWC |
| 26 | |
| 27 | #include "hwc_names.hpp" |
| 28 | |
| 29 | #include <errno.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <poll.h> |
| 32 | #include <stddef.h> |
| 33 | #include <stdint.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
| 36 | #include <sys/ioctl.h> |
| 37 | #include <sys/mman.h> |
| 38 | #include <unistd.h> |
| 39 | |
| 40 | #if defined(ANDROID) || defined(__ANDROID__) |
| 41 | /* We use _IOR_BAD/_IOW_BAD rather than _IOR/_IOW otherwise fails to compile with NDK-BUILD because of _IOC_TYPECHECK is defined, not because the paramter is invalid */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 42 | #define MALI_IOR(a, b, c) _IOR_BAD(a, b, c) |
| 43 | #define MALI_IOW(a, b, c) _IOW_BAD(a, b, c) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 44 | #else /* defined(ANDROID) || defined(__ANDROID__) */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 45 | #define MALI_IOR(a, b, c) _IOR(a, b, c) |
| 46 | #define MALI_IOW(a, b, c) _IOW(a, b, c) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 47 | #endif /* defined(ANDROID) || defined(__ANDROID__) */ |
| 48 | |
| 49 | namespace mali_userspace |
| 50 | { |
| 51 | union uk_header |
| 52 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 53 | uint32_t id; |
| 54 | uint32_t ret; |
| 55 | uint64_t sizer; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | #define BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3 |
| 59 | #define BASE_MAX_COHERENT_GROUPS 16 |
| 60 | |
| 61 | struct mali_base_gpu_core_props |
| 62 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 63 | uint32_t product_id; |
| 64 | uint16_t version_status; |
| 65 | uint16_t minor_revision; |
| 66 | uint16_t major_revision; |
| 67 | uint16_t padding; |
| 68 | uint32_t gpu_speed_mhz; |
| 69 | uint32_t gpu_freq_khz_max; |
| 70 | uint32_t gpu_freq_khz_min; |
| 71 | uint32_t log2_program_counter_size; |
| 72 | uint32_t texture_features[BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS]; |
| 73 | uint64_t gpu_available_memory_size; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | struct mali_base_gpu_l2_cache_props |
| 77 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 78 | uint8_t log2_line_size; |
| 79 | uint8_t log2_cache_size; |
| 80 | uint8_t num_l2_slices; |
| 81 | uint8_t padding[5]; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct mali_base_gpu_tiler_props |
| 85 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 86 | uint32_t bin_size_bytes; |
| 87 | uint32_t max_active_levels; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | struct mali_base_gpu_thread_props |
| 91 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 92 | uint32_t max_threads; |
| 93 | uint32_t max_workgroup_size; |
| 94 | uint32_t max_barrier_size; |
| 95 | uint16_t max_registers; |
| 96 | uint8_t max_task_queue; |
| 97 | uint8_t max_thread_group_split; |
| 98 | uint8_t impl_tech; |
| 99 | uint8_t padding[7]; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | struct mali_base_gpu_coherent_group |
| 103 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 104 | uint64_t core_mask; |
| 105 | uint16_t num_cores; |
| 106 | uint16_t padding[3]; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | struct mali_base_gpu_coherent_group_info |
| 110 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 111 | uint32_t num_groups; |
| 112 | uint32_t num_core_groups; |
| 113 | uint32_t coherency; |
| 114 | uint32_t padding; |
| 115 | mali_base_gpu_coherent_group group[BASE_MAX_COHERENT_GROUPS]; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | #define GPU_MAX_JOB_SLOTS 16 |
| 119 | struct gpu_raw_gpu_props |
| 120 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 121 | uint64_t shader_present; |
| 122 | uint64_t tiler_present; |
| 123 | uint64_t l2_present; |
| 124 | uint64_t unused_1; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 125 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 126 | uint32_t l2_features; |
| 127 | uint32_t suspend_size; |
| 128 | uint32_t mem_features; |
| 129 | uint32_t mmu_features; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 130 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 131 | uint32_t as_present; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 132 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 133 | uint32_t js_present; |
| 134 | uint32_t js_features[GPU_MAX_JOB_SLOTS]; |
| 135 | uint32_t tiler_features; |
| 136 | uint32_t texture_features[3]; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 137 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 138 | uint32_t gpu_id; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 139 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 140 | uint32_t thread_max_threads; |
| 141 | uint32_t thread_max_workgroup_size; |
| 142 | uint32_t thread_max_barrier_size; |
| 143 | uint32_t thread_features; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 144 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 145 | uint32_t coherency_mode; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | struct mali_base_gpu_props |
| 149 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 150 | mali_base_gpu_core_props core_props; |
| 151 | mali_base_gpu_l2_cache_props l2_props; |
| 152 | uint64_t unused; |
| 153 | mali_base_gpu_tiler_props tiler_props; |
| 154 | mali_base_gpu_thread_props thread_props; |
| 155 | gpu_raw_gpu_props raw_props; |
| 156 | mali_base_gpu_coherent_group_info coherency_info; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | struct kbase_uk_gpuprops |
| 160 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 161 | uk_header header; |
| 162 | mali_base_gpu_props props; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 163 | }; |
| 164 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 165 | #define KBASE_GPUPROP_VALUE_SIZE_U8 (0x0) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 166 | #define KBASE_GPUPROP_VALUE_SIZE_U16 (0x1) |
| 167 | #define KBASE_GPUPROP_VALUE_SIZE_U32 (0x2) |
| 168 | #define KBASE_GPUPROP_VALUE_SIZE_U64 (0x3) |
| 169 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 170 | #define KBASE_GPUPROP_PRODUCT_ID 1 |
| 171 | #define KBASE_GPUPROP_MINOR_REVISION 3 |
| 172 | #define KBASE_GPUPROP_MAJOR_REVISION 4 |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 173 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 174 | #define KBASE_GPUPROP_COHERENCY_NUM_GROUPS 61 |
| 175 | #define KBASE_GPUPROP_COHERENCY_NUM_CORE_GROUPS 62 |
| 176 | #define KBASE_GPUPROP_COHERENCY_GROUP_0 64 |
| 177 | #define KBASE_GPUPROP_COHERENCY_GROUP_1 65 |
| 178 | #define KBASE_GPUPROP_COHERENCY_GROUP_2 66 |
| 179 | #define KBASE_GPUPROP_COHERENCY_GROUP_3 67 |
| 180 | #define KBASE_GPUPROP_COHERENCY_GROUP_4 68 |
| 181 | #define KBASE_GPUPROP_COHERENCY_GROUP_5 69 |
| 182 | #define KBASE_GPUPROP_COHERENCY_GROUP_6 70 |
| 183 | #define KBASE_GPUPROP_COHERENCY_GROUP_7 71 |
| 184 | #define KBASE_GPUPROP_COHERENCY_GROUP_8 72 |
| 185 | #define KBASE_GPUPROP_COHERENCY_GROUP_9 73 |
| 186 | #define KBASE_GPUPROP_COHERENCY_GROUP_10 74 |
| 187 | #define KBASE_GPUPROP_COHERENCY_GROUP_11 75 |
| 188 | #define KBASE_GPUPROP_COHERENCY_GROUP_12 76 |
| 189 | #define KBASE_GPUPROP_COHERENCY_GROUP_13 77 |
| 190 | #define KBASE_GPUPROP_COHERENCY_GROUP_14 78 |
| 191 | #define KBASE_GPUPROP_COHERENCY_GROUP_15 79 |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 192 | |
| 193 | struct gpu_props |
| 194 | { |
| 195 | uint32_t product_id; |
| 196 | uint16_t minor_revision; |
| 197 | uint16_t major_revision; |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 198 | uint32_t num_groups; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 199 | uint32_t num_core_groups; |
| 200 | uint64_t core_mask[16]; |
| 201 | }; |
| 202 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 203 | static const struct |
| 204 | { |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 205 | uint32_t type; |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 206 | size_t offset; |
| 207 | int size; |
| 208 | } gpu_property_mapping[] = |
| 209 | { |
| 210 | #define PROP(name, member) \ |
| 211 | { \ |
| 212 | KBASE_GPUPROP_##name, offsetof(struct gpu_props, member), \ |
| 213 | sizeof(((struct gpu_props *)0)->member) \ |
| 214 | } |
| 215 | #define PROP2(name, member, off) \ |
| 216 | { \ |
| 217 | KBASE_GPUPROP_##name, offsetof(struct gpu_props, member) + off, \ |
| 218 | sizeof(((struct gpu_props *)0)->member) \ |
| 219 | } |
| 220 | PROP(PRODUCT_ID, product_id), |
| 221 | PROP(MINOR_REVISION, minor_revision), |
| 222 | PROP(MAJOR_REVISION, major_revision), |
| 223 | PROP(COHERENCY_NUM_GROUPS, num_groups), |
| 224 | PROP(COHERENCY_NUM_CORE_GROUPS, num_core_groups), |
| 225 | PROP2(COHERENCY_GROUP_0, core_mask, 0), |
| 226 | PROP2(COHERENCY_GROUP_1, core_mask, 1), |
| 227 | PROP2(COHERENCY_GROUP_2, core_mask, 2), |
| 228 | PROP2(COHERENCY_GROUP_3, core_mask, 3), |
| 229 | PROP2(COHERENCY_GROUP_4, core_mask, 4), |
| 230 | PROP2(COHERENCY_GROUP_5, core_mask, 5), |
| 231 | PROP2(COHERENCY_GROUP_6, core_mask, 6), |
| 232 | PROP2(COHERENCY_GROUP_7, core_mask, 7), |
| 233 | PROP2(COHERENCY_GROUP_8, core_mask, 8), |
| 234 | PROP2(COHERENCY_GROUP_9, core_mask, 9), |
| 235 | PROP2(COHERENCY_GROUP_10, core_mask, 10), |
| 236 | PROP2(COHERENCY_GROUP_11, core_mask, 11), |
| 237 | PROP2(COHERENCY_GROUP_12, core_mask, 12), |
| 238 | PROP2(COHERENCY_GROUP_13, core_mask, 13), |
| 239 | PROP2(COHERENCY_GROUP_14, core_mask, 14), |
| 240 | PROP2(COHERENCY_GROUP_15, core_mask, 15), |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 241 | #undef PROP |
| 242 | #undef PROP2 |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 243 | { 0, 0, 0 } |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | struct kbase_hwcnt_reader_metadata |
| 247 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 248 | uint64_t timestamp = 0; |
| 249 | uint32_t event_id = 0; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 250 | uint32_t buffer_idx = 0; |
| 251 | }; |
| 252 | |
| 253 | namespace |
| 254 | { |
| 255 | /** Message header */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 256 | union kbase_uk_hwcnt_header |
| 257 | { |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 258 | /* 32-bit number identifying the UK function to be called. */ |
| 259 | uint32_t id; |
| 260 | /* The int return code returned by the called UK function. */ |
| 261 | uint32_t ret; |
| 262 | /* Used to ensure 64-bit alignment of this union. Do not remove. */ |
| 263 | uint64_t sizer; |
| 264 | }; |
| 265 | |
| 266 | /** IOCTL parameters to check version */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 267 | struct kbase_uk_hwcnt_reader_version_check_args |
| 268 | { |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 269 | union kbase_uk_hwcnt_header header; |
| 270 | |
| 271 | uint16_t major; |
| 272 | uint16_t minor; |
| 273 | uint8_t padding[4]; |
| 274 | }; |
| 275 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 276 | union kbase_pointer |
| 277 | { |
| 278 | void *value; |
| 279 | uint32_t compat_value; |
| 280 | uint64_t sizer; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 281 | }; |
| 282 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 283 | struct kbase_ioctl_get_gpuprops |
| 284 | { |
| 285 | kbase_pointer buffer; |
| 286 | uint32_t size; |
| 287 | uint32_t flags; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | #define KBASE_IOCTL_TYPE 0x80 |
| 291 | #define KBASE_IOCTL_GET_GPUPROPS MALI_IOW(KBASE_IOCTL_TYPE, 3, struct kbase_ioctl_get_gpuprops) |
| 292 | |
| 293 | /** IOCTL parameters to set flags */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 294 | struct kbase_uk_hwcnt_reader_set_flags |
| 295 | { |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 296 | union kbase_uk_hwcnt_header header; |
| 297 | |
| 298 | uint32_t create_flags; |
| 299 | uint32_t padding; |
| 300 | }; |
| 301 | |
| 302 | /** IOCTL parameters to configure reader */ |
| 303 | struct kbase_uk_hwcnt_reader_setup |
| 304 | { |
| 305 | union kbase_uk_hwcnt_header header; |
| 306 | |
| 307 | /* IN */ |
| 308 | uint32_t buffer_count; |
| 309 | uint32_t jm_bm; |
| 310 | uint32_t shader_bm; |
| 311 | uint32_t tiler_bm; |
| 312 | uint32_t mmu_l2_bm; |
| 313 | |
| 314 | /* OUT */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 315 | int32_t fd; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | static const uint32_t HWCNT_READER_API = 1; |
| 319 | |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 320 | struct uku_version_check_args |
| 321 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 322 | uk_header header; |
| 323 | uint16_t major; |
| 324 | uint16_t minor; |
| 325 | uint8_t padding[4]; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 326 | }; |
| 327 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 328 | enum |
| 329 | { |
| 330 | UKP_FUNC_ID_CHECK_VERSION = 0, |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 331 | /* Related to mali0 ioctl interface */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 332 | LINUX_UK_BASE_MAGIC = 0x80, |
| 333 | BASE_CONTEXT_CREATE_KERNEL_FLAGS = 0x2, |
| 334 | KBASE_FUNC_HWCNT_UK_FUNC_ID = 512, |
| 335 | KBASE_FUNC_GPU_PROPS_REG_DUMP = KBASE_FUNC_HWCNT_UK_FUNC_ID + 14, |
| 336 | KBASE_FUNC_HWCNT_READER_SETUP = KBASE_FUNC_HWCNT_UK_FUNC_ID + 36, |
| 337 | KBASE_FUNC_HWCNT_DUMP = KBASE_FUNC_HWCNT_UK_FUNC_ID + 11, |
| 338 | KBASE_FUNC_HWCNT_CLEAR = KBASE_FUNC_HWCNT_UK_FUNC_ID + 12, |
| 339 | KBASE_FUNC_SET_FLAGS = KBASE_FUNC_HWCNT_UK_FUNC_ID + 18, |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 340 | |
| 341 | /* The ids of ioctl commands for the reader interface */ |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 342 | KBASE_HWCNT_READER = 0xBE, |
| 343 | KBASE_HWCNT_READER_GET_HWVER = MALI_IOR(KBASE_HWCNT_READER, 0x00, uint32_t), |
| 344 | KBASE_HWCNT_READER_GET_BUFFER_SIZE = MALI_IOR(KBASE_HWCNT_READER, 0x01, uint32_t), |
| 345 | KBASE_HWCNT_READER_DUMP = MALI_IOW(KBASE_HWCNT_READER, 0x10, uint32_t), |
| 346 | KBASE_HWCNT_READER_CLEAR = MALI_IOW(KBASE_HWCNT_READER, 0x11, uint32_t), |
| 347 | KBASE_HWCNT_READER_GET_BUFFER = MALI_IOR(KBASE_HWCNT_READER, 0x20, struct kbase_hwcnt_reader_metadata), |
| 348 | KBASE_HWCNT_READER_PUT_BUFFER = MALI_IOW(KBASE_HWCNT_READER, 0x21, struct kbase_hwcnt_reader_metadata), |
| 349 | KBASE_HWCNT_READER_SET_INTERVAL = MALI_IOW(KBASE_HWCNT_READER, 0x30, uint32_t), |
| 350 | KBASE_HWCNT_READER_ENABLE_EVENT = MALI_IOW(KBASE_HWCNT_READER, 0x40, uint32_t), |
| 351 | KBASE_HWCNT_READER_DISABLE_EVENT = MALI_IOW(KBASE_HWCNT_READER, 0x41, uint32_t), |
| 352 | KBASE_HWCNT_READER_GET_API_VERSION = MALI_IOW(KBASE_HWCNT_READER, 0xFF, uint32_t) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 353 | |
| 354 | }; |
| 355 | |
| 356 | enum |
| 357 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 358 | PIPE_DESCRIPTOR_IN, /**< The index of a pipe's input descriptor. */ |
| 359 | PIPE_DESCRIPTOR_OUT, /**< The index of a pipe's output descriptor. */ |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 360 | |
| 361 | PIPE_DESCRIPTOR_COUNT /**< The number of descriptors forming a pipe. */ |
| 362 | }; |
| 363 | |
| 364 | enum |
| 365 | { |
| 366 | POLL_DESCRIPTOR_SIGNAL, /**< The index of the signal descriptor in poll fds array. */ |
| 367 | POLL_DESCRIPTOR_HWCNT_READER, /**< The index of the hwcnt reader descriptor in poll fds array. */ |
| 368 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 369 | POLL_DESCRIPTOR_COUNT /**< The number of descriptors poll is waiting for. */ |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | /** Write a single byte into the pipe to interrupt the reader thread */ |
| 373 | typedef char poll_data_t; |
| 374 | } |
| 375 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 376 | template <typename T> |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 377 | static inline int mali_ioctl(int fd, T &arg) |
| 378 | { |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 379 | auto *hdr = &arg.header; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 380 | const int cmd = _IOC(_IOC_READ | _IOC_WRITE, LINUX_UK_BASE_MAGIC, hdr->id, sizeof(T)); |
| 381 | |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 382 | if(ioctl(fd, cmd, &arg)) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 383 | return -1; |
Anthony Barbier | 88b8d8c | 2017-12-22 15:45:00 +0000 | [diff] [blame] | 384 | if(hdr->ret) |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 385 | return -1; |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | } // namespace mali_userspace |
| 390 | #endif /* ARM_COMPUTE_TEST_HWC */ |