blob: c65e381b85f3925d41446492df8f4bc4dd18a2de [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"
Michal Wajdeczko9f436c42017-10-04 18:13:40 +000033#include "i915_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 Wilson418e3cd2017-02-06 21:36:08 +000040static __always_inline void seq_print_param(struct seq_file *m,
41 const char *name,
42 const char *type,
43 const void *x)
44{
45 if (!__builtin_strcmp(type, "bool"))
46 seq_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
47 else if (!__builtin_strcmp(type, "int"))
48 seq_printf(m, "i915.%s=%d\n", name, *(const int *)x);
49 else if (!__builtin_strcmp(type, "unsigned int"))
50 seq_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
Chris Wilson1d6aa7a2017-02-21 16:26:19 +000051 else if (!__builtin_strcmp(type, "char *"))
52 seq_printf(m, "i915.%s=%s\n", name, *(const char **)x);
Chris Wilson418e3cd2017-02-06 21:36:08 +000053 else
54 BUILD_BUG();
55}
56
Chris Wilson70d39fe2010-08-25 16:03:34 +010057static int i915_capabilities(struct seq_file *m, void *data)
58{
David Weinehall36cdd012016-08-22 13:59:31 +030059 struct drm_i915_private *dev_priv = node_to_i915(m->private);
60 const struct intel_device_info *info = INTEL_INFO(dev_priv);
Chris Wilson70d39fe2010-08-25 16:03:34 +010061
David Weinehall36cdd012016-08-22 13:59:31 +030062 seq_printf(m, "gen: %d\n", INTEL_GEN(dev_priv));
Jani Nikula2e0d26f2016-12-01 14:49:55 +020063 seq_printf(m, "platform: %s\n", intel_platform_name(info->platform));
David Weinehall36cdd012016-08-22 13:59:31 +030064 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev_priv));
Chris Wilson418e3cd2017-02-06 21:36:08 +000065
Damien Lespiau79fc46d2013-04-23 16:37:17 +010066#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
Joonas Lahtinen604db652016-10-05 13:50:16 +030067 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
Damien Lespiau79fc46d2013-04-23 16:37:17 +010068#undef PRINT_FLAG
Chris Wilson70d39fe2010-08-25 16:03:34 +010069
Chris Wilson418e3cd2017-02-06 21:36:08 +000070 kernel_param_lock(THIS_MODULE);
Michal Wajdeczko7075cb852017-09-25 10:50:07 +000071#define PRINT_PARAM(T, x, ...) seq_print_param(m, #x, #T, &i915_modparams.x);
Chris Wilson418e3cd2017-02-06 21:36:08 +000072 I915_PARAMS_FOR_EACH(PRINT_PARAM);
73#undef PRINT_PARAM
74 kernel_param_unlock(THIS_MODULE);
75
Chris Wilson70d39fe2010-08-25 16:03:34 +010076 return 0;
77}
Ben Gamari433e12f2009-02-17 20:08:51 -050078
Imre Deaka7363de2016-05-12 16:18:52 +030079static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000080{
Chris Wilson573adb32016-08-04 16:32:39 +010081 return i915_gem_object_is_active(obj) ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000082}
83
Imre Deaka7363de2016-05-12 16:18:52 +030084static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010085{
Chris Wilsonbd3d2252017-10-13 21:26:14 +010086 return obj->pin_global ? 'p' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010087}
88
Imre Deaka7363de2016-05-12 16:18:52 +030089static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000090{
Chris Wilson3e510a82016-08-05 10:14:23 +010091 switch (i915_gem_object_get_tiling(obj)) {
Akshay Joshi0206e352011-08-16 15:34:10 -040092 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010093 case I915_TILING_NONE: return ' ';
94 case I915_TILING_X: return 'X';
95 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -040096 }
Chris Wilsona6172a82009-02-11 14:26:38 +000097}
98
Imre Deaka7363de2016-05-12 16:18:52 +030099static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700100{
Chris Wilsona65adaf2017-10-09 09:43:57 +0100101 return obj->userfault_count ? 'g' : ' ';
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100102}
103
Imre Deaka7363de2016-05-12 16:18:52 +0300104static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100105{
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100106 return obj->mm.mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700107}
108
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100109static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
110{
111 u64 size = 0;
112 struct i915_vma *vma;
113
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000114 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson3272db52016-08-04 16:32:32 +0100115 if (i915_vma_is_ggtt(vma) && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100116 size += vma->node.size;
117 }
118
119 return size;
120}
121
Matthew Auld7393b7e2017-10-06 23:18:28 +0100122static const char *
123stringify_page_sizes(unsigned int page_sizes, char *buf, size_t len)
124{
125 size_t x = 0;
126
127 switch (page_sizes) {
128 case 0:
129 return "";
130 case I915_GTT_PAGE_SIZE_4K:
131 return "4K";
132 case I915_GTT_PAGE_SIZE_64K:
133 return "64K";
134 case I915_GTT_PAGE_SIZE_2M:
135 return "2M";
136 default:
137 if (!buf)
138 return "M";
139
140 if (page_sizes & I915_GTT_PAGE_SIZE_2M)
141 x += snprintf(buf + x, len - x, "2M, ");
142 if (page_sizes & I915_GTT_PAGE_SIZE_64K)
143 x += snprintf(buf + x, len - x, "64K, ");
144 if (page_sizes & I915_GTT_PAGE_SIZE_4K)
145 x += snprintf(buf + x, len - x, "4K, ");
146 buf[x-2] = '\0';
147
148 return buf;
149 }
150}
151
Chris Wilson37811fc2010-08-25 22:45:57 +0100152static void
153describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
154{
Chris Wilsonb4716182015-04-27 13:41:17 +0100155 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000156 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700157 struct i915_vma *vma;
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100158 unsigned int frontbuffer_bits;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800159 int pin_count = 0;
160
Chris Wilson188c1ab2016-04-03 14:14:20 +0100161 lockdep_assert_held(&obj->base.dev->struct_mutex);
162
Chris Wilsond07f0e52016-10-28 13:58:44 +0100163 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x %s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100164 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100165 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100166 get_pin_flag(obj),
167 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700168 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100169 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800170 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100171 obj->base.read_domains,
Chris Wilsond07f0e52016-10-28 13:58:44 +0100172 obj->base.write_domain,
David Weinehall36cdd012016-08-22 13:59:31 +0300173 i915_cache_level_str(dev_priv, obj->cache_level),
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100174 obj->mm.dirty ? " dirty" : "",
175 obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
Chris Wilson37811fc2010-08-25 22:45:57 +0100176 if (obj->base.name)
177 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000178 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson20dfbde2016-08-04 16:32:30 +0100179 if (i915_vma_is_pinned(vma))
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800180 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300181 }
182 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsonbd3d2252017-10-13 21:26:14 +0100183 if (obj->pin_global)
184 seq_printf(m, " (global)");
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000185 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson15717de2016-08-04 07:52:26 +0100186 if (!drm_mm_node_allocated(&vma->node))
187 continue;
188
Matthew Auld7393b7e2017-10-06 23:18:28 +0100189 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx, pages: %s",
Chris Wilson3272db52016-08-04 16:32:32 +0100190 i915_vma_is_ggtt(vma) ? "g" : "pp",
Matthew Auld7393b7e2017-10-06 23:18:28 +0100191 vma->node.start, vma->node.size,
192 stringify_page_sizes(vma->page_sizes.gtt, NULL, 0));
Chris Wilson21976852017-01-12 11:21:08 +0000193 if (i915_vma_is_ggtt(vma)) {
194 switch (vma->ggtt_view.type) {
195 case I915_GGTT_VIEW_NORMAL:
196 seq_puts(m, ", normal");
197 break;
198
199 case I915_GGTT_VIEW_PARTIAL:
200 seq_printf(m, ", partial [%08llx+%x]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000201 vma->ggtt_view.partial.offset << PAGE_SHIFT,
202 vma->ggtt_view.partial.size << PAGE_SHIFT);
Chris Wilson21976852017-01-12 11:21:08 +0000203 break;
204
205 case I915_GGTT_VIEW_ROTATED:
206 seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
Chris Wilson8bab11932017-01-14 00:28:25 +0000207 vma->ggtt_view.rotated.plane[0].width,
208 vma->ggtt_view.rotated.plane[0].height,
209 vma->ggtt_view.rotated.plane[0].stride,
210 vma->ggtt_view.rotated.plane[0].offset,
211 vma->ggtt_view.rotated.plane[1].width,
212 vma->ggtt_view.rotated.plane[1].height,
213 vma->ggtt_view.rotated.plane[1].stride,
214 vma->ggtt_view.rotated.plane[1].offset);
Chris Wilson21976852017-01-12 11:21:08 +0000215 break;
216
217 default:
218 MISSING_CASE(vma->ggtt_view.type);
219 break;
220 }
221 }
Chris Wilson49ef5292016-08-18 17:17:00 +0100222 if (vma->fence)
223 seq_printf(m, " , fence: %d%s",
224 vma->fence->id,
225 i915_gem_active_isset(&vma->last_fence) ? "*" : "");
Chris Wilson596c5922016-02-26 11:03:20 +0000226 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700227 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000228 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100229 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100230
Chris Wilsond07f0e52016-10-28 13:58:44 +0100231 engine = i915_gem_object_last_write_engine(obj);
Chris Wilson27c01aa2016-08-04 07:52:30 +0100232 if (engine)
233 seq_printf(m, " (%s)", engine->name);
234
Chris Wilsonfaf5bf02016-08-04 16:32:37 +0100235 frontbuffer_bits = atomic_read(&obj->frontbuffer_bits);
236 if (frontbuffer_bits)
237 seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100238}
239
Chris Wilsone637d2c2017-03-16 13:19:57 +0000240static int obj_rank_by_stolen(const void *A, const void *B)
Chris Wilson6d2b88852013-08-07 18:30:54 +0100241{
Chris Wilsone637d2c2017-03-16 13:19:57 +0000242 const struct drm_i915_gem_object *a =
243 *(const struct drm_i915_gem_object **)A;
244 const struct drm_i915_gem_object *b =
245 *(const struct drm_i915_gem_object **)B;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200247 if (a->stolen->start < b->stolen->start)
248 return -1;
249 if (a->stolen->start > b->stolen->start)
250 return 1;
251 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100252}
253
254static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
255{
David Weinehall36cdd012016-08-22 13:59:31 +0300256 struct drm_i915_private *dev_priv = node_to_i915(m->private);
257 struct drm_device *dev = &dev_priv->drm;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000258 struct drm_i915_gem_object **objects;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100259 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300260 u64 total_obj_size, total_gtt_size;
Chris Wilsone637d2c2017-03-16 13:19:57 +0000261 unsigned long total, count, n;
262 int ret;
263
264 total = READ_ONCE(dev_priv->mm.object_count);
Michal Hocko20981052017-05-17 14:23:12 +0200265 objects = kvmalloc_array(total, sizeof(*objects), GFP_KERNEL);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000266 if (!objects)
267 return -ENOMEM;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100268
269 ret = mutex_lock_interruptible(&dev->struct_mutex);
270 if (ret)
Chris Wilsone637d2c2017-03-16 13:19:57 +0000271 goto out;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100272
273 total_obj_size = total_gtt_size = count = 0;
Chris Wilsonf2123812017-10-16 12:40:37 +0100274
275 spin_lock(&dev_priv->mm.obj_lock);
276 list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000277 if (count == total)
278 break;
279
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 if (obj->stolen == NULL)
281 continue;
282
Chris Wilsone637d2c2017-03-16 13:19:57 +0000283 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100285 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000286
Chris Wilson6d2b88852013-08-07 18:30:54 +0100287 }
Chris Wilsonf2123812017-10-16 12:40:37 +0100288 list_for_each_entry(obj, &dev_priv->mm.unbound_list, mm.link) {
Chris Wilsone637d2c2017-03-16 13:19:57 +0000289 if (count == total)
290 break;
291
Chris Wilson6d2b88852013-08-07 18:30:54 +0100292 if (obj->stolen == NULL)
293 continue;
294
Chris Wilsone637d2c2017-03-16 13:19:57 +0000295 objects[count++] = obj;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100296 total_obj_size += obj->base.size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100297 }
Chris Wilsonf2123812017-10-16 12:40:37 +0100298 spin_unlock(&dev_priv->mm.obj_lock);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100299
Chris Wilsone637d2c2017-03-16 13:19:57 +0000300 sort(objects, count, sizeof(*objects), obj_rank_by_stolen, NULL);
301
302 seq_puts(m, "Stolen:\n");
303 for (n = 0; n < count; n++) {
304 seq_puts(m, " ");
305 describe_obj(m, objects[n]);
306 seq_putc(m, '\n');
307 }
308 seq_printf(m, "Total %lu objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100309 count, total_obj_size, total_gtt_size);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000310
311 mutex_unlock(&dev->struct_mutex);
312out:
Michal Hocko20981052017-05-17 14:23:12 +0200313 kvfree(objects);
Chris Wilsone637d2c2017-03-16 13:19:57 +0000314 return ret;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100315}
316
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100317struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000318 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300319 unsigned long count;
320 u64 total, unbound;
321 u64 global, shared;
322 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100323};
324
325static int per_file_stats(int id, void *ptr, void *data)
326{
327 struct drm_i915_gem_object *obj = ptr;
328 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000329 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100330
Chris Wilson0caf81b2017-06-17 12:57:44 +0100331 lockdep_assert_held(&obj->base.dev->struct_mutex);
332
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100333 stats->count++;
334 stats->total += obj->base.size;
Chris Wilson15717de2016-08-04 07:52:26 +0100335 if (!obj->bind_count)
336 stats->unbound += obj->base.size;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000337 if (obj->base.name || obj->base.dma_buf)
338 stats->shared += obj->base.size;
339
Chris Wilson894eeec2016-08-04 07:52:20 +0100340 list_for_each_entry(vma, &obj->vma_list, obj_link) {
341 if (!drm_mm_node_allocated(&vma->node))
342 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000343
Chris Wilson3272db52016-08-04 16:32:32 +0100344 if (i915_vma_is_ggtt(vma)) {
Chris Wilson894eeec2016-08-04 07:52:20 +0100345 stats->global += vma->node.size;
346 } else {
347 struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
Chris Wilson6313c202014-03-19 13:45:45 +0000348
Chris Wilson2bfa9962016-08-04 07:52:25 +0100349 if (ppgtt->base.file != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000350 continue;
Chris Wilson6313c202014-03-19 13:45:45 +0000351 }
Chris Wilson894eeec2016-08-04 07:52:20 +0100352
Chris Wilsonb0decaf2016-08-04 07:52:44 +0100353 if (i915_vma_is_active(vma))
Chris Wilson894eeec2016-08-04 07:52:20 +0100354 stats->active += vma->node.size;
355 else
356 stats->inactive += vma->node.size;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100357 }
358
359 return 0;
360}
361
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100362#define print_file_stats(m, name, stats) do { \
363 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300364 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 +0100365 name, \
366 stats.count, \
367 stats.total, \
368 stats.active, \
369 stats.inactive, \
370 stats.global, \
371 stats.shared, \
372 stats.unbound); \
373} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800374
375static void print_batch_pool_stats(struct seq_file *m,
376 struct drm_i915_private *dev_priv)
377{
378 struct drm_i915_gem_object *obj;
379 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000380 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530381 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000382 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800383
384 memset(&stats, 0, sizeof(stats));
385
Akash Goel3b3f1652016-10-13 22:44:48 +0530386 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000387 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100388 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000389 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100390 batch_pool_link)
391 per_file_stats(0, obj, &stats);
392 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100393 }
Brad Volkin493018d2014-12-11 12:13:08 -0800394
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100395 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800396}
397
Chris Wilson15da9562016-05-24 14:53:43 +0100398static int per_file_ctx_stats(int id, void *ptr, void *data)
399{
400 struct i915_gem_context *ctx = ptr;
401 int n;
402
403 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
404 if (ctx->engine[n].state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +0100405 per_file_stats(0, ctx->engine[n].state->obj, data);
Chris Wilsondca33ec2016-08-02 22:50:20 +0100406 if (ctx->engine[n].ring)
Chris Wilson57e88532016-08-15 10:48:57 +0100407 per_file_stats(0, ctx->engine[n].ring->vma->obj, data);
Chris Wilson15da9562016-05-24 14:53:43 +0100408 }
409
410 return 0;
411}
412
413static void print_context_stats(struct seq_file *m,
414 struct drm_i915_private *dev_priv)
415{
David Weinehall36cdd012016-08-22 13:59:31 +0300416 struct drm_device *dev = &dev_priv->drm;
Chris Wilson15da9562016-05-24 14:53:43 +0100417 struct file_stats stats;
418 struct drm_file *file;
419
420 memset(&stats, 0, sizeof(stats));
421
David Weinehall36cdd012016-08-22 13:59:31 +0300422 mutex_lock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100423 if (dev_priv->kernel_context)
424 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
425
David Weinehall36cdd012016-08-22 13:59:31 +0300426 list_for_each_entry(file, &dev->filelist, lhead) {
Chris Wilson15da9562016-05-24 14:53:43 +0100427 struct drm_i915_file_private *fpriv = file->driver_priv;
428 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
429 }
David Weinehall36cdd012016-08-22 13:59:31 +0300430 mutex_unlock(&dev->struct_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100431
432 print_file_stats(m, "[k]contexts", stats);
433}
434
David Weinehall36cdd012016-08-22 13:59:31 +0300435static int i915_gem_object_info(struct seq_file *m, void *data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100436{
David Weinehall36cdd012016-08-22 13:59:31 +0300437 struct drm_i915_private *dev_priv = node_to_i915(m->private);
438 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300439 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100440 u32 count, mapped_count, purgeable_count, dpy_count, huge_count;
441 u64 size, mapped_size, purgeable_size, dpy_size, huge_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000442 struct drm_i915_gem_object *obj;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100443 unsigned int page_sizes = 0;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100444 struct drm_file *file;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100445 char buf[80];
Chris Wilson73aa8082010-09-30 11:46:12 +0100446 int ret;
447
448 ret = mutex_lock_interruptible(&dev->struct_mutex);
449 if (ret)
450 return ret;
451
Chris Wilson3ef7f222016-10-18 13:02:48 +0100452 seq_printf(m, "%u objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000453 dev_priv->mm.object_count,
454 dev_priv->mm.object_memory);
455
Chris Wilson1544c422016-08-15 13:18:16 +0100456 size = count = 0;
457 mapped_size = mapped_count = 0;
458 purgeable_size = purgeable_count = 0;
Matthew Auld7393b7e2017-10-06 23:18:28 +0100459 huge_size = huge_count = 0;
Chris Wilsonf2123812017-10-16 12:40:37 +0100460
461 spin_lock(&dev_priv->mm.obj_lock);
462 list_for_each_entry(obj, &dev_priv->mm.unbound_list, mm.link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100463 size += obj->base.size;
464 ++count;
Chris Wilson6c085a72012-08-20 11:40:46 +0200465
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100466 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilsonb7abb712012-08-20 11:33:30 +0200467 purgeable_size += obj->base.size;
468 ++purgeable_count;
469 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100470
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100471 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100472 mapped_count++;
473 mapped_size += obj->base.size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100474 }
Matthew Auld7393b7e2017-10-06 23:18:28 +0100475
476 if (obj->mm.page_sizes.sg > I915_GTT_PAGE_SIZE) {
477 huge_count++;
478 huge_size += obj->base.size;
479 page_sizes |= obj->mm.page_sizes.sg;
480 }
Chris Wilson6299f992010-11-24 12:23:44 +0000481 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100482 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
483
484 size = count = dpy_size = dpy_count = 0;
Chris Wilsonf2123812017-10-16 12:40:37 +0100485 list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100486 size += obj->base.size;
487 ++count;
488
Chris Wilsonbd3d2252017-10-13 21:26:14 +0100489 if (obj->pin_global) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100490 dpy_size += obj->base.size;
491 ++dpy_count;
492 }
493
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100494 if (obj->mm.madv == I915_MADV_DONTNEED) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100495 purgeable_size += obj->base.size;
496 ++purgeable_count;
497 }
498
Chris Wilsona4f5ea62016-10-28 13:58:35 +0100499 if (obj->mm.mapping) {
Chris Wilson2bd160a2016-08-15 10:48:45 +0100500 mapped_count++;
501 mapped_size += obj->base.size;
502 }
Matthew Auld7393b7e2017-10-06 23:18:28 +0100503
504 if (obj->mm.page_sizes.sg > I915_GTT_PAGE_SIZE) {
505 huge_count++;
506 huge_size += obj->base.size;
507 page_sizes |= obj->mm.page_sizes.sg;
508 }
Chris Wilson2bd160a2016-08-15 10:48:45 +0100509 }
Chris Wilsonf2123812017-10-16 12:40:37 +0100510 spin_unlock(&dev_priv->mm.obj_lock);
511
Chris Wilson2bd160a2016-08-15 10:48:45 +0100512 seq_printf(m, "%u bound objects, %llu bytes\n",
513 count, size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300514 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200515 purgeable_count, purgeable_size);
Chris Wilson2bd160a2016-08-15 10:48:45 +0100516 seq_printf(m, "%u mapped objects, %llu bytes\n",
517 mapped_count, mapped_size);
Matthew Auld7393b7e2017-10-06 23:18:28 +0100518 seq_printf(m, "%u huge-paged objects (%s) %llu bytes\n",
519 huge_count,
520 stringify_page_sizes(page_sizes, buf, sizeof(buf)),
521 huge_size);
Chris Wilsonbd3d2252017-10-13 21:26:14 +0100522 seq_printf(m, "%u display objects (globally pinned), %llu bytes\n",
Chris Wilson2bd160a2016-08-15 10:48:45 +0100523 dpy_count, dpy_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000524
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300525 seq_printf(m, "%llu [%llu] gtt total\n",
Chris Wilson381b9432017-02-15 08:43:54 +0000526 ggtt->base.total, ggtt->mappable_end);
Matthew Auld7393b7e2017-10-06 23:18:28 +0100527 seq_printf(m, "Supported page sizes: %s\n",
528 stringify_page_sizes(INTEL_INFO(dev_priv)->page_sizes,
529 buf, sizeof(buf)));
Chris Wilson73aa8082010-09-30 11:46:12 +0100530
Damien Lespiau267f0c92013-06-24 22:59:48 +0100531 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800532 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200533 mutex_unlock(&dev->struct_mutex);
534
535 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100536 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100537 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
538 struct file_stats stats;
Chris Wilsonc84455b2016-08-15 10:49:08 +0100539 struct drm_i915_file_private *file_priv = file->driver_priv;
540 struct drm_i915_gem_request *request;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900541 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100542
Chris Wilson0caf81b2017-06-17 12:57:44 +0100543 mutex_lock(&dev->struct_mutex);
544
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100545 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000546 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100547 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100548 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100549 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900550 /*
551 * Although we have a valid reference on file->pid, that does
552 * not guarantee that the task_struct who called get_pid() is
553 * still alive (e.g. get_pid(current) => fork() => exit()).
554 * Therefore, we need to protect this ->comm access using RCU.
555 */
Chris Wilsonc84455b2016-08-15 10:49:08 +0100556 request = list_first_entry_or_null(&file_priv->mm.request_list,
557 struct drm_i915_gem_request,
Chris Wilsonc8659ef2017-03-02 12:25:25 +0000558 client_link);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900559 rcu_read_lock();
Chris Wilsonc84455b2016-08-15 10:49:08 +0100560 task = pid_task(request && request->ctx->pid ?
561 request->ctx->pid : file->pid,
562 PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800563 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900564 rcu_read_unlock();
Chris Wilson0caf81b2017-06-17 12:57:44 +0100565
Chris Wilsonc84455b2016-08-15 10:49:08 +0100566 mutex_unlock(&dev->struct_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100567 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200568 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100569
570 return 0;
571}
572
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100573static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000574{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100575 struct drm_info_node *node = m->private;
David Weinehall36cdd012016-08-22 13:59:31 +0300576 struct drm_i915_private *dev_priv = node_to_i915(node);
577 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonf2123812017-10-16 12:40:37 +0100578 struct drm_i915_gem_object **objects;
Chris Wilson08c18322011-01-10 00:00:24 +0000579 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300580 u64 total_obj_size, total_gtt_size;
Chris Wilsonf2123812017-10-16 12:40:37 +0100581 unsigned long nobject, n;
Chris Wilson08c18322011-01-10 00:00:24 +0000582 int count, ret;
583
Chris Wilsonf2123812017-10-16 12:40:37 +0100584 nobject = READ_ONCE(dev_priv->mm.object_count);
585 objects = kvmalloc_array(nobject, sizeof(*objects), GFP_KERNEL);
586 if (!objects)
587 return -ENOMEM;
588
Chris Wilson08c18322011-01-10 00:00:24 +0000589 ret = mutex_lock_interruptible(&dev->struct_mutex);
590 if (ret)
591 return ret;
592
Chris Wilsonf2123812017-10-16 12:40:37 +0100593 count = 0;
594 spin_lock(&dev_priv->mm.obj_lock);
595 list_for_each_entry(obj, &dev_priv->mm.bound_list, mm.link) {
596 objects[count++] = obj;
597 if (count == nobject)
598 break;
599 }
600 spin_unlock(&dev_priv->mm.obj_lock);
601
602 total_obj_size = total_gtt_size = 0;
603 for (n = 0; n < count; n++) {
604 obj = objects[n];
605
Damien Lespiau267f0c92013-06-24 22:59:48 +0100606 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000607 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100608 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000609 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100610 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000611 }
612
613 mutex_unlock(&dev->struct_mutex);
614
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300615 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000616 count, total_obj_size, total_gtt_size);
Chris Wilsonf2123812017-10-16 12:40:37 +0100617 kvfree(objects);
Chris Wilson08c18322011-01-10 00:00:24 +0000618
619 return 0;
620}
621
Brad Volkin493018d2014-12-11 12:13:08 -0800622static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
623{
David Weinehall36cdd012016-08-22 13:59:31 +0300624 struct drm_i915_private *dev_priv = node_to_i915(m->private);
625 struct drm_device *dev = &dev_priv->drm;
Brad Volkin493018d2014-12-11 12:13:08 -0800626 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000627 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530628 enum intel_engine_id id;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100629 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000630 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800631
632 ret = mutex_lock_interruptible(&dev->struct_mutex);
633 if (ret)
634 return ret;
635
Akash Goel3b3f1652016-10-13 22:44:48 +0530636 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000637 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100638 int count;
639
640 count = 0;
641 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000642 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100643 batch_pool_link)
644 count++;
645 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000646 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100647
648 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000649 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100650 batch_pool_link) {
651 seq_puts(m, " ");
652 describe_obj(m, obj);
653 seq_putc(m, '\n');
654 }
655
656 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100657 }
Brad Volkin493018d2014-12-11 12:13:08 -0800658 }
659
Chris Wilson8d9d5742015-04-07 16:20:38 +0100660 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800661
662 mutex_unlock(&dev->struct_mutex);
663
664 return 0;
665}
666
Chris Wilsonb2223492010-10-27 15:27:33 +0100667static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000668 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100669{
Chris Wilson688e6c72016-07-01 17:23:15 +0100670 struct intel_breadcrumbs *b = &engine->breadcrumbs;
671 struct rb_node *rb;
672
Chris Wilson12471ba2016-04-09 10:57:55 +0100673 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100674 engine->name, intel_engine_get_seqno(engine));
Chris Wilson688e6c72016-07-01 17:23:15 +0100675
Chris Wilson61d3dc72017-03-03 19:08:24 +0000676 spin_lock_irq(&b->rb_lock);
Chris Wilson688e6c72016-07-01 17:23:15 +0100677 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +0800678 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson688e6c72016-07-01 17:23:15 +0100679
680 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
681 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
682 }
Chris Wilson61d3dc72017-03-03 19:08:24 +0000683 spin_unlock_irq(&b->rb_lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100684}
685
Ben Gamari20172632009-02-17 20:08:50 -0500686static int i915_gem_seqno_info(struct seq_file *m, void *data)
687{
David Weinehall36cdd012016-08-22 13:59:31 +0300688 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000689 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530690 enum intel_engine_id id;
Ben Gamari20172632009-02-17 20:08:50 -0500691
Akash Goel3b3f1652016-10-13 22:44:48 +0530692 for_each_engine(engine, dev_priv, id)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000693 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100694
Ben Gamari20172632009-02-17 20:08:50 -0500695 return 0;
696}
697
698
699static int i915_interrupt_info(struct seq_file *m, void *data)
700{
David Weinehall36cdd012016-08-22 13:59:31 +0300701 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000702 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530703 enum intel_engine_id id;
Chris Wilson4bb05042016-09-03 07:53:43 +0100704 int i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100705
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200706 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500707
David Weinehall36cdd012016-08-22 13:59:31 +0300708 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300709 seq_printf(m, "Master Interrupt Control:\t%08x\n",
710 I915_READ(GEN8_MASTER_IRQ));
711
712 seq_printf(m, "Display IER:\t%08x\n",
713 I915_READ(VLV_IER));
714 seq_printf(m, "Display IIR:\t%08x\n",
715 I915_READ(VLV_IIR));
716 seq_printf(m, "Display IIR_RW:\t%08x\n",
717 I915_READ(VLV_IIR_RW));
718 seq_printf(m, "Display IMR:\t%08x\n",
719 I915_READ(VLV_IMR));
Chris Wilson9c870d02016-10-24 13:42:15 +0100720 for_each_pipe(dev_priv, pipe) {
721 enum intel_display_power_domain power_domain;
722
723 power_domain = POWER_DOMAIN_PIPE(pipe);
724 if (!intel_display_power_get_if_enabled(dev_priv,
725 power_domain)) {
726 seq_printf(m, "Pipe %c power disabled\n",
727 pipe_name(pipe));
728 continue;
729 }
730
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300731 seq_printf(m, "Pipe %c stat:\t%08x\n",
732 pipe_name(pipe),
733 I915_READ(PIPESTAT(pipe)));
734
Chris Wilson9c870d02016-10-24 13:42:15 +0100735 intel_display_power_put(dev_priv, power_domain);
736 }
737
738 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300739 seq_printf(m, "Port hotplug:\t%08x\n",
740 I915_READ(PORT_HOTPLUG_EN));
741 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
742 I915_READ(VLV_DPFLIPSTAT));
743 seq_printf(m, "DPINVGTT:\t%08x\n",
744 I915_READ(DPINVGTT));
Chris Wilson9c870d02016-10-24 13:42:15 +0100745 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300746
747 for (i = 0; i < 4; i++) {
748 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
749 i, I915_READ(GEN8_GT_IMR(i)));
750 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
751 i, I915_READ(GEN8_GT_IIR(i)));
752 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
753 i, I915_READ(GEN8_GT_IER(i)));
754 }
755
756 seq_printf(m, "PCU interrupt mask:\t%08x\n",
757 I915_READ(GEN8_PCU_IMR));
758 seq_printf(m, "PCU interrupt identity:\t%08x\n",
759 I915_READ(GEN8_PCU_IIR));
760 seq_printf(m, "PCU interrupt enable:\t%08x\n",
761 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300762 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700763 seq_printf(m, "Master Interrupt Control:\t%08x\n",
764 I915_READ(GEN8_MASTER_IRQ));
765
766 for (i = 0; i < 4; i++) {
767 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
768 i, I915_READ(GEN8_GT_IMR(i)));
769 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
770 i, I915_READ(GEN8_GT_IIR(i)));
771 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
772 i, I915_READ(GEN8_GT_IER(i)));
773 }
774
Damien Lespiau055e3932014-08-18 13:49:10 +0100775 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200776 enum intel_display_power_domain power_domain;
777
778 power_domain = POWER_DOMAIN_PIPE(pipe);
779 if (!intel_display_power_get_if_enabled(dev_priv,
780 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300781 seq_printf(m, "Pipe %c power disabled\n",
782 pipe_name(pipe));
783 continue;
784 }
Ben Widawskya123f152013-11-02 21:07:10 -0700785 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000786 pipe_name(pipe),
787 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700788 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000789 pipe_name(pipe),
790 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700791 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000792 pipe_name(pipe),
793 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200794
795 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700796 }
797
798 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
799 I915_READ(GEN8_DE_PORT_IMR));
800 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
801 I915_READ(GEN8_DE_PORT_IIR));
802 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
803 I915_READ(GEN8_DE_PORT_IER));
804
805 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
806 I915_READ(GEN8_DE_MISC_IMR));
807 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
808 I915_READ(GEN8_DE_MISC_IIR));
809 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
810 I915_READ(GEN8_DE_MISC_IER));
811
812 seq_printf(m, "PCU interrupt mask:\t%08x\n",
813 I915_READ(GEN8_PCU_IMR));
814 seq_printf(m, "PCU interrupt identity:\t%08x\n",
815 I915_READ(GEN8_PCU_IIR));
816 seq_printf(m, "PCU interrupt enable:\t%08x\n",
817 I915_READ(GEN8_PCU_IER));
David Weinehall36cdd012016-08-22 13:59:31 +0300818 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700819 seq_printf(m, "Display IER:\t%08x\n",
820 I915_READ(VLV_IER));
821 seq_printf(m, "Display IIR:\t%08x\n",
822 I915_READ(VLV_IIR));
823 seq_printf(m, "Display IIR_RW:\t%08x\n",
824 I915_READ(VLV_IIR_RW));
825 seq_printf(m, "Display IMR:\t%08x\n",
826 I915_READ(VLV_IMR));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000827 for_each_pipe(dev_priv, pipe) {
828 enum intel_display_power_domain power_domain;
829
830 power_domain = POWER_DOMAIN_PIPE(pipe);
831 if (!intel_display_power_get_if_enabled(dev_priv,
832 power_domain)) {
833 seq_printf(m, "Pipe %c power disabled\n",
834 pipe_name(pipe));
835 continue;
836 }
837
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700838 seq_printf(m, "Pipe %c stat:\t%08x\n",
839 pipe_name(pipe),
840 I915_READ(PIPESTAT(pipe)));
Chris Wilson4f4631a2017-02-10 13:36:32 +0000841 intel_display_power_put(dev_priv, power_domain);
842 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700843
844 seq_printf(m, "Master IER:\t%08x\n",
845 I915_READ(VLV_MASTER_IER));
846
847 seq_printf(m, "Render IER:\t%08x\n",
848 I915_READ(GTIER));
849 seq_printf(m, "Render IIR:\t%08x\n",
850 I915_READ(GTIIR));
851 seq_printf(m, "Render IMR:\t%08x\n",
852 I915_READ(GTIMR));
853
854 seq_printf(m, "PM IER:\t\t%08x\n",
855 I915_READ(GEN6_PMIER));
856 seq_printf(m, "PM IIR:\t\t%08x\n",
857 I915_READ(GEN6_PMIIR));
858 seq_printf(m, "PM IMR:\t\t%08x\n",
859 I915_READ(GEN6_PMIMR));
860
861 seq_printf(m, "Port hotplug:\t%08x\n",
862 I915_READ(PORT_HOTPLUG_EN));
863 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
864 I915_READ(VLV_DPFLIPSTAT));
865 seq_printf(m, "DPINVGTT:\t%08x\n",
866 I915_READ(DPINVGTT));
867
David Weinehall36cdd012016-08-22 13:59:31 +0300868 } else if (!HAS_PCH_SPLIT(dev_priv)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800869 seq_printf(m, "Interrupt enable: %08x\n",
870 I915_READ(IER));
871 seq_printf(m, "Interrupt identity: %08x\n",
872 I915_READ(IIR));
873 seq_printf(m, "Interrupt mask: %08x\n",
874 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100875 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800876 seq_printf(m, "Pipe %c stat: %08x\n",
877 pipe_name(pipe),
878 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800879 } else {
880 seq_printf(m, "North Display Interrupt enable: %08x\n",
881 I915_READ(DEIER));
882 seq_printf(m, "North Display Interrupt identity: %08x\n",
883 I915_READ(DEIIR));
884 seq_printf(m, "North Display Interrupt mask: %08x\n",
885 I915_READ(DEIMR));
886 seq_printf(m, "South Display Interrupt enable: %08x\n",
887 I915_READ(SDEIER));
888 seq_printf(m, "South Display Interrupt identity: %08x\n",
889 I915_READ(SDEIIR));
890 seq_printf(m, "South Display Interrupt mask: %08x\n",
891 I915_READ(SDEIMR));
892 seq_printf(m, "Graphics Interrupt enable: %08x\n",
893 I915_READ(GTIER));
894 seq_printf(m, "Graphics Interrupt identity: %08x\n",
895 I915_READ(GTIIR));
896 seq_printf(m, "Graphics Interrupt mask: %08x\n",
897 I915_READ(GTIMR));
898 }
Akash Goel3b3f1652016-10-13 22:44:48 +0530899 for_each_engine(engine, dev_priv, id) {
David Weinehall36cdd012016-08-22 13:59:31 +0300900 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100901 seq_printf(m,
902 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000903 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000904 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000905 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000906 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200907 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100908
Ben Gamari20172632009-02-17 20:08:50 -0500909 return 0;
910}
911
Chris Wilsona6172a82009-02-11 14:26:38 +0000912static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
913{
David Weinehall36cdd012016-08-22 13:59:31 +0300914 struct drm_i915_private *dev_priv = node_to_i915(m->private);
915 struct drm_device *dev = &dev_priv->drm;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100916 int i, ret;
917
918 ret = mutex_lock_interruptible(&dev->struct_mutex);
919 if (ret)
920 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000921
Chris Wilsona6172a82009-02-11 14:26:38 +0000922 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
923 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson49ef5292016-08-18 17:17:00 +0100924 struct i915_vma *vma = dev_priv->fence_regs[i].vma;
Chris Wilsona6172a82009-02-11 14:26:38 +0000925
Chris Wilson6c085a72012-08-20 11:40:46 +0200926 seq_printf(m, "Fence %d, pin count = %d, object = ",
927 i, dev_priv->fence_regs[i].pin_count);
Chris Wilson49ef5292016-08-18 17:17:00 +0100928 if (!vma)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100929 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100930 else
Chris Wilson49ef5292016-08-18 17:17:00 +0100931 describe_obj(m, vma->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100932 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000933 }
934
Chris Wilson05394f32010-11-08 19:18:58 +0000935 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000936 return 0;
937}
938
Chris Wilson98a2f412016-10-12 10:05:18 +0100939#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000940static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
941 size_t count, loff_t *pos)
942{
943 struct i915_gpu_state *error = file->private_data;
944 struct drm_i915_error_state_buf str;
945 ssize_t ret;
946 loff_t tmp;
947
948 if (!error)
949 return 0;
950
951 ret = i915_error_state_buf_init(&str, error->i915, count, *pos);
952 if (ret)
953 return ret;
954
955 ret = i915_error_state_to_str(&str, error);
956 if (ret)
957 goto out;
958
959 tmp = 0;
960 ret = simple_read_from_buffer(ubuf, count, &tmp, str.buf, str.bytes);
961 if (ret < 0)
962 goto out;
963
964 *pos = str.start + ret;
965out:
966 i915_error_state_buf_release(&str);
967 return ret;
968}
969
970static int gpu_state_release(struct inode *inode, struct file *file)
971{
972 i915_gpu_state_put(file->private_data);
973 return 0;
974}
975
976static int i915_gpu_info_open(struct inode *inode, struct file *file)
977{
Chris Wilson090e5fe2017-03-28 14:14:07 +0100978 struct drm_i915_private *i915 = inode->i_private;
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000979 struct i915_gpu_state *gpu;
980
Chris Wilson090e5fe2017-03-28 14:14:07 +0100981 intel_runtime_pm_get(i915);
982 gpu = i915_capture_gpu_state(i915);
983 intel_runtime_pm_put(i915);
Chris Wilson5a4c6f12017-02-14 16:46:11 +0000984 if (!gpu)
985 return -ENOMEM;
986
987 file->private_data = gpu;
988 return 0;
989}
990
991static const struct file_operations i915_gpu_info_fops = {
992 .owner = THIS_MODULE,
993 .open = i915_gpu_info_open,
994 .read = gpu_state_read,
995 .llseek = default_llseek,
996 .release = gpu_state_release,
997};
Chris Wilson98a2f412016-10-12 10:05:18 +0100998
Daniel Vetterd5442302012-04-27 15:17:40 +0200999static ssize_t
1000i915_error_state_write(struct file *filp,
1001 const char __user *ubuf,
1002 size_t cnt,
1003 loff_t *ppos)
1004{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001005 struct i915_gpu_state *error = filp->private_data;
1006
1007 if (!error)
1008 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001009
1010 DRM_DEBUG_DRIVER("Resetting error state\n");
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001011 i915_reset_error_state(error->i915);
Daniel Vetterd5442302012-04-27 15:17:40 +02001012
1013 return cnt;
1014}
1015
1016static int i915_error_state_open(struct inode *inode, struct file *file)
1017{
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001018 file->private_data = i915_first_error_state(inode->i_private);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001019 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001020}
1021
Daniel Vetterd5442302012-04-27 15:17:40 +02001022static const struct file_operations i915_error_state_fops = {
1023 .owner = THIS_MODULE,
1024 .open = i915_error_state_open,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001025 .read = gpu_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001026 .write = i915_error_state_write,
1027 .llseek = default_llseek,
Chris Wilson5a4c6f12017-02-14 16:46:11 +00001028 .release = gpu_state_release,
Daniel Vetterd5442302012-04-27 15:17:40 +02001029};
Chris Wilson98a2f412016-10-12 10:05:18 +01001030#endif
1031
Kees Cook647416f2013-03-10 14:10:06 -07001032static int
Kees Cook647416f2013-03-10 14:10:06 -07001033i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001034{
David Weinehall36cdd012016-08-22 13:59:31 +03001035 struct drm_i915_private *dev_priv = data;
1036 struct drm_device *dev = &dev_priv->drm;
Mika Kuoppala40633212012-12-04 15:12:00 +02001037 int ret;
1038
Mika Kuoppala40633212012-12-04 15:12:00 +02001039 ret = mutex_lock_interruptible(&dev->struct_mutex);
1040 if (ret)
1041 return ret;
1042
Chris Wilson73cb9702016-10-28 13:58:46 +01001043 ret = i915_gem_set_global_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001044 mutex_unlock(&dev->struct_mutex);
1045
Kees Cook647416f2013-03-10 14:10:06 -07001046 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001047}
1048
Kees Cook647416f2013-03-10 14:10:06 -07001049DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
Chris Wilson9b6586a2017-02-23 07:44:08 +00001050 NULL, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001051 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001052
Deepak Sadb4bd12014-03-31 11:30:02 +05301053static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001054{
David Weinehall36cdd012016-08-22 13:59:31 +03001055 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001056 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001057 int ret = 0;
1058
1059 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001060
David Weinehall36cdd012016-08-22 13:59:31 +03001061 if (IS_GEN5(dev_priv)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001062 u16 rgvswctl = I915_READ16(MEMSWCTL);
1063 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1064
1065 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1066 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1067 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1068 MEMSTAT_VID_SHIFT);
1069 seq_printf(m, "Current P-state: %d\n",
1070 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
David Weinehall36cdd012016-08-22 13:59:31 +03001071 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001072 u32 rpmodectl, freq_sts;
Wayne Boyer666a4532015-12-09 12:29:35 -08001073
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001074 mutex_lock(&dev_priv->pcu_lock);
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001075
1076 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1077 seq_printf(m, "Video Turbo Mode: %s\n",
1078 yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
1079 seq_printf(m, "HW control enabled: %s\n",
1080 yesno(rpmodectl & GEN6_RP_ENABLE));
1081 seq_printf(m, "SW control enabled: %s\n",
1082 yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
1083 GEN6_RP_MEDIA_SW_MODE));
1084
Wayne Boyer666a4532015-12-09 12:29:35 -08001085 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1086 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1087 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1088
1089 seq_printf(m, "actual GPU freq: %d MHz\n",
1090 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1091
1092 seq_printf(m, "current GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001093 intel_gpu_freq(dev_priv, rps->cur_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001094
1095 seq_printf(m, "max GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001096 intel_gpu_freq(dev_priv, rps->max_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001097
1098 seq_printf(m, "min GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001099 intel_gpu_freq(dev_priv, rps->min_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001100
1101 seq_printf(m, "idle GPU freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001102 intel_gpu_freq(dev_priv, rps->idle_freq));
Wayne Boyer666a4532015-12-09 12:29:35 -08001103
1104 seq_printf(m,
1105 "efficient (RPe) frequency: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001106 intel_gpu_freq(dev_priv, rps->efficient_freq));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001107 mutex_unlock(&dev_priv->pcu_lock);
David Weinehall36cdd012016-08-22 13:59:31 +03001108 } else if (INTEL_GEN(dev_priv) >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001109 u32 rp_state_limits;
1110 u32 gt_perf_status;
1111 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001112 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001113 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001114 u32 rpupei, rpcurup, rpprevup;
1115 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001116 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001117 int max_freq;
1118
Bob Paauwe35040562015-06-25 14:54:07 -07001119 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001120 if (IS_GEN9_LP(dev_priv)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001121 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1122 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1123 } else {
1124 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1125 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1126 }
1127
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001128 /* RPSTAT1 is in the GT power well */
Mika Kuoppala59bad942015-01-16 11:34:40 +02001129 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001130
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001131 reqf = I915_READ(GEN6_RPNSWREQ);
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001132 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301133 reqf >>= 23;
1134 else {
1135 reqf &= ~GEN6_TURBO_DISABLE;
David Weinehall36cdd012016-08-22 13:59:31 +03001136 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Akash Goel60260a52015-03-06 11:07:21 +05301137 reqf >>= 24;
1138 else
1139 reqf >>= 25;
1140 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001141 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001142
Chris Wilson0d8f9492014-03-27 09:06:14 +00001143 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1144 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1145 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1146
Jesse Barnesccab5c82011-01-18 15:49:25 -08001147 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301148 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1149 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1150 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1151 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1152 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1153 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001154 if (INTEL_GEN(dev_priv) >= 9)
Akash Goel60260a52015-03-06 11:07:21 +05301155 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
David Weinehall36cdd012016-08-22 13:59:31 +03001156 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001157 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1158 else
1159 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001160 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001161
Mika Kuoppala59bad942015-01-16 11:34:40 +02001162 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001163
David Weinehall36cdd012016-08-22 13:59:31 +03001164 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001165 pm_ier = I915_READ(GEN6_PMIER);
1166 pm_imr = I915_READ(GEN6_PMIMR);
1167 pm_isr = I915_READ(GEN6_PMISR);
1168 pm_iir = I915_READ(GEN6_PMIIR);
1169 pm_mask = I915_READ(GEN6_PMINTRMSK);
1170 } else {
1171 pm_ier = I915_READ(GEN8_GT_IER(2));
1172 pm_imr = I915_READ(GEN8_GT_IMR(2));
1173 pm_isr = I915_READ(GEN8_GT_ISR(2));
1174 pm_iir = I915_READ(GEN8_GT_IIR(2));
1175 pm_mask = I915_READ(GEN6_PMINTRMSK);
1176 }
Sagar Arun Kamble960e5462017-10-10 22:29:59 +01001177 seq_printf(m, "Video Turbo Mode: %s\n",
1178 yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
1179 seq_printf(m, "HW control enabled: %s\n",
1180 yesno(rpmodectl & GEN6_RP_ENABLE));
1181 seq_printf(m, "SW control enabled: %s\n",
1182 yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
1183 GEN6_RP_MEDIA_SW_MODE));
Chris Wilson0d8f9492014-03-27 09:06:14 +00001184 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 -03001185 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05301186 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001187 rps->pm_intrmsk_mbz);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001188 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001189 seq_printf(m, "Render p-state ratio: %d\n",
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001190 (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001191 seq_printf(m, "Render p-state VID: %d\n",
1192 gt_perf_status & 0xff);
1193 seq_printf(m, "Render p-state limit: %d\n",
1194 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001195 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1196 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1197 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1198 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001199 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001200 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301201 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1202 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1203 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1204 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1205 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1206 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001207 seq_printf(m, "Up threshold: %d%%\n", rps->up_threshold);
Chris Wilsond86ed342015-04-27 13:41:19 +01001208
Akash Goeld6cda9c2016-04-23 00:05:46 +05301209 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1210 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1211 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1212 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1213 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1214 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001215 seq_printf(m, "Down threshold: %d%%\n", rps->down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001216
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001217 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
Bob Paauwe35040562015-06-25 14:54:07 -07001218 rp_state_cap >> 16) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001219 max_freq *= (IS_GEN9_BC(dev_priv) ||
1220 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001221 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001222 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001223
1224 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001225 max_freq *= (IS_GEN9_BC(dev_priv) ||
1226 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001227 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001228 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001229
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02001230 max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
Bob Paauwe35040562015-06-25 14:54:07 -07001231 rp_state_cap >> 0) & 0xff;
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001232 max_freq *= (IS_GEN9_BC(dev_priv) ||
1233 IS_CANNONLAKE(dev_priv) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001234 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001235 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001236 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001237 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001238
Chris Wilsond86ed342015-04-27 13:41:19 +01001239 seq_printf(m, "Current freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001240 intel_gpu_freq(dev_priv, rps->cur_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001241 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001242 seq_printf(m, "Idle freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001243 intel_gpu_freq(dev_priv, rps->idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001244 seq_printf(m, "Min freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001245 intel_gpu_freq(dev_priv, rps->min_freq));
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001246 seq_printf(m, "Boost freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001247 intel_gpu_freq(dev_priv, rps->boost_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001248 seq_printf(m, "Max freq: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001249 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001250 seq_printf(m,
1251 "efficient (RPe) frequency: %d MHz\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001252 intel_gpu_freq(dev_priv, rps->efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001253 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001254 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001255 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001256
Ville Syrjälä49cd97a2017-02-07 20:33:45 +02001257 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
Mika Kahola1170f282015-09-25 14:00:32 +03001258 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1259 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1260
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001261 intel_runtime_pm_put(dev_priv);
1262 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001263}
1264
Ben Widawskyd6369512016-09-20 16:54:32 +03001265static void i915_instdone_info(struct drm_i915_private *dev_priv,
1266 struct seq_file *m,
1267 struct intel_instdone *instdone)
1268{
Ben Widawskyf9e61372016-09-20 16:54:33 +03001269 int slice;
1270 int subslice;
1271
Ben Widawskyd6369512016-09-20 16:54:32 +03001272 seq_printf(m, "\t\tINSTDONE: 0x%08x\n",
1273 instdone->instdone);
1274
1275 if (INTEL_GEN(dev_priv) <= 3)
1276 return;
1277
1278 seq_printf(m, "\t\tSC_INSTDONE: 0x%08x\n",
1279 instdone->slice_common);
1280
1281 if (INTEL_GEN(dev_priv) <= 6)
1282 return;
1283
Ben Widawskyf9e61372016-09-20 16:54:33 +03001284 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1285 seq_printf(m, "\t\tSAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
1286 slice, subslice, instdone->sampler[slice][subslice]);
1287
1288 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
1289 seq_printf(m, "\t\tROW_INSTDONE[%d][%d]: 0x%08x\n",
1290 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03001291}
1292
Chris Wilsonf6544492015-01-26 18:03:04 +02001293static int i915_hangcheck_info(struct seq_file *m, void *unused)
1294{
David Weinehall36cdd012016-08-22 13:59:31 +03001295 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001296 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001297 u64 acthd[I915_NUM_ENGINES];
1298 u32 seqno[I915_NUM_ENGINES];
Ben Widawskyd6369512016-09-20 16:54:32 +03001299 struct intel_instdone instdone;
Dave Gordonc3232b12016-03-23 18:19:53 +00001300 enum intel_engine_id id;
Chris Wilsonf6544492015-01-26 18:03:04 +02001301
Chris Wilson8af29b02016-09-09 14:11:47 +01001302 if (test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001303 seq_puts(m, "Wedged\n");
1304 if (test_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags))
1305 seq_puts(m, "Reset in progress: struct_mutex backoff\n");
1306 if (test_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags))
1307 seq_puts(m, "Reset in progress: reset handoff to waiter\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001308 if (waitqueue_active(&dev_priv->gpu_error.wait_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001309 seq_puts(m, "Waiter holding struct mutex\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001310 if (waitqueue_active(&dev_priv->gpu_error.reset_queue))
Chris Wilson8c185ec2017-03-16 17:13:02 +00001311 seq_puts(m, "struct_mutex blocked for reset\n");
Chris Wilson8af29b02016-09-09 14:11:47 +01001312
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001313 if (!i915_modparams.enable_hangcheck) {
Chris Wilson8c185ec2017-03-16 17:13:02 +00001314 seq_puts(m, "Hangcheck disabled\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001315 return 0;
1316 }
1317
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001318 intel_runtime_pm_get(dev_priv);
1319
Akash Goel3b3f1652016-10-13 22:44:48 +05301320 for_each_engine(engine, dev_priv, id) {
Chris Wilson7e37f882016-08-02 22:50:21 +01001321 acthd[id] = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001322 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001323 }
1324
Akash Goel3b3f1652016-10-13 22:44:48 +05301325 intel_engine_get_instdone(dev_priv->engine[RCS], &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001326
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001327 intel_runtime_pm_put(dev_priv);
1328
Chris Wilson8352aea2017-03-03 09:00:56 +00001329 if (timer_pending(&dev_priv->gpu_error.hangcheck_work.timer))
1330 seq_printf(m, "Hangcheck active, timer fires in %dms\n",
Chris Wilsonf6544492015-01-26 18:03:04 +02001331 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1332 jiffies));
Chris Wilson8352aea2017-03-03 09:00:56 +00001333 else if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work))
1334 seq_puts(m, "Hangcheck active, work pending\n");
1335 else
1336 seq_puts(m, "Hangcheck inactive\n");
Chris Wilsonf6544492015-01-26 18:03:04 +02001337
Chris Wilsonf73b5672017-03-02 15:03:56 +00001338 seq_printf(m, "GT active? %s\n", yesno(dev_priv->gt.awake));
1339
Akash Goel3b3f1652016-10-13 22:44:48 +05301340 for_each_engine(engine, dev_priv, id) {
Chris Wilson33f53712016-10-04 21:11:32 +01001341 struct intel_breadcrumbs *b = &engine->breadcrumbs;
1342 struct rb_node *rb;
1343
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001344 seq_printf(m, "%s:\n", engine->name);
Chris Wilsonf73b5672017-03-02 15:03:56 +00001345 seq_printf(m, "\tseqno = %x [current %x, last %x], inflight %d\n",
Chris Wilsoncb399ea2016-11-01 10:03:16 +00001346 engine->hangcheck.seqno, seqno[id],
Chris Wilsonf73b5672017-03-02 15:03:56 +00001347 intel_engine_last_submit(engine),
1348 engine->timeline->inflight_seqnos);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001349 seq_printf(m, "\twaiters? %s, fake irq active? %s, stalled? %s\n",
Chris Wilson83348ba2016-08-09 17:47:51 +01001350 yesno(intel_engine_has_waiter(engine)),
1351 yesno(test_bit(engine->id,
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001352 &dev_priv->gpu_error.missed_irq_rings)),
1353 yesno(engine->hangcheck.stalled));
1354
Chris Wilson61d3dc72017-03-03 19:08:24 +00001355 spin_lock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001356 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
Geliang Tangf802cf72016-12-19 22:43:49 +08001357 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
Chris Wilson33f53712016-10-04 21:11:32 +01001358
1359 seq_printf(m, "\t%s [%d] waiting for %x\n",
1360 w->tsk->comm, w->tsk->pid, w->seqno);
1361 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001362 spin_unlock_irq(&b->rb_lock);
Chris Wilson33f53712016-10-04 21:11:32 +01001363
Chris Wilsonf6544492015-01-26 18:03:04 +02001364 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001365 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001366 (long long)acthd[id]);
Mika Kuoppala3fe3b032016-11-18 15:09:04 +02001367 seq_printf(m, "\taction = %s(%d) %d ms ago\n",
1368 hangcheck_action_to_str(engine->hangcheck.action),
1369 engine->hangcheck.action,
1370 jiffies_to_msecs(jiffies -
1371 engine->hangcheck.action_timestamp));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001372
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001373 if (engine->id == RCS) {
Ben Widawskyd6369512016-09-20 16:54:32 +03001374 seq_puts(m, "\tinstdone read =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001375
Ben Widawskyd6369512016-09-20 16:54:32 +03001376 i915_instdone_info(dev_priv, m, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001377
Ben Widawskyd6369512016-09-20 16:54:32 +03001378 seq_puts(m, "\tinstdone accu =\n");
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001379
Ben Widawskyd6369512016-09-20 16:54:32 +03001380 i915_instdone_info(dev_priv, m,
1381 &engine->hangcheck.instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001382 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001383 }
1384
1385 return 0;
1386}
1387
Michel Thierry061d06a2017-06-20 10:57:49 +01001388static int i915_reset_info(struct seq_file *m, void *unused)
1389{
1390 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1391 struct i915_gpu_error *error = &dev_priv->gpu_error;
1392 struct intel_engine_cs *engine;
1393 enum intel_engine_id id;
1394
1395 seq_printf(m, "full gpu reset = %u\n", i915_reset_count(error));
1396
1397 for_each_engine(engine, dev_priv, id) {
1398 seq_printf(m, "%s = %u\n", engine->name,
1399 i915_reset_engine_count(error, engine));
1400 }
1401
1402 return 0;
1403}
1404
Ben Widawsky4d855292011-12-12 19:34:16 -08001405static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001406{
David Weinehall36cdd012016-08-22 13:59:31 +03001407 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001408 u32 rgvmodectl, rstdbyctl;
1409 u16 crstandvid;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001410
Ben Widawsky616fdb52011-10-05 11:44:54 -07001411 rgvmodectl = I915_READ(MEMMODECTL);
1412 rstdbyctl = I915_READ(RSTDBYCTL);
1413 crstandvid = I915_READ16(CRSTANDVID);
1414
Jani Nikula742f4912015-09-03 11:16:09 +03001415 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001416 seq_printf(m, "Boost freq: %d\n",
1417 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1418 MEMMODE_BOOST_FREQ_SHIFT);
1419 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001420 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001421 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001422 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001423 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001424 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001425 seq_printf(m, "Starting frequency: P%d\n",
1426 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001427 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001428 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001429 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1430 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1431 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1432 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001433 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001434 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001435 switch (rstdbyctl & RSX_STATUS_MASK) {
1436 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001437 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001438 break;
1439 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001440 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001441 break;
1442 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001443 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001444 break;
1445 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001446 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001447 break;
1448 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001449 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001450 break;
1451 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001452 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001453 break;
1454 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001455 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001456 break;
1457 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001458
1459 return 0;
1460}
1461
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001462static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001463{
Chris Wilson233ebf52017-03-23 10:19:44 +00001464 struct drm_i915_private *i915 = node_to_i915(m->private);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001465 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsond2dc94b2017-03-23 10:19:41 +00001466 unsigned int tmp;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001467
Chris Wilsond7a133d2017-09-07 14:44:41 +01001468 seq_printf(m, "user.bypass_count = %u\n",
1469 i915->uncore.user_forcewake.count);
1470
Chris Wilson233ebf52017-03-23 10:19:44 +00001471 for_each_fw_domain(fw_domain, i915, tmp)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001472 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001473 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilson233ebf52017-03-23 10:19:44 +00001474 READ_ONCE(fw_domain->wake_count));
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001475
1476 return 0;
1477}
1478
Mika Kuoppala13628772017-03-15 17:43:02 +02001479static void print_rc6_res(struct seq_file *m,
1480 const char *title,
1481 const i915_reg_t reg)
1482{
1483 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1484
1485 seq_printf(m, "%s %u (%llu us)\n",
1486 title, I915_READ(reg),
1487 intel_rc6_residency_us(dev_priv, reg));
1488}
1489
Deepak S669ab5a2014-01-10 15:18:26 +05301490static int vlv_drpc_info(struct seq_file *m)
1491{
David Weinehall36cdd012016-08-22 13:59:31 +03001492 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble0d6fc922017-10-10 22:30:02 +01001493 u32 rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301494
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001495 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301496 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1497
Deepak S669ab5a2014-01-10 15:18:26 +05301498 seq_printf(m, "RC6 Enabled: %s\n",
1499 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1500 GEN6_RC_CTL_EI_MODE(1))));
1501 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001502 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301503 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001504 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301505
Mika Kuoppala13628772017-03-15 17:43:02 +02001506 print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
1507 print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
Imre Deak9cc19be2014-04-14 20:24:24 +03001508
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001509 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301510}
1511
Ben Widawsky4d855292011-12-12 19:34:16 -08001512static int gen6_drpc_info(struct seq_file *m)
1513{
David Weinehall36cdd012016-08-22 13:59:31 +03001514 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble960e5462017-10-10 22:29:59 +01001515 u32 gt_core_status, rcctl1, rc6vids = 0;
Akash Goelf2dd7572016-06-27 20:10:01 +05301516 u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001517 unsigned forcewake_count;
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001518 int count = 0;
Ben Widawsky4d855292011-12-12 19:34:16 -08001519
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001520 forcewake_count = READ_ONCE(dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001521 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001522 seq_puts(m, "RC information inaccurate because somebody "
1523 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001524 } else {
1525 /* NB: we cannot use forcewake, else we read the wrong values */
1526 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1527 udelay(10);
1528 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1529 }
1530
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001531 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001532 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001533
Ben Widawsky4d855292011-12-12 19:34:16 -08001534 rcctl1 = I915_READ(GEN6_RC_CONTROL);
David Weinehall36cdd012016-08-22 13:59:31 +03001535 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301536 gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
1537 gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
1538 }
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001539
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001540 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001541 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001542 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001543
Eric Anholtfff24e22012-01-23 16:14:05 -08001544 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001545 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1546 seq_printf(m, "RC6 Enabled: %s\n",
1547 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
David Weinehall36cdd012016-08-22 13:59:31 +03001548 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301549 seq_printf(m, "Render Well Gating Enabled: %s\n",
1550 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
1551 seq_printf(m, "Media Well Gating Enabled: %s\n",
1552 yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
1553 }
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 seq_printf(m, "Deep RC6 Enabled: %s\n",
1555 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1556 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1557 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 switch (gt_core_status & GEN6_RCn_MASK) {
1560 case GEN6_RC0:
1561 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001562 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001564 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 break;
1566 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001567 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 break;
1569 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001570 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001571 break;
1572 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001573 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001574 break;
1575 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001576 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001577 break;
1578 }
1579
1580 seq_printf(m, "Core Power Down: %s\n",
1581 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
David Weinehall36cdd012016-08-22 13:59:31 +03001582 if (INTEL_GEN(dev_priv) >= 9) {
Akash Goelf2dd7572016-06-27 20:10:01 +05301583 seq_printf(m, "Render Power Well: %s\n",
1584 (gen9_powergate_status &
1585 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
1586 seq_printf(m, "Media Power Well: %s\n",
1587 (gen9_powergate_status &
1588 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
1589 }
Ben Widawskycce66a22012-03-27 18:59:38 -07001590
1591 /* Not exactly sure what this is */
Mika Kuoppala13628772017-03-15 17:43:02 +02001592 print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
1593 GEN6_GT_GFX_RC6_LOCKED);
1594 print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
1595 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
1596 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
Ben Widawskycce66a22012-03-27 18:59:38 -07001597
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001598 seq_printf(m, "RC6 voltage: %dmV\n",
1599 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1600 seq_printf(m, "RC6+ voltage: %dmV\n",
1601 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1602 seq_printf(m, "RC6++ voltage: %dmV\n",
1603 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Akash Goelf2dd7572016-06-27 20:10:01 +05301604 return i915_forcewake_domains(m, NULL);
Ben Widawsky4d855292011-12-12 19:34:16 -08001605}
1606
1607static int i915_drpc_info(struct seq_file *m, void *unused)
1608{
David Weinehall36cdd012016-08-22 13:59:31 +03001609 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001610 int err;
1611
1612 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001613
David Weinehall36cdd012016-08-22 13:59:31 +03001614 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001615 err = vlv_drpc_info(m);
David Weinehall36cdd012016-08-22 13:59:31 +03001616 else if (INTEL_GEN(dev_priv) >= 6)
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001617 err = gen6_drpc_info(m);
Ben Widawsky4d855292011-12-12 19:34:16 -08001618 else
Chris Wilsoncf632bd2017-03-13 09:56:17 +00001619 err = ironlake_drpc_info(m);
1620
1621 intel_runtime_pm_put(dev_priv);
1622
1623 return err;
Ben Widawsky4d855292011-12-12 19:34:16 -08001624}
1625
Daniel Vetter9a851782015-06-18 10:30:22 +02001626static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1627{
David Weinehall36cdd012016-08-22 13:59:31 +03001628 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetter9a851782015-06-18 10:30:22 +02001629
1630 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1631 dev_priv->fb_tracking.busy_bits);
1632
1633 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1634 dev_priv->fb_tracking.flip_bits);
1635
1636 return 0;
1637}
1638
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001639static int i915_fbc_status(struct seq_file *m, void *unused)
1640{
David Weinehall36cdd012016-08-22 13:59:31 +03001641 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001642
David Weinehall36cdd012016-08-22 13:59:31 +03001643 if (!HAS_FBC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001644 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001645 return 0;
1646 }
1647
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001648 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001649 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001651 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001652 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001653 else
1654 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001655 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001656
Ville Syrjälä3fd5d1e2017-06-06 15:43:18 +03001657 if (intel_fbc_is_active(dev_priv)) {
1658 u32 mask;
1659
1660 if (INTEL_GEN(dev_priv) >= 8)
1661 mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
1662 else if (INTEL_GEN(dev_priv) >= 7)
1663 mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
1664 else if (INTEL_GEN(dev_priv) >= 5)
1665 mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
1666 else if (IS_G4X(dev_priv))
1667 mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
1668 else
1669 mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
1670 FBC_STAT_COMPRESSED);
1671
1672 seq_printf(m, "Compressing: %s\n", yesno(mask));
Paulo Zanoni0fc6a9d2016-10-21 13:55:46 -02001673 }
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001674
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001675 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001676 intel_runtime_pm_put(dev_priv);
1677
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001678 return 0;
1679}
1680
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001681static int i915_fbc_false_color_get(void *data, u64 *val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001682{
David Weinehall36cdd012016-08-22 13:59:31 +03001683 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001684
David Weinehall36cdd012016-08-22 13:59:31 +03001685 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001686 return -ENODEV;
1687
Rodrigo Vivida46f932014-08-01 02:04:45 -07001688 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001689
1690 return 0;
1691}
1692
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001693static int i915_fbc_false_color_set(void *data, u64 val)
Rodrigo Vivida46f932014-08-01 02:04:45 -07001694{
David Weinehall36cdd012016-08-22 13:59:31 +03001695 struct drm_i915_private *dev_priv = data;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001696 u32 reg;
1697
David Weinehall36cdd012016-08-22 13:59:31 +03001698 if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
Rodrigo Vivida46f932014-08-01 02:04:45 -07001699 return -ENODEV;
1700
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001701 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001702
1703 reg = I915_READ(ILK_DPFC_CONTROL);
1704 dev_priv->fbc.false_color = val;
1705
1706 I915_WRITE(ILK_DPFC_CONTROL, val ?
1707 (reg | FBC_CTL_FALSE_COLOR) :
1708 (reg & ~FBC_CTL_FALSE_COLOR));
1709
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001710 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001711 return 0;
1712}
1713
Ville Syrjälä4127dc42017-06-06 15:44:12 +03001714DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
1715 i915_fbc_false_color_get, i915_fbc_false_color_set,
Rodrigo Vivida46f932014-08-01 02:04:45 -07001716 "%llu\n");
1717
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718static int i915_ips_status(struct seq_file *m, void *unused)
1719{
David Weinehall36cdd012016-08-22 13:59:31 +03001720 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721
David Weinehall36cdd012016-08-22 13:59:31 +03001722 if (!HAS_IPS(dev_priv)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001723 seq_puts(m, "not supported\n");
1724 return 0;
1725 }
1726
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001727 intel_runtime_pm_get(dev_priv);
1728
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001729 seq_printf(m, "Enabled by kernel parameter: %s\n",
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001730 yesno(i915_modparams.enable_ips));
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001731
David Weinehall36cdd012016-08-22 13:59:31 +03001732 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001733 seq_puts(m, "Currently: unknown\n");
1734 } else {
1735 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1736 seq_puts(m, "Currently: enabled\n");
1737 else
1738 seq_puts(m, "Currently: disabled\n");
1739 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001740
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001741 intel_runtime_pm_put(dev_priv);
1742
Paulo Zanoni92d44622013-05-31 16:33:24 -03001743 return 0;
1744}
1745
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001746static int i915_sr_status(struct seq_file *m, void *unused)
1747{
David Weinehall36cdd012016-08-22 13:59:31 +03001748 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001749 bool sr_enabled = false;
1750
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001751 intel_runtime_pm_get(dev_priv);
Chris Wilson9c870d02016-10-24 13:42:15 +01001752 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001753
Chris Wilson7342a722017-03-09 14:20:49 +00001754 if (INTEL_GEN(dev_priv) >= 9)
1755 /* no global SR status; inspect per-plane WM */;
1756 else if (HAS_PCH_SPLIT(dev_priv))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001757 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Jani Nikulac0f86832016-12-07 12:13:04 +02001758 else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
David Weinehall36cdd012016-08-22 13:59:31 +03001759 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001760 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001761 else if (IS_I915GM(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001762 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001763 else if (IS_PINEVIEW(dev_priv))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001764 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
David Weinehall36cdd012016-08-22 13:59:31 +03001765 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001766 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001767
Chris Wilson9c870d02016-10-24 13:42:15 +01001768 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001769 intel_runtime_pm_put(dev_priv);
1770
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +00001771 seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001772
1773 return 0;
1774}
1775
Jesse Barnes7648fa92010-05-20 14:28:11 -07001776static int i915_emon_status(struct seq_file *m, void *unused)
1777{
David Weinehall36cdd012016-08-22 13:59:31 +03001778 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1779 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001780 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001781 int ret;
1782
David Weinehall36cdd012016-08-22 13:59:31 +03001783 if (!IS_GEN5(dev_priv))
Chris Wilson582be6b2012-04-30 19:35:02 +01001784 return -ENODEV;
1785
Chris Wilsonde227ef2010-07-03 07:58:38 +01001786 ret = mutex_lock_interruptible(&dev->struct_mutex);
1787 if (ret)
1788 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001789
1790 temp = i915_mch_val(dev_priv);
1791 chipset = i915_chipset_val(dev_priv);
1792 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001793 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001794
1795 seq_printf(m, "GMCH temp: %ld\n", temp);
1796 seq_printf(m, "Chipset power: %ld\n", chipset);
1797 seq_printf(m, "GFX power: %ld\n", gfx);
1798 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1799
1800 return 0;
1801}
1802
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001803static int i915_ring_freq_table(struct seq_file *m, void *unused)
1804{
David Weinehall36cdd012016-08-22 13:59:31 +03001805 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001806 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001807 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001808 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301809 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001810
Carlos Santa26310342016-08-17 12:30:41 -07001811 if (!HAS_LLC(dev_priv)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001812 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001813 return 0;
1814 }
1815
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001816 intel_runtime_pm_get(dev_priv);
1817
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001818 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001819 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001820 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001821
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001822 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301823 /* Convert GT frequency to 50 HZ units */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001824 min_gpu_freq = rps->min_freq_softlimit / GEN9_FREQ_SCALER;
1825 max_gpu_freq = rps->max_freq_softlimit / GEN9_FREQ_SCALER;
Akash Goelf936ec32015-06-29 14:50:22 +05301826 } else {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001827 min_gpu_freq = rps->min_freq_softlimit;
1828 max_gpu_freq = rps->max_freq_softlimit;
Akash Goelf936ec32015-06-29 14:50:22 +05301829 }
1830
Damien Lespiau267f0c92013-06-24 22:59:48 +01001831 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001832
Akash Goelf936ec32015-06-29 14:50:22 +05301833 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001834 ia_freq = gpu_freq;
1835 sandybridge_pcode_read(dev_priv,
1836 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1837 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001838 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301839 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivi35ceabf2017-07-06 13:41:13 -07001840 (IS_GEN9_BC(dev_priv) ||
1841 IS_CANNONLAKE(dev_priv) ?
Rodrigo Vivib976dc52017-01-23 10:32:37 -08001842 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001843 ((ia_freq >> 0) & 0xff) * 100,
1844 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001845 }
1846
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001847 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001848
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001849out:
1850 intel_runtime_pm_put(dev_priv);
1851 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001852}
1853
Chris Wilson44834a62010-08-19 16:09:23 +01001854static int i915_opregion(struct seq_file *m, void *unused)
1855{
David Weinehall36cdd012016-08-22 13:59:31 +03001856 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1857 struct drm_device *dev = &dev_priv->drm;
Chris Wilson44834a62010-08-19 16:09:23 +01001858 struct intel_opregion *opregion = &dev_priv->opregion;
1859 int ret;
1860
1861 ret = mutex_lock_interruptible(&dev->struct_mutex);
1862 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001863 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001864
Jani Nikula2455a8e2015-12-14 12:50:53 +02001865 if (opregion->header)
1866 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001867
1868 mutex_unlock(&dev->struct_mutex);
1869
Daniel Vetter0d38f002012-04-21 22:49:10 +02001870out:
Chris Wilson44834a62010-08-19 16:09:23 +01001871 return 0;
1872}
1873
Jani Nikulaada8f952015-12-15 13:17:12 +02001874static int i915_vbt(struct seq_file *m, void *unused)
1875{
David Weinehall36cdd012016-08-22 13:59:31 +03001876 struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
Jani Nikulaada8f952015-12-15 13:17:12 +02001877
1878 if (opregion->vbt)
1879 seq_write(m, opregion->vbt, opregion->vbt_size);
1880
1881 return 0;
1882}
1883
Chris Wilson37811fc2010-08-25 22:45:57 +01001884static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1885{
David Weinehall36cdd012016-08-22 13:59:31 +03001886 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1887 struct drm_device *dev = &dev_priv->drm;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301888 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001889 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001890 int ret;
1891
1892 ret = mutex_lock_interruptible(&dev->struct_mutex);
1893 if (ret)
1894 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001895
Daniel Vetter06957262015-08-10 13:34:08 +02001896#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter346fb4e2017-07-06 15:00:20 +02001897 if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
David Weinehall36cdd012016-08-22 13:59:31 +03001898 fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001899
Chris Wilson25bcce92016-07-02 15:36:00 +01001900 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1901 fbdev_fb->base.width,
1902 fbdev_fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001903 fbdev_fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001904 fbdev_fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001905 fbdev_fb->base.modifier,
Chris Wilson25bcce92016-07-02 15:36:00 +01001906 drm_framebuffer_read_refcount(&fbdev_fb->base));
1907 describe_obj(m, fbdev_fb->obj);
1908 seq_putc(m, '\n');
1909 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001910#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001911
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001912 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001913 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301914 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1915 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001916 continue;
1917
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001918 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 +01001919 fb->base.width,
1920 fb->base.height,
Ville Syrjäläb00c6002016-12-14 23:31:35 +02001921 fb->base.format->depth,
Ville Syrjälä272725c2016-12-14 23:32:20 +02001922 fb->base.format->cpp[0] * 8,
Ville Syrjäläbae781b2016-11-16 13:33:16 +02001923 fb->base.modifier,
Dave Airlie747a5982016-04-15 15:10:35 +10001924 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001925 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001926 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001927 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001928 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001929 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001930
1931 return 0;
1932}
1933
Chris Wilson7e37f882016-08-02 22:50:21 +01001934static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001935{
Chris Wilsonfe085f12017-03-21 10:25:52 +00001936 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u)",
1937 ring->space, ring->head, ring->tail);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001938}
1939
Ben Widawskye76d3632011-03-19 18:14:29 -07001940static int i915_context_status(struct seq_file *m, void *unused)
1941{
David Weinehall36cdd012016-08-22 13:59:31 +03001942 struct drm_i915_private *dev_priv = node_to_i915(m->private);
1943 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001944 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01001945 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05301946 enum intel_engine_id id;
Dave Gordonc3232b12016-03-23 18:19:53 +00001947 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001948
Daniel Vetterf3d28872014-05-29 23:23:08 +02001949 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001950 if (ret)
1951 return ret;
1952
Chris Wilson829a0af2017-06-20 12:05:45 +01001953 list_for_each_entry(ctx, &dev_priv->contexts.list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01001954 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsonc84455b2016-08-15 10:49:08 +01001955 if (ctx->pid) {
Chris Wilsond28b99a2016-05-24 14:53:39 +01001956 struct task_struct *task;
1957
Chris Wilsonc84455b2016-08-15 10:49:08 +01001958 task = get_pid_task(ctx->pid, PIDTYPE_PID);
Chris Wilsond28b99a2016-05-24 14:53:39 +01001959 if (task) {
1960 seq_printf(m, "(%s [%d]) ",
1961 task->comm, task->pid);
1962 put_task_struct(task);
1963 }
Chris Wilsonc84455b2016-08-15 10:49:08 +01001964 } else if (IS_ERR(ctx->file_priv)) {
1965 seq_puts(m, "(deleted) ");
Chris Wilsond28b99a2016-05-24 14:53:39 +01001966 } else {
1967 seq_puts(m, "(kernel) ");
1968 }
1969
Chris Wilsonbca44d82016-05-24 14:53:41 +01001970 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
1971 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07001972
Akash Goel3b3f1652016-10-13 22:44:48 +05301973 for_each_engine(engine, dev_priv, id) {
Chris Wilsonbca44d82016-05-24 14:53:41 +01001974 struct intel_context *ce = &ctx->engine[engine->id];
1975
1976 seq_printf(m, "%s: ", engine->name);
1977 seq_putc(m, ce->initialised ? 'I' : 'i');
1978 if (ce->state)
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001979 describe_obj(m, ce->state->obj);
Chris Wilsondca33ec2016-08-02 22:50:20 +01001980 if (ce->ring)
Chris Wilson7e37f882016-08-02 22:50:21 +01001981 describe_ctx_ring(m, ce->ring);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001982 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001983 }
1984
Ben Widawskya33afea2013-09-17 21:12:45 -07001985 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001986 }
1987
Daniel Vetterf3d28872014-05-29 23:23:08 +02001988 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001989
1990 return 0;
1991}
1992
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001993static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01001994 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001995 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001996{
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001997 struct i915_vma *vma = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001998 struct page *page;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999 int j;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002000
Chris Wilson7069b142016-04-28 09:56:52 +01002001 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2002
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002003 if (!vma) {
2004 seq_puts(m, "\tFake context\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002005 return;
2006 }
2007
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002008 if (vma->flags & I915_VMA_GLOBAL_BIND)
2009 seq_printf(m, "\tBound in GGTT at 0x%08x\n",
Chris Wilsonbde13eb2016-08-15 10:49:07 +01002010 i915_ggtt_offset(vma));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002011
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002012 if (i915_gem_object_pin_pages(vma->obj)) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002013 seq_puts(m, "\tFailed to get pages for context object\n\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002014 return;
2015 }
2016
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002017 page = i915_gem_object_get_page(vma->obj, LRC_STATE_PN);
2018 if (page) {
2019 u32 *reg_state = kmap_atomic(page);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020
2021 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
Chris Wilsonbf3783e2016-08-15 10:48:54 +01002022 seq_printf(m,
2023 "\t[0x%04x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2024 j * 4,
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002025 reg_state[j], reg_state[j + 1],
2026 reg_state[j + 2], reg_state[j + 3]);
2027 }
2028 kunmap_atomic(reg_state);
2029 }
2030
Chris Wilsona4f5ea62016-10-28 13:58:35 +01002031 i915_gem_object_unpin_pages(vma->obj);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002032 seq_putc(m, '\n');
2033}
2034
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002035static int i915_dump_lrc(struct seq_file *m, void *unused)
2036{
David Weinehall36cdd012016-08-22 13:59:31 +03002037 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2038 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002039 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002040 struct i915_gem_context *ctx;
Akash Goel3b3f1652016-10-13 22:44:48 +05302041 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002042 int ret;
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002043
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002044 if (!i915_modparams.enable_execlists) {
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002045 seq_printf(m, "Logical Ring Contexts are disabled\n");
2046 return 0;
2047 }
2048
2049 ret = mutex_lock_interruptible(&dev->struct_mutex);
2050 if (ret)
2051 return ret;
2052
Chris Wilson829a0af2017-06-20 12:05:45 +01002053 list_for_each_entry(ctx, &dev_priv->contexts.list, link)
Akash Goel3b3f1652016-10-13 22:44:48 +05302054 for_each_engine(engine, dev_priv, id)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002055 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002056
2057 mutex_unlock(&dev->struct_mutex);
2058
2059 return 0;
2060}
2061
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002062static const char *swizzle_string(unsigned swizzle)
2063{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002064 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002065 case I915_BIT_6_SWIZZLE_NONE:
2066 return "none";
2067 case I915_BIT_6_SWIZZLE_9:
2068 return "bit9";
2069 case I915_BIT_6_SWIZZLE_9_10:
2070 return "bit9/bit10";
2071 case I915_BIT_6_SWIZZLE_9_11:
2072 return "bit9/bit11";
2073 case I915_BIT_6_SWIZZLE_9_10_11:
2074 return "bit9/bit10/bit11";
2075 case I915_BIT_6_SWIZZLE_9_17:
2076 return "bit9/bit17";
2077 case I915_BIT_6_SWIZZLE_9_10_17:
2078 return "bit9/bit10/bit17";
2079 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002080 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002081 }
2082
2083 return "bug";
2084}
2085
2086static int i915_swizzle_info(struct seq_file *m, void *data)
2087{
David Weinehall36cdd012016-08-22 13:59:31 +03002088 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002089
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002090 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002091
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002092 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2093 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2094 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2095 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2096
David Weinehall36cdd012016-08-22 13:59:31 +03002097 if (IS_GEN3(dev_priv) || IS_GEN4(dev_priv)) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002098 seq_printf(m, "DDC = 0x%08x\n",
2099 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002100 seq_printf(m, "DDC2 = 0x%08x\n",
2101 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002102 seq_printf(m, "C0DRB3 = 0x%04x\n",
2103 I915_READ16(C0DRB3));
2104 seq_printf(m, "C1DRB3 = 0x%04x\n",
2105 I915_READ16(C1DRB3));
David Weinehall36cdd012016-08-22 13:59:31 +03002106 } else if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002107 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2108 I915_READ(MAD_DIMM_C0));
2109 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2110 I915_READ(MAD_DIMM_C1));
2111 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2112 I915_READ(MAD_DIMM_C2));
2113 seq_printf(m, "TILECTL = 0x%08x\n",
2114 I915_READ(TILECTL));
David Weinehall36cdd012016-08-22 13:59:31 +03002115 if (INTEL_GEN(dev_priv) >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002116 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2117 I915_READ(GAMTARBMODE));
2118 else
2119 seq_printf(m, "ARB_MODE = 0x%08x\n",
2120 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002121 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2122 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002123 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002124
2125 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2126 seq_puts(m, "L-shaped memory detected\n");
2127
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002128 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002129
2130 return 0;
2131}
2132
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002133static int per_file_ctx(int id, void *ptr, void *data)
2134{
Chris Wilsone2efd132016-05-24 14:53:34 +01002135 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002136 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002137 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2138
2139 if (!ppgtt) {
2140 seq_printf(m, " no ppgtt for context %d\n",
2141 ctx->user_handle);
2142 return 0;
2143 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002144
Oscar Mateof83d6512014-05-22 14:13:38 +01002145 if (i915_gem_context_is_default(ctx))
2146 seq_puts(m, " default context:\n");
2147 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002148 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002149 ppgtt->debug_dump(ppgtt, m);
2150
2151 return 0;
2152}
2153
David Weinehall36cdd012016-08-22 13:59:31 +03002154static void gen8_ppgtt_info(struct seq_file *m,
2155 struct drm_i915_private *dev_priv)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002156{
Ben Widawsky77df6772013-11-02 21:07:30 -07002157 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Akash Goel3b3f1652016-10-13 22:44:48 +05302158 struct intel_engine_cs *engine;
2159 enum intel_engine_id id;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002160 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002161
Ben Widawsky77df6772013-11-02 21:07:30 -07002162 if (!ppgtt)
2163 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002164
Akash Goel3b3f1652016-10-13 22:44:48 +05302165 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002167 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002168 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002169 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002170 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002171 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002172 }
2173 }
2174}
2175
David Weinehall36cdd012016-08-22 13:59:31 +03002176static void gen6_ppgtt_info(struct seq_file *m,
2177 struct drm_i915_private *dev_priv)
Ben Widawsky77df6772013-11-02 21:07:30 -07002178{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002179 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302180 enum intel_engine_id id;
Ben Widawsky77df6772013-11-02 21:07:30 -07002181
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002182 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002183 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2184
Akash Goel3b3f1652016-10-13 22:44:48 +05302185 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002186 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002187 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002188 seq_printf(m, "GFX_MODE: 0x%08x\n",
2189 I915_READ(RING_MODE_GEN7(engine)));
2190 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2191 I915_READ(RING_PP_DIR_BASE(engine)));
2192 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2193 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2194 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2195 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002196 }
2197 if (dev_priv->mm.aliasing_ppgtt) {
2198 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2199
Damien Lespiau267f0c92013-06-24 22:59:48 +01002200 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002201 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002202
Ben Widawsky87d60b62013-12-06 14:11:29 -08002203 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002204 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002205
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002206 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002207}
2208
2209static int i915_ppgtt_info(struct seq_file *m, void *data)
2210{
David Weinehall36cdd012016-08-22 13:59:31 +03002211 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2212 struct drm_device *dev = &dev_priv->drm;
Michel Thierryea91e402015-07-29 17:23:57 +01002213 struct drm_file *file;
Chris Wilson637ee292016-08-22 14:28:20 +01002214 int ret;
Ben Widawsky77df6772013-11-02 21:07:30 -07002215
Chris Wilson637ee292016-08-22 14:28:20 +01002216 mutex_lock(&dev->filelist_mutex);
2217 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawsky77df6772013-11-02 21:07:30 -07002218 if (ret)
Chris Wilson637ee292016-08-22 14:28:20 +01002219 goto out_unlock;
2220
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002221 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002222
David Weinehall36cdd012016-08-22 13:59:31 +03002223 if (INTEL_GEN(dev_priv) >= 8)
2224 gen8_ppgtt_info(m, dev_priv);
2225 else if (INTEL_GEN(dev_priv) >= 6)
2226 gen6_ppgtt_info(m, dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002227
Michel Thierryea91e402015-07-29 17:23:57 +01002228 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2229 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002230 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002231
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002232 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002233 if (!task) {
2234 ret = -ESRCH;
Chris Wilson637ee292016-08-22 14:28:20 +01002235 goto out_rpm;
Dan Carpenter06812762015-10-02 18:14:22 +03002236 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002237 seq_printf(m, "\nproc: %s\n", task->comm);
2238 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002239 idr_for_each(&file_priv->context_idr, per_file_ctx,
2240 (void *)(unsigned long)m);
2241 }
2242
Chris Wilson637ee292016-08-22 14:28:20 +01002243out_rpm:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002244 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002245 mutex_unlock(&dev->struct_mutex);
Chris Wilson637ee292016-08-22 14:28:20 +01002246out_unlock:
2247 mutex_unlock(&dev->filelist_mutex);
Dan Carpenter06812762015-10-02 18:14:22 +03002248 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002249}
2250
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002251static int count_irq_waiters(struct drm_i915_private *i915)
2252{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002253 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05302254 enum intel_engine_id id;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002255 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002256
Akash Goel3b3f1652016-10-13 22:44:48 +05302257 for_each_engine(engine, i915, id)
Chris Wilson688e6c72016-07-01 17:23:15 +01002258 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002259
2260 return count;
2261}
2262
Chris Wilson7466c292016-08-15 09:49:33 +01002263static const char *rps_power_to_str(unsigned int power)
2264{
2265 static const char * const strings[] = {
2266 [LOW_POWER] = "low power",
2267 [BETWEEN] = "mixed",
2268 [HIGH_POWER] = "high power",
2269 };
2270
2271 if (power >= ARRAY_SIZE(strings) || !strings[power])
2272 return "unknown";
2273
2274 return strings[power];
2275}
2276
Chris Wilson1854d5c2015-04-07 16:20:32 +01002277static int i915_rps_boost_info(struct seq_file *m, void *data)
2278{
David Weinehall36cdd012016-08-22 13:59:31 +03002279 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2280 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002281 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002282 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002283
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002284 seq_printf(m, "RPS enabled? %d\n", rps->enabled);
Chris Wilson28176ef2016-10-28 13:58:56 +01002285 seq_printf(m, "GPU busy? %s [%d requests]\n",
2286 yesno(dev_priv->gt.awake), dev_priv->gt.active_requests);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002287 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002288 seq_printf(m, "Boosts outstanding? %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002289 atomic_read(&rps->num_waiters));
Chris Wilson7466c292016-08-15 09:49:33 +01002290 seq_printf(m, "Frequency requested %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002291 intel_gpu_freq(dev_priv, rps->cur_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002292 seq_printf(m, " min hard:%d, soft:%d; max soft:%d, hard:%d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002293 intel_gpu_freq(dev_priv, rps->min_freq),
2294 intel_gpu_freq(dev_priv, rps->min_freq_softlimit),
2295 intel_gpu_freq(dev_priv, rps->max_freq_softlimit),
2296 intel_gpu_freq(dev_priv, rps->max_freq));
Chris Wilson7466c292016-08-15 09:49:33 +01002297 seq_printf(m, " idle:%d, efficient:%d, boost:%d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002298 intel_gpu_freq(dev_priv, rps->idle_freq),
2299 intel_gpu_freq(dev_priv, rps->efficient_freq),
2300 intel_gpu_freq(dev_priv, rps->boost_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002301
2302 mutex_lock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002303 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2304 struct drm_i915_file_private *file_priv = file->driver_priv;
2305 struct task_struct *task;
2306
2307 rcu_read_lock();
2308 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002309 seq_printf(m, "%s [%d]: %d boosts\n",
Chris Wilson1854d5c2015-04-07 16:20:32 +01002310 task ? task->comm : "<unknown>",
2311 task ? task->pid : -1,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002312 atomic_read(&file_priv->rps_client.boosts));
Chris Wilson1854d5c2015-04-07 16:20:32 +01002313 rcu_read_unlock();
2314 }
Chris Wilson7b92c1b2017-06-28 13:35:48 +01002315 seq_printf(m, "Kernel (anonymous) boosts: %d\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002316 atomic_read(&rps->boosts));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002317 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002318
Chris Wilson7466c292016-08-15 09:49:33 +01002319 if (INTEL_GEN(dev_priv) >= 6 &&
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002320 rps->enabled &&
Chris Wilson28176ef2016-10-28 13:58:56 +01002321 dev_priv->gt.active_requests) {
Chris Wilson7466c292016-08-15 09:49:33 +01002322 u32 rpup, rpupei;
2323 u32 rpdown, rpdownei;
2324
2325 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
2326 rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
2327 rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
2328 rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
2329 rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
2330 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
2331
2332 seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002333 rps_power_to_str(rps->power));
Chris Wilson7466c292016-08-15 09:49:33 +01002334 seq_printf(m, " Avg. up: %d%% [above threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002335 rpup && rpupei ? 100 * rpup / rpupei : 0,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002336 rps->up_threshold);
Chris Wilson7466c292016-08-15 09:49:33 +01002337 seq_printf(m, " Avg. down: %d%% [below threshold? %d%%]\n",
Chris Wilson23f4a282017-02-18 11:27:08 +00002338 rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01002339 rps->down_threshold);
Chris Wilson7466c292016-08-15 09:49:33 +01002340 } else {
2341 seq_puts(m, "\nRPS Autotuning inactive\n");
2342 }
2343
Chris Wilson8d3afd72015-05-21 21:01:47 +01002344 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002345}
2346
Ben Widawsky63573eb2013-07-04 11:02:07 -07002347static int i915_llc(struct seq_file *m, void *data)
2348{
David Weinehall36cdd012016-08-22 13:59:31 +03002349 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002350 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002351
David Weinehall36cdd012016-08-22 13:59:31 +03002352 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002353 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2354 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002355
2356 return 0;
2357}
2358
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002359static int i915_huc_load_status_info(struct seq_file *m, void *data)
2360{
2361 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002362 struct drm_printer p;
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002363
2364 if (!HAS_HUC_UCODE(dev_priv))
2365 return 0;
2366
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002367 p = drm_seq_file_printer(m);
2368 intel_uc_fw_dump(&dev_priv->huc.fw, &p);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002369
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302370 intel_runtime_pm_get(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002371 seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302372 intel_runtime_pm_put(dev_priv);
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08002373
2374 return 0;
2375}
2376
Alex Daifdf5d352015-08-12 15:43:37 +01002377static int i915_guc_load_status_info(struct seq_file *m, void *data)
2378{
David Weinehall36cdd012016-08-22 13:59:31 +03002379 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002380 struct drm_printer p;
Alex Daifdf5d352015-08-12 15:43:37 +01002381 u32 tmp, i;
2382
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002383 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002384 return 0;
2385
Michal Wajdeczko56ffc742017-10-17 09:44:49 +00002386 p = drm_seq_file_printer(m);
2387 intel_uc_fw_dump(&dev_priv->guc.fw, &p);
Alex Daifdf5d352015-08-12 15:43:37 +01002388
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302389 intel_runtime_pm_get(dev_priv);
2390
Alex Daifdf5d352015-08-12 15:43:37 +01002391 tmp = I915_READ(GUC_STATUS);
2392
2393 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2394 seq_printf(m, "\tBootrom status = 0x%x\n",
2395 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2396 seq_printf(m, "\tuKernel status = 0x%x\n",
2397 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2398 seq_printf(m, "\tMIA Core status = 0x%x\n",
2399 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2400 seq_puts(m, "\nScratch registers:\n");
2401 for (i = 0; i < 16; i++)
2402 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2403
sagar.a.kamble@intel.com3582ad12017-02-03 13:58:33 +05302404 intel_runtime_pm_put(dev_priv);
2405
Alex Daifdf5d352015-08-12 15:43:37 +01002406 return 0;
2407}
2408
Akash Goel5aa1ee42016-10-12 21:54:36 +05302409static void i915_guc_log_info(struct seq_file *m,
2410 struct drm_i915_private *dev_priv)
2411{
2412 struct intel_guc *guc = &dev_priv->guc;
2413
2414 seq_puts(m, "\nGuC logging stats:\n");
2415
2416 seq_printf(m, "\tISR: flush count %10u, overflow count %10u\n",
2417 guc->log.flush_count[GUC_ISR_LOG_BUFFER],
2418 guc->log.total_overflow_count[GUC_ISR_LOG_BUFFER]);
2419
2420 seq_printf(m, "\tDPC: flush count %10u, overflow count %10u\n",
2421 guc->log.flush_count[GUC_DPC_LOG_BUFFER],
2422 guc->log.total_overflow_count[GUC_DPC_LOG_BUFFER]);
2423
2424 seq_printf(m, "\tCRASH: flush count %10u, overflow count %10u\n",
2425 guc->log.flush_count[GUC_CRASH_DUMP_LOG_BUFFER],
2426 guc->log.total_overflow_count[GUC_CRASH_DUMP_LOG_BUFFER]);
2427
2428 seq_printf(m, "\tTotal flush interrupt count: %u\n",
2429 guc->log.flush_interrupt_count);
2430
2431 seq_printf(m, "\tCapture miss count: %u\n",
2432 guc->log.capture_miss_count);
2433}
2434
Dave Gordon8b417c22015-08-12 15:43:44 +01002435static void i915_guc_client_info(struct seq_file *m,
2436 struct drm_i915_private *dev_priv,
2437 struct i915_guc_client *client)
2438{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002439 struct intel_engine_cs *engine;
Dave Gordonc18468c2016-08-09 15:19:22 +01002440 enum intel_engine_id id;
Dave Gordon8b417c22015-08-12 15:43:44 +01002441 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002442
Oscar Mateob09935a2017-03-22 10:39:53 -07002443 seq_printf(m, "\tPriority %d, GuC stage index: %u, PD offset 0x%x\n",
2444 client->priority, client->stage_id, client->proc_desc_offset);
Michał Winiarski59db36c2017-09-14 12:51:23 +02002445 seq_printf(m, "\tDoorbell id %d, offset: 0x%lx\n",
2446 client->doorbell_id, client->doorbell_offset);
Dave Gordon8b417c22015-08-12 15:43:44 +01002447
Akash Goel3b3f1652016-10-13 22:44:48 +05302448 for_each_engine(engine, dev_priv, id) {
Dave Gordonc18468c2016-08-09 15:19:22 +01002449 u64 submissions = client->submissions[id];
2450 tot += submissions;
Dave Gordon8b417c22015-08-12 15:43:44 +01002451 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordonc18468c2016-08-09 15:19:22 +01002452 submissions, engine->name);
Dave Gordon8b417c22015-08-12 15:43:44 +01002453 }
2454 seq_printf(m, "\tTotal: %llu\n", tot);
2455}
2456
Oscar Mateoa8b93702017-05-10 15:04:51 +00002457static bool check_guc_submission(struct seq_file *m)
Dave Gordon8b417c22015-08-12 15:43:44 +01002458{
David Weinehall36cdd012016-08-22 13:59:31 +03002459 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Chris Wilson334636c2016-11-29 12:10:20 +00002460 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002461
Chris Wilson334636c2016-11-29 12:10:20 +00002462 if (!guc->execbuf_client) {
2463 seq_printf(m, "GuC submission %s\n",
2464 HAS_GUC_SCHED(dev_priv) ?
2465 "disabled" :
2466 "not supported");
Oscar Mateoa8b93702017-05-10 15:04:51 +00002467 return false;
Chris Wilson334636c2016-11-29 12:10:20 +00002468 }
Dave Gordon8b417c22015-08-12 15:43:44 +01002469
Oscar Mateoa8b93702017-05-10 15:04:51 +00002470 return true;
2471}
2472
Dave Gordon8b417c22015-08-12 15:43:44 +01002473static int i915_guc_info(struct seq_file *m, void *data)
2474{
2475 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2476 const struct intel_guc *guc = &dev_priv->guc;
Dave Gordon8b417c22015-08-12 15:43:44 +01002477
Oscar Mateoa8b93702017-05-10 15:04:51 +00002478 if (!check_guc_submission(m))
Dave Gordon8b417c22015-08-12 15:43:44 +01002479 return 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002480
Dave Gordon9636f6d2016-06-13 17:57:28 +01002481 seq_printf(m, "Doorbell map:\n");
Joonas Lahtinenabddffd2017-03-22 10:39:44 -07002482 seq_printf(m, "\t%*pb\n", GUC_NUM_DOORBELLS, guc->doorbell_bitmap);
Chris Wilson334636c2016-11-29 12:10:20 +00002483 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc->db_cacheline);
Dave Gordon9636f6d2016-06-13 17:57:28 +01002484
Chris Wilson334636c2016-11-29 12:10:20 +00002485 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc->execbuf_client);
2486 i915_guc_client_info(m, dev_priv, guc->execbuf_client);
Dave Gordon8b417c22015-08-12 15:43:44 +01002487
Akash Goel5aa1ee42016-10-12 21:54:36 +05302488 i915_guc_log_info(m, dev_priv);
2489
Dave Gordon8b417c22015-08-12 15:43:44 +01002490 /* Add more as required ... */
2491
2492 return 0;
2493}
2494
Oscar Mateoa8b93702017-05-10 15:04:51 +00002495static int i915_guc_stage_pool(struct seq_file *m, void *data)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002496{
David Weinehall36cdd012016-08-22 13:59:31 +03002497 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Oscar Mateoa8b93702017-05-10 15:04:51 +00002498 const struct intel_guc *guc = &dev_priv->guc;
2499 struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
2500 struct i915_guc_client *client = guc->execbuf_client;
2501 unsigned int tmp;
2502 int index;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002503
Oscar Mateoa8b93702017-05-10 15:04:51 +00002504 if (!check_guc_submission(m))
Alex Dai4c7e77f2015-08-12 15:43:40 +01002505 return 0;
2506
Oscar Mateoa8b93702017-05-10 15:04:51 +00002507 for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
2508 struct intel_engine_cs *engine;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002509
Oscar Mateoa8b93702017-05-10 15:04:51 +00002510 if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
2511 continue;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002512
Oscar Mateoa8b93702017-05-10 15:04:51 +00002513 seq_printf(m, "GuC stage descriptor %u:\n", index);
2514 seq_printf(m, "\tIndex: %u\n", desc->stage_id);
2515 seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
2516 seq_printf(m, "\tPriority: %d\n", desc->priority);
2517 seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
2518 seq_printf(m, "\tEngines used: 0x%x\n",
2519 desc->engines_used);
2520 seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
2521 desc->db_trigger_phy,
2522 desc->db_trigger_cpu,
2523 desc->db_trigger_uk);
2524 seq_printf(m, "\tProcess descriptor: 0x%x\n",
2525 desc->process_desc);
Colin Ian King9a094852017-05-16 10:22:35 +01002526 seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
Oscar Mateoa8b93702017-05-10 15:04:51 +00002527 desc->wq_addr, desc->wq_size);
2528 seq_putc(m, '\n');
2529
2530 for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
2531 u32 guc_engine_id = engine->guc_id;
2532 struct guc_execlist_context *lrc =
2533 &desc->lrc[guc_engine_id];
2534
2535 seq_printf(m, "\t%s LRC:\n", engine->name);
2536 seq_printf(m, "\t\tContext desc: 0x%x\n",
2537 lrc->context_desc);
2538 seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
2539 seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
2540 seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
2541 seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
2542 seq_putc(m, '\n');
2543 }
Alex Dai4c7e77f2015-08-12 15:43:40 +01002544 }
2545
Oscar Mateoa8b93702017-05-10 15:04:51 +00002546 return 0;
2547}
2548
Alex Dai4c7e77f2015-08-12 15:43:40 +01002549static int i915_guc_log_dump(struct seq_file *m, void *data)
2550{
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002551 struct drm_info_node *node = m->private;
2552 struct drm_i915_private *dev_priv = node_to_i915(node);
2553 bool dump_load_err = !!node->info_ent->data;
2554 struct drm_i915_gem_object *obj = NULL;
2555 u32 *log;
2556 int i = 0;
Alex Dai4c7e77f2015-08-12 15:43:40 +01002557
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002558 if (dump_load_err)
2559 obj = dev_priv->guc.load_err_log;
2560 else if (dev_priv->guc.log.vma)
2561 obj = dev_priv->guc.log.vma->obj;
2562
2563 if (!obj)
Alex Dai4c7e77f2015-08-12 15:43:40 +01002564 return 0;
2565
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002566 log = i915_gem_object_pin_map(obj, I915_MAP_WC);
2567 if (IS_ERR(log)) {
2568 DRM_DEBUG("Failed to pin object\n");
2569 seq_puts(m, "(log data unaccessible)\n");
2570 return PTR_ERR(log);
Alex Dai4c7e77f2015-08-12 15:43:40 +01002571 }
2572
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002573 for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
2574 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2575 *(log + i), *(log + i + 1),
2576 *(log + i + 2), *(log + i + 3));
2577
Alex Dai4c7e77f2015-08-12 15:43:40 +01002578 seq_putc(m, '\n');
2579
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07002580 i915_gem_object_unpin_map(obj);
2581
Alex Dai4c7e77f2015-08-12 15:43:40 +01002582 return 0;
2583}
2584
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302585static int i915_guc_log_control_get(void *data, u64 *val)
2586{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002587 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302588
2589 if (!dev_priv->guc.log.vma)
2590 return -EINVAL;
2591
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00002592 *val = i915_modparams.guc_log_level;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302593
2594 return 0;
2595}
2596
2597static int i915_guc_log_control_set(void *data, u64 val)
2598{
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002599 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302600 int ret;
2601
2602 if (!dev_priv->guc.log.vma)
2603 return -EINVAL;
2604
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002605 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302606 if (ret)
2607 return ret;
2608
2609 intel_runtime_pm_get(dev_priv);
2610 ret = i915_guc_log_control(dev_priv, val);
2611 intel_runtime_pm_put(dev_priv);
2612
Chris Wilsonbcc36d82017-04-07 20:42:20 +01002613 mutex_unlock(&dev_priv->drm.struct_mutex);
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05302614 return ret;
2615}
2616
2617DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_control_fops,
2618 i915_guc_log_control_get, i915_guc_log_control_set,
2619 "%lld\n");
2620
Chris Wilsonb86bef202017-01-16 13:06:21 +00002621static const char *psr2_live_status(u32 val)
2622{
2623 static const char * const live_status[] = {
2624 "IDLE",
2625 "CAPTURE",
2626 "CAPTURE_FS",
2627 "SLEEP",
2628 "BUFON_FW",
2629 "ML_UP",
2630 "SU_STANDBY",
2631 "FAST_SLEEP",
2632 "DEEP_SLEEP",
2633 "BUF_ON",
2634 "TG_ON"
2635 };
2636
2637 val = (val & EDP_PSR2_STATUS_STATE_MASK) >> EDP_PSR2_STATUS_STATE_SHIFT;
2638 if (val < ARRAY_SIZE(live_status))
2639 return live_status[val];
2640
2641 return "unknown";
2642}
2643
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002644static int i915_edp_psr_status(struct seq_file *m, void *data)
2645{
David Weinehall36cdd012016-08-22 13:59:31 +03002646 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002647 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002648 u32 stat[3];
2649 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002650 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002651
David Weinehall36cdd012016-08-22 13:59:31 +03002652 if (!HAS_PSR(dev_priv)) {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002653 seq_puts(m, "PSR not supported\n");
2654 return 0;
2655 }
2656
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002657 intel_runtime_pm_get(dev_priv);
2658
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002659 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002660 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2661 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002662 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002663 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002664 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2665 dev_priv->psr.busy_frontbuffer_bits);
2666 seq_printf(m, "Re-enable work scheduled: %s\n",
2667 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002668
Nagaraju, Vathsala7e3eb592016-12-09 23:42:09 +05302669 if (HAS_DDI(dev_priv)) {
2670 if (dev_priv->psr.psr2_support)
2671 enabled = I915_READ(EDP_PSR2_CTL) & EDP_PSR2_ENABLE;
2672 else
2673 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
2674 } else {
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002675 for_each_pipe(dev_priv, pipe) {
Chris Wilson9c870d02016-10-24 13:42:15 +01002676 enum transcoder cpu_transcoder =
2677 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
2678 enum intel_display_power_domain power_domain;
2679
2680 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
2681 if (!intel_display_power_get_if_enabled(dev_priv,
2682 power_domain))
2683 continue;
2684
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002685 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2686 VLV_EDP_PSR_CURR_STATE_MASK;
2687 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2688 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2689 enabled = true;
Chris Wilson9c870d02016-10-24 13:42:15 +01002690
2691 intel_display_power_put(dev_priv, power_domain);
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002692 }
2693 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002694
2695 seq_printf(m, "Main link in standby mode: %s\n",
2696 yesno(dev_priv->psr.link_standby));
2697
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002698 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002699
David Weinehall36cdd012016-08-22 13:59:31 +03002700 if (!HAS_DDI(dev_priv))
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002701 for_each_pipe(dev_priv, pipe) {
2702 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2703 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2704 seq_printf(m, " pipe %c", pipe_name(pipe));
2705 }
2706 seq_puts(m, "\n");
2707
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002708 /*
2709 * VLV/CHV PSR has no kind of performance counter
2710 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2711 */
David Weinehall36cdd012016-08-22 13:59:31 +03002712 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002713 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002714 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002715
2716 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2717 }
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302718 if (dev_priv->psr.psr2_support) {
Chris Wilsonb86bef202017-01-16 13:06:21 +00002719 u32 psr2 = I915_READ(EDP_PSR2_STATUS_CTL);
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302720
Chris Wilsonb86bef202017-01-16 13:06:21 +00002721 seq_printf(m, "EDP_PSR2_STATUS_CTL: %x [%s]\n",
2722 psr2, psr2_live_status(psr2));
Nagaraju, Vathsala6ba1f9e2017-01-06 22:02:32 +05302723 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002724 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002725
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002726 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002727 return 0;
2728}
2729
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002730static int i915_sink_crc(struct seq_file *m, void *data)
2731{
David Weinehall36cdd012016-08-22 13:59:31 +03002732 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2733 struct drm_device *dev = &dev_priv->drm;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002734 struct intel_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002735 struct drm_connector_list_iter conn_iter;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002736 struct intel_dp *intel_dp = NULL;
2737 int ret;
2738 u8 crc[6];
2739
2740 drm_modeset_lock_all(dev);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002741 drm_connector_list_iter_begin(dev, &conn_iter);
2742 for_each_intel_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002743 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002744
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002745 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002746 continue;
2747
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002748 crtc = connector->base.state->crtc;
2749 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002750 continue;
2751
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002752 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002753 continue;
2754
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002755 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002756
2757 ret = intel_dp_sink_crc(intel_dp, crc);
2758 if (ret)
2759 goto out;
2760
2761 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2762 crc[0], crc[1], crc[2],
2763 crc[3], crc[4], crc[5]);
2764 goto out;
2765 }
2766 ret = -ENODEV;
2767out:
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01002768 drm_connector_list_iter_end(&conn_iter);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002769 drm_modeset_unlock_all(dev);
2770 return ret;
2771}
2772
Jesse Barnesec013e72013-08-20 10:29:23 +01002773static int i915_energy_uJ(struct seq_file *m, void *data)
2774{
David Weinehall36cdd012016-08-22 13:59:31 +03002775 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002776 unsigned long long power;
Jesse Barnesec013e72013-08-20 10:29:23 +01002777 u32 units;
2778
David Weinehall36cdd012016-08-22 13:59:31 +03002779 if (INTEL_GEN(dev_priv) < 6)
Jesse Barnesec013e72013-08-20 10:29:23 +01002780 return -ENODEV;
2781
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002782 intel_runtime_pm_get(dev_priv);
2783
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002784 if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power)) {
2785 intel_runtime_pm_put(dev_priv);
2786 return -ENODEV;
2787 }
2788
2789 units = (power & 0x1f00) >> 8;
Jesse Barnesec013e72013-08-20 10:29:23 +01002790 power = I915_READ(MCH_SECP_NRG_STTS);
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002791 power = (1000000 * power) >> units; /* convert to uJ */
Jesse Barnesec013e72013-08-20 10:29:23 +01002792
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002793 intel_runtime_pm_put(dev_priv);
2794
Gabriel Krisman Bertazid38014e2017-07-26 02:30:16 -03002795 seq_printf(m, "%llu", power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002796
2797 return 0;
2798}
2799
Damien Lespiau6455c872015-06-04 18:23:57 +01002800static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002801{
David Weinehall36cdd012016-08-22 13:59:31 +03002802 struct drm_i915_private *dev_priv = node_to_i915(m->private);
David Weinehall52a05c32016-08-22 13:32:44 +03002803 struct pci_dev *pdev = dev_priv->drm.pdev;
Paulo Zanoni371db662013-08-19 13:18:10 -03002804
Chris Wilsona156e642016-04-03 14:14:21 +01002805 if (!HAS_RUNTIME_PM(dev_priv))
2806 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002807
Chris Wilson67d97da2016-07-04 08:08:31 +01002808 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
Paulo Zanoni371db662013-08-19 13:18:10 -03002809 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002810 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002811#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002812 seq_printf(m, "Usage count: %d\n",
David Weinehall36cdd012016-08-22 13:59:31 +03002813 atomic_read(&dev_priv->drm.dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002814#else
2815 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2816#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002817 seq_printf(m, "PCI device power state: %s [%d]\n",
David Weinehall52a05c32016-08-22 13:32:44 +03002818 pci_power_name(pdev->current_state),
2819 pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002820
Jesse Barnesec013e72013-08-20 10:29:23 +01002821 return 0;
2822}
2823
Imre Deak1da51582013-11-25 17:15:35 +02002824static int i915_power_domain_info(struct seq_file *m, void *unused)
2825{
David Weinehall36cdd012016-08-22 13:59:31 +03002826 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak1da51582013-11-25 17:15:35 +02002827 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2828 int i;
2829
2830 mutex_lock(&power_domains->lock);
2831
2832 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2833 for (i = 0; i < power_domains->power_well_count; i++) {
2834 struct i915_power_well *power_well;
2835 enum intel_display_power_domain power_domain;
2836
2837 power_well = &power_domains->power_wells[i];
2838 seq_printf(m, "%-25s %d\n", power_well->name,
2839 power_well->count);
2840
Joonas Lahtinen8385c2e2017-02-08 15:12:10 +02002841 for_each_power_domain(power_domain, power_well->domains)
Imre Deak1da51582013-11-25 17:15:35 +02002842 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002843 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002844 power_domains->domain_use_count[power_domain]);
Imre Deak1da51582013-11-25 17:15:35 +02002845 }
2846
2847 mutex_unlock(&power_domains->lock);
2848
2849 return 0;
2850}
2851
Damien Lespiaub7cec662015-10-27 14:47:01 +02002852static int i915_dmc_info(struct seq_file *m, void *unused)
2853{
David Weinehall36cdd012016-08-22 13:59:31 +03002854 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Damien Lespiaub7cec662015-10-27 14:47:01 +02002855 struct intel_csr *csr;
2856
David Weinehall36cdd012016-08-22 13:59:31 +03002857 if (!HAS_CSR(dev_priv)) {
Damien Lespiaub7cec662015-10-27 14:47:01 +02002858 seq_puts(m, "not supported\n");
2859 return 0;
2860 }
2861
2862 csr = &dev_priv->csr;
2863
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002864 intel_runtime_pm_get(dev_priv);
2865
Damien Lespiaub7cec662015-10-27 14:47:01 +02002866 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2867 seq_printf(m, "path: %s\n", csr->fw_path);
2868
2869 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002870 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002871
2872 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2873 CSR_VERSION_MINOR(csr->version));
2874
Mika Kuoppala48de5682017-05-09 13:05:22 +03002875 if (IS_KABYLAKE(dev_priv) ||
2876 (IS_SKYLAKE(dev_priv) && csr->version >= CSR_VERSION(1, 6))) {
Damien Lespiau83372062015-10-30 17:53:32 +02002877 seq_printf(m, "DC3 -> DC5 count: %d\n",
2878 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2879 seq_printf(m, "DC5 -> DC6 count: %d\n",
2880 I915_READ(SKL_CSR_DC5_DC6_COUNT));
David Weinehall36cdd012016-08-22 13:59:31 +03002881 } else if (IS_BROXTON(dev_priv) && csr->version >= CSR_VERSION(1, 4)) {
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002882 seq_printf(m, "DC3 -> DC5 count: %d\n",
2883 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002884 }
2885
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002886out:
2887 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2888 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2889 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2890
Damien Lespiau83372062015-10-30 17:53:32 +02002891 intel_runtime_pm_put(dev_priv);
2892
Damien Lespiaub7cec662015-10-27 14:47:01 +02002893 return 0;
2894}
2895
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002896static void intel_seq_print_mode(struct seq_file *m, int tabs,
2897 struct drm_display_mode *mode)
2898{
2899 int i;
2900
2901 for (i = 0; i < tabs; i++)
2902 seq_putc(m, '\t');
2903
2904 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",
2905 mode->base.id, mode->name,
2906 mode->vrefresh, mode->clock,
2907 mode->hdisplay, mode->hsync_start,
2908 mode->hsync_end, mode->htotal,
2909 mode->vdisplay, mode->vsync_start,
2910 mode->vsync_end, mode->vtotal,
2911 mode->type, mode->flags);
2912}
2913
2914static void intel_encoder_info(struct seq_file *m,
2915 struct intel_crtc *intel_crtc,
2916 struct intel_encoder *intel_encoder)
2917{
David Weinehall36cdd012016-08-22 13:59:31 +03002918 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2919 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002920 struct drm_crtc *crtc = &intel_crtc->base;
2921 struct intel_connector *intel_connector;
2922 struct drm_encoder *encoder;
2923
2924 encoder = &intel_encoder->base;
2925 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002926 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002927 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2928 struct drm_connector *connector = &intel_connector->base;
2929 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2930 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002931 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002932 drm_get_connector_status_name(connector->status));
2933 if (connector->status == connector_status_connected) {
2934 struct drm_display_mode *mode = &crtc->mode;
2935 seq_printf(m, ", mode:\n");
2936 intel_seq_print_mode(m, 2, mode);
2937 } else {
2938 seq_putc(m, '\n');
2939 }
2940 }
2941}
2942
2943static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2944{
David Weinehall36cdd012016-08-22 13:59:31 +03002945 struct drm_i915_private *dev_priv = node_to_i915(m->private);
2946 struct drm_device *dev = &dev_priv->drm;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002947 struct drm_crtc *crtc = &intel_crtc->base;
2948 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002949 struct drm_plane_state *plane_state = crtc->primary->state;
2950 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002951
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002952 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002953 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002954 fb->base.id, plane_state->src_x >> 16,
2955 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002956 else
2957 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002958 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2959 intel_encoder_info(m, intel_crtc, intel_encoder);
2960}
2961
2962static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2963{
2964 struct drm_display_mode *mode = panel->fixed_mode;
2965
2966 seq_printf(m, "\tfixed mode:\n");
2967 intel_seq_print_mode(m, 2, mode);
2968}
2969
2970static void intel_dp_info(struct seq_file *m,
2971 struct intel_connector *intel_connector)
2972{
2973 struct intel_encoder *intel_encoder = intel_connector->encoder;
2974 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2975
2976 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002977 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002978 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002979 intel_panel_info(m, &intel_connector->panel);
Mika Kahola80209e52016-09-09 14:10:57 +03002980
2981 drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
2982 &intel_dp->aux);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002983}
2984
Libin Yang9a148a92016-11-28 20:07:05 +08002985static void intel_dp_mst_info(struct seq_file *m,
2986 struct intel_connector *intel_connector)
2987{
2988 struct intel_encoder *intel_encoder = intel_connector->encoder;
2989 struct intel_dp_mst_encoder *intel_mst =
2990 enc_to_mst(&intel_encoder->base);
2991 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2992 struct intel_dp *intel_dp = &intel_dig_port->dp;
2993 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2994 intel_connector->port);
2995
2996 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2997}
2998
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002999static void intel_hdmi_info(struct seq_file *m,
3000 struct intel_connector *intel_connector)
3001{
3002 struct intel_encoder *intel_encoder = intel_connector->encoder;
3003 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
3004
Jani Nikula742f4912015-09-03 11:16:09 +03003005 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003006}
3007
3008static void intel_lvds_info(struct seq_file *m,
3009 struct intel_connector *intel_connector)
3010{
3011 intel_panel_info(m, &intel_connector->panel);
3012}
3013
3014static void intel_connector_info(struct seq_file *m,
3015 struct drm_connector *connector)
3016{
3017 struct intel_connector *intel_connector = to_intel_connector(connector);
3018 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08003019 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003020
3021 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03003022 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003023 drm_get_connector_status_name(connector->status));
3024 if (connector->status == connector_status_connected) {
3025 seq_printf(m, "\tname: %s\n", connector->display_info.name);
3026 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
3027 connector->display_info.width_mm,
3028 connector->display_info.height_mm);
3029 seq_printf(m, "\tsubpixel order: %s\n",
3030 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3031 seq_printf(m, "\tCEA rev: %d\n",
3032 connector->display_info.cea_rev);
3033 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003034
Maarten Lankhorst77d1f612017-06-26 10:33:49 +02003035 if (!intel_encoder)
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003036 return;
3037
3038 switch (connector->connector_type) {
3039 case DRM_MODE_CONNECTOR_DisplayPort:
3040 case DRM_MODE_CONNECTOR_eDP:
Libin Yang9a148a92016-11-28 20:07:05 +08003041 if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
3042 intel_dp_mst_info(m, intel_connector);
3043 else
3044 intel_dp_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003045 break;
3046 case DRM_MODE_CONNECTOR_LVDS:
3047 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003048 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003049 break;
3050 case DRM_MODE_CONNECTOR_HDMIA:
3051 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3052 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3053 intel_hdmi_info(m, intel_connector);
3054 break;
3055 default:
3056 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003057 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003058
Jesse Barnesf103fc72014-02-20 12:39:57 -08003059 seq_printf(m, "\tmodes:\n");
3060 list_for_each_entry(mode, &connector->modes, head)
3061 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003062}
3063
Robert Fekete3abc4e02015-10-27 16:58:32 +01003064static const char *plane_type(enum drm_plane_type type)
3065{
3066 switch (type) {
3067 case DRM_PLANE_TYPE_OVERLAY:
3068 return "OVL";
3069 case DRM_PLANE_TYPE_PRIMARY:
3070 return "PRI";
3071 case DRM_PLANE_TYPE_CURSOR:
3072 return "CUR";
3073 /*
3074 * Deliberately omitting default: to generate compiler warnings
3075 * when a new drm_plane_type gets added.
3076 */
3077 }
3078
3079 return "unknown";
3080}
3081
3082static const char *plane_rotation(unsigned int rotation)
3083{
3084 static char buf[48];
3085 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003086 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
Robert Fekete3abc4e02015-10-27 16:58:32 +01003087 * will print them all to visualize if the values are misused
3088 */
3089 snprintf(buf, sizeof(buf),
3090 "%s%s%s%s%s%s(0x%08x)",
Robert Fossc2c446a2017-05-19 16:50:17 -04003091 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
3092 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
3093 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
3094 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
3095 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
3096 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
Robert Fekete3abc4e02015-10-27 16:58:32 +01003097 rotation);
3098
3099 return buf;
3100}
3101
3102static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3103{
David Weinehall36cdd012016-08-22 13:59:31 +03003104 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3105 struct drm_device *dev = &dev_priv->drm;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003106 struct intel_plane *intel_plane;
3107
3108 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3109 struct drm_plane_state *state;
3110 struct drm_plane *plane = &intel_plane->base;
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003111 struct drm_format_name_buf format_name;
Robert Fekete3abc4e02015-10-27 16:58:32 +01003112
3113 if (!plane->state) {
3114 seq_puts(m, "plane->state is NULL!\n");
3115 continue;
3116 }
3117
3118 state = plane->state;
3119
Eric Engestrom90844f02016-08-15 01:02:38 +01003120 if (state->fb) {
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003121 drm_get_format_name(state->fb->format->format,
3122 &format_name);
Eric Engestrom90844f02016-08-15 01:02:38 +01003123 } else {
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003124 sprintf(format_name.str, "N/A");
Eric Engestrom90844f02016-08-15 01:02:38 +01003125 }
3126
Robert Fekete3abc4e02015-10-27 16:58:32 +01003127 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",
3128 plane->base.id,
3129 plane_type(intel_plane->base.type),
3130 state->crtc_x, state->crtc_y,
3131 state->crtc_w, state->crtc_h,
3132 (state->src_x >> 16),
3133 ((state->src_x & 0xffff) * 15625) >> 10,
3134 (state->src_y >> 16),
3135 ((state->src_y & 0xffff) * 15625) >> 10,
3136 (state->src_w >> 16),
3137 ((state->src_w & 0xffff) * 15625) >> 10,
3138 (state->src_h >> 16),
3139 ((state->src_h & 0xffff) * 15625) >> 10,
Eric Engestromb3c11ac2016-11-12 01:12:56 +00003140 format_name.str,
Robert Fekete3abc4e02015-10-27 16:58:32 +01003141 plane_rotation(state->rotation));
3142 }
3143}
3144
3145static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3146{
3147 struct intel_crtc_state *pipe_config;
3148 int num_scalers = intel_crtc->num_scalers;
3149 int i;
3150
3151 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3152
3153 /* Not all platformas have a scaler */
3154 if (num_scalers) {
3155 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3156 num_scalers,
3157 pipe_config->scaler_state.scaler_users,
3158 pipe_config->scaler_state.scaler_id);
3159
A.Sunil Kamath58415912016-11-20 23:20:26 +05303160 for (i = 0; i < num_scalers; i++) {
Robert Fekete3abc4e02015-10-27 16:58:32 +01003161 struct intel_scaler *sc =
3162 &pipe_config->scaler_state.scalers[i];
3163
3164 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3165 i, yesno(sc->in_use), sc->mode);
3166 }
3167 seq_puts(m, "\n");
3168 } else {
3169 seq_puts(m, "\tNo scalers available on this platform\n");
3170 }
3171}
3172
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003173static int i915_display_info(struct seq_file *m, void *unused)
3174{
David Weinehall36cdd012016-08-22 13:59:31 +03003175 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3176 struct drm_device *dev = &dev_priv->drm;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003177 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003178 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003179 struct drm_connector_list_iter conn_iter;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003180
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003181 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003182 seq_printf(m, "CRTC info\n");
3183 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003184 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003185 struct intel_crtc_state *pipe_config;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003186
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003187 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003188 pipe_config = to_intel_crtc_state(crtc->base.state);
3189
Robert Fekete3abc4e02015-10-27 16:58:32 +01003190 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003191 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003192 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003193 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3194 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3195
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003196 if (pipe_config->base.active) {
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003197 struct intel_plane *cursor =
3198 to_intel_plane(crtc->base.cursor);
3199
Chris Wilson065f2ec2014-03-12 09:13:13 +00003200 intel_crtc_info(m, crtc);
3201
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03003202 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x\n",
3203 yesno(cursor->base.state->visible),
3204 cursor->base.state->crtc_x,
3205 cursor->base.state->crtc_y,
3206 cursor->base.state->crtc_w,
3207 cursor->base.state->crtc_h,
3208 cursor->cursor.base);
Robert Fekete3abc4e02015-10-27 16:58:32 +01003209 intel_scaler_info(m, crtc);
3210 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003211 }
Daniel Vettercace8412014-05-22 17:56:31 +02003212
3213 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3214 yesno(!crtc->cpu_fifo_underrun_disabled),
3215 yesno(!crtc->pch_fifo_underrun_disabled));
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003216 drm_modeset_unlock(&crtc->base.mutex);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003217 }
3218
3219 seq_printf(m, "\n");
3220 seq_printf(m, "Connector info\n");
3221 seq_printf(m, "--------------\n");
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003222 mutex_lock(&dev->mode_config.mutex);
3223 drm_connector_list_iter_begin(dev, &conn_iter);
3224 drm_for_each_connector_iter(connector, &conn_iter)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003225 intel_connector_info(m, connector);
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003226 drm_connector_list_iter_end(&conn_iter);
3227 mutex_unlock(&dev->mode_config.mutex);
3228
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003229 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003230
3231 return 0;
3232}
3233
Chris Wilson1b365952016-10-04 21:11:31 +01003234static int i915_engine_info(struct seq_file *m, void *unused)
3235{
3236 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3237 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05303238 enum intel_engine_id id;
Chris Wilsonf636edb2017-10-09 12:02:57 +01003239 struct drm_printer p;
Chris Wilson1b365952016-10-04 21:11:31 +01003240
Chris Wilson9c870d02016-10-24 13:42:15 +01003241 intel_runtime_pm_get(dev_priv);
3242
Chris Wilsonf73b5672017-03-02 15:03:56 +00003243 seq_printf(m, "GT awake? %s\n",
3244 yesno(dev_priv->gt.awake));
3245 seq_printf(m, "Global active requests: %d\n",
3246 dev_priv->gt.active_requests);
3247
Chris Wilsonf636edb2017-10-09 12:02:57 +01003248 p = drm_seq_file_printer(m);
3249 for_each_engine(engine, dev_priv, id)
3250 intel_engine_dump(engine, &p);
Chris Wilson1b365952016-10-04 21:11:31 +01003251
Chris Wilson9c870d02016-10-24 13:42:15 +01003252 intel_runtime_pm_put(dev_priv);
3253
Chris Wilson1b365952016-10-04 21:11:31 +01003254 return 0;
3255}
3256
Chris Wilsonc5418a82017-10-13 21:26:19 +01003257static int i915_shrinker_info(struct seq_file *m, void *unused)
3258{
3259 struct drm_i915_private *i915 = node_to_i915(m->private);
3260
3261 seq_printf(m, "seeks = %d\n", i915->mm.shrinker.seeks);
3262 seq_printf(m, "batch = %lu\n", i915->mm.shrinker.batch);
3263
3264 return 0;
3265}
3266
Ben Widawskye04934c2014-06-30 09:53:42 -07003267static int i915_semaphore_status(struct seq_file *m, void *unused)
3268{
David Weinehall36cdd012016-08-22 13:59:31 +03003269 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3270 struct drm_device *dev = &dev_priv->drm;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003271 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003272 int num_rings = INTEL_INFO(dev_priv)->num_rings;
Dave Gordonc3232b12016-03-23 18:19:53 +00003273 enum intel_engine_id id;
3274 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003275
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003276 if (!i915_modparams.semaphores) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003277 seq_puts(m, "Semaphores are disabled\n");
3278 return 0;
3279 }
3280
3281 ret = mutex_lock_interruptible(&dev->struct_mutex);
3282 if (ret)
3283 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003284 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003285
David Weinehall36cdd012016-08-22 13:59:31 +03003286 if (IS_BROADWELL(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003287 struct page *page;
3288 uint64_t *seqno;
3289
Chris Wilson51d545d2016-08-15 10:49:02 +01003290 page = i915_gem_object_get_page(dev_priv->semaphore->obj, 0);
Ben Widawskye04934c2014-06-30 09:53:42 -07003291
3292 seqno = (uint64_t *)kmap_atomic(page);
Akash Goel3b3f1652016-10-13 22:44:48 +05303293 for_each_engine(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003294 uint64_t offset;
3295
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003296 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003297
3298 seq_puts(m, " Last signal:");
3299 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003300 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003301 seq_printf(m, "0x%08llx (0x%02llx) ",
3302 seqno[offset], offset * 8);
3303 }
3304 seq_putc(m, '\n');
3305
3306 seq_puts(m, " Last wait: ");
3307 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003308 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003309 seq_printf(m, "0x%08llx (0x%02llx) ",
3310 seqno[offset], offset * 8);
3311 }
3312 seq_putc(m, '\n');
3313
3314 }
3315 kunmap_atomic(seqno);
3316 } else {
3317 seq_puts(m, " Last signal:");
Akash Goel3b3f1652016-10-13 22:44:48 +05303318 for_each_engine(engine, dev_priv, id)
Ben Widawskye04934c2014-06-30 09:53:42 -07003319 for (j = 0; j < num_rings; j++)
3320 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003321 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003322 seq_putc(m, '\n');
3323 }
3324
Paulo Zanoni03872062014-07-09 14:31:57 -03003325 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003326 mutex_unlock(&dev->struct_mutex);
3327 return 0;
3328}
3329
Daniel Vetter728e29d2014-06-25 22:01:53 +03003330static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3331{
David Weinehall36cdd012016-08-22 13:59:31 +03003332 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3333 struct drm_device *dev = &dev_priv->drm;
Daniel Vetter728e29d2014-06-25 22:01:53 +03003334 int i;
3335
3336 drm_modeset_lock_all(dev);
3337 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3338 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3339
3340 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003341 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003342 pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003343 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003344 seq_printf(m, " dpll: 0x%08x\n", pll->state.hw_state.dpll);
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003345 seq_printf(m, " dpll_md: 0x%08x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +02003346 pll->state.hw_state.dpll_md);
3347 seq_printf(m, " fp0: 0x%08x\n", pll->state.hw_state.fp0);
3348 seq_printf(m, " fp1: 0x%08x\n", pll->state.hw_state.fp1);
3349 seq_printf(m, " wrpll: 0x%08x\n", pll->state.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003350 }
3351 drm_modeset_unlock_all(dev);
3352
3353 return 0;
3354}
3355
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003356static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003357{
3358 int i;
3359 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003360 struct intel_engine_cs *engine;
David Weinehall36cdd012016-08-22 13:59:31 +03003361 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3362 struct drm_device *dev = &dev_priv->drm;
Arun Siluvery33136b02016-01-21 21:43:47 +00003363 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003364 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003365
Arun Siluvery888b5992014-08-26 14:44:51 +01003366 ret = mutex_lock_interruptible(&dev->struct_mutex);
3367 if (ret)
3368 return ret;
3369
3370 intel_runtime_pm_get(dev_priv);
3371
Arun Siluvery33136b02016-01-21 21:43:47 +00003372 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Akash Goel3b3f1652016-10-13 22:44:48 +05303373 for_each_engine(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003374 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003375 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003376 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003377 i915_reg_t addr;
3378 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003379 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003380
Arun Siluvery33136b02016-01-21 21:43:47 +00003381 addr = workarounds->reg[i].addr;
3382 mask = workarounds->reg[i].mask;
3383 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003384 read = I915_READ(addr);
3385 ok = (value & mask) == (read & mask);
3386 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 +02003387 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003388 }
3389
3390 intel_runtime_pm_put(dev_priv);
3391 mutex_unlock(&dev->struct_mutex);
3392
3393 return 0;
3394}
3395
Kumar, Maheshd2d4f392017-08-17 19:15:29 +05303396static int i915_ipc_status_show(struct seq_file *m, void *data)
3397{
3398 struct drm_i915_private *dev_priv = m->private;
3399
3400 seq_printf(m, "Isochronous Priority Control: %s\n",
3401 yesno(dev_priv->ipc_enabled));
3402 return 0;
3403}
3404
3405static int i915_ipc_status_open(struct inode *inode, struct file *file)
3406{
3407 struct drm_i915_private *dev_priv = inode->i_private;
3408
3409 if (!HAS_IPC(dev_priv))
3410 return -ENODEV;
3411
3412 return single_open(file, i915_ipc_status_show, dev_priv);
3413}
3414
3415static ssize_t i915_ipc_status_write(struct file *file, const char __user *ubuf,
3416 size_t len, loff_t *offp)
3417{
3418 struct seq_file *m = file->private_data;
3419 struct drm_i915_private *dev_priv = m->private;
3420 int ret;
3421 bool enable;
3422
3423 ret = kstrtobool_from_user(ubuf, len, &enable);
3424 if (ret < 0)
3425 return ret;
3426
3427 intel_runtime_pm_get(dev_priv);
3428 if (!dev_priv->ipc_enabled && enable)
3429 DRM_INFO("Enabling IPC: WM will be proper only after next commit\n");
3430 dev_priv->wm.distrust_bios_wm = true;
3431 dev_priv->ipc_enabled = enable;
3432 intel_enable_ipc(dev_priv);
3433 intel_runtime_pm_put(dev_priv);
3434
3435 return len;
3436}
3437
3438static const struct file_operations i915_ipc_status_fops = {
3439 .owner = THIS_MODULE,
3440 .open = i915_ipc_status_open,
3441 .read = seq_read,
3442 .llseek = seq_lseek,
3443 .release = single_release,
3444 .write = i915_ipc_status_write
3445};
3446
Damien Lespiauc5511e42014-11-04 17:06:51 +00003447static int i915_ddb_info(struct seq_file *m, void *unused)
3448{
David Weinehall36cdd012016-08-22 13:59:31 +03003449 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3450 struct drm_device *dev = &dev_priv->drm;
Damien Lespiauc5511e42014-11-04 17:06:51 +00003451 struct skl_ddb_allocation *ddb;
3452 struct skl_ddb_entry *entry;
3453 enum pipe pipe;
3454 int plane;
3455
David Weinehall36cdd012016-08-22 13:59:31 +03003456 if (INTEL_GEN(dev_priv) < 9)
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003457 return 0;
3458
Damien Lespiauc5511e42014-11-04 17:06:51 +00003459 drm_modeset_lock_all(dev);
3460
3461 ddb = &dev_priv->wm.skl_hw.ddb;
3462
3463 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3464
3465 for_each_pipe(dev_priv, pipe) {
3466 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3467
Matt Roper8b364b42016-10-26 15:51:28 -07003468 for_each_universal_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003469 entry = &ddb->plane[pipe][plane];
3470 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3471 entry->start, entry->end,
3472 skl_ddb_entry_size(entry));
3473 }
3474
Matt Roper4969d332015-09-24 15:53:10 -07003475 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003476 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3477 entry->end, skl_ddb_entry_size(entry));
3478 }
3479
3480 drm_modeset_unlock_all(dev);
3481
3482 return 0;
3483}
3484
Vandana Kannana54746e2015-03-03 20:53:10 +05303485static void drrs_status_per_crtc(struct seq_file *m,
David Weinehall36cdd012016-08-22 13:59:31 +03003486 struct drm_device *dev,
3487 struct intel_crtc *intel_crtc)
Vandana Kannana54746e2015-03-03 20:53:10 +05303488{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003489 struct drm_i915_private *dev_priv = to_i915(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303490 struct i915_drrs *drrs = &dev_priv->drrs;
3491 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003492 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003493 struct drm_connector_list_iter conn_iter;
Vandana Kannana54746e2015-03-03 20:53:10 +05303494
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003495 drm_connector_list_iter_begin(dev, &conn_iter);
3496 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003497 if (connector->state->crtc != &intel_crtc->base)
3498 continue;
3499
3500 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303501 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003502 drm_connector_list_iter_end(&conn_iter);
Vandana Kannana54746e2015-03-03 20:53:10 +05303503
3504 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3505 seq_puts(m, "\tVBT: DRRS_type: Static");
3506 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3507 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3508 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3509 seq_puts(m, "\tVBT: DRRS_type: None");
3510 else
3511 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3512
3513 seq_puts(m, "\n\n");
3514
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003515 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303516 struct intel_panel *panel;
3517
3518 mutex_lock(&drrs->mutex);
3519 /* DRRS Supported */
3520 seq_puts(m, "\tDRRS Supported: Yes\n");
3521
3522 /* disable_drrs() will make drrs->dp NULL */
3523 if (!drrs->dp) {
3524 seq_puts(m, "Idleness DRRS: Disabled");
3525 mutex_unlock(&drrs->mutex);
3526 return;
3527 }
3528
3529 panel = &drrs->dp->attached_connector->panel;
3530 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3531 drrs->busy_frontbuffer_bits);
3532
3533 seq_puts(m, "\n\t\t");
3534 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3535 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3536 vrefresh = panel->fixed_mode->vrefresh;
3537 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3538 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3539 vrefresh = panel->downclock_mode->vrefresh;
3540 } else {
3541 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3542 drrs->refresh_rate_type);
3543 mutex_unlock(&drrs->mutex);
3544 return;
3545 }
3546 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3547
3548 seq_puts(m, "\n\t\t");
3549 mutex_unlock(&drrs->mutex);
3550 } else {
3551 /* DRRS not supported. Print the VBT parameter*/
3552 seq_puts(m, "\tDRRS Supported : No");
3553 }
3554 seq_puts(m, "\n");
3555}
3556
3557static int i915_drrs_status(struct seq_file *m, void *unused)
3558{
David Weinehall36cdd012016-08-22 13:59:31 +03003559 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3560 struct drm_device *dev = &dev_priv->drm;
Vandana Kannana54746e2015-03-03 20:53:10 +05303561 struct intel_crtc *intel_crtc;
3562 int active_crtc_cnt = 0;
3563
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003564 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303565 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003566 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303567 active_crtc_cnt++;
3568 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3569
3570 drrs_status_per_crtc(m, dev, intel_crtc);
3571 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303572 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003573 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303574
3575 if (!active_crtc_cnt)
3576 seq_puts(m, "No active crtc found\n");
3577
3578 return 0;
3579}
3580
Dave Airlie11bed952014-05-12 15:22:27 +10003581static int i915_dp_mst_info(struct seq_file *m, void *unused)
3582{
David Weinehall36cdd012016-08-22 13:59:31 +03003583 struct drm_i915_private *dev_priv = node_to_i915(m->private);
3584 struct drm_device *dev = &dev_priv->drm;
Dave Airlie11bed952014-05-12 15:22:27 +10003585 struct intel_encoder *intel_encoder;
3586 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003587 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003588 struct drm_connector_list_iter conn_iter;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003589
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003590 drm_connector_list_iter_begin(dev, &conn_iter);
3591 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003592 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003593 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003594
3595 intel_encoder = intel_attached_encoder(connector);
3596 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3597 continue;
3598
3599 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003600 if (!intel_dig_port->dp.can_mst)
3601 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003602
Jim Bride40ae80c2016-04-14 10:18:37 -07003603 seq_printf(m, "MST Source Port %c\n",
3604 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003605 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3606 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003607 drm_connector_list_iter_end(&conn_iter);
3608
Dave Airlie11bed952014-05-12 15:22:27 +10003609 return 0;
3610}
3611
Todd Previteeb3394fa2015-04-18 00:04:19 -07003612static ssize_t i915_displayport_test_active_write(struct file *file,
David Weinehall36cdd012016-08-22 13:59:31 +03003613 const char __user *ubuf,
3614 size_t len, loff_t *offp)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003615{
3616 char *input_buffer;
3617 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003618 struct drm_device *dev;
3619 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003620 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003621 struct intel_dp *intel_dp;
3622 int val = 0;
3623
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05303624 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003625
Todd Previteeb3394fa2015-04-18 00:04:19 -07003626 if (len == 0)
3627 return 0;
3628
Geliang Tang261aeba2017-05-06 23:40:17 +08003629 input_buffer = memdup_user_nul(ubuf, len);
3630 if (IS_ERR(input_buffer))
3631 return PTR_ERR(input_buffer);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003632
Todd Previteeb3394fa2015-04-18 00:04:19 -07003633 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
3634
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003635 drm_connector_list_iter_begin(dev, &conn_iter);
3636 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003637 struct intel_encoder *encoder;
3638
Todd Previteeb3394fa2015-04-18 00:04:19 -07003639 if (connector->connector_type !=
3640 DRM_MODE_CONNECTOR_DisplayPort)
3641 continue;
3642
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003643 encoder = to_intel_encoder(connector->encoder);
3644 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3645 continue;
3646
3647 if (encoder && connector->status == connector_status_connected) {
3648 intel_dp = enc_to_intel_dp(&encoder->base);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003649 status = kstrtoint(input_buffer, 10, &val);
3650 if (status < 0)
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003651 break;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003652 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
3653 /* To prevent erroneous activation of the compliance
3654 * testing code, only accept an actual value of 1 here
3655 */
3656 if (val == 1)
Manasi Navarec1617ab2016-12-09 16:22:50 -08003657 intel_dp->compliance.test_active = 1;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003658 else
Manasi Navarec1617ab2016-12-09 16:22:50 -08003659 intel_dp->compliance.test_active = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003660 }
3661 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003662 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003663 kfree(input_buffer);
3664 if (status < 0)
3665 return status;
3666
3667 *offp += len;
3668 return len;
3669}
3670
3671static int i915_displayport_test_active_show(struct seq_file *m, void *data)
3672{
3673 struct drm_device *dev = m->private;
3674 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003675 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003676 struct intel_dp *intel_dp;
3677
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003678 drm_connector_list_iter_begin(dev, &conn_iter);
3679 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003680 struct intel_encoder *encoder;
3681
Todd Previteeb3394fa2015-04-18 00:04:19 -07003682 if (connector->connector_type !=
3683 DRM_MODE_CONNECTOR_DisplayPort)
3684 continue;
3685
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003686 encoder = to_intel_encoder(connector->encoder);
3687 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3688 continue;
3689
3690 if (encoder && connector->status == connector_status_connected) {
3691 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003692 if (intel_dp->compliance.test_active)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003693 seq_puts(m, "1");
3694 else
3695 seq_puts(m, "0");
3696 } else
3697 seq_puts(m, "0");
3698 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003699 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003700
3701 return 0;
3702}
3703
3704static int i915_displayport_test_active_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003705 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003706{
David Weinehall36cdd012016-08-22 13:59:31 +03003707 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003708
David Weinehall36cdd012016-08-22 13:59:31 +03003709 return single_open(file, i915_displayport_test_active_show,
3710 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003711}
3712
3713static const struct file_operations i915_displayport_test_active_fops = {
3714 .owner = THIS_MODULE,
3715 .open = i915_displayport_test_active_open,
3716 .read = seq_read,
3717 .llseek = seq_lseek,
3718 .release = single_release,
3719 .write = i915_displayport_test_active_write
3720};
3721
3722static int i915_displayport_test_data_show(struct seq_file *m, void *data)
3723{
3724 struct drm_device *dev = m->private;
3725 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003726 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003727 struct intel_dp *intel_dp;
3728
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003729 drm_connector_list_iter_begin(dev, &conn_iter);
3730 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003731 struct intel_encoder *encoder;
3732
Todd Previteeb3394fa2015-04-18 00:04:19 -07003733 if (connector->connector_type !=
3734 DRM_MODE_CONNECTOR_DisplayPort)
3735 continue;
3736
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003737 encoder = to_intel_encoder(connector->encoder);
3738 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3739 continue;
3740
3741 if (encoder && connector->status == connector_status_connected) {
3742 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navareb48a5ba2017-01-20 19:09:28 -08003743 if (intel_dp->compliance.test_type ==
3744 DP_TEST_LINK_EDID_READ)
3745 seq_printf(m, "%lx",
3746 intel_dp->compliance.test_data.edid);
Manasi Navare611032b2017-01-24 08:21:49 -08003747 else if (intel_dp->compliance.test_type ==
3748 DP_TEST_LINK_VIDEO_PATTERN) {
3749 seq_printf(m, "hdisplay: %d\n",
3750 intel_dp->compliance.test_data.hdisplay);
3751 seq_printf(m, "vdisplay: %d\n",
3752 intel_dp->compliance.test_data.vdisplay);
3753 seq_printf(m, "bpc: %u\n",
3754 intel_dp->compliance.test_data.bpc);
3755 }
Todd Previteeb3394fa2015-04-18 00:04:19 -07003756 } else
3757 seq_puts(m, "0");
3758 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003759 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003760
3761 return 0;
3762}
3763static int i915_displayport_test_data_open(struct inode *inode,
David Weinehall36cdd012016-08-22 13:59:31 +03003764 struct file *file)
Todd Previteeb3394fa2015-04-18 00:04:19 -07003765{
David Weinehall36cdd012016-08-22 13:59:31 +03003766 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003767
David Weinehall36cdd012016-08-22 13:59:31 +03003768 return single_open(file, i915_displayport_test_data_show,
3769 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003770}
3771
3772static const struct file_operations i915_displayport_test_data_fops = {
3773 .owner = THIS_MODULE,
3774 .open = i915_displayport_test_data_open,
3775 .read = seq_read,
3776 .llseek = seq_lseek,
3777 .release = single_release
3778};
3779
3780static int i915_displayport_test_type_show(struct seq_file *m, void *data)
3781{
3782 struct drm_device *dev = m->private;
3783 struct drm_connector *connector;
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003784 struct drm_connector_list_iter conn_iter;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003785 struct intel_dp *intel_dp;
3786
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003787 drm_connector_list_iter_begin(dev, &conn_iter);
3788 drm_for_each_connector_iter(connector, &conn_iter) {
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003789 struct intel_encoder *encoder;
3790
Todd Previteeb3394fa2015-04-18 00:04:19 -07003791 if (connector->connector_type !=
3792 DRM_MODE_CONNECTOR_DisplayPort)
3793 continue;
3794
Maarten Lankhorsta874b6a2017-06-26 10:18:35 +02003795 encoder = to_intel_encoder(connector->encoder);
3796 if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
3797 continue;
3798
3799 if (encoder && connector->status == connector_status_connected) {
3800 intel_dp = enc_to_intel_dp(&encoder->base);
Manasi Navarec1617ab2016-12-09 16:22:50 -08003801 seq_printf(m, "%02lx", intel_dp->compliance.test_type);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003802 } else
3803 seq_puts(m, "0");
3804 }
Daniel Vetter3f6a5e12017-03-01 10:52:21 +01003805 drm_connector_list_iter_end(&conn_iter);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003806
3807 return 0;
3808}
3809
3810static int i915_displayport_test_type_open(struct inode *inode,
3811 struct file *file)
3812{
David Weinehall36cdd012016-08-22 13:59:31 +03003813 struct drm_i915_private *dev_priv = inode->i_private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07003814
David Weinehall36cdd012016-08-22 13:59:31 +03003815 return single_open(file, i915_displayport_test_type_show,
3816 &dev_priv->drm);
Todd Previteeb3394fa2015-04-18 00:04:19 -07003817}
3818
3819static const struct file_operations i915_displayport_test_type_fops = {
3820 .owner = THIS_MODULE,
3821 .open = i915_displayport_test_type_open,
3822 .read = seq_read,
3823 .llseek = seq_lseek,
3824 .release = single_release
3825};
3826
Damien Lespiau97e94b22014-11-04 17:06:50 +00003827static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003828{
David Weinehall36cdd012016-08-22 13:59:31 +03003829 struct drm_i915_private *dev_priv = m->private;
3830 struct drm_device *dev = &dev_priv->drm;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003831 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003832 int num_levels;
3833
David Weinehall36cdd012016-08-22 13:59:31 +03003834 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003835 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003836 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003837 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003838 else if (IS_G4X(dev_priv))
3839 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003840 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003841 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003842
3843 drm_modeset_lock_all(dev);
3844
3845 for (level = 0; level < num_levels; level++) {
3846 unsigned int latency = wm[level];
3847
Damien Lespiau97e94b22014-11-04 17:06:50 +00003848 /*
3849 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03003850 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00003851 */
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003852 if (INTEL_GEN(dev_priv) >= 9 ||
3853 IS_VALLEYVIEW(dev_priv) ||
3854 IS_CHERRYVIEW(dev_priv) ||
3855 IS_G4X(dev_priv))
Damien Lespiau97e94b22014-11-04 17:06:50 +00003856 latency *= 10;
3857 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003858 latency *= 5;
3859
3860 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003861 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003862 }
3863
3864 drm_modeset_unlock_all(dev);
3865}
3866
3867static int pri_wm_latency_show(struct seq_file *m, void *data)
3868{
David Weinehall36cdd012016-08-22 13:59:31 +03003869 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003870 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003871
David Weinehall36cdd012016-08-22 13:59:31 +03003872 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003873 latencies = dev_priv->wm.skl_latency;
3874 else
David Weinehall36cdd012016-08-22 13:59:31 +03003875 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003876
3877 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003878
3879 return 0;
3880}
3881
3882static int spr_wm_latency_show(struct seq_file *m, void *data)
3883{
David Weinehall36cdd012016-08-22 13:59:31 +03003884 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003885 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003886
David Weinehall36cdd012016-08-22 13:59:31 +03003887 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003888 latencies = dev_priv->wm.skl_latency;
3889 else
David Weinehall36cdd012016-08-22 13:59:31 +03003890 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003891
3892 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003893
3894 return 0;
3895}
3896
3897static int cur_wm_latency_show(struct seq_file *m, void *data)
3898{
David Weinehall36cdd012016-08-22 13:59:31 +03003899 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003900 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003901
David Weinehall36cdd012016-08-22 13:59:31 +03003902 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003903 latencies = dev_priv->wm.skl_latency;
3904 else
David Weinehall36cdd012016-08-22 13:59:31 +03003905 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003906
3907 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003908
3909 return 0;
3910}
3911
3912static int pri_wm_latency_open(struct inode *inode, struct file *file)
3913{
David Weinehall36cdd012016-08-22 13:59:31 +03003914 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003915
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003916 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003917 return -ENODEV;
3918
David Weinehall36cdd012016-08-22 13:59:31 +03003919 return single_open(file, pri_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003920}
3921
3922static int spr_wm_latency_open(struct inode *inode, struct file *file)
3923{
David Weinehall36cdd012016-08-22 13:59:31 +03003924 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003925
David Weinehall36cdd012016-08-22 13:59:31 +03003926 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003927 return -ENODEV;
3928
David Weinehall36cdd012016-08-22 13:59:31 +03003929 return single_open(file, spr_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003930}
3931
3932static int cur_wm_latency_open(struct inode *inode, struct file *file)
3933{
David Weinehall36cdd012016-08-22 13:59:31 +03003934 struct drm_i915_private *dev_priv = inode->i_private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003935
David Weinehall36cdd012016-08-22 13:59:31 +03003936 if (HAS_GMCH_DISPLAY(dev_priv))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003937 return -ENODEV;
3938
David Weinehall36cdd012016-08-22 13:59:31 +03003939 return single_open(file, cur_wm_latency_show, dev_priv);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003940}
3941
3942static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003943 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003944{
3945 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003946 struct drm_i915_private *dev_priv = m->private;
3947 struct drm_device *dev = &dev_priv->drm;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003948 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03003949 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003950 int level;
3951 int ret;
3952 char tmp[32];
3953
David Weinehall36cdd012016-08-22 13:59:31 +03003954 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003955 num_levels = 3;
David Weinehall36cdd012016-08-22 13:59:31 +03003956 else if (IS_VALLEYVIEW(dev_priv))
Ville Syrjäläde38b952015-06-24 22:00:09 +03003957 num_levels = 1;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03003958 else if (IS_G4X(dev_priv))
3959 num_levels = 3;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003960 else
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003961 num_levels = ilk_wm_max_level(dev_priv) + 1;
Ville Syrjäläde38b952015-06-24 22:00:09 +03003962
Ville Syrjälä369a1342014-01-22 14:36:08 +02003963 if (len >= sizeof(tmp))
3964 return -EINVAL;
3965
3966 if (copy_from_user(tmp, ubuf, len))
3967 return -EFAULT;
3968
3969 tmp[len] = '\0';
3970
Damien Lespiau97e94b22014-11-04 17:06:50 +00003971 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3972 &new[0], &new[1], &new[2], &new[3],
3973 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003974 if (ret != num_levels)
3975 return -EINVAL;
3976
3977 drm_modeset_lock_all(dev);
3978
3979 for (level = 0; level < num_levels; level++)
3980 wm[level] = new[level];
3981
3982 drm_modeset_unlock_all(dev);
3983
3984 return len;
3985}
3986
3987
3988static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3989 size_t len, loff_t *offp)
3990{
3991 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03003992 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003993 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003994
David Weinehall36cdd012016-08-22 13:59:31 +03003995 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00003996 latencies = dev_priv->wm.skl_latency;
3997 else
David Weinehall36cdd012016-08-22 13:59:31 +03003998 latencies = dev_priv->wm.pri_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003999
4000 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004001}
4002
4003static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4004 size_t len, loff_t *offp)
4005{
4006 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004007 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004008 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004009
David Weinehall36cdd012016-08-22 13:59:31 +03004010 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004011 latencies = dev_priv->wm.skl_latency;
4012 else
David Weinehall36cdd012016-08-22 13:59:31 +03004013 latencies = dev_priv->wm.spr_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004014
4015 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004016}
4017
4018static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4019 size_t len, loff_t *offp)
4020{
4021 struct seq_file *m = file->private_data;
David Weinehall36cdd012016-08-22 13:59:31 +03004022 struct drm_i915_private *dev_priv = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004023 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004024
David Weinehall36cdd012016-08-22 13:59:31 +03004025 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau97e94b22014-11-04 17:06:50 +00004026 latencies = dev_priv->wm.skl_latency;
4027 else
David Weinehall36cdd012016-08-22 13:59:31 +03004028 latencies = dev_priv->wm.cur_latency;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004029
4030 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004031}
4032
4033static const struct file_operations i915_pri_wm_latency_fops = {
4034 .owner = THIS_MODULE,
4035 .open = pri_wm_latency_open,
4036 .read = seq_read,
4037 .llseek = seq_lseek,
4038 .release = single_release,
4039 .write = pri_wm_latency_write
4040};
4041
4042static const struct file_operations i915_spr_wm_latency_fops = {
4043 .owner = THIS_MODULE,
4044 .open = spr_wm_latency_open,
4045 .read = seq_read,
4046 .llseek = seq_lseek,
4047 .release = single_release,
4048 .write = spr_wm_latency_write
4049};
4050
4051static const struct file_operations i915_cur_wm_latency_fops = {
4052 .owner = THIS_MODULE,
4053 .open = cur_wm_latency_open,
4054 .read = seq_read,
4055 .llseek = seq_lseek,
4056 .release = single_release,
4057 .write = cur_wm_latency_write
4058};
4059
Kees Cook647416f2013-03-10 14:10:06 -07004060static int
4061i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004062{
David Weinehall36cdd012016-08-22 13:59:31 +03004063 struct drm_i915_private *dev_priv = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004064
Chris Wilsond98c52c2016-04-13 17:35:05 +01004065 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004066
Kees Cook647416f2013-03-10 14:10:06 -07004067 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004068}
4069
Kees Cook647416f2013-03-10 14:10:06 -07004070static int
4071i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004072{
Chris Wilson598b6b52017-03-25 13:47:35 +00004073 struct drm_i915_private *i915 = data;
4074 struct intel_engine_cs *engine;
4075 unsigned int tmp;
Imre Deakd46c0512014-04-14 20:24:27 +03004076
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004077 /*
4078 * There is no safeguard against this debugfs entry colliding
4079 * with the hangcheck calling same i915_handle_error() in
4080 * parallel, causing an explosion. For now we assume that the
4081 * test harness is responsible enough not to inject gpu hangs
4082 * while it is writing to 'i915_wedged'
4083 */
4084
Chris Wilson598b6b52017-03-25 13:47:35 +00004085 if (i915_reset_backoff(&i915->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004086 return -EAGAIN;
4087
Chris Wilson598b6b52017-03-25 13:47:35 +00004088 for_each_engine_masked(engine, i915, val, tmp) {
4089 engine->hangcheck.seqno = intel_engine_get_seqno(engine);
4090 engine->hangcheck.stalled = true;
4091 }
Imre Deakd46c0512014-04-14 20:24:27 +03004092
Chris Wilson598b6b52017-03-25 13:47:35 +00004093 i915_handle_error(i915, val, "Manually setting wedged to %llu", val);
4094
4095 wait_on_bit(&i915->gpu_error.flags,
Chris Wilsond3df42b2017-03-16 17:13:05 +00004096 I915_RESET_HANDOFF,
4097 TASK_UNINTERRUPTIBLE);
4098
Kees Cook647416f2013-03-10 14:10:06 -07004099 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004100}
4101
Kees Cook647416f2013-03-10 14:10:06 -07004102DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4103 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004104 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004105
Kees Cook647416f2013-03-10 14:10:06 -07004106static int
Chris Wilson64486ae2017-03-07 15:59:08 +00004107fault_irq_set(struct drm_i915_private *i915,
4108 unsigned long *irq,
4109 unsigned long val)
4110{
4111 int err;
4112
4113 err = mutex_lock_interruptible(&i915->drm.struct_mutex);
4114 if (err)
4115 return err;
4116
4117 err = i915_gem_wait_for_idle(i915,
4118 I915_WAIT_LOCKED |
4119 I915_WAIT_INTERRUPTIBLE);
4120 if (err)
4121 goto err_unlock;
4122
Chris Wilson64486ae2017-03-07 15:59:08 +00004123 *irq = val;
4124 mutex_unlock(&i915->drm.struct_mutex);
4125
4126 /* Flush idle worker to disarm irq */
Chris Wilson7c262402017-10-06 11:40:38 +01004127 drain_delayed_work(&i915->gt.idle_work);
Chris Wilson64486ae2017-03-07 15:59:08 +00004128
4129 return 0;
4130
4131err_unlock:
4132 mutex_unlock(&i915->drm.struct_mutex);
4133 return err;
4134}
4135
4136static int
Chris Wilson094f9a52013-09-25 17:34:55 +01004137i915_ring_missed_irq_get(void *data, u64 *val)
4138{
David Weinehall36cdd012016-08-22 13:59:31 +03004139 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004140
4141 *val = dev_priv->gpu_error.missed_irq_rings;
4142 return 0;
4143}
4144
4145static int
4146i915_ring_missed_irq_set(void *data, u64 val)
4147{
Chris Wilson64486ae2017-03-07 15:59:08 +00004148 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004149
Chris Wilson64486ae2017-03-07 15:59:08 +00004150 return fault_irq_set(i915, &i915->gpu_error.missed_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004151}
4152
4153DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4154 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4155 "0x%08llx\n");
4156
4157static int
4158i915_ring_test_irq_get(void *data, u64 *val)
4159{
David Weinehall36cdd012016-08-22 13:59:31 +03004160 struct drm_i915_private *dev_priv = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004161
4162 *val = dev_priv->gpu_error.test_irq_rings;
4163
4164 return 0;
4165}
4166
4167static int
4168i915_ring_test_irq_set(void *data, u64 val)
4169{
Chris Wilson64486ae2017-03-07 15:59:08 +00004170 struct drm_i915_private *i915 = data;
Chris Wilson094f9a52013-09-25 17:34:55 +01004171
Chris Wilson64486ae2017-03-07 15:59:08 +00004172 val &= INTEL_INFO(i915)->ring_mask;
Chris Wilson094f9a52013-09-25 17:34:55 +01004173 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004174
Chris Wilson64486ae2017-03-07 15:59:08 +00004175 return fault_irq_set(i915, &i915->gpu_error.test_irq_rings, val);
Chris Wilson094f9a52013-09-25 17:34:55 +01004176}
4177
4178DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4179 i915_ring_test_irq_get, i915_ring_test_irq_set,
4180 "0x%08llx\n");
4181
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004182#define DROP_UNBOUND BIT(0)
4183#define DROP_BOUND BIT(1)
4184#define DROP_RETIRE BIT(2)
4185#define DROP_ACTIVE BIT(3)
4186#define DROP_FREED BIT(4)
4187#define DROP_SHRINK_ALL BIT(5)
4188#define DROP_IDLE BIT(6)
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004189#define DROP_ALL (DROP_UNBOUND | \
4190 DROP_BOUND | \
4191 DROP_RETIRE | \
4192 DROP_ACTIVE | \
Chris Wilson8eadc192017-03-08 14:46:22 +00004193 DROP_FREED | \
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004194 DROP_SHRINK_ALL |\
4195 DROP_IDLE)
Kees Cook647416f2013-03-10 14:10:06 -07004196static int
4197i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004198{
Kees Cook647416f2013-03-10 14:10:06 -07004199 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004200
Kees Cook647416f2013-03-10 14:10:06 -07004201 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004202}
4203
Kees Cook647416f2013-03-10 14:10:06 -07004204static int
4205i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004206{
David Weinehall36cdd012016-08-22 13:59:31 +03004207 struct drm_i915_private *dev_priv = data;
4208 struct drm_device *dev = &dev_priv->drm;
Chris Wilson00c26cf2017-05-24 17:26:53 +01004209 int ret = 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004210
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004211 DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
4212 val, val & DROP_ALL);
Chris Wilsondd624af2013-01-15 12:39:35 +00004213
4214 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4215 * on ioctls on -EAGAIN. */
Chris Wilson00c26cf2017-05-24 17:26:53 +01004216 if (val & (DROP_ACTIVE | DROP_RETIRE)) {
4217 ret = mutex_lock_interruptible(&dev->struct_mutex);
Chris Wilsondd624af2013-01-15 12:39:35 +00004218 if (ret)
Chris Wilson00c26cf2017-05-24 17:26:53 +01004219 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004220
Chris Wilson00c26cf2017-05-24 17:26:53 +01004221 if (val & DROP_ACTIVE)
4222 ret = i915_gem_wait_for_idle(dev_priv,
4223 I915_WAIT_INTERRUPTIBLE |
4224 I915_WAIT_LOCKED);
4225
4226 if (val & DROP_RETIRE)
4227 i915_gem_retire_requests(dev_priv);
4228
4229 mutex_unlock(&dev->struct_mutex);
4230 }
Chris Wilsondd624af2013-01-15 12:39:35 +00004231
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +01004232 fs_reclaim_acquire(GFP_KERNEL);
Chris Wilson21ab4e72014-09-09 11:16:08 +01004233 if (val & DROP_BOUND)
Chris Wilson912d5722017-09-06 16:19:30 -07004234 i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004235
Chris Wilson21ab4e72014-09-09 11:16:08 +01004236 if (val & DROP_UNBOUND)
Chris Wilson912d5722017-09-06 16:19:30 -07004237 i915_gem_shrink(dev_priv, LONG_MAX, NULL, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004238
Chris Wilson8eadc192017-03-08 14:46:22 +00004239 if (val & DROP_SHRINK_ALL)
4240 i915_gem_shrink_all(dev_priv);
Peter Zijlstrad92a8cf2017-03-03 10:13:38 +01004241 fs_reclaim_release(GFP_KERNEL);
Chris Wilson8eadc192017-03-08 14:46:22 +00004242
Chris Wilsonb4a0b322017-10-18 13:16:21 +01004243 if (val & DROP_IDLE)
4244 drain_delayed_work(&dev_priv->gt.idle_work);
4245
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004246 if (val & DROP_FREED) {
4247 synchronize_rcu();
Chris Wilsonbdeb9782016-12-23 14:57:56 +00004248 i915_gem_drain_freed_objects(dev_priv);
Chris Wilsonfbbd37b2016-10-28 13:58:42 +01004249 }
4250
Kees Cook647416f2013-03-10 14:10:06 -07004251 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004252}
4253
Kees Cook647416f2013-03-10 14:10:06 -07004254DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4255 i915_drop_caches_get, i915_drop_caches_set,
4256 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004257
Kees Cook647416f2013-03-10 14:10:06 -07004258static int
4259i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004260{
David Weinehall36cdd012016-08-22 13:59:31 +03004261 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004262
David Weinehall36cdd012016-08-22 13:59:31 +03004263 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004264 return -ENODEV;
4265
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004266 *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.max_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004267 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004268}
4269
Kees Cook647416f2013-03-10 14:10:06 -07004270static int
4271i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004272{
David Weinehall36cdd012016-08-22 13:59:31 +03004273 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004274 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304275 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004276 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004277
David Weinehall36cdd012016-08-22 13:59:31 +03004278 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004279 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004280
Kees Cook647416f2013-03-10 14:10:06 -07004281 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004282
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004283 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004284 if (ret)
4285 return ret;
4286
Jesse Barnes358733e2011-07-27 11:53:01 -07004287 /*
4288 * Turbo will still be enabled, but won't go above the set value.
4289 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304290 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004291
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004292 hw_max = rps->max_freq;
4293 hw_min = rps->min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004294
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004295 if (val < hw_min || val > hw_max || val < rps->min_freq_softlimit) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004296 mutex_unlock(&dev_priv->pcu_lock);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004297 return -EINVAL;
4298 }
4299
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004300 rps->max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004301
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004302 if (intel_set_rps(dev_priv, val))
4303 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004304
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004305 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004306
Kees Cook647416f2013-03-10 14:10:06 -07004307 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004308}
4309
Kees Cook647416f2013-03-10 14:10:06 -07004310DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4311 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004312 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004313
Kees Cook647416f2013-03-10 14:10:06 -07004314static int
4315i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004316{
David Weinehall36cdd012016-08-22 13:59:31 +03004317 struct drm_i915_private *dev_priv = data;
Daniel Vetter004777c2012-08-09 15:07:01 +02004318
Chris Wilson62e1baa2016-07-13 09:10:36 +01004319 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004320 return -ENODEV;
4321
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004322 *val = intel_gpu_freq(dev_priv, dev_priv->gt_pm.rps.min_freq_softlimit);
Kees Cook647416f2013-03-10 14:10:06 -07004323 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004324}
4325
Kees Cook647416f2013-03-10 14:10:06 -07004326static int
4327i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004328{
David Weinehall36cdd012016-08-22 13:59:31 +03004329 struct drm_i915_private *dev_priv = data;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004330 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304331 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004332 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004333
Chris Wilson62e1baa2016-07-13 09:10:36 +01004334 if (INTEL_GEN(dev_priv) < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004335 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004336
Kees Cook647416f2013-03-10 14:10:06 -07004337 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004338
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004339 ret = mutex_lock_interruptible(&dev_priv->pcu_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004340 if (ret)
4341 return ret;
4342
Jesse Barnes1523c312012-05-25 12:34:54 -07004343 /*
4344 * Turbo will still be enabled, but won't go below the set value.
4345 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304346 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004347
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004348 hw_max = rps->max_freq;
4349 hw_min = rps->min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004350
David Weinehall36cdd012016-08-22 13:59:31 +03004351 if (val < hw_min ||
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004352 val > hw_max || val > rps->max_freq_softlimit) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004353 mutex_unlock(&dev_priv->pcu_lock);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004354 return -EINVAL;
4355 }
4356
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004357 rps->min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004358
Chris Wilson9fcee2f2017-01-26 10:19:19 +00004359 if (intel_set_rps(dev_priv, val))
4360 DRM_DEBUG_DRIVER("failed to update RPS to new softlimit\n");
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004361
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01004362 mutex_unlock(&dev_priv->pcu_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004363
Kees Cook647416f2013-03-10 14:10:06 -07004364 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004365}
4366
Kees Cook647416f2013-03-10 14:10:06 -07004367DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4368 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004369 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004370
Kees Cook647416f2013-03-10 14:10:06 -07004371static int
4372i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004373{
David Weinehall36cdd012016-08-22 13:59:31 +03004374 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004375 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004376
David Weinehall36cdd012016-08-22 13:59:31 +03004377 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004378 return -ENODEV;
4379
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004380 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004381
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004382 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004383
4384 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004385
Kees Cook647416f2013-03-10 14:10:06 -07004386 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004387
Kees Cook647416f2013-03-10 14:10:06 -07004388 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004389}
4390
Kees Cook647416f2013-03-10 14:10:06 -07004391static int
4392i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004393{
David Weinehall36cdd012016-08-22 13:59:31 +03004394 struct drm_i915_private *dev_priv = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004395 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004396
David Weinehall36cdd012016-08-22 13:59:31 +03004397 if (!(IS_GEN6(dev_priv) || IS_GEN7(dev_priv)))
Daniel Vetter004777c2012-08-09 15:07:01 +02004398 return -ENODEV;
4399
Kees Cook647416f2013-03-10 14:10:06 -07004400 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004401 return -EINVAL;
4402
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004403 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004404 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004405
4406 /* Update the cache sharing policy here as well */
4407 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4408 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4409 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4410 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4411
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004412 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004413 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004414}
4415
Kees Cook647416f2013-03-10 14:10:06 -07004416DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4417 i915_cache_sharing_get, i915_cache_sharing_set,
4418 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004419
David Weinehall36cdd012016-08-22 13:59:31 +03004420static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004421 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004422{
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004423 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004424 int ss;
4425 u32 sig1[ss_max], sig2[ss_max];
4426
4427 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4428 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4429 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4430 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4431
4432 for (ss = 0; ss < ss_max; ss++) {
4433 unsigned int eu_cnt;
4434
4435 if (sig1[ss] & CHV_SS_PG_ENABLE)
4436 /* skip disabled subslice */
4437 continue;
4438
Imre Deakf08a0c92016-08-31 19:13:04 +03004439 sseu->slice_mask = BIT(0);
Imre Deak57ec1712016-08-31 19:13:05 +03004440 sseu->subslice_mask |= BIT(ss);
Jeff McGee5d395252015-04-03 18:13:17 -07004441 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4442 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4443 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4444 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
Imre Deak915490d2016-08-31 19:13:01 +03004445 sseu->eu_total += eu_cnt;
4446 sseu->eu_per_subslice = max_t(unsigned int,
4447 sseu->eu_per_subslice, eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004448 }
Jeff McGee5d395252015-04-03 18:13:17 -07004449}
4450
David Weinehall36cdd012016-08-22 13:59:31 +03004451static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004452 struct sseu_dev_info *sseu)
Jeff McGee5d395252015-04-03 18:13:17 -07004453{
Jeff McGee1c046bc2015-04-03 18:13:18 -07004454 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004455 int s, ss;
4456 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4457
Jeff McGee1c046bc2015-04-03 18:13:18 -07004458 /* BXT has a single slice and at most 3 subslices. */
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004459 if (IS_GEN9_LP(dev_priv)) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004460 s_max = 1;
4461 ss_max = 3;
4462 }
4463
4464 for (s = 0; s < s_max; s++) {
4465 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4466 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4467 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4468 }
4469
Jeff McGee5d395252015-04-03 18:13:17 -07004470 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4471 GEN9_PGCTL_SSA_EU19_ACK |
4472 GEN9_PGCTL_SSA_EU210_ACK |
4473 GEN9_PGCTL_SSA_EU311_ACK;
4474 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4475 GEN9_PGCTL_SSB_EU19_ACK |
4476 GEN9_PGCTL_SSB_EU210_ACK |
4477 GEN9_PGCTL_SSB_EU311_ACK;
4478
4479 for (s = 0; s < s_max; s++) {
4480 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4481 /* skip disabled slice */
4482 continue;
4483
Imre Deakf08a0c92016-08-31 19:13:04 +03004484 sseu->slice_mask |= BIT(s);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004485
Rodrigo Vivi7ea1adf2017-08-09 13:07:02 -07004486 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv))
Imre Deak57ec1712016-08-31 19:13:05 +03004487 sseu->subslice_mask =
4488 INTEL_INFO(dev_priv)->sseu.subslice_mask;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004489
Jeff McGee5d395252015-04-03 18:13:17 -07004490 for (ss = 0; ss < ss_max; ss++) {
4491 unsigned int eu_cnt;
4492
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004493 if (IS_GEN9_LP(dev_priv)) {
Imre Deak57ec1712016-08-31 19:13:05 +03004494 if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4495 /* skip disabled subslice */
4496 continue;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004497
Imre Deak57ec1712016-08-31 19:13:05 +03004498 sseu->subslice_mask |= BIT(ss);
4499 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004500
Jeff McGee5d395252015-04-03 18:13:17 -07004501 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4502 eu_mask[ss%2]);
Imre Deak915490d2016-08-31 19:13:01 +03004503 sseu->eu_total += eu_cnt;
4504 sseu->eu_per_subslice = max_t(unsigned int,
4505 sseu->eu_per_subslice,
4506 eu_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004507 }
4508 }
4509}
4510
David Weinehall36cdd012016-08-22 13:59:31 +03004511static void broadwell_sseu_device_status(struct drm_i915_private *dev_priv,
Imre Deak915490d2016-08-31 19:13:01 +03004512 struct sseu_dev_info *sseu)
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004513{
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004514 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
David Weinehall36cdd012016-08-22 13:59:31 +03004515 int s;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004516
Imre Deakf08a0c92016-08-31 19:13:04 +03004517 sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004518
Imre Deakf08a0c92016-08-31 19:13:04 +03004519 if (sseu->slice_mask) {
Imre Deak57ec1712016-08-31 19:13:05 +03004520 sseu->subslice_mask = INTEL_INFO(dev_priv)->sseu.subslice_mask;
Imre Deak43b67992016-08-31 19:13:02 +03004521 sseu->eu_per_subslice =
4522 INTEL_INFO(dev_priv)->sseu.eu_per_subslice;
Imre Deak57ec1712016-08-31 19:13:05 +03004523 sseu->eu_total = sseu->eu_per_subslice *
4524 sseu_subslice_total(sseu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004525
4526 /* subtract fused off EU(s) from enabled slice(s) */
Imre Deak795b38b2016-08-31 19:13:07 +03004527 for (s = 0; s < fls(sseu->slice_mask); s++) {
Imre Deak43b67992016-08-31 19:13:02 +03004528 u8 subslice_7eu =
4529 INTEL_INFO(dev_priv)->sseu.subslice_7eu[s];
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004530
Imre Deak915490d2016-08-31 19:13:01 +03004531 sseu->eu_total -= hweight8(subslice_7eu);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02004532 }
4533 }
4534}
4535
Imre Deak615d8902016-08-31 19:13:03 +03004536static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
4537 const struct sseu_dev_info *sseu)
4538{
4539 struct drm_i915_private *dev_priv = node_to_i915(m->private);
4540 const char *type = is_available_info ? "Available" : "Enabled";
4541
Imre Deakc67ba532016-08-31 19:13:06 +03004542 seq_printf(m, " %s Slice Mask: %04x\n", type,
4543 sseu->slice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004544 seq_printf(m, " %s Slice Total: %u\n", type,
Imre Deakf08a0c92016-08-31 19:13:04 +03004545 hweight8(sseu->slice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004546 seq_printf(m, " %s Subslice Total: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004547 sseu_subslice_total(sseu));
Imre Deakc67ba532016-08-31 19:13:06 +03004548 seq_printf(m, " %s Subslice Mask: %04x\n", type,
4549 sseu->subslice_mask);
Imre Deak615d8902016-08-31 19:13:03 +03004550 seq_printf(m, " %s Subslice Per Slice: %u\n", type,
Imre Deak57ec1712016-08-31 19:13:05 +03004551 hweight8(sseu->subslice_mask));
Imre Deak615d8902016-08-31 19:13:03 +03004552 seq_printf(m, " %s EU Total: %u\n", type,
4553 sseu->eu_total);
4554 seq_printf(m, " %s EU Per Subslice: %u\n", type,
4555 sseu->eu_per_subslice);
4556
4557 if (!is_available_info)
4558 return;
4559
4560 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
4561 if (HAS_POOLED_EU(dev_priv))
4562 seq_printf(m, " Min EU in pool: %u\n", sseu->min_eu_in_pool);
4563
4564 seq_printf(m, " Has Slice Power Gating: %s\n",
4565 yesno(sseu->has_slice_pg));
4566 seq_printf(m, " Has Subslice Power Gating: %s\n",
4567 yesno(sseu->has_subslice_pg));
4568 seq_printf(m, " Has EU Power Gating: %s\n",
4569 yesno(sseu->has_eu_pg));
4570}
4571
Jeff McGee38732182015-02-13 10:27:54 -06004572static int i915_sseu_status(struct seq_file *m, void *unused)
4573{
David Weinehall36cdd012016-08-22 13:59:31 +03004574 struct drm_i915_private *dev_priv = node_to_i915(m->private);
Imre Deak915490d2016-08-31 19:13:01 +03004575 struct sseu_dev_info sseu;
Jeff McGee38732182015-02-13 10:27:54 -06004576
David Weinehall36cdd012016-08-22 13:59:31 +03004577 if (INTEL_GEN(dev_priv) < 8)
Jeff McGee38732182015-02-13 10:27:54 -06004578 return -ENODEV;
4579
4580 seq_puts(m, "SSEU Device Info\n");
Imre Deak615d8902016-08-31 19:13:03 +03004581 i915_print_sseu_info(m, true, &INTEL_INFO(dev_priv)->sseu);
Jeff McGee38732182015-02-13 10:27:54 -06004582
Jeff McGee7f992ab2015-02-13 10:27:55 -06004583 seq_puts(m, "SSEU Device Status\n");
Imre Deak915490d2016-08-31 19:13:01 +03004584 memset(&sseu, 0, sizeof(sseu));
David Weinehall238010e2016-08-01 17:33:27 +03004585
4586 intel_runtime_pm_get(dev_priv);
4587
David Weinehall36cdd012016-08-22 13:59:31 +03004588 if (IS_CHERRYVIEW(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004589 cherryview_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004590 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak915490d2016-08-31 19:13:01 +03004591 broadwell_sseu_device_status(dev_priv, &sseu);
David Weinehall36cdd012016-08-22 13:59:31 +03004592 } else if (INTEL_GEN(dev_priv) >= 9) {
Imre Deak915490d2016-08-31 19:13:01 +03004593 gen9_sseu_device_status(dev_priv, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004594 }
David Weinehall238010e2016-08-01 17:33:27 +03004595
4596 intel_runtime_pm_put(dev_priv);
4597
Imre Deak615d8902016-08-31 19:13:03 +03004598 i915_print_sseu_info(m, false, &sseu);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004599
Jeff McGee38732182015-02-13 10:27:54 -06004600 return 0;
4601}
4602
Ben Widawsky6d794d42011-04-25 11:25:56 -07004603static int i915_forcewake_open(struct inode *inode, struct file *file)
4604{
Chris Wilsond7a133d2017-09-07 14:44:41 +01004605 struct drm_i915_private *i915 = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004606
Chris Wilsond7a133d2017-09-07 14:44:41 +01004607 if (INTEL_GEN(i915) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004608 return 0;
4609
Chris Wilsond7a133d2017-09-07 14:44:41 +01004610 intel_runtime_pm_get(i915);
4611 intel_uncore_forcewake_user_get(i915);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004612
4613 return 0;
4614}
4615
Ben Widawskyc43b5632012-04-16 14:07:40 -07004616static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004617{
Chris Wilsond7a133d2017-09-07 14:44:41 +01004618 struct drm_i915_private *i915 = inode->i_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004619
Chris Wilsond7a133d2017-09-07 14:44:41 +01004620 if (INTEL_GEN(i915) < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004621 return 0;
4622
Chris Wilsond7a133d2017-09-07 14:44:41 +01004623 intel_uncore_forcewake_user_put(i915);
4624 intel_runtime_pm_put(i915);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004625
4626 return 0;
4627}
4628
4629static const struct file_operations i915_forcewake_fops = {
4630 .owner = THIS_MODULE,
4631 .open = i915_forcewake_open,
4632 .release = i915_forcewake_release,
4633};
4634
Lyude317eaa92017-02-03 21:18:25 -05004635static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
4636{
4637 struct drm_i915_private *dev_priv = m->private;
4638 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4639
4640 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
4641 seq_printf(m, "Detected: %s\n",
4642 yesno(delayed_work_pending(&hotplug->reenable_work)));
4643
4644 return 0;
4645}
4646
4647static ssize_t i915_hpd_storm_ctl_write(struct file *file,
4648 const char __user *ubuf, size_t len,
4649 loff_t *offp)
4650{
4651 struct seq_file *m = file->private_data;
4652 struct drm_i915_private *dev_priv = m->private;
4653 struct i915_hotplug *hotplug = &dev_priv->hotplug;
4654 unsigned int new_threshold;
4655 int i;
4656 char *newline;
4657 char tmp[16];
4658
4659 if (len >= sizeof(tmp))
4660 return -EINVAL;
4661
4662 if (copy_from_user(tmp, ubuf, len))
4663 return -EFAULT;
4664
4665 tmp[len] = '\0';
4666
4667 /* Strip newline, if any */
4668 newline = strchr(tmp, '\n');
4669 if (newline)
4670 *newline = '\0';
4671
4672 if (strcmp(tmp, "reset") == 0)
4673 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4674 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
4675 return -EINVAL;
4676
4677 if (new_threshold > 0)
4678 DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
4679 new_threshold);
4680 else
4681 DRM_DEBUG_KMS("Disabling HPD storm detection\n");
4682
4683 spin_lock_irq(&dev_priv->irq_lock);
4684 hotplug->hpd_storm_threshold = new_threshold;
4685 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
4686 for_each_hpd_pin(i)
4687 hotplug->stats[i].count = 0;
4688 spin_unlock_irq(&dev_priv->irq_lock);
4689
4690 /* Re-enable hpd immediately if we were in an irq storm */
4691 flush_delayed_work(&dev_priv->hotplug.reenable_work);
4692
4693 return len;
4694}
4695
4696static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
4697{
4698 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
4699}
4700
4701static const struct file_operations i915_hpd_storm_ctl_fops = {
4702 .owner = THIS_MODULE,
4703 .open = i915_hpd_storm_ctl_open,
4704 .read = seq_read,
4705 .llseek = seq_lseek,
4706 .release = single_release,
4707 .write = i915_hpd_storm_ctl_write
4708};
4709
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004710static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004711 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004712 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004713 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004714 {"i915_gem_stolen", i915_gem_stolen_list_info },
Ben Gamari20172632009-02-17 20:08:50 -05004715 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004716 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004717 {"i915_gem_interrupt", i915_interrupt_info, 0},
Brad Volkin493018d2014-12-11 12:13:08 -08004718 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01004719 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01004720 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01004721 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Daniele Ceraolo Spurioac58d2a2017-05-22 10:50:28 -07004722 {"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
Oscar Mateoa8b93702017-05-10 15:04:51 +00004723 {"i915_guc_stage_pool", i915_guc_stage_pool, 0},
Anusha Srivatsa0509ead2017-01-18 08:05:56 -08004724 {"i915_huc_load_status", i915_huc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304725 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004726 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Michel Thierry061d06a2017-06-20 10:57:49 +01004727 {"i915_reset_info", i915_reset_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004728 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004729 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004730 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02004731 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004732 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004733 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004734 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004735 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02004736 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004737 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004738 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01004739 {"i915_dump_lrc", i915_dump_lrc, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004740 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004741 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004742 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004743 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004744 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004745 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004746 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01004747 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004748 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02004749 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004750 {"i915_display_info", i915_display_info, 0},
Chris Wilson1b365952016-10-04 21:11:31 +01004751 {"i915_engine_info", i915_engine_info, 0},
Chris Wilsonc5418a82017-10-13 21:26:19 +01004752 {"i915_shrinker_info", i915_shrinker_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004753 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004754 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004755 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004756 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004757 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004758 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304759 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004760 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004761};
Ben Gamari27c202a2009-07-01 22:26:52 -04004762#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004763
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004764static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004765 const char *name;
4766 const struct file_operations *fops;
4767} i915_debugfs_files[] = {
4768 {"i915_wedged", &i915_wedged_fops},
4769 {"i915_max_freq", &i915_max_freq_fops},
4770 {"i915_min_freq", &i915_min_freq_fops},
4771 {"i915_cache_sharing", &i915_cache_sharing_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004772 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4773 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004774 {"i915_gem_drop_caches", &i915_drop_caches_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004775#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
Daniel Vetter34b96742013-07-04 20:49:44 +02004776 {"i915_error_state", &i915_error_state_fops},
Chris Wilson5a4c6f12017-02-14 16:46:11 +00004777 {"i915_gpu_info", &i915_gpu_info_fops},
Chris Wilson98a2f412016-10-12 10:05:18 +01004778#endif
Daniel Vetter34b96742013-07-04 20:49:44 +02004779 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004780 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004781 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4782 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4783 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Ville Syrjälä4127dc42017-06-06 15:44:12 +03004784 {"i915_fbc_false_color", &i915_fbc_false_color_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07004785 {"i915_dp_test_data", &i915_displayport_test_data_fops},
4786 {"i915_dp_test_type", &i915_displayport_test_type_fops},
Sagar Arun Kamble685534e2016-10-12 21:54:41 +05304787 {"i915_dp_test_active", &i915_displayport_test_active_fops},
Lyude317eaa92017-02-03 21:18:25 -05004788 {"i915_guc_log_control", &i915_guc_log_control_fops},
Kumar, Maheshd2d4f392017-08-17 19:15:29 +05304789 {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops},
4790 {"i915_ipc_status", &i915_ipc_status_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02004791};
4792
Chris Wilson1dac8912016-06-24 14:00:17 +01004793int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05004794{
Chris Wilson91c8a322016-07-05 10:40:23 +01004795 struct drm_minor *minor = dev_priv->drm.primary;
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004796 struct dentry *ent;
Daniel Vetter34b96742013-07-04 20:49:44 +02004797 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004798
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004799 ent = debugfs_create_file("i915_forcewake_user", S_IRUSR,
4800 minor->debugfs_root, to_i915(minor->dev),
4801 &i915_forcewake_fops);
4802 if (!ent)
4803 return -ENOMEM;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004804
Tomeu Vizoso731035f2016-12-12 13:29:48 +01004805 ret = intel_pipe_crc_create(minor);
4806 if (ret)
4807 return ret;
Damien Lespiau07144422013-10-15 18:55:40 +01004808
Daniel Vetter34b96742013-07-04 20:49:44 +02004809 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004810 ent = debugfs_create_file(i915_debugfs_files[i].name,
4811 S_IRUGO | S_IWUSR,
4812 minor->debugfs_root,
4813 to_i915(minor->dev),
Daniel Vetter34b96742013-07-04 20:49:44 +02004814 i915_debugfs_files[i].fops);
Noralf Trønnesb05eeb02017-01-26 23:56:21 +01004815 if (!ent)
4816 return -ENOMEM;
Daniel Vetter34b96742013-07-04 20:49:44 +02004817 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004818
Ben Gamari27c202a2009-07-01 22:26:52 -04004819 return drm_debugfs_create_files(i915_debugfs_list,
4820 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004821 minor->debugfs_root, minor);
4822}
4823
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004824struct dpcd_block {
4825 /* DPCD dump start address. */
4826 unsigned int offset;
4827 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4828 unsigned int end;
4829 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4830 size_t size;
4831 /* Only valid for eDP. */
4832 bool edp;
4833};
4834
4835static const struct dpcd_block i915_dpcd_debug[] = {
4836 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4837 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4838 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4839 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4840 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4841 { .offset = DP_SET_POWER },
4842 { .offset = DP_EDP_DPCD_REV },
4843 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4844 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4845 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4846};
4847
4848static int i915_dpcd_show(struct seq_file *m, void *data)
4849{
4850 struct drm_connector *connector = m->private;
4851 struct intel_dp *intel_dp =
4852 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4853 uint8_t buf[16];
4854 ssize_t err;
4855 int i;
4856
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03004857 if (connector->status != connector_status_connected)
4858 return -ENODEV;
4859
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004860 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4861 const struct dpcd_block *b = &i915_dpcd_debug[i];
4862 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4863
4864 if (b->edp &&
4865 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4866 continue;
4867
4868 /* low tech for now */
4869 if (WARN_ON(size > sizeof(buf)))
4870 continue;
4871
4872 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4873 if (err <= 0) {
4874 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4875 size, b->offset, err);
4876 continue;
4877 }
4878
4879 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08004880 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004881
4882 return 0;
4883}
4884
4885static int i915_dpcd_open(struct inode *inode, struct file *file)
4886{
4887 return single_open(file, i915_dpcd_show, inode->i_private);
4888}
4889
4890static const struct file_operations i915_dpcd_fops = {
4891 .owner = THIS_MODULE,
4892 .open = i915_dpcd_open,
4893 .read = seq_read,
4894 .llseek = seq_lseek,
4895 .release = single_release,
4896};
4897
David Weinehallecbd6782016-08-23 12:23:56 +03004898static int i915_panel_show(struct seq_file *m, void *data)
4899{
4900 struct drm_connector *connector = m->private;
4901 struct intel_dp *intel_dp =
4902 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4903
4904 if (connector->status != connector_status_connected)
4905 return -ENODEV;
4906
4907 seq_printf(m, "Panel power up delay: %d\n",
4908 intel_dp->panel_power_up_delay);
4909 seq_printf(m, "Panel power down delay: %d\n",
4910 intel_dp->panel_power_down_delay);
4911 seq_printf(m, "Backlight on delay: %d\n",
4912 intel_dp->backlight_on_delay);
4913 seq_printf(m, "Backlight off delay: %d\n",
4914 intel_dp->backlight_off_delay);
4915
4916 return 0;
4917}
4918
4919static int i915_panel_open(struct inode *inode, struct file *file)
4920{
4921 return single_open(file, i915_panel_show, inode->i_private);
4922}
4923
4924static const struct file_operations i915_panel_fops = {
4925 .owner = THIS_MODULE,
4926 .open = i915_panel_open,
4927 .read = seq_read,
4928 .llseek = seq_lseek,
4929 .release = single_release,
4930};
4931
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004932/**
4933 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4934 * @connector: pointer to a registered drm_connector
4935 *
4936 * Cleanup will be done by drm_connector_unregister() through a call to
4937 * drm_debugfs_connector_remove().
4938 *
4939 * Returns 0 on success, negative error codes on error.
4940 */
4941int i915_debugfs_connector_add(struct drm_connector *connector)
4942{
4943 struct dentry *root = connector->debugfs_entry;
4944
4945 /* The connector must have been registered beforehands. */
4946 if (!root)
4947 return -ENODEV;
4948
4949 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4950 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
David Weinehallecbd6782016-08-23 12:23:56 +03004951 debugfs_create_file("i915_dpcd", S_IRUGO, root,
4952 connector, &i915_dpcd_fops);
4953
4954 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4955 debugfs_create_file("i915_panel_timings", S_IRUGO, root,
4956 connector, &i915_panel_fops);
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004957
4958 return 0;
4959}