Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Ben Widawsky <ben@bwidawsk.net> |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <linux/device.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/stat.h> |
| 31 | #include <linux/sysfs.h> |
Chris Wilson | 56c5098 | 2019-04-26 09:17:22 +0100 | [diff] [blame] | 32 | |
Andi Shyti | c113236 | 2019-09-27 12:08:49 +0100 | [diff] [blame] | 33 | #include "gt/intel_rc6.h" |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 34 | #include "gt/intel_rps.h" |
Chris Wilson | 4ec76db | 2020-02-28 13:17:10 +0000 | [diff] [blame] | 35 | #include "gt/sysfs_engines.h" |
Andi Shyti | c113236 | 2019-09-27 12:08:49 +0100 | [diff] [blame] | 36 | |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 37 | #include "i915_drv.h" |
Jani Nikula | be68261 | 2019-08-08 16:42:45 +0300 | [diff] [blame] | 38 | #include "i915_sysfs.h" |
Jani Nikula | ecbb5fb | 2019-04-29 15:29:37 +0300 | [diff] [blame] | 39 | #include "intel_pm.h" |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 40 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 41 | static inline struct drm_i915_private *kdev_minor_to_i915(struct device *kdev) |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 42 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 43 | struct drm_minor *minor = dev_get_drvdata(kdev); |
| 44 | return to_i915(minor->dev); |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 45 | } |
Dave Airlie | 14c8d110 | 2013-10-11 14:45:30 +1000 | [diff] [blame] | 46 | |
Hunt Xu | 5ab3633 | 2012-07-01 03:45:07 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 48 | static u32 calc_residency(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 49 | i915_reg_t reg) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 50 | { |
Chris Wilson | 48d1c81 | 2019-01-14 14:21:13 +0000 | [diff] [blame] | 51 | intel_wakeref_t wakeref; |
Chris Wilson | d4225a5 | 2019-01-14 14:21:23 +0000 | [diff] [blame] | 52 | u64 res = 0; |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 53 | |
Daniele Ceraolo Spurio | c447ff7 | 2019-06-13 16:21:55 -0700 | [diff] [blame] | 54 | with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) |
Andi Shyti | c113236 | 2019-09-27 12:08:49 +0100 | [diff] [blame] | 55 | res = intel_rc6_residency_us(&dev_priv->gt.rc6, reg); |
Tvrtko Ursulin | 36cc8b9 | 2017-11-21 18:18:51 +0000 | [diff] [blame] | 56 | |
| 57 | return DIV_ROUND_CLOSEST_ULL(res, 1000); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 58 | } |
| 59 | |
YueHaibing | 177f30c | 2021-05-28 18:04:03 +0800 | [diff] [blame] | 60 | static ssize_t rc6_enable_show(struct device *kdev, |
| 61 | struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 62 | { |
Chris Wilson | fb6db0f | 2017-12-01 11:30:30 +0000 | [diff] [blame] | 63 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 64 | unsigned int mask; |
| 65 | |
| 66 | mask = 0; |
| 67 | if (HAS_RC6(dev_priv)) |
| 68 | mask |= BIT(0); |
| 69 | if (HAS_RC6p(dev_priv)) |
| 70 | mask |= BIT(1); |
| 71 | if (HAS_RC6pp(dev_priv)) |
| 72 | mask |= BIT(2); |
| 73 | |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 74 | return sysfs_emit(buf, "%x\n", mask); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 75 | } |
| 76 | |
YueHaibing | 177f30c | 2021-05-28 18:04:03 +0800 | [diff] [blame] | 77 | static ssize_t rc6_residency_ms_show(struct device *kdev, |
| 78 | struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 79 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 80 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 81 | u32 rc6_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6); |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 82 | return sysfs_emit(buf, "%u\n", rc6_residency); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 83 | } |
| 84 | |
YueHaibing | 177f30c | 2021-05-28 18:04:03 +0800 | [diff] [blame] | 85 | static ssize_t rc6p_residency_ms_show(struct device *kdev, |
| 86 | struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 87 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 88 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 89 | u32 rc6p_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6p); |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 90 | return sysfs_emit(buf, "%u\n", rc6p_residency); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 91 | } |
| 92 | |
YueHaibing | 177f30c | 2021-05-28 18:04:03 +0800 | [diff] [blame] | 93 | static ssize_t rc6pp_residency_ms_show(struct device *kdev, |
| 94 | struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 95 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 96 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 97 | u32 rc6pp_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6pp); |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 98 | return sysfs_emit(buf, "%u\n", rc6pp_residency); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 99 | } |
| 100 | |
YueHaibing | 177f30c | 2021-05-28 18:04:03 +0800 | [diff] [blame] | 101 | static ssize_t media_rc6_residency_ms_show(struct device *kdev, |
| 102 | struct device_attribute *attr, char *buf) |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 103 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 104 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 105 | u32 rc6_residency = calc_residency(dev_priv, VLV_GT_MEDIA_RC6); |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 106 | return sysfs_emit(buf, "%u\n", rc6_residency); |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 107 | } |
| 108 | |
YueHaibing | 177f30c | 2021-05-28 18:04:03 +0800 | [diff] [blame] | 109 | static DEVICE_ATTR_RO(rc6_enable); |
| 110 | static DEVICE_ATTR_RO(rc6_residency_ms); |
| 111 | static DEVICE_ATTR_RO(rc6p_residency_ms); |
| 112 | static DEVICE_ATTR_RO(rc6pp_residency_ms); |
| 113 | static DEVICE_ATTR_RO(media_rc6_residency_ms); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 114 | |
| 115 | static struct attribute *rc6_attrs[] = { |
| 116 | &dev_attr_rc6_enable.attr, |
| 117 | &dev_attr_rc6_residency_ms.attr, |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 118 | NULL |
| 119 | }; |
| 120 | |
Arvind Yadav | 0a7a098 | 2017-07-03 16:38:25 +0530 | [diff] [blame] | 121 | static const struct attribute_group rc6_attr_group = { |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 122 | .name = power_group_name, |
| 123 | .attrs = rc6_attrs |
| 124 | }; |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 125 | |
| 126 | static struct attribute *rc6p_attrs[] = { |
| 127 | &dev_attr_rc6p_residency_ms.attr, |
| 128 | &dev_attr_rc6pp_residency_ms.attr, |
| 129 | NULL |
| 130 | }; |
| 131 | |
Arvind Yadav | 0a7a098 | 2017-07-03 16:38:25 +0530 | [diff] [blame] | 132 | static const struct attribute_group rc6p_attr_group = { |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 133 | .name = power_group_name, |
| 134 | .attrs = rc6p_attrs |
| 135 | }; |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 136 | |
| 137 | static struct attribute *media_rc6_attrs[] = { |
| 138 | &dev_attr_media_rc6_residency_ms.attr, |
| 139 | NULL |
| 140 | }; |
| 141 | |
Arvind Yadav | 0a7a098 | 2017-07-03 16:38:25 +0530 | [diff] [blame] | 142 | static const struct attribute_group media_rc6_attr_group = { |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 143 | .name = power_group_name, |
| 144 | .attrs = media_rc6_attrs |
| 145 | }; |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 146 | #endif |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 147 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 148 | static int l3_access_valid(struct drm_i915_private *i915, loff_t offset) |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 149 | { |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 150 | if (!HAS_L3_DPF(i915)) |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 151 | return -EPERM; |
| 152 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 153 | if (!IS_ALIGNED(offset, sizeof(u32))) |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 154 | return -EINVAL; |
| 155 | |
| 156 | if (offset >= GEN7_L3LOG_SIZE) |
| 157 | return -ENXIO; |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static ssize_t |
| 163 | i915_l3_read(struct file *filp, struct kobject *kobj, |
| 164 | struct bin_attribute *attr, char *buf, |
| 165 | loff_t offset, size_t count) |
| 166 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 167 | struct device *kdev = kobj_to_dev(kobj); |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 168 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 169 | int slice = (int)(uintptr_t)attr->private; |
Ben Widawsky | 3ccfd19 | 2013-09-18 19:03:18 -0700 | [diff] [blame] | 170 | int ret; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 171 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 172 | ret = l3_access_valid(i915, offset); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 173 | if (ret) |
| 174 | return ret; |
| 175 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 176 | count = round_down(count, sizeof(u32)); |
Dan Carpenter | e5ad402 | 2013-09-20 14:20:18 +0300 | [diff] [blame] | 177 | count = min_t(size_t, GEN7_L3LOG_SIZE - offset, count); |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 178 | memset(buf, 0, count); |
Ben Widawsky | 33618ea | 2013-09-12 22:28:29 -0700 | [diff] [blame] | 179 | |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 180 | spin_lock(&i915->gem.contexts.lock); |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 181 | if (i915->l3_parity.remap_info[slice]) |
Ben Widawsky | 3ccfd19 | 2013-09-18 19:03:18 -0700 | [diff] [blame] | 182 | memcpy(buf, |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 183 | i915->l3_parity.remap_info[slice] + offset / sizeof(u32), |
Ben Widawsky | 3ccfd19 | 2013-09-18 19:03:18 -0700 | [diff] [blame] | 184 | count); |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 185 | spin_unlock(&i915->gem.contexts.lock); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 186 | |
Ben Widawsky | 1c966dd | 2013-09-17 21:12:42 -0700 | [diff] [blame] | 187 | return count; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static ssize_t |
| 191 | i915_l3_write(struct file *filp, struct kobject *kobj, |
| 192 | struct bin_attribute *attr, char *buf, |
| 193 | loff_t offset, size_t count) |
| 194 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 195 | struct device *kdev = kobj_to_dev(kobj); |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 196 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 197 | int slice = (int)(uintptr_t)attr->private; |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 198 | u32 *remap_info, *freeme = NULL; |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 199 | struct i915_gem_context *ctx; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 200 | int ret; |
| 201 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 202 | ret = l3_access_valid(i915, offset); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 203 | if (ret) |
| 204 | return ret; |
| 205 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 206 | if (count < sizeof(u32)) |
| 207 | return -EINVAL; |
| 208 | |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 209 | remap_info = kzalloc(GEN7_L3LOG_SIZE, GFP_KERNEL); |
| 210 | if (!remap_info) |
| 211 | return -ENOMEM; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 212 | |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 213 | spin_lock(&i915->gem.contexts.lock); |
| 214 | |
| 215 | if (i915->l3_parity.remap_info[slice]) { |
| 216 | freeme = remap_info; |
| 217 | remap_info = i915->l3_parity.remap_info[slice]; |
| 218 | } else { |
| 219 | i915->l3_parity.remap_info[slice] = remap_info; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 222 | count = round_down(count, sizeof(u32)); |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 223 | memcpy(remap_info + offset / sizeof(u32), buf, count); |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 224 | |
| 225 | /* NB: We defer the remapping until we switch to the context */ |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 226 | list_for_each_entry(ctx, &i915->gem.contexts.list, link) |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 227 | ctx->remap_slice |= BIT(slice); |
| 228 | |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 229 | spin_unlock(&i915->gem.contexts.lock); |
| 230 | kfree(freeme); |
| 231 | |
Chris Wilson | 261ea7e | 2019-10-04 11:59:58 +0100 | [diff] [blame] | 232 | /* |
| 233 | * TODO: Ideally we really want a GPU reset here to make sure errors |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 234 | * aren't propagated. Since I cannot find a stable way to reset the GPU |
| 235 | * at this point it is left as a TODO. |
| 236 | */ |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 237 | |
Chris Wilson | a4e7ccd | 2019-10-04 14:40:09 +0100 | [diff] [blame] | 238 | return count; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Bhumika Goyal | 59f3da1 | 2017-08-02 22:50:47 +0530 | [diff] [blame] | 241 | static const struct bin_attribute dpf_attrs = { |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 242 | .attr = {.name = "l3_parity", .mode = (S_IRUSR | S_IWUSR)}, |
| 243 | .size = GEN7_L3LOG_SIZE, |
| 244 | .read = i915_l3_read, |
| 245 | .write = i915_l3_write, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 246 | .mmap = NULL, |
| 247 | .private = (void *)0 |
| 248 | }; |
| 249 | |
Bhumika Goyal | 59f3da1 | 2017-08-02 22:50:47 +0530 | [diff] [blame] | 250 | static const struct bin_attribute dpf_attrs_1 = { |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 251 | .attr = {.name = "l3_parity_slice_1", .mode = (S_IRUSR | S_IWUSR)}, |
| 252 | .size = GEN7_L3LOG_SIZE, |
| 253 | .read = i915_l3_read, |
| 254 | .write = i915_l3_write, |
| 255 | .mmap = NULL, |
| 256 | .private = (void *)1 |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 259 | static ssize_t gt_act_freq_mhz_show(struct device *kdev, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 260 | struct device_attribute *attr, char *buf) |
| 261 | { |
Andi Shyti | e03512e | 2019-12-13 20:37:35 +0200 | [diff] [blame] | 262 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
| 263 | struct intel_rps *rps = &i915->gt.rps; |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 264 | |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 265 | return sysfs_emit(buf, "%d\n", intel_rps_read_actual_frequency(rps)); |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static ssize_t gt_cur_freq_mhz_show(struct device *kdev, |
| 269 | struct device_attribute *attr, char *buf) |
| 270 | { |
Andi Shyti | e03512e | 2019-12-13 20:37:35 +0200 | [diff] [blame] | 271 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
| 272 | struct intel_rps *rps = &i915->gt.rps; |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 273 | |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 274 | return sysfs_emit(buf, "%d\n", intel_rps_get_requested_frequency(rps)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 277 | static ssize_t gt_boost_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 278 | { |
Andi Shyti | e03512e | 2019-12-13 20:37:35 +0200 | [diff] [blame] | 279 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
| 280 | struct intel_rps *rps = &i915->gt.rps; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 281 | |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 282 | return sysfs_emit(buf, "%d\n", intel_gpu_freq(rps, rps->boost_freq)); |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static ssize_t gt_boost_freq_mhz_store(struct device *kdev, |
| 286 | struct device_attribute *attr, |
| 287 | const char *buf, size_t count) |
| 288 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 289 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 290 | struct intel_rps *rps = &dev_priv->gt.rps; |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 291 | bool boost = false; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 292 | ssize_t ret; |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 293 | u32 val; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 294 | |
| 295 | ret = kstrtou32(buf, 0, &val); |
| 296 | if (ret) |
| 297 | return ret; |
| 298 | |
| 299 | /* Validate against (static) hardware limits */ |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 300 | val = intel_freq_opcode(rps, val); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 301 | if (val < rps->min_freq || val > rps->max_freq) |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 302 | return -EINVAL; |
| 303 | |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 304 | mutex_lock(&rps->lock); |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 305 | if (val != rps->boost_freq) { |
| 306 | rps->boost_freq = val; |
| 307 | boost = atomic_read(&rps->num_waiters); |
| 308 | } |
Chris Wilson | ebb5eb7 | 2019-04-26 09:17:21 +0100 | [diff] [blame] | 309 | mutex_unlock(&rps->lock); |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 310 | if (boost) |
| 311 | schedule_work(&rps->work); |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 312 | |
| 313 | return count; |
| 314 | } |
| 315 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 316 | static ssize_t vlv_rpe_freq_mhz_show(struct device *kdev, |
| 317 | struct device_attribute *attr, char *buf) |
| 318 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 319 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 320 | struct intel_rps *rps = &dev_priv->gt.rps; |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 321 | |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 322 | return sysfs_emit(buf, "%d\n", intel_gpu_freq(rps, rps->efficient_freq)); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 323 | } |
| 324 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 325 | static ssize_t gt_max_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 326 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 327 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 328 | struct intel_gt *gt = &dev_priv->gt; |
| 329 | struct intel_rps *rps = >->rps; |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 330 | |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 331 | return sysfs_emit(buf, "%d\n", intel_rps_get_max_frequency(rps)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 334 | static ssize_t gt_max_freq_mhz_store(struct device *kdev, |
| 335 | struct device_attribute *attr, |
| 336 | const char *buf, size_t count) |
| 337 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 338 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 339 | struct intel_gt *gt = &dev_priv->gt; |
| 340 | struct intel_rps *rps = >->rps; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 341 | ssize_t ret; |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 342 | u32 val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 343 | |
| 344 | ret = kstrtou32(buf, 0, &val); |
| 345 | if (ret) |
| 346 | return ret; |
| 347 | |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 348 | ret = intel_rps_set_max_frequency(rps, val); |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 349 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 350 | return ret ?: count; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 353 | static ssize_t gt_min_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 354 | { |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 355 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
| 356 | struct intel_gt *gt = &i915->gt; |
| 357 | struct intel_rps *rps = >->rps; |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 358 | |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 359 | return sysfs_emit(buf, "%d\n", intel_rps_get_min_frequency(rps)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 362 | static ssize_t gt_min_freq_mhz_store(struct device *kdev, |
| 363 | struct device_attribute *attr, |
| 364 | const char *buf, size_t count) |
| 365 | { |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 366 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
| 367 | struct intel_rps *rps = &i915->gt.rps; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 368 | ssize_t ret; |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 369 | u32 val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 370 | |
| 371 | ret = kstrtou32(buf, 0, &val); |
| 372 | if (ret) |
| 373 | return ret; |
| 374 | |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 375 | ret = intel_rps_set_min_frequency(rps, val); |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 376 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 377 | return ret ?: count; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 380 | static DEVICE_ATTR_RO(gt_act_freq_mhz); |
| 381 | static DEVICE_ATTR_RO(gt_cur_freq_mhz); |
Joe Perches | b6b996b | 2017-12-19 10:15:07 -0800 | [diff] [blame] | 382 | static DEVICE_ATTR_RW(gt_boost_freq_mhz); |
| 383 | static DEVICE_ATTR_RW(gt_max_freq_mhz); |
| 384 | static DEVICE_ATTR_RW(gt_min_freq_mhz); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 385 | |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 386 | static DEVICE_ATTR_RO(vlv_rpe_freq_mhz); |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 387 | |
| 388 | static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf); |
| 389 | static DEVICE_ATTR(gt_RP0_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 390 | static DEVICE_ATTR(gt_RP1_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 391 | static DEVICE_ATTR(gt_RPn_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 392 | |
| 393 | /* For now we have a static number of RP states */ |
| 394 | static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 395 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 396 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Andi Shyti | 3e7abf8 | 2019-10-24 22:16:41 +0100 | [diff] [blame] | 397 | struct intel_rps *rps = &dev_priv->gt.rps; |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 398 | u32 val; |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 399 | |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 400 | if (attr == &dev_attr_gt_RP0_freq_mhz) |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 401 | val = intel_rps_get_rp0_frequency(rps); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 402 | else if (attr == &dev_attr_gt_RP1_freq_mhz) |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 403 | val = intel_rps_get_rp1_frequency(rps); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 404 | else if (attr == &dev_attr_gt_RPn_freq_mhz) |
Vinay Belgaumkar | 41e5c17 | 2021-07-30 13:21:17 -0700 | [diff] [blame] | 405 | val = intel_rps_get_rpn_frequency(rps); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 406 | else |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 407 | BUG(); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 408 | |
Xuezhi Zhang | 11cda49 | 2021-04-04 08:41:03 +0000 | [diff] [blame] | 409 | return sysfs_emit(buf, "%d\n", val); |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Jani Nikula | e1215de | 2018-10-04 17:37:50 +0300 | [diff] [blame] | 412 | static const struct attribute * const gen6_attrs[] = { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 413 | &dev_attr_gt_act_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 414 | &dev_attr_gt_cur_freq_mhz.attr, |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 415 | &dev_attr_gt_boost_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 416 | &dev_attr_gt_max_freq_mhz.attr, |
| 417 | &dev_attr_gt_min_freq_mhz.attr, |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 418 | &dev_attr_gt_RP0_freq_mhz.attr, |
| 419 | &dev_attr_gt_RP1_freq_mhz.attr, |
| 420 | &dev_attr_gt_RPn_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 421 | NULL, |
| 422 | }; |
| 423 | |
Jani Nikula | e1215de | 2018-10-04 17:37:50 +0300 | [diff] [blame] | 424 | static const struct attribute * const vlv_attrs[] = { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 425 | &dev_attr_gt_act_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 426 | &dev_attr_gt_cur_freq_mhz.attr, |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 427 | &dev_attr_gt_boost_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 428 | &dev_attr_gt_max_freq_mhz.attr, |
| 429 | &dev_attr_gt_min_freq_mhz.attr, |
Deepak S | 74c4f62 | 2014-07-10 13:16:22 +0530 | [diff] [blame] | 430 | &dev_attr_gt_RP0_freq_mhz.attr, |
| 431 | &dev_attr_gt_RP1_freq_mhz.attr, |
| 432 | &dev_attr_gt_RPn_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 433 | &dev_attr_vlv_rpe_freq_mhz.attr, |
| 434 | NULL, |
| 435 | }; |
| 436 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 437 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 438 | |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 439 | static ssize_t error_state_read(struct file *filp, struct kobject *kobj, |
| 440 | struct bin_attribute *attr, char *buf, |
| 441 | loff_t off, size_t count) |
| 442 | { |
| 443 | |
Geliang Tang | 657fb5f | 2016-01-13 22:48:40 +0800 | [diff] [blame] | 444 | struct device *kdev = kobj_to_dev(kobj); |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 445 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
Chris Wilson | 742379c | 2020-01-10 12:30:56 +0000 | [diff] [blame] | 446 | struct i915_gpu_coredump *gpu; |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 447 | ssize_t ret; |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 448 | |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 449 | gpu = i915_first_error_state(i915); |
Chris Wilson | e6154e4 | 2018-12-07 11:05:54 +0000 | [diff] [blame] | 450 | if (IS_ERR(gpu)) { |
| 451 | ret = PTR_ERR(gpu); |
| 452 | } else if (gpu) { |
Chris Wilson | 742379c | 2020-01-10 12:30:56 +0000 | [diff] [blame] | 453 | ret = i915_gpu_coredump_copy_to_buffer(gpu, buf, off, count); |
| 454 | i915_gpu_coredump_put(gpu); |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 455 | } else { |
| 456 | const char *str = "No error state collected\n"; |
| 457 | size_t len = strlen(str); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 458 | |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 459 | ret = min_t(size_t, count, len - off); |
| 460 | memcpy(buf, str + off, ret); |
| 461 | } |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 462 | |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 463 | return ret; |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static ssize_t error_state_write(struct file *file, struct kobject *kobj, |
| 467 | struct bin_attribute *attr, char *buf, |
| 468 | loff_t off, size_t count) |
| 469 | { |
Geliang Tang | 657fb5f | 2016-01-13 22:48:40 +0800 | [diff] [blame] | 470 | struct device *kdev = kobj_to_dev(kobj); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 471 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 472 | |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 473 | drm_dbg(&dev_priv->drm, "Resetting error state\n"); |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 474 | i915_reset_error_state(dev_priv); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 475 | |
| 476 | return count; |
| 477 | } |
| 478 | |
Bhumika Goyal | 59f3da1 | 2017-08-02 22:50:47 +0530 | [diff] [blame] | 479 | static const struct bin_attribute error_state_attr = { |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 480 | .attr.name = "error", |
| 481 | .attr.mode = S_IRUSR | S_IWUSR, |
| 482 | .size = 0, |
| 483 | .read = error_state_read, |
| 484 | .write = error_state_write, |
| 485 | }; |
| 486 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 487 | static void i915_setup_error_capture(struct device *kdev) |
| 488 | { |
| 489 | if (sysfs_create_bin_file(&kdev->kobj, &error_state_attr)) |
| 490 | DRM_ERROR("error_state sysfs setup failed\n"); |
| 491 | } |
| 492 | |
| 493 | static void i915_teardown_error_capture(struct device *kdev) |
| 494 | { |
| 495 | sysfs_remove_bin_file(&kdev->kobj, &error_state_attr); |
| 496 | } |
| 497 | #else |
| 498 | static void i915_setup_error_capture(struct device *kdev) {} |
| 499 | static void i915_teardown_error_capture(struct device *kdev) {} |
| 500 | #endif |
| 501 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 502 | void i915_setup_sysfs(struct drm_i915_private *dev_priv) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 503 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 504 | struct device *kdev = dev_priv->drm.primary->kdev; |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 505 | int ret; |
| 506 | |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 507 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 508 | if (HAS_RC6(dev_priv)) { |
| 509 | ret = sysfs_merge_group(&kdev->kobj, |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 510 | &rc6_attr_group); |
| 511 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 512 | drm_err(&dev_priv->drm, |
| 513 | "RC6 residency sysfs setup failed\n"); |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 514 | } |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 515 | if (HAS_RC6p(dev_priv)) { |
| 516 | ret = sysfs_merge_group(&kdev->kobj, |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 517 | &rc6p_attr_group); |
| 518 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 519 | drm_err(&dev_priv->drm, |
| 520 | "RC6p residency sysfs setup failed\n"); |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 521 | } |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 522 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 523 | ret = sysfs_merge_group(&kdev->kobj, |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 524 | &media_rc6_attr_group); |
| 525 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 526 | drm_err(&dev_priv->drm, |
| 527 | "Media RC6 residency sysfs setup failed\n"); |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 528 | } |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 529 | #endif |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 530 | if (HAS_L3_DPF(dev_priv)) { |
| 531 | ret = device_create_bin_file(kdev, &dpf_attrs); |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 532 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 533 | drm_err(&dev_priv->drm, |
| 534 | "l3 parity sysfs setup failed\n"); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 535 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 536 | if (NUM_L3_SLICES(dev_priv) > 1) { |
| 537 | ret = device_create_bin_file(kdev, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 538 | &dpf_attrs_1); |
| 539 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 540 | drm_err(&dev_priv->drm, |
| 541 | "l3 parity slice 1 setup failed\n"); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 542 | } |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 543 | } |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 544 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 545 | ret = 0; |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 546 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 547 | ret = sysfs_create_files(&kdev->kobj, vlv_attrs); |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 548 | else if (GRAPHICS_VER(dev_priv) >= 6) |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 549 | ret = sysfs_create_files(&kdev->kobj, gen6_attrs); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 550 | if (ret) |
Wambui Karuga | 00376cc | 2020-01-31 12:34:12 +0300 | [diff] [blame] | 551 | drm_err(&dev_priv->drm, "RPS sysfs setup failed\n"); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 552 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 553 | i915_setup_error_capture(kdev); |
Chris Wilson | 4ec76db | 2020-02-28 13:17:10 +0000 | [diff] [blame] | 554 | |
| 555 | intel_engines_add_sysfs(dev_priv); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 556 | } |
| 557 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 558 | void i915_teardown_sysfs(struct drm_i915_private *dev_priv) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 559 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 560 | struct device *kdev = dev_priv->drm.primary->kdev; |
| 561 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 562 | i915_teardown_error_capture(kdev); |
| 563 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 564 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 565 | sysfs_remove_files(&kdev->kobj, vlv_attrs); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 566 | else |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 567 | sysfs_remove_files(&kdev->kobj, gen6_attrs); |
| 568 | device_remove_bin_file(kdev, &dpf_attrs_1); |
| 569 | device_remove_bin_file(kdev, &dpf_attrs); |
Ben Widawsky | 853c70e | 2012-09-19 10:50:19 -0700 | [diff] [blame] | 570 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 571 | sysfs_unmerge_group(&kdev->kobj, &rc6_attr_group); |
| 572 | sysfs_unmerge_group(&kdev->kobj, &rc6p_attr_group); |
Ben Widawsky | 853c70e | 2012-09-19 10:50:19 -0700 | [diff] [blame] | 573 | #endif |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 574 | } |