blob: eb87865c20d4c1db9ced1dca9085f8aa881aa590 [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
29#include <linux/seq_file.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010030#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040032#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010033#include <linux/list_sort.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010035#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000036#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050038#include "i915_drv.h"
39
40#define DRM_I915_RING_DEBUG 1
41
42
43#if defined(CONFIG_DEBUG_FS)
44
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010046 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010048 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010049};
Ben Gamari433e12f2009-02-17 20:08:51 -050050
Chris Wilson70d39fe2010-08-25 16:03:34 +010051static const char *yesno(int v)
52{
53 return v ? "yes" : "no";
54}
55
56static int i915_capabilities(struct seq_file *m, void *data)
57{
58 struct drm_info_node *node = (struct drm_info_node *) m->private;
59 struct drm_device *dev = node->minor->dev;
60 const struct intel_device_info *info = INTEL_INFO(dev);
61
62 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030063 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010064#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
65#define SEP_SEMICOLON ;
66 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
67#undef PRINT_FLAG
68#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010069
70 return 0;
71}
Ben Gamari433e12f2009-02-17 20:08:51 -050072
Chris Wilson05394f32010-11-08 19:18:58 +000073static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000074{
Chris Wilson05394f32010-11-08 19:18:58 +000075 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000076 return "P";
Chris Wilson05394f32010-11-08 19:18:58 +000077 else if (obj->pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +000078 return "p";
79 else
80 return " ";
81}
82
Chris Wilson05394f32010-11-08 19:18:58 +000083static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000084{
Akshay Joshi0206e352011-08-16 15:34:10 -040085 switch (obj->tiling_mode) {
86 default:
87 case I915_TILING_NONE: return " ";
88 case I915_TILING_X: return "X";
89 case I915_TILING_Y: return "Y";
90 }
Chris Wilsona6172a82009-02-11 14:26:38 +000091}
92
Ben Widawsky1d693bc2013-07-31 17:00:00 -070093static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
94{
95 return obj->has_global_gtt_mapping ? "g" : " ";
96}
97
Chris Wilson37811fc2010-08-25 22:45:57 +010098static void
99describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
100{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700101 struct i915_vma *vma;
102 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %d %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100103 &obj->base,
104 get_pin_flag(obj),
105 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700106 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800107 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100108 obj->base.read_domains,
109 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100110 obj->last_read_seqno,
111 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000112 obj->last_fenced_seqno,
Mika Kuoppala84734a02013-07-12 16:50:57 +0300113 i915_cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100114 obj->dirty ? " dirty" : "",
115 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
116 if (obj->base.name)
117 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100118 if (obj->pin_count)
119 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100120 if (obj->pin_display)
121 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100122 if (obj->fence_reg != I915_FENCE_REG_NONE)
123 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700124 list_for_each_entry(vma, &obj->vma_list, vma_link) {
125 if (!i915_is_ggtt(vma->vm))
126 seq_puts(m, " (pp");
127 else
128 seq_puts(m, " (g");
129 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
130 vma->node.start, vma->node.size);
131 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000132 if (obj->stolen)
133 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000134 if (obj->pin_mappable || obj->fault_mappable) {
135 char s[3], *t = s;
136 if (obj->pin_mappable)
137 *t++ = 'p';
138 if (obj->fault_mappable)
139 *t++ = 'f';
140 *t = '\0';
141 seq_printf(m, " (%s mappable)", s);
142 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100143 if (obj->ring != NULL)
144 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100145}
146
Ben Gamari433e12f2009-02-17 20:08:51 -0500147static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500148{
149 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500150 uintptr_t list = (uintptr_t) node->info_ent->data;
151 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500152 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700153 struct drm_i915_private *dev_priv = dev->dev_private;
154 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700155 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100156 size_t total_obj_size, total_gtt_size;
157 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100158
159 ret = mutex_lock_interruptible(&dev->struct_mutex);
160 if (ret)
161 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500162
Ben Widawskyca191b12013-07-31 17:00:14 -0700163 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500164 switch (list) {
165 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100166 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700167 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500168 break;
169 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100170 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700171 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500172 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500173 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100174 mutex_unlock(&dev->struct_mutex);
175 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500176 }
177
Chris Wilson8f2480f2010-09-26 11:44:19 +0100178 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700179 list_for_each_entry(vma, head, mm_list) {
180 seq_printf(m, " ");
181 describe_obj(m, vma->obj);
182 seq_printf(m, "\n");
183 total_obj_size += vma->obj->base.size;
184 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100185 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500186 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100187 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700188
Chris Wilson8f2480f2010-09-26 11:44:19 +0100189 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
190 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500191 return 0;
192}
193
Chris Wilson6d2b88852013-08-07 18:30:54 +0100194static int obj_rank_by_stolen(void *priv,
195 struct list_head *A, struct list_head *B)
196{
197 struct drm_i915_gem_object *a =
198 container_of(A, struct drm_i915_gem_object, exec_list);
199 struct drm_i915_gem_object *b =
200 container_of(B, struct drm_i915_gem_object, exec_list);
201
202 return a->stolen->start - b->stolen->start;
203}
204
205static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
206{
207 struct drm_info_node *node = (struct drm_info_node *) m->private;
208 struct drm_device *dev = node->minor->dev;
209 struct drm_i915_private *dev_priv = dev->dev_private;
210 struct drm_i915_gem_object *obj;
211 size_t total_obj_size, total_gtt_size;
212 LIST_HEAD(stolen);
213 int count, ret;
214
215 ret = mutex_lock_interruptible(&dev->struct_mutex);
216 if (ret)
217 return ret;
218
219 total_obj_size = total_gtt_size = count = 0;
220 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
221 if (obj->stolen == NULL)
222 continue;
223
224 list_add(&obj->exec_list, &stolen);
225
226 total_obj_size += obj->base.size;
227 total_gtt_size += i915_gem_obj_ggtt_size(obj);
228 count++;
229 }
230 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
231 if (obj->stolen == NULL)
232 continue;
233
234 list_add(&obj->exec_list, &stolen);
235
236 total_obj_size += obj->base.size;
237 count++;
238 }
239 list_sort(NULL, &stolen, obj_rank_by_stolen);
240 seq_puts(m, "Stolen:\n");
241 while (!list_empty(&stolen)) {
242 obj = list_first_entry(&stolen, typeof(*obj), exec_list);
243 seq_puts(m, " ");
244 describe_obj(m, obj);
245 seq_putc(m, '\n');
246 list_del_init(&obj->exec_list);
247 }
248 mutex_unlock(&dev->struct_mutex);
249
250 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
251 count, total_obj_size, total_gtt_size);
252 return 0;
253}
254
Chris Wilson6299f992010-11-24 12:23:44 +0000255#define count_objects(list, member) do { \
256 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700257 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000258 ++count; \
259 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700260 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000261 ++mappable_count; \
262 } \
263 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400264} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000265
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100266struct file_stats {
267 int count;
268 size_t total, active, inactive, unbound;
269};
270
271static int per_file_stats(int id, void *ptr, void *data)
272{
273 struct drm_i915_gem_object *obj = ptr;
274 struct file_stats *stats = data;
275
276 stats->count++;
277 stats->total += obj->base.size;
278
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700279 if (i915_gem_obj_ggtt_bound(obj)) {
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100280 if (!list_empty(&obj->ring_list))
281 stats->active += obj->base.size;
282 else
283 stats->inactive += obj->base.size;
284 } else {
285 if (!list_empty(&obj->global_list))
286 stats->unbound += obj->base.size;
287 }
288
289 return 0;
290}
291
Ben Widawskyca191b12013-07-31 17:00:14 -0700292#define count_vmas(list, member) do { \
293 list_for_each_entry(vma, list, member) { \
294 size += i915_gem_obj_ggtt_size(vma->obj); \
295 ++count; \
296 if (vma->obj->map_and_fenceable) { \
297 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
298 ++mappable_count; \
299 } \
300 } \
301} while (0)
302
303static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100304{
305 struct drm_info_node *node = (struct drm_info_node *) m->private;
306 struct drm_device *dev = node->minor->dev;
307 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200308 u32 count, mappable_count, purgeable_count;
309 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000310 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700311 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100312 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700313 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100314 int ret;
315
316 ret = mutex_lock_interruptible(&dev->struct_mutex);
317 if (ret)
318 return ret;
319
Chris Wilson6299f992010-11-24 12:23:44 +0000320 seq_printf(m, "%u objects, %zu bytes\n",
321 dev_priv->mm.object_count,
322 dev_priv->mm.object_memory);
323
324 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700325 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000326 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
327 count, mappable_count, size, mappable_size);
328
329 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700330 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000331 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
332 count, mappable_count, size, mappable_size);
333
334 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700335 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000336 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
337 count, mappable_count, size, mappable_size);
338
Chris Wilsonb7abb712012-08-20 11:33:30 +0200339 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700340 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200341 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200342 if (obj->madv == I915_MADV_DONTNEED)
343 purgeable_size += obj->base.size, ++purgeable_count;
344 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200345 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
346
Chris Wilson6299f992010-11-24 12:23:44 +0000347 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700348 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000349 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700350 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000351 ++count;
352 }
353 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700354 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000355 ++mappable_count;
356 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200357 if (obj->madv == I915_MADV_DONTNEED) {
358 purgeable_size += obj->base.size;
359 ++purgeable_count;
360 }
Chris Wilson6299f992010-11-24 12:23:44 +0000361 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200362 seq_printf(m, "%u purgeable objects, %zu bytes\n",
363 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000364 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
365 mappable_count, mappable_size);
366 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
367 count, size);
368
Ben Widawsky93d18792013-01-17 12:45:17 -0800369 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700370 dev_priv->gtt.base.total,
371 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100372
Damien Lespiau267f0c92013-06-24 22:59:48 +0100373 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100374 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
375 struct file_stats stats;
376
377 memset(&stats, 0, sizeof(stats));
378 idr_for_each(&file->object_idr, per_file_stats, &stats);
379 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu unbound)\n",
380 get_pid_task(file->pid, PIDTYPE_PID)->comm,
381 stats.count,
382 stats.total,
383 stats.active,
384 stats.inactive,
385 stats.unbound);
386 }
387
Chris Wilson73aa8082010-09-30 11:46:12 +0100388 mutex_unlock(&dev->struct_mutex);
389
390 return 0;
391}
392
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100393static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000394{
395 struct drm_info_node *node = (struct drm_info_node *) m->private;
396 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100397 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000398 struct drm_i915_private *dev_priv = dev->dev_private;
399 struct drm_i915_gem_object *obj;
400 size_t total_obj_size, total_gtt_size;
401 int count, ret;
402
403 ret = mutex_lock_interruptible(&dev->struct_mutex);
404 if (ret)
405 return ret;
406
407 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700408 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100409 if (list == PINNED_LIST && obj->pin_count == 0)
410 continue;
411
Damien Lespiau267f0c92013-06-24 22:59:48 +0100412 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000413 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100414 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000415 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700416 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000417 count++;
418 }
419
420 mutex_unlock(&dev->struct_mutex);
421
422 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
423 count, total_obj_size, total_gtt_size);
424
425 return 0;
426}
427
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100428static int i915_gem_pageflip_info(struct seq_file *m, void *data)
429{
430 struct drm_info_node *node = (struct drm_info_node *) m->private;
431 struct drm_device *dev = node->minor->dev;
432 unsigned long flags;
433 struct intel_crtc *crtc;
434
435 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800436 const char pipe = pipe_name(crtc->pipe);
437 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100438 struct intel_unpin_work *work;
439
440 spin_lock_irqsave(&dev->event_lock, flags);
441 work = crtc->unpin_work;
442 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800443 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100444 pipe, plane);
445 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000446 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800447 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100448 pipe, plane);
449 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800450 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100451 pipe, plane);
452 }
453 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100454 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100455 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100456 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000457 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100458
459 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000460 struct drm_i915_gem_object *obj = work->old_fb_obj;
461 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700462 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
463 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100464 }
465 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000466 struct drm_i915_gem_object *obj = work->pending_flip_obj;
467 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700468 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
469 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100470 }
471 }
472 spin_unlock_irqrestore(&dev->event_lock, flags);
473 }
474
475 return 0;
476}
477
Ben Gamari20172632009-02-17 20:08:50 -0500478static int i915_gem_request_info(struct seq_file *m, void *data)
479{
480 struct drm_info_node *node = (struct drm_info_node *) m->private;
481 struct drm_device *dev = node->minor->dev;
482 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100483 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500484 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100485 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100486
487 ret = mutex_lock_interruptible(&dev->struct_mutex);
488 if (ret)
489 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500490
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100491 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100492 for_each_ring(ring, dev_priv, i) {
493 if (list_empty(&ring->request_list))
494 continue;
495
496 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100497 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100498 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100499 list) {
500 seq_printf(m, " %d @ %d\n",
501 gem_request->seqno,
502 (int) (jiffies - gem_request->emitted_jiffies));
503 }
504 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500505 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100506 mutex_unlock(&dev->struct_mutex);
507
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100508 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100509 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100510
Ben Gamari20172632009-02-17 20:08:50 -0500511 return 0;
512}
513
Chris Wilsonb2223492010-10-27 15:27:33 +0100514static void i915_ring_seqno_info(struct seq_file *m,
515 struct intel_ring_buffer *ring)
516{
517 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200518 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100519 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100520 }
521}
522
Ben Gamari20172632009-02-17 20:08:50 -0500523static int i915_gem_seqno_info(struct seq_file *m, void *data)
524{
525 struct drm_info_node *node = (struct drm_info_node *) m->private;
526 struct drm_device *dev = node->minor->dev;
527 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100528 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000529 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100530
531 ret = mutex_lock_interruptible(&dev->struct_mutex);
532 if (ret)
533 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500534
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100535 for_each_ring(ring, dev_priv, i)
536 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100537
538 mutex_unlock(&dev->struct_mutex);
539
Ben Gamari20172632009-02-17 20:08:50 -0500540 return 0;
541}
542
543
544static int i915_interrupt_info(struct seq_file *m, void *data)
545{
546 struct drm_info_node *node = (struct drm_info_node *) m->private;
547 struct drm_device *dev = node->minor->dev;
548 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100549 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800550 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100551
552 ret = mutex_lock_interruptible(&dev->struct_mutex);
553 if (ret)
554 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500555
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700556 if (IS_VALLEYVIEW(dev)) {
557 seq_printf(m, "Display IER:\t%08x\n",
558 I915_READ(VLV_IER));
559 seq_printf(m, "Display IIR:\t%08x\n",
560 I915_READ(VLV_IIR));
561 seq_printf(m, "Display IIR_RW:\t%08x\n",
562 I915_READ(VLV_IIR_RW));
563 seq_printf(m, "Display IMR:\t%08x\n",
564 I915_READ(VLV_IMR));
565 for_each_pipe(pipe)
566 seq_printf(m, "Pipe %c stat:\t%08x\n",
567 pipe_name(pipe),
568 I915_READ(PIPESTAT(pipe)));
569
570 seq_printf(m, "Master IER:\t%08x\n",
571 I915_READ(VLV_MASTER_IER));
572
573 seq_printf(m, "Render IER:\t%08x\n",
574 I915_READ(GTIER));
575 seq_printf(m, "Render IIR:\t%08x\n",
576 I915_READ(GTIIR));
577 seq_printf(m, "Render IMR:\t%08x\n",
578 I915_READ(GTIMR));
579
580 seq_printf(m, "PM IER:\t\t%08x\n",
581 I915_READ(GEN6_PMIER));
582 seq_printf(m, "PM IIR:\t\t%08x\n",
583 I915_READ(GEN6_PMIIR));
584 seq_printf(m, "PM IMR:\t\t%08x\n",
585 I915_READ(GEN6_PMIMR));
586
587 seq_printf(m, "Port hotplug:\t%08x\n",
588 I915_READ(PORT_HOTPLUG_EN));
589 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
590 I915_READ(VLV_DPFLIPSTAT));
591 seq_printf(m, "DPINVGTT:\t%08x\n",
592 I915_READ(DPINVGTT));
593
594 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800595 seq_printf(m, "Interrupt enable: %08x\n",
596 I915_READ(IER));
597 seq_printf(m, "Interrupt identity: %08x\n",
598 I915_READ(IIR));
599 seq_printf(m, "Interrupt mask: %08x\n",
600 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800601 for_each_pipe(pipe)
602 seq_printf(m, "Pipe %c stat: %08x\n",
603 pipe_name(pipe),
604 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800605 } else {
606 seq_printf(m, "North Display Interrupt enable: %08x\n",
607 I915_READ(DEIER));
608 seq_printf(m, "North Display Interrupt identity: %08x\n",
609 I915_READ(DEIIR));
610 seq_printf(m, "North Display Interrupt mask: %08x\n",
611 I915_READ(DEIMR));
612 seq_printf(m, "South Display Interrupt enable: %08x\n",
613 I915_READ(SDEIER));
614 seq_printf(m, "South Display Interrupt identity: %08x\n",
615 I915_READ(SDEIIR));
616 seq_printf(m, "South Display Interrupt mask: %08x\n",
617 I915_READ(SDEIMR));
618 seq_printf(m, "Graphics Interrupt enable: %08x\n",
619 I915_READ(GTIER));
620 seq_printf(m, "Graphics Interrupt identity: %08x\n",
621 I915_READ(GTIIR));
622 seq_printf(m, "Graphics Interrupt mask: %08x\n",
623 I915_READ(GTIMR));
624 }
Ben Gamari20172632009-02-17 20:08:50 -0500625 seq_printf(m, "Interrupts received: %d\n",
626 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100627 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700628 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100629 seq_printf(m,
630 "Graphics Interrupt mask (%s): %08x\n",
631 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000632 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100633 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000634 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100635 mutex_unlock(&dev->struct_mutex);
636
Ben Gamari20172632009-02-17 20:08:50 -0500637 return 0;
638}
639
Chris Wilsona6172a82009-02-11 14:26:38 +0000640static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
641{
642 struct drm_info_node *node = (struct drm_info_node *) m->private;
643 struct drm_device *dev = node->minor->dev;
644 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100645 int i, ret;
646
647 ret = mutex_lock_interruptible(&dev->struct_mutex);
648 if (ret)
649 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000650
651 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
652 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
653 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000654 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000655
Chris Wilson6c085a72012-08-20 11:40:46 +0200656 seq_printf(m, "Fence %d, pin count = %d, object = ",
657 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100658 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100659 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100660 else
Chris Wilson05394f32010-11-08 19:18:58 +0000661 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100662 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000663 }
664
Chris Wilson05394f32010-11-08 19:18:58 +0000665 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000666 return 0;
667}
668
Ben Gamari20172632009-02-17 20:08:50 -0500669static int i915_hws_info(struct seq_file *m, void *data)
670{
671 struct drm_info_node *node = (struct drm_info_node *) m->private;
672 struct drm_device *dev = node->minor->dev;
673 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100674 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100675 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100676 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500677
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000678 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100679 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500680 if (hws == NULL)
681 return 0;
682
683 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
684 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
685 i * 4,
686 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
687 }
688 return 0;
689}
690
Daniel Vetterd5442302012-04-27 15:17:40 +0200691static ssize_t
692i915_error_state_write(struct file *filp,
693 const char __user *ubuf,
694 size_t cnt,
695 loff_t *ppos)
696{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300697 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200698 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200699 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200700
701 DRM_DEBUG_DRIVER("Resetting error state\n");
702
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200703 ret = mutex_lock_interruptible(&dev->struct_mutex);
704 if (ret)
705 return ret;
706
Daniel Vetterd5442302012-04-27 15:17:40 +0200707 i915_destroy_error_state(dev);
708 mutex_unlock(&dev->struct_mutex);
709
710 return cnt;
711}
712
713static int i915_error_state_open(struct inode *inode, struct file *file)
714{
715 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200716 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200717
718 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
719 if (!error_priv)
720 return -ENOMEM;
721
722 error_priv->dev = dev;
723
Mika Kuoppala95d5bfb32013-06-06 15:18:40 +0300724 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200725
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300726 file->private_data = error_priv;
727
728 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200729}
730
731static int i915_error_state_release(struct inode *inode, struct file *file)
732{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300733 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200734
Mika Kuoppala95d5bfb32013-06-06 15:18:40 +0300735 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200736 kfree(error_priv);
737
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300738 return 0;
739}
740
741static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
742 size_t count, loff_t *pos)
743{
744 struct i915_error_state_file_priv *error_priv = file->private_data;
745 struct drm_i915_error_state_buf error_str;
746 loff_t tmp_pos = 0;
747 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300748 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300749
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300750 ret = i915_error_state_buf_init(&error_str, count, *pos);
751 if (ret)
752 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300753
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300754 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300755 if (ret)
756 goto out;
757
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300758 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
759 error_str.buf,
760 error_str.bytes);
761
762 if (ret_count < 0)
763 ret = ret_count;
764 else
765 *pos = error_str.start + ret_count;
766out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300767 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300768 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200769}
770
771static const struct file_operations i915_error_state_fops = {
772 .owner = THIS_MODULE,
773 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300774 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200775 .write = i915_error_state_write,
776 .llseek = default_llseek,
777 .release = i915_error_state_release,
778};
779
Kees Cook647416f2013-03-10 14:10:06 -0700780static int
781i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200782{
Kees Cook647416f2013-03-10 14:10:06 -0700783 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200784 drm_i915_private_t *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200785 int ret;
786
787 ret = mutex_lock_interruptible(&dev->struct_mutex);
788 if (ret)
789 return ret;
790
Kees Cook647416f2013-03-10 14:10:06 -0700791 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200792 mutex_unlock(&dev->struct_mutex);
793
Kees Cook647416f2013-03-10 14:10:06 -0700794 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200795}
796
Kees Cook647416f2013-03-10 14:10:06 -0700797static int
798i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200799{
Kees Cook647416f2013-03-10 14:10:06 -0700800 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200801 int ret;
802
Mika Kuoppala40633212012-12-04 15:12:00 +0200803 ret = mutex_lock_interruptible(&dev->struct_mutex);
804 if (ret)
805 return ret;
806
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200807 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200808 mutex_unlock(&dev->struct_mutex);
809
Kees Cook647416f2013-03-10 14:10:06 -0700810 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200811}
812
Kees Cook647416f2013-03-10 14:10:06 -0700813DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
814 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +0300815 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +0200816
Jesse Barnesf97108d2010-01-29 11:27:07 -0800817static int i915_rstdby_delays(struct seq_file *m, void *unused)
818{
819 struct drm_info_node *node = (struct drm_info_node *) m->private;
820 struct drm_device *dev = node->minor->dev;
821 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700822 u16 crstanddelay;
823 int ret;
824
825 ret = mutex_lock_interruptible(&dev->struct_mutex);
826 if (ret)
827 return ret;
828
829 crstanddelay = I915_READ16(CRSTANDVID);
830
831 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800832
833 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
834
835 return 0;
836}
837
838static int i915_cur_delayinfo(struct seq_file *m, void *unused)
839{
840 struct drm_info_node *node = (struct drm_info_node *) m->private;
841 struct drm_device *dev = node->minor->dev;
842 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100843 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800844
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800845 if (IS_GEN5(dev)) {
846 u16 rgvswctl = I915_READ16(MEMSWCTL);
847 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
848
849 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
850 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
851 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
852 MEMSTAT_VID_SHIFT);
853 seq_printf(m, "Current P-state: %d\n",
854 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700855 } else if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800856 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
857 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
858 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800859 u32 rpstat, cagf;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800860 u32 rpupei, rpcurup, rpprevup;
861 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800862 int max_freq;
863
864 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100865 ret = mutex_lock_interruptible(&dev->struct_mutex);
866 if (ret)
867 return ret;
868
Ben Widawskyfcca7922011-04-25 11:23:07 -0700869 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800870
Jesse Barnesccab5c82011-01-18 15:49:25 -0800871 rpstat = I915_READ(GEN6_RPSTAT1);
872 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
873 rpcurup = I915_READ(GEN6_RP_CUR_UP);
874 rpprevup = I915_READ(GEN6_RP_PREV_UP);
875 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
876 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
877 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800878 if (IS_HASWELL(dev))
879 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
880 else
881 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
882 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -0800883
Ben Widawskyd1ebd8162011-04-25 20:11:50 +0100884 gen6_gt_force_wake_put(dev_priv);
885 mutex_unlock(&dev->struct_mutex);
886
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800887 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800888 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800889 seq_printf(m, "Render p-state ratio: %d\n",
890 (gt_perf_status & 0xff00) >> 8);
891 seq_printf(m, "Render p-state VID: %d\n",
892 gt_perf_status & 0xff);
893 seq_printf(m, "Render p-state limit: %d\n",
894 rp_state_limits & 0xff);
Ben Widawskyf82855d2013-01-29 12:00:15 -0800895 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -0800896 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
897 GEN6_CURICONT_MASK);
898 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
899 GEN6_CURBSYTAVG_MASK);
900 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
901 GEN6_CURBSYTAVG_MASK);
902 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
903 GEN6_CURIAVG_MASK);
904 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
905 GEN6_CURBSYTAVG_MASK);
906 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
907 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800908
909 max_freq = (rp_state_cap & 0xff0000) >> 16;
910 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700911 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800912
913 max_freq = (rp_state_cap & 0xff00) >> 8;
914 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700915 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800916
917 max_freq = rp_state_cap & 0xff;
918 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -0700919 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -0700920
921 seq_printf(m, "Max overclocked frequency: %dMHz\n",
922 dev_priv->rps.hw_max * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700923 } else if (IS_VALLEYVIEW(dev)) {
924 u32 freq_sts, val;
925
Jesse Barnes259bd5d2013-04-22 15:59:30 -0700926 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +0300927 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700928 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
929 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
930
Jani Nikula64936252013-05-22 15:36:20 +0300931 val = vlv_punit_read(dev_priv, PUNIT_FUSE_BUS1);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700932 seq_printf(m, "max GPU freq: %d MHz\n",
933 vlv_gpu_freq(dev_priv->mem_freq, val));
934
Jani Nikula64936252013-05-22 15:36:20 +0300935 val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM);
Jesse Barnes0a073b82013-04-17 15:54:58 -0700936 seq_printf(m, "min GPU freq: %d MHz\n",
937 vlv_gpu_freq(dev_priv->mem_freq, val));
938
939 seq_printf(m, "current GPU freq: %d MHz\n",
940 vlv_gpu_freq(dev_priv->mem_freq,
941 (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -0700942 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800943 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +0100944 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800945 }
Jesse Barnesf97108d2010-01-29 11:27:07 -0800946
947 return 0;
948}
949
950static int i915_delayfreq_table(struct seq_file *m, void *unused)
951{
952 struct drm_info_node *node = (struct drm_info_node *) m->private;
953 struct drm_device *dev = node->minor->dev;
954 drm_i915_private_t *dev_priv = dev->dev_private;
955 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700956 int ret, i;
957
958 ret = mutex_lock_interruptible(&dev->struct_mutex);
959 if (ret)
960 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800961
962 for (i = 0; i < 16; i++) {
963 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -0700964 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
965 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800966 }
967
Ben Widawsky616fdb52011-10-05 11:44:54 -0700968 mutex_unlock(&dev->struct_mutex);
969
Jesse Barnesf97108d2010-01-29 11:27:07 -0800970 return 0;
971}
972
973static inline int MAP_TO_MV(int map)
974{
975 return 1250 - (map * 25);
976}
977
978static int i915_inttoext_table(struct seq_file *m, void *unused)
979{
980 struct drm_info_node *node = (struct drm_info_node *) m->private;
981 struct drm_device *dev = node->minor->dev;
982 drm_i915_private_t *dev_priv = dev->dev_private;
983 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700984 int ret, i;
985
986 ret = mutex_lock_interruptible(&dev->struct_mutex);
987 if (ret)
988 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800989
990 for (i = 1; i <= 32; i++) {
991 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
992 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
993 }
994
Ben Widawsky616fdb52011-10-05 11:44:54 -0700995 mutex_unlock(&dev->struct_mutex);
996
Jesse Barnesf97108d2010-01-29 11:27:07 -0800997 return 0;
998}
999
Ben Widawsky4d855292011-12-12 19:34:16 -08001000static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001001{
1002 struct drm_info_node *node = (struct drm_info_node *) m->private;
1003 struct drm_device *dev = node->minor->dev;
1004 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001005 u32 rgvmodectl, rstdbyctl;
1006 u16 crstandvid;
1007 int ret;
1008
1009 ret = mutex_lock_interruptible(&dev->struct_mutex);
1010 if (ret)
1011 return ret;
1012
1013 rgvmodectl = I915_READ(MEMMODECTL);
1014 rstdbyctl = I915_READ(RSTDBYCTL);
1015 crstandvid = I915_READ16(CRSTANDVID);
1016
1017 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001018
1019 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1020 "yes" : "no");
1021 seq_printf(m, "Boost freq: %d\n",
1022 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1023 MEMMODE_BOOST_FREQ_SHIFT);
1024 seq_printf(m, "HW control enabled: %s\n",
1025 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1026 seq_printf(m, "SW control enabled: %s\n",
1027 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1028 seq_printf(m, "Gated voltage change: %s\n",
1029 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1030 seq_printf(m, "Starting frequency: P%d\n",
1031 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001032 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001033 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001034 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1035 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1036 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1037 seq_printf(m, "Render standby enabled: %s\n",
1038 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001039 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001040 switch (rstdbyctl & RSX_STATUS_MASK) {
1041 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001042 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001043 break;
1044 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001045 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001046 break;
1047 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001048 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001049 break;
1050 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001051 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001052 break;
1053 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001054 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001055 break;
1056 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001057 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001058 break;
1059 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001060 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001061 break;
1062 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001063
1064 return 0;
1065}
1066
Ben Widawsky4d855292011-12-12 19:34:16 -08001067static int gen6_drpc_info(struct seq_file *m)
1068{
1069
1070 struct drm_info_node *node = (struct drm_info_node *) m->private;
1071 struct drm_device *dev = node->minor->dev;
1072 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001073 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001074 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001075 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001076
1077 ret = mutex_lock_interruptible(&dev->struct_mutex);
1078 if (ret)
1079 return ret;
1080
Chris Wilson907b28c2013-07-19 20:36:52 +01001081 spin_lock_irq(&dev_priv->uncore.lock);
1082 forcewake_count = dev_priv->uncore.forcewake_count;
1083 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001084
1085 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001086 seq_puts(m, "RC information inaccurate because somebody "
1087 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001088 } else {
1089 /* NB: we cannot use forcewake, else we read the wrong values */
1090 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1091 udelay(10);
1092 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1093 }
1094
1095 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001096 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001097
1098 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1099 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1100 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001101 mutex_lock(&dev_priv->rps.hw_lock);
1102 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1103 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001104
1105 seq_printf(m, "Video Turbo Mode: %s\n",
1106 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1107 seq_printf(m, "HW control enabled: %s\n",
1108 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1109 seq_printf(m, "SW control enabled: %s\n",
1110 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1111 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001112 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001113 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1114 seq_printf(m, "RC6 Enabled: %s\n",
1115 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1116 seq_printf(m, "Deep RC6 Enabled: %s\n",
1117 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1118 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1119 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001120 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001121 switch (gt_core_status & GEN6_RCn_MASK) {
1122 case GEN6_RC0:
1123 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001124 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001125 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001126 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001127 break;
1128 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001129 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001130 break;
1131 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001132 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001133 break;
1134 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001135 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001136 break;
1137 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001138 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001139 break;
1140 }
1141
1142 seq_printf(m, "Core Power Down: %s\n",
1143 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001144
1145 /* Not exactly sure what this is */
1146 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1147 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1148 seq_printf(m, "RC6 residency since boot: %u\n",
1149 I915_READ(GEN6_GT_GFX_RC6));
1150 seq_printf(m, "RC6+ residency since boot: %u\n",
1151 I915_READ(GEN6_GT_GFX_RC6p));
1152 seq_printf(m, "RC6++ residency since boot: %u\n",
1153 I915_READ(GEN6_GT_GFX_RC6pp));
1154
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001155 seq_printf(m, "RC6 voltage: %dmV\n",
1156 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1157 seq_printf(m, "RC6+ voltage: %dmV\n",
1158 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1159 seq_printf(m, "RC6++ voltage: %dmV\n",
1160 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001161 return 0;
1162}
1163
1164static int i915_drpc_info(struct seq_file *m, void *unused)
1165{
1166 struct drm_info_node *node = (struct drm_info_node *) m->private;
1167 struct drm_device *dev = node->minor->dev;
1168
1169 if (IS_GEN6(dev) || IS_GEN7(dev))
1170 return gen6_drpc_info(m);
1171 else
1172 return ironlake_drpc_info(m);
1173}
1174
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001175static int i915_fbc_status(struct seq_file *m, void *unused)
1176{
1177 struct drm_info_node *node = (struct drm_info_node *) m->private;
1178 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001179 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001180
Adam Jacksonee5382a2010-04-23 11:17:39 -04001181 if (!I915_HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001182 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001183 return 0;
1184 }
1185
Adam Jacksonee5382a2010-04-23 11:17:39 -04001186 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001187 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001188 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001189 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001190 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001191 case FBC_OK:
1192 seq_puts(m, "FBC actived, but currently disabled in hardware");
1193 break;
1194 case FBC_UNSUPPORTED:
1195 seq_puts(m, "unsupported by this chipset");
1196 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001197 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001198 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001199 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001200 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001201 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001202 break;
1203 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001204 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001205 break;
1206 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001207 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001208 break;
1209 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001210 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001211 break;
1212 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001213 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001214 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001215 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001216 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001217 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001218 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001219 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001220 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001221 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001222 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001223 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001224 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001225 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001226 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001227 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001228 }
1229 return 0;
1230}
1231
Paulo Zanoni92d44622013-05-31 16:33:24 -03001232static int i915_ips_status(struct seq_file *m, void *unused)
1233{
1234 struct drm_info_node *node = (struct drm_info_node *) m->private;
1235 struct drm_device *dev = node->minor->dev;
1236 struct drm_i915_private *dev_priv = dev->dev_private;
1237
Damien Lespiauf5adf942013-06-24 18:29:34 +01001238 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001239 seq_puts(m, "not supported\n");
1240 return 0;
1241 }
1242
1243 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1244 seq_puts(m, "enabled\n");
1245 else
1246 seq_puts(m, "disabled\n");
1247
1248 return 0;
1249}
1250
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001251static int i915_sr_status(struct seq_file *m, void *unused)
1252{
1253 struct drm_info_node *node = (struct drm_info_node *) m->private;
1254 struct drm_device *dev = node->minor->dev;
1255 drm_i915_private_t *dev_priv = dev->dev_private;
1256 bool sr_enabled = false;
1257
Yuanhan Liu13982612010-12-15 15:42:31 +08001258 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001259 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001260 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001261 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1262 else if (IS_I915GM(dev))
1263 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1264 else if (IS_PINEVIEW(dev))
1265 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1266
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001267 seq_printf(m, "self-refresh: %s\n",
1268 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001269
1270 return 0;
1271}
1272
Jesse Barnes7648fa92010-05-20 14:28:11 -07001273static int i915_emon_status(struct seq_file *m, void *unused)
1274{
1275 struct drm_info_node *node = (struct drm_info_node *) m->private;
1276 struct drm_device *dev = node->minor->dev;
1277 drm_i915_private_t *dev_priv = dev->dev_private;
1278 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001279 int ret;
1280
Chris Wilson582be6b2012-04-30 19:35:02 +01001281 if (!IS_GEN5(dev))
1282 return -ENODEV;
1283
Chris Wilsonde227ef2010-07-03 07:58:38 +01001284 ret = mutex_lock_interruptible(&dev->struct_mutex);
1285 if (ret)
1286 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001287
1288 temp = i915_mch_val(dev_priv);
1289 chipset = i915_chipset_val(dev_priv);
1290 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001291 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001292
1293 seq_printf(m, "GMCH temp: %ld\n", temp);
1294 seq_printf(m, "Chipset power: %ld\n", chipset);
1295 seq_printf(m, "GFX power: %ld\n", gfx);
1296 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1297
1298 return 0;
1299}
1300
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001301static int i915_ring_freq_table(struct seq_file *m, void *unused)
1302{
1303 struct drm_info_node *node = (struct drm_info_node *) m->private;
1304 struct drm_device *dev = node->minor->dev;
1305 drm_i915_private_t *dev_priv = dev->dev_private;
1306 int ret;
1307 int gpu_freq, ia_freq;
1308
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001309 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001310 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001311 return 0;
1312 }
1313
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001314 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001315 if (ret)
1316 return ret;
1317
Damien Lespiau267f0c92013-06-24 22:59:48 +01001318 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001319
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001320 for (gpu_freq = dev_priv->rps.min_delay;
1321 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001322 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001323 ia_freq = gpu_freq;
1324 sandybridge_pcode_read(dev_priv,
1325 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1326 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001327 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1328 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1329 ((ia_freq >> 0) & 0xff) * 100,
1330 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001331 }
1332
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001333 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001334
1335 return 0;
1336}
1337
Jesse Barnes7648fa92010-05-20 14:28:11 -07001338static int i915_gfxec(struct seq_file *m, void *unused)
1339{
1340 struct drm_info_node *node = (struct drm_info_node *) m->private;
1341 struct drm_device *dev = node->minor->dev;
1342 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001343 int ret;
1344
1345 ret = mutex_lock_interruptible(&dev->struct_mutex);
1346 if (ret)
1347 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001348
1349 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1350
Ben Widawsky616fdb52011-10-05 11:44:54 -07001351 mutex_unlock(&dev->struct_mutex);
1352
Jesse Barnes7648fa92010-05-20 14:28:11 -07001353 return 0;
1354}
1355
Chris Wilson44834a62010-08-19 16:09:23 +01001356static int i915_opregion(struct seq_file *m, void *unused)
1357{
1358 struct drm_info_node *node = (struct drm_info_node *) m->private;
1359 struct drm_device *dev = node->minor->dev;
1360 drm_i915_private_t *dev_priv = dev->dev_private;
1361 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001362 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001363 int ret;
1364
Daniel Vetter0d38f002012-04-21 22:49:10 +02001365 if (data == NULL)
1366 return -ENOMEM;
1367
Chris Wilson44834a62010-08-19 16:09:23 +01001368 ret = mutex_lock_interruptible(&dev->struct_mutex);
1369 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001370 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001371
Daniel Vetter0d38f002012-04-21 22:49:10 +02001372 if (opregion->header) {
1373 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1374 seq_write(m, data, OPREGION_SIZE);
1375 }
Chris Wilson44834a62010-08-19 16:09:23 +01001376
1377 mutex_unlock(&dev->struct_mutex);
1378
Daniel Vetter0d38f002012-04-21 22:49:10 +02001379out:
1380 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001381 return 0;
1382}
1383
Chris Wilson37811fc2010-08-25 22:45:57 +01001384static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1385{
1386 struct drm_info_node *node = (struct drm_info_node *) m->private;
1387 struct drm_device *dev = node->minor->dev;
1388 drm_i915_private_t *dev_priv = dev->dev_private;
1389 struct intel_fbdev *ifbdev;
1390 struct intel_framebuffer *fb;
1391 int ret;
1392
1393 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1394 if (ret)
1395 return ret;
1396
1397 ifbdev = dev_priv->fbdev;
1398 fb = to_intel_framebuffer(ifbdev->helper.fb);
1399
Daniel Vetter623f9782012-12-11 16:21:38 +01001400 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001401 fb->base.width,
1402 fb->base.height,
1403 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001404 fb->base.bits_per_pixel,
1405 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001406 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001407 seq_putc(m, '\n');
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001408 mutex_unlock(&dev->mode_config.mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001409
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001410 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001411 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1412 if (&fb->base == ifbdev->helper.fb)
1413 continue;
1414
Daniel Vetter623f9782012-12-11 16:21:38 +01001415 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001416 fb->base.width,
1417 fb->base.height,
1418 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001419 fb->base.bits_per_pixel,
1420 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001421 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001423 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001424 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001425
1426 return 0;
1427}
1428
Ben Widawskye76d3632011-03-19 18:14:29 -07001429static int i915_context_status(struct seq_file *m, void *unused)
1430{
1431 struct drm_info_node *node = (struct drm_info_node *) m->private;
1432 struct drm_device *dev = node->minor->dev;
1433 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskya168c292013-02-14 15:05:12 -08001434 struct intel_ring_buffer *ring;
1435 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001436
1437 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1438 if (ret)
1439 return ret;
1440
Daniel Vetter3e373942012-11-02 19:55:04 +01001441 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001442 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001443 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001445 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001446
Daniel Vetter3e373942012-11-02 19:55:04 +01001447 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001448 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001449 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001451 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001452
Ben Widawskya168c292013-02-14 15:05:12 -08001453 for_each_ring(ring, dev_priv, i) {
1454 if (ring->default_context) {
1455 seq_printf(m, "HW default context %s ring ", ring->name);
1456 describe_obj(m, ring->default_context->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001457 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001458 }
1459 }
1460
Ben Widawskye76d3632011-03-19 18:14:29 -07001461 mutex_unlock(&dev->mode_config.mutex);
1462
1463 return 0;
1464}
1465
Ben Widawsky6d794d42011-04-25 11:25:56 -07001466static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1467{
1468 struct drm_info_node *node = (struct drm_info_node *) m->private;
1469 struct drm_device *dev = node->minor->dev;
1470 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001471 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001472
Chris Wilson907b28c2013-07-19 20:36:52 +01001473 spin_lock_irq(&dev_priv->uncore.lock);
1474 forcewake_count = dev_priv->uncore.forcewake_count;
1475 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001476
1477 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001478
1479 return 0;
1480}
1481
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001482static const char *swizzle_string(unsigned swizzle)
1483{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001484 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001485 case I915_BIT_6_SWIZZLE_NONE:
1486 return "none";
1487 case I915_BIT_6_SWIZZLE_9:
1488 return "bit9";
1489 case I915_BIT_6_SWIZZLE_9_10:
1490 return "bit9/bit10";
1491 case I915_BIT_6_SWIZZLE_9_11:
1492 return "bit9/bit11";
1493 case I915_BIT_6_SWIZZLE_9_10_11:
1494 return "bit9/bit10/bit11";
1495 case I915_BIT_6_SWIZZLE_9_17:
1496 return "bit9/bit17";
1497 case I915_BIT_6_SWIZZLE_9_10_17:
1498 return "bit9/bit10/bit17";
1499 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001500 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001501 }
1502
1503 return "bug";
1504}
1505
1506static int i915_swizzle_info(struct seq_file *m, void *data)
1507{
1508 struct drm_info_node *node = (struct drm_info_node *) m->private;
1509 struct drm_device *dev = node->minor->dev;
1510 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001511 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001512
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001513 ret = mutex_lock_interruptible(&dev->struct_mutex);
1514 if (ret)
1515 return ret;
1516
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001517 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1518 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1519 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1520 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1521
1522 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1523 seq_printf(m, "DDC = 0x%08x\n",
1524 I915_READ(DCC));
1525 seq_printf(m, "C0DRB3 = 0x%04x\n",
1526 I915_READ16(C0DRB3));
1527 seq_printf(m, "C1DRB3 = 0x%04x\n",
1528 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001529 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1530 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1531 I915_READ(MAD_DIMM_C0));
1532 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1533 I915_READ(MAD_DIMM_C1));
1534 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1535 I915_READ(MAD_DIMM_C2));
1536 seq_printf(m, "TILECTL = 0x%08x\n",
1537 I915_READ(TILECTL));
1538 seq_printf(m, "ARB_MODE = 0x%08x\n",
1539 I915_READ(ARB_MODE));
1540 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1541 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001542 }
1543 mutex_unlock(&dev->struct_mutex);
1544
1545 return 0;
1546}
1547
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001548static int i915_ppgtt_info(struct seq_file *m, void *data)
1549{
1550 struct drm_info_node *node = (struct drm_info_node *) m->private;
1551 struct drm_device *dev = node->minor->dev;
1552 struct drm_i915_private *dev_priv = dev->dev_private;
1553 struct intel_ring_buffer *ring;
1554 int i, ret;
1555
1556
1557 ret = mutex_lock_interruptible(&dev->struct_mutex);
1558 if (ret)
1559 return ret;
1560 if (INTEL_INFO(dev)->gen == 6)
1561 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1562
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001563 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001564 seq_printf(m, "%s\n", ring->name);
1565 if (INTEL_INFO(dev)->gen == 7)
1566 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1567 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1568 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1569 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1570 }
1571 if (dev_priv->mm.aliasing_ppgtt) {
1572 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1573
Damien Lespiau267f0c92013-06-24 22:59:48 +01001574 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001575 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1576 }
1577 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1578 mutex_unlock(&dev->struct_mutex);
1579
1580 return 0;
1581}
1582
Jesse Barnes57f350b2012-03-28 13:39:25 -07001583static int i915_dpio_info(struct seq_file *m, void *data)
1584{
1585 struct drm_info_node *node = (struct drm_info_node *) m->private;
1586 struct drm_device *dev = node->minor->dev;
1587 struct drm_i915_private *dev_priv = dev->dev_private;
1588 int ret;
1589
1590
1591 if (!IS_VALLEYVIEW(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001592 seq_puts(m, "unsupported\n");
Jesse Barnes57f350b2012-03-28 13:39:25 -07001593 return 0;
1594 }
1595
Daniel Vetter09153002012-12-12 14:06:44 +01001596 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001597 if (ret)
1598 return ret;
1599
1600 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1601
1602 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001603 vlv_dpio_read(dev_priv, _DPIO_DIV_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001604 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001605 vlv_dpio_read(dev_priv, _DPIO_DIV_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001606
1607 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001608 vlv_dpio_read(dev_priv, _DPIO_REFSFR_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001609 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001610 vlv_dpio_read(dev_priv, _DPIO_REFSFR_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001611
1612 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001613 vlv_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001614 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001615 vlv_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001616
Ville Syrjälä4abb2c32013-06-14 14:02:53 +03001617 seq_printf(m, "DPIO_LPF_COEFF_A: 0x%08x\n",
1618 vlv_dpio_read(dev_priv, _DPIO_LPF_COEFF_A));
1619 seq_printf(m, "DPIO_LPF_COEFF_B: 0x%08x\n",
1620 vlv_dpio_read(dev_priv, _DPIO_LPF_COEFF_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001621
1622 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001623 vlv_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001624
Daniel Vetter09153002012-12-12 14:06:44 +01001625 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001626
1627 return 0;
1628}
1629
Ben Widawsky63573eb2013-07-04 11:02:07 -07001630static int i915_llc(struct seq_file *m, void *data)
1631{
1632 struct drm_info_node *node = (struct drm_info_node *) m->private;
1633 struct drm_device *dev = node->minor->dev;
1634 struct drm_i915_private *dev_priv = dev->dev_private;
1635
1636 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1637 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1638 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1639
1640 return 0;
1641}
1642
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001643static int i915_edp_psr_status(struct seq_file *m, void *data)
1644{
1645 struct drm_info_node *node = m->private;
1646 struct drm_device *dev = node->minor->dev;
1647 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001648 u32 psrstat, psrperf;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001649
1650 if (!IS_HASWELL(dev)) {
1651 seq_puts(m, "PSR not supported on this platform\n");
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001652 } else if (IS_HASWELL(dev) && I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE) {
1653 seq_puts(m, "PSR enabled\n");
1654 } else {
1655 seq_puts(m, "PSR disabled: ");
1656 switch (dev_priv->no_psr_reason) {
1657 case PSR_NO_SOURCE:
1658 seq_puts(m, "not supported on this platform");
1659 break;
1660 case PSR_NO_SINK:
1661 seq_puts(m, "not supported by panel");
1662 break;
Rodrigo Vivi105b7c12013-07-11 18:45:02 -03001663 case PSR_MODULE_PARAM:
1664 seq_puts(m, "disabled by flag");
1665 break;
Rodrigo Vivi3f51e472013-07-11 18:45:00 -03001666 case PSR_CRTC_NOT_ACTIVE:
1667 seq_puts(m, "crtc not active");
1668 break;
1669 case PSR_PWR_WELL_ENABLED:
1670 seq_puts(m, "power well enabled");
1671 break;
1672 case PSR_NOT_TILED:
1673 seq_puts(m, "not tiled");
1674 break;
1675 case PSR_SPRITE_ENABLED:
1676 seq_puts(m, "sprite enabled");
1677 break;
1678 case PSR_S3D_ENABLED:
1679 seq_puts(m, "stereo 3d enabled");
1680 break;
1681 case PSR_INTERLACED_ENABLED:
1682 seq_puts(m, "interlaced enabled");
1683 break;
1684 case PSR_HSW_NOT_DDIA:
1685 seq_puts(m, "HSW ties PSR to DDI A (eDP)");
1686 break;
1687 default:
1688 seq_puts(m, "unknown reason");
1689 }
1690 seq_puts(m, "\n");
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001691 return 0;
1692 }
1693
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001694 psrstat = I915_READ(EDP_PSR_STATUS_CTL);
1695
1696 seq_puts(m, "PSR Current State: ");
1697 switch (psrstat & EDP_PSR_STATUS_STATE_MASK) {
1698 case EDP_PSR_STATUS_STATE_IDLE:
1699 seq_puts(m, "Reset state\n");
1700 break;
1701 case EDP_PSR_STATUS_STATE_SRDONACK:
1702 seq_puts(m, "Wait for TG/Stream to send on frame of data after SRD conditions are met\n");
1703 break;
1704 case EDP_PSR_STATUS_STATE_SRDENT:
1705 seq_puts(m, "SRD entry\n");
1706 break;
1707 case EDP_PSR_STATUS_STATE_BUFOFF:
1708 seq_puts(m, "Wait for buffer turn off\n");
1709 break;
1710 case EDP_PSR_STATUS_STATE_BUFON:
1711 seq_puts(m, "Wait for buffer turn on\n");
1712 break;
1713 case EDP_PSR_STATUS_STATE_AUXACK:
1714 seq_puts(m, "Wait for AUX to acknowledge on SRD exit\n");
1715 break;
1716 case EDP_PSR_STATUS_STATE_SRDOFFACK:
1717 seq_puts(m, "Wait for TG/Stream to acknowledge the SRD VDM exit\n");
1718 break;
1719 default:
1720 seq_puts(m, "Unknown\n");
1721 break;
1722 }
1723
1724 seq_puts(m, "Link Status: ");
1725 switch (psrstat & EDP_PSR_STATUS_LINK_MASK) {
1726 case EDP_PSR_STATUS_LINK_FULL_OFF:
1727 seq_puts(m, "Link is fully off\n");
1728 break;
1729 case EDP_PSR_STATUS_LINK_FULL_ON:
1730 seq_puts(m, "Link is fully on\n");
1731 break;
1732 case EDP_PSR_STATUS_LINK_STANDBY:
1733 seq_puts(m, "Link is in standby\n");
1734 break;
1735 default:
1736 seq_puts(m, "Unknown\n");
1737 break;
1738 }
1739
1740 seq_printf(m, "PSR Entry Count: %u\n",
1741 psrstat >> EDP_PSR_STATUS_COUNT_SHIFT &
1742 EDP_PSR_STATUS_COUNT_MASK);
1743
1744 seq_printf(m, "Max Sleep Timer Counter: %u\n",
1745 psrstat >> EDP_PSR_STATUS_MAX_SLEEP_TIMER_SHIFT &
1746 EDP_PSR_STATUS_MAX_SLEEP_TIMER_MASK);
1747
1748 seq_printf(m, "Had AUX error: %s\n",
1749 yesno(psrstat & EDP_PSR_STATUS_AUX_ERROR));
1750
1751 seq_printf(m, "Sending AUX: %s\n",
1752 yesno(psrstat & EDP_PSR_STATUS_AUX_SENDING));
1753
1754 seq_printf(m, "Sending Idle: %s\n",
1755 yesno(psrstat & EDP_PSR_STATUS_SENDING_IDLE));
1756
1757 seq_printf(m, "Sending TP2 TP3: %s\n",
1758 yesno(psrstat & EDP_PSR_STATUS_SENDING_TP2_TP3));
1759
1760 seq_printf(m, "Sending TP1: %s\n",
1761 yesno(psrstat & EDP_PSR_STATUS_SENDING_TP1));
1762
1763 seq_printf(m, "Idle Count: %u\n",
1764 psrstat & EDP_PSR_STATUS_IDLE_MASK);
1765
1766 psrperf = (I915_READ(EDP_PSR_PERF_CNT)) & EDP_PSR_PERF_CNT_MASK;
1767 seq_printf(m, "Performance Counter: %u\n", psrperf);
1768
1769 return 0;
1770}
1771
Kees Cook647416f2013-03-10 14:10:06 -07001772static int
1773i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001774{
Kees Cook647416f2013-03-10 14:10:06 -07001775 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001776 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001777
Kees Cook647416f2013-03-10 14:10:06 -07001778 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001779
Kees Cook647416f2013-03-10 14:10:06 -07001780 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001781}
1782
Kees Cook647416f2013-03-10 14:10:06 -07001783static int
1784i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001785{
Kees Cook647416f2013-03-10 14:10:06 -07001786 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001787
Kees Cook647416f2013-03-10 14:10:06 -07001788 DRM_INFO("Manually setting wedged to %llu\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001789 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001790
Kees Cook647416f2013-03-10 14:10:06 -07001791 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001792}
1793
Kees Cook647416f2013-03-10 14:10:06 -07001794DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
1795 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001796 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001797
Kees Cook647416f2013-03-10 14:10:06 -07001798static int
1799i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001800{
Kees Cook647416f2013-03-10 14:10:06 -07001801 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001802 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001803
Kees Cook647416f2013-03-10 14:10:06 -07001804 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001805
Kees Cook647416f2013-03-10 14:10:06 -07001806 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001807}
1808
Kees Cook647416f2013-03-10 14:10:06 -07001809static int
1810i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001811{
Kees Cook647416f2013-03-10 14:10:06 -07001812 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001813 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001814 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001815
Kees Cook647416f2013-03-10 14:10:06 -07001816 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001817
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001818 ret = mutex_lock_interruptible(&dev->struct_mutex);
1819 if (ret)
1820 return ret;
1821
Daniel Vetter99584db2012-11-14 17:14:04 +01001822 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001823 mutex_unlock(&dev->struct_mutex);
1824
Kees Cook647416f2013-03-10 14:10:06 -07001825 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001826}
1827
Kees Cook647416f2013-03-10 14:10:06 -07001828DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
1829 i915_ring_stop_get, i915_ring_stop_set,
1830 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02001831
Chris Wilsondd624af2013-01-15 12:39:35 +00001832#define DROP_UNBOUND 0x1
1833#define DROP_BOUND 0x2
1834#define DROP_RETIRE 0x4
1835#define DROP_ACTIVE 0x8
1836#define DROP_ALL (DROP_UNBOUND | \
1837 DROP_BOUND | \
1838 DROP_RETIRE | \
1839 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07001840static int
1841i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00001842{
Kees Cook647416f2013-03-10 14:10:06 -07001843 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00001844
Kees Cook647416f2013-03-10 14:10:06 -07001845 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00001846}
1847
Kees Cook647416f2013-03-10 14:10:06 -07001848static int
1849i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00001850{
Kees Cook647416f2013-03-10 14:10:06 -07001851 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00001852 struct drm_i915_private *dev_priv = dev->dev_private;
1853 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07001854 struct i915_address_space *vm;
1855 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07001856 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00001857
Kees Cook647416f2013-03-10 14:10:06 -07001858 DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00001859
1860 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1861 * on ioctls on -EAGAIN. */
1862 ret = mutex_lock_interruptible(&dev->struct_mutex);
1863 if (ret)
1864 return ret;
1865
1866 if (val & DROP_ACTIVE) {
1867 ret = i915_gpu_idle(dev);
1868 if (ret)
1869 goto unlock;
1870 }
1871
1872 if (val & (DROP_RETIRE | DROP_ACTIVE))
1873 i915_gem_retire_requests(dev);
1874
1875 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07001876 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
1877 list_for_each_entry_safe(vma, x, &vm->inactive_list,
1878 mm_list) {
1879 if (vma->obj->pin_count)
1880 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07001881
Ben Widawskyca191b12013-07-31 17:00:14 -07001882 ret = i915_vma_unbind(vma);
1883 if (ret)
1884 goto unlock;
1885 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07001886 }
Chris Wilsondd624af2013-01-15 12:39:35 +00001887 }
1888
1889 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07001890 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
1891 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00001892 if (obj->pages_pin_count == 0) {
1893 ret = i915_gem_object_put_pages(obj);
1894 if (ret)
1895 goto unlock;
1896 }
1897 }
1898
1899unlock:
1900 mutex_unlock(&dev->struct_mutex);
1901
Kees Cook647416f2013-03-10 14:10:06 -07001902 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00001903}
1904
Kees Cook647416f2013-03-10 14:10:06 -07001905DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
1906 i915_drop_caches_get, i915_drop_caches_set,
1907 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00001908
Kees Cook647416f2013-03-10 14:10:06 -07001909static int
1910i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07001911{
Kees Cook647416f2013-03-10 14:10:06 -07001912 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07001913 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001914 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02001915
1916 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1917 return -ENODEV;
1918
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001919 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001920 if (ret)
1921 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001922
Jesse Barnes0a073b82013-04-17 15:54:58 -07001923 if (IS_VALLEYVIEW(dev))
1924 *val = vlv_gpu_freq(dev_priv->mem_freq,
1925 dev_priv->rps.max_delay);
1926 else
1927 *val = dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001928 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001929
Kees Cook647416f2013-03-10 14:10:06 -07001930 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07001931}
1932
Kees Cook647416f2013-03-10 14:10:06 -07001933static int
1934i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07001935{
Kees Cook647416f2013-03-10 14:10:06 -07001936 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07001937 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001938 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02001939
1940 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1941 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001942
Kees Cook647416f2013-03-10 14:10:06 -07001943 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07001944
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001945 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001946 if (ret)
1947 return ret;
1948
Jesse Barnes358733e2011-07-27 11:53:01 -07001949 /*
1950 * Turbo will still be enabled, but won't go above the set value.
1951 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07001952 if (IS_VALLEYVIEW(dev)) {
1953 val = vlv_freq_opcode(dev_priv->mem_freq, val);
1954 dev_priv->rps.max_delay = val;
1955 gen6_set_rps(dev, val);
1956 } else {
1957 do_div(val, GT_FREQUENCY_MULTIPLIER);
1958 dev_priv->rps.max_delay = val;
1959 gen6_set_rps(dev, val);
1960 }
1961
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001962 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001963
Kees Cook647416f2013-03-10 14:10:06 -07001964 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07001965}
1966
Kees Cook647416f2013-03-10 14:10:06 -07001967DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
1968 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001969 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07001970
Kees Cook647416f2013-03-10 14:10:06 -07001971static int
1972i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07001973{
Kees Cook647416f2013-03-10 14:10:06 -07001974 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07001975 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001976 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02001977
1978 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1979 return -ENODEV;
1980
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001981 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001982 if (ret)
1983 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07001984
Jesse Barnes0a073b82013-04-17 15:54:58 -07001985 if (IS_VALLEYVIEW(dev))
1986 *val = vlv_gpu_freq(dev_priv->mem_freq,
1987 dev_priv->rps.min_delay);
1988 else
1989 *val = dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001990 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07001991
Kees Cook647416f2013-03-10 14:10:06 -07001992 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07001993}
1994
Kees Cook647416f2013-03-10 14:10:06 -07001995static int
1996i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07001997{
Kees Cook647416f2013-03-10 14:10:06 -07001998 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07001999 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002000 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002001
2002 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2003 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07002004
Kees Cook647416f2013-03-10 14:10:06 -07002005 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07002006
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002007 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002008 if (ret)
2009 return ret;
2010
Jesse Barnes1523c312012-05-25 12:34:54 -07002011 /*
2012 * Turbo will still be enabled, but won't go below the set value.
2013 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07002014 if (IS_VALLEYVIEW(dev)) {
2015 val = vlv_freq_opcode(dev_priv->mem_freq, val);
2016 dev_priv->rps.min_delay = val;
2017 valleyview_set_rps(dev, val);
2018 } else {
2019 do_div(val, GT_FREQUENCY_MULTIPLIER);
2020 dev_priv->rps.min_delay = val;
2021 gen6_set_rps(dev, val);
2022 }
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002023 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002024
Kees Cook647416f2013-03-10 14:10:06 -07002025 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07002026}
2027
Kees Cook647416f2013-03-10 14:10:06 -07002028DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
2029 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002030 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07002031
Kees Cook647416f2013-03-10 14:10:06 -07002032static int
2033i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002034{
Kees Cook647416f2013-03-10 14:10:06 -07002035 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002036 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002037 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07002038 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002039
Daniel Vetter004777c2012-08-09 15:07:01 +02002040 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2041 return -ENODEV;
2042
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002043 ret = mutex_lock_interruptible(&dev->struct_mutex);
2044 if (ret)
2045 return ret;
2046
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002047 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2048 mutex_unlock(&dev_priv->dev->struct_mutex);
2049
Kees Cook647416f2013-03-10 14:10:06 -07002050 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002051
Kees Cook647416f2013-03-10 14:10:06 -07002052 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002053}
2054
Kees Cook647416f2013-03-10 14:10:06 -07002055static int
2056i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002057{
Kees Cook647416f2013-03-10 14:10:06 -07002058 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002059 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002060 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002061
Daniel Vetter004777c2012-08-09 15:07:01 +02002062 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2063 return -ENODEV;
2064
Kees Cook647416f2013-03-10 14:10:06 -07002065 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002066 return -EINVAL;
2067
Kees Cook647416f2013-03-10 14:10:06 -07002068 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002069
2070 /* Update the cache sharing policy here as well */
2071 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2072 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2073 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2074 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2075
Kees Cook647416f2013-03-10 14:10:06 -07002076 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002077}
2078
Kees Cook647416f2013-03-10 14:10:06 -07002079DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
2080 i915_cache_sharing_get, i915_cache_sharing_set,
2081 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002082
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002083/* As the drm_debugfs_init() routines are called before dev->dev_private is
2084 * allocated we need to hook into the minor for release. */
2085static int
2086drm_add_fake_info_node(struct drm_minor *minor,
2087 struct dentry *ent,
2088 const void *key)
2089{
2090 struct drm_info_node *node;
2091
2092 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2093 if (node == NULL) {
2094 debugfs_remove(ent);
2095 return -ENOMEM;
2096 }
2097
2098 node->minor = minor;
2099 node->dent = ent;
2100 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002101
2102 mutex_lock(&minor->debugfs_lock);
2103 list_add(&node->list, &minor->debugfs_list);
2104 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002105
2106 return 0;
2107}
2108
Ben Widawsky6d794d42011-04-25 11:25:56 -07002109static int i915_forcewake_open(struct inode *inode, struct file *file)
2110{
2111 struct drm_device *dev = inode->i_private;
2112 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002113
Daniel Vetter075edca2012-01-24 09:44:28 +01002114 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002115 return 0;
2116
Ben Widawsky6d794d42011-04-25 11:25:56 -07002117 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002118
2119 return 0;
2120}
2121
Ben Widawskyc43b5632012-04-16 14:07:40 -07002122static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002123{
2124 struct drm_device *dev = inode->i_private;
2125 struct drm_i915_private *dev_priv = dev->dev_private;
2126
Daniel Vetter075edca2012-01-24 09:44:28 +01002127 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002128 return 0;
2129
Ben Widawsky6d794d42011-04-25 11:25:56 -07002130 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002131
2132 return 0;
2133}
2134
2135static const struct file_operations i915_forcewake_fops = {
2136 .owner = THIS_MODULE,
2137 .open = i915_forcewake_open,
2138 .release = i915_forcewake_release,
2139};
2140
2141static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2142{
2143 struct drm_device *dev = minor->dev;
2144 struct dentry *ent;
2145
2146 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002147 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002148 root, dev,
2149 &i915_forcewake_fops);
2150 if (IS_ERR(ent))
2151 return PTR_ERR(ent);
2152
Ben Widawsky8eb57292011-05-11 15:10:58 -07002153 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002154}
2155
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002156static int i915_debugfs_create(struct dentry *root,
2157 struct drm_minor *minor,
2158 const char *name,
2159 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002160{
2161 struct drm_device *dev = minor->dev;
2162 struct dentry *ent;
2163
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002164 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002165 S_IRUGO | S_IWUSR,
2166 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002167 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002168 if (IS_ERR(ent))
2169 return PTR_ERR(ent);
2170
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002171 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002172}
2173
Ben Gamari27c202a2009-07-01 22:26:52 -04002174static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002175 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002176 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002177 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002178 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002179 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002180 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01002181 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002182 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002183 {"i915_gem_request", i915_gem_request_info, 0},
2184 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002185 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002186 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002187 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2188 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2189 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07002190 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002191 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2192 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2193 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2194 {"i915_inttoext_table", i915_inttoext_table, 0},
2195 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002196 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002197 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002198 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002199 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03002200 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002201 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002202 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002203 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002204 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002205 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002206 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002207 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002208 {"i915_dpio", i915_dpio_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07002209 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002210 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002211};
Ben Gamari27c202a2009-07-01 22:26:52 -04002212#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002213
Ville Syrjälä2b4bd0e2013-08-07 15:11:52 +03002214static struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02002215 const char *name;
2216 const struct file_operations *fops;
2217} i915_debugfs_files[] = {
2218 {"i915_wedged", &i915_wedged_fops},
2219 {"i915_max_freq", &i915_max_freq_fops},
2220 {"i915_min_freq", &i915_min_freq_fops},
2221 {"i915_cache_sharing", &i915_cache_sharing_fops},
2222 {"i915_ring_stop", &i915_ring_stop_fops},
2223 {"i915_gem_drop_caches", &i915_drop_caches_fops},
2224 {"i915_error_state", &i915_error_state_fops},
2225 {"i915_next_seqno", &i915_next_seqno_fops},
2226};
2227
Ben Gamari27c202a2009-07-01 22:26:52 -04002228int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002229{
Daniel Vetter34b96742013-07-04 20:49:44 +02002230 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002231
Ben Widawsky6d794d42011-04-25 11:25:56 -07002232 ret = i915_forcewake_create(minor->debugfs_root, minor);
2233 if (ret)
2234 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002235
Daniel Vetter34b96742013-07-04 20:49:44 +02002236 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
2237 ret = i915_debugfs_create(minor->debugfs_root, minor,
2238 i915_debugfs_files[i].name,
2239 i915_debugfs_files[i].fops);
2240 if (ret)
2241 return ret;
2242 }
Mika Kuoppala40633212012-12-04 15:12:00 +02002243
Ben Gamari27c202a2009-07-01 22:26:52 -04002244 return drm_debugfs_create_files(i915_debugfs_list,
2245 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002246 minor->debugfs_root, minor);
2247}
2248
Ben Gamari27c202a2009-07-01 22:26:52 -04002249void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002250{
Daniel Vetter34b96742013-07-04 20:49:44 +02002251 int i;
2252
Ben Gamari27c202a2009-07-01 22:26:52 -04002253 drm_debugfs_remove_files(i915_debugfs_list,
2254 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002255 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2256 1, minor);
Daniel Vetter34b96742013-07-04 20:49:44 +02002257 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
2258 struct drm_info_list *info_list =
2259 (struct drm_info_list *) i915_debugfs_files[i].fops;
2260
2261 drm_debugfs_remove_files(info_list, 1, minor);
2262 }
Ben Gamari20172632009-02-17 20:08:50 -05002263}
2264
2265#endif /* CONFIG_DEBUG_FS */