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> |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 32 | #include "intel_drv.h" |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 33 | #include "i915_drv.h" |
| 34 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 35 | 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] | 36 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 37 | struct drm_minor *minor = dev_get_drvdata(kdev); |
| 38 | return to_i915(minor->dev); |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 39 | } |
Dave Airlie | 14c8d110 | 2013-10-11 14:45:30 +1000 | [diff] [blame] | 40 | |
Hunt Xu | 5ab3633 | 2012-07-01 03:45:07 +0000 | [diff] [blame] | 41 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 42 | static u32 calc_residency(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 43 | i915_reg_t reg) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 44 | { |
Mika Kuoppala | c5a0ad1 | 2017-03-15 17:43:00 +0200 | [diff] [blame] | 45 | return DIV_ROUND_CLOSEST_ULL(intel_rc6_residency_us(dev_priv, reg), |
| 46 | 1000); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static ssize_t |
Ben Widawsky | dbdfd8e | 2012-09-07 19:43:38 -0700 | [diff] [blame] | 50 | show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 51 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 52 | return snprintf(buf, PAGE_SIZE, "%x\n", intel_enable_rc6()); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static ssize_t |
Ben Widawsky | dbdfd8e | 2012-09-07 19:43:38 -0700 | [diff] [blame] | 56 | show_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 57 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 58 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 59 | u32 rc6_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6); |
Jani Nikula | 3e2a155 | 2013-02-14 10:42:11 +0200 | [diff] [blame] | 60 | return snprintf(buf, PAGE_SIZE, "%u\n", rc6_residency); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static ssize_t |
Ben Widawsky | dbdfd8e | 2012-09-07 19:43:38 -0700 | [diff] [blame] | 64 | show_rc6p_ms(struct device *kdev, struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 65 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 66 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 67 | u32 rc6p_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6p); |
Jani Nikula | 3e2a155 | 2013-02-14 10:42:11 +0200 | [diff] [blame] | 68 | return snprintf(buf, PAGE_SIZE, "%u\n", rc6p_residency); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static ssize_t |
Ben Widawsky | dbdfd8e | 2012-09-07 19:43:38 -0700 | [diff] [blame] | 72 | show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, char *buf) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 73 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 74 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 75 | u32 rc6pp_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6pp); |
Jani Nikula | 3e2a155 | 2013-02-14 10:42:11 +0200 | [diff] [blame] | 76 | return snprintf(buf, PAGE_SIZE, "%u\n", rc6pp_residency); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 79 | static ssize_t |
| 80 | show_media_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf) |
| 81 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 82 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 83 | u32 rc6_residency = calc_residency(dev_priv, VLV_GT_MEDIA_RC6); |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 84 | return snprintf(buf, PAGE_SIZE, "%u\n", rc6_residency); |
| 85 | } |
| 86 | |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 87 | static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL); |
| 88 | static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL); |
| 89 | static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL); |
| 90 | static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL); |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 91 | static DEVICE_ATTR(media_rc6_residency_ms, S_IRUGO, show_media_rc6_ms, NULL); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 92 | |
| 93 | static struct attribute *rc6_attrs[] = { |
| 94 | &dev_attr_rc6_enable.attr, |
| 95 | &dev_attr_rc6_residency_ms.attr, |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 96 | NULL |
| 97 | }; |
| 98 | |
| 99 | static struct attribute_group rc6_attr_group = { |
| 100 | .name = power_group_name, |
| 101 | .attrs = rc6_attrs |
| 102 | }; |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 103 | |
| 104 | static struct attribute *rc6p_attrs[] = { |
| 105 | &dev_attr_rc6p_residency_ms.attr, |
| 106 | &dev_attr_rc6pp_residency_ms.attr, |
| 107 | NULL |
| 108 | }; |
| 109 | |
| 110 | static struct attribute_group rc6p_attr_group = { |
| 111 | .name = power_group_name, |
| 112 | .attrs = rc6p_attrs |
| 113 | }; |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 114 | |
| 115 | static struct attribute *media_rc6_attrs[] = { |
| 116 | &dev_attr_media_rc6_residency_ms.attr, |
| 117 | NULL |
| 118 | }; |
| 119 | |
| 120 | static struct attribute_group media_rc6_attr_group = { |
| 121 | .name = power_group_name, |
| 122 | .attrs = media_rc6_attrs |
| 123 | }; |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 124 | #endif |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 125 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 126 | static int l3_access_valid(struct drm_i915_private *dev_priv, loff_t offset) |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 127 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 128 | if (!HAS_L3_DPF(dev_priv)) |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 129 | return -EPERM; |
| 130 | |
| 131 | if (offset % 4 != 0) |
| 132 | return -EINVAL; |
| 133 | |
| 134 | if (offset >= GEN7_L3LOG_SIZE) |
| 135 | return -ENXIO; |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static ssize_t |
| 141 | i915_l3_read(struct file *filp, struct kobject *kobj, |
| 142 | struct bin_attribute *attr, char *buf, |
| 143 | loff_t offset, size_t count) |
| 144 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 145 | struct device *kdev = kobj_to_dev(kobj); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 146 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 147 | struct drm_device *dev = &dev_priv->drm; |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 148 | int slice = (int)(uintptr_t)attr->private; |
Ben Widawsky | 3ccfd19 | 2013-09-18 19:03:18 -0700 | [diff] [blame] | 149 | int ret; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 150 | |
Ben Widawsky | 1c3dcd1 | 2013-09-12 22:28:28 -0700 | [diff] [blame] | 151 | count = round_down(count, 4); |
| 152 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 153 | ret = l3_access_valid(dev_priv, offset); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 154 | if (ret) |
| 155 | return ret; |
| 156 | |
Dan Carpenter | e5ad402 | 2013-09-20 14:20:18 +0300 | [diff] [blame] | 157 | count = min_t(size_t, GEN7_L3LOG_SIZE - offset, count); |
Ben Widawsky | 33618ea | 2013-09-12 22:28:29 -0700 | [diff] [blame] | 158 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 159 | ret = i915_mutex_lock_interruptible(dev); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 160 | if (ret) |
| 161 | return ret; |
| 162 | |
Ben Widawsky | 3ccfd19 | 2013-09-18 19:03:18 -0700 | [diff] [blame] | 163 | if (dev_priv->l3_parity.remap_info[slice]) |
| 164 | memcpy(buf, |
| 165 | dev_priv->l3_parity.remap_info[slice] + (offset/4), |
| 166 | count); |
| 167 | else |
| 168 | memset(buf, 0, count); |
Ben Widawsky | 1c966dd | 2013-09-17 21:12:42 -0700 | [diff] [blame] | 169 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 170 | mutex_unlock(&dev->struct_mutex); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 171 | |
Ben Widawsky | 1c966dd | 2013-09-17 21:12:42 -0700 | [diff] [blame] | 172 | return count; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static ssize_t |
| 176 | i915_l3_write(struct file *filp, struct kobject *kobj, |
| 177 | struct bin_attribute *attr, char *buf, |
| 178 | loff_t offset, size_t count) |
| 179 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 180 | struct device *kdev = kobj_to_dev(kobj); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 181 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
| 182 | struct drm_device *dev = &dev_priv->drm; |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 183 | struct i915_gem_context *ctx; |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 184 | int slice = (int)(uintptr_t)attr->private; |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame^] | 185 | u32 **remap_info; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 186 | int ret; |
| 187 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 188 | ret = l3_access_valid(dev_priv, offset); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 189 | if (ret) |
| 190 | return ret; |
| 191 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 192 | ret = i915_mutex_lock_interruptible(dev); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 193 | if (ret) |
| 194 | return ret; |
| 195 | |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame^] | 196 | remap_info = &dev_priv->l3_parity.remap_info[slice]; |
| 197 | if (!*remap_info) { |
| 198 | *remap_info = kzalloc(GEN7_L3LOG_SIZE, GFP_KERNEL); |
| 199 | if (!*remap_info) { |
| 200 | ret = -ENOMEM; |
| 201 | goto out; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 205 | /* TODO: Ideally we really want a GPU reset here to make sure errors |
| 206 | * aren't propagated. Since I cannot find a stable way to reset the GPU |
| 207 | * at this point it is left as a TODO. |
| 208 | */ |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame^] | 209 | memcpy(*remap_info + (offset/4), buf, count); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 210 | |
Ben Widawsky | 3ccfd19 | 2013-09-18 19:03:18 -0700 | [diff] [blame] | 211 | /* NB: We defer the remapping until we switch to the context */ |
| 212 | list_for_each_entry(ctx, &dev_priv->context_list, link) |
| 213 | ctx->remap_slice |= (1<<slice); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 214 | |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame^] | 215 | ret = count; |
| 216 | |
| 217 | out: |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 218 | mutex_unlock(&dev->struct_mutex); |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 219 | |
Joonas Lahtinen | cefcff8 | 2017-04-28 10:58:39 +0300 | [diff] [blame^] | 220 | return ret; |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static struct bin_attribute dpf_attrs = { |
| 224 | .attr = {.name = "l3_parity", .mode = (S_IRUSR | S_IWUSR)}, |
| 225 | .size = GEN7_L3LOG_SIZE, |
| 226 | .read = i915_l3_read, |
| 227 | .write = i915_l3_write, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 228 | .mmap = NULL, |
| 229 | .private = (void *)0 |
| 230 | }; |
| 231 | |
| 232 | static struct bin_attribute dpf_attrs_1 = { |
| 233 | .attr = {.name = "l3_parity_slice_1", .mode = (S_IRUSR | S_IWUSR)}, |
| 234 | .size = GEN7_L3LOG_SIZE, |
| 235 | .read = i915_l3_read, |
| 236 | .write = i915_l3_write, |
| 237 | .mmap = NULL, |
| 238 | .private = (void *)1 |
Ben Widawsky | 84bc758 | 2012-05-25 16:56:25 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 241 | static ssize_t gt_act_freq_mhz_show(struct device *kdev, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 242 | struct device_attribute *attr, char *buf) |
| 243 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 244 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 245 | int ret; |
| 246 | |
Imre Deak | d46c051 | 2014-04-14 20:24:27 +0300 | [diff] [blame] | 247 | intel_runtime_pm_get(dev_priv); |
| 248 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 249 | mutex_lock(&dev_priv->rps.hw_lock); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 250 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 177006a | 2013-05-02 10:48:07 -0700 | [diff] [blame] | 251 | u32 freq; |
Jani Nikula | 6493625 | 2013-05-22 15:36:20 +0300 | [diff] [blame] | 252 | freq = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS); |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 253 | ret = intel_gpu_freq(dev_priv, (freq >> 8) & 0xff); |
Jesse Barnes | 177006a | 2013-05-02 10:48:07 -0700 | [diff] [blame] | 254 | } else { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 255 | u32 rpstat = I915_READ(GEN6_RPSTAT1); |
Akash Goel | ed64d66 | 2015-03-06 11:07:22 +0530 | [diff] [blame] | 256 | if (IS_GEN9(dev_priv)) |
| 257 | ret = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT; |
| 258 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 259 | ret = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT; |
| 260 | else |
| 261 | ret = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT; |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 262 | ret = intel_gpu_freq(dev_priv, ret); |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 263 | } |
| 264 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 265 | |
| 266 | intel_runtime_pm_put(dev_priv); |
| 267 | |
| 268 | return snprintf(buf, PAGE_SIZE, "%d\n", ret); |
| 269 | } |
| 270 | |
| 271 | static ssize_t gt_cur_freq_mhz_show(struct device *kdev, |
| 272 | struct device_attribute *attr, char *buf) |
| 273 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 274 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 275 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 276 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 277 | intel_gpu_freq(dev_priv, |
| 278 | dev_priv->rps.cur_freq)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 281 | static ssize_t gt_boost_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 282 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 283 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 284 | |
| 285 | return snprintf(buf, PAGE_SIZE, "%d\n", |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 286 | intel_gpu_freq(dev_priv, |
| 287 | dev_priv->rps.boost_freq)); |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static ssize_t gt_boost_freq_mhz_store(struct device *kdev, |
| 291 | struct device_attribute *attr, |
| 292 | const char *buf, size_t count) |
| 293 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 294 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 295 | u32 val; |
| 296 | ssize_t ret; |
| 297 | |
| 298 | ret = kstrtou32(buf, 0, &val); |
| 299 | if (ret) |
| 300 | return ret; |
| 301 | |
| 302 | /* Validate against (static) hardware limits */ |
| 303 | val = intel_freq_opcode(dev_priv, val); |
| 304 | if (val < dev_priv->rps.min_freq || val > dev_priv->rps.max_freq) |
| 305 | return -EINVAL; |
| 306 | |
| 307 | mutex_lock(&dev_priv->rps.hw_lock); |
| 308 | dev_priv->rps.boost_freq = val; |
| 309 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 310 | |
| 311 | return count; |
| 312 | } |
| 313 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 314 | static ssize_t vlv_rpe_freq_mhz_show(struct device *kdev, |
| 315 | struct device_attribute *attr, char *buf) |
| 316 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 317 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 318 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 319 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 320 | intel_gpu_freq(dev_priv, |
| 321 | dev_priv->rps.efficient_freq)); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 322 | } |
| 323 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 324 | static ssize_t gt_max_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 325 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 326 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 327 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 328 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 329 | intel_gpu_freq(dev_priv, |
| 330 | dev_priv->rps.max_freq_softlimit)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 333 | static ssize_t gt_max_freq_mhz_store(struct device *kdev, |
| 334 | struct device_attribute *attr, |
| 335 | const char *buf, size_t count) |
| 336 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 337 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 338 | u32 val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 339 | ssize_t ret; |
| 340 | |
| 341 | ret = kstrtou32(buf, 0, &val); |
| 342 | if (ret) |
| 343 | return ret; |
| 344 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 345 | intel_runtime_pm_get(dev_priv); |
| 346 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 347 | mutex_lock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 348 | |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 349 | val = intel_freq_opcode(dev_priv, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 350 | |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 351 | if (val < dev_priv->rps.min_freq || |
| 352 | val > dev_priv->rps.max_freq || |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 353 | val < dev_priv->rps.min_freq_softlimit) { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 354 | mutex_unlock(&dev_priv->rps.hw_lock); |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 355 | intel_runtime_pm_put(dev_priv); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 356 | return -EINVAL; |
| 357 | } |
| 358 | |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 359 | if (val > dev_priv->rps.rp0_freq) |
Ben Widawsky | 31c7738 | 2013-04-05 14:29:22 -0700 | [diff] [blame] | 360 | DRM_DEBUG("User requested overclocking to %d\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 361 | intel_gpu_freq(dev_priv, val)); |
Ben Widawsky | 31c7738 | 2013-04-05 14:29:22 -0700 | [diff] [blame] | 362 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 363 | dev_priv->rps.max_freq_softlimit = val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 364 | |
Ville Syrjälä | f745a80 | 2015-01-23 21:04:23 +0200 | [diff] [blame] | 365 | val = clamp_t(int, dev_priv->rps.cur_freq, |
| 366 | dev_priv->rps.min_freq_softlimit, |
| 367 | dev_priv->rps.max_freq_softlimit); |
| 368 | |
| 369 | /* We still need *_set_rps to process the new max_delay and |
| 370 | * update the interrupt limits and PMINTRMSK even though |
| 371 | * frequency request may be unchanged. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 372 | ret = intel_set_rps(dev_priv, val); |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 373 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 374 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 375 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 376 | intel_runtime_pm_put(dev_priv); |
| 377 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 378 | return ret ?: count; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 381 | static ssize_t gt_min_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 382 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 383 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 384 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 385 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 386 | intel_gpu_freq(dev_priv, |
| 387 | dev_priv->rps.min_freq_softlimit)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 390 | static ssize_t gt_min_freq_mhz_store(struct device *kdev, |
| 391 | struct device_attribute *attr, |
| 392 | const char *buf, size_t count) |
| 393 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 394 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 395 | u32 val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 396 | ssize_t ret; |
| 397 | |
| 398 | ret = kstrtou32(buf, 0, &val); |
| 399 | if (ret) |
| 400 | return ret; |
| 401 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 402 | intel_runtime_pm_get(dev_priv); |
| 403 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 404 | mutex_lock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 405 | |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 406 | val = intel_freq_opcode(dev_priv, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 407 | |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 408 | if (val < dev_priv->rps.min_freq || |
| 409 | val > dev_priv->rps.max_freq || |
| 410 | val > dev_priv->rps.max_freq_softlimit) { |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 411 | mutex_unlock(&dev_priv->rps.hw_lock); |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 412 | intel_runtime_pm_put(dev_priv); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 413 | return -EINVAL; |
| 414 | } |
| 415 | |
Ben Widawsky | b39fb29 | 2014-03-19 18:31:11 -0700 | [diff] [blame] | 416 | dev_priv->rps.min_freq_softlimit = val; |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 417 | |
Ville Syrjälä | f745a80 | 2015-01-23 21:04:23 +0200 | [diff] [blame] | 418 | val = clamp_t(int, dev_priv->rps.cur_freq, |
| 419 | dev_priv->rps.min_freq_softlimit, |
| 420 | dev_priv->rps.max_freq_softlimit); |
| 421 | |
| 422 | /* We still need *_set_rps to process the new min_delay and |
| 423 | * update the interrupt limits and PMINTRMSK even though |
| 424 | * frequency request may be unchanged. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 425 | ret = intel_set_rps(dev_priv, val); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 426 | |
Jesse Barnes | 4fc688c | 2012-11-02 11:14:01 -0700 | [diff] [blame] | 427 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 428 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 429 | intel_runtime_pm_put(dev_priv); |
| 430 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 431 | return ret ?: count; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 434 | static DEVICE_ATTR(gt_act_freq_mhz, S_IRUGO, gt_act_freq_mhz_show, NULL); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 435 | static DEVICE_ATTR(gt_cur_freq_mhz, S_IRUGO, gt_cur_freq_mhz_show, NULL); |
Mika Kuoppala | 73a7987 | 2016-12-14 14:26:20 +0200 | [diff] [blame] | 436 | static DEVICE_ATTR(gt_boost_freq_mhz, S_IRUGO | S_IWUSR, gt_boost_freq_mhz_show, gt_boost_freq_mhz_store); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 437 | static DEVICE_ATTR(gt_max_freq_mhz, S_IRUGO | S_IWUSR, gt_max_freq_mhz_show, gt_max_freq_mhz_store); |
| 438 | static DEVICE_ATTR(gt_min_freq_mhz, S_IRUGO | S_IWUSR, gt_min_freq_mhz_show, gt_min_freq_mhz_store); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 439 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 440 | static DEVICE_ATTR(vlv_rpe_freq_mhz, S_IRUGO, vlv_rpe_freq_mhz_show, NULL); |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 441 | |
| 442 | static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf); |
| 443 | static DEVICE_ATTR(gt_RP0_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 444 | static DEVICE_ATTR(gt_RP1_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 445 | static DEVICE_ATTR(gt_RPn_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 446 | |
| 447 | /* For now we have a static number of RP states */ |
| 448 | static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 449 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 450 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 451 | u32 val; |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 452 | |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 453 | if (attr == &dev_attr_gt_RP0_freq_mhz) |
| 454 | val = intel_gpu_freq(dev_priv, dev_priv->rps.rp0_freq); |
| 455 | else if (attr == &dev_attr_gt_RP1_freq_mhz) |
| 456 | val = intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq); |
| 457 | else if (attr == &dev_attr_gt_RPn_freq_mhz) |
| 458 | val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq); |
| 459 | else |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 460 | BUG(); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 461 | |
Jani Nikula | 3e2a155 | 2013-02-14 10:42:11 +0200 | [diff] [blame] | 462 | return snprintf(buf, PAGE_SIZE, "%d\n", val); |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 465 | static const struct attribute *gen6_attrs[] = { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 466 | &dev_attr_gt_act_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 467 | &dev_attr_gt_cur_freq_mhz.attr, |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 468 | &dev_attr_gt_boost_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 469 | &dev_attr_gt_max_freq_mhz.attr, |
| 470 | &dev_attr_gt_min_freq_mhz.attr, |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 471 | &dev_attr_gt_RP0_freq_mhz.attr, |
| 472 | &dev_attr_gt_RP1_freq_mhz.attr, |
| 473 | &dev_attr_gt_RPn_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 474 | NULL, |
| 475 | }; |
| 476 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 477 | static const struct attribute *vlv_attrs[] = { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 478 | &dev_attr_gt_act_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 479 | &dev_attr_gt_cur_freq_mhz.attr, |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 480 | &dev_attr_gt_boost_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 481 | &dev_attr_gt_max_freq_mhz.attr, |
| 482 | &dev_attr_gt_min_freq_mhz.attr, |
Deepak S | 74c4f62 | 2014-07-10 13:16:22 +0530 | [diff] [blame] | 483 | &dev_attr_gt_RP0_freq_mhz.attr, |
| 484 | &dev_attr_gt_RP1_freq_mhz.attr, |
| 485 | &dev_attr_gt_RPn_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 486 | &dev_attr_vlv_rpe_freq_mhz.attr, |
| 487 | NULL, |
| 488 | }; |
| 489 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 490 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 491 | |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 492 | static ssize_t error_state_read(struct file *filp, struct kobject *kobj, |
| 493 | struct bin_attribute *attr, char *buf, |
| 494 | loff_t off, size_t count) |
| 495 | { |
| 496 | |
Geliang Tang | 657fb5f | 2016-01-13 22:48:40 +0800 | [diff] [blame] | 497 | struct device *kdev = kobj_to_dev(kobj); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 498 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 499 | struct drm_i915_error_state_buf error_str; |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 500 | struct i915_gpu_state *gpu; |
| 501 | ssize_t ret; |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 502 | |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 503 | ret = i915_error_state_buf_init(&error_str, dev_priv, count, off); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 504 | if (ret) |
| 505 | return ret; |
| 506 | |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 507 | gpu = i915_first_error_state(dev_priv); |
| 508 | ret = i915_error_state_to_str(&error_str, gpu); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 509 | if (ret) |
| 510 | goto out; |
| 511 | |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 512 | ret = count < error_str.bytes ? count : error_str.bytes; |
| 513 | memcpy(buf, error_str.buf, ret); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 514 | |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 515 | out: |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 516 | i915_gpu_state_put(gpu); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 517 | i915_error_state_buf_release(&error_str); |
| 518 | |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 519 | return ret; |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static ssize_t error_state_write(struct file *file, struct kobject *kobj, |
| 523 | struct bin_attribute *attr, char *buf, |
| 524 | loff_t off, size_t count) |
| 525 | { |
Geliang Tang | 657fb5f | 2016-01-13 22:48:40 +0800 | [diff] [blame] | 526 | struct device *kdev = kobj_to_dev(kobj); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 527 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 528 | |
| 529 | DRM_DEBUG_DRIVER("Resetting error state\n"); |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 530 | i915_reset_error_state(dev_priv); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 531 | |
| 532 | return count; |
| 533 | } |
| 534 | |
| 535 | static struct bin_attribute error_state_attr = { |
| 536 | .attr.name = "error", |
| 537 | .attr.mode = S_IRUSR | S_IWUSR, |
| 538 | .size = 0, |
| 539 | .read = error_state_read, |
| 540 | .write = error_state_write, |
| 541 | }; |
| 542 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 543 | static void i915_setup_error_capture(struct device *kdev) |
| 544 | { |
| 545 | if (sysfs_create_bin_file(&kdev->kobj, &error_state_attr)) |
| 546 | DRM_ERROR("error_state sysfs setup failed\n"); |
| 547 | } |
| 548 | |
| 549 | static void i915_teardown_error_capture(struct device *kdev) |
| 550 | { |
| 551 | sysfs_remove_bin_file(&kdev->kobj, &error_state_attr); |
| 552 | } |
| 553 | #else |
| 554 | static void i915_setup_error_capture(struct device *kdev) {} |
| 555 | static void i915_teardown_error_capture(struct device *kdev) {} |
| 556 | #endif |
| 557 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 558 | void i915_setup_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; |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 561 | int ret; |
| 562 | |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 563 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 564 | if (HAS_RC6(dev_priv)) { |
| 565 | ret = sysfs_merge_group(&kdev->kobj, |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 566 | &rc6_attr_group); |
| 567 | if (ret) |
| 568 | DRM_ERROR("RC6 residency sysfs setup failed\n"); |
| 569 | } |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 570 | if (HAS_RC6p(dev_priv)) { |
| 571 | ret = sysfs_merge_group(&kdev->kobj, |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 572 | &rc6p_attr_group); |
| 573 | if (ret) |
| 574 | DRM_ERROR("RC6p residency sysfs setup failed\n"); |
| 575 | } |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 576 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 577 | ret = sysfs_merge_group(&kdev->kobj, |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 578 | &media_rc6_attr_group); |
| 579 | if (ret) |
| 580 | DRM_ERROR("Media RC6 residency sysfs setup failed\n"); |
| 581 | } |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 582 | #endif |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 583 | if (HAS_L3_DPF(dev_priv)) { |
| 584 | ret = device_create_bin_file(kdev, &dpf_attrs); |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 585 | if (ret) |
| 586 | DRM_ERROR("l3 parity sysfs setup failed\n"); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 587 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 588 | if (NUM_L3_SLICES(dev_priv) > 1) { |
| 589 | ret = device_create_bin_file(kdev, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 590 | &dpf_attrs_1); |
| 591 | if (ret) |
| 592 | DRM_ERROR("l3 parity slice 1 setup failed\n"); |
| 593 | } |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 594 | } |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 595 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 596 | ret = 0; |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 597 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 598 | ret = sysfs_create_files(&kdev->kobj, vlv_attrs); |
| 599 | else if (INTEL_GEN(dev_priv) >= 6) |
| 600 | ret = sysfs_create_files(&kdev->kobj, gen6_attrs); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 601 | if (ret) |
| 602 | DRM_ERROR("RPS sysfs setup failed\n"); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 603 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 604 | i915_setup_error_capture(kdev); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 605 | } |
| 606 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 607 | void i915_teardown_sysfs(struct drm_i915_private *dev_priv) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 608 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 609 | struct device *kdev = dev_priv->drm.primary->kdev; |
| 610 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 611 | i915_teardown_error_capture(kdev); |
| 612 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 613 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 614 | sysfs_remove_files(&kdev->kobj, vlv_attrs); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 615 | else |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 616 | sysfs_remove_files(&kdev->kobj, gen6_attrs); |
| 617 | device_remove_bin_file(kdev, &dpf_attrs_1); |
| 618 | device_remove_bin_file(kdev, &dpf_attrs); |
Ben Widawsky | 853c70e | 2012-09-19 10:50:19 -0700 | [diff] [blame] | 619 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 620 | sysfs_unmerge_group(&kdev->kobj, &rc6_attr_group); |
| 621 | sysfs_unmerge_group(&kdev->kobj, &rc6p_attr_group); |
Ben Widawsky | 853c70e | 2012-09-19 10:50:19 -0700 | [diff] [blame] | 622 | #endif |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 623 | } |