1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2015, 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 #ifndef _UAPI_KBASE_HWCNT_READER_H_ 23 #define _UAPI_KBASE_HWCNT_READER_H_ 24 25 #include <stddef.h> 26 #include <linux/types.h> 27 28 /* The ids of ioctl commands. */ 29 #define KBASE_HWCNT_READER 0xBE 30 #define KBASE_HWCNT_READER_GET_HWVER _IOR(KBASE_HWCNT_READER, 0x00, __u32) 31 #define KBASE_HWCNT_READER_GET_BUFFER_SIZE _IOR(KBASE_HWCNT_READER, 0x01, __u32) 32 #define KBASE_HWCNT_READER_DUMP _IOW(KBASE_HWCNT_READER, 0x10, __u32) 33 #define KBASE_HWCNT_READER_CLEAR _IOW(KBASE_HWCNT_READER, 0x11, __u32) 34 #define KBASE_HWCNT_READER_GET_BUFFER _IOC(_IOC_READ, KBASE_HWCNT_READER, 0x20,\ 35 offsetof(struct kbase_hwcnt_reader_metadata, cycles)) 36 #define KBASE_HWCNT_READER_GET_BUFFER_WITH_CYCLES _IOR(KBASE_HWCNT_READER, 0x20,\ 37 struct kbase_hwcnt_reader_metadata) 38 #define KBASE_HWCNT_READER_PUT_BUFFER _IOC(_IOC_WRITE, KBASE_HWCNT_READER, 0x21,\ 39 offsetof(struct kbase_hwcnt_reader_metadata, cycles)) 40 #define KBASE_HWCNT_READER_PUT_BUFFER_WITH_CYCLES _IOW(KBASE_HWCNT_READER, 0x21,\ 41 struct kbase_hwcnt_reader_metadata) 42 #define KBASE_HWCNT_READER_SET_INTERVAL _IOW(KBASE_HWCNT_READER, 0x30, __u32) 43 #define KBASE_HWCNT_READER_ENABLE_EVENT _IOW(KBASE_HWCNT_READER, 0x40, __u32) 44 #define KBASE_HWCNT_READER_DISABLE_EVENT _IOW(KBASE_HWCNT_READER, 0x41, __u32) 45 #define KBASE_HWCNT_READER_GET_API_VERSION _IOW(KBASE_HWCNT_READER, 0xFF, __u32) 46 #define KBASE_HWCNT_READER_GET_API_VERSION_WITH_FEATURES \ 47 _IOW(KBASE_HWCNT_READER, 0xFF, \ 48 struct kbase_hwcnt_reader_api_version) 49 50 /** 51 * struct kbase_hwcnt_reader_metadata_cycles - GPU clock cycles 52 * @top: the number of cycles associated with the main clock for the 53 * GPU 54 * @shader_cores: the cycles that have elapsed on the GPU shader cores 55 */ 56 struct kbase_hwcnt_reader_metadata_cycles { 57 __u64 top; 58 __u64 shader_cores; 59 }; 60 61 /** 62 * struct kbase_hwcnt_reader_metadata - hwcnt reader sample buffer metadata 63 * @timestamp: time when sample was collected 64 * @event_id: id of an event that triggered sample collection 65 * @buffer_idx: position in sampling area where sample buffer was stored 66 * @cycles: the GPU cycles that occurred since the last sample 67 */ 68 struct kbase_hwcnt_reader_metadata { 69 __u64 timestamp; 70 __u32 event_id; 71 __u32 buffer_idx; 72 struct kbase_hwcnt_reader_metadata_cycles cycles; 73 }; 74 75 /** 76 * enum base_hwcnt_reader_event - hwcnt dumping events 77 * @BASE_HWCNT_READER_EVENT_MANUAL: manual request for dump 78 * @BASE_HWCNT_READER_EVENT_PERIODIC: periodic dump 79 * @BASE_HWCNT_READER_EVENT_PREJOB: prejob dump request 80 * @BASE_HWCNT_READER_EVENT_POSTJOB: postjob dump request 81 * @BASE_HWCNT_READER_EVENT_COUNT: number of supported events 82 */ 83 enum base_hwcnt_reader_event { 84 BASE_HWCNT_READER_EVENT_MANUAL, 85 BASE_HWCNT_READER_EVENT_PERIODIC, 86 BASE_HWCNT_READER_EVENT_PREJOB, 87 BASE_HWCNT_READER_EVENT_POSTJOB, 88 BASE_HWCNT_READER_EVENT_COUNT 89 }; 90 91 #define KBASE_HWCNT_READER_API_VERSION_NO_FEATURE (0) 92 #define KBASE_HWCNT_READER_API_VERSION_FEATURE_CYCLES_TOP (1 << 0) 93 #define KBASE_HWCNT_READER_API_VERSION_FEATURE_CYCLES_SHADER_CORES (1 << 1) 94 95 /** 96 * struct kbase_hwcnt_reader_api_version - hwcnt reader API version 97 * @version: API version 98 * @features: available features in this API version 99 */ 100 struct kbase_hwcnt_reader_api_version { 101 __u32 version; 102 __u32 features; 103 }; 104 105 /** Hardware counters reader API version */ 106 #define PRFCNT_READER_API_VERSION (0) 107 108 /** 109 * enum prfcnt_list_type - Type of list item 110 * @PRFCNT_LIST_TYPE_ENUM: Enumeration of performance counters. 111 * @PRFCNT_LIST_TYPE_REQUEST: Request for configuration setup. 112 * @PRFCNT_LIST_TYPE_SAMPLE_META: Sample metadata. 113 */ 114 enum prfcnt_list_type { 115 PRFCNT_LIST_TYPE_ENUM, 116 PRFCNT_LIST_TYPE_REQUEST, 117 PRFCNT_LIST_TYPE_SAMPLE_META, 118 }; 119 120 #define FLEX_LIST_TYPE(type, subtype) \ 121 (__u16)(((type & 0xf) << 12) | (subtype & 0xfff)) 122 #define FLEX_LIST_TYPE_NONE FLEX_LIST_TYPE(0, 0) 123 124 #define PRFCNT_ENUM_TYPE_BLOCK FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_ENUM, 0) 125 #define PRFCNT_ENUM_TYPE_REQUEST FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_ENUM, 1) 126 127 #define PRFCNT_REQUEST_TYPE_MODE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 0) 128 #define PRFCNT_REQUEST_TYPE_ENABLE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 1) 129 #define PRFCNT_REQUEST_TYPE_SCOPE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 2) 130 131 #define PRFCNT_SAMPLE_META_TYPE_SAMPLE \ 132 FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 0) 133 #define PRFCNT_SAMPLE_META_TYPE_CLOCK \ 134 FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 1) 135 #define PRFCNT_SAMPLE_META_TYPE_BLOCK \ 136 FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 2) 137 138 /** 139 * struct prfcnt_item_header - Header for an item of the list. 140 * @item_type: Type of item. 141 * @item_version: Protocol version. 142 */ 143 struct prfcnt_item_header { 144 __u16 item_type; 145 __u16 item_version; 146 }; 147 148 /** 149 * enum prfcnt_block_type - Type of performance counter block. 150 * @PRFCNT_BLOCK_TYPE_FE: Front End. 151 * @PRFCNT_BLOCK_TYPE_TILER: Tiler. 152 * @PRFCNT_BLOCK_TYPE_MEMORY: Memory System. 153 * @PRFCNT_BLOCK_TYPE_SHADER_CORE: Shader Core. 154 * @PRFCNT_BLOCK_TYPE_RESERVED: Reserved. 155 */ 156 enum prfcnt_block_type { 157 PRFCNT_BLOCK_TYPE_FE, 158 PRFCNT_BLOCK_TYPE_TILER, 159 PRFCNT_BLOCK_TYPE_MEMORY, 160 PRFCNT_BLOCK_TYPE_SHADER_CORE, 161 PRFCNT_BLOCK_TYPE_RESERVED = 255, 162 }; 163 164 /** 165 * enum prfcnt_set - Type of performance counter block set. 166 * @PRFCNT_SET_PRIMARY: Primary. 167 * @PRFCNT_SET_SECONDARY: Secondary. 168 * @PRFCNT_SET_TERTIARY: Tertiary. 169 * @PRFCNT_SET_RESERVED: Reserved. 170 */ 171 enum prfcnt_set { 172 PRFCNT_SET_PRIMARY, 173 PRFCNT_SET_SECONDARY, 174 PRFCNT_SET_TERTIARY, 175 PRFCNT_SET_RESERVED = 255, 176 }; 177 178 /** 179 * struct prfcnt_enum_block_counter - Performance counter block descriptor. 180 * @block_type: Type of performance counter block. 181 * @set: Which SET this represents: primary, secondary or tertiary. 182 * @pad: Padding bytes. 183 * @num_instances: How many instances of this block type exist in the hardware. 184 * @num_values: How many entries in the values array there are for samples 185 * from this block. 186 * @counter_mask: Bitmask that indicates the availability of counters in this 187 * block. 188 */ 189 struct prfcnt_enum_block_counter { 190 __u8 block_type; 191 __u8 set; 192 __u8 pad[2]; 193 __u16 num_instances; 194 __u16 num_values; 195 __u64 counter_mask[2]; 196 }; 197 198 /** 199 * struct prfcnt_enum_request - Request descriptor. 200 * @request_item_type: Type of request. 201 * @pad: Padding bytes. 202 * @versions_mask: Bitmask of versions that support this request. 203 */ 204 struct prfcnt_enum_request { 205 __u16 request_item_type; 206 __u16 pad; 207 __u32 versions_mask; 208 }; 209 210 /** 211 * struct prfcnt_enum_item - Performance counter enumeration item. 212 * @hdr: Header describing the type of item in the list. 213 * @u: Structure containing discriptor for enumeration item type. 214 * @u.block_counter: Performance counter block descriptor. 215 * @u.request: Request descriptor. 216 */ 217 struct prfcnt_enum_item { 218 struct prfcnt_item_header hdr; 219 /** union u - union of block_counter and request */ 220 union { 221 struct prfcnt_enum_block_counter block_counter; 222 struct prfcnt_enum_request request; 223 } u; 224 }; 225 226 /** 227 * enum prfcnt_mode - Capture mode for counter sampling. 228 * @PRFCNT_MODE_MANUAL: Manual sampling mode. 229 * @PRFCNT_MODE_PERIODIC: Periodic sampling mode. 230 * @PRFCNT_MODE_RESERVED: Reserved. 231 */ 232 enum prfcnt_mode { 233 PRFCNT_MODE_MANUAL, 234 PRFCNT_MODE_PERIODIC, 235 PRFCNT_MODE_RESERVED = 255, 236 }; 237 238 /** 239 * struct prfcnt_request_mode - Mode request descriptor. 240 * @mode: Capture mode for the session, either manual or periodic. 241 * @pad: Padding bytes. 242 * @mode_config: Structure containing configuration for periodic mode. 243 * @mode_config.period: Periodic config. 244 * @mode_config.period.period_ns: Period in nanoseconds, for periodic mode. 245 */ 246 struct prfcnt_request_mode { 247 __u8 mode; 248 __u8 pad[7]; 249 /** union mode_config - request mode configuration*/ 250 union { 251 struct { 252 __u64 period_ns; 253 } periodic; 254 } mode_config; 255 }; 256 257 /** 258 * struct prfcnt_request_enable - Enable request descriptor. 259 * @block_type: Type of performance counter block. 260 * @set: Which SET to use: primary, secondary or tertiary. 261 * @pad: Padding bytes. 262 * @enable_mask: Bitmask that indicates which performance counters to enable. 263 * Unavailable counters will be ignored. 264 */ 265 struct prfcnt_request_enable { 266 __u8 block_type; 267 __u8 set; 268 __u8 pad[6]; 269 __u64 enable_mask[2]; 270 }; 271 272 /** 273 * enum prfcnt_scope - Scope of performance counters. 274 * @PRFCNT_SCOPE_GLOBAL: Global scope. 275 * @PRFCNT_SCOPE_RESERVED: Reserved. 276 */ 277 enum prfcnt_scope { 278 PRFCNT_SCOPE_GLOBAL, 279 PRFCNT_SCOPE_RESERVED = 255, 280 }; 281 282 /** 283 * struct prfcnt_request_scope - Scope request descriptor. 284 * @scope: Scope of the performance counters to capture. 285 * @pad: Padding bytes. 286 */ 287 struct prfcnt_request_scope { 288 __u8 scope; 289 __u8 pad[7]; 290 }; 291 292 /** 293 * struct prfcnt_request_item - Performance counter request item. 294 * @hdr: Header describing the type of item in the list. 295 * @u: Structure containing descriptor for request type. 296 * @u.req_mode: Mode request descriptor. 297 * @u.req_enable: Enable request descriptor. 298 * @u.req_scope: Scope request descriptor. 299 */ 300 struct prfcnt_request_item { 301 struct prfcnt_item_header hdr; 302 /** union u - union on req_mode and req_enable */ 303 union { 304 struct prfcnt_request_mode req_mode; 305 struct prfcnt_request_enable req_enable; 306 struct prfcnt_request_scope req_scope; 307 } u; 308 }; 309 310 /** 311 * enum prfcnt_request_type - Type of request descriptor. 312 * @PRFCNT_REQUEST_MODE: Specify the capture mode to be used for the session. 313 * @PRFCNT_REQUEST_ENABLE: Specify which performance counters to capture. 314 * @PRFCNT_REQUEST_SCOPE: Specify the scope of the performance counters. 315 */ 316 enum prfcnt_request_type { 317 PRFCNT_REQUEST_MODE, 318 PRFCNT_REQUEST_ENABLE, 319 PRFCNT_REQUEST_SCOPE, 320 }; 321 322 /* This sample contains overflows from dump duration stretch because the sample buffer was full */ 323 #define SAMPLE_FLAG_OVERFLOW (1u << 0) 324 /* This sample has had an error condition for sample duration */ 325 #define SAMPLE_FLAG_ERROR (1u << 30) 326 327 /** 328 * struct prfcnt_sample_metadata - Metadata for counter sample data. 329 * @timestamp_start: Earliest timestamp that values in this sample represent. 330 * @timestamp_end: Latest timestamp that values in this sample represent. 331 * @seq: Sequence number of this sample. Must match the value from 332 * GET_SAMPLE. 333 * @user_data: User data provided to HWC_CMD_START or HWC_CMD_SAMPLE_* 334 * @flags: Property flags. 335 * @pad: Padding bytes. 336 */ 337 struct prfcnt_sample_metadata { 338 __u64 timestamp_start; 339 __u64 timestamp_end; 340 __u64 seq; 341 __u64 user_data; 342 __u32 flags; 343 __u32 pad; 344 }; 345 346 /* Maximum number of domains a metadata for clock cycles can refer to */ 347 #define MAX_REPORTED_DOMAINS (4) 348 349 /** 350 * struct prfcnt_clock_metadata - Metadata for clock cycles. 351 * @num_domains: Number of domains this metadata refers to. 352 * @pad: Padding bytes. 353 * @cycles: Number of cycles elapsed in each counter domain between 354 * timestamp_start and timestamp_end. Valid only for the 355 * first @p num_domains. 356 */ 357 struct prfcnt_clock_metadata { 358 __u32 num_domains; 359 __u32 pad; 360 __u64 cycles[MAX_REPORTED_DOMAINS]; 361 }; 362 363 /* This block state is unknown */ 364 #define BLOCK_STATE_UNKNOWN (0) 365 /* This block was powered on for at least some portion of the sample */ 366 #define BLOCK_STATE_ON (1 << 0) 367 /* This block was powered off for at least some portion of the sample */ 368 #define BLOCK_STATE_OFF (1 << 1) 369 /* This block was available to this VM for at least some portion of the sample */ 370 #define BLOCK_STATE_AVAILABLE (1 << 2) 371 /* This block was not available to this VM for at least some portion of the sample 372 * Note that no data is collected when the block is not available to the VM. 373 */ 374 #define BLOCK_STATE_UNAVAILABLE (1 << 3) 375 /* This block was operating in "normal" (non-protected) mode for at least some portion of the sample */ 376 #define BLOCK_STATE_NORMAL (1 << 4) 377 /* This block was operating in "protected" mode for at least some portion of the sample. 378 * Note that no data is collected when the block is in protected mode. 379 */ 380 #define BLOCK_STATE_PROTECTED (1 << 5) 381 382 /** 383 * struct prfcnt_block_metadata - Metadata for counter block. 384 * @block_type: Type of performance counter block. 385 * @block_idx: Index of performance counter block. 386 * @set: Set of performance counter block. 387 * @pad_u8: Padding bytes. 388 * @block_state: Bits set indicate the states which the block is known 389 * to have operated in during this sample. 390 * @values_offset: Offset from the start of the mmapped region, to the values 391 * for this block. The values themselves are an array of __u64. 392 * @pad_u32: Padding bytes. 393 */ 394 struct prfcnt_block_metadata { 395 __u8 block_type; 396 __u8 block_idx; 397 __u8 set; 398 __u8 pad_u8; 399 __u32 block_state; 400 __u32 values_offset; 401 __u32 pad_u32; 402 }; 403 404 /** 405 * struct prfcnt_metadata - Performance counter metadata item. 406 * @hdr: Header describing the type of item in the list. 407 * @u: Structure containing descriptor for metadata type. 408 * @u.sample_md: Counter sample data metadata descriptor. 409 * @u.clock_md: Clock cycles metadata descriptor. 410 * @u.block_md: Counter block metadata descriptor. 411 */ 412 struct prfcnt_metadata { 413 struct prfcnt_item_header hdr; 414 union { 415 struct prfcnt_sample_metadata sample_md; 416 struct prfcnt_clock_metadata clock_md; 417 struct prfcnt_block_metadata block_md; 418 } u; 419 }; 420 421 /** 422 * enum prfcnt_control_cmd_code - Control command code for client session. 423 * @PRFCNT_CONTROL_CMD_START: Start the counter data dump run for 424 * the calling client session. 425 * @PRFCNT_CONTROL_CMD_STOP: Stop the counter data dump run for the 426 * calling client session. 427 * @PRFCNT_CONTROL_CMD_SAMPLE_SYNC: Trigger a synchronous manual sample. 428 * @PRFCNT_CONTROL_CMD_SAMPLE_ASYNC: Trigger an asynchronous manual sample. 429 * @PRFCNT_CONTROL_CMD_DISCARD: Discard all samples which have not yet 430 * been consumed by userspace. Note that 431 * this can race with new samples if 432 * HWC_CMD_STOP is not called first. 433 */ 434 enum prfcnt_control_cmd_code { 435 PRFCNT_CONTROL_CMD_START = 1, 436 PRFCNT_CONTROL_CMD_STOP, 437 PRFCNT_CONTROL_CMD_SAMPLE_SYNC, 438 PRFCNT_CONTROL_CMD_SAMPLE_ASYNC, 439 PRFCNT_CONTROL_CMD_DISCARD, 440 }; 441 442 /** struct prfcnt_control_cmd - Control command 443 * @cmd: Control command for the session. 444 * @pad: Padding bytes. 445 * @user_data: Pointer to user data, which will be returned as part of 446 * sample metadata. It only affects a single sample if used 447 * with CMD_SAMPLE_SYNC or CMD_SAMPLE_ASYNC. It affects all 448 * samples between CMD_START and CMD_STOP if used with the 449 * periodic sampling. 450 */ 451 struct prfcnt_control_cmd { 452 __u16 cmd; 453 __u16 pad[3]; 454 __u64 user_data; 455 }; 456 457 /** struct prfcnt_sample_access - Metadata to access a sample. 458 * @sequence: Sequence number for the sample. 459 * For GET_SAMPLE, it will be set by the kernel. 460 * For PUT_SAMPLE, it shall be equal to the same value 461 * provided by the kernel for GET_SAMPLE. 462 * @sample_offset_bytes: Offset from the start of the mapped area to the first 463 * entry in the metadata list (sample_metadata) for this 464 * sample. 465 */ 466 struct prfcnt_sample_access { 467 __u64 sequence; 468 __u64 sample_offset_bytes; 469 }; 470 471 /* The ids of ioctl commands, on a reader file descriptor, magic number */ 472 #define KBASE_KINSTR_PRFCNT_READER 0xBF 473 /* Ioctl ID for issuing a session operational command */ 474 #define KBASE_IOCTL_KINSTR_PRFCNT_CMD \ 475 _IOW(KBASE_KINSTR_PRFCNT_READER, 0x00, struct prfcnt_control_cmd) 476 /* Ioctl ID for fetching a dumpped sample */ 477 #define KBASE_IOCTL_KINSTR_PRFCNT_GET_SAMPLE \ 478 _IOR(KBASE_KINSTR_PRFCNT_READER, 0x01, struct prfcnt_sample_access) 479 /* Ioctl ID for release internal buffer of the previously fetched sample */ 480 #define KBASE_IOCTL_KINSTR_PRFCNT_PUT_SAMPLE \ 481 _IOW(KBASE_KINSTR_PRFCNT_READER, 0x10, struct prfcnt_sample_access) 482 483 #endif /* _UAPI_KBASE_HWCNT_READER_H_ */ 484 485