1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ 2 /* Copyright 2025-2026 Arm, Ltd. */ 3 #ifndef __ETHOSU_DRV_H__ 4 #define __ETHOSU_DRV_H__ 5 6 #include <linux/mutex.h> 7 #include <linux/xarray.h> 8 #include <drm/gpu_scheduler.h> 9 10 struct ethosu_device; 11 struct drm_device; 12 struct drm_file; 13 14 struct ethosu_file_priv { 15 struct ethosu_device *edev; 16 struct drm_sched_entity sched_entity; 17 struct xarray perfmons; 18 }; 19 20 /* Performance monitor object. The perfmon lifetime is controlled by userspace 21 * using perfmon related ioctls. A perfmon can be attached to a DRM_ETHOSU_SUBMIT 22 * request, and when this is the case, HW perf counters will be activated just 23 * before the job is submitted to the NPU and disabled when the job is 24 * done. This way, only events related to a specific job will be counted. 25 */ 26 struct ethosu_perfmon { 27 /* Tracks the number of users of the perfmon, when this counter reaches 28 * zero the perfmon is destroyed. 29 */ 30 refcount_t refcnt; 31 32 /* Number of counters activated in this perfmon instance 33 * (should be less than or equal to DRM_ETHOSU_MAX_PERF_COUNTERS). 34 */ 35 u8 ncounters; 36 37 /* Events counted by the HW perf counters. */ 38 u16 counters[DRM_ETHOSU_MAX_PERF_EVENT_COUNTERS]; 39 40 /* 41 * Storage for counter values. Counters are incremented by the HW 42 * perf counter values every time the perfmon is attached to an 43 * NPU job. This way, perfmon users don't have to retrieve the 44 * results after each job if they want to track events covering 45 * several submissions. Note that counter values can't be reset, 46 * but you can fake a reset by destroying the perfmon and 47 * creating a new one. 48 */ 49 u64 values[] __counted_by(ncounters); 50 }; 51 52 /* ethosu_perfmon.c */ 53 void ethosu_perfmon_get(struct ethosu_perfmon *perfmon); 54 void ethosu_perfmon_put(struct ethosu_perfmon *perfmon); 55 void ethosu_perfmon_start(struct ethosu_device *ethosu, 56 struct ethosu_perfmon *perfmon); 57 void ethosu_perfmon_stop(struct ethosu_device *ethosu, 58 struct ethosu_perfmon *perfmon, bool capture); 59 void ethosu_perfmon_stop_locked(struct ethosu_device *ethosu, struct ethosu_perfmon *perfmon, 60 bool capture); 61 struct ethosu_perfmon *ethosu_perfmon_find(struct ethosu_file_priv *ethosu_priv, 62 int id); 63 void ethosu_perfmon_open_file(struct ethosu_file_priv *ethosu_priv); 64 void ethosu_perfmon_close_file(struct ethosu_file_priv *ethosu_priv); 65 int ethosu_ioctl_perfmon_create(struct drm_device *dev, void *data, 66 struct drm_file *file_priv); 67 int ethosu_ioctl_perfmon_destroy(struct drm_device *dev, void *data, 68 struct drm_file *file_priv); 69 int ethosu_ioctl_perfmon_get_values(struct drm_device *dev, void *data, 70 struct drm_file *file_priv); 71 int ethosu_ioctl_perfmon_set_global(struct drm_device *dev, void *data, 72 struct drm_file *file_priv); 73 74 #endif 75