From e636c8d336489bf3eed5878299e6cc045bbad077 Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Tue, 20 Feb 2024 01:17:29 +0000
Subject: [PATCH] debug lk

---
 kernel/include/uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h |  404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 401 insertions(+), 3 deletions(-)

diff --git a/kernel/include/uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h b/kernel/include/uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h
index 9baaec1..5089bf2 100644
--- a/kernel/include/uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h
+++ b/kernel/include/uapi/gpu/arm/bifrost/mali_kbase_hwcnt_reader.h
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 /*
  *
- * (C) COPYRIGHT 2015, 2020-2021 ARM Limited. All rights reserved.
+ * (C) COPYRIGHT 2015, 2020-2022 ARM Limited. All rights reserved.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -22,7 +22,7 @@
 #ifndef _UAPI_KBASE_HWCNT_READER_H_
 #define _UAPI_KBASE_HWCNT_READER_H_
 
-#include <stddef.h>
+#include <linux/stddef.h>
 #include <linux/types.h>
 
 /* The ids of ioctl commands. */
@@ -91,6 +91,7 @@
 #define KBASE_HWCNT_READER_API_VERSION_NO_FEATURE (0)
 #define KBASE_HWCNT_READER_API_VERSION_FEATURE_CYCLES_TOP (1 << 0)
 #define KBASE_HWCNT_READER_API_VERSION_FEATURE_CYCLES_SHADER_CORES (1 << 1)
+
 /**
  * struct kbase_hwcnt_reader_api_version - hwcnt reader API version
  * @version:  API version
@@ -101,5 +102,402 @@
 	__u32 features;
 };
 
-#endif /* _UAPI_KBASE_HWCNT_READER_H_ */
+/** Hardware counters reader API version */
+#define PRFCNT_READER_API_VERSION (0)
 
+/**
+ * enum prfcnt_list_type - Type of list item
+ * @PRFCNT_LIST_TYPE_ENUM:        Enumeration of performance counters.
+ * @PRFCNT_LIST_TYPE_REQUEST:     Request for configuration setup.
+ * @PRFCNT_LIST_TYPE_SAMPLE_META: Sample metadata.
+ */
+enum prfcnt_list_type {
+	PRFCNT_LIST_TYPE_ENUM,
+	PRFCNT_LIST_TYPE_REQUEST,
+	PRFCNT_LIST_TYPE_SAMPLE_META,
+};
+
+#define FLEX_LIST_TYPE(type, subtype)                                          \
+	((__u16)(((type & 0xf) << 12) | (subtype & 0xfff)))
+#define FLEX_LIST_TYPE_NONE FLEX_LIST_TYPE(0, 0)
+
+#define PRFCNT_ENUM_TYPE_BLOCK FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_ENUM, 0)
+#define PRFCNT_ENUM_TYPE_REQUEST FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_ENUM, 1)
+#define PRFCNT_ENUM_TYPE_SAMPLE_INFO FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_ENUM, 2)
+
+#define PRFCNT_REQUEST_TYPE_MODE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 0)
+#define PRFCNT_REQUEST_TYPE_ENABLE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 1)
+#define PRFCNT_REQUEST_TYPE_SCOPE FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_REQUEST, 2)
+
+#define PRFCNT_SAMPLE_META_TYPE_SAMPLE                                         \
+	FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 0)
+#define PRFCNT_SAMPLE_META_TYPE_CLOCK                                          \
+	FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 1)
+#define PRFCNT_SAMPLE_META_TYPE_BLOCK                                          \
+	FLEX_LIST_TYPE(PRFCNT_LIST_TYPE_SAMPLE_META, 2)
+
+/**
+ * struct prfcnt_item_header - Header for an item of the list.
+ * @item_type:    Type of item.
+ * @item_version: Protocol version.
+ */
+struct prfcnt_item_header {
+	__u16 item_type;
+	__u16 item_version;
+};
+
+/**
+ * enum prfcnt_block_type - Type of performance counter block.
+ * @PRFCNT_BLOCK_TYPE_FE:          Front End.
+ * @PRFCNT_BLOCK_TYPE_TILER:       Tiler.
+ * @PRFCNT_BLOCK_TYPE_MEMORY:      Memory System.
+ * @PRFCNT_BLOCK_TYPE_SHADER_CORE: Shader Core.
+ * @PRFCNT_BLOCK_TYPE_RESERVED:    Reserved.
+ */
+enum prfcnt_block_type {
+	PRFCNT_BLOCK_TYPE_FE,
+	PRFCNT_BLOCK_TYPE_TILER,
+	PRFCNT_BLOCK_TYPE_MEMORY,
+	PRFCNT_BLOCK_TYPE_SHADER_CORE,
+	PRFCNT_BLOCK_TYPE_RESERVED = 255,
+};
+
+/**
+ * enum prfcnt_set - Type of performance counter block set.
+ * @PRFCNT_SET_PRIMARY:   Primary.
+ * @PRFCNT_SET_SECONDARY: Secondary.
+ * @PRFCNT_SET_TERTIARY:  Tertiary.
+ * @PRFCNT_SET_RESERVED:  Reserved.
+ */
+enum prfcnt_set {
+	PRFCNT_SET_PRIMARY,
+	PRFCNT_SET_SECONDARY,
+	PRFCNT_SET_TERTIARY,
+	PRFCNT_SET_RESERVED = 255,
+};
+
+/**
+ * struct prfcnt_enum_block_counter - Performance counter block descriptor.
+ * @block_type:    Type of performance counter block.
+ * @set:           Which SET this represents: primary, secondary or tertiary.
+ * @pad:           Padding bytes.
+ * @num_instances: How many instances of this block type exist in the hardware.
+ * @num_values:    How many entries in the values array there are for samples
+ *                 from this block.
+ * @counter_mask:  Bitmask that indicates counter availability in this block.
+ *                 A '0' indicates that a counter is not available at that
+ *                 index and will always return zeroes if requested.
+ */
+struct prfcnt_enum_block_counter {
+	__u8 block_type;
+	__u8 set;
+	__u8 pad[2];
+	__u16 num_instances;
+	__u16 num_values;
+	__u64 counter_mask[2];
+};
+
+/**
+ * struct prfcnt_enum_request - Request descriptor.
+ * @request_item_type:       Type of request.
+ * @pad:                     Padding bytes.
+ * @versions_mask: Bitmask of versions that support this request.
+ */
+struct prfcnt_enum_request {
+	__u16 request_item_type;
+	__u16 pad;
+	__u32 versions_mask;
+};
+
+/**
+ * struct prfcnt_enum_sample_info - Sample information descriptor.
+ * @num_clock_domains:       Number of clock domains of the GPU.
+ * @pad:                     Padding bytes.
+ */
+struct prfcnt_enum_sample_info {
+	__u32 num_clock_domains;
+	__u32 pad;
+};
+
+/**
+ * struct prfcnt_enum_item - Performance counter enumeration item.
+ * @padding:         Padding bytes.
+ * @hdr:             Header describing the type of item in the list.
+ * @u:               Structure containing discriptor for enumeration item type.
+ * @u.block_counter: Performance counter block descriptor.
+ * @u.request:       Request descriptor.
+ * @u.sample_info:   Performance counter sample information descriptor.
+ */
+struct prfcnt_enum_item {
+	struct prfcnt_item_header hdr;
+	__u8 padding[4];
+	/** union u - union of block_counter and request */
+	union {
+		struct prfcnt_enum_block_counter block_counter;
+		struct prfcnt_enum_request request;
+		struct prfcnt_enum_sample_info sample_info;
+	} u;
+};
+
+/**
+ * enum prfcnt_mode - Capture mode for counter sampling.
+ * @PRFCNT_MODE_MANUAL:   Manual sampling mode.
+ * @PRFCNT_MODE_PERIODIC: Periodic sampling mode.
+ * @PRFCNT_MODE_RESERVED: Reserved.
+ */
+enum prfcnt_mode {
+	PRFCNT_MODE_MANUAL,
+	PRFCNT_MODE_PERIODIC,
+	PRFCNT_MODE_RESERVED = 255,
+};
+
+/**
+ * struct prfcnt_request_mode - Mode request descriptor.
+ * @mode:                           Capture mode for the session, either manual or periodic.
+ * @pad:                            Padding bytes.
+ * @mode_config:                    Structure containing configuration for periodic mode.
+ * @mode_config.periodic:           Periodic config.
+ * @mode_config.periodic.period_ns: Period in nanoseconds, for periodic mode.
+ */
+struct prfcnt_request_mode {
+	__u8 mode;
+	__u8 pad[7];
+	/** union mode_config - request mode configuration*/
+	union {
+		struct {
+			__u64 period_ns;
+		} periodic;
+	} mode_config;
+};
+
+/**
+ * struct prfcnt_request_enable - Enable request descriptor.
+ * @block_type:  Type of performance counter block.
+ * @set:         Which SET to use: primary, secondary or tertiary.
+ * @pad:         Padding bytes.
+ * @enable_mask: Bitmask that indicates which performance counters to enable.
+ *               Unavailable counters will be ignored.
+ */
+struct prfcnt_request_enable {
+	__u8 block_type;
+	__u8 set;
+	__u8 pad[6];
+	__u64 enable_mask[2];
+};
+
+/**
+ * enum prfcnt_scope - Scope of performance counters.
+ * @PRFCNT_SCOPE_GLOBAL:   Global scope.
+ * @PRFCNT_SCOPE_RESERVED: Reserved.
+ */
+enum prfcnt_scope {
+	PRFCNT_SCOPE_GLOBAL,
+	PRFCNT_SCOPE_RESERVED = 255,
+};
+
+/**
+ * struct prfcnt_request_scope - Scope request descriptor.
+ * @scope: Scope of the performance counters to capture.
+ * @pad:   Padding bytes.
+ */
+struct prfcnt_request_scope {
+	__u8 scope;
+	__u8 pad[7];
+};
+
+/**
+ * struct prfcnt_request_item - Performance counter request item.
+ * @padding:      Padding bytes.
+ * @hdr:          Header describing the type of item in the list.
+ * @u:            Structure containing descriptor for request type.
+ * @u.req_mode:   Mode request descriptor.
+ * @u.req_enable: Enable request descriptor.
+ * @u.req_scope:  Scope request descriptor.
+ */
+struct prfcnt_request_item {
+	struct prfcnt_item_header hdr;
+	__u8 padding[4];
+	/** union u - union on req_mode and req_enable */
+	union {
+		struct prfcnt_request_mode req_mode;
+		struct prfcnt_request_enable req_enable;
+		struct prfcnt_request_scope req_scope;
+	} u;
+};
+
+/**
+ * enum prfcnt_request_type - Type of request descriptor.
+ * @PRFCNT_REQUEST_MODE:   Specify the capture mode to be used for the session.
+ * @PRFCNT_REQUEST_ENABLE: Specify which performance counters to capture.
+ * @PRFCNT_REQUEST_SCOPE:  Specify the scope of the performance counters.
+ */
+enum prfcnt_request_type {
+	PRFCNT_REQUEST_MODE,
+	PRFCNT_REQUEST_ENABLE,
+	PRFCNT_REQUEST_SCOPE,
+};
+
+/* This sample contains overflows from dump duration stretch because the sample buffer was full */
+#define SAMPLE_FLAG_OVERFLOW (1u << 0)
+/* This sample has had an error condition for sample duration */
+#define SAMPLE_FLAG_ERROR (1u << 30)
+
+/**
+ * struct prfcnt_sample_metadata - Metadata for counter sample data.
+ * @timestamp_start: Earliest timestamp that values in this sample represent.
+ * @timestamp_end:   Latest timestamp that values in this sample represent.
+ * @seq:             Sequence number of this sample. Must match the value from
+ *                   GET_SAMPLE.
+ * @user_data:       User data provided to HWC_CMD_START or HWC_CMD_SAMPLE_*
+ * @flags:           Property flags.
+ * @pad:             Padding bytes.
+ */
+struct prfcnt_sample_metadata {
+	__u64 timestamp_start;
+	__u64 timestamp_end;
+	__u64 seq;
+	__u64 user_data;
+	__u32 flags;
+	__u32 pad;
+};
+
+/* Maximum number of domains a metadata for clock cycles can refer to */
+#define MAX_REPORTED_DOMAINS (4)
+
+/**
+ * struct prfcnt_clock_metadata - Metadata for clock cycles.
+ * @num_domains: Number of domains this metadata refers to.
+ * @pad:         Padding bytes.
+ * @cycles:      Number of cycles elapsed in each counter domain between
+ *               timestamp_start and timestamp_end. Valid only for the
+ *               first @p num_domains.
+ */
+struct prfcnt_clock_metadata {
+	__u32 num_domains;
+	__u32 pad;
+	__u64 cycles[MAX_REPORTED_DOMAINS];
+};
+
+/* This block state is unknown */
+#define BLOCK_STATE_UNKNOWN (0)
+/* This block was powered on for at least some portion of the sample */
+#define BLOCK_STATE_ON (1 << 0)
+/* This block was powered off for at least some portion of the sample */
+#define BLOCK_STATE_OFF (1 << 1)
+/* This block was available to this VM for at least some portion of the sample */
+#define BLOCK_STATE_AVAILABLE (1 << 2)
+/* This block was not available to this VM for at least some portion of the sample
+ *  Note that no data is collected when the block is not available to the VM.
+ */
+#define BLOCK_STATE_UNAVAILABLE (1 << 3)
+/* This block was operating in "normal" (non-protected) mode for at least some portion of the sample */
+#define BLOCK_STATE_NORMAL (1 << 4)
+/* This block was operating in "protected" mode for at least some portion of the sample.
+ * Note that no data is collected when the block is in protected mode.
+ */
+#define BLOCK_STATE_PROTECTED (1 << 5)
+
+/**
+ * struct prfcnt_block_metadata - Metadata for counter block.
+ * @block_type:    Type of performance counter block.
+ * @block_idx:     Index of performance counter block.
+ * @set:           Set of performance counter block.
+ * @pad_u8:        Padding bytes.
+ * @block_state:   Bits set indicate the states which the block is known
+ *                 to have operated in during this sample.
+ * @values_offset: Offset from the start of the mmapped region, to the values
+ *                 for this block. The values themselves are an array of __u64.
+ * @pad_u32:       Padding bytes.
+ */
+struct prfcnt_block_metadata {
+	__u8 block_type;
+	__u8 block_idx;
+	__u8 set;
+	__u8 pad_u8;
+	__u32 block_state;
+	__u32 values_offset;
+	__u32 pad_u32;
+};
+
+/**
+ * struct prfcnt_metadata - Performance counter metadata item.
+ * @padding:     Padding bytes.
+ * @hdr:         Header describing the type of item in the list.
+ * @u:           Structure containing descriptor for metadata type.
+ * @u.sample_md: Counter sample data metadata descriptor.
+ * @u.clock_md:  Clock cycles metadata descriptor.
+ * @u.block_md:  Counter block metadata descriptor.
+ */
+struct prfcnt_metadata {
+	struct prfcnt_item_header hdr;
+	__u8 padding[4];
+	union {
+		struct prfcnt_sample_metadata sample_md;
+		struct prfcnt_clock_metadata clock_md;
+		struct prfcnt_block_metadata block_md;
+	} u;
+};
+
+/**
+ * enum prfcnt_control_cmd_code - Control command code for client session.
+ * @PRFCNT_CONTROL_CMD_START:        Start the counter data dump run for
+ *                                   the calling client session.
+ * @PRFCNT_CONTROL_CMD_STOP:         Stop the counter data dump run for the
+ *                                   calling client session.
+ * @PRFCNT_CONTROL_CMD_SAMPLE_SYNC:  Trigger a synchronous manual sample.
+ * @PRFCNT_CONTROL_CMD_RESERVED:     Previously SAMPLE_ASYNC not supported any more.
+ * @PRFCNT_CONTROL_CMD_DISCARD:      Discard all samples which have not yet
+ *                                   been consumed by userspace. Note that
+ *                                   this can race with new samples if
+ *                                   HWC_CMD_STOP is not called first.
+ */
+enum prfcnt_control_cmd_code {
+	PRFCNT_CONTROL_CMD_START = 1,
+	PRFCNT_CONTROL_CMD_STOP,
+	PRFCNT_CONTROL_CMD_SAMPLE_SYNC,
+	PRFCNT_CONTROL_CMD_RESERVED,
+	PRFCNT_CONTROL_CMD_DISCARD,
+};
+
+/** struct prfcnt_control_cmd - Control command
+ * @cmd:       Control command for the session.
+ * @pad:       Padding bytes.
+ * @user_data: Pointer to user data, which will be returned as part of
+ *             sample metadata. It only affects a single sample if used
+ *             with CMD_SAMPLE_SYNC or CMD_SAMPLE_ASYNC. It affects all
+ *             samples between CMD_START and CMD_STOP if used with the
+ *             periodic sampling.
+ */
+struct prfcnt_control_cmd {
+	__u16 cmd;
+	__u16 pad[3];
+	__u64 user_data;
+};
+
+/** struct prfcnt_sample_access - Metadata to access a sample.
+ * @sequence:            Sequence number for the sample.
+ *                       For GET_SAMPLE, it will be set by the kernel.
+ *                       For PUT_SAMPLE, it shall be equal to the same value
+ *                       provided by the kernel for GET_SAMPLE.
+ * @sample_offset_bytes: Offset from the start of the mapped area to the first
+ *                       entry in the metadata list (sample_metadata) for this
+ *                       sample.
+ */
+struct prfcnt_sample_access {
+	__u64 sequence;
+	__u64 sample_offset_bytes;
+};
+
+/* The ids of ioctl commands, on a reader file descriptor, magic number */
+#define KBASE_KINSTR_PRFCNT_READER 0xBF
+/* Ioctl ID for issuing a session operational command */
+#define KBASE_IOCTL_KINSTR_PRFCNT_CMD                                          \
+	_IOW(KBASE_KINSTR_PRFCNT_READER, 0x00, struct prfcnt_control_cmd)
+/* Ioctl ID for fetching a dumpped sample */
+#define KBASE_IOCTL_KINSTR_PRFCNT_GET_SAMPLE                                   \
+	_IOR(KBASE_KINSTR_PRFCNT_READER, 0x01, struct prfcnt_sample_access)
+/* Ioctl ID for release internal buffer of the previously fetched sample */
+#define KBASE_IOCTL_KINSTR_PRFCNT_PUT_SAMPLE                                   \
+	_IOW(KBASE_KINSTR_PRFCNT_READER, 0x10, struct prfcnt_sample_access)
+
+#endif /* _UAPI_KBASE_HWCNT_READER_H_ */

--
Gitblit v1.6.2