blob: ccce2279a794a27e1bb99514b541f2b4e51b637a [file] [log] [blame]
Chris Wilsonb98bade2013-08-20 21:39:27 +01001/*
2 * Copyright © 2013 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 */
24
Chris Wilson55b8c332013-08-19 18:15:04 +010025#include <sys/stat.h>
26#include <sys/mount.h>
27#include <errno.h>
Chris Wilson9574cb12013-08-23 15:51:21 +010028#include <stdio.h>
Chris Wilson55b8c332013-08-19 18:15:04 +010029
30#include "debugfs.h"
31
Chris Wilson9574cb12013-08-23 15:51:21 +010032char debugfs_path[128];
33
Chris Wilson55b8c332013-08-19 18:15:04 +010034int debugfs_init(void)
35{
Chris Wilson9574cb12013-08-23 15:51:21 +010036 const char *path = "/sys/kernel/debug";
Chris Wilson55b8c332013-08-19 18:15:04 +010037 struct stat st;
Chris Wilson9574cb12013-08-23 15:51:21 +010038 int n;
39
40 if (stat("/debug/dri", &st) == 0) {
41 path = "/debug/dri";
42 goto find_minor;
43 }
Chris Wilson55b8c332013-08-19 18:15:04 +010044
45 if (stat("/sys/kernel/debug/dri", &st) == 0)
Chris Wilson9574cb12013-08-23 15:51:21 +010046 goto find_minor;
Chris Wilson55b8c332013-08-19 18:15:04 +010047
48 if (stat("/sys/kernel/debug", &st))
49 return errno;
50
51 if (mount("debug", "/sys/kernel/debug", "debugfs", 0, 0))
52 return errno;
53
Chris Wilson9574cb12013-08-23 15:51:21 +010054find_minor:
55 for (n = 0; n < 16; n++) {
56 int len = sprintf(debugfs_path, "%s/dri/%d", path, n);
57 sprintf(debugfs_path + len, "/i915_error_state");
58 if (stat(debugfs_path, &st) == 0) {
59 debugfs_path[len] = '\0';
60 return 0;
61 }
62 }
63
64 debugfs_path[0] = '\0';
65 return ENOENT;
Chris Wilson55b8c332013-08-19 18:15:04 +010066}