blob: 2eb572afbcd37219d6e730d4aa1ebe74b9f90686 [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>
Daniel Vetter4518f612013-01-23 16:16:35 +010033#include <generated/utsrelease.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
Chris Wilson93dfb402011-03-29 16:59:50 -070093static const char *cache_level_str(int type)
Chris Wilson08c18322011-01-10 00:00:24 +000094{
95 switch (type) {
Chris Wilson93dfb402011-03-29 16:59:50 -070096 case I915_CACHE_NONE: return " uncached";
97 case I915_CACHE_LLC: return " snooped (LLC)";
98 case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
Chris Wilson08c18322011-01-10 00:00:24 +000099 default: return "";
100 }
101}
102
Chris Wilson37811fc2010-08-25 22:45:57 +0100103static void
104describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
105{
Kees Cook2563a452013-03-11 12:25:19 -0700106 seq_printf(m, "%pK: %s%s %8zdKiB %02x %02x %d %d %d%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100107 &obj->base,
108 get_pin_flag(obj),
109 get_tiling_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800110 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100111 obj->base.read_domains,
112 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100113 obj->last_read_seqno,
114 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000115 obj->last_fenced_seqno,
Chris Wilson93dfb402011-03-29 16:59:50 -0700116 cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100117 obj->dirty ? " dirty" : "",
118 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
119 if (obj->base.name)
120 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilsonc110a6d2012-08-11 15:41:02 +0100121 if (obj->pin_count)
122 seq_printf(m, " (pinned x %d)", obj->pin_count);
Chris Wilson37811fc2010-08-25 22:45:57 +0100123 if (obj->fence_reg != I915_FENCE_REG_NONE)
124 seq_printf(m, " (fence: %d)", obj->fence_reg);
125 if (obj->gtt_space != NULL)
Chris Wilsona00b10c2010-09-24 21:15:47 +0100126 seq_printf(m, " (gtt offset: %08x, size: %08x)",
127 obj->gtt_offset, (unsigned int)obj->gtt_space->size);
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000128 if (obj->stolen)
129 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000130 if (obj->pin_mappable || obj->fault_mappable) {
131 char s[3], *t = s;
132 if (obj->pin_mappable)
133 *t++ = 'p';
134 if (obj->fault_mappable)
135 *t++ = 'f';
136 *t = '\0';
137 seq_printf(m, " (%s mappable)", s);
138 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100139 if (obj->ring != NULL)
140 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100141}
142
Ben Gamari433e12f2009-02-17 20:08:51 -0500143static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500144{
145 struct drm_info_node *node = (struct drm_info_node *) m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500146 uintptr_t list = (uintptr_t) node->info_ent->data;
147 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500148 struct drm_device *dev = node->minor->dev;
149 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000150 struct drm_i915_gem_object *obj;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100151 size_t total_obj_size, total_gtt_size;
152 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100153
154 ret = mutex_lock_interruptible(&dev->struct_mutex);
155 if (ret)
156 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500157
Ben Gamari433e12f2009-02-17 20:08:51 -0500158 switch (list) {
159 case ACTIVE_LIST:
160 seq_printf(m, "Active:\n");
Chris Wilson69dc4982010-10-19 10:36:51 +0100161 head = &dev_priv->mm.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500162 break;
163 case INACTIVE_LIST:
Ben Gamaria17458f2009-07-01 15:01:36 -0400164 seq_printf(m, "Inactive:\n");
Ben Gamari433e12f2009-02-17 20:08:51 -0500165 head = &dev_priv->mm.inactive_list;
166 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500167 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100168 mutex_unlock(&dev->struct_mutex);
169 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500170 }
171
Chris Wilson8f2480f2010-09-26 11:44:19 +0100172 total_obj_size = total_gtt_size = count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000173 list_for_each_entry(obj, head, mm_list) {
Chris Wilson37811fc2010-08-25 22:45:57 +0100174 seq_printf(m, " ");
Chris Wilson05394f32010-11-08 19:18:58 +0000175 describe_obj(m, obj);
Eric Anholtf4ceda82009-02-17 23:53:41 -0800176 seq_printf(m, "\n");
Chris Wilson05394f32010-11-08 19:18:58 +0000177 total_obj_size += obj->base.size;
178 total_gtt_size += obj->gtt_space->size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100179 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500180 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100181 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700182
Chris Wilson8f2480f2010-09-26 11:44:19 +0100183 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
184 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500185 return 0;
186}
187
Chris Wilson6299f992010-11-24 12:23:44 +0000188#define count_objects(list, member) do { \
189 list_for_each_entry(obj, list, member) { \
190 size += obj->gtt_space->size; \
191 ++count; \
192 if (obj->map_and_fenceable) { \
193 mappable_size += obj->gtt_space->size; \
194 ++mappable_count; \
195 } \
196 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400197} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000198
Chris Wilson73aa8082010-09-30 11:46:12 +0100199static int i915_gem_object_info(struct seq_file *m, void* data)
200{
201 struct drm_info_node *node = (struct drm_info_node *) m->private;
202 struct drm_device *dev = node->minor->dev;
203 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200204 u32 count, mappable_count, purgeable_count;
205 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000206 struct drm_i915_gem_object *obj;
Chris Wilson73aa8082010-09-30 11:46:12 +0100207 int ret;
208
209 ret = mutex_lock_interruptible(&dev->struct_mutex);
210 if (ret)
211 return ret;
212
Chris Wilson6299f992010-11-24 12:23:44 +0000213 seq_printf(m, "%u objects, %zu bytes\n",
214 dev_priv->mm.object_count,
215 dev_priv->mm.object_memory);
216
217 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200218 count_objects(&dev_priv->mm.bound_list, gtt_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000219 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
220 count, mappable_count, size, mappable_size);
221
222 size = count = mappable_size = mappable_count = 0;
223 count_objects(&dev_priv->mm.active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000224 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
225 count, mappable_count, size, mappable_size);
226
227 size = count = mappable_size = mappable_count = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000228 count_objects(&dev_priv->mm.inactive_list, mm_list);
229 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
230 count, mappable_count, size, mappable_size);
231
Chris Wilsonb7abb712012-08-20 11:33:30 +0200232 size = count = purgeable_size = purgeable_count = 0;
233 list_for_each_entry(obj, &dev_priv->mm.unbound_list, gtt_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200234 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200235 if (obj->madv == I915_MADV_DONTNEED)
236 purgeable_size += obj->base.size, ++purgeable_count;
237 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200238 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
239
Chris Wilson6299f992010-11-24 12:23:44 +0000240 size = count = mappable_size = mappable_count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200241 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000242 if (obj->fault_mappable) {
243 size += obj->gtt_space->size;
244 ++count;
245 }
246 if (obj->pin_mappable) {
247 mappable_size += obj->gtt_space->size;
248 ++mappable_count;
249 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200250 if (obj->madv == I915_MADV_DONTNEED) {
251 purgeable_size += obj->base.size;
252 ++purgeable_count;
253 }
Chris Wilson6299f992010-11-24 12:23:44 +0000254 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200255 seq_printf(m, "%u purgeable objects, %zu bytes\n",
256 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000257 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
258 mappable_count, mappable_size);
259 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
260 count, size);
261
Ben Widawsky93d18792013-01-17 12:45:17 -0800262 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky5d4545a2013-01-17 12:45:15 -0800263 dev_priv->gtt.total,
264 dev_priv->gtt.mappable_end - dev_priv->gtt.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100265
266 mutex_unlock(&dev->struct_mutex);
267
268 return 0;
269}
270
Chris Wilson08c18322011-01-10 00:00:24 +0000271static int i915_gem_gtt_info(struct seq_file *m, void* data)
272{
273 struct drm_info_node *node = (struct drm_info_node *) m->private;
274 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100275 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000276 struct drm_i915_private *dev_priv = dev->dev_private;
277 struct drm_i915_gem_object *obj;
278 size_t total_obj_size, total_gtt_size;
279 int count, ret;
280
281 ret = mutex_lock_interruptible(&dev->struct_mutex);
282 if (ret)
283 return ret;
284
285 total_obj_size = total_gtt_size = count = 0;
Chris Wilson6c085a72012-08-20 11:40:46 +0200286 list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list) {
Chris Wilson1b502472012-04-24 15:47:30 +0100287 if (list == PINNED_LIST && obj->pin_count == 0)
288 continue;
289
Chris Wilson08c18322011-01-10 00:00:24 +0000290 seq_printf(m, " ");
291 describe_obj(m, obj);
292 seq_printf(m, "\n");
293 total_obj_size += obj->base.size;
294 total_gtt_size += obj->gtt_space->size;
295 count++;
296 }
297
298 mutex_unlock(&dev->struct_mutex);
299
300 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
301 count, total_obj_size, total_gtt_size);
302
303 return 0;
304}
305
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100306static int i915_gem_pageflip_info(struct seq_file *m, void *data)
307{
308 struct drm_info_node *node = (struct drm_info_node *) m->private;
309 struct drm_device *dev = node->minor->dev;
310 unsigned long flags;
311 struct intel_crtc *crtc;
312
313 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800314 const char pipe = pipe_name(crtc->pipe);
315 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100316 struct intel_unpin_work *work;
317
318 spin_lock_irqsave(&dev->event_lock, flags);
319 work = crtc->unpin_work;
320 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800321 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100322 pipe, plane);
323 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000324 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800325 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100326 pipe, plane);
327 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800328 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100329 pipe, plane);
330 }
331 if (work->enable_stall_check)
332 seq_printf(m, "Stall check enabled, ");
333 else
334 seq_printf(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000335 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100336
337 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000338 struct drm_i915_gem_object *obj = work->old_fb_obj;
339 if (obj)
340 seq_printf(m, "Old framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100341 }
342 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000343 struct drm_i915_gem_object *obj = work->pending_flip_obj;
344 if (obj)
345 seq_printf(m, "New framebuffer gtt_offset 0x%08x\n", obj->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100346 }
347 }
348 spin_unlock_irqrestore(&dev->event_lock, flags);
349 }
350
351 return 0;
352}
353
Ben Gamari20172632009-02-17 20:08:50 -0500354static int i915_gem_request_info(struct seq_file *m, void *data)
355{
356 struct drm_info_node *node = (struct drm_info_node *) m->private;
357 struct drm_device *dev = node->minor->dev;
358 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100359 struct intel_ring_buffer *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500360 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100361 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100362
363 ret = mutex_lock_interruptible(&dev->struct_mutex);
364 if (ret)
365 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500366
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100367 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100368 for_each_ring(ring, dev_priv, i) {
369 if (list_empty(&ring->request_list))
370 continue;
371
372 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100373 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100374 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100375 list) {
376 seq_printf(m, " %d @ %d\n",
377 gem_request->seqno,
378 (int) (jiffies - gem_request->emitted_jiffies));
379 }
380 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500381 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100382 mutex_unlock(&dev->struct_mutex);
383
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100384 if (count == 0)
385 seq_printf(m, "No requests\n");
386
Ben Gamari20172632009-02-17 20:08:50 -0500387 return 0;
388}
389
Chris Wilsonb2223492010-10-27 15:27:33 +0100390static void i915_ring_seqno_info(struct seq_file *m,
391 struct intel_ring_buffer *ring)
392{
393 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200394 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100395 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100396 }
397}
398
Ben Gamari20172632009-02-17 20:08:50 -0500399static int i915_gem_seqno_info(struct seq_file *m, void *data)
400{
401 struct drm_info_node *node = (struct drm_info_node *) m->private;
402 struct drm_device *dev = node->minor->dev;
403 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100404 struct intel_ring_buffer *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000405 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100406
407 ret = mutex_lock_interruptible(&dev->struct_mutex);
408 if (ret)
409 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500410
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100411 for_each_ring(ring, dev_priv, i)
412 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100413
414 mutex_unlock(&dev->struct_mutex);
415
Ben Gamari20172632009-02-17 20:08:50 -0500416 return 0;
417}
418
419
420static int i915_interrupt_info(struct seq_file *m, void *data)
421{
422 struct drm_info_node *node = (struct drm_info_node *) m->private;
423 struct drm_device *dev = node->minor->dev;
424 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100425 struct intel_ring_buffer *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800426 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100427
428 ret = mutex_lock_interruptible(&dev->struct_mutex);
429 if (ret)
430 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500431
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700432 if (IS_VALLEYVIEW(dev)) {
433 seq_printf(m, "Display IER:\t%08x\n",
434 I915_READ(VLV_IER));
435 seq_printf(m, "Display IIR:\t%08x\n",
436 I915_READ(VLV_IIR));
437 seq_printf(m, "Display IIR_RW:\t%08x\n",
438 I915_READ(VLV_IIR_RW));
439 seq_printf(m, "Display IMR:\t%08x\n",
440 I915_READ(VLV_IMR));
441 for_each_pipe(pipe)
442 seq_printf(m, "Pipe %c stat:\t%08x\n",
443 pipe_name(pipe),
444 I915_READ(PIPESTAT(pipe)));
445
446 seq_printf(m, "Master IER:\t%08x\n",
447 I915_READ(VLV_MASTER_IER));
448
449 seq_printf(m, "Render IER:\t%08x\n",
450 I915_READ(GTIER));
451 seq_printf(m, "Render IIR:\t%08x\n",
452 I915_READ(GTIIR));
453 seq_printf(m, "Render IMR:\t%08x\n",
454 I915_READ(GTIMR));
455
456 seq_printf(m, "PM IER:\t\t%08x\n",
457 I915_READ(GEN6_PMIER));
458 seq_printf(m, "PM IIR:\t\t%08x\n",
459 I915_READ(GEN6_PMIIR));
460 seq_printf(m, "PM IMR:\t\t%08x\n",
461 I915_READ(GEN6_PMIMR));
462
463 seq_printf(m, "Port hotplug:\t%08x\n",
464 I915_READ(PORT_HOTPLUG_EN));
465 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
466 I915_READ(VLV_DPFLIPSTAT));
467 seq_printf(m, "DPINVGTT:\t%08x\n",
468 I915_READ(DPINVGTT));
469
470 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800471 seq_printf(m, "Interrupt enable: %08x\n",
472 I915_READ(IER));
473 seq_printf(m, "Interrupt identity: %08x\n",
474 I915_READ(IIR));
475 seq_printf(m, "Interrupt mask: %08x\n",
476 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800477 for_each_pipe(pipe)
478 seq_printf(m, "Pipe %c stat: %08x\n",
479 pipe_name(pipe),
480 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800481 } else {
482 seq_printf(m, "North Display Interrupt enable: %08x\n",
483 I915_READ(DEIER));
484 seq_printf(m, "North Display Interrupt identity: %08x\n",
485 I915_READ(DEIIR));
486 seq_printf(m, "North Display Interrupt mask: %08x\n",
487 I915_READ(DEIMR));
488 seq_printf(m, "South Display Interrupt enable: %08x\n",
489 I915_READ(SDEIER));
490 seq_printf(m, "South Display Interrupt identity: %08x\n",
491 I915_READ(SDEIIR));
492 seq_printf(m, "South Display Interrupt mask: %08x\n",
493 I915_READ(SDEIMR));
494 seq_printf(m, "Graphics Interrupt enable: %08x\n",
495 I915_READ(GTIER));
496 seq_printf(m, "Graphics Interrupt identity: %08x\n",
497 I915_READ(GTIIR));
498 seq_printf(m, "Graphics Interrupt mask: %08x\n",
499 I915_READ(GTIMR));
500 }
Ben Gamari20172632009-02-17 20:08:50 -0500501 seq_printf(m, "Interrupts received: %d\n",
502 atomic_read(&dev_priv->irq_received));
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100503 for_each_ring(ring, dev_priv, i) {
Jesse Barnesda64c6f2011-08-09 09:17:46 -0700504 if (IS_GEN6(dev) || IS_GEN7(dev)) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100505 seq_printf(m,
506 "Graphics Interrupt mask (%s): %08x\n",
507 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000508 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100509 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000510 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100511 mutex_unlock(&dev->struct_mutex);
512
Ben Gamari20172632009-02-17 20:08:50 -0500513 return 0;
514}
515
Chris Wilsona6172a82009-02-11 14:26:38 +0000516static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
517{
518 struct drm_info_node *node = (struct drm_info_node *) m->private;
519 struct drm_device *dev = node->minor->dev;
520 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100521 int i, ret;
522
523 ret = mutex_lock_interruptible(&dev->struct_mutex);
524 if (ret)
525 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000526
527 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
528 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
529 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000530 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000531
Chris Wilson6c085a72012-08-20 11:40:46 +0200532 seq_printf(m, "Fence %d, pin count = %d, object = ",
533 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100534 if (obj == NULL)
535 seq_printf(m, "unused");
536 else
Chris Wilson05394f32010-11-08 19:18:58 +0000537 describe_obj(m, obj);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100538 seq_printf(m, "\n");
Chris Wilsona6172a82009-02-11 14:26:38 +0000539 }
540
Chris Wilson05394f32010-11-08 19:18:58 +0000541 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000542 return 0;
543}
544
Ben Gamari20172632009-02-17 20:08:50 -0500545static int i915_hws_info(struct seq_file *m, void *data)
546{
547 struct drm_info_node *node = (struct drm_info_node *) m->private;
548 struct drm_device *dev = node->minor->dev;
549 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100550 struct intel_ring_buffer *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100551 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100552 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500553
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000554 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100555 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500556 if (hws == NULL)
557 return 0;
558
559 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
560 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
561 i * 4,
562 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
563 }
564 return 0;
565}
566
Chris Wilsone5c65262010-11-01 11:35:28 +0000567static const char *ring_str(int ring)
568{
569 switch (ring) {
Daniel Vetter96154f22011-12-14 13:57:00 +0100570 case RCS: return "render";
571 case VCS: return "bsd";
572 case BCS: return "blt";
Chris Wilsone5c65262010-11-01 11:35:28 +0000573 default: return "";
574 }
575}
576
Chris Wilson9df30792010-02-18 10:24:56 +0000577static const char *pin_flag(int pinned)
578{
579 if (pinned > 0)
580 return " P";
581 else if (pinned < 0)
582 return " p";
583 else
584 return "";
585}
586
587static const char *tiling_flag(int tiling)
588{
589 switch (tiling) {
590 default:
591 case I915_TILING_NONE: return "";
592 case I915_TILING_X: return " X";
593 case I915_TILING_Y: return " Y";
594 }
595}
596
597static const char *dirty_flag(int dirty)
598{
599 return dirty ? " dirty" : "";
600}
601
602static const char *purgeable_flag(int purgeable)
603{
604 return purgeable ? " purgeable" : "";
605}
606
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300607static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
608 const char *f, va_list args)
609{
610 unsigned len;
611
612 if (!e->err && WARN(e->bytes > (e->size - 1), "overflow")) {
613 e->err = -ENOSPC;
614 return;
615 }
616
617 if (e->bytes == e->size - 1 || e->err)
618 return;
619
620 /* Seek the first printf which is hits start position */
621 if (e->pos < e->start) {
622 len = vsnprintf(NULL, 0, f, args);
623 if (e->pos + len <= e->start) {
624 e->pos += len;
625 return;
626 }
627
628 /* First vsnprintf needs to fit in full for memmove*/
629 if (len >= e->size) {
630 e->err = -EIO;
631 return;
632 }
633 }
634
635 len = vsnprintf(e->buf + e->bytes, e->size - e->bytes, f, args);
636 if (len >= e->size - e->bytes)
637 len = e->size - e->bytes - 1;
638
639 /* If this is first printf in this window, adjust it so that
640 * start position matches start of the buffer
641 */
642 if (e->pos < e->start) {
643 const size_t off = e->start - e->pos;
644
645 /* Should not happen but be paranoid */
646 if (off > len || e->bytes) {
647 e->err = -EIO;
648 return;
649 }
650
651 memmove(e->buf, e->buf + off, len - off);
652 e->bytes = len - off;
653 e->pos = e->start;
654 return;
655 }
656
657 e->bytes += len;
658 e->pos += len;
659}
660
661void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
662{
663 va_list args;
664
665 va_start(args, f);
666 i915_error_vprintf(e, f, args);
667 va_end(args);
668}
669
670#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
671
672static void print_error_buffers(struct drm_i915_error_state_buf *m,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000673 const char *name,
674 struct drm_i915_error_buffer *err,
675 int count)
676{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300677 err_printf(m, "%s [%d]:\n", name, count);
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000678
679 while (count--) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300680 err_printf(m, " %08x %8u %02x %02x %x %x%s%s%s%s%s%s%s",
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000681 err->gtt_offset,
682 err->size,
683 err->read_domains,
684 err->write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100685 err->rseqno, err->wseqno,
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000686 pin_flag(err->pinned),
687 tiling_flag(err->tiling),
688 dirty_flag(err->dirty),
689 purgeable_flag(err->purgeable),
Daniel Vetter96154f22011-12-14 13:57:00 +0100690 err->ring != -1 ? " " : "",
Chris Wilsona779e5a2011-01-09 21:07:49 +0000691 ring_str(err->ring),
Chris Wilson93dfb402011-03-29 16:59:50 -0700692 cache_level_str(err->cache_level));
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000693
694 if (err->name)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300695 err_printf(m, " (name: %d)", err->name);
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000696 if (err->fence_reg != I915_FENCE_REG_NONE)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300697 err_printf(m, " (fence: %d)", err->fence_reg);
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000698
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300699 err_printf(m, "\n");
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000700 err++;
701 }
702}
703
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300704static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100705 struct drm_device *dev,
706 struct drm_i915_error_state *error,
707 unsigned ring)
708{
Ben Widawskyec34a012012-04-03 23:03:00 -0700709 BUG_ON(ring >= I915_NUM_RINGS); /* shut up confused gcc */
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300710 err_printf(m, "%s command stream:\n", ring_str(ring));
711 err_printf(m, " HEAD: 0x%08x\n", error->head[ring]);
712 err_printf(m, " TAIL: 0x%08x\n", error->tail[ring]);
713 err_printf(m, " CTL: 0x%08x\n", error->ctl[ring]);
714 err_printf(m, " ACTHD: 0x%08x\n", error->acthd[ring]);
715 err_printf(m, " IPEIR: 0x%08x\n", error->ipeir[ring]);
716 err_printf(m, " IPEHR: 0x%08x\n", error->ipehr[ring]);
717 err_printf(m, " INSTDONE: 0x%08x\n", error->instdone[ring]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700718 if (ring == RCS && INTEL_INFO(dev)->gen >= 4)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300719 err_printf(m, " BBADDR: 0x%08llx\n", error->bbaddr);
Ben Widawsky050ee912012-08-22 11:32:15 -0700720
Daniel Vetterc1cd90e2011-12-14 13:57:02 +0100721 if (INTEL_INFO(dev)->gen >= 4)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300722 err_printf(m, " INSTPS: 0x%08x\n", error->instps[ring]);
723 err_printf(m, " INSTPM: 0x%08x\n", error->instpm[ring]);
724 err_printf(m, " FADDR: 0x%08x\n", error->faddr[ring]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100725 if (INTEL_INFO(dev)->gen >= 6) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300726 err_printf(m, " RC PSMI: 0x%08x\n", error->rc_psmi[ring]);
727 err_printf(m, " FAULT_REG: 0x%08x\n", error->fault_reg[ring]);
728 err_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
Chris Wilsondf2b23d2012-11-27 17:06:54 +0000729 error->semaphore_mboxes[ring][0],
730 error->semaphore_seqno[ring][0]);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300731 err_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
Chris Wilsondf2b23d2012-11-27 17:06:54 +0000732 error->semaphore_mboxes[ring][1],
733 error->semaphore_seqno[ring][1]);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100734 }
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300735 err_printf(m, " seqno: 0x%08x\n", error->seqno[ring]);
736 err_printf(m, " waiting: %s\n", yesno(error->waiting[ring]));
737 err_printf(m, " ring->head: 0x%08x\n", error->cpu_ring_head[ring]);
738 err_printf(m, " ring->tail: 0x%08x\n", error->cpu_ring_tail[ring]);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100739}
740
Daniel Vetterd5442302012-04-27 15:17:40 +0200741struct i915_error_state_file_priv {
742 struct drm_device *dev;
743 struct drm_i915_error_state *error;
744};
745
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300746
747static int i915_error_state(struct i915_error_state_file_priv *error_priv,
748 struct drm_i915_error_state_buf *m)
749
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700750{
Daniel Vetterd5442302012-04-27 15:17:40 +0200751 struct drm_device *dev = error_priv->dev;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700752 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200753 struct drm_i915_error_state *error = error_priv->error;
Chris Wilsonb4519512012-05-11 14:29:30 +0100754 struct intel_ring_buffer *ring;
Chris Wilson52d39a22012-02-15 11:25:37 +0000755 int i, j, page, offset, elt;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700756
Daniel Vetter742cbee2012-04-27 15:17:39 +0200757 if (!error) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300758 err_printf(m, "no error state collected\n");
Daniel Vetter742cbee2012-04-27 15:17:39 +0200759 return 0;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700760 }
761
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300762 err_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
Jesse Barnes8a905232009-07-11 16:48:03 -0400763 error->time.tv_usec);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300764 err_printf(m, "Kernel: " UTS_RELEASE "\n");
765 err_printf(m, "PCI ID: 0x%04x\n", dev->pci_device);
766 err_printf(m, "EIR: 0x%08x\n", error->eir);
767 err_printf(m, "IER: 0x%08x\n", error->ier);
768 err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
769 err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
770 err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
771 err_printf(m, "CCID: 0x%08x\n", error->ccid);
Chris Wilson9df30792010-02-18 10:24:56 +0000772
Daniel Vetterbf3301a2011-05-12 22:17:12 +0100773 for (i = 0; i < dev_priv->num_fence_regs; i++)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300774 err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
Chris Wilson748ebc62010-10-24 10:28:47 +0100775
Ben Widawsky050ee912012-08-22 11:32:15 -0700776 for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300777 err_printf(m, " INSTDONE_%d: 0x%08x\n", i,
778 error->extra_instdone[i]);
Ben Widawsky050ee912012-08-22 11:32:15 -0700779
Daniel Vetter33f3f512011-12-14 13:57:39 +0100780 if (INTEL_INFO(dev)->gen >= 6) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300781 err_printf(m, "ERROR: 0x%08x\n", error->error);
782 err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
Daniel Vetter33f3f512011-12-14 13:57:39 +0100783 }
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100784
Ben Widawsky71e172e2012-08-20 16:15:13 -0700785 if (INTEL_INFO(dev)->gen == 7)
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300786 err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
Ben Widawsky71e172e2012-08-20 16:15:13 -0700787
Chris Wilsonb4519512012-05-11 14:29:30 +0100788 for_each_ring(ring, dev_priv, i)
789 i915_ring_error_state(m, dev, error, i);
Daniel Vetterd27b1e02011-12-14 13:57:01 +0100790
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000791 if (error->active_bo)
792 print_error_buffers(m, "Active",
793 error->active_bo,
794 error->active_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000795
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000796 if (error->pinned_bo)
797 print_error_buffers(m, "Pinned",
798 error->pinned_bo,
799 error->pinned_bo_count);
Chris Wilson9df30792010-02-18 10:24:56 +0000800
Chris Wilson52d39a22012-02-15 11:25:37 +0000801 for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
802 struct drm_i915_error_object *obj;
Chris Wilson9df30792010-02-18 10:24:56 +0000803
Chris Wilson52d39a22012-02-15 11:25:37 +0000804 if ((obj = error->ring[i].batchbuffer)) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300805 err_printf(m, "%s --- gtt_offset = 0x%08x\n",
Chris Wilsonbcfb2e22011-01-07 21:06:07 +0000806 dev_priv->ring[i].name,
807 obj->gtt_offset);
Chris Wilson9df30792010-02-18 10:24:56 +0000808 offset = 0;
809 for (page = 0; page < obj->page_count; page++) {
810 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300811 err_printf(m, "%08x : %08x\n", offset,
812 obj->pages[page][elt]);
Chris Wilson9df30792010-02-18 10:24:56 +0000813 offset += 4;
814 }
815 }
816 }
Chris Wilson9df30792010-02-18 10:24:56 +0000817
Chris Wilson52d39a22012-02-15 11:25:37 +0000818 if (error->ring[i].num_requests) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300819 err_printf(m, "%s --- %d requests\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000820 dev_priv->ring[i].name,
821 error->ring[i].num_requests);
822 for (j = 0; j < error->ring[i].num_requests; j++) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300823 err_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
Chris Wilson52d39a22012-02-15 11:25:37 +0000824 error->ring[i].requests[j].seqno,
Chris Wilsonee4f42b2012-02-15 11:25:38 +0000825 error->ring[i].requests[j].jiffies,
826 error->ring[i].requests[j].tail);
Chris Wilson52d39a22012-02-15 11:25:37 +0000827 }
828 }
829
830 if ((obj = error->ring[i].ringbuffer)) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300831 err_printf(m, "%s --- ringbuffer = 0x%08x\n",
Chris Wilsone2f973d2011-01-27 19:15:11 +0000832 dev_priv->ring[i].name,
833 obj->gtt_offset);
834 offset = 0;
835 for (page = 0; page < obj->page_count; page++) {
836 for (elt = 0; elt < PAGE_SIZE/4; elt++) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300837 err_printf(m, "%08x : %08x\n",
Chris Wilsone2f973d2011-01-27 19:15:11 +0000838 offset,
839 obj->pages[page][elt]);
840 offset += 4;
841 }
Chris Wilson9df30792010-02-18 10:24:56 +0000842 }
843 }
Ben Widawsky8c123e52013-03-04 17:00:29 -0800844
845 obj = error->ring[i].ctx;
846 if (obj) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300847 err_printf(m, "%s --- HW Context = 0x%08x\n",
Ben Widawsky8c123e52013-03-04 17:00:29 -0800848 dev_priv->ring[i].name,
849 obj->gtt_offset);
850 offset = 0;
851 for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300852 err_printf(m, "[%04x] %08x %08x %08x %08x\n",
Ben Widawsky8c123e52013-03-04 17:00:29 -0800853 offset,
854 obj->pages[0][elt],
855 obj->pages[0][elt+1],
856 obj->pages[0][elt+2],
857 obj->pages[0][elt+3]);
858 offset += 16;
859 }
860 }
Chris Wilson9df30792010-02-18 10:24:56 +0000861 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700862
Chris Wilson6ef3d422010-08-04 20:26:07 +0100863 if (error->overlay)
864 intel_overlay_print_error_state(m, error->overlay);
865
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000866 if (error->display)
867 intel_display_print_error_state(m, dev, error->display);
868
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700869 return 0;
870}
Ben Gamari6911a9b2009-04-02 11:24:54 -0700871
Daniel Vetterd5442302012-04-27 15:17:40 +0200872static ssize_t
873i915_error_state_write(struct file *filp,
874 const char __user *ubuf,
875 size_t cnt,
876 loff_t *ppos)
877{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300878 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200879 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200880 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200881
882 DRM_DEBUG_DRIVER("Resetting error state\n");
883
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200884 ret = mutex_lock_interruptible(&dev->struct_mutex);
885 if (ret)
886 return ret;
887
Daniel Vetterd5442302012-04-27 15:17:40 +0200888 i915_destroy_error_state(dev);
889 mutex_unlock(&dev->struct_mutex);
890
891 return cnt;
892}
893
894static int i915_error_state_open(struct inode *inode, struct file *file)
895{
896 struct drm_device *dev = inode->i_private;
897 drm_i915_private_t *dev_priv = dev->dev_private;
898 struct i915_error_state_file_priv *error_priv;
899 unsigned long flags;
900
901 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
902 if (!error_priv)
903 return -ENOMEM;
904
905 error_priv->dev = dev;
906
Daniel Vetter99584db2012-11-14 17:14:04 +0100907 spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
908 error_priv->error = dev_priv->gpu_error.first_error;
Daniel Vetterd5442302012-04-27 15:17:40 +0200909 if (error_priv->error)
910 kref_get(&error_priv->error->ref);
Daniel Vetter99584db2012-11-14 17:14:04 +0100911 spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
Daniel Vetterd5442302012-04-27 15:17:40 +0200912
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300913 file->private_data = error_priv;
914
915 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200916}
917
918static int i915_error_state_release(struct inode *inode, struct file *file)
919{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300920 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200921
922 if (error_priv->error)
923 kref_put(&error_priv->error->ref, i915_error_state_free);
924 kfree(error_priv);
925
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300926 return 0;
927}
928
929static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
930 size_t count, loff_t *pos)
931{
932 struct i915_error_state_file_priv *error_priv = file->private_data;
933 struct drm_i915_error_state_buf error_str;
934 loff_t tmp_pos = 0;
935 ssize_t ret_count = 0;
936 int ret = 0;
937
938 memset(&error_str, 0, sizeof(error_str));
939
940 /* We need to have enough room to store any i915_error_state printf
941 * so that we can move it to start position.
942 */
943 error_str.size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
944 error_str.buf = kmalloc(error_str.size,
945 GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN);
946
947 if (error_str.buf == NULL) {
948 error_str.size = PAGE_SIZE;
949 error_str.buf = kmalloc(error_str.size, GFP_TEMPORARY);
950 }
951
952 if (error_str.buf == NULL) {
953 error_str.size = 128;
954 error_str.buf = kmalloc(error_str.size, GFP_TEMPORARY);
955 }
956
957 if (error_str.buf == NULL)
958 return -ENOMEM;
959
960 error_str.start = *pos;
961
962 ret = i915_error_state(error_priv, &error_str);
963 if (ret)
964 goto out;
965
966 if (error_str.bytes == 0 && error_str.err) {
967 ret = error_str.err;
968 goto out;
969 }
970
971 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
972 error_str.buf,
973 error_str.bytes);
974
975 if (ret_count < 0)
976 ret = ret_count;
977 else
978 *pos = error_str.start + ret_count;
979out:
980 kfree(error_str.buf);
981 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200982}
983
984static const struct file_operations i915_error_state_fops = {
985 .owner = THIS_MODULE,
986 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300987 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200988 .write = i915_error_state_write,
989 .llseek = default_llseek,
990 .release = i915_error_state_release,
991};
992
Kees Cook647416f2013-03-10 14:10:06 -0700993static int
994i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200995{
Kees Cook647416f2013-03-10 14:10:06 -0700996 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200997 drm_i915_private_t *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200998 int ret;
999
1000 ret = mutex_lock_interruptible(&dev->struct_mutex);
1001 if (ret)
1002 return ret;
1003
Kees Cook647416f2013-03-10 14:10:06 -07001004 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001005 mutex_unlock(&dev->struct_mutex);
1006
Kees Cook647416f2013-03-10 14:10:06 -07001007 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001008}
1009
Kees Cook647416f2013-03-10 14:10:06 -07001010static int
1011i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001012{
Kees Cook647416f2013-03-10 14:10:06 -07001013 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001014 int ret;
1015
Mika Kuoppala40633212012-12-04 15:12:00 +02001016 ret = mutex_lock_interruptible(&dev->struct_mutex);
1017 if (ret)
1018 return ret;
1019
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001020 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001021 mutex_unlock(&dev->struct_mutex);
1022
Kees Cook647416f2013-03-10 14:10:06 -07001023 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001024}
1025
Kees Cook647416f2013-03-10 14:10:06 -07001026DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1027 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001028 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001029
Jesse Barnesf97108d2010-01-29 11:27:07 -08001030static int i915_rstdby_delays(struct seq_file *m, void *unused)
1031{
1032 struct drm_info_node *node = (struct drm_info_node *) m->private;
1033 struct drm_device *dev = node->minor->dev;
1034 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001035 u16 crstanddelay;
1036 int ret;
1037
1038 ret = mutex_lock_interruptible(&dev->struct_mutex);
1039 if (ret)
1040 return ret;
1041
1042 crstanddelay = I915_READ16(CRSTANDVID);
1043
1044 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001045
1046 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
1047
1048 return 0;
1049}
1050
1051static int i915_cur_delayinfo(struct seq_file *m, void *unused)
1052{
1053 struct drm_info_node *node = (struct drm_info_node *) m->private;
1054 struct drm_device *dev = node->minor->dev;
1055 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001056 int ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001057
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001058 if (IS_GEN5(dev)) {
1059 u16 rgvswctl = I915_READ16(MEMSWCTL);
1060 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1061
1062 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1063 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1064 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1065 MEMSTAT_VID_SHIFT);
1066 seq_printf(m, "Current P-state: %d\n",
1067 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001068 } else if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001069 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1070 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1071 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001072 u32 rpstat, cagf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001073 u32 rpupei, rpcurup, rpprevup;
1074 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001075 int max_freq;
1076
1077 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001078 ret = mutex_lock_interruptible(&dev->struct_mutex);
1079 if (ret)
1080 return ret;
1081
Ben Widawskyfcca7922011-04-25 11:23:07 -07001082 gen6_gt_force_wake_get(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001083
Jesse Barnesccab5c82011-01-18 15:49:25 -08001084 rpstat = I915_READ(GEN6_RPSTAT1);
1085 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1086 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1087 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1088 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1089 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1090 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001091 if (IS_HASWELL(dev))
1092 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1093 else
1094 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1095 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001096
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001097 gen6_gt_force_wake_put(dev_priv);
1098 mutex_unlock(&dev->struct_mutex);
1099
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001100 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001101 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001102 seq_printf(m, "Render p-state ratio: %d\n",
1103 (gt_perf_status & 0xff00) >> 8);
1104 seq_printf(m, "Render p-state VID: %d\n",
1105 gt_perf_status & 0xff);
1106 seq_printf(m, "Render p-state limit: %d\n",
1107 rp_state_limits & 0xff);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001108 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001109 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1110 GEN6_CURICONT_MASK);
1111 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1112 GEN6_CURBSYTAVG_MASK);
1113 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1114 GEN6_CURBSYTAVG_MASK);
1115 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1116 GEN6_CURIAVG_MASK);
1117 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1118 GEN6_CURBSYTAVG_MASK);
1119 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1120 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001121
1122 max_freq = (rp_state_cap & 0xff0000) >> 16;
1123 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001124 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001125
1126 max_freq = (rp_state_cap & 0xff00) >> 8;
1127 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001128 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001129
1130 max_freq = rp_state_cap & 0xff;
1131 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001132 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001133
1134 seq_printf(m, "Max overclocked frequency: %dMHz\n",
1135 dev_priv->rps.hw_max * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001136 } else if (IS_VALLEYVIEW(dev)) {
1137 u32 freq_sts, val;
1138
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001139 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001140 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001141 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1142 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1143
Jani Nikula64936252013-05-22 15:36:20 +03001144 val = vlv_punit_read(dev_priv, PUNIT_FUSE_BUS1);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001145 seq_printf(m, "max GPU freq: %d MHz\n",
1146 vlv_gpu_freq(dev_priv->mem_freq, val));
1147
Jani Nikula64936252013-05-22 15:36:20 +03001148 val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001149 seq_printf(m, "min GPU freq: %d MHz\n",
1150 vlv_gpu_freq(dev_priv->mem_freq, val));
1151
1152 seq_printf(m, "current GPU freq: %d MHz\n",
1153 vlv_gpu_freq(dev_priv->mem_freq,
1154 (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001155 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001156 } else {
1157 seq_printf(m, "no P-state info available\n");
1158 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001159
1160 return 0;
1161}
1162
1163static int i915_delayfreq_table(struct seq_file *m, void *unused)
1164{
1165 struct drm_info_node *node = (struct drm_info_node *) m->private;
1166 struct drm_device *dev = node->minor->dev;
1167 drm_i915_private_t *dev_priv = dev->dev_private;
1168 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001169 int ret, i;
1170
1171 ret = mutex_lock_interruptible(&dev->struct_mutex);
1172 if (ret)
1173 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001174
1175 for (i = 0; i < 16; i++) {
1176 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001177 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1178 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001179 }
1180
Ben Widawsky616fdb52011-10-05 11:44:54 -07001181 mutex_unlock(&dev->struct_mutex);
1182
Jesse Barnesf97108d2010-01-29 11:27:07 -08001183 return 0;
1184}
1185
1186static inline int MAP_TO_MV(int map)
1187{
1188 return 1250 - (map * 25);
1189}
1190
1191static int i915_inttoext_table(struct seq_file *m, void *unused)
1192{
1193 struct drm_info_node *node = (struct drm_info_node *) m->private;
1194 struct drm_device *dev = node->minor->dev;
1195 drm_i915_private_t *dev_priv = dev->dev_private;
1196 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001197 int ret, i;
1198
1199 ret = mutex_lock_interruptible(&dev->struct_mutex);
1200 if (ret)
1201 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001202
1203 for (i = 1; i <= 32; i++) {
1204 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1205 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1206 }
1207
Ben Widawsky616fdb52011-10-05 11:44:54 -07001208 mutex_unlock(&dev->struct_mutex);
1209
Jesse Barnesf97108d2010-01-29 11:27:07 -08001210 return 0;
1211}
1212
Ben Widawsky4d855292011-12-12 19:34:16 -08001213static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001214{
1215 struct drm_info_node *node = (struct drm_info_node *) m->private;
1216 struct drm_device *dev = node->minor->dev;
1217 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001218 u32 rgvmodectl, rstdbyctl;
1219 u16 crstandvid;
1220 int ret;
1221
1222 ret = mutex_lock_interruptible(&dev->struct_mutex);
1223 if (ret)
1224 return ret;
1225
1226 rgvmodectl = I915_READ(MEMMODECTL);
1227 rstdbyctl = I915_READ(RSTDBYCTL);
1228 crstandvid = I915_READ16(CRSTANDVID);
1229
1230 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001231
1232 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1233 "yes" : "no");
1234 seq_printf(m, "Boost freq: %d\n",
1235 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1236 MEMMODE_BOOST_FREQ_SHIFT);
1237 seq_printf(m, "HW control enabled: %s\n",
1238 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1239 seq_printf(m, "SW control enabled: %s\n",
1240 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1241 seq_printf(m, "Gated voltage change: %s\n",
1242 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1243 seq_printf(m, "Starting frequency: P%d\n",
1244 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001245 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001246 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001247 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1248 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1249 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1250 seq_printf(m, "Render standby enabled: %s\n",
1251 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Jesse Barnes88271da2011-01-05 12:01:24 -08001252 seq_printf(m, "Current RS state: ");
1253 switch (rstdbyctl & RSX_STATUS_MASK) {
1254 case RSX_STATUS_ON:
1255 seq_printf(m, "on\n");
1256 break;
1257 case RSX_STATUS_RC1:
1258 seq_printf(m, "RC1\n");
1259 break;
1260 case RSX_STATUS_RC1E:
1261 seq_printf(m, "RC1E\n");
1262 break;
1263 case RSX_STATUS_RS1:
1264 seq_printf(m, "RS1\n");
1265 break;
1266 case RSX_STATUS_RS2:
1267 seq_printf(m, "RS2 (RC6)\n");
1268 break;
1269 case RSX_STATUS_RS3:
1270 seq_printf(m, "RC3 (RC6+)\n");
1271 break;
1272 default:
1273 seq_printf(m, "unknown\n");
1274 break;
1275 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001276
1277 return 0;
1278}
1279
Ben Widawsky4d855292011-12-12 19:34:16 -08001280static int gen6_drpc_info(struct seq_file *m)
1281{
1282
1283 struct drm_info_node *node = (struct drm_info_node *) m->private;
1284 struct drm_device *dev = node->minor->dev;
1285 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001286 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001287 unsigned forcewake_count;
Ben Widawsky4d855292011-12-12 19:34:16 -08001288 int count=0, ret;
1289
1290
1291 ret = mutex_lock_interruptible(&dev->struct_mutex);
1292 if (ret)
1293 return ret;
1294
Daniel Vetter93b525d2012-01-25 13:52:43 +01001295 spin_lock_irq(&dev_priv->gt_lock);
1296 forcewake_count = dev_priv->forcewake_count;
1297 spin_unlock_irq(&dev_priv->gt_lock);
1298
1299 if (forcewake_count) {
1300 seq_printf(m, "RC information inaccurate because somebody "
1301 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001302 } else {
1303 /* NB: we cannot use forcewake, else we read the wrong values */
1304 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1305 udelay(10);
1306 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1307 }
1308
1309 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
1310 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4);
1311
1312 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1313 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1314 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001315 mutex_lock(&dev_priv->rps.hw_lock);
1316 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1317 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001318
1319 seq_printf(m, "Video Turbo Mode: %s\n",
1320 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1321 seq_printf(m, "HW control enabled: %s\n",
1322 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1323 seq_printf(m, "SW control enabled: %s\n",
1324 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1325 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001326 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001327 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1328 seq_printf(m, "RC6 Enabled: %s\n",
1329 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1330 seq_printf(m, "Deep RC6 Enabled: %s\n",
1331 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1332 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1333 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
1334 seq_printf(m, "Current RC state: ");
1335 switch (gt_core_status & GEN6_RCn_MASK) {
1336 case GEN6_RC0:
1337 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
1338 seq_printf(m, "Core Power Down\n");
1339 else
1340 seq_printf(m, "on\n");
1341 break;
1342 case GEN6_RC3:
1343 seq_printf(m, "RC3\n");
1344 break;
1345 case GEN6_RC6:
1346 seq_printf(m, "RC6\n");
1347 break;
1348 case GEN6_RC7:
1349 seq_printf(m, "RC7\n");
1350 break;
1351 default:
1352 seq_printf(m, "Unknown\n");
1353 break;
1354 }
1355
1356 seq_printf(m, "Core Power Down: %s\n",
1357 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001358
1359 /* Not exactly sure what this is */
1360 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1361 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1362 seq_printf(m, "RC6 residency since boot: %u\n",
1363 I915_READ(GEN6_GT_GFX_RC6));
1364 seq_printf(m, "RC6+ residency since boot: %u\n",
1365 I915_READ(GEN6_GT_GFX_RC6p));
1366 seq_printf(m, "RC6++ residency since boot: %u\n",
1367 I915_READ(GEN6_GT_GFX_RC6pp));
1368
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001369 seq_printf(m, "RC6 voltage: %dmV\n",
1370 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1371 seq_printf(m, "RC6+ voltage: %dmV\n",
1372 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1373 seq_printf(m, "RC6++ voltage: %dmV\n",
1374 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001375 return 0;
1376}
1377
1378static int i915_drpc_info(struct seq_file *m, void *unused)
1379{
1380 struct drm_info_node *node = (struct drm_info_node *) m->private;
1381 struct drm_device *dev = node->minor->dev;
1382
1383 if (IS_GEN6(dev) || IS_GEN7(dev))
1384 return gen6_drpc_info(m);
1385 else
1386 return ironlake_drpc_info(m);
1387}
1388
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001389static int i915_fbc_status(struct seq_file *m, void *unused)
1390{
1391 struct drm_info_node *node = (struct drm_info_node *) m->private;
1392 struct drm_device *dev = node->minor->dev;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001393 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001394
Adam Jacksonee5382a2010-04-23 11:17:39 -04001395 if (!I915_HAS_FBC(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001396 seq_printf(m, "FBC unsupported on this chipset\n");
1397 return 0;
1398 }
1399
Adam Jacksonee5382a2010-04-23 11:17:39 -04001400 if (intel_fbc_enabled(dev)) {
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001401 seq_printf(m, "FBC enabled\n");
1402 } else {
1403 seq_printf(m, "FBC disabled: ");
1404 switch (dev_priv->no_fbc_reason) {
Chris Wilsonbed4a672010-09-11 10:47:47 +01001405 case FBC_NO_OUTPUT:
1406 seq_printf(m, "no outputs");
1407 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001408 case FBC_STOLEN_TOO_SMALL:
1409 seq_printf(m, "not enough stolen memory");
1410 break;
1411 case FBC_UNSUPPORTED_MODE:
1412 seq_printf(m, "mode not supported");
1413 break;
1414 case FBC_MODE_TOO_LARGE:
1415 seq_printf(m, "mode too large");
1416 break;
1417 case FBC_BAD_PLANE:
1418 seq_printf(m, "FBC unsupported on plane");
1419 break;
1420 case FBC_NOT_TILED:
1421 seq_printf(m, "scanout buffer not tiled");
1422 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001423 case FBC_MULTIPLE_PIPES:
1424 seq_printf(m, "multiple pipes are enabled");
1425 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001426 case FBC_MODULE_PARAM:
1427 seq_printf(m, "disabled per module param (default off)");
1428 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001429 default:
1430 seq_printf(m, "unknown reason");
1431 }
1432 seq_printf(m, "\n");
1433 }
1434 return 0;
1435}
1436
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001437static int i915_sr_status(struct seq_file *m, void *unused)
1438{
1439 struct drm_info_node *node = (struct drm_info_node *) m->private;
1440 struct drm_device *dev = node->minor->dev;
1441 drm_i915_private_t *dev_priv = dev->dev_private;
1442 bool sr_enabled = false;
1443
Yuanhan Liu13982612010-12-15 15:42:31 +08001444 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001445 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001446 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001447 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1448 else if (IS_I915GM(dev))
1449 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1450 else if (IS_PINEVIEW(dev))
1451 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1452
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001453 seq_printf(m, "self-refresh: %s\n",
1454 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001455
1456 return 0;
1457}
1458
Jesse Barnes7648fa92010-05-20 14:28:11 -07001459static int i915_emon_status(struct seq_file *m, void *unused)
1460{
1461 struct drm_info_node *node = (struct drm_info_node *) m->private;
1462 struct drm_device *dev = node->minor->dev;
1463 drm_i915_private_t *dev_priv = dev->dev_private;
1464 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001465 int ret;
1466
Chris Wilson582be6b2012-04-30 19:35:02 +01001467 if (!IS_GEN5(dev))
1468 return -ENODEV;
1469
Chris Wilsonde227ef2010-07-03 07:58:38 +01001470 ret = mutex_lock_interruptible(&dev->struct_mutex);
1471 if (ret)
1472 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001473
1474 temp = i915_mch_val(dev_priv);
1475 chipset = i915_chipset_val(dev_priv);
1476 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001477 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001478
1479 seq_printf(m, "GMCH temp: %ld\n", temp);
1480 seq_printf(m, "Chipset power: %ld\n", chipset);
1481 seq_printf(m, "GFX power: %ld\n", gfx);
1482 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1483
1484 return 0;
1485}
1486
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001487static int i915_ring_freq_table(struct seq_file *m, void *unused)
1488{
1489 struct drm_info_node *node = (struct drm_info_node *) m->private;
1490 struct drm_device *dev = node->minor->dev;
1491 drm_i915_private_t *dev_priv = dev->dev_private;
1492 int ret;
1493 int gpu_freq, ia_freq;
1494
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001495 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001496 seq_printf(m, "unsupported on this chipset\n");
1497 return 0;
1498 }
1499
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001500 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001501 if (ret)
1502 return ret;
1503
Chris Wilson3ebecd02013-04-12 19:10:13 +01001504 seq_printf(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001505
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001506 for (gpu_freq = dev_priv->rps.min_delay;
1507 gpu_freq <= dev_priv->rps.max_delay;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001508 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001509 ia_freq = gpu_freq;
1510 sandybridge_pcode_read(dev_priv,
1511 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1512 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001513 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1514 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1515 ((ia_freq >> 0) & 0xff) * 100,
1516 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001517 }
1518
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001519 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001520
1521 return 0;
1522}
1523
Jesse Barnes7648fa92010-05-20 14:28:11 -07001524static int i915_gfxec(struct seq_file *m, void *unused)
1525{
1526 struct drm_info_node *node = (struct drm_info_node *) m->private;
1527 struct drm_device *dev = node->minor->dev;
1528 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001529 int ret;
1530
1531 ret = mutex_lock_interruptible(&dev->struct_mutex);
1532 if (ret)
1533 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001534
1535 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
1536
Ben Widawsky616fdb52011-10-05 11:44:54 -07001537 mutex_unlock(&dev->struct_mutex);
1538
Jesse Barnes7648fa92010-05-20 14:28:11 -07001539 return 0;
1540}
1541
Chris Wilson44834a62010-08-19 16:09:23 +01001542static int i915_opregion(struct seq_file *m, void *unused)
1543{
1544 struct drm_info_node *node = (struct drm_info_node *) m->private;
1545 struct drm_device *dev = node->minor->dev;
1546 drm_i915_private_t *dev_priv = dev->dev_private;
1547 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001548 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001549 int ret;
1550
Daniel Vetter0d38f002012-04-21 22:49:10 +02001551 if (data == NULL)
1552 return -ENOMEM;
1553
Chris Wilson44834a62010-08-19 16:09:23 +01001554 ret = mutex_lock_interruptible(&dev->struct_mutex);
1555 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001556 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001557
Daniel Vetter0d38f002012-04-21 22:49:10 +02001558 if (opregion->header) {
1559 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1560 seq_write(m, data, OPREGION_SIZE);
1561 }
Chris Wilson44834a62010-08-19 16:09:23 +01001562
1563 mutex_unlock(&dev->struct_mutex);
1564
Daniel Vetter0d38f002012-04-21 22:49:10 +02001565out:
1566 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001567 return 0;
1568}
1569
Chris Wilson37811fc2010-08-25 22:45:57 +01001570static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1571{
1572 struct drm_info_node *node = (struct drm_info_node *) m->private;
1573 struct drm_device *dev = node->minor->dev;
1574 drm_i915_private_t *dev_priv = dev->dev_private;
1575 struct intel_fbdev *ifbdev;
1576 struct intel_framebuffer *fb;
1577 int ret;
1578
1579 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1580 if (ret)
1581 return ret;
1582
1583 ifbdev = dev_priv->fbdev;
1584 fb = to_intel_framebuffer(ifbdev->helper.fb);
1585
Daniel Vetter623f9782012-12-11 16:21:38 +01001586 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001587 fb->base.width,
1588 fb->base.height,
1589 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001590 fb->base.bits_per_pixel,
1591 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001592 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001593 seq_printf(m, "\n");
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001594 mutex_unlock(&dev->mode_config.mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001595
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001596 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001597 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
1598 if (&fb->base == ifbdev->helper.fb)
1599 continue;
1600
Daniel Vetter623f9782012-12-11 16:21:38 +01001601 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001602 fb->base.width,
1603 fb->base.height,
1604 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001605 fb->base.bits_per_pixel,
1606 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001607 describe_obj(m, fb->obj);
Chris Wilson37811fc2010-08-25 22:45:57 +01001608 seq_printf(m, "\n");
1609 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001610 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001611
1612 return 0;
1613}
1614
Ben Widawskye76d3632011-03-19 18:14:29 -07001615static int i915_context_status(struct seq_file *m, void *unused)
1616{
1617 struct drm_info_node *node = (struct drm_info_node *) m->private;
1618 struct drm_device *dev = node->minor->dev;
1619 drm_i915_private_t *dev_priv = dev->dev_private;
Ben Widawskya168c292013-02-14 15:05:12 -08001620 struct intel_ring_buffer *ring;
1621 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001622
1623 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
1624 if (ret)
1625 return ret;
1626
Daniel Vetter3e373942012-11-02 19:55:04 +01001627 if (dev_priv->ips.pwrctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001628 seq_printf(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001629 describe_obj(m, dev_priv->ips.pwrctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001630 seq_printf(m, "\n");
1631 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001632
Daniel Vetter3e373942012-11-02 19:55:04 +01001633 if (dev_priv->ips.renderctx) {
Ben Widawskydc501fb2011-06-29 11:41:51 -07001634 seq_printf(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001635 describe_obj(m, dev_priv->ips.renderctx);
Ben Widawskydc501fb2011-06-29 11:41:51 -07001636 seq_printf(m, "\n");
1637 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001638
Ben Widawskya168c292013-02-14 15:05:12 -08001639 for_each_ring(ring, dev_priv, i) {
1640 if (ring->default_context) {
1641 seq_printf(m, "HW default context %s ring ", ring->name);
1642 describe_obj(m, ring->default_context->obj);
1643 seq_printf(m, "\n");
1644 }
1645 }
1646
Ben Widawskye76d3632011-03-19 18:14:29 -07001647 mutex_unlock(&dev->mode_config.mutex);
1648
1649 return 0;
1650}
1651
Ben Widawsky6d794d42011-04-25 11:25:56 -07001652static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1653{
1654 struct drm_info_node *node = (struct drm_info_node *) m->private;
1655 struct drm_device *dev = node->minor->dev;
1656 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001657 unsigned forcewake_count;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001658
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001659 spin_lock_irq(&dev_priv->gt_lock);
1660 forcewake_count = dev_priv->forcewake_count;
1661 spin_unlock_irq(&dev_priv->gt_lock);
1662
1663 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001664
1665 return 0;
1666}
1667
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001668static const char *swizzle_string(unsigned swizzle)
1669{
1670 switch(swizzle) {
1671 case I915_BIT_6_SWIZZLE_NONE:
1672 return "none";
1673 case I915_BIT_6_SWIZZLE_9:
1674 return "bit9";
1675 case I915_BIT_6_SWIZZLE_9_10:
1676 return "bit9/bit10";
1677 case I915_BIT_6_SWIZZLE_9_11:
1678 return "bit9/bit11";
1679 case I915_BIT_6_SWIZZLE_9_10_11:
1680 return "bit9/bit10/bit11";
1681 case I915_BIT_6_SWIZZLE_9_17:
1682 return "bit9/bit17";
1683 case I915_BIT_6_SWIZZLE_9_10_17:
1684 return "bit9/bit10/bit17";
1685 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001686 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001687 }
1688
1689 return "bug";
1690}
1691
1692static int i915_swizzle_info(struct seq_file *m, void *data)
1693{
1694 struct drm_info_node *node = (struct drm_info_node *) m->private;
1695 struct drm_device *dev = node->minor->dev;
1696 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001697 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001698
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001699 ret = mutex_lock_interruptible(&dev->struct_mutex);
1700 if (ret)
1701 return ret;
1702
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001703 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1704 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1705 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1706 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1707
1708 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1709 seq_printf(m, "DDC = 0x%08x\n",
1710 I915_READ(DCC));
1711 seq_printf(m, "C0DRB3 = 0x%04x\n",
1712 I915_READ16(C0DRB3));
1713 seq_printf(m, "C1DRB3 = 0x%04x\n",
1714 I915_READ16(C1DRB3));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001715 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
1716 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1717 I915_READ(MAD_DIMM_C0));
1718 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1719 I915_READ(MAD_DIMM_C1));
1720 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1721 I915_READ(MAD_DIMM_C2));
1722 seq_printf(m, "TILECTL = 0x%08x\n",
1723 I915_READ(TILECTL));
1724 seq_printf(m, "ARB_MODE = 0x%08x\n",
1725 I915_READ(ARB_MODE));
1726 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1727 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001728 }
1729 mutex_unlock(&dev->struct_mutex);
1730
1731 return 0;
1732}
1733
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001734static int i915_ppgtt_info(struct seq_file *m, void *data)
1735{
1736 struct drm_info_node *node = (struct drm_info_node *) m->private;
1737 struct drm_device *dev = node->minor->dev;
1738 struct drm_i915_private *dev_priv = dev->dev_private;
1739 struct intel_ring_buffer *ring;
1740 int i, ret;
1741
1742
1743 ret = mutex_lock_interruptible(&dev->struct_mutex);
1744 if (ret)
1745 return ret;
1746 if (INTEL_INFO(dev)->gen == 6)
1747 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1748
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001749 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001750 seq_printf(m, "%s\n", ring->name);
1751 if (INTEL_INFO(dev)->gen == 7)
1752 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1753 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1754 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1755 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1756 }
1757 if (dev_priv->mm.aliasing_ppgtt) {
1758 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1759
1760 seq_printf(m, "aliasing PPGTT:\n");
1761 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
1762 }
1763 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
1764 mutex_unlock(&dev->struct_mutex);
1765
1766 return 0;
1767}
1768
Jesse Barnes57f350b2012-03-28 13:39:25 -07001769static int i915_dpio_info(struct seq_file *m, void *data)
1770{
1771 struct drm_info_node *node = (struct drm_info_node *) m->private;
1772 struct drm_device *dev = node->minor->dev;
1773 struct drm_i915_private *dev_priv = dev->dev_private;
1774 int ret;
1775
1776
1777 if (!IS_VALLEYVIEW(dev)) {
1778 seq_printf(m, "unsupported\n");
1779 return 0;
1780 }
1781
Daniel Vetter09153002012-12-12 14:06:44 +01001782 ret = mutex_lock_interruptible(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001783 if (ret)
1784 return ret;
1785
1786 seq_printf(m, "DPIO_CTL: 0x%08x\n", I915_READ(DPIO_CTL));
1787
1788 seq_printf(m, "DPIO_DIV_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001789 vlv_dpio_read(dev_priv, _DPIO_DIV_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001790 seq_printf(m, "DPIO_DIV_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001791 vlv_dpio_read(dev_priv, _DPIO_DIV_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001792
1793 seq_printf(m, "DPIO_REFSFR_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001794 vlv_dpio_read(dev_priv, _DPIO_REFSFR_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001795 seq_printf(m, "DPIO_REFSFR_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001796 vlv_dpio_read(dev_priv, _DPIO_REFSFR_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001797
1798 seq_printf(m, "DPIO_CORE_CLK_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001799 vlv_dpio_read(dev_priv, _DPIO_CORE_CLK_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001800 seq_printf(m, "DPIO_CORE_CLK_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001801 vlv_dpio_read(dev_priv, _DPIO_CORE_CLK_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001802
1803 seq_printf(m, "DPIO_LFP_COEFF_A: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001804 vlv_dpio_read(dev_priv, _DPIO_LFP_COEFF_A));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001805 seq_printf(m, "DPIO_LFP_COEFF_B: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001806 vlv_dpio_read(dev_priv, _DPIO_LFP_COEFF_B));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001807
1808 seq_printf(m, "DPIO_FASTCLK_DISABLE: 0x%08x\n",
Jani Nikulaae992582013-05-22 15:36:19 +03001809 vlv_dpio_read(dev_priv, DPIO_FASTCLK_DISABLE));
Jesse Barnes57f350b2012-03-28 13:39:25 -07001810
Daniel Vetter09153002012-12-12 14:06:44 +01001811 mutex_unlock(&dev_priv->dpio_lock);
Jesse Barnes57f350b2012-03-28 13:39:25 -07001812
1813 return 0;
1814}
1815
Kees Cook647416f2013-03-10 14:10:06 -07001816static int
1817i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001818{
Kees Cook647416f2013-03-10 14:10:06 -07001819 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001820 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001821
Kees Cook647416f2013-03-10 14:10:06 -07001822 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001823
Kees Cook647416f2013-03-10 14:10:06 -07001824 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001825}
1826
Kees Cook647416f2013-03-10 14:10:06 -07001827static int
1828i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001829{
Kees Cook647416f2013-03-10 14:10:06 -07001830 struct drm_device *dev = data;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001831
Kees Cook647416f2013-03-10 14:10:06 -07001832 DRM_INFO("Manually setting wedged to %llu\n", val);
Chris Wilson527f9e92010-11-11 01:16:58 +00001833 i915_handle_error(dev, val);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001834
Kees Cook647416f2013-03-10 14:10:06 -07001835 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001836}
1837
Kees Cook647416f2013-03-10 14:10:06 -07001838DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
1839 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001840 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01001841
Kees Cook647416f2013-03-10 14:10:06 -07001842static int
1843i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001844{
Kees Cook647416f2013-03-10 14:10:06 -07001845 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001846 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001847
Kees Cook647416f2013-03-10 14:10:06 -07001848 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001849
Kees Cook647416f2013-03-10 14:10:06 -07001850 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001851}
1852
Kees Cook647416f2013-03-10 14:10:06 -07001853static int
1854i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001855{
Kees Cook647416f2013-03-10 14:10:06 -07001856 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001857 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001858 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001859
Kees Cook647416f2013-03-10 14:10:06 -07001860 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001861
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001862 ret = mutex_lock_interruptible(&dev->struct_mutex);
1863 if (ret)
1864 return ret;
1865
Daniel Vetter99584db2012-11-14 17:14:04 +01001866 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001867 mutex_unlock(&dev->struct_mutex);
1868
Kees Cook647416f2013-03-10 14:10:06 -07001869 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02001870}
1871
Kees Cook647416f2013-03-10 14:10:06 -07001872DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
1873 i915_ring_stop_get, i915_ring_stop_set,
1874 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02001875
Chris Wilsondd624af2013-01-15 12:39:35 +00001876#define DROP_UNBOUND 0x1
1877#define DROP_BOUND 0x2
1878#define DROP_RETIRE 0x4
1879#define DROP_ACTIVE 0x8
1880#define DROP_ALL (DROP_UNBOUND | \
1881 DROP_BOUND | \
1882 DROP_RETIRE | \
1883 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07001884static int
1885i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00001886{
Kees Cook647416f2013-03-10 14:10:06 -07001887 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00001888
Kees Cook647416f2013-03-10 14:10:06 -07001889 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00001890}
1891
Kees Cook647416f2013-03-10 14:10:06 -07001892static int
1893i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00001894{
Kees Cook647416f2013-03-10 14:10:06 -07001895 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00001896 struct drm_i915_private *dev_priv = dev->dev_private;
1897 struct drm_i915_gem_object *obj, *next;
Kees Cook647416f2013-03-10 14:10:06 -07001898 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00001899
Kees Cook647416f2013-03-10 14:10:06 -07001900 DRM_DEBUG_DRIVER("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00001901
1902 /* No need to check and wait for gpu resets, only libdrm auto-restarts
1903 * on ioctls on -EAGAIN. */
1904 ret = mutex_lock_interruptible(&dev->struct_mutex);
1905 if (ret)
1906 return ret;
1907
1908 if (val & DROP_ACTIVE) {
1909 ret = i915_gpu_idle(dev);
1910 if (ret)
1911 goto unlock;
1912 }
1913
1914 if (val & (DROP_RETIRE | DROP_ACTIVE))
1915 i915_gem_retire_requests(dev);
1916
1917 if (val & DROP_BOUND) {
1918 list_for_each_entry_safe(obj, next, &dev_priv->mm.inactive_list, mm_list)
1919 if (obj->pin_count == 0) {
1920 ret = i915_gem_object_unbind(obj);
1921 if (ret)
1922 goto unlock;
1923 }
1924 }
1925
1926 if (val & DROP_UNBOUND) {
1927 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list, gtt_list)
1928 if (obj->pages_pin_count == 0) {
1929 ret = i915_gem_object_put_pages(obj);
1930 if (ret)
1931 goto unlock;
1932 }
1933 }
1934
1935unlock:
1936 mutex_unlock(&dev->struct_mutex);
1937
Kees Cook647416f2013-03-10 14:10:06 -07001938 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00001939}
1940
Kees Cook647416f2013-03-10 14:10:06 -07001941DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
1942 i915_drop_caches_get, i915_drop_caches_set,
1943 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00001944
Kees Cook647416f2013-03-10 14:10:06 -07001945static int
1946i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07001947{
Kees Cook647416f2013-03-10 14:10:06 -07001948 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07001949 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001950 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02001951
1952 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1953 return -ENODEV;
1954
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001955 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02001956 if (ret)
1957 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07001958
Jesse Barnes0a073b82013-04-17 15:54:58 -07001959 if (IS_VALLEYVIEW(dev))
1960 *val = vlv_gpu_freq(dev_priv->mem_freq,
1961 dev_priv->rps.max_delay);
1962 else
1963 *val = dev_priv->rps.max_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001964 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001965
Kees Cook647416f2013-03-10 14:10:06 -07001966 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07001967}
1968
Kees Cook647416f2013-03-10 14:10:06 -07001969static int
1970i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07001971{
Kees Cook647416f2013-03-10 14:10:06 -07001972 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07001973 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07001974 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02001975
1976 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
1977 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07001978
Kees Cook647416f2013-03-10 14:10:06 -07001979 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07001980
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;
1984
Jesse Barnes358733e2011-07-27 11:53:01 -07001985 /*
1986 * Turbo will still be enabled, but won't go above the set value.
1987 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07001988 if (IS_VALLEYVIEW(dev)) {
1989 val = vlv_freq_opcode(dev_priv->mem_freq, val);
1990 dev_priv->rps.max_delay = val;
1991 gen6_set_rps(dev, val);
1992 } else {
1993 do_div(val, GT_FREQUENCY_MULTIPLIER);
1994 dev_priv->rps.max_delay = val;
1995 gen6_set_rps(dev, val);
1996 }
1997
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001998 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07001999
Kees Cook647416f2013-03-10 14:10:06 -07002000 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07002001}
2002
Kees Cook647416f2013-03-10 14:10:06 -07002003DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
2004 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002005 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07002006
Kees Cook647416f2013-03-10 14:10:06 -07002007static int
2008i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07002009{
Kees Cook647416f2013-03-10 14:10:06 -07002010 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07002011 drm_i915_private_t *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002012 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002013
2014 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2015 return -ENODEV;
2016
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002017 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002018 if (ret)
2019 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07002020
Jesse Barnes0a073b82013-04-17 15:54:58 -07002021 if (IS_VALLEYVIEW(dev))
2022 *val = vlv_gpu_freq(dev_priv->mem_freq,
2023 dev_priv->rps.min_delay);
2024 else
2025 *val = dev_priv->rps.min_delay * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002026 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002027
Kees Cook647416f2013-03-10 14:10:06 -07002028 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07002029}
2030
Kees Cook647416f2013-03-10 14:10:06 -07002031static int
2032i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07002033{
Kees Cook647416f2013-03-10 14:10:06 -07002034 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07002035 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07002036 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002037
2038 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2039 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07002040
Kees Cook647416f2013-03-10 14:10:06 -07002041 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07002042
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002043 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02002044 if (ret)
2045 return ret;
2046
Jesse Barnes1523c312012-05-25 12:34:54 -07002047 /*
2048 * Turbo will still be enabled, but won't go below the set value.
2049 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07002050 if (IS_VALLEYVIEW(dev)) {
2051 val = vlv_freq_opcode(dev_priv->mem_freq, val);
2052 dev_priv->rps.min_delay = val;
2053 valleyview_set_rps(dev, val);
2054 } else {
2055 do_div(val, GT_FREQUENCY_MULTIPLIER);
2056 dev_priv->rps.min_delay = val;
2057 gen6_set_rps(dev, val);
2058 }
Jesse Barnes4fc688c2012-11-02 11:14:01 -07002059 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07002060
Kees Cook647416f2013-03-10 14:10:06 -07002061 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07002062}
2063
Kees Cook647416f2013-03-10 14:10:06 -07002064DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
2065 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03002066 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07002067
Kees Cook647416f2013-03-10 14:10:06 -07002068static int
2069i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002070{
Kees Cook647416f2013-03-10 14:10:06 -07002071 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002072 drm_i915_private_t *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002073 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07002074 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002075
Daniel Vetter004777c2012-08-09 15:07:01 +02002076 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2077 return -ENODEV;
2078
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002079 ret = mutex_lock_interruptible(&dev->struct_mutex);
2080 if (ret)
2081 return ret;
2082
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002083 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2084 mutex_unlock(&dev_priv->dev->struct_mutex);
2085
Kees Cook647416f2013-03-10 14:10:06 -07002086 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002087
Kees Cook647416f2013-03-10 14:10:06 -07002088 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002089}
2090
Kees Cook647416f2013-03-10 14:10:06 -07002091static int
2092i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002093{
Kees Cook647416f2013-03-10 14:10:06 -07002094 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002095 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002096 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002097
Daniel Vetter004777c2012-08-09 15:07:01 +02002098 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
2099 return -ENODEV;
2100
Kees Cook647416f2013-03-10 14:10:06 -07002101 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002102 return -EINVAL;
2103
Kees Cook647416f2013-03-10 14:10:06 -07002104 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002105
2106 /* Update the cache sharing policy here as well */
2107 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
2108 snpcr &= ~GEN6_MBC_SNPCR_MASK;
2109 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
2110 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
2111
Kees Cook647416f2013-03-10 14:10:06 -07002112 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002113}
2114
Kees Cook647416f2013-03-10 14:10:06 -07002115DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
2116 i915_cache_sharing_get, i915_cache_sharing_set,
2117 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002118
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002119/* As the drm_debugfs_init() routines are called before dev->dev_private is
2120 * allocated we need to hook into the minor for release. */
2121static int
2122drm_add_fake_info_node(struct drm_minor *minor,
2123 struct dentry *ent,
2124 const void *key)
2125{
2126 struct drm_info_node *node;
2127
2128 node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
2129 if (node == NULL) {
2130 debugfs_remove(ent);
2131 return -ENOMEM;
2132 }
2133
2134 node->minor = minor;
2135 node->dent = ent;
2136 node->info_ent = (void *) key;
Marcin Slusarzb3e067c2011-11-09 22:20:35 +01002137
2138 mutex_lock(&minor->debugfs_lock);
2139 list_add(&node->list, &minor->debugfs_list);
2140 mutex_unlock(&minor->debugfs_lock);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002141
2142 return 0;
2143}
2144
Ben Widawsky6d794d42011-04-25 11:25:56 -07002145static int i915_forcewake_open(struct inode *inode, struct file *file)
2146{
2147 struct drm_device *dev = inode->i_private;
2148 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002149
Daniel Vetter075edca2012-01-24 09:44:28 +01002150 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002151 return 0;
2152
Ben Widawsky6d794d42011-04-25 11:25:56 -07002153 gen6_gt_force_wake_get(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002154
2155 return 0;
2156}
2157
Ben Widawskyc43b5632012-04-16 14:07:40 -07002158static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002159{
2160 struct drm_device *dev = inode->i_private;
2161 struct drm_i915_private *dev_priv = dev->dev_private;
2162
Daniel Vetter075edca2012-01-24 09:44:28 +01002163 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07002164 return 0;
2165
Ben Widawsky6d794d42011-04-25 11:25:56 -07002166 gen6_gt_force_wake_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002167
2168 return 0;
2169}
2170
2171static const struct file_operations i915_forcewake_fops = {
2172 .owner = THIS_MODULE,
2173 .open = i915_forcewake_open,
2174 .release = i915_forcewake_release,
2175};
2176
2177static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
2178{
2179 struct drm_device *dev = minor->dev;
2180 struct dentry *ent;
2181
2182 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07002183 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07002184 root, dev,
2185 &i915_forcewake_fops);
2186 if (IS_ERR(ent))
2187 return PTR_ERR(ent);
2188
Ben Widawsky8eb57292011-05-11 15:10:58 -07002189 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002190}
2191
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002192static int i915_debugfs_create(struct dentry *root,
2193 struct drm_minor *minor,
2194 const char *name,
2195 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07002196{
2197 struct drm_device *dev = minor->dev;
2198 struct dentry *ent;
2199
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002200 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07002201 S_IRUGO | S_IWUSR,
2202 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002203 fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002204 if (IS_ERR(ent))
2205 return PTR_ERR(ent);
2206
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002207 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002208}
2209
Ben Gamari27c202a2009-07-01 22:26:52 -04002210static struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00002211 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01002212 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00002213 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01002214 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002215 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05002216 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002217 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002218 {"i915_gem_request", i915_gem_request_info, 0},
2219 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00002220 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002221 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002222 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
2223 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
2224 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08002225 {"i915_rstdby_delays", i915_rstdby_delays, 0},
2226 {"i915_cur_delayinfo", i915_cur_delayinfo, 0},
2227 {"i915_delayfreq_table", i915_delayfreq_table, 0},
2228 {"i915_inttoext_table", i915_inttoext_table, 0},
2229 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002230 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07002231 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07002232 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08002233 {"i915_fbc_status", i915_fbc_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08002234 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01002235 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01002236 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07002237 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07002238 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002239 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002240 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Jesse Barnes57f350b2012-03-28 13:39:25 -07002241 {"i915_dpio", i915_dpio_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05002242};
Ben Gamari27c202a2009-07-01 22:26:52 -04002243#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05002244
Ben Gamari27c202a2009-07-01 22:26:52 -04002245int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002246{
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002247 int ret;
2248
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002249 ret = i915_debugfs_create(minor->debugfs_root, minor,
2250 "i915_wedged",
2251 &i915_wedged_fops);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01002252 if (ret)
2253 return ret;
2254
Ben Widawsky6d794d42011-04-25 11:25:56 -07002255 ret = i915_forcewake_create(minor->debugfs_root, minor);
2256 if (ret)
2257 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002258
2259 ret = i915_debugfs_create(minor->debugfs_root, minor,
2260 "i915_max_freq",
2261 &i915_max_freq_fops);
Jesse Barnes358733e2011-07-27 11:53:01 -07002262 if (ret)
2263 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002264
2265 ret = i915_debugfs_create(minor->debugfs_root, minor,
Jesse Barnes1523c312012-05-25 12:34:54 -07002266 "i915_min_freq",
2267 &i915_min_freq_fops);
2268 if (ret)
2269 return ret;
2270
2271 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01002272 "i915_cache_sharing",
2273 &i915_cache_sharing_fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002274 if (ret)
2275 return ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02002276
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002277 ret = i915_debugfs_create(minor->debugfs_root, minor,
2278 "i915_ring_stop",
2279 &i915_ring_stop_fops);
2280 if (ret)
2281 return ret;
Ben Widawsky6d794d42011-04-25 11:25:56 -07002282
Daniel Vetterd5442302012-04-27 15:17:40 +02002283 ret = i915_debugfs_create(minor->debugfs_root, minor,
Chris Wilsondd624af2013-01-15 12:39:35 +00002284 "i915_gem_drop_caches",
2285 &i915_drop_caches_fops);
2286 if (ret)
2287 return ret;
2288
2289 ret = i915_debugfs_create(minor->debugfs_root, minor,
Daniel Vetterd5442302012-04-27 15:17:40 +02002290 "i915_error_state",
2291 &i915_error_state_fops);
2292 if (ret)
2293 return ret;
2294
Mika Kuoppala40633212012-12-04 15:12:00 +02002295 ret = i915_debugfs_create(minor->debugfs_root, minor,
2296 "i915_next_seqno",
2297 &i915_next_seqno_fops);
2298 if (ret)
2299 return ret;
2300
Ben Gamari27c202a2009-07-01 22:26:52 -04002301 return drm_debugfs_create_files(i915_debugfs_list,
2302 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05002303 minor->debugfs_root, minor);
2304}
2305
Ben Gamari27c202a2009-07-01 22:26:52 -04002306void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05002307{
Ben Gamari27c202a2009-07-01 22:26:52 -04002308 drm_debugfs_remove_files(i915_debugfs_list,
2309 I915_DEBUGFS_ENTRIES, minor);
Ben Widawsky6d794d42011-04-25 11:25:56 -07002310 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
2311 1, minor);
Kristian Høgsberg33db6792009-11-11 12:19:16 -05002312 drm_debugfs_remove_files((struct drm_info_list *) &i915_wedged_fops,
2313 1, minor);
Jesse Barnes358733e2011-07-27 11:53:01 -07002314 drm_debugfs_remove_files((struct drm_info_list *) &i915_max_freq_fops,
2315 1, minor);
Jesse Barnes1523c312012-05-25 12:34:54 -07002316 drm_debugfs_remove_files((struct drm_info_list *) &i915_min_freq_fops,
2317 1, minor);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07002318 drm_debugfs_remove_files((struct drm_info_list *) &i915_cache_sharing_fops,
2319 1, minor);
Chris Wilsondd624af2013-01-15 12:39:35 +00002320 drm_debugfs_remove_files((struct drm_info_list *) &i915_drop_caches_fops,
2321 1, minor);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02002322 drm_debugfs_remove_files((struct drm_info_list *) &i915_ring_stop_fops,
2323 1, minor);
Daniel Vetter6bd459d2012-05-21 19:56:52 +02002324 drm_debugfs_remove_files((struct drm_info_list *) &i915_error_state_fops,
2325 1, minor);
Mika Kuoppala40633212012-12-04 15:12:00 +02002326 drm_debugfs_remove_files((struct drm_info_list *) &i915_next_seqno_fops,
2327 1, minor);
Ben Gamari20172632009-02-17 20:08:50 -05002328}
2329
2330#endif /* CONFIG_DEBUG_FS */