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 | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 307 | bool boost = false; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 308 | ssize_t ret; |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 309 | u32 val; |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 310 | |
| 311 | ret = kstrtou32(buf, 0, &val); |
| 312 | if (ret) |
| 313 | return ret; |
| 314 | |
| 315 | /* Validate against (static) hardware limits */ |
| 316 | val = intel_freq_opcode(dev_priv, val); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 317 | if (val < rps->min_freq || val > rps->max_freq) |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 318 | return -EINVAL; |
| 319 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 320 | mutex_lock(&dev_priv->pcu_lock); |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 321 | if (val != rps->boost_freq) { |
| 322 | rps->boost_freq = val; |
| 323 | boost = atomic_read(&rps->num_waiters); |
| 324 | } |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 325 | mutex_unlock(&dev_priv->pcu_lock); |
Chris Wilson | 59cd31f | 2018-03-08 14:26:47 +0000 | [diff] [blame] | 326 | if (boost) |
| 327 | schedule_work(&rps->work); |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 328 | |
| 329 | return count; |
| 330 | } |
| 331 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 332 | static ssize_t vlv_rpe_freq_mhz_show(struct device *kdev, |
| 333 | struct device_attribute *attr, char *buf) |
| 334 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 335 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 336 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 337 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 338 | intel_gpu_freq(dev_priv, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 339 | dev_priv->gt_pm.rps.efficient_freq)); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 342 | static ssize_t gt_max_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 343 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 344 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 345 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 346 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 347 | intel_gpu_freq(dev_priv, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 348 | dev_priv->gt_pm.rps.max_freq_softlimit)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 351 | static ssize_t gt_max_freq_mhz_store(struct device *kdev, |
| 352 | struct device_attribute *attr, |
| 353 | const char *buf, size_t count) |
| 354 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 355 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 356 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 357 | u32 val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 358 | ssize_t ret; |
| 359 | |
| 360 | ret = kstrtou32(buf, 0, &val); |
| 361 | if (ret) |
| 362 | return ret; |
| 363 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 364 | intel_runtime_pm_get(dev_priv); |
| 365 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 366 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 367 | |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 368 | val = intel_freq_opcode(dev_priv, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 369 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 370 | if (val < rps->min_freq || |
| 371 | val > rps->max_freq || |
| 372 | val < rps->min_freq_softlimit) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 373 | mutex_unlock(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 374 | intel_runtime_pm_put(dev_priv); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 375 | return -EINVAL; |
| 376 | } |
| 377 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 378 | if (val > rps->rp0_freq) |
Ben Widawsky | 31c7738 | 2013-04-05 14:29:22 -0700 | [diff] [blame] | 379 | DRM_DEBUG("User requested overclocking to %d\n", |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 380 | intel_gpu_freq(dev_priv, val)); |
Ben Widawsky | 31c7738 | 2013-04-05 14:29:22 -0700 | [diff] [blame] | 381 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 382 | rps->max_freq_softlimit = val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 383 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 384 | val = clamp_t(int, rps->cur_freq, |
| 385 | rps->min_freq_softlimit, |
| 386 | rps->max_freq_softlimit); |
Ville Syrjälä | f745a80 | 2015-01-23 21:04:23 +0200 | [diff] [blame] | 387 | |
| 388 | /* We still need *_set_rps to process the new max_delay and |
| 389 | * update the interrupt limits and PMINTRMSK even though |
| 390 | * frequency request may be unchanged. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 391 | ret = intel_set_rps(dev_priv, val); |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 392 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 393 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 394 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 395 | intel_runtime_pm_put(dev_priv); |
| 396 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 397 | return ret ?: count; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 400 | static ssize_t gt_min_freq_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 401 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 402 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 403 | |
Chris Wilson | 62e1baa | 2016-07-13 09:10:36 +0100 | [diff] [blame] | 404 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 405 | intel_gpu_freq(dev_priv, |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 406 | dev_priv->gt_pm.rps.min_freq_softlimit)); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 409 | static ssize_t gt_min_freq_mhz_store(struct device *kdev, |
| 410 | struct device_attribute *attr, |
| 411 | const char *buf, size_t count) |
| 412 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 413 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 414 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Ben Widawsky | 2a5913a | 2014-03-19 18:31:13 -0700 | [diff] [blame] | 415 | u32 val; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 416 | ssize_t ret; |
| 417 | |
| 418 | ret = kstrtou32(buf, 0, &val); |
| 419 | if (ret) |
| 420 | return ret; |
| 421 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 422 | intel_runtime_pm_get(dev_priv); |
| 423 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 424 | mutex_lock(&dev_priv->pcu_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 425 | |
Ville Syrjälä | 7c59a9c1 | 2015-01-23 21:04:26 +0200 | [diff] [blame] | 426 | val = intel_freq_opcode(dev_priv, val); |
Jesse Barnes | 0a073b8 | 2013-04-17 15:54:58 -0700 | [diff] [blame] | 427 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 428 | if (val < rps->min_freq || |
| 429 | val > rps->max_freq || |
| 430 | val > rps->max_freq_softlimit) { |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 431 | mutex_unlock(&dev_priv->pcu_lock); |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 432 | intel_runtime_pm_put(dev_priv); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 433 | return -EINVAL; |
| 434 | } |
| 435 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 436 | rps->min_freq_softlimit = val; |
Chris Wilson | 6917c7b | 2013-11-06 13:56:26 -0200 | [diff] [blame] | 437 | |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 438 | val = clamp_t(int, rps->cur_freq, |
| 439 | rps->min_freq_softlimit, |
| 440 | rps->max_freq_softlimit); |
Ville Syrjälä | f745a80 | 2015-01-23 21:04:23 +0200 | [diff] [blame] | 441 | |
| 442 | /* We still need *_set_rps to process the new min_delay and |
| 443 | * update the interrupt limits and PMINTRMSK even though |
| 444 | * frequency request may be unchanged. */ |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 445 | ret = intel_set_rps(dev_priv, val); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 446 | |
Sagar Arun Kamble | 9f81750 | 2017-10-10 22:30:05 +0100 | [diff] [blame] | 447 | mutex_unlock(&dev_priv->pcu_lock); |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 448 | |
Sagar Arun Kamble | 933bfb4 | 2016-02-08 22:47:11 +0530 | [diff] [blame] | 449 | intel_runtime_pm_put(dev_priv); |
| 450 | |
Chris Wilson | 9fcee2f | 2017-01-26 10:19:19 +0000 | [diff] [blame] | 451 | return ret ?: count; |
Ben Widawsky | 46ddf19 | 2012-09-12 18:12:07 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 454 | static DEVICE_ATTR_RO(gt_act_freq_mhz); |
| 455 | static DEVICE_ATTR_RO(gt_cur_freq_mhz); |
Joe Perches | b6b996b | 2017-12-19 10:15:07 -0800 | [diff] [blame] | 456 | static DEVICE_ATTR_RW(gt_boost_freq_mhz); |
| 457 | static DEVICE_ATTR_RW(gt_max_freq_mhz); |
| 458 | static DEVICE_ATTR_RW(gt_min_freq_mhz); |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 459 | |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 460 | static DEVICE_ATTR_RO(vlv_rpe_freq_mhz); |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 461 | |
| 462 | static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf); |
| 463 | static DEVICE_ATTR(gt_RP0_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 464 | static DEVICE_ATTR(gt_RP1_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 465 | static DEVICE_ATTR(gt_RPn_freq_mhz, S_IRUGO, gt_rp_mhz_show, NULL); |
| 466 | |
| 467 | /* For now we have a static number of RP states */ |
| 468 | static ssize_t gt_rp_mhz_show(struct device *kdev, struct device_attribute *attr, char *buf) |
| 469 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 470 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 471 | struct intel_rps *rps = &dev_priv->gt_pm.rps; |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 472 | u32 val; |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 473 | |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 474 | if (attr == &dev_attr_gt_RP0_freq_mhz) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 475 | val = intel_gpu_freq(dev_priv, rps->rp0_freq); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 476 | else if (attr == &dev_attr_gt_RP1_freq_mhz) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 477 | val = intel_gpu_freq(dev_priv, rps->rp1_freq); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 478 | else if (attr == &dev_attr_gt_RPn_freq_mhz) |
Sagar Arun Kamble | 562d9ba | 2017-10-10 22:30:06 +0100 | [diff] [blame] | 479 | val = intel_gpu_freq(dev_priv, rps->min_freq); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 480 | else |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 481 | BUG(); |
Akash Goel | bc4d91f | 2015-02-26 16:09:47 +0530 | [diff] [blame] | 482 | |
Jani Nikula | 3e2a155 | 2013-02-14 10:42:11 +0200 | [diff] [blame] | 483 | return snprintf(buf, PAGE_SIZE, "%d\n", val); |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Jani Nikula | e1215de | 2018-10-04 17:37:50 +0300 | [diff] [blame] | 486 | static const struct attribute * const gen6_attrs[] = { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 487 | &dev_attr_gt_act_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 488 | &dev_attr_gt_cur_freq_mhz.attr, |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 489 | &dev_attr_gt_boost_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 490 | &dev_attr_gt_max_freq_mhz.attr, |
| 491 | &dev_attr_gt_min_freq_mhz.attr, |
Ben Widawsky | ac6ae34 | 2012-09-07 19:43:44 -0700 | [diff] [blame] | 492 | &dev_attr_gt_RP0_freq_mhz.attr, |
| 493 | &dev_attr_gt_RP1_freq_mhz.attr, |
| 494 | &dev_attr_gt_RPn_freq_mhz.attr, |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 495 | NULL, |
| 496 | }; |
| 497 | |
Jani Nikula | e1215de | 2018-10-04 17:37:50 +0300 | [diff] [blame] | 498 | static const struct attribute * const vlv_attrs[] = { |
Ville Syrjälä | c8c972e | 2015-01-23 21:04:24 +0200 | [diff] [blame] | 499 | &dev_attr_gt_act_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 500 | &dev_attr_gt_cur_freq_mhz.attr, |
Chris Wilson | 29ecd78d | 2016-07-13 09:10:35 +0100 | [diff] [blame] | 501 | &dev_attr_gt_boost_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 502 | &dev_attr_gt_max_freq_mhz.attr, |
| 503 | &dev_attr_gt_min_freq_mhz.attr, |
Deepak S | 74c4f62 | 2014-07-10 13:16:22 +0530 | [diff] [blame] | 504 | &dev_attr_gt_RP0_freq_mhz.attr, |
| 505 | &dev_attr_gt_RP1_freq_mhz.attr, |
| 506 | &dev_attr_gt_RPn_freq_mhz.attr, |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 507 | &dev_attr_vlv_rpe_freq_mhz.attr, |
| 508 | NULL, |
| 509 | }; |
| 510 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 511 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 512 | |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 513 | static ssize_t error_state_read(struct file *filp, struct kobject *kobj, |
| 514 | struct bin_attribute *attr, char *buf, |
| 515 | loff_t off, size_t count) |
| 516 | { |
| 517 | |
Geliang Tang | 657fb5f | 2016-01-13 22:48:40 +0800 | [diff] [blame] | 518 | struct device *kdev = kobj_to_dev(kobj); |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 519 | struct drm_i915_private *i915 = kdev_minor_to_i915(kdev); |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 520 | struct i915_gpu_state *gpu; |
| 521 | ssize_t ret; |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 522 | |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 523 | gpu = i915_first_error_state(i915); |
Chris Wilson | e6154e4 | 2018-12-07 11:05:54 +0000 | [diff] [blame^] | 524 | if (IS_ERR(gpu)) { |
| 525 | ret = PTR_ERR(gpu); |
| 526 | } else if (gpu) { |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 527 | ret = i915_gpu_state_copy_to_buffer(gpu, buf, off, count); |
| 528 | i915_gpu_state_put(gpu); |
| 529 | } else { |
| 530 | const char *str = "No error state collected\n"; |
| 531 | size_t len = strlen(str); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 532 | |
Chris Wilson | 0e39037 | 2018-11-23 13:23:25 +0000 | [diff] [blame] | 533 | ret = min_t(size_t, count, len - off); |
| 534 | memcpy(buf, str + off, ret); |
| 535 | } |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 536 | |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 537 | return ret; |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static ssize_t error_state_write(struct file *file, struct kobject *kobj, |
| 541 | struct bin_attribute *attr, char *buf, |
| 542 | loff_t off, size_t count) |
| 543 | { |
Geliang Tang | 657fb5f | 2016-01-13 22:48:40 +0800 | [diff] [blame] | 544 | struct device *kdev = kobj_to_dev(kobj); |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 545 | struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 546 | |
| 547 | DRM_DEBUG_DRIVER("Resetting error state\n"); |
Chris Wilson | 5a4c6f1 | 2017-02-14 16:46:11 +0000 | [diff] [blame] | 548 | i915_reset_error_state(dev_priv); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 549 | |
| 550 | return count; |
| 551 | } |
| 552 | |
Bhumika Goyal | 59f3da1 | 2017-08-02 22:50:47 +0530 | [diff] [blame] | 553 | static const struct bin_attribute error_state_attr = { |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 554 | .attr.name = "error", |
| 555 | .attr.mode = S_IRUSR | S_IWUSR, |
| 556 | .size = 0, |
| 557 | .read = error_state_read, |
| 558 | .write = error_state_write, |
| 559 | }; |
| 560 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 561 | static void i915_setup_error_capture(struct device *kdev) |
| 562 | { |
| 563 | if (sysfs_create_bin_file(&kdev->kobj, &error_state_attr)) |
| 564 | DRM_ERROR("error_state sysfs setup failed\n"); |
| 565 | } |
| 566 | |
| 567 | static void i915_teardown_error_capture(struct device *kdev) |
| 568 | { |
| 569 | sysfs_remove_bin_file(&kdev->kobj, &error_state_attr); |
| 570 | } |
| 571 | #else |
| 572 | static void i915_setup_error_capture(struct device *kdev) {} |
| 573 | static void i915_teardown_error_capture(struct device *kdev) {} |
| 574 | #endif |
| 575 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 576 | void i915_setup_sysfs(struct drm_i915_private *dev_priv) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 577 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 578 | struct device *kdev = dev_priv->drm.primary->kdev; |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 579 | int ret; |
| 580 | |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 581 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 582 | if (HAS_RC6(dev_priv)) { |
| 583 | ret = sysfs_merge_group(&kdev->kobj, |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 584 | &rc6_attr_group); |
| 585 | if (ret) |
| 586 | DRM_ERROR("RC6 residency sysfs setup failed\n"); |
| 587 | } |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 588 | if (HAS_RC6p(dev_priv)) { |
| 589 | ret = sysfs_merge_group(&kdev->kobj, |
Rodrigo Vivi | 58abf1d | 2014-10-07 07:06:50 -0700 | [diff] [blame] | 590 | &rc6p_attr_group); |
| 591 | if (ret) |
| 592 | DRM_ERROR("RC6p residency sysfs setup failed\n"); |
| 593 | } |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 594 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
| 595 | ret = sysfs_merge_group(&kdev->kobj, |
Ville Syrjälä | 626ad6f | 2015-02-26 21:10:27 +0530 | [diff] [blame] | 596 | &media_rc6_attr_group); |
| 597 | if (ret) |
| 598 | DRM_ERROR("Media RC6 residency sysfs setup failed\n"); |
| 599 | } |
Ben Widawsky | 8c3f929 | 2012-09-02 00:24:40 -0700 | [diff] [blame] | 600 | #endif |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 601 | if (HAS_L3_DPF(dev_priv)) { |
| 602 | ret = device_create_bin_file(kdev, &dpf_attrs); |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 603 | if (ret) |
| 604 | DRM_ERROR("l3 parity sysfs setup failed\n"); |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 605 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 606 | if (NUM_L3_SLICES(dev_priv) > 1) { |
| 607 | ret = device_create_bin_file(kdev, |
Ben Widawsky | 35a85ac | 2013-09-19 11:13:41 -0700 | [diff] [blame] | 608 | &dpf_attrs_1); |
| 609 | if (ret) |
| 610 | DRM_ERROR("l3 parity slice 1 setup failed\n"); |
| 611 | } |
Daniel Vetter | 112abd2 | 2012-05-31 14:57:43 +0200 | [diff] [blame] | 612 | } |
Ben Widawsky | df6eedc | 2012-09-07 19:43:40 -0700 | [diff] [blame] | 613 | |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 614 | ret = 0; |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 615 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 616 | ret = sysfs_create_files(&kdev->kobj, vlv_attrs); |
| 617 | else if (INTEL_GEN(dev_priv) >= 6) |
| 618 | ret = sysfs_create_files(&kdev->kobj, gen6_attrs); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 619 | if (ret) |
| 620 | DRM_ERROR("RPS sysfs setup failed\n"); |
Mika Kuoppala | ef86ddc | 2013-06-06 17:38:54 +0300 | [diff] [blame] | 621 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 622 | i915_setup_error_capture(kdev); |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 623 | } |
| 624 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 625 | void i915_teardown_sysfs(struct drm_i915_private *dev_priv) |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 626 | { |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 627 | struct device *kdev = dev_priv->drm.primary->kdev; |
| 628 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 629 | i915_teardown_error_capture(kdev); |
| 630 | |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 631 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 632 | sysfs_remove_files(&kdev->kobj, vlv_attrs); |
Chris Wilson | 97e4eed | 2013-08-26 16:18:54 +0100 | [diff] [blame] | 633 | else |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 634 | sysfs_remove_files(&kdev->kobj, gen6_attrs); |
| 635 | device_remove_bin_file(kdev, &dpf_attrs_1); |
| 636 | device_remove_bin_file(kdev, &dpf_attrs); |
Ben Widawsky | 853c70e | 2012-09-19 10:50:19 -0700 | [diff] [blame] | 637 | #ifdef CONFIG_PM |
David Weinehall | 694c282 | 2016-08-22 13:32:43 +0300 | [diff] [blame] | 638 | sysfs_unmerge_group(&kdev->kobj, &rc6_attr_group); |
| 639 | sysfs_unmerge_group(&kdev->kobj, &rc6p_attr_group); |
Ben Widawsky | 853c70e | 2012-09-19 10:50:19 -0700 | [diff] [blame] | 640 | #endif |
Ben Widawsky | 0136db5 | 2012-04-10 21:17:01 -0700 | [diff] [blame] | 641 | } |