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