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