|
1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | 2 | /* |
3 | | - * Copyright (C) 2024 Intel Corporation |
| 3 | + * Copyright (C) 2024-2025 Intel Corporation |
4 | 4 | */ |
5 | 5 |
|
6 | 6 | #include <linux/device.h> |
7 | 7 | #include <linux/err.h> |
| 8 | +#include <linux/pm_runtime.h> |
| 9 | +#include <linux/units.h> |
8 | 10 |
|
9 | 11 | #include "ivpu_drv.h" |
10 | 12 | #include "ivpu_gem.h" |
@@ -90,10 +92,55 @@ sched_mode_show(struct device *dev, struct device_attribute *attr, char *buf) |
90 | 92 |
|
91 | 93 | static DEVICE_ATTR_RO(sched_mode); |
92 | 94 |
|
| 95 | +/** |
| 96 | + * DOC: npu_max_frequency |
| 97 | + * |
| 98 | + * The npu_max_frequency shows maximum frequency in MHz of the NPU's data |
| 99 | + * processing unit |
| 100 | + */ |
| 101 | +static ssize_t |
| 102 | +npu_max_frequency_mhz_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 103 | +{ |
| 104 | + struct drm_device *drm = dev_get_drvdata(dev); |
| 105 | + struct ivpu_device *vdev = to_ivpu_device(drm); |
| 106 | + u32 freq = ivpu_hw_dpu_max_freq_get(vdev); |
| 107 | + |
| 108 | + return sysfs_emit(buf, "%lu\n", freq / HZ_PER_MHZ); |
| 109 | +} |
| 110 | + |
| 111 | +static DEVICE_ATTR_RO(npu_max_frequency_mhz); |
| 112 | + |
| 113 | +/** |
| 114 | + * DOC: npu_current_frequency_mhz |
| 115 | + * |
| 116 | + * The npu_current_frequency_mhz shows current frequency in MHz of the NPU's |
| 117 | + * data processing unit |
| 118 | + */ |
| 119 | +static ssize_t |
| 120 | +npu_current_frequency_mhz_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 121 | +{ |
| 122 | + struct drm_device *drm = dev_get_drvdata(dev); |
| 123 | + struct ivpu_device *vdev = to_ivpu_device(drm); |
| 124 | + u32 freq = 0; |
| 125 | + |
| 126 | + /* Read frequency only if device is active, otherwise frequency is 0 */ |
| 127 | + if (pm_runtime_get_if_active(vdev->drm.dev) > 0) { |
| 128 | + freq = ivpu_hw_dpu_freq_get(vdev); |
| 129 | + |
| 130 | + pm_runtime_put_autosuspend(vdev->drm.dev); |
| 131 | + } |
| 132 | + |
| 133 | + return sysfs_emit(buf, "%lu\n", freq / HZ_PER_MHZ); |
| 134 | +} |
| 135 | + |
| 136 | +static DEVICE_ATTR_RO(npu_current_frequency_mhz); |
| 137 | + |
93 | 138 | static struct attribute *ivpu_dev_attrs[] = { |
94 | 139 | &dev_attr_npu_busy_time_us.attr, |
95 | 140 | &dev_attr_npu_memory_utilization.attr, |
96 | 141 | &dev_attr_sched_mode.attr, |
| 142 | + &dev_attr_npu_max_frequency_mhz.attr, |
| 143 | + &dev_attr_npu_current_frequency_mhz.attr, |
97 | 144 | NULL, |
98 | 145 | }; |
99 | 146 |
|
|
0 commit comments