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