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