@@ -9,6 +9,7 @@ panthor-y := \
panthor_gpu.o \
panthor_heap.o \
panthor_mmu.o \
+ panthor_perf.o \
panthor_sched.o
obj-$(CONFIG_DRM_PANTHOR) += panthor.o
@@ -19,6 +19,7 @@
#include "panthor_fw.h"
#include "panthor_gpu.h"
#include "panthor_mmu.h"
+#include "panthor_perf.h"
#include "panthor_regs.h"
#include "panthor_sched.h"
@@ -259,6 +260,10 @@ int panthor_device_init(struct panthor_device *ptdev)
if (ret)
goto err_unplug_fw;
+ ret = panthor_perf_init(ptdev);
+ if (ret)
+ goto err_unplug_fw;
+
/* ~3 frames */
pm_runtime_set_autosuspend_delay(ptdev->base.dev, 50);
pm_runtime_use_autosuspend(ptdev->base.dev);
@@ -120,6 +120,9 @@ struct panthor_device {
/** @csif_info: Command stream interface information. */
struct drm_panthor_csif_info csif_info;
+ /** @perf_info: Performance counter interface information. */
+ struct drm_panthor_perf_info perf_info;
+
/** @gpu: GPU management data. */
struct panthor_gpu *gpu;
@@ -175,7 +175,8 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride,
PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \
PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \
PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \
- PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs))
+ PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \
+ PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info, shader_blocks))
/**
* PANTHOR_UOBJ_SET() - Copy a kernel object to a user object.
@@ -835,6 +836,10 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
args->size = sizeof(priorities_info);
return 0;
+ case DRM_PANTHOR_DEV_QUERY_PERF_INFO:
+ args->size = sizeof(ptdev->perf_info);
+ return 0;
+
default:
return -EINVAL;
}
@@ -859,6 +864,9 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
panthor_query_group_priorities_info(file, &priorities_info);
return PANTHOR_UOBJ_SET(args->pointer, args->size, priorities_info);
+ case DRM_PANTHOR_DEV_QUERY_PERF_INFO:
+ return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->perf_info);
+
default:
return -EINVAL;
}
@@ -197,8 +197,11 @@ struct panthor_fw_global_control_iface {
u32 output_va;
u32 group_num;
u32 group_stride;
+#define GLB_PERFCNT_FW_SIZE(x) ((((x) >> 16) << 8))
u32 perfcnt_size;
u32 instr_features;
+#define PERFCNT_FEATURES_MD_SIZE(x) (((x) & GENMASK(3, 0)) << 8)
+ u32 perfcnt_features;
};
struct panthor_fw_global_input_iface {
new file mode 100644
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
+/* Copyright 2023 Collabora Ltd */
+/* Copyright 2025 Arm ltd. */
+
+#include <linux/bitops.h>
+#include <drm/panthor_drm.h>
+
+#include "panthor_device.h"
+#include "panthor_fw.h"
+#include "panthor_perf.h"
+
+/**
+ * PANTHOR_PERF_COUNTERS_PER_BLOCK - On CSF architectures pre-11.x, the number of counters
+ * per block was hardcoded to be 64. Arch 11.0 onwards supports the PRFCNT_FEATURES GPU register,
+ * which indicates the same information.
+ */
+#define PANTHOR_PERF_COUNTERS_PER_BLOCK (64)
+
+static void panthor_perf_info_init(struct panthor_device *ptdev)
+{
+ struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
+ struct drm_panthor_perf_info *const perf_info = &ptdev->perf_info;
+
+ if (PERFCNT_FEATURES_MD_SIZE(glb_iface->control->perfcnt_features))
+ perf_info->flags |= DRM_PANTHOR_PERF_BLOCK_STATES_SUPPORT;
+
+ perf_info->counters_per_block = PANTHOR_PERF_COUNTERS_PER_BLOCK;
+
+ perf_info->sample_header_size = sizeof(struct drm_panthor_perf_sample_header);
+ perf_info->block_header_size = sizeof(struct drm_panthor_perf_block_header);
+
+ if (GLB_PERFCNT_FW_SIZE(glb_iface->control->perfcnt_size))
+ perf_info->fw_blocks = 1;
+
+ perf_info->cshw_blocks = 1;
+ perf_info->tiler_blocks = 1;
+ perf_info->memsys_blocks = DRM_PANTHOR_L2_SLICES(ptdev->gpu_info.mem_features);
+ perf_info->shader_blocks = hweight64(ptdev->gpu_info.shader_present);
+}
+
+/**
+ * panthor_perf_init - Initialize the performance counter subsystem.
+ * @ptdev: Panthor device
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int panthor_perf_init(struct panthor_device *ptdev)
+{
+ if (!ptdev)
+ return -EINVAL;
+
+ panthor_perf_info_init(ptdev);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 or MIT */
+/* Copyright 2025 Collabora Ltd */
+/* Copyright 2025 Arm ltd. */
+
+#ifndef __PANTHOR_PERF_H__
+#define __PANTHOR_PERF_H__
+
+#include <linux/types.h>
+
+struct panthor_device;
+
+int panthor_perf_init(struct panthor_device *ptdev);
+
+#endif /* __PANTHOR_PERF_H__ */
+
@@ -270,6 +270,7 @@ struct drm_panthor_gpu_info {
/** @mem_features: Memory features. */
__u32 mem_features;
+#define DRM_PANTHOR_L2_SLICES(x) ((((x) >> 8) & 0xf) + 1)
/** @mmu_features: MMU features. */
__u32 mmu_features;