blob: 2bdce9fea6717e4731e295e785f148b9f2a68827 [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,
Chris Wilson37811fc2010-08-25 22:45:57 +0100153 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100154 obj->base.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;
522 struct drm_i915_gem_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,
539 struct drm_i915_gem_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
Ben Gamari20172632009-02-17 20:08:50 -0500649static int i915_interrupt_info(struct seq_file *m, void *data)
650{
David Weinehall36cdd012016-08-22 13:59:31 +0300651 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000652 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530653 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100654 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100655
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200656 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500657
David Weinehall36cdd012016-08-22 13:59:31 +0300658 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300659 seq_printf(m, "Master Interrupt Control:\t%08x\n",
660 I915_READ(GEN8_MASTER_IRQ));
661
662 seq_printf(m, "Display IER:\t%08x\n",
663 I915_READ(VLV_IER));
664 seq_printf(m, "Display IIR:\t%08x\n",
665 I915_READ(VLV_IIR));
666 seq_printf(m, "Display IIR_RW:\t%08x\n",
667 I915_READ(VLV_IIR_RW));
668 seq_printf(m, "Display IMR:\t%08x\n",
669 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100670 for_each_pipe(dev_priv, pipe) {
671 enum intel_display_power_domain power_domain;
672
673 power_domain = POWER_DOMAIN_PIPE(pipe);
674 if (!intel_display_power_get_if_enabled(dev_priv,
675 power_domain)) {
676 seq_printf(m, "Pipe %c power disabled\n",
677 pipe_name(pipe));
678 continue;
679 }
680
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300681 seq_printf(m, "Pipe %c stat:\t%08x\n",
682 pipe_name(pipe),
683 I915_READ(PIPESTAT(pipe)));
684
Chris Wilson9c870d02016-10-24 13:42:15 +0100685 intel_display_power_put(dev_priv, power_domain);
686 }
687
688 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300689 seq_printf(m, "Port hotplug:\t%08x\n",
690 I915_READ(PORT_HOTPLUG_EN));
691 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
692 I915_READ(VLV_DPFLIPSTAT));
693 seq_printf(m, "DPINVGTT:\t%08x\n",
694 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100695 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300696
697 for (i = 0; i < 4; i++) {
698 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
699 i, I915_READ(GEN8_GT_IMR(i)));
700 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
701 i, I915_READ(GEN8_GT_IIR(i)));
702 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
703 i, I915_READ(GEN8_GT_IER(i)));
704 }
705
706 seq_printf(m, "PCU interrupt mask:\t%08x\n",
707 I915_READ(GEN8_PCU_IMR));
708 seq_printf(m, "PCU interrupt identity:\t%08x\n",
709 I915_READ(GEN8_PCU_IIR));
710 seq_printf(m, "PCU interrupt enable:\t%08x\n",
711 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300712 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700713 seq_printf(m, "Master Interrupt Control:\t%08x\n",
714 I915_READ(GEN8_MASTER_IRQ));
715
716 for (i = 0; i < 4; i++) {
717 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
718 i, I915_READ(GEN8_GT_IMR(i)));
719 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
720 i, I915_READ(GEN8_GT_IIR(i)));
721 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
722 i, I915_READ(GEN8_GT_IER(i)));
723 }
724
Damien Lespiau055e3932014-08-18 13:49:10 +0100725 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200726 enum intel_display_power_domain power_domain;
727
728 power_domain = POWER_DOMAIN_PIPE(pipe);
729 if (!intel_display_power_get_if_enabled(dev_priv,
730 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300731 seq_printf(m, "Pipe %c power disabled\n",
732 pipe_name(pipe));
733 continue;
734 }
Ben Widawskya123f152013-11-02 21:07:10 -0700735 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000736 pipe_name(pipe),
737 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700738 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000739 pipe_name(pipe),
740 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700741 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000742 pipe_name(pipe),
743 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200744
745 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700746 }
747
748 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
749 I915_READ(GEN8_DE_PORT_IMR));
750 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
751 I915_READ(GEN8_DE_PORT_IIR));
752 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
753 I915_READ(GEN8_DE_PORT_IER));
754
755 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
756 I915_READ(GEN8_DE_MISC_IMR));
757 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
758 I915_READ(GEN8_DE_MISC_IIR));
759 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
760 I915_READ(GEN8_DE_MISC_IER));
761
762 seq_printf(m, "PCU interrupt mask:\t%08x\n",
763 I915_READ(GEN8_PCU_IMR));
764 seq_printf(m, "PCU interrupt identity:\t%08x\n",
765 I915_READ(GEN8_PCU_IIR));
766 seq_printf(m, "PCU interrupt enable:\t%08x\n",
767 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300768 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700769 seq_printf(m, "Display IER:\t%08x\n",
770 I915_READ(VLV_IER));
771 seq_printf(m, "Display IIR:\t%08x\n",
772 I915_READ(VLV_IIR));
773 seq_printf(m, "Display IIR_RW:\t%08x\n",
774 I915_READ(VLV_IIR_RW));
775 seq_printf(m, "Display IMR:\t%08x\n",
776 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000777 for_each_pipe(dev_priv, pipe) {
778 enum intel_display_power_domain power_domain;
779
780 power_domain = POWER_DOMAIN_PIPE(pipe);
781 if (!intel_display_power_get_if_enabled(dev_priv,
782 power_domain)) {
783 seq_printf(m, "Pipe %c power disabled\n",
784 pipe_name(pipe));
785 continue;
786 }
787
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700788 seq_printf(m, "Pipe %c stat:\t%08x\n",
789 pipe_name(pipe),
790 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000791 intel_display_power_put(dev_priv, power_domain);
792 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700793
794 seq_printf(m, "Master IER:\t%08x\n",
795 I915_READ(VLV_MASTER_IER));
796
797 seq_printf(m, "Render IER:\t%08x\n",
798 I915_READ(GTIER));
799 seq_printf(m, "Render IIR:\t%08x\n",
800 I915_READ(GTIIR));
801 seq_printf(m, "Render IMR:\t%08x\n",
802 I915_READ(GTIMR));
803
804 seq_printf(m, "PM IER:\t\t%08x\n",
805 I915_READ(GEN6_PMIER));
806 seq_printf(m, "PM IIR:\t\t%08x\n",
807 I915_READ(GEN6_PMIIR));
808 seq_printf(m, "PM IMR:\t\t%08x\n",
809 I915_READ(GEN6_PMIMR));
810
811 seq_printf(m, "Port hotplug:\t%08x\n",
812 I915_READ(PORT_HOTPLUG_EN));
813 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
814 I915_READ(VLV_DPFLIPSTAT));
815 seq_printf(m, "DPINVGTT:\t%08x\n",
816 I915_READ(DPINVGTT));
817
David Weinehall36cdd012016-08-22 13:59:31 +0300818 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800819 seq_printf(m, "Interrupt enable: %08x\n",
820 I915_READ(IER));
821 seq_printf(m, "Interrupt identity: %08x\n",
822 I915_READ(IIR));
823 seq_printf(m, "Interrupt mask: %08x\n",
824 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100825 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800826 seq_printf(m, "Pipe %c stat: %08x\n",
827 pipe_name(pipe),
828 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800829 } else {
830 seq_printf(m, "North Display Interrupt enable: %08x\n",
831 I915_READ(DEIER));
832 seq_printf(m, "North Display Interrupt identity: %08x\n",
833 I915_READ(DEIIR));
834 seq_printf(m, "North Display Interrupt mask: %08x\n",
835 I915_READ(DEIMR));
836 seq_printf(m, "South Display Interrupt enable: %08x\n",
837 I915_READ(SDEIER));
838 seq_printf(m, "South Display Interrupt identity: %08x\n",
839 I915_READ(SDEIIR));
840 seq_printf(m, "South Display Interrupt mask: %08x\n",
841 I915_READ(SDEIMR));
842 seq_printf(m, "Graphics Interrupt enable: %08x\n",
843 I915_READ(GTIER));
844 seq_printf(m, "Graphics Interrupt identity: %08x\n",
845 I915_READ(GTIIR));
846 seq_printf(m, "Graphics Interrupt mask: %08x\n",
847 I915_READ(GTIMR));
848 }
Chris Wilsond5acadf2017-12-09 10:44:18 +0000849 if (INTEL_GEN(dev_priv) >= 6) {
850 for_each_engine(engine, dev_priv, id) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100851 seq_printf(m,
852 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000853 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000854 }
Chris Wilson9862e602011-01-04 22:22:17 +0000855 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200856 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100857
Ben Gamari20172632009-02-17 20:08:50 -0500858 return 0;
859}
860
Chris Wilsona6172a82009-02-11 14:26:38 +0000861static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
862{
David Weinehall36cdd012016-08-22 13:59:31 +0300863 struct drm_i915_private *dev_priv = node_to_i915(m->private);
864 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100865 int i, ret;
866
867 ret = mutex_lock_interruptible(&dev->struct_mutex);
868 if (ret)
869 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000870
Chris Wilsona6172a82009-02-11 14:26:38 +0000871 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
872 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100873 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000874
Chris Wilson6c085a72012-08-20 11:40:46 +0200875 seq_printf(m, "Fence %d, pin count = %d, object = ",
876 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100877 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100878 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100879 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100880 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100881 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000882 }
883
Chris Wilson05394f32010-11-08 19:18:58 +0000884 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000885 return 0;
886}
887
Chris Wilson98a2f412016-10-12 10:05:18 +0100888#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000889static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
890 size_t count, loff_t *pos)
891{
892 struct i915_gpu_state *error = file->private_data;
893 struct drm_i915_error_state_buf str;
894 ssize_t ret;
895 loff_t tmp;
896
897 if (!error)
898 return 0;
899
900 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
901 if (ret)
902 return ret;
903
904 ret = i915_error_state_to_str(&str, error);
905 if (ret)
906 goto out;
907
908 tmp = 0;
909 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
910 if (ret < 0)
911 goto out;
912
913 *pos = str.start + ret;
914out:
915 i915_error_state_buf_release(&str);
916 return ret;
917}
918
919static int gpu_state_release(struct inode *inode, struct file *file)
920{
921 i915_gpu_state_put(file->private_data);
922 return 0;
923}
924
925static int i915_gpu_info_open(struct inode *inode, struct file *file)
926{
Chris Wilson090e5fe2017-03-28 14:14:07 +0100927 struct drm_i915_private *i915 = inode->i_private;
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000928 struct i915_gpu_state *gpu;
929
Chris Wilson090e5fe2017-03-28 14:14:07 +0100930 intel_runtime_pm_get(i915);
931 gpu = i915_capture_gpu_state(i915);
932 intel_runtime_pm_put(i915);
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000933 if (!gpu)
934 return -ENOMEM;
935
936 file->private_data = gpu;
937 return 0;
938}
939
940static const struct file_operations i915_gpu_info_fops = {
941 .owner = THIS_MODULE,
942 .open = i915_gpu_info_open,
943 .read = gpu_state_read,
944 .llseek = default_llseek,
945 .release = gpu_state_release,
946};
Chris Wilson98a2f412016-10-12 10:05:18 +0100947
Daniel Vetterd5442302012-04-27 15:17:40 +0200948static ssize_t
949i915_error_state_write(struct file *filp,
950 const char __user *ubuf,
951 size_t cnt,
952 loff_t *ppos)
953{
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000954 struct i915_gpu_state *error = filp->private_data;
955
956 if (!error)
957 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200958
959 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000960 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +0200961
962 return cnt;
963}
964
965static int i915_error_state_open(struct inode *inode, struct file *file)
966{
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000967 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300968 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200969}
970
Daniel Vetterd5442302012-04-27 15:17:40 +0200971static const struct file_operations i915_error_state_fops = {
972 .owner = THIS_MODULE,
973 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000974 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200975 .write = i915_error_state_write,
976 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000977 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +0200978};
Chris Wilson98a2f412016-10-12 10:05:18 +0100979#endif
980
Kees Cook647416f2013-03-10 14:10:06 -0700981static int
Kees Cook647416f2013-03-10 14:10:06 -0700982i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200983{
David Weinehall36cdd012016-08-22 13:59:31 +0300984 struct drm_i915_private *dev_priv = data;
985 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +0200986 int ret;
987
Mika Kuoppala40633212012-12-04 15:12:00 +0200988 ret = mutex_lock_interruptible(&dev->struct_mutex);
989 if (ret)
990 return ret;
991
Chris Wilson65c475c2018-01-02 15:12:31 +0000992 intel_runtime_pm_get(dev_priv);
Chris Wilson73cb9702016-10-28 13:58:46 +0100993 ret = i915_gem_set_global_seqno(dev, val);
Chris Wilson65c475c2018-01-02 15:12:31 +0000994 intel_runtime_pm_put(dev_priv);
995
Mika Kuoppala40633212012-12-04 15:12:00 +0200996 mutex_unlock(&dev->struct_mutex);
997
Kees Cook647416f2013-03-10 14:10:06 -0700998 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200999}
1000
Kees Cook647416f2013-03-10 14:10:06 -07001001DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001002 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001003 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001004
Deepak Sadb4bd12014-03-31 11:30:02 +05301005static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001006{
David Weinehall36cdd012016-08-22 13:59:31 +03001007 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001008 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001009 int ret = 0;
1010
1011 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001012
David Weinehall36cdd012016-08-22 13:59:31 +03001013 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001014 u16 rgvswctl = I915_READ16(MEMSWCTL);
1015 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1016
1017 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1018 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1019 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1020 MEMSTAT_VID_SHIFT);
1021 seq_printf(m, "Current P-state: %d\n",
1022 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001023 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001024 u32 rpmodectl, freq_sts;
Wayne Boyer666a4532015-12-09 12:29:35 -08001025
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001026 mutex_lock(&dev_priv->pcu_lock);
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001027
1028 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1029 seq_printf(m, "Video Turbo Mode: %s\n",
1030 yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
1031 seq_printf(m, "HW control enabled: %s\n",
1032 yesno(rpmodectl & GEN6_RP_ENABLE));
1033 seq_printf(m, "SW control enabled: %s\n",
1034 yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
1035 GEN6_RP_MEDIA_SW_MODE));
1036
Wayne Boyer666a4532015-12-09 12:29:35 -08001037 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1038 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1039 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1040
1041 seq_printf(m, "actual GPU freq: %d MHz\n",
1042 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1043
1044 seq_printf(m, "current GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001045 intel_gpu_freq(dev_priv, rps->cur_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001046
1047 seq_printf(m, "max GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001048 intel_gpu_freq(dev_priv, rps->max_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001049
1050 seq_printf(m, "min GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001051 intel_gpu_freq(dev_priv, rps->min_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001052
1053 seq_printf(m, "idle GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001054 intel_gpu_freq(dev_priv, rps->idle_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001055
1056 seq_printf(m,
1057 "efficient (RPe) frequency: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001058 intel_gpu_freq(dev_priv, rps->efficient_freq));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001059 mutex_unlock(&dev_priv->pcu_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001060 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001061 u32 rp_state_limits;
1062 u32 gt_perf_status;
1063 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001064 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001065 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001066 u32 rpupei, rpcurup, rpprevup;
1067 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001068 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001069 int max_freq;
1070
Bob Paauwe35040562015-06-25 14:54:07 -07001071 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001072 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001073 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1074 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1075 } else {
1076 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1077 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1078 }
1079
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001080 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001081 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001082
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001083 reqf = I915_READ(GEN6_RPNSWREQ);
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001084 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301085 reqf >>= 23;
1086 else {
1087 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001088 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301089 reqf >>= 24;
1090 else
1091 reqf >>= 25;
1092 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001093 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001094
Chris Wilson0d8f9492014-03-27 09:06:14 +00001095 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1096 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1097 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1098
Jesse Barnesccab5c82011-01-18 15:49:25 -08001099 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301100 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1101 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1102 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1103 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1104 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1105 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Tvrtko Ursulinc84b2702017-11-21 18:18:44 +00001106 cagf = intel_gpu_freq(dev_priv,
1107 intel_get_cagf(dev_priv, rpstat));
Jesse Barnesccab5c82011-01-18 15:49:25 -08001108
Mika Kuoppala59bad942015-01-16 11:34:40 +02001109 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001110
David Weinehall36cdd012016-08-22 13:59:31 +03001111 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001112 pm_ier = I915_READ(GEN6_PMIER);
1113 pm_imr = I915_READ(GEN6_PMIMR);
1114 pm_isr = I915_READ(GEN6_PMISR);
1115 pm_iir = I915_READ(GEN6_PMIIR);
1116 pm_mask = I915_READ(GEN6_PMINTRMSK);
1117 } else {
1118 pm_ier = I915_READ(GEN8_GT_IER(2));
1119 pm_imr = I915_READ(GEN8_GT_IMR(2));
1120 pm_isr = I915_READ(GEN8_GT_ISR(2));
1121 pm_iir = I915_READ(GEN8_GT_IIR(2));
1122 pm_mask = I915_READ(GEN6_PMINTRMSK);
1123 }
Sagar Arun Kamble960e5462017-10-10 22:29:59 +01001124 seq_printf(m, "Video Turbo Mode: %s\n",
1125 yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
1126 seq_printf(m, "HW control enabled: %s\n",
1127 yesno(rpmodectl & GEN6_RP_ENABLE));
1128 seq_printf(m, "SW control enabled: %s\n",
1129 yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
1130 GEN6_RP_MEDIA_SW_MODE));
Chris Wilson0d8f9492014-03-27 09:06:14 +00001131 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 -03001132 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301133 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001134 rps->pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001135 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001136 seq_printf(m, "Render p-state ratio: %d\n",
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001137 (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001138 seq_printf(m, "Render p-state VID: %d\n",
1139 gt_perf_status & 0xff);
1140 seq_printf(m, "Render p-state limit: %d\n",
1141 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001142 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1143 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1144 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1145 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001146 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001147 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301148 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1149 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1150 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1151 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1152 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1153 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001154 seq_printf(m, "Up threshold: %d%%\n", rps->up_threshold);
Chris Wilsond86ed342015-04-27 13:41:19 +01001155
Akash Goeld6cda9c2016-04-23 00:05:46 +05301156 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1157 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1158 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1159 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1160 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1161 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001162 seq_printf(m, "Down threshold: %d%%\n", rps->down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001163
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001164 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001165 rp_state_cap >> 16) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001166 max_freq *= (IS_GEN9_BC(dev_priv) ||
1167 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001168 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001169 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001170
1171 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001172 max_freq *= (IS_GEN9_BC(dev_priv) ||
1173 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001174 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001175 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001176
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001177 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001178 rp_state_cap >> 0) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001179 max_freq *= (IS_GEN9_BC(dev_priv) ||
1180 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001181 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001182 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001183 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001184 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001185
Chris Wilsond86ed342015-04-27 13:41:19 +01001186 seq_printf(m, "Current freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001187 intel_gpu_freq(dev_priv, rps->cur_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001188 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001189 seq_printf(m, "Idle freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001190 intel_gpu_freq(dev_priv, rps->idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001191 seq_printf(m, "Min freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001192 intel_gpu_freq(dev_priv, rps->min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001193 seq_printf(m, "Boost freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001194 intel_gpu_freq(dev_priv, rps->boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001195 seq_printf(m, "Max freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001196 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001197 seq_printf(m,
1198 "efficient (RPe) frequency: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001199 intel_gpu_freq(dev_priv, rps->efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001200 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001201 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001202 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001203
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001204 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001205 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1206 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1207
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001208 intel_runtime_pm_put(dev_priv);
1209 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001210}
1211
Ben Widawskyd6369512016-09-20 16:54:32 +03001212static void i915_instdone_info(struct drm_i915_private *dev_priv,
1213 struct seq_file *m,
1214 struct intel_instdone *instdone)
1215{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001216 int slice;
1217 int subslice;
1218
Ben Widawskyd6369512016-09-20 16:54:32 +03001219 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1220 instdone->instdone);
1221
1222 if (INTEL_GEN(dev_priv) <= 3)
1223 return;
1224
1225 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1226 instdone->slice_common);
1227
1228 if (INTEL_GEN(dev_priv) <= 6)
1229 return;
1230
Ben Widawskyf9e61372016-09-20 16:54:33 +03001231 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1232 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1233 slice, subslice, instdone->sampler[slice][subslice]);
1234
1235 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1236 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1237 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001238}
1239
Chris Wilsonf6544492015-01-26 18:03:04 +02001240static int i915_hangcheck_info(struct seq_file *m, void *unused)
1241{
David Weinehall36cdd012016-08-22 13:59:31 +03001242 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001243 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001244 u64 acthd[I915_NUM_ENGINES];
1245 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001246 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001247 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001248
Chris Wilson8af29b02016-09-09 14:11:47 +01001249 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001250 seq_puts(m, "Wedged\n");
1251 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1252 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1253 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1254 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001255 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001256 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001257 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001258 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001259
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001260 if (!i915_modparams.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001261 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001262 return 0;
1263 }
1264
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001265 intel_runtime_pm_get(dev_priv);
1266
Akash Goel3b3f1652016-10-13 22:44:48 +05301267 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001268 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001269 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001270 }
1271
Akash Goel3b3f1652016-10-13 22:44:48 +05301272 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001273
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001274 intel_runtime_pm_put(dev_priv);
1275
Chris Wilson8352aea2017-03-03 09:00:56 +00001276 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1277 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001278 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1279 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001280 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1281 seq_puts(m, "Hangcheck active, work pending\n");
1282 else
1283 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001284
Chris Wilsonf73b5672017-03-02 15:03:56 +00001285 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1286
Akash Goel3b3f1652016-10-13 22:44:48 +05301287 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001288 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1289 struct rb_node *rb;
1290
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001291 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001292 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001293 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001294 intel_engine_last_submit(engine),
1295 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001296 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001297 yesno(intel_engine_has_waiter(engine)),
1298 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001299 &dev_priv->gpu_error.missed_irq_rings)),
1300 yesno(engine->hangcheck.stalled));
1301
Chris Wilson61d3dc72017-03-03 19:08:24 +00001302 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001303 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001304 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001305
1306 seq_printf(m, "\t%s [%d] waiting for %x\n",
1307 w->tsk->comm, w->tsk->pid, w->seqno);
1308 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001309 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001310
Chris Wilsonf6544492015-01-26 18:03:04 +02001311 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001312 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001313 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001314 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1315 hangcheck_action_to_str(engine->hangcheck.action),
1316 engine->hangcheck.action,
1317 jiffies_to_msecs(jiffies -
1318 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001319
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001320 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001321 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001322
Ben Widawskyd6369512016-09-20 16:54:32 +03001323 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001324
Ben Widawskyd6369512016-09-20 16:54:32 +03001325 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001326
Ben Widawskyd6369512016-09-20 16:54:32 +03001327 i915_instdone_info(dev_priv, m,
1328 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001329 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001330 }
1331
1332 return 0;
1333}
1334
Michel Thierry061d06a2017-06-20 10:57:49 +01001335static int i915_reset_info(struct seq_file *m, void *unused)
1336{
1337 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1338 struct i915_gpu_error *error = &dev_priv->gpu_error;
1339 struct intel_engine_cs *engine;
1340 enum intel_engine_id id;
1341
1342 seq_printf(m, "full gpu reset = %u\n", i915_reset_count(error));
1343
1344 for_each_engine(engine, dev_priv, id) {
1345 seq_printf(m, "%s = %u\n", engine->name,
1346 i915_reset_engine_count(error, engine));
1347 }
1348
1349 return 0;
1350}
1351
Ben Widawsky4d855292011-12-12 19:34:16 -08001352static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001353{
David Weinehall36cdd012016-08-22 13:59:31 +03001354 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001355 u32 rgvmodectl, rstdbyctl;
1356 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001357
Ben Widawsky616fdb52011-10-05 11:44:54 -07001358 rgvmodectl = I915_READ(MEMMODECTL);
1359 rstdbyctl = I915_READ(RSTDBYCTL);
1360 crstandvid = I915_READ16(CRSTANDVID);
1361
Jani Nikula742f4912015-09-03 11:16:09 +03001362 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001363 seq_printf(m, "Boost freq: %d\n",
1364 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1365 MEMMODE_BOOST_FREQ_SHIFT);
1366 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001367 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001368 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001369 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001370 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001371 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001372 seq_printf(m, "Starting frequency: P%d\n",
1373 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001374 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001375 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001376 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1377 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1378 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1379 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001380 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001381 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001382 switch (rstdbyctl & RSX_STATUS_MASK) {
1383 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001384 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001385 break;
1386 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001387 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001388 break;
1389 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001390 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001391 break;
1392 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001393 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001394 break;
1395 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001396 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001397 break;
1398 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001399 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001400 break;
1401 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001402 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001403 break;
1404 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001405
1406 return 0;
1407}
1408
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001409static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001410{
Chris Wilson233ebf52017-03-23 10:19:44 +00001411 struct drm_i915_private *i915 = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001412 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsond2dc94b2017-03-23 10:19:41 +00001413 unsigned int tmp;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001414
Chris Wilsond7a133d2017-09-07 14:44:41 +01001415 seq_printf(m, "user.bypass_count = %u\n",
1416 i915->uncore.user_forcewake.count);
1417
Chris Wilson233ebf52017-03-23 10:19:44 +00001418 for_each_fw_domain(fw_domain, i915, tmp)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001419 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001420 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilson233ebf52017-03-23 10:19:44 +00001421 READ_ONCE(fw_domain->wake_count));
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001422
1423 return 0;
1424}
1425
Mika Kuoppala13628772017-03-15 17:43:02 +02001426static void print_rc6_res(struct seq_file *m,
1427 const char *title,
1428 const i915_reg_t reg)
1429{
1430 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1431
1432 seq_printf(m, "%s %u (%llu us)\n",
1433 title, I915_READ(reg),
1434 intel_rc6_residency_us(dev_priv, reg));
1435}
1436
Deepak S669ab5a2014-01-10 15:18:26 +05301437static int vlv_drpc_info(struct seq_file *m)
1438{
David Weinehall36cdd012016-08-22 13:59:31 +03001439 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001440 u32 rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301441
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001442 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301443 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1444
Deepak S669ab5a2014-01-10 15:18:26 +05301445 seq_printf(m, "RC6 Enabled: %s\n",
1446 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1447 GEN6_RC_CTL_EI_MODE(1))));
1448 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001449 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301450 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001451 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301452
Mika Kuoppala13628772017-03-15 17:43:02 +02001453 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1454 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001455
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001456 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301457}
1458
Ben Widawsky4d855292011-12-12 19:34:16 -08001459static int gen6_drpc_info(struct seq_file *m)
1460{
David Weinehall36cdd012016-08-22 13:59:31 +03001461 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble960e5462017-10-10 22:29:59 +01001462 u32 gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301463 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001464 unsigned forcewake_count;
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001465 int count = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001466
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001467 forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001468 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001469 seq_puts(m, "RC information inaccurate because somebody "
1470 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001471 } else {
1472 /* NB: we cannot use forcewake, else we read the wrong values */
1473 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1474 udelay(10);
1475 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1476 }
1477
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001478 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001479 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001480
Ben Widawsky4d855292011-12-12 19:34:16 -08001481 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001482 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301483 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1484 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1485 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001486
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001487 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001488 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001489 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001490
Eric Anholtfff24e22012-01-23 16:14:05 -08001491 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001492 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1493 seq_printf(m, "RC6 Enabled: %s\n",
1494 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001495 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301496 seq_printf(m, "Render Well Gating Enabled: %s\n",
1497 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1498 seq_printf(m, "Media Well Gating Enabled: %s\n",
1499 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1500 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001501 seq_printf(m, "Deep RC6 Enabled: %s\n",
1502 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1503 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1504 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001505 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001506 switch (gt_core_status & GEN6_RCn_MASK) {
1507 case GEN6_RC0:
1508 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001509 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001510 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001511 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001512 break;
1513 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001514 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001515 break;
1516 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001517 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001518 break;
1519 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001520 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001521 break;
1522 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001523 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001524 break;
1525 }
1526
1527 seq_printf(m, "Core Power Down: %s\n",
1528 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001529 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301530 seq_printf(m, "Render Power Well: %s\n",
1531 (gen9_powergate_status &
1532 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1533 seq_printf(m, "Media Power Well: %s\n",
1534 (gen9_powergate_status &
1535 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1536 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001537
1538 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001539 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1540 GEN6_GT_GFX_RC6_LOCKED);
1541 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1542 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1543 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001544
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001545 seq_printf(m, "RC6 voltage: %dmV\n",
1546 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1547 seq_printf(m, "RC6+ voltage: %dmV\n",
1548 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1549 seq_printf(m, "RC6++ voltage: %dmV\n",
1550 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301551 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001552}
1553
1554static int i915_drpc_info(struct seq_file *m, void *unused)
1555{
David Weinehall36cdd012016-08-22 13:59:31 +03001556 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001557 int err;
1558
1559 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001560
David Weinehall36cdd012016-08-22 13:59:31 +03001561 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001562 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001563 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001564 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001566 err = ironlake_drpc_info(m);
1567
1568 intel_runtime_pm_put(dev_priv);
1569
1570 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001571}
1572
Daniel Vetter9a851782015-06-18 10:30:22 +02001573static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1574{
David Weinehall36cdd012016-08-22 13:59:31 +03001575 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001576
1577 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1578 dev_priv->fb_tracking.busy_bits);
1579
1580 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1581 dev_priv->fb_tracking.flip_bits);
1582
1583 return 0;
1584}
1585
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001586static int i915_fbc_status(struct seq_file *m, void *unused)
1587{
David Weinehall36cdd012016-08-22 13:59:31 +03001588 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson31388722017-12-20 20:58:48 +00001589 struct intel_fbc *fbc = &dev_priv->fbc;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001590
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00001591 if (!HAS_FBC(dev_priv))
1592 return -ENODEV;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001593
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001594 intel_runtime_pm_get(dev_priv);
Chris Wilson31388722017-12-20 20:58:48 +00001595 mutex_lock(&fbc->lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001596
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001597 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001599 else
Chris Wilson31388722017-12-20 20:58:48 +00001600 seq_printf(m, "FBC disabled: %s\n", fbc->no_fbc_reason);
1601
1602 if (fbc->work.scheduled)
1603 seq_printf(m, "FBC worker scheduled on vblank %u, now %llu\n",
1604 fbc->work.scheduled_vblank,
1605 drm_crtc_vblank_count(&fbc->crtc->base));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001606
Ville Syrjälä3fd5d1e2017-06-06 15:43:18 +03001607 if (intel_fbc_is_active(dev_priv)) {
1608 u32 mask;
1609
1610 if (INTEL_GEN(dev_priv) >= 8)
1611 mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
1612 else if (INTEL_GEN(dev_priv) >= 7)
1613 mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
1614 else if (INTEL_GEN(dev_priv) >= 5)
1615 mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
1616 else if (IS_G4X(dev_priv))
1617 mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
1618 else
1619 mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
1620 FBC_STAT_COMPRESSED);
1621
1622 seq_printf(m, "Compressing: %s\n", yesno(mask));
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001623 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001624
Chris Wilson31388722017-12-20 20:58:48 +00001625 mutex_unlock(&fbc->lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001626 intel_runtime_pm_put(dev_priv);
1627
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001628 return 0;
1629}
1630
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001631static int i915_fbc_false_color_get(void *data, u64 *val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001632{
David Weinehall36cdd012016-08-22 13:59:31 +03001633 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001634
David Weinehall36cdd012016-08-22 13:59:31 +03001635 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001636 return -ENODEV;
1637
Rodrigo Vivida46f932014-08-01 02:04:45 -07001638 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001639
1640 return 0;
1641}
1642
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001643static int i915_fbc_false_color_set(void *data, u64 val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001644{
David Weinehall36cdd012016-08-22 13:59:31 +03001645 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001646 u32 reg;
1647
David Weinehall36cdd012016-08-22 13:59:31 +03001648 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001649 return -ENODEV;
1650
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001651 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001652
1653 reg = I915_READ(ILK_DPFC_CONTROL);
1654 dev_priv->fbc.false_color = val;
1655
1656 I915_WRITE(ILK_DPFC_CONTROL, val ?
1657 (reg | FBC_CTL_FALSE_COLOR) :
1658 (reg & ~FBC_CTL_FALSE_COLOR));
1659
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001660 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001661 return 0;
1662}
1663
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001664DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
1665 i915_fbc_false_color_get, i915_fbc_false_color_set,
Rodrigo Vivida46f932014-08-01 02:04:45 -07001666 "%llu\n");
1667
Paulo Zanoni92d44622013-05-31 16:33:24 -03001668static int i915_ips_status(struct seq_file *m, void *unused)
1669{
David Weinehall36cdd012016-08-22 13:59:31 +03001670 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001671
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00001672 if (!HAS_IPS(dev_priv))
1673 return -ENODEV;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001674
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001675 intel_runtime_pm_get(dev_priv);
1676
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001677 seq_printf(m, "Enabled by kernel parameter: %s\n",
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001678 yesno(i915_modparams.enable_ips));
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001679
David Weinehall36cdd012016-08-22 13:59:31 +03001680 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001681 seq_puts(m, "Currently: unknown\n");
1682 } else {
1683 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1684 seq_puts(m, "Currently: enabled\n");
1685 else
1686 seq_puts(m, "Currently: disabled\n");
1687 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001688
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001689 intel_runtime_pm_put(dev_priv);
1690
Paulo Zanoni92d44622013-05-31 16:33:24 -03001691 return 0;
1692}
1693
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001694static int i915_sr_status(struct seq_file *m, void *unused)
1695{
David Weinehall36cdd012016-08-22 13:59:31 +03001696 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001697 bool sr_enabled = false;
1698
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001699 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001700 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001701
Chris Wilson7342a722017-03-09 14:20:49 +00001702 if (INTEL_GEN(dev_priv) >= 9)
1703 /* no global SR status; inspect per-plane WM */;
1704 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001705 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001706 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001707 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001708 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001709 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001710 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001711 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001712 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001713 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001714 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001715
Chris Wilson9c870d02016-10-24 13:42:15 +01001716 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001717 intel_runtime_pm_put(dev_priv);
1718
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001719 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001720
1721 return 0;
1722}
1723
Jesse Barnes7648fa92010-05-20 14:28:11 -07001724static int i915_emon_status(struct seq_file *m, void *unused)
1725{
David Weinehall36cdd012016-08-22 13:59:31 +03001726 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1727 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001728 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001729 int ret;
1730
David Weinehall36cdd012016-08-22 13:59:31 +03001731 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001732 return -ENODEV;
1733
Chris Wilsonde227ef2010-07-03 07:58:38 +01001734 ret = mutex_lock_interruptible(&dev->struct_mutex);
1735 if (ret)
1736 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001737
1738 temp = i915_mch_val(dev_priv);
1739 chipset = i915_chipset_val(dev_priv);
1740 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001741 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001742
1743 seq_printf(m, "GMCH temp: %ld\n", temp);
1744 seq_printf(m, "Chipset power: %ld\n", chipset);
1745 seq_printf(m, "GFX power: %ld\n", gfx);
1746 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1747
1748 return 0;
1749}
1750
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001751static int i915_ring_freq_table(struct seq_file *m, void *unused)
1752{
David Weinehall36cdd012016-08-22 13:59:31 +03001753 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001754 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001755 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001756 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301757 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001758
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00001759 if (!HAS_LLC(dev_priv))
1760 return -ENODEV;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001761
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001762 intel_runtime_pm_get(dev_priv);
1763
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001764 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001765 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001766 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001767
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001768 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301769 /* Convert GT frequency to 50 HZ units */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001770 min_gpu_freq = rps->min_freq_softlimit / GEN9_FREQ_SCALER;
1771 max_gpu_freq = rps->max_freq_softlimit / GEN9_FREQ_SCALER;
Akash Goelf936ec32015-06-29 14:50:22 +05301772 } else {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001773 min_gpu_freq = rps->min_freq_softlimit;
1774 max_gpu_freq = rps->max_freq_softlimit;
Akash Goelf936ec32015-06-29 14:50:22 +05301775 }
1776
Damien Lespiau267f0c92013-06-24 22:59:48 +01001777 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001778
Akash Goelf936ec32015-06-29 14:50:22 +05301779 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001780 ia_freq = gpu_freq;
1781 sandybridge_pcode_read(dev_priv,
1782 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1783 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001784 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301785 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001786 (IS_GEN9_BC(dev_priv) ||
1787 IS_CANNONLAKE(dev_priv) ?
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001788 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001789 ((ia_freq >> 0) & 0xff) * 100,
1790 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001791 }
1792
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001793 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001794
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001795out:
1796 intel_runtime_pm_put(dev_priv);
1797 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001798}
1799
Chris Wilson44834a62010-08-19 16:09:23 +01001800static int i915_opregion(struct seq_file *m, void *unused)
1801{
David Weinehall36cdd012016-08-22 13:59:31 +03001802 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1803 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001804 struct intel_opregion *opregion = &dev_priv->opregion;
1805 int ret;
1806
1807 ret = mutex_lock_interruptible(&dev->struct_mutex);
1808 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001809 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001810
Jani Nikula2455a8e2015-12-14 12:50:53 +02001811 if (opregion->header)
1812 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001813
1814 mutex_unlock(&dev->struct_mutex);
1815
Daniel Vetter0d38f002012-04-21 22:49:10 +02001816out:
Chris Wilson44834a62010-08-19 16:09:23 +01001817 return 0;
1818}
1819
Jani Nikulaada8f952015-12-15 13:17:12 +02001820static int i915_vbt(struct seq_file *m, void *unused)
1821{
David Weinehall36cdd012016-08-22 13:59:31 +03001822 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001823
1824 if (opregion->vbt)
1825 seq_write(m, opregion->vbt, opregion->vbt_size);
1826
1827 return 0;
1828}
1829
Chris Wilson37811fc2010-08-25 22:45:57 +01001830static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1831{
David Weinehall36cdd012016-08-22 13:59:31 +03001832 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1833 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301834 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001835 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001836 int ret;
1837
1838 ret = mutex_lock_interruptible(&dev->struct_mutex);
1839 if (ret)
1840 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001841
Daniel Vetter06957262015-08-10 13:34:08 +02001842#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter346fb4e2017-07-06 15:00:20 +02001843 if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
David Weinehall36cdd012016-08-22 13:59:31 +03001844 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001845
Chris Wilson25bcce92016-07-02 15:36:00 +01001846 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1847 fbdev_fb->base.width,
1848 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001849 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001850 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001851 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001852 drm_framebuffer_read_refcount(&fbdev_fb->base));
1853 describe_obj(m, fbdev_fb->obj);
1854 seq_putc(m, '\n');
1855 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001856#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001857
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001858 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001859 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301860 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1861 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001862 continue;
1863
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001864 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 +01001865 fb->base.width,
1866 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001867 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001868 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001869 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001870 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001871 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001872 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001873 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001874 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001875 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001876
1877 return 0;
1878}
1879
Chris Wilson7e37f882016-08-02 22:50:21 +01001880static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001881{
Chris Wilsonfe085f12017-03-21 10:25:52 +00001882 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u)",
1883 ring->space, ring->head, ring->tail);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001884}
1885
Ben Widawskye76d3632011-03-19 18:14:29 -07001886static int i915_context_status(struct seq_file *m, void *unused)
1887{
David Weinehall36cdd012016-08-22 13:59:31 +03001888 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1889 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001890 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001891 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301892 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001893 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001894
Daniel Vetterf3d28872014-05-29 23:23:08 +02001895 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001896 if (ret)
1897 return ret;
1898
Chris Wilson829a0af2017-06-20 12:05:45 +01001899 list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001900 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001901 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001902 struct task_struct *task;
1903
Chris Wilsonc84455b2016-08-15 10:49:08 +01001904 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001905 if (task) {
1906 seq_printf(m, "(%s [%d]) ",
1907 task->comm, task->pid);
1908 put_task_struct(task);
1909 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001910 } else if (IS_ERR(ctx->file_priv)) {
1911 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001912 } else {
1913 seq_puts(m, "(kernel) ");
1914 }
1915
Chris Wilsonbca44d82016-05-24 14:53:41 +01001916 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1917 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001918
Akash Goel3b3f1652016-10-13 22:44:48 +05301919 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001920 struct intel_context *ce = &ctx->engine[engine->id];
1921
1922 seq_printf(m, "%s: ", engine->name);
Chris Wilsonbca44d82016-05-24 14:53:41 +01001923 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001924 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001925 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001926 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001927 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001928 }
1929
Ben Widawskya33afea2013-09-17 21:12:45 -07001930 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001931 }
1932
Daniel Vetterf3d28872014-05-29 23:23:08 +02001933 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001934
1935 return 0;
1936}
1937
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001938static const char *swizzle_string(unsigned swizzle)
1939{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001940 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001941 case I915_BIT_6_SWIZZLE_NONE:
1942 return "none";
1943 case I915_BIT_6_SWIZZLE_9:
1944 return "bit9";
1945 case I915_BIT_6_SWIZZLE_9_10:
1946 return "bit9/bit10";
1947 case I915_BIT_6_SWIZZLE_9_11:
1948 return "bit9/bit11";
1949 case I915_BIT_6_SWIZZLE_9_10_11:
1950 return "bit9/bit10/bit11";
1951 case I915_BIT_6_SWIZZLE_9_17:
1952 return "bit9/bit17";
1953 case I915_BIT_6_SWIZZLE_9_10_17:
1954 return "bit9/bit10/bit17";
1955 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001956 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001957 }
1958
1959 return "bug";
1960}
1961
1962static int i915_swizzle_info(struct seq_file *m, void *data)
1963{
David Weinehall36cdd012016-08-22 13:59:31 +03001964 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001965
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001966 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001967
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001968 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1969 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1970 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1971 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1972
David Weinehall36cdd012016-08-22 13:59:31 +03001973 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001974 seq_printf(m, "DDC = 0x%08x\n",
1975 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01001976 seq_printf(m, "DDC2 = 0x%08x\n",
1977 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001978 seq_printf(m, "C0DRB3 = 0x%04x\n",
1979 I915_READ16(C0DRB3));
1980 seq_printf(m, "C1DRB3 = 0x%04x\n",
1981 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03001982 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001983 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1984 I915_READ(MAD_DIMM_C0));
1985 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1986 I915_READ(MAD_DIMM_C1));
1987 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1988 I915_READ(MAD_DIMM_C2));
1989 seq_printf(m, "TILECTL = 0x%08x\n",
1990 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03001991 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001992 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1993 I915_READ(GAMTARBMODE));
1994 else
1995 seq_printf(m, "ARB_MODE = 0x%08x\n",
1996 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001997 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1998 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001999 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002000
2001 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2002 seq_puts(m, "L-shaped memory detected\n");
2003
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002004 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002005
2006 return 0;
2007}
2008
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002009static int per_file_ctx(int id, void *ptr, void *data)
2010{
Chris Wilsone2efd132016-05-24 14:53:34 +01002011 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002012 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002013 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2014
2015 if (!ppgtt) {
2016 seq_printf(m, " no ppgtt for context %d\n",
2017 ctx->user_handle);
2018 return 0;
2019 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002020
Oscar Mateof83d6512014-05-22 14:13:38 +01002021 if (i915_gem_context_is_default(ctx))
2022 seq_puts(m, " default context:\n");
2023 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002024 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002025 ppgtt->debug_dump(ppgtt, m);
2026
2027 return 0;
2028}
2029
David Weinehall36cdd012016-08-22 13:59:31 +03002030static void gen8_ppgtt_info(struct seq_file *m,
2031 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002032{
Ben Widawsky77df6772013-11-02 21:07:30 -07002033 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302034 struct intel_engine_cs *engine;
2035 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002036 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002037
Ben Widawsky77df6772013-11-02 21:07:30 -07002038 if (!ppgtt)
2039 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002040
Akash Goel3b3f1652016-10-13 22:44:48 +05302041 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002042 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002043 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002044 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002045 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002046 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002047 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002048 }
2049 }
2050}
2051
David Weinehall36cdd012016-08-22 13:59:31 +03002052static void gen6_ppgtt_info(struct seq_file *m,
2053 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002054{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002055 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302056 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002057
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002058 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002059 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2060
Akash Goel3b3f1652016-10-13 22:44:48 +05302061 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002062 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002063 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002064 seq_printf(m, "GFX_MODE: 0x%08x\n",
2065 I915_READ(RING_MODE_GEN7(engine)));
2066 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2067 I915_READ(RING_PP_DIR_BASE(engine)));
2068 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2069 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2070 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2071 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002072 }
2073 if (dev_priv->mm.aliasing_ppgtt) {
2074 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2075
Damien Lespiau267f0c92013-06-24 22:59:48 +01002076 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002077 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002078
Ben Widawsky87d60b62013-12-06 14:11:29 -08002079 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002080 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002081
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002082 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002083}
2084
2085static int i915_ppgtt_info(struct seq_file *m, void *data)
2086{
David Weinehall36cdd012016-08-22 13:59:31 +03002087 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2088 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002089 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002090 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002091
Chris Wilson637ee292016-08-22 14:28:20 +01002092 mutex_lock(&dev->filelist_mutex);
2093 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002094 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002095 goto out_unlock;
2096
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002097 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002098
David Weinehall36cdd012016-08-22 13:59:31 +03002099 if (INTEL_GEN(dev_priv) >= 8)
2100 gen8_ppgtt_info(m, dev_priv);
2101 else if (INTEL_GEN(dev_priv) >= 6)
2102 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002103
Michel Thierryea91e402015-07-29 17:23:57 +01002104 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2105 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002106 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002107
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002108 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002109 if (!task) {
2110 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002111 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002112 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002113 seq_printf(m, "\nproc: %s\n", task->comm);
2114 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002115 idr_for_each(&file_priv->context_idr, per_file_ctx,
2116 (void *)(unsigned long)m);
2117 }
2118
Chris Wilson637ee292016-08-22 14:28:20 +01002119out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002120 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002121 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002122out_unlock:
2123 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002124 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002125}
2126
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002127static int count_irq_waiters(struct drm_i915_private *i915)
2128{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002129 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302130 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002131 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002132
Akash Goel3b3f1652016-10-13 22:44:48 +05302133 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002134 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002135
2136 return count;
2137}
2138
Chris Wilson7466c292016-08-15 09:49:33 +01002139static const char *rps_power_to_str(unsigned int power)
2140{
2141 static const char * const strings[] = {
2142 [LOW_POWER] = "low power",
2143 [BETWEEN] = "mixed",
2144 [HIGH_POWER] = "high power",
2145 };
2146
2147 if (power >= ARRAY_SIZE(strings) || !strings[power])
2148 return "unknown";
2149
2150 return strings[power];
2151}
2152
Chris Wilson1854d5c2015-04-07 16:20:32 +01002153static int i915_rps_boost_info(struct seq_file *m, void *data)
2154{
David Weinehall36cdd012016-08-22 13:59:31 +03002155 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2156 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002157 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002158 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002159
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002160 seq_printf(m, "RPS enabled? %d\n", rps->enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002161 seq_printf(m, "GPU busy? %s [%d requests]\n",
2162 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002163 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002164 seq_printf(m, "Boosts outstanding? %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002165 atomic_read(&rps->num_waiters));
Chris Wilson7466c292016-08-15 09:49:33 +01002166 seq_printf(m, "Frequency requested %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002167 intel_gpu_freq(dev_priv, rps->cur_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002168 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002169 intel_gpu_freq(dev_priv, rps->min_freq),
2170 intel_gpu_freq(dev_priv, rps->min_freq_softlimit),
2171 intel_gpu_freq(dev_priv, rps->max_freq_softlimit),
2172 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002173 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002174 intel_gpu_freq(dev_priv, rps->idle_freq),
2175 intel_gpu_freq(dev_priv, rps->efficient_freq),
2176 intel_gpu_freq(dev_priv, rps->boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002177
2178 mutex_lock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002179 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2180 struct drm_i915_file_private *file_priv = file->driver_priv;
2181 struct task_struct *task;
2182
2183 rcu_read_lock();
2184 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002185 seq_printf(m, "%s [%d]: %d boosts\n",
Chris Wilson1854d5c2015-04-07 16:20:32 +01002186 task ? task->comm : "<unknown>",
2187 task ? task->pid : -1,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002188 atomic_read(&file_priv->rps_client.boosts));
Chris Wilson1854d5c2015-04-07 16:20:32 +01002189 rcu_read_unlock();
2190 }
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002191 seq_printf(m, "Kernel (anonymous) boosts: %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002192 atomic_read(&rps->boosts));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002193 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002194
Chris Wilson7466c292016-08-15 09:49:33 +01002195 if (INTEL_GEN(dev_priv) >= 6 &&
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002196 rps->enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002197 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002198 u32 rpup, rpupei;
2199 u32 rpdown, rpdownei;
2200
2201 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2202 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2203 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2204 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2205 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2206 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2207
2208 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002209 rps_power_to_str(rps->power));
Chris Wilson7466c292016-08-15 09:49:33 +01002210 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002211 rpup && rpupei ? 100 * rpup / rpupei : 0,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002212 rps->up_threshold);
Chris Wilson7466c292016-08-15 09:49:33 +01002213 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002214 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002215 rps->down_threshold);
Chris Wilson7466c292016-08-15 09:49:33 +01002216 } else {
2217 seq_puts(m, "\nRPS Autotuning inactive\n");
2218 }
2219
Chris Wilson8d3afd72015-05-21 21:01:47 +01002220 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002221}
2222
Ben Widawsky63573eb2013-07-04 11:02:07 -07002223static int i915_llc(struct seq_file *m, void *data)
2224{
David Weinehall36cdd012016-08-22 13:59:31 +03002225 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002226 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002227
David Weinehall36cdd012016-08-22 13:59:31 +03002228 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002229 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2230 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002231
2232 return 0;
2233}
2234
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002235static int i915_huc_load_status_info(struct seq_file *m, void *data)
2236{
2237 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002238 struct drm_printer p;
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002239
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002240 if (!HAS_HUC(dev_priv))
2241 return -ENODEV;
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002242
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002243 p = drm_seq_file_printer(m);
2244 intel_uc_fw_dump(&dev_priv->huc.fw, &p);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002245
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302246 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002247 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302248 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002249
2250 return 0;
2251}
2252
Alex Daifdf5d352015-08-12 15:43:37 +01002253static int i915_guc_load_status_info(struct seq_file *m, void *data)
2254{
David Weinehall36cdd012016-08-22 13:59:31 +03002255 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002256 struct drm_printer p;
Alex Daifdf5d352015-08-12 15:43:37 +01002257 u32 tmp, i;
2258
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002259 if (!HAS_GUC(dev_priv))
2260 return -ENODEV;
Alex Daifdf5d352015-08-12 15:43:37 +01002261
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002262 p = drm_seq_file_printer(m);
2263 intel_uc_fw_dump(&dev_priv->guc.fw, &p);
Alex Daifdf5d352015-08-12 15:43:37 +01002264
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302265 intel_runtime_pm_get(dev_priv);
2266
Alex Daifdf5d352015-08-12 15:43:37 +01002267 tmp = I915_READ(GUC_STATUS);
2268
2269 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2270 seq_printf(m, "\tBootrom status = 0x%x\n",
2271 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2272 seq_printf(m, "\tuKernel status = 0x%x\n",
2273 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2274 seq_printf(m, "\tMIA Core status = 0x%x\n",
2275 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2276 seq_puts(m, "\nScratch registers:\n");
2277 for (i = 0; i < 16; i++)
2278 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2279
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302280 intel_runtime_pm_put(dev_priv);
2281
Alex Daifdf5d352015-08-12 15:43:37 +01002282 return 0;
2283}
2284
Akash Goel5aa1ee42016-10-12 21:54:36 +05302285static void i915_guc_log_info(struct seq_file *m,
2286 struct drm_i915_private *dev_priv)
2287{
2288 struct intel_guc *guc = &dev_priv->guc;
2289
2290 seq_puts(m, "\nGuC logging stats:\n");
2291
2292 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2293 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2294 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2295
2296 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2297 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2298 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2299
2300 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2301 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2302 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2303
2304 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2305 guc->log.flush_interrupt_count);
2306
2307 seq_printf(m, "\tCapture miss count: %u\n",
2308 guc->log.capture_miss_count);
2309}
2310
Dave Gordon8b417c22015-08-12 15:43:44 +01002311static void i915_guc_client_info(struct seq_file *m,
2312 struct drm_i915_private *dev_priv,
Sagar Arun Kamble5afc8b42017-11-16 19:02:40 +05302313 struct intel_guc_client *client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002314{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002315 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002316 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002317 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002318
Oscar Mateob09935a2017-03-22 10:39:53 -07002319 seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
2320 client->priority, client->stage_id, client->proc_desc_offset);
Michał Winiarski59db36c2017-09-14 12:51:23 +02002321 seq_printf(m, "\tDoorbell id %d, offset: 0x%lx\n",
2322 client->doorbell_id, client->doorbell_offset);
Dave Gordon8b417c22015-08-12 15:43:44 +01002323
Akash Goel3b3f1652016-10-13 22:44:48 +05302324 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002325 u64 submissions = client->submissions[id];
2326 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002327 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002328 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002329 }
2330 seq_printf(m, "\tTotal: %llu\n", tot);
2331}
2332
2333static int i915_guc_info(struct seq_file *m, void *data)
2334{
David Weinehall36cdd012016-08-22 13:59:31 +03002335 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002336 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002337
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002338 if (!USES_GUC_SUBMISSION(dev_priv))
2339 return -ENODEV;
2340
2341 GEM_BUG_ON(!guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002342
Dave Gordon9636f6d2016-06-13 17:57:28 +01002343 seq_printf(m, "Doorbell map:\n");
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002344 seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
Chris Wilson334636c2016-11-29 12:10:20 +00002345 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002346
Chris Wilson334636c2016-11-29 12:10:20 +00002347 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2348 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Chris Wilsone78c9172018-02-07 21:05:42 +00002349 if (guc->preempt_client) {
2350 seq_printf(m, "\nGuC preempt client @ %p:\n",
2351 guc->preempt_client);
2352 i915_guc_client_info(m, dev_priv, guc->preempt_client);
2353 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002354
Akash Goel5aa1ee42016-10-12 21:54:36 +05302355 i915_guc_log_info(m, dev_priv);
2356
Dave Gordon8b417c22015-08-12 15:43:44 +01002357 /* Add more as required ... */
2358
2359 return 0;
2360}
2361
Oscar Mateoa8b93702017-05-10 15:04:51 +00002362static int i915_guc_stage_pool(struct seq_file *m, void *data)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002363{
David Weinehall36cdd012016-08-22 13:59:31 +03002364 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Oscar Mateoa8b93702017-05-10 15:04:51 +00002365 const struct intel_guc *guc = &dev_priv->guc;
2366 struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
Sagar Arun Kamble5afc8b42017-11-16 19:02:40 +05302367 struct intel_guc_client *client = guc->execbuf_client;
Oscar Mateoa8b93702017-05-10 15:04:51 +00002368 unsigned int tmp;
2369 int index;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002370
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002371 if (!USES_GUC_SUBMISSION(dev_priv))
2372 return -ENODEV;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002373
Oscar Mateoa8b93702017-05-10 15:04:51 +00002374 for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
2375 struct intel_engine_cs *engine;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002376
Oscar Mateoa8b93702017-05-10 15:04:51 +00002377 if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
2378 continue;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002379
Oscar Mateoa8b93702017-05-10 15:04:51 +00002380 seq_printf(m, "GuC stage descriptor %u:\n", index);
2381 seq_printf(m, "\tIndex: %u\n", desc->stage_id);
2382 seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
2383 seq_printf(m, "\tPriority: %d\n", desc->priority);
2384 seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
2385 seq_printf(m, "\tEngines used: 0x%x\n",
2386 desc->engines_used);
2387 seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
2388 desc->db_trigger_phy,
2389 desc->db_trigger_cpu,
2390 desc->db_trigger_uk);
2391 seq_printf(m, "\tProcess descriptor: 0x%x\n",
2392 desc->process_desc);
Colin Ian King9a094852017-05-16 10:22:35 +01002393 seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
Oscar Mateoa8b93702017-05-10 15:04:51 +00002394 desc->wq_addr, desc->wq_size);
2395 seq_putc(m, '\n');
2396
2397 for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
2398 u32 guc_engine_id = engine->guc_id;
2399 struct guc_execlist_context *lrc =
2400 &desc->lrc[guc_engine_id];
2401
2402 seq_printf(m, "\t%s LRC:\n", engine->name);
2403 seq_printf(m, "\t\tContext desc: 0x%x\n",
2404 lrc->context_desc);
2405 seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
2406 seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
2407 seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
2408 seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
2409 seq_putc(m, '\n');
2410 }
Alex Dai4c7e77f2015-08-12 15:43:40 +01002411 }
2412
Oscar Mateoa8b93702017-05-10 15:04:51 +00002413 return 0;
2414}
2415
Alex Dai4c7e77f2015-08-12 15:43:40 +01002416static int i915_guc_log_dump(struct seq_file *m, void *data)
2417{
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002418 struct drm_info_node *node = m->private;
2419 struct drm_i915_private *dev_priv = node_to_i915(node);
2420 bool dump_load_err = !!node->info_ent->data;
2421 struct drm_i915_gem_object *obj = NULL;
2422 u32 *log;
2423 int i = 0;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002424
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002425 if (!HAS_GUC(dev_priv))
2426 return -ENODEV;
2427
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002428 if (dump_load_err)
2429 obj = dev_priv->guc.load_err_log;
2430 else if (dev_priv->guc.log.vma)
2431 obj = dev_priv->guc.log.vma->obj;
2432
2433 if (!obj)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002434 return 0;
2435
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002436 log = i915_gem_object_pin_map(obj, I915_MAP_WC);
2437 if (IS_ERR(log)) {
2438 DRM_DEBUG("Failed to pin object\n");
2439 seq_puts(m, "(log data unaccessible)\n");
2440 return PTR_ERR(log);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002441 }
2442
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002443 for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
2444 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2445 *(log + i), *(log + i + 1),
2446 *(log + i + 2), *(log + i + 3));
2447
Alex Dai4c7e77f2015-08-12 15:43:40 +01002448 seq_putc(m, '\n');
2449
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002450 i915_gem_object_unpin_map(obj);
2451
Alex Dai4c7e77f2015-08-12 15:43:40 +01002452 return 0;
2453}
2454
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302455static int i915_guc_log_control_get(void *data, u64 *val)
2456{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002457 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302458
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002459 if (!HAS_GUC(dev_priv))
2460 return -ENODEV;
2461
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302462 if (!dev_priv->guc.log.vma)
2463 return -EINVAL;
2464
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002465 *val = i915_modparams.guc_log_level;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302466
2467 return 0;
2468}
2469
2470static int i915_guc_log_control_set(void *data, u64 val)
2471{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002472 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302473
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002474 if (!HAS_GUC(dev_priv))
2475 return -ENODEV;
2476
Sagar Arun Kamble065dd5a2018-01-24 21:16:59 +05302477 return intel_guc_log_control(&dev_priv->guc, val);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302478}
2479
2480DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2481 i915_guc_log_control_get, i915_guc_log_control_set,
2482 "%lld\n");
2483
Chris Wilsonb86bef202017-01-16 13:06:21 +00002484static const char *psr2_live_status(u32 val)
2485{
2486 static const char * const live_status[] = {
2487 "IDLE",
2488 "CAPTURE",
2489 "CAPTURE_FS",
2490 "SLEEP",
2491 "BUFON_FW",
2492 "ML_UP",
2493 "SU_STANDBY",
2494 "FAST_SLEEP",
2495 "DEEP_SLEEP",
2496 "BUF_ON",
2497 "TG_ON"
2498 };
2499
2500 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2501 if (val < ARRAY_SIZE(live_status))
2502 return live_status[val];
2503
2504 return "unknown";
2505}
2506
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002507static int i915_edp_psr_status(struct seq_file *m, void *data)
2508{
David Weinehall36cdd012016-08-22 13:59:31 +03002509 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002510 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002511 u32 stat[3];
2512 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002513 bool enabled = false;
Dhinakaran Pandiyanc9ef2912018-01-03 13:38:24 -08002514 bool sink_support;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002515
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002516 if (!HAS_PSR(dev_priv))
2517 return -ENODEV;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002518
Dhinakaran Pandiyanc9ef2912018-01-03 13:38:24 -08002519 sink_support = dev_priv->psr.sink_support;
2520 seq_printf(m, "Sink_Support: %s\n", yesno(sink_support));
2521 if (!sink_support)
2522 return 0;
2523
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002524 intel_runtime_pm_get(dev_priv);
2525
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002526 mutex_lock(&dev_priv->psr.lock);
Daniel Vetter2807cf62014-07-11 10:30:11 -07002527 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002528 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002529 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2530 dev_priv->psr.busy_frontbuffer_bits);
2531 seq_printf(m, "Re-enable work scheduled: %s\n",
2532 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002533
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302534 if (HAS_DDI(dev_priv)) {
2535 if (dev_priv->psr.psr2_support)
2536 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2537 else
2538 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2539 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002540 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002541 enum transcoder cpu_transcoder =
2542 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2543 enum intel_display_power_domain power_domain;
2544
2545 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2546 if (!intel_display_power_get_if_enabled(dev_priv,
2547 power_domain))
2548 continue;
2549
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002550 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2551 VLV_EDP_PSR_CURR_STATE_MASK;
2552 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2553 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2554 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002555
2556 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002557 }
2558 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002559
2560 seq_printf(m, "Main link in standby mode: %s\n",
2561 yesno(dev_priv->psr.link_standby));
2562
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002563 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002564
David Weinehall36cdd012016-08-22 13:59:31 +03002565 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002566 for_each_pipe(dev_priv, pipe) {
2567 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2568 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2569 seq_printf(m, " pipe %c", pipe_name(pipe));
2570 }
2571 seq_puts(m, "\n");
2572
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002573 /*
2574 * VLV/CHV PSR has no kind of performance counter
2575 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2576 */
David Weinehall36cdd012016-08-22 13:59:31 +03002577 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002578 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002579 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002580
2581 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2582 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302583 if (dev_priv->psr.psr2_support) {
Dhinakaran Pandiyan861023e2017-12-20 12:10:21 -08002584 u32 psr2 = I915_READ(EDP_PSR2_STATUS);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302585
Dhinakaran Pandiyan861023e2017-12-20 12:10:21 -08002586 seq_printf(m, "EDP_PSR2_STATUS: %x [%s]\n",
Chris Wilsonb86bef202017-01-16 13:06:21 +00002587 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302588 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002589 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002590
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002591 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002592 return 0;
2593}
2594
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002595static int i915_sink_crc(struct seq_file *m, void *data)
2596{
David Weinehall36cdd012016-08-22 13:59:31 +03002597 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2598 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002599 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002600 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002601 struct intel_dp *intel_dp = NULL;
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002602 struct drm_modeset_acquire_ctx ctx;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002603 int ret;
2604 u8 crc[6];
2605
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002606 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
2607
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002608 drm_connector_list_iter_begin(dev, &conn_iter);
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002609
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002610 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002611 struct drm_crtc *crtc;
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002612 struct drm_connector_state *state;
Maarten Lankhorst93313532017-11-10 12:34:59 +01002613 struct intel_crtc_state *crtc_state;
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002614
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002615 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002616 continue;
2617
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002618retry:
2619 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
2620 if (ret)
2621 goto err;
2622
2623 state = connector->base.state;
2624 if (!state->best_encoder)
2625 continue;
2626
2627 crtc = state->crtc;
2628 ret = drm_modeset_lock(&crtc->mutex, &ctx);
2629 if (ret)
2630 goto err;
2631
Maarten Lankhorst93313532017-11-10 12:34:59 +01002632 crtc_state = to_intel_crtc_state(crtc->state);
2633 if (!crtc_state->base.active)
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002634 continue;
2635
Maarten Lankhorst93313532017-11-10 12:34:59 +01002636 /*
2637 * We need to wait for all crtc updates to complete, to make
2638 * sure any pending modesets and plane updates are completed.
2639 */
2640 if (crtc_state->base.commit) {
2641 ret = wait_for_completion_interruptible(&crtc_state->base.commit->hw_done);
2642
2643 if (ret)
2644 goto err;
2645 }
2646
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002647 intel_dp = enc_to_intel_dp(state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002648
Maarten Lankhorst93313532017-11-10 12:34:59 +01002649 ret = intel_dp_sink_crc(intel_dp, crtc_state, crc);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002650 if (ret)
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002651 goto err;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002652
2653 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2654 crc[0], crc[1], crc[2],
2655 crc[3], crc[4], crc[5]);
2656 goto out;
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002657
2658err:
2659 if (ret == -EDEADLK) {
2660 ret = drm_modeset_backoff(&ctx);
2661 if (!ret)
2662 goto retry;
2663 }
2664 goto out;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002665 }
2666 ret = -ENODEV;
2667out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002668 drm_connector_list_iter_end(&conn_iter);
Maarten Lankhorst10bf0a32017-11-10 12:34:58 +01002669 drm_modeset_drop_locks(&ctx);
2670 drm_modeset_acquire_fini(&ctx);
2671
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002672 return ret;
2673}
2674
Jesse Barnesec013e72013-08-20 10:29:23 +01002675static int i915_energy_uJ(struct seq_file *m, void *data)
2676{
David Weinehall36cdd012016-08-22 13:59:31 +03002677 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002678 unsigned long long power;
Jesse Barnesec013e72013-08-20 10:29:23 +01002679 u32 units;
2680
David Weinehall36cdd012016-08-22 13:59:31 +03002681 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002682 return -ENODEV;
2683
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002684 intel_runtime_pm_get(dev_priv);
2685
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002686 if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
2687 intel_runtime_pm_put(dev_priv);
2688 return -ENODEV;
2689 }
2690
2691 units = (power & 0x1f00) >> 8;
Jesse Barnesec013e72013-08-20 10:29:23 +01002692 power = I915_READ(MCH_SECP_NRG_STTS);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002693 power = (1000000 * power) >> units; /* convert to uJ */
Jesse Barnesec013e72013-08-20 10:29:23 +01002694
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002695 intel_runtime_pm_put(dev_priv);
2696
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002697 seq_printf(m, "%llu", power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002698
2699 return 0;
2700}
2701
Damien Lespiau6455c872015-06-04 18:23:57 +01002702static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002703{
David Weinehall36cdd012016-08-22 13:59:31 +03002704 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002705 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002706
Chris Wilsona156e642016-04-03 14:14:21 +01002707 if (!HAS_RUNTIME_PM(dev_priv))
2708 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002709
Chris Wilson6f561032018-01-24 11:36:07 +00002710 seq_printf(m, "GPU idle: %s (epoch %u)\n",
2711 yesno(!dev_priv->gt.awake), dev_priv->gt.epoch);
Paulo Zanoni371db662013-08-19 13:18:10 -03002712 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002713 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002714#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002715 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002716 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002717#else
2718 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2719#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002720 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002721 pci_power_name(pdev->current_state),
2722 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002723
Jesse Barnesec013e72013-08-20 10:29:23 +01002724 return 0;
2725}
2726
Imre Deak1da51582013-11-25 17:15:35 +02002727static int i915_power_domain_info(struct seq_file *m, void *unused)
2728{
David Weinehall36cdd012016-08-22 13:59:31 +03002729 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002730 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2731 int i;
2732
2733 mutex_lock(&power_domains->lock);
2734
2735 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2736 for (i = 0; i < power_domains->power_well_count; i++) {
2737 struct i915_power_well *power_well;
2738 enum intel_display_power_domain power_domain;
2739
2740 power_well = &power_domains->power_wells[i];
2741 seq_printf(m, "%-25s %d\n", power_well->name,
2742 power_well->count);
2743
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002744 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002745 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002746 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002747 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002748 }
2749
2750 mutex_unlock(&power_domains->lock);
2751
2752 return 0;
2753}
2754
Damien Lespiaub7cec662015-10-27 14:47:01 +02002755static int i915_dmc_info(struct seq_file *m, void *unused)
2756{
David Weinehall36cdd012016-08-22 13:59:31 +03002757 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002758 struct intel_csr *csr;
2759
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00002760 if (!HAS_CSR(dev_priv))
2761 return -ENODEV;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002762
2763 csr = &dev_priv->csr;
2764
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002765 intel_runtime_pm_get(dev_priv);
2766
Damien Lespiaub7cec662015-10-27 14:47:01 +02002767 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2768 seq_printf(m, "path: %s\n", csr->fw_path);
2769
2770 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002771 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002772
2773 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2774 CSR_VERSION_MINOR(csr->version));
2775
Mika Kuoppala48de5682017-05-09 13:05:22 +03002776 if (IS_KABYLAKE(dev_priv) ||
2777 (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
Damien Lespiau83372062015-10-30 17:53:32 +02002778 seq_printf(m, "DC3 -> DC5 count: %d\n",
2779 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2780 seq_printf(m, "DC5 -> DC6 count: %d\n",
2781 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002782 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002783 seq_printf(m, "DC3 -> DC5 count: %d\n",
2784 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002785 }
2786
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002787out:
2788 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2789 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2790 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2791
Damien Lespiau83372062015-10-30 17:53:32 +02002792 intel_runtime_pm_put(dev_priv);
2793
Damien Lespiaub7cec662015-10-27 14:47:01 +02002794 return 0;
2795}
2796
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002797static void intel_seq_print_mode(struct seq_file *m, int tabs,
2798 struct drm_display_mode *mode)
2799{
2800 int i;
2801
2802 for (i = 0; i < tabs; i++)
2803 seq_putc(m, '\t');
2804
2805 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",
2806 mode->base.id, mode->name,
2807 mode->vrefresh, mode->clock,
2808 mode->hdisplay, mode->hsync_start,
2809 mode->hsync_end, mode->htotal,
2810 mode->vdisplay, mode->vsync_start,
2811 mode->vsync_end, mode->vtotal,
2812 mode->type, mode->flags);
2813}
2814
2815static void intel_encoder_info(struct seq_file *m,
2816 struct intel_crtc *intel_crtc,
2817 struct intel_encoder *intel_encoder)
2818{
David Weinehall36cdd012016-08-22 13:59:31 +03002819 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2820 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002821 struct drm_crtc *crtc = &intel_crtc->base;
2822 struct intel_connector *intel_connector;
2823 struct drm_encoder *encoder;
2824
2825 encoder = &intel_encoder->base;
2826 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002827 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002828 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2829 struct drm_connector *connector = &intel_connector->base;
2830 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2831 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002832 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002833 drm_get_connector_status_name(connector->status));
2834 if (connector->status == connector_status_connected) {
2835 struct drm_display_mode *mode = &crtc->mode;
2836 seq_printf(m, ", mode:\n");
2837 intel_seq_print_mode(m, 2, mode);
2838 } else {
2839 seq_putc(m, '\n');
2840 }
2841 }
2842}
2843
2844static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2845{
David Weinehall36cdd012016-08-22 13:59:31 +03002846 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2847 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002848 struct drm_crtc *crtc = &intel_crtc->base;
2849 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002850 struct drm_plane_state *plane_state = crtc->primary->state;
2851 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002852
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002853 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002854 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002855 fb->base.id, plane_state->src_x >> 16,
2856 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002857 else
2858 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002859 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2860 intel_encoder_info(m, intel_crtc, intel_encoder);
2861}
2862
2863static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2864{
2865 struct drm_display_mode *mode = panel->fixed_mode;
2866
2867 seq_printf(m, "\tfixed mode:\n");
2868 intel_seq_print_mode(m, 2, mode);
2869}
2870
2871static void intel_dp_info(struct seq_file *m,
2872 struct intel_connector *intel_connector)
2873{
2874 struct intel_encoder *intel_encoder = intel_connector->encoder;
2875 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2876
2877 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002878 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002879 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002880 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002881
2882 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2883 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002884}
2885
Libin Yang9a148a92016-11-28 20:07:05 +08002886static void intel_dp_mst_info(struct seq_file *m,
2887 struct intel_connector *intel_connector)
2888{
2889 struct intel_encoder *intel_encoder = intel_connector->encoder;
2890 struct intel_dp_mst_encoder *intel_mst =
2891 enc_to_mst(&intel_encoder->base);
2892 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2893 struct intel_dp *intel_dp = &intel_dig_port->dp;
2894 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2895 intel_connector->port);
2896
2897 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2898}
2899
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002900static void intel_hdmi_info(struct seq_file *m,
2901 struct intel_connector *intel_connector)
2902{
2903 struct intel_encoder *intel_encoder = intel_connector->encoder;
2904 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2905
Jani Nikula742f4912015-09-03 11:16:09 +03002906 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002907}
2908
2909static void intel_lvds_info(struct seq_file *m,
2910 struct intel_connector *intel_connector)
2911{
2912 intel_panel_info(m, &intel_connector->panel);
2913}
2914
2915static void intel_connector_info(struct seq_file *m,
2916 struct drm_connector *connector)
2917{
2918 struct intel_connector *intel_connector = to_intel_connector(connector);
2919 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002920 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002921
2922 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002923 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002924 drm_get_connector_status_name(connector->status));
2925 if (connector->status == connector_status_connected) {
2926 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2927 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2928 connector->display_info.width_mm,
2929 connector->display_info.height_mm);
2930 seq_printf(m, "\tsubpixel order: %s\n",
2931 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2932 seq_printf(m, "\tCEA rev: %d\n",
2933 connector->display_info.cea_rev);
2934 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002935
Maarten Lankhorst77d1f612017-06-26 10:33:49 +02002936 if (!intel_encoder)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002937 return;
2938
2939 switch (connector->connector_type) {
2940 case DRM_MODE_CONNECTOR_DisplayPort:
2941 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08002942 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
2943 intel_dp_mst_info(m, intel_connector);
2944 else
2945 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002946 break;
2947 case DRM_MODE_CONNECTOR_LVDS:
2948 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10002949 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002950 break;
2951 case DRM_MODE_CONNECTOR_HDMIA:
2952 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
Ville Syrjälä7e732ca2017-10-27 22:31:24 +03002953 intel_encoder->type == INTEL_OUTPUT_DDI)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02002954 intel_hdmi_info(m, intel_connector);
2955 break;
2956 default:
2957 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10002958 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002959
Jesse Barnesf103fc72014-02-20 12:39:57 -08002960 seq_printf(m, "\tmodes:\n");
2961 list_for_each_entry(mode, &connector->modes, head)
2962 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002963}
2964
Robert Fekete3abc4e02015-10-27 16:58:32 +01002965static const char *plane_type(enum drm_plane_type type)
2966{
2967 switch (type) {
2968 case DRM_PLANE_TYPE_OVERLAY:
2969 return "OVL";
2970 case DRM_PLANE_TYPE_PRIMARY:
2971 return "PRI";
2972 case DRM_PLANE_TYPE_CURSOR:
2973 return "CUR";
2974 /*
2975 * Deliberately omitting default: to generate compiler warnings
2976 * when a new drm_plane_type gets added.
2977 */
2978 }
2979
2980 return "unknown";
2981}
2982
2983static const char *plane_rotation(unsigned int rotation)
2984{
2985 static char buf[48];
2986 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04002987 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
Robert Fekete3abc4e02015-10-27 16:58:32 +01002988 * will print them all to visualize if the values are misused
2989 */
2990 snprintf(buf, sizeof(buf),
2991 "%s%s%s%s%s%s(0x%08x)",
Robert Fossc2c446a2017-05-19 16:50:17 -04002992 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
2993 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
2994 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
2995 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
2996 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
2997 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01002998 rotation);
2999
3000 return buf;
3001}
3002
3003static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3004{
David Weinehall36cdd012016-08-22 13:59:31 +03003005 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3006 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003007 struct intel_plane *intel_plane;
3008
3009 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3010 struct drm_plane_state *state;
3011 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003012 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003013
3014 if (!plane->state) {
3015 seq_puts(m, "plane->state is NULL!\n");
3016 continue;
3017 }
3018
3019 state = plane->state;
3020
Eric Engestrom90844f02016-08-15 01:02:38 +01003021 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003022 drm_get_format_name(state->fb->format->format,
3023 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003024 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003025 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003026 }
3027
Robert Fekete3abc4e02015-10-27 16:58:32 +01003028 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",
3029 plane->base.id,
3030 plane_type(intel_plane->base.type),
3031 state->crtc_x, state->crtc_y,
3032 state->crtc_w, state->crtc_h,
3033 (state->src_x >> 16),
3034 ((state->src_x & 0xffff) * 15625) >> 10,
3035 (state->src_y >> 16),
3036 ((state->src_y & 0xffff) * 15625) >> 10,
3037 (state->src_w >> 16),
3038 ((state->src_w & 0xffff) * 15625) >> 10,
3039 (state->src_h >> 16),
3040 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003041 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003042 plane_rotation(state->rotation));
3043 }
3044}
3045
3046static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3047{
3048 struct intel_crtc_state *pipe_config;
3049 int num_scalers = intel_crtc->num_scalers;
3050 int i;
3051
3052 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3053
3054 /* Not all platformas have a scaler */
3055 if (num_scalers) {
3056 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3057 num_scalers,
3058 pipe_config->scaler_state.scaler_users,
3059 pipe_config->scaler_state.scaler_id);
3060
A.Sunil Kamath58415912016-11-20 23:20:26 +05303061 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003062 struct intel_scaler *sc =
3063 &pipe_config->scaler_state.scalers[i];
3064
3065 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3066 i, yesno(sc->in_use), sc->mode);
3067 }
3068 seq_puts(m, "\n");
3069 } else {
3070 seq_puts(m, "\tNo scalers available on this platform\n");
3071 }
3072}
3073
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003074static int i915_display_info(struct seq_file *m, void *unused)
3075{
David Weinehall36cdd012016-08-22 13:59:31 +03003076 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3077 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003078 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003079 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003080 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003081
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003082 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003083 seq_printf(m, "CRTC info\n");
3084 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003085 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003086 struct intel_crtc_state *pipe_config;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003087
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003088 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003089 pipe_config = to_intel_crtc_state(crtc->base.state);
3090
Robert Fekete3abc4e02015-10-27 16:58:32 +01003091 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003092 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003093 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003094 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3095 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3096
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003097 if (pipe_config->base.active) {
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003098 struct intel_plane *cursor =
3099 to_intel_plane(crtc->base.cursor);
3100
Chris Wilson065f2ec22014-03-12 09:13:13 +00003101 intel_crtc_info(m, crtc);
3102
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003103 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
3104 yesno(cursor->base.state->visible),
3105 cursor->base.state->crtc_x,
3106 cursor->base.state->crtc_y,
3107 cursor->base.state->crtc_w,
3108 cursor->base.state->crtc_h,
3109 cursor->cursor.base);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003110 intel_scaler_info(m, crtc);
3111 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003112 }
Daniel Vettercace8412014-05-22 17:56:31 +02003113
3114 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3115 yesno(!crtc->cpu_fifo_underrun_disabled),
3116 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003117 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003118 }
3119
3120 seq_printf(m, "\n");
3121 seq_printf(m, "Connector info\n");
3122 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003123 mutex_lock(&dev->mode_config.mutex);
3124 drm_connector_list_iter_begin(dev, &conn_iter);
3125 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003126 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003127 drm_connector_list_iter_end(&conn_iter);
3128 mutex_unlock(&dev->mode_config.mutex);
3129
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003130 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003131
3132 return 0;
3133}
3134
Chris Wilson1b365952016-10-04 21:11:31 +01003135static int i915_engine_info(struct seq_file *m, void *unused)
3136{
3137 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3138 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303139 enum intel_engine_id id;
Chris Wilsonf636edb2017-10-09 12:02:57 +01003140 struct drm_printer p;
Chris Wilson1b365952016-10-04 21:11:31 +01003141
Chris Wilson9c870d02016-10-24 13:42:15 +01003142 intel_runtime_pm_get(dev_priv);
3143
Chris Wilson6f561032018-01-24 11:36:07 +00003144 seq_printf(m, "GT awake? %s (epoch %u)\n",
3145 yesno(dev_priv->gt.awake), dev_priv->gt.epoch);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003146 seq_printf(m, "Global active requests: %d\n",
3147 dev_priv->gt.active_requests);
Lionel Landwerlinf577a032017-11-13 23:34:53 +00003148 seq_printf(m, "CS timestamp frequency: %u kHz\n",
3149 dev_priv->info.cs_timestamp_frequency_khz);
Chris Wilsonf73b5672017-03-02 15:03:56 +00003150
Chris Wilsonf636edb2017-10-09 12:02:57 +01003151 p = drm_seq_file_printer(m);
3152 for_each_engine(engine, dev_priv, id)
Chris Wilson0db18b12017-12-08 01:23:00 +00003153 intel_engine_dump(engine, &p, "%s\n", engine->name);
Chris Wilson1b365952016-10-04 21:11:31 +01003154
Chris Wilson9c870d02016-10-24 13:42:15 +01003155 intel_runtime_pm_put(dev_priv);
3156
Chris Wilson1b365952016-10-04 21:11:31 +01003157 return 0;
3158}
3159
Chris Wilsonc5418a82017-10-13 21:26:19 +01003160static int i915_shrinker_info(struct seq_file *m, void *unused)
3161{
3162 struct drm_i915_private *i915 = node_to_i915(m->private);
3163
3164 seq_printf(m, "seeks = %d\n", i915->mm.shrinker.seeks);
3165 seq_printf(m, "batch = %lu\n", i915->mm.shrinker.batch);
3166
3167 return 0;
3168}
3169
Daniel Vetter728e29d2014-06-25 22:01:53 +03003170static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3171{
David Weinehall36cdd012016-08-22 13:59:31 +03003172 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3173 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003174 int i;
3175
3176 drm_modeset_lock_all(dev);
3177 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3178 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3179
3180 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003181 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003182 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003183 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003184 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003185 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003186 pll->state.hw_state.dpll_md);
3187 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3188 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3189 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003190 }
3191 drm_modeset_unlock_all(dev);
3192
3193 return 0;
3194}
3195
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003196static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003197{
3198 int i;
3199 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003200 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003201 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3202 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003203 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003204 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003205
Arun Siluvery888b5992014-08-26 14:44:51 +01003206 ret = mutex_lock_interruptible(&dev->struct_mutex);
3207 if (ret)
3208 return ret;
3209
3210 intel_runtime_pm_get(dev_priv);
3211
Arun Siluvery33136b02016-01-21 21:43:47 +00003212 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303213 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003214 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003215 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003216 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003217 i915_reg_t addr;
3218 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003219 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003220
Arun Siluvery33136b02016-01-21 21:43:47 +00003221 addr = workarounds->reg[i].addr;
3222 mask = workarounds->reg[i].mask;
3223 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003224 read = I915_READ(addr);
3225 ok = (value & mask) == (read & mask);
3226 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 +02003227 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003228 }
3229
3230 intel_runtime_pm_put(dev_priv);
3231 mutex_unlock(&dev->struct_mutex);
3232
3233 return 0;
3234}
3235
Kumar, Maheshd2d4f392017-08-17 19:15:29 +05303236static int i915_ipc_status_show(struct seq_file *m, void *data)
3237{
3238 struct drm_i915_private *dev_priv = m->private;
3239
3240 seq_printf(m, "Isochronous Priority Control: %s\n",
3241 yesno(dev_priv->ipc_enabled));
3242 return 0;
3243}
3244
3245static int i915_ipc_status_open(struct inode *inode, struct file *file)
3246{
3247 struct drm_i915_private *dev_priv = inode->i_private;
3248
3249 if (!HAS_IPC(dev_priv))
3250 return -ENODEV;
3251
3252 return single_open(file, i915_ipc_status_show, dev_priv);
3253}
3254
3255static ssize_t i915_ipc_status_write(struct file *file, const char __user *ubuf,
3256 size_t len, loff_t *offp)
3257{
3258 struct seq_file *m = file->private_data;
3259 struct drm_i915_private *dev_priv = m->private;
3260 int ret;
3261 bool enable;
3262
3263 ret = kstrtobool_from_user(ubuf, len, &enable);
3264 if (ret < 0)
3265 return ret;
3266
3267 intel_runtime_pm_get(dev_priv);
3268 if (!dev_priv->ipc_enabled && enable)
3269 DRM_INFO("Enabling IPC: WM will be proper only after next commit\n");
3270 dev_priv->wm.distrust_bios_wm = true;
3271 dev_priv->ipc_enabled = enable;
3272 intel_enable_ipc(dev_priv);
3273 intel_runtime_pm_put(dev_priv);
3274
3275 return len;
3276}
3277
3278static const struct file_operations i915_ipc_status_fops = {
3279 .owner = THIS_MODULE,
3280 .open = i915_ipc_status_open,
3281 .read = seq_read,
3282 .llseek = seq_lseek,
3283 .release = single_release,
3284 .write = i915_ipc_status_write
3285};
3286
Damien Lespiauc5511e42014-11-04 17:06:51 +00003287static int i915_ddb_info(struct seq_file *m, void *unused)
3288{
David Weinehall36cdd012016-08-22 13:59:31 +03003289 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3290 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003291 struct skl_ddb_allocation *ddb;
3292 struct skl_ddb_entry *entry;
3293 enum pipe pipe;
3294 int plane;
3295
David Weinehall36cdd012016-08-22 13:59:31 +03003296 if (INTEL_GEN(dev_priv) < 9)
Michal Wajdeczkoab309a62017-12-15 14:36:35 +00003297 return -ENODEV;
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003298
Damien Lespiauc5511e42014-11-04 17:06:51 +00003299 drm_modeset_lock_all(dev);
3300
3301 ddb = &dev_priv->wm.skl_hw.ddb;
3302
3303 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3304
3305 for_each_pipe(dev_priv, pipe) {
3306 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3307
Matt Roper8b364b42016-10-26 15:51:28 -07003308 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003309 entry = &ddb->plane[pipe][plane];
3310 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3311 entry->start, entry->end,
3312 skl_ddb_entry_size(entry));
3313 }
3314
Matt Roper4969d332015-09-24 15:53:10 -07003315 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003316 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3317 entry->end, skl_ddb_entry_size(entry));
3318 }
3319
3320 drm_modeset_unlock_all(dev);
3321
3322 return 0;
3323}
3324
Vandana Kannana54746e2015-03-03 20:53:10 +05303325static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003326 struct drm_device *dev,
3327 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303328{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003329 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303330 struct i915_drrs *drrs = &dev_priv->drrs;
3331 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003332 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003333 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303334
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003335 drm_connector_list_iter_begin(dev, &conn_iter);
3336 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003337 if (connector->state->crtc != &intel_crtc->base)
3338 continue;
3339
3340 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303341 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003342 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303343
3344 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3345 seq_puts(m, "\tVBT: DRRS_type: Static");
3346 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3347 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3348 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3349 seq_puts(m, "\tVBT: DRRS_type: None");
3350 else
3351 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3352
3353 seq_puts(m, "\n\n");
3354
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003355 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303356 struct intel_panel *panel;
3357
3358 mutex_lock(&drrs->mutex);
3359 /* DRRS Supported */
3360 seq_puts(m, "\tDRRS Supported: Yes\n");
3361
3362 /* disable_drrs() will make drrs->dp NULL */
3363 if (!drrs->dp) {
C, Ramalingamce6e2132017-11-20 09:53:47 +05303364 seq_puts(m, "Idleness DRRS: Disabled\n");
3365 if (dev_priv->psr.enabled)
3366 seq_puts(m,
3367 "\tAs PSR is enabled, DRRS is not enabled\n");
Vandana Kannana54746e2015-03-03 20:53:10 +05303368 mutex_unlock(&drrs->mutex);
3369 return;
3370 }
3371
3372 panel = &drrs->dp->attached_connector->panel;
3373 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3374 drrs->busy_frontbuffer_bits);
3375
3376 seq_puts(m, "\n\t\t");
3377 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3378 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3379 vrefresh = panel->fixed_mode->vrefresh;
3380 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3381 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3382 vrefresh = panel->downclock_mode->vrefresh;
3383 } else {
3384 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3385 drrs->refresh_rate_type);
3386 mutex_unlock(&drrs->mutex);
3387 return;
3388 }
3389 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3390
3391 seq_puts(m, "\n\t\t");
3392 mutex_unlock(&drrs->mutex);
3393 } else {
3394 /* DRRS not supported. Print the VBT parameter*/
3395 seq_puts(m, "\tDRRS Supported : No");
3396 }
3397 seq_puts(m, "\n");
3398}
3399
3400static int i915_drrs_status(struct seq_file *m, void *unused)
3401{
David Weinehall36cdd012016-08-22 13:59:31 +03003402 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3403 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303404 struct intel_crtc *intel_crtc;
3405 int active_crtc_cnt = 0;
3406
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003407 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303408 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003409 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303410 active_crtc_cnt++;
3411 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3412
3413 drrs_status_per_crtc(m, dev, intel_crtc);
3414 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303415 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003416 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303417
3418 if (!active_crtc_cnt)
3419 seq_puts(m, "No active crtc found\n");
3420
3421 return 0;
3422}
3423
Dave Airlie11bed952014-05-12 15:22:27 +10003424static int i915_dp_mst_info(struct seq_file *m, void *unused)
3425{
David Weinehall36cdd012016-08-22 13:59:31 +03003426 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3427 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003428 struct intel_encoder *intel_encoder;
3429 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003430 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003431 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003432
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003433 drm_connector_list_iter_begin(dev, &conn_iter);
3434 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003435 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003436 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003437
3438 intel_encoder = intel_attached_encoder(connector);
3439 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3440 continue;
3441
3442 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003443 if (!intel_dig_port->dp.can_mst)
3444 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003445
Jim Bride40ae80c2016-04-14 10:18:37 -07003446 seq_printf(m, "MST Source Port %c\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02003447 port_name(intel_dig_port->base.port));
Dave Airlie11bed952014-05-12 15:22:27 +10003448 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3449 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003450 drm_connector_list_iter_end(&conn_iter);
3451
Dave Airlie11bed952014-05-12 15:22:27 +10003452 return 0;
3453}
3454
Todd Previteeb3394fa2015-04-18 00:04:19 -07003455static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003456 const char __user *ubuf,
3457 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003458{
3459 char *input_buffer;
3460 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003461 struct drm_device *dev;
3462 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003463 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003464 struct intel_dp *intel_dp;
3465 int val = 0;
3466
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303467 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003468
Todd Previteeb3394fa2015-04-18 00:04:19 -07003469 if (len == 0)
3470 return 0;
3471
Geliang Tang261aeba2017-05-06 23:40:17 +08003472 input_buffer = memdup_user_nul(ubuf, len);
3473 if (IS_ERR(input_buffer))
3474 return PTR_ERR(input_buffer);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003475
Todd Previteeb3394fa2015-04-18 00:04:19 -07003476 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3477
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003478 drm_connector_list_iter_begin(dev, &conn_iter);
3479 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003480 struct intel_encoder *encoder;
3481
Todd Previteeb3394fa2015-04-18 00:04:19 -07003482 if (connector->connector_type !=
3483 DRM_MODE_CONNECTOR_DisplayPort)
3484 continue;
3485
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003486 encoder = to_intel_encoder(connector->encoder);
3487 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3488 continue;
3489
3490 if (encoder && connector->status == connector_status_connected) {
3491 intel_dp = enc_to_intel_dp(&encoder->base);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003492 status = kstrtoint(input_buffer, 10, &val);
3493 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003494 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003495 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3496 /* To prevent erroneous activation of the compliance
3497 * testing code, only accept an actual value of 1 here
3498 */
3499 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003500 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003501 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003502 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003503 }
3504 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003505 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003506 kfree(input_buffer);
3507 if (status < 0)
3508 return status;
3509
3510 *offp += len;
3511 return len;
3512}
3513
3514static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3515{
3516 struct drm_device *dev = m->private;
3517 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003518 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003519 struct intel_dp *intel_dp;
3520
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003521 drm_connector_list_iter_begin(dev, &conn_iter);
3522 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003523 struct intel_encoder *encoder;
3524
Todd Previteeb3394fa2015-04-18 00:04:19 -07003525 if (connector->connector_type !=
3526 DRM_MODE_CONNECTOR_DisplayPort)
3527 continue;
3528
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003529 encoder = to_intel_encoder(connector->encoder);
3530 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3531 continue;
3532
3533 if (encoder && connector->status == connector_status_connected) {
3534 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003535 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003536 seq_puts(m, "1");
3537 else
3538 seq_puts(m, "0");
3539 } else
3540 seq_puts(m, "0");
3541 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003542 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003543
3544 return 0;
3545}
3546
3547static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003548 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003549{
David Weinehall36cdd012016-08-22 13:59:31 +03003550 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003551
David Weinehall36cdd012016-08-22 13:59:31 +03003552 return single_open(file, i915_displayport_test_active_show,
3553 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003554}
3555
3556static const struct file_operations i915_displayport_test_active_fops = {
3557 .owner = THIS_MODULE,
3558 .open = i915_displayport_test_active_open,
3559 .read = seq_read,
3560 .llseek = seq_lseek,
3561 .release = single_release,
3562 .write = i915_displayport_test_active_write
3563};
3564
3565static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3566{
3567 struct drm_device *dev = m->private;
3568 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003569 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003570 struct intel_dp *intel_dp;
3571
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003572 drm_connector_list_iter_begin(dev, &conn_iter);
3573 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003574 struct intel_encoder *encoder;
3575
Todd Previteeb3394fa2015-04-18 00:04:19 -07003576 if (connector->connector_type !=
3577 DRM_MODE_CONNECTOR_DisplayPort)
3578 continue;
3579
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003580 encoder = to_intel_encoder(connector->encoder);
3581 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3582 continue;
3583
3584 if (encoder && connector->status == connector_status_connected) {
3585 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003586 if (intel_dp->compliance.test_type ==
3587 DP_TEST_LINK_EDID_READ)
3588 seq_printf(m, "%lx",
3589 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003590 else if (intel_dp->compliance.test_type ==
3591 DP_TEST_LINK_VIDEO_PATTERN) {
3592 seq_printf(m, "hdisplay: %d\n",
3593 intel_dp->compliance.test_data.hdisplay);
3594 seq_printf(m, "vdisplay: %d\n",
3595 intel_dp->compliance.test_data.vdisplay);
3596 seq_printf(m, "bpc: %u\n",
3597 intel_dp->compliance.test_data.bpc);
3598 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003599 } else
3600 seq_puts(m, "0");
3601 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003602 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003603
3604 return 0;
3605}
3606static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003607 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003608{
David Weinehall36cdd012016-08-22 13:59:31 +03003609 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003610
David Weinehall36cdd012016-08-22 13:59:31 +03003611 return single_open(file, i915_displayport_test_data_show,
3612 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003613}
3614
3615static const struct file_operations i915_displayport_test_data_fops = {
3616 .owner = THIS_MODULE,
3617 .open = i915_displayport_test_data_open,
3618 .read = seq_read,
3619 .llseek = seq_lseek,
3620 .release = single_release
3621};
3622
3623static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3624{
3625 struct drm_device *dev = m->private;
3626 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003627 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003628 struct intel_dp *intel_dp;
3629
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003630 drm_connector_list_iter_begin(dev, &conn_iter);
3631 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003632 struct intel_encoder *encoder;
3633
Todd Previteeb3394fa2015-04-18 00:04:19 -07003634 if (connector->connector_type !=
3635 DRM_MODE_CONNECTOR_DisplayPort)
3636 continue;
3637
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003638 encoder = to_intel_encoder(connector->encoder);
3639 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3640 continue;
3641
3642 if (encoder && connector->status == connector_status_connected) {
3643 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003644 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003645 } else
3646 seq_puts(m, "0");
3647 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003648 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003649
3650 return 0;
3651}
3652
3653static int i915_displayport_test_type_open(struct inode *inode,
3654 struct file *file)
3655{
David Weinehall36cdd012016-08-22 13:59:31 +03003656 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003657
David Weinehall36cdd012016-08-22 13:59:31 +03003658 return single_open(file, i915_displayport_test_type_show,
3659 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003660}
3661
3662static const struct file_operations i915_displayport_test_type_fops = {
3663 .owner = THIS_MODULE,
3664 .open = i915_displayport_test_type_open,
3665 .read = seq_read,
3666 .llseek = seq_lseek,
3667 .release = single_release
3668};
3669
Damien Lespiau97e94b22014-11-04 17:06:50 +00003670static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003671{
David Weinehall36cdd012016-08-22 13:59:31 +03003672 struct drm_i915_private *dev_priv = m->private;
3673 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003674 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003675 int num_levels;
3676
David Weinehall36cdd012016-08-22 13:59:31 +03003677 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003678 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003679 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003680 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003681 else if (IS_G4X(dev_priv))
3682 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003683 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003684 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003685
3686 drm_modeset_lock_all(dev);
3687
3688 for (level = 0; level < num_levels; level++) {
3689 unsigned int latency = wm[level];
3690
Damien Lespiau97e94b22014-11-04 17:06:50 +00003691 /*
3692 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003693 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003694 */
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003695 if (INTEL_GEN(dev_priv) >= 9 ||
3696 IS_VALLEYVIEW(dev_priv) ||
3697 IS_CHERRYVIEW(dev_priv) ||
3698 IS_G4X(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003699 latency *= 10;
3700 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003701 latency *= 5;
3702
3703 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003704 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003705 }
3706
3707 drm_modeset_unlock_all(dev);
3708}
3709
3710static int pri_wm_latency_show(struct seq_file *m, void *data)
3711{
David Weinehall36cdd012016-08-22 13:59:31 +03003712 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003713 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003714
David Weinehall36cdd012016-08-22 13:59:31 +03003715 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003716 latencies = dev_priv->wm.skl_latency;
3717 else
David Weinehall36cdd012016-08-22 13:59:31 +03003718 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003719
3720 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003721
3722 return 0;
3723}
3724
3725static int spr_wm_latency_show(struct seq_file *m, void *data)
3726{
David Weinehall36cdd012016-08-22 13:59:31 +03003727 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003728 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003729
David Weinehall36cdd012016-08-22 13:59:31 +03003730 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003731 latencies = dev_priv->wm.skl_latency;
3732 else
David Weinehall36cdd012016-08-22 13:59:31 +03003733 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003734
3735 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003736
3737 return 0;
3738}
3739
3740static int cur_wm_latency_show(struct seq_file *m, void *data)
3741{
David Weinehall36cdd012016-08-22 13:59:31 +03003742 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003743 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003744
David Weinehall36cdd012016-08-22 13:59:31 +03003745 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003746 latencies = dev_priv->wm.skl_latency;
3747 else
David Weinehall36cdd012016-08-22 13:59:31 +03003748 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003749
3750 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003751
3752 return 0;
3753}
3754
3755static int pri_wm_latency_open(struct inode *inode, struct file *file)
3756{
David Weinehall36cdd012016-08-22 13:59:31 +03003757 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003758
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003759 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003760 return -ENODEV;
3761
David Weinehall36cdd012016-08-22 13:59:31 +03003762 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003763}
3764
3765static int spr_wm_latency_open(struct inode *inode, struct file *file)
3766{
David Weinehall36cdd012016-08-22 13:59:31 +03003767 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003768
David Weinehall36cdd012016-08-22 13:59:31 +03003769 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003770 return -ENODEV;
3771
David Weinehall36cdd012016-08-22 13:59:31 +03003772 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003773}
3774
3775static int cur_wm_latency_open(struct inode *inode, struct file *file)
3776{
David Weinehall36cdd012016-08-22 13:59:31 +03003777 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003778
David Weinehall36cdd012016-08-22 13:59:31 +03003779 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003780 return -ENODEV;
3781
David Weinehall36cdd012016-08-22 13:59:31 +03003782 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003783}
3784
3785static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003786 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003787{
3788 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003789 struct drm_i915_private *dev_priv = m->private;
3790 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003791 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03003792 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003793 int level;
3794 int ret;
3795 char tmp[32];
3796
David Weinehall36cdd012016-08-22 13:59:31 +03003797 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003798 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003799 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003800 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003801 else if (IS_G4X(dev_priv))
3802 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003803 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003804 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003805
Ville Syrjälä369a1342014-01-22 14:36:08 +02003806 if (len >= sizeof(tmp))
3807 return -EINVAL;
3808
3809 if (copy_from_user(tmp, ubuf, len))
3810 return -EFAULT;
3811
3812 tmp[len] = '\0';
3813
Damien Lespiau97e94b22014-11-04 17:06:50 +00003814 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3815 &new[0], &new[1], &new[2], &new[3],
3816 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003817 if (ret != num_levels)
3818 return -EINVAL;
3819
3820 drm_modeset_lock_all(dev);
3821
3822 for (level = 0; level < num_levels; level++)
3823 wm[level] = new[level];
3824
3825 drm_modeset_unlock_all(dev);
3826
3827 return len;
3828}
3829
3830
3831static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3832 size_t len, loff_t *offp)
3833{
3834 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003835 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003836 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003837
David Weinehall36cdd012016-08-22 13:59:31 +03003838 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003839 latencies = dev_priv->wm.skl_latency;
3840 else
David Weinehall36cdd012016-08-22 13:59:31 +03003841 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003842
3843 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003844}
3845
3846static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3847 size_t len, loff_t *offp)
3848{
3849 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003850 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003851 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003852
David Weinehall36cdd012016-08-22 13:59:31 +03003853 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003854 latencies = dev_priv->wm.skl_latency;
3855 else
David Weinehall36cdd012016-08-22 13:59:31 +03003856 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003857
3858 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003859}
3860
3861static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3862 size_t len, loff_t *offp)
3863{
3864 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003865 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003866 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003867
David Weinehall36cdd012016-08-22 13:59:31 +03003868 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003869 latencies = dev_priv->wm.skl_latency;
3870 else
David Weinehall36cdd012016-08-22 13:59:31 +03003871 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003872
3873 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003874}
3875
3876static const struct file_operations i915_pri_wm_latency_fops = {
3877 .owner = THIS_MODULE,
3878 .open = pri_wm_latency_open,
3879 .read = seq_read,
3880 .llseek = seq_lseek,
3881 .release = single_release,
3882 .write = pri_wm_latency_write
3883};
3884
3885static const struct file_operations i915_spr_wm_latency_fops = {
3886 .owner = THIS_MODULE,
3887 .open = spr_wm_latency_open,
3888 .read = seq_read,
3889 .llseek = seq_lseek,
3890 .release = single_release,
3891 .write = spr_wm_latency_write
3892};
3893
3894static const struct file_operations i915_cur_wm_latency_fops = {
3895 .owner = THIS_MODULE,
3896 .open = cur_wm_latency_open,
3897 .read = seq_read,
3898 .llseek = seq_lseek,
3899 .release = single_release,
3900 .write = cur_wm_latency_write
3901};
3902
Kees Cook647416f2013-03-10 14:10:06 -07003903static int
3904i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003905{
David Weinehall36cdd012016-08-22 13:59:31 +03003906 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003907
Chris Wilsond98c52c2016-04-13 17:35:05 +01003908 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003909
Kees Cook647416f2013-03-10 14:10:06 -07003910 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003911}
3912
Kees Cook647416f2013-03-10 14:10:06 -07003913static int
3914i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003915{
Chris Wilson598b6b52017-03-25 13:47:35 +00003916 struct drm_i915_private *i915 = data;
3917 struct intel_engine_cs *engine;
3918 unsigned int tmp;
Imre Deakd46c0512014-04-14 20:24:27 +03003919
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003920 /*
3921 * There is no safeguard against this debugfs entry colliding
3922 * with the hangcheck calling same i915_handle_error() in
3923 * parallel, causing an explosion. For now we assume that the
3924 * test harness is responsible enough not to inject gpu hangs
3925 * while it is writing to 'i915_wedged'
3926 */
3927
Chris Wilson598b6b52017-03-25 13:47:35 +00003928 if (i915_reset_backoff(&i915->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003929 return -EAGAIN;
3930
Chris Wilson598b6b52017-03-25 13:47:35 +00003931 for_each_engine_masked(engine, i915, val, tmp) {
3932 engine->hangcheck.seqno = intel_engine_get_seqno(engine);
3933 engine->hangcheck.stalled = true;
3934 }
Imre Deakd46c0512014-04-14 20:24:27 +03003935
Chris Wilson598b6b52017-03-25 13:47:35 +00003936 i915_handle_error(i915, val, "Manually setting wedged to %llu", val);
3937
3938 wait_on_bit(&i915->gpu_error.flags,
Chris Wilsond3df42b2017-03-16 17:13:05 +00003939 I915_RESET_HANDOFF,
3940 TASK_UNINTERRUPTIBLE);
3941
Kees Cook647416f2013-03-10 14:10:06 -07003942 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003943}
3944
Kees Cook647416f2013-03-10 14:10:06 -07003945DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3946 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003947 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003948
Kees Cook647416f2013-03-10 14:10:06 -07003949static int
Chris Wilson64486ae2017-03-07 15:59:08 +00003950fault_irq_set(struct drm_i915_private *i915,
3951 unsigned long *irq,
3952 unsigned long val)
3953{
3954 int err;
3955
3956 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
3957 if (err)
3958 return err;
3959
3960 err = i915_gem_wait_for_idle(i915,
3961 I915_WAIT_LOCKED |
3962 I915_WAIT_INTERRUPTIBLE);
3963 if (err)
3964 goto err_unlock;
3965
Chris Wilson64486ae2017-03-07 15:59:08 +00003966 *irq = val;
3967 mutex_unlock(&i915->drm.struct_mutex);
3968
3969 /* Flush idle worker to disarm irq */
Chris Wilson7c262402017-10-06 11:40:38 +01003970 drain_delayed_work(&i915->gt.idle_work);
Chris Wilson64486ae2017-03-07 15:59:08 +00003971
3972 return 0;
3973
3974err_unlock:
3975 mutex_unlock(&i915->drm.struct_mutex);
3976 return err;
3977}
3978
3979static int
Chris Wilson094f9a52013-09-25 17:34:55 +01003980i915_ring_missed_irq_get(void *data, u64 *val)
3981{
David Weinehall36cdd012016-08-22 13:59:31 +03003982 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01003983
3984 *val = dev_priv->gpu_error.missed_irq_rings;
3985 return 0;
3986}
3987
3988static int
3989i915_ring_missed_irq_set(void *data, u64 val)
3990{
Chris Wilson64486ae2017-03-07 15:59:08 +00003991 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01003992
Chris Wilson64486ae2017-03-07 15:59:08 +00003993 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01003994}
3995
3996DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3997 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3998 "0x%08llx\n");
3999
4000static int
4001i915_ring_test_irq_get(void *data, u64 *val)
4002{
David Weinehall36cdd012016-08-22 13:59:31 +03004003 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004004
4005 *val = dev_priv->gpu_error.test_irq_rings;
4006
4007 return 0;
4008}
4009
4010static int
4011i915_ring_test_irq_set(void *data, u64 val)
4012{
Chris Wilson64486ae2017-03-07 15:59:08 +00004013 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004014
Chris Wilson64486ae2017-03-07 15:59:08 +00004015 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004016 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004017
Chris Wilson64486ae2017-03-07 15:59:08 +00004018 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004019}
4020
4021DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4022 i915_ring_test_irq_get, i915_ring_test_irq_set,
4023 "0x%08llx\n");
4024
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004025#define DROP_UNBOUND BIT(0)
4026#define DROP_BOUND BIT(1)
4027#define DROP_RETIRE BIT(2)
4028#define DROP_ACTIVE BIT(3)
4029#define DROP_FREED BIT(4)
4030#define DROP_SHRINK_ALL BIT(5)
4031#define DROP_IDLE BIT(6)
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004032#define DROP_ALL (DROP_UNBOUND | \
4033 DROP_BOUND | \
4034 DROP_RETIRE | \
4035 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004036 DROP_FREED | \
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004037 DROP_SHRINK_ALL |\
4038 DROP_IDLE)
Kees Cook647416f2013-03-10 14:10:06 -07004039static int
4040i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004041{
Kees Cook647416f2013-03-10 14:10:06 -07004042 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004043
Kees Cook647416f2013-03-10 14:10:06 -07004044 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004045}
4046
Kees Cook647416f2013-03-10 14:10:06 -07004047static int
4048i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004049{
David Weinehall36cdd012016-08-22 13:59:31 +03004050 struct drm_i915_private *dev_priv = data;
4051 struct drm_device *dev = &dev_priv->drm;
Chris Wilson00c26cf2017-05-24 17:26:53 +01004052 int ret = 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004053
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004054 DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
4055 val, val & DROP_ALL);
Chris Wilsondd624af2013-01-15 12:39:35 +00004056
4057 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4058 * on ioctls on -EAGAIN. */
Chris Wilson00c26cf2017-05-24 17:26:53 +01004059 if (val & (DROP_ACTIVE | DROP_RETIRE)) {
4060 ret = mutex_lock_interruptible(&dev->struct_mutex);
Chris Wilsondd624af2013-01-15 12:39:35 +00004061 if (ret)
Chris Wilson00c26cf2017-05-24 17:26:53 +01004062 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004063
Chris Wilson00c26cf2017-05-24 17:26:53 +01004064 if (val & DROP_ACTIVE)
4065 ret = i915_gem_wait_for_idle(dev_priv,
4066 I915_WAIT_INTERRUPTIBLE |
4067 I915_WAIT_LOCKED);
4068
4069 if (val & DROP_RETIRE)
4070 i915_gem_retire_requests(dev_priv);
4071
4072 mutex_unlock(&dev->struct_mutex);
4073 }
Chris Wilsondd624af2013-01-15 12:39:35 +00004074
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +01004075 fs_reclaim_acquire(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004076 if (val & DROP_BOUND)
Chris Wilson912d5722017-09-06 16:19:30 -07004077 i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004078
Chris Wilson21ab4e72014-09-09 11:16:08 +01004079 if (val & DROP_UNBOUND)
Chris Wilson912d5722017-09-06 16:19:30 -07004080 i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004081
Chris Wilson8eadc192017-03-08 14:46:22 +00004082 if (val & DROP_SHRINK_ALL)
4083 i915_gem_shrink_all(dev_priv);
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +01004084 fs_reclaim_release(GFP_KERNEL);
Chris Wilson8eadc192017-03-08 14:46:22 +00004085
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004086 if (val & DROP_IDLE)
4087 drain_delayed_work(&dev_priv->gt.idle_work);
4088
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004089 if (val & DROP_FREED) {
4090 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004091 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004092 }
4093
Kees Cook647416f2013-03-10 14:10:06 -07004094 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004095}
4096
Kees Cook647416f2013-03-10 14:10:06 -07004097DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4098 i915_drop_caches_get, i915_drop_caches_set,
4099 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004100
Kees Cook647416f2013-03-10 14:10:06 -07004101static int
4102i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004103{
David Weinehall36cdd012016-08-22 13:59:31 +03004104 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004105
David Weinehall36cdd012016-08-22 13:59:31 +03004106 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004107 return -ENODEV;
4108
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004109 *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004110 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004111}
4112
Kees Cook647416f2013-03-10 14:10:06 -07004113static int
4114i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004115{
David Weinehall36cdd012016-08-22 13:59:31 +03004116 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004117 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304118 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004119 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004120
David Weinehall36cdd012016-08-22 13:59:31 +03004121 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004122 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004123
Kees Cook647416f2013-03-10 14:10:06 -07004124 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004125
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004126 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004127 if (ret)
4128 return ret;
4129
Jesse Barnes358733e2011-07-27 11:53:01 -07004130 /*
4131 * Turbo will still be enabled, but won't go above the set value.
4132 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304133 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004134
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004135 hw_max = rps->max_freq;
4136 hw_min = rps->min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004137
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004138 if (val < hw_min || val > hw_max || val < rps->min_freq_softlimit) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004139 mutex_unlock(&dev_priv->pcu_lock);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004140 return -EINVAL;
4141 }
4142
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004143 rps->max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004144
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004145 if (intel_set_rps(dev_priv, val))
4146 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004147
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004148 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004149
Kees Cook647416f2013-03-10 14:10:06 -07004150 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004151}
4152
Kees Cook647416f2013-03-10 14:10:06 -07004153DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4154 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004155 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004156
Kees Cook647416f2013-03-10 14:10:06 -07004157static int
4158i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004159{
David Weinehall36cdd012016-08-22 13:59:31 +03004160 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004161
Chris Wilson62e1baa2016-07-13 09:10:36 +01004162 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004163 return -ENODEV;
4164
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004165 *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004166 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004167}
4168
Kees Cook647416f2013-03-10 14:10:06 -07004169static int
4170i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004171{
David Weinehall36cdd012016-08-22 13:59:31 +03004172 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004173 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304174 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004175 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004176
Chris Wilson62e1baa2016-07-13 09:10:36 +01004177 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004178 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004179
Kees Cook647416f2013-03-10 14:10:06 -07004180 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004181
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004182 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004183 if (ret)
4184 return ret;
4185
Jesse Barnes1523c312012-05-25 12:34:54 -07004186 /*
4187 * Turbo will still be enabled, but won't go below the set value.
4188 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304189 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004190
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004191 hw_max = rps->max_freq;
4192 hw_min = rps->min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004193
David Weinehall36cdd012016-08-22 13:59:31 +03004194 if (val < hw_min ||
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004195 val > hw_max || val > rps->max_freq_softlimit) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004196 mutex_unlock(&dev_priv->pcu_lock);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004197 return -EINVAL;
4198 }
4199
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004200 rps->min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004201
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004202 if (intel_set_rps(dev_priv, val))
4203 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004204
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004205 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004206
Kees Cook647416f2013-03-10 14:10:06 -07004207 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004208}
4209
Kees Cook647416f2013-03-10 14:10:06 -07004210DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4211 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004212 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004213
Kees Cook647416f2013-03-10 14:10:06 -07004214static int
4215i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004216{
David Weinehall36cdd012016-08-22 13:59:31 +03004217 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004218 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004219
David Weinehall36cdd012016-08-22 13:59:31 +03004220 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004221 return -ENODEV;
4222
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004223 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004224
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004225 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004226
4227 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004228
Kees Cook647416f2013-03-10 14:10:06 -07004229 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004230
Kees Cook647416f2013-03-10 14:10:06 -07004231 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004232}
4233
Kees Cook647416f2013-03-10 14:10:06 -07004234static int
4235i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004236{
David Weinehall36cdd012016-08-22 13:59:31 +03004237 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004238 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004239
David Weinehall36cdd012016-08-22 13:59:31 +03004240 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004241 return -ENODEV;
4242
Kees Cook647416f2013-03-10 14:10:06 -07004243 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004244 return -EINVAL;
4245
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004246 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004247 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004248
4249 /* Update the cache sharing policy here as well */
4250 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4251 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4252 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4253 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4254
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004255 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004256 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004257}
4258
Kees Cook647416f2013-03-10 14:10:06 -07004259DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4260 i915_cache_sharing_get, i915_cache_sharing_set,
4261 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004262
David Weinehall36cdd012016-08-22 13:59:31 +03004263static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004264 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004265{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004266 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004267 int ss;
4268 u32 sig1[ss_max], sig2[ss_max];
4269
4270 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4271 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4272 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4273 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4274
4275 for (ss = 0; ss < ss_max; ss++) {
4276 unsigned int eu_cnt;
4277
4278 if (sig1[ss] & CHV_SS_PG_ENABLE)
4279 /* skip disabled subslice */
4280 continue;
4281
Imre Deakf08a0c92016-08-31 19:13:04 +03004282 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004283 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004284 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4285 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4286 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4287 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004288 sseu->eu_total += eu_cnt;
4289 sseu->eu_per_subslice = max_t(unsigned int,
4290 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004291 }
Jeff McGee5d395252015-04-03 18:13:17 -07004292}
4293
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004294static void gen10_sseu_device_status(struct drm_i915_private *dev_priv,
4295 struct sseu_dev_info *sseu)
4296{
4297 const struct intel_device_info *info = INTEL_INFO(dev_priv);
4298 int s_max = 6, ss_max = 4;
4299 int s, ss;
4300 u32 s_reg[s_max], eu_reg[2 * s_max], eu_mask[2];
4301
4302 for (s = 0; s < s_max; s++) {
4303 /*
4304 * FIXME: Valid SS Mask respects the spec and read
4305 * only valid bits for those registers, excluding reserverd
4306 * although this seems wrong because it would leave many
4307 * subslices without ACK.
4308 */
4309 s_reg[s] = I915_READ(GEN10_SLICE_PGCTL_ACK(s)) &
4310 GEN10_PGCTL_VALID_SS_MASK(s);
4311 eu_reg[2 * s] = I915_READ(GEN10_SS01_EU_PGCTL_ACK(s));
4312 eu_reg[2 * s + 1] = I915_READ(GEN10_SS23_EU_PGCTL_ACK(s));
4313 }
4314
4315 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4316 GEN9_PGCTL_SSA_EU19_ACK |
4317 GEN9_PGCTL_SSA_EU210_ACK |
4318 GEN9_PGCTL_SSA_EU311_ACK;
4319 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4320 GEN9_PGCTL_SSB_EU19_ACK |
4321 GEN9_PGCTL_SSB_EU210_ACK |
4322 GEN9_PGCTL_SSB_EU311_ACK;
4323
4324 for (s = 0; s < s_max; s++) {
4325 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4326 /* skip disabled slice */
4327 continue;
4328
4329 sseu->slice_mask |= BIT(s);
4330 sseu->subslice_mask = info->sseu.subslice_mask;
4331
4332 for (ss = 0; ss < ss_max; ss++) {
4333 unsigned int eu_cnt;
4334
4335 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4336 /* skip disabled subslice */
4337 continue;
4338
4339 eu_cnt = 2 * hweight32(eu_reg[2 * s + ss / 2] &
4340 eu_mask[ss % 2]);
4341 sseu->eu_total += eu_cnt;
4342 sseu->eu_per_subslice = max_t(unsigned int,
4343 sseu->eu_per_subslice,
4344 eu_cnt);
4345 }
4346 }
4347}
4348
David Weinehall36cdd012016-08-22 13:59:31 +03004349static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004350 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004351{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004352 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004353 int s, ss;
4354 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4355
Jeff McGee1c046bc2015-04-03 18:13:18 -07004356 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004357 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004358 s_max = 1;
4359 ss_max = 3;
4360 }
4361
4362 for (s = 0; s < s_max; s++) {
4363 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4364 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4365 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4366 }
4367
Jeff McGee5d395252015-04-03 18:13:17 -07004368 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4369 GEN9_PGCTL_SSA_EU19_ACK |
4370 GEN9_PGCTL_SSA_EU210_ACK |
4371 GEN9_PGCTL_SSA_EU311_ACK;
4372 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4373 GEN9_PGCTL_SSB_EU19_ACK |
4374 GEN9_PGCTL_SSB_EU210_ACK |
4375 GEN9_PGCTL_SSB_EU311_ACK;
4376
4377 for (s = 0; s < s_max; s++) {
4378 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4379 /* skip disabled slice */
4380 continue;
4381
Imre Deakf08a0c92016-08-31 19:13:04 +03004382 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004383
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004384 if (IS_GEN9_BC(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004385 sseu->subslice_mask =
4386 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004387
Jeff McGee5d395252015-04-03 18:13:17 -07004388 for (ss = 0; ss < ss_max; ss++) {
4389 unsigned int eu_cnt;
4390
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004391 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004392 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4393 /* skip disabled subslice */
4394 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004395
Imre Deak57ec1712016-08-31 19:13:05 +03004396 sseu->subslice_mask |= BIT(ss);
4397 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004398
Jeff McGee5d395252015-04-03 18:13:17 -07004399 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4400 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004401 sseu->eu_total += eu_cnt;
4402 sseu->eu_per_subslice = max_t(unsigned int,
4403 sseu->eu_per_subslice,
4404 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004405 }
4406 }
4407}
4408
David Weinehall36cdd012016-08-22 13:59:31 +03004409static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004410 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004411{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004412 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004413 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004414
Imre Deakf08a0c92016-08-31 19:13:04 +03004415 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004416
Imre Deakf08a0c92016-08-31 19:13:04 +03004417 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004418 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004419 sseu->eu_per_subslice =
4420 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004421 sseu->eu_total = sseu->eu_per_subslice *
4422 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004423
4424 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004425 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004426 u8 subslice_7eu =
4427 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004428
Imre Deak915490d2016-08-31 19:13:01 +03004429 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004430 }
4431 }
4432}
4433
Imre Deak615d8902016-08-31 19:13:03 +03004434static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4435 const struct sseu_dev_info *sseu)
4436{
4437 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4438 const char *type = is_available_info ? "Available" : "Enabled";
4439
Imre Deakc67ba532016-08-31 19:13:06 +03004440 seq_printf(m, " %s Slice Mask: %04x\n", type,
4441 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004442 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004443 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004444 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004445 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004446 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4447 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004448 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004449 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004450 seq_printf(m, " %s EU Total: %u\n", type,
4451 sseu->eu_total);
4452 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4453 sseu->eu_per_subslice);
4454
4455 if (!is_available_info)
4456 return;
4457
4458 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4459 if (HAS_POOLED_EU(dev_priv))
4460 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4461
4462 seq_printf(m, " Has Slice Power Gating: %s\n",
4463 yesno(sseu->has_slice_pg));
4464 seq_printf(m, " Has Subslice Power Gating: %s\n",
4465 yesno(sseu->has_subslice_pg));
4466 seq_printf(m, " Has EU Power Gating: %s\n",
4467 yesno(sseu->has_eu_pg));
4468}
4469
Jeff McGee38732182015-02-13 10:27:54 -06004470static int i915_sseu_status(struct seq_file *m, void *unused)
4471{
David Weinehall36cdd012016-08-22 13:59:31 +03004472 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004473 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004474
David Weinehall36cdd012016-08-22 13:59:31 +03004475 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004476 return -ENODEV;
4477
4478 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004479 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004480
Jeff McGee7f992ab2015-02-13 10:27:55 -06004481 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004482 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004483
4484 intel_runtime_pm_get(dev_priv);
4485
David Weinehall36cdd012016-08-22 13:59:31 +03004486 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004487 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004488 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004489 broadwell_sseu_device_status(dev_priv, &sseu);
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004490 } else if (IS_GEN9(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004491 gen9_sseu_device_status(dev_priv, &sseu);
Rodrigo Vivif8c3dcf2017-10-25 17:15:46 -07004492 } else if (INTEL_GEN(dev_priv) >= 10) {
4493 gen10_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004494 }
David Weinehall238010e2016-08-01 17:33:27 +03004495
4496 intel_runtime_pm_put(dev_priv);
4497
Imre Deak615d8902016-08-31 19:13:03 +03004498 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004499
Jeff McGee38732182015-02-13 10:27:54 -06004500 return 0;
4501}
4502
Ben Widawsky6d794d42011-04-25 11:25:56 -07004503static int i915_forcewake_open(struct inode *inode, struct file *file)
4504{
Chris Wilsond7a133d2017-09-07 14:44:41 +01004505 struct drm_i915_private *i915 = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004506
Chris Wilsond7a133d2017-09-07 14:44:41 +01004507 if (INTEL_GEN(i915) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004508 return 0;
4509
Chris Wilsond7a133d2017-09-07 14:44:41 +01004510 intel_runtime_pm_get(i915);
4511 intel_uncore_forcewake_user_get(i915);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004512
4513 return 0;
4514}
4515
Ben Widawskyc43b5632012-04-16 14:07:40 -07004516static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004517{
Chris Wilsond7a133d2017-09-07 14:44:41 +01004518 struct drm_i915_private *i915 = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004519
Chris Wilsond7a133d2017-09-07 14:44:41 +01004520 if (INTEL_GEN(i915) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004521 return 0;
4522
Chris Wilsond7a133d2017-09-07 14:44:41 +01004523 intel_uncore_forcewake_user_put(i915);
4524 intel_runtime_pm_put(i915);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004525
4526 return 0;
4527}
4528
4529static const struct file_operations i915_forcewake_fops = {
4530 .owner = THIS_MODULE,
4531 .open = i915_forcewake_open,
4532 .release = i915_forcewake_release,
4533};
4534
Lyude317eaa92017-02-03 21:18:25 -05004535static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4536{
4537 struct drm_i915_private *dev_priv = m->private;
4538 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4539
4540 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4541 seq_printf(m, "Detected: %s\n",
4542 yesno(delayed_work_pending(&hotplug->reenable_work)));
4543
4544 return 0;
4545}
4546
4547static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4548 const char __user *ubuf, size_t len,
4549 loff_t *offp)
4550{
4551 struct seq_file *m = file->private_data;
4552 struct drm_i915_private *dev_priv = m->private;
4553 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4554 unsigned int new_threshold;
4555 int i;
4556 char *newline;
4557 char tmp[16];
4558
4559 if (len >= sizeof(tmp))
4560 return -EINVAL;
4561
4562 if (copy_from_user(tmp, ubuf, len))
4563 return -EFAULT;
4564
4565 tmp[len] = '\0';
4566
4567 /* Strip newline, if any */
4568 newline = strchr(tmp, '\n');
4569 if (newline)
4570 *newline = '\0';
4571
4572 if (strcmp(tmp, "reset") == 0)
4573 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4574 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4575 return -EINVAL;
4576
4577 if (new_threshold > 0)
4578 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4579 new_threshold);
4580 else
4581 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4582
4583 spin_lock_irq(&dev_priv->irq_lock);
4584 hotplug->hpd_storm_threshold = new_threshold;
4585 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4586 for_each_hpd_pin(i)
4587 hotplug->stats[i].count = 0;
4588 spin_unlock_irq(&dev_priv->irq_lock);
4589
4590 /* Re-enable hpd immediately if we were in an irq storm */
4591 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4592
4593 return len;
4594}
4595
4596static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4597{
4598 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4599}
4600
4601static const struct file_operations i915_hpd_storm_ctl_fops = {
4602 .owner = THIS_MODULE,
4603 .open = i915_hpd_storm_ctl_open,
4604 .read = seq_read,
4605 .llseek = seq_lseek,
4606 .release = single_release,
4607 .write = i915_hpd_storm_ctl_write
4608};
4609
C, Ramalingam35954e82017-11-08 00:08:23 +05304610static int i915_drrs_ctl_set(void *data, u64 val)
4611{
4612 struct drm_i915_private *dev_priv = data;
4613 struct drm_device *dev = &dev_priv->drm;
4614 struct intel_crtc *intel_crtc;
4615 struct intel_encoder *encoder;
4616 struct intel_dp *intel_dp;
4617
4618 if (INTEL_GEN(dev_priv) < 7)
4619 return -ENODEV;
4620
4621 drm_modeset_lock_all(dev);
4622 for_each_intel_crtc(dev, intel_crtc) {
4623 if (!intel_crtc->base.state->active ||
4624 !intel_crtc->config->has_drrs)
4625 continue;
4626
4627 for_each_encoder_on_crtc(dev, &intel_crtc->base, encoder) {
4628 if (encoder->type != INTEL_OUTPUT_EDP)
4629 continue;
4630
4631 DRM_DEBUG_DRIVER("Manually %sabling DRRS. %llu\n",
4632 val ? "en" : "dis", val);
4633
4634 intel_dp = enc_to_intel_dp(&encoder->base);
4635 if (val)
4636 intel_edp_drrs_enable(intel_dp,
4637 intel_crtc->config);
4638 else
4639 intel_edp_drrs_disable(intel_dp,
4640 intel_crtc->config);
4641 }
4642 }
4643 drm_modeset_unlock_all(dev);
4644
4645 return 0;
4646}
4647
4648DEFINE_SIMPLE_ATTRIBUTE(i915_drrs_ctl_fops, NULL, i915_drrs_ctl_set, "%llu\n");
4649
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004650static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004651 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004652 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004653 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004654 {"i915_gem_stolen", i915_gem_stolen_list_info },
Chris Wilsona6172a82009-02-11 14:26:38 +00004655 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004656 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004657 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004658 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004659 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004660 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07004661 {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
Oscar Mateoa8b93702017-05-10 15:04:51 +00004662 {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004663 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304664 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004665 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Michel Thierry061d06a2017-06-20 10:57:49 +01004666 {"i915_reset_info", i915_reset_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004667 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004668 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004669 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004670 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004671 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004672 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004673 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004674 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004675 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004676 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004677 {"i915_context_status", i915_context_status, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004678 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004679 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004680 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004681 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004682 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004683 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004684 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004685 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004686 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004687 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004688 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004689 {"i915_engine_info", i915_engine_info, 0},
Chris Wilsonc5418a82017-10-13 21:26:19 +01004690 {"i915_shrinker_info", i915_shrinker_info, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004691 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004692 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004693 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004694 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004695 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304696 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004697 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004698};
Ben Gamari27c202a2009-07-01 22:26:52 -04004699#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004700
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004701static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004702 const char *name;
4703 const struct file_operations *fops;
4704} i915_debugfs_files[] = {
4705 {"i915_wedged", &i915_wedged_fops},
4706 {"i915_max_freq", &i915_max_freq_fops},
4707 {"i915_min_freq", &i915_min_freq_fops},
4708 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004709 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4710 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004711 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004712#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004713 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004714 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004715#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004716 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004717 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004718 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4719 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4720 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Ville Syrjälä4127dc42017-06-06 15:44:12 +03004721 {"i915_fbc_false_color", &i915_fbc_false_color_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004722 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4723 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304724 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004725 {"i915_guc_log_control", &i915_guc_log_control_fops},
Kumar, Maheshd2d4f392017-08-17 19:15:29 +05304726 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops},
C, Ramalingam35954e82017-11-08 00:08:23 +05304727 {"i915_ipc_status", &i915_ipc_status_fops},
4728 {"i915_drrs_ctl", &i915_drrs_ctl_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004729};
4730
Chris Wilson1dac8912016-06-24 14:00:17 +01004731int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004732{
Chris Wilson91c8a322016-07-05 10:40:23 +01004733 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004734 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004735 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004736
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004737 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4738 minor->debugfs_root, to_i915(minor->dev),
4739 &i915_forcewake_fops);
4740 if (!ent)
4741 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004742
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004743 ret = intel_pipe_crc_create(minor);
4744 if (ret)
4745 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004746
Daniel Vetter34b96742013-07-04 20:49:44 +02004747 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004748 ent = debugfs_create_file(i915_debugfs_files[i].name,
4749 S_IRUGO | S_IWUSR,
4750 minor->debugfs_root,
4751 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004752 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004753 if (!ent)
4754 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004755 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004756
Ben Gamari27c202a2009-07-01 22:26:52 -04004757 return drm_debugfs_create_files(i915_debugfs_list,
4758 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004759 minor->debugfs_root, minor);
4760}
4761
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004762struct dpcd_block {
4763 /* DPCD dump start address. */
4764 unsigned int offset;
4765 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4766 unsigned int end;
4767 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4768 size_t size;
4769 /* Only valid for eDP. */
4770 bool edp;
4771};
4772
4773static const struct dpcd_block i915_dpcd_debug[] = {
4774 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4775 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4776 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4777 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4778 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4779 { .offset = DP_SET_POWER },
4780 { .offset = DP_EDP_DPCD_REV },
4781 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4782 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4783 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4784};
4785
4786static int i915_dpcd_show(struct seq_file *m, void *data)
4787{
4788 struct drm_connector *connector = m->private;
4789 struct intel_dp *intel_dp =
4790 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4791 uint8_t buf[16];
4792 ssize_t err;
4793 int i;
4794
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004795 if (connector->status != connector_status_connected)
4796 return -ENODEV;
4797
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004798 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4799 const struct dpcd_block *b = &i915_dpcd_debug[i];
4800 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4801
4802 if (b->edp &&
4803 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4804 continue;
4805
4806 /* low tech for now */
4807 if (WARN_ON(size > sizeof(buf)))
4808 continue;
4809
4810 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4811 if (err <= 0) {
4812 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4813 size, b->offset, err);
4814 continue;
4815 }
4816
4817 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004818 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004819
4820 return 0;
4821}
4822
4823static int i915_dpcd_open(struct inode *inode, struct file *file)
4824{
4825 return single_open(file, i915_dpcd_show, inode->i_private);
4826}
4827
4828static const struct file_operations i915_dpcd_fops = {
4829 .owner = THIS_MODULE,
4830 .open = i915_dpcd_open,
4831 .read = seq_read,
4832 .llseek = seq_lseek,
4833 .release = single_release,
4834};
4835
David Weinehallecbd6782016-08-23 12:23:56 +03004836static int i915_panel_show(struct seq_file *m, void *data)
4837{
4838 struct drm_connector *connector = m->private;
4839 struct intel_dp *intel_dp =
4840 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4841
4842 if (connector->status != connector_status_connected)
4843 return -ENODEV;
4844
4845 seq_printf(m, "Panel power up delay: %d\n",
4846 intel_dp->panel_power_up_delay);
4847 seq_printf(m, "Panel power down delay: %d\n",
4848 intel_dp->panel_power_down_delay);
4849 seq_printf(m, "Backlight on delay: %d\n",
4850 intel_dp->backlight_on_delay);
4851 seq_printf(m, "Backlight off delay: %d\n",
4852 intel_dp->backlight_off_delay);
4853
4854 return 0;
4855}
4856
4857static int i915_panel_open(struct inode *inode, struct file *file)
4858{
4859 return single_open(file, i915_panel_show, inode->i_private);
4860}
4861
4862static const struct file_operations i915_panel_fops = {
4863 .owner = THIS_MODULE,
4864 .open = i915_panel_open,
4865 .read = seq_read,
4866 .llseek = seq_lseek,
4867 .release = single_release,
4868};
4869
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004870/**
4871 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4872 * @connector: pointer to a registered drm_connector
4873 *
4874 * Cleanup will be done by drm_connector_unregister() through a call to
4875 * drm_debugfs_connector_remove().
4876 *
4877 * Returns 0 on success, negative error codes on error.
4878 */
4879int i915_debugfs_connector_add(struct drm_connector *connector)
4880{
4881 struct dentry *root = connector->debugfs_entry;
4882
4883 /* The connector must have been registered beforehands. */
4884 if (!root)
4885 return -ENODEV;
4886
4887 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4888 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03004889 debugfs_create_file("i915_dpcd", S_IRUGO, root,
4890 connector, &i915_dpcd_fops);
4891
4892 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4893 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
4894 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004895
4896 return 0;
4897}