1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2015, 2020-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 #ifndef _UAPI_KBASE_HWCNT_READER_H_ 23 #define _UAPI_KBASE_HWCNT_READER_H_ 24 25 #include <linux/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 #define PRFCNT_ENUM_TYPE_SAMPLE_INFO FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_ENUM, 2) 127 128 #define PRFCNT_REQUEST_TYPE_MODE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 0) 129 #define PRFCNT_REQUEST_TYPE_ENABLE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 1) 130 #define PRFCNT_REQUEST_TYPE_SCOPE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 2) 131 132 #define PRFCNT_SAMPLE_META_TYPE_SAMPLE \ 133 FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 0) 134 #define PRFCNT_SAMPLE_META_TYPE_CLOCK \ 135 FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 1) 136 #define PRFCNT_SAMPLE_META_TYPE_BLOCK \ 137 FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 2) 138 139 /** 140 * struct prfcnt_item_header - Header for an item of the list. 141 * @item_type: Type of item. 142 * @item_version: Protocol version. 143 */ 144 struct prfcnt_item_header { 145 __u16 item_type; 146 __u16 item_version; 147 }; 148 149 /** 150 * enum prfcnt_block_type - Type of performance counter block. 151 * @PRFCNT_BLOCK_TYPE_FE: Front End. 152 * @PRFCNT_BLOCK_TYPE_TILER: Tiler. 153 * @PRFCNT_BLOCK_TYPE_MEMORY: Memory System. 154 * @PRFCNT_BLOCK_TYPE_SHADER_CORE: Shader Core. 155 * @PRFCNT_BLOCK_TYPE_RESERVED: Reserved. 156 */ 157 enum prfcnt_block_type { 158 PRFCNT_BLOCK_TYPE_FE, 159 PRFCNT_BLOCK_TYPE_TILER, 160 PRFCNT_BLOCK_TYPE_MEMORY, 161 PRFCNT_BLOCK_TYPE_SHADER_CORE, 162 PRFCNT_BLOCK_TYPE_RESERVED = 255, 163 }; 164 165 /** 166 * enum prfcnt_set - Type of performance counter block set. 167 * @PRFCNT_SET_PRIMARY: Primary. 168 * @PRFCNT_SET_SECONDARY: Secondary. 169 * @PRFCNT_SET_TERTIARY: Tertiary. 170 * @PRFCNT_SET_RESERVED: Reserved. 171 */ 172 enum prfcnt_set { 173 PRFCNT_SET_PRIMARY, 174 PRFCNT_SET_SECONDARY, 175 PRFCNT_SET_TERTIARY, 176 PRFCNT_SET_RESERVED = 255, 177 }; 178 179 /** 180 * struct prfcnt_enum_block_counter - Performance counter block descriptor. 181 * @block_type: Type of performance counter block. 182 * @set: Which SET this represents: primary, secondary or tertiary. 183 * @pad: Padding bytes. 184 * @num_instances: How many instances of this block type exist in the hardware. 185 * @num_values: How many entries in the values array there are for samples 186 * from this block. 187 * @counter_mask: Bitmask that indicates counter availability in this block. 188 * A '0' indicates that a counter is not available at that 189 * index and will always return zeroes if requested. 190 */ 191 struct prfcnt_enum_block_counter { 192 __u8 block_type; 193 __u8 set; 194 __u8 pad[2]; 195 __u16 num_instances; 196 __u16 num_values; 197 __u64 counter_mask[2]; 198 }; 199 200 /** 201 * struct prfcnt_enum_request - Request descriptor. 202 * @request_item_type: Type of request. 203 * @pad: Padding bytes. 204 * @versions_mask: Bitmask of versions that support this request. 205 */ 206 struct prfcnt_enum_request { 207 __u16 request_item_type; 208 __u16 pad; 209 __u32 versions_mask; 210 }; 211 212 /** 213 * struct prfcnt_enum_sample_info - Sample information descriptor. 214 * @num_clock_domains: Number of clock domains of the GPU. 215 * @pad: Padding bytes. 216 */ 217 struct prfcnt_enum_sample_info { 218 __u32 num_clock_domains; 219 __u32 pad; 220 }; 221 222 /** 223 * struct prfcnt_enum_item - Performance counter enumeration item. 224 * @padding: Padding bytes. 225 * @hdr: Header describing the type of item in the list. 226 * @u: Structure containing discriptor for enumeration item type. 227 * @u.block_counter: Performance counter block descriptor. 228 * @u.request: Request descriptor. 229 * @u.sample_info: Performance counter sample information descriptor. 230 */ 231 struct prfcnt_enum_item { 232 struct prfcnt_item_header hdr; 233 __u8 padding[4]; 234 /** union u - union of block_counter and request */ 235 union { 236 struct prfcnt_enum_block_counter block_counter; 237 struct prfcnt_enum_request request; 238 struct prfcnt_enum_sample_info sample_info; 239 } u; 240 }; 241 242 /** 243 * enum prfcnt_mode - Capture mode for counter sampling. 244 * @PRFCNT_MODE_MANUAL: Manual sampling mode. 245 * @PRFCNT_MODE_PERIODIC: Periodic sampling mode. 246 * @PRFCNT_MODE_RESERVED: Reserved. 247 */ 248 enum prfcnt_mode { 249 PRFCNT_MODE_MANUAL, 250 PRFCNT_MODE_PERIODIC, 251 PRFCNT_MODE_RESERVED = 255, 252 }; 253 254 /** 255 * struct prfcnt_request_mode - Mode request descriptor. 256 * @mode: Capture mode for the session, either manual or periodic. 257 * @pad: Padding bytes. 258 * @mode_config: Structure containing configuration for periodic mode. 259 * @mode_config.periodic: Periodic config. 260 * @mode_config.periodic.period_ns: Period in nanoseconds, for periodic mode. 261 */ 262 struct prfcnt_request_mode { 263 __u8 mode; 264 __u8 pad[7]; 265 /** union mode_config - request mode configuration*/ 266 union { 267 struct { 268 __u64 period_ns; 269 } periodic; 270 } mode_config; 271 }; 272 273 /** 274 * struct prfcnt_request_enable - Enable request descriptor. 275 * @block_type: Type of performance counter block. 276 * @set: Which SET to use: primary, secondary or tertiary. 277 * @pad: Padding bytes. 278 * @enable_mask: Bitmask that indicates which performance counters to enable. 279 * Unavailable counters will be ignored. 280 */ 281 struct prfcnt_request_enable { 282 __u8 block_type; 283 __u8 set; 284 __u8 pad[6]; 285 __u64 enable_mask[2]; 286 }; 287 288 /** 289 * enum prfcnt_scope - Scope of performance counters. 290 * @PRFCNT_SCOPE_GLOBAL: Global scope. 291 * @PRFCNT_SCOPE_RESERVED: Reserved. 292 */ 293 enum prfcnt_scope { 294 PRFCNT_SCOPE_GLOBAL, 295 PRFCNT_SCOPE_RESERVED = 255, 296 }; 297 298 /** 299 * struct prfcnt_request_scope - Scope request descriptor. 300 * @scope: Scope of the performance counters to capture. 301 * @pad: Padding bytes. 302 */ 303 struct prfcnt_request_scope { 304 __u8 scope; 305 __u8 pad[7]; 306 }; 307 308 /** 309 * struct prfcnt_request_item - Performance counter request item. 310 * @padding: Padding bytes. 311 * @hdr: Header describing the type of item in the list. 312 * @u: Structure containing descriptor for request type. 313 * @u.req_mode: Mode request descriptor. 314 * @u.req_enable: Enable request descriptor. 315 * @u.req_scope: Scope request descriptor. 316 */ 317 struct prfcnt_request_item { 318 struct prfcnt_item_header hdr; 319 __u8 padding[4]; 320 /** union u - union on req_mode and req_enable */ 321 union { 322 struct prfcnt_request_mode req_mode; 323 struct prfcnt_request_enable req_enable; 324 struct prfcnt_request_scope req_scope; 325 } u; 326 }; 327 328 /** 329 * enum prfcnt_request_type - Type of request descriptor. 330 * @PRFCNT_REQUEST_MODE: Specify the capture mode to be used for the session. 331 * @PRFCNT_REQUEST_ENABLE: Specify which performance counters to capture. 332 * @PRFCNT_REQUEST_SCOPE: Specify the scope of the performance counters. 333 */ 334 enum prfcnt_request_type { 335 PRFCNT_REQUEST_MODE, 336 PRFCNT_REQUEST_ENABLE, 337 PRFCNT_REQUEST_SCOPE, 338 }; 339 340 /* This sample contains overflows from dump duration stretch because the sample buffer was full */ 341 #define SAMPLE_FLAG_OVERFLOW (1u << 0) 342 /* This sample has had an error condition for sample duration */ 343 #define SAMPLE_FLAG_ERROR (1u << 30) 344 345 /** 346 * struct prfcnt_sample_metadata - Metadata for counter sample data. 347 * @timestamp_start: Earliest timestamp that values in this sample represent. 348 * @timestamp_end: Latest timestamp that values in this sample represent. 349 * @seq: Sequence number of this sample. Must match the value from 350 * GET_SAMPLE. 351 * @user_data: User data provided to HWC_CMD_START or HWC_CMD_SAMPLE_* 352 * @flags: Property flags. 353 * @pad: Padding bytes. 354 */ 355 struct prfcnt_sample_metadata { 356 __u64 timestamp_start; 357 __u64 timestamp_end; 358 __u64 seq; 359 __u64 user_data; 360 __u32 flags; 361 __u32 pad; 362 }; 363 364 /* Maximum number of domains a metadata for clock cycles can refer to */ 365 #define MAX_REPORTED_DOMAINS (4) 366 367 /** 368 * struct prfcnt_clock_metadata - Metadata for clock cycles. 369 * @num_domains: Number of domains this metadata refers to. 370 * @pad: Padding bytes. 371 * @cycles: Number of cycles elapsed in each counter domain between 372 * timestamp_start and timestamp_end. Valid only for the 373 * first @p num_domains. 374 */ 375 struct prfcnt_clock_metadata { 376 __u32 num_domains; 377 __u32 pad; 378 __u64 cycles[MAX_REPORTED_DOMAINS]; 379 }; 380 381 /* This block state is unknown */ 382 #define BLOCK_STATE_UNKNOWN (0) 383 /* This block was powered on for at least some portion of the sample */ 384 #define BLOCK_STATE_ON (1 << 0) 385 /* This block was powered off for at least some portion of the sample */ 386 #define BLOCK_STATE_OFF (1 << 1) 387 /* This block was available to this VM for at least some portion of the sample */ 388 #define BLOCK_STATE_AVAILABLE (1 << 2) 389 /* This block was not available to this VM for at least some portion of the sample 390 * Note that no data is collected when the block is not available to the VM. 391 */ 392 #define BLOCK_STATE_UNAVAILABLE (1 << 3) 393 /* This block was operating in "normal" (non-protected) mode for at least some portion of the sample */ 394 #define BLOCK_STATE_NORMAL (1 << 4) 395 /* This block was operating in "protected" mode for at least some portion of the sample. 396 * Note that no data is collected when the block is in protected mode. 397 */ 398 #define BLOCK_STATE_PROTECTED (1 << 5) 399 400 /** 401 * struct prfcnt_block_metadata - Metadata for counter block. 402 * @block_type: Type of performance counter block. 403 * @block_idx: Index of performance counter block. 404 * @set: Set of performance counter block. 405 * @pad_u8: Padding bytes. 406 * @block_state: Bits set indicate the states which the block is known 407 * to have operated in during this sample. 408 * @values_offset: Offset from the start of the mmapped region, to the values 409 * for this block. The values themselves are an array of __u64. 410 * @pad_u32: Padding bytes. 411 */ 412 struct prfcnt_block_metadata { 413 __u8 block_type; 414 __u8 block_idx; 415 __u8 set; 416 __u8 pad_u8; 417 __u32 block_state; 418 __u32 values_offset; 419 __u32 pad_u32; 420 }; 421 422 /** 423 * struct prfcnt_metadata - Performance counter metadata item. 424 * @padding: Padding bytes. 425 * @hdr: Header describing the type of item in the list. 426 * @u: Structure containing descriptor for metadata type. 427 * @u.sample_md: Counter sample data metadata descriptor. 428 * @u.clock_md: Clock cycles metadata descriptor. 429 * @u.block_md: Counter block metadata descriptor. 430 */ 431 struct prfcnt_metadata { 432 struct prfcnt_item_header hdr; 433 __u8 padding[4]; 434 union { 435 struct prfcnt_sample_metadata sample_md; 436 struct prfcnt_clock_metadata clock_md; 437 struct prfcnt_block_metadata block_md; 438 } u; 439 }; 440 441 /** 442 * enum prfcnt_control_cmd_code - Control command code for client session. 443 * @PRFCNT_CONTROL_CMD_START: Start the counter data dump run for 444 * the calling client session. 445 * @PRFCNT_CONTROL_CMD_STOP: Stop the counter data dump run for the 446 * calling client session. 447 * @PRFCNT_CONTROL_CMD_SAMPLE_SYNC: Trigger a synchronous manual sample. 448 * @PRFCNT_CONTROL_CMD_RESERVED: Previously SAMPLE_ASYNC not supported any more. 449 * @PRFCNT_CONTROL_CMD_DISCARD: Discard all samples which have not yet 450 * been consumed by userspace. Note that 451 * this can race with new samples if 452 * HWC_CMD_STOP is not called first. 453 */ 454 enum prfcnt_control_cmd_code { 455 PRFCNT_CONTROL_CMD_START = 1, 456 PRFCNT_CONTROL_CMD_STOP, 457 PRFCNT_CONTROL_CMD_SAMPLE_SYNC, 458 PRFCNT_CONTROL_CMD_RESERVED, 459 PRFCNT_CONTROL_CMD_DISCARD, 460 }; 461 462 /** struct prfcnt_control_cmd - Control command 463 * @cmd: Control command for the session. 464 * @pad: Padding bytes. 465 * @user_data: Pointer to user data, which will be returned as part of 466 * sample metadata. It only affects a single sample if used 467 * with CMD_SAMPLE_SYNC or CMD_SAMPLE_ASYNC. It affects all 468 * samples between CMD_START and CMD_STOP if used with the 469 * periodic sampling. 470 */ 471 struct prfcnt_control_cmd { 472 __u16 cmd; 473 __u16 pad[3]; 474 __u64 user_data; 475 }; 476 477 /** struct prfcnt_sample_access - Metadata to access a sample. 478 * @sequence: Sequence number for the sample. 479 * For GET_SAMPLE, it will be set by the kernel. 480 * For PUT_SAMPLE, it shall be equal to the same value 481 * provided by the kernel for GET_SAMPLE. 482 * @sample_offset_bytes: Offset from the start of the mapped area to the first 483 * entry in the metadata list (sample_metadata) for this 484 * sample. 485 */ 486 struct prfcnt_sample_access { 487 __u64 sequence; 488 __u64 sample_offset_bytes; 489 }; 490 491 /* The ids of ioctl commands, on a reader file descriptor, magic number */ 492 #define KBASE_KINSTR_PRFCNT_READER 0xBF 493 /* Ioctl ID for issuing a session operational command */ 494 #define KBASE_IOCTL_KINSTR_PRFCNT_CMD \ 495 _IOW(KBASE_KINSTR_PRFCNT_READER, 0x00, struct prfcnt_control_cmd) 496 /* Ioctl ID for fetching a dumpped sample */ 497 #define KBASE_IOCTL_KINSTR_PRFCNT_GET_SAMPLE \ 498 _IOR(KBASE_KINSTR_PRFCNT_READER, 0x01, struct prfcnt_sample_access) 499 /* Ioctl ID for release internal buffer of the previously fetched sample */ 500 #define KBASE_IOCTL_KINSTR_PRFCNT_PUT_SAMPLE \ 501 _IOW(KBASE_KINSTR_PRFCNT_READER, 0x10, struct prfcnt_sample_access) 502 503 #endif /* _UAPI_KBASE_HWCNT_READER_H_ */ 504