blob: 1dba2c451255716ed3462fecf6f6cb5666f4b88f [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 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 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
Chris Wilsonf3cd4742009-10-13 22:20:20 +010029#include <linux/debugfs.h>
Chris Wilsone637d2c2017-03-16 13:19:57 +000030#include <linux/sort.h>
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +010031#include <linux/sched/mm.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010032#include "intel_drv.h"
Sagar Arun Kamblea2695742017-11-16 19:02:41 +053033#include "intel_guc_submission.h"
Ben Gamari20172632009-02-17 20:08:50 -050034
David Weinehall36cdd012016-08-22 13:59:31 +030035static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
36{
37 return to_i915(node->minor->dev);
38}
39
Chris Wilson70d39fe2010-08-25 16:03:34 +010040static int i915_capabilities(struct seq_file *m, void *data)
41{
David Weinehall36cdd012016-08-22 13:59:31 +030042 struct drm_i915_private *dev_priv = node_to_i915(m->private);
43 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Michal Wajdeczkoa8c9b842017-12-19 11:43:44 +000044 struct drm_printer p = drm_seq_file_printer(m);
Chris Wilson70d39fe2010-08-25 16:03:34 +010045
David Weinehall36cdd012016-08-22 13:59:31 +030046 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020047 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030048 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Chris Wilson418e3cd2017-02-06 21:36:08 +000049
Michal Wajdeczkoa8c9b842017-12-19 11:43:44 +000050 intel_device_info_dump_flags(info, &p);
Michal Wajdeczko5fbbe8d2017-12-21 21:57:34 +000051 intel_device_info_dump_runtime(info, &p);
Chris Wilson3fed1802018-02-07 21:05:43 +000052 intel_driver_caps_print(&dev_priv->caps, &p);
Chris Wilson70d39fe2010-08-25 16:03:34 +010053
Chris Wilson418e3cd2017-02-06 21:36:08 +000054 kernel_param_lock(THIS_MODULE);
Michal Wajdeczkoacfb9972017-12-19 11:43:46 +000055 i915_params_dump(&i915_modparams, &p);
Chris Wilson418e3cd2017-02-06 21:36:08 +000056 kernel_param_unlock(THIS_MODULE);
57
Chris Wilson70d39fe2010-08-25 16:03:34 +010058 return 0;
59}
Ben Gamari433e12f2009-02-17 20:08:51 -050060
Imre Deaka7363de2016-05-12 16:18:52 +030061static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000062{
Chris Wilson573adb32016-08-04 16:32:39 +010063 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000064}
65
Imre Deaka7363de2016-05-12 16:18:52 +030066static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010067{
Chris Wilsonbd3d2252017-10-13 21:26:14 +010068 return obj->pin_global ? 'p' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010069}
70
Imre Deaka7363de2016-05-12 16:18:52 +030071static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000072{
Chris Wilson3e510a82016-08-05 10:14:23 +010073 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -040074 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010075 case I915_TILING_NONE: return ' ';
76 case I915_TILING_X: return 'X';
77 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -040078 }
Chris Wilsona6172a82009-02-11 14:26:38 +000079}
80
Imre Deaka7363de2016-05-12 16:18:52 +030081static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -070082{
Chris Wilsona65adaf2017-10-09 09:43:57 +010083 return obj->userfault_count ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010084}
85
Imre Deaka7363de2016-05-12 16:18:52 +030086static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010087{
Chris Wilsona4f5ea62016-10-28 13:58:35 +010088 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -070089}
90
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +010091static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
92{
93 u64 size = 0;
94 struct i915_vma *vma;
95
Chris Wilsone2189dd2017-12-07 21:14:07 +000096 for_each_ggtt_vma(vma, obj) {
97 if (drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +010098 size += vma->node.size;
99 }
100
101 return size;
102}
103
Matthew Auld7393b7e2017-10-06 23:18:28 +0100104static const char *
105stringify_page_sizes(unsigned int page_sizes, char *buf, size_t len)
106{
107 size_t x = 0;
108
109 switch (page_sizes) {
110 case 0:
111 return "";
112 case I915_GTT_PAGE_SIZE_4K:
113 return "4K";
114 case I915_GTT_PAGE_SIZE_64K:
115 return "64K";
116 case I915_GTT_PAGE_SIZE_2M:
117 return "2M";
118 default:
119 if (!buf)
120 return "M";
121
122 if (page_sizes & I915_GTT_PAGE_SIZE_2M)
123 x += snprintf(buf + x, len - x, "2M, ");
124 if (page_sizes & I915_GTT_PAGE_SIZE_64K)
125 x += snprintf(buf + x, len - x, "64K, ");
126 if (page_sizes & I915_GTT_PAGE_SIZE_4K)
127 x += snprintf(buf + x, len - x, "4K, ");
128 buf[x-2] = '\0';
129
130 return buf;
131 }
132}
133
Chris Wilson37811fc2010-08-25 22:45:57 +0100134static void
135describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
136{
Chris Wilsonb4716182015-04-27 13:41:17 +0100137 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000138 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700139 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100140 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800141 int pin_count = 0;
142
Chris Wilson188c1ab2016-04-03 14:14:20 +0100143 lockdep_assert_held(&obj->base.dev->struct_mutex);
144
Chris Wilsond07f0e52016-10-28 13:58:44 +0100145 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100147 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100148 get_pin_flag(obj),
149 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700150 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100151 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800152 obj->base.size / 1024,
Christian Königc0a51fd2018-02-16 13:43:38 +0100153 obj->read_domains,
154 obj->write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300155 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100156 obj->mm.dirty ? " dirty" : "",
157 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100158 if (obj->base.name)
159 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000160 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100161 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800162 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300163 }
164 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsonbd3d2252017-10-13 21:26:14 +0100165 if (obj->pin_global)
166 seq_printf(m, " (global)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000167 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100168 if (!drm_mm_node_allocated(&vma->node))
169 continue;
170
Matthew Auld7393b7e2017-10-06 23:18:28 +0100171 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx, pages: %s",
Chris Wilson3272db52016-08-04 16:32:32 +0100172 i915_vma_is_ggtt(vma) ? "g" : "pp",
Matthew Auld7393b7e2017-10-06 23:18:28 +0100173 vma->node.start, vma->node.size,
174 stringify_page_sizes(vma->page_sizes.gtt, NULL, 0));
Chris Wilson21976852017-01-12 11:21:08 +0000175 if (i915_vma_is_ggtt(vma)) {
176 switch (vma->ggtt_view.type) {
177 case I915_GGTT_VIEW_NORMAL:
178 seq_puts(m, ", normal");
179 break;
180
181 case I915_GGTT_VIEW_PARTIAL:
182 seq_printf(m, ", partial [%08llx+%x]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000183 vma->ggtt_view.partial.offset << PAGE_SHIFT,
184 vma->ggtt_view.partial.size << PAGE_SHIFT);
Chris Wilson21976852017-01-12 11:21:08 +0000185 break;
186
187 case I915_GGTT_VIEW_ROTATED:
188 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000189 vma->ggtt_view.rotated.plane[0].width,
190 vma->ggtt_view.rotated.plane[0].height,
191 vma->ggtt_view.rotated.plane[0].stride,
192 vma->ggtt_view.rotated.plane[0].offset,
193 vma->ggtt_view.rotated.plane[1].width,
194 vma->ggtt_view.rotated.plane[1].height,
195 vma->ggtt_view.rotated.plane[1].stride,
196 vma->ggtt_view.rotated.plane[1].offset);
Chris Wilson21976852017-01-12 11:21:08 +0000197 break;
198
199 default:
200 MISSING_CASE(vma->ggtt_view.type);
201 break;
202 }
203 }
Chris Wilson49ef5292016-08-18 17:17:00 +0100204 if (vma->fence)
205 seq_printf(m, " , fence: %d%s",
206 vma->fence->id,
207 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000208 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700209 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000210 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100211 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100212
Chris Wilsond07f0e52016-10-28 13:58:44 +0100213 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100214 if (engine)
215 seq_printf(m, " (%s)", engine->name);
216
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100217 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
218 if (frontbuffer_bits)
219 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100220}
221
Chris Wilsone637d2c2017-03-16 13:19:57 +0000222static int obj_rank_by_stolen(const void *A, const void *B)
Chris Wilson6d2b88852013-08-07 18:30:54 +0100223{
Chris Wilsone637d2c2017-03-16 13:19:57 +0000224 const struct drm_i915_gem_object *a =
225 *(const struct drm_i915_gem_object **)A;
226 const struct drm_i915_gem_object *b =
227 *(const struct drm_i915_gem_object **)B;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100228
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200229 if (a->stolen->start < b->stolen->start)
230 return -1;
231 if (a->stolen->start > b->stolen->start)
232 return 1;
233 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100234}
235
236static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
237{
David Weinehall36cdd012016-08-22 13:59:31 +0300238 struct drm_i915_private *dev_priv = node_to_i915(m->private);
239 struct drm_device *dev = &dev_priv->drm;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000240 struct drm_i915_gem_object **objects;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100241 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300242 u64 total_obj_size, total_gtt_size;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000243 unsigned long total, count, n;
244 int ret;
245
246 total = READ_ONCE(dev_priv->mm.object_count);
Michal Hocko20981052017-05-17 14:23:12 +0200247 objects = kvmalloc_array(total, sizeof(*objects), GFP_KERNEL);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000248 if (!objects)
249 return -ENOMEM;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100250
251 ret = mutex_lock_interruptible(&dev->struct_mutex);
252 if (ret)
Chris Wilsone637d2c2017-03-16 13:19:57 +0000253 goto out;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100254
255 total_obj_size = total_gtt_size = count = 0;
Chris Wilsonf2123812017-10-16 12:40:37 +0100256
257 spin_lock(&dev_priv->mm.obj_lock);
258 list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000259 if (count == total)
260 break;
261
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262 if (obj->stolen == NULL)
263 continue;
264
Chris Wilsone637d2c2017-03-16 13:19:57 +0000265 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100266 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100267 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000268
Chris Wilson6d2b88852013-08-07 18:30:54 +0100269 }
Chris Wilsonf2123812017-10-16 12:40:37 +0100270 list_for_each_entry(obj, &dev_priv->mm.unbound_list, mm.link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000271 if (count == total)
272 break;
273
Chris Wilson6d2b88852013-08-07 18:30:54 +0100274 if (obj->stolen == NULL)
275 continue;
276
Chris Wilsone637d2c2017-03-16 13:19:57 +0000277 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100278 total_obj_size += obj->base.size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100279 }
Chris Wilsonf2123812017-10-16 12:40:37 +0100280 spin_unlock(&dev_priv->mm.obj_lock);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100281
Chris Wilsone637d2c2017-03-16 13:19:57 +0000282 sort(objects, count, sizeof(*objects), obj_rank_by_stolen, NULL);
283
284 seq_puts(m, "Stolen:\n");
285 for (n = 0; n < count; n++) {
286 seq_puts(m, " ");
287 describe_obj(m, objects[n]);
288 seq_putc(m, '\n');
289 }
290 seq_printf(m, "Total %lu objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100291 count, total_obj_size, total_gtt_size);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000292
293 mutex_unlock(&dev->struct_mutex);
294out:
Michal Hocko20981052017-05-17 14:23:12 +0200295 kvfree(objects);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000296 return ret;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100297}
298
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100299struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000300 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300301 unsigned long count;
302 u64 total, unbound;
303 u64 global, shared;
304 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100305};
306
307static int per_file_stats(int id, void *ptr, void *data)
308{
309 struct drm_i915_gem_object *obj = ptr;
310 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000311 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100312
Chris Wilson0caf81b2017-06-17 12:57:44 +0100313 lockdep_assert_held(&obj->base.dev->struct_mutex);
314
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100315 stats->count++;
316 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100317 if (!obj->bind_count)
318 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000319 if (obj->base.name || obj->base.dma_buf)
320 stats->shared += obj->base.size;
321
Chris Wilson894eeec2016-08-04 07:52:20 +0100322 list_for_each_entry(vma, &obj->vma_list, obj_link) {
323 if (!drm_mm_node_allocated(&vma->node))
324 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000325
Chris Wilson3272db52016-08-04 16:32:32 +0100326 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100327 stats->global += vma->node.size;
328 } else {
329 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000330
Chris Wilson2bfa9962016-08-04 07:52:25 +0100331 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000332 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000333 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100334
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100335 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100336 stats->active += vma->node.size;
337 else
338 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100339 }
340
341 return 0;
342}
343
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100344#define print_file_stats(m, name, stats) do { \
345 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300346 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100347 name, \
348 stats.count, \
349 stats.total, \
350 stats.active, \
351 stats.inactive, \
352 stats.global, \
353 stats.shared, \
354 stats.unbound); \
355} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800356
357static void print_batch_pool_stats(struct seq_file *m,
358 struct drm_i915_private *dev_priv)
359{
360 struct drm_i915_gem_object *obj;
361 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000362 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530363 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000364 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800365
366 memset(&stats, 0, sizeof(stats));
367
Akash Goel3b3f1652016-10-13 22:44:48 +0530368 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000369 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100370 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000371 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100372 batch_pool_link)
373 per_file_stats(0, obj, &stats);
374 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100375 }
Brad Volkin493018d2014-12-11 12:13:08 -0800376
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100377 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800378}
379
Chris Wilson15da9562016-05-24 14:53:43 +0100380static int per_file_ctx_stats(int id, void *ptr, void *data)
381{
382 struct i915_gem_context *ctx = ptr;
383 int n;
384
385 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
386 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100387 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100388 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100389 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100390 }
391
392 return 0;
393}
394
395static void print_context_stats(struct seq_file *m,
396 struct drm_i915_private *dev_priv)
397{
David Weinehall36cdd012016-08-22 13:59:31 +0300398 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100399 struct file_stats stats;
400 struct drm_file *file;
401
402 memset(&stats, 0, sizeof(stats));
403
David Weinehall36cdd012016-08-22 13:59:31 +0300404 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100405 if (dev_priv->kernel_context)
406 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
407
David Weinehall36cdd012016-08-22 13:59:31 +0300408 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100409 struct drm_i915_file_private *fpriv = file->driver_priv;
410 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
411 }
David Weinehall36cdd012016-08-22 13:59:31 +0300412 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100413
414 print_file_stats(m, "[k]contexts", stats);
415}
416
David Weinehall36cdd012016-08-22 13:59:31 +0300417static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100418{
David Weinehall36cdd012016-08-22 13:59:31 +0300419 struct drm_i915_private *dev_priv = node_to_i915(m->private);
420 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300421 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100422 u32 count, mapped_count, purgeable_count, dpy_count, huge_count;
423 u64 size, mapped_size, purgeable_size, dpy_size, huge_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000424 struct drm_i915_gem_object *obj;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100425 unsigned int page_sizes = 0;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100426 struct drm_file *file;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100427 char buf[80];
Chris Wilson73aa8082010-09-30 11:46:12 +0100428 int ret;
429
430 ret = mutex_lock_interruptible(&dev->struct_mutex);
431 if (ret)
432 return ret;
433
Chris Wilson3ef7f222016-10-18 13:02:48 +0100434 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000435 dev_priv->mm.object_count,
436 dev_priv->mm.object_memory);
437
Chris Wilson1544c422016-08-15 13:18:16 +0100438 size = count = 0;
439 mapped_size = mapped_count = 0;
440 purgeable_size = purgeable_count = 0;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100441 huge_size = huge_count = 0;
Chris Wilsonf2123812017-10-16 12:40:37 +0100442
443 spin_lock(&dev_priv->mm.obj_lock);
444 list_for_each_entry(obj, &dev_priv->mm.unbound_list, mm.link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100445 size += obj->base.size;
446 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200447
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100448 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200449 purgeable_size += obj->base.size;
450 ++purgeable_count;
451 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100452
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100453 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100454 mapped_count++;
455 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100456 }
Matthew Auld7393b7e2017-10-06 23:18:28 +0100457
458 if (obj->mm.page_sizes.sg > I915_GTT_PAGE_SIZE) {
459 huge_count++;
460 huge_size += obj->base.size;
461 page_sizes |= obj->mm.page_sizes.sg;
462 }
Chris Wilson6299f992010-11-24 12:23:44 +0000463 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100464 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
465
466 size = count = dpy_size = dpy_count = 0;
Chris Wilsonf2123812017-10-16 12:40:37 +0100467 list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100468 size += obj->base.size;
469 ++count;
470
Chris Wilsonbd3d2252017-10-13 21:26:14 +0100471 if (obj->pin_global) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100472 dpy_size += obj->base.size;
473 ++dpy_count;
474 }
475
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100476 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100477 purgeable_size += obj->base.size;
478 ++purgeable_count;
479 }
480
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100481 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100482 mapped_count++;
483 mapped_size += obj->base.size;
484 }
Matthew Auld7393b7e2017-10-06 23:18:28 +0100485
486 if (obj->mm.page_sizes.sg > I915_GTT_PAGE_SIZE) {
487 huge_count++;
488 huge_size += obj->base.size;
489 page_sizes |= obj->mm.page_sizes.sg;
490 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100491 }
Chris Wilsonf2123812017-10-16 12:40:37 +0100492 spin_unlock(&dev_priv->mm.obj_lock);
493
Chris Wilson2bd160a2016-08-15 10:48:45 +0100494 seq_printf(m, "%u bound objects, %llu bytes\n",
495 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300496 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200497 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100498 seq_printf(m, "%u mapped objects, %llu bytes\n",
499 mapped_count, mapped_size);
Matthew Auld7393b7e2017-10-06 23:18:28 +0100500 seq_printf(m, "%u huge-paged objects (%s) %llu bytes\n",
501 huge_count,
502 stringify_page_sizes(page_sizes, buf, sizeof(buf)),
503 huge_size);
Chris Wilsonbd3d2252017-10-13 21:26:14 +0100504 seq_printf(m, "%u display objects (globally pinned), %llu bytes\n",
Chris Wilson2bd160a2016-08-15 10:48:45 +0100505 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000506
Matthew Auldb7128ef2017-12-11 15:18:22 +0000507 seq_printf(m, "%llu [%pa] gtt total\n",
508 ggtt->base.total, &ggtt->mappable_end);
Matthew Auld7393b7e2017-10-06 23:18:28 +0100509 seq_printf(m, "Supported page sizes: %s\n",
510 stringify_page_sizes(INTEL_INFO(dev_priv)->page_sizes,
511 buf, sizeof(buf)));
Chris Wilson73aa8082010-09-30 11:46:12 +0100512
Damien Lespiau267f0c92013-06-24 22:59:48 +0100513 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800514 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200515 mutex_unlock(&dev->struct_mutex);
516
517 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100518 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100519 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
520 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100521 struct drm_i915_file_private *file_priv = file->driver_priv;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000522 struct i915_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900523 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100524
Chris Wilson0caf81b2017-06-17 12:57:44 +0100525 mutex_lock(&dev->struct_mutex);
526
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100527 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000528 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100529 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100530 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100531 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900532 /*
533 * Although we have a valid reference on file->pid, that does
534 * not guarantee that the task_struct who called get_pid() is
535 * still alive (e.g. get_pid(current) => fork() => exit()).
536 * Therefore, we need to protect this ->comm access using RCU.
537 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100538 request = list_first_entry_or_null(&file_priv->mm.request_list,
Chris Wilsone61e0f52018-02-21 09:56:36 +0000539 struct i915_request,
Chris Wilsonc8659ef2017-03-02 12:25:25 +0000540 client_link);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900541 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100542 task = pid_task(request && request->ctx->pid ?
543 request->ctx->pid : file->pid,
544 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800545 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900546 rcu_read_unlock();
Chris Wilson0caf81b2017-06-17 12:57:44 +0100547
Chris Wilsonc84455b2016-08-15 10:49:08 +0100548 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100549 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200550 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100551
552 return 0;
553}
554
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100555static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000556{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100557 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300558 struct drm_i915_private *dev_priv = node_to_i915(node);
559 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonf2123812017-10-16 12:40:37 +0100560 struct drm_i915_gem_object **objects;
Chris Wilson08c18322011-01-10 00:00:24 +0000561 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300562 u64 total_obj_size, total_gtt_size;
Chris Wilsonf2123812017-10-16 12:40:37 +0100563 unsigned long nobject, n;
Chris Wilson08c18322011-01-10 00:00:24 +0000564 int count, ret;
565
Chris Wilsonf2123812017-10-16 12:40:37 +0100566 nobject = READ_ONCE(dev_priv->mm.object_count);
567 objects = kvmalloc_array(nobject, sizeof(*objects), GFP_KERNEL);
568 if (!objects)
569 return -ENOMEM;
570
Chris Wilson08c18322011-01-10 00:00:24 +0000571 ret = mutex_lock_interruptible(&dev->struct_mutex);
572 if (ret)
573 return ret;
574
Chris Wilsonf2123812017-10-16 12:40:37 +0100575 count = 0;
576 spin_lock(&dev_priv->mm.obj_lock);
577 list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
578 objects[count++] = obj;
579 if (count == nobject)
580 break;
581 }
582 spin_unlock(&dev_priv->mm.obj_lock);
583
584 total_obj_size = total_gtt_size = 0;
585 for (n = 0; n < count; n++) {
586 obj = objects[n];
587
Damien Lespiau267f0c92013-06-24 22:59:48 +0100588 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000589 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100590 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000591 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100592 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000593 }
594
595 mutex_unlock(&dev->struct_mutex);
596
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300597 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000598 count, total_obj_size, total_gtt_size);
Chris Wilsonf2123812017-10-16 12:40:37 +0100599 kvfree(objects);
Chris Wilson08c18322011-01-10 00:00:24 +0000600
601 return 0;
602}
603
Brad Volkin493018d2014-12-11 12:13:08 -0800604static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
605{
David Weinehall36cdd012016-08-22 13:59:31 +0300606 struct drm_i915_private *dev_priv = node_to_i915(m->private);
607 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800608 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000609 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530610 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100611 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000612 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800613
614 ret = mutex_lock_interruptible(&dev->struct_mutex);
615 if (ret)
616 return ret;
617
Akash Goel3b3f1652016-10-13 22:44:48 +0530618 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000619 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100620 int count;
621
622 count = 0;
623 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000624 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100625 batch_pool_link)
626 count++;
627 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000628 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100629
630 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000631 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100632 batch_pool_link) {
633 seq_puts(m, " ");
634 describe_obj(m, obj);
635 seq_putc(m, '\n');
636 }
637
638 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100639 }
Brad Volkin493018d2014-12-11 12:13:08 -0800640 }
641
Chris Wilson8d9d5742015-04-07 16:20:38 +0100642 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800643
644 mutex_unlock(&dev->struct_mutex);
645
646 return 0;
647}
648
Tvrtko Ursulin80d89352018-02-20 17:37:53 +0200649static void gen8_display_interrupt_info(struct seq_file *m)
650{
651 struct drm_i915_private *dev_priv = node_to_i915(m->private);
652 int pipe;
653
654 for_each_pipe(dev_priv, pipe) {
655 enum intel_display_power_domain power_domain;
656
657 power_domain = POWER_DOMAIN_PIPE(pipe);
658 if (!intel_display_power_get_if_enabled(dev_priv,
659 power_domain)) {
660 seq_printf(m, "Pipe %c power disabled\n",
661 pipe_name(pipe));
662 continue;
663 }
664 seq_printf(m, "Pipe %c IMR:\t%08x\n",
665 pipe_name(pipe),
666 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
667 seq_printf(m, "Pipe %c IIR:\t%08x\n",
668 pipe_name(pipe),
669 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
670 seq_printf(m, "Pipe %c IER:\t%08x\n",
671 pipe_name(pipe),
672 I915_READ(GEN8_DE_PIPE_IER(pipe)));
673
674 intel_display_power_put(dev_priv, power_domain);
675 }
676
677 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
678 I915_READ(GEN8_DE_PORT_IMR));
679 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
680 I915_READ(GEN8_DE_PORT_IIR));
681 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
682 I915_READ(GEN8_DE_PORT_IER));
683
684 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
685 I915_READ(GEN8_DE_MISC_IMR));
686 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
687 I915_READ(GEN8_DE_MISC_IIR));
688 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
689 I915_READ(GEN8_DE_MISC_IER));
690
691 seq_printf(m, "PCU interrupt mask:\t%08x\n",
692 I915_READ(GEN8_PCU_IMR));
693 seq_printf(m, "PCU interrupt identity:\t%08x\n",
694 I915_READ(GEN8_PCU_IIR));
695 seq_printf(m, "PCU interrupt enable:\t%08x\n",
696 I915_READ(GEN8_PCU_IER));
697}
698
Ben Gamari20172632009-02-17 20:08:50 -0500699static int i915_interrupt_info(struct seq_file *m, void *data)
700{
David Weinehall36cdd012016-08-22 13:59:31 +0300701 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000702 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530703 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100704 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100705
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200706 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500707
David Weinehall36cdd012016-08-22 13:59:31 +0300708 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300709 seq_printf(m, "Master Interrupt Control:\t%08x\n",
710 I915_READ(GEN8_MASTER_IRQ));
711
712 seq_printf(m, "Display IER:\t%08x\n",
713 I915_READ(VLV_IER));
714 seq_printf(m, "Display IIR:\t%08x\n",
715 I915_READ(VLV_IIR));
716 seq_printf(m, "Display IIR_RW:\t%08x\n",
717 I915_READ(VLV_IIR_RW));
718 seq_printf(m, "Display IMR:\t%08x\n",
719 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100720 for_each_pipe(dev_priv, pipe) {
721 enum intel_display_power_domain power_domain;
722
723 power_domain = POWER_DOMAIN_PIPE(pipe);
724 if (!intel_display_power_get_if_enabled(dev_priv,
725 power_domain)) {
726 seq_printf(m, "Pipe %c power disabled\n",
727 pipe_name(pipe));
728 continue;
729 }
730
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300731 seq_printf(m, "Pipe %c stat:\t%08x\n",
732 pipe_name(pipe),
733 I915_READ(PIPESTAT(pipe)));
734
Chris Wilson9c870d02016-10-24 13:42:15 +0100735 intel_display_power_put(dev_priv, power_domain);
736 }
737
738 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300739 seq_printf(m, "Port hotplug:\t%08x\n",
740 I915_READ(PORT_HOTPLUG_EN));
741 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
742 I915_READ(VLV_DPFLIPSTAT));
743 seq_printf(m, "DPINVGTT:\t%08x\n",
744 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100745 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300746
747 for (i = 0; i < 4; i++) {
748 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
749 i, I915_READ(GEN8_GT_IMR(i)));
750 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
751 i, I915_READ(GEN8_GT_IIR(i)));
752 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
753 i, I915_READ(GEN8_GT_IER(i)));
754 }
755
756 seq_printf(m, "PCU interrupt mask:\t%08x\n",
757 I915_READ(GEN8_PCU_IMR));
758 seq_printf(m, "PCU interrupt identity:\t%08x\n",
759 I915_READ(GEN8_PCU_IIR));
760 seq_printf(m, "PCU interrupt enable:\t%08x\n",
761 I915_READ(GEN8_PCU_IER));
Tvrtko Ursulin80d89352018-02-20 17:37:53 +0200762 } else if (INTEL_GEN(dev_priv) >= 11) {
763 seq_printf(m, "Master Interrupt Control: %08x\n",
764 I915_READ(GEN11_GFX_MSTR_IRQ));
765
766 seq_printf(m, "Render/Copy Intr Enable: %08x\n",
767 I915_READ(GEN11_RENDER_COPY_INTR_ENABLE));
768 seq_printf(m, "VCS/VECS Intr Enable: %08x\n",
769 I915_READ(GEN11_VCS_VECS_INTR_ENABLE));
770 seq_printf(m, "GUC/SG Intr Enable:\t %08x\n",
771 I915_READ(GEN11_GUC_SG_INTR_ENABLE));
772 seq_printf(m, "GPM/WGBOXPERF Intr Enable: %08x\n",
773 I915_READ(GEN11_GPM_WGBOXPERF_INTR_ENABLE));
774 seq_printf(m, "Crypto Intr Enable:\t %08x\n",
775 I915_READ(GEN11_CRYPTO_RSVD_INTR_ENABLE));
776 seq_printf(m, "GUnit/CSME Intr Enable:\t %08x\n",
777 I915_READ(GEN11_GUNIT_CSME_INTR_ENABLE));
778
779 seq_printf(m, "Display Interrupt Control:\t%08x\n",
780 I915_READ(GEN11_DISPLAY_INT_CTL));
781
782 gen8_display_interrupt_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +0300783 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700784 seq_printf(m, "Master Interrupt Control:\t%08x\n",
785 I915_READ(GEN8_MASTER_IRQ));
786
787 for (i = 0; i < 4; i++) {
788 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
789 i, I915_READ(GEN8_GT_IMR(i)));
790 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
791 i, I915_READ(GEN8_GT_IIR(i)));
792 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
793 i, I915_READ(GEN8_GT_IER(i)));
794 }
795
Tvrtko Ursulin80d89352018-02-20 17:37:53 +0200796 gen8_display_interrupt_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +0300797 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700798 seq_printf(m, "Display IER:\t%08x\n",
799 I915_READ(VLV_IER));
800 seq_printf(m, "Display IIR:\t%08x\n",
801 I915_READ(VLV_IIR));
802 seq_printf(m, "Display IIR_RW:\t%08x\n",
803 I915_READ(VLV_IIR_RW));
804 seq_printf(m, "Display IMR:\t%08x\n",
805 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000806 for_each_pipe(dev_priv, pipe) {
807 enum intel_display_power_domain power_domain;
808
809 power_domain = POWER_DOMAIN_PIPE(pipe);
810 if (!intel_display_power_get_if_enabled(dev_priv,
811 power_domain)) {
812 seq_printf(m, "Pipe %c power disabled\n",
813 pipe_name(pipe));
814 continue;
815 }
816
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700817 seq_printf(m, "Pipe %c stat:\t%08x\n",
818 pipe_name(pipe),
819 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000820 intel_display_power_put(dev_priv, power_domain);
821 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700822
823 seq_printf(m, "Master IER:\t%08x\n",
824 I915_READ(VLV_MASTER_IER));
825
826 seq_printf(m, "Render IER:\t%08x\n",
827 I915_READ(GTIER));
828 seq_printf(m, "Render IIR:\t%08x\n",
829 I915_READ(GTIIR));
830 seq_printf(m, "Render IMR:\t%08x\n",
831 I915_READ(GTIMR));
832
833 seq_printf(m, "PM IER:\t\t%08x\n",
834 I915_READ(GEN6_PMIER));
835 seq_printf(m, "PM IIR:\t\t%08x\n",
836 I915_READ(GEN6_PMIIR));
837 seq_printf(m, "PM IMR:\t\t%08x\n",
838 I915_READ(GEN6_PMIMR));
839
840 seq_printf(m, "Port hotplug:\t%08x\n",
841 I915_READ(PORT_HOTPLUG_EN));
842 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
843 I915_READ(VLV_DPFLIPSTAT));
844 seq_printf(m, "DPINVGTT:\t%08x\n",
845 I915_READ(DPINVGTT));
846
David Weinehall36cdd012016-08-22 13:59:31 +0300847 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800848 seq_printf(m, "Interrupt enable: %08x\n",
849 I915_READ(IER));
850 seq_printf(m, "Interrupt identity: %08x\n",
851 I915_READ(IIR));
852 seq_printf(m, "Interrupt mask: %08x\n",
853 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100854 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800855 seq_printf(m, "Pipe %c stat: %08x\n",
856 pipe_name(pipe),
857 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800858 } else {
859 seq_printf(m, "North Display Interrupt enable: %08x\n",
860 I915_READ(DEIER));
861 seq_printf(m, "North Display Interrupt identity: %08x\n",
862 I915_READ(DEIIR));
863 seq_printf(m, "North Display Interrupt mask: %08x\n",
864 I915_READ(DEIMR));
865 seq_printf(m, "South Display Interrupt enable: %08x\n",
866 I915_READ(SDEIER));
867 seq_printf(m, "South Display Interrupt identity: %08x\n",
868 I915_READ(SDEIIR));
869 seq_printf(m, "South Display Interrupt mask: %08x\n",
870 I915_READ(SDEIMR));
871 seq_printf(m, "Graphics Interrupt enable: %08x\n",
872 I915_READ(GTIER));
873 seq_printf(m, "Graphics Interrupt identity: %08x\n",
874 I915_READ(GTIIR));
875 seq_printf(m, "Graphics Interrupt mask: %08x\n",
876 I915_READ(GTIMR));
877 }
Tvrtko Ursulin80d89352018-02-20 17:37:53 +0200878
879 if (INTEL_GEN(dev_priv) >= 11) {
880 seq_printf(m, "RCS Intr Mask:\t %08x\n",
881 I915_READ(GEN11_RCS0_RSVD_INTR_MASK));
882 seq_printf(m, "BCS Intr Mask:\t %08x\n",
883 I915_READ(GEN11_BCS_RSVD_INTR_MASK));
884 seq_printf(m, "VCS0/VCS1 Intr Mask:\t %08x\n",
885 I915_READ(GEN11_VCS0_VCS1_INTR_MASK));
886 seq_printf(m, "VCS2/VCS3 Intr Mask:\t %08x\n",
887 I915_READ(GEN11_VCS2_VCS3_INTR_MASK));
888 seq_printf(m, "VECS0/VECS1 Intr Mask:\t %08x\n",
889 I915_READ(GEN11_VECS0_VECS1_INTR_MASK));
890 seq_printf(m, "GUC/SG Intr Mask:\t %08x\n",
891 I915_READ(GEN11_GUC_SG_INTR_MASK));
892 seq_printf(m, "GPM/WGBOXPERF Intr Mask: %08x\n",
893 I915_READ(GEN11_GPM_WGBOXPERF_INTR_MASK));
894 seq_printf(m, "Crypto Intr Mask:\t %08x\n",
895 I915_READ(GEN11_CRYPTO_RSVD_INTR_MASK));
896 seq_printf(m, "Gunit/CSME Intr Mask:\t %08x\n",
897 I915_READ(GEN11_GUNIT_CSME_INTR_MASK));
898
899 } else if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsond5acadf2017-12-09 10:44:18 +0000900 for_each_engine(engine, dev_priv, id) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100901 seq_printf(m,
902 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000903 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000904 }
Chris Wilson9862e602011-01-04 22:22:17 +0000905 }
Tvrtko Ursulin80d89352018-02-20 17:37:53 +0200906
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200907 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100908
Ben Gamari20172632009-02-17 20:08:50 -0500909 return 0;
910}
911
Chris Wilsona6172a82009-02-11 14:26:38 +0000912static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
913{
David Weinehall36cdd012016-08-22 13:59:31 +0300914 struct drm_i915_private *dev_priv = node_to_i915(m->private);
915 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100916 int i, ret;
917
918 ret = mutex_lock_interruptible(&dev->struct_mutex);
919 if (ret)
920 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000921
Chris Wilsona6172a82009-02-11 14:26:38 +0000922 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
923 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100924 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000925
Chris Wilson6c085a72012-08-20 11:40:46 +0200926 seq_printf(m, "Fence %d, pin count = %d, object = ",
927 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100928 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100929 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100930 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100931 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100932 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000933 }
934
Chris Wilson05394f32010-11-08 19:18:58 +0000935 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 return 0;
937}
938
Chris Wilson98a2f412016-10-12 10:05:18 +0100939#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000940static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
941 size_t count, loff_t *pos)
942{
943 struct i915_gpu_state *error = file->private_data;
944 struct drm_i915_error_state_buf str;
945 ssize_t ret;
946 loff_t tmp;
947
948 if (!error)
949 return 0;
950
951 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
952 if (ret)
953 return ret;
954
955 ret = i915_error_state_to_str(&str, error);
956 if (ret)
957 goto out;
958
959 tmp = 0;
960 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
961 if (ret < 0)
962 goto out;
963
964 *pos = str.start + ret;
965out:
966 i915_error_state_buf_release(&str);
967 return ret;
968}
969
970static int gpu_state_release(struct inode *inode, struct file *file)
971{
972 i915_gpu_state_put(file->private_data);
973 return 0;
974}
975
976static int i915_gpu_info_open(struct inode *inode, struct file *file)
977{
Chris Wilson090e5fe2017-03-28 14:14:07 +0100978 struct drm_i915_private *i915 = inode->i_private;
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000979 struct i915_gpu_state *gpu;
980
Chris Wilson090e5fe2017-03-28 14:14:07 +0100981 intel_runtime_pm_get(i915);
982 gpu = i915_capture_gpu_state(i915);
983 intel_runtime_pm_put(i915);
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000984 if (!gpu)
985 return -ENOMEM;
986
987 file->private_data = gpu;
988 return 0;
989}
990
991static const struct file_operations i915_gpu_info_fops = {
992 .owner = THIS_MODULE,
993 .open = i915_gpu_info_open,
994 .read = gpu_state_read,
995 .llseek = default_llseek,
996 .release = gpu_state_release,
997};
Chris Wilson98a2f412016-10-12 10:05:18 +0100998
Daniel Vetterd5442302012-04-27 15:17:40 +0200999static ssize_t
1000i915_error_state_write(struct file *filp,
1001 const char __user *ubuf,
1002 size_t cnt,
1003 loff_t *ppos)
1004{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001005 struct i915_gpu_state *error = filp->private_data;
1006
1007 if (!error)
1008 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001009
1010 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001011 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +02001012
1013 return cnt;
1014}
1015
1016static int i915_error_state_open(struct inode *inode, struct file *file)
1017{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001018 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001019 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001020}
1021
Daniel Vetterd5442302012-04-27 15:17:40 +02001022static const struct file_operations i915_error_state_fops = {
1023 .owner = THIS_MODULE,
1024 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001025 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001026 .write = i915_error_state_write,
1027 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001028 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001029};
Chris Wilson98a2f412016-10-12 10:05:18 +01001030#endif
1031
Kees Cook647416f2013-03-10 14:10:06 -07001032static int
Kees Cook647416f2013-03-10 14:10:06 -07001033i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001034{
David Weinehall36cdd012016-08-22 13:59:31 +03001035 struct drm_i915_private *dev_priv = data;
1036 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001037 int ret;
1038
Mika Kuoppala40633212012-12-04 15:12:00 +02001039 ret = mutex_lock_interruptible(&dev->struct_mutex);
1040 if (ret)
1041 return ret;
1042
Chris Wilson65c475c2018-01-02 15:12:31 +00001043 intel_runtime_pm_get(dev_priv);
Chris Wilson73cb9702016-10-28 13:58:46 +01001044 ret = i915_gem_set_global_seqno(dev, val);
Chris Wilson65c475c2018-01-02 15:12:31 +00001045 intel_runtime_pm_put(dev_priv);
1046
Mika Kuoppala40633212012-12-04 15:12:00 +02001047 mutex_unlock(&dev->struct_mutex);
1048
Kees Cook647416f2013-03-10 14:10:06 -07001049 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001050}
1051
Kees Cook647416f2013-03-10 14:10:06 -07001052DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001053 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001054 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001055
Deepak Sadb4bd12014-03-31 11:30:02 +05301056static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001057{
David Weinehall36cdd012016-08-22 13:59:31 +03001058 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001059 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001060 int ret = 0;
1061
1062 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001063
David Weinehall36cdd012016-08-22 13:59:31 +03001064 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001065 u16 rgvswctl = I915_READ16(MEMSWCTL);
1066 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1067
1068 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1069 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1070 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1071 MEMSTAT_VID_SHIFT);
1072 seq_printf(m, "Current P-state: %d\n",
1073 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001074 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001075 u32 rpmodectl, freq_sts;
Wayne Boyer666a4532015-12-09 12:29:35 -08001076
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001077 mutex_lock(&dev_priv->pcu_lock);
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001078
1079 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1080 seq_printf(m, "Video Turbo Mode: %s\n",
1081 yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
1082 seq_printf(m, "HW control enabled: %s\n",
1083 yesno(rpmodectl & GEN6_RP_ENABLE));
1084 seq_printf(m, "SW control enabled: %s\n",
1085 yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
1086 GEN6_RP_MEDIA_SW_MODE));
1087
Wayne Boyer666a4532015-12-09 12:29:35 -08001088 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1089 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1090 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1091
1092 seq_printf(m, "actual GPU freq: %d MHz\n",
1093 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1094
1095 seq_printf(m, "current GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001096 intel_gpu_freq(dev_priv, rps->cur_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001097
1098 seq_printf(m, "max GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001099 intel_gpu_freq(dev_priv, rps->max_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001100
1101 seq_printf(m, "min GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001102 intel_gpu_freq(dev_priv, rps->min_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001103
1104 seq_printf(m, "idle GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001105 intel_gpu_freq(dev_priv, rps->idle_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001106
1107 seq_printf(m,
1108 "efficient (RPe) frequency: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001109 intel_gpu_freq(dev_priv, rps->efficient_freq));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001110 mutex_unlock(&dev_priv->pcu_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001111 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001112 u32 rp_state_limits;
1113 u32 gt_perf_status;
1114 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001115 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001116 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001117 u32 rpupei, rpcurup, rpprevup;
1118 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001119 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001120 int max_freq;
1121
Bob Paauwe35040562015-06-25 14:54:07 -07001122 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001123 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001124 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1125 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1126 } else {
1127 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1128 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1129 }
1130
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001131 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001132 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001133
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001134 reqf = I915_READ(GEN6_RPNSWREQ);
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001135 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301136 reqf >>= 23;
1137 else {
1138 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001139 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301140 reqf >>= 24;
1141 else
1142 reqf >>= 25;
1143 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001144 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001145
Chris Wilson0d8f9492014-03-27 09:06:14 +00001146 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1147 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1148 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1149
Jesse Barnesccab5c82011-01-18 15:49:25 -08001150 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301151 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1152 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1153 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1154 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1155 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1156 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Tvrtko Ursulinc84b2702017-11-21 18:18:44 +00001157 cagf = intel_gpu_freq(dev_priv,
1158 intel_get_cagf(dev_priv, rpstat));
Jesse Barnesccab5c82011-01-18 15:49:25 -08001159
Mika Kuoppala59bad942015-01-16 11:34:40 +02001160 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001161
David Weinehall36cdd012016-08-22 13:59:31 +03001162 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001163 pm_ier = I915_READ(GEN6_PMIER);
1164 pm_imr = I915_READ(GEN6_PMIMR);
1165 pm_isr = I915_READ(GEN6_PMISR);
1166 pm_iir = I915_READ(GEN6_PMIIR);
1167 pm_mask = I915_READ(GEN6_PMINTRMSK);
1168 } else {
1169 pm_ier = I915_READ(GEN8_GT_IER(2));
1170 pm_imr = I915_READ(GEN8_GT_IMR(2));
1171 pm_isr = I915_READ(GEN8_GT_ISR(2));
1172 pm_iir = I915_READ(GEN8_GT_IIR(2));
1173 pm_mask = I915_READ(GEN6_PMINTRMSK);
1174 }
Sagar Arun Kamble960e5462017-10-10 22:29:59 +01001175 seq_printf(m, "Video Turbo Mode: %s\n",
1176 yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
1177 seq_printf(m, "HW control enabled: %s\n",
1178 yesno(rpmodectl & GEN6_RP_ENABLE));
1179 seq_printf(m, "SW control enabled: %s\n",
1180 yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
1181 GEN6_RP_MEDIA_SW_MODE));
Chris Wilson0d8f9492014-03-27 09:06:14 +00001182 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001183 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301184 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001185 rps->pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001186 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001187 seq_printf(m, "Render p-state ratio: %d\n",
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001188 (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001189 seq_printf(m, "Render p-state VID: %d\n",
1190 gt_perf_status & 0xff);
1191 seq_printf(m, "Render p-state limit: %d\n",
1192 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001193 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1194 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1195 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1196 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001197 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001198 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301199 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1200 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1201 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1202 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1203 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1204 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001205 seq_printf(m, "Up threshold: %d%%\n", rps->up_threshold);
Chris Wilsond86ed342015-04-27 13:41:19 +01001206
Akash Goeld6cda9c2016-04-23 00:05:46 +05301207 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1208 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1209 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1210 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1211 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1212 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001213 seq_printf(m, "Down threshold: %d%%\n", rps->down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001215 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001216 rp_state_cap >> 16) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001217 max_freq *= (IS_GEN9_BC(dev_priv) ||
1218 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001219 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001220 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001221
1222 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001223 max_freq *= (IS_GEN9_BC(dev_priv) ||
1224 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001226 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001227
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001228 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001229 rp_state_cap >> 0) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001230 max_freq *= (IS_GEN9_BC(dev_priv) ||
1231 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001232 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001233 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001234 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001235 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001236
Chris Wilsond86ed342015-04-27 13:41:19 +01001237 seq_printf(m, "Current freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001238 intel_gpu_freq(dev_priv, rps->cur_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001239 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001240 seq_printf(m, "Idle freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001241 intel_gpu_freq(dev_priv, rps->idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001242 seq_printf(m, "Min freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001243 intel_gpu_freq(dev_priv, rps->min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001244 seq_printf(m, "Boost freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001245 intel_gpu_freq(dev_priv, rps->boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001246 seq_printf(m, "Max freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001247 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001248 seq_printf(m,
1249 "efficient (RPe) frequency: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001250 intel_gpu_freq(dev_priv, rps->efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001251 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001252 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001253 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001254
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001255 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001256 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1257 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1258
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001259 intel_runtime_pm_put(dev_priv);
1260 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001261}
1262
Ben Widawskyd6369512016-09-20 16:54:32 +03001263static void i915_instdone_info(struct drm_i915_private *dev_priv,
1264 struct seq_file *m,
1265 struct intel_instdone *instdone)
1266{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001267 int slice;
1268 int subslice;
1269
Ben Widawskyd6369512016-09-20 16:54:32 +03001270 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1271 instdone->instdone);
1272
1273 if (INTEL_GEN(dev_priv) <= 3)
1274 return;
1275
1276 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1277 instdone->slice_common);
1278
1279 if (INTEL_GEN(dev_priv) <= 6)
1280 return;
1281
Ben Widawskyf9e61372016-09-20 16:54:33 +03001282 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1283 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1284 slice, subslice, instdone->sampler[slice][subslice]);
1285
1286 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1287 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1288 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001289}
1290
Chris Wilsonf6544492015-01-26 18:03:04 +02001291static int i915_hangcheck_info(struct seq_file *m, void *unused)
1292{
David Weinehall36cdd012016-08-22 13:59:31 +03001293 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001294 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001295 u64 acthd[I915_NUM_ENGINES];
1296 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001297 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001298 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001299
Chris Wilson8af29b02016-09-09 14:11:47 +01001300 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001301 seq_puts(m, "Wedged\n");
1302 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1303 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1304 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1305 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001306 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001307 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001308 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001309 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001310
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001311 if (!i915_modparams.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001312 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001313 return 0;
1314 }
1315
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001316 intel_runtime_pm_get(dev_priv);
1317
Akash Goel3b3f1652016-10-13 22:44:48 +05301318 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001319 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001320 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001321 }
1322
Akash Goel3b3f1652016-10-13 22:44:48 +05301323 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001324
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001325 intel_runtime_pm_put(dev_priv);
1326
Chris Wilson8352aea2017-03-03 09:00:56 +00001327 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1328 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001329 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1330 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001331 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1332 seq_puts(m, "Hangcheck active, work pending\n");
1333 else
1334 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001335
Chris Wilsonf73b5672017-03-02 15:03:56 +00001336 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1337
Akash Goel3b3f1652016-10-13 22:44:48 +05301338 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001339 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1340 struct rb_node *rb;
1341
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001342 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001343 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001344 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001345 intel_engine_last_submit(engine),
1346 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001347 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001348 yesno(intel_engine_has_waiter(engine)),
1349 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001350 &dev_priv->gpu_error.missed_irq_rings)),
1351 yesno(engine->hangcheck.stalled));
1352
Chris Wilson61d3dc72017-03-03 19:08:24 +00001353 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001354 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001355 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001356
1357 seq_printf(m, "\t%s [%d] waiting for %x\n",
1358 w->tsk->comm, w->tsk->pid, w->seqno);
1359 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001360 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001361
Chris Wilsonf6544492015-01-26 18:03:04 +02001362 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001363 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001364 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001365 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1366 hangcheck_action_to_str(engine->hangcheck.action),
1367 engine->hangcheck.action,
1368 jiffies_to_msecs(jiffies -
1369 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001370
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001371 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001372 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001373
Ben Widawskyd6369512016-09-20 16:54:32 +03001374 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001375
Ben Widawskyd6369512016-09-20 16:54:32 +03001376 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001377
Ben Widawskyd6369512016-09-20 16:54:32 +03001378 i915_instdone_info(dev_priv, m,
1379 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001380 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001381 }
1382
1383 return 0;
1384}
1385
Michel Thierry061d06a2017-06-20 10:57:49 +01001386static int i915_reset_info(struct seq_file *m, void *unused)
1387{
1388 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1389 struct i915_gpu_error *error = &dev_priv->gpu_error;
1390 struct intel_engine_cs *engine;
1391 enum intel_engine_id id;
1392
1393 seq_printf(m, "full gpu reset = %u\n", i915_reset_count(error));
1394
1395 for_each_engine(engine, dev_priv, id) {
1396 seq_printf(m, "%s = %u\n", engine->name,
1397 i915_reset_engine_count(error, engine));
1398 }
1399
1400 return 0;
1401}
1402
Ben Widawsky4d855292011-12-12 19:34:16 -08001403static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001404{
David Weinehall36cdd012016-08-22 13:59:31 +03001405 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001406 u32 rgvmodectl, rstdbyctl;
1407 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001408
Ben Widawsky616fdb52011-10-05 11:44:54 -07001409 rgvmodectl = I915_READ(MEMMODECTL);
1410 rstdbyctl = I915_READ(RSTDBYCTL);
1411 crstandvid = I915_READ16(CRSTANDVID);
1412
Jani Nikula742f4912015-09-03 11:16:09 +03001413 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001414 seq_printf(m, "Boost freq: %d\n",
1415 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1416 MEMMODE_BOOST_FREQ_SHIFT);
1417 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001418 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001419 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001420 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001421 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001422 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001423 seq_printf(m, "Starting frequency: P%d\n",
1424 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001425 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001426 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001427 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1428 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1429 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1430 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001431 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001432 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001433 switch (rstdbyctl & RSX_STATUS_MASK) {
1434 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001435 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001436 break;
1437 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001439 break;
1440 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001442 break;
1443 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 break;
1446 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001456
1457 return 0;
1458}
1459
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001460static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001461{
Chris Wilson233ebf52017-03-23 10:19:44 +00001462 struct drm_i915_private *i915 = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001463 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsond2dc94b2017-03-23 10:19:41 +00001464 unsigned int tmp;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001465
Chris Wilsond7a133d2017-09-07 14:44:41 +01001466 seq_printf(m, "user.bypass_count = %u\n",
1467 i915->uncore.user_forcewake.count);
1468
Chris Wilson233ebf52017-03-23 10:19:44 +00001469 for_each_fw_domain(fw_domain, i915, tmp)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001470 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001471 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilson233ebf52017-03-23 10:19:44 +00001472 READ_ONCE(fw_domain->wake_count));
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001473
1474 return 0;
1475}
1476
Mika Kuoppala13628772017-03-15 17:43:02 +02001477static void print_rc6_res(struct seq_file *m,
1478 const char *title,
1479 const i915_reg_t reg)
1480{
1481 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1482
1483 seq_printf(m, "%s %u (%llu us)\n",
1484 title, I915_READ(reg),
1485 intel_rc6_residency_us(dev_priv, reg));
1486}
1487
Deepak S669ab5a2014-01-10 15:18:26 +05301488static int vlv_drpc_info(struct seq_file *m)
1489{
David Weinehall36cdd012016-08-22 13:59:31 +03001490 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001491 u32 rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301492
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001493 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301494 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1495
Deepak S669ab5a2014-01-10 15:18:26 +05301496 seq_printf(m, "RC6 Enabled: %s\n",
1497 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1498 GEN6_RC_CTL_EI_MODE(1))));
1499 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001500 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301501 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001502 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301503
Mika Kuoppala13628772017-03-15 17:43:02 +02001504 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1505 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001506
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001507 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301508}
1509
Ben Widawsky4d855292011-12-12 19:34:16 -08001510static int gen6_drpc_info(struct seq_file *m)
1511{
David Weinehall36cdd012016-08-22 13:59:31 +03001512 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble960e5462017-10-10 22:29:59 +01001513 u32 gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301514 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001515
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001516 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001517 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001518
Ben Widawsky4d855292011-12-12 19:34:16 -08001519 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001520 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301521 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1522 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1523 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001524
Imre Deak51cc9ad2018-02-08 19:41:02 +02001525 if (INTEL_GEN(dev_priv) <= 7) {
1526 mutex_lock(&dev_priv->pcu_lock);
1527 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS,
1528 &rc6vids);
1529 mutex_unlock(&dev_priv->pcu_lock);
1530 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001531
Eric Anholtfff24e22012-01-23 16:14:05 -08001532 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001533 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1534 seq_printf(m, "RC6 Enabled: %s\n",
1535 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001536 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301537 seq_printf(m, "Render Well Gating Enabled: %s\n",
1538 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1539 seq_printf(m, "Media Well Gating Enabled: %s\n",
1540 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1541 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001542 seq_printf(m, "Deep RC6 Enabled: %s\n",
1543 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1544 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1545 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001546 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 switch (gt_core_status & GEN6_RCn_MASK) {
1548 case GEN6_RC0:
1549 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001550 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001551 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001552 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001553 break;
1554 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001555 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001556 break;
1557 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 break;
1560 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001561 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001562 break;
1563 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001564 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 break;
1566 }
1567
1568 seq_printf(m, "Core Power Down: %s\n",
1569 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001570 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301571 seq_printf(m, "Render Power Well: %s\n",
1572 (gen9_powergate_status &
1573 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1574 seq_printf(m, "Media Power Well: %s\n",
1575 (gen9_powergate_status &
1576 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1577 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001578
1579 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001580 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1581 GEN6_GT_GFX_RC6_LOCKED);
1582 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1583 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1584 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001585
Imre Deak51cc9ad2018-02-08 19:41:02 +02001586 if (INTEL_GEN(dev_priv) <= 7) {
1587 seq_printf(m, "RC6 voltage: %dmV\n",
1588 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1589 seq_printf(m, "RC6+ voltage: %dmV\n",
1590 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1591 seq_printf(m, "RC6++ voltage: %dmV\n",
1592 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
1593 }
1594
Akash Goelf2dd7572016-06-27 20:10:01 +05301595 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001596}
1597
1598static int i915_drpc_info(struct seq_file *m, void *unused)
1599{
David Weinehall36cdd012016-08-22 13:59:31 +03001600 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001601 int err;
1602
1603 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001604
David Weinehall36cdd012016-08-22 13:59:31 +03001605 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001606 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001607 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001608 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001609 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001610 err = ironlake_drpc_info(m);
1611
1612 intel_runtime_pm_put(dev_priv);
1613
1614 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001615}
1616
Daniel Vetter9a851782015-06-18 10:30:22 +02001617static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1618{
David Weinehall36cdd012016-08-22 13:59:31 +03001619 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001620
1621 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1622 dev_priv->fb_tracking.busy_bits);
1623
1624 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1625 dev_priv->fb_tracking.flip_bits);
1626
1627 return 0;
1628}
1629
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001630static int i915_fbc_status(struct seq_file *m, void *unused)
1631{
David Weinehall36cdd012016-08-22 13:59:31 +03001632 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson31388722017-12-20 20:58:48 +00001633 struct intel_fbc *fbc = &dev_priv->fbc;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001634
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00001635 if (!HAS_FBC(dev_priv))
1636 return -ENODEV;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001637
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001638 intel_runtime_pm_get(dev_priv);
Chris Wilson31388722017-12-20 20:58:48 +00001639 mutex_lock(&fbc->lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001640
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001641 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001642 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001643 else
Chris Wilson31388722017-12-20 20:58:48 +00001644 seq_printf(m, "FBC disabled: %s\n", fbc->no_fbc_reason);
1645
1646 if (fbc->work.scheduled)
Dhinakaran Pandiyan1b29b7c2018-02-02 21:12:55 -08001647 seq_printf(m, "FBC worker scheduled on vblank %llu, now %llu\n",
Chris Wilson31388722017-12-20 20:58:48 +00001648 fbc->work.scheduled_vblank,
1649 drm_crtc_vblank_count(&fbc->crtc->base));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650
Ville Syrjälä3fd5d1e2017-06-06 15:43:18 +03001651 if (intel_fbc_is_active(dev_priv)) {
1652 u32 mask;
1653
1654 if (INTEL_GEN(dev_priv) >= 8)
1655 mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
1656 else if (INTEL_GEN(dev_priv) >= 7)
1657 mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
1658 else if (INTEL_GEN(dev_priv) >= 5)
1659 mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
1660 else if (IS_G4X(dev_priv))
1661 mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
1662 else
1663 mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
1664 FBC_STAT_COMPRESSED);
1665
1666 seq_printf(m, "Compressing: %s\n", yesno(mask));
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001667 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001668
Chris Wilson31388722017-12-20 20:58:48 +00001669 mutex_unlock(&fbc->lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001670 intel_runtime_pm_put(dev_priv);
1671
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001672 return 0;
1673}
1674
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001675static int i915_fbc_false_color_get(void *data, u64 *val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001676{
David Weinehall36cdd012016-08-22 13:59:31 +03001677 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001678
David Weinehall36cdd012016-08-22 13:59:31 +03001679 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001680 return -ENODEV;
1681
Rodrigo Vivida46f932014-08-01 02:04:45 -07001682 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001683
1684 return 0;
1685}
1686
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001687static int i915_fbc_false_color_set(void *data, u64 val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001688{
David Weinehall36cdd012016-08-22 13:59:31 +03001689 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001690 u32 reg;
1691
David Weinehall36cdd012016-08-22 13:59:31 +03001692 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001693 return -ENODEV;
1694
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001695 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001696
1697 reg = I915_READ(ILK_DPFC_CONTROL);
1698 dev_priv->fbc.false_color = val;
1699
1700 I915_WRITE(ILK_DPFC_CONTROL, val ?
1701 (reg | FBC_CTL_FALSE_COLOR) :
1702 (reg & ~FBC_CTL_FALSE_COLOR));
1703
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001704 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001705 return 0;
1706}
1707
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001708DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
1709 i915_fbc_false_color_get, i915_fbc_false_color_set,
Rodrigo Vivida46f932014-08-01 02:04:45 -07001710 "%llu\n");
1711
Paulo Zanoni92d44622013-05-31 16:33:24 -03001712static int i915_ips_status(struct seq_file *m, void *unused)
1713{
David Weinehall36cdd012016-08-22 13:59:31 +03001714 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001715
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00001716 if (!HAS_IPS(dev_priv))
1717 return -ENODEV;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001719 intel_runtime_pm_get(dev_priv);
1720
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001721 seq_printf(m, "Enabled by kernel parameter: %s\n",
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001722 yesno(i915_modparams.enable_ips));
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001723
David Weinehall36cdd012016-08-22 13:59:31 +03001724 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001725 seq_puts(m, "Currently: unknown\n");
1726 } else {
1727 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1728 seq_puts(m, "Currently: enabled\n");
1729 else
1730 seq_puts(m, "Currently: disabled\n");
1731 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001732
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001733 intel_runtime_pm_put(dev_priv);
1734
Paulo Zanoni92d44622013-05-31 16:33:24 -03001735 return 0;
1736}
1737
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001738static int i915_sr_status(struct seq_file *m, void *unused)
1739{
David Weinehall36cdd012016-08-22 13:59:31 +03001740 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001741 bool sr_enabled = false;
1742
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001743 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001744 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001745
Chris Wilson7342a722017-03-09 14:20:49 +00001746 if (INTEL_GEN(dev_priv) >= 9)
1747 /* no global SR status; inspect per-plane WM */;
1748 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001749 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001750 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001751 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001752 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001753 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001754 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001755 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001756 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001757 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001758 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001759
Chris Wilson9c870d02016-10-24 13:42:15 +01001760 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001761 intel_runtime_pm_put(dev_priv);
1762
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001763 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001764
1765 return 0;
1766}
1767
Jesse Barnes7648fa92010-05-20 14:28:11 -07001768static int i915_emon_status(struct seq_file *m, void *unused)
1769{
David Weinehall36cdd012016-08-22 13:59:31 +03001770 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1771 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001772 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001773 int ret;
1774
David Weinehall36cdd012016-08-22 13:59:31 +03001775 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001776 return -ENODEV;
1777
Chris Wilsonde227ef2010-07-03 07:58:38 +01001778 ret = mutex_lock_interruptible(&dev->struct_mutex);
1779 if (ret)
1780 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001781
1782 temp = i915_mch_val(dev_priv);
1783 chipset = i915_chipset_val(dev_priv);
1784 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001785 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001786
1787 seq_printf(m, "GMCH temp: %ld\n", temp);
1788 seq_printf(m, "Chipset power: %ld\n", chipset);
1789 seq_printf(m, "GFX power: %ld\n", gfx);
1790 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1791
1792 return 0;
1793}
1794
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001795static int i915_ring_freq_table(struct seq_file *m, void *unused)
1796{
David Weinehall36cdd012016-08-22 13:59:31 +03001797 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001798 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelf936ec32015-06-29 14:50:22 +05301799 unsigned int max_gpu_freq, min_gpu_freq;
Chris Wilsond586b5f2018-03-08 14:26:48 +00001800 int gpu_freq, ia_freq;
1801 int ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001802
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00001803 if (!HAS_LLC(dev_priv))
1804 return -ENODEV;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001805
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001806 intel_runtime_pm_get(dev_priv);
1807
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001808 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001809 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001810 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001811
Chris Wilsond586b5f2018-03-08 14:26:48 +00001812 min_gpu_freq = rps->min_freq;
1813 max_gpu_freq = rps->max_freq;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001814 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301815 /* Convert GT frequency to 50 HZ units */
Chris Wilsond586b5f2018-03-08 14:26:48 +00001816 min_gpu_freq /= GEN9_FREQ_SCALER;
1817 max_gpu_freq /= GEN9_FREQ_SCALER;
Akash Goelf936ec32015-06-29 14:50:22 +05301818 }
1819
Damien Lespiau267f0c92013-06-24 22:59:48 +01001820 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001821
Akash Goelf936ec32015-06-29 14:50:22 +05301822 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001823 ia_freq = gpu_freq;
1824 sandybridge_pcode_read(dev_priv,
1825 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1826 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001827 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301828 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001829 (IS_GEN9_BC(dev_priv) ||
1830 IS_CANNONLAKE(dev_priv) ?
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001831 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001832 ((ia_freq >> 0) & 0xff) * 100,
1833 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001834 }
1835
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001836 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001837
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001838out:
1839 intel_runtime_pm_put(dev_priv);
1840 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001841}
1842
Chris Wilson44834a62010-08-19 16:09:23 +01001843static int i915_opregion(struct seq_file *m, void *unused)
1844{
David Weinehall36cdd012016-08-22 13:59:31 +03001845 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1846 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001847 struct intel_opregion *opregion = &dev_priv->opregion;
1848 int ret;
1849
1850 ret = mutex_lock_interruptible(&dev->struct_mutex);
1851 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001852 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001853
Jani Nikula2455a8e2015-12-14 12:50:53 +02001854 if (opregion->header)
1855 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001856
1857 mutex_unlock(&dev->struct_mutex);
1858
Daniel Vetter0d38f002012-04-21 22:49:10 +02001859out:
Chris Wilson44834a62010-08-19 16:09:23 +01001860 return 0;
1861}
1862
Jani Nikulaada8f952015-12-15 13:17:12 +02001863static int i915_vbt(struct seq_file *m, void *unused)
1864{
David Weinehall36cdd012016-08-22 13:59:31 +03001865 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001866
1867 if (opregion->vbt)
1868 seq_write(m, opregion->vbt, opregion->vbt_size);
1869
1870 return 0;
1871}
1872
Chris Wilson37811fc2010-08-25 22:45:57 +01001873static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1874{
David Weinehall36cdd012016-08-22 13:59:31 +03001875 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1876 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301877 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001878 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001879 int ret;
1880
1881 ret = mutex_lock_interruptible(&dev->struct_mutex);
1882 if (ret)
1883 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001884
Daniel Vetter06957262015-08-10 13:34:08 +02001885#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter346fb4e2017-07-06 15:00:20 +02001886 if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
David Weinehall36cdd012016-08-22 13:59:31 +03001887 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001888
Chris Wilson25bcce92016-07-02 15:36:00 +01001889 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1890 fbdev_fb->base.width,
1891 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001892 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001893 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001894 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001895 drm_framebuffer_read_refcount(&fbdev_fb->base));
1896 describe_obj(m, fbdev_fb->obj);
1897 seq_putc(m, '\n');
1898 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001899#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001900
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001901 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001902 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301903 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1904 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001905 continue;
1906
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001907 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001908 fb->base.width,
1909 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001910 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001911 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001912 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001913 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001914 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001915 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001916 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001917 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001918 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001919
1920 return 0;
1921}
1922
Chris Wilson7e37f882016-08-02 22:50:21 +01001923static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001924{
Chris Wilsonef5032a2018-03-07 13:42:24 +00001925 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, emit: %u)",
1926 ring->space, ring->head, ring->tail, ring->emit);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001927}
1928
Ben Widawskye76d3632011-03-19 18:14:29 -07001929static int i915_context_status(struct seq_file *m, void *unused)
1930{
David Weinehall36cdd012016-08-22 13:59:31 +03001931 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1932 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001933 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001934 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301935 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001936 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001937
Daniel Vetterf3d28872014-05-29 23:23:08 +02001938 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001939 if (ret)
1940 return ret;
1941
Chris Wilson829a0af2017-06-20 12:05:45 +01001942 list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001943 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001944 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001945 struct task_struct *task;
1946
Chris Wilsonc84455b2016-08-15 10:49:08 +01001947 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001948 if (task) {
1949 seq_printf(m, "(%s [%d]) ",
1950 task->comm, task->pid);
1951 put_task_struct(task);
1952 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001953 } else if (IS_ERR(ctx->file_priv)) {
1954 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001955 } else {
1956 seq_puts(m, "(kernel) ");
1957 }
1958
Chris Wilsonbca44d82016-05-24 14:53:41 +01001959 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1960 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001961
Akash Goel3b3f1652016-10-13 22:44:48 +05301962 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001963 struct intel_context *ce = &ctx->engine[engine->id];
1964
1965 seq_printf(m, "%s: ", engine->name);
Chris Wilsonbca44d82016-05-24 14:53:41 +01001966 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001967 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001968 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001969 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001970 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001971 }
1972
Ben Widawskya33afea2013-09-17 21:12:45 -07001973 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001974 }
1975
Daniel Vetterf3d28872014-05-29 23:23:08 +02001976 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001977
1978 return 0;
1979}
1980
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001981static const char *swizzle_string(unsigned swizzle)
1982{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001983 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001984 case I915_BIT_6_SWIZZLE_NONE:
1985 return "none";
1986 case I915_BIT_6_SWIZZLE_9:
1987 return "bit9";
1988 case I915_BIT_6_SWIZZLE_9_10:
1989 return "bit9/bit10";
1990 case I915_BIT_6_SWIZZLE_9_11:
1991 return "bit9/bit11";
1992 case I915_BIT_6_SWIZZLE_9_10_11:
1993 return "bit9/bit10/bit11";
1994 case I915_BIT_6_SWIZZLE_9_17:
1995 return "bit9/bit17";
1996 case I915_BIT_6_SWIZZLE_9_10_17:
1997 return "bit9/bit10/bit17";
1998 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001999 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002000 }
2001
2002 return "bug";
2003}
2004
2005static int i915_swizzle_info(struct seq_file *m, void *data)
2006{
David Weinehall36cdd012016-08-22 13:59:31 +03002007 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002008
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002009 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002010
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002011 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2012 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2013 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2014 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2015
David Weinehall36cdd012016-08-22 13:59:31 +03002016 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002017 seq_printf(m, "DDC = 0x%08x\n",
2018 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002019 seq_printf(m, "DDC2 = 0x%08x\n",
2020 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002021 seq_printf(m, "C0DRB3 = 0x%04x\n",
2022 I915_READ16(C0DRB3));
2023 seq_printf(m, "C1DRB3 = 0x%04x\n",
2024 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002025 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002026 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2027 I915_READ(MAD_DIMM_C0));
2028 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2029 I915_READ(MAD_DIMM_C1));
2030 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2031 I915_READ(MAD_DIMM_C2));
2032 seq_printf(m, "TILECTL = 0x%08x\n",
2033 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002034 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002035 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2036 I915_READ(GAMTARBMODE));
2037 else
2038 seq_printf(m, "ARB_MODE = 0x%08x\n",
2039 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002040 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2041 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002042 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002043
2044 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2045 seq_puts(m, "L-shaped memory detected\n");
2046
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002047 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002048
2049 return 0;
2050}
2051
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002052static int per_file_ctx(int id, void *ptr, void *data)
2053{
Chris Wilsone2efd132016-05-24 14:53:34 +01002054 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002055 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002056 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2057
2058 if (!ppgtt) {
2059 seq_printf(m, " no ppgtt for context %d\n",
2060 ctx->user_handle);
2061 return 0;
2062 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002063
Oscar Mateof83d6512014-05-22 14:13:38 +01002064 if (i915_gem_context_is_default(ctx))
2065 seq_puts(m, " default context:\n");
2066 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002067 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002068 ppgtt->debug_dump(ppgtt, m);
2069
2070 return 0;
2071}
2072
David Weinehall36cdd012016-08-22 13:59:31 +03002073static void gen8_ppgtt_info(struct seq_file *m,
2074 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002075{
Ben Widawsky77df6772013-11-02 21:07:30 -07002076 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302077 struct intel_engine_cs *engine;
2078 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002079 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002080
Ben Widawsky77df6772013-11-02 21:07:30 -07002081 if (!ppgtt)
2082 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002083
Akash Goel3b3f1652016-10-13 22:44:48 +05302084 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002085 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002086 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002087 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002088 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002089 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002090 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002091 }
2092 }
2093}
2094
David Weinehall36cdd012016-08-22 13:59:31 +03002095static void gen6_ppgtt_info(struct seq_file *m,
2096 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002097{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002098 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302099 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002100
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002101 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002102 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2103
Akash Goel3b3f1652016-10-13 22:44:48 +05302104 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002105 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002106 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002107 seq_printf(m, "GFX_MODE: 0x%08x\n",
2108 I915_READ(RING_MODE_GEN7(engine)));
2109 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2110 I915_READ(RING_PP_DIR_BASE(engine)));
2111 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2112 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2113 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2114 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002115 }
2116 if (dev_priv->mm.aliasing_ppgtt) {
2117 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2118
Damien Lespiau267f0c92013-06-24 22:59:48 +01002119 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002120 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002121
Ben Widawsky87d60b62013-12-06 14:11:29 -08002122 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002123 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002124
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002125 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002126}
2127
2128static int i915_ppgtt_info(struct seq_file *m, void *data)
2129{
David Weinehall36cdd012016-08-22 13:59:31 +03002130 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2131 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002132 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002133 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002134
Chris Wilson637ee292016-08-22 14:28:20 +01002135 mutex_lock(&dev->filelist_mutex);
2136 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002137 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002138 goto out_unlock;
2139
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002140 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002141
David Weinehall36cdd012016-08-22 13:59:31 +03002142 if (INTEL_GEN(dev_priv) >= 8)
2143 gen8_ppgtt_info(m, dev_priv);
2144 else if (INTEL_GEN(dev_priv) >= 6)
2145 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002146
Michel Thierryea91e402015-07-29 17:23:57 +01002147 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2148 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002149 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002150
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002151 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002152 if (!task) {
2153 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002154 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002155 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002156 seq_printf(m, "\nproc: %s\n", task->comm);
2157 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002158 idr_for_each(&file_priv->context_idr, per_file_ctx,
2159 (void *)(unsigned long)m);
2160 }
2161
Chris Wilson637ee292016-08-22 14:28:20 +01002162out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002163 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002164 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002165out_unlock:
2166 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002167 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002168}
2169
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002170static int count_irq_waiters(struct drm_i915_private *i915)
2171{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002172 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302173 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002174 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002175
Akash Goel3b3f1652016-10-13 22:44:48 +05302176 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002177 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002178
2179 return count;
2180}
2181
Chris Wilson7466c292016-08-15 09:49:33 +01002182static const char *rps_power_to_str(unsigned int power)
2183{
2184 static const char * const strings[] = {
2185 [LOW_POWER] = "low power",
2186 [BETWEEN] = "mixed",
2187 [HIGH_POWER] = "high power",
2188 };
2189
2190 if (power >= ARRAY_SIZE(strings) || !strings[power])
2191 return "unknown";
2192
2193 return strings[power];
2194}
2195
Chris Wilson1854d5c2015-04-07 16:20:32 +01002196static int i915_rps_boost_info(struct seq_file *m, void *data)
2197{
David Weinehall36cdd012016-08-22 13:59:31 +03002198 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2199 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002200 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002201 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002202
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002203 seq_printf(m, "RPS enabled? %d\n", rps->enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002204 seq_printf(m, "GPU busy? %s [%d requests]\n",
2205 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002206 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002207 seq_printf(m, "Boosts outstanding? %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002208 atomic_read(&rps->num_waiters));
Chris Wilson7466c292016-08-15 09:49:33 +01002209 seq_printf(m, "Frequency requested %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002210 intel_gpu_freq(dev_priv, rps->cur_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002211 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002212 intel_gpu_freq(dev_priv, rps->min_freq),
2213 intel_gpu_freq(dev_priv, rps->min_freq_softlimit),
2214 intel_gpu_freq(dev_priv, rps->max_freq_softlimit),
2215 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002216 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002217 intel_gpu_freq(dev_priv, rps->idle_freq),
2218 intel_gpu_freq(dev_priv, rps->efficient_freq),
2219 intel_gpu_freq(dev_priv, rps->boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002220
2221 mutex_lock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002222 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2223 struct drm_i915_file_private *file_priv = file->driver_priv;
2224 struct task_struct *task;
2225
2226 rcu_read_lock();
2227 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002228 seq_printf(m, "%s [%d]: %d boosts\n",
Chris Wilson1854d5c2015-04-07 16:20:32 +01002229 task ? task->comm : "<unknown>",
2230 task ? task->pid : -1,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002231 atomic_read(&file_priv->rps_client.boosts));
Chris Wilson1854d5c2015-04-07 16:20:32 +01002232 rcu_read_unlock();
2233 }
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002234 seq_printf(m, "Kernel (anonymous) boosts: %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002235 atomic_read(&rps->boosts));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002236 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002237
Chris Wilson7466c292016-08-15 09:49:33 +01002238 if (INTEL_GEN(dev_priv) >= 6 &&
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002239 rps->enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002240 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002241 u32 rpup, rpupei;
2242 u32 rpdown, rpdownei;
2243
2244 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2245 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2246 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2247 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2248 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2249 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2250
2251 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002252 rps_power_to_str(rps->power));
Chris Wilson7466c292016-08-15 09:49:33 +01002253 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002254 rpup && rpupei ? 100 * rpup / rpupei : 0,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002255 rps->up_threshold);
Chris Wilson7466c292016-08-15 09:49:33 +01002256 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002257 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002258 rps->down_threshold);
Chris Wilson7466c292016-08-15 09:49:33 +01002259 } else {
2260 seq_puts(m, "\nRPS Autotuning inactive\n");
2261 }
2262
Chris Wilson8d3afd72015-05-21 21:01:47 +01002263 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002264}
2265
Ben Widawsky63573eb2013-07-04 11:02:07 -07002266static int i915_llc(struct seq_file *m, void *data)
2267{
David Weinehall36cdd012016-08-22 13:59:31 +03002268 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002269 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002270
David Weinehall36cdd012016-08-22 13:59:31 +03002271 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002272 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2273 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002274
2275 return 0;
2276}
2277
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002278static int i915_huc_load_status_info(struct seq_file *m, void *data)
2279{
2280 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002281 struct drm_printer p;
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002282
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002283 if (!HAS_HUC(dev_priv))
2284 return -ENODEV;
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002285
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002286 p = drm_seq_file_printer(m);
2287 intel_uc_fw_dump(&dev_priv->huc.fw, &p);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002288
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302289 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002290 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302291 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002292
2293 return 0;
2294}
2295
Alex Daifdf5d352015-08-12 15:43:37 +01002296static int i915_guc_load_status_info(struct seq_file *m, void *data)
2297{
David Weinehall36cdd012016-08-22 13:59:31 +03002298 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002299 struct drm_printer p;
Alex Daifdf5d352015-08-12 15:43:37 +01002300 u32 tmp, i;
2301
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002302 if (!HAS_GUC(dev_priv))
2303 return -ENODEV;
Alex Daifdf5d352015-08-12 15:43:37 +01002304
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002305 p = drm_seq_file_printer(m);
2306 intel_uc_fw_dump(&dev_priv->guc.fw, &p);
Alex Daifdf5d352015-08-12 15:43:37 +01002307
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302308 intel_runtime_pm_get(dev_priv);
2309
Alex Daifdf5d352015-08-12 15:43:37 +01002310 tmp = I915_READ(GUC_STATUS);
2311
2312 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2313 seq_printf(m, "\tBootrom status = 0x%x\n",
2314 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2315 seq_printf(m, "\tuKernel status = 0x%x\n",
2316 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2317 seq_printf(m, "\tMIA Core status = 0x%x\n",
2318 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2319 seq_puts(m, "\nScratch registers:\n");
2320 for (i = 0; i < 16; i++)
2321 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2322
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302323 intel_runtime_pm_put(dev_priv);
2324
Alex Daifdf5d352015-08-12 15:43:37 +01002325 return 0;
2326}
2327
Michał Winiarski5e24e4a2018-03-19 10:53:44 +01002328static const char *
2329stringify_guc_log_type(enum guc_log_buffer_type type)
2330{
2331 switch (type) {
2332 case GUC_ISR_LOG_BUFFER:
2333 return "ISR";
2334 case GUC_DPC_LOG_BUFFER:
2335 return "DPC";
2336 case GUC_CRASH_DUMP_LOG_BUFFER:
2337 return "CRASH";
2338 default:
2339 MISSING_CASE(type);
2340 }
2341
2342 return "";
2343}
2344
Akash Goel5aa1ee42016-10-12 21:54:36 +05302345static void i915_guc_log_info(struct seq_file *m,
2346 struct drm_i915_private *dev_priv)
2347{
Michał Winiarski5e24e4a2018-03-19 10:53:44 +01002348 struct intel_guc_log *log = &dev_priv->guc.log;
2349 enum guc_log_buffer_type type;
2350
2351 if (!intel_guc_log_relay_enabled(log)) {
2352 seq_puts(m, "GuC log relay disabled\n");
2353 return;
2354 }
Akash Goel5aa1ee42016-10-12 21:54:36 +05302355
Michał Winiarskidb557992018-03-19 10:53:43 +01002356 seq_puts(m, "GuC logging stats:\n");
Akash Goel5aa1ee42016-10-12 21:54:36 +05302357
Michał Winiarski6a96be22018-03-19 10:53:42 +01002358 seq_printf(m, "\tRelay full count: %u\n",
Michał Winiarski5e24e4a2018-03-19 10:53:44 +01002359 log->relay.full_count);
2360
2361 for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) {
2362 seq_printf(m, "\t%s:\tflush count %10u, overflow count %10u\n",
2363 stringify_guc_log_type(type),
2364 log->stats[type].flush,
2365 log->stats[type].sampled_overflow);
2366 }
Akash Goel5aa1ee42016-10-12 21:54:36 +05302367}
2368
Dave Gordon8b417c22015-08-12 15:43:44 +01002369static void i915_guc_client_info(struct seq_file *m,
2370 struct drm_i915_private *dev_priv,
Sagar Arun Kamble5afc8b42017-11-16 19:02:40 +05302371 struct intel_guc_client *client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002372{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002373 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002374 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002375 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002376
Oscar Mateob09935a2017-03-22 10:39:53 -07002377 seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
2378 client->priority, client->stage_id, client->proc_desc_offset);
Michał Winiarski59db36c2017-09-14 12:51:23 +02002379 seq_printf(m, "\tDoorbell id %d, offset: 0x%lx\n",
2380 client->doorbell_id, client->doorbell_offset);
Dave Gordon8b417c22015-08-12 15:43:44 +01002381
Akash Goel3b3f1652016-10-13 22:44:48 +05302382 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002383 u64 submissions = client->submissions[id];
2384 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002385 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002386 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002387 }
2388 seq_printf(m, "\tTotal: %llu\n", tot);
2389}
2390
2391static int i915_guc_info(struct seq_file *m, void *data)
2392{
David Weinehall36cdd012016-08-22 13:59:31 +03002393 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002394 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002395
Michał Winiarskidb557992018-03-19 10:53:43 +01002396 if (!USES_GUC(dev_priv))
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002397 return -ENODEV;
2398
Michał Winiarskidb557992018-03-19 10:53:43 +01002399 i915_guc_log_info(m, dev_priv);
2400
2401 if (!USES_GUC_SUBMISSION(dev_priv))
2402 return 0;
2403
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002404 GEM_BUG_ON(!guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002405
Michał Winiarskidb557992018-03-19 10:53:43 +01002406 seq_printf(m, "\nDoorbell map:\n");
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002407 seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
Michał Winiarskidb557992018-03-19 10:53:43 +01002408 seq_printf(m, "Doorbell next cacheline: 0x%x\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002409
Chris Wilson334636c2016-11-29 12:10:20 +00002410 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2411 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Chris Wilsone78c9172018-02-07 21:05:42 +00002412 if (guc->preempt_client) {
2413 seq_printf(m, "\nGuC preempt client @ %p:\n",
2414 guc->preempt_client);
2415 i915_guc_client_info(m, dev_priv, guc->preempt_client);
2416 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002417
2418 /* Add more as required ... */
2419
2420 return 0;
2421}
2422
Oscar Mateoa8b93702017-05-10 15:04:51 +00002423static int i915_guc_stage_pool(struct seq_file *m, void *data)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002424{
David Weinehall36cdd012016-08-22 13:59:31 +03002425 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Oscar Mateoa8b93702017-05-10 15:04:51 +00002426 const struct intel_guc *guc = &dev_priv->guc;
2427 struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
Sagar Arun Kamble5afc8b42017-11-16 19:02:40 +05302428 struct intel_guc_client *client = guc->execbuf_client;
Oscar Mateoa8b93702017-05-10 15:04:51 +00002429 unsigned int tmp;
2430 int index;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002431
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002432 if (!USES_GUC_SUBMISSION(dev_priv))
2433 return -ENODEV;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002434
Oscar Mateoa8b93702017-05-10 15:04:51 +00002435 for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
2436 struct intel_engine_cs *engine;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002437
Oscar Mateoa8b93702017-05-10 15:04:51 +00002438 if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
2439 continue;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002440
Oscar Mateoa8b93702017-05-10 15:04:51 +00002441 seq_printf(m, "GuC stage descriptor %u:\n", index);
2442 seq_printf(m, "\tIndex: %u\n", desc->stage_id);
2443 seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
2444 seq_printf(m, "\tPriority: %d\n", desc->priority);
2445 seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
2446 seq_printf(m, "\tEngines used: 0x%x\n",
2447 desc->engines_used);
2448 seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
2449 desc->db_trigger_phy,
2450 desc->db_trigger_cpu,
2451 desc->db_trigger_uk);
2452 seq_printf(m, "\tProcess descriptor: 0x%x\n",
2453 desc->process_desc);
Colin Ian King9a094852017-05-16 10:22:35 +01002454 seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
Oscar Mateoa8b93702017-05-10 15:04:51 +00002455 desc->wq_addr, desc->wq_size);
2456 seq_putc(m, '\n');
2457
2458 for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
2459 u32 guc_engine_id = engine->guc_id;
2460 struct guc_execlist_context *lrc =
2461 &desc->lrc[guc_engine_id];
2462
2463 seq_printf(m, "\t%s LRC:\n", engine->name);
2464 seq_printf(m, "\t\tContext desc: 0x%x\n",
2465 lrc->context_desc);
2466 seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
2467 seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
2468 seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
2469 seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
2470 seq_putc(m, '\n');
2471 }
Alex Dai4c7e77f2015-08-12 15:43:40 +01002472 }
2473
Oscar Mateoa8b93702017-05-10 15:04:51 +00002474 return 0;
2475}
2476
Alex Dai4c7e77f2015-08-12 15:43:40 +01002477static int i915_guc_log_dump(struct seq_file *m, void *data)
2478{
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002479 struct drm_info_node *node = m->private;
2480 struct drm_i915_private *dev_priv = node_to_i915(node);
2481 bool dump_load_err = !!node->info_ent->data;
2482 struct drm_i915_gem_object *obj = NULL;
2483 u32 *log;
2484 int i = 0;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002485
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002486 if (!HAS_GUC(dev_priv))
2487 return -ENODEV;
2488
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002489 if (dump_load_err)
2490 obj = dev_priv->guc.load_err_log;
2491 else if (dev_priv->guc.log.vma)
2492 obj = dev_priv->guc.log.vma->obj;
2493
2494 if (!obj)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002495 return 0;
2496
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002497 log = i915_gem_object_pin_map(obj, I915_MAP_WC);
2498 if (IS_ERR(log)) {
2499 DRM_DEBUG("Failed to pin object\n");
2500 seq_puts(m, "(log data unaccessible)\n");
2501 return PTR_ERR(log);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002502 }
2503
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002504 for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
2505 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2506 *(log + i), *(log + i + 1),
2507 *(log + i + 2), *(log + i + 3));
2508
Alex Dai4c7e77f2015-08-12 15:43:40 +01002509 seq_putc(m, '\n');
2510
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002511 i915_gem_object_unpin_map(obj);
2512
Alex Dai4c7e77f2015-08-12 15:43:40 +01002513 return 0;
2514}
2515
Michał Winiarski4977a282018-03-19 10:53:40 +01002516static int i915_guc_log_level_get(void *data, u64 *val)
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302517{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002518 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302519
Michał Winiarski86aa8242018-03-08 16:46:53 +01002520 if (!USES_GUC(dev_priv))
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002521 return -ENODEV;
2522
Michał Winiarski4977a282018-03-19 10:53:40 +01002523 *val = intel_guc_log_level_get(&dev_priv->guc.log);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302524
2525 return 0;
2526}
2527
Michał Winiarski4977a282018-03-19 10:53:40 +01002528static int i915_guc_log_level_set(void *data, u64 val)
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302529{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002530 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302531
Michał Winiarski86aa8242018-03-08 16:46:53 +01002532 if (!USES_GUC(dev_priv))
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002533 return -ENODEV;
2534
Michał Winiarski4977a282018-03-19 10:53:40 +01002535 return intel_guc_log_level_set(&dev_priv->guc.log, val);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302536}
2537
Michał Winiarski4977a282018-03-19 10:53:40 +01002538DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_level_fops,
2539 i915_guc_log_level_get, i915_guc_log_level_set,
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302540 "%lld\n");
2541
Michał Winiarski4977a282018-03-19 10:53:40 +01002542static int i915_guc_log_relay_open(struct inode *inode, struct file *file)
2543{
2544 struct drm_i915_private *dev_priv = inode->i_private;
2545
2546 if (!USES_GUC(dev_priv))
2547 return -ENODEV;
2548
2549 file->private_data = &dev_priv->guc.log;
2550
2551 return intel_guc_log_relay_open(&dev_priv->guc.log);
2552}
2553
2554static ssize_t
2555i915_guc_log_relay_write(struct file *filp,
2556 const char __user *ubuf,
2557 size_t cnt,
2558 loff_t *ppos)
2559{
2560 struct intel_guc_log *log = filp->private_data;
2561
2562 intel_guc_log_relay_flush(log);
2563
2564 return cnt;
2565}
2566
2567static int i915_guc_log_relay_release(struct inode *inode, struct file *file)
2568{
2569 struct drm_i915_private *dev_priv = inode->i_private;
2570
2571 intel_guc_log_relay_close(&dev_priv->guc.log);
2572
2573 return 0;
2574}
2575
2576static const struct file_operations i915_guc_log_relay_fops = {
2577 .owner = THIS_MODULE,
2578 .open = i915_guc_log_relay_open,
2579 .write = i915_guc_log_relay_write,
2580 .release = i915_guc_log_relay_release,
2581};
2582
Chris Wilsonb86bef202017-01-16 13:06:21 +00002583static const char *psr2_live_status(u32 val)
2584{
2585 static const char * const live_status[] = {
2586 "IDLE",
2587 "CAPTURE",
2588 "CAPTURE_FS",
2589 "SLEEP",
2590 "BUFON_FW",
2591 "ML_UP",
2592 "SU_STANDBY",
2593 "FAST_SLEEP",
2594 "DEEP_SLEEP",
2595 "BUF_ON",
2596 "TG_ON"
2597 };
2598
2599 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2600 if (val < ARRAY_SIZE(live_status))
2601 return live_status[val];
2602
2603 return "unknown";
2604}
2605
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002606static int i915_edp_psr_status(struct seq_file *m, void *data)
2607{
David Weinehall36cdd012016-08-22 13:59:31 +03002608 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002609 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002610 u32 stat[3];
2611 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002612 bool enabled = false;
Dhinakaran Pandiyanc9ef2912018-01-03 13:38:24 -08002613 bool sink_support;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002614
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002615 if (!HAS_PSR(dev_priv))
2616 return -ENODEV;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002617
Dhinakaran Pandiyanc9ef2912018-01-03 13:38:24 -08002618 sink_support = dev_priv->psr.sink_support;
2619 seq_printf(m, "Sink_Support: %s\n", yesno(sink_support));
2620 if (!sink_support)
2621 return 0;
2622
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002623 intel_runtime_pm_get(dev_priv);
2624
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002625 mutex_lock(&dev_priv->psr.lock);
Daniel Vetter2807cf62014-07-11 10:30:11 -07002626 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002627 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2628 dev_priv->psr.busy_frontbuffer_bits);
2629 seq_printf(m, "Re-enable work scheduled: %s\n",
2630 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002631
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302632 if (HAS_DDI(dev_priv)) {
José Roberto de Souza95f28d22018-03-28 15:30:42 -07002633 if (dev_priv->psr.psr2_enabled)
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302634 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2635 else
2636 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2637 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002638 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002639 enum transcoder cpu_transcoder =
2640 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2641 enum intel_display_power_domain power_domain;
2642
2643 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2644 if (!intel_display_power_get_if_enabled(dev_priv,
2645 power_domain))
2646 continue;
2647
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002648 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2649 VLV_EDP_PSR_CURR_STATE_MASK;
2650 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2651 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2652 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002653
2654 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002655 }
2656 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002657
2658 seq_printf(m, "Main link in standby mode: %s\n",
2659 yesno(dev_priv->psr.link_standby));
2660
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002661 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002662
David Weinehall36cdd012016-08-22 13:59:31 +03002663 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002664 for_each_pipe(dev_priv, pipe) {
2665 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2666 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2667 seq_printf(m, " pipe %c", pipe_name(pipe));
2668 }
2669 seq_puts(m, "\n");
2670
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002671 /*
2672 * VLV/CHV PSR has no kind of performance counter
2673 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2674 */
David Weinehall36cdd012016-08-22 13:59:31 +03002675 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002676 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002677 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002678
2679 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2680 }
José Roberto de Souza95f28d22018-03-28 15:30:42 -07002681 if (dev_priv->psr.psr2_enabled) {
Dhinakaran Pandiyan861023e2017-12-20 12:10:21 -08002682 u32 psr2 = I915_READ(EDP_PSR2_STATUS);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302683
Dhinakaran Pandiyan861023e2017-12-20 12:10:21 -08002684 seq_printf(m, "EDP_PSR2_STATUS: %x [%s]\n",
Chris Wilsonb86bef202017-01-16 13:06:21 +00002685 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302686 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002687 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002688
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002689 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002690 return 0;
2691}
2692
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002693static int i915_sink_crc(struct seq_file *m, void *data)
2694{
David Weinehall36cdd012016-08-22 13:59:31 +03002695 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2696 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002697 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002698 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002699 struct intel_dp *intel_dp = NULL;
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002700 struct drm_modeset_acquire_ctx ctx;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002701 int ret;
2702 u8 crc[6];
2703
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002704 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
2705
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002706 drm_connector_list_iter_begin(dev, &conn_iter);
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002707
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002708 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002709 struct drm_crtc *crtc;
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002710 struct drm_connector_state *state;
Maarten Lankhorst93313532017-11-10 12:34:59 +01002711 struct intel_crtc_state *crtc_state;
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002712
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002713 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002714 continue;
2715
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002716retry:
2717 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
2718 if (ret)
2719 goto err;
2720
2721 state = connector->base.state;
2722 if (!state->best_encoder)
2723 continue;
2724
2725 crtc = state->crtc;
2726 ret = drm_modeset_lock(&crtc->mutex, &ctx);
2727 if (ret)
2728 goto err;
2729
Maarten Lankhorst93313532017-11-10 12:34:59 +01002730 crtc_state = to_intel_crtc_state(crtc->state);
2731 if (!crtc_state->base.active)
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002732 continue;
2733
Maarten Lankhorst93313532017-11-10 12:34:59 +01002734 /*
2735 * We need to wait for all crtc updates to complete, to make
2736 * sure any pending modesets and plane updates are completed.
2737 */
2738 if (crtc_state->base.commit) {
2739 ret = wait_for_completion_interruptible(&crtc_state->base.commit->hw_done);
2740
2741 if (ret)
2742 goto err;
2743 }
2744
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002745 intel_dp = enc_to_intel_dp(state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002746
Maarten Lankhorst93313532017-11-10 12:34:59 +01002747 ret = intel_dp_sink_crc(intel_dp, crtc_state, crc);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002748 if (ret)
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002749 goto err;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002750
2751 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2752 crc[0], crc[1], crc[2],
2753 crc[3], crc[4], crc[5]);
2754 goto out;
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002755
2756err:
2757 if (ret == -EDEADLK) {
2758 ret = drm_modeset_backoff(&ctx);
2759 if (!ret)
2760 goto retry;
2761 }
2762 goto out;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002763 }
2764 ret = -ENODEV;
2765out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002766 drm_connector_list_iter_end(&conn_iter);
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002767 drm_modeset_drop_locks(&ctx);
2768 drm_modeset_acquire_fini(&ctx);
2769
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002770 return ret;
2771}
2772
Jesse Barnesec013e72013-08-20 10:29:23 +01002773static int i915_energy_uJ(struct seq_file *m, void *data)
2774{
David Weinehall36cdd012016-08-22 13:59:31 +03002775 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002776 unsigned long long power;
Jesse Barnesec013e72013-08-20 10:29:23 +01002777 u32 units;
2778
David Weinehall36cdd012016-08-22 13:59:31 +03002779 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002780 return -ENODEV;
2781
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002782 intel_runtime_pm_get(dev_priv);
2783
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002784 if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
2785 intel_runtime_pm_put(dev_priv);
2786 return -ENODEV;
2787 }
2788
2789 units = (power & 0x1f00) >> 8;
Jesse Barnesec013e72013-08-20 10:29:23 +01002790 power = I915_READ(MCH_SECP_NRG_STTS);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002791 power = (1000000 * power) >> units; /* convert to uJ */
Jesse Barnesec013e72013-08-20 10:29:23 +01002792
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002793 intel_runtime_pm_put(dev_priv);
2794
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002795 seq_printf(m, "%llu", power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002796
2797 return 0;
2798}
2799
Damien Lespiau6455c872015-06-04 18:23:57 +01002800static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002801{
David Weinehall36cdd012016-08-22 13:59:31 +03002802 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002803 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002804
Chris Wilsona156e642016-04-03 14:14:21 +01002805 if (!HAS_RUNTIME_PM(dev_priv))
2806 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002807
Chris Wilson6f561032018-01-24 11:36:07 +00002808 seq_printf(m, "GPU idle: %s (epoch %u)\n",
2809 yesno(!dev_priv->gt.awake), dev_priv->gt.epoch);
Paulo Zanoni371db662013-08-19 13:18:10 -03002810 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002811 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002812#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002813 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002814 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002815#else
2816 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2817#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002818 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002819 pci_power_name(pdev->current_state),
2820 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002821
Jesse Barnesec013e72013-08-20 10:29:23 +01002822 return 0;
2823}
2824
Imre Deak1da51582013-11-25 17:15:35 +02002825static int i915_power_domain_info(struct seq_file *m, void *unused)
2826{
David Weinehall36cdd012016-08-22 13:59:31 +03002827 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002828 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2829 int i;
2830
2831 mutex_lock(&power_domains->lock);
2832
2833 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2834 for (i = 0; i < power_domains->power_well_count; i++) {
2835 struct i915_power_well *power_well;
2836 enum intel_display_power_domain power_domain;
2837
2838 power_well = &power_domains->power_wells[i];
2839 seq_printf(m, "%-25s %d\n", power_well->name,
2840 power_well->count);
2841
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002842 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002843 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002844 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002845 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002846 }
2847
2848 mutex_unlock(&power_domains->lock);
2849
2850 return 0;
2851}
2852
Damien Lespiaub7cec662015-10-27 14:47:01 +02002853static int i915_dmc_info(struct seq_file *m, void *unused)
2854{
David Weinehall36cdd012016-08-22 13:59:31 +03002855 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002856 struct intel_csr *csr;
2857
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002858 if (!HAS_CSR(dev_priv))
2859 return -ENODEV;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002860
2861 csr = &dev_priv->csr;
2862
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002863 intel_runtime_pm_get(dev_priv);
2864
Damien Lespiaub7cec662015-10-27 14:47:01 +02002865 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2866 seq_printf(m, "path: %s\n", csr->fw_path);
2867
2868 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002869 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002870
2871 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2872 CSR_VERSION_MINOR(csr->version));
2873
Mika Kuoppala48de5682017-05-09 13:05:22 +03002874 if (IS_KABYLAKE(dev_priv) ||
2875 (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
Damien Lespiau83372062015-10-30 17:53:32 +02002876 seq_printf(m, "DC3 -> DC5 count: %d\n",
2877 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2878 seq_printf(m, "DC5 -> DC6 count: %d\n",
2879 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002880 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002881 seq_printf(m, "DC3 -> DC5 count: %d\n",
2882 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002883 }
2884
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002885out:
2886 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2887 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2888 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2889
Damien Lespiau83372062015-10-30 17:53:32 +02002890 intel_runtime_pm_put(dev_priv);
2891
Damien Lespiaub7cec662015-10-27 14:47:01 +02002892 return 0;
2893}
2894
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002895static void intel_seq_print_mode(struct seq_file *m, int tabs,
2896 struct drm_display_mode *mode)
2897{
2898 int i;
2899
2900 for (i = 0; i < tabs; i++)
2901 seq_putc(m, '\t');
2902
2903 seq_printf(m, "id %d:\"%s\" freq %d clock %d hdisp %d hss %d hse %d htot %d vdisp %d vss %d vse %d vtot %d type 0x%x flags 0x%x\n",
2904 mode->base.id, mode->name,
2905 mode->vrefresh, mode->clock,
2906 mode->hdisplay, mode->hsync_start,
2907 mode->hsync_end, mode->htotal,
2908 mode->vdisplay, mode->vsync_start,
2909 mode->vsync_end, mode->vtotal,
2910 mode->type, mode->flags);
2911}
2912
2913static void intel_encoder_info(struct seq_file *m,
2914 struct intel_crtc *intel_crtc,
2915 struct intel_encoder *intel_encoder)
2916{
David Weinehall36cdd012016-08-22 13:59:31 +03002917 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2918 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002919 struct drm_crtc *crtc = &intel_crtc->base;
2920 struct intel_connector *intel_connector;
2921 struct drm_encoder *encoder;
2922
2923 encoder = &intel_encoder->base;
2924 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002925 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002926 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2927 struct drm_connector *connector = &intel_connector->base;
2928 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2929 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002930 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002931 drm_get_connector_status_name(connector->status));
2932 if (connector->status == connector_status_connected) {
2933 struct drm_display_mode *mode = &crtc->mode;
2934 seq_printf(m, ", mode:\n");
2935 intel_seq_print_mode(m, 2, mode);
2936 } else {
2937 seq_putc(m, '\n');
2938 }
2939 }
2940}
2941
2942static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2943{
David Weinehall36cdd012016-08-22 13:59:31 +03002944 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2945 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002946 struct drm_crtc *crtc = &intel_crtc->base;
2947 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002948 struct drm_plane_state *plane_state = crtc->primary->state;
2949 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002950
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002951 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002952 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002953 fb->base.id, plane_state->src_x >> 16,
2954 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002955 else
2956 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002957 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2958 intel_encoder_info(m, intel_crtc, intel_encoder);
2959}
2960
2961static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2962{
2963 struct drm_display_mode *mode = panel->fixed_mode;
2964
2965 seq_printf(m, "\tfixed mode:\n");
2966 intel_seq_print_mode(m, 2, mode);
2967}
2968
2969static void intel_dp_info(struct seq_file *m,
2970 struct intel_connector *intel_connector)
2971{
2972 struct intel_encoder *intel_encoder = intel_connector->encoder;
2973 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2974
2975 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002976 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002977 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002978 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002979
2980 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2981 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002982}
2983
Libin Yang9a148a92016-11-28 20:07:05 +08002984static void intel_dp_mst_info(struct seq_file *m,
2985 struct intel_connector *intel_connector)
2986{
2987 struct intel_encoder *intel_encoder = intel_connector->encoder;
2988 struct intel_dp_mst_encoder *intel_mst =
2989 enc_to_mst(&intel_encoder->base);
2990 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2991 struct intel_dp *intel_dp = &intel_dig_port->dp;
2992 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2993 intel_connector->port);
2994
2995 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2996}
2997
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002998static void intel_hdmi_info(struct seq_file *m,
2999 struct intel_connector *intel_connector)
3000{
3001 struct intel_encoder *intel_encoder = intel_connector->encoder;
3002 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
3003
Jani Nikula742f4912015-09-03 11:16:09 +03003004 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003005}
3006
3007static void intel_lvds_info(struct seq_file *m,
3008 struct intel_connector *intel_connector)
3009{
3010 intel_panel_info(m, &intel_connector->panel);
3011}
3012
3013static void intel_connector_info(struct seq_file *m,
3014 struct drm_connector *connector)
3015{
3016 struct intel_connector *intel_connector = to_intel_connector(connector);
3017 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003018 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003019
3020 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003021 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003022 drm_get_connector_status_name(connector->status));
3023 if (connector->status == connector_status_connected) {
3024 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3025 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3026 connector->display_info.width_mm,
3027 connector->display_info.height_mm);
3028 seq_printf(m, "\tsubpixel order: %s\n",
3029 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3030 seq_printf(m, "\tCEA rev: %d\n",
3031 connector->display_info.cea_rev);
3032 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003033
Maarten Lankhorst77d1f612017-06-26 10:33:49 +02003034 if (!intel_encoder)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003035 return;
3036
3037 switch (connector->connector_type) {
3038 case DRM_MODE_CONNECTOR_DisplayPort:
3039 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003040 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3041 intel_dp_mst_info(m, intel_connector);
3042 else
3043 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003044 break;
3045 case DRM_MODE_CONNECTOR_LVDS:
3046 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003047 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003048 break;
3049 case DRM_MODE_CONNECTOR_HDMIA:
3050 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03003051 intel_encoder->type == INTEL_OUTPUT_DDI)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003052 intel_hdmi_info(m, intel_connector);
3053 break;
3054 default:
3055 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003056 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003057
Jesse Barnesf103fc72014-02-20 12:39:57 -08003058 seq_printf(m, "\tmodes:\n");
3059 list_for_each_entry(mode, &connector->modes, head)
3060 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003061}
3062
Robert Fekete3abc4e02015-10-27 16:58:32 +01003063static const char *plane_type(enum drm_plane_type type)
3064{
3065 switch (type) {
3066 case DRM_PLANE_TYPE_OVERLAY:
3067 return "OVL";
3068 case DRM_PLANE_TYPE_PRIMARY:
3069 return "PRI";
3070 case DRM_PLANE_TYPE_CURSOR:
3071 return "CUR";
3072 /*
3073 * Deliberately omitting default: to generate compiler warnings
3074 * when a new drm_plane_type gets added.
3075 */
3076 }
3077
3078 return "unknown";
3079}
3080
3081static const char *plane_rotation(unsigned int rotation)
3082{
3083 static char buf[48];
3084 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003085 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
Robert Fekete3abc4e02015-10-27 16:58:32 +01003086 * will print them all to visualize if the values are misused
3087 */
3088 snprintf(buf, sizeof(buf),
3089 "%s%s%s%s%s%s(0x%08x)",
Robert Fossc2c446a2017-05-19 16:50:17 -04003090 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
3091 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
3092 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
3093 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
3094 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
3095 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003096 rotation);
3097
3098 return buf;
3099}
3100
3101static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3102{
David Weinehall36cdd012016-08-22 13:59:31 +03003103 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3104 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003105 struct intel_plane *intel_plane;
3106
3107 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3108 struct drm_plane_state *state;
3109 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003110 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003111
3112 if (!plane->state) {
3113 seq_puts(m, "plane->state is NULL!\n");
3114 continue;
3115 }
3116
3117 state = plane->state;
3118
Eric Engestrom90844f02016-08-15 01:02:38 +01003119 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003120 drm_get_format_name(state->fb->format->format,
3121 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003122 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003123 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003124 }
3125
Robert Fekete3abc4e02015-10-27 16:58:32 +01003126 seq_printf(m, "\t--Plane id %d: type=%s, crtc_pos=%4dx%4d, crtc_size=%4dx%4d, src_pos=%d.%04ux%d.%04u, src_size=%d.%04ux%d.%04u, format=%s, rotation=%s\n",
3127 plane->base.id,
3128 plane_type(intel_plane->base.type),
3129 state->crtc_x, state->crtc_y,
3130 state->crtc_w, state->crtc_h,
3131 (state->src_x >> 16),
3132 ((state->src_x & 0xffff) * 15625) >> 10,
3133 (state->src_y >> 16),
3134 ((state->src_y & 0xffff) * 15625) >> 10,
3135 (state->src_w >> 16),
3136 ((state->src_w & 0xffff) * 15625) >> 10,
3137 (state->src_h >> 16),
3138 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003139 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003140 plane_rotation(state->rotation));
3141 }
3142}
3143
3144static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3145{
3146 struct intel_crtc_state *pipe_config;
3147 int num_scalers = intel_crtc->num_scalers;
3148 int i;
3149
3150 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3151
3152 /* Not all platformas have a scaler */
3153 if (num_scalers) {
3154 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3155 num_scalers,
3156 pipe_config->scaler_state.scaler_users,
3157 pipe_config->scaler_state.scaler_id);
3158
A.Sunil Kamath58415912016-11-20 23:20:26 +05303159 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003160 struct intel_scaler *sc =
3161 &pipe_config->scaler_state.scalers[i];
3162
3163 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3164 i, yesno(sc->in_use), sc->mode);
3165 }
3166 seq_puts(m, "\n");
3167 } else {
3168 seq_puts(m, "\tNo scalers available on this platform\n");
3169 }
3170}
3171
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003172static int i915_display_info(struct seq_file *m, void *unused)
3173{
David Weinehall36cdd012016-08-22 13:59:31 +03003174 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3175 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003176 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003177 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003178 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003179
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003180 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003181 seq_printf(m, "CRTC info\n");
3182 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003183 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003184 struct intel_crtc_state *pipe_config;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003185
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003186 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003187 pipe_config = to_intel_crtc_state(crtc->base.state);
3188
Robert Fekete3abc4e02015-10-27 16:58:32 +01003189 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003190 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003191 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003192 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3193 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3194
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003195 if (pipe_config->base.active) {
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003196 struct intel_plane *cursor =
3197 to_intel_plane(crtc->base.cursor);
3198
Chris Wilson065f2ec22014-03-12 09:13:13 +00003199 intel_crtc_info(m, crtc);
3200
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003201 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
3202 yesno(cursor->base.state->visible),
3203 cursor->base.state->crtc_x,
3204 cursor->base.state->crtc_y,
3205 cursor->base.state->crtc_w,
3206 cursor->base.state->crtc_h,
3207 cursor->cursor.base);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003208 intel_scaler_info(m, crtc);
3209 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003210 }
Daniel Vettercace8412014-05-22 17:56:31 +02003211
3212 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3213 yesno(!crtc->cpu_fifo_underrun_disabled),
3214 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003215 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003216 }
3217
3218 seq_printf(m, "\n");
3219 seq_printf(m, "Connector info\n");
3220 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003221 mutex_lock(&dev->mode_config.mutex);
3222 drm_connector_list_iter_begin(dev, &conn_iter);
3223 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003224 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003225 drm_connector_list_iter_end(&conn_iter);
3226 mutex_unlock(&dev->mode_config.mutex);
3227
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003228 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003229
3230 return 0;
3231}
3232
Chris Wilson1b365952016-10-04 21:11:31 +01003233static int i915_engine_info(struct seq_file *m, void *unused)
3234{
3235 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3236 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303237 enum intel_engine_id id;
Chris Wilsonf636edb2017-10-09 12:02:57 +01003238 struct drm_printer p;
Chris Wilson1b365952016-10-04 21:11:31 +01003239
Chris Wilson9c870d02016-10-24 13:42:15 +01003240 intel_runtime_pm_get(dev_priv);
3241
Chris Wilson6f561032018-01-24 11:36:07 +00003242 seq_printf(m, "GT awake? %s (epoch %u)\n",
3243 yesno(dev_priv->gt.awake), dev_priv->gt.epoch);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003244 seq_printf(m, "Global active requests: %d\n",
3245 dev_priv->gt.active_requests);
Lionel Landwerlinf577a032017-11-13 23:34:53 +00003246 seq_printf(m, "CS timestamp frequency: %u kHz\n",
3247 dev_priv->info.cs_timestamp_frequency_khz);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003248
Chris Wilsonf636edb2017-10-09 12:02:57 +01003249 p = drm_seq_file_printer(m);
3250 for_each_engine(engine, dev_priv, id)
Chris Wilson0db18b12017-12-08 01:23:00 +00003251 intel_engine_dump(engine, &p, "%s\n", engine->name);
Chris Wilson1b365952016-10-04 21:11:31 +01003252
Chris Wilson9c870d02016-10-24 13:42:15 +01003253 intel_runtime_pm_put(dev_priv);
3254
Chris Wilson1b365952016-10-04 21:11:31 +01003255 return 0;
3256}
3257
Lionel Landwerlin79e9cd52018-03-06 12:28:54 +00003258static int i915_rcs_topology(struct seq_file *m, void *unused)
3259{
3260 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3261 struct drm_printer p = drm_seq_file_printer(m);
3262
3263 intel_device_info_dump_topology(&INTEL_INFO(dev_priv)->sseu, &p);
3264
3265 return 0;
3266}
3267
Chris Wilsonc5418a82017-10-13 21:26:19 +01003268static int i915_shrinker_info(struct seq_file *m, void *unused)
3269{
3270 struct drm_i915_private *i915 = node_to_i915(m->private);
3271
3272 seq_printf(m, "seeks = %d\n", i915->mm.shrinker.seeks);
3273 seq_printf(m, "batch = %lu\n", i915->mm.shrinker.batch);
3274
3275 return 0;
3276}
3277
Daniel Vetter728e29d2014-06-25 22:01:53 +03003278static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3279{
David Weinehall36cdd012016-08-22 13:59:31 +03003280 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3281 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003282 int i;
3283
3284 drm_modeset_lock_all(dev);
3285 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3286 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3287
Lucas De Marchi72f775f2018-03-20 15:06:34 -07003288 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->info->name,
Lucas De Marchi0823eb92018-03-20 15:06:35 -07003289 pll->info->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003290 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003291 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003292 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003293 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003294 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003295 pll->state.hw_state.dpll_md);
3296 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3297 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3298 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003299 }
3300 drm_modeset_unlock_all(dev);
3301
3302 return 0;
3303}
3304
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003305static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003306{
3307 int i;
3308 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003309 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003310 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3311 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003312 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003313 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003314
Arun Siluvery888b5992014-08-26 14:44:51 +01003315 ret = mutex_lock_interruptible(&dev->struct_mutex);
3316 if (ret)
3317 return ret;
3318
3319 intel_runtime_pm_get(dev_priv);
3320
Arun Siluvery33136b02016-01-21 21:43:47 +00003321 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303322 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003323 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003324 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003325 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003326 i915_reg_t addr;
3327 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003328 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003329
Arun Siluvery33136b02016-01-21 21:43:47 +00003330 addr = workarounds->reg[i].addr;
3331 mask = workarounds->reg[i].mask;
3332 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003333 read = I915_READ(addr);
3334 ok = (value & mask) == (read & mask);
3335 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003336 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003337 }
3338
3339 intel_runtime_pm_put(dev_priv);
3340 mutex_unlock(&dev->struct_mutex);
3341
3342 return 0;
3343}
3344
Kumar, Maheshd2d4f392017-08-17 19:15:29 +05303345static int i915_ipc_status_show(struct seq_file *m, void *data)
3346{
3347 struct drm_i915_private *dev_priv = m->private;
3348
3349 seq_printf(m, "Isochronous Priority Control: %s\n",
3350 yesno(dev_priv->ipc_enabled));
3351 return 0;
3352}
3353
3354static int i915_ipc_status_open(struct inode *inode, struct file *file)
3355{
3356 struct drm_i915_private *dev_priv = inode->i_private;
3357
3358 if (!HAS_IPC(dev_priv))
3359 return -ENODEV;
3360
3361 return single_open(file, i915_ipc_status_show, dev_priv);
3362}
3363
3364static ssize_t i915_ipc_status_write(struct file *file, const char __user *ubuf,
3365 size_t len, loff_t *offp)
3366{
3367 struct seq_file *m = file->private_data;
3368 struct drm_i915_private *dev_priv = m->private;
3369 int ret;
3370 bool enable;
3371
3372 ret = kstrtobool_from_user(ubuf, len, &enable);
3373 if (ret < 0)
3374 return ret;
3375
3376 intel_runtime_pm_get(dev_priv);
3377 if (!dev_priv->ipc_enabled && enable)
3378 DRM_INFO("Enabling IPC: WM will be proper only after next commit\n");
3379 dev_priv->wm.distrust_bios_wm = true;
3380 dev_priv->ipc_enabled = enable;
3381 intel_enable_ipc(dev_priv);
3382 intel_runtime_pm_put(dev_priv);
3383
3384 return len;
3385}
3386
3387static const struct file_operations i915_ipc_status_fops = {
3388 .owner = THIS_MODULE,
3389 .open = i915_ipc_status_open,
3390 .read = seq_read,
3391 .llseek = seq_lseek,
3392 .release = single_release,
3393 .write = i915_ipc_status_write
3394};
3395
Damien Lespiauc5511e42014-11-04 17:06:51 +00003396static int i915_ddb_info(struct seq_file *m, void *unused)
3397{
David Weinehall36cdd012016-08-22 13:59:31 +03003398 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3399 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003400 struct skl_ddb_allocation *ddb;
3401 struct skl_ddb_entry *entry;
3402 enum pipe pipe;
3403 int plane;
3404
David Weinehall36cdd012016-08-22 13:59:31 +03003405 if (INTEL_GEN(dev_priv) < 9)
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00003406 return -ENODEV;
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003407
Damien Lespiauc5511e42014-11-04 17:06:51 +00003408 drm_modeset_lock_all(dev);
3409
3410 ddb = &dev_priv->wm.skl_hw.ddb;
3411
3412 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3413
3414 for_each_pipe(dev_priv, pipe) {
3415 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3416
Matt Roper8b364b42016-10-26 15:51:28 -07003417 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003418 entry = &ddb->plane[pipe][plane];
3419 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3420 entry->start, entry->end,
3421 skl_ddb_entry_size(entry));
3422 }
3423
Matt Roper4969d332015-09-24 15:53:10 -07003424 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003425 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3426 entry->end, skl_ddb_entry_size(entry));
3427 }
3428
3429 drm_modeset_unlock_all(dev);
3430
3431 return 0;
3432}
3433
Vandana Kannana54746e2015-03-03 20:53:10 +05303434static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003435 struct drm_device *dev,
3436 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303437{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003438 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303439 struct i915_drrs *drrs = &dev_priv->drrs;
3440 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003441 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003442 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303443
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003444 drm_connector_list_iter_begin(dev, &conn_iter);
3445 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003446 if (connector->state->crtc != &intel_crtc->base)
3447 continue;
3448
3449 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303450 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003451 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303452
3453 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3454 seq_puts(m, "\tVBT: DRRS_type: Static");
3455 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3456 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3457 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3458 seq_puts(m, "\tVBT: DRRS_type: None");
3459 else
3460 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3461
3462 seq_puts(m, "\n\n");
3463
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003464 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303465 struct intel_panel *panel;
3466
3467 mutex_lock(&drrs->mutex);
3468 /* DRRS Supported */
3469 seq_puts(m, "\tDRRS Supported: Yes\n");
3470
3471 /* disable_drrs() will make drrs->dp NULL */
3472 if (!drrs->dp) {
C, Ramalingamce6e2132017-11-20 09:53:47 +05303473 seq_puts(m, "Idleness DRRS: Disabled\n");
3474 if (dev_priv->psr.enabled)
3475 seq_puts(m,
3476 "\tAs PSR is enabled, DRRS is not enabled\n");
Vandana Kannana54746e2015-03-03 20:53:10 +05303477 mutex_unlock(&drrs->mutex);
3478 return;
3479 }
3480
3481 panel = &drrs->dp->attached_connector->panel;
3482 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3483 drrs->busy_frontbuffer_bits);
3484
3485 seq_puts(m, "\n\t\t");
3486 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3487 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3488 vrefresh = panel->fixed_mode->vrefresh;
3489 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3490 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3491 vrefresh = panel->downclock_mode->vrefresh;
3492 } else {
3493 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3494 drrs->refresh_rate_type);
3495 mutex_unlock(&drrs->mutex);
3496 return;
3497 }
3498 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3499
3500 seq_puts(m, "\n\t\t");
3501 mutex_unlock(&drrs->mutex);
3502 } else {
3503 /* DRRS not supported. Print the VBT parameter*/
3504 seq_puts(m, "\tDRRS Supported : No");
3505 }
3506 seq_puts(m, "\n");
3507}
3508
3509static int i915_drrs_status(struct seq_file *m, void *unused)
3510{
David Weinehall36cdd012016-08-22 13:59:31 +03003511 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3512 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303513 struct intel_crtc *intel_crtc;
3514 int active_crtc_cnt = 0;
3515
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003516 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303517 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003518 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303519 active_crtc_cnt++;
3520 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3521
3522 drrs_status_per_crtc(m, dev, intel_crtc);
3523 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303524 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003525 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303526
3527 if (!active_crtc_cnt)
3528 seq_puts(m, "No active crtc found\n");
3529
3530 return 0;
3531}
3532
Dave Airlie11bed952014-05-12 15:22:27 +10003533static int i915_dp_mst_info(struct seq_file *m, void *unused)
3534{
David Weinehall36cdd012016-08-22 13:59:31 +03003535 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3536 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003537 struct intel_encoder *intel_encoder;
3538 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003539 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003540 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003541
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003542 drm_connector_list_iter_begin(dev, &conn_iter);
3543 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003544 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003545 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003546
3547 intel_encoder = intel_attached_encoder(connector);
3548 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3549 continue;
3550
3551 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003552 if (!intel_dig_port->dp.can_mst)
3553 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003554
Jim Bride40ae80c2016-04-14 10:18:37 -07003555 seq_printf(m, "MST Source Port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003556 port_name(intel_dig_port->base.port));
Dave Airlie11bed952014-05-12 15:22:27 +10003557 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3558 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003559 drm_connector_list_iter_end(&conn_iter);
3560
Dave Airlie11bed952014-05-12 15:22:27 +10003561 return 0;
3562}
3563
Todd Previteeb3394fa2015-04-18 00:04:19 -07003564static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003565 const char __user *ubuf,
3566 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003567{
3568 char *input_buffer;
3569 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003570 struct drm_device *dev;
3571 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003572 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003573 struct intel_dp *intel_dp;
3574 int val = 0;
3575
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303576 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003577
Todd Previteeb3394fa2015-04-18 00:04:19 -07003578 if (len == 0)
3579 return 0;
3580
Geliang Tang261aeba2017-05-06 23:40:17 +08003581 input_buffer = memdup_user_nul(ubuf, len);
3582 if (IS_ERR(input_buffer))
3583 return PTR_ERR(input_buffer);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003584
Todd Previteeb3394fa2015-04-18 00:04:19 -07003585 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3586
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003587 drm_connector_list_iter_begin(dev, &conn_iter);
3588 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003589 struct intel_encoder *encoder;
3590
Todd Previteeb3394fa2015-04-18 00:04:19 -07003591 if (connector->connector_type !=
3592 DRM_MODE_CONNECTOR_DisplayPort)
3593 continue;
3594
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003595 encoder = to_intel_encoder(connector->encoder);
3596 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3597 continue;
3598
3599 if (encoder && connector->status == connector_status_connected) {
3600 intel_dp = enc_to_intel_dp(&encoder->base);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003601 status = kstrtoint(input_buffer, 10, &val);
3602 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003603 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003604 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3605 /* To prevent erroneous activation of the compliance
3606 * testing code, only accept an actual value of 1 here
3607 */
3608 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003609 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003610 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003611 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003612 }
3613 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003614 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003615 kfree(input_buffer);
3616 if (status < 0)
3617 return status;
3618
3619 *offp += len;
3620 return len;
3621}
3622
3623static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3624{
Andy Shevchenkoe4006712018-03-16 16:12:13 +02003625 struct drm_i915_private *dev_priv = m->private;
3626 struct drm_device *dev = &dev_priv->drm;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003627 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003628 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003629 struct intel_dp *intel_dp;
3630
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003631 drm_connector_list_iter_begin(dev, &conn_iter);
3632 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003633 struct intel_encoder *encoder;
3634
Todd Previteeb3394fa2015-04-18 00:04:19 -07003635 if (connector->connector_type !=
3636 DRM_MODE_CONNECTOR_DisplayPort)
3637 continue;
3638
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003639 encoder = to_intel_encoder(connector->encoder);
3640 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3641 continue;
3642
3643 if (encoder && connector->status == connector_status_connected) {
3644 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003645 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003646 seq_puts(m, "1");
3647 else
3648 seq_puts(m, "0");
3649 } else
3650 seq_puts(m, "0");
3651 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003652 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003653
3654 return 0;
3655}
3656
3657static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003658 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003659{
David Weinehall36cdd012016-08-22 13:59:31 +03003660 return single_open(file, i915_displayport_test_active_show,
Andy Shevchenkoe4006712018-03-16 16:12:13 +02003661 inode->i_private);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003662}
3663
3664static const struct file_operations i915_displayport_test_active_fops = {
3665 .owner = THIS_MODULE,
3666 .open = i915_displayport_test_active_open,
3667 .read = seq_read,
3668 .llseek = seq_lseek,
3669 .release = single_release,
3670 .write = i915_displayport_test_active_write
3671};
3672
3673static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3674{
Andy Shevchenkoe4006712018-03-16 16:12:13 +02003675 struct drm_i915_private *dev_priv = m->private;
3676 struct drm_device *dev = &dev_priv->drm;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003677 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003678 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003679 struct intel_dp *intel_dp;
3680
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003681 drm_connector_list_iter_begin(dev, &conn_iter);
3682 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003683 struct intel_encoder *encoder;
3684
Todd Previteeb3394fa2015-04-18 00:04:19 -07003685 if (connector->connector_type !=
3686 DRM_MODE_CONNECTOR_DisplayPort)
3687 continue;
3688
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003689 encoder = to_intel_encoder(connector->encoder);
3690 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3691 continue;
3692
3693 if (encoder && connector->status == connector_status_connected) {
3694 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003695 if (intel_dp->compliance.test_type ==
3696 DP_TEST_LINK_EDID_READ)
3697 seq_printf(m, "%lx",
3698 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003699 else if (intel_dp->compliance.test_type ==
3700 DP_TEST_LINK_VIDEO_PATTERN) {
3701 seq_printf(m, "hdisplay: %d\n",
3702 intel_dp->compliance.test_data.hdisplay);
3703 seq_printf(m, "vdisplay: %d\n",
3704 intel_dp->compliance.test_data.vdisplay);
3705 seq_printf(m, "bpc: %u\n",
3706 intel_dp->compliance.test_data.bpc);
3707 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003708 } else
3709 seq_puts(m, "0");
3710 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003711 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003712
3713 return 0;
3714}
Andy Shevchenkoe4006712018-03-16 16:12:13 +02003715DEFINE_SHOW_ATTRIBUTE(i915_displayport_test_data);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003716
3717static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3718{
Andy Shevchenkoe4006712018-03-16 16:12:13 +02003719 struct drm_i915_private *dev_priv = m->private;
3720 struct drm_device *dev = &dev_priv->drm;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003721 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003722 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003723 struct intel_dp *intel_dp;
3724
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003725 drm_connector_list_iter_begin(dev, &conn_iter);
3726 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003727 struct intel_encoder *encoder;
3728
Todd Previteeb3394fa2015-04-18 00:04:19 -07003729 if (connector->connector_type !=
3730 DRM_MODE_CONNECTOR_DisplayPort)
3731 continue;
3732
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003733 encoder = to_intel_encoder(connector->encoder);
3734 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3735 continue;
3736
3737 if (encoder && connector->status == connector_status_connected) {
3738 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003739 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003740 } else
3741 seq_puts(m, "0");
3742 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003743 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003744
3745 return 0;
3746}
Andy Shevchenkoe4006712018-03-16 16:12:13 +02003747DEFINE_SHOW_ATTRIBUTE(i915_displayport_test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003748
Damien Lespiau97e94b22014-11-04 17:06:50 +00003749static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003750{
David Weinehall36cdd012016-08-22 13:59:31 +03003751 struct drm_i915_private *dev_priv = m->private;
3752 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003753 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003754 int num_levels;
3755
David Weinehall36cdd012016-08-22 13:59:31 +03003756 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003757 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003758 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003759 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003760 else if (IS_G4X(dev_priv))
3761 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003762 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003763 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003764
3765 drm_modeset_lock_all(dev);
3766
3767 for (level = 0; level < num_levels; level++) {
3768 unsigned int latency = wm[level];
3769
Damien Lespiau97e94b22014-11-04 17:06:50 +00003770 /*
3771 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003772 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003773 */
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003774 if (INTEL_GEN(dev_priv) >= 9 ||
3775 IS_VALLEYVIEW(dev_priv) ||
3776 IS_CHERRYVIEW(dev_priv) ||
3777 IS_G4X(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003778 latency *= 10;
3779 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003780 latency *= 5;
3781
3782 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003783 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003784 }
3785
3786 drm_modeset_unlock_all(dev);
3787}
3788
3789static int pri_wm_latency_show(struct seq_file *m, void *data)
3790{
David Weinehall36cdd012016-08-22 13:59:31 +03003791 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003792 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003793
David Weinehall36cdd012016-08-22 13:59:31 +03003794 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003795 latencies = dev_priv->wm.skl_latency;
3796 else
David Weinehall36cdd012016-08-22 13:59:31 +03003797 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003798
3799 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003800
3801 return 0;
3802}
3803
3804static int spr_wm_latency_show(struct seq_file *m, void *data)
3805{
David Weinehall36cdd012016-08-22 13:59:31 +03003806 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003807 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003808
David Weinehall36cdd012016-08-22 13:59:31 +03003809 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003810 latencies = dev_priv->wm.skl_latency;
3811 else
David Weinehall36cdd012016-08-22 13:59:31 +03003812 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003813
3814 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003815
3816 return 0;
3817}
3818
3819static int cur_wm_latency_show(struct seq_file *m, void *data)
3820{
David Weinehall36cdd012016-08-22 13:59:31 +03003821 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003822 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003823
David Weinehall36cdd012016-08-22 13:59:31 +03003824 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003825 latencies = dev_priv->wm.skl_latency;
3826 else
David Weinehall36cdd012016-08-22 13:59:31 +03003827 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003828
3829 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003830
3831 return 0;
3832}
3833
3834static int pri_wm_latency_open(struct inode *inode, struct file *file)
3835{
David Weinehall36cdd012016-08-22 13:59:31 +03003836 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003837
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003838 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003839 return -ENODEV;
3840
David Weinehall36cdd012016-08-22 13:59:31 +03003841 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003842}
3843
3844static int spr_wm_latency_open(struct inode *inode, struct file *file)
3845{
David Weinehall36cdd012016-08-22 13:59:31 +03003846 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003847
David Weinehall36cdd012016-08-22 13:59:31 +03003848 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003849 return -ENODEV;
3850
David Weinehall36cdd012016-08-22 13:59:31 +03003851 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003852}
3853
3854static int cur_wm_latency_open(struct inode *inode, struct file *file)
3855{
David Weinehall36cdd012016-08-22 13:59:31 +03003856 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003857
David Weinehall36cdd012016-08-22 13:59:31 +03003858 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003859 return -ENODEV;
3860
David Weinehall36cdd012016-08-22 13:59:31 +03003861 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003862}
3863
3864static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003865 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003866{
3867 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003868 struct drm_i915_private *dev_priv = m->private;
3869 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003870 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03003871 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003872 int level;
3873 int ret;
3874 char tmp[32];
3875
David Weinehall36cdd012016-08-22 13:59:31 +03003876 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003877 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003878 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003879 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003880 else if (IS_G4X(dev_priv))
3881 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003882 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003883 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003884
Ville Syrjälä369a1342014-01-22 14:36:08 +02003885 if (len >= sizeof(tmp))
3886 return -EINVAL;
3887
3888 if (copy_from_user(tmp, ubuf, len))
3889 return -EFAULT;
3890
3891 tmp[len] = '\0';
3892
Damien Lespiau97e94b22014-11-04 17:06:50 +00003893 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3894 &new[0], &new[1], &new[2], &new[3],
3895 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003896 if (ret != num_levels)
3897 return -EINVAL;
3898
3899 drm_modeset_lock_all(dev);
3900
3901 for (level = 0; level < num_levels; level++)
3902 wm[level] = new[level];
3903
3904 drm_modeset_unlock_all(dev);
3905
3906 return len;
3907}
3908
3909
3910static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3911 size_t len, loff_t *offp)
3912{
3913 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003914 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003915 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003916
David Weinehall36cdd012016-08-22 13:59:31 +03003917 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003918 latencies = dev_priv->wm.skl_latency;
3919 else
David Weinehall36cdd012016-08-22 13:59:31 +03003920 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003921
3922 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003923}
3924
3925static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3926 size_t len, loff_t *offp)
3927{
3928 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003929 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003930 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003931
David Weinehall36cdd012016-08-22 13:59:31 +03003932 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003933 latencies = dev_priv->wm.skl_latency;
3934 else
David Weinehall36cdd012016-08-22 13:59:31 +03003935 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003936
3937 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003938}
3939
3940static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3941 size_t len, loff_t *offp)
3942{
3943 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003944 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003945 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003946
David Weinehall36cdd012016-08-22 13:59:31 +03003947 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003948 latencies = dev_priv->wm.skl_latency;
3949 else
David Weinehall36cdd012016-08-22 13:59:31 +03003950 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003951
3952 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003953}
3954
3955static const struct file_operations i915_pri_wm_latency_fops = {
3956 .owner = THIS_MODULE,
3957 .open = pri_wm_latency_open,
3958 .read = seq_read,
3959 .llseek = seq_lseek,
3960 .release = single_release,
3961 .write = pri_wm_latency_write
3962};
3963
3964static const struct file_operations i915_spr_wm_latency_fops = {
3965 .owner = THIS_MODULE,
3966 .open = spr_wm_latency_open,
3967 .read = seq_read,
3968 .llseek = seq_lseek,
3969 .release = single_release,
3970 .write = spr_wm_latency_write
3971};
3972
3973static const struct file_operations i915_cur_wm_latency_fops = {
3974 .owner = THIS_MODULE,
3975 .open = cur_wm_latency_open,
3976 .read = seq_read,
3977 .llseek = seq_lseek,
3978 .release = single_release,
3979 .write = cur_wm_latency_write
3980};
3981
Kees Cook647416f2013-03-10 14:10:06 -07003982static int
3983i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003984{
David Weinehall36cdd012016-08-22 13:59:31 +03003985 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003986
Chris Wilsond98c52c2016-04-13 17:35:05 +01003987 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003988
Kees Cook647416f2013-03-10 14:10:06 -07003989 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003990}
3991
Kees Cook647416f2013-03-10 14:10:06 -07003992static int
3993i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003994{
Chris Wilson598b6b52017-03-25 13:47:35 +00003995 struct drm_i915_private *i915 = data;
3996 struct intel_engine_cs *engine;
3997 unsigned int tmp;
Imre Deakd46c0512014-04-14 20:24:27 +03003998
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003999 /*
4000 * There is no safeguard against this debugfs entry colliding
4001 * with the hangcheck calling same i915_handle_error() in
4002 * parallel, causing an explosion. For now we assume that the
4003 * test harness is responsible enough not to inject gpu hangs
4004 * while it is writing to 'i915_wedged'
4005 */
4006
Chris Wilson598b6b52017-03-25 13:47:35 +00004007 if (i915_reset_backoff(&i915->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004008 return -EAGAIN;
4009
Chris Wilson598b6b52017-03-25 13:47:35 +00004010 for_each_engine_masked(engine, i915, val, tmp) {
4011 engine->hangcheck.seqno = intel_engine_get_seqno(engine);
4012 engine->hangcheck.stalled = true;
4013 }
Imre Deakd46c0512014-04-14 20:24:27 +03004014
Chris Wilsonce800752018-03-20 10:04:49 +00004015 i915_handle_error(i915, val, I915_ERROR_CAPTURE,
4016 "Manually set wedged engine mask = %llx", val);
Chris Wilson598b6b52017-03-25 13:47:35 +00004017
4018 wait_on_bit(&i915->gpu_error.flags,
Chris Wilsond3df42b2017-03-16 17:13:05 +00004019 I915_RESET_HANDOFF,
4020 TASK_UNINTERRUPTIBLE);
4021
Kees Cook647416f2013-03-10 14:10:06 -07004022 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004023}
4024
Kees Cook647416f2013-03-10 14:10:06 -07004025DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4026 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004027 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004028
Kees Cook647416f2013-03-10 14:10:06 -07004029static int
Chris Wilson64486ae2017-03-07 15:59:08 +00004030fault_irq_set(struct drm_i915_private *i915,
4031 unsigned long *irq,
4032 unsigned long val)
4033{
4034 int err;
4035
4036 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
4037 if (err)
4038 return err;
4039
4040 err = i915_gem_wait_for_idle(i915,
4041 I915_WAIT_LOCKED |
4042 I915_WAIT_INTERRUPTIBLE);
4043 if (err)
4044 goto err_unlock;
4045
Chris Wilson64486ae2017-03-07 15:59:08 +00004046 *irq = val;
4047 mutex_unlock(&i915->drm.struct_mutex);
4048
4049 /* Flush idle worker to disarm irq */
Chris Wilson7c262402017-10-06 11:40:38 +01004050 drain_delayed_work(&i915->gt.idle_work);
Chris Wilson64486ae2017-03-07 15:59:08 +00004051
4052 return 0;
4053
4054err_unlock:
4055 mutex_unlock(&i915->drm.struct_mutex);
4056 return err;
4057}
4058
4059static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004060i915_ring_missed_irq_get(void *data, u64 *val)
4061{
David Weinehall36cdd012016-08-22 13:59:31 +03004062 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004063
4064 *val = dev_priv->gpu_error.missed_irq_rings;
4065 return 0;
4066}
4067
4068static int
4069i915_ring_missed_irq_set(void *data, u64 val)
4070{
Chris Wilson64486ae2017-03-07 15:59:08 +00004071 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004072
Chris Wilson64486ae2017-03-07 15:59:08 +00004073 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004074}
4075
4076DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4077 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4078 "0x%08llx\n");
4079
4080static int
4081i915_ring_test_irq_get(void *data, u64 *val)
4082{
David Weinehall36cdd012016-08-22 13:59:31 +03004083 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004084
4085 *val = dev_priv->gpu_error.test_irq_rings;
4086
4087 return 0;
4088}
4089
4090static int
4091i915_ring_test_irq_set(void *data, u64 val)
4092{
Chris Wilson64486ae2017-03-07 15:59:08 +00004093 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004094
Chris Wilson64486ae2017-03-07 15:59:08 +00004095 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004096 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004097
Chris Wilson64486ae2017-03-07 15:59:08 +00004098 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004099}
4100
4101DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4102 i915_ring_test_irq_get, i915_ring_test_irq_set,
4103 "0x%08llx\n");
4104
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004105#define DROP_UNBOUND BIT(0)
4106#define DROP_BOUND BIT(1)
4107#define DROP_RETIRE BIT(2)
4108#define DROP_ACTIVE BIT(3)
4109#define DROP_FREED BIT(4)
4110#define DROP_SHRINK_ALL BIT(5)
4111#define DROP_IDLE BIT(6)
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004112#define DROP_ALL (DROP_UNBOUND | \
4113 DROP_BOUND | \
4114 DROP_RETIRE | \
4115 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004116 DROP_FREED | \
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004117 DROP_SHRINK_ALL |\
4118 DROP_IDLE)
Kees Cook647416f2013-03-10 14:10:06 -07004119static int
4120i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004121{
Kees Cook647416f2013-03-10 14:10:06 -07004122 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004123
Kees Cook647416f2013-03-10 14:10:06 -07004124 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004125}
4126
Kees Cook647416f2013-03-10 14:10:06 -07004127static int
4128i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004129{
David Weinehall36cdd012016-08-22 13:59:31 +03004130 struct drm_i915_private *dev_priv = data;
4131 struct drm_device *dev = &dev_priv->drm;
Chris Wilson00c26cf2017-05-24 17:26:53 +01004132 int ret = 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004133
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004134 DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
4135 val, val & DROP_ALL);
Chris Wilsondd624af2013-01-15 12:39:35 +00004136
4137 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4138 * on ioctls on -EAGAIN. */
Chris Wilson00c26cf2017-05-24 17:26:53 +01004139 if (val & (DROP_ACTIVE | DROP_RETIRE)) {
4140 ret = mutex_lock_interruptible(&dev->struct_mutex);
Chris Wilsondd624af2013-01-15 12:39:35 +00004141 if (ret)
Chris Wilson00c26cf2017-05-24 17:26:53 +01004142 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004143
Chris Wilson00c26cf2017-05-24 17:26:53 +01004144 if (val & DROP_ACTIVE)
4145 ret = i915_gem_wait_for_idle(dev_priv,
4146 I915_WAIT_INTERRUPTIBLE |
4147 I915_WAIT_LOCKED);
4148
4149 if (val & DROP_RETIRE)
Chris Wilsone61e0f52018-02-21 09:56:36 +00004150 i915_retire_requests(dev_priv);
Chris Wilson00c26cf2017-05-24 17:26:53 +01004151
4152 mutex_unlock(&dev->struct_mutex);
4153 }
Chris Wilsondd624af2013-01-15 12:39:35 +00004154
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +01004155 fs_reclaim_acquire(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004156 if (val & DROP_BOUND)
Chris Wilson912d5722017-09-06 16:19:30 -07004157 i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004158
Chris Wilson21ab4e72014-09-09 11:16:08 +01004159 if (val & DROP_UNBOUND)
Chris Wilson912d5722017-09-06 16:19:30 -07004160 i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004161
Chris Wilson8eadc192017-03-08 14:46:22 +00004162 if (val & DROP_SHRINK_ALL)
4163 i915_gem_shrink_all(dev_priv);
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +01004164 fs_reclaim_release(GFP_KERNEL);
Chris Wilson8eadc192017-03-08 14:46:22 +00004165
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004166 if (val & DROP_IDLE)
4167 drain_delayed_work(&dev_priv->gt.idle_work);
4168
Chris Wilsonc9c704712018-02-19 22:06:31 +00004169 if (val & DROP_FREED)
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004170 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004171
Kees Cook647416f2013-03-10 14:10:06 -07004172 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004173}
4174
Kees Cook647416f2013-03-10 14:10:06 -07004175DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4176 i915_drop_caches_get, i915_drop_caches_set,
4177 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004178
Kees Cook647416f2013-03-10 14:10:06 -07004179static int
4180i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004181{
David Weinehall36cdd012016-08-22 13:59:31 +03004182 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004183
David Weinehall36cdd012016-08-22 13:59:31 +03004184 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004185 return -ENODEV;
4186
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004187 *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004188 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004189}
4190
Kees Cook647416f2013-03-10 14:10:06 -07004191static int
4192i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004193{
David Weinehall36cdd012016-08-22 13:59:31 +03004194 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004195 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304196 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004197 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004198
David Weinehall36cdd012016-08-22 13:59:31 +03004199 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004200 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004201
Kees Cook647416f2013-03-10 14:10:06 -07004202 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004203
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004204 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004205 if (ret)
4206 return ret;
4207
Jesse Barnes358733e2011-07-27 11:53:01 -07004208 /*
4209 * Turbo will still be enabled, but won't go above the set value.
4210 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304211 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004212
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004213 hw_max = rps->max_freq;
4214 hw_min = rps->min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004215
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004216 if (val < hw_min || val > hw_max || val < rps->min_freq_softlimit) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004217 mutex_unlock(&dev_priv->pcu_lock);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004218 return -EINVAL;
4219 }
4220
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004221 rps->max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004222
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004223 if (intel_set_rps(dev_priv, val))
4224 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004225
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004226 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004227
Kees Cook647416f2013-03-10 14:10:06 -07004228 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004229}
4230
Kees Cook647416f2013-03-10 14:10:06 -07004231DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4232 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004233 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004234
Kees Cook647416f2013-03-10 14:10:06 -07004235static int
4236i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004237{
David Weinehall36cdd012016-08-22 13:59:31 +03004238 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004239
Chris Wilson62e1baa2016-07-13 09:10:36 +01004240 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004241 return -ENODEV;
4242
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004243 *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004244 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004245}
4246
Kees Cook647416f2013-03-10 14:10:06 -07004247static int
4248i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004249{
David Weinehall36cdd012016-08-22 13:59:31 +03004250 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004251 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304252 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004253 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004254
Chris Wilson62e1baa2016-07-13 09:10:36 +01004255 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004256 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004257
Kees Cook647416f2013-03-10 14:10:06 -07004258 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004259
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004260 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004261 if (ret)
4262 return ret;
4263
Jesse Barnes1523c312012-05-25 12:34:54 -07004264 /*
4265 * Turbo will still be enabled, but won't go below the set value.
4266 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304267 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004268
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004269 hw_max = rps->max_freq;
4270 hw_min = rps->min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004271
David Weinehall36cdd012016-08-22 13:59:31 +03004272 if (val < hw_min ||
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004273 val > hw_max || val > rps->max_freq_softlimit) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004274 mutex_unlock(&dev_priv->pcu_lock);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004275 return -EINVAL;
4276 }
4277
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004278 rps->min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004279
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004280 if (intel_set_rps(dev_priv, val))
4281 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004282
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004283 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004284
Kees Cook647416f2013-03-10 14:10:06 -07004285 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004286}
4287
Kees Cook647416f2013-03-10 14:10:06 -07004288DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4289 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004290 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004291
Kees Cook647416f2013-03-10 14:10:06 -07004292static int
4293i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004294{
David Weinehall36cdd012016-08-22 13:59:31 +03004295 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004296 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004297
David Weinehall36cdd012016-08-22 13:59:31 +03004298 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004299 return -ENODEV;
4300
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004301 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004302
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004303 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004304
4305 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004306
Kees Cook647416f2013-03-10 14:10:06 -07004307 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004308
Kees Cook647416f2013-03-10 14:10:06 -07004309 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004310}
4311
Kees Cook647416f2013-03-10 14:10:06 -07004312static int
4313i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004314{
David Weinehall36cdd012016-08-22 13:59:31 +03004315 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004316 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004317
David Weinehall36cdd012016-08-22 13:59:31 +03004318 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004319 return -ENODEV;
4320
Kees Cook647416f2013-03-10 14:10:06 -07004321 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004322 return -EINVAL;
4323
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004324 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004325 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004326
4327 /* Update the cache sharing policy here as well */
4328 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4329 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4330 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4331 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4332
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004333 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004334 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004335}
4336
Kees Cook647416f2013-03-10 14:10:06 -07004337DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4338 i915_cache_sharing_get, i915_cache_sharing_set,
4339 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004340
David Weinehall36cdd012016-08-22 13:59:31 +03004341static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004342 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004343{
Chris Wilson7aa0b142018-03-13 00:40:54 +00004344#define SS_MAX 2
4345 const int ss_max = SS_MAX;
4346 u32 sig1[SS_MAX], sig2[SS_MAX];
Jeff McGee5d395252015-04-03 18:13:17 -07004347 int ss;
Jeff McGee5d395252015-04-03 18:13:17 -07004348
4349 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4350 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4351 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4352 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4353
4354 for (ss = 0; ss < ss_max; ss++) {
4355 unsigned int eu_cnt;
4356
4357 if (sig1[ss] & CHV_SS_PG_ENABLE)
4358 /* skip disabled subslice */
4359 continue;
4360
Imre Deakf08a0c92016-08-31 19:13:04 +03004361 sseu->slice_mask = BIT(0);
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004362 sseu->subslice_mask[0] |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004363 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4364 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4365 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4366 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004367 sseu->eu_total += eu_cnt;
4368 sseu->eu_per_subslice = max_t(unsigned int,
4369 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004370 }
Chris Wilson7aa0b142018-03-13 00:40:54 +00004371#undef SS_MAX
Jeff McGee5d395252015-04-03 18:13:17 -07004372}
4373
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004374static void gen10_sseu_device_status(struct drm_i915_private *dev_priv,
4375 struct sseu_dev_info *sseu)
4376{
Chris Wilsonc7fb3c62018-03-13 11:31:49 +00004377#define SS_MAX 6
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004378 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilsonc7fb3c62018-03-13 11:31:49 +00004379 u32 s_reg[SS_MAX], eu_reg[2 * SS_MAX], eu_mask[2];
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004380 int s, ss;
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004381
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004382 for (s = 0; s < info->sseu.max_slices; s++) {
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004383 /*
4384 * FIXME: Valid SS Mask respects the spec and read
4385 * only valid bits for those registers, excluding reserverd
4386 * although this seems wrong because it would leave many
4387 * subslices without ACK.
4388 */
4389 s_reg[s] = I915_READ(GEN10_SLICE_PGCTL_ACK(s)) &
4390 GEN10_PGCTL_VALID_SS_MASK(s);
4391 eu_reg[2 * s] = I915_READ(GEN10_SS01_EU_PGCTL_ACK(s));
4392 eu_reg[2 * s + 1] = I915_READ(GEN10_SS23_EU_PGCTL_ACK(s));
4393 }
4394
4395 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4396 GEN9_PGCTL_SSA_EU19_ACK |
4397 GEN9_PGCTL_SSA_EU210_ACK |
4398 GEN9_PGCTL_SSA_EU311_ACK;
4399 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4400 GEN9_PGCTL_SSB_EU19_ACK |
4401 GEN9_PGCTL_SSB_EU210_ACK |
4402 GEN9_PGCTL_SSB_EU311_ACK;
4403
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004404 for (s = 0; s < info->sseu.max_slices; s++) {
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004405 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4406 /* skip disabled slice */
4407 continue;
4408
4409 sseu->slice_mask |= BIT(s);
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004410 sseu->subslice_mask[s] = info->sseu.subslice_mask[s];
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004411
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004412 for (ss = 0; ss < info->sseu.max_subslices; ss++) {
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004413 unsigned int eu_cnt;
4414
4415 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4416 /* skip disabled subslice */
4417 continue;
4418
4419 eu_cnt = 2 * hweight32(eu_reg[2 * s + ss / 2] &
4420 eu_mask[ss % 2]);
4421 sseu->eu_total += eu_cnt;
4422 sseu->eu_per_subslice = max_t(unsigned int,
4423 sseu->eu_per_subslice,
4424 eu_cnt);
4425 }
4426 }
Chris Wilsonc7fb3c62018-03-13 11:31:49 +00004427#undef SS_MAX
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004428}
4429
David Weinehall36cdd012016-08-22 13:59:31 +03004430static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004431 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004432{
Chris Wilsonc7fb3c62018-03-13 11:31:49 +00004433#define SS_MAX 3
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004434 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilsonc7fb3c62018-03-13 11:31:49 +00004435 u32 s_reg[SS_MAX], eu_reg[2 * SS_MAX], eu_mask[2];
Jeff McGee5d395252015-04-03 18:13:17 -07004436 int s, ss;
Jeff McGee5d395252015-04-03 18:13:17 -07004437
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004438 for (s = 0; s < info->sseu.max_slices; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004439 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4440 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4441 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4442 }
4443
Jeff McGee5d395252015-04-03 18:13:17 -07004444 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4445 GEN9_PGCTL_SSA_EU19_ACK |
4446 GEN9_PGCTL_SSA_EU210_ACK |
4447 GEN9_PGCTL_SSA_EU311_ACK;
4448 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4449 GEN9_PGCTL_SSB_EU19_ACK |
4450 GEN9_PGCTL_SSB_EU210_ACK |
4451 GEN9_PGCTL_SSB_EU311_ACK;
4452
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004453 for (s = 0; s < info->sseu.max_slices; s++) {
Jeff McGee5d395252015-04-03 18:13:17 -07004454 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4455 /* skip disabled slice */
4456 continue;
4457
Imre Deakf08a0c92016-08-31 19:13:04 +03004458 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004459
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004460 if (IS_GEN9_BC(dev_priv))
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004461 sseu->subslice_mask[s] =
4462 INTEL_INFO(dev_priv)->sseu.subslice_mask[s];
Jeff McGee1c046bc2015-04-03 18:13:18 -07004463
Lionel Landwerlinb3e7f862018-03-06 12:28:53 +00004464 for (ss = 0; ss < info->sseu.max_subslices; ss++) {
Jeff McGee5d395252015-04-03 18:13:17 -07004465 unsigned int eu_cnt;
4466
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004467 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004468 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4469 /* skip disabled subslice */
4470 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004471
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004472 sseu->subslice_mask[s] |= BIT(ss);
Imre Deak57ec1712016-08-31 19:13:05 +03004473 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004474
Jeff McGee5d395252015-04-03 18:13:17 -07004475 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4476 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004477 sseu->eu_total += eu_cnt;
4478 sseu->eu_per_subslice = max_t(unsigned int,
4479 sseu->eu_per_subslice,
4480 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004481 }
4482 }
Chris Wilsonc7fb3c62018-03-13 11:31:49 +00004483#undef SS_MAX
Jeff McGee5d395252015-04-03 18:13:17 -07004484}
4485
David Weinehall36cdd012016-08-22 13:59:31 +03004486static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004487 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004488{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004489 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004490 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004491
Imre Deakf08a0c92016-08-31 19:13:04 +03004492 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004493
Imre Deakf08a0c92016-08-31 19:13:04 +03004494 if (sseu->slice_mask) {
Imre Deak43b67992016-08-31 19:13:02 +03004495 sseu->eu_per_subslice =
4496 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004497 for (s = 0; s < fls(sseu->slice_mask); s++) {
4498 sseu->subslice_mask[s] =
4499 INTEL_INFO(dev_priv)->sseu.subslice_mask[s];
4500 }
Imre Deak57ec1712016-08-31 19:13:05 +03004501 sseu->eu_total = sseu->eu_per_subslice *
4502 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004503
4504 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004505 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004506 u8 subslice_7eu =
4507 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004508
Imre Deak915490d2016-08-31 19:13:01 +03004509 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004510 }
4511 }
4512}
4513
Imre Deak615d8902016-08-31 19:13:03 +03004514static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4515 const struct sseu_dev_info *sseu)
4516{
4517 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4518 const char *type = is_available_info ? "Available" : "Enabled";
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004519 int s;
Imre Deak615d8902016-08-31 19:13:03 +03004520
Imre Deakc67ba532016-08-31 19:13:06 +03004521 seq_printf(m, " %s Slice Mask: %04x\n", type,
4522 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004523 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004524 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004525 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004526 sseu_subslice_total(sseu));
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004527 for (s = 0; s < fls(sseu->slice_mask); s++) {
4528 seq_printf(m, " %s Slice%i subslices: %u\n", type,
4529 s, hweight8(sseu->subslice_mask[s]));
4530 }
Imre Deak615d8902016-08-31 19:13:03 +03004531 seq_printf(m, " %s EU Total: %u\n", type,
4532 sseu->eu_total);
4533 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4534 sseu->eu_per_subslice);
4535
4536 if (!is_available_info)
4537 return;
4538
4539 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4540 if (HAS_POOLED_EU(dev_priv))
4541 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4542
4543 seq_printf(m, " Has Slice Power Gating: %s\n",
4544 yesno(sseu->has_slice_pg));
4545 seq_printf(m, " Has Subslice Power Gating: %s\n",
4546 yesno(sseu->has_subslice_pg));
4547 seq_printf(m, " Has EU Power Gating: %s\n",
4548 yesno(sseu->has_eu_pg));
4549}
4550
Jeff McGee38732182015-02-13 10:27:54 -06004551static int i915_sseu_status(struct seq_file *m, void *unused)
4552{
David Weinehall36cdd012016-08-22 13:59:31 +03004553 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004554 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004555
David Weinehall36cdd012016-08-22 13:59:31 +03004556 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004557 return -ENODEV;
4558
4559 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004560 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004561
Jeff McGee7f992ab2015-02-13 10:27:55 -06004562 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004563 memset(&sseu, 0, sizeof(sseu));
Lionel Landwerlin8cc76692018-03-06 12:28:52 +00004564 sseu.max_slices = INTEL_INFO(dev_priv)->sseu.max_slices;
4565 sseu.max_subslices = INTEL_INFO(dev_priv)->sseu.max_subslices;
4566 sseu.max_eus_per_subslice =
4567 INTEL_INFO(dev_priv)->sseu.max_eus_per_subslice;
David Weinehall238010e2016-08-01 17:33:27 +03004568
4569 intel_runtime_pm_get(dev_priv);
4570
David Weinehall36cdd012016-08-22 13:59:31 +03004571 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004572 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004573 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004574 broadwell_sseu_device_status(dev_priv, &sseu);
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004575 } else if (IS_GEN9(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004576 gen9_sseu_device_status(dev_priv, &sseu);
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004577 } else if (INTEL_GEN(dev_priv) >= 10) {
4578 gen10_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004579 }
David Weinehall238010e2016-08-01 17:33:27 +03004580
4581 intel_runtime_pm_put(dev_priv);
4582
Imre Deak615d8902016-08-31 19:13:03 +03004583 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004584
Jeff McGee38732182015-02-13 10:27:54 -06004585 return 0;
4586}
4587
Ben Widawsky6d794d42011-04-25 11:25:56 -07004588static int i915_forcewake_open(struct inode *inode, struct file *file)
4589{
Chris Wilsond7a133d2017-09-07 14:44:41 +01004590 struct drm_i915_private *i915 = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004591
Chris Wilsond7a133d2017-09-07 14:44:41 +01004592 if (INTEL_GEN(i915) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004593 return 0;
4594
Chris Wilsond7a133d2017-09-07 14:44:41 +01004595 intel_runtime_pm_get(i915);
4596 intel_uncore_forcewake_user_get(i915);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004597
4598 return 0;
4599}
4600
Ben Widawskyc43b5632012-04-16 14:07:40 -07004601static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004602{
Chris Wilsond7a133d2017-09-07 14:44:41 +01004603 struct drm_i915_private *i915 = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004604
Chris Wilsond7a133d2017-09-07 14:44:41 +01004605 if (INTEL_GEN(i915) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004606 return 0;
4607
Chris Wilsond7a133d2017-09-07 14:44:41 +01004608 intel_uncore_forcewake_user_put(i915);
4609 intel_runtime_pm_put(i915);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004610
4611 return 0;
4612}
4613
4614static const struct file_operations i915_forcewake_fops = {
4615 .owner = THIS_MODULE,
4616 .open = i915_forcewake_open,
4617 .release = i915_forcewake_release,
4618};
4619
Lyude317eaa92017-02-03 21:18:25 -05004620static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4621{
4622 struct drm_i915_private *dev_priv = m->private;
4623 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4624
4625 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4626 seq_printf(m, "Detected: %s\n",
4627 yesno(delayed_work_pending(&hotplug->reenable_work)));
4628
4629 return 0;
4630}
4631
4632static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4633 const char __user *ubuf, size_t len,
4634 loff_t *offp)
4635{
4636 struct seq_file *m = file->private_data;
4637 struct drm_i915_private *dev_priv = m->private;
4638 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4639 unsigned int new_threshold;
4640 int i;
4641 char *newline;
4642 char tmp[16];
4643
4644 if (len >= sizeof(tmp))
4645 return -EINVAL;
4646
4647 if (copy_from_user(tmp, ubuf, len))
4648 return -EFAULT;
4649
4650 tmp[len] = '\0';
4651
4652 /* Strip newline, if any */
4653 newline = strchr(tmp, '\n');
4654 if (newline)
4655 *newline = '\0';
4656
4657 if (strcmp(tmp, "reset") == 0)
4658 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4659 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4660 return -EINVAL;
4661
4662 if (new_threshold > 0)
4663 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4664 new_threshold);
4665 else
4666 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4667
4668 spin_lock_irq(&dev_priv->irq_lock);
4669 hotplug->hpd_storm_threshold = new_threshold;
4670 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4671 for_each_hpd_pin(i)
4672 hotplug->stats[i].count = 0;
4673 spin_unlock_irq(&dev_priv->irq_lock);
4674
4675 /* Re-enable hpd immediately if we were in an irq storm */
4676 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4677
4678 return len;
4679}
4680
4681static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4682{
4683 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4684}
4685
4686static const struct file_operations i915_hpd_storm_ctl_fops = {
4687 .owner = THIS_MODULE,
4688 .open = i915_hpd_storm_ctl_open,
4689 .read = seq_read,
4690 .llseek = seq_lseek,
4691 .release = single_release,
4692 .write = i915_hpd_storm_ctl_write
4693};
4694
C, Ramalingam35954e82017-11-08 00:08:23 +05304695static int i915_drrs_ctl_set(void *data, u64 val)
4696{
4697 struct drm_i915_private *dev_priv = data;
4698 struct drm_device *dev = &dev_priv->drm;
4699 struct intel_crtc *intel_crtc;
4700 struct intel_encoder *encoder;
4701 struct intel_dp *intel_dp;
4702
4703 if (INTEL_GEN(dev_priv) < 7)
4704 return -ENODEV;
4705
4706 drm_modeset_lock_all(dev);
4707 for_each_intel_crtc(dev, intel_crtc) {
4708 if (!intel_crtc->base.state->active ||
4709 !intel_crtc->config->has_drrs)
4710 continue;
4711
4712 for_each_encoder_on_crtc(dev, &intel_crtc->base, encoder) {
4713 if (encoder->type != INTEL_OUTPUT_EDP)
4714 continue;
4715
4716 DRM_DEBUG_DRIVER("Manually %sabling DRRS. %llu\n",
4717 val ? "en" : "dis", val);
4718
4719 intel_dp = enc_to_intel_dp(&encoder->base);
4720 if (val)
4721 intel_edp_drrs_enable(intel_dp,
4722 intel_crtc->config);
4723 else
4724 intel_edp_drrs_disable(intel_dp,
4725 intel_crtc->config);
4726 }
4727 }
4728 drm_modeset_unlock_all(dev);
4729
4730 return 0;
4731}
4732
4733DEFINE_SIMPLE_ATTRIBUTE(i915_drrs_ctl_fops, NULL, i915_drrs_ctl_set, "%llu\n");
4734
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004735static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004736 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004737 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004738 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004739 {"i915_gem_stolen", i915_gem_stolen_list_info },
Chris Wilsona6172a82009-02-11 14:26:38 +00004740 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004741 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004742 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004743 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004744 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004745 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07004746 {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
Oscar Mateoa8b93702017-05-10 15:04:51 +00004747 {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004748 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304749 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004750 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Michel Thierry061d06a2017-06-20 10:57:49 +01004751 {"i915_reset_info", i915_reset_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004752 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004753 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004754 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004755 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004756 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004757 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004758 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004759 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004760 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004761 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004762 {"i915_context_status", i915_context_status, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004763 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004764 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004765 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004766 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004767 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004768 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004769 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004770 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004771 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004772 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004773 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004774 {"i915_engine_info", i915_engine_info, 0},
Lionel Landwerlin79e9cd52018-03-06 12:28:54 +00004775 {"i915_rcs_topology", i915_rcs_topology, 0},
Chris Wilsonc5418a82017-10-13 21:26:19 +01004776 {"i915_shrinker_info", i915_shrinker_info, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004777 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004778 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004779 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004780 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004781 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304782 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004783 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004784};
Ben Gamari27c202a2009-07-01 22:26:52 -04004785#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004786
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004787static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004788 const char *name;
4789 const struct file_operations *fops;
4790} i915_debugfs_files[] = {
4791 {"i915_wedged", &i915_wedged_fops},
4792 {"i915_max_freq", &i915_max_freq_fops},
4793 {"i915_min_freq", &i915_min_freq_fops},
4794 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004795 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4796 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004797 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004798#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004799 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004800 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004801#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004802 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004803 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004804 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4805 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4806 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Ville Syrjälä4127dc42017-06-06 15:44:12 +03004807 {"i915_fbc_false_color", &i915_fbc_false_color_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004808 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4809 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304810 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Michał Winiarski4977a282018-03-19 10:53:40 +01004811 {"i915_guc_log_level", &i915_guc_log_level_fops},
4812 {"i915_guc_log_relay", &i915_guc_log_relay_fops},
Kumar, Maheshd2d4f392017-08-17 19:15:29 +05304813 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops},
C, Ramalingam35954e82017-11-08 00:08:23 +05304814 {"i915_ipc_status", &i915_ipc_status_fops},
4815 {"i915_drrs_ctl", &i915_drrs_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004816};
4817
Chris Wilson1dac8912016-06-24 14:00:17 +01004818int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004819{
Chris Wilson91c8a322016-07-05 10:40:23 +01004820 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004821 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004822 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004823
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004824 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4825 minor->debugfs_root, to_i915(minor->dev),
4826 &i915_forcewake_fops);
4827 if (!ent)
4828 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004829
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004830 ret = intel_pipe_crc_create(minor);
4831 if (ret)
4832 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004833
Daniel Vetter34b96742013-07-04 20:49:44 +02004834 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004835 ent = debugfs_create_file(i915_debugfs_files[i].name,
4836 S_IRUGO | S_IWUSR,
4837 minor->debugfs_root,
4838 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004839 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004840 if (!ent)
4841 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004842 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004843
Ben Gamari27c202a2009-07-01 22:26:52 -04004844 return drm_debugfs_create_files(i915_debugfs_list,
4845 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004846 minor->debugfs_root, minor);
4847}
4848
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004849struct dpcd_block {
4850 /* DPCD dump start address. */
4851 unsigned int offset;
4852 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4853 unsigned int end;
4854 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4855 size_t size;
4856 /* Only valid for eDP. */
4857 bool edp;
4858};
4859
4860static const struct dpcd_block i915_dpcd_debug[] = {
4861 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4862 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4863 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4864 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4865 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4866 { .offset = DP_SET_POWER },
4867 { .offset = DP_EDP_DPCD_REV },
4868 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4869 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4870 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4871};
4872
4873static int i915_dpcd_show(struct seq_file *m, void *data)
4874{
4875 struct drm_connector *connector = m->private;
4876 struct intel_dp *intel_dp =
4877 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4878 uint8_t buf[16];
4879 ssize_t err;
4880 int i;
4881
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004882 if (connector->status != connector_status_connected)
4883 return -ENODEV;
4884
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004885 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4886 const struct dpcd_block *b = &i915_dpcd_debug[i];
4887 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4888
4889 if (b->edp &&
4890 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4891 continue;
4892
4893 /* low tech for now */
4894 if (WARN_ON(size > sizeof(buf)))
4895 continue;
4896
4897 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4898 if (err <= 0) {
4899 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4900 size, b->offset, err);
4901 continue;
4902 }
4903
4904 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004905 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004906
4907 return 0;
4908}
Andy Shevchenkoe4006712018-03-16 16:12:13 +02004909DEFINE_SHOW_ATTRIBUTE(i915_dpcd);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004910
David Weinehallecbd6782016-08-23 12:23:56 +03004911static int i915_panel_show(struct seq_file *m, void *data)
4912{
4913 struct drm_connector *connector = m->private;
4914 struct intel_dp *intel_dp =
4915 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4916
4917 if (connector->status != connector_status_connected)
4918 return -ENODEV;
4919
4920 seq_printf(m, "Panel power up delay: %d\n",
4921 intel_dp->panel_power_up_delay);
4922 seq_printf(m, "Panel power down delay: %d\n",
4923 intel_dp->panel_power_down_delay);
4924 seq_printf(m, "Backlight on delay: %d\n",
4925 intel_dp->backlight_on_delay);
4926 seq_printf(m, "Backlight off delay: %d\n",
4927 intel_dp->backlight_off_delay);
4928
4929 return 0;
4930}
Andy Shevchenkoe4006712018-03-16 16:12:13 +02004931DEFINE_SHOW_ATTRIBUTE(i915_panel);
David Weinehallecbd6782016-08-23 12:23:56 +03004932
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004933/**
4934 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4935 * @connector: pointer to a registered drm_connector
4936 *
4937 * Cleanup will be done by drm_connector_unregister() through a call to
4938 * drm_debugfs_connector_remove().
4939 *
4940 * Returns 0 on success, negative error codes on error.
4941 */
4942int i915_debugfs_connector_add(struct drm_connector *connector)
4943{
4944 struct dentry *root = connector->debugfs_entry;
4945
4946 /* The connector must have been registered beforehands. */
4947 if (!root)
4948 return -ENODEV;
4949
4950 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4951 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03004952 debugfs_create_file("i915_dpcd", S_IRUGO, root,
4953 connector, &i915_dpcd_fops);
4954
4955 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4956 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
4957 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004958
4959 return 0;
4960}