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